[U-Boot] [PATCH 4/5] dm: serial: Adjust serial_getinfo() to use proper API

Simon Glass sjg at chromium.org
Wed Dec 5 19:53:52 UTC 2018


All driver-model functions should have a device as the first parameter.
Update this function accordingly.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 arch/x86/lib/acpi_table.c      | 10 +++++-----
 drivers/serial/serial-uclass.c |  9 +++------
 include/serial.h               |  2 +-
 test/dm/serial.c               |  4 ++--
 4 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c
index bfcf2adbf12..cc7bbfa1436 100644
--- a/arch/x86/lib/acpi_table.c
+++ b/arch/x86/lib/acpi_table.c
@@ -354,7 +354,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
 	header->length = sizeof(struct acpi_spcr);
 	header->revision = 2;
 
-	ret = serial_getinfo(&serial_info);
+	ret = uclass_first_device_err(UCLASS_SERIAL, &dev);
+	if (!ret)
+		ret = serial_getinfo(dev, &serial_info);
 	if (ret)
 		serial_info.type = SERIAL_CHIP_UNKNOWN;
 
@@ -432,11 +434,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
 		break;
 	}
 
-	ret = uclass_first_device_err(UCLASS_SERIAL, &dev);
-	if (!ret)
+	serial_config = SERIAL_DEFAULT_CONFIG;
+	if (dev)
 		ret = serial_getconfig(dev, &serial_config);
-	if (ret)
-		serial_config = SERIAL_DEFAULT_CONFIG;
 
 	spcr->parity = SERIAL_GET_PARITY(serial_config);
 	spcr->stop_bits = SERIAL_GET_STOP(serial_config);
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 669c82f3793..d4488a2cc28 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -316,21 +316,18 @@ int serial_setconfig(struct udevice *dev, uint config)
 	return 0;
 }
 
-int serial_getinfo(struct serial_device_info *info)
+int serial_getinfo(struct udevice *dev, struct serial_device_info *info)
 {
 	struct dm_serial_ops *ops;
 
-	if (!gd->cur_serial_dev)
-		return -ENODEV;
-
 	if (!info)
 		return -EINVAL;
 
 	info->baudrate = gd->baudrate;
 
-	ops = serial_get_ops(gd->cur_serial_dev);
+	ops = serial_get_ops(dev);
 	if (ops->getinfo)
-		return ops->getinfo(gd->cur_serial_dev, info);
+		return ops->getinfo(dev, info);
 
 	return -EINVAL;
 }
diff --git a/include/serial.h b/include/serial.h
index 8a05a090898..8a790ccaaf4 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -283,7 +283,7 @@ struct serial_dev_priv {
 
 int serial_getconfig(struct udevice *dev, uint *config);
 int serial_setconfig(struct udevice *dev, uint config);
-int serial_getinfo(struct serial_device_info *info);
+int serial_getinfo(struct udevice *dev, struct serial_device_info *info);
 
 void atmel_serial_initialize(void);
 void mcf_serial_initialize(void);
diff --git a/test/dm/serial.c b/test/dm/serial.c
index f82b4a19e8f..3d741a8c363 100644
--- a/test/dm/serial.c
+++ b/test/dm/serial.c
@@ -26,14 +26,14 @@ static int dm_test_serial(struct unit_test_state *uts)
 	ut_assertok(serial_setconfig(dev_serial, SERIAL_DEFAULT_CONFIG));
 	ut_assertok(serial_getconfig(dev_serial, &value_serial));
 	ut_assert(value_serial == SERIAL_DEFAULT_CONFIG);
-	ut_assertok(serial_getinfo(&info_serial));
+	ut_assertok(serial_getinfo(dev_serial, &info_serial));
 	ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
 	ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
 	/*
 	 * test with a parameter which is NULL pointer
 	 */
 	ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL));
-	ut_asserteq(-EINVAL, serial_getinfo(NULL));
+	ut_asserteq(-EINVAL, serial_getinfo(dev_serial, NULL));
 	/*
 	 * test with a serial config which is not supported by
 	 * sandbox_serial driver: test with wrong parity
-- 
2.20.0.rc1.387.gf8505762e3-goog



More information about the U-Boot mailing list