From 67d1b0513079049baa3e0e38603eb33a3857af5d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 28 Dec 2018 14:23:08 -0700 Subject: [PATCH] dm: serial: Adjust serial_getconfig() to use proper API All driver-model functions should have a device as the first parameter. Update this function accordingly. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- arch/x86/lib/acpi_table.c | 5 ++++- drivers/serial/serial-uclass.c | 9 +++------ include/serial.h | 2 +- test/dm/serial.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index 79bc2000bd..bfcf2adbf1 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -342,6 +342,7 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) struct acpi_table_header *header = &(spcr->header); struct serial_device_info serial_info = {0}; ulong serial_address, serial_offset; + struct udevice *dev; uint serial_config; uint serial_width; int access_size; @@ -431,7 +432,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) break; } - ret = serial_getconfig(&serial_config); + ret = uclass_first_device_err(UCLASS_SERIAL, &dev); + if (!ret) + ret = serial_getconfig(dev, &serial_config); if (ret) serial_config = SERIAL_DEFAULT_CONFIG; diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index ffcd6d15af..81f1067f42 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -294,16 +294,13 @@ void serial_setbrg(void) ops->setbrg(gd->cur_serial_dev, gd->baudrate); } -int serial_getconfig(uint *config) +int serial_getconfig(struct udevice *dev, uint *config) { struct dm_serial_ops *ops; - if (!gd->cur_serial_dev) - return 0; - - ops = serial_get_ops(gd->cur_serial_dev); + ops = serial_get_ops(dev); if (ops->getconfig) - return ops->getconfig(gd->cur_serial_dev, config); + return ops->getconfig(dev, config); return 0; } diff --git a/include/serial.h b/include/serial.h index fa7e0130bd..5ba031ab53 100644 --- a/include/serial.h +++ b/include/serial.h @@ -281,7 +281,7 @@ struct serial_dev_priv { /* Access the serial operations for a device */ #define serial_get_ops(dev) ((struct dm_serial_ops *)(dev)->driver->ops) -int serial_getconfig(uint *config); +int serial_getconfig(struct udevice *dev, uint *config); int serial_setconfig(uint config); int serial_getinfo(struct serial_device_info *info); diff --git a/test/dm/serial.c b/test/dm/serial.c index 19a15d5d95..972755face 100644 --- a/test/dm/serial.c +++ b/test/dm/serial.c @@ -24,7 +24,7 @@ static int dm_test_serial(struct unit_test_state *uts) * sandbox_serial driver */ ut_assertok(serial_setconfig(SERIAL_DEFAULT_CONFIG)); - ut_assertok(serial_getconfig(&value_serial)); + ut_assertok(serial_getconfig(dev_serial, &value_serial)); ut_assert(value_serial == SERIAL_DEFAULT_CONFIG); ut_assertok(serial_getinfo(&info_serial)); ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN); @@ -32,7 +32,7 @@ static int dm_test_serial(struct unit_test_state *uts) /* * test with a parameter which is NULL pointer */ - ut_asserteq(-EINVAL, serial_getconfig(NULL)); + ut_asserteq(-EINVAL, serial_getconfig(dev_serial, NULL)); ut_asserteq(-EINVAL, serial_getinfo(NULL)); /* * test with a serial config which is not supported by -- 2.39.5