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

Input: adc-joystick - add polled input device support

Add polled input device support to the adc-joystick driver. This is
useful for devices which do not have hardware capable triggers on
their SARADC. Code modified from adc-joystick.c changes made by Maya
Matuszczyk.

Signed-off-by: Maya Matuszczyk <maccraft123mc@gmail.com>
Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
Link: https://lore.kernel.org/r/20220816210440.14260-3-macroalpha82@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Chris Morgan and committed by
Dmitry Torokhov
24c06e00 c42a5ff5

+53 -12
+53 -12
drivers/input/joystick/adc-joystick.c
··· 26 26 struct adc_joystick_axis *axes; 27 27 struct iio_channel *chans; 28 28 int num_chans; 29 + bool polled; 29 30 }; 31 + 32 + static void adc_joystick_poll(struct input_dev *input) 33 + { 34 + struct adc_joystick *joy = input_get_drvdata(input); 35 + int i, val, ret; 36 + 37 + for (i = 0; i < joy->num_chans; i++) { 38 + ret = iio_read_channel_raw(&joy->chans[i], &val); 39 + if (ret < 0) 40 + return; 41 + input_report_abs(input, joy->axes[i].code, val); 42 + } 43 + input_sync(input); 44 + } 30 45 31 46 static int adc_joystick_handle(const void *data, void *private) 32 47 { ··· 194 179 int error; 195 180 int bits; 196 181 int i; 182 + unsigned int poll_interval; 197 183 198 184 joy = devm_kzalloc(dev, sizeof(*joy), GFP_KERNEL); 199 185 if (!joy) ··· 208 192 return error; 209 193 } 210 194 211 - /* Count how many channels we got. NULL terminated. */ 195 + error = device_property_read_u32(dev, "poll-interval", &poll_interval); 196 + if (error) { 197 + /* -EINVAL means the property is absent. */ 198 + if (error != -EINVAL) 199 + return error; 200 + } else if (poll_interval == 0) { 201 + dev_err(dev, "Unable to get poll-interval\n"); 202 + return -EINVAL; 203 + } else { 204 + joy->polled = true; 205 + } 206 + 207 + /* 208 + * Count how many channels we got. NULL terminated. 209 + * Do not check the storage size if using polling. 210 + */ 212 211 for (i = 0; joy->chans[i].indio_dev; i++) { 212 + if (joy->polled) 213 + continue; 213 214 bits = joy->chans[i].channel->scan_type.storagebits; 214 215 if (!bits || bits > 16) { 215 216 dev_err(dev, "Unsupported channel storage size\n"); ··· 248 215 joy->input = input; 249 216 input->name = pdev->name; 250 217 input->id.bustype = BUS_HOST; 251 - input->open = adc_joystick_open; 252 - input->close = adc_joystick_close; 253 218 254 219 error = adc_joystick_set_axes(dev, joy); 255 220 if (error) 256 221 return error; 257 222 258 - joy->buffer = iio_channel_get_all_cb(dev, adc_joystick_handle, joy); 259 - if (IS_ERR(joy->buffer)) { 260 - dev_err(dev, "Unable to allocate callback buffer\n"); 261 - return PTR_ERR(joy->buffer); 262 - } 223 + if (joy->polled) { 224 + input_setup_polling(input, adc_joystick_poll); 225 + input_set_poll_interval(input, poll_interval); 226 + } else { 227 + input->open = adc_joystick_open; 228 + input->close = adc_joystick_close; 263 229 264 - error = devm_add_action_or_reset(dev, adc_joystick_cleanup, joy->buffer); 265 - if (error) { 266 - dev_err(dev, "Unable to add action\n"); 267 - return error; 230 + joy->buffer = iio_channel_get_all_cb(dev, adc_joystick_handle, 231 + joy); 232 + if (IS_ERR(joy->buffer)) { 233 + dev_err(dev, "Unable to allocate callback buffer\n"); 234 + return PTR_ERR(joy->buffer); 235 + } 236 + 237 + error = devm_add_action_or_reset(dev, adc_joystick_cleanup, 238 + joy->buffer); 239 + if (error) { 240 + dev_err(dev, "Unable to add action\n"); 241 + return error; 242 + } 268 243 } 269 244 270 245 input_set_drvdata(input, joy);