* [U-Boot] [PATCH v1] serial: ns16550: Add fractional divider for Intel MID
@ 2017-02-21 12:59 Andy Shevchenko
2017-02-22 4:00 ` Simon Glass
0 siblings, 1 reply; 2+ messages in thread
From: Andy Shevchenko @ 2017-02-21 12:59 UTC (permalink / raw)
To: u-boot
The change introduces three integer Kconfig options
SERIAL_DIV_M multiplier
SERIAL_DIV_N divisor
SERIAL_DIV_PS prescaler divisor
to set default configuration of prescaler.
The UART clock is calculated as
UART clock = XTAL * SERIAL_DIV_M / SERIAL_DIV_N
The baudrate is calculated as
baud rate = UART clock / SERIAL_DIV_PS
In the future the options can be used on any UART where fractional
divider is implemented.
In particular, Intel MID platforms have additional registers in UART to
configure a fractional divider.
Initialize fractional divider correctly for Intel Edison platform.
For backward compatibility we have to set initial DLAB value to 16
and speed to 115200 baud, where initial frequency is 29491200Hz, and
XTAL frequency is 38.4MHz.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/serial/Kconfig | 12 ++++++++++++
drivers/serial/ns16550.c | 21 +++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index b11f3ff89e..7860009a4b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -268,6 +268,18 @@ config DEBUG_UART_SKIP_INIT
Select this if the UART you want to use for debug output is already
initialized by the time U-Boot starts its execution.
+config SERIAL_DIV_M
+ int
+ default 96
+
+config SERIAL_DIV_N
+ int
+ default 125
+
+config SERIAL_DIV_PS
+ int
+ default 16
+
config ALTERA_JTAG_UART
bool "Altera JTAG UART support"
depends on DM_SERIAL
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
index 1f819d487b..34e39a2873 100644
--- a/drivers/serial/ns16550.c
+++ b/drivers/serial/ns16550.c
@@ -48,6 +48,22 @@ DECLARE_GLOBAL_DATA_PTR;
#endif
#endif
+#if defined(CONFIG_INTEL_MID)
+#define UART_MUL 0x34
+#define UART_DIV 0x38
+
+static void ns16550_writel(NS16550_t port, int offset, int value)
+{
+ struct ns16550_platdata *plat = port->plat;
+ unsigned char *addr;
+
+ offset *= 1 << plat->reg_shift;
+ addr = (unsigned char *)plat->base + offset;
+
+ writel(value, addr + plat->reg_offset);
+}
+#endif
+
#ifndef CONFIG_SYS_NS16550_IER
#define CONFIG_SYS_NS16550_IER 0x00
#endif /* CONFIG_SYS_NS16550_IER */
@@ -181,6 +197,11 @@ void NS16550_init(NS16550_t com_port, int baud_divisor)
#endif
serial_out(UART_MCRVAL, &com_port->mcr);
serial_out(ns16550_getfcr(com_port), &com_port->fcr);
+#if defined(CONFIG_INTEL_MID)
+ ns16550_writel(com_port, UART_MUL, CONFIG_SERIAL_DIV_M);
+ ns16550_writel(com_port, UART_DIV, CONFIG_SERIAL_DIV_N);
+ NS16550_setbrg(com_port, CONFIG_SERIAL_DIV_PS);
+#endif
if (baud_divisor != -1)
NS16550_setbrg(com_port, baud_divisor);
#if defined(CONFIG_OMAP) || \
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATCH v1] serial: ns16550: Add fractional divider for Intel MID
2017-02-21 12:59 [U-Boot] [PATCH v1] serial: ns16550: Add fractional divider for Intel MID Andy Shevchenko
@ 2017-02-22 4:00 ` Simon Glass
0 siblings, 0 replies; 2+ messages in thread
From: Simon Glass @ 2017-02-22 4:00 UTC (permalink / raw)
To: u-boot
Hi Andy,
On 21 February 2017 at 05:59, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> The change introduces three integer Kconfig options
> SERIAL_DIV_M multiplier
> SERIAL_DIV_N divisor
> SERIAL_DIV_PS prescaler divisor
> to set default configuration of prescaler.
>
> The UART clock is calculated as
>
> UART clock = XTAL * SERIAL_DIV_M / SERIAL_DIV_N
>
> The baudrate is calculated as
>
> baud rate = UART clock / SERIAL_DIV_PS
>
> In the future the options can be used on any UART where fractional
> divider is implemented.
>
> In particular, Intel MID platforms have additional registers in UART to
> configure a fractional divider.
>
> Initialize fractional divider correctly for Intel Edison platform.
This should somehow be encoded in the device tree so you don't need an
#ifdef in the driver. One day this driver will be clean, and this is
heading in the wrong direction unfortunately.
Can the values not be calculated from the clock? If not, then we need
new device-tree properties.
Another approach would be to create your own driver which calls into
ns16550 in some cases. For example serial_rockchip does this.
>
> For backward compatibility we have to set initial DLAB value to 16
> and speed to 115200 baud, where initial frequency is 29491200Hz, and
> XTAL frequency is 38.4MHz.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/serial/Kconfig | 12 ++++++++++++
> drivers/serial/ns16550.c | 21 +++++++++++++++++++++
> 2 files changed, 33 insertions(+)
>
> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> index b11f3ff89e..7860009a4b 100644
> --- a/drivers/serial/Kconfig
> +++ b/drivers/serial/Kconfig
> @@ -268,6 +268,18 @@ config DEBUG_UART_SKIP_INIT
> Select this if the UART you want to use for debug output is already
> initialized by the time U-Boot starts its execution.
>
> +config SERIAL_DIV_M
> + int
> + default 96
> +
> +config SERIAL_DIV_N
> + int
> + default 125
> +
> +config SERIAL_DIV_PS
> + int
> + default 16
> +
> config ALTERA_JTAG_UART
> bool "Altera JTAG UART support"
> depends on DM_SERIAL
> diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
> index 1f819d487b..34e39a2873 100644
> --- a/drivers/serial/ns16550.c
> +++ b/drivers/serial/ns16550.c
> @@ -48,6 +48,22 @@ DECLARE_GLOBAL_DATA_PTR;
> #endif
> #endif
>
> +#if defined(CONFIG_INTEL_MID)
> +#define UART_MUL 0x34
> +#define UART_DIV 0x38
> +
> +static void ns16550_writel(NS16550_t port, int offset, int value)
> +{
> + struct ns16550_platdata *plat = port->plat;
> + unsigned char *addr;
> +
> + offset *= 1 << plat->reg_shift;
> + addr = (unsigned char *)plat->base + offset;
> +
> + writel(value, addr + plat->reg_offset);
> +}
> +#endif
> +
> #ifndef CONFIG_SYS_NS16550_IER
> #define CONFIG_SYS_NS16550_IER 0x00
> #endif /* CONFIG_SYS_NS16550_IER */
> @@ -181,6 +197,11 @@ void NS16550_init(NS16550_t com_port, int baud_divisor)
> #endif
> serial_out(UART_MCRVAL, &com_port->mcr);
> serial_out(ns16550_getfcr(com_port), &com_port->fcr);
> +#if defined(CONFIG_INTEL_MID)
> + ns16550_writel(com_port, UART_MUL, CONFIG_SERIAL_DIV_M);
> + ns16550_writel(com_port, UART_DIV, CONFIG_SERIAL_DIV_N);
> + NS16550_setbrg(com_port, CONFIG_SERIAL_DIV_PS);
> +#endif
> if (baud_divisor != -1)
> NS16550_setbrg(com_port, baud_divisor);
> #if defined(CONFIG_OMAP) || \
> --
> 2.11.0
>
REgards,
Simon
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-02-22 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-21 12:59 [U-Boot] [PATCH v1] serial: ns16550: Add fractional divider for Intel MID Andy Shevchenko
2017-02-22 4:00 ` Simon Glass
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox