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