Skip to contentSkip to conversation

dm: serial: Add clock member to struct serial_device_info

PATCH New Andy Shevchenko 3 participants 11 messages Feb 27, 2020 – Apr 15, 2020 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dm: serial: Add clock member to struct serial_device_info

Some callers of serial_getinfo() would like to know the UART base clock speed in order to make decision what to pass to OS in some cases. In particular, ACPI SPCR table expects only certain base clock speed and thus we have to act accordingly.

---
 drivers/serial/sandbox.c | 1 +
 include/serial.h         | 3 +++
 test/dm/serial.c         | 1 +
 3 files changed, 5 insertions(+)
drivers/serial/sandbox.c +1 -0
index 1af5cc12f3..545ff3f747 100644
@@ -198,6 +198,7 @@ static int sandbox_serial_getinfo(struct udevice *dev,
 		.reg_width = 1,
 		.reg_offset = 0,
 		.reg_shift = 0,
+		.clock = SERIAL_DEFAULT_CLOCK,
 	};
 
 	if (!serial_info)
include/serial.h +3 -0
index 104f34ff91..54b21a0470 100644
@@ -139,6 +139,7 @@ enum adr_space_type {
  * @reg_width:	size (in bytes) of the IO accesses to the registers
  * @reg_offset:	offset to apply to the @addr from the start of the registers
  * @reg_shift:	quantity to shift the register offsets by
+ * @clock:	UART base clock speed in Hz
  * @baudrate:	baud rate
  */
 struct serial_device_info {
@@ -148,10 +149,12 @@ struct serial_device_info {
 	u8 reg_width;
 	u8 reg_offset;
 	u8 reg_shift;
+	unsigned int clock;
 	unsigned int baudrate;
 };
 
 #define SERIAL_DEFAULT_ADDRESS	0xBADACCE5
+#define SERIAL_DEFAULT_CLOCK	(16 * 115200)
 
 /**
  * struct struct dm_serial_ops - Driver model serial operations
test/dm/serial.c +1 -0
index 3d741a8c36..c6be6ab7ab 100644
@@ -29,6 +29,7 @@ static int dm_test_serial(struct unit_test_state *uts)
 	ut_assertok(serial_getinfo(dev_serial, &info_serial));
 	ut_assert(info_serial.type == SERIAL_CHIP_UNKNOWN);
 	ut_assert(info_serial.addr == SERIAL_DEFAULT_ADDRESS);
+	ut_assert(info_serial.clock == SERIAL_DEFAULT_CLOCK);
 	/*
 	 * test with a parameter which is NULL pointer
 	 */
Signature · 1 line
2.25.0
#1 lore raw

PATCH 2/3 serial: ns16550: Provide UART base clock speed in ->getinfo()

Some callers may need the UART base clock speed value. Provide it in the ->getinfo() callback.

---
 drivers/serial/ns16550.c | 1 +
 1 file changed, 1 insertion(+)
drivers/serial/ns16550.c +1 -0
index 1fcbc35015..386b5e04c8 100644
@@ -476,6 +476,7 @@ static int ns16550_serial_getinfo(struct udevice *dev,
 	info->reg_width = plat->reg_width;
 	info->reg_shift = plat->reg_shift;
 	info->reg_offset = plat->reg_offset;
+	info->clock = plat->clock;
 	return 0;
 }
 
Signature · 1 line
2.25.0
#5 lore raw

PATCH 3/3 x86: acpi: Let OS know that console already had been initialized

In reply to Andy Shevchenko

SPCR has no clue if the UART base clock speed is different to the default one. However, the SPCR 1.04 defines baud rate 0 as a preconfigured state of UART and OS is supposed not to touch the configuration of the serial device.

Linux kernel supports that starting from v5.0, see commit b413b1abeb21 ("ACPI: SPCR: Consider baud rate 0 as preconfigured state") for the details.

---
 arch/x86/lib/acpi_table.c | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/x86/lib/acpi_table.c +9 -0
index 66e32f21bd..074987e294 100644
@@ -471,6 +471,15 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)
 	spcr->pci_device_id = 0xffff;
 	spcr->pci_vendor_id = 0xffff;
 
+	/*
+	 * SPCR has no clue if the UART base clock speed is different
+	 * to the default one. However, the SPCR 1.04 defines baud rate
+	 * 0 as a preconfigured state of UART and OS is supposed not
+	 * to touch the configuration of the serial device.
+	 */
+	if (serial_info.clock != SERIAL_DEFAULT_CLOCK)
+		spcr->baud_rate = 0;
+
 	/* Fix checksum */
 	header->checksum = table_compute_checksum((void *)spcr, header->length);
 }
Signature · 1 line
2.25.0
#8 lore raw

PATCH 1/3 dm: serial: Add clock member to struct serial_device_info

In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

Some callers of serial_getinfo() would like to know the UART base clock speed in order to make decision what to pass to OS in some cases. In particular, ACPI SPCR table expects only certain base clock speed and thus we have to act accordingly.

Quoted 6 lines
---
 drivers/serial/sandbox.c | 1 +
 include/serial.h         | 3 +++
 test/dm/serial.c         | 1 +
 3 files changed, 5 insertions(+)
#2 lore raw

PATCH 2/3 serial: ns16550: Provide UART base clock speed in ->getinfo()

In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

Some callers may need the UART base clock speed value. Provide it in the ->getinfo() callback.

---
 drivers/serial/ns16550.c | 1 +
 1 file changed, 1 insertion(+)

drivers/serial/ns16550.c static int ns16550_serial_getinfo(struct udevice *dev, · line 479

Quoted 10 lines
drivers/serial/ns16550.c +1 -0
index 1fcbc35015..386b5e04c8 100644
@@ -476,6 +476,7 @@ static int ns16550_serial_getinfo(struct udevice *dev,
        info->reg_width = plat->reg_width;
        info->reg_shift = plat->reg_shift;
        info->reg_offset = plat->reg_offset;
+       info->clock = plat->clock;

blank line before return

Quoted 7 lines
drivers/serial/ns16550.c +0 -1
        return 0;
 }
 
 
--

2.25.0

#9 lore raw

PATCH 1/3 dm: serial: Add clock member to struct serial_device_info

In reply to Simon Glass
Quoted 9 lines · Simon Glass
Quoted 6 lines · Andy Shevchenko

Some callers of serial_getinfo() would like to know the UART base clock speed in order to make decision what to pass to OS in some cases. In particular, ACPI SPCR table expects only certain base clock speed and thus we have to act accordingly.

Quoted 8 lines
Quoted 6 lines
---
 drivers/serial/sandbox.c | 1 +
 include/serial.h         | 3 +++
 test/dm/serial.c         | 1 +
 3 files changed, 5 insertions(+)
#3 lore raw

PATCH 2/3 serial: ns16550: Provide UART base clock speed in ->getinfo()

In reply to Simon Glass
Quoted 15 lines · Simon Glass
Quoted 8 lines · Andy Shevchenko

Some callers may need the UART base clock speed value. Provide it in the ->getinfo() callback.

---
 drivers/serial/ns16550.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 1 line
Quoted 11 lines

drivers/serial/ns16550.c static int ns16550_serial_getinfo(struct udevice *dev, · line 479

Quoted 9 lines
drivers/serial/ns16550.c +1 -0
index 1fcbc35015..386b5e04c8 100644
@@ -476,6 +476,7 @@ static int ns16550_serial_getinfo(struct udevice *dev,
        info->reg_width = plat->reg_width;
        info->reg_shift = plat->reg_shift;
        info->reg_offset = plat->reg_offset;
+       info->clock = plat->clock;

blank line before return

I can fix this when applying.

Quoted 3 lines

drivers/serial/ns16550.c static int ns16550_serial_getinfo(struct udevice *dev, · line 481

Quoted 3 lines
drivers/serial/ns16550.c +0 -0
        return 0;
 }
#6 lore raw

PATCH 3/3 x86: acpi: Let OS know that console already had been initialized

In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

SPCR has no clue if the UART base clock speed is different to the default one. However, the SPCR 1.04 defines baud rate 0 as a preconfigured state of UART and OS is supposed not to touch the configuration of the serial device.

Quoted 9 lines

Linux kernel supports that starting from v5.0, see commit b413b1abeb21 ("ACPI: SPCR: Consider baud rate 0 as preconfigured state") for the details.

---
 arch/x86/lib/acpi_table.c | 9 +++++++++
 1 file changed, 9 insertions(+)
#10 lore raw

PATCH 1/3 dm: serial: Add clock member to struct serial_device_info

In reply to Bin Meng
Quoted 18 lines · Bin Meng
Quoted 16 lines · Simon Glass
Quoted 12 lines · Andy Shevchenko

Some callers of serial_getinfo() would like to know the UART base clock speed in order to make decision what to pass to OS in some cases. In particular, ACPI SPCR table expects only certain base clock speed and thus we have to act accordingly.

---
 drivers/serial/sandbox.c | 1 +
 include/serial.h         | 3 +++
 test/dm/serial.c         | 1 +
 3 files changed, 5 insertions(+)
Quoted 3 lines
Quoted 1 line

applied to u-boot-x86, thanks!

#4 lore raw

PATCH 2/3 serial: ns16550: Provide UART base clock speed in ->getinfo()

In reply to Bin Meng
Quoted 29 lines · Bin Meng
Quoted 15 lines · Simon Glass
Quoted 8 lines · Andy Shevchenko

Some callers may need the UART base clock speed value. Provide it in the ->getinfo() callback.

---
 drivers/serial/ns16550.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 1 line
Quoted 11 lines

drivers/serial/ns16550.c static int ns16550_serial_getinfo(struct udevice *dev, · line 479

Quoted 9 lines
drivers/serial/ns16550.c +1 -0
index 1fcbc35015..386b5e04c8 100644
@@ -476,6 +476,7 @@ static int ns16550_serial_getinfo(struct udevice *dev,
        info->reg_width = plat->reg_width;
        info->reg_shift = plat->reg_shift;
        info->reg_offset = plat->reg_offset;
+       info->clock = plat->clock;

blank line before return

Quoted 7 lines

I can fix this when applying.

Quoted 3 lines

drivers/serial/ns16550.c static int ns16550_serial_getinfo(struct udevice *dev, · line 481

Quoted 3 lines
drivers/serial/ns16550.c +0 -0
        return 0;
 }

applied to u-boot-x86, thanks!

#7 lore raw

PATCH 3/3 x86: acpi: Let OS know that console already had been initialized

In reply to Bin Meng
Quoted 13 lines · Bin Meng
Quoted 10 lines · Andy Shevchenko

SPCR has no clue if the UART base clock speed is different to the default one. However, the SPCR 1.04 defines baud rate 0 as a preconfigured state of UART and OS is supposed not to touch the configuration of the serial device.

Linux kernel supports that starting from v5.0, see commit b413b1abeb21 ("ACPI: SPCR: Consider baud rate 0 as preconfigured state") for the details.

Quoted 7 lines
Quoted 5 lines
---
 arch/x86/lib/acpi_table.c | 9 +++++++++
 1 file changed, 9 insertions(+)

applied to u-boot-x86, thanks!