Skip to contentSkip to conversation

arm: ls1021atwr: Convert to driver model and enable serial support

PATCH New Bin Meng 6 participants 41 messages Dec 31, 2015 – Jan 14, 2016 Arm (32-bit)

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

This series converts Freescale LS1021A-TWR board to driver model.
- Enable ns16550 serial driver on ls1021atwr_nor configuration
- Convert LPUART serial driver to driver model
- Enable LPUART serial driver on ls1021atwr_nor_lpuart configuration

Bin Meng (8):
fdt: Fix up stdout correctly in fdt_fixup_stdout()
arm: ls1021atwr: Convert to driver model and enable serial support
serial: lpuart: Move CONFIG_FSL_LPUART to Kconfig
serial: lpuart: Fix several cosmetic issues
serial: lpuart: Call local version of setbrg and putc directly
serial: lpuart: Prepare the driver for DM conversion
serial: lpuart: Add driver model serial support
arm: ls1021atwr: Enable driver model lpuart serial driver

 arch/arm/dts/ls1021a-twr.dts                 |   8 +
 arch/arm/dts/ls1021a.dtsi                    |   4 -
 common/fdt_support.c                         |  16 +-
 configs/colibri_vf_defconfig                 |   1 +
 configs/colibri_vf_dtb_defconfig             |   1 +
 configs/ls1021aqds_ddr4_nor_lpuart_defconfig |   1 +
 configs/ls1021aqds_nor_lpuart_defconfig      |   1 +
 configs/ls1021atwr_nor_defconfig             |   4 +
 configs/ls1021atwr_nor_lpuart_defconfig      |   5 +
 configs/pcm052_defconfig                     |   1 +
 configs/vf610twr_defconfig                   |   1 +
 configs/vf610twr_nand_defconfig              |   1 +
 doc/driver-model/serial-howto.txt            |   1 -
 drivers/serial/Kconfig                       |   6 +
 drivers/serial/serial_lpuart.c               | 334 +++++++++++++++++++++------
 include/configs/colibri_vf.h                 |   1 -
 include/configs/ls1021aqds.h                 |   1 -
 include/configs/ls1021atwr.h                 |   3 +-
 include/configs/pcm052.h                     |   1 -
 include/configs/vf610twr.h                   |   1 -
 20 files changed, 298 insertions(+), 94 deletions(-)
Signature · 1 line
1.8.2.1
author
#1 lore raw

PATCH 1/8 fdt: Fix up stdout correctly in fdt_fixup_stdout()

When CONFIG_OF_STDOUT_VIA_ALIAS is on, always fix up kernel's stdout string with hardcoded CONFIG_CONS_INDEX.

This actually reverts commit 3e303f748cf57fb23e8ec95ab7eac0074be50e2b "fdt_support: Add multi-serial support for stdout fixup", as the fix up in the /aliases node did not work under the following scenarios:
- Not every non-DM serial driver was written to have a driver name that conforms the format of "serial%d" or "eserial%d".
- With driver model serial, the stdio_devices[] stores the serial device node name in the device tree.

---

 common/fdt_support.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
common/fdt_support.c +1 -15
index 66464db..4ce17d4 100644
@@ -131,18 +131,6 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
 			      OF_STDOUT_PATH, strlen(OF_STDOUT_PATH) + 1);
 }
 #elif defined(CONFIG_OF_STDOUT_VIA_ALIAS) && defined(CONFIG_CONS_INDEX)
-static void fdt_fill_multisername(char *sername, size_t maxlen)
-{
-	const char *outname = stdio_devices[stdout]->name;
-
-	if (strcmp(outname, "serial") > 0)
-		strncpy(sername, outname, maxlen);
-
-	/* eserial? */
-	if (strcmp(outname + 1, "serial") > 0)
-		strncpy(sername, outname + 1, maxlen);
-}
-
 static int fdt_fixup_stdout(void *fdt, int chosenoff)
 {
 	int err;
@@ -152,9 +140,7 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
 	int len;
 	char tmp[256]; /* long enough */
 
-	fdt_fill_multisername(sername, sizeof(sername) - 1);
-	if (!sername[0])
-		sprintf(sername, "serial%d", CONFIG_CONS_INDEX - 1);
+	sprintf(sername, "serial%d", CONFIG_CONS_INDEX - 1);
 
 	aliasoff = fdt_path_offset(fdt, "/aliases");
 	if (aliasoff < 0) {
Signature · 1 line
1.8.2.1
#2 lore raw

PATCH 1/8 fdt: Fix up stdout correctly in fdt_fixup_stdout()

Hi Bin,

Quoted 5 lines · Bin Meng

When CONFIG_OF_STDOUT_VIA_ALIAS is on, always fix up kernel's stdout string with hardcoded CONFIG_CONS_INDEX.

This actually reverts commit 3e303f748cf57fb23e8ec95ab7eac0074be50e2b "fdt_support: Add multi-serial support for stdout fixup", as the fix

In that case, could this be a revert, created with 'git revert'?

Quoted 11 lines

up in the /aliases node did not work under the following scenarios:
- Not every non-DM serial driver was written to have a driver name that conforms the format of "serial%d" or "eserial%d".
- With driver model serial, the stdio_devices[] stores the serial device node name in the device tree.

---

 common/fdt_support.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

Regards,
Simon

author
#3 lore raw

PATCH 1/8 fdt: Fix up stdout correctly in fdt_fixup_stdout()

Hi Simon,

Quoted 10 lines · Simon Glass

Hi Bin,

Quoted 5 lines · Bin Meng

When CONFIG_OF_STDOUT_VIA_ALIAS is on, always fix up kernel's stdout string with hardcoded CONFIG_CONS_INDEX.

This actually reverts commit 3e303f748cf57fb23e8ec95ab7eac0074be50e2b "fdt_support: Add multi-serial support for stdout fixup", as the fix

In that case, could this be a revert, created with 'git revert'?

I've never used 'git revert' command. Did you mean this commit/patch should be recreated using 'git revert'? Does this matter?

Quoted 7 lines
Quoted 7 lines

up in the /aliases node did not work under the following scenarios:
- Not every non-DM serial driver was written to have a driver name that conforms the format of "serial%d" or "eserial%d".
- With driver model serial, the stdio_devices[] stores the serial device node name in the device tree.

Quoted 6 lines
Quoted 5 lines

---

 common/fdt_support.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

Regards,
Bin

#4 lore raw

PATCH 1/8 fdt: Fix up stdout correctly in fdt_fixup_stdout()

Hi Bin,

Quoted 9 lines · Bin Meng

Hi Simon,

Quoted 6 lines · Simon Glass

Hi Bin,

Quoted 3 lines · Bin Meng

When CONFIG_OF_STDOUT_VIA_ALIAS is on, always fix up kernel's stdout string with hardcoded CONFIG_CONS_INDEX.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This actually reverts commit 3e303f748cf57fb23e8ec95ab7eac0074be50e2b "fdt_support: Add multi-serial support for stdout fixup", as the fix

In that case, could this be a revert, created with 'git revert'?

I've never used 'git revert' command. Did you mean this commit/patch should be recreated using 'git revert'? Does this matter?

Well it creates a commit with a particular subject and format, which people are used to seeing for reverts. So if it is actually a revert, then yes I think you should use 'git revert'. You can edit the commit message to provide more detail.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

up in the /aliases node did not work under the following scenarios:
- Not every non-DM serial driver was written to have a driver name that conforms the format of "serial%d" or "eserial%d".
- With driver model serial, the stdio_devices[] stores the serial device node name in the device tree.

---

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
 common/fdt_support.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

Regards,
Bin

Regards,
Simon

author
#5 lore raw

PATCH 1/8 fdt: Fix up stdout correctly in fdt_fixup_stdout()

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Bin,

Quoted 14 lines · Bin Meng

Hi Simon,

Quoted 10 lines · Simon Glass

Hi Bin,

Quoted 5 lines · Bin Meng

When CONFIG_OF_STDOUT_VIA_ALIAS is on, always fix up kernel's stdout string with hardcoded CONFIG_CONS_INDEX.

This actually reverts commit 3e303f748cf57fb23e8ec95ab7eac0074be50e2b "fdt_support: Add multi-serial support for stdout fixup", as the fix

In that case, could this be a revert, created with 'git revert'?

Quoted 8 lines
Quoted 2 lines

I've never used 'git revert' command. Did you mean this commit/patch should be recreated using 'git revert'? Does this matter?

Well it creates a commit with a particular subject and format, which people are used to seeing for reverts. So if it is actually a revert, then yes I think you should use 'git revert'. You can edit the commit message to provide more detail.

When running 'git revert 3e303f748cf57fb23e8ec95ab7eac0074be50e2b', I got:

error: could not revert 3e303f7... fdt_support: Add multi-serial support for stdout fixup
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

Looks it cannot be reverted cleanly using 'git revert' command. What's the best practice here?

Regards,
Bin

#6 lore raw

PATCH 1/8 fdt: Fix up stdout correctly in fdt_fixup_stdout()

Hi Bin,

Quoted 31 lines · Bin Meng

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Bin,

Quoted 14 lines · Bin Meng

Hi Simon,

Quoted 10 lines · Simon Glass

Hi Bin,

Quoted 5 lines · Bin Meng

When CONFIG_OF_STDOUT_VIA_ALIAS is on, always fix up kernel's stdout string with hardcoded CONFIG_CONS_INDEX.

This actually reverts commit 3e303f748cf57fb23e8ec95ab7eac0074be50e2b "fdt_support: Add multi-serial support for stdout fixup", as the fix

In that case, could this be a revert, created with 'git revert'?

Quoted 8 lines
Quoted 2 lines

I've never used 'git revert' command. Did you mean this commit/patch should be recreated using 'git revert'? Does this matter?

Well it creates a commit with a particular subject and format, which people are used to seeing for reverts. So if it is actually a revert, then yes I think you should use 'git revert'. You can edit the commit message to provide more detail.

When running 'git revert 3e303f748cf57fb23e8ec95ab7eac0074be50e2b', I got:

Quoted 8 lines

error: could not revert 3e303f7... fdt_support: Add multi-serial support for stdout fixup
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

Looks it cannot be reverted cleanly using 'git revert' command. What's the best practice here?

I suggest using your original patch and updating the commit subject and message to better match the output of 'git revert'. You can 'git revert HEAD' to an example of see this.

Regards,
Simon

author
#7 lore raw

PATCH 2/8 arm: ls1021atwr: Convert to driver model and enable serial support

In reply to Bin Meng

Convert ls1021atwr_nor to driver model support. As a start, enable ns16550 serial port driver.

---

 arch/arm/dts/ls1021a-twr.dts     | 4 ++++
 arch/arm/dts/ls1021a.dtsi        | 4 ----
 configs/ls1021atwr_nor_defconfig | 4 ++++
 include/configs/ls1021atwr.h     | 2 ++
 4 files changed, 10 insertions(+), 4 deletions(-)
arch/arm/dts/ls1021a-twr.dts +4 -0
index 6ccd332..aead13f 100644
@@ -19,6 +19,10 @@
 		spi0 = &qspi;
 		spi1 = &dspi1;
 	};
+
+	chosen {
+		stdout-path = &uart0;
+	};
 };
 
 &qspi {
arch/arm/dts/ls1021a.dtsi +0 -4
index 7fadd7c..ee0e554 100644
@@ -218,7 +218,6 @@
 			compatible = "fsl,16550-FIFO64", "ns16550a";
 			reg = <0x21c0500 0x100>;
 			interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;
-			clock-frequency = <0>;
 			fifo-size = <15>;
 			status = "disabled";
 		};
@@ -227,7 +226,6 @@
 			compatible = "fsl,16550-FIFO64", "ns16550a";
 			reg = <0x21c0600 0x100>;
 			interrupts = <GIC_SPI 86 IRQ_TYPE_LEVEL_HIGH>;
-			clock-frequency = <0>;
 			fifo-size = <15>;
 			status = "disabled";
 		};
@@ -236,7 +234,6 @@
 			compatible = "fsl,16550-FIFO64", "ns16550a";
 			reg = <0x21d0500 0x100>;
 			interrupts = <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>;
-			clock-frequency = <0>;
 			fifo-size = <15>;
 			status = "disabled";
 		};
@@ -245,7 +242,6 @@
 			compatible = "fsl,16550-FIFO64", "ns16550a";
 			reg = <0x21d0600 0x100>;
 			interrupts = <GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>;
-			clock-frequency = <0>;
 			fifo-size = <15>;
 			status = "disabled";
 		};
configs/ls1021atwr_nor_defconfig +4 -0
index aa874fd..2b79443 100644
@@ -1,6 +1,10 @@
 CONFIG_ARM=y
 CONFIG_TARGET_LS1021ATWR=y
+CONFIG_DM_SERIAL=y
+CONFIG_DEFAULT_DEVICE_TREE="ls1021a-twr"
 # CONFIG_CMD_SETEXPR is not set
+CONFIG_OF_CONTROL=y
+CONFIG_DM=y
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
 CONFIG_SYS_NS16550=y
include/configs/ls1021atwr.h +2 -0
index c12ba3a..bbef2a7 100644
@@ -271,7 +271,9 @@
 #else
 #define CONFIG_CONS_INDEX		1
 #define CONFIG_SYS_NS16550_SERIAL
+#ifndef CONFIG_DM_SERIAL
 #define CONFIG_SYS_NS16550_REG_SIZE	1
+#endif
 #define CONFIG_SYS_NS16550_CLK		get_serial_clock()
 #endif
 
Signature · 1 line
1.8.2.1
author
#8 lore raw

PATCH 3/8 serial: lpuart: Move CONFIG_FSL_LPUART to Kconfig

In reply to Bin Meng

LPUART is seen on Freescale VF610 and QorIQ Layerscape devices. Create a Kconfig option and move it to defconfig for all boards that have this serial driver.

---

 configs/colibri_vf_defconfig                 | 1 +
 configs/colibri_vf_dtb_defconfig             | 1 +
 configs/ls1021aqds_ddr4_nor_lpuart_defconfig | 1 +
 configs/ls1021aqds_nor_lpuart_defconfig      | 1 +
 configs/ls1021atwr_nor_lpuart_defconfig      | 1 +
 configs/pcm052_defconfig                     | 1 +
 configs/vf610twr_defconfig                   | 1 +
 configs/vf610twr_nand_defconfig              | 1 +
 drivers/serial/Kconfig                       | 6 ++++++
 include/configs/colibri_vf.h                 | 1 -
 include/configs/ls1021aqds.h                 | 1 -
 include/configs/ls1021atwr.h                 | 1 -
 include/configs/pcm052.h                     | 1 -
 include/configs/vf610twr.h                   | 1 -
 14 files changed, 14 insertions(+), 5 deletions(-)
configs/colibri_vf_defconfig +1 -0
index f8441e3..45917c8 100644
@@ -8,3 +8,4 @@ CONFIG_CMD_GPIO=y
 CONFIG_DM=y
 CONFIG_NAND_VF610_NFC=y
 CONFIG_SYS_NAND_VF610_NFC_60_ECC_BYTES=y
+CONFIG_FSL_LPUART=y
configs/colibri_vf_dtb_defconfig +1 -0
index 3596cec..b1a843a 100644
@@ -11,3 +11,4 @@ CONFIG_OF_CONTROL=y
 CONFIG_DM=y
 CONFIG_NAND_VF610_NFC=y
 CONFIG_SYS_NAND_VF610_NFC_60_ECC_BYTES=y
+CONFIG_FSL_LPUART=y
configs/ls1021aqds_ddr4_nor_lpuart_defconfig +1 -0
index 68bd117..44b2a0d 100644
@@ -4,3 +4,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SYS_FSL_DDR4,LPUART"
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
+CONFIG_FSL_LPUART=y
configs/ls1021aqds_nor_lpuart_defconfig +1 -0
index b2f6832..1186af2 100644
@@ -4,3 +4,4 @@ CONFIG_SYS_EXTRA_OPTIONS="LPUART"
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
+CONFIG_FSL_LPUART=y
configs/ls1021atwr_nor_lpuart_defconfig +1 -0
index d7afca9..58cd61f 100644
@@ -4,3 +4,4 @@ CONFIG_SYS_EXTRA_OPTIONS="LPUART"
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
+CONFIG_FSL_LPUART=y
configs/pcm052_defconfig +1 -0
index 9125645..26ab733 100644
@@ -3,3 +3,4 @@ CONFIG_TARGET_PCM052=y
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/phytec/pcm052/imximage.cfg,ENV_IS_IN_NAND"
 CONFIG_NAND_VF610_NFC=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
+CONFIG_FSL_LPUART=y
configs/vf610twr_defconfig +1 -0
index dc8df5c..d51c93b 100644
@@ -6,3 +6,4 @@ CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/vf610twr/imximage.cfg,ENV_I
 CONFIG_NAND_VF610_NFC=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_SPI_FLASH=y
+CONFIG_FSL_LPUART=y
configs/vf610twr_nand_defconfig +1 -0
index 98880f3..299fa8f 100644
@@ -6,3 +6,4 @@ CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/vf610twr/imximage.cfg,ENV_I
 CONFIG_NAND_VF610_NFC=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_SPI_FLASH=y
+CONFIG_FSL_LPUART=y
drivers/serial/Kconfig +6 -0
index 1fc287e..3b54511 100644
@@ -186,6 +186,12 @@ config ALTERA_UART
 	  Select this to enable an UART for Altera devices. Please find
 	  details on the "Embedded Peripherals IP User Guide" of Altera.
 
+config FSL_LPUART
+	bool "Freescale LPUART support"
+	help
+	  Select this to enable a Low Power UART for Freescale VF610 and
+	  QorIQ Layerscape devices.
+
 config SYS_NS16550
 	bool "NS16550 UART or compatible"
 	help
include/configs/colibri_vf.h +0 -1
index 708c79a..5aed3a5 100644
@@ -36,7 +36,6 @@
 
 #define CONFIG_BOARD_EARLY_INIT_F
 
-#define CONFIG_FSL_LPUART
 #define LPUART_BASE			UART0_BASE
 
 /* Allow to overwrite serial and ethaddr */
include/configs/ls1021aqds.h +0 -1
index 2e8dbc7..e8b1eca 100644
@@ -371,7 +371,6 @@ unsigned long get_board_ddr_clk(void);
  * Serial Port
  */
 #ifdef CONFIG_LPUART
-#define CONFIG_FSL_LPUART
 #define CONFIG_LPUART_32B_REG
 #else
 #define CONFIG_CONS_INDEX		1
include/configs/ls1021atwr.h +0 -1
index bbef2a7..317ba62 100644
@@ -266,7 +266,6 @@
  * Serial Port
  */
 #ifdef CONFIG_LPUART
-#define CONFIG_FSL_LPUART
 #define CONFIG_LPUART_32B_REG
 #else
 #define CONFIG_CONS_INDEX		1
include/configs/pcm052.h +0 -1
index b851bba..891bdb0 100644
@@ -27,7 +27,6 @@
 
 #define CONFIG_BOARD_EARLY_INIT_F
 
-#define CONFIG_FSL_LPUART
 #define LPUART_BASE			UART1_BASE
 
 /* Allow to overwrite serial and ethaddr */
include/configs/vf610twr.h +0 -1
index 34df6f0..dcfafaf 100644
@@ -34,7 +34,6 @@
 
 #define CONFIG_BOARD_EARLY_INIT_F
 
-#define CONFIG_FSL_LPUART
 #define LPUART_BASE			UART1_BASE
 
 /* Allow to overwrite serial and ethaddr */
Signature · 1 line
1.8.2.1
#9 lore raw

PATCH 3/8 serial: lpuart: Move CONFIG_FSL_LPUART to Kconfig

Quoted 7 lines · Bin Meng

LPUART is seen on Freescale VF610 and QorIQ Layerscape devices. Create a Kconfig option and move it to defconfig for all boards that have this serial driver.

---

Quoted 15 lines
 configs/colibri_vf_defconfig                 | 1 +
 configs/colibri_vf_dtb_defconfig             | 1 +
 configs/ls1021aqds_ddr4_nor_lpuart_defconfig | 1 +
 configs/ls1021aqds_nor_lpuart_defconfig      | 1 +
 configs/ls1021atwr_nor_lpuart_defconfig      | 1 +
 configs/pcm052_defconfig                     | 1 +
 configs/vf610twr_defconfig                   | 1 +
 configs/vf610twr_nand_defconfig              | 1 +
 drivers/serial/Kconfig                       | 6 ++++++
 include/configs/colibri_vf.h                 | 1 -
 include/configs/ls1021aqds.h                 | 1 -
 include/configs/ls1021atwr.h                 | 1 -
 include/configs/pcm052.h                     | 1 -
 include/configs/vf610twr.h                   | 1 -
 14 files changed, 14 insertions(+), 5 deletions(-)
#10 lore raw

PATCH 3/8 serial: lpuart: Move CONFIG_FSL_LPUART to Kconfig

In reply to Bin Meng

Hi Bin,

Quoted 7 lines · Bin Meng

LPUART is seen on Freescale VF610 and QorIQ Layerscape devices. Create a Kconfig option and move it to defconfig for all boards that have this serial driver.

---

Quoted 10 lines
 configs/colibri_vf_defconfig                 | 1 +
 configs/colibri_vf_dtb_defconfig             | 1 +
 configs/ls1021aqds_ddr4_nor_lpuart_defconfig | 1 +
 configs/ls1021aqds_nor_lpuart_defconfig      | 1 +
 configs/ls1021atwr_nor_lpuart_defconfig      | 1 +
 configs/pcm052_defconfig                     | 1 +
 configs/vf610twr_defconfig                   | 1 +
 configs/vf610twr_nand_defconfig              | 1 +
 drivers/serial/Kconfig                       | 6 ++++++
 include/configs/colibri_vf.h                 | 1 -

It would have been nice to CC the maintainers of these boards so they are aware of the change.

As Bhuvan pointed out, this patchset as is breaks colibri_vf_defconfig drivers/serial/serial_lpuart.c: In function ?lpuart_serial_tstc?:
drivers/serial/serial_lpuart.c:148:9: error: too few arguments to function ?_lpuart_serial_tstc?
return _lpuart_serial_tstc();

--
Stefan

Quoted 161 lines
 include/configs/ls1021aqds.h                 | 1 -
 include/configs/ls1021atwr.h                 | 1 -
 include/configs/pcm052.h                     | 1 -
 include/configs/vf610twr.h                   | 1 -
 14 files changed, 14 insertions(+), 5 deletions(-)
configs/colibri_vf_defconfig +1 -0
index f8441e3..45917c8 100644
@@ -8,3 +8,4 @@ CONFIG_CMD_GPIO=y
 CONFIG_DM=y
 CONFIG_NAND_VF610_NFC=y
 CONFIG_SYS_NAND_VF610_NFC_60_ECC_BYTES=y
+CONFIG_FSL_LPUART=y
configs/colibri_vf_dtb_defconfig +1 -0
index 3596cec..b1a843a 100644
@@ -11,3 +11,4 @@ CONFIG_OF_CONTROL=y
 CONFIG_DM=y
 CONFIG_NAND_VF610_NFC=y
 CONFIG_SYS_NAND_VF610_NFC_60_ECC_BYTES=y
+CONFIG_FSL_LPUART=y
configs/ls1021aqds_ddr4_nor_lpuart_defconfig +1 -0
index 68bd117..44b2a0d 100644
@@ -4,3 +4,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SYS_FSL_DDR4,LPUART"
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
+CONFIG_FSL_LPUART=y
configs/ls1021aqds_nor_lpuart_defconfig +1 -0
index b2f6832..1186af2 100644
@@ -4,3 +4,4 @@ CONFIG_SYS_EXTRA_OPTIONS="LPUART"
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
+CONFIG_FSL_LPUART=y
configs/ls1021atwr_nor_lpuart_defconfig +1 -0
index d7afca9..58cd61f 100644
@@ -4,3 +4,4 @@ CONFIG_SYS_EXTRA_OPTIONS="LPUART"
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
+CONFIG_FSL_LPUART=y
configs/pcm052_defconfig +0 -0
index 9125645..26ab733 100644
@@ -3,3 +3,4 @@ CONFIG_TARGET_PCM052=y
 

CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/phytec/pcm052/imximage.cfg,ENV_IS_IN_NAND"
CONFIG_NAND_VF610_NFC=y
CONFIG_SYS_NAND_BUSWIDTH_16BIT=y

configs/pcm052_defconfig +1 -0
+CONFIG_FSL_LPUART=y
configs/vf610twr_defconfig +0 -0
index dc8df5c..d51c93b 100644
@@ -6,3 +6,4 @@

CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/vf610twr/imximage.cfg,ENV_I
CONFIG_NAND_VF610_NFC=y
CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
CONFIG_SPI_FLASH=y

configs/vf610twr_defconfig +1 -0
+CONFIG_FSL_LPUART=y
configs/vf610twr_nand_defconfig +0 -0
index 98880f3..299fa8f 100644
@@ -6,3 +6,4 @@

CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/vf610twr/imximage.cfg,ENV_I
CONFIG_NAND_VF610_NFC=y
CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
CONFIG_SPI_FLASH=y

configs/vf610twr_nand_defconfig +1 -0
+CONFIG_FSL_LPUART=y
drivers/serial/Kconfig +6 -0
index 1fc287e..3b54511 100644
@@ -186,6 +186,12 @@ config ALTERA_UART
 	  Select this to enable an UART for Altera devices. Please find
 	  details on the "Embedded Peripherals IP User Guide" of Altera.
 
+config FSL_LPUART
+	bool "Freescale LPUART support"
+	help
+	  Select this to enable a Low Power UART for Freescale VF610 and
+	  QorIQ Layerscape devices.
+
 config SYS_NS16550
 	bool "NS16550 UART or compatible"
 	help
include/configs/colibri_vf.h +0 -1
index 708c79a..5aed3a5 100644
@@ -36,7 +36,6 @@
 
 #define CONFIG_BOARD_EARLY_INIT_F
 
-#define CONFIG_FSL_LPUART
 #define LPUART_BASE			UART0_BASE
 
 /* Allow to overwrite serial and ethaddr */
include/configs/ls1021aqds.h +0 -1
index 2e8dbc7..e8b1eca 100644
@@ -371,7 +371,6 @@ unsigned long get_board_ddr_clk(void);
  * Serial Port
  */
 #ifdef CONFIG_LPUART
-#define CONFIG_FSL_LPUART
 #define CONFIG_LPUART_32B_REG
 #else
 #define CONFIG_CONS_INDEX		1
include/configs/ls1021atwr.h +0 -1
index bbef2a7..317ba62 100644
@@ -266,7 +266,6 @@
  * Serial Port
  */
 #ifdef CONFIG_LPUART
-#define CONFIG_FSL_LPUART
 #define CONFIG_LPUART_32B_REG
 #else
 #define CONFIG_CONS_INDEX		1
include/configs/pcm052.h +0 -1
index b851bba..891bdb0 100644
@@ -27,7 +27,6 @@
 
 #define CONFIG_BOARD_EARLY_INIT_F
 
-#define CONFIG_FSL_LPUART
 #define LPUART_BASE			UART1_BASE
 
 /* Allow to overwrite serial and ethaddr */
include/configs/vf610twr.h +0 -1
index 34df6f0..dcfafaf 100644
@@ -34,7 +34,6 @@
 
 #define CONFIG_BOARD_EARLY_INIT_F
 
-#define CONFIG_FSL_LPUART
 #define LPUART_BASE			UART1_BASE
 
 /* Allow to overwrite serial and ethaddr */
author
#11 lore raw

PATCH 4/8 serial: lpuart: Fix several cosmetic issues

In reply to Bin Meng

Clean up the driver codes a little bit, by:
- Use tab instead of space in the macro defines
- Use single line comment whenever possible
- Fix insertion of blank lines

---

 drivers/serial/serial_lpuart.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
drivers/serial/serial_lpuart.c +15 -20
index 63fc388..ae47183 100644
@@ -12,15 +12,15 @@
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/clock.h>
 
-#define US1_TDRE        (1 << 7)
-#define US1_RDRF        (1 << 5)
-#define US1_OR          (1 << 3)
-#define UC2_TE          (1 << 3)
-#define UC2_RE          (1 << 2)
-#define CFIFO_TXFLUSH   (1 << 7)
-#define CFIFO_RXFLUSH   (1 << 6)
-#define SFIFO_RXOF      (1 << 2)
-#define SFIFO_RXUF      (1 << 0)
+#define US1_TDRE	(1 << 7)
+#define US1_RDRF	(1 << 5)
+#define US1_OR		(1 << 3)
+#define UC2_TE		(1 << 3)
+#define UC2_RE		(1 << 2)
+#define CFIFO_TXFLUSH	(1 << 7)
+#define CFIFO_RXFLUSH	(1 << 6)
+#define SFIFO_RXOF	(1 << 2)
+#define SFIFO_RXUF	(1 << 0)
 
 #define STAT_LBKDIF	(1 << 31)
 #define STAT_RXEDGIF	(1 << 30)
@@ -34,7 +34,7 @@
 #define STAT_MA1F	(1 << 15)
 #define STAT_MA2F	(1 << 14)
 #define STAT_FLAGS	(STAT_LBKDIF | STAT_RXEDGIF | STAT_IDLE | STAT_OR | \
-			STAT_NF | STAT_FE | STAT_PF | STAT_MA1F | STAT_MA2F)
+			 STAT_NF | STAT_FE | STAT_PF | STAT_MA1F | STAT_MA2F)
 
 #define CTRL_TE		(1 << 19)
 #define CTRL_RE		(1 << 18)
@@ -59,8 +59,8 @@ static void lpuart_serial_setbrg(void)
 		gd->baudrate = CONFIG_BAUDRATE;
 
 	sbr = (u16)(clk / (16 * gd->baudrate));
-	/* place adjustment later - n/32 BRFA */
 
+	/* place adjustment later - n/32 BRFA */
 	__raw_writeb(sbr >> 8, &base->ubdh);
 	__raw_writeb(sbr & 0xff, &base->ubdl);
 }
@@ -86,9 +86,7 @@ static void lpuart_serial_putc(const char c)
 	__raw_writeb(c, &base->ud);
 }
 
-/*
- * Test whether a character is in the RX buffer
- */
+/* Test whether a character is in the RX buffer */
 static int lpuart_serial_tstc(void)
 {
 	if (__raw_readb(&base->urcfifo) == 0)
@@ -120,7 +118,6 @@ static int lpuart_serial_init(void)
 	__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
 
 	/* provide data bits, parity, stop bit, etc */
-
 	serial_setbrg();
 
 	__raw_writeb(UC2_RE | UC2_TE, &base->uc2);
@@ -148,8 +145,8 @@ static void lpuart32_serial_setbrg(void)
 		gd->baudrate = CONFIG_BAUDRATE;
 
 	sbr = (clk / (16 * gd->baudrate));
-	/* place adjustment later - n/32 BRFA */
 
+	/* place adjustment later - n/32 BRFA */
 	out_be32(&base->baud, sbr);
 }
 
@@ -176,9 +173,7 @@ static void lpuart32_serial_putc(const char c)
 	out_be32(&base->data, c);
 }
 
-/*
- * Test whether a character is in the RX buffer
- */
+/* Test whether a character is in the RX buffer */
 static int lpuart32_serial_tstc(void)
 {
 	if ((in_be32(&base->water) >> 24) == 0)
@@ -204,8 +199,8 @@ static int lpuart32_serial_init(void)
 	out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE));
 
 	out_be32(&base->match, 0);
-	/* provide data bits, parity, stop bit, etc */
 
+	/* provide data bits, parity, stop bit, etc */
 	serial_setbrg();
 
 	out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
Signature · 1 line
1.8.2.1
#12 lore raw

PATCH 4/8 serial: lpuart: Fix several cosmetic issues

Quoted 10 lines · Bin Meng

Clean up the driver codes a little bit, by:
- Use tab instead of space in the macro defines
- Use single line comment whenever possible
- Fix insertion of blank lines

---

 drivers/serial/serial_lpuart.c | 35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)
author
#13 lore raw

PATCH 5/8 serial: lpuart: Call local version of setbrg and putc directly

In reply to Bin Meng

There is no need to go through serial driver subsystem, instead call the driver's setbrg and putc routines directly.

---

 drivers/serial/serial_lpuart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/serial/serial_lpuart.c +4 -4
index ae47183..0c0ab87 100644
@@ -78,7 +78,7 @@ static int lpuart_serial_getc(void)
 static void lpuart_serial_putc(const char c)
 {
 	if (c == '\n')
-		serial_putc('\r');
+		lpuart_serial_putc('\r');
 
 	while (!(__raw_readb(&base->us1) & US1_TDRE))
 		WATCHDOG_RESET();
@@ -118,7 +118,7 @@ static int lpuart_serial_init(void)
 	__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
 
 	/* provide data bits, parity, stop bit, etc */
-	serial_setbrg();
+	lpuart_serial_setbrg();
 
 	__raw_writeb(UC2_RE | UC2_TE, &base->uc2);
 
@@ -165,7 +165,7 @@ static int lpuart32_serial_getc(void)
 static void lpuart32_serial_putc(const char c)
 {
 	if (c == '\n')
-		serial_putc('\r');
+		lpuart32_serial_putc('\r');
 
 	while (!(in_be32(&base->stat) & STAT_TDRE))
 		WATCHDOG_RESET();
@@ -201,7 +201,7 @@ static int lpuart32_serial_init(void)
 	out_be32(&base->match, 0);
 
 	/* provide data bits, parity, stop bit, etc */
-	serial_setbrg();
+	lpuart32_serial_setbrg();
 
 	out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
 
Signature · 1 line
1.8.2.1
#14 lore raw

PATCH 5/8 serial: lpuart: Call local version of setbrg and putc directly

Quoted 8 lines · Bin Meng

There is no need to go through serial driver subsystem, instead call the driver's setbrg and putc routines directly.

---

 drivers/serial/serial_lpuart.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
author
#15 lore raw

PATCH 6/8 serial: lpuart: Prepare the driver for DM conversion

In reply to Bin Meng

Create internal routines which take lpuart's register base as a parameter, in preparation for driver model conversion.

---

 drivers/serial/serial_lpuart.c | 146 +++++++++++++++++++++++++++--------------
 1 file changed, 95 insertions(+), 51 deletions(-)
drivers/serial/serial_lpuart.c +95 -51
index 0c0ab87..fed83a6 100644
@@ -50,46 +50,43 @@ DECLARE_GLOBAL_DATA_PTR;
 struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
 
 #ifndef CONFIG_LPUART_32B_REG
-static void lpuart_serial_setbrg(void)
+static void _lpuart_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
 	u32 clk = mxc_get_clock(MXC_UART_CLK);
 	u16 sbr;
 
-	if (!gd->baudrate)
-		gd->baudrate = CONFIG_BAUDRATE;
-
-	sbr = (u16)(clk / (16 * gd->baudrate));
+	sbr = (u16)(clk / (16 * baudrate));
 
 	/* place adjustment later - n/32 BRFA */
-	__raw_writeb(sbr >> 8, &base->ubdh);
-	__raw_writeb(sbr & 0xff, &base->ubdl);
+	__raw_writeb(sbr >> 8, &reg->ubdh);
+	__raw_writeb(sbr & 0xff, &reg->ubdl);
 }
 
-static int lpuart_serial_getc(void)
+static int _lpuart_serial_getc(struct lpuart_fsl *reg)
 {
-	while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
+	while (!(__raw_readb(&reg->us1) & (US1_RDRF | US1_OR)))
 		WATCHDOG_RESET();
 
 	barrier();
 
-	return __raw_readb(&base->ud);
+	return __raw_readb(&reg->ud);
 }
 
-static void lpuart_serial_putc(const char c)
+static void _lpuart_serial_putc(struct lpuart_fsl *reg, const char c)
 {
 	if (c == '\n')
-		lpuart_serial_putc('\r');
+		_lpuart_serial_putc(reg, '\r');
 
-	while (!(__raw_readb(&base->us1) & US1_TDRE))
+	while (!(__raw_readb(&reg->us1) & US1_TDRE))
 		WATCHDOG_RESET();
 
-	__raw_writeb(c, &base->ud);
+	__raw_writeb(c, &reg->ud);
 }
 
 /* Test whether a character is in the RX buffer */
-static int lpuart_serial_tstc(void)
+static int _lpuart_serial_tstc(struct lpuart_fsl *reg)
 {
-	if (__raw_readb(&base->urcfifo) == 0)
+	if (__raw_readb(&reg->urcfifo) == 0)
 		return 0;
 
 	return 1;
@@ -99,32 +96,57 @@ static int lpuart_serial_tstc(void)
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  */
-static int lpuart_serial_init(void)
+static int _lpuart_serial_init(struct lpuart_fsl *reg)
 {
 	u8 ctrl;
 
-	ctrl = __raw_readb(&base->uc2);
+	ctrl = __raw_readb(&reg->uc2);
 	ctrl &= ~UC2_RE;
 	ctrl &= ~UC2_TE;
-	__raw_writeb(ctrl, &base->uc2);
+	__raw_writeb(ctrl, &reg->uc2);
 
-	__raw_writeb(0, &base->umodem);
-	__raw_writeb(0, &base->uc1);
+	__raw_writeb(0, &reg->umodem);
+	__raw_writeb(0, &reg->uc1);
 
 	/* Disable FIFO and flush buffer */
-	__raw_writeb(0x0, &base->upfifo);
-	__raw_writeb(0x0, &base->utwfifo);
-	__raw_writeb(0x1, &base->urwfifo);
-	__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
+	__raw_writeb(0x0, &reg->upfifo);
+	__raw_writeb(0x0, &reg->utwfifo);
+	__raw_writeb(0x1, &reg->urwfifo);
+	__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &reg->ucfifo);
 
 	/* provide data bits, parity, stop bit, etc */
-	lpuart_serial_setbrg();
+	_lpuart_serial_setbrg(reg, gd->baudrate);
 
-	__raw_writeb(UC2_RE | UC2_TE, &base->uc2);
+	__raw_writeb(UC2_RE | UC2_TE, &reg->uc2);
 
 	return 0;
 }
 
+static void lpuart_serial_setbrg(void)
+{
+	_lpuart_serial_setbrg(base, gd->baudrate);
+}
+
+static int lpuart_serial_getc(void)
+{
+	return _lpuart_serial_getc(base);
+}
+
+static void lpuart_serial_putc(const char c)
+{
+	_lpuart_serial_putc(base, c);
+}
+
+static int lpuart_serial_tstc(void)
+{
+	return _lpuart_serial_tstc();
+}
+
+static int lpuart_serial_init(void)
+{
+	return _lpuart_serial_init(base);
+}
+
 static struct serial_device lpuart_serial_drv = {
 	.name = "lpuart_serial",
 	.start = lpuart_serial_init,
@@ -136,47 +158,44 @@ static struct serial_device lpuart_serial_drv = {
 	.tstc = lpuart_serial_tstc,
 };
 #else
-static void lpuart32_serial_setbrg(void)
+static void _lpuart32_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
 	u32 clk = CONFIG_SYS_CLK_FREQ;
 	u32 sbr;
 
-	if (!gd->baudrate)
-		gd->baudrate = CONFIG_BAUDRATE;
-
-	sbr = (clk / (16 * gd->baudrate));
+	sbr = (clk / (16 * baudrate));
 
 	/* place adjustment later - n/32 BRFA */
-	out_be32(&base->baud, sbr);
+	out_be32(&reg->baud, sbr);
 }
 
-static int lpuart32_serial_getc(void)
+static int _lpuart32_serial_getc(struct lpuart_fsl *reg)
 {
 	u32 stat;
 
-	while (((stat = in_be32(&base->stat)) & STAT_RDRF) == 0) {
-		out_be32(&base->stat, STAT_FLAGS);
+	while (((stat = in_be32(&reg->stat)) & STAT_RDRF) == 0) {
+		out_be32(&reg->stat, STAT_FLAGS);
 		WATCHDOG_RESET();
 	}
 
-	return in_be32(&base->data) & 0x3ff;
+	return in_be32(&reg->data) & 0x3ff;
 }
 
-static void lpuart32_serial_putc(const char c)
+static void _lpuart32_serial_putc(struct lpuart_fsl *reg, const char c)
 {
 	if (c == '\n')
-		lpuart32_serial_putc('\r');
+		_lpuart32_serial_putc(reg, '\r');
 
-	while (!(in_be32(&base->stat) & STAT_TDRE))
+	while (!(in_be32(&reg->stat) & STAT_TDRE))
 		WATCHDOG_RESET();
 
-	out_be32(&base->data, c);
+	out_be32(&reg->data, c);
 }
 
 /* Test whether a character is in the RX buffer */
-static int lpuart32_serial_tstc(void)
+static int _lpuart32_serial_tstc(struct lpuart_fsl *reg)
 {
-	if ((in_be32(&base->water) >> 24) == 0)
+	if ((in_be32(&reg->water) >> 24) == 0)
 		return 0;
 
 	return 1;
@@ -186,28 +205,53 @@ static int lpuart32_serial_tstc(void)
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  */
-static int lpuart32_serial_init(void)
+static int _lpuart32_serial_init(struct lpuart_fsl *reg)
 {
 	u8 ctrl;
 
-	ctrl = in_be32(&base->ctrl);
+	ctrl = in_be32(&reg->ctrl);
 	ctrl &= ~CTRL_RE;
 	ctrl &= ~CTRL_TE;
-	out_be32(&base->ctrl, ctrl);
+	out_be32(&reg->ctrl, ctrl);
 
-	out_be32(&base->modir, 0);
-	out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE));
+	out_be32(&reg->modir, 0);
+	out_be32(&reg->fifo, ~(FIFO_TXFE | FIFO_RXFE));
 
-	out_be32(&base->match, 0);
+	out_be32(&reg->match, 0);
 
 	/* provide data bits, parity, stop bit, etc */
-	lpuart32_serial_setbrg();
+	_lpuart32_serial_setbrg(reg, gd->baudrate);
 
-	out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
+	out_be32(&reg->ctrl, CTRL_RE | CTRL_TE);
 
 	return 0;
 }
 
+static void lpuart32_serial_setbrg(void)
+{
+	_lpuart32_serial_setbrg(base, gd->baudrate);
+}
+
+static int lpuart32_serial_getc(void)
+{
+	return _lpuart32_serial_getc(base);
+}
+
+static void lpuart32_serial_putc(const char c)
+{
+	_lpuart32_serial_putc(base, c);
+}
+
+static int lpuart32_serial_tstc(void)
+{
+	return _lpuart32_serial_tstc(base);
+}
+
+static int lpuart32_serial_init(void)
+{
+	return _lpuart32_serial_init(base);
+}
+
 static struct serial_device lpuart32_serial_drv = {
 	.name = "lpuart32_serial",
 	.start = lpuart32_serial_init,
Signature · 1 line
1.8.2.1
#16 lore raw

PATCH 6/8 serial: lpuart: Prepare the driver for DM conversion

Quoted 8 lines · Bin Meng

Create internal routines which take lpuart's register base as a parameter, in preparation for driver model conversion.

---

 drivers/serial/serial_lpuart.c | 146 +++++++++++++++++++++++++++--------------
 1 file changed, 95 insertions(+), 51 deletions(-)
#17 lore raw

PATCH 6/8 serial: lpuart: Prepare the driver for DM conversion

In reply to Bin Meng
Quoted 74 lines · Bin Meng

Create internal routines which take lpuart's register base as a parameter, in preparation for driver model conversion.

---

 drivers/serial/serial_lpuart.c | 146 +++++++++++++++++++++++++++--------------
 1 file changed, 95 insertions(+), 51 deletions(-)
drivers/serial/serial_lpuart.c +13 -16
index 0c0ab87..fed83a6 100644
@@ -50,46 +50,43 @@ DECLARE_GLOBAL_DATA_PTR;
 struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
 
 #ifndef CONFIG_LPUART_32B_REG
-static void lpuart_serial_setbrg(void)
+static void _lpuart_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
 	u32 clk = mxc_get_clock(MXC_UART_CLK);
 	u16 sbr;
 
-	if (!gd->baudrate)
-		gd->baudrate = CONFIG_BAUDRATE;
-
-	sbr = (u16)(clk / (16 * gd->baudrate));
+	sbr = (u16)(clk / (16 * baudrate));
 
 	/* place adjustment later - n/32 BRFA */
-	__raw_writeb(sbr >> 8, &base->ubdh);
-	__raw_writeb(sbr & 0xff, &base->ubdl);
+	__raw_writeb(sbr >> 8, &reg->ubdh);
+	__raw_writeb(sbr & 0xff, &reg->ubdl);
 }
 
-static int lpuart_serial_getc(void)
+static int _lpuart_serial_getc(struct lpuart_fsl *reg)
 {
-	while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
+	while (!(__raw_readb(&reg->us1) & (US1_RDRF | US1_OR)))
 		WATCHDOG_RESET();
 
 	barrier();
 
-	return __raw_readb(&base->ud);
+	return __raw_readb(&reg->ud);
 }
 
-static void lpuart_serial_putc(const char c)
+static void _lpuart_serial_putc(struct lpuart_fsl *reg, const char c)
 {
 	if (c == '\n')
-		lpuart_serial_putc('\r');
+		_lpuart_serial_putc(reg, '\r');
 
-	while (!(__raw_readb(&base->us1) & US1_TDRE))
+	while (!(__raw_readb(&reg->us1) & US1_TDRE))
 		WATCHDOG_RESET();
 
-	__raw_writeb(c, &base->ud);
+	__raw_writeb(c, &reg->ud);
 }
 
 /* Test whether a character is in the RX buffer */
-static int lpuart_serial_tstc(void)
+static int _lpuart_serial_tstc(struct lpuart_fsl *reg)
 {
-	if (__raw_readb(&base->urcfifo) == 0)
+	if (__raw_readb(&reg->urcfifo) == 0)
 		return 0;
 
 	return 1;

drivers/serial/serial_lpuart.c static int lpuart_serial_tstc(void) · line 99

Quoted 5 lines
drivers/serial/serial_lpuart.c +1 -1
@@ -99,32 +96,57 @@ static int lpuart_serial_tstc(void)
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  */
-static int lpuart_serial_init(void)
+static int _lpuart_serial_init(struct lpuart_fsl *reg)

Couldn't you just name the parameter base and get rid of the changes below? IMHO, renaming variables is only really necessary if the current name is misleading, which I don't think it is...

Quoted 186 lines
drivers/serial/serial_lpuart.c +81 -34
 {
 	u8 ctrl;
 
-	ctrl = __raw_readb(&base->uc2);
+	ctrl = __raw_readb(&reg->uc2);
 	ctrl &= ~UC2_RE;
 	ctrl &= ~UC2_TE;
-	__raw_writeb(ctrl, &base->uc2);
+	__raw_writeb(ctrl, &reg->uc2);
 
-	__raw_writeb(0, &base->umodem);
-	__raw_writeb(0, &base->uc1);
+	__raw_writeb(0, &reg->umodem);
+	__raw_writeb(0, &reg->uc1);
 
 	/* Disable FIFO and flush buffer */
-	__raw_writeb(0x0, &base->upfifo);
-	__raw_writeb(0x0, &base->utwfifo);
-	__raw_writeb(0x1, &base->urwfifo);
-	__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
+	__raw_writeb(0x0, &reg->upfifo);
+	__raw_writeb(0x0, &reg->utwfifo);
+	__raw_writeb(0x1, &reg->urwfifo);
+	__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &reg->ucfifo);
 
 	/* provide data bits, parity, stop bit, etc */
-	lpuart_serial_setbrg();
+	_lpuart_serial_setbrg(reg, gd->baudrate);
 
-	__raw_writeb(UC2_RE | UC2_TE, &base->uc2);
+	__raw_writeb(UC2_RE | UC2_TE, &reg->uc2);
 
 	return 0;
 }
 
+static void lpuart_serial_setbrg(void)
+{
+	_lpuart_serial_setbrg(base, gd->baudrate);
+}
+
+static int lpuart_serial_getc(void)
+{
+	return _lpuart_serial_getc(base);
+}
+
+static void lpuart_serial_putc(const char c)
+{
+	_lpuart_serial_putc(base, c);
+}
+
+static int lpuart_serial_tstc(void)
+{
+	return _lpuart_serial_tstc();
+}
+
+static int lpuart_serial_init(void)
+{
+	return _lpuart_serial_init(base);
+}
+
 static struct serial_device lpuart_serial_drv = {
 	.name = "lpuart_serial",
 	.start = lpuart_serial_init,
@@ -136,47 +158,44 @@ static struct serial_device lpuart_serial_drv = {
 	.tstc = lpuart_serial_tstc,
 };
 #else
-static void lpuart32_serial_setbrg(void)
+static void _lpuart32_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
 	u32 clk = CONFIG_SYS_CLK_FREQ;
 	u32 sbr;
 
-	if (!gd->baudrate)
-		gd->baudrate = CONFIG_BAUDRATE;
-
-	sbr = (clk / (16 * gd->baudrate));
+	sbr = (clk / (16 * baudrate));
 
 	/* place adjustment later - n/32 BRFA */
-	out_be32(&base->baud, sbr);
+	out_be32(&reg->baud, sbr);
 }
 
-static int lpuart32_serial_getc(void)
+static int _lpuart32_serial_getc(struct lpuart_fsl *reg)
 {
 	u32 stat;
 
-	while (((stat = in_be32(&base->stat)) & STAT_RDRF) == 0) {
-		out_be32(&base->stat, STAT_FLAGS);
+	while (((stat = in_be32(&reg->stat)) & STAT_RDRF) == 0) {
+		out_be32(&reg->stat, STAT_FLAGS);
 		WATCHDOG_RESET();
 	}
 
-	return in_be32(&base->data) & 0x3ff;
+	return in_be32(&reg->data) & 0x3ff;
 }
 
-static void lpuart32_serial_putc(const char c)
+static void _lpuart32_serial_putc(struct lpuart_fsl *reg, const char c)
 {
 	if (c == '\n')
-		lpuart32_serial_putc('\r');
+		_lpuart32_serial_putc(reg, '\r');
 
-	while (!(in_be32(&base->stat) & STAT_TDRE))
+	while (!(in_be32(&reg->stat) & STAT_TDRE))
 		WATCHDOG_RESET();
 
-	out_be32(&base->data, c);
+	out_be32(&reg->data, c);
 }
 
 /* Test whether a character is in the RX buffer */
-static int lpuart32_serial_tstc(void)
+static int _lpuart32_serial_tstc(struct lpuart_fsl *reg)
 {
-	if ((in_be32(&base->water) >> 24) == 0)
+	if ((in_be32(&reg->water) >> 24) == 0)
 		return 0;
 
 	return 1;
@@ -186,28 +205,53 @@ static int lpuart32_serial_tstc(void)
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  */
-static int lpuart32_serial_init(void)
+static int _lpuart32_serial_init(struct lpuart_fsl *reg)
 {
 	u8 ctrl;
 
-	ctrl = in_be32(&base->ctrl);
+	ctrl = in_be32(&reg->ctrl);
 	ctrl &= ~CTRL_RE;
 	ctrl &= ~CTRL_TE;
-	out_be32(&base->ctrl, ctrl);
+	out_be32(&reg->ctrl, ctrl);
 
-	out_be32(&base->modir, 0);
-	out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE));
+	out_be32(&reg->modir, 0);
+	out_be32(&reg->fifo, ~(FIFO_TXFE | FIFO_RXFE));
 
-	out_be32(&base->match, 0);
+	out_be32(&reg->match, 0);
 
 	/* provide data bits, parity, stop bit, etc */
-	lpuart32_serial_setbrg();
+	_lpuart32_serial_setbrg(reg, gd->baudrate);
 
-	out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
+	out_be32(&reg->ctrl, CTRL_RE | CTRL_TE);
 
 	return 0;
 }
 
+static void lpuart32_serial_setbrg(void)
+{
+	_lpuart32_serial_setbrg(base, gd->baudrate);
+}
+
+static int lpuart32_serial_getc(void)
+{
+	return _lpuart32_serial_getc(base);
+}
+
+static void lpuart32_serial_putc(const char c)
+{
+	_lpuart32_serial_putc(base, c);
+}
+
+static int lpuart32_serial_tstc(void)
+{
+	return _lpuart32_serial_tstc(base);
+}
+
+static int lpuart32_serial_init(void)
+{
+	return _lpuart32_serial_init(base);
+}
+
 static struct serial_device lpuart32_serial_drv = {
 	.name = "lpuart32_serial",
 	.start = lpuart32_serial_init,
author
#18 lore raw

PATCH 6/8 serial: lpuart: Prepare the driver for DM conversion

Hi Stefan,

Quoted 73 lines · Stefan Agner
Quoted 72 lines · Bin Meng

Create internal routines which take lpuart's register base as a parameter, in preparation for driver model conversion.

---

 drivers/serial/serial_lpuart.c | 146 +++++++++++++++++++++++++++--------------
 1 file changed, 95 insertions(+), 51 deletions(-)
drivers/serial/serial_lpuart.c +13 -16
index 0c0ab87..fed83a6 100644
@@ -50,46 +50,43 @@ DECLARE_GLOBAL_DATA_PTR;
 struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
 
 #ifndef CONFIG_LPUART_32B_REG
-static void lpuart_serial_setbrg(void)
+static void _lpuart_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
      u32 clk = mxc_get_clock(MXC_UART_CLK);
      u16 sbr;
 
-     if (!gd->baudrate)
-             gd->baudrate = CONFIG_BAUDRATE;
-
-     sbr = (u16)(clk / (16 * gd->baudrate));
+     sbr = (u16)(clk / (16 * baudrate));
 
      /* place adjustment later - n/32 BRFA */
-     __raw_writeb(sbr >> 8, &base->ubdh);
-     __raw_writeb(sbr & 0xff, &base->ubdl);
+     __raw_writeb(sbr >> 8, &reg->ubdh);
+     __raw_writeb(sbr & 0xff, &reg->ubdl);
 }
 
-static int lpuart_serial_getc(void)
+static int _lpuart_serial_getc(struct lpuart_fsl *reg)
 {
-     while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
+     while (!(__raw_readb(&reg->us1) & (US1_RDRF | US1_OR)))
              WATCHDOG_RESET();
 
      barrier();
 
-     return __raw_readb(&base->ud);
+     return __raw_readb(&reg->ud);
 }
 
-static void lpuart_serial_putc(const char c)
+static void _lpuart_serial_putc(struct lpuart_fsl *reg, const char c)
 {
      if (c == '\n')
-             lpuart_serial_putc('\r');
+             _lpuart_serial_putc(reg, '\r');
 
-     while (!(__raw_readb(&base->us1) & US1_TDRE))
+     while (!(__raw_readb(&reg->us1) & US1_TDRE))
              WATCHDOG_RESET();
 
-     __raw_writeb(c, &base->ud);
+     __raw_writeb(c, &reg->ud);
 }
 
 /* Test whether a character is in the RX buffer */
-static int lpuart_serial_tstc(void)
+static int _lpuart_serial_tstc(struct lpuart_fsl *reg)
 {
-     if (__raw_readb(&base->urcfifo) == 0)
+     if (__raw_readb(&reg->urcfifo) == 0)
              return 0;
 
Quoted 12 lines

drivers/serial/serial_lpuart.c static int lpuart_serial_tstc(void) · line 99

Quoted 7 lines
drivers/serial/serial_lpuart.c +1 -1
      return 1;
@@ -99,32 +96,57 @@ static int lpuart_serial_tstc(void)
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  */
-static int lpuart_serial_init(void)
+static int _lpuart_serial_init(struct lpuart_fsl *reg)

Couldn't you just name the parameter base and get rid of the changes below? IMHO, renaming variables is only really necessary if the current name is misleading, which I don't think it is...

Will change 'reg' to 'base' in v2.

Quoted 178 lines
Quoted 178 lines
drivers/serial/serial_lpuart.c +76 -34
 {
      u8 ctrl;
 
-     ctrl = __raw_readb(&base->uc2);
+     ctrl = __raw_readb(&reg->uc2);
      ctrl &= ~UC2_RE;
      ctrl &= ~UC2_TE;
-     __raw_writeb(ctrl, &base->uc2);
+     __raw_writeb(ctrl, &reg->uc2);
 
-     __raw_writeb(0, &base->umodem);
-     __raw_writeb(0, &base->uc1);
+     __raw_writeb(0, &reg->umodem);
+     __raw_writeb(0, &reg->uc1);
 
      /* Disable FIFO and flush buffer */
-     __raw_writeb(0x0, &base->upfifo);
-     __raw_writeb(0x0, &base->utwfifo);
-     __raw_writeb(0x1, &base->urwfifo);
-     __raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
+     __raw_writeb(0x0, &reg->upfifo);
+     __raw_writeb(0x0, &reg->utwfifo);
+     __raw_writeb(0x1, &reg->urwfifo);
+     __raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &reg->ucfifo);
 
      /* provide data bits, parity, stop bit, etc */
-     lpuart_serial_setbrg();
+     _lpuart_serial_setbrg(reg, gd->baudrate);
 
-     __raw_writeb(UC2_RE | UC2_TE, &base->uc2);
+     __raw_writeb(UC2_RE | UC2_TE, &reg->uc2);
 
      return 0;
 }
 
+static void lpuart_serial_setbrg(void)
+{
+     _lpuart_serial_setbrg(base, gd->baudrate);
+}
+
+static int lpuart_serial_getc(void)
+{
+     return _lpuart_serial_getc(base);
+}
+
+static void lpuart_serial_putc(const char c)
+{
+     _lpuart_serial_putc(base, c);
+}
+
+static int lpuart_serial_tstc(void)
+{
+     return _lpuart_serial_tstc();
+}
+
+static int lpuart_serial_init(void)
+{
+     return _lpuart_serial_init(base);
+}
+
 static struct serial_device lpuart_serial_drv = {
      .name = "lpuart_serial",
      .start = lpuart_serial_init,
@@ -136,47 +158,44 @@ static struct serial_device lpuart_serial_drv = {
      .tstc = lpuart_serial_tstc,
 };
 #else
-static void lpuart32_serial_setbrg(void)
+static void _lpuart32_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
      u32 clk = CONFIG_SYS_CLK_FREQ;
      u32 sbr;
 
-     if (!gd->baudrate)
-             gd->baudrate = CONFIG_BAUDRATE;
-
-     sbr = (clk / (16 * gd->baudrate));
+     sbr = (clk / (16 * baudrate));
 
      /* place adjustment later - n/32 BRFA */
-     out_be32(&base->baud, sbr);
+     out_be32(&reg->baud, sbr);
 }
 
-static int lpuart32_serial_getc(void)
+static int _lpuart32_serial_getc(struct lpuart_fsl *reg)
 {
      u32 stat;
 
-     while (((stat = in_be32(&base->stat)) & STAT_RDRF) == 0) {
-             out_be32(&base->stat, STAT_FLAGS);
+     while (((stat = in_be32(&reg->stat)) & STAT_RDRF) == 0) {
+             out_be32(&reg->stat, STAT_FLAGS);
              WATCHDOG_RESET();
      }
 
-     return in_be32(&base->data) & 0x3ff;
+     return in_be32(&reg->data) & 0x3ff;
 }
 
-static void lpuart32_serial_putc(const char c)
+static void _lpuart32_serial_putc(struct lpuart_fsl *reg, const char c)
 {
      if (c == '\n')
-             lpuart32_serial_putc('\r');
+             _lpuart32_serial_putc(reg, '\r');
 
-     while (!(in_be32(&base->stat) & STAT_TDRE))
+     while (!(in_be32(&reg->stat) & STAT_TDRE))
              WATCHDOG_RESET();
 
-     out_be32(&base->data, c);
+     out_be32(&reg->data, c);
 }
 
 /* Test whether a character is in the RX buffer */
-static int lpuart32_serial_tstc(void)
+static int _lpuart32_serial_tstc(struct lpuart_fsl *reg)
 {
-     if ((in_be32(&base->water) >> 24) == 0)
+     if ((in_be32(&reg->water) >> 24) == 0)
              return 0;
 
      return 1;
@@ -186,28 +205,53 @@ static int lpuart32_serial_tstc(void)
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  */
-static int lpuart32_serial_init(void)
+static int _lpuart32_serial_init(struct lpuart_fsl *reg)
 {
      u8 ctrl;
 
-     ctrl = in_be32(&base->ctrl);
+     ctrl = in_be32(&reg->ctrl);
      ctrl &= ~CTRL_RE;
      ctrl &= ~CTRL_TE;
-     out_be32(&base->ctrl, ctrl);
+     out_be32(&reg->ctrl, ctrl);
 
-     out_be32(&base->modir, 0);
-     out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE));
+     out_be32(&reg->modir, 0);
+     out_be32(&reg->fifo, ~(FIFO_TXFE | FIFO_RXFE));
 
-     out_be32(&base->match, 0);
+     out_be32(&reg->match, 0);
 
      /* provide data bits, parity, stop bit, etc */
-     lpuart32_serial_setbrg();
+     _lpuart32_serial_setbrg(reg, gd->baudrate);
 
-     out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
+     out_be32(&reg->ctrl, CTRL_RE | CTRL_TE);
 
      return 0;
 }
 
+static void lpuart32_serial_setbrg(void)
+{
+     _lpuart32_serial_setbrg(base, gd->baudrate);
+}
+
+static int lpuart32_serial_getc(void)
+{
+     return _lpuart32_serial_getc(base);
+}
+
+static void lpuart32_serial_putc(const char c)
+{
+     _lpuart32_serial_putc(base, c);
+}
+
+static int lpuart32_serial_tstc(void)
+{
+     return _lpuart32_serial_tstc(base);
+}
+
Quoted 8 lines

drivers/serial/serial_lpuart.c static int lpuart32_serial_tstc(void) · line 257

Quoted 8 lines
drivers/serial/serial_lpuart.c +5 -0
+static int lpuart32_serial_init(void)
+{
+     return _lpuart32_serial_init(base);
+}
+
 static struct serial_device lpuart32_serial_drv = {
      .name = "lpuart32_serial",
      .start = lpuart32_serial_init,

Regards,
Bin

author
#19 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

In reply to Bin Meng

This adds driver model support to lpuart serial driver.

---

 doc/driver-model/serial-howto.txt |   1 -
 drivers/serial/serial_lpuart.c    | 157 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 1 deletion(-)
doc/driver-model/serial-howto.txt +0 -1
index 76ad629..b933836 100644
@@ -13,7 +13,6 @@ is time for maintainers to start converting over the remaining serial drivers:
    opencores_yanu.c
    serial_bfin.c
    serial_imx.c
-   serial_lpuart.c
    serial_max3100.c
    serial_pxa.c
    serial_s3c24x0.c
drivers/serial/serial_lpuart.c +157 -0

198 lines not on this page · raw message

Signature · 1 line
1.8.2.1
#20 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

Hi Bin,

Quoted 8 lines · Bin Meng

This adds driver model support to lpuart serial driver.

---

 doc/driver-model/serial-howto.txt |   1 -
 drivers/serial/serial_lpuart.c    | 157 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 1 deletion(-)

But please see below.

Quoted 194 lines
doc/driver-model/serial-howto.txt +0 -1
index 76ad629..b933836 100644
@@ -13,7 +13,6 @@ is time for maintainers to start converting over the remaining serial drivers:
    opencores_yanu.c
    serial_bfin.c
    serial_imx.c
-   serial_lpuart.c
    serial_max3100.c
    serial_pxa.c
    serial_s3c24x0.c
drivers/serial/serial_lpuart.c +129 -0
index fed83a6..b1ba1bc 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <watchdog.h>
 #include <asm/io.h>
 #include <serial.h>
@@ -49,6 +50,10 @@ DECLARE_GLOBAL_DATA_PTR;
 
 struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
 
+struct lpuart_serial_platdata {
+       struct lpuart_fsl *reg;
+};
+
 #ifndef CONFIG_LPUART_32B_REG
 static void _lpuart_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
@@ -122,6 +127,7 @@ static int _lpuart_serial_init(struct lpuart_fsl *reg)
        return 0;
 }
 
+#ifndef CONFIG_DM_SERIAL
 static void lpuart_serial_setbrg(void)
 {
        _lpuart_serial_setbrg(base, gd->baudrate);
@@ -157,6 +163,54 @@ static struct serial_device lpuart_serial_drv = {
        .getc = lpuart_serial_getc,
        .tstc = lpuart_serial_tstc,
 };
+#else /* CONFIG_DM_SERIAL */
+static int lpuart_serial_setbrg(struct udevice *dev, int baudrate)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart_serial_setbrg(reg, baudrate);
+
+       return 0;
+}
+
+static int lpuart_serial_getc(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart_serial_getc(reg);
+}
+
+static int lpuart_serial_putc(struct udevice *dev, const char c)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart_serial_putc(reg, c);
+
+       return 0;
+}
+
+static int lpuart_serial_pending(struct udevice *dev, bool input)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       if (input)
+               return _lpuart_serial_tstc(reg);
+       else
+               return __raw_readb(&reg->us1) & US1_TDRE ? 0 : 1;
+}
+
+static int lpuart_serial_probe(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart_serial_init(reg);
+}
+#endif /* CONFIG_DM_SERIAL */
 #else
 static void _lpuart32_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
@@ -227,6 +281,7 @@ static int _lpuart32_serial_init(struct lpuart_fsl *reg)
        return 0;
 }
 
+#ifndef CONFIG_DM_SERIAL
 static void lpuart32_serial_setbrg(void)
 {
        _lpuart32_serial_setbrg(base, gd->baudrate);
@@ -262,8 +317,57 @@ static struct serial_device lpuart32_serial_drv = {
        .getc = lpuart32_serial_getc,
        .tstc = lpuart32_serial_tstc,
 };
+#else /* CONFIG_DM_SERIAL */
+static int lpuart32_serial_setbrg(struct udevice *dev, int baudrate)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart32_serial_setbrg(reg, baudrate);
+
+       return 0;
+}
+
+static int lpuart32_serial_getc(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart32_serial_getc(reg);
+}
+
+static int lpuart32_serial_putc(struct udevice *dev, const char c)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart32_serial_putc(reg, c);
+
+       return 0;
+}
+
+static int lpuart32_serial_pending(struct udevice *dev, bool input)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       if (input)
+               return _lpuart32_serial_tstc(reg);
+       else
+               return in_be32(&reg->stat) & STAT_TDRE ? 0 : 1;
+}
+
+static int lpuart32_serial_probe(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart32_serial_init(reg);
+}
+#endif /* CONFIG_DM_SERIAL */
 #endif
 
+#ifndef CONFIG_DM_SERIAL
 void lpuart_serial_initialize(void)
 {
 #ifdef CONFIG_LPUART_32B_REG
@@ -281,3 +385,56 @@ __weak struct serial_device *default_serial_console(void)
        return &lpuart_serial_drv;
 #endif
 }
+#else /* CONFIG_DM_SERIAL */
+static int lpuart_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       fdt_addr_t addr;
+
+       addr = dev_get_addr(dev);
+       if (addr == FDT_ADDR_T_NONE)
+               return -EINVAL;
+
+       plat->reg = (struct lpuart_fsl *)addr;
+
+       return 0;
+}
+
+static const struct dm_serial_ops lpuart_serial_ops = {
+#ifdef CONFIG_LPUART_32B_REG
+       .putc = lpuart32_serial_putc,
+       .pending = lpuart32_serial_pending,
+       .getc = lpuart32_serial_getc,
+       .setbrg = lpuart32_serial_setbrg,
+#else
+       .putc = lpuart_serial_putc,
+       .pending = lpuart_serial_pending,
+       .getc = lpuart_serial_getc,

drivers/serial/serial_lpuart.c __weak struct serial_device *default_serial_console(void) · line 422

Quoted 10 lines
drivers/serial/serial_lpuart.c +10 -0
+       .setbrg = lpuart_serial_setbrg,
+#endif
+};
+
+static const struct udevice_id lpuart_serial_ids[] = {
+#ifdef CONFIG_LPUART_32B_REG
+       { .compatible = "fsl,ls1021a-lpuart" },
+#else
+       { .compatible = "fsl,vf610-lpuart" },
+#endif

Shouldn't we have both of these in there, with a .data member to distinguish between them? Or two separate U_BOOT_DRIVER() entries each with their own operations.

Quoted 19 lines
drivers/serial/serial_lpuart.c +18 -1
+       { }
+};
+
+U_BOOT_DRIVER(serial_lpuart) = {
+       .name   = "serial_lpuart",
+       .id     = UCLASS_SERIAL,
+       .of_match = lpuart_serial_ids,
+       .ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
+#ifdef CONFIG_LPUART_32B_REG
+       .probe = lpuart32_serial_probe,
+#else
+       .probe = lpuart_serial_probe,
+#endif
+       .ops    = &lpuart_serial_ops,
+       .flags = DM_FLAG_PRE_RELOC,
+};
+#endif /* CONFIG_DM_SERIAL */
--
Quoted 2 lines

1.8.2.1

Regards,
Simon

author
#21 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

Hi Simon,

Quoted 17 lines · Simon Glass

Hi Bin,

Quoted 8 lines · Bin Meng

This adds driver model support to lpuart serial driver.

---

 doc/driver-model/serial-howto.txt |   1 -
 drivers/serial/serial_lpuart.c    | 157 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 1 deletion(-)

But please see below.

Quoted 1 line

[snip]

Quoted 31 lines
Quoted 31 lines
drivers/serial/serial_lpuart.c +31 -0
+#else /* CONFIG_DM_SERIAL */
+static int lpuart_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       fdt_addr_t addr;
+
+       addr = dev_get_addr(dev);
+       if (addr == FDT_ADDR_T_NONE)
+               return -EINVAL;
+
+       plat->reg = (struct lpuart_fsl *)addr;
+
+       return 0;
+}
+
+static const struct dm_serial_ops lpuart_serial_ops = {
+#ifdef CONFIG_LPUART_32B_REG
+       .putc = lpuart32_serial_putc,
+       .pending = lpuart32_serial_pending,
+       .getc = lpuart32_serial_getc,
+       .setbrg = lpuart32_serial_setbrg,
+#else
+       .putc = lpuart_serial_putc,
+       .pending = lpuart_serial_pending,
+       .getc = lpuart_serial_getc,
+       .setbrg = lpuart_serial_setbrg,
+#endif
+};
+
+static const struct udevice_id lpuart_serial_ids[] = {
+#ifdef CONFIG_LPUART_32B_REG
Quoted 8 lines

drivers/serial/serial_lpuart.c __weak struct serial_device *default_serial_console(void) · line 422

Quoted 4 lines
drivers/serial/serial_lpuart.c +4 -0
+       { .compatible = "fsl,ls1021a-lpuart" },
+#else
+       { .compatible = "fsl,vf610-lpuart" },
+#endif

Shouldn't we have both of these in there, with a .data member to distinguish between them? Or two separate U_BOOT_DRIVER() entries each with their own operations.

Sure, will do in v2.

Quoted 12 lines
Quoted 12 lines
drivers/serial/serial_lpuart.c +11 -0
+       { }
+};
+
+U_BOOT_DRIVER(serial_lpuart) = {
+       .name   = "serial_lpuart",
+       .id     = UCLASS_SERIAL,
+       .of_match = lpuart_serial_ids,
+       .ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
+#ifdef CONFIG_LPUART_32B_REG
+       .probe = lpuart32_serial_probe,
Quoted 8 lines

drivers/serial/serial_lpuart.c __weak struct serial_device *default_serial_console(void)

Quoted 8 lines
drivers/serial/serial_lpuart.c +7 -1
+#else
+       .probe = lpuart_serial_probe,
+#endif
+       .ops    = &lpuart_serial_ops,
+       .flags = DM_FLAG_PRE_RELOC,
+};
+#endif /* CONFIG_DM_SERIAL */
--

Regards,
Bin

#22 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

In reply to Bin Meng

Hi Bin,

With reference to the discussion here[1].

Unfortunately the lpuart driver is now broken for legacy code and also the driver doesn't
work with serial driver model enabled on Toradex Colibri VF50/VF61, Freescale VF610twr
and Phytec pcm052 boards. Did some one tested this patchset on these boards ?

[1] http://lists.denx.de/pipermail/u-boot/2016-January/240781.html

Best regards,
Bhuvan

Quoted 237 lines · Bin Meng

This adds driver model support to lpuart serial driver.

---

 doc/driver-model/serial-howto.txt |   1 -
 drivers/serial/serial_lpuart.c    | 157 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 157 insertions(+), 1 deletion(-)
doc/driver-model/serial-howto.txt +0 -1
index 76ad629..b933836 100644
@@ -13,7 +13,6 @@ is time for maintainers to start converting over the remaining serial drivers:
    opencores_yanu.c
    serial_bfin.c
    serial_imx.c
-   serial_lpuart.c
    serial_max3100.c
    serial_pxa.c
    serial_s3c24x0.c
drivers/serial/serial_lpuart.c +157 -1
index fed83a6..b1ba1bc 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <watchdog.h>
 #include <asm/io.h>
 #include <serial.h>
@@ -49,6 +50,10 @@ DECLARE_GLOBAL_DATA_PTR;
 
 struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
 
+struct lpuart_serial_platdata {
+       struct lpuart_fsl *reg;
+};
+
 #ifndef CONFIG_LPUART_32B_REG
 static void _lpuart_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
@@ -122,6 +127,7 @@ static int _lpuart_serial_init(struct lpuart_fsl *reg)
        return 0;
 }
 
+#ifndef CONFIG_DM_SERIAL
 static void lpuart_serial_setbrg(void)
 {
        _lpuart_serial_setbrg(base, gd->baudrate);
@@ -157,6 +163,54 @@ static struct serial_device lpuart_serial_drv = {
        .getc = lpuart_serial_getc,
        .tstc = lpuart_serial_tstc,
 };
+#else /* CONFIG_DM_SERIAL */
+static int lpuart_serial_setbrg(struct udevice *dev, int baudrate)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart_serial_setbrg(reg, baudrate);
+
+       return 0;
+}
+
+static int lpuart_serial_getc(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart_serial_getc(reg);
+}
+
+static int lpuart_serial_putc(struct udevice *dev, const char c)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart_serial_putc(reg, c);
+
+       return 0;
+}
+
+static int lpuart_serial_pending(struct udevice *dev, bool input)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       if (input)
+               return _lpuart_serial_tstc(reg);
+       else
+               return __raw_readb(&reg->us1) & US1_TDRE ? 0 : 1;
+}
+
+static int lpuart_serial_probe(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart_serial_init(reg);
+}
+#endif /* CONFIG_DM_SERIAL */
 #else
 static void _lpuart32_serial_setbrg(struct lpuart_fsl *reg, int baudrate)
 {
@@ -227,6 +281,7 @@ static int _lpuart32_serial_init(struct lpuart_fsl *reg)
        return 0;
 }
 
+#ifndef CONFIG_DM_SERIAL
 static void lpuart32_serial_setbrg(void)
 {
        _lpuart32_serial_setbrg(base, gd->baudrate);
@@ -262,8 +317,57 @@ static struct serial_device lpuart32_serial_drv = {
        .getc = lpuart32_serial_getc,
        .tstc = lpuart32_serial_tstc,
 };
+#else /* CONFIG_DM_SERIAL */
+static int lpuart32_serial_setbrg(struct udevice *dev, int baudrate)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart32_serial_setbrg(reg, baudrate);
+
+       return 0;
+}
+
+static int lpuart32_serial_getc(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart32_serial_getc(reg);
+}
+
+static int lpuart32_serial_putc(struct udevice *dev, const char c)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       _lpuart32_serial_putc(reg, c);
+
+       return 0;
+}
+
+static int lpuart32_serial_pending(struct udevice *dev, bool input)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       if (input)
+               return _lpuart32_serial_tstc(reg);
+       else
+               return in_be32(&reg->stat) & STAT_TDRE ? 0 : 1;
+}
+
+static int lpuart32_serial_probe(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       struct lpuart_fsl *reg = plat->reg;
+
+       return _lpuart32_serial_init(reg);
+}
+#endif /* CONFIG_DM_SERIAL */
 #endif
 
+#ifndef CONFIG_DM_SERIAL
 void lpuart_serial_initialize(void)
 {
 #ifdef CONFIG_LPUART_32B_REG
@@ -281,3 +385,56 @@ __weak struct serial_device *default_serial_console(void)
        return &lpuart_serial_drv;
 #endif
 }
+#else /* CONFIG_DM_SERIAL */
+static int lpuart_serial_ofdata_to_platdata(struct udevice *dev)
+{
+       struct lpuart_serial_platdata *plat = dev->platdata;
+       fdt_addr_t addr;
+
+       addr = dev_get_addr(dev);
+       if (addr == FDT_ADDR_T_NONE)
+               return -EINVAL;
+
+       plat->reg = (struct lpuart_fsl *)addr;
+
+       return 0;
+}
+
+static const struct dm_serial_ops lpuart_serial_ops = {
+#ifdef CONFIG_LPUART_32B_REG
+       .putc = lpuart32_serial_putc,
+       .pending = lpuart32_serial_pending,
+       .getc = lpuart32_serial_getc,
+       .setbrg = lpuart32_serial_setbrg,
+#else
+       .putc = lpuart_serial_putc,
+       .pending = lpuart_serial_pending,
+       .getc = lpuart_serial_getc,
+       .setbrg = lpuart_serial_setbrg,
+#endif
+};
+
+static const struct udevice_id lpuart_serial_ids[] = {
+#ifdef CONFIG_LPUART_32B_REG
+       { .compatible = "fsl,ls1021a-lpuart" },
+#else
+       { .compatible = "fsl,vf610-lpuart" },
+#endif
+       { }
+};
+
+U_BOOT_DRIVER(serial_lpuart) = {
+       .name   = "serial_lpuart",
+       .id     = UCLASS_SERIAL,
+       .of_match = lpuart_serial_ids,
+       .ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
+       .platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
+#ifdef CONFIG_LPUART_32B_REG
+       .probe = lpuart32_serial_probe,
+#else
+       .probe = lpuart_serial_probe,
+#endif
+       .ops    = &lpuart_serial_ops,
+       .flags = DM_FLAG_PRE_RELOC,
+};
+#endif /* CONFIG_DM_SERIAL */
--

1.8.2.1

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

author
#23 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

Hi Bhuvan,

Quoted 9 lines · Bhuvanchandra DV

Hi Bin,

With reference to the discussion here[1].

Unfortunately the lpuart driver is now broken for legacy code and also the driver doesn't
work with serial driver model enabled on Toradex Colibri VF50/VF61, Freescale VF610twr
and Phytec pcm052 boards. Did some one tested this patchset on these boards ?

I will fix the legacy code build in v2. About serial driver model not working on these boards, is that the caused by no device tree of these boards?

Quoted 6 lines

[1] http://lists.denx.de/pipermail/u-boot/2016-January/240781.html

Best regards,
Bhuvan

Regards,
Bin

#24 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

Hi Bin,

Quoted 14 lines · Bin Meng

Hi Bhuvan,

Quoted 9 lines · Bhuvanchandra DV

Hi Bin,

With reference to the discussion here[1].

Unfortunately the lpuart driver is now broken for legacy code and also the driver doesn't
work with serial driver model enabled on Toradex Colibri VF50/VF61, Freescale VF610twr
and Phytec pcm052 boards. Did some one tested this patchset on these boards ?

Quoted 3 lines

I will fix the legacy code build in v2. About serial driver model not working on these boards, is that the caused by no device tree of these boards?

Yes, i tested on Colibri VF50/VF61 with device tree and it works fine. I think it would be nice to have the support for both platform data and device tree so that we can use it with platform data via board files and device tree too.

Since only few boards are using lpuart driver we can update the driver completly to driver model, drop the legacy code and update the boards.

Quoted 15 lines
Quoted 7 lines

[1] http://lists.denx.de/pipermail/u-boot/2016-January/240781.html

Best regards,
Bhuvan

Regards,
Bin
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 2 lines
Best regards,
Bhuvan
author
#25 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

+Simon

Hi Bhuvan,

Quoted 21 lines · Bhuvanchandra DV

Hi Bin,

Quoted 18 lines · Bin Meng

Hi Bhuvan,

Quoted 11 lines · Bhuvanchandra DV

Hi Bin,

With reference to the discussion here[1].

Unfortunately the lpuart driver is now broken for legacy code and also the driver doesn't
work with serial driver model enabled on Toradex Colibri VF50/VF61, Freescale VF610twr
and Phytec pcm052 boards. Did some one tested this patchset on these boards ?

Quoted 6 lines
Quoted 3 lines

I will fix the legacy code build in v2. About serial driver model not working on these boards, is that the caused by no device tree of these boards?

Yes, i tested on Colibri VF50/VF61 with device tree and it works fine.

Great to know!

Quoted 3 lines

I think it would be nice to have the support for both platform data and device tree so that we can use it with platform data via board files and device tree too.

I believe we should introduce device tree support on these boards. The configuration data (like in your patches the reg base for LPUART) should really be put into device tree. I adapted the comments from platdata.h below:

31/**
32 * NOTE: Avoid using these except in extreme circumstances, where device tree 33 * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is 34 * available). U-Boot's driver model uses device tree for configuration. 35 */
36#define U_BOOT_DEVICE(__name) \
37 ll_entry_declare(struct driver_info, __name, driver_info)

Quoted 4 lines

Since only few boards are using lpuart driver we can update the driver completly to driver model, drop the legacy code and update the boards.

Since in my patches I only updated ls1021atwr board to use driver model serial, and I don't have those other boards (like Colibri VF50/VF61) to test this lpuart dm driver. I chose to leave the legacy codes there. On top of my series, you can prepare a patch to completely drop those legacy codes after you switch to use driver model lpuart driver on those boards in your series. Then we get a legacy-free driver for lpuart boards :)

Regards,
Bin

#26 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

Quoted 36 lines · Bin Meng

+Simon

Hi Bhuvan,

Quoted 21 lines · Bhuvanchandra DV

Hi Bin,

Quoted 18 lines · Bin Meng

Hi Bhuvan,

Quoted 11 lines · Bhuvanchandra DV

Hi Bin,

With reference to the discussion here[1].

Unfortunately the lpuart driver is now broken for legacy code and also the driver doesn't
work with serial driver model enabled on Toradex Colibri VF50/VF61, Freescale VF610twr
and Phytec pcm052 boards. Did some one tested this patchset on these boards ?

Quoted 6 lines
Quoted 3 lines

I will fix the legacy code build in v2. About serial driver model not working on these boards, is that the caused by no device tree of these boards?

Yes, i tested on Colibri VF50/VF61 with device tree and it works fine.

Great to know!

Quoted 8 lines
Quoted 3 lines

I think it would be nice to have the support for both platform data and device tree so that we can use it with platform data via board files and device tree too.

I believe we should introduce device tree support on these boards. The configuration data (like in your patches the reg base for LPUART) should really be put into device tree. I adapted the comments from platdata.h below:

Currently colibri_vf has both, a DT and a non-DT config. There has been only one driver (SPI I think?) which required DT so far, and since most user do not use that driver, we created two configs.

However, if something like UART requires DT, then we can as well drop the non-DT config for colibri_vf.

Quoted 9 lines

31/**
32 * NOTE: Avoid using these except in extreme circumstances, where device tree 33 * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is 34 * available). U-Boot's driver model uses device tree for configuration. 35 */
36#define U_BOOT_DEVICE(__name) \
37 ll_entry_declare(struct driver_info, __name, driver_info)

Since Vybrid has so large internal SRAM, there has been no need for SPL at all so far. Not sure about LS1021a/other LPUART SoCs...

Quoted 5 lines
Quoted 4 lines

Since only few boards are using lpuart driver we can update the driver completly to driver model, drop the legacy code and update the boards.

Quoted 7 lines

Since in my patches I only updated ls1021atwr board to use driver model serial, and I don't have those other boards (like Colibri VF50/VF61) to test this lpuart dm driver. I chose to leave the legacy codes there. On top of my series, you can prepare a patch to completely drop those legacy codes after you switch to use driver model lpuart driver on those boards in your series. Then we get a legacy-free driver for lpuart boards :)

I guess nobody has all this boards, we should nontheless try to find a solution for all of them.

I see three options:
- Leave legacy code and the other boards as is (pcm052/vf610twr)
- Drop legacy code, and add platform data support and the corresponding platform data for pcm052/vf610twr (in this case, we could also keep the colibri_vf non-DT config)
- Drop legacy code, add device tree for pcm052/vf610twr, extend colibri_vf device tree and drop non-DT config for colibri_vf.

I am inclined to say lets go for the pure DT solution, since that is where U-Boot is evolving to long term anyway. Not sure how much work is required to make that happen. I guess the lpuart only DT for pcm052/vf610twr should be fairly easy to create...?

Other opinions?

--
Stefan

author
#27 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

Hi Stefan,

Quoted 46 lines · Stefan Agner
Quoted 36 lines · Bin Meng

+Simon

Hi Bhuvan,

Quoted 21 lines · Bhuvanchandra DV

Hi Bin,

Quoted 18 lines · Bin Meng

Hi Bhuvan,

Quoted 11 lines · Bhuvanchandra DV

Hi Bin,

With reference to the discussion here[1].

Unfortunately the lpuart driver is now broken for legacy code and also the driver doesn't
work with serial driver model enabled on Toradex Colibri VF50/VF61, Freescale VF610twr
and Phytec pcm052 boards. Did some one tested this patchset on these boards ?

Quoted 6 lines
Quoted 3 lines

I will fix the legacy code build in v2. About serial driver model not working on these boards, is that the caused by no device tree of these boards?

Yes, i tested on Colibri VF50/VF61 with device tree and it works fine.

Great to know!

Quoted 8 lines
Quoted 3 lines

I think it would be nice to have the support for both platform data and device tree so that we can use it with platform data via board files and device tree too.

I believe we should introduce device tree support on these boards. The configuration data (like in your patches the reg base for LPUART) should really be put into device tree. I adapted the comments from platdata.h below:

Quoted 7 lines

Currently colibri_vf has both, a DT and a non-DT config. There has been only one driver (SPI I think?) which required DT so far, and since most user do not use that driver, we created two configs.

However, if something like UART requires DT, then we can as well drop the non-DT config for colibri_vf.

I vote for dropping the non-DT config.

Quoted 10 lines
Quoted 9 lines

31/**
32 * NOTE: Avoid using these except in extreme circumstances, where device tree 33 * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is 34 * available). U-Boot's driver model uses device tree for configuration. 35 */
36#define U_BOOT_DEVICE(__name) \
37 ll_entry_declare(struct driver_info, __name, driver_info)

Quoted 3 lines

Since Vybrid has so large internal SRAM, there has been no need for SPL at all so far. Not sure about LS1021a/other LPUART SoCs...

LS1021 has 128KB SRAM, and current lp1021atwr_nor_lpuart does not use SPL. It boots from NOR flash.

Quoted 24 lines
Quoted 5 lines
Quoted 4 lines

Since only few boards are using lpuart driver we can update the driver completly to driver model, drop the legacy code and update the boards.

Quoted 7 lines

Since in my patches I only updated ls1021atwr board to use driver model serial, and I don't have those other boards (like Colibri VF50/VF61) to test this lpuart dm driver. I chose to leave the legacy codes there. On top of my series, you can prepare a patch to completely drop those legacy codes after you switch to use driver model lpuart driver on those boards in your series. Then we get a legacy-free driver for lpuart boards :)

I guess nobody has all this boards, we should nontheless try to find a solution for all of them.

I see three options:
- Leave legacy code and the other boards as is (pcm052/vf610twr)
- Drop legacy code, and add platform data support and the corresponding platform data for pcm052/vf610twr (in this case, we could also keep the colibri_vf non-DT config)
- Drop legacy code, add device tree for pcm052/vf610twr, extend colibri_vf device tree and drop non-DT config for colibri_vf.

Quoted 8 lines

I am inclined to say lets go for the pure DT solution, since that is where U-Boot is evolving to long term anyway. Not sure how much work is required to make that happen. I guess the lpuart only DT for pcm052/vf610twr should be fairly easy to create...?

Other opinions?

--

I would go for option 3.

Regards,
Bin

#28 lore raw

PATCH 7/8 serial: lpuart: Add driver model serial support

Quoted 105 lines · Bin Meng

Hi Stefan,

Quoted 46 lines · Stefan Agner
Quoted 36 lines · Bin Meng

+Simon

Hi Bhuvan,

Quoted 21 lines · Bhuvanchandra DV

Hi Bin,

Quoted 18 lines · Bin Meng

Hi Bhuvan,

Quoted 11 lines · Bhuvanchandra DV

Hi Bin,

With reference to the discussion here[1].

Unfortunately the lpuart driver is now broken for legacy code and also the driver doesn't
work with serial driver model enabled on Toradex Colibri VF50/VF61, Freescale VF610twr
and Phytec pcm052 boards. Did some one tested this patchset on these boards ?

Quoted 6 lines
Quoted 3 lines

I will fix the legacy code build in v2. About serial driver model not working on these boards, is that the caused by no device tree of these boards?

Yes, i tested on Colibri VF50/VF61 with device tree and it works fine.

Great to know!

Quoted 8 lines
Quoted 3 lines

I think it would be nice to have the support for both platform data and device tree so that we can use it with platform data via board files and device tree too.

I believe we should introduce device tree support on these boards. The configuration data (like in your patches the reg base for LPUART) should really be put into device tree. I adapted the comments from platdata.h below:

Quoted 7 lines

Currently colibri_vf has both, a DT and a non-DT config. There has been only one driver (SPI I think?) which required DT so far, and since most user do not use that driver, we created two configs.

However, if something like UART requires DT, then we can as well drop the non-DT config for colibri_vf.

I vote for dropping the non-DT config.

Quoted 10 lines
Quoted 9 lines

31/**
32 * NOTE: Avoid using these except in extreme circumstances, where device tree 33 * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is 34 * available). U-Boot's driver model uses device tree for configuration. 35 */
36#define U_BOOT_DEVICE(__name) \
37 ll_entry_declare(struct driver_info, __name, driver_info)

Quoted 3 lines

Since Vybrid has so large internal SRAM, there has been no need for SPL at all so far. Not sure about LS1021a/other LPUART SoCs...

LS1021 has 128KB SRAM, and current lp1021atwr_nor_lpuart does not use SPL. It boots from NOR flash.

Quoted 29 lines
Quoted 5 lines
Quoted 4 lines

Since only few boards are using lpuart driver we can update the driver completly to driver model, drop the legacy code and update the boards.

Quoted 7 lines

Since in my patches I only updated ls1021atwr board to use driver model serial, and I don't have those other boards (like Colibri VF50/VF61) to test this lpuart dm driver. I chose to leave the legacy codes there. On top of my series, you can prepare a patch to completely drop those legacy codes after you switch to use driver model lpuart driver on those boards in your series. Then we get a legacy-free driver for lpuart boards :)

I guess nobody has all this boards, we should nontheless try to find a solution for all of them.

I see three options:
- Leave legacy code and the other boards as is (pcm052/vf610twr)
- Drop legacy code, and add platform data support and the corresponding platform data for pcm052/vf610twr (in this case, we could also keep the colibri_vf non-DT config)
- Drop legacy code, add device tree for pcm052/vf610twr, extend colibri_vf device tree and drop non-DT config for colibri_vf.

I am inclined to say lets go for the pure DT solution, since that is where U-Boot is evolving to long term anyway. Not sure how much work is required to make that happen. I guess the lpuart only DT for pcm052/vf610twr should be fairly easy to create...?

Quoted 5 lines
Quoted 3 lines

Other opinions?

--

I would go for option 3.

I too agree with Stefan and Bin for going with pure DT solution. Will do the device tree files for vf610-twr, pcm052 boards and extend Colibri-VFxx board with lpuart support. Will submit the new patchset after Bin's patchset upstreamed.

Quoted 4 lines

Regards,
Bin

Signature · 2 lines
Best regards,
Bhuvan
author
#29 lore raw

PATCH 8/8 arm: ls1021atwr: Enable driver model lpuart serial driver

In reply to Bin Meng

Convert ls1021atwr_nor_lpuart to driver model support. As a start, enable lpuart serial port driver.

---

 arch/arm/dts/ls1021a-twr.dts            | 4 ++++
 configs/ls1021atwr_nor_lpuart_defconfig | 4 ++++
 2 files changed, 8 insertions(+)
arch/arm/dts/ls1021a-twr.dts +4 -0
index aead13f..deabb12 100644
@@ -21,6 +21,10 @@
 	};
 
 	chosen {
+		/*
+		 * With ls1021atwr_nor_lpuart_defconfig configuration,
+		 * this needs to be changed to &lpuart0.
+		 */
 		stdout-path = &uart0;
 	};
 };
configs/ls1021atwr_nor_lpuart_defconfig +4 -0
index 58cd61f..5346359 100644
@@ -1,7 +1,11 @@
 CONFIG_ARM=y
 CONFIG_TARGET_LS1021ATWR=y
+CONFIG_DM_SERIAL=y
+CONFIG_DEFAULT_DEVICE_TREE="ls1021a-twr"
 CONFIG_SYS_EXTRA_OPTIONS="LPUART"
 # CONFIG_CMD_SETEXPR is not set
+CONFIG_OF_CONTROL=y
+CONFIG_DM=y
 CONFIG_NETDEVICES=y
 CONFIG_E1000=y
 CONFIG_FSL_LPUART=y
Signature · 1 line
1.8.2.1
#30 lore raw

PATCH 8/8 arm: ls1021atwr: Enable driver model lpuart serial driver

Quoted 10 lines · Bin Meng

Convert ls1021atwr_nor_lpuart to driver model support. As a start, enable lpuart serial port driver.

---

 arch/arm/dts/ls1021a-twr.dts            | 4 ++++
 configs/ls1021atwr_nor_lpuart_defconfig | 4 ++++
 2 files changed, 8 insertions(+)
#31 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

In reply to Bin Meng

Hi,

I tested this set on my LS1021ATWR board. NOR boot using DUART as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Best Regards,
Alison Wang

Quoted 48 lines

-----Original Message-----
From: Bin Meng [mailto:bmeng.cn at gmail.com]
Sent: Thursday, December 31, 2015 4:53 PM
To: Simon Glass; Yusong Sun; Alison Wang; U-Boot Mailing List
Subject: [PATCH 0/8] arm: ls1021atwr: Convert to driver model and enable serial support

This series converts Freescale LS1021A-TWR board to driver model.
- Enable ns16550 serial driver on ls1021atwr_nor configuration
- Convert LPUART serial driver to driver model
- Enable LPUART serial driver on ls1021atwr_nor_lpuart configuration

Bin Meng (8):
fdt: Fix up stdout correctly in fdt_fixup_stdout()
arm: ls1021atwr: Convert to driver model and enable serial support
serial: lpuart: Move CONFIG_FSL_LPUART to Kconfig
serial: lpuart: Fix several cosmetic issues
serial: lpuart: Call local version of setbrg and putc directly
serial: lpuart: Prepare the driver for DM conversion
serial: lpuart: Add driver model serial support
arm: ls1021atwr: Enable driver model lpuart serial driver

 arch/arm/dts/ls1021a-twr.dts                 |   8 +
 arch/arm/dts/ls1021a.dtsi                    |   4 -
 common/fdt_support.c                         |  16 +-
 configs/colibri_vf_defconfig                 |   1 +
 configs/colibri_vf_dtb_defconfig             |   1 +
 configs/ls1021aqds_ddr4_nor_lpuart_defconfig |   1 +
 configs/ls1021aqds_nor_lpuart_defconfig      |   1 +
 configs/ls1021atwr_nor_defconfig             |   4 +
 configs/ls1021atwr_nor_lpuart_defconfig      |   5 +
 configs/pcm052_defconfig                     |   1 +
 configs/vf610twr_defconfig                   |   1 +
 configs/vf610twr_nand_defconfig              |   1 +
 doc/driver-model/serial-howto.txt            |   1 -
 drivers/serial/Kconfig                       |   6 +
 drivers/serial/serial_lpuart.c               | 334
+++++++++++++++++++++------
 include/configs/colibri_vf.h                 |   1 -
 include/configs/ls1021aqds.h                 |   1 -
 include/configs/ls1021atwr.h                 |   3 +-
 include/configs/pcm052.h                     |   1 -
 include/configs/vf610twr.h                   |   1 -
 20 files changed, 298 insertions(+), 94 deletions(-)

--
1.8.2.1

author
#32 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Hi Alison,

Quoted 4 lines · Huan Wang

Hi,

I tested this set on my LS1021ATWR board. NOR boot using DUART as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19, J20) to route the LPUART signal.

[snip]

Regards,
Bin

#33 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Hi, Bin,

Quoted 12 lines · Huan Wang
Quoted 3 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19, J20) to route the LPUART signal.

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

Best Regards,
Alison Wang

author
#34 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Hi Alison,

Quoted 10 lines · Huan Wang

Hi, Bin,

Quoted 8 lines · Huan Wang
Quoted 3 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19, J20) to route the LPUART signal.

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

That's strange. Can you please send your build instructions? Did you program the u-boot-dtb.bin (not u-boot.bin anymore) to the NOR?

Regards,
Bin

#35 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Hi, Bin,

Quoted 17 lines · Huan Wang
Quoted 16 lines

Hi, Bin,

Quoted 14 lines · Huan Wang
Quoted 4 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using
DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19,
J20) to route the LPUART signal.

Quoted 8 lines
Quoted 4 lines

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

That's strange. Can you please send your build instructions? Did you program the u-boot-dtb.bin (not u-boot.bin anymore) to the NOR?

[Alison Wang] My build instructions are,

make ARCH=arm ls1021atwr_nor_lpuart_defconfig
make

Yes. I programmed u-boot-dtb.bin to NOR flash.

Best Regards,
Alison Wang

author
#36 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Hi Alison,

Quoted 27 lines · Huan Wang

Hi, Bin,

Quoted 17 lines · Huan Wang
Quoted 16 lines

Hi, Bin,

Quoted 14 lines · Huan Wang
Quoted 4 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using
DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19,
J20) to route the LPUART signal.

Quoted 8 lines
Quoted 4 lines

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

That's strange. Can you please send your build instructions? Did you program the u-boot-dtb.bin (not u-boot.bin anymore) to the NOR?

Quoted 7 lines

[Alison Wang] My build instructions are,

make ARCH=arm ls1021atwr_nor_lpuart_defconfig
make

Yes. I programmed u-boot-dtb.bin to NOR flash.

Oh, it turns out the last thing to suspect is the /chose node :)

See comments in patch#8 in this series
(http://patchwork.ozlabs.org/patch/561859/)

chosen {
+ /*
+ * With ls1021atwr_nor_lpuart_defconfig configuration,
+ * this needs to be changed to &lpuart0.
+ */
stdout-path = &uart0;
};

I was wondering whether I should introduce another separate dts file for this LPUART configuration, something like ls1021a-twr_lpuart.dts, but I felt it's quite some duplication thus I chose to just add some comments under the /chosen node in the original dts file.

I've done the PCI UART support on the Crown Bay before using the same way. Simon, do you have some better way to handle this?

Regards,
Bin

author
#37 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Hi Simon,

Quoted 51 lines · Bin Meng

Hi Alison,

Quoted 27 lines · Huan Wang

Hi, Bin,

Quoted 17 lines · Huan Wang
Quoted 16 lines

Hi, Bin,

Quoted 14 lines · Huan Wang
Quoted 4 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using
DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19,
J20) to route the LPUART signal.

Quoted 8 lines
Quoted 4 lines

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

That's strange. Can you please send your build instructions? Did you program the u-boot-dtb.bin (not u-boot.bin anymore) to the NOR?

Quoted 7 lines

[Alison Wang] My build instructions are,

make ARCH=arm ls1021atwr_nor_lpuart_defconfig
make

Yes. I programmed u-boot-dtb.bin to NOR flash.

Oh, it turns out the last thing to suspect is the /chose node :)

See comments in patch#8 in this series
(http://patchwork.ozlabs.org/patch/561859/)

chosen {
+ /*
+ * With ls1021atwr_nor_lpuart_defconfig configuration,
+ * this needs to be changed to &lpuart0.
+ */
stdout-path = &uart0;
};

Quoted 7 lines

I was wondering whether I should introduce another separate dts file for this LPUART configuration, something like ls1021a-twr_lpuart.dts, but I felt it's quite some duplication thus I chose to just add some comments under the /chosen node in the original dts file.

I've done the PCI UART support on the Crown Bay before using the same way. Simon, do you have some better way to handle this?

Alison has tested this series on her board. I believe the only concern is with the lpuart in the /chosen node. Can you comment on this?

Regards,
Bin

#38 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Hi,

Quoted 59 lines · Bin Meng

Hi Simon,

Quoted 56 lines · Bin Meng

Hi Alison,

Quoted 27 lines · Huan Wang

Hi, Bin,

Quoted 17 lines · Huan Wang
Quoted 16 lines

Hi, Bin,

Quoted 14 lines · Huan Wang
Quoted 4 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using
DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19,
J20) to route the LPUART signal.

Quoted 8 lines
Quoted 4 lines

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

That's strange. Can you please send your build instructions? Did you program the u-boot-dtb.bin (not u-boot.bin anymore) to the NOR?

Quoted 7 lines

[Alison Wang] My build instructions are,

make ARCH=arm ls1021atwr_nor_lpuart_defconfig
make

Yes. I programmed u-boot-dtb.bin to NOR flash.

Oh, it turns out the last thing to suspect is the /chose node :)

See comments in patch#8 in this series
(http://patchwork.ozlabs.org/patch/561859/)

chosen {
+ /*
+ * With ls1021atwr_nor_lpuart_defconfig configuration,
+ * this needs to be changed to &lpuart0.
+ */
stdout-path = &uart0;
};

I was wondering whether I should introduce another separate dts file for this LPUART configuration, something like ls1021a-twr_lpuart.dts, but I felt it's quite some duplication thus I chose to just add some comments under the /chosen node in the original dts file.

Quoted 5 lines
Quoted 2 lines

I've done the PCI UART support on the Crown Bay before using the same way. Simon, do you have some better way to handle this?

Alison has tested this series on her board. I believe the only concern is with the lpuart in the /chosen node. Can you comment on this?

It looks OK to me. You could create a separate device tree and put the common contents in a .dtsi file,. I'm not sure of the trade-offs with this though.

Regards,
Simon

#39 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

In reply to Bin Meng
Quoted 51 lines · Bin Meng

Hi Alison,

Quoted 27 lines · Huan Wang

Hi, Bin,

Quoted 17 lines · Huan Wang
Quoted 16 lines

Hi, Bin,

Quoted 14 lines · Huan Wang
Quoted 4 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using
DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19,
J20) to route the LPUART signal.

Quoted 8 lines
Quoted 4 lines

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

That's strange. Can you please send your build instructions? Did you program the u-boot-dtb.bin (not u-boot.bin anymore) to the NOR?

Quoted 7 lines

[Alison Wang] My build instructions are,

make ARCH=arm ls1021atwr_nor_lpuart_defconfig
make

Yes. I programmed u-boot-dtb.bin to NOR flash.

Oh, it turns out the last thing to suspect is the /chose node :)

See comments in patch#8 in this series
(http://patchwork.ozlabs.org/patch/561859/)

chosen {
+ /*
+ * With ls1021atwr_nor_lpuart_defconfig configuration,
+ * this needs to be changed to &lpuart0.
+ */
stdout-path = &uart0;
};

Quoted 4 lines

I was wondering whether I should introduce another separate dts file for this LPUART configuration, something like ls1021a-twr_lpuart.dts, but I felt it's quite some duplication thus I chose to just add some comments under the /chosen node in the original dts file.

How about:
ls1021a-twr.dts => ls1021a-twr.dtsi

And include that from
ls1021a-twr-uart.dts
ls1021a-twr-lpuart.dts
and add the /chosen node to those files.

--
Stefan

author
#40 lore raw

cover arm: ls1021atwr: Convert to driver model and enable serial support

Quoted 57 lines · Stefan Agner
Quoted 51 lines · Bin Meng

Hi Alison,

Quoted 27 lines · Huan Wang

Hi, Bin,

Quoted 17 lines · Huan Wang
Quoted 16 lines

Hi, Bin,

Quoted 14 lines · Huan Wang
Quoted 4 lines

Hi,

I tested this set on my LS1021ATWR board. NOR boot using
DUART

as serial output is ok. But NOR boot using LPUART as serial output failed. How about your test result?

Quoted 1 line

Yes, I tested NOR boot using DUART or LPUART. Both boot. I suspect you forgot to update the RCW for LPUART, or change the jumper setting (J19,
J20) to route the LPUART signal.

Quoted 8 lines
Quoted 4 lines

[Alison Wang] I updated the RCW for LPUART and changed the jumper setting (J19, J20). Without this set, NOR boot using LPUART is ok. But after adding this set, NOR boot using LPUART failed.

That's strange. Can you please send your build instructions? Did you program the u-boot-dtb.bin (not u-boot.bin anymore) to the NOR?

Quoted 7 lines

[Alison Wang] My build instructions are,

make ARCH=arm ls1021atwr_nor_lpuart_defconfig
make

Yes. I programmed u-boot-dtb.bin to NOR flash.

Oh, it turns out the last thing to suspect is the /chose node :)

See comments in patch#8 in this series
(http://patchwork.ozlabs.org/patch/561859/)

chosen {
+ /*
+ * With ls1021atwr_nor_lpuart_defconfig configuration,
+ * this needs to be changed to &lpuart0.
+ */
stdout-path = &uart0;
};

Quoted 4 lines

I was wondering whether I should introduce another separate dts file for this LPUART configuration, something like ls1021a-twr_lpuart.dts, but I felt it's quite some duplication thus I chose to just add some comments under the /chosen node in the original dts file.

Quoted 8 lines

How about:
ls1021a-twr.dts => ls1021a-twr.dtsi

And include that from
ls1021a-twr-uart.dts
ls1021a-twr-lpuart.dts
and add the /chosen node to those files.

Yep, will take this approach in v2. Thanks!

Regards,
Bin