Commit 040b837e718408436b79c2aaf68ed86b09682af4

Authored by Jonathan Cameron
1 parent 7611294799

iio:dac:max517 move to info_mask_(shared_by_type/separate)

The original info_mask is going away in favour of the broken out versions.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
cc: Roland Stigge <stigge@antcom.de>

Showing 1 changed file with 2 additions and 2 deletions Inline Diff

drivers/iio/dac/max517.c
1 /* 1 /*
2 * max517.c - Support for Maxim MAX517, MAX518 and MAX519 2 * max517.c - Support for Maxim MAX517, MAX518 and MAX519
3 * 3 *
4 * Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de> 4 * Copyright (C) 2010, 2011 Roland Stigge <stigge@antcom.de>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20 20
21 #include <linux/module.h> 21 #include <linux/module.h>
22 #include <linux/init.h> 22 #include <linux/init.h>
23 #include <linux/slab.h> 23 #include <linux/slab.h>
24 #include <linux/jiffies.h> 24 #include <linux/jiffies.h>
25 #include <linux/i2c.h> 25 #include <linux/i2c.h>
26 #include <linux/err.h> 26 #include <linux/err.h>
27 27
28 #include <linux/iio/iio.h> 28 #include <linux/iio/iio.h>
29 #include <linux/iio/sysfs.h> 29 #include <linux/iio/sysfs.h>
30 #include <linux/iio/dac/max517.h> 30 #include <linux/iio/dac/max517.h>
31 31
32 #define MAX517_DRV_NAME "max517" 32 #define MAX517_DRV_NAME "max517"
33 33
34 /* Commands */ 34 /* Commands */
35 #define COMMAND_CHANNEL0 0x00 35 #define COMMAND_CHANNEL0 0x00
36 #define COMMAND_CHANNEL1 0x01 /* for MAX518 and MAX519 */ 36 #define COMMAND_CHANNEL1 0x01 /* for MAX518 and MAX519 */
37 #define COMMAND_PD 0x08 /* Power Down */ 37 #define COMMAND_PD 0x08 /* Power Down */
38 38
39 enum max517_device_ids { 39 enum max517_device_ids {
40 ID_MAX517, 40 ID_MAX517,
41 ID_MAX518, 41 ID_MAX518,
42 ID_MAX519, 42 ID_MAX519,
43 }; 43 };
44 44
45 struct max517_data { 45 struct max517_data {
46 struct i2c_client *client; 46 struct i2c_client *client;
47 unsigned short vref_mv[2]; 47 unsigned short vref_mv[2];
48 }; 48 };
49 49
50 /* 50 /*
51 * channel: bit 0: channel 1 51 * channel: bit 0: channel 1
52 * bit 1: channel 2 52 * bit 1: channel 2
53 * (this way, it's possible to set both channels at once) 53 * (this way, it's possible to set both channels at once)
54 */ 54 */
55 static int max517_set_value(struct iio_dev *indio_dev, 55 static int max517_set_value(struct iio_dev *indio_dev,
56 long val, int channel) 56 long val, int channel)
57 { 57 {
58 struct max517_data *data = iio_priv(indio_dev); 58 struct max517_data *data = iio_priv(indio_dev);
59 struct i2c_client *client = data->client; 59 struct i2c_client *client = data->client;
60 u8 outbuf[2]; 60 u8 outbuf[2];
61 int res; 61 int res;
62 62
63 if (val < 0 || val > 255) 63 if (val < 0 || val > 255)
64 return -EINVAL; 64 return -EINVAL;
65 65
66 outbuf[0] = channel; 66 outbuf[0] = channel;
67 outbuf[1] = val; 67 outbuf[1] = val;
68 68
69 res = i2c_master_send(client, outbuf, 2); 69 res = i2c_master_send(client, outbuf, 2);
70 if (res < 0) 70 if (res < 0)
71 return res; 71 return res;
72 else if (res != 2) 72 else if (res != 2)
73 return -EIO; 73 return -EIO;
74 else 74 else
75 return 0; 75 return 0;
76 } 76 }
77 77
78 static int max517_read_raw(struct iio_dev *indio_dev, 78 static int max517_read_raw(struct iio_dev *indio_dev,
79 struct iio_chan_spec const *chan, 79 struct iio_chan_spec const *chan,
80 int *val, 80 int *val,
81 int *val2, 81 int *val2,
82 long m) 82 long m)
83 { 83 {
84 struct max517_data *data = iio_priv(indio_dev); 84 struct max517_data *data = iio_priv(indio_dev);
85 unsigned int scale_uv; 85 unsigned int scale_uv;
86 86
87 switch (m) { 87 switch (m) {
88 case IIO_CHAN_INFO_SCALE: 88 case IIO_CHAN_INFO_SCALE:
89 /* Corresponds to Vref / 2^(bits) */ 89 /* Corresponds to Vref / 2^(bits) */
90 scale_uv = (data->vref_mv[chan->channel] * 1000) >> 8; 90 scale_uv = (data->vref_mv[chan->channel] * 1000) >> 8;
91 *val = scale_uv / 1000000; 91 *val = scale_uv / 1000000;
92 *val2 = scale_uv % 1000000; 92 *val2 = scale_uv % 1000000;
93 return IIO_VAL_INT_PLUS_MICRO; 93 return IIO_VAL_INT_PLUS_MICRO;
94 default: 94 default:
95 break; 95 break;
96 } 96 }
97 return -EINVAL; 97 return -EINVAL;
98 } 98 }
99 99
100 static int max517_write_raw(struct iio_dev *indio_dev, 100 static int max517_write_raw(struct iio_dev *indio_dev,
101 struct iio_chan_spec const *chan, int val, int val2, long mask) 101 struct iio_chan_spec const *chan, int val, int val2, long mask)
102 { 102 {
103 int ret; 103 int ret;
104 104
105 switch (mask) { 105 switch (mask) {
106 case IIO_CHAN_INFO_RAW: 106 case IIO_CHAN_INFO_RAW:
107 ret = max517_set_value(indio_dev, val, chan->channel); 107 ret = max517_set_value(indio_dev, val, chan->channel);
108 break; 108 break;
109 default: 109 default:
110 ret = -EINVAL; 110 ret = -EINVAL;
111 break; 111 break;
112 } 112 }
113 113
114 return ret; 114 return ret;
115 } 115 }
116 116
117 #ifdef CONFIG_PM_SLEEP 117 #ifdef CONFIG_PM_SLEEP
118 static int max517_suspend(struct device *dev) 118 static int max517_suspend(struct device *dev)
119 { 119 {
120 u8 outbuf = COMMAND_PD; 120 u8 outbuf = COMMAND_PD;
121 121
122 return i2c_master_send(to_i2c_client(dev), &outbuf, 1); 122 return i2c_master_send(to_i2c_client(dev), &outbuf, 1);
123 } 123 }
124 124
125 static int max517_resume(struct device *dev) 125 static int max517_resume(struct device *dev)
126 { 126 {
127 u8 outbuf = 0; 127 u8 outbuf = 0;
128 128
129 return i2c_master_send(to_i2c_client(dev), &outbuf, 1); 129 return i2c_master_send(to_i2c_client(dev), &outbuf, 1);
130 } 130 }
131 131
132 static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume); 132 static SIMPLE_DEV_PM_OPS(max517_pm_ops, max517_suspend, max517_resume);
133 #define MAX517_PM_OPS (&max517_pm_ops) 133 #define MAX517_PM_OPS (&max517_pm_ops)
134 #else 134 #else
135 #define MAX517_PM_OPS NULL 135 #define MAX517_PM_OPS NULL
136 #endif 136 #endif
137 137
138 static const struct iio_info max517_info = { 138 static const struct iio_info max517_info = {
139 .read_raw = max517_read_raw, 139 .read_raw = max517_read_raw,
140 .write_raw = max517_write_raw, 140 .write_raw = max517_write_raw,
141 .driver_module = THIS_MODULE, 141 .driver_module = THIS_MODULE,
142 }; 142 };
143 143
144 #define MAX517_CHANNEL(chan) { \ 144 #define MAX517_CHANNEL(chan) { \
145 .type = IIO_VOLTAGE, \ 145 .type = IIO_VOLTAGE, \
146 .indexed = 1, \ 146 .indexed = 1, \
147 .output = 1, \ 147 .output = 1, \
148 .channel = (chan), \ 148 .channel = (chan), \
149 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ 149 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
150 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \ 150 BIT(IIO_CHAN_INFO_SCALE), \
151 .scan_type = IIO_ST('u', 8, 8, 0), \ 151 .scan_type = IIO_ST('u', 8, 8, 0), \
152 } 152 }
153 153
154 static const struct iio_chan_spec max517_channels[] = { 154 static const struct iio_chan_spec max517_channels[] = {
155 MAX517_CHANNEL(0), 155 MAX517_CHANNEL(0),
156 MAX517_CHANNEL(1) 156 MAX517_CHANNEL(1)
157 }; 157 };
158 158
159 static int max517_probe(struct i2c_client *client, 159 static int max517_probe(struct i2c_client *client,
160 const struct i2c_device_id *id) 160 const struct i2c_device_id *id)
161 { 161 {
162 struct max517_data *data; 162 struct max517_data *data;
163 struct iio_dev *indio_dev; 163 struct iio_dev *indio_dev;
164 struct max517_platform_data *platform_data = client->dev.platform_data; 164 struct max517_platform_data *platform_data = client->dev.platform_data;
165 int err; 165 int err;
166 166
167 indio_dev = iio_device_alloc(sizeof(*data)); 167 indio_dev = iio_device_alloc(sizeof(*data));
168 if (indio_dev == NULL) { 168 if (indio_dev == NULL) {
169 err = -ENOMEM; 169 err = -ENOMEM;
170 goto exit; 170 goto exit;
171 } 171 }
172 data = iio_priv(indio_dev); 172 data = iio_priv(indio_dev);
173 i2c_set_clientdata(client, indio_dev); 173 i2c_set_clientdata(client, indio_dev);
174 data->client = client; 174 data->client = client;
175 175
176 /* establish that the iio_dev is a child of the i2c device */ 176 /* establish that the iio_dev is a child of the i2c device */
177 indio_dev->dev.parent = &client->dev; 177 indio_dev->dev.parent = &client->dev;
178 178
179 /* reduced channel set for MAX517 */ 179 /* reduced channel set for MAX517 */
180 if (id->driver_data == ID_MAX517) 180 if (id->driver_data == ID_MAX517)
181 indio_dev->num_channels = 1; 181 indio_dev->num_channels = 1;
182 else 182 else
183 indio_dev->num_channels = 2; 183 indio_dev->num_channels = 2;
184 indio_dev->channels = max517_channels; 184 indio_dev->channels = max517_channels;
185 indio_dev->modes = INDIO_DIRECT_MODE; 185 indio_dev->modes = INDIO_DIRECT_MODE;
186 indio_dev->info = &max517_info; 186 indio_dev->info = &max517_info;
187 187
188 /* 188 /*
189 * Reference voltage on MAX518 and default is 5V, else take vref_mv 189 * Reference voltage on MAX518 and default is 5V, else take vref_mv
190 * from platform_data 190 * from platform_data
191 */ 191 */
192 if (id->driver_data == ID_MAX518 || !platform_data) { 192 if (id->driver_data == ID_MAX518 || !platform_data) {
193 data->vref_mv[0] = data->vref_mv[1] = 5000; /* mV */ 193 data->vref_mv[0] = data->vref_mv[1] = 5000; /* mV */
194 } else { 194 } else {
195 data->vref_mv[0] = platform_data->vref_mv[0]; 195 data->vref_mv[0] = platform_data->vref_mv[0];
196 data->vref_mv[1] = platform_data->vref_mv[1]; 196 data->vref_mv[1] = platform_data->vref_mv[1];
197 } 197 }
198 198
199 err = iio_device_register(indio_dev); 199 err = iio_device_register(indio_dev);
200 if (err) 200 if (err)
201 goto exit_free_device; 201 goto exit_free_device;
202 202
203 dev_info(&client->dev, "DAC registered\n"); 203 dev_info(&client->dev, "DAC registered\n");
204 204
205 return 0; 205 return 0;
206 206
207 exit_free_device: 207 exit_free_device:
208 iio_device_free(indio_dev); 208 iio_device_free(indio_dev);
209 exit: 209 exit:
210 return err; 210 return err;
211 } 211 }
212 212
213 static int max517_remove(struct i2c_client *client) 213 static int max517_remove(struct i2c_client *client)
214 { 214 {
215 iio_device_unregister(i2c_get_clientdata(client)); 215 iio_device_unregister(i2c_get_clientdata(client));
216 iio_device_free(i2c_get_clientdata(client)); 216 iio_device_free(i2c_get_clientdata(client));
217 217
218 return 0; 218 return 0;
219 } 219 }
220 220
221 static const struct i2c_device_id max517_id[] = { 221 static const struct i2c_device_id max517_id[] = {
222 { "max517", ID_MAX517 }, 222 { "max517", ID_MAX517 },
223 { "max518", ID_MAX518 }, 223 { "max518", ID_MAX518 },
224 { "max519", ID_MAX519 }, 224 { "max519", ID_MAX519 },
225 { } 225 { }
226 }; 226 };
227 MODULE_DEVICE_TABLE(i2c, max517_id); 227 MODULE_DEVICE_TABLE(i2c, max517_id);
228 228
229 static struct i2c_driver max517_driver = { 229 static struct i2c_driver max517_driver = {
230 .driver = { 230 .driver = {
231 .name = MAX517_DRV_NAME, 231 .name = MAX517_DRV_NAME,
232 .pm = MAX517_PM_OPS, 232 .pm = MAX517_PM_OPS,
233 }, 233 },
234 .probe = max517_probe, 234 .probe = max517_probe,
235 .remove = max517_remove, 235 .remove = max517_remove,
236 .id_table = max517_id, 236 .id_table = max517_id,
237 }; 237 };
238 module_i2c_driver(max517_driver); 238 module_i2c_driver(max517_driver);
239 239
240 MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>"); 240 MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
241 MODULE_DESCRIPTION("MAX517/MAX518/MAX519 8-bit DAC"); 241 MODULE_DESCRIPTION("MAX517/MAX518/MAX519 8-bit DAC");
242 MODULE_LICENSE("GPL"); 242 MODULE_LICENSE("GPL");
243 243