Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: iio: Add iio_triggered_ring postenable and predisable + use in drivers

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Barry Song <21cnbao@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Jonathan Cameron and committed by
Greg Kroah-Hartman
c3db00cc 15744090

+41 -158
+2 -18
drivers/staging/iio/accel/adis16209_ring.c
··· 186 186 return 0; 187 187 } 188 188 189 - static int adis16209_data_rdy_ring_postenable(struct iio_dev *indio_dev) 190 - { 191 - return indio_dev->trig 192 - ? iio_trigger_attach_poll_func(indio_dev->trig, 193 - indio_dev->pollfunc) 194 - : 0; 195 - } 196 - 197 - static int adis16209_data_rdy_ring_predisable(struct iio_dev *indio_dev) 198 - { 199 - return indio_dev->trig 200 - ? iio_trigger_dettach_poll_func(indio_dev->trig, 201 - indio_dev->pollfunc) 202 - : 0; 203 - } 204 - 205 189 void adis16209_unconfigure_ring(struct iio_dev *indio_dev) 206 190 { 207 191 kfree(indio_dev->pollfunc); ··· 221 237 /* Effectively select the ring buffer implementation */ 222 238 iio_ring_sw_register_funcs(&ring->access); 223 239 ring->preenable = &adis16209_data_rdy_ring_preenable; 224 - ring->postenable = &adis16209_data_rdy_ring_postenable; 225 - ring->predisable = &adis16209_data_rdy_ring_predisable; 240 + ring->postenable = &iio_triggered_ring_postenable; 241 + ring->predisable = &iio_triggered_ring_predisable; 226 242 ring->owner = THIS_MODULE; 227 243 228 244 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16209_poll_func_th);
+2 -18
drivers/staging/iio/accel/adis16240_ring.c
··· 176 176 return 0; 177 177 } 178 178 179 - static int adis16240_data_rdy_ring_postenable(struct iio_dev *indio_dev) 180 - { 181 - return indio_dev->trig 182 - ? iio_trigger_attach_poll_func(indio_dev->trig, 183 - indio_dev->pollfunc) 184 - : 0; 185 - } 186 - 187 - static int adis16240_data_rdy_ring_predisable(struct iio_dev *indio_dev) 188 - { 189 - return indio_dev->trig 190 - ? iio_trigger_dettach_poll_func(indio_dev->trig, 191 - indio_dev->pollfunc) 192 - : 0; 193 - } 194 - 195 179 void adis16240_unconfigure_ring(struct iio_dev *indio_dev) 196 180 { 197 181 kfree(indio_dev->pollfunc); ··· 209 225 /* Effectively select the ring buffer implementation */ 210 226 iio_ring_sw_register_funcs(&ring->access); 211 227 ring->preenable = &adis16240_data_rdy_ring_preenable; 212 - ring->postenable = &adis16240_data_rdy_ring_postenable; 213 - ring->predisable = &adis16240_data_rdy_ring_predisable; 228 + ring->postenable = &iio_triggered_ring_postenable; 229 + ring->predisable = &iio_triggered_ring_predisable; 214 230 ring->owner = THIS_MODULE; 215 231 216 232 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16240_poll_func_th);
+2 -19
drivers/staging/iio/accel/lis3l02dq_ring.c
··· 339 339 return 0; 340 340 } 341 341 342 - static int lis3l02dq_data_rdy_ring_postenable(struct iio_dev *indio_dev) 343 - { 344 - return indio_dev->trig 345 - ? iio_trigger_attach_poll_func(indio_dev->trig, 346 - indio_dev->pollfunc) 347 - : 0; 348 - } 349 - 350 - static int lis3l02dq_data_rdy_ring_predisable(struct iio_dev *indio_dev) 351 - { 352 - return indio_dev->trig 353 - ? iio_trigger_dettach_poll_func(indio_dev->trig, 354 - indio_dev->pollfunc) 355 - : 0; 356 - } 357 - 358 - 359 342 /* Caller responsible for locking as necessary. */ 360 343 static int 361 344 __lis3l02dq_write_data_ready_config(struct device *dev, ··· 545 562 /* Effectively select the ring buffer implementation */ 546 563 iio_ring_sw_register_funcs(&ring->access); 547 564 ring->preenable = &lis3l02dq_data_rdy_ring_preenable; 548 - ring->postenable = &lis3l02dq_data_rdy_ring_postenable; 549 - ring->predisable = &lis3l02dq_data_rdy_ring_predisable; 565 + ring->postenable = &iio_triggered_ring_postenable; 566 + ring->predisable = &iio_triggered_ring_predisable; 550 567 ring->owner = THIS_MODULE; 551 568 552 569 ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th);
+2 -31
drivers/staging/iio/adc/max1363_ring.c
··· 105 105 return 0; 106 106 } 107 107 108 - /** 109 - * max1363_ring_postenable() - typical ring post enable 110 - * 111 - * Only not moved into the core for the hardware ring buffer cases 112 - * that are more sophisticated. 113 - **/ 114 - static int max1363_ring_postenable(struct iio_dev *indio_dev) 115 - { 116 - if (indio_dev->trig == NULL) 117 - return 0; 118 - return iio_trigger_attach_poll_func(indio_dev->trig, 119 - indio_dev->pollfunc); 120 - } 121 - 122 - /** 123 - * max1363_ring_predisable() - runs just prior to ring buffer being disabled 124 - * 125 - * Typical predisable function which ensures that no trigger events can 126 - * occur before we disable the ring buffer (and hence would have no idea 127 - * what to do with them) 128 - **/ 129 - static int max1363_ring_predisable(struct iio_dev *indio_dev) 130 - { 131 - if (indio_dev->trig) 132 - return iio_trigger_dettach_poll_func(indio_dev->trig, 133 - indio_dev->pollfunc); 134 - else 135 - return 0; 136 - } 137 108 138 109 /** 139 110 * max1363_poll_func_th() - th of trigger launched polling to ring buffer ··· 199 228 goto error_deallocate_sw_rb; 200 229 201 230 /* Ring buffer functions - here trigger setup related */ 202 - indio_dev->ring->postenable = &max1363_ring_postenable; 231 + indio_dev->ring->postenable = &iio_triggered_ring_postenable; 203 232 indio_dev->ring->preenable = &max1363_ring_preenable; 204 - indio_dev->ring->predisable = &max1363_ring_predisable; 233 + indio_dev->ring->predisable = &iio_triggered_ring_predisable; 205 234 INIT_WORK(&st->poll_work, &max1363_poll_bh_to_ring); 206 235 207 236 /* Flag that polled ring buffering is possible */
+2 -18
drivers/staging/iio/gyro/adis16260_ring.c
··· 179 179 return 0; 180 180 } 181 181 182 - static int adis16260_data_rdy_ring_postenable(struct iio_dev *indio_dev) 183 - { 184 - return indio_dev->trig 185 - ? iio_trigger_attach_poll_func(indio_dev->trig, 186 - indio_dev->pollfunc) 187 - : 0; 188 - } 189 - 190 - static int adis16260_data_rdy_ring_predisable(struct iio_dev *indio_dev) 191 - { 192 - return indio_dev->trig 193 - ? iio_trigger_dettach_poll_func(indio_dev->trig, 194 - indio_dev->pollfunc) 195 - : 0; 196 - } 197 - 198 182 void adis16260_unconfigure_ring(struct iio_dev *indio_dev) 199 183 { 200 184 kfree(indio_dev->pollfunc); ··· 211 227 /* Effectively select the ring buffer implementation */ 212 228 iio_ring_sw_register_funcs(&ring->access); 213 229 ring->preenable = &adis16260_data_rdy_ring_preenable; 214 - ring->postenable = &adis16260_data_rdy_ring_postenable; 215 - ring->predisable = &adis16260_data_rdy_ring_predisable; 230 + ring->postenable = &iio_triggered_ring_postenable; 231 + ring->predisable = &iio_triggered_ring_predisable; 216 232 ring->owner = THIS_MODULE; 217 233 218 234 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16260_poll_func_th);
+2 -18
drivers/staging/iio/imu/adis16300_ring.c
··· 200 200 return 0; 201 201 } 202 202 203 - static int adis16300_data_rdy_ring_postenable(struct iio_dev *indio_dev) 204 - { 205 - return indio_dev->trig 206 - ? iio_trigger_attach_poll_func(indio_dev->trig, 207 - indio_dev->pollfunc) 208 - : 0; 209 - } 210 - 211 - static int adis16300_data_rdy_ring_predisable(struct iio_dev *indio_dev) 212 - { 213 - return indio_dev->trig 214 - ? iio_trigger_dettach_poll_func(indio_dev->trig, 215 - indio_dev->pollfunc) 216 - : 0; 217 - } 218 - 219 203 void adis16300_unconfigure_ring(struct iio_dev *indio_dev) 220 204 { 221 205 kfree(indio_dev->pollfunc); ··· 236 252 /* Effectively select the ring buffer implementation */ 237 253 iio_ring_sw_register_funcs(&ring->access); 238 254 ring->preenable = &adis16300_data_rdy_ring_preenable; 239 - ring->postenable = &adis16300_data_rdy_ring_postenable; 240 - ring->predisable = &adis16300_data_rdy_ring_predisable; 255 + ring->postenable = &iio_triggered_ring_postenable; 256 + ring->predisable = &iio_triggered_ring_predisable; 241 257 ring->owner = THIS_MODULE; 242 258 243 259 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16300_poll_func_th);
+2 -18
drivers/staging/iio/imu/adis16350_ring.c
··· 203 203 return 0; 204 204 } 205 205 206 - static int adis16350_data_rdy_ring_postenable(struct iio_dev *indio_dev) 207 - { 208 - return indio_dev->trig 209 - ? iio_trigger_attach_poll_func(indio_dev->trig, 210 - indio_dev->pollfunc) 211 - : 0; 212 - } 213 - 214 - static int adis16350_data_rdy_ring_predisable(struct iio_dev *indio_dev) 215 - { 216 - return indio_dev->trig 217 - ? iio_trigger_dettach_poll_func(indio_dev->trig, 218 - indio_dev->pollfunc) 219 - : 0; 220 - } 221 - 222 206 void adis16350_unconfigure_ring(struct iio_dev *indio_dev) 223 207 { 224 208 kfree(indio_dev->pollfunc); ··· 241 257 /* Effectively select the ring buffer implementation */ 242 258 iio_ring_sw_register_funcs(&ring->access); 243 259 ring->preenable = &adis16350_data_rdy_ring_preenable; 244 - ring->postenable = &adis16350_data_rdy_ring_postenable; 245 - ring->predisable = &adis16350_data_rdy_ring_predisable; 260 + ring->postenable = &iio_triggered_ring_postenable; 261 + ring->predisable = &iio_triggered_ring_predisable; 246 262 ring->owner = THIS_MODULE; 247 263 248 264 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16350_poll_func_th);
+2 -18
drivers/staging/iio/imu/adis16400_ring.c
··· 209 209 return 0; 210 210 } 211 211 212 - static int adis16400_data_rdy_ring_postenable(struct iio_dev *indio_dev) 213 - { 214 - return indio_dev->trig 215 - ? iio_trigger_attach_poll_func(indio_dev->trig, 216 - indio_dev->pollfunc) 217 - : 0; 218 - } 219 - 220 - static int adis16400_data_rdy_ring_predisable(struct iio_dev *indio_dev) 221 - { 222 - return indio_dev->trig 223 - ? iio_trigger_dettach_poll_func(indio_dev->trig, 224 - indio_dev->pollfunc) 225 - : 0; 226 - } 227 - 228 212 void adis16400_unconfigure_ring(struct iio_dev *indio_dev) 229 213 { 230 214 kfree(indio_dev->pollfunc); ··· 248 264 /* Effectively select the ring buffer implementation */ 249 265 iio_ring_sw_register_funcs(&ring->access); 250 266 ring->preenable = &adis16400_data_rdy_ring_preenable; 251 - ring->postenable = &adis16400_data_rdy_ring_postenable; 252 - ring->predisable = &adis16400_data_rdy_ring_predisable; 267 + ring->postenable = &iio_triggered_ring_postenable; 268 + ring->predisable = &iio_triggered_ring_predisable; 253 269 ring->owner = THIS_MODULE; 254 270 255 271 ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16400_poll_func_th);
+18
drivers/staging/iio/industrialio-trigger.c
··· 411 411 return 0; 412 412 } 413 413 EXPORT_SYMBOL(iio_alloc_pollfunc); 414 + 415 + int iio_triggered_ring_postenable(struct iio_dev *indio_dev) 416 + { 417 + return indio_dev->trig 418 + ? iio_trigger_attach_poll_func(indio_dev->trig, 419 + indio_dev->pollfunc) 420 + : 0; 421 + } 422 + EXPORT_SYMBOL(iio_triggered_ring_postenable); 423 + 424 + int iio_triggered_ring_predisable(struct iio_dev *indio_dev) 425 + { 426 + return indio_dev->trig 427 + ? iio_trigger_dettach_poll_func(indio_dev->trig, 428 + indio_dev->pollfunc) 429 + : 0; 430 + } 431 + EXPORT_SYMBOL(iio_triggered_ring_predisable);
+7
drivers/staging/iio/trigger.h
··· 152 152 void (*immediate)(struct iio_dev *indio_dev), 153 153 void (*main)(struct iio_dev *private_data)); 154 154 155 + /* 156 + * Two functions for common case where all that happens is a pollfunc 157 + * is attached and detached form a trigger 158 + */ 159 + int iio_triggered_ring_postenable(struct iio_dev *indio_dev); 160 + int iio_triggered_ring_predisable(struct iio_dev *indio_dev); 161 + 155 162 struct iio_trigger *iio_allocate_trigger(void); 156 163 157 164 void iio_free_trigger(struct iio_trigger *trig);