Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2019 Intel Corporation <www.intel.com> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 9 | #include <ns16550.h> |
| 10 | #include <serial.h> |
| 11 | #include <asm/arch/slimbootloader.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * The serial port info hob is generated by Slim Bootloader, so eligible for |
| 16 | * Slim Bootloader based boards only. |
| 17 | */ |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 18 | static int slimbootloader_serial_of_to_plat(struct udevice *dev) |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 19 | { |
| 20 | const efi_guid_t guid = SBL_SERIAL_PORT_INFO_GUID; |
| 21 | struct sbl_serial_port_info *data; |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 22 | struct ns16550_plat *plat = dev_get_plat(dev); |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 23 | |
| 24 | if (!gd->arch.hob_list) |
| 25 | panic("hob list not found!"); |
| 26 | |
| 27 | data = hob_get_guid_hob_data(gd->arch.hob_list, NULL, &guid); |
| 28 | if (!data) { |
| 29 | debug("failed to get serial port information\n"); |
| 30 | return -ENOENT; |
| 31 | } |
| 32 | debug("type:%d base=0x%08x baudrate=%d stride=%d clk=%d\n", |
| 33 | data->type, |
| 34 | data->base, |
| 35 | data->baud, |
| 36 | data->stride, |
| 37 | data->clk); |
| 38 | |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 39 | plat->base = data->base; |
| 40 | /* ns16550 uses reg_shift, then covert stride to shift */ |
| 41 | plat->reg_shift = data->stride >> 1; |
Park, Aiden | 18416ba | 2019-12-18 05:56:23 +0000 | [diff] [blame] | 42 | plat->reg_width = data->stride; |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 43 | plat->clock = data->clk; |
Park, Aiden | 18416ba | 2019-12-18 05:56:23 +0000 | [diff] [blame] | 44 | plat->fcr = UART_FCR_DEFVAL; |
| 45 | plat->flags = 0; |
| 46 | if (data->type == 1) |
| 47 | plat->flags |= NS16550_FLAG_IO; |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static const struct udevice_id slimbootloader_serial_ids[] = { |
| 53 | { .compatible = "intel,slimbootloader-uart" }, |
| 54 | {} |
| 55 | }; |
| 56 | |
| 57 | U_BOOT_DRIVER(serial_slimbootloader) = { |
| 58 | .name = "serial_slimbootloader", |
| 59 | .id = UCLASS_SERIAL, |
| 60 | .of_match = slimbootloader_serial_ids, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 61 | .of_to_plat = slimbootloader_serial_of_to_plat, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 62 | .plat_auto = sizeof(struct ns16550_plat), |
Simon Glass | d30c720 | 2020-12-22 19:30:18 -0700 | [diff] [blame] | 63 | .priv_auto = sizeof(struct ns16550), |
Park, Aiden | 2869c3b | 2019-08-03 08:30:44 +0000 | [diff] [blame] | 64 | .probe = ns16550_serial_probe, |
| 65 | .ops = &ns16550_serial_ops, |
| 66 | }; |