blob: d28b280890d36060902db7090f6366c6b9538653 [file] [log] [blame]
Park, Aiden1636d262019-08-03 08:30:44 +00001// 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 Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Park, Aiden1636d262019-08-03 08:30:44 +00009#include <ns16550.h>
10#include <serial.h>
11#include <asm/arch/slimbootloader.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Park, Aiden1636d262019-08-03 08:30:44 +000013
14/**
15 * The serial port info hob is generated by Slim Bootloader, so eligible for
16 * Slim Bootloader based boards only.
17 */
Simon Glassaad29ae2020-12-03 16:55:21 -070018static int slimbootloader_serial_of_to_plat(struct udevice *dev)
Park, Aiden1636d262019-08-03 08:30:44 +000019{
20 const efi_guid_t guid = SBL_SERIAL_PORT_INFO_GUID;
21 struct sbl_serial_port_info *data;
Simon Glass95588622020-12-22 19:30:28 -070022 struct ns16550_plat *plat = dev_get_plat(dev);
Park, Aiden1636d262019-08-03 08:30:44 +000023
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, Aiden1636d262019-08-03 08:30:44 +000039 plat->base = data->base;
40 /* ns16550 uses reg_shift, then covert stride to shift */
41 plat->reg_shift = data->stride >> 1;
Park, Aiden15a38b32019-12-18 05:56:23 +000042 plat->reg_width = data->stride;
Park, Aiden1636d262019-08-03 08:30:44 +000043 plat->clock = data->clk;
Park, Aiden15a38b32019-12-18 05:56:23 +000044 plat->fcr = UART_FCR_DEFVAL;
45 plat->flags = 0;
46 if (data->type == 1)
47 plat->flags |= NS16550_FLAG_IO;
Park, Aiden1636d262019-08-03 08:30:44 +000048
49 return 0;
50}
51
52static const struct udevice_id slimbootloader_serial_ids[] = {
53 { .compatible = "intel,slimbootloader-uart" },
54 {}
55};
56
57U_BOOT_DRIVER(serial_slimbootloader) = {
58 .name = "serial_slimbootloader",
59 .id = UCLASS_SERIAL,
60 .of_match = slimbootloader_serial_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -070061 .of_to_plat = slimbootloader_serial_of_to_plat,
Simon Glassb75b15b2020-12-03 16:55:23 -070062 .plat_auto = sizeof(struct ns16550_plat),
Simon Glass119e7ef2020-12-22 19:30:18 -070063 .priv_auto = sizeof(struct ns16550),
Park, Aiden1636d262019-08-03 08:30:44 +000064 .probe = ns16550_serial_probe,
65 .ops = &ns16550_serial_ops,
66};