[U-Boot] [PATCH v2] serial: fdt: add device tree support for pl01x

This patch adds device tree support for arm pl010/pl011 driver.
Signed-off-by: Vikas Manocha vikas.manocha@st.com ---
Changes in v2: - removed #ifdef CONFIG_OF_CONTROL from driver structure & used of_match_ptr
doc/device-tree-bindings/serial/pl01x.txt | 7 +++++++ drivers/serial/serial_pl01x.c | 30 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 doc/device-tree-bindings/serial/pl01x.txt
diff --git a/doc/device-tree-bindings/serial/pl01x.txt b/doc/device-tree-bindings/serial/pl01x.txt new file mode 100644 index 0000000..61c27d1 --- /dev/null +++ b/doc/device-tree-bindings/serial/pl01x.txt @@ -0,0 +1,7 @@ +* ARM AMBA Primecell PL011 & PL010 serial UART + +Required properties: +- compatible: must be "arm,primecell", "arm,pl011" or "arm,pl010" +- reg: exactly one register range with length 0x1000 +- clock: input clock frequency for the UART (used to calculate the baud + rate divisor) diff --git a/drivers/serial/serial_pl01x.c b/drivers/serial/serial_pl01x.c index 2124161..ad503af 100644 --- a/drivers/serial/serial_pl01x.c +++ b/drivers/serial/serial_pl01x.c @@ -20,6 +20,9 @@ #include <dm/platform_data/serial_pl01x.h> #include <linux/compiler.h> #include "serial_pl01x_internal.h" +#include <fdtdec.h> + +DECLARE_GLOBAL_DATA_PTR;
#ifndef CONFIG_DM_SERIAL
@@ -28,7 +31,6 @@ static enum pl01x_type pl01x_type __attribute__ ((section(".data"))); static struct pl01x_regs *base_regs __attribute__ ((section(".data"))); #define NUM_PORTS (sizeof(port)/sizeof(port[0]))
-DECLARE_GLOBAL_DATA_PTR; #endif
static int pl01x_putc(struct pl01x_regs *regs, char c) @@ -351,9 +353,35 @@ static const struct dm_serial_ops pl01x_serial_ops = { .setbrg = pl01x_serial_setbrg, };
+#ifdef CONFIG_OF_CONTROL +static const struct udevice_id pl01x_serial_id[] ={ + {.compatible = "arm,pl011", .data = TYPE_PL011}, + {.compatible = "arm,pl010", .data = TYPE_PL010}, + {} +}; + +static int pl01x_serial_ofdata_to_platdata(struct udevice *dev) +{ + struct pl01x_serial_platdata *plat = dev_get_platdata(dev); + fdt_addr_t addr; + + addr = fdtdec_get_addr(gd->fdt_blob, dev->of_offset, "reg"); + if (addr == FDT_ADDR_T_NONE) + return -EINVAL; + + plat->base = addr; + plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "clock", 1); + plat->type = dev_get_driver_data(dev); + return 0; +} +#endif + U_BOOT_DRIVER(serial_pl01x) = { .name = "serial_pl01x", .id = UCLASS_SERIAL, + .of_match = of_match_ptr(pl01x_serial_id), + .ofdata_to_platdata = of_match_ptr(pl01x_serial_ofdata_to_platdata), + .platdata_auto_alloc_size = sizeof(struct pl01x_serial_platdata), .probe = pl01x_serial_probe, .ops = &pl01x_serial_ops, .flags = DM_FLAG_PRE_RELOC,

Hi Masahiro,
On 6 May 2015 at 12:46, Vikas Manocha vikas.manocha@st.com wrote:
This patch adds device tree support for arm pl010/pl011 driver.
Signed-off-by: Vikas Manocha vikas.manocha@st.com
Changes in v2:
- removed #ifdef CONFIG_OF_CONTROL from driver structure & used of_match_ptr
Acked-by: Simon Glass sjg@chromium.org
But let me know what you think of the use of of_match_ptr() below.
doc/device-tree-bindings/serial/pl01x.txt | 7 +++++++ drivers/serial/serial_pl01x.c | 30 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 doc/device-tree-bindings/serial/pl01x.txt
diff --git a/doc/device-tree-bindings/serial/pl01x.txt b/doc/device-tree-bindings/serial/pl01x.txt new file mode 100644 index 0000000..61c27d1 --- /dev/null +++ b/doc/device-tree-bindings/serial/pl01x.txt @@ -0,0 +1,7 @@ +* ARM AMBA Primecell PL011 & PL010 serial UART
+Required properties: +- compatible: must be "arm,primecell", "arm,pl011" or "arm,pl010" +- reg: exactly one register range with length 0x1000 +- clock: input clock frequency for the UART (used to calculate the baud
- rate divisor)
diff --git a/drivers/serial/serial_pl01x.c b/drivers/serial/serial_pl01x.c index 2124161..ad503af 100644 --- a/drivers/serial/serial_pl01x.c +++ b/drivers/serial/serial_pl01x.c @@ -20,6 +20,9 @@ #include <dm/platform_data/serial_pl01x.h> #include <linux/compiler.h> #include "serial_pl01x_internal.h" +#include <fdtdec.h>
+DECLARE_GLOBAL_DATA_PTR;
#ifndef CONFIG_DM_SERIAL
@@ -28,7 +31,6 @@ static enum pl01x_type pl01x_type __attribute__ ((section(".data"))); static struct pl01x_regs *base_regs __attribute__ ((section(".data"))); #define NUM_PORTS (sizeof(port)/sizeof(port[0]))
-DECLARE_GLOBAL_DATA_PTR; #endif
static int pl01x_putc(struct pl01x_regs *regs, char c) @@ -351,9 +353,35 @@ static const struct dm_serial_ops pl01x_serial_ops = { .setbrg = pl01x_serial_setbrg, };
+#ifdef CONFIG_OF_CONTROL +static const struct udevice_id pl01x_serial_id[] ={
{.compatible = "arm,pl011", .data = TYPE_PL011},
{.compatible = "arm,pl010", .data = TYPE_PL010},
{}
+};
+static int pl01x_serial_ofdata_to_platdata(struct udevice *dev) +{
struct pl01x_serial_platdata *plat = dev_get_platdata(dev);
fdt_addr_t addr;
addr = fdtdec_get_addr(gd->fdt_blob, dev->of_offset, "reg");
if (addr == FDT_ADDR_T_NONE)
return -EINVAL;
plat->base = addr;
plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "clock", 1);
plat->type = dev_get_driver_data(dev);
return 0;
+} +#endif
U_BOOT_DRIVER(serial_pl01x) = { .name = "serial_pl01x", .id = UCLASS_SERIAL,
.of_match = of_match_ptr(pl01x_serial_id),
.ofdata_to_platdata = of_match_ptr(pl01x_serial_ofdata_to_platdata),
.platdata_auto_alloc_size = sizeof(struct pl01x_serial_platdata), .probe = pl01x_serial_probe, .ops = &pl01x_serial_ops, .flags = DM_FLAG_PRE_RELOC,
-- 1.7.9.5
Regards, Simon

On Wed, May 06, 2015 at 11:46:29AM -0700, Vikas Manocha wrote:
This patch adds device tree support for arm pl010/pl011 driver.
Signed-off-by: Vikas Manocha vikas.manocha@st.com Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
participants (3)
-
Simon Glass
-
Tom Rini
-
Vikas Manocha