Lines Matching +full:multi +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2009-2011 Analog Devices Inc.
132 mask = ((1 << (end_stage + 1)) - 1) - ((1 << start_stage) - 1); in ad714x_use_com_int()
134 ad714x->read(ad714x, STG_COM_INT_EN_REG, &data, 1); in ad714x_use_com_int()
136 ad714x->write(ad714x, STG_COM_INT_EN_REG, data); in ad714x_use_com_int()
138 ad714x->read(ad714x, STG_HIGH_INT_EN_REG, &data, 1); in ad714x_use_com_int()
140 ad714x->write(ad714x, STG_HIGH_INT_EN_REG, data); in ad714x_use_com_int()
149 mask = ((1 << (end_stage + 1)) - 1) - ((1 << start_stage) - 1); in ad714x_use_thr_int()
151 ad714x->read(ad714x, STG_COM_INT_EN_REG, &data, 1); in ad714x_use_thr_int()
153 ad714x->write(ad714x, STG_COM_INT_EN_REG, data); in ad714x_use_thr_int()
155 ad714x->read(ad714x, STG_HIGH_INT_EN_REG, &data, 1); in ad714x_use_thr_int()
157 ad714x->write(ad714x, STG_HIGH_INT_EN_REG, data); in ad714x_use_thr_int()
168 if (ad714x->sensor_val[i] > max_res) { in ad714x_cal_highest_stage()
169 max_res = ad714x->sensor_val[i]; in ad714x_cal_highest_stage()
184 a_param = ad714x->sensor_val[start_stage + 1]; in ad714x_cal_abs_pos()
185 b_param = ad714x->sensor_val[start_stage] + in ad714x_cal_abs_pos()
186 ad714x->sensor_val[start_stage + 1]; in ad714x_cal_abs_pos()
188 a_param = ad714x->sensor_val[end_stage] * in ad714x_cal_abs_pos()
189 (end_stage - start_stage) + in ad714x_cal_abs_pos()
190 ad714x->sensor_val[end_stage - 1] * in ad714x_cal_abs_pos()
191 (end_stage - start_stage - 1); in ad714x_cal_abs_pos()
192 b_param = ad714x->sensor_val[end_stage] + in ad714x_cal_abs_pos()
193 ad714x->sensor_val[end_stage - 1]; in ad714x_cal_abs_pos()
195 a_param = ad714x->sensor_val[highest_stage] * in ad714x_cal_abs_pos()
196 (highest_stage - start_stage) + in ad714x_cal_abs_pos()
197 ad714x->sensor_val[highest_stage - 1] * in ad714x_cal_abs_pos()
198 (highest_stage - start_stage - 1) + in ad714x_cal_abs_pos()
199 ad714x->sensor_val[highest_stage + 1] * in ad714x_cal_abs_pos()
200 (highest_stage - start_stage + 1); in ad714x_cal_abs_pos()
201 b_param = ad714x->sensor_val[highest_stage] + in ad714x_cal_abs_pos()
202 ad714x->sensor_val[highest_stage - 1] + in ad714x_cal_abs_pos()
203 ad714x->sensor_val[highest_stage + 1]; in ad714x_cal_abs_pos()
206 return (max_coord / (end_stage - start_stage)) * a_param / b_param; in ad714x_cal_abs_pos()
210 * One button can connect to multi positive and negative of CDCs
211 * Multi-buttons can connect to same positive/negative of one CDC
215 struct ad714x_button_plat *hw = &ad714x->hw->button[idx]; in ad714x_button_state_machine()
216 struct ad714x_button_drv *sw = &ad714x->sw->button[idx]; in ad714x_button_state_machine()
218 switch (sw->state) { in ad714x_button_state_machine()
220 if (((ad714x->h_state & hw->h_mask) == hw->h_mask) && in ad714x_button_state_machine()
221 ((ad714x->l_state & hw->l_mask) == hw->l_mask)) { in ad714x_button_state_machine()
222 dev_dbg(ad714x->dev, "button %d touched\n", idx); in ad714x_button_state_machine()
223 input_report_key(sw->input, hw->keycode, 1); in ad714x_button_state_machine()
224 input_sync(sw->input); in ad714x_button_state_machine()
225 sw->state = ACTIVE; in ad714x_button_state_machine()
230 if (((ad714x->h_state & hw->h_mask) != hw->h_mask) || in ad714x_button_state_machine()
231 ((ad714x->l_state & hw->l_mask) != hw->l_mask)) { in ad714x_button_state_machine()
232 dev_dbg(ad714x->dev, "button %d released\n", idx); in ad714x_button_state_machine()
233 input_report_key(sw->input, hw->keycode, 0); in ad714x_button_state_machine()
234 input_sync(sw->input); in ad714x_button_state_machine()
235 sw->state = IDLE; in ad714x_button_state_machine()
245 * The response of a sensor is defined by the absolute number of codes
250 struct ad714x_slider_plat *hw = &ad714x->hw->slider[idx]; in ad714x_slider_cal_sensor_val()
253 ad714x->read(ad714x, CDC_RESULT_S0 + hw->start_stage, in ad714x_slider_cal_sensor_val()
254 &ad714x->adc_reg[hw->start_stage], in ad714x_slider_cal_sensor_val()
255 hw->end_stage - hw->start_stage + 1); in ad714x_slider_cal_sensor_val()
257 for (i = hw->start_stage; i <= hw->end_stage; i++) { in ad714x_slider_cal_sensor_val()
258 ad714x->read(ad714x, STAGE0_AMBIENT + i * PER_STAGE_REG_NUM, in ad714x_slider_cal_sensor_val()
259 &ad714x->amb_reg[i], 1); in ad714x_slider_cal_sensor_val()
261 ad714x->sensor_val[i] = in ad714x_slider_cal_sensor_val()
262 abs(ad714x->adc_reg[i] - ad714x->amb_reg[i]); in ad714x_slider_cal_sensor_val()
268 struct ad714x_slider_plat *hw = &ad714x->hw->slider[idx]; in ad714x_slider_cal_highest_stage()
269 struct ad714x_slider_drv *sw = &ad714x->sw->slider[idx]; in ad714x_slider_cal_highest_stage()
271 sw->highest_stage = ad714x_cal_highest_stage(ad714x, hw->start_stage, in ad714x_slider_cal_highest_stage()
272 hw->end_stage); in ad714x_slider_cal_highest_stage()
274 dev_dbg(ad714x->dev, "slider %d highest_stage:%d\n", idx, in ad714x_slider_cal_highest_stage()
275 sw->highest_stage); in ad714x_slider_cal_highest_stage()
279 * The formulae are very straight forward. It uses the sensor with the
281 * When Sensor 0 has the highest response, only sensor 0 and sensor 1
282 * are used in the calculations. Similarly when the last sensor has the
283 * highest response, only the last sensor and the second last sensors
286 * For i= idx_of_peak_Sensor-1 to i= idx_of_peak_Sensor+1
287 * v += Sensor response(i)*i
288 * w += Sensor response(i)
289 * POS=(Number_of_Positions_Wanted/(Number_of_Sensors_Used-1)) *(v/w)
293 struct ad714x_slider_plat *hw = &ad714x->hw->slider[idx]; in ad714x_slider_cal_abs_pos()
294 struct ad714x_slider_drv *sw = &ad714x->sw->slider[idx]; in ad714x_slider_cal_abs_pos()
296 sw->abs_pos = ad714x_cal_abs_pos(ad714x, hw->start_stage, hw->end_stage, in ad714x_slider_cal_abs_pos()
297 sw->highest_stage, hw->max_coord); in ad714x_slider_cal_abs_pos()
299 dev_dbg(ad714x->dev, "slider %d absolute position:%d\n", idx, in ad714x_slider_cal_abs_pos()
300 sw->abs_pos); in ad714x_slider_cal_abs_pos()
310 * Filtered_CDC_result = (Filtered_CDC_result * (10 - Coefficient) +
315 struct ad714x_slider_drv *sw = &ad714x->sw->slider[idx]; in ad714x_slider_cal_flt_pos()
317 sw->flt_pos = (sw->flt_pos * (10 - 4) + in ad714x_slider_cal_flt_pos()
318 sw->abs_pos * 4)/10; in ad714x_slider_cal_flt_pos()
320 dev_dbg(ad714x->dev, "slider %d filter position:%d\n", idx, in ad714x_slider_cal_flt_pos()
321 sw->flt_pos); in ad714x_slider_cal_flt_pos()
326 struct ad714x_slider_plat *hw = &ad714x->hw->slider[idx]; in ad714x_slider_use_com_int()
328 ad714x_use_com_int(ad714x, hw->start_stage, hw->end_stage); in ad714x_slider_use_com_int()
333 struct ad714x_slider_plat *hw = &ad714x->hw->slider[idx]; in ad714x_slider_use_thr_int()
335 ad714x_use_thr_int(ad714x, hw->start_stage, hw->end_stage); in ad714x_slider_use_thr_int()
340 struct ad714x_slider_plat *hw = &ad714x->hw->slider[idx]; in ad714x_slider_state_machine()
341 struct ad714x_slider_drv *sw = &ad714x->sw->slider[idx]; in ad714x_slider_state_machine()
345 mask = ((1 << (hw->end_stage + 1)) - 1) - ((1 << hw->start_stage) - 1); in ad714x_slider_state_machine()
347 h_state = ad714x->h_state & mask; in ad714x_slider_state_machine()
348 c_state = ad714x->c_state & mask; in ad714x_slider_state_machine()
350 switch (sw->state) { in ad714x_slider_state_machine()
353 sw->state = JITTER; in ad714x_slider_state_machine()
358 dev_dbg(ad714x->dev, "slider %d touched\n", idx); in ad714x_slider_state_machine()
367 sw->flt_pos = sw->abs_pos; in ad714x_slider_state_machine()
368 sw->state = ACTIVE; in ad714x_slider_state_machine()
379 input_report_abs(sw->input, ABS_X, sw->flt_pos); in ad714x_slider_state_machine()
380 input_report_key(sw->input, BTN_TOUCH, 1); in ad714x_slider_state_machine()
382 /* When the user lifts off the sensor, configure in ad714x_slider_state_machine()
386 sw->state = IDLE; in ad714x_slider_state_machine()
387 input_report_key(sw->input, BTN_TOUCH, 0); in ad714x_slider_state_machine()
388 dev_dbg(ad714x->dev, "slider %d released\n", in ad714x_slider_state_machine()
391 input_sync(sw->input); in ad714x_slider_state_machine()
402 * on the sensor values. To calculate the position, we first determine the
403 * sensor that has the greatest response among the 8 sensors that constitutes
405 * sensor with the highest response and we apply weights to these sensors.
409 struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; in ad714x_wheel_cal_highest_stage()
410 struct ad714x_wheel_drv *sw = &ad714x->sw->wheel[idx]; in ad714x_wheel_cal_highest_stage()
412 sw->pre_highest_stage = sw->highest_stage; in ad714x_wheel_cal_highest_stage()
413 sw->highest_stage = ad714x_cal_highest_stage(ad714x, hw->start_stage, in ad714x_wheel_cal_highest_stage()
414 hw->end_stage); in ad714x_wheel_cal_highest_stage()
416 dev_dbg(ad714x->dev, "wheel %d highest_stage:%d\n", idx, in ad714x_wheel_cal_highest_stage()
417 sw->highest_stage); in ad714x_wheel_cal_highest_stage()
422 struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; in ad714x_wheel_cal_sensor_val()
425 ad714x->read(ad714x, CDC_RESULT_S0 + hw->start_stage, in ad714x_wheel_cal_sensor_val()
426 &ad714x->adc_reg[hw->start_stage], in ad714x_wheel_cal_sensor_val()
427 hw->end_stage - hw->start_stage + 1); in ad714x_wheel_cal_sensor_val()
429 for (i = hw->start_stage; i <= hw->end_stage; i++) { in ad714x_wheel_cal_sensor_val()
430 ad714x->read(ad714x, STAGE0_AMBIENT + i * PER_STAGE_REG_NUM, in ad714x_wheel_cal_sensor_val()
431 &ad714x->amb_reg[i], 1); in ad714x_wheel_cal_sensor_val()
432 if (ad714x->adc_reg[i] > ad714x->amb_reg[i]) in ad714x_wheel_cal_sensor_val()
433 ad714x->sensor_val[i] = in ad714x_wheel_cal_sensor_val()
434 ad714x->adc_reg[i] - ad714x->amb_reg[i]; in ad714x_wheel_cal_sensor_val()
436 ad714x->sensor_val[i] = 0; in ad714x_wheel_cal_sensor_val()
442 * on the sensor values. To calculate the position, we first determine the
443 * sensor that has the greatest response among the sensors that constitutes
445 * sensor with the highest response and we apply weights to these sensors. The
451 struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; in ad714x_wheel_cal_abs_pos()
452 struct ad714x_wheel_drv *sw = &ad714x->sw->wheel[idx]; in ad714x_wheel_cal_abs_pos()
453 int stage_num = hw->end_stage - hw->start_stage + 1; in ad714x_wheel_cal_abs_pos()
457 first_before = (sw->highest_stage + stage_num - 1) % stage_num; in ad714x_wheel_cal_abs_pos()
458 highest = sw->highest_stage; in ad714x_wheel_cal_abs_pos()
459 first_after = (sw->highest_stage + stage_num + 1) % stage_num; in ad714x_wheel_cal_abs_pos()
461 a_param = ad714x->sensor_val[highest] * in ad714x_wheel_cal_abs_pos()
462 (highest - hw->start_stage) + in ad714x_wheel_cal_abs_pos()
463 ad714x->sensor_val[first_before] * in ad714x_wheel_cal_abs_pos()
464 (highest - hw->start_stage - 1) + in ad714x_wheel_cal_abs_pos()
465 ad714x->sensor_val[first_after] * in ad714x_wheel_cal_abs_pos()
466 (highest - hw->start_stage + 1); in ad714x_wheel_cal_abs_pos()
467 b_param = ad714x->sensor_val[highest] + in ad714x_wheel_cal_abs_pos()
468 ad714x->sensor_val[first_before] + in ad714x_wheel_cal_abs_pos()
469 ad714x->sensor_val[first_after]; in ad714x_wheel_cal_abs_pos()
471 sw->abs_pos = ((hw->max_coord / (hw->end_stage - hw->start_stage)) * in ad714x_wheel_cal_abs_pos()
474 if (sw->abs_pos > hw->max_coord) in ad714x_wheel_cal_abs_pos()
475 sw->abs_pos = hw->max_coord; in ad714x_wheel_cal_abs_pos()
476 else if (sw->abs_pos < 0) in ad714x_wheel_cal_abs_pos()
477 sw->abs_pos = 0; in ad714x_wheel_cal_abs_pos()
482 struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; in ad714x_wheel_cal_flt_pos()
483 struct ad714x_wheel_drv *sw = &ad714x->sw->wheel[idx]; in ad714x_wheel_cal_flt_pos()
484 if (((sw->pre_highest_stage == hw->end_stage) && in ad714x_wheel_cal_flt_pos()
485 (sw->highest_stage == hw->start_stage)) || in ad714x_wheel_cal_flt_pos()
486 ((sw->pre_highest_stage == hw->start_stage) && in ad714x_wheel_cal_flt_pos()
487 (sw->highest_stage == hw->end_stage))) in ad714x_wheel_cal_flt_pos()
488 sw->flt_pos = sw->abs_pos; in ad714x_wheel_cal_flt_pos()
490 sw->flt_pos = ((sw->flt_pos * 30) + (sw->abs_pos * 71)) / 100; in ad714x_wheel_cal_flt_pos()
492 if (sw->flt_pos > hw->max_coord) in ad714x_wheel_cal_flt_pos()
493 sw->flt_pos = hw->max_coord; in ad714x_wheel_cal_flt_pos()
498 struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; in ad714x_wheel_use_com_int()
500 ad714x_use_com_int(ad714x, hw->start_stage, hw->end_stage); in ad714x_wheel_use_com_int()
505 struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; in ad714x_wheel_use_thr_int()
507 ad714x_use_thr_int(ad714x, hw->start_stage, hw->end_stage); in ad714x_wheel_use_thr_int()
512 struct ad714x_wheel_plat *hw = &ad714x->hw->wheel[idx]; in ad714x_wheel_state_machine()
513 struct ad714x_wheel_drv *sw = &ad714x->sw->wheel[idx]; in ad714x_wheel_state_machine()
517 mask = ((1 << (hw->end_stage + 1)) - 1) - ((1 << hw->start_stage) - 1); in ad714x_wheel_state_machine()
519 h_state = ad714x->h_state & mask; in ad714x_wheel_state_machine()
520 c_state = ad714x->c_state & mask; in ad714x_wheel_state_machine()
522 switch (sw->state) { in ad714x_wheel_state_machine()
525 sw->state = JITTER; in ad714x_wheel_state_machine()
530 dev_dbg(ad714x->dev, "wheel %d touched\n", idx); in ad714x_wheel_state_machine()
539 sw->flt_pos = sw->abs_pos; in ad714x_wheel_state_machine()
540 sw->state = ACTIVE; in ad714x_wheel_state_machine()
551 input_report_abs(sw->input, ABS_WHEEL, in ad714x_wheel_state_machine()
552 sw->flt_pos); in ad714x_wheel_state_machine()
553 input_report_key(sw->input, BTN_TOUCH, 1); in ad714x_wheel_state_machine()
555 /* When the user lifts off the sensor, configure in ad714x_wheel_state_machine()
559 sw->state = IDLE; in ad714x_wheel_state_machine()
560 input_report_key(sw->input, BTN_TOUCH, 0); in ad714x_wheel_state_machine()
562 dev_dbg(ad714x->dev, "wheel %d released\n", in ad714x_wheel_state_machine()
565 input_sync(sw->input); in ad714x_wheel_state_machine()
576 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in touchpad_cal_sensor_val()
579 ad714x->read(ad714x, CDC_RESULT_S0 + hw->x_start_stage, in touchpad_cal_sensor_val()
580 &ad714x->adc_reg[hw->x_start_stage], in touchpad_cal_sensor_val()
581 hw->x_end_stage - hw->x_start_stage + 1); in touchpad_cal_sensor_val()
583 for (i = hw->x_start_stage; i <= hw->x_end_stage; i++) { in touchpad_cal_sensor_val()
584 ad714x->read(ad714x, STAGE0_AMBIENT + i * PER_STAGE_REG_NUM, in touchpad_cal_sensor_val()
585 &ad714x->amb_reg[i], 1); in touchpad_cal_sensor_val()
586 if (ad714x->adc_reg[i] > ad714x->amb_reg[i]) in touchpad_cal_sensor_val()
587 ad714x->sensor_val[i] = in touchpad_cal_sensor_val()
588 ad714x->adc_reg[i] - ad714x->amb_reg[i]; in touchpad_cal_sensor_val()
590 ad714x->sensor_val[i] = 0; in touchpad_cal_sensor_val()
596 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in touchpad_cal_highest_stage()
597 struct ad714x_touchpad_drv *sw = &ad714x->sw->touchpad[idx]; in touchpad_cal_highest_stage()
599 sw->x_highest_stage = ad714x_cal_highest_stage(ad714x, in touchpad_cal_highest_stage()
600 hw->x_start_stage, hw->x_end_stage); in touchpad_cal_highest_stage()
601 sw->y_highest_stage = ad714x_cal_highest_stage(ad714x, in touchpad_cal_highest_stage()
602 hw->y_start_stage, hw->y_end_stage); in touchpad_cal_highest_stage()
604 dev_dbg(ad714x->dev, in touchpad_cal_highest_stage()
606 idx, sw->x_highest_stage, sw->y_highest_stage); in touchpad_cal_highest_stage()
610 * If 2 fingers are touching the sensor then 2 peaks can be observed in the
612 * The arithmetic doesn't support to get absolute coordinates for multi-touch
617 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in touchpad_check_second_peak()
618 struct ad714x_touchpad_drv *sw = &ad714x->sw->touchpad[idx]; in touchpad_check_second_peak()
621 for (i = hw->x_start_stage; i < sw->x_highest_stage; i++) { in touchpad_check_second_peak()
622 if ((ad714x->sensor_val[i] - ad714x->sensor_val[i + 1]) in touchpad_check_second_peak()
623 > (ad714x->sensor_val[i + 1] / 10)) in touchpad_check_second_peak()
627 for (i = sw->x_highest_stage; i < hw->x_end_stage; i++) { in touchpad_check_second_peak()
628 if ((ad714x->sensor_val[i + 1] - ad714x->sensor_val[i]) in touchpad_check_second_peak()
629 > (ad714x->sensor_val[i] / 10)) in touchpad_check_second_peak()
633 for (i = hw->y_start_stage; i < sw->y_highest_stage; i++) { in touchpad_check_second_peak()
634 if ((ad714x->sensor_val[i] - ad714x->sensor_val[i + 1]) in touchpad_check_second_peak()
635 > (ad714x->sensor_val[i + 1] / 10)) in touchpad_check_second_peak()
639 for (i = sw->y_highest_stage; i < hw->y_end_stage; i++) { in touchpad_check_second_peak()
640 if ((ad714x->sensor_val[i + 1] - ad714x->sensor_val[i]) in touchpad_check_second_peak()
641 > (ad714x->sensor_val[i] / 10)) in touchpad_check_second_peak()
656 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in touchpad_cal_abs_pos()
657 struct ad714x_touchpad_drv *sw = &ad714x->sw->touchpad[idx]; in touchpad_cal_abs_pos()
659 sw->x_abs_pos = ad714x_cal_abs_pos(ad714x, hw->x_start_stage, in touchpad_cal_abs_pos()
660 hw->x_end_stage, sw->x_highest_stage, hw->x_max_coord); in touchpad_cal_abs_pos()
661 sw->y_abs_pos = ad714x_cal_abs_pos(ad714x, hw->y_start_stage, in touchpad_cal_abs_pos()
662 hw->y_end_stage, sw->y_highest_stage, hw->y_max_coord); in touchpad_cal_abs_pos()
664 dev_dbg(ad714x->dev, "touchpad %d absolute position:(%d, %d)\n", idx, in touchpad_cal_abs_pos()
665 sw->x_abs_pos, sw->y_abs_pos); in touchpad_cal_abs_pos()
670 struct ad714x_touchpad_drv *sw = &ad714x->sw->touchpad[idx]; in touchpad_cal_flt_pos()
672 sw->x_flt_pos = (sw->x_flt_pos * (10 - 4) + in touchpad_cal_flt_pos()
673 sw->x_abs_pos * 4)/10; in touchpad_cal_flt_pos()
674 sw->y_flt_pos = (sw->y_flt_pos * (10 - 4) + in touchpad_cal_flt_pos()
675 sw->y_abs_pos * 4)/10; in touchpad_cal_flt_pos()
677 dev_dbg(ad714x->dev, "touchpad %d filter position:(%d, %d)\n", in touchpad_cal_flt_pos()
678 idx, sw->x_flt_pos, sw->y_flt_pos); in touchpad_cal_flt_pos()
685 * End points are detected on the 4 edges of the touchpad sensor. The
688 * percent between the sensor on the edge and the adjacent one. The
701 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in touchpad_check_endpoint()
702 struct ad714x_touchpad_drv *sw = &ad714x->sw->touchpad[idx]; in touchpad_check_endpoint()
706 percent_sensor_diff = (ad714x->sensor_val[hw->x_start_stage] - in touchpad_check_endpoint()
707 ad714x->sensor_val[hw->x_start_stage + 1]) * 100 / in touchpad_check_endpoint()
708 ad714x->sensor_val[hw->x_start_stage + 1]; in touchpad_check_endpoint()
709 if (!sw->left_ep) { in touchpad_check_endpoint()
711 sw->left_ep = 1; in touchpad_check_endpoint()
712 sw->left_ep_val = in touchpad_check_endpoint()
713 ad714x->sensor_val[hw->x_start_stage + 1]; in touchpad_check_endpoint()
717 (ad714x->sensor_val[hw->x_start_stage + 1] > in touchpad_check_endpoint()
718 LEFT_RIGHT_END_POINT_DEAVTIVALION_LEVEL + sw->left_ep_val)) in touchpad_check_endpoint()
719 sw->left_ep = 0; in touchpad_check_endpoint()
723 percent_sensor_diff = (ad714x->sensor_val[hw->x_end_stage] - in touchpad_check_endpoint()
724 ad714x->sensor_val[hw->x_end_stage - 1]) * 100 / in touchpad_check_endpoint()
725 ad714x->sensor_val[hw->x_end_stage - 1]; in touchpad_check_endpoint()
726 if (!sw->right_ep) { in touchpad_check_endpoint()
728 sw->right_ep = 1; in touchpad_check_endpoint()
729 sw->right_ep_val = in touchpad_check_endpoint()
730 ad714x->sensor_val[hw->x_end_stage - 1]; in touchpad_check_endpoint()
734 (ad714x->sensor_val[hw->x_end_stage - 1] > in touchpad_check_endpoint()
735 LEFT_RIGHT_END_POINT_DEAVTIVALION_LEVEL + sw->right_ep_val)) in touchpad_check_endpoint()
736 sw->right_ep = 0; in touchpad_check_endpoint()
740 percent_sensor_diff = (ad714x->sensor_val[hw->y_start_stage] - in touchpad_check_endpoint()
741 ad714x->sensor_val[hw->y_start_stage + 1]) * 100 / in touchpad_check_endpoint()
742 ad714x->sensor_val[hw->y_start_stage + 1]; in touchpad_check_endpoint()
743 if (!sw->top_ep) { in touchpad_check_endpoint()
745 sw->top_ep = 1; in touchpad_check_endpoint()
746 sw->top_ep_val = in touchpad_check_endpoint()
747 ad714x->sensor_val[hw->y_start_stage + 1]; in touchpad_check_endpoint()
751 (ad714x->sensor_val[hw->y_start_stage + 1] > in touchpad_check_endpoint()
752 TOP_BOTTOM_END_POINT_DEAVTIVALION_LEVEL + sw->top_ep_val)) in touchpad_check_endpoint()
753 sw->top_ep = 0; in touchpad_check_endpoint()
757 percent_sensor_diff = (ad714x->sensor_val[hw->y_end_stage] - in touchpad_check_endpoint()
758 ad714x->sensor_val[hw->y_end_stage - 1]) * 100 / in touchpad_check_endpoint()
759 ad714x->sensor_val[hw->y_end_stage - 1]; in touchpad_check_endpoint()
760 if (!sw->bottom_ep) { in touchpad_check_endpoint()
762 sw->bottom_ep = 1; in touchpad_check_endpoint()
763 sw->bottom_ep_val = in touchpad_check_endpoint()
764 ad714x->sensor_val[hw->y_end_stage - 1]; in touchpad_check_endpoint()
768 (ad714x->sensor_val[hw->y_end_stage - 1] > in touchpad_check_endpoint()
769 TOP_BOTTOM_END_POINT_DEAVTIVALION_LEVEL + sw->bottom_ep_val)) in touchpad_check_endpoint()
770 sw->bottom_ep = 0; in touchpad_check_endpoint()
773 return sw->left_ep || sw->right_ep || sw->top_ep || sw->bottom_ep; in touchpad_check_endpoint()
778 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in touchpad_use_com_int()
780 ad714x_use_com_int(ad714x, hw->x_start_stage, hw->x_end_stage); in touchpad_use_com_int()
785 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in touchpad_use_thr_int()
787 ad714x_use_thr_int(ad714x, hw->x_start_stage, hw->x_end_stage); in touchpad_use_thr_int()
788 ad714x_use_thr_int(ad714x, hw->y_start_stage, hw->y_end_stage); in touchpad_use_thr_int()
793 struct ad714x_touchpad_plat *hw = &ad714x->hw->touchpad[idx]; in ad714x_touchpad_state_machine()
794 struct ad714x_touchpad_drv *sw = &ad714x->sw->touchpad[idx]; in ad714x_touchpad_state_machine()
798 mask = (((1 << (hw->x_end_stage + 1)) - 1) - in ad714x_touchpad_state_machine()
799 ((1 << hw->x_start_stage) - 1)) + in ad714x_touchpad_state_machine()
800 (((1 << (hw->y_end_stage + 1)) - 1) - in ad714x_touchpad_state_machine()
801 ((1 << hw->y_start_stage) - 1)); in ad714x_touchpad_state_machine()
803 h_state = ad714x->h_state & mask; in ad714x_touchpad_state_machine()
804 c_state = ad714x->c_state & mask; in ad714x_touchpad_state_machine()
806 switch (sw->state) { in ad714x_touchpad_state_machine()
809 sw->state = JITTER; in ad714x_touchpad_state_machine()
814 dev_dbg(ad714x->dev, "touchpad %d touched\n", idx); in ad714x_touchpad_state_machine()
824 dev_dbg(ad714x->dev, in ad714x_touchpad_state_machine()
828 sw->x_flt_pos = sw->x_abs_pos; in ad714x_touchpad_state_machine()
829 sw->y_flt_pos = sw->y_abs_pos; in ad714x_touchpad_state_machine()
830 sw->state = ACTIVE; in ad714x_touchpad_state_machine()
844 input_report_abs(sw->input, ABS_X, in ad714x_touchpad_state_machine()
845 sw->x_flt_pos); in ad714x_touchpad_state_machine()
846 input_report_abs(sw->input, ABS_Y, in ad714x_touchpad_state_machine()
847 sw->y_flt_pos); in ad714x_touchpad_state_machine()
848 input_report_key(sw->input, BTN_TOUCH, in ad714x_touchpad_state_machine()
852 /* When the user lifts off the sensor, configure in ad714x_touchpad_state_machine()
856 sw->state = IDLE; in ad714x_touchpad_state_machine()
857 input_report_key(sw->input, BTN_TOUCH, 0); in ad714x_touchpad_state_machine()
858 dev_dbg(ad714x->dev, "touchpad %d released\n", in ad714x_touchpad_state_machine()
861 input_sync(sw->input); in ad714x_touchpad_state_machine()
874 ad714x->read(ad714x, AD714X_PARTID_REG, &data, 1); in ad714x_hw_detect()
877 ad714x->product = 0x7142; in ad714x_hw_detect()
878 ad714x->version = data & 0xF; in ad714x_hw_detect()
879 dev_info(ad714x->dev, "found AD7142 captouch, rev:%d\n", in ad714x_hw_detect()
880 ad714x->version); in ad714x_hw_detect()
884 ad714x->product = 0x7143; in ad714x_hw_detect()
885 ad714x->version = data & 0xF; in ad714x_hw_detect()
886 dev_info(ad714x->dev, "found AD7143 captouch, rev:%d\n", in ad714x_hw_detect()
887 ad714x->version); in ad714x_hw_detect()
891 ad714x->product = 0x7147; in ad714x_hw_detect()
892 ad714x->version = data & 0xF; in ad714x_hw_detect()
893 dev_info(ad714x->dev, "found AD7147(A) captouch, rev:%d\n", in ad714x_hw_detect()
894 ad714x->version); in ad714x_hw_detect()
898 ad714x->product = 0x7148; in ad714x_hw_detect()
899 ad714x->version = data & 0xF; in ad714x_hw_detect()
900 dev_info(ad714x->dev, "found AD7148 captouch, rev:%d\n", in ad714x_hw_detect()
901 ad714x->version); in ad714x_hw_detect()
905 dev_err(ad714x->dev, in ad714x_hw_detect()
908 return -ENODEV; in ad714x_hw_detect()
923 ad714x->write(ad714x, reg_base + j, in ad714x_hw_init()
924 ad714x->hw->stage_cfg_reg[i][j]); in ad714x_hw_init()
928 ad714x->write(ad714x, AD714X_SYSCFG_REG + i, in ad714x_hw_init()
929 ad714x->hw->sys_cfg_reg[i]); in ad714x_hw_init()
931 ad714x->read(ad714x, AD714X_SYSCFG_REG + i, &data, 1); in ad714x_hw_init()
933 ad714x->write(ad714x, AD714X_STG_CAL_EN_REG, 0xFFF); in ad714x_hw_init()
936 ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3); in ad714x_hw_init()
944 mutex_lock(&ad714x->mutex); in ad714x_interrupt_thread()
946 ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3); in ad714x_interrupt_thread()
948 for (i = 0; i < ad714x->hw->button_num; i++) in ad714x_interrupt_thread()
950 for (i = 0; i < ad714x->hw->slider_num; i++) in ad714x_interrupt_thread()
952 for (i = 0; i < ad714x->hw->wheel_num; i++) in ad714x_interrupt_thread()
954 for (i = 0; i < ad714x->hw->touchpad_num; i++) in ad714x_interrupt_thread()
957 mutex_unlock(&ad714x->mutex); in ad714x_interrupt_thread()
982 error = -EINVAL; in ad714x_probe()
988 error = -EINVAL; in ad714x_probe()
992 ad714x = devm_kzalloc(dev, sizeof(*ad714x) + sizeof(*ad714x->sw) + in ad714x_probe()
993 sizeof(*sd_drv) * plat_data->slider_num + in ad714x_probe()
994 sizeof(*wl_drv) * plat_data->wheel_num + in ad714x_probe()
995 sizeof(*tp_drv) * plat_data->touchpad_num + in ad714x_probe()
996 sizeof(*bt_drv) * plat_data->button_num, in ad714x_probe()
999 error = -ENOMEM; in ad714x_probe()
1002 ad714x->hw = plat_data; in ad714x_probe()
1005 ad714x->sw = drv_mem; in ad714x_probe()
1006 drv_mem += sizeof(*ad714x->sw); in ad714x_probe()
1007 ad714x->sw->slider = sd_drv = drv_mem; in ad714x_probe()
1008 drv_mem += sizeof(*sd_drv) * ad714x->hw->slider_num; in ad714x_probe()
1009 ad714x->sw->wheel = wl_drv = drv_mem; in ad714x_probe()
1010 drv_mem += sizeof(*wl_drv) * ad714x->hw->wheel_num; in ad714x_probe()
1011 ad714x->sw->touchpad = tp_drv = drv_mem; in ad714x_probe()
1012 drv_mem += sizeof(*tp_drv) * ad714x->hw->touchpad_num; in ad714x_probe()
1013 ad714x->sw->button = bt_drv = drv_mem; in ad714x_probe()
1014 drv_mem += sizeof(*bt_drv) * ad714x->hw->button_num; in ad714x_probe()
1016 ad714x->read = read; in ad714x_probe()
1017 ad714x->write = write; in ad714x_probe()
1018 ad714x->irq = irq; in ad714x_probe()
1019 ad714x->dev = dev; in ad714x_probe()
1028 mutex_init(&ad714x->mutex); in ad714x_probe()
1031 if (ad714x->hw->slider_num > 0) { in ad714x_probe()
1032 struct ad714x_slider_plat *sd_plat = ad714x->hw->slider; in ad714x_probe()
1034 for (i = 0; i < ad714x->hw->slider_num; i++) { in ad714x_probe()
1037 return ERR_PTR(-ENOMEM); in ad714x_probe()
1039 __set_bit(EV_ABS, input->evbit); in ad714x_probe()
1040 __set_bit(EV_KEY, input->evbit); in ad714x_probe()
1041 __set_bit(ABS_X, input->absbit); in ad714x_probe()
1042 __set_bit(BTN_TOUCH, input->keybit); in ad714x_probe()
1044 ABS_X, 0, sd_plat->max_coord, 0, 0); in ad714x_probe()
1046 input->id.bustype = bus_type; in ad714x_probe()
1047 input->id.product = ad714x->product; in ad714x_probe()
1048 input->id.version = ad714x->version; in ad714x_probe()
1049 input->name = "ad714x_captouch_slider"; in ad714x_probe()
1050 input->dev.parent = dev; in ad714x_probe()
1061 if (ad714x->hw->wheel_num > 0) { in ad714x_probe()
1062 struct ad714x_wheel_plat *wl_plat = ad714x->hw->wheel; in ad714x_probe()
1064 for (i = 0; i < ad714x->hw->wheel_num; i++) { in ad714x_probe()
1067 return ERR_PTR(-ENOMEM); in ad714x_probe()
1069 __set_bit(EV_KEY, input->evbit); in ad714x_probe()
1070 __set_bit(EV_ABS, input->evbit); in ad714x_probe()
1071 __set_bit(ABS_WHEEL, input->absbit); in ad714x_probe()
1072 __set_bit(BTN_TOUCH, input->keybit); in ad714x_probe()
1074 ABS_WHEEL, 0, wl_plat->max_coord, 0, 0); in ad714x_probe()
1076 input->id.bustype = bus_type; in ad714x_probe()
1077 input->id.product = ad714x->product; in ad714x_probe()
1078 input->id.version = ad714x->version; in ad714x_probe()
1079 input->name = "ad714x_captouch_wheel"; in ad714x_probe()
1080 input->dev.parent = dev; in ad714x_probe()
1091 if (ad714x->hw->touchpad_num > 0) { in ad714x_probe()
1092 struct ad714x_touchpad_plat *tp_plat = ad714x->hw->touchpad; in ad714x_probe()
1094 for (i = 0; i < ad714x->hw->touchpad_num; i++) { in ad714x_probe()
1097 return ERR_PTR(-ENOMEM); in ad714x_probe()
1099 __set_bit(EV_ABS, input->evbit); in ad714x_probe()
1100 __set_bit(EV_KEY, input->evbit); in ad714x_probe()
1101 __set_bit(ABS_X, input->absbit); in ad714x_probe()
1102 __set_bit(ABS_Y, input->absbit); in ad714x_probe()
1103 __set_bit(BTN_TOUCH, input->keybit); in ad714x_probe()
1105 ABS_X, 0, tp_plat->x_max_coord, 0, 0); in ad714x_probe()
1107 ABS_Y, 0, tp_plat->y_max_coord, 0, 0); in ad714x_probe()
1109 input->id.bustype = bus_type; in ad714x_probe()
1110 input->id.product = ad714x->product; in ad714x_probe()
1111 input->id.version = ad714x->version; in ad714x_probe()
1112 input->name = "ad714x_captouch_pad"; in ad714x_probe()
1113 input->dev.parent = dev; in ad714x_probe()
1124 if (ad714x->hw->button_num > 0) { in ad714x_probe()
1125 struct ad714x_button_plat *bt_plat = ad714x->hw->button; in ad714x_probe()
1129 error = -ENOMEM; in ad714x_probe()
1133 __set_bit(EV_KEY, input->evbit); in ad714x_probe()
1134 for (i = 0; i < ad714x->hw->button_num; i++) { in ad714x_probe()
1136 __set_bit(bt_plat[i].keycode, input->keybit); in ad714x_probe()
1139 input->id.bustype = bus_type; in ad714x_probe()
1140 input->id.product = ad714x->product; in ad714x_probe()
1141 input->id.version = ad714x->version; in ad714x_probe()
1142 input->name = "ad714x_captouch_button"; in ad714x_probe()
1143 input->dev.parent = dev; in ad714x_probe()
1150 irqflags = plat_data->irqflags ?: IRQF_TRIGGER_FALLING; in ad714x_probe()
1153 error = devm_request_threaded_irq(dev, ad714x->irq, NULL, in ad714x_probe()
1157 dev_err(dev, "can't allocate irq %d\n", ad714x->irq); in ad714x_probe()
1170 dev_dbg(ad714x->dev, "%s enter\n", __func__); in ad714x_disable()
1172 mutex_lock(&ad714x->mutex); in ad714x_disable()
1174 data = ad714x->hw->sys_cfg_reg[AD714X_PWR_CTRL] | 0x3; in ad714x_disable()
1175 ad714x->write(ad714x, AD714X_PWR_CTRL, data); in ad714x_disable()
1177 mutex_unlock(&ad714x->mutex); in ad714x_disable()
1185 dev_dbg(ad714x->dev, "%s enter\n", __func__); in ad714x_enable()
1187 mutex_lock(&ad714x->mutex); in ad714x_enable()
1189 /* resume to non-shutdown mode */ in ad714x_enable()
1191 ad714x->write(ad714x, AD714X_PWR_CTRL, in ad714x_enable()
1192 ad714x->hw->sys_cfg_reg[AD714X_PWR_CTRL]); in ad714x_enable()
1195 * otherwise we will get no chance to enter falling-edge irq again in ad714x_enable()
1198 ad714x->read(ad714x, STG_LOW_INT_STA_REG, &ad714x->l_state, 3); in ad714x_enable()
1200 mutex_unlock(&ad714x->mutex); in ad714x_enable()
1207 MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor Driver");