blob: d28b280890d36060902db7090f6366c6b9538653 [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>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Park, Aiden2869c3b2019-08-03 08:30:44 +00009#include <ns16550.h>
10#include <serial.h>
11#include <asm/arch/slimbootloader.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Park, Aiden2869c3b2019-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 Glassd1998a92020-12-03 16:55:21 -070018static int slimbootloader_serial_of_to_plat(struct udevice *dev)
Park, Aiden2869c3b2019-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 Glass0fd3d912020-12-22 19:30:28 -070022 struct ns16550_plat *plat = dev_get_plat(dev);
Park, Aiden2869c3b2019-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, Aiden2869c3b2019-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, Aiden18416ba2019-12-18 05:56:23 +000042 plat->reg_width = data->stride;
Park, Aiden2869c3b2019-08-03 08:30:44 +000043 plat->clock = data->clk;
Park, Aiden18416ba2019-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, Aiden2869c3b2019-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 Glassd1998a92020-12-03 16:55:21 -070061 .of_to_plat = slimbootloader_serial_of_to_plat,
Simon Glass8a8d24b2020-12-03 16:55:23 -070062 .plat_auto = sizeof(struct ns16550_plat),
Simon Glassd30c7202020-12-22 19:30:18 -070063 .priv_auto = sizeof(struct ns16550),
Park, Aiden2869c3b2019-08-03 08:30:44 +000064 .probe = ns16550_serial_probe,
65 .ops = &ns16550_serial_ops,
66};