Commit 75ed0be7 authored by Cristian Pop's avatar Cristian Pop Committed by Jonathan Cameron
Browse files

iio: adc: ad7768-1: Add channel labels.

parent 3079188f
Loading
Loading
Loading
Loading
+41 −0
Original line number Original line Diff line number Diff line
@@ -161,6 +161,7 @@ struct ad7768_state {
	struct completion completion;
	struct completion completion;
	struct iio_trigger *trig;
	struct iio_trigger *trig;
	struct gpio_desc *gpio_sync_in;
	struct gpio_desc *gpio_sync_in;
	const char *labels[ARRAY_SIZE(ad7768_channels)];
	/*
	/*
	 * DMA (thus cache coherency maintenance) requires the
	 * DMA (thus cache coherency maintenance) requires the
	 * transfer buffers to live in their own cache lines.
	 * transfer buffers to live in their own cache lines.
@@ -407,6 +408,14 @@ static int ad7768_write_raw(struct iio_dev *indio_dev,
	}
	}
}
}


static int ad7768_read_label(struct iio_dev *indio_dev,
	const struct iio_chan_spec *chan, char *label)
{
	struct ad7768_state *st = iio_priv(indio_dev);

	return sprintf(label, "%s\n", st->labels[chan->channel]);
}

static struct attribute *ad7768_attributes[] = {
static struct attribute *ad7768_attributes[] = {
	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
	&iio_dev_attr_sampling_frequency_available.dev_attr.attr,
	NULL
	NULL
@@ -420,6 +429,7 @@ static const struct iio_info ad7768_info = {
	.attrs = &ad7768_group,
	.attrs = &ad7768_group,
	.read_raw = &ad7768_read_raw,
	.read_raw = &ad7768_read_raw,
	.write_raw = &ad7768_write_raw,
	.write_raw = &ad7768_write_raw,
	.read_label = ad7768_read_label,
	.debugfs_reg_access = &ad7768_reg_access,
	.debugfs_reg_access = &ad7768_reg_access,
};
};


@@ -532,6 +542,33 @@ static void ad7768_clk_disable(void *data)
	clk_disable_unprepare(st->mclk);
	clk_disable_unprepare(st->mclk);
}
}


static int ad7768_set_channel_label(struct iio_dev *indio_dev,
						int num_channels)
{
	struct ad7768_state *st = iio_priv(indio_dev);
	struct device *device = indio_dev->dev.parent;
	struct fwnode_handle *fwnode;
	struct fwnode_handle *child;
	const char *label;
	int crt_ch = 0;

	fwnode = dev_fwnode(device);
	fwnode_for_each_child_node(fwnode, child) {
		if (fwnode_property_read_u32(child, "reg", &crt_ch))
			continue;

		if (crt_ch >= num_channels)
			continue;

		if (fwnode_property_read_string(child, "label", &label))
			continue;

		st->labels[crt_ch] = label;
	}

	return 0;
}

static int ad7768_probe(struct spi_device *spi)
static int ad7768_probe(struct spi_device *spi)
{
{
	struct ad7768_state *st;
	struct ad7768_state *st;
@@ -604,6 +641,10 @@ static int ad7768_probe(struct spi_device *spi)


	init_completion(&st->completion);
	init_completion(&st->completion);


	ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels));
	if (ret)
		return ret;

	ret = devm_request_irq(&spi->dev, spi->irq,
	ret = devm_request_irq(&spi->dev, spi->irq,
			       &ad7768_interrupt,
			       &ad7768_interrupt,
			       IRQF_TRIGGER_RISING | IRQF_ONESHOT,
			       IRQF_TRIGGER_RISING | IRQF_ONESHOT,