Lines Matching full:keypad
3 * Samsung keypad driver
23 #include <linux/input/samsung-keypad.h>
79 static void samsung_keypad_scan(struct samsung_keypad *keypad, in samsung_keypad_scan() argument
85 for (col = 0; col < keypad->cols; col++) { in samsung_keypad_scan()
86 if (keypad->type == KEYPAD_TYPE_S5PV210) { in samsung_keypad_scan()
94 writel(val, keypad->base + SAMSUNG_KEYIFCOL); in samsung_keypad_scan()
97 val = readl(keypad->base + SAMSUNG_KEYIFROW); in samsung_keypad_scan()
98 row_state[col] = ~val & ((1 << keypad->rows) - 1); in samsung_keypad_scan()
102 writel(0, keypad->base + SAMSUNG_KEYIFCOL); in samsung_keypad_scan()
105 static bool samsung_keypad_report(struct samsung_keypad *keypad, in samsung_keypad_report() argument
108 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_report()
115 for (col = 0; col < keypad->cols; col++) { in samsung_keypad_report()
116 changed = row_state[col] ^ keypad->row_state[col]; in samsung_keypad_report()
121 for (row = 0; row < keypad->rows; row++) { in samsung_keypad_report()
127 dev_dbg(&keypad->input_dev->dev, in samsung_keypad_report()
131 val = MATRIX_SCAN_CODE(row, col, keypad->row_shift); in samsung_keypad_report()
135 keypad->keycodes[val], pressed); in samsung_keypad_report()
137 input_sync(keypad->input_dev); in samsung_keypad_report()
140 memcpy(keypad->row_state, row_state, sizeof(keypad->row_state)); in samsung_keypad_report()
147 struct samsung_keypad *keypad = dev_id; in samsung_keypad_irq() local
151 pm_runtime_get_sync(&keypad->pdev->dev); in samsung_keypad_irq()
154 readl(keypad->base + SAMSUNG_KEYIFSTSCLR); in samsung_keypad_irq()
156 writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR); in samsung_keypad_irq()
158 samsung_keypad_scan(keypad, row_state); in samsung_keypad_irq()
160 key_down = samsung_keypad_report(keypad, row_state); in samsung_keypad_irq()
162 wait_event_timeout(keypad->wait, keypad->stopped, in samsung_keypad_irq()
165 } while (key_down && !keypad->stopped); in samsung_keypad_irq()
167 pm_runtime_put(&keypad->pdev->dev); in samsung_keypad_irq()
172 static void samsung_keypad_start(struct samsung_keypad *keypad) in samsung_keypad_start() argument
176 pm_runtime_get_sync(&keypad->pdev->dev); in samsung_keypad_start()
179 keypad->stopped = false; in samsung_keypad_start()
181 clk_enable(keypad->clk); in samsung_keypad_start()
184 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_start()
186 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_start()
189 writel(0, keypad->base + SAMSUNG_KEYIFCOL); in samsung_keypad_start()
191 pm_runtime_put(&keypad->pdev->dev); in samsung_keypad_start()
194 static void samsung_keypad_stop(struct samsung_keypad *keypad) in samsung_keypad_stop() argument
198 pm_runtime_get_sync(&keypad->pdev->dev); in samsung_keypad_stop()
201 keypad->stopped = true; in samsung_keypad_stop()
202 wake_up(&keypad->wait); in samsung_keypad_stop()
203 disable_irq(keypad->irq); in samsung_keypad_stop()
206 writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR); in samsung_keypad_stop()
209 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_stop()
211 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_stop()
213 clk_disable(keypad->clk); in samsung_keypad_stop()
219 enable_irq(keypad->irq); in samsung_keypad_stop()
221 pm_runtime_put(&keypad->pdev->dev); in samsung_keypad_stop()
226 struct samsung_keypad *keypad = input_get_drvdata(input_dev); in samsung_keypad_open() local
228 samsung_keypad_start(keypad); in samsung_keypad_open()
235 struct samsung_keypad *keypad = input_get_drvdata(input_dev); in samsung_keypad_close() local
237 samsung_keypad_stop(keypad); in samsung_keypad_close()
261 of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows); in samsung_keypad_parse_dt()
262 of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols); in samsung_keypad_parse_dt()
264 dev_err(dev, "number of keypad rows/columns not specified\n"); in samsung_keypad_parse_dt()
288 of_property_read_u32(key_np, "keypad,row", &row); in samsung_keypad_parse_dt()
289 of_property_read_u32(key_np, "keypad,column", &col); in samsung_keypad_parse_dt()
317 struct samsung_keypad *keypad; in samsung_keypad_probe() local
348 keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]); in samsung_keypad_probe()
350 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size, in samsung_keypad_probe()
353 if (!keypad || !input_dev) in samsung_keypad_probe()
360 keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); in samsung_keypad_probe()
361 if (!keypad->base) in samsung_keypad_probe()
364 keypad->clk = devm_clk_get(&pdev->dev, "keypad"); in samsung_keypad_probe()
365 if (IS_ERR(keypad->clk)) { in samsung_keypad_probe()
366 dev_err(&pdev->dev, "failed to get keypad clk\n"); in samsung_keypad_probe()
367 return PTR_ERR(keypad->clk); in samsung_keypad_probe()
370 error = clk_prepare(keypad->clk); in samsung_keypad_probe()
372 dev_err(&pdev->dev, "keypad clock prepare failed\n"); in samsung_keypad_probe()
376 keypad->input_dev = input_dev; in samsung_keypad_probe()
377 keypad->pdev = pdev; in samsung_keypad_probe()
378 keypad->row_shift = row_shift; in samsung_keypad_probe()
379 keypad->rows = pdata->rows; in samsung_keypad_probe()
380 keypad->cols = pdata->cols; in samsung_keypad_probe()
381 keypad->stopped = true; in samsung_keypad_probe()
382 init_waitqueue_head(&keypad->wait); in samsung_keypad_probe()
385 keypad->type = of_device_is_compatible(pdev->dev.of_node, in samsung_keypad_probe()
386 "samsung,s5pv210-keypad"); in samsung_keypad_probe()
388 keypad->type = platform_get_device_id(pdev)->driver_data; in samsung_keypad_probe()
399 keypad->keycodes, input_dev); in samsung_keypad_probe()
409 input_set_drvdata(input_dev, keypad); in samsung_keypad_probe()
411 keypad->irq = platform_get_irq(pdev, 0); in samsung_keypad_probe()
412 if (keypad->irq < 0) { in samsung_keypad_probe()
413 error = keypad->irq; in samsung_keypad_probe()
417 error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL, in samsung_keypad_probe()
419 dev_name(&pdev->dev), keypad); in samsung_keypad_probe()
421 dev_err(&pdev->dev, "failed to register keypad interrupt\n"); in samsung_keypad_probe()
426 platform_set_drvdata(pdev, keypad); in samsung_keypad_probe()
429 error = input_register_device(keypad->input_dev); in samsung_keypad_probe()
443 clk_unprepare(keypad->clk); in samsung_keypad_probe()
449 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_remove() local
453 input_unregister_device(keypad->input_dev); in samsung_keypad_remove()
455 clk_unprepare(keypad->clk); in samsung_keypad_remove()
463 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_runtime_suspend() local
467 if (keypad->stopped) in samsung_keypad_runtime_suspend()
471 error = enable_irq_wake(keypad->irq); in samsung_keypad_runtime_suspend()
473 keypad->wake_enabled = true; in samsung_keypad_runtime_suspend()
475 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
477 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
479 clk_disable(keypad->clk); in samsung_keypad_runtime_suspend()
487 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_runtime_resume() local
490 if (keypad->stopped) in samsung_keypad_runtime_resume()
493 clk_enable(keypad->clk); in samsung_keypad_runtime_resume()
495 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
497 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
499 if (keypad->wake_enabled) in samsung_keypad_runtime_resume()
500 disable_irq_wake(keypad->irq); in samsung_keypad_runtime_resume()
505 static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad, in samsung_keypad_toggle_wakeup() argument
510 clk_enable(keypad->clk); in samsung_keypad_toggle_wakeup()
512 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
515 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
516 enable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
519 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
520 disable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
522 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
524 clk_disable(keypad->clk); in samsung_keypad_toggle_wakeup()
530 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_suspend() local
531 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_suspend()
536 samsung_keypad_stop(keypad); in samsung_keypad_suspend()
538 samsung_keypad_toggle_wakeup(keypad, true); in samsung_keypad_suspend()
548 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_resume() local
549 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_resume()
553 samsung_keypad_toggle_wakeup(keypad, false); in samsung_keypad_resume()
556 samsung_keypad_start(keypad); in samsung_keypad_resume()
571 { .compatible = "samsung,s3c6410-keypad" },
572 { .compatible = "samsung,s5pv210-keypad" },
580 .name = "samsung-keypad",
583 .name = "s5pv210-keypad",
594 .name = "samsung-keypad",
602 MODULE_DESCRIPTION("Samsung keypad driver");