dm: serial: Adjust serial_getinfo() to use proper API
authorSimon Glass <sjg@chromium.org>
Fri, 28 Dec 2018 21:23:10 +0000 (14:23 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 15 Jan 2019 00:47:13 +0000 (17:47 -0700)
All driver-model functions should have a device as the first parameter.
Update this function accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
arch/x86/lib/acpi_table.c
drivers/serial/serial-uclass.c
include/serial.h
test/dm/serial.c

index bfcf2adbf12288a5d532b7a52acc5466322b17d3..04058a60d75eb59c20dce160cf751cb11f9b8ad9 100644 (file)
@@ -354,7 +354,10 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
        header->length = sizeof(struct acpi_spcr);
        header->revision = 2;
 
-       ret = serial_getinfo(&serial_info);
+       /* Read the device once, here. It is reused below */
+       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 +435,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);
index 669c82f37931fa6dbfdae6939a68491a01227110..d4488a2cc288a55c977825a4c92d575388e9a41f 100644 (file)
@@ -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;
 }
index 8a05a0908980cbd5b09b5255326f8a9ac5d87718..8a790ccaaf4b36a624392c1878bf573c5728c832 100644 (file)
@@ -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);
index f82b4a19e8fb9933afcb564d6f1fe46a6ff9a64b..3d741a8c363cd38d37046582bcb66876e9e50602 100644 (file)
@@ -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