Lines Matching refs:keypad

79 static void imx_keypad_scan_matrix(struct imx_keypad *keypad,  in imx_keypad_scan_matrix()  argument
86 if ((keypad->cols_en_mask & (1 << col)) == 0) in imx_keypad_scan_matrix()
94 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
96 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
98 reg_val = readw(keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
99 reg_val &= ~((keypad->cols_en_mask & 0xff) << 8); in imx_keypad_scan_matrix()
100 writew(reg_val, keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
104 reg_val = readw(keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
105 reg_val |= (keypad->cols_en_mask & 0xff) << 8; in imx_keypad_scan_matrix()
106 writew(reg_val, keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
113 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
115 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
127 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
128 matrix_volatile_state[col] = (~reg_val) & keypad->rows_en_mask; in imx_keypad_scan_matrix()
135 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
137 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
144 static void imx_keypad_fire_events(struct imx_keypad *keypad, in imx_keypad_fire_events() argument
147 struct input_dev *input_dev = keypad->input_dev; in imx_keypad_fire_events()
154 if ((keypad->cols_en_mask & (1 << col)) == 0) in imx_keypad_fire_events()
157 bits_changed = keypad->matrix_stable_state[col] ^ in imx_keypad_fire_events()
164 if ((keypad->rows_en_mask & (1 << row)) == 0) in imx_keypad_fire_events()
171 input_report_key(input_dev, keypad->keycodes[code], in imx_keypad_fire_events()
174 keypad->keycodes[code], in imx_keypad_fire_events()
186 struct imx_keypad *keypad = from_timer(keypad, t, check_matrix_timer); in imx_keypad_check_for_events() local
194 imx_keypad_scan_matrix(keypad, matrix_volatile_state); in imx_keypad_check_for_events()
198 if ((keypad->cols_en_mask & (1 << i)) == 0) in imx_keypad_check_for_events()
201 if (keypad->matrix_unstable_state[i] ^ matrix_volatile_state[i]) { in imx_keypad_check_for_events()
215 memcpy(keypad->matrix_unstable_state, matrix_volatile_state, in imx_keypad_check_for_events()
217 keypad->stable_count = 0; in imx_keypad_check_for_events()
219 keypad->stable_count++; in imx_keypad_check_for_events()
225 if (keypad->stable_count < IMX_KEYPAD_SCANS_FOR_STABILITY) { in imx_keypad_check_for_events()
226 mod_timer(&keypad->check_matrix_timer, in imx_keypad_check_for_events()
237 if (keypad->stable_count == IMX_KEYPAD_SCANS_FOR_STABILITY) { in imx_keypad_check_for_events()
238 imx_keypad_fire_events(keypad, matrix_volatile_state); in imx_keypad_check_for_events()
240 memcpy(keypad->matrix_stable_state, matrix_volatile_state, in imx_keypad_check_for_events()
259 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
261 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
263 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
266 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
274 mod_timer(&keypad->check_matrix_timer, in imx_keypad_check_for_events()
277 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
279 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
281 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
284 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
290 struct imx_keypad *keypad = dev_id; in imx_keypad_irq_handler() local
293 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_irq_handler()
299 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_irq_handler()
301 if (keypad->enabled) { in imx_keypad_irq_handler()
303 keypad->stable_count = 0; in imx_keypad_irq_handler()
306 mod_timer(&keypad->check_matrix_timer, in imx_keypad_irq_handler()
313 static void imx_keypad_config(struct imx_keypad *keypad) in imx_keypad_config() argument
321 reg_val = readw(keypad->mmio_base + KPCR); in imx_keypad_config()
322 reg_val |= keypad->rows_en_mask & 0xff; /* rows */ in imx_keypad_config()
323 reg_val |= (keypad->cols_en_mask & 0xff) << 8; /* cols */ in imx_keypad_config()
324 writew(reg_val, keypad->mmio_base + KPCR); in imx_keypad_config()
327 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_config()
329 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_config()
332 writew(0xff00, keypad->mmio_base + KDDR); in imx_keypad_config()
338 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_config()
341 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_config()
346 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_config()
349 static void imx_keypad_inhibit(struct imx_keypad *keypad) in imx_keypad_inhibit() argument
354 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_inhibit()
357 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_inhibit()
360 reg_val = (keypad->cols_en_mask & 0xff) << 8; in imx_keypad_inhibit()
361 writew(reg_val, keypad->mmio_base + KPCR); in imx_keypad_inhibit()
366 struct imx_keypad *keypad = input_get_drvdata(dev); in imx_keypad_close() local
371 keypad->enabled = false; in imx_keypad_close()
372 synchronize_irq(keypad->irq); in imx_keypad_close()
373 del_timer_sync(&keypad->check_matrix_timer); in imx_keypad_close()
375 imx_keypad_inhibit(keypad); in imx_keypad_close()
378 clk_disable_unprepare(keypad->clk); in imx_keypad_close()
383 struct imx_keypad *keypad = input_get_drvdata(dev); in imx_keypad_open() local
389 error = clk_prepare_enable(keypad->clk); in imx_keypad_open()
394 keypad->enabled = true; in imx_keypad_open()
396 imx_keypad_config(keypad); in imx_keypad_open()
399 if ((readw(keypad->mmio_base + KPDR) & keypad->rows_en_mask) == 0) { in imx_keypad_open()
420 struct imx_keypad *keypad; in imx_keypad_probe() local
434 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); in imx_keypad_probe()
435 if (!keypad) { in imx_keypad_probe()
440 keypad->input_dev = input_dev; in imx_keypad_probe()
441 keypad->irq = irq; in imx_keypad_probe()
442 keypad->stable_count = 0; in imx_keypad_probe()
444 timer_setup(&keypad->check_matrix_timer, in imx_keypad_probe()
447 keypad->mmio_base = devm_platform_ioremap_resource(pdev, 0); in imx_keypad_probe()
448 if (IS_ERR(keypad->mmio_base)) in imx_keypad_probe()
449 return PTR_ERR(keypad->mmio_base); in imx_keypad_probe()
451 keypad->clk = devm_clk_get(&pdev->dev, NULL); in imx_keypad_probe()
452 if (IS_ERR(keypad->clk)) { in imx_keypad_probe()
454 return PTR_ERR(keypad->clk); in imx_keypad_probe()
467 keypad->keycodes, input_dev); in imx_keypad_probe()
477 if (keypad->keycodes[i] != KEY_RESERVED) { in imx_keypad_probe()
478 keypad->rows_en_mask |= 1 << row; in imx_keypad_probe()
479 keypad->cols_en_mask |= 1 << col; in imx_keypad_probe()
483 dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask); in imx_keypad_probe()
484 dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask); in imx_keypad_probe()
488 input_set_drvdata(input_dev, keypad); in imx_keypad_probe()
491 error = clk_prepare_enable(keypad->clk); in imx_keypad_probe()
494 imx_keypad_inhibit(keypad); in imx_keypad_probe()
495 clk_disable_unprepare(keypad->clk); in imx_keypad_probe()
498 pdev->name, keypad); in imx_keypad_probe()
511 platform_set_drvdata(pdev, keypad); in imx_keypad_probe()