blob: 8a15173f238f4f2abcfb33d834c3ed4571ca3ed8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassb3068ad2016-07-04 11:58:24 -06002/*
3 * Copyright (c) 2015 Google, Inc
Simon Glassb3068ad2016-07-04 11:58:24 -06004 */
5
Simon Glassb3068ad2016-07-04 11:58:24 -06006#include <debug_uart.h>
7#include <dm.h>
8#include <dt-structs.h>
9#include <ns16550.h>
10#include <serial.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080011#include <asm/arch-rockchip/clock.h>
Simon Glass95588622020-12-22 19:30:28 -070012#include <dm/device-internal.h>
Simon Glassb3068ad2016-07-04 11:58:24 -060013
Simon Glassb75b15b2020-12-03 16:55:23 -070014struct rockchip_uart_plat {
Johan Jonkere7903162022-04-09 18:55:10 +020015#if CONFIG_IS_ENABLED(OF_PLATDATA)
Johan Jonkerd1c0eb92022-04-09 18:55:12 +020016 struct dtd_rockchip_uart dtplat;
Johan Jonkere7903162022-04-09 18:55:10 +020017#endif
Simon Glassb75b15b2020-12-03 16:55:23 -070018 struct ns16550_plat plat;
Simon Glassb3068ad2016-07-04 11:58:24 -060019};
Johan Jonkere7903162022-04-09 18:55:10 +020020
21#if CONFIG_IS_ENABLED(OF_PLATDATA)
Johan Jonkerd1c0eb92022-04-09 18:55:12 +020022struct dtd_rockchip_uart *dtplat, s_dtplat;
Heiko Stübner2d76bfd2017-02-18 19:46:29 +010023#endif
Simon Glassb3068ad2016-07-04 11:58:24 -060024
25static int rockchip_serial_probe(struct udevice *dev)
26{
Johan Jonkere7903162022-04-09 18:55:10 +020027#if CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glassb75b15b2020-12-03 16:55:23 -070028 struct rockchip_uart_plat *plat = dev_get_plat(dev);
Simon Glassb3068ad2016-07-04 11:58:24 -060029
30 /* Create some new platform data for the standard driver */
31 plat->plat.base = plat->dtplat.reg[0];
32 plat->plat.reg_shift = plat->dtplat.reg_shift;
33 plat->plat.clock = plat->dtplat.clock_frequency;
Heiko Schocher06f108e2017-01-18 08:05:49 +010034 plat->plat.fcr = UART_FCR_DEFVAL;
Simon Glass95588622020-12-22 19:30:28 -070035 dev_set_plat(dev, &plat->plat);
Simon Glassb3068ad2016-07-04 11:58:24 -060036
37 return ns16550_serial_probe(dev);
Johan Jonkere7903162022-04-09 18:55:10 +020038#else
39 return -ENODEV;
40#endif
Simon Glassb3068ad2016-07-04 11:58:24 -060041}
42
Johan Jonkerd1c0eb92022-04-09 18:55:12 +020043U_BOOT_DRIVER(rockchip_uart) = {
44 .name = "rockchip_uart",
Johan Jonkere7903162022-04-09 18:55:10 +020045 .id = UCLASS_SERIAL,
Simon Glass119e7ef2020-12-22 19:30:18 -070046 .priv_auto = sizeof(struct ns16550),
Simon Glassb75b15b2020-12-03 16:55:23 -070047 .plat_auto = sizeof(struct rockchip_uart_plat),
Johan Jonkere7903162022-04-09 18:55:10 +020048 .probe = rockchip_serial_probe,
49 .ops = &ns16550_serial_ops,
50 .flags = DM_FLAG_PRE_RELOC,
Simon Glassb3068ad2016-07-04 11:58:24 -060051};
Johan Jonkerd1c0eb92022-04-09 18:55:12 +020052DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3066_uart)
53DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3188_uart)
54DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3288_uart)
55DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3328_uart)
56DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3368_uart)