drivers/iio/adc/sd_adc_modulator.c

Source file repositories/reference/linux-study-clean/drivers/iio/adc/sd_adc_modulator.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/sd_adc_modulator.c
Extension
.c
Size
3873 bytes
Lines
164
Domain
Driver Families
Bucket
drivers/iio
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

struct iio_sd_backend_priv {
	struct regulator *vref;
	int vref_mv;
};

static int iio_sd_mod_enable(struct iio_backend *backend)
{
	struct iio_sd_backend_priv *priv = iio_backend_get_priv(backend);

	if (priv->vref)
		return regulator_enable(priv->vref);

	return 0;
};

static void iio_sd_mod_disable(struct iio_backend *backend)
{
	struct iio_sd_backend_priv *priv = iio_backend_get_priv(backend);

	if (priv->vref)
		regulator_disable(priv->vref);
};

static int iio_sd_mod_read(struct iio_backend *backend, struct iio_chan_spec const *chan, int *val,
			   int *val2, long mask)
{
	struct iio_sd_backend_priv *priv = iio_backend_get_priv(backend);

	switch (mask) {
	case IIO_CHAN_INFO_SCALE:
		*val = priv->vref_mv;
		return IIO_VAL_INT;

	case IIO_CHAN_INFO_OFFSET:
		*val = 0;
		return IIO_VAL_INT;
	}

	return -EOPNOTSUPP;
};

static const struct iio_backend_ops sd_backend_ops = {
	.enable = iio_sd_mod_enable,
	.disable = iio_sd_mod_disable,
	.read_raw = iio_sd_mod_read,
};

static const struct iio_backend_info sd_backend_info = {
	.name = "sd-modulator",
	.ops = &sd_backend_ops,
	.caps = IIO_BACKEND_CAP_ENABLE,
};

static int iio_sd_mod_register(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct iio_dev *iio;

	iio = devm_iio_device_alloc(dev, 0);
	if (!iio)
		return -ENOMEM;

	iio->name = dev_name(dev);
	iio->info = &iio_sd_mod_iio_info;
	iio->modes = INDIO_BUFFER_HARDWARE;

	iio->num_channels = 1;
	iio->channels = &iio_sd_mod_ch;

	platform_set_drvdata(pdev, iio);

	return devm_iio_device_register(&pdev->dev, iio);
}

static int iio_sd_mod_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct regulator *vref;
	struct iio_sd_backend_priv *priv;
	int ret;

	/* If sd modulator is not defined as an IIO backend device, fallback to legacy */
	if (!device_property_present(dev, "#io-backend-cells"))
		return iio_sd_mod_register(pdev);

	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	/*

Annotation

Implementation Notes