diff mbox

[U-Boot,v3,2/2] m68k: add DM model serial driver

Message ID 1461536423-14782-1-git-send-email-angelo@sysam.it
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Angelo Dureghello April 24, 2016, 10:20 p.m. UTC
Boards can now use DM serial driver, or still legacy mcf uart
driver version.

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
---
Changes for v2:
   - remove while loops in putc and getc, replacing with return -EAGAIN
   - remove unneeded ifdef
Changes for v3:
   - no changes
---
 drivers/serial/mcfuart.c | 188 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 144 insertions(+), 44 deletions(-)

Comments

Simon Glass April 25, 2016, 9:54 p.m. UTC | #1
Hi Angelo,

On 24 April 2016 at 16:20, Angelo Dureghello <angelo@sysam.it> wrote:
> Boards can now use DM serial driver, or still legacy mcf uart
> driver version.
>
> Signed-off-by: Angelo Dureghello <angelo@sysam.it>
> ---
> Changes for v2:
>    - remove while loops in putc and getc, replacing with return -EAGAIN
>    - remove unneeded ifdef
> Changes for v3:
>    - no changes
> ---
>  drivers/serial/mcfuart.c | 188 ++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 144 insertions(+), 44 deletions(-)
>

Missing file?

02: dm: gpio: pca953x: introduce driver model support for pca953x
03: m68k: add malloc memory for early malloc
04: m68k: add DM model serial driver
      m68k:  +   M5329AFEE M5249EVB M5208EVBE M5475FFE M54451EVB
astro_mcf5373l M54418TWR_serial_rmii M54455EVB_intel amcore M5282EVB
M54455EVB_i66 M54455EVB_a66 M5475GFE M5485GFE M5253DEMO
M54455EVB_stm33 M5475AFE M54455EVB M5485BFE M5329BFEE M52277EVB
M5475EFE M54418TWR_nand_mii M5475CFE cobra5272 M5485AFE M5485HFE
M54418TWR_nand_rmii_lowfreq M5485DFE M5475DFE M5275EVB M54418TWR
M52277EVB_stmicro eb_cpu5282 eb_cpu5282_internal M53017EVB M5485CFE
M5475BFE M5485EFE M5253EVBE M5485FFE M5235EVB_Flash32 M5373EVB
M54418TWR_nand_rmii M54418TWR_serial_mii M5235EVB M54451EVB_stmicro
M5272C3
+../drivers/serial/mcfuart.c:18:46: fatal error:
dm/platform_data/serial_coldfire.h: No such file or directory
+ #include <dm/platform_data/serial_coldfire.h>
+                                              ^
+compilation terminated.
+make[2]: *** [drivers/serial/mcfuart.o] Error 1
+make[1]: *** [drivers/serial] Error 2

Regards,
Simon
Angelo Dureghello April 26, 2016, 9:03 a.m. UTC | #2
Hi Simon,

i realized this patch (v3) is invalid, due to my tests done with 
"CONFIG_DM_SRIAL" (missing 'A'), so was using the legacy driver still.

Also, i found a small issue in start.S files.

I send v4 asap later.

thanks,

regards,
Angelo Dureghello


On 25/04/2016 23:54, Simon Glass wrote:
> Hi Angelo,
>
> On 24 April 2016 at 16:20, Angelo Dureghello <angelo@sysam.it> wrote:
>> Boards can now use DM serial driver, or still legacy mcf uart
>> driver version.
>>
>> Signed-off-by: Angelo Dureghello <angelo@sysam.it>
>> ---
>> Changes for v2:
>>     - remove while loops in putc and getc, replacing with return -EAGAIN
>>     - remove unneeded ifdef
>> Changes for v3:
>>     - no changes
>> ---
>>   drivers/serial/mcfuart.c | 188 ++++++++++++++++++++++++++++++++++++-----------
>>   1 file changed, 144 insertions(+), 44 deletions(-)
>>
>
> Missing file?
>
> 02: dm: gpio: pca953x: introduce driver model support for pca953x
> 03: m68k: add malloc memory for early malloc
> 04: m68k: add DM model serial driver
>        m68k:  +   M5329AFEE M5249EVB M5208EVBE M5475FFE M54451EVB
> astro_mcf5373l M54418TWR_serial_rmii M54455EVB_intel amcore M5282EVB
> M54455EVB_i66 M54455EVB_a66 M5475GFE M5485GFE M5253DEMO
> M54455EVB_stm33 M5475AFE M54455EVB M5485BFE M5329BFEE M52277EVB
> M5475EFE M54418TWR_nand_mii M5475CFE cobra5272 M5485AFE M5485HFE
> M54418TWR_nand_rmii_lowfreq M5485DFE M5475DFE M5275EVB M54418TWR
> M52277EVB_stmicro eb_cpu5282 eb_cpu5282_internal M53017EVB M5485CFE
> M5475BFE M5485EFE M5253EVBE M5485FFE M5235EVB_Flash32 M5373EVB
> M54418TWR_nand_rmii M54418TWR_serial_mii M5235EVB M54451EVB_stmicro
> M5272C3
> +../drivers/serial/mcfuart.c:18:46: fatal error:
> dm/platform_data/serial_coldfire.h: No such file or directory
> + #include <dm/platform_data/serial_coldfire.h>
> +                                              ^
> +compilation terminated.
> +make[2]: *** [drivers/serial/mcfuart.o] Error 1
> +make[1]: *** [drivers/serial] Error 2
>
> Regards,
> Simon
>
Simon Glass April 26, 2016, 3:26 p.m. UTC | #3
Hi Angelo,

On 26 April 2016 at 03:03, Angelo Dureghello <angelo@sysam.it> wrote:
>
> Hi Simon,
>
> i realized this patch (v3) is invalid, due to my tests done with "CONFIG_DM_SRIAL" (missing 'A'), so was using the legacy driver still.
>
> Also, i found a small issue in start.S files.
>
> I send v4 asap later.

OK, thank you. I'll look out for it.

Regards,
Simon

>
> thanks,
>
> regards,
> Angelo Dureghello
>
>
>
> On 25/04/2016 23:54, Simon Glass wrote:
>>
>> Hi Angelo,
>>
>> On 24 April 2016 at 16:20, Angelo Dureghello <angelo@sysam.it> wrote:
>>>
>>> Boards can now use DM serial driver, or still legacy mcf uart
>>> driver version.
>>>
>>> Signed-off-by: Angelo Dureghello <angelo@sysam.it>
>>> ---
>>> Changes for v2:
>>>     - remove while loops in putc and getc, replacing with return -EAGAIN
>>>     - remove unneeded ifdef
>>> Changes for v3:
>>>     - no changes
>>> ---
>>>   drivers/serial/mcfuart.c | 188 ++++++++++++++++++++++++++++++++++++-----------
>>>   1 file changed, 144 insertions(+), 44 deletions(-)
>>>
>>
>> Missing file?
>>
>> 02: dm: gpio: pca953x: introduce driver model support for pca953x
>> 03: m68k: add malloc memory for early malloc
>> 04: m68k: add DM model serial driver
>>        m68k:  +   M5329AFEE M5249EVB M5208EVBE M5475FFE M54451EVB
>> astro_mcf5373l M54418TWR_serial_rmii M54455EVB_intel amcore M5282EVB
>> M54455EVB_i66 M54455EVB_a66 M5475GFE M5485GFE M5253DEMO
>> M54455EVB_stm33 M5475AFE M54455EVB M5485BFE M5329BFEE M52277EVB
>> M5475EFE M54418TWR_nand_mii M5475CFE cobra5272 M5485AFE M5485HFE
>> M54418TWR_nand_rmii_lowfreq M5485DFE M5475DFE M5275EVB M54418TWR
>> M52277EVB_stmicro eb_cpu5282 eb_cpu5282_internal M53017EVB M5485CFE
>> M5475BFE M5485EFE M5253EVBE M5485FFE M5235EVB_Flash32 M5373EVB
>> M54418TWR_nand_rmii M54418TWR_serial_mii M5235EVB M54451EVB_stmicro
>> M5272C3
>> +../drivers/serial/mcfuart.c:18:46: fatal error:
>> dm/platform_data/serial_coldfire.h: No such file or directory
>> + #include <dm/platform_data/serial_coldfire.h>
>> +                                              ^
>> +compilation terminated.
>> +make[2]: *** [drivers/serial/mcfuart.o] Error 1
>> +make[1]: *** [drivers/serial] Error 2
>>
>> Regards,
>> Simon
>>
Angelo Dureghello April 27, 2016, 8:02 p.m. UTC | #4
Hi Simon,

sent v4.

Tested

- legacy serial driver and DM serial driver in mcf5307 "amcore" board
- buildman, pass all boards
- checkpatch

Regards,
angelo


On 26/04/2016 17:26, Simon Glass wrote:
> Hi Angelo,
>
> On 26 April 2016 at 03:03, Angelo Dureghello <angelo@sysam.it> wrote:
>>
>> Hi Simon,
>>
>> i realized this patch (v3) is invalid, due to my tests done with "CONFIG_DM_SRIAL" (missing 'A'), so was using the legacy driver still.
>>
>> Also, i found a small issue in start.S files.
>>
>> I send v4 asap later.
>
> OK, thank you. I'll look out for it.
>
> Regards,
> Simon
>
>>
>> thanks,
>>
>> regards,
>> Angelo Dureghello
>>
>>
>>
>> On 25/04/2016 23:54, Simon Glass wrote:
>>>
>>> Hi Angelo,
>>>
>>> On 24 April 2016 at 16:20, Angelo Dureghello <angelo@sysam.it> wrote:
>>>>
>>>> Boards can now use DM serial driver, or still legacy mcf uart
>>>> driver version.
>>>>
>>>> Signed-off-by: Angelo Dureghello <angelo@sysam.it>
>>>> ---
>>>> Changes for v2:
>>>>      - remove while loops in putc and getc, replacing with return -EAGAIN
>>>>      - remove unneeded ifdef
>>>> Changes for v3:
>>>>      - no changes
>>>> ---
>>>>    drivers/serial/mcfuart.c | 188 ++++++++++++++++++++++++++++++++++++-----------
>>>>    1 file changed, 144 insertions(+), 44 deletions(-)
>>>>
>>>
>>> Missing file?
>>>
>>> 02: dm: gpio: pca953x: introduce driver model support for pca953x
>>> 03: m68k: add malloc memory for early malloc
>>> 04: m68k: add DM model serial driver
>>>         m68k:  +   M5329AFEE M5249EVB M5208EVBE M5475FFE M54451EVB
>>> astro_mcf5373l M54418TWR_serial_rmii M54455EVB_intel amcore M5282EVB
>>> M54455EVB_i66 M54455EVB_a66 M5475GFE M5485GFE M5253DEMO
>>> M54455EVB_stm33 M5475AFE M54455EVB M5485BFE M5329BFEE M52277EVB
>>> M5475EFE M54418TWR_nand_mii M5475CFE cobra5272 M5485AFE M5485HFE
>>> M54418TWR_nand_rmii_lowfreq M5485DFE M5475DFE M5275EVB M54418TWR
>>> M52277EVB_stmicro eb_cpu5282 eb_cpu5282_internal M53017EVB M5485CFE
>>> M5475BFE M5485EFE M5253EVBE M5485FFE M5235EVB_Flash32 M5373EVB
>>> M54418TWR_nand_rmii M54418TWR_serial_mii M5235EVB M54451EVB_stmicro
>>> M5272C3
>>> +../drivers/serial/mcfuart.c:18:46: fatal error:
>>> dm/platform_data/serial_coldfire.h: No such file or directory
>>> + #include <dm/platform_data/serial_coldfire.h>
>>> +                                              ^
>>> +compilation terminated.
>>> +make[2]: *** [drivers/serial/mcfuart.o] Error 1
>>> +make[1]: *** [drivers/serial] Error 2
>>>
>>> Regards,
>>> Simon
>>>
diff mbox

Patch

diff --git a/drivers/serial/mcfuart.c b/drivers/serial/mcfuart.c
index 407354f..059cb0f 100644
--- a/drivers/serial/mcfuart.c
+++ b/drivers/serial/mcfuart.c
@@ -2,6 +2,9 @@ 
  * (C) Copyright 2004-2007 Freescale Semiconductor, Inc.
  * TsiChung Liew, Tsi-Chung.Liew@freescale.com.
  *
+ * Modified to add device model (DM) support
+ * (C) Copyright 2015  Angelo Dureghello <angelo@sysam.it>
+ *
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
@@ -11,9 +14,10 @@ 
  */
 
 #include <common.h>
+#include <dm.h>
+#include <dm/platform_data/serial_coldfire.h>
 #include <serial.h>
 #include <linux/compiler.h>
-
 #include <asm/immap.h>
 #include <asm/uart.h>
 
@@ -21,91 +25,110 @@  DECLARE_GLOBAL_DATA_PTR;
 
 extern void uart_port_conf(int port);
 
-static int mcf_serial_init(void)
+static int mcf_serial_init_common(uart_t *uart, int port_idx, int baudrate)
 {
-	volatile uart_t *uart;
 	u32 counter;
 
-	uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE);
-
-	uart_port_conf(CONFIG_SYS_UART_PORT);
+	uart_port_conf(port_idx);
 
 	/* write to SICR: SIM2 = uart mode,dcd does not affect rx */
-	uart->ucr = UART_UCR_RESET_RX;
-	uart->ucr = UART_UCR_RESET_TX;
-	uart->ucr = UART_UCR_RESET_ERROR;
-	uart->ucr = UART_UCR_RESET_MR;
+	writeb(UART_UCR_RESET_RX, &uart->ucr);
+	writeb(UART_UCR_RESET_TX, &uart->ucr);
+	writeb(UART_UCR_RESET_ERROR, &uart->ucr);
+	writeb(UART_UCR_RESET_MR, &uart->ucr);
 	__asm__("nop");
 
-	uart->uimr = 0;
+	writeb(0, &uart->uimr);
 
 	/* write to CSR: RX/TX baud rate from timers */
-	uart->ucsr = (UART_UCSR_RCS_SYS_CLK | UART_UCSR_TCS_SYS_CLK);
+	writeb(UART_UCSR_RCS_SYS_CLK | UART_UCSR_TCS_SYS_CLK, &uart->ucsr);
 
-	uart->umr = (UART_UMR_BC_8 | UART_UMR_PM_NONE);
-	uart->umr = UART_UMR_SB_STOP_BITS_1;
+	writeb(UART_UMR_BC_8 | UART_UMR_PM_NONE, &uart->umr);
+	writeb(UART_UMR_SB_STOP_BITS_1, &uart->umr);
 
 	/* Setting up BaudRate */
-	counter = (u32) ((gd->bus_clk / 32) + (gd->baudrate / 2));
-	counter = counter / gd->baudrate;
+	counter = (u32) ((gd->bus_clk / 32) + (baudrate / 2));
+	counter = counter / baudrate;
 
 	/* write to CTUR: divide counter upper byte */
-	uart->ubg1 = (u8) ((counter & 0xff00) >> 8);
+	writeb((u8)((counter & 0xff00) >> 8), &uart->ubg1);
 	/* write to CTLR: divide counter lower byte */
-	uart->ubg2 = (u8) (counter & 0x00ff);
+	writeb((u8)(counter & 0x00ff), &uart->ubg2);
 
-	uart->ucr = (UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED);
+	writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
 
 	return (0);
 }
 
+static void mcf_serial_setbrg_common(uart_t *uart, int baudrate)
+{
+	u32 counter;
+
+	/* Setting up BaudRate */
+	counter = (u32) ((gd->bus_clk / 32) + (baudrate / 2));
+	counter = counter / baudrate;
+
+	/* write to CTUR: divide counter upper byte */
+	writeb(((counter & 0xff00) >> 8), &uart->ubg1);
+	/* write to CTLR: divide counter lower byte */
+	writeb((counter & 0x00ff), &uart->ubg2);
+
+	writeb(UART_UCR_RESET_RX, &uart->ucr);
+	writeb(UART_UCR_RESET_TX, &uart->ucr);
+
+	writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
+}
+
+#ifndef CONFIG_DM_SERIAL
+
+static int mcf_serial_init(void)
+{
+	uart_t *uart_base;
+	int port_idx;
+
+	uart_base = (uart_t *)CONFIG_SYS_UART_BASE;
+	port_idx = CONFIG_SYS_UART_PORT;
+
+	return mcf_serial_init_common(uart_base, port_idx, gd->baudrate);
+}
+
 static void mcf_serial_putc(const char c)
 {
-	volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE);
+	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
 
 	if (c == '\n')
 		serial_putc('\r');
 
 	/* Wait for last character to go. */
-	while (!(uart->usr & UART_USR_TXRDY)) ;
+	while (!(readb(&uart->usr) & UART_USR_TXRDY))
+		;
 
-	uart->utb = c;
+	writeb(c, &uart->utb);
 }
 
 static int mcf_serial_getc(void)
 {
-	volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE);
+	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
 
 	/* Wait for a character to arrive. */
-	while (!(uart->usr & UART_USR_RXRDY)) ;
-	return uart->urb;
-}
-
-static int mcf_serial_tstc(void)
-{
-	volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE);
+	while (!(readb(&uart->usr) & UART_USR_RXRDY))
+		;
 
-	return (uart->usr & UART_USR_RXRDY);
+	return readb(&uart->urb);
 }
 
 static void mcf_serial_setbrg(void)
 {
-	volatile uart_t *uart = (volatile uart_t *)(CONFIG_SYS_UART_BASE);
-	u32 counter;
-
-	/* Setting up BaudRate */
-	counter = (u32) ((gd->bus_clk / 32) + (gd->baudrate / 2));
-	counter = counter / gd->baudrate;
+	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
 
-	/* write to CTUR: divide counter upper byte */
-	uart->ubg1 = ((counter & 0xff00) >> 8);
-	/* write to CTLR: divide counter lower byte */
-	uart->ubg2 = (counter & 0x00ff);
+	mcf_serial_setbrg_common(uart, gd->baudrate);
+}
 
-	uart->ucr = UART_UCR_RESET_RX;
-	uart->ucr = UART_UCR_RESET_TX;
+static int mcf_serial_tstc(void)
+{
+	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
 
-	uart->ucr = UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED;
+	return readb(&uart->usr) & UART_USR_RXRDY;
 }
 
 static struct serial_device mcf_serial_drv = {
@@ -128,3 +151,80 @@  __weak struct serial_device *default_serial_console(void)
 {
 	return &mcf_serial_drv;
 }
+
+#endif
+
+#ifdef CONFIG_DM_SERIAL
+
+static int coldfire_serial_probe(struct udevice *dev)
+{
+	struct coldfire_serial_platdata *plat = dev->platdata;
+
+	return mcf_serial_init_common((uart_t *)plat->base,
+						plat->port, plat->baudrate);
+}
+
+static int coldfire_serial_putc(struct udevice *dev, const char ch)
+{
+	struct coldfire_serial_platdata *plat = dev->platdata;
+	uart_t *uart = (uart_t *)plat->base;
+
+	/* Wait for last character to go. */
+	if (!(readb(&uart->usr) & UART_USR_TXRDY))
+		return -EAGAIN;
+
+	writeb(ch, &uart->utb);
+
+	return 0;
+}
+
+static int coldfire_serial_getc(struct udevice *dev)
+{
+	struct coldfire_serial_platdata *plat = dev->platdata;
+	uart_t *uart = (uart_t *)(plat->base);
+
+	/* Wait for a character to arrive. */
+	if (!(readb(&uart->usr) & UART_USR_RXRDY))
+		return -EAGAIN;
+
+	return readb(&uart->urb);
+}
+
+int coldfire_serial_setbrg(struct udevice *dev, int baudrate)
+{
+	struct coldfire_serial_platdata *plat = dev->platdata;
+	uart_t *uart = (uart_t *)(plat->base);
+
+	mcf_serial_setbrg_common(uart, baudrate);
+
+	return 0;
+}
+
+static int coldfire_serial_pending(struct udevice *dev, bool input)
+{
+	struct coldfire_serial_platdata *plat = dev->platdata;
+	uart_t *uart = (uart_t *)(plat->base);
+
+	if (input)
+		return readb(&uart->usr) & UART_USR_RXRDY ? 1 : 0;
+	else
+		return readb(&uart->usr) & UART_USR_TXRDY ? 0 : 1;
+
+	return 0;
+}
+
+static const struct dm_serial_ops coldfire_serial_ops = {
+	.putc = coldfire_serial_putc,
+	.pending = coldfire_serial_pending,
+	.getc = coldfire_serial_getc,
+	.setbrg = coldfire_serial_setbrg,
+};
+
+U_BOOT_DRIVER(serial_coldfire) = {
+	.name = "serial_coldfire",
+	.id = UCLASS_SERIAL,
+	.probe = coldfire_serial_probe,
+	.ops = &coldfire_serial_ops,
+	.flags = DM_FLAG_PRE_RELOC,
+};
+#endif