Commit 697517293085f7907abd17ac350a530b26cfa85e

Authored by Vikas Manocha
Committed by Tom Rini
1 parent a69bdba9c6

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>
Acked-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 36 additions and 1 deletions Side-by-side Diff

doc/device-tree-bindings/serial/pl01x.txt
  1 +* ARM AMBA Primecell PL011 & PL010 serial UART
  2 +
  3 +Required properties:
  4 +- compatible: must be "arm,primecell", "arm,pl011" or "arm,pl010"
  5 +- reg: exactly one register range with length 0x1000
  6 +- clock: input clock frequency for the UART (used to calculate the baud
  7 + rate divisor)
drivers/serial/serial_pl01x.c
... ... @@ -20,7 +20,10 @@
20 20 #include <dm/platform_data/serial_pl01x.h>
21 21 #include <linux/compiler.h>
22 22 #include "serial_pl01x_internal.h"
  23 +#include <fdtdec.h>
23 24  
  25 +DECLARE_GLOBAL_DATA_PTR;
  26 +
24 27 #ifndef CONFIG_DM_SERIAL
25 28  
26 29 static volatile unsigned char *const port[] = CONFIG_PL01x_PORTS;
... ... @@ -28,7 +31,6 @@
28 31 static struct pl01x_regs *base_regs __attribute__ ((section(".data")));
29 32 #define NUM_PORTS (sizeof(port)/sizeof(port[0]))
30 33  
31   -DECLARE_GLOBAL_DATA_PTR;
32 34 #endif
33 35  
34 36 static int pl01x_putc(struct pl01x_regs *regs, char c)
35 37  
... ... @@ -351,9 +353,35 @@
351 353 .setbrg = pl01x_serial_setbrg,
352 354 };
353 355  
  356 +#ifdef CONFIG_OF_CONTROL
  357 +static const struct udevice_id pl01x_serial_id[] ={
  358 + {.compatible = "arm,pl011", .data = TYPE_PL011},
  359 + {.compatible = "arm,pl010", .data = TYPE_PL010},
  360 + {}
  361 +};
  362 +
  363 +static int pl01x_serial_ofdata_to_platdata(struct udevice *dev)
  364 +{
  365 + struct pl01x_serial_platdata *plat = dev_get_platdata(dev);
  366 + fdt_addr_t addr;
  367 +
  368 + addr = fdtdec_get_addr(gd->fdt_blob, dev->of_offset, "reg");
  369 + if (addr == FDT_ADDR_T_NONE)
  370 + return -EINVAL;
  371 +
  372 + plat->base = addr;
  373 + plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "clock", 1);
  374 + plat->type = dev_get_driver_data(dev);
  375 + return 0;
  376 +}
  377 +#endif
  378 +
354 379 U_BOOT_DRIVER(serial_pl01x) = {
355 380 .name = "serial_pl01x",
356 381 .id = UCLASS_SERIAL,
  382 + .of_match = of_match_ptr(pl01x_serial_id),
  383 + .ofdata_to_platdata = of_match_ptr(pl01x_serial_ofdata_to_platdata),
  384 + .platdata_auto_alloc_size = sizeof(struct pl01x_serial_platdata),
357 385 .probe = pl01x_serial_probe,
358 386 .ops = &pl01x_serial_ops,
359 387 .flags = DM_FLAG_PRE_RELOC,