Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1 | /* |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 2 | * iio/adc/max1363.c |
| 3 | * Copyright (C) 2008-2010 Jonathan Cameron |
| 4 | * |
| 5 | * based on linux/drivers/i2c/chips/max123x |
| 6 | * Copyright (C) 2002-2004 Stefan Eletzhofer |
| 7 | * |
| 8 | * based on linux/drivers/acron/char/pcf8583.c |
| 9 | * Copyright (C) 2000 Russell King |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * max1363.c |
| 16 | * |
| 17 | * Partial support for max1363 and similar chips. |
| 18 | * |
| 19 | * Not currently implemented. |
| 20 | * |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 21 | * - Control of internal reference. |
| 22 | */ |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 23 | |
| 24 | #include <linux/interrupt.h> |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 25 | #include <linux/device.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/sysfs.h> |
| 28 | #include <linux/list.h> |
| 29 | #include <linux/i2c.h> |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 30 | #include <linux/regulator/consumer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Jonathan Cameron | c40ab87 | 2010-06-26 12:54:14 +0100 | [diff] [blame] | 32 | #include <linux/err.h> |
Paul Gortmaker | 99c9785 | 2011-07-03 15:49:50 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 34 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 35 | #include <linux/iio/iio.h> |
| 36 | #include <linux/iio/sysfs.h> |
| 37 | #include <linux/iio/events.h> |
| 38 | #include <linux/iio/buffer.h> |
| 39 | #include <linux/iio/driver.h> |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 40 | #include <linux/iio/kfifo_buf.h> |
| 41 | #include <linux/iio/trigger_consumer.h> |
Peter Meerwald | 4389fbe | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 42 | #include <linux/iio/triggered_buffer.h> |
Jonathan Cameron | cdf3870 | 2011-08-12 17:08:43 +0100 | [diff] [blame] | 43 | |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 44 | #define MAX1363_SETUP_BYTE(a) ((a) | 0x80) |
| 45 | |
| 46 | /* There is a fair bit more defined here than currently |
| 47 | * used, but the intention is to support everything these |
| 48 | * chips do in the long run */ |
| 49 | |
| 50 | /* see data sheets */ |
| 51 | /* max1363 and max1236, max1237, max1238, max1239 */ |
| 52 | #define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD 0x00 |
| 53 | #define MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF 0x20 |
| 54 | #define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT 0x40 |
| 55 | #define MAX1363_SETUP_AIN3_IS_REF_REF_IS_INT 0x60 |
| 56 | #define MAX1363_SETUP_POWER_UP_INT_REF 0x10 |
| 57 | #define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00 |
| 58 | |
Peter Meerwald | 71d2c12 | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 59 | /* think about including max11600 etc - more settings */ |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 60 | #define MAX1363_SETUP_EXT_CLOCK 0x08 |
| 61 | #define MAX1363_SETUP_INT_CLOCK 0x00 |
| 62 | #define MAX1363_SETUP_UNIPOLAR 0x00 |
| 63 | #define MAX1363_SETUP_BIPOLAR 0x04 |
| 64 | #define MAX1363_SETUP_RESET 0x00 |
| 65 | #define MAX1363_SETUP_NORESET 0x02 |
| 66 | /* max1363 only - though don't care on others. |
| 67 | * For now monitor modes are not implemented as the relevant |
| 68 | * line is not connected on my test board. |
| 69 | * The definitions are here as I intend to add this soon. |
| 70 | */ |
| 71 | #define MAX1363_SETUP_MONITOR_SETUP 0x01 |
| 72 | |
| 73 | /* Specific to the max1363 */ |
| 74 | #define MAX1363_MON_RESET_CHAN(a) (1 << ((a) + 4)) |
| 75 | #define MAX1363_MON_INT_ENABLE 0x01 |
| 76 | |
| 77 | /* defined for readability reasons */ |
| 78 | /* All chips */ |
| 79 | #define MAX1363_CONFIG_BYTE(a) ((a)) |
| 80 | |
| 81 | #define MAX1363_CONFIG_SE 0x01 |
| 82 | #define MAX1363_CONFIG_DE 0x00 |
| 83 | #define MAX1363_CONFIG_SCAN_TO_CS 0x00 |
| 84 | #define MAX1363_CONFIG_SCAN_SINGLE_8 0x20 |
| 85 | #define MAX1363_CONFIG_SCAN_MONITOR_MODE 0x40 |
| 86 | #define MAX1363_CONFIG_SCAN_SINGLE_1 0x60 |
| 87 | /* max123{6-9} only */ |
| 88 | #define MAX1236_SCAN_MID_TO_CHANNEL 0x40 |
| 89 | |
Peter Meerwald | 71d2c12 | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 90 | /* max1363 only - merely part of channel selects or don't care for others */ |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 91 | #define MAX1363_CONFIG_EN_MON_MODE_READ 0x18 |
| 92 | |
| 93 | #define MAX1363_CHANNEL_SEL(a) ((a) << 1) |
| 94 | |
| 95 | /* max1363 strictly 0x06 - but doesn't matter */ |
| 96 | #define MAX1363_CHANNEL_SEL_MASK 0x1E |
| 97 | #define MAX1363_SCAN_MASK 0x60 |
| 98 | #define MAX1363_SE_DE_MASK 0x01 |
| 99 | |
| 100 | #define MAX1363_MAX_CHANNELS 25 |
| 101 | /** |
| 102 | * struct max1363_mode - scan mode information |
| 103 | * @conf: The corresponding value of the configuration register |
| 104 | * @modemask: Bit mask corresponding to channels enabled in this mode |
| 105 | */ |
| 106 | struct max1363_mode { |
| 107 | int8_t conf; |
| 108 | DECLARE_BITMAP(modemask, MAX1363_MAX_CHANNELS); |
| 109 | }; |
| 110 | |
| 111 | /* This must be maintained along side the max1363_mode_table in max1363_core */ |
| 112 | enum max1363_modes { |
| 113 | /* Single read of a single channel */ |
| 114 | _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11, |
| 115 | /* Differential single read */ |
| 116 | d0m1, d2m3, d4m5, d6m7, d8m9, d10m11, |
| 117 | d1m0, d3m2, d5m4, d7m6, d9m8, d11m10, |
| 118 | /* Scan to channel and mid to channel where overlapping */ |
| 119 | s0to1, s0to2, s2to3, s0to3, s0to4, s0to5, s0to6, |
| 120 | s6to7, s0to7, s6to8, s0to8, s6to9, |
| 121 | s0to9, s6to10, s0to10, s6to11, s0to11, |
| 122 | /* Differential scan to channel and mid to channel where overlapping */ |
| 123 | d0m1to2m3, d0m1to4m5, d0m1to6m7, d6m7to8m9, |
| 124 | d0m1to8m9, d6m7to10m11, d0m1to10m11, d1m0to3m2, |
| 125 | d1m0to5m4, d1m0to7m6, d7m6to9m8, d1m0to9m8, |
| 126 | d7m6to11m10, d1m0to11m10, |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * struct max1363_chip_info - chip specifc information |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 131 | * @info: iio core function callbacks structure |
Jonathan Cameron | 2593b13 | 2012-10-06 14:37:44 +0100 | [diff] [blame] | 132 | * @channels: channel specification |
| 133 | * @num_channels: number of channels |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 134 | * @mode_list: array of available scan modes |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 135 | * @default_mode: the scan mode in which the chip starts up |
Jonathan Cameron | 2593b13 | 2012-10-06 14:37:44 +0100 | [diff] [blame] | 136 | * @int_vref_mv: the internal reference voltage |
Peter Meerwald | 71d2c12 | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 137 | * @num_modes: number of modes |
Jonathan Cameron | 2593b13 | 2012-10-06 14:37:44 +0100 | [diff] [blame] | 138 | * @bits: accuracy of the adc in bits |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 139 | */ |
| 140 | struct max1363_chip_info { |
| 141 | const struct iio_info *info; |
Jonathan Cameron | 2593b13 | 2012-10-06 14:37:44 +0100 | [diff] [blame] | 142 | const struct iio_chan_spec *channels; |
| 143 | int num_channels; |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 144 | const enum max1363_modes *mode_list; |
| 145 | enum max1363_modes default_mode; |
| 146 | u16 int_vref_mv; |
| 147 | u8 num_modes; |
| 148 | u8 bits; |
| 149 | }; |
| 150 | |
| 151 | /** |
| 152 | * struct max1363_state - driver instance specific data |
| 153 | * @client: i2c_client |
| 154 | * @setupbyte: cache of current device setup byte |
| 155 | * @configbyte: cache of current device config byte |
Peter Meerwald | 71d2c12 | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 156 | * @chip_info: chip model specific constants, available modes, etc. |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 157 | * @current_mode: the scan mode of this chip |
| 158 | * @requestedmask: a valid requested set of channels |
| 159 | * @reg: supply regulator |
| 160 | * @monitor_on: whether monitor mode is enabled |
| 161 | * @monitor_speed: parameter corresponding to device monitor speed setting |
| 162 | * @mask_high: bitmask for enabled high thresholds |
| 163 | * @mask_low: bitmask for enabled low thresholds |
| 164 | * @thresh_high: high threshold values |
| 165 | * @thresh_low: low threshold values |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 166 | * @vref: Reference voltage regulator |
| 167 | * @vref_uv: Actual (external or internal) reference voltage |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 168 | */ |
| 169 | struct max1363_state { |
| 170 | struct i2c_client *client; |
| 171 | u8 setupbyte; |
| 172 | u8 configbyte; |
| 173 | const struct max1363_chip_info *chip_info; |
| 174 | const struct max1363_mode *current_mode; |
| 175 | u32 requestedmask; |
| 176 | struct regulator *reg; |
| 177 | |
| 178 | /* Using monitor modes and buffer at the same time is |
| 179 | currently not supported */ |
| 180 | bool monitor_on; |
| 181 | unsigned int monitor_speed:3; |
| 182 | u8 mask_high; |
| 183 | u8 mask_low; |
| 184 | /* 4x unipolar first then the fours bipolar ones */ |
| 185 | s16 thresh_high[8]; |
| 186 | s16 thresh_low[8]; |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 187 | struct regulator *vref; |
| 188 | u32 vref_uv; |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 189 | }; |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 190 | |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 191 | #define MAX1363_MODE_SINGLE(_num, _mask) { \ |
| 192 | .conf = MAX1363_CHANNEL_SEL(_num) \ |
| 193 | | MAX1363_CONFIG_SCAN_SINGLE_1 \ |
| 194 | | MAX1363_CONFIG_SE, \ |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 195 | .modemask[0] = _mask, \ |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | #define MAX1363_MODE_SCAN_TO_CHANNEL(_num, _mask) { \ |
| 199 | .conf = MAX1363_CHANNEL_SEL(_num) \ |
| 200 | | MAX1363_CONFIG_SCAN_TO_CS \ |
| 201 | | MAX1363_CONFIG_SE, \ |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 202 | .modemask[0] = _mask, \ |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* note not available for max1363 hence naming */ |
| 206 | #define MAX1236_MODE_SCAN_MID_TO_CHANNEL(_mid, _num, _mask) { \ |
| 207 | .conf = MAX1363_CHANNEL_SEL(_num) \ |
| 208 | | MAX1236_SCAN_MID_TO_CHANNEL \ |
| 209 | | MAX1363_CONFIG_SE, \ |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 210 | .modemask[0] = _mask \ |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | #define MAX1363_MODE_DIFF_SINGLE(_nump, _numm, _mask) { \ |
| 214 | .conf = MAX1363_CHANNEL_SEL(_nump) \ |
| 215 | | MAX1363_CONFIG_SCAN_SINGLE_1 \ |
| 216 | | MAX1363_CONFIG_DE, \ |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 217 | .modemask[0] = _mask \ |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* Can't think how to automate naming so specify for now */ |
| 221 | #define MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(_num, _numvals, _mask) { \ |
| 222 | .conf = MAX1363_CHANNEL_SEL(_num) \ |
| 223 | | MAX1363_CONFIG_SCAN_TO_CS \ |
| 224 | | MAX1363_CONFIG_DE, \ |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 225 | .modemask[0] = _mask \ |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* note only available for max1363 hence naming */ |
| 229 | #define MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(_num, _numvals, _mask) { \ |
| 230 | .conf = MAX1363_CHANNEL_SEL(_num) \ |
| 231 | | MAX1236_SCAN_MID_TO_CHANNEL \ |
| 232 | | MAX1363_CONFIG_SE, \ |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 233 | .modemask[0] = _mask \ |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 234 | } |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 235 | |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 236 | static const struct max1363_mode max1363_mode_table[] = { |
| 237 | /* All of the single channel options first */ |
| 238 | MAX1363_MODE_SINGLE(0, 1 << 0), |
| 239 | MAX1363_MODE_SINGLE(1, 1 << 1), |
| 240 | MAX1363_MODE_SINGLE(2, 1 << 2), |
| 241 | MAX1363_MODE_SINGLE(3, 1 << 3), |
| 242 | MAX1363_MODE_SINGLE(4, 1 << 4), |
| 243 | MAX1363_MODE_SINGLE(5, 1 << 5), |
| 244 | MAX1363_MODE_SINGLE(6, 1 << 6), |
| 245 | MAX1363_MODE_SINGLE(7, 1 << 7), |
| 246 | MAX1363_MODE_SINGLE(8, 1 << 8), |
| 247 | MAX1363_MODE_SINGLE(9, 1 << 9), |
| 248 | MAX1363_MODE_SINGLE(10, 1 << 10), |
| 249 | MAX1363_MODE_SINGLE(11, 1 << 11), |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 250 | |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 251 | MAX1363_MODE_DIFF_SINGLE(0, 1, 1 << 12), |
| 252 | MAX1363_MODE_DIFF_SINGLE(2, 3, 1 << 13), |
| 253 | MAX1363_MODE_DIFF_SINGLE(4, 5, 1 << 14), |
| 254 | MAX1363_MODE_DIFF_SINGLE(6, 7, 1 << 15), |
| 255 | MAX1363_MODE_DIFF_SINGLE(8, 9, 1 << 16), |
| 256 | MAX1363_MODE_DIFF_SINGLE(10, 11, 1 << 17), |
| 257 | MAX1363_MODE_DIFF_SINGLE(1, 0, 1 << 18), |
| 258 | MAX1363_MODE_DIFF_SINGLE(3, 2, 1 << 19), |
| 259 | MAX1363_MODE_DIFF_SINGLE(5, 4, 1 << 20), |
| 260 | MAX1363_MODE_DIFF_SINGLE(7, 6, 1 << 21), |
| 261 | MAX1363_MODE_DIFF_SINGLE(9, 8, 1 << 22), |
| 262 | MAX1363_MODE_DIFF_SINGLE(11, 10, 1 << 23), |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 263 | |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 264 | /* The multichannel scans next */ |
| 265 | MAX1363_MODE_SCAN_TO_CHANNEL(1, 0x003), |
| 266 | MAX1363_MODE_SCAN_TO_CHANNEL(2, 0x007), |
| 267 | MAX1236_MODE_SCAN_MID_TO_CHANNEL(2, 3, 0x00C), |
| 268 | MAX1363_MODE_SCAN_TO_CHANNEL(3, 0x00F), |
| 269 | MAX1363_MODE_SCAN_TO_CHANNEL(4, 0x01F), |
| 270 | MAX1363_MODE_SCAN_TO_CHANNEL(5, 0x03F), |
| 271 | MAX1363_MODE_SCAN_TO_CHANNEL(6, 0x07F), |
| 272 | MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 7, 0x0C0), |
| 273 | MAX1363_MODE_SCAN_TO_CHANNEL(7, 0x0FF), |
| 274 | MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 8, 0x1C0), |
| 275 | MAX1363_MODE_SCAN_TO_CHANNEL(8, 0x1FF), |
| 276 | MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 9, 0x3C0), |
| 277 | MAX1363_MODE_SCAN_TO_CHANNEL(9, 0x3FF), |
| 278 | MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 10, 0x7C0), |
| 279 | MAX1363_MODE_SCAN_TO_CHANNEL(10, 0x7FF), |
| 280 | MAX1236_MODE_SCAN_MID_TO_CHANNEL(6, 11, 0xFC0), |
| 281 | MAX1363_MODE_SCAN_TO_CHANNEL(11, 0xFFF), |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 282 | |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 283 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(2, 2, 0x003000), |
| 284 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(4, 3, 0x007000), |
| 285 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(6, 4, 0x00F000), |
| 286 | MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(8, 2, 0x018000), |
| 287 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(8, 5, 0x01F000), |
| 288 | MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(10, 3, 0x038000), |
| 289 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(10, 6, 0x3F000), |
| 290 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(3, 2, 0x0C0000), |
| 291 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(5, 3, 0x1C0000), |
| 292 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(7, 4, 0x3C0000), |
| 293 | MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(9, 2, 0x600000), |
| 294 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(9, 5, 0x7C0000), |
| 295 | MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(11, 3, 0xE00000), |
| 296 | MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(11, 6, 0xFC0000), |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 297 | }; |
| 298 | |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 299 | static const struct max1363_mode |
Jonathan Cameron | c52cfb6 | 2011-12-05 21:37:15 +0000 | [diff] [blame] | 300 | *max1363_match_mode(const unsigned long *mask, |
Peter Meerwald | 71d2c12 | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 301 | const struct max1363_chip_info *ci) |
Greg Kroah-Hartman | 1b183e4 | 2010-05-04 22:24:05 -0700 | [diff] [blame] | 302 | { |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 303 | int i; |
| 304 | if (mask) |
| 305 | for (i = 0; i < ci->num_modes; i++) |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 306 | if (bitmap_subset(mask, |
| 307 | max1363_mode_table[ci->mode_list[i]]. |
| 308 | modemask, |
| 309 | MAX1363_MAX_CHANNELS)) |
Greg Kroah-Hartman | 1b183e4 | 2010-05-04 22:24:05 -0700 | [diff] [blame] | 310 | return &max1363_mode_table[ci->mode_list[i]]; |
| 311 | return NULL; |
Mike Frysinger | c608cb0 | 2010-05-23 03:10:30 -0400 | [diff] [blame] | 312 | } |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 313 | |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 314 | static int max1363_write_basic_config(struct i2c_client *client, |
| 315 | unsigned char d1, |
| 316 | unsigned char d2) |
| 317 | { |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 318 | u8 tx_buf[2] = {d1, d2}; |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 319 | |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 320 | return i2c_master_send(client, tx_buf, 2); |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 323 | static int max1363_set_scan_mode(struct max1363_state *st) |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 324 | { |
| 325 | st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK |
| 326 | | MAX1363_SCAN_MASK |
| 327 | | MAX1363_SE_DE_MASK); |
| 328 | st->configbyte |= st->current_mode->conf; |
| 329 | |
| 330 | return max1363_write_basic_config(st->client, |
| 331 | st->setupbyte, |
| 332 | st->configbyte); |
| 333 | } |
| 334 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 335 | static int max1363_read_single_chan(struct iio_dev *indio_dev, |
| 336 | struct iio_chan_spec const *chan, |
| 337 | int *val, |
| 338 | long m) |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 339 | { |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 340 | int ret = 0; |
| 341 | s32 data; |
Guenter Roeck | 482bb4e | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 342 | u8 rxbuf[2]; |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 343 | struct max1363_state *st = iio_priv(indio_dev); |
| 344 | struct i2c_client *client = st->client; |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 345 | |
Jonathan Cameron | b6b7068 | 2011-04-15 18:55:58 +0100 | [diff] [blame] | 346 | mutex_lock(&indio_dev->mlock); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 347 | /* |
| 348 | * If monitor mode is enabled, the method for reading a single |
| 349 | * channel will have to be rather different and has not yet |
| 350 | * been implemented. |
Jonathan Cameron | 3ca34cc | 2011-12-05 22:18:25 +0000 | [diff] [blame] | 351 | * |
| 352 | * Also, cannot read directly if buffered capture enabled. |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 353 | */ |
Jonathan Cameron | 3ca34cc | 2011-12-05 22:18:25 +0000 | [diff] [blame] | 354 | if (st->monitor_on || iio_buffer_enabled(indio_dev)) { |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 355 | ret = -EBUSY; |
| 356 | goto error_ret; |
| 357 | } |
| 358 | |
Jonathan Cameron | 3ca34cc | 2011-12-05 22:18:25 +0000 | [diff] [blame] | 359 | /* Check to see if current scan mode is correct */ |
| 360 | if (st->current_mode != &max1363_mode_table[chan->address]) { |
| 361 | /* Update scan mode if needed */ |
| 362 | st->current_mode = &max1363_mode_table[chan->address]; |
| 363 | ret = max1363_set_scan_mode(st); |
| 364 | if (ret < 0) |
| 365 | goto error_ret; |
| 366 | } |
| 367 | if (st->chip_info->bits != 8) { |
| 368 | /* Get reading */ |
| 369 | data = i2c_master_recv(client, rxbuf, 2); |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 370 | if (data < 0) { |
| 371 | ret = data; |
| 372 | goto error_ret; |
| 373 | } |
Guenter Roeck | 482bb4e | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 374 | data = (rxbuf[1] | rxbuf[0] << 8) & |
| 375 | ((1 << st->chip_info->bits) - 1); |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 376 | } else { |
Jonathan Cameron | 3ca34cc | 2011-12-05 22:18:25 +0000 | [diff] [blame] | 377 | /* Get reading */ |
| 378 | data = i2c_master_recv(client, rxbuf, 1); |
| 379 | if (data < 0) { |
| 380 | ret = data; |
| 381 | goto error_ret; |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 382 | } |
Jonathan Cameron | 3ca34cc | 2011-12-05 22:18:25 +0000 | [diff] [blame] | 383 | data = rxbuf[0]; |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 384 | } |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 385 | *val = data; |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 386 | error_ret: |
Jonathan Cameron | b6b7068 | 2011-04-15 18:55:58 +0100 | [diff] [blame] | 387 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 388 | return ret; |
| 389 | |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 390 | } |
| 391 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 392 | static int max1363_read_raw(struct iio_dev *indio_dev, |
| 393 | struct iio_chan_spec const *chan, |
| 394 | int *val, |
| 395 | int *val2, |
| 396 | long m) |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 397 | { |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 398 | struct max1363_state *st = iio_priv(indio_dev); |
| 399 | int ret; |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 400 | unsigned long scale_uv; |
| 401 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 402 | switch (m) { |
Jonathan Cameron | b11f98f | 2012-04-15 17:41:18 +0100 | [diff] [blame] | 403 | case IIO_CHAN_INFO_RAW: |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 404 | ret = max1363_read_single_chan(indio_dev, chan, val, m); |
Jonathan Cameron | cd03801 | 2011-08-12 16:55:29 +0100 | [diff] [blame] | 405 | if (ret < 0) |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 406 | return ret; |
| 407 | return IIO_VAL_INT; |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 408 | case IIO_CHAN_INFO_SCALE: |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 409 | scale_uv = st->vref_uv >> st->chip_info->bits; |
| 410 | *val = scale_uv / 1000; |
| 411 | *val2 = (scale_uv % 1000) * 1000; |
| 412 | return IIO_VAL_INT_PLUS_MICRO; |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 413 | default: |
| 414 | return -EINVAL; |
| 415 | } |
| 416 | return 0; |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 419 | /* Applies to max1363 */ |
| 420 | static const enum max1363_modes max1363_mode_list[] = { |
| 421 | _s0, _s1, _s2, _s3, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 422 | s0to1, s0to2, s0to3, |
| 423 | d0m1, d2m3, d1m0, d3m2, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 424 | d0m1to2m3, d1m0to3m2, |
| 425 | }; |
| 426 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 427 | #define MAX1363_EV_M \ |
| 428 | (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) \ |
| 429 | | IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING)) |
Jonathan Cameron | b11f98f | 2012-04-15 17:41:18 +0100 | [diff] [blame] | 430 | #define MAX1363_INFO_MASK (IIO_CHAN_INFO_RAW_SEPARATE_BIT | \ |
| 431 | IIO_CHAN_INFO_SCALE_SHARED_BIT) |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 432 | #define MAX1363_CHAN_U(num, addr, si, bits, evmask) \ |
| 433 | { \ |
| 434 | .type = IIO_VOLTAGE, \ |
| 435 | .indexed = 1, \ |
| 436 | .channel = num, \ |
| 437 | .address = addr, \ |
| 438 | .info_mask = MAX1363_INFO_MASK, \ |
Jonathan Cameron | bc234e7 | 2011-12-05 21:56:01 +0000 | [diff] [blame] | 439 | .datasheet_name = "AIN"#num, \ |
Jonathan Cameron | 18cffbed | 2011-12-05 21:37:16 +0000 | [diff] [blame] | 440 | .scan_type = { \ |
| 441 | .sign = 'u', \ |
| 442 | .realbits = bits, \ |
| 443 | .storagebits = (bits > 8) ? 16 : 8, \ |
| 444 | .endianness = IIO_BE, \ |
| 445 | }, \ |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 446 | .scan_index = si, \ |
| 447 | .event_mask = evmask, \ |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 448 | } |
| 449 | |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 450 | /* bipolar channel */ |
| 451 | #define MAX1363_CHAN_B(num, num2, addr, si, bits, evmask) \ |
| 452 | { \ |
| 453 | .type = IIO_VOLTAGE, \ |
| 454 | .differential = 1, \ |
| 455 | .indexed = 1, \ |
| 456 | .channel = num, \ |
| 457 | .channel2 = num2, \ |
| 458 | .address = addr, \ |
| 459 | .info_mask = MAX1363_INFO_MASK, \ |
Jonathan Cameron | bc234e7 | 2011-12-05 21:56:01 +0000 | [diff] [blame] | 460 | .datasheet_name = "AIN"#num"-AIN"#num2, \ |
Jonathan Cameron | 18cffbed | 2011-12-05 21:37:16 +0000 | [diff] [blame] | 461 | .scan_type = { \ |
| 462 | .sign = 's', \ |
| 463 | .realbits = bits, \ |
| 464 | .storagebits = (bits > 8) ? 16 : 8, \ |
| 465 | .endianness = IIO_BE, \ |
| 466 | }, \ |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 467 | .scan_index = si, \ |
| 468 | .event_mask = evmask, \ |
| 469 | } |
| 470 | |
| 471 | #define MAX1363_4X_CHANS(bits, em) { \ |
| 472 | MAX1363_CHAN_U(0, _s0, 0, bits, em), \ |
| 473 | MAX1363_CHAN_U(1, _s1, 1, bits, em), \ |
| 474 | MAX1363_CHAN_U(2, _s2, 2, bits, em), \ |
| 475 | MAX1363_CHAN_U(3, _s3, 3, bits, em), \ |
| 476 | MAX1363_CHAN_B(0, 1, d0m1, 4, bits, em), \ |
| 477 | MAX1363_CHAN_B(2, 3, d2m3, 5, bits, em), \ |
| 478 | MAX1363_CHAN_B(1, 0, d1m0, 6, bits, em), \ |
| 479 | MAX1363_CHAN_B(3, 2, d3m2, 7, bits, em), \ |
| 480 | IIO_CHAN_SOFT_TIMESTAMP(8) \ |
| 481 | } |
| 482 | |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 483 | static const struct iio_chan_spec max1036_channels[] = MAX1363_4X_CHANS(8, 0); |
| 484 | static const struct iio_chan_spec max1136_channels[] = MAX1363_4X_CHANS(10, 0); |
| 485 | static const struct iio_chan_spec max1236_channels[] = MAX1363_4X_CHANS(12, 0); |
| 486 | static const struct iio_chan_spec max1361_channels[] = |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 487 | MAX1363_4X_CHANS(10, MAX1363_EV_M); |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 488 | static const struct iio_chan_spec max1363_channels[] = |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 489 | MAX1363_4X_CHANS(12, MAX1363_EV_M); |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 490 | |
Justin P. Mattock | 4abf6f8 | 2012-02-29 22:00:38 -0800 | [diff] [blame] | 491 | /* Applies to max1236, max1237 */ |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 492 | static const enum max1363_modes max1236_mode_list[] = { |
| 493 | _s0, _s1, _s2, _s3, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 494 | s0to1, s0to2, s0to3, |
| 495 | d0m1, d2m3, d1m0, d3m2, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 496 | d0m1to2m3, d1m0to3m2, |
| 497 | s2to3, |
| 498 | }; |
| 499 | |
| 500 | /* Applies to max1238, max1239 */ |
| 501 | static const enum max1363_modes max1238_mode_list[] = { |
| 502 | _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 503 | s0to1, s0to2, s0to3, s0to4, s0to5, s0to6, |
| 504 | s0to7, s0to8, s0to9, s0to10, s0to11, |
| 505 | d0m1, d2m3, d4m5, d6m7, d8m9, d10m11, |
| 506 | d1m0, d3m2, d5m4, d7m6, d9m8, d11m10, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 507 | d0m1to2m3, d0m1to4m5, d0m1to6m7, d0m1to8m9, d0m1to10m11, |
| 508 | d1m0to3m2, d1m0to5m4, d1m0to7m6, d1m0to9m8, d1m0to11m10, |
| 509 | s6to7, s6to8, s6to9, s6to10, s6to11, |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 510 | d6m7to8m9, d6m7to10m11, d7m6to9m8, d7m6to11m10, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 511 | }; |
| 512 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 513 | #define MAX1363_12X_CHANS(bits) { \ |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 514 | MAX1363_CHAN_U(0, _s0, 0, bits, 0), \ |
| 515 | MAX1363_CHAN_U(1, _s1, 1, bits, 0), \ |
| 516 | MAX1363_CHAN_U(2, _s2, 2, bits, 0), \ |
| 517 | MAX1363_CHAN_U(3, _s3, 3, bits, 0), \ |
| 518 | MAX1363_CHAN_U(4, _s4, 4, bits, 0), \ |
| 519 | MAX1363_CHAN_U(5, _s5, 5, bits, 0), \ |
| 520 | MAX1363_CHAN_U(6, _s6, 6, bits, 0), \ |
| 521 | MAX1363_CHAN_U(7, _s7, 7, bits, 0), \ |
| 522 | MAX1363_CHAN_U(8, _s8, 8, bits, 0), \ |
| 523 | MAX1363_CHAN_U(9, _s9, 9, bits, 0), \ |
| 524 | MAX1363_CHAN_U(10, _s10, 10, bits, 0), \ |
| 525 | MAX1363_CHAN_U(11, _s11, 11, bits, 0), \ |
| 526 | MAX1363_CHAN_B(0, 1, d0m1, 12, bits, 0), \ |
| 527 | MAX1363_CHAN_B(2, 3, d2m3, 13, bits, 0), \ |
| 528 | MAX1363_CHAN_B(4, 5, d4m5, 14, bits, 0), \ |
| 529 | MAX1363_CHAN_B(6, 7, d6m7, 15, bits, 0), \ |
| 530 | MAX1363_CHAN_B(8, 9, d8m9, 16, bits, 0), \ |
| 531 | MAX1363_CHAN_B(10, 11, d10m11, 17, bits, 0), \ |
| 532 | MAX1363_CHAN_B(1, 0, d1m0, 18, bits, 0), \ |
| 533 | MAX1363_CHAN_B(3, 2, d3m2, 19, bits, 0), \ |
| 534 | MAX1363_CHAN_B(5, 4, d5m4, 20, bits, 0), \ |
| 535 | MAX1363_CHAN_B(7, 6, d7m6, 21, bits, 0), \ |
| 536 | MAX1363_CHAN_B(9, 8, d9m8, 22, bits, 0), \ |
| 537 | MAX1363_CHAN_B(11, 10, d11m10, 23, bits, 0), \ |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 538 | IIO_CHAN_SOFT_TIMESTAMP(24) \ |
| 539 | } |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 540 | static const struct iio_chan_spec max1038_channels[] = MAX1363_12X_CHANS(8); |
| 541 | static const struct iio_chan_spec max1138_channels[] = MAX1363_12X_CHANS(10); |
| 542 | static const struct iio_chan_spec max1238_channels[] = MAX1363_12X_CHANS(12); |
Jonathan Cameron | c3fa0fdd | 2010-05-04 14:43:09 +0100 | [diff] [blame] | 543 | |
| 544 | static const enum max1363_modes max11607_mode_list[] = { |
| 545 | _s0, _s1, _s2, _s3, |
| 546 | s0to1, s0to2, s0to3, |
| 547 | s2to3, |
| 548 | d0m1, d2m3, d1m0, d3m2, |
| 549 | d0m1to2m3, d1m0to3m2, |
| 550 | }; |
| 551 | |
| 552 | static const enum max1363_modes max11608_mode_list[] = { |
| 553 | _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, |
| 554 | s0to1, s0to2, s0to3, s0to4, s0to5, s0to6, s0to7, |
| 555 | s6to7, |
| 556 | d0m1, d2m3, d4m5, d6m7, |
| 557 | d1m0, d3m2, d5m4, d7m6, |
| 558 | d0m1to2m3, d0m1to4m5, d0m1to6m7, |
| 559 | d1m0to3m2, d1m0to5m4, d1m0to7m6, |
| 560 | }; |
| 561 | |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 562 | #define MAX1363_8X_CHANS(bits) { \ |
| 563 | MAX1363_CHAN_U(0, _s0, 0, bits, 0), \ |
| 564 | MAX1363_CHAN_U(1, _s1, 1, bits, 0), \ |
| 565 | MAX1363_CHAN_U(2, _s2, 2, bits, 0), \ |
| 566 | MAX1363_CHAN_U(3, _s3, 3, bits, 0), \ |
| 567 | MAX1363_CHAN_U(4, _s4, 4, bits, 0), \ |
| 568 | MAX1363_CHAN_U(5, _s5, 5, bits, 0), \ |
| 569 | MAX1363_CHAN_U(6, _s6, 6, bits, 0), \ |
| 570 | MAX1363_CHAN_U(7, _s7, 7, bits, 0), \ |
| 571 | MAX1363_CHAN_B(0, 1, d0m1, 8, bits, 0), \ |
| 572 | MAX1363_CHAN_B(2, 3, d2m3, 9, bits, 0), \ |
| 573 | MAX1363_CHAN_B(4, 5, d4m5, 10, bits, 0), \ |
| 574 | MAX1363_CHAN_B(6, 7, d6m7, 11, bits, 0), \ |
| 575 | MAX1363_CHAN_B(1, 0, d1m0, 12, bits, 0), \ |
| 576 | MAX1363_CHAN_B(3, 2, d3m2, 13, bits, 0), \ |
| 577 | MAX1363_CHAN_B(5, 4, d5m4, 14, bits, 0), \ |
| 578 | MAX1363_CHAN_B(7, 6, d7m6, 15, bits, 0), \ |
| 579 | IIO_CHAN_SOFT_TIMESTAMP(16) \ |
| 580 | } |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 581 | static const struct iio_chan_spec max11602_channels[] = MAX1363_8X_CHANS(8); |
| 582 | static const struct iio_chan_spec max11608_channels[] = MAX1363_8X_CHANS(10); |
| 583 | static const struct iio_chan_spec max11614_channels[] = MAX1363_8X_CHANS(12); |
Jonathan Cameron | c3fa0fdd | 2010-05-04 14:43:09 +0100 | [diff] [blame] | 584 | |
Jonathan Cameron | 586d152 | 2011-05-18 14:42:10 +0100 | [diff] [blame] | 585 | static const enum max1363_modes max11644_mode_list[] = { |
| 586 | _s0, _s1, s0to1, d0m1, d1m0, |
| 587 | }; |
| 588 | |
| 589 | #define MAX1363_2X_CHANS(bits) { \ |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 590 | MAX1363_CHAN_U(0, _s0, 0, bits, 0), \ |
| 591 | MAX1363_CHAN_U(1, _s1, 1, bits, 0), \ |
| 592 | MAX1363_CHAN_B(0, 1, d0m1, 2, bits, 0), \ |
| 593 | MAX1363_CHAN_B(1, 0, d1m0, 3, bits, 0), \ |
Jonathan Cameron | 586d152 | 2011-05-18 14:42:10 +0100 | [diff] [blame] | 594 | IIO_CHAN_SOFT_TIMESTAMP(4) \ |
| 595 | } |
| 596 | |
Lars-Peter Clausen | f4e4b95 | 2012-08-09 08:51:00 +0100 | [diff] [blame] | 597 | static const struct iio_chan_spec max11646_channels[] = MAX1363_2X_CHANS(10); |
| 598 | static const struct iio_chan_spec max11644_channels[] = MAX1363_2X_CHANS(12); |
Jonathan Cameron | 586d152 | 2011-05-18 14:42:10 +0100 | [diff] [blame] | 599 | |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 600 | enum { max1361, |
| 601 | max1362, |
| 602 | max1363, |
| 603 | max1364, |
Jonathan Cameron | 3bf877c | 2010-05-04 14:43:10 +0100 | [diff] [blame] | 604 | max1036, |
| 605 | max1037, |
| 606 | max1038, |
| 607 | max1039, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 608 | max1136, |
| 609 | max1137, |
| 610 | max1138, |
| 611 | max1139, |
| 612 | max1236, |
| 613 | max1237, |
| 614 | max1238, |
| 615 | max1239, |
Jonathan Cameron | 3bf877c | 2010-05-04 14:43:10 +0100 | [diff] [blame] | 616 | max11600, |
| 617 | max11601, |
| 618 | max11602, |
| 619 | max11603, |
| 620 | max11604, |
| 621 | max11605, |
Jonathan Cameron | c3fa0fdd | 2010-05-04 14:43:09 +0100 | [diff] [blame] | 622 | max11606, |
| 623 | max11607, |
| 624 | max11608, |
| 625 | max11609, |
| 626 | max11610, |
| 627 | max11611, |
| 628 | max11612, |
| 629 | max11613, |
| 630 | max11614, |
| 631 | max11615, |
| 632 | max11616, |
| 633 | max11617, |
Jonathan Cameron | 586d152 | 2011-05-18 14:42:10 +0100 | [diff] [blame] | 634 | max11644, |
| 635 | max11645, |
| 636 | max11646, |
| 637 | max11647 |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 638 | }; |
| 639 | |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 640 | static const int max1363_monitor_speeds[] = { 133000, 665000, 33300, 16600, |
| 641 | 8300, 4200, 2000, 1000 }; |
| 642 | |
| 643 | static ssize_t max1363_monitor_show_freq(struct device *dev, |
| 644 | struct device_attribute *attr, |
| 645 | char *buf) |
| 646 | { |
Lars-Peter Clausen | 62c5183 | 2012-05-12 15:39:42 +0200 | [diff] [blame] | 647 | struct max1363_state *st = iio_priv(dev_to_iio_dev(dev)); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 648 | return sprintf(buf, "%d\n", max1363_monitor_speeds[st->monitor_speed]); |
| 649 | } |
| 650 | |
| 651 | static ssize_t max1363_monitor_store_freq(struct device *dev, |
| 652 | struct device_attribute *attr, |
| 653 | const char *buf, |
| 654 | size_t len) |
| 655 | { |
Lars-Peter Clausen | 62c5183 | 2012-05-12 15:39:42 +0200 | [diff] [blame] | 656 | struct iio_dev *indio_dev = dev_to_iio_dev(dev); |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 657 | struct max1363_state *st = iio_priv(indio_dev); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 658 | int i, ret; |
| 659 | unsigned long val; |
| 660 | bool found = false; |
| 661 | |
| 662 | ret = strict_strtoul(buf, 10, &val); |
| 663 | if (ret) |
| 664 | return -EINVAL; |
| 665 | for (i = 0; i < ARRAY_SIZE(max1363_monitor_speeds); i++) |
| 666 | if (val == max1363_monitor_speeds[i]) { |
| 667 | found = true; |
| 668 | break; |
| 669 | } |
| 670 | if (!found) |
| 671 | return -EINVAL; |
| 672 | |
Jonathan Cameron | b6b7068 | 2011-04-15 18:55:58 +0100 | [diff] [blame] | 673 | mutex_lock(&indio_dev->mlock); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 674 | st->monitor_speed = i; |
Jonathan Cameron | b6b7068 | 2011-04-15 18:55:58 +0100 | [diff] [blame] | 675 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 676 | |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, |
| 681 | max1363_monitor_show_freq, |
| 682 | max1363_monitor_store_freq); |
| 683 | |
| 684 | static IIO_CONST_ATTR(sampling_frequency_available, |
| 685 | "133000 665000 33300 16600 8300 4200 2000 1000"); |
| 686 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 687 | static int max1363_read_thresh(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 688 | u64 event_code, |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 689 | int *val) |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 690 | { |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 691 | struct max1363_state *st = iio_priv(indio_dev); |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 692 | if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) |
Lars-Peter Clausen | da36716 | 2012-02-13 10:25:32 +0100 | [diff] [blame] | 693 | *val = st->thresh_low[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)]; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 694 | else |
Lars-Peter Clausen | da36716 | 2012-02-13 10:25:32 +0100 | [diff] [blame] | 695 | *val = st->thresh_high[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)]; |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 696 | return 0; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 697 | } |
| 698 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 699 | static int max1363_write_thresh(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 700 | u64 event_code, |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 701 | int val) |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 702 | { |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 703 | struct max1363_state *st = iio_priv(indio_dev); |
| 704 | /* make it handle signed correctly as well */ |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 705 | switch (st->chip_info->bits) { |
| 706 | case 10: |
| 707 | if (val > 0x3FF) |
| 708 | return -EINVAL; |
| 709 | break; |
| 710 | case 12: |
| 711 | if (val > 0xFFF) |
| 712 | return -EINVAL; |
| 713 | break; |
| 714 | } |
| 715 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 716 | switch (IIO_EVENT_CODE_EXTRACT_DIR(event_code)) { |
| 717 | case IIO_EV_DIR_FALLING: |
Lars-Peter Clausen | da36716 | 2012-02-13 10:25:32 +0100 | [diff] [blame] | 718 | st->thresh_low[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] = val; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 719 | break; |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 720 | case IIO_EV_DIR_RISING: |
Lars-Peter Clausen | da36716 | 2012-02-13 10:25:32 +0100 | [diff] [blame] | 721 | st->thresh_high[IIO_EVENT_CODE_EXTRACT_CHAN(event_code)] = val; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 722 | break; |
| 723 | } |
| 724 | |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 725 | return 0; |
| 726 | } |
| 727 | |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 728 | static const u64 max1363_event_codes[] = { |
Jonathan Cameron | 6835cb6 | 2011-09-27 09:56:41 +0100 | [diff] [blame] | 729 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0, |
| 730 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), |
| 731 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1, |
| 732 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), |
| 733 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 2, |
| 734 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), |
| 735 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 3, |
| 736 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_FALLING), |
| 737 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 0, |
| 738 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), |
| 739 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1, |
| 740 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), |
| 741 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 2, |
| 742 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), |
| 743 | IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 3, |
| 744 | IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING), |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 745 | }; |
| 746 | |
Jonathan Cameron | aaf370d | 2011-05-18 14:41:16 +0100 | [diff] [blame] | 747 | static irqreturn_t max1363_event_handler(int irq, void *private) |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 748 | { |
Jonathan Cameron | aaf370d | 2011-05-18 14:41:16 +0100 | [diff] [blame] | 749 | struct iio_dev *indio_dev = private; |
| 750 | struct max1363_state *st = iio_priv(indio_dev); |
| 751 | s64 timestamp = iio_get_time_ns(); |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 752 | unsigned long mask, loc; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 753 | u8 rx; |
| 754 | u8 tx[2] = { st->setupbyte, |
| 755 | MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0 }; |
| 756 | |
| 757 | i2c_master_recv(st->client, &rx, 1); |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 758 | mask = rx; |
| 759 | for_each_set_bit(loc, &mask, 8) |
Jonathan Cameron | 5aa9618 | 2011-08-30 12:41:06 +0100 | [diff] [blame] | 760 | iio_push_event(indio_dev, max1363_event_codes[loc], timestamp); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 761 | i2c_master_send(st->client, tx, 2); |
Jonathan Cameron | aaf370d | 2011-05-18 14:41:16 +0100 | [diff] [blame] | 762 | |
| 763 | return IRQ_HANDLED; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 764 | } |
| 765 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 766 | static int max1363_read_event_config(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 767 | u64 event_code) |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 768 | { |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 769 | struct max1363_state *st = iio_priv(indio_dev); |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 770 | int val; |
Lars-Peter Clausen | da36716 | 2012-02-13 10:25:32 +0100 | [diff] [blame] | 771 | int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); |
Jonathan Cameron | 0d9fa2c | 2012-10-06 14:38:11 +0100 | [diff] [blame] | 772 | |
Jonathan Cameron | b6b7068 | 2011-04-15 18:55:58 +0100 | [diff] [blame] | 773 | mutex_lock(&indio_dev->mlock); |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 774 | if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) |
| 775 | val = (1 << number) & st->mask_low; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 776 | else |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 777 | val = (1 << number) & st->mask_high; |
Jonathan Cameron | b6b7068 | 2011-04-15 18:55:58 +0100 | [diff] [blame] | 778 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 779 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 780 | return val; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | static int max1363_monitor_mode_update(struct max1363_state *st, int enabled) |
| 784 | { |
| 785 | u8 *tx_buf; |
| 786 | int ret, i = 3, j; |
| 787 | unsigned long numelements; |
| 788 | int len; |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 789 | const long *modemask; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 790 | |
| 791 | if (!enabled) { |
Jonathan Cameron | ec44372 | 2012-10-06 14:19:01 +0100 | [diff] [blame] | 792 | /* transition to buffered capture is not currently supported */ |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 793 | st->setupbyte &= ~MAX1363_SETUP_MONITOR_SETUP; |
| 794 | st->configbyte &= ~MAX1363_SCAN_MASK; |
| 795 | st->monitor_on = false; |
| 796 | return max1363_write_basic_config(st->client, |
| 797 | st->setupbyte, |
| 798 | st->configbyte); |
| 799 | } |
| 800 | |
| 801 | /* Ensure we are in the relevant mode */ |
| 802 | st->setupbyte |= MAX1363_SETUP_MONITOR_SETUP; |
| 803 | st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK |
| 804 | | MAX1363_SCAN_MASK |
| 805 | | MAX1363_SE_DE_MASK); |
| 806 | st->configbyte |= MAX1363_CONFIG_SCAN_MONITOR_MODE; |
| 807 | if ((st->mask_low | st->mask_high) & 0x0F) { |
| 808 | st->configbyte |= max1363_mode_table[s0to3].conf; |
| 809 | modemask = max1363_mode_table[s0to3].modemask; |
| 810 | } else if ((st->mask_low | st->mask_high) & 0x30) { |
| 811 | st->configbyte |= max1363_mode_table[d0m1to2m3].conf; |
| 812 | modemask = max1363_mode_table[d0m1to2m3].modemask; |
| 813 | } else { |
| 814 | st->configbyte |= max1363_mode_table[d1m0to3m2].conf; |
| 815 | modemask = max1363_mode_table[d1m0to3m2].modemask; |
| 816 | } |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 817 | numelements = bitmap_weight(modemask, MAX1363_MAX_CHANNELS); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 818 | len = 3 * numelements + 3; |
| 819 | tx_buf = kmalloc(len, GFP_KERNEL); |
| 820 | if (!tx_buf) { |
| 821 | ret = -ENOMEM; |
| 822 | goto error_ret; |
| 823 | } |
| 824 | tx_buf[0] = st->configbyte; |
| 825 | tx_buf[1] = st->setupbyte; |
| 826 | tx_buf[2] = (st->monitor_speed << 1); |
| 827 | |
| 828 | /* |
| 829 | * So we need to do yet another bit of nefarious scan mode |
| 830 | * setup to match what we need. |
| 831 | */ |
| 832 | for (j = 0; j < 8; j++) |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 833 | if (test_bit(j, modemask)) { |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 834 | /* Establish the mode is in the scan */ |
| 835 | if (st->mask_low & (1 << j)) { |
| 836 | tx_buf[i] = (st->thresh_low[j] >> 4) & 0xFF; |
| 837 | tx_buf[i + 1] = (st->thresh_low[j] << 4) & 0xF0; |
| 838 | } else if (j < 4) { |
| 839 | tx_buf[i] = 0; |
| 840 | tx_buf[i + 1] = 0; |
| 841 | } else { |
| 842 | tx_buf[i] = 0x80; |
| 843 | tx_buf[i + 1] = 0; |
| 844 | } |
| 845 | if (st->mask_high & (1 << j)) { |
| 846 | tx_buf[i + 1] |= |
| 847 | (st->thresh_high[j] >> 8) & 0x0F; |
| 848 | tx_buf[i + 2] = st->thresh_high[j] & 0xFF; |
| 849 | } else if (j < 4) { |
| 850 | tx_buf[i + 1] |= 0x0F; |
| 851 | tx_buf[i + 2] = 0xFF; |
| 852 | } else { |
| 853 | tx_buf[i + 1] |= 0x07; |
| 854 | tx_buf[i + 2] = 0xFF; |
| 855 | } |
| 856 | i += 3; |
| 857 | } |
| 858 | |
| 859 | |
| 860 | ret = i2c_master_send(st->client, tx_buf, len); |
| 861 | if (ret < 0) |
| 862 | goto error_ret; |
| 863 | if (ret != len) { |
| 864 | ret = -EIO; |
| 865 | goto error_ret; |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * Now that we hopefully have sensible thresholds in place it is |
| 870 | * time to turn the interrupts on. |
| 871 | * It is unclear from the data sheet if this should be necessary |
| 872 | * (i.e. whether monitor mode setup is atomic) but it appears to |
| 873 | * be in practice. |
| 874 | */ |
| 875 | tx_buf[0] = st->setupbyte; |
| 876 | tx_buf[1] = MAX1363_MON_INT_ENABLE | (st->monitor_speed << 1) | 0xF0; |
| 877 | ret = i2c_master_send(st->client, tx_buf, 2); |
| 878 | if (ret < 0) |
| 879 | goto error_ret; |
| 880 | if (ret != 2) { |
| 881 | ret = -EIO; |
| 882 | goto error_ret; |
| 883 | } |
| 884 | ret = 0; |
| 885 | st->monitor_on = true; |
| 886 | error_ret: |
| 887 | |
| 888 | kfree(tx_buf); |
| 889 | |
| 890 | return ret; |
| 891 | } |
| 892 | |
| 893 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 894 | * To keep this manageable we always use one of 3 scan modes. |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 895 | * Scan 0...3, 0-1,2-3 and 1-0,3-2 |
| 896 | */ |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 897 | |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 898 | static inline int __max1363_check_event_mask(int thismask, int checkmask) |
| 899 | { |
| 900 | int ret = 0; |
| 901 | /* Is it unipolar */ |
| 902 | if (thismask < 4) { |
| 903 | if (checkmask & ~0x0F) { |
| 904 | ret = -EBUSY; |
| 905 | goto error_ret; |
| 906 | } |
| 907 | } else if (thismask < 6) { |
| 908 | if (checkmask & ~0x30) { |
| 909 | ret = -EBUSY; |
| 910 | goto error_ret; |
| 911 | } |
| 912 | } else if (checkmask & ~0xC0) |
| 913 | ret = -EBUSY; |
| 914 | error_ret: |
| 915 | return ret; |
| 916 | } |
| 917 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 918 | static int max1363_write_event_config(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 919 | u64 event_code, |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 920 | int state) |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 921 | { |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 922 | int ret = 0; |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 923 | struct max1363_state *st = iio_priv(indio_dev); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 924 | u16 unifiedmask; |
Lars-Peter Clausen | da36716 | 2012-02-13 10:25:32 +0100 | [diff] [blame] | 925 | int number = IIO_EVENT_CODE_EXTRACT_CHAN(event_code); |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 926 | |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 927 | mutex_lock(&indio_dev->mlock); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 928 | unifiedmask = st->mask_low | st->mask_high; |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 929 | if (IIO_EVENT_CODE_EXTRACT_DIR(event_code) == IIO_EV_DIR_FALLING) { |
| 930 | |
| 931 | if (state == 0) |
| 932 | st->mask_low &= ~(1 << number); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 933 | else { |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 934 | ret = __max1363_check_event_mask((1 << number), |
| 935 | unifiedmask); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 936 | if (ret) |
| 937 | goto error_ret; |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 938 | st->mask_low |= (1 << number); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 939 | } |
| 940 | } else { |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 941 | if (state == 0) |
| 942 | st->mask_high &= ~(1 << number); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 943 | else { |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 944 | ret = __max1363_check_event_mask((1 << number), |
| 945 | unifiedmask); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 946 | if (ret) |
| 947 | goto error_ret; |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 948 | st->mask_high |= (1 << number); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 949 | } |
| 950 | } |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 951 | |
| 952 | max1363_monitor_mode_update(st, !!(st->mask_high | st->mask_low)); |
| 953 | error_ret: |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 954 | mutex_unlock(&indio_dev->mlock); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 955 | |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 956 | return ret; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 957 | } |
| 958 | |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 959 | /* |
| 960 | * As with scan_elements, only certain sets of these can |
| 961 | * be combined. |
| 962 | */ |
| 963 | static struct attribute *max1363_event_attributes[] = { |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 964 | &iio_dev_attr_sampling_frequency.dev_attr.attr, |
| 965 | &iio_const_attr_sampling_frequency_available.dev_attr.attr, |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 966 | NULL, |
| 967 | }; |
| 968 | |
| 969 | static struct attribute_group max1363_event_attribute_group = { |
| 970 | .attrs = max1363_event_attributes, |
Jonathan Cameron | 8e7d967 | 2011-08-30 12:32:45 +0100 | [diff] [blame] | 971 | .name = "events", |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 972 | }; |
| 973 | |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 974 | static int max1363_update_scan_mode(struct iio_dev *indio_dev, |
| 975 | const unsigned long *scan_mask) |
| 976 | { |
| 977 | struct max1363_state *st = iio_priv(indio_dev); |
| 978 | |
| 979 | /* |
| 980 | * Need to figure out the current mode based upon the requested |
| 981 | * scan mask in iio_dev |
| 982 | */ |
| 983 | st->current_mode = max1363_match_mode(scan_mask, st->chip_info); |
| 984 | if (!st->current_mode) |
| 985 | return -EINVAL; |
| 986 | max1363_set_scan_mode(st); |
| 987 | return 0; |
| 988 | } |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 989 | |
| 990 | static const struct iio_info max1238_info = { |
| 991 | .read_raw = &max1363_read_raw, |
| 992 | .driver_module = THIS_MODULE, |
Jonathan Cameron | a9ea1b1 | 2012-04-10 21:11:05 +0100 | [diff] [blame] | 993 | .update_scan_mode = &max1363_update_scan_mode, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 994 | }; |
| 995 | |
| 996 | static const struct iio_info max1363_info = { |
| 997 | .read_event_value = &max1363_read_thresh, |
| 998 | .write_event_value = &max1363_write_thresh, |
| 999 | .read_event_config = &max1363_read_event_config, |
| 1000 | .write_event_config = &max1363_write_event_config, |
| 1001 | .read_raw = &max1363_read_raw, |
Jonathan Cameron | c52cfb6 | 2011-12-05 21:37:15 +0000 | [diff] [blame] | 1002 | .update_scan_mode = &max1363_update_scan_mode, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 1003 | .driver_module = THIS_MODULE, |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 1004 | .event_attrs = &max1363_event_attribute_group, |
| 1005 | }; |
| 1006 | |
| 1007 | /* max1363 and max1368 tested - rest from data sheet */ |
| 1008 | static const struct max1363_chip_info max1363_chip_info_tbl[] = { |
| 1009 | [max1361] = { |
| 1010 | .bits = 10, |
| 1011 | .int_vref_mv = 2048, |
| 1012 | .mode_list = max1363_mode_list, |
| 1013 | .num_modes = ARRAY_SIZE(max1363_mode_list), |
| 1014 | .default_mode = s0to3, |
| 1015 | .channels = max1361_channels, |
| 1016 | .num_channels = ARRAY_SIZE(max1361_channels), |
| 1017 | .info = &max1363_info, |
| 1018 | }, |
| 1019 | [max1362] = { |
| 1020 | .bits = 10, |
| 1021 | .int_vref_mv = 4096, |
| 1022 | .mode_list = max1363_mode_list, |
| 1023 | .num_modes = ARRAY_SIZE(max1363_mode_list), |
| 1024 | .default_mode = s0to3, |
| 1025 | .channels = max1361_channels, |
| 1026 | .num_channels = ARRAY_SIZE(max1361_channels), |
| 1027 | .info = &max1363_info, |
| 1028 | }, |
| 1029 | [max1363] = { |
| 1030 | .bits = 12, |
| 1031 | .int_vref_mv = 2048, |
| 1032 | .mode_list = max1363_mode_list, |
| 1033 | .num_modes = ARRAY_SIZE(max1363_mode_list), |
| 1034 | .default_mode = s0to3, |
| 1035 | .channels = max1363_channels, |
| 1036 | .num_channels = ARRAY_SIZE(max1363_channels), |
| 1037 | .info = &max1363_info, |
| 1038 | }, |
| 1039 | [max1364] = { |
| 1040 | .bits = 12, |
| 1041 | .int_vref_mv = 4096, |
| 1042 | .mode_list = max1363_mode_list, |
| 1043 | .num_modes = ARRAY_SIZE(max1363_mode_list), |
| 1044 | .default_mode = s0to3, |
| 1045 | .channels = max1363_channels, |
| 1046 | .num_channels = ARRAY_SIZE(max1363_channels), |
| 1047 | .info = &max1363_info, |
| 1048 | }, |
| 1049 | [max1036] = { |
| 1050 | .bits = 8, |
| 1051 | .int_vref_mv = 4096, |
| 1052 | .mode_list = max1236_mode_list, |
| 1053 | .num_modes = ARRAY_SIZE(max1236_mode_list), |
| 1054 | .default_mode = s0to3, |
| 1055 | .info = &max1238_info, |
| 1056 | .channels = max1036_channels, |
| 1057 | .num_channels = ARRAY_SIZE(max1036_channels), |
| 1058 | }, |
| 1059 | [max1037] = { |
| 1060 | .bits = 8, |
| 1061 | .int_vref_mv = 2048, |
| 1062 | .mode_list = max1236_mode_list, |
| 1063 | .num_modes = ARRAY_SIZE(max1236_mode_list), |
| 1064 | .default_mode = s0to3, |
| 1065 | .info = &max1238_info, |
| 1066 | .channels = max1036_channels, |
| 1067 | .num_channels = ARRAY_SIZE(max1036_channels), |
| 1068 | }, |
| 1069 | [max1038] = { |
| 1070 | .bits = 8, |
| 1071 | .int_vref_mv = 4096, |
| 1072 | .mode_list = max1238_mode_list, |
| 1073 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1074 | .default_mode = s0to11, |
| 1075 | .info = &max1238_info, |
| 1076 | .channels = max1038_channels, |
| 1077 | .num_channels = ARRAY_SIZE(max1038_channels), |
| 1078 | }, |
| 1079 | [max1039] = { |
| 1080 | .bits = 8, |
| 1081 | .int_vref_mv = 2048, |
| 1082 | .mode_list = max1238_mode_list, |
| 1083 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1084 | .default_mode = s0to11, |
| 1085 | .info = &max1238_info, |
| 1086 | .channels = max1038_channels, |
| 1087 | .num_channels = ARRAY_SIZE(max1038_channels), |
| 1088 | }, |
| 1089 | [max1136] = { |
| 1090 | .bits = 10, |
| 1091 | .int_vref_mv = 4096, |
| 1092 | .mode_list = max1236_mode_list, |
| 1093 | .num_modes = ARRAY_SIZE(max1236_mode_list), |
| 1094 | .default_mode = s0to3, |
| 1095 | .info = &max1238_info, |
| 1096 | .channels = max1136_channels, |
| 1097 | .num_channels = ARRAY_SIZE(max1136_channels), |
| 1098 | }, |
| 1099 | [max1137] = { |
| 1100 | .bits = 10, |
| 1101 | .int_vref_mv = 2048, |
| 1102 | .mode_list = max1236_mode_list, |
| 1103 | .num_modes = ARRAY_SIZE(max1236_mode_list), |
| 1104 | .default_mode = s0to3, |
| 1105 | .info = &max1238_info, |
| 1106 | .channels = max1136_channels, |
| 1107 | .num_channels = ARRAY_SIZE(max1136_channels), |
| 1108 | }, |
| 1109 | [max1138] = { |
| 1110 | .bits = 10, |
| 1111 | .int_vref_mv = 4096, |
| 1112 | .mode_list = max1238_mode_list, |
| 1113 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1114 | .default_mode = s0to11, |
| 1115 | .info = &max1238_info, |
| 1116 | .channels = max1138_channels, |
| 1117 | .num_channels = ARRAY_SIZE(max1138_channels), |
| 1118 | }, |
| 1119 | [max1139] = { |
| 1120 | .bits = 10, |
| 1121 | .int_vref_mv = 2048, |
| 1122 | .mode_list = max1238_mode_list, |
| 1123 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1124 | .default_mode = s0to11, |
| 1125 | .info = &max1238_info, |
| 1126 | .channels = max1138_channels, |
| 1127 | .num_channels = ARRAY_SIZE(max1138_channels), |
| 1128 | }, |
| 1129 | [max1236] = { |
| 1130 | .bits = 12, |
| 1131 | .int_vref_mv = 4096, |
| 1132 | .mode_list = max1236_mode_list, |
| 1133 | .num_modes = ARRAY_SIZE(max1236_mode_list), |
| 1134 | .default_mode = s0to3, |
| 1135 | .info = &max1238_info, |
| 1136 | .channels = max1236_channels, |
| 1137 | .num_channels = ARRAY_SIZE(max1236_channels), |
| 1138 | }, |
| 1139 | [max1237] = { |
| 1140 | .bits = 12, |
| 1141 | .int_vref_mv = 2048, |
| 1142 | .mode_list = max1236_mode_list, |
| 1143 | .num_modes = ARRAY_SIZE(max1236_mode_list), |
| 1144 | .default_mode = s0to3, |
| 1145 | .info = &max1238_info, |
| 1146 | .channels = max1236_channels, |
| 1147 | .num_channels = ARRAY_SIZE(max1236_channels), |
| 1148 | }, |
| 1149 | [max1238] = { |
| 1150 | .bits = 12, |
| 1151 | .int_vref_mv = 4096, |
| 1152 | .mode_list = max1238_mode_list, |
| 1153 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1154 | .default_mode = s0to11, |
| 1155 | .info = &max1238_info, |
| 1156 | .channels = max1238_channels, |
| 1157 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1158 | }, |
| 1159 | [max1239] = { |
| 1160 | .bits = 12, |
| 1161 | .int_vref_mv = 2048, |
| 1162 | .mode_list = max1238_mode_list, |
| 1163 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1164 | .default_mode = s0to11, |
| 1165 | .info = &max1238_info, |
| 1166 | .channels = max1238_channels, |
| 1167 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1168 | }, |
| 1169 | [max11600] = { |
| 1170 | .bits = 8, |
| 1171 | .int_vref_mv = 4096, |
| 1172 | .mode_list = max11607_mode_list, |
| 1173 | .num_modes = ARRAY_SIZE(max11607_mode_list), |
| 1174 | .default_mode = s0to3, |
| 1175 | .info = &max1238_info, |
| 1176 | .channels = max1036_channels, |
| 1177 | .num_channels = ARRAY_SIZE(max1036_channels), |
| 1178 | }, |
| 1179 | [max11601] = { |
| 1180 | .bits = 8, |
| 1181 | .int_vref_mv = 2048, |
| 1182 | .mode_list = max11607_mode_list, |
| 1183 | .num_modes = ARRAY_SIZE(max11607_mode_list), |
| 1184 | .default_mode = s0to3, |
| 1185 | .info = &max1238_info, |
| 1186 | .channels = max1036_channels, |
| 1187 | .num_channels = ARRAY_SIZE(max1036_channels), |
| 1188 | }, |
| 1189 | [max11602] = { |
| 1190 | .bits = 8, |
| 1191 | .int_vref_mv = 4096, |
| 1192 | .mode_list = max11608_mode_list, |
| 1193 | .num_modes = ARRAY_SIZE(max11608_mode_list), |
| 1194 | .default_mode = s0to7, |
| 1195 | .info = &max1238_info, |
| 1196 | .channels = max11602_channels, |
| 1197 | .num_channels = ARRAY_SIZE(max11602_channels), |
| 1198 | }, |
| 1199 | [max11603] = { |
| 1200 | .bits = 8, |
| 1201 | .int_vref_mv = 2048, |
| 1202 | .mode_list = max11608_mode_list, |
| 1203 | .num_modes = ARRAY_SIZE(max11608_mode_list), |
| 1204 | .default_mode = s0to7, |
| 1205 | .info = &max1238_info, |
| 1206 | .channels = max11602_channels, |
| 1207 | .num_channels = ARRAY_SIZE(max11602_channels), |
| 1208 | }, |
| 1209 | [max11604] = { |
| 1210 | .bits = 8, |
| 1211 | .int_vref_mv = 4098, |
| 1212 | .mode_list = max1238_mode_list, |
| 1213 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1214 | .default_mode = s0to11, |
| 1215 | .info = &max1238_info, |
| 1216 | .channels = max1238_channels, |
| 1217 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1218 | }, |
| 1219 | [max11605] = { |
| 1220 | .bits = 8, |
| 1221 | .int_vref_mv = 2048, |
| 1222 | .mode_list = max1238_mode_list, |
| 1223 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1224 | .default_mode = s0to11, |
| 1225 | .info = &max1238_info, |
| 1226 | .channels = max1238_channels, |
| 1227 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1228 | }, |
| 1229 | [max11606] = { |
| 1230 | .bits = 10, |
| 1231 | .int_vref_mv = 4096, |
| 1232 | .mode_list = max11607_mode_list, |
| 1233 | .num_modes = ARRAY_SIZE(max11607_mode_list), |
| 1234 | .default_mode = s0to3, |
| 1235 | .info = &max1238_info, |
| 1236 | .channels = max1136_channels, |
| 1237 | .num_channels = ARRAY_SIZE(max1136_channels), |
| 1238 | }, |
| 1239 | [max11607] = { |
| 1240 | .bits = 10, |
| 1241 | .int_vref_mv = 2048, |
| 1242 | .mode_list = max11607_mode_list, |
| 1243 | .num_modes = ARRAY_SIZE(max11607_mode_list), |
| 1244 | .default_mode = s0to3, |
| 1245 | .info = &max1238_info, |
| 1246 | .channels = max1136_channels, |
| 1247 | .num_channels = ARRAY_SIZE(max1136_channels), |
| 1248 | }, |
| 1249 | [max11608] = { |
| 1250 | .bits = 10, |
| 1251 | .int_vref_mv = 4096, |
| 1252 | .mode_list = max11608_mode_list, |
| 1253 | .num_modes = ARRAY_SIZE(max11608_mode_list), |
| 1254 | .default_mode = s0to7, |
| 1255 | .info = &max1238_info, |
| 1256 | .channels = max11608_channels, |
| 1257 | .num_channels = ARRAY_SIZE(max11608_channels), |
| 1258 | }, |
| 1259 | [max11609] = { |
| 1260 | .bits = 10, |
| 1261 | .int_vref_mv = 2048, |
| 1262 | .mode_list = max11608_mode_list, |
| 1263 | .num_modes = ARRAY_SIZE(max11608_mode_list), |
| 1264 | .default_mode = s0to7, |
| 1265 | .info = &max1238_info, |
| 1266 | .channels = max11608_channels, |
| 1267 | .num_channels = ARRAY_SIZE(max11608_channels), |
| 1268 | }, |
| 1269 | [max11610] = { |
| 1270 | .bits = 10, |
| 1271 | .int_vref_mv = 4098, |
| 1272 | .mode_list = max1238_mode_list, |
| 1273 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1274 | .default_mode = s0to11, |
| 1275 | .info = &max1238_info, |
| 1276 | .channels = max1238_channels, |
| 1277 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1278 | }, |
| 1279 | [max11611] = { |
| 1280 | .bits = 10, |
| 1281 | .int_vref_mv = 2048, |
| 1282 | .mode_list = max1238_mode_list, |
| 1283 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1284 | .default_mode = s0to11, |
| 1285 | .info = &max1238_info, |
| 1286 | .channels = max1238_channels, |
| 1287 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1288 | }, |
| 1289 | [max11612] = { |
| 1290 | .bits = 12, |
| 1291 | .int_vref_mv = 4096, |
| 1292 | .mode_list = max11607_mode_list, |
| 1293 | .num_modes = ARRAY_SIZE(max11607_mode_list), |
| 1294 | .default_mode = s0to3, |
| 1295 | .info = &max1238_info, |
| 1296 | .channels = max1363_channels, |
| 1297 | .num_channels = ARRAY_SIZE(max1363_channels), |
| 1298 | }, |
| 1299 | [max11613] = { |
| 1300 | .bits = 12, |
| 1301 | .int_vref_mv = 2048, |
| 1302 | .mode_list = max11607_mode_list, |
| 1303 | .num_modes = ARRAY_SIZE(max11607_mode_list), |
| 1304 | .default_mode = s0to3, |
| 1305 | .info = &max1238_info, |
| 1306 | .channels = max1363_channels, |
| 1307 | .num_channels = ARRAY_SIZE(max1363_channels), |
| 1308 | }, |
| 1309 | [max11614] = { |
| 1310 | .bits = 12, |
| 1311 | .int_vref_mv = 4096, |
| 1312 | .mode_list = max11608_mode_list, |
| 1313 | .num_modes = ARRAY_SIZE(max11608_mode_list), |
| 1314 | .default_mode = s0to7, |
| 1315 | .info = &max1238_info, |
| 1316 | .channels = max11614_channels, |
| 1317 | .num_channels = ARRAY_SIZE(max11614_channels), |
| 1318 | }, |
| 1319 | [max11615] = { |
| 1320 | .bits = 12, |
| 1321 | .int_vref_mv = 2048, |
| 1322 | .mode_list = max11608_mode_list, |
| 1323 | .num_modes = ARRAY_SIZE(max11608_mode_list), |
| 1324 | .default_mode = s0to7, |
| 1325 | .info = &max1238_info, |
| 1326 | .channels = max11614_channels, |
| 1327 | .num_channels = ARRAY_SIZE(max11614_channels), |
| 1328 | }, |
| 1329 | [max11616] = { |
| 1330 | .bits = 12, |
| 1331 | .int_vref_mv = 4098, |
| 1332 | .mode_list = max1238_mode_list, |
| 1333 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1334 | .default_mode = s0to11, |
| 1335 | .info = &max1238_info, |
| 1336 | .channels = max1238_channels, |
| 1337 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1338 | }, |
| 1339 | [max11617] = { |
| 1340 | .bits = 12, |
| 1341 | .int_vref_mv = 2048, |
| 1342 | .mode_list = max1238_mode_list, |
| 1343 | .num_modes = ARRAY_SIZE(max1238_mode_list), |
| 1344 | .default_mode = s0to11, |
| 1345 | .info = &max1238_info, |
| 1346 | .channels = max1238_channels, |
| 1347 | .num_channels = ARRAY_SIZE(max1238_channels), |
| 1348 | }, |
| 1349 | [max11644] = { |
| 1350 | .bits = 12, |
| 1351 | .int_vref_mv = 2048, |
| 1352 | .mode_list = max11644_mode_list, |
| 1353 | .num_modes = ARRAY_SIZE(max11644_mode_list), |
| 1354 | .default_mode = s0to1, |
| 1355 | .info = &max1238_info, |
| 1356 | .channels = max11644_channels, |
| 1357 | .num_channels = ARRAY_SIZE(max11644_channels), |
| 1358 | }, |
| 1359 | [max11645] = { |
| 1360 | .bits = 12, |
| 1361 | .int_vref_mv = 4096, |
| 1362 | .mode_list = max11644_mode_list, |
| 1363 | .num_modes = ARRAY_SIZE(max11644_mode_list), |
| 1364 | .default_mode = s0to1, |
| 1365 | .info = &max1238_info, |
| 1366 | .channels = max11644_channels, |
| 1367 | .num_channels = ARRAY_SIZE(max11644_channels), |
| 1368 | }, |
| 1369 | [max11646] = { |
| 1370 | .bits = 10, |
| 1371 | .int_vref_mv = 2048, |
| 1372 | .mode_list = max11644_mode_list, |
| 1373 | .num_modes = ARRAY_SIZE(max11644_mode_list), |
| 1374 | .default_mode = s0to1, |
| 1375 | .info = &max1238_info, |
| 1376 | .channels = max11646_channels, |
| 1377 | .num_channels = ARRAY_SIZE(max11646_channels), |
| 1378 | }, |
| 1379 | [max11647] = { |
| 1380 | .bits = 10, |
| 1381 | .int_vref_mv = 4096, |
| 1382 | .mode_list = max11644_mode_list, |
| 1383 | .num_modes = ARRAY_SIZE(max11644_mode_list), |
| 1384 | .default_mode = s0to1, |
| 1385 | .info = &max1238_info, |
| 1386 | .channels = max11646_channels, |
| 1387 | .num_channels = ARRAY_SIZE(max11646_channels), |
| 1388 | }, |
| 1389 | }; |
| 1390 | |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1391 | static int max1363_initial_setup(struct max1363_state *st) |
| 1392 | { |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1393 | st->setupbyte = MAX1363_SETUP_INT_CLOCK |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1394 | | MAX1363_SETUP_UNIPOLAR |
| 1395 | | MAX1363_SETUP_NORESET; |
| 1396 | |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1397 | if (st->vref) |
| 1398 | st->setupbyte |= MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF; |
| 1399 | else |
| 1400 | st->setupbyte |= MAX1363_SETUP_POWER_UP_INT_REF |
| 1401 | | MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT; |
| 1402 | |
Peter Meerwald | 71d2c12 | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 1403 | /* Set scan mode writes the config anyway so wait until then */ |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1404 | st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); |
| 1405 | st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; |
| 1406 | st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte); |
| 1407 | |
| 1408 | return max1363_set_scan_mode(st); |
| 1409 | } |
| 1410 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 1411 | static int max1363_alloc_scan_masks(struct iio_dev *indio_dev) |
Michael Hennerich | cd4361c | 2012-02-22 13:16:49 +0100 | [diff] [blame] | 1412 | { |
| 1413 | struct max1363_state *st = iio_priv(indio_dev); |
| 1414 | unsigned long *masks; |
| 1415 | int i; |
| 1416 | |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1417 | masks = devm_kzalloc(&indio_dev->dev, |
| 1418 | BITS_TO_LONGS(MAX1363_MAX_CHANNELS) * sizeof(long) * |
| 1419 | (st->chip_info->num_modes + 1), GFP_KERNEL); |
Michael Hennerich | cd4361c | 2012-02-22 13:16:49 +0100 | [diff] [blame] | 1420 | if (!masks) |
| 1421 | return -ENOMEM; |
| 1422 | |
| 1423 | for (i = 0; i < st->chip_info->num_modes; i++) |
| 1424 | bitmap_copy(masks + BITS_TO_LONGS(MAX1363_MAX_CHANNELS)*i, |
| 1425 | max1363_mode_table[st->chip_info->mode_list[i]] |
| 1426 | .modemask, MAX1363_MAX_CHANNELS); |
| 1427 | |
| 1428 | indio_dev->available_scan_masks = masks; |
| 1429 | |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 1433 | static irqreturn_t max1363_trigger_handler(int irq, void *p) |
| 1434 | { |
| 1435 | struct iio_poll_func *pf = p; |
| 1436 | struct iio_dev *indio_dev = pf->indio_dev; |
| 1437 | struct max1363_state *st = iio_priv(indio_dev); |
| 1438 | s64 time_ns; |
| 1439 | __u8 *rxbuf; |
| 1440 | int b_sent; |
| 1441 | size_t d_size; |
| 1442 | unsigned long numvals = bitmap_weight(st->current_mode->modemask, |
| 1443 | MAX1363_MAX_CHANNELS); |
| 1444 | |
| 1445 | /* Ensure the timestamp is 8 byte aligned */ |
| 1446 | if (st->chip_info->bits != 8) |
| 1447 | d_size = numvals*2; |
| 1448 | else |
| 1449 | d_size = numvals; |
| 1450 | if (indio_dev->scan_timestamp) { |
| 1451 | d_size += sizeof(s64); |
| 1452 | if (d_size % sizeof(s64)) |
| 1453 | d_size += sizeof(s64) - (d_size % sizeof(s64)); |
| 1454 | } |
| 1455 | /* Monitor mode prevents reading. Whilst not currently implemented |
| 1456 | * might as well have this test in here in the meantime as it does |
| 1457 | * no harm. |
| 1458 | */ |
| 1459 | if (numvals == 0) |
| 1460 | goto done; |
| 1461 | |
| 1462 | rxbuf = kmalloc(d_size, GFP_KERNEL); |
| 1463 | if (rxbuf == NULL) |
| 1464 | goto done; |
| 1465 | if (st->chip_info->bits != 8) |
| 1466 | b_sent = i2c_master_recv(st->client, rxbuf, numvals*2); |
| 1467 | else |
| 1468 | b_sent = i2c_master_recv(st->client, rxbuf, numvals); |
| 1469 | if (b_sent < 0) |
| 1470 | goto done_free; |
| 1471 | |
| 1472 | time_ns = iio_get_time_ns(); |
| 1473 | |
| 1474 | if (indio_dev->scan_timestamp) |
| 1475 | memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns)); |
| 1476 | iio_push_to_buffers(indio_dev, rxbuf); |
| 1477 | |
| 1478 | done_free: |
| 1479 | kfree(rxbuf); |
| 1480 | done: |
| 1481 | iio_trigger_notify_done(indio_dev->trig); |
| 1482 | |
| 1483 | return IRQ_HANDLED; |
| 1484 | } |
| 1485 | |
Jonathan Cameron | ec44372 | 2012-10-06 14:19:01 +0100 | [diff] [blame] | 1486 | static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = { |
Jonathan Cameron | b3bcbfc | 2012-10-06 14:10:05 +0100 | [diff] [blame] | 1487 | .postenable = &iio_triggered_buffer_postenable, |
| 1488 | .preenable = &iio_sw_buffer_preenable, |
| 1489 | .predisable = &iio_triggered_buffer_predisable, |
| 1490 | }; |
| 1491 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 1492 | static int max1363_probe(struct i2c_client *client, |
| 1493 | const struct i2c_device_id *id) |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1494 | { |
Michael Hennerich | cd4361c | 2012-02-22 13:16:49 +0100 | [diff] [blame] | 1495 | int ret; |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 1496 | struct max1363_state *st; |
| 1497 | struct iio_dev *indio_dev; |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1498 | struct regulator *vref; |
Dan Carpenter | f88af7e | 2011-06-08 09:42:21 +0300 | [diff] [blame] | 1499 | |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 1500 | indio_dev = iio_device_alloc(sizeof(struct max1363_state)); |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 1501 | if (indio_dev == NULL) { |
| 1502 | ret = -ENOMEM; |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1503 | goto error_out; |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 1504 | } |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1505 | |
Guenter Roeck | 315ce4b | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 1506 | indio_dev->dev.of_node = client->dev.of_node; |
Jonathan Cameron | 0b27d67 | 2012-04-10 21:11:07 +0100 | [diff] [blame] | 1507 | ret = iio_map_array_register(indio_dev, client->dev.platform_data); |
| 1508 | if (ret < 0) |
| 1509 | goto error_free_device; |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1510 | |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 1511 | st = iio_priv(indio_dev); |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1512 | |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1513 | st->reg = devm_regulator_get(&client->dev, "vcc"); |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1514 | if (IS_ERR(st->reg)) { |
| 1515 | ret = PTR_ERR(st->reg); |
| 1516 | goto error_unregister_map; |
| 1517 | } |
| 1518 | |
| 1519 | ret = regulator_enable(st->reg); |
| 1520 | if (ret) |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1521 | goto error_unregister_map; |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1522 | |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1523 | /* this is only used for device removal purposes */ |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 1524 | i2c_set_clientdata(client, indio_dev); |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1525 | |
Jonathan Cameron | 962a4cc | 2010-06-26 12:54:13 +0100 | [diff] [blame] | 1526 | st->chip_info = &max1363_chip_info_tbl[id->driver_data]; |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1527 | st->client = client; |
| 1528 | |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1529 | st->vref_uv = st->chip_info->int_vref_mv * 1000; |
| 1530 | vref = devm_regulator_get(&client->dev, "vref"); |
| 1531 | if (!IS_ERR(vref)) { |
| 1532 | int vref_uv; |
| 1533 | |
| 1534 | ret = regulator_enable(vref); |
| 1535 | if (ret) |
| 1536 | goto error_disable_reg; |
| 1537 | st->vref = vref; |
| 1538 | vref_uv = regulator_get_voltage(vref); |
| 1539 | if (vref_uv <= 0) { |
| 1540 | ret = -EINVAL; |
| 1541 | goto error_disable_reg; |
| 1542 | } |
| 1543 | st->vref_uv = vref_uv; |
| 1544 | } |
| 1545 | |
Michael Hennerich | cd4361c | 2012-02-22 13:16:49 +0100 | [diff] [blame] | 1546 | ret = max1363_alloc_scan_masks(indio_dev); |
| 1547 | if (ret) |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1548 | goto error_disable_reg; |
Jonathan Cameron | 82020b0 | 2010-05-04 14:43:03 +0100 | [diff] [blame] | 1549 | |
Peter Meerwald | 71d2c12 | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 1550 | /* Establish that the iio_dev is a child of the i2c device */ |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 1551 | indio_dev->dev.parent = &client->dev; |
Jonathan Cameron | 845bd12 | 2011-05-18 14:41:44 +0100 | [diff] [blame] | 1552 | indio_dev->name = id->name; |
Jonathan Cameron | 8e7d967 | 2011-08-30 12:32:45 +0100 | [diff] [blame] | 1553 | indio_dev->channels = st->chip_info->channels; |
| 1554 | indio_dev->num_channels = st->chip_info->num_channels; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 1555 | indio_dev->info = st->chip_info->info; |
| 1556 | indio_dev->modes = INDIO_DIRECT_MODE; |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1557 | ret = max1363_initial_setup(st); |
Jonathan Cameron | 58f0a25 | 2011-05-18 14:42:38 +0100 | [diff] [blame] | 1558 | if (ret < 0) |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1559 | goto error_disable_reg; |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1560 | |
Peter Meerwald | 4389fbe | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 1561 | ret = iio_triggered_buffer_setup(indio_dev, NULL, |
| 1562 | &max1363_trigger_handler, &max1363_buffered_setup_ops); |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1563 | if (ret) |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1564 | goto error_disable_reg; |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1565 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 1566 | if (client->irq) { |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1567 | ret = devm_request_threaded_irq(&client->dev, st->client->irq, |
Jonathan Cameron | aaf370d | 2011-05-18 14:41:16 +0100 | [diff] [blame] | 1568 | NULL, |
| 1569 | &max1363_event_handler, |
| 1570 | IRQF_TRIGGER_RISING | IRQF_ONESHOT, |
| 1571 | "max1363_event", |
| 1572 | indio_dev); |
Jonathan Cameron | 298cd97 | 2011-05-18 14:40:53 +0100 | [diff] [blame] | 1573 | |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 1574 | if (ret) |
Jonathan Cameron | ec44372 | 2012-10-06 14:19:01 +0100 | [diff] [blame] | 1575 | goto error_uninit_buffer; |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 1578 | ret = iio_device_register(indio_dev); |
| 1579 | if (ret < 0) |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1580 | goto error_uninit_buffer; |
Dan Carpenter | f88af7e | 2011-06-08 09:42:21 +0300 | [diff] [blame] | 1581 | |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 1582 | return 0; |
Guenter Roeck | 7c3e867 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1583 | |
Jonathan Cameron | ec44372 | 2012-10-06 14:19:01 +0100 | [diff] [blame] | 1584 | error_uninit_buffer: |
Peter Meerwald | 4389fbe | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 1585 | iio_triggered_buffer_cleanup(indio_dev); |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1586 | error_disable_reg: |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1587 | if (st->vref) |
| 1588 | regulator_disable(st->vref); |
Jonathan Cameron | b77b8f8 | 2012-10-06 14:39:19 +0100 | [diff] [blame] | 1589 | regulator_disable(st->reg); |
Guenter Roeck | 678fb42 | 2012-12-24 06:24:00 +0000 | [diff] [blame] | 1590 | error_unregister_map: |
Guenter Roeck | 6cb2afd | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 1591 | iio_map_array_unregister(indio_dev); |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1592 | error_free_device: |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 1593 | iio_device_free(indio_dev); |
Dan Carpenter | f88af7e | 2011-06-08 09:42:21 +0300 | [diff] [blame] | 1594 | error_out: |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1595 | return ret; |
| 1596 | } |
| 1597 | |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 1598 | static int max1363_remove(struct i2c_client *client) |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1599 | { |
Jonathan Cameron | 3dba81b | 2011-04-15 18:55:59 +0100 | [diff] [blame] | 1600 | struct iio_dev *indio_dev = i2c_get_clientdata(client); |
| 1601 | struct max1363_state *st = iio_priv(indio_dev); |
Jonathan Cameron | 440a520 | 2010-06-26 12:54:23 +0100 | [diff] [blame] | 1602 | |
Jonathan Cameron | d2fffd6 | 2011-10-14 14:46:58 +0100 | [diff] [blame] | 1603 | iio_device_unregister(indio_dev); |
Peter Meerwald | 4389fbe | 2012-12-30 23:26:00 +0000 | [diff] [blame] | 1604 | iio_triggered_buffer_cleanup(indio_dev); |
Guenter Roeck | a405b00 | 2013-02-03 00:59:00 +0000 | [diff] [blame] | 1605 | if (st->vref) |
| 1606 | regulator_disable(st->vref); |
Guenter Roeck | 678fb42 | 2012-12-24 06:24:00 +0000 | [diff] [blame] | 1607 | regulator_disable(st->reg); |
Guenter Roeck | 6cb2afd | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 1608 | iio_map_array_unregister(indio_dev); |
Lars-Peter Clausen | 7cbb753 | 2012-04-26 13:35:01 +0200 | [diff] [blame] | 1609 | iio_device_free(indio_dev); |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1610 | |
| 1611 | return 0; |
| 1612 | } |
| 1613 | |
| 1614 | static const struct i2c_device_id max1363_id[] = { |
| 1615 | { "max1361", max1361 }, |
| 1616 | { "max1362", max1362 }, |
| 1617 | { "max1363", max1363 }, |
| 1618 | { "max1364", max1364 }, |
Jonathan Cameron | 3bf877c | 2010-05-04 14:43:10 +0100 | [diff] [blame] | 1619 | { "max1036", max1036 }, |
| 1620 | { "max1037", max1037 }, |
| 1621 | { "max1038", max1038 }, |
| 1622 | { "max1039", max1039 }, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1623 | { "max1136", max1136 }, |
| 1624 | { "max1137", max1137 }, |
| 1625 | { "max1138", max1138 }, |
| 1626 | { "max1139", max1139 }, |
| 1627 | { "max1236", max1236 }, |
| 1628 | { "max1237", max1237 }, |
| 1629 | { "max1238", max1238 }, |
| 1630 | { "max1239", max1239 }, |
Jonathan Cameron | 3bf877c | 2010-05-04 14:43:10 +0100 | [diff] [blame] | 1631 | { "max11600", max11600 }, |
| 1632 | { "max11601", max11601 }, |
| 1633 | { "max11602", max11602 }, |
| 1634 | { "max11603", max11603 }, |
| 1635 | { "max11604", max11604 }, |
| 1636 | { "max11605", max11605 }, |
Jonathan Cameron | c3fa0fdd | 2010-05-04 14:43:09 +0100 | [diff] [blame] | 1637 | { "max11606", max11606 }, |
| 1638 | { "max11607", max11607 }, |
| 1639 | { "max11608", max11608 }, |
| 1640 | { "max11609", max11609 }, |
| 1641 | { "max11610", max11610 }, |
| 1642 | { "max11611", max11611 }, |
| 1643 | { "max11612", max11612 }, |
| 1644 | { "max11613", max11613 }, |
| 1645 | { "max11614", max11614 }, |
| 1646 | { "max11615", max11615 }, |
| 1647 | { "max11616", max11616 }, |
| 1648 | { "max11617", max11617 }, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1649 | {} |
| 1650 | }; |
| 1651 | |
| 1652 | MODULE_DEVICE_TABLE(i2c, max1363_id); |
| 1653 | |
| 1654 | static struct i2c_driver max1363_driver = { |
| 1655 | .driver = { |
| 1656 | .name = "max1363", |
| 1657 | }, |
| 1658 | .probe = max1363_probe, |
Greg Kroah-Hartman | fc52692 | 2012-12-21 13:21:43 -0800 | [diff] [blame] | 1659 | .remove = max1363_remove, |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1660 | .id_table = max1363_id, |
| 1661 | }; |
Lars-Peter Clausen | 6e5af18 | 2011-11-16 10:13:38 +0100 | [diff] [blame] | 1662 | module_i2c_driver(max1363_driver); |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1663 | |
Jonathan Cameron | 0f8c962 | 2012-09-02 21:34:59 +0100 | [diff] [blame] | 1664 | MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); |
Jonathan Cameron | d1325cf | 2009-08-18 18:06:20 +0100 | [diff] [blame] | 1665 | MODULE_DESCRIPTION("Maxim 1363 ADC"); |
| 1666 | MODULE_LICENSE("GPL v2"); |