@@ -123,14 +123,14 @@ static int ad7150_read_raw(struct iio_dev *indio_dev,
123123 }
124124}
125125
126- static int ad7150_read_event_config (struct iio_dev * indio_dev , u64 event_code )
126+ static int ad7150_read_event_config (struct iio_dev * indio_dev ,
127+ const struct iio_chan_spec * chan , enum iio_event_type type ,
128+ enum iio_event_direction dir )
127129{
128130 int ret ;
129131 u8 threshtype ;
130132 bool adaptive ;
131133 struct ad7150_chip_info * chip = iio_priv (indio_dev );
132- int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR (event_code ) ==
133- IIO_EV_DIR_RISING );
134134
135135 ret = i2c_smbus_read_byte_data (chip -> client , AD7150_CFG );
136136 if (ret < 0 )
@@ -139,42 +139,47 @@ static int ad7150_read_event_config(struct iio_dev *indio_dev, u64 event_code)
139139 threshtype = (ret >> 5 ) & 0x03 ;
140140 adaptive = !!(ret & 0x80 );
141141
142- switch (IIO_EVENT_CODE_EXTRACT_TYPE ( event_code ) ) {
142+ switch (type ) {
143143 case IIO_EV_TYPE_MAG_ADAPTIVE :
144- if (rising )
144+ if (dir == IIO_EV_DIR_RISING )
145145 return adaptive && (threshtype == 0x1 );
146146 else
147147 return adaptive && (threshtype == 0x0 );
148148 case IIO_EV_TYPE_THRESH_ADAPTIVE :
149- if (rising )
149+ if (dir == IIO_EV_DIR_RISING )
150150 return adaptive && (threshtype == 0x3 );
151151 else
152152 return adaptive && (threshtype == 0x2 );
153153
154154 case IIO_EV_TYPE_THRESH :
155- if (rising )
155+ if (dir == IIO_EV_DIR_RISING )
156156 return !adaptive && (threshtype == 0x1 );
157157 else
158158 return !adaptive && (threshtype == 0x0 );
159+ default :
160+ break ;
159161 }
160162 return - EINVAL ;
161163}
162164
163165/* lock should be held */
164- static int ad7150_write_event_params (struct iio_dev * indio_dev , u64 event_code )
166+ static int ad7150_write_event_params (struct iio_dev * indio_dev ,
167+ unsigned int chan , enum iio_event_type type ,
168+ enum iio_event_direction dir )
165169{
166170 int ret ;
167171 u16 value ;
168172 u8 sens , timeout ;
169173 struct ad7150_chip_info * chip = iio_priv (indio_dev );
170- int chan = IIO_EVENT_CODE_EXTRACT_CHAN (event_code );
171- int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR (event_code ) ==
172- IIO_EV_DIR_RISING );
174+ int rising = (dir == IIO_EV_DIR_RISING );
175+ u64 event_code ;
176+
177+ event_code = IIO_UNMOD_EVENT_CODE (IIO_CAPACITANCE , chan , type , dir );
173178
174179 if (event_code != chip -> current_event )
175180 return 0 ;
176181
177- switch (IIO_EVENT_CODE_EXTRACT_TYPE ( event_code ) ) {
182+ switch (type ) {
178183 /* Note completely different from the adaptive versions */
179184 case IIO_EV_TYPE_THRESH :
180185 value = chip -> threshold [rising ][chan ];
@@ -211,18 +216,20 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, u64 event_code)
211216}
212217
213218static int ad7150_write_event_config (struct iio_dev * indio_dev ,
214- u64 event_code , int state )
219+ const struct iio_chan_spec * chan , enum iio_event_type type ,
220+ enum iio_event_direction dir , int state )
215221{
216222 u8 thresh_type , cfg , adaptive ;
217223 int ret ;
218224 struct ad7150_chip_info * chip = iio_priv (indio_dev );
219- int rising = !!( IIO_EVENT_CODE_EXTRACT_DIR ( event_code ) ==
220- IIO_EV_DIR_RISING ) ;
225+ int rising = ( dir == IIO_EV_DIR_RISING );
226+ u64 event_code ;
221227
222228 /* Something must always be turned on */
223229 if (state == 0 )
224230 return - EINVAL ;
225231
232+ event_code = IIO_UNMOD_EVENT_CODE (chan -> type , chan -> channel , type , dir );
226233 if (event_code == chip -> current_event )
227234 return 0 ;
228235 mutex_lock (& chip -> state_lock );
@@ -232,7 +239,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
232239
233240 cfg = ret & ~((0x03 << 5 ) | (0x1 << 7 ));
234241
235- switch (IIO_EVENT_CODE_EXTRACT_TYPE ( event_code ) ) {
242+ switch (type ) {
236243 case IIO_EV_TYPE_MAG_ADAPTIVE :
237244 adaptive = 1 ;
238245 if (rising )
@@ -268,69 +275,68 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
268275 chip -> current_event = event_code ;
269276
270277 /* update control attributes */
271- ret = ad7150_write_event_params (indio_dev , event_code );
278+ ret = ad7150_write_event_params (indio_dev , chan -> channel , type , dir );
272279error_ret :
273280 mutex_unlock (& chip -> state_lock );
274281
275282 return 0 ;
276283}
277284
278285static int ad7150_read_event_value (struct iio_dev * indio_dev ,
279- u64 event_code ,
280- int * val )
286+ const struct iio_chan_spec * chan ,
287+ enum iio_event_type type ,
288+ enum iio_event_direction dir ,
289+ enum iio_event_info info ,
290+ int * val , int * val2 )
281291{
282- int chan = IIO_EVENT_CODE_EXTRACT_CHAN (event_code );
283292 struct ad7150_chip_info * chip = iio_priv (indio_dev );
284- int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR (event_code ) ==
285- IIO_EV_DIR_RISING );
293+ int rising = (dir == IIO_EV_DIR_RISING );
286294
287295 /* Complex register sharing going on here */
288- switch (IIO_EVENT_CODE_EXTRACT_TYPE ( event_code ) ) {
296+ switch (type ) {
289297 case IIO_EV_TYPE_MAG_ADAPTIVE :
290- * val = chip -> mag_sensitivity [rising ][chan ];
291- return 0 ;
292-
298+ * val = chip -> mag_sensitivity [rising ][chan -> channel ];
299+ return IIO_VAL_INT ;
293300 case IIO_EV_TYPE_THRESH_ADAPTIVE :
294- * val = chip -> thresh_sensitivity [rising ][chan ];
295- return 0 ;
296-
301+ * val = chip -> thresh_sensitivity [rising ][chan -> channel ];
302+ return IIO_VAL_INT ;
297303 case IIO_EV_TYPE_THRESH :
298- * val = chip -> threshold [rising ][chan ];
299- return 0 ;
300-
304+ * val = chip -> threshold [rising ][chan -> channel ];
305+ return IIO_VAL_INT ;
301306 default :
302307 return - EINVAL ;
303308 };
304309}
305310
306311static int ad7150_write_event_value (struct iio_dev * indio_dev ,
307- u64 event_code ,
308- int val )
312+ const struct iio_chan_spec * chan ,
313+ enum iio_event_type type ,
314+ enum iio_event_direction dir ,
315+ enum iio_event_info info ,
316+ int val , int val2 )
309317{
310318 int ret ;
311319 struct ad7150_chip_info * chip = iio_priv (indio_dev );
312- int chan = IIO_EVENT_CODE_EXTRACT_CHAN (event_code );
313- int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR (event_code ) ==
314- IIO_EV_DIR_RISING );
320+ int rising = (dir == IIO_EV_DIR_RISING );
315321
316322 mutex_lock (& chip -> state_lock );
317- switch (IIO_EVENT_CODE_EXTRACT_TYPE ( event_code ) ) {
323+ switch (type ) {
318324 case IIO_EV_TYPE_MAG_ADAPTIVE :
319- chip -> mag_sensitivity [rising ][chan ] = val ;
325+ chip -> mag_sensitivity [rising ][chan -> channel ] = val ;
320326 break ;
321327 case IIO_EV_TYPE_THRESH_ADAPTIVE :
322- chip -> thresh_sensitivity [rising ][chan ] = val ;
328+ chip -> thresh_sensitivity [rising ][chan -> channel ] = val ;
323329 break ;
324330 case IIO_EV_TYPE_THRESH :
325- chip -> threshold [rising ][chan ] = val ;
331+ chip -> threshold [rising ][chan -> channel ] = val ;
326332 break ;
327333 default :
328334 ret = - EINVAL ;
329335 goto error_ret ;
330336 }
331337
332338 /* write back if active */
333- ret = ad7150_write_event_params (indio_dev , event_code );
339+ ret = ad7150_write_event_params (indio_dev , chan -> channel , type , dir );
334340
335341error_ret :
336342 mutex_unlock (& chip -> state_lock );
@@ -374,17 +380,22 @@ static ssize_t ad7150_store_timeout(struct device *dev,
374380 struct ad7150_chip_info * chip = iio_priv (indio_dev );
375381 struct iio_dev_attr * this_attr = to_iio_dev_attr (attr );
376382 int chan = IIO_EVENT_CODE_EXTRACT_CHAN (this_attr -> address );
377- int rising = !!(IIO_EVENT_CODE_EXTRACT_DIR (this_attr -> address ) ==
378- IIO_EV_DIR_RISING );
383+ enum iio_event_direction dir ;
384+ enum iio_event_type type ;
385+ int rising ;
379386 u8 data ;
380387 int ret ;
381388
389+ type = IIO_EVENT_CODE_EXTRACT_TYPE (this_attr -> address );
390+ dir = IIO_EVENT_CODE_EXTRACT_DIR (this_attr -> address );
391+ rising = (dir == IIO_EV_DIR_RISING );
392+
382393 ret = kstrtou8 (buf , 10 , & data );
383394 if (ret < 0 )
384395 return ret ;
385396
386397 mutex_lock (& chip -> state_lock );
387- switch (IIO_EVENT_CODE_EXTRACT_TYPE ( this_attr -> address ) ) {
398+ switch (type ) {
388399 case IIO_EV_TYPE_MAG_ADAPTIVE :
389400 chip -> mag_timeout [rising ][chan ] = data ;
390401 break ;
@@ -396,7 +407,7 @@ static ssize_t ad7150_store_timeout(struct device *dev,
396407 goto error_ret ;
397408 }
398409
399- ret = ad7150_write_event_params (indio_dev , this_attr -> address );
410+ ret = ad7150_write_event_params (indio_dev , chan , type , dir );
400411error_ret :
401412 mutex_unlock (& chip -> state_lock );
402413
@@ -424,33 +435,57 @@ static AD7150_TIMEOUT(0, thresh_adaptive, falling, THRESH_ADAPTIVE, FALLING);
424435static AD7150_TIMEOUT (1 , thresh_adaptive , rising , THRESH_ADAPTIVE , RISING ) ;
425436static AD7150_TIMEOUT (1 , thresh_adaptive , falling , THRESH_ADAPTIVE , FALLING ) ;
426437
438+ static const struct iio_event_spec ad7150_events [] = {
439+ {
440+ .type = IIO_EV_TYPE_THRESH ,
441+ .dir = IIO_EV_DIR_RISING ,
442+ .mask_separate = BIT (IIO_EV_INFO_VALUE ) |
443+ BIT (IIO_EV_INFO_ENABLE ),
444+ }, {
445+ .type = IIO_EV_TYPE_THRESH ,
446+ .dir = IIO_EV_DIR_FALLING ,
447+ .mask_separate = BIT (IIO_EV_INFO_VALUE ) |
448+ BIT (IIO_EV_INFO_ENABLE ),
449+ }, {
450+ .type = IIO_EV_TYPE_THRESH_ADAPTIVE ,
451+ .dir = IIO_EV_DIR_RISING ,
452+ .mask_separate = BIT (IIO_EV_INFO_VALUE ) |
453+ BIT (IIO_EV_INFO_ENABLE ),
454+ }, {
455+ .type = IIO_EV_TYPE_THRESH_ADAPTIVE ,
456+ .dir = IIO_EV_DIR_FALLING ,
457+ .mask_separate = BIT (IIO_EV_INFO_VALUE ) |
458+ BIT (IIO_EV_INFO_ENABLE ),
459+ }, {
460+ .type = IIO_EV_TYPE_MAG_ADAPTIVE ,
461+ .dir = IIO_EV_DIR_RISING ,
462+ .mask_separate = BIT (IIO_EV_INFO_VALUE ) |
463+ BIT (IIO_EV_INFO_ENABLE ),
464+ }, {
465+ .type = IIO_EV_TYPE_MAG_ADAPTIVE ,
466+ .dir = IIO_EV_DIR_FALLING ,
467+ .mask_separate = BIT (IIO_EV_INFO_VALUE ) |
468+ BIT (IIO_EV_INFO_ENABLE ),
469+ },
470+ };
471+
427472static const struct iio_chan_spec ad7150_channels [] = {
428473 {
429474 .type = IIO_CAPACITANCE ,
430475 .indexed = 1 ,
431476 .channel = 0 ,
432477 .info_mask_separate = BIT (IIO_CHAN_INFO_RAW ) |
433478 BIT (IIO_CHAN_INFO_AVERAGE_RAW ),
434- .event_mask =
435- IIO_EV_BIT (IIO_EV_TYPE_THRESH , IIO_EV_DIR_RISING ) |
436- IIO_EV_BIT (IIO_EV_TYPE_THRESH , IIO_EV_DIR_FALLING ) |
437- IIO_EV_BIT (IIO_EV_TYPE_THRESH_ADAPTIVE , IIO_EV_DIR_RISING ) |
438- IIO_EV_BIT (IIO_EV_TYPE_THRESH_ADAPTIVE , IIO_EV_DIR_FALLING ) |
439- IIO_EV_BIT (IIO_EV_TYPE_MAG_ADAPTIVE , IIO_EV_DIR_RISING ) |
440- IIO_EV_BIT (IIO_EV_TYPE_MAG_ADAPTIVE , IIO_EV_DIR_FALLING )
479+ .event_spec = ad7150_events ,
480+ .num_event_specs = ARRAY_SIZE (ad7150_events ),
441481 }, {
442482 .type = IIO_CAPACITANCE ,
443483 .indexed = 1 ,
444484 .channel = 1 ,
445485 .info_mask_separate = BIT (IIO_CHAN_INFO_RAW ) |
446486 BIT (IIO_CHAN_INFO_AVERAGE_RAW ),
447- .event_mask =
448- IIO_EV_BIT (IIO_EV_TYPE_THRESH , IIO_EV_DIR_RISING ) |
449- IIO_EV_BIT (IIO_EV_TYPE_THRESH , IIO_EV_DIR_FALLING ) |
450- IIO_EV_BIT (IIO_EV_TYPE_THRESH_ADAPTIVE , IIO_EV_DIR_RISING ) |
451- IIO_EV_BIT (IIO_EV_TYPE_THRESH_ADAPTIVE , IIO_EV_DIR_FALLING ) |
452- IIO_EV_BIT (IIO_EV_TYPE_MAG_ADAPTIVE , IIO_EV_DIR_RISING ) |
453- IIO_EV_BIT (IIO_EV_TYPE_MAG_ADAPTIVE , IIO_EV_DIR_FALLING )
487+ .event_spec = ad7150_events ,
488+ .num_event_specs = ARRAY_SIZE (ad7150_events ),
454489 },
455490};
456491
@@ -541,10 +576,10 @@ static const struct iio_info ad7150_info = {
541576 .event_attrs = & ad7150_event_attribute_group ,
542577 .driver_module = THIS_MODULE ,
543578 .read_raw = & ad7150_read_raw ,
544- .read_event_config = & ad7150_read_event_config ,
545- .write_event_config = & ad7150_write_event_config ,
546- .read_event_value = & ad7150_read_event_value ,
547- .write_event_value = & ad7150_write_event_value ,
579+ .read_event_config_new = & ad7150_read_event_config ,
580+ .write_event_config_new = & ad7150_write_event_config ,
581+ .read_event_value_new = & ad7150_read_event_value ,
582+ .write_event_value_new = & ad7150_write_event_value ,
548583};
549584
550585/*
0 commit comments