Skip to content

Commit 86a11f8

Browse files
author
Radu Pirea
committed
mfd: at91-usart: added mfd driver for usart
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> Acked-by: Rob Herring <robh@kernel.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-for-MFD-by: Lee Jones <lee.jones@linaro.org>
1 parent cbef03f commit 86a11f8

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

drivers/mfd/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ config MFD_AAT2870_CORE
8282
additional drivers must be enabled in order to use the
8383
functionality of the device.
8484

85+
config MFD_AT91_USART
86+
tristate "AT91 USART Driver"
87+
select MFD_CORE
88+
help
89+
Select this to get support for AT91 USART IP. This is a wrapper
90+
over at91-usart-serial driver and usart-spi-driver. Only one function
91+
can be used at a time. The choice is done at boot time by the probe
92+
function of this MFD driver according to a device tree property.
93+
8594
config MFD_ATMEL_FLEXCOM
8695
tristate "Atmel Flexcom (Flexible Serial Communication Unit)"
8796
select MFD_CORE

drivers/mfd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ obj-$(CONFIG_MFD_SPMI_PMIC) += qcom-spmi-pmic.o
178178
obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o
179179
obj-$(CONFIG_MFD_TPS65090) += tps65090.o
180180
obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o
181+
obj-$(CONFIG_MFD_AT91_USART) += at91-usart.o
181182
obj-$(CONFIG_MFD_ATMEL_FLEXCOM) += atmel-flexcom.o
182183
obj-$(CONFIG_MFD_ATMEL_HLCDC) += atmel-hlcdc.o
183184
obj-$(CONFIG_MFD_INTEL_LPSS) += intel-lpss.o

drivers/mfd/at91-usart.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Driver for AT91 USART
4+
*
5+
* Copyright (C) 2018 Microchip Technology
6+
*
7+
* Author: Radu Pirea <radu.pirea@microchip.com>
8+
*
9+
*/
10+
11+
#include <dt-bindings/mfd/at91-usart.h>
12+
13+
#include <linux/module.h>
14+
#include <linux/mfd/core.h>
15+
#include <linux/property.h>
16+
17+
static struct mfd_cell at91_usart_spi_subdev = {
18+
.name = "at91_usart_spi",
19+
.of_compatible = "microchip,at91sam9g45-usart-spi",
20+
};
21+
22+
static struct mfd_cell at91_usart_serial_subdev = {
23+
.name = "atmel_usart_serial",
24+
.of_compatible = "atmel,at91rm9200-usart-serial",
25+
};
26+
27+
static int at91_usart_mode_probe(struct platform_device *pdev)
28+
{
29+
struct mfd_cell cell;
30+
u32 opmode = AT91_USART_MODE_SERIAL;
31+
32+
device_property_read_u32(&pdev->dev, "atmel,usart-mode", &opmode);
33+
34+
switch (opmode) {
35+
case AT91_USART_MODE_SPI:
36+
cell = at91_usart_spi_subdev;
37+
break;
38+
case AT91_USART_MODE_SERIAL:
39+
cell = at91_usart_serial_subdev;
40+
break;
41+
default:
42+
dev_err(&pdev->dev, "atmel,usart-mode has an invalid value %u\n",
43+
opmode);
44+
return -EINVAL;
45+
}
46+
47+
return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO, &cell, 1,
48+
NULL, 0, NULL);
49+
}
50+
51+
static const struct of_device_id at91_usart_mode_of_match[] = {
52+
{ .compatible = "atmel,at91rm9200-usart" },
53+
{ .compatible = "atmel,at91sam9260-usart" },
54+
{ /* sentinel */ }
55+
};
56+
57+
MODULE_DEVICE_TABLE(of, at91_flexcom_of_match);
58+
59+
static struct platform_driver at91_usart_mfd = {
60+
.probe = at91_usart_mode_probe,
61+
.driver = {
62+
.name = "at91_usart_mode",
63+
.of_match_table = at91_usart_mode_of_match,
64+
},
65+
};
66+
67+
module_platform_driver(at91_usart_mfd);
68+
69+
MODULE_AUTHOR("Radu Pirea <radu.pirea@microchip.com>");
70+
MODULE_DESCRIPTION("AT91 USART MFD driver");
71+
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)