Simon Glass | 4d22107 | 2019-12-19 17:58:20 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * UART support for U-Boot when launched from Coreboot |
| 4 | * |
| 5 | * Copyright 2019 Google LLC |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <ns16550.h> |
| 11 | #include <serial.h> |
Simon Glass | 9a01fd9 | 2021-03-15 18:00:18 +1300 | [diff] [blame] | 12 | #include <asm/cb_sysinfo.h> |
Simon Glass | 4d22107 | 2019-12-19 17:58:20 -0700 | [diff] [blame] | 13 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 14 | static int coreboot_of_to_plat(struct udevice *dev) |
Simon Glass | 4d22107 | 2019-12-19 17:58:20 -0700 | [diff] [blame] | 15 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 16 | struct ns16550_plat *plat = dev_get_plat(dev); |
Simon Glass | 4d22107 | 2019-12-19 17:58:20 -0700 | [diff] [blame] | 17 | struct cb_serial *cb_info = lib_sysinfo.serial; |
| 18 | |
| 19 | plat->base = cb_info->baseaddr; |
| 20 | plat->reg_shift = cb_info->regwidth == 4 ? 2 : 0; |
| 21 | plat->reg_width = cb_info->regwidth; |
| 22 | plat->clock = cb_info->input_hertz; |
| 23 | plat->fcr = UART_FCR_DEFVAL; |
| 24 | plat->flags = 0; |
| 25 | if (cb_info->type == CB_SERIAL_TYPE_IO_MAPPED) |
| 26 | plat->flags |= NS16550_FLAG_IO; |
| 27 | |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static const struct udevice_id coreboot_serial_ids[] = { |
| 32 | { .compatible = "coreboot-serial" }, |
| 33 | { }, |
| 34 | }; |
| 35 | |
| 36 | U_BOOT_DRIVER(coreboot_uart) = { |
| 37 | .name = "coreboot_uart", |
| 38 | .id = UCLASS_SERIAL, |
| 39 | .of_match = coreboot_serial_ids, |
Simon Glass | 119e7ef | 2020-12-22 19:30:18 -0700 | [diff] [blame] | 40 | .priv_auto = sizeof(struct ns16550), |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 41 | .plat_auto = sizeof(struct ns16550_plat), |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 42 | .of_to_plat = coreboot_of_to_plat, |
Simon Glass | 4d22107 | 2019-12-19 17:58:20 -0700 | [diff] [blame] | 43 | .probe = ns16550_serial_probe, |
| 44 | .ops = &ns16550_serial_ops, |
| 45 | .flags = DM_FLAG_PRE_RELOC, |
| 46 | }; |