1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2019, Microchip Technology, Inc.
4 * Author: Eugen Hristev <eugen.hristev@microchip.com>
13 #include <linux/err.h>
15 struct microchip_flexcom_regs {
19 struct microchip_flexcom_platdata {
20 struct microchip_flexcom_regs *regs;
24 static int microchip_flexcom_ofdata_to_platdata(struct udevice *dev)
26 struct microchip_flexcom_platdata *plat = dev_get_platdata(dev);
29 plat->regs = map_physmem(dev_read_addr(dev),
30 sizeof(struct microchip_flexcom_regs),
33 ret = dev_read_u32(dev, "atmel,flexcom-mode", &plat->flexcom_mode);
35 if (IS_ERR_VALUE(ret)) {
36 debug("Missing atmel,flexcom-mode property\n");
41 * The mode must have only 2 bits. If any other bits are set,
42 * the value is not supported.
44 if (plat->flexcom_mode & 0xfffffffc) {
45 debug("Wrong atmel,flexcom-mode property\n");
49 writel(plat->flexcom_mode, &plat->regs->cr);
54 static const struct udevice_id microchip_flexcom_ids[] = {
55 { .compatible = "atmel,sama5d2-flexcom" },
56 { .compatible = "microchip,flexcom" },
60 U_BOOT_DRIVER(microchip_flexcom) = {
61 .name = "microchip_flexcom",
63 .of_match = microchip_flexcom_ids,
64 .ofdata_to_platdata = microchip_flexcom_ofdata_to_platdata,
65 .platdata_auto_alloc_size = sizeof(struct microchip_flexcom_platdata),