Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 6 | #include <debug_uart.h> |
| 7 | #include <dm.h> |
| 8 | #include <dt-structs.h> |
| 9 | #include <ns16550.h> |
| 10 | #include <serial.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 11 | #include <asm/arch-rockchip/clock.h> |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 12 | #include <dm/device-internal.h> |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 13 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 14 | struct rockchip_uart_plat { |
Johan Jonker | e790316 | 2022-04-09 18:55:10 +0200 | [diff] [blame] | 15 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
Johan Jonker | d1c0eb9 | 2022-04-09 18:55:12 +0200 | [diff] [blame] | 16 | struct dtd_rockchip_uart dtplat; |
Johan Jonker | e790316 | 2022-04-09 18:55:10 +0200 | [diff] [blame] | 17 | #endif |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 18 | struct ns16550_plat plat; |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 19 | }; |
Johan Jonker | e790316 | 2022-04-09 18:55:10 +0200 | [diff] [blame] | 20 | |
| 21 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
Johan Jonker | d1c0eb9 | 2022-04-09 18:55:12 +0200 | [diff] [blame] | 22 | struct dtd_rockchip_uart *dtplat, s_dtplat; |
Heiko Stübner | 2d76bfd | 2017-02-18 19:46:29 +0100 | [diff] [blame] | 23 | #endif |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 24 | |
| 25 | static int rockchip_serial_probe(struct udevice *dev) |
| 26 | { |
Johan Jonker | e790316 | 2022-04-09 18:55:10 +0200 | [diff] [blame] | 27 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 28 | struct rockchip_uart_plat *plat = dev_get_plat(dev); |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 29 | |
| 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 Schocher | 06f108e | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 34 | plat->plat.fcr = UART_FCR_DEFVAL; |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 35 | dev_set_plat(dev, &plat->plat); |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 36 | |
| 37 | return ns16550_serial_probe(dev); |
Johan Jonker | e790316 | 2022-04-09 18:55:10 +0200 | [diff] [blame] | 38 | #else |
| 39 | return -ENODEV; |
| 40 | #endif |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 41 | } |
| 42 | |
Johan Jonker | d1c0eb9 | 2022-04-09 18:55:12 +0200 | [diff] [blame] | 43 | U_BOOT_DRIVER(rockchip_uart) = { |
| 44 | .name = "rockchip_uart", |
Johan Jonker | e790316 | 2022-04-09 18:55:10 +0200 | [diff] [blame] | 45 | .id = UCLASS_SERIAL, |
Simon Glass | 119e7ef | 2020-12-22 19:30:18 -0700 | [diff] [blame] | 46 | .priv_auto = sizeof(struct ns16550), |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 47 | .plat_auto = sizeof(struct rockchip_uart_plat), |
Johan Jonker | e790316 | 2022-04-09 18:55:10 +0200 | [diff] [blame] | 48 | .probe = rockchip_serial_probe, |
| 49 | .ops = &ns16550_serial_ops, |
| 50 | .flags = DM_FLAG_PRE_RELOC, |
Simon Glass | b3068ad | 2016-07-04 11:58:24 -0600 | [diff] [blame] | 51 | }; |
Johan Jonker | d1c0eb9 | 2022-04-09 18:55:12 +0200 | [diff] [blame] | 52 | DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3066_uart) |
| 53 | DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3188_uart) |
| 54 | DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3288_uart) |
| 55 | DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3328_uart) |
| 56 | DM_DRIVER_ALIAS(rockchip_uart, rockchip_rk3368_uart) |