aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Fiol <antonio@fiol.es>2015-03-28 04:07:14 -0400
committerJonathan Cameron <jic23@kernel.org>2015-03-28 06:57:34 -0400
commita878a1a61a1f0e4b23602ddd87b1408a7a748d0e (patch)
tree5e6da606d28aa24f012bb5b3dcbe6b22b66b9074
parent7253606d383954c5b0470b5f27fbcedeec2e6d72 (diff)
iio: max517: Add support for MAX520 and MAX521 chips.
MAX520 and MAX521 are protocol-compatible with the already supported chips, just have more channels. Signed-off-by: Antonio Fiol <antonio@fiol.es> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/dac/Kconfig11
-rw-r--r--drivers/iio/dac/max517.c45
-rw-r--r--include/linux/iio/dac/max517.h2
3 files changed, 42 insertions, 16 deletions
diff --git a/drivers/iio/dac/Kconfig b/drivers/iio/dac/Kconfig
index 2236ea22f98a..13471a76e5bf 100644
--- a/drivers/iio/dac/Kconfig
+++ b/drivers/iio/dac/Kconfig
@@ -143,11 +143,16 @@ config AD7303
143 ad7303. 143 ad7303.
144 144
145config MAX517 145config MAX517
146 tristate "Maxim MAX517/518/519 DAC driver" 146 tristate "Maxim MAX517/518/519/520/521 DAC driver"
147 depends on I2C 147 depends on I2C
148 help 148 help
149 If you say yes here you get support for the Maxim chips MAX517, 149 If you say yes here you get support for the following Maxim chips
150 MAX518 and MAX519 (I2C 8-Bit DACs with rail-to-rail outputs). 150 (I2C 8-Bit DACs with rail-to-rail outputs):
151 MAX517 - Single channel, single reference
152 MAX518 - Dual channel, ref=Vdd
153 MAX519 - Dual channel, dual reference
154 MAX520 - Quad channel, quad reference
155 MAX521 - Octal channel, independent ref for ch0-3, shared ref for ch4-7
151 156
152 This driver can also be built as a module. If so, the module 157 This driver can also be built as a module. If so, the module
153 will be called max517. 158 will be called max517.
diff --git a/drivers/iio/dac/max517.c b/drivers/iio/dac/max517.c
index 9a82a7255ebb..5507b3970b4b 100644
--- a/drivers/iio/dac/max517.c
+++ b/drivers/iio/dac/max517.c
@@ -39,11 +39,13 @@ enum max517_device_ids {
39 ID_MAX517, 39 ID_MAX517,
40 ID_MAX518, 40 ID_MAX518,
41 ID_MAX519, 41 ID_MAX519,
42 ID_MAX520,
43 ID_MAX521,
42}; 44};
43 45
44struct max517_data { 46struct max517_data {
45 struct i2c_client *client; 47 struct i2c_client *client;
46 unsigned short vref_mv[2]; 48 unsigned short vref_mv[8];
47}; 49};
48 50
49/* 51/*
@@ -149,7 +151,13 @@ static const struct iio_info max517_info = {
149 151
150static const struct iio_chan_spec max517_channels[] = { 152static const struct iio_chan_spec max517_channels[] = {
151 MAX517_CHANNEL(0), 153 MAX517_CHANNEL(0),
152 MAX517_CHANNEL(1) 154 MAX517_CHANNEL(1),
155 MAX517_CHANNEL(2),
156 MAX517_CHANNEL(3),
157 MAX517_CHANNEL(4),
158 MAX517_CHANNEL(5),
159 MAX517_CHANNEL(6),
160 MAX517_CHANNEL(7),
153}; 161};
154 162
155static int max517_probe(struct i2c_client *client, 163static int max517_probe(struct i2c_client *client,
@@ -158,6 +166,7 @@ static int max517_probe(struct i2c_client *client,
158 struct max517_data *data; 166 struct max517_data *data;
159 struct iio_dev *indio_dev; 167 struct iio_dev *indio_dev;
160 struct max517_platform_data *platform_data = client->dev.platform_data; 168 struct max517_platform_data *platform_data = client->dev.platform_data;
169 int chan;
161 170
162 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 171 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
163 if (!indio_dev) 172 if (!indio_dev)
@@ -169,11 +178,21 @@ static int max517_probe(struct i2c_client *client,
169 /* establish that the iio_dev is a child of the i2c device */ 178 /* establish that the iio_dev is a child of the i2c device */
170 indio_dev->dev.parent = &client->dev; 179 indio_dev->dev.parent = &client->dev;
171 180
172 /* reduced channel set for MAX517 */ 181 switch (id->driver_data) {
173 if (id->driver_data == ID_MAX517) 182 case ID_MAX521:
174 indio_dev->num_channels = 1; 183 indio_dev->num_channels = 8;
175 else 184 break;
185 case ID_MAX520:
186 indio_dev->num_channels = 4;
187 break;
188 case ID_MAX519:
189 case ID_MAX518:
176 indio_dev->num_channels = 2; 190 indio_dev->num_channels = 2;
191 break;
192 default: /* single channel for MAX517 */
193 indio_dev->num_channels = 1;
194 break;
195 }
177 indio_dev->channels = max517_channels; 196 indio_dev->channels = max517_channels;
178 indio_dev->modes = INDIO_DIRECT_MODE; 197 indio_dev->modes = INDIO_DIRECT_MODE;
179 indio_dev->info = &max517_info; 198 indio_dev->info = &max517_info;
@@ -182,11 +201,11 @@ static int max517_probe(struct i2c_client *client,
182 * Reference voltage on MAX518 and default is 5V, else take vref_mv 201 * Reference voltage on MAX518 and default is 5V, else take vref_mv
183 * from platform_data 202 * from platform_data
184 */ 203 */
185 if (id->driver_data == ID_MAX518 || !platform_data) { 204 for (chan = 0; chan < indio_dev->num_channels; chan++) {
186 data->vref_mv[0] = data->vref_mv[1] = 5000; /* mV */ 205 if (id->driver_data == ID_MAX518 || !platform_data)
187 } else { 206 data->vref_mv[chan] = 5000; /* mV */
188 data->vref_mv[0] = platform_data->vref_mv[0]; 207 else
189 data->vref_mv[1] = platform_data->vref_mv[1]; 208 data->vref_mv[chan] = platform_data->vref_mv[chan];
190 } 209 }
191 210
192 return iio_device_register(indio_dev); 211 return iio_device_register(indio_dev);
@@ -202,6 +221,8 @@ static const struct i2c_device_id max517_id[] = {
202 { "max517", ID_MAX517 }, 221 { "max517", ID_MAX517 },
203 { "max518", ID_MAX518 }, 222 { "max518", ID_MAX518 },
204 { "max519", ID_MAX519 }, 223 { "max519", ID_MAX519 },
224 { "max520", ID_MAX520 },
225 { "max521", ID_MAX521 },
205 { } 226 { }
206}; 227};
207MODULE_DEVICE_TABLE(i2c, max517_id); 228MODULE_DEVICE_TABLE(i2c, max517_id);
@@ -218,5 +239,5 @@ static struct i2c_driver max517_driver = {
218module_i2c_driver(max517_driver); 239module_i2c_driver(max517_driver);
219 240
220MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); 241MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
221MODULE_DESCRIPTION("MAX517/MAX518/MAX519 8-bit DAC"); 242MODULE_DESCRIPTION("MAX517/518/519/520/521 8-bit DAC");
222MODULE_LICENSE("GPL"); 243MODULE_LICENSE("GPL");
diff --git a/include/linux/iio/dac/max517.h b/include/linux/iio/dac/max517.h
index f6d1d252f08d..7668716cd73c 100644
--- a/include/linux/iio/dac/max517.h
+++ b/include/linux/iio/dac/max517.h
@@ -9,7 +9,7 @@
9#define IIO_DAC_MAX517_H_ 9#define IIO_DAC_MAX517_H_
10 10
11struct max517_platform_data { 11struct max517_platform_data {
12 u16 vref_mv[2]; 12 u16 vref_mv[8];
13}; 13};
14 14
15#endif /* IIO_DAC_MAX517_H_ */ 15#endif /* IIO_DAC_MAX517_H_ */