drivers/mfd/sun4i-gpadc.c

Source file repositories/reference/linux-study-clean/drivers/mfd/sun4i-gpadc.c

File Facts

System
Linux kernel
Corpus path
drivers/mfd/sun4i-gpadc.c
Extension
.c
Size
4415 bytes
Lines
175
Domain
Driver Families
Bucket
drivers/mfd
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/* ADC MFD core driver for sunxi platforms
 *
 * Copyright (c) 2016 Quentin Schulz <quentin.schulz@free-electrons.com>
 */

#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/mfd/core.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>

#include <linux/mfd/sun4i-gpadc.h>

#define ARCH_SUN4I_A10 0
#define ARCH_SUN5I_A13 1
#define ARCH_SUN6I_A31 2

static const struct resource adc_resources[] = {
	DEFINE_RES_IRQ_NAMED(SUN4I_GPADC_IRQ_FIFO_DATA, "FIFO_DATA_PENDING"),
	DEFINE_RES_IRQ_NAMED(SUN4I_GPADC_IRQ_TEMP_DATA, "TEMP_DATA_PENDING"),
};

static const struct regmap_irq sun4i_gpadc_regmap_irq[] = {
	REGMAP_IRQ_REG(SUN4I_GPADC_IRQ_FIFO_DATA, 0,
		       SUN4I_GPADC_INT_FIFOC_TP_DATA_IRQ_EN),
	REGMAP_IRQ_REG(SUN4I_GPADC_IRQ_TEMP_DATA, 0,
		       SUN4I_GPADC_INT_FIFOC_TEMP_IRQ_EN),
};

static const struct regmap_irq_chip sun4i_gpadc_regmap_irq_chip = {
	.name = "sun4i_gpadc_irq_chip",
	.status_base = SUN4I_GPADC_INT_FIFOS,
	.ack_base = SUN4I_GPADC_INT_FIFOS,
	.unmask_base = SUN4I_GPADC_INT_FIFOC,
	.init_ack_masked = true,
	.irqs = sun4i_gpadc_regmap_irq,
	.num_irqs = ARRAY_SIZE(sun4i_gpadc_regmap_irq),
	.num_regs = 1,
};

static struct mfd_cell sun4i_gpadc_cells[] = {
	{
		.name	= "sun4i-a10-gpadc-iio",
		.resources = adc_resources,
		.num_resources = ARRAY_SIZE(adc_resources),
	},
	{ .name = "iio_hwmon" }
};

static struct mfd_cell sun5i_gpadc_cells[] = {
	{
		.name	= "sun5i-a13-gpadc-iio",
		.resources = adc_resources,
		.num_resources = ARRAY_SIZE(adc_resources),
	},
	{ .name = "iio_hwmon" },
};

static struct mfd_cell sun6i_gpadc_cells[] = {
	{
		.name	= "sun6i-a31-gpadc-iio",
		.resources = adc_resources,
		.num_resources = ARRAY_SIZE(adc_resources),
	},
	{ .name = "iio_hwmon" },
};

static const struct regmap_config sun4i_gpadc_regmap_config = {
	.reg_bits = 32,
	.val_bits = 32,
	.reg_stride = 4,
};

static const struct of_device_id sun4i_gpadc_of_match[] = {
	{
		.compatible = "allwinner,sun4i-a10-ts",
		.data = (void *)ARCH_SUN4I_A10,
	}, {
		.compatible = "allwinner,sun5i-a13-ts",
		.data = (void *)ARCH_SUN5I_A13,
	}, {
		.compatible = "allwinner,sun6i-a31-ts",
		.data = (void *)ARCH_SUN6I_A31,
	}, { /* sentinel */ }
};

MODULE_DEVICE_TABLE(of, sun4i_gpadc_of_match);

Annotation

Implementation Notes