blob: f4e9422ed91c95e965f43b043f5be82db245586d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass2fc24d52016-07-04 11:58:24 -06002/*
3 * Copyright (c) 2015 Google, Inc
Simon Glass2fc24d52016-07-04 11:58:24 -06004 */
5
6#include <common.h>
7#include <debug_uart.h>
8#include <dm.h>
9#include <dt-structs.h>
10#include <ns16550.h>
11#include <serial.h>
Kever Yang15f09a12019-03-28 11:01:23 +080012#include <asm/arch-rockchip/clock.h>
Simon Glass0fd3d912020-12-22 19:30:28 -070013#include <dm/device-internal.h>
Simon Glass2fc24d52016-07-04 11:58:24 -060014
Simon Glass8a8d24b2020-12-03 16:55:23 -070015struct rockchip_uart_plat {
Johan Jonker72848972022-04-09 18:55:10 +020016#if CONFIG_IS_ENABLED(OF_PLATDATA)
Johan Jonker6e2ee2e2022-04-09 18:55:12 +020017 struct dtd_rockchip_uart dtplat;
Johan Jonker72848972022-04-09 18:55:10 +020018#endif
Simon Glass8a8d24b2020-12-03 16:55:23 -070019 struct ns16550_plat plat;
Simon Glass2fc24d52016-07-04 11:58:24 -060020};
Johan Jonker72848972022-04-09 18:55:10 +020021
22#if CONFIG_IS_ENABLED(OF_PLATDATA)
Johan Jonker6e2ee2e2022-04-09 18:55:12 +020023struct dtd_rockchip_uart *dtplat, s_dtplat;
Heiko Stübnercd769162017-02-18 19:46:29 +010024#endif
Simon Glass2fc24d52016-07-04 11:58:24 -060025
26static int rockchip_serial_probe(struct udevice *dev)
27{
Johan Jonker72848972022-04-09 18:55:10 +020028#if CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass8a8d24b2020-12-03 16:55:23 -070029 struct rockchip_uart_plat *plat = dev_get_plat(dev);
Simon Glass2fc24d52016-07-04 11:58:24 -060030
31 /* Create some new platform data for the standard driver */
32 plat->plat.base = plat->dtplat.reg[0];
33 plat->plat.reg_shift = plat->dtplat.reg_shift;
34 plat->plat.clock = plat->dtplat.clock_frequency;
Heiko Schocher17fa0322017-01-18 08:05:49 +010035 plat->plat.fcr = UART_FCR_DEFVAL;
Simon Glass0fd3d912020-12-22 19:30:28 -070036 dev_set_plat(dev, &plat->plat);
Simon Glass2fc24d52016-07-04 11:58:24 -060037
38 return ns16550_serial_probe(dev);
Johan Jonker72848972022-04-09 18:55:10 +020039#else
40 return -ENODEV;
41#endif
Simon Glass2fc24d52016-07-04 11:58:24 -060042}
43
Johan Jonker6e2ee2e2022-04-09 18:55:12 +020044U_BOOT_DRIVER(rockchip_uart) = {
45 .name = "rockchip_uart",
Johan Jonker72848972022-04-09 18:55:10 +020046 .id = UCLASS_SERIAL,
Simon Glassd30c7202020-12-22 19:30:18 -070047 .priv_auto = sizeof(struct ns16550),
Simon Glass8a8d24b2020-12-03 16:55:23 -070048 .plat_auto = sizeof(struct rockchip_uart_plat),
Johan Jonker72848972022-04-09 18:55:10 +020049 .probe = rockchip_serial_probe,
50 .ops = &ns16550_serial_ops,
51 .flags = DM_FLAG_PRE_RELOC,
Simon Glass2fc24d52016-07-04 11:58:24 -060052};
Johan Jonker6e2ee2e2022-04-09 18:55:12 +020053DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3066_uart)
54DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3188_uart)
55DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3288_uart)
56DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3328_uart)
57DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3368_uart)