max11100.c (a8e7e88df9ec1b7df2d12b6ee4ec48aee7b6aec7) max11100.c (ac2bec9d587c6a423a00c7a2d21a8a5928dfedf5)
1/*
2 * iio/adc/max11100.c
3 * Maxim max11100 ADC Driver with IIO interface
4 *
5 * Copyright (C) 2016-17 Renesas Electronics Corporation
6 * Copyright (C) 2016-17 Jacopo Mondi
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 16 unchanged lines hidden (view full) ---

25 * LSB is used to calculate analog voltage value
26 * from the number of ADC steps count
27 *
28 * Ain = (count * LSB)
29 */
30#define MAX11100_LSB_DIV (1 << 16)
31
32struct max11100_state {
1/*
2 * iio/adc/max11100.c
3 * Maxim max11100 ADC Driver with IIO interface
4 *
5 * Copyright (C) 2016-17 Renesas Electronics Corporation
6 * Copyright (C) 2016-17 Jacopo Mondi
7 *
8 * This program is free software; you can redistribute it and/or modify

--- 16 unchanged lines hidden (view full) ---

25 * LSB is used to calculate analog voltage value
26 * from the number of ADC steps count
27 *
28 * Ain = (count * LSB)
29 */
30#define MAX11100_LSB_DIV (1 << 16)
31
32struct max11100_state {
33 const struct max11100_chip_desc *desc;
34 struct regulator *vref_reg;
35 struct spi_device *spi;
36
37 /*
38 * DMA (thus cache coherency maintenance) requires the
39 * transfer buffers to live in their own cache lines.
40 */
41 u8 buffer[3] ____cacheline_aligned;
42};
43
44static struct iio_chan_spec max11100_channels[] = {
45 { /* [0] */
46 .type = IIO_VOLTAGE,
47 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
48 BIT(IIO_CHAN_INFO_SCALE),
49 },
50};
51
33 struct regulator *vref_reg;
34 struct spi_device *spi;
35
36 /*
37 * DMA (thus cache coherency maintenance) requires the
38 * transfer buffers to live in their own cache lines.
39 */
40 u8 buffer[3] ____cacheline_aligned;
41};
42
43static struct iio_chan_spec max11100_channels[] = {
44 { /* [0] */
45 .type = IIO_VOLTAGE,
46 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
47 BIT(IIO_CHAN_INFO_SCALE),
48 },
49};
50
52static struct max11100_chip_desc {
53 unsigned int num_chan;
54 const struct iio_chan_spec *channels;
55} max11100_desc = {
56 .num_chan = ARRAY_SIZE(max11100_channels),
57 .channels = max11100_channels,
58};
59
60static int max11100_read_single(struct iio_dev *indio_dev, int *val)
61{
62 int ret;
63 struct max11100_state *state = iio_priv(indio_dev);
64
65 ret = spi_read(state->spi, state->buffer, sizeof(state->buffer));
66 if (ret) {
67 dev_err(&indio_dev->dev, "SPI transfer failed\n");

--- 54 unchanged lines hidden (view full) ---

122 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*state));
123 if (!indio_dev)
124 return -ENOMEM;
125
126 spi_set_drvdata(spi, indio_dev);
127
128 state = iio_priv(indio_dev);
129 state->spi = spi;
51static int max11100_read_single(struct iio_dev *indio_dev, int *val)
52{
53 int ret;
54 struct max11100_state *state = iio_priv(indio_dev);
55
56 ret = spi_read(state->spi, state->buffer, sizeof(state->buffer));
57 if (ret) {
58 dev_err(&indio_dev->dev, "SPI transfer failed\n");

--- 54 unchanged lines hidden (view full) ---

113 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*state));
114 if (!indio_dev)
115 return -ENOMEM;
116
117 spi_set_drvdata(spi, indio_dev);
118
119 state = iio_priv(indio_dev);
120 state->spi = spi;
130 state->desc = &max11100_desc;
131
132 indio_dev->dev.parent = &spi->dev;
133 indio_dev->dev.of_node = spi->dev.of_node;
134 indio_dev->name = "max11100";
135 indio_dev->info = &max11100_info;
136 indio_dev->modes = INDIO_DIRECT_MODE;
121
122 indio_dev->dev.parent = &spi->dev;
123 indio_dev->dev.of_node = spi->dev.of_node;
124 indio_dev->name = "max11100";
125 indio_dev->info = &max11100_info;
126 indio_dev->modes = INDIO_DIRECT_MODE;
137 indio_dev->channels = state->desc->channels;
138 indio_dev->num_channels = state->desc->num_chan;
127 indio_dev->channels = max11100_channels,
128 indio_dev->num_channels = ARRAY_SIZE(max11100_channels),
139
140 state->vref_reg = devm_regulator_get(&spi->dev, "vref");
141 if (IS_ERR(state->vref_reg))
142 return PTR_ERR(state->vref_reg);
143
144 ret = regulator_enable(state->vref_reg);
145 if (ret)
146 return ret;

--- 10 unchanged lines hidden (view full) ---

157 return ret;
158}
159
160static int max11100_remove(struct spi_device *spi)
161{
162 struct iio_dev *indio_dev = spi_get_drvdata(spi);
163 struct max11100_state *state = iio_priv(indio_dev);
164
129
130 state->vref_reg = devm_regulator_get(&spi->dev, "vref");
131 if (IS_ERR(state->vref_reg))
132 return PTR_ERR(state->vref_reg);
133
134 ret = regulator_enable(state->vref_reg);
135 if (ret)
136 return ret;

--- 10 unchanged lines hidden (view full) ---

147 return ret;
148}
149
150static int max11100_remove(struct spi_device *spi)
151{
152 struct iio_dev *indio_dev = spi_get_drvdata(spi);
153 struct max11100_state *state = iio_priv(indio_dev);
154
155 iio_device_unregister(indio_dev);
165 regulator_disable(state->vref_reg);
166
156 regulator_disable(state->vref_reg);
157
167 iio_device_unregister(indio_dev);
168
169 return 0;
170}
171
172static const struct of_device_id max11100_ids[] = {
173 {.compatible = "maxim,max11100"},
174 { },
175};
176MODULE_DEVICE_TABLE(of, max11100_ids);

--- 16 unchanged lines hidden ---
158 return 0;
159}
160
161static const struct of_device_id max11100_ids[] = {
162 {.compatible = "maxim,max11100"},
163 { },
164};
165MODULE_DEVICE_TABLE(of, max11100_ids);

--- 16 unchanged lines hidden ---