]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
mfd: at91-usart: Add MFD driver for USART
authorRadu Pirea <radu.pirea@microchip.com>
Fri, 13 Jul 2018 16:47:33 +0000 (19:47 +0300)
committerLee Jones <lee.jones@linaro.org>
Mon, 10 Sep 2018 15:07:24 +0000 (16:07 +0100)
This MFD driver is just a wrapper over atmel_serial driver and
spi-at91-usart driver. Selection of one of the drivers is based on a
property from device tree. If the property is not specified, the default
driver is atmel_serial.

Signed-off-by: Radu Pirea <radu.pirea@microchip.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: Rob Herring <robh@kernel.org>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
drivers/mfd/Kconfig
drivers/mfd/Makefile
drivers/mfd/at91-usart.c [new file with mode: 0644]

index 11841f4b7b2ba4c9f1fe845fdf1c8daaf4e539ae..0b79c5d04cc9f6d517ca3de5f0e5620442fba423 100644 (file)
@@ -99,6 +99,15 @@ config MFD_AAT2870_CORE
          additional drivers must be enabled in order to use the
          functionality of the device.
 
+config MFD_AT91_USART
+       tristate "AT91 USART Driver"
+       select MFD_CORE
+       help
+         Select this to get support for AT91 USART IP. This is a wrapper
+         over at91-usart-serial driver and usart-spi-driver. Only one function
+         can be used at a time. The choice is done at boot time by the probe
+         function of this MFD driver according to a device tree property.
+
 config MFD_ATMEL_FLEXCOM
        tristate "Atmel Flexcom (Flexible Serial Communication Unit)"
        select MFD_CORE
index 5856a9489cbd83157025004c05fae2b341e2b51f..12980a4ad46080b3e510ccd237a421c4bde8325c 100644 (file)
@@ -196,6 +196,7 @@ obj-$(CONFIG_MFD_SPMI_PMIC) += qcom-spmi-pmic.o
 obj-$(CONFIG_TPS65911_COMPARATOR)      += tps65911-comparator.o
 obj-$(CONFIG_MFD_TPS65090)     += tps65090.o
 obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o
+obj-$(CONFIG_MFD_AT91_USART)   += at91-usart.o
 obj-$(CONFIG_MFD_ATMEL_FLEXCOM)        += atmel-flexcom.o
 obj-$(CONFIG_MFD_ATMEL_HLCDC)  += atmel-hlcdc.o
 obj-$(CONFIG_MFD_ATMEL_SMC)    += atmel-smc.o
diff --git a/drivers/mfd/at91-usart.c b/drivers/mfd/at91-usart.c
new file mode 100644 (file)
index 0000000..a4b9929
--- /dev/null
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for AT91 USART
+ *
+ * Copyright (C) 2018 Microchip Technology
+ *
+ * Author: Radu Pirea <radu.pirea@microchip.com>
+ *
+ */
+
+#include <dt-bindings/mfd/at91-usart.h>
+
+#include <linux/module.h>
+#include <linux/mfd/core.h>
+#include <linux/property.h>
+
+static struct mfd_cell at91_usart_spi_subdev = {
+               .name = "at91_usart_spi",
+               .of_compatible = "microchip,at91sam9g45-usart-spi",
+       };
+
+static struct mfd_cell at91_usart_serial_subdev = {
+               .name = "atmel_usart_serial",
+               .of_compatible = "atmel,at91rm9200-usart-serial",
+       };
+
+static int at91_usart_mode_probe(struct platform_device *pdev)
+{
+       struct mfd_cell cell;
+       u32 opmode = AT91_USART_MODE_SERIAL;
+
+       device_property_read_u32(&pdev->dev, "atmel,usart-mode", &opmode);
+
+       switch (opmode) {
+       case AT91_USART_MODE_SPI:
+               cell = at91_usart_spi_subdev;
+               break;
+       case AT91_USART_MODE_SERIAL:
+               cell = at91_usart_serial_subdev;
+               break;
+       default:
+               dev_err(&pdev->dev, "atmel,usart-mode has an invalid value %u\n",
+                       opmode);
+               return -EINVAL;
+       }
+
+       return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, &cell, 1,
+                             NULL, 0, NULL);
+}
+
+static const struct of_device_id at91_usart_mode_of_match[] = {
+       { .compatible = "atmel,at91rm9200-usart" },
+       { .compatible = "atmel,at91sam9260-usart" },
+       { /* sentinel */ }
+};
+
+MODULE_DEVICE_TABLE(of, at91_usart_mode_of_match);
+
+static struct platform_driver at91_usart_mfd = {
+       .probe  = at91_usart_mode_probe,
+       .driver = {
+               .name           = "at91_usart_mode",
+               .of_match_table = at91_usart_mode_of_match,
+       },
+};
+
+module_platform_driver(at91_usart_mfd);
+
+MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>");
+MODULE_DESCRIPTION("AT91 USART MFD driver");
+MODULE_LICENSE("GPL v2");