• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <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  */
slimbootloader_serial_ofdata_to_platdata(struct udevice * dev)16 static 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 
37 	/*
38 	 * The data->type provides port io or mmio access type info,
39 	 * but the access type will be controlled by
40 	 * CONFIG_SYS_NS16550_PORT_MAPPED or CONFIG_SYS_NS16550_MEM32.
41 	 *
42 	 * TBD: ns16550 access type configuration in runtime.
43 	 *      ex) plat->access_type = data->type
44 	 */
45 	plat->base = data->base;
46 	/* ns16550 uses reg_shift, then covert stride to shift */
47 	plat->reg_shift = data->stride >> 1;
48 	plat->clock = data->clk;
49 
50 	return 0;
51 }
52 
53 static const struct udevice_id slimbootloader_serial_ids[] = {
54 	{ .compatible = "intel,slimbootloader-uart" },
55 	{}
56 };
57 
58 U_BOOT_DRIVER(serial_slimbootloader) = {
59 	.name	= "serial_slimbootloader",
60 	.id	= UCLASS_SERIAL,
61 	.of_match = slimbootloader_serial_ids,
62 	.ofdata_to_platdata = slimbootloader_serial_ofdata_to_platdata,
63 	.platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
64 	.priv_auto_alloc_size = sizeof(struct NS16550),
65 	.probe	= ns16550_serial_probe,
66 	.ops	= &ns16550_serial_ops,
67 };
68