xref: /openbmc/u-boot/drivers/serial/serial_omap.c (revision 038be18f)
1 /*
2  * Copyright (c) 2014 Google, Inc
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <fdtdec.h>
10 #include <ns16550.h>
11 #include <serial.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 #define DEFAULT_CLK_SPEED 48000000 /* 48Mhz */
16 
17 #if CONFIG_IS_ENABLED(OF_CONTROL)
18 static const struct udevice_id omap_serial_ids[] = {
19 	{ .compatible = "ti,omap2-uart" },
20 	{ .compatible = "ti,omap3-uart" },
21 	{ .compatible = "ti,omap4-uart" },
22 	{ .compatible = "ti,am3352-uart" },
23 	{ .compatible = "ti,am4372-uart" },
24 	{ .compatible = "ti,dra742-uart" },
25 	{ }
26 };
27 
28 static int omap_serial_ofdata_to_platdata(struct udevice *dev)
29 {
30 	struct ns16550_platdata *plat = dev_get_platdata(dev);
31 	int ret;
32 
33 	ret = ns16550_serial_ofdata_to_platdata(dev);
34 	if (ret)
35 		return ret;
36 	plat->clock = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
37 				     "clock-frequency", DEFAULT_CLK_SPEED);
38 	plat->reg_shift = 2;
39 
40 	return 0;
41 }
42 #endif
43 
44 U_BOOT_DRIVER(serial_omap_ns16550) = {
45 	.name	= "serial_omap",
46 	.id	= UCLASS_SERIAL,
47 	.of_match = of_match_ptr(omap_serial_ids),
48 	.ofdata_to_platdata = of_match_ptr(omap_serial_ofdata_to_platdata),
49 	.platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
50 	.priv_auto_alloc_size = sizeof(struct NS16550),
51 	.probe = ns16550_serial_probe,
52 	.ops	= &ns16550_serial_ops,
53 	.flags	= DM_FLAG_PRE_RELOC,
54 };
55