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>
8 #include <log.h>
9 #include <ns16550.h>
10 #include <serial.h>
11 #include <asm/arch/slimbootloader.h>
12 #include <asm/global_data.h>
13 
14 /**
15  * The serial port info hob is generated by Slim Bootloader, so eligible for
16  * Slim Bootloader based boards only.
17  */
slimbootloader_serial_of_to_plat(struct udevice * dev)18 static int slimbootloader_serial_of_to_plat(struct udevice *dev)
19 {
20 	const efi_guid_t guid = SBL_SERIAL_PORT_INFO_GUID;
21 	struct sbl_serial_port_info *data;
22 	struct ns16550_plat *plat = dev_get_plat(dev);
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 
39 	plat->base = data->base;
40 	/* ns16550 uses reg_shift, then covert stride to shift */
41 	plat->reg_shift = data->stride >> 1;
42 	plat->reg_width = data->stride;
43 	plat->clock = data->clk;
44 	plat->fcr = UART_FCR_DEFVAL;
45 	plat->flags = 0;
46 	if (data->type == 1)
47 		plat->flags |= NS16550_FLAG_IO;
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,
61 	.of_to_plat = slimbootloader_serial_of_to_plat,
62 	.plat_auto	= sizeof(struct ns16550_plat),
63 	.priv_auto	= sizeof(struct ns16550),
64 	.probe	= ns16550_serial_probe,
65 	.ops	= &ns16550_serial_ops,
66 };
67