Message ID | 1467101897-15946-2-git-send-email-quentin.schulz@free-electrons.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hello Quentin! A few comments bellow: On Tue, Jun 28, 2016 at 10:18:15AM +0200, Quentin Schulz wrote: > > diff --git a/drivers/mfd/sunxi-gpadc-mfd.c b/drivers/mfd/sunxi-gpadc-mfd.c > new file mode 100644 > index 0000000..710e297 > --- /dev/null > +++ b/drivers/mfd/sunxi-gpadc-mfd.c > @@ -0,0 +1,188 @@ You should add a license statement here. > +#include <linux/interrupt.h> > +#include <linux/regmap.h> > +#include <linux/mfd/sunxi-gpadc-mfd.h> > +#include <linux/mfd/core.h> > +#include <linux/of_device.h> > +#include <linux/of_irq.h> > +#include <linux/kernel.h> > +#include <linux/module.h> Headers are usually included in the alphabetical order. [...] > diff --git a/include/linux/mfd/sunxi-gpadc-mfd.h b/include/linux/mfd/sunxi-gpadc-mfd.h > new file mode 100644 > index 0000000..341f8c3 > --- /dev/null > +++ b/include/linux/mfd/sunxi-gpadc-mfd.h > @@ -0,0 +1,14 @@ You should also add a license statement here. > +#ifndef __SUNXI_GPADC_MFD__H__ > +#define __SUNXI_GPADC_MFD__H__ > + > +#define TP_INT_FIFOC 0x10 > +#define TP_INT_FIFOS 0x14 > + > +struct sunxi_gpadc_mfd_dev { > + void __iomem *regs; > + struct device *dev; > + struct regmap *regmap; > + struct regmap_irq_chip_data *regmap_irqc; > +}; > + > +#endif Thanks! Antoine
Hello, On Tue, Jun 28, 2016 at 10:18:15AM +0200, Quentin Schulz wrote: > diff --git a/drivers/mfd/sunxi-gpadc-mfd.c b/drivers/mfd/sunxi-gpadc-mfd.c > new file mode 100644 > index 0000000..710e297 > --- /dev/null > +++ b/drivers/mfd/sunxi-gpadc-mfd.c > @@ -0,0 +1,188 @@ [...] > + if (of_device_is_compatible(pdev->dev.of_node, > + "allwinner,sun4i-a10-ts")) > + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, > + sun4i_gpadc_mfd_cells, > + ARRAY_SIZE(sun4i_gpadc_mfd_cells), NULL, > + 0, NULL); > + else if (of_device_is_compatible(pdev->dev.of_node, > + "allwinner,sun5i-a13-ts")) > + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, > + sun5i_gpadc_mfd_cells, > + ARRAY_SIZE(sun5i_gpadc_mfd_cells), NULL, > + 0, NULL); > + else if (of_device_is_compatible(pdev->dev.of_node, > + "allwinner,sun6i-a31-ts")) > + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, > + sun6i_gpadc_mfd_cells, > + ARRAY_SIZE(sun6i_gpadc_mfd_cells), NULL, > + 0, NULL); > + > + if (ret) { > + dev_err(&pdev->dev, "failed to add MFD devices: %d\n", ret); > + regmap_del_irq_chip(irq, sunxi_gpadc_mfd_dev->regmap_irqc); > + mfd_remove_devices(&pdev->dev); You don't need to explicitly call mfd_remove_devices() when mfd_add_devices() fails. See: http://lxr.free-electrons.com/source/drivers/mfd/mfd-core.c#L298 > + return ret; > + } Thanks, Antoine
On 28/06/16 09:18, Quentin Schulz wrote: > The Allwinner SoCs all have an ADC that can also act as a touchscreen > controller and a thermal sensor. For now, only the ADC and the thermal > sensor drivers are probed by the MFD, the touchscreen controller support > will be added later. > > Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com> The code looks fine to me. The 'controversial' bit of this is listing iio-hwmon as an mfd child to get it to probe as a result of this being present. My immediately thought is that it should be separately described in the devicetree and hence instantiated outside of this driver. Perhaps you could describe your reasoning for doing it this way? Thanks, Jonathan > --- > drivers/mfd/Kconfig | 14 +++ > drivers/mfd/Makefile | 2 + > drivers/mfd/sunxi-gpadc-mfd.c | 188 ++++++++++++++++++++++++++++++++++++ > include/linux/mfd/sunxi-gpadc-mfd.h | 14 +++ > 4 files changed, 218 insertions(+) > create mode 100644 drivers/mfd/sunxi-gpadc-mfd.c > create mode 100644 include/linux/mfd/sunxi-gpadc-mfd.h > > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig > index eea61e3..1663db9 100644 > --- a/drivers/mfd/Kconfig > +++ b/drivers/mfd/Kconfig > @@ -82,6 +82,20 @@ config MFD_ATMEL_FLEXCOM > by the probe function of this MFD driver according to a device tree > property. > > +config MFD_SUNXI_ADC > + tristate "ADC MFD core driver for sunxi platforms" > + select MFD_CORE > + select REGMAP_MMIO > + help > + Select this to get support for Allwinner SoCs (A10, A13 and A31) ADC. > + This driver will only map the hardware interrupt and registers, you > + have to select individual drivers based on this MFD to be able to use > + the ADC or the thermal sensor. This will try to probe the ADC driver > + sunxi-gpadc-iio and the hwmon driver iio_hwmon. > + > + To compile this driver as a module, choose M here: the > + module will be called sunxi-gpadc-mfd. > + > config MFD_ATMEL_HLCDC > tristate "Atmel HLCDC (High-end LCD Controller)" > select MFD_CORE > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > index 5eaa6465d..b280d0a 100644 > --- a/drivers/mfd/Makefile > +++ b/drivers/mfd/Makefile > @@ -199,6 +199,8 @@ obj-$(CONFIG_MFD_DLN2) += dln2.o > obj-$(CONFIG_MFD_RT5033) += rt5033.o > obj-$(CONFIG_MFD_SKY81452) += sky81452.o > > +obj-$(CONFIG_MFD_SUNXI_ADC) += sunxi-gpadc-mfd.o > + > intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o > intel-soc-pmic-$(CONFIG_INTEL_PMC_IPC) += intel_soc_pmic_bxtwc.o > obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o > diff --git a/drivers/mfd/sunxi-gpadc-mfd.c b/drivers/mfd/sunxi-gpadc-mfd.c > new file mode 100644 > index 0000000..710e297 > --- /dev/null > +++ b/drivers/mfd/sunxi-gpadc-mfd.c > @@ -0,0 +1,188 @@ > +#include <linux/interrupt.h> > +#include <linux/regmap.h> > +#include <linux/mfd/sunxi-gpadc-mfd.h> > +#include <linux/mfd/core.h> > +#include <linux/of_device.h> > +#include <linux/of_irq.h> > +#include <linux/kernel.h> > +#include <linux/module.h> > + > +#define SUNXI_IRQ_FIFO_DATA 0 > +#define SUNXI_IRQ_TEMP_DATA 1 > + > +static struct resource adc_resources[] = { > + { > + .name = "FIFO_DATA_PENDING", > + .start = SUNXI_IRQ_FIFO_DATA, > + .end = SUNXI_IRQ_FIFO_DATA, > + .flags = IORESOURCE_IRQ, > + }, { > + .name = "TEMP_DATA_PENDING", > + .start = SUNXI_IRQ_TEMP_DATA, > + .end = SUNXI_IRQ_TEMP_DATA, > + .flags = IORESOURCE_IRQ, > + }, > +}; > + > +static const struct regmap_irq sunxi_gpadc_mfd_regmap_irq[] = { > + REGMAP_IRQ_REG(SUNXI_IRQ_FIFO_DATA, 0, BIT(16)), > + REGMAP_IRQ_REG(SUNXI_IRQ_TEMP_DATA, 0, BIT(18)), > +}; > + > +static const struct regmap_irq_chip sunxi_gpadc_mfd_regmap_irq_chip = { > + .name = "sunxi_gpadc_mfd_irq_chip", > + .status_base = TP_INT_FIFOS, > + .ack_base = TP_INT_FIFOS, > + .mask_base = TP_INT_FIFOC, > + .init_ack_masked = true, > + .mask_invert = true, > + .irqs = sunxi_gpadc_mfd_regmap_irq, > + .num_irqs = ARRAY_SIZE(sunxi_gpadc_mfd_regmap_irq), > + .num_regs = 1, > +}; > + > +static struct mfd_cell sun4i_gpadc_mfd_cells[] = { > + { > + .name = "sun4i-a10-gpadc-iio", > + .resources = adc_resources, > + .num_resources = ARRAY_SIZE(adc_resources), > + }, { > + .name = "iio_hwmon", > + } > +}; > + > +static struct mfd_cell sun5i_gpadc_mfd_cells[] = { > + { > + .name = "sun5i-a13-gpadc-iio", > + .resources = adc_resources, > + .num_resources = ARRAY_SIZE(adc_resources), > + }, { > + .name = "iio_hwmon", > + }, > +}; > + > +static struct mfd_cell sun6i_gpadc_mfd_cells[] = { > + { > + .name = "sun6i-a31-gpadc-iio", > + .resources = adc_resources, > + .num_resources = ARRAY_SIZE(adc_resources), > + }, { > + .name = "iio_hwmon", Interesting to probe this as part of the mfd as opposed to separately describing it in the devicetree. > + }, > +}; > + > +static const struct regmap_config sunxi_gpadc_mfd_regmap_config = { > + .reg_bits = 32, > + .val_bits = 32, > + .reg_stride = 4, > + .fast_io = true, > +}; > + > +static int sunxi_gpadc_mfd_probe(struct platform_device *pdev) > +{ > + struct sunxi_gpadc_mfd_dev *sunxi_gpadc_mfd_dev = NULL; > + struct resource *mem = NULL; > + unsigned int irq; > + int ret; > + > + sunxi_gpadc_mfd_dev = devm_kzalloc(&pdev->dev, > + sizeof(*sunxi_gpadc_mfd_dev), > + GFP_KERNEL); > + if (!sunxi_gpadc_mfd_dev) > + return -ENOMEM; > + > + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + sunxi_gpadc_mfd_dev->regs = devm_ioremap_resource(&pdev->dev, mem); > + if (IS_ERR(sunxi_gpadc_mfd_dev->regs)) > + return PTR_ERR(sunxi_gpadc_mfd_dev->regs); > + > + sunxi_gpadc_mfd_dev->dev = &pdev->dev; > + dev_set_drvdata(sunxi_gpadc_mfd_dev->dev, sunxi_gpadc_mfd_dev); > + > + sunxi_gpadc_mfd_dev->regmap = > + devm_regmap_init_mmio(sunxi_gpadc_mfd_dev->dev, > + sunxi_gpadc_mfd_dev->regs, > + &sunxi_gpadc_mfd_regmap_config); > + if (IS_ERR(sunxi_gpadc_mfd_dev->regmap)) { > + ret = PTR_ERR(sunxi_gpadc_mfd_dev->regmap); > + dev_err(&pdev->dev, "failed to init regmap: %d\n", ret); > + return ret; > + } > + > + irq = platform_get_irq(pdev, 0); > + ret = regmap_add_irq_chip(sunxi_gpadc_mfd_dev->regmap, irq, > + IRQF_ONESHOT, 0, > + &sunxi_gpadc_mfd_regmap_irq_chip, > + &sunxi_gpadc_mfd_dev->regmap_irqc); > + if (ret) { > + dev_err(&pdev->dev, "failed to add irq chip: %d\n", ret); > + return ret; > + } > + > + if (of_device_is_compatible(pdev->dev.of_node, > + "allwinner,sun4i-a10-ts")) > + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, > + sun4i_gpadc_mfd_cells, > + ARRAY_SIZE(sun4i_gpadc_mfd_cells), NULL, > + 0, NULL); > + else if (of_device_is_compatible(pdev->dev.of_node, > + "allwinner,sun5i-a13-ts")) > + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, > + sun5i_gpadc_mfd_cells, > + ARRAY_SIZE(sun5i_gpadc_mfd_cells), NULL, > + 0, NULL); > + else if (of_device_is_compatible(pdev->dev.of_node, > + "allwinner,sun6i-a31-ts")) > + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, > + sun6i_gpadc_mfd_cells, > + ARRAY_SIZE(sun6i_gpadc_mfd_cells), NULL, > + 0, NULL); > + > + if (ret) { > + dev_err(&pdev->dev, "failed to add MFD devices: %d\n", ret); > + regmap_del_irq_chip(irq, sunxi_gpadc_mfd_dev->regmap_irqc); > + mfd_remove_devices(&pdev->dev); > + return ret; > + } > + > + dev_info(&pdev->dev, "successfully loaded\n"); > + > + return 0; > +} > + > +static int sunxi_gpadc_mfd_remove(struct platform_device *pdev) > +{ > + struct sunxi_gpadc_mfd_dev *sunxi_gpadc_mfd_dev; > + unsigned int irq; > + > + irq = platform_get_irq(pdev, 0); > + mfd_remove_devices(&pdev->dev); > + sunxi_gpadc_mfd_dev = dev_get_drvdata(&pdev->dev); > + regmap_del_irq_chip(irq, sunxi_gpadc_mfd_dev->regmap_irqc); > + > + return 0; > +} > + > +static const struct of_device_id sunxi_gpadc_mfd_of_match[] = { > + { .compatible = "allwinner,sun4i-a10-ts" }, > + { .compatible = "allwinner,sun5i-a13-ts" }, > + { .compatible = "allwinner,sun6i-a31-ts" }, > + { /* sentinel */ } > +}; > + > +MODULE_DEVICE_TABLE(of, sunxi_gpadc_mfd_of_match); > + > +static struct platform_driver sunxi_gpadc_mfd_driver = { > + .driver = { > + .name = "sunxi-adc-mfd", > + .of_match_table = of_match_ptr(sunxi_gpadc_mfd_of_match), > + }, > + .probe = sunxi_gpadc_mfd_probe, > + .remove = sunxi_gpadc_mfd_remove, > +}; > + > +module_platform_driver(sunxi_gpadc_mfd_driver); > + > +MODULE_DESCRIPTION("ADC MFD core driver for sunxi platforms"); > +MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>"); > +MODULE_LICENSE("GPL v2"); > diff --git a/include/linux/mfd/sunxi-gpadc-mfd.h b/include/linux/mfd/sunxi-gpadc-mfd.h > new file mode 100644 > index 0000000..341f8c3 > --- /dev/null > +++ b/include/linux/mfd/sunxi-gpadc-mfd.h > @@ -0,0 +1,14 @@ > +#ifndef __SUNXI_GPADC_MFD__H__ > +#define __SUNXI_GPADC_MFD__H__ > + > +#define TP_INT_FIFOC 0x10 > +#define TP_INT_FIFOS 0x14 > + > +struct sunxi_gpadc_mfd_dev { > + void __iomem *regs; > + struct device *dev; > + struct regmap *regmap; > + struct regmap_irq_chip_data *regmap_irqc; > +}; > + > +#endif >
On 07/03/2016 01:17 PM, Jonathan Cameron wrote: > On 28/06/16 09:18, Quentin Schulz wrote: >> The Allwinner SoCs all have an ADC that can also act as a touchscreen >> controller and a thermal sensor. For now, only the ADC and the thermal >> sensor drivers are probed by the MFD, the touchscreen controller support >> will be added later. >> >> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com> > The code looks fine to me. The 'controversial' bit of this is listing > iio-hwmon as an mfd child to get it to probe as a result of this being > present. My immediately thought is that it should be separately > described in the devicetree and hence instantiated outside of this driver. The devicetree is a generic description of the hardware. The iio-hwmon bridge is a software component that translates between two Linux specific ABIs. In my opinion putting the later in the former is makes no sense, it is simply not part of the hardware description. Its quite terrible that we have the bindings in the first place, but I guess we have to keep them considering they are ABI and there are existing users. But we should definitely strongly discourage the introduction of new users. It is policy whether an application wants to access a device using the IIO or hwmon API. As such it must be managed by userspace, this is not something that can be done using devicetree nor should it be something that is done on a driver by driver basis. - Lars
On 07/03/2016 09:49 AM, Lars-Peter Clausen wrote: > On 07/03/2016 01:17 PM, Jonathan Cameron wrote: >> On 28/06/16 09:18, Quentin Schulz wrote: >>> The Allwinner SoCs all have an ADC that can also act as a touchscreen >>> controller and a thermal sensor. For now, only the ADC and the thermal >>> sensor drivers are probed by the MFD, the touchscreen controller support >>> will be added later. >>> >>> Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com> >> The code looks fine to me. The 'controversial' bit of this is listing >> iio-hwmon as an mfd child to get it to probe as a result of this being >> present. My immediately thought is that it should be separately >> described in the devicetree and hence instantiated outside of this driver. > > The devicetree is a generic description of the hardware. The iio-hwmon > bridge is a software component that translates between two Linux specific > ABIs. In my opinion putting the later in the former is makes no sense, it is > simply not part of the hardware description. > Actually, this is where people get it wrong. > Its quite terrible that we have the bindings in the first place, but I guess > we have to keep them considering they are ABI and there are existing users. > But we should definitely strongly discourage the introduction of new users. > I do agree that the _bindings_ are bad. The ultimate problem is to find bindings which do describe the hardware in a way that would be acceptable to the devicetree community and is at the same time useful for software when trying to determine what to do with that hardware. _This_ is the exceptionally hard problem. One example would be an adc channel connected to a board voltage. I would assume that it should be permissible to describe this relationship in a way that can be _used_ by software to expose that adc channel as voltage, by whatever means necessary (it be through hwmon or as a regulator or whatever). Similar, some pin on a chip may be connected to a thermal sensor. I would assume that it should be permissible to describe that thermal sensor (and its location) in a way that can be _used_ by software in a meaningful way, either for it to be reported as hardware monitoring attribute or to be used by the thermal subsystem as a thermal input channel. In addition to that, there are various other properties which _do_ describe the hardware, but are commonly seen as "software". Examples for that would be voltage or temperature limits (or any other limits, for that matter). Such limits _are_ part of the hardware description, but are not commonly accepted as such. > It is policy whether an application wants to access a device using the IIO > or hwmon API. As such it must be managed by userspace, this is not something > that can be done using devicetree nor should it be something that is done on > a driver by driver basis. > Agreed. However, the connections from one chip to another, and the use of a chip on a board, _is_ part of the hardware description. It is determined by the schematics as well as the board layout. A well defined hardware description needs to provide more than "this is an ADC channel" or "this is a thermal sensor". Guenter
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index eea61e3..1663db9 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -82,6 +82,20 @@ config MFD_ATMEL_FLEXCOM by the probe function of this MFD driver according to a device tree property. +config MFD_SUNXI_ADC + tristate "ADC MFD core driver for sunxi platforms" + select MFD_CORE + select REGMAP_MMIO + help + Select this to get support for Allwinner SoCs (A10, A13 and A31) ADC. + This driver will only map the hardware interrupt and registers, you + have to select individual drivers based on this MFD to be able to use + the ADC or the thermal sensor. This will try to probe the ADC driver + sunxi-gpadc-iio and the hwmon driver iio_hwmon. + + To compile this driver as a module, choose M here: the + module will be called sunxi-gpadc-mfd. + config MFD_ATMEL_HLCDC tristate "Atmel HLCDC (High-end LCD Controller)" select MFD_CORE diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 5eaa6465d..b280d0a 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -199,6 +199,8 @@ obj-$(CONFIG_MFD_DLN2) += dln2.o obj-$(CONFIG_MFD_RT5033) += rt5033.o obj-$(CONFIG_MFD_SKY81452) += sky81452.o +obj-$(CONFIG_MFD_SUNXI_ADC) += sunxi-gpadc-mfd.o + intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o intel-soc-pmic-$(CONFIG_INTEL_PMC_IPC) += intel_soc_pmic_bxtwc.o obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o diff --git a/drivers/mfd/sunxi-gpadc-mfd.c b/drivers/mfd/sunxi-gpadc-mfd.c new file mode 100644 index 0000000..710e297 --- /dev/null +++ b/drivers/mfd/sunxi-gpadc-mfd.c @@ -0,0 +1,188 @@ +#include <linux/interrupt.h> +#include <linux/regmap.h> +#include <linux/mfd/sunxi-gpadc-mfd.h> +#include <linux/mfd/core.h> +#include <linux/of_device.h> +#include <linux/of_irq.h> +#include <linux/kernel.h> +#include <linux/module.h> + +#define SUNXI_IRQ_FIFO_DATA 0 +#define SUNXI_IRQ_TEMP_DATA 1 + +static struct resource adc_resources[] = { + { + .name = "FIFO_DATA_PENDING", + .start = SUNXI_IRQ_FIFO_DATA, + .end = SUNXI_IRQ_FIFO_DATA, + .flags = IORESOURCE_IRQ, + }, { + .name = "TEMP_DATA_PENDING", + .start = SUNXI_IRQ_TEMP_DATA, + .end = SUNXI_IRQ_TEMP_DATA, + .flags = IORESOURCE_IRQ, + }, +}; + +static const struct regmap_irq sunxi_gpadc_mfd_regmap_irq[] = { + REGMAP_IRQ_REG(SUNXI_IRQ_FIFO_DATA, 0, BIT(16)), + REGMAP_IRQ_REG(SUNXI_IRQ_TEMP_DATA, 0, BIT(18)), +}; + +static const struct regmap_irq_chip sunxi_gpadc_mfd_regmap_irq_chip = { + .name = "sunxi_gpadc_mfd_irq_chip", + .status_base = TP_INT_FIFOS, + .ack_base = TP_INT_FIFOS, + .mask_base = TP_INT_FIFOC, + .init_ack_masked = true, + .mask_invert = true, + .irqs = sunxi_gpadc_mfd_regmap_irq, + .num_irqs = ARRAY_SIZE(sunxi_gpadc_mfd_regmap_irq), + .num_regs = 1, +}; + +static struct mfd_cell sun4i_gpadc_mfd_cells[] = { + { + .name = "sun4i-a10-gpadc-iio", + .resources = adc_resources, + .num_resources = ARRAY_SIZE(adc_resources), + }, { + .name = "iio_hwmon", + } +}; + +static struct mfd_cell sun5i_gpadc_mfd_cells[] = { + { + .name = "sun5i-a13-gpadc-iio", + .resources = adc_resources, + .num_resources = ARRAY_SIZE(adc_resources), + }, { + .name = "iio_hwmon", + }, +}; + +static struct mfd_cell sun6i_gpadc_mfd_cells[] = { + { + .name = "sun6i-a31-gpadc-iio", + .resources = adc_resources, + .num_resources = ARRAY_SIZE(adc_resources), + }, { + .name = "iio_hwmon", + }, +}; + +static const struct regmap_config sunxi_gpadc_mfd_regmap_config = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = 4, + .fast_io = true, +}; + +static int sunxi_gpadc_mfd_probe(struct platform_device *pdev) +{ + struct sunxi_gpadc_mfd_dev *sunxi_gpadc_mfd_dev = NULL; + struct resource *mem = NULL; + unsigned int irq; + int ret; + + sunxi_gpadc_mfd_dev = devm_kzalloc(&pdev->dev, + sizeof(*sunxi_gpadc_mfd_dev), + GFP_KERNEL); + if (!sunxi_gpadc_mfd_dev) + return -ENOMEM; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + sunxi_gpadc_mfd_dev->regs = devm_ioremap_resource(&pdev->dev, mem); + if (IS_ERR(sunxi_gpadc_mfd_dev->regs)) + return PTR_ERR(sunxi_gpadc_mfd_dev->regs); + + sunxi_gpadc_mfd_dev->dev = &pdev->dev; + dev_set_drvdata(sunxi_gpadc_mfd_dev->dev, sunxi_gpadc_mfd_dev); + + sunxi_gpadc_mfd_dev->regmap = + devm_regmap_init_mmio(sunxi_gpadc_mfd_dev->dev, + sunxi_gpadc_mfd_dev->regs, + &sunxi_gpadc_mfd_regmap_config); + if (IS_ERR(sunxi_gpadc_mfd_dev->regmap)) { + ret = PTR_ERR(sunxi_gpadc_mfd_dev->regmap); + dev_err(&pdev->dev, "failed to init regmap: %d\n", ret); + return ret; + } + + irq = platform_get_irq(pdev, 0); + ret = regmap_add_irq_chip(sunxi_gpadc_mfd_dev->regmap, irq, + IRQF_ONESHOT, 0, + &sunxi_gpadc_mfd_regmap_irq_chip, + &sunxi_gpadc_mfd_dev->regmap_irqc); + if (ret) { + dev_err(&pdev->dev, "failed to add irq chip: %d\n", ret); + return ret; + } + + if (of_device_is_compatible(pdev->dev.of_node, + "allwinner,sun4i-a10-ts")) + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, + sun4i_gpadc_mfd_cells, + ARRAY_SIZE(sun4i_gpadc_mfd_cells), NULL, + 0, NULL); + else if (of_device_is_compatible(pdev->dev.of_node, + "allwinner,sun5i-a13-ts")) + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, + sun5i_gpadc_mfd_cells, + ARRAY_SIZE(sun5i_gpadc_mfd_cells), NULL, + 0, NULL); + else if (of_device_is_compatible(pdev->dev.of_node, + "allwinner,sun6i-a31-ts")) + ret = mfd_add_devices(sunxi_gpadc_mfd_dev->dev, 0, + sun6i_gpadc_mfd_cells, + ARRAY_SIZE(sun6i_gpadc_mfd_cells), NULL, + 0, NULL); + + if (ret) { + dev_err(&pdev->dev, "failed to add MFD devices: %d\n", ret); + regmap_del_irq_chip(irq, sunxi_gpadc_mfd_dev->regmap_irqc); + mfd_remove_devices(&pdev->dev); + return ret; + } + + dev_info(&pdev->dev, "successfully loaded\n"); + + return 0; +} + +static int sunxi_gpadc_mfd_remove(struct platform_device *pdev) +{ + struct sunxi_gpadc_mfd_dev *sunxi_gpadc_mfd_dev; + unsigned int irq; + + irq = platform_get_irq(pdev, 0); + mfd_remove_devices(&pdev->dev); + sunxi_gpadc_mfd_dev = dev_get_drvdata(&pdev->dev); + regmap_del_irq_chip(irq, sunxi_gpadc_mfd_dev->regmap_irqc); + + return 0; +} + +static const struct of_device_id sunxi_gpadc_mfd_of_match[] = { + { .compatible = "allwinner,sun4i-a10-ts" }, + { .compatible = "allwinner,sun5i-a13-ts" }, + { .compatible = "allwinner,sun6i-a31-ts" }, + { /* sentinel */ } +}; + +MODULE_DEVICE_TABLE(of, sunxi_gpadc_mfd_of_match); + +static struct platform_driver sunxi_gpadc_mfd_driver = { + .driver = { + .name = "sunxi-adc-mfd", + .of_match_table = of_match_ptr(sunxi_gpadc_mfd_of_match), + }, + .probe = sunxi_gpadc_mfd_probe, + .remove = sunxi_gpadc_mfd_remove, +}; + +module_platform_driver(sunxi_gpadc_mfd_driver); + +MODULE_DESCRIPTION("ADC MFD core driver for sunxi platforms"); +MODULE_AUTHOR("Quentin Schulz <quentin.schulz@free-electrons.com>"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/sunxi-gpadc-mfd.h b/include/linux/mfd/sunxi-gpadc-mfd.h new file mode 100644 index 0000000..341f8c3 --- /dev/null +++ b/include/linux/mfd/sunxi-gpadc-mfd.h @@ -0,0 +1,14 @@ +#ifndef __SUNXI_GPADC_MFD__H__ +#define __SUNXI_GPADC_MFD__H__ + +#define TP_INT_FIFOC 0x10 +#define TP_INT_FIFOS 0x14 + +struct sunxi_gpadc_mfd_dev { + void __iomem *regs; + struct device *dev; + struct regmap *regmap; + struct regmap_irq_chip_data *regmap_irqc; +}; + +#endif
The Allwinner SoCs all have an ADC that can also act as a touchscreen controller and a thermal sensor. For now, only the ADC and the thermal sensor drivers are probed by the MFD, the touchscreen controller support will be added later. Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com> --- drivers/mfd/Kconfig | 14 +++ drivers/mfd/Makefile | 2 + drivers/mfd/sunxi-gpadc-mfd.c | 188 ++++++++++++++++++++++++++++++++++++ include/linux/mfd/sunxi-gpadc-mfd.h | 14 +++ 4 files changed, 218 insertions(+) create mode 100644 drivers/mfd/sunxi-gpadc-mfd.c create mode 100644 include/linux/mfd/sunxi-gpadc-mfd.h