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