diff mbox series

[U-Boot,1/6] misc: microchip_flexcom: introduce microchip_flexcom driver

Message ID 1570612670-29333-1-git-send-email-eugen.hristev@microchip.com
State Accepted
Commit f81649586df766083c987bfa6ea72547fc5acb7e
Delegated to: Eugen Hristev
Headers show
Series [U-Boot,1/6] misc: microchip_flexcom: introduce microchip_flexcom driver | expand

Commit Message

Eugen Hristev Oct. 9, 2019, 9:23 a.m. UTC
From: Eugen Hristev <eugen.hristev@microchip.com>

The Microchip Flexcom is just a wrapper which embeds a SPI controller,
an I2C controller and an USART.
Only one function can be used at a time and is chosen at boot time according
to the device tree.
The bindings are kept as in Linux.
The driver registers to MISC_UCLASS.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
---
 drivers/misc/Kconfig             |  9 ++++++
 drivers/misc/Makefile            |  1 +
 drivers/misc/microchip_flexcom.c | 64 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 drivers/misc/microchip_flexcom.c

Comments

Eugen Hristev Oct. 24, 2019, 10:12 a.m. UTC | #1
On 09.10.2019 12:23, Eugen Hristev - M18282 wrote:
> From: Eugen Hristev <eugen.hristev@microchip.com>
> 
> The Microchip Flexcom is just a wrapper which embeds a SPI controller,
> an I2C controller and an USART.
> Only one function can be used at a time and is chosen at boot time according
> to the device tree.
> The bindings are kept as in Linux.
> The driver registers to MISC_UCLASS.
> 
> Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>

Applied to u-boot-atmel/master
diff mbox series

Patch

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 8037b6e..8b757c0 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -412,4 +412,13 @@  config IHS_FPGA
 	  by the devices. This driver supports both CON and CPU variants of the
 	  devices, depending on the device tree entry.
 
+config MICROCHIP_FLEXCOM
+	bool "Enable Microchip Flexcom driver"
+	depends on MISC
+	help
+	  The Atmel Flexcom is just a wrapper which embeds a SPI controller,
+	  an I2C controller and an USART.
+	  Only one function can be used at a time and is chosen at boot time
+	  according to the device tree.
+
 endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 509c588..56d5a7a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -65,3 +65,4 @@  obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
 obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o
 obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
 obj-$(CONFIG_JZ4780_EFUSE) += jz4780_efuse.o
+obj-$(CONFIG_MICROCHIP_FLEXCOM) += microchip_flexcom.o
diff --git a/drivers/misc/microchip_flexcom.c b/drivers/misc/microchip_flexcom.c
new file mode 100644
index 0000000..1bc19ed
--- /dev/null
+++ b/drivers/misc/microchip_flexcom.c
@@ -0,0 +1,64 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019, Microchip Technology, Inc.
+ * Author: Eugen Hristev <eugen.hristev@microchip.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <misc.h>
+#include <asm/io.h>
+
+struct microchip_flexcom_regs {
+	u32 cr;
+};
+
+struct microchip_flexcom_platdata {
+	struct microchip_flexcom_regs *regs;
+	u32 flexcom_mode;
+};
+
+static int microchip_flexcom_ofdata_to_platdata(struct udevice *dev)
+{
+	struct microchip_flexcom_platdata *plat = dev_get_platdata(dev);
+	int ret;
+
+	plat->regs = map_physmem(devfdt_get_addr(dev),
+				 sizeof(struct microchip_flexcom_regs),
+				MAP_NOCACHE);
+
+	ret = dev_read_u32(dev, "atmel,flexcom-mode", &plat->flexcom_mode);
+
+	if (IS_ERR_VALUE(ret)) {
+		debug("Missing atmel,flexcom-mode property\n");
+		return ret;
+	}
+
+	/*
+	 * The mode must have only 2 bits. If any other bits are set,
+	 * the value is not supported.
+	 */
+	if (plat->flexcom_mode & 0xfffffffc) {
+		debug("Wrong atmel,flexcom-mode property\n");
+		return -EINVAL;
+	}
+
+	writel(plat->flexcom_mode, &plat->regs->cr);
+
+	return 0;
+}
+
+static const struct udevice_id microchip_flexcom_ids[] = {
+	{ .compatible = "atmel,sama5d2-flexcom" },
+	{ .compatible = "microchip,flexcom" },
+	{}
+};
+
+U_BOOT_DRIVER(microchip_flexcom) = {
+	.name	= "microchip_flexcom",
+	.id	= UCLASS_MISC,
+	.of_match = microchip_flexcom_ids,
+	.ofdata_to_platdata = microchip_flexcom_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct microchip_flexcom_platdata),
+};