1
2
3
4
5
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
10#include <misc.h>
11#include <asm/io.h>
12
13struct microchip_flexcom_regs {
14 u32 cr;
15};
16
17struct microchip_flexcom_platdata {
18 struct microchip_flexcom_regs *regs;
19 u32 flexcom_mode;
20};
21
22static int microchip_flexcom_ofdata_to_platdata(struct udevice *dev)
23{
24 struct microchip_flexcom_platdata *plat = dev_get_platdata(dev);
25 int ret;
26
27 plat->regs = map_physmem(devfdt_get_addr(dev),
28 sizeof(struct microchip_flexcom_regs),
29 MAP_NOCACHE);
30
31 ret = dev_read_u32(dev, "atmel,flexcom-mode", &plat->flexcom_mode);
32
33 if (IS_ERR_VALUE(ret)) {
34 debug("Missing atmel,flexcom-mode property\n");
35 return ret;
36 }
37
38
39
40
41
42 if (plat->flexcom_mode & 0xfffffffc) {
43 debug("Wrong atmel,flexcom-mode property\n");
44 return -EINVAL;
45 }
46
47 writel(plat->flexcom_mode, &plat->regs->cr);
48
49 return 0;
50}
51
52static const struct udevice_id microchip_flexcom_ids[] = {
53 { .compatible = "atmel,sama5d2-flexcom" },
54 { .compatible = "microchip,flexcom" },
55 {}
56};
57
58U_BOOT_DRIVER(microchip_flexcom) = {
59 .name = "microchip_flexcom",
60 .id = UCLASS_MISC,
61 .of_match = microchip_flexcom_ids,
62 .ofdata_to_platdata = microchip_flexcom_ofdata_to_platdata,
63 .platdata_auto_alloc_size = sizeof(struct microchip_flexcom_platdata),
64};
65