dm: serial: Fix up some serial API errors
v2 cover dm: serial: Fix up some serial API errors
New serial functions should use a driver pointer as the first argument. The old functions are only there for backwards compatibilty, and can be adjusted soon.
For now, adjust the new functions to work correctly.
Changes in v2:
- Add a comment about reusing the device pointer
- Fix @return comment on getinfo() method
Simon Glass (5):
serial: Move new functions to serial.h
dm: serial: Adjust serial_getconfig() to use proper API
dm: serial: Adjust serial_setconfig() to use proper API
dm: serial: Adjust serial_getinfo() to use proper API
dm: serial: Tidy up header file comments
arch/x86/lib/acpi_table.c | 12 +++++++---- drivers/serial/serial-uclass.c | 27 ++++++++---------------- include/common.h | 5 ----- include/serial.h | 38 +++++++++++++++++++++++++++++++--- test/dm/serial.c | 19 ++++++++++------- 5 files changed, 63 insertions(+), 38 deletions(-)
Signature · 1 line
2.20.1.415.g653613c723-goog
PATCH v2 1/5 serial: Move new functions to serial.h
We should not be adding new functions to common.h. Move these recently added functions to serial.h.
---
Changes in v2: None
include/common.h | 5 ----- include/serial.h | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-)
include/common.h +0 -5
@@ -350,8 +350,6 @@ void smp_set_core_boot_addr(unsigned long addr, int corenr);void smp_kick_all_cpus (void );/* $(CPU)/serial.c */ -struct serial_device_info ; -int serial_init (void );void serial_setbrg (void );void serial_putc (const char );
@@ -359,9 +357,6 @@ void serial_putc_raw(const char);void serial_puts (const char *);int serial_getc (void );int serial_tstc (void ); -int serial_getconfig (uint *config); -int serial_setconfig (uint config); -int serial_getinfo (struct serial_device_info *info);/* $(CPU)/speed.c */ int get_clocks (void );
include/serial.h +4 -0
@@ -281,6 +281,10 @@ 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_setconfig (uint config); +int serial_getinfo (struct serial_device_info *info); +void atmel_serial_initialize (void );void mcf_serial_initialize (void );void mpc85xx_serial_initialize (void );
Signature · 1 line
2.20.1.415.g653613c723-goog
PATCH v2 1/5 serial: Move new functions to serial.h
We should not be adding new functions to common.h. Move these recently added functions to serial.h.
---
Changes in v2: None
include/common.h | 5 ----- include/serial.h | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v2 2/5 dm: serial: Adjust serial_getconfig() to use proper API
In reply to Simon GlassAll driver-model functions should have a device as the first parameter. Update this function accordingly.
---
Changes in v2: None
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(-)
arch/x86/lib/acpi_table.c +4 -1
@@ -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 ;
drivers/serial/serial-uclass.c +3 -6
@@ -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 ; }
include/serial.h +1 -1
@@ -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);
test/dm/serial.c +2 -2
@@ -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
Signature · 1 line
2.20.1.415.g653613c723-goog
PATCH v2 2/5 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.
---
Changes in v2: None
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(-)
Applied to u-boot-dm/next, thanks!
PATCH v2 3/5 dm: serial: Adjust serial_setconfig() to use proper API
In reply to Simon GlassAll driver-model functions should have a device as the first parameter. Update this function accordingly.
---
Changes in v2: None
drivers/serial/serial-uclass.c | 9 +++------ include/serial.h | 2 +- test/dm/serial.c | 11 +++++++---- 3 files changed, 11 insertions(+), 11 deletions(-)
drivers/serial/serial-uclass.c +3 -6
@@ -305,16 +305,13 @@ int serial_getconfig(struct udevice *dev, uint *config)return 0 ; } -int serial_setconfig (uint config) +int serial_setconfig (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->setconfig) -return ops->setconfig (gd->cur_serial_dev, config); +return ops->setconfig (dev, config);return 0 ; }
include/serial.h +1 -1
@@ -282,7 +282,7 @@ struct serial_dev_priv {#define serial_get_ops (dev) ((struct dm_serial_ops *)(dev)->driver->ops)int serial_getconfig (struct udevice *dev,uint *config); -int serial_setconfig (uint config); +int serial_setconfig (struct udevice *dev,uint config);int serial_getinfo (struct serial_device_info *info);void atmel_serial_initialize (void );
test/dm/serial.c +7 -4
@@ -23,7 +23,7 @@ static int dm_test_serial(struct unit_test_state *uts)* test with default config which is the only one supported by * sandbox_serial driver */ -ut_assertok (serial_setconfig (SERIAL_DEFAULT_CONFIG )); +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));
@@ -39,7 +39,8 @@ static int dm_test_serial(struct unit_test_state *uts)* sandbox_serial driver: test with wrong parity */ ut_asserteq (-ENOTSUPP , -serial_setconfig (SERIAL_CONFIG (SERIAL_PAR_ODD , +serial_setconfig (dev_serial, +SERIAL_CONFIG (SERIAL_PAR_ODD ,SERIAL_8_BITS ,SERIAL_ONE_STOP )));/*
@@ -47,7 +48,8 @@ static int dm_test_serial(struct unit_test_state *uts)* sandbox_serial driver: test with wrong bits number */ ut_asserteq (-ENOTSUPP , -serial_setconfig (SERIAL_CONFIG (SERIAL_PAR_NONE , +serial_setconfig (dev_serial, +SERIAL_CONFIG (SERIAL_PAR_NONE ,SERIAL_6_BITS ,SERIAL_ONE_STOP )));
@@ -56,7 +58,8 @@ static int dm_test_serial(struct unit_test_state *uts)* sandbox_serial driver: test with wrong stop bits number */ ut_asserteq (-ENOTSUPP , -serial_setconfig (SERIAL_CONFIG (SERIAL_PAR_NONE , +serial_setconfig (dev_serial, +SERIAL_CONFIG (SERIAL_PAR_NONE ,SERIAL_8_BITS ,SERIAL_TWO_STOP )));
Signature · 1 line
2.20.1.415.g653613c723-goog
PATCH v2 3/5 dm: serial: Adjust serial_setconfig() to use proper API
All driver-model functions should have a device as the first parameter. Update this function accordingly.
---
Changes in v2: None
drivers/serial/serial-uclass.c | 9 +++------ include/serial.h | 2 +- test/dm/serial.c | 11 +++++++---- 3 files changed, 11 insertions(+), 11 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v2 4/5 dm: serial: Adjust serial_getinfo() to use proper API
In reply to Simon GlassAll driver-model functions should have a device as the first parameter. Update this function accordingly.
---
Changes in v2:
- Add a comment about reusing the device pointer
arch/x86/lib/acpi_table.c | 11 ++++++----- drivers/serial/serial-uclass.c | 9 +++------ include/serial.h | 2 +- test/dm/serial.c | 4 ++-- 4 files changed, 12 insertions(+), 14 deletions(-)
arch/x86/lib/acpi_table.c +6 -5
@@ -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 (&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);
drivers/serial/serial-uclass.c +3 -6
@@ -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 ; }
include/serial.h +1 -1
@@ -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 );
test/dm/serial.c +2 -2
@@ -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
Signature · 1 line
2.20.1.415.g653613c723-goog
PATCH v2 4/5 dm: serial: Adjust serial_getinfo() to use proper API
All driver-model functions should have a device as the first parameter. Update this function accordingly.
---
Changes in v2:
- Add a comment about reusing the device pointer
arch/x86/lib/acpi_table.c | 11 ++++++----- drivers/serial/serial-uclass.c | 9 +++------ include/serial.h | 2 +- test/dm/serial.c | 4 ++-- 4 files changed, 12 insertions(+), 14 deletions(-)
Applied to u-boot-dm/next, thanks!
PATCH v2 5/5 dm: serial: Tidy up header file comments
In reply to Simon GlassThe getconfig() comment is out of date. Fix this and add comments for recently added functions.
---
Changes in v2:
- Fix @return comment on getinfo() method
include/serial.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
include/serial.h +31 -3
@@ -235,9 +235,7 @@ struct dm_serial_ops {* Get a current config for this device. * * @dev: Device pointer -* @parity: parity to use -* @bits: bits number to use -* @stop: stop bits number to use +* @serial_config: Returns config information (see SERIAL_... above) * @return 0 if OK, -ve on error */ int (*getconfig)(struct udevice *dev,uint *serial_config);
@@ -257,6 +255,7 @@ struct dm_serial_ops {* * @dev: Device pointer * @info: struct serial_device_info to fill +* @return 0 if OK, -ve on error */ int (*getinfo)(struct udevice *dev,struct serial_device_info *info); };
@@ -281,8 +280,37 @@ struct serial_dev_priv {/* Access the serial operations for a device */ #define serial_get_ops (dev) ((struct dm_serial_ops *)(dev)->driver->ops) +/** +* serial_getconfig() - Get the uart configuration +* (parity, 5/6/7/8 bits word length, stop bits) +* +* Get a current config for this device. +* +* @dev: Device pointer +* @serial_config: Returns config information (see SERIAL_... above) +* @return 0 if OK, -ve on error +*/ int serial_getconfig (struct udevice *dev,uint *config); + +/** +* serial_setconfig() - Set up the uart configuration +* (parity, 5/6/7/8 bits word length, stop bits) +* +* Set up a new config for this device. +* +* @dev: Device pointer +* @serial_config: number of bits, parity and number of stopbits to use +* @return 0 if OK, -ve on error +*/ int serial_setconfig (struct udevice *dev,uint config); + +/** +* serial_getinfo() - Get serial device information +* +* @dev: Device pointer +* @info: struct serial_device_info to fill +* @return 0 if OK, -ve on error +*/ int serial_getinfo (struct udevice *dev,struct serial_device_info *info);void atmel_serial_initialize (void );
Signature · 1 line
2.20.1.415.g653613c723-goog
PATCH v2 5/5 dm: serial: Tidy up header file comments
The getconfig() comment is out of date. Fix this and add comments for recently added functions.
---
Changes in v2:
- Fix @return comment on getinfo() method
include/serial.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-)
Applied to u-boot-dm/next, thanks!