Lines Matching refs:keypad

84 static void imx_keypad_scan_matrix(struct imx_keypad *keypad,  in imx_keypad_scan_matrix()  argument
91 if ((keypad->cols_en_mask & (1 << col)) == 0) in imx_keypad_scan_matrix()
99 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
101 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
103 reg_val = readw(keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
104 reg_val &= ~((keypad->cols_en_mask & 0xff) << 8); in imx_keypad_scan_matrix()
105 writew(reg_val, keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
109 reg_val = readw(keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
110 reg_val |= (keypad->cols_en_mask & 0xff) << 8; in imx_keypad_scan_matrix()
111 writew(reg_val, keypad->mmio_base + KPCR); in imx_keypad_scan_matrix()
118 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
120 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
132 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
133 matrix_volatile_state[col] = (~reg_val) & keypad->rows_en_mask; in imx_keypad_scan_matrix()
140 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
142 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_scan_matrix()
149 static void imx_keypad_fire_events(struct imx_keypad *keypad, in imx_keypad_fire_events() argument
152 struct input_dev *input_dev = keypad->input_dev; in imx_keypad_fire_events()
159 if ((keypad->cols_en_mask & (1 << col)) == 0) in imx_keypad_fire_events()
162 bits_changed = keypad->matrix_stable_state[col] ^ in imx_keypad_fire_events()
169 if ((keypad->rows_en_mask & (1 << row)) == 0) in imx_keypad_fire_events()
176 input_report_key(input_dev, keypad->keycodes[code], in imx_keypad_fire_events()
179 keypad->keycodes[code], in imx_keypad_fire_events()
191 struct imx_keypad *keypad = (struct imx_keypad *) data; in imx_keypad_check_for_events() local
199 imx_keypad_scan_matrix(keypad, matrix_volatile_state); in imx_keypad_check_for_events()
203 if ((keypad->cols_en_mask & (1 << i)) == 0) in imx_keypad_check_for_events()
206 if (keypad->matrix_unstable_state[i] ^ matrix_volatile_state[i]) { in imx_keypad_check_for_events()
220 memcpy(keypad->matrix_unstable_state, matrix_volatile_state, in imx_keypad_check_for_events()
222 keypad->stable_count = 0; in imx_keypad_check_for_events()
224 keypad->stable_count++; in imx_keypad_check_for_events()
230 if (keypad->stable_count < IMX_KEYPAD_SCANS_FOR_STABILITY) { in imx_keypad_check_for_events()
231 mod_timer(&keypad->check_matrix_timer, in imx_keypad_check_for_events()
242 if (keypad->stable_count == IMX_KEYPAD_SCANS_FOR_STABILITY) { in imx_keypad_check_for_events()
243 imx_keypad_fire_events(keypad, matrix_volatile_state); in imx_keypad_check_for_events()
245 memcpy(keypad->matrix_stable_state, matrix_volatile_state, in imx_keypad_check_for_events()
264 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()
268 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
271 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
279 mod_timer(&keypad->check_matrix_timer, in imx_keypad_check_for_events()
282 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()
286 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
289 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_check_for_events()
295 struct imx_keypad *keypad = dev_id; in imx_keypad_irq_handler() local
298 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_irq_handler()
304 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_irq_handler()
306 if (keypad->enabled) { in imx_keypad_irq_handler()
308 keypad->stable_count = 0; in imx_keypad_irq_handler()
311 mod_timer(&keypad->check_matrix_timer, in imx_keypad_irq_handler()
318 static void imx_keypad_config(struct imx_keypad *keypad) in imx_keypad_config() argument
326 reg_val = readw(keypad->mmio_base + KPCR); in imx_keypad_config()
327 reg_val |= keypad->rows_en_mask & 0xff; /* rows */ in imx_keypad_config()
328 reg_val |= (keypad->cols_en_mask & 0xff) << 8; /* cols */ in imx_keypad_config()
329 writew(reg_val, keypad->mmio_base + KPCR); in imx_keypad_config()
332 reg_val = readw(keypad->mmio_base + KPDR); in imx_keypad_config()
334 writew(reg_val, keypad->mmio_base + KPDR); in imx_keypad_config()
337 writew(0xff00, keypad->mmio_base + KDDR); in imx_keypad_config()
343 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_config()
346 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_config()
351 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_config()
354 static void imx_keypad_inhibit(struct imx_keypad *keypad) in imx_keypad_inhibit() argument
359 reg_val = readw(keypad->mmio_base + KPSR); in imx_keypad_inhibit()
361 writew(reg_val, keypad->mmio_base + KPSR); in imx_keypad_inhibit()
364 writew(0xff00, keypad->mmio_base + KPCR); in imx_keypad_inhibit()
369 struct imx_keypad *keypad = input_get_drvdata(dev); in imx_keypad_close() local
374 keypad->enabled = false; in imx_keypad_close()
375 synchronize_irq(keypad->irq); in imx_keypad_close()
376 del_timer_sync(&keypad->check_matrix_timer); in imx_keypad_close()
378 imx_keypad_inhibit(keypad); in imx_keypad_close()
381 clk_disable(keypad->clk); in imx_keypad_close()
386 struct imx_keypad *keypad = input_get_drvdata(dev); in imx_keypad_open() local
391 keypad->enabled = true; in imx_keypad_open()
394 clk_enable(keypad->clk); in imx_keypad_open()
395 imx_keypad_config(keypad); in imx_keypad_open()
398 if ((readw(keypad->mmio_base + KPDR) & keypad->rows_en_mask) == 0) { in imx_keypad_open()
414 struct imx_keypad *keypad; in imx_keypad_probe() local
449 keypad = kzalloc(sizeof(struct imx_keypad), GFP_KERNEL); in imx_keypad_probe()
450 if (!keypad) { in imx_keypad_probe()
456 keypad->input_dev = input_dev; in imx_keypad_probe()
457 keypad->irq = irq; in imx_keypad_probe()
458 keypad->stable_count = 0; in imx_keypad_probe()
460 setup_timer(&keypad->check_matrix_timer, in imx_keypad_probe()
461 imx_keypad_check_for_events, (unsigned long) keypad); in imx_keypad_probe()
463 keypad->mmio_base = ioremap(res->start, resource_size(res)); in imx_keypad_probe()
464 if (keypad->mmio_base == NULL) { in imx_keypad_probe()
470 keypad->clk = clk_get(&pdev->dev, "kpp"); in imx_keypad_probe()
471 if (IS_ERR(keypad->clk)) { in imx_keypad_probe()
473 error = PTR_ERR(keypad->clk); in imx_keypad_probe()
479 keypad->rows_en_mask |= 1 << KEY_ROW(keymap_data->keymap[i]); in imx_keypad_probe()
480 keypad->cols_en_mask |= 1 << KEY_COL(keymap_data->keymap[i]); in imx_keypad_probe()
483 if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) || in imx_keypad_probe()
484 keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) { in imx_keypad_probe()
490 dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask); in imx_keypad_probe()
491 dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask); in imx_keypad_probe()
500 input_dev->keycode = keypad->keycodes; in imx_keypad_probe()
501 input_dev->keycodesize = sizeof(keypad->keycodes[0]); in imx_keypad_probe()
502 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes); in imx_keypad_probe()
505 keypad->keycodes, input_dev->keybit); in imx_keypad_probe()
508 input_set_drvdata(input_dev, keypad); in imx_keypad_probe()
511 imx_keypad_inhibit(keypad); in imx_keypad_probe()
514 pdev->name, keypad); in imx_keypad_probe()
527 platform_set_drvdata(pdev, keypad); in imx_keypad_probe()
535 clk_put(keypad->clk); in imx_keypad_probe()
537 iounmap(keypad->mmio_base); in imx_keypad_probe()
539 kfree(keypad); in imx_keypad_probe()
549 struct imx_keypad *keypad = platform_get_drvdata(pdev); in imx_keypad_remove() local
556 input_unregister_device(keypad->input_dev); in imx_keypad_remove()
558 free_irq(keypad->irq, keypad); in imx_keypad_remove()
559 clk_put(keypad->clk); in imx_keypad_remove()
561 iounmap(keypad->mmio_base); in imx_keypad_remove()
565 kfree(keypad); in imx_keypad_remove()