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
152 pm_runtime_get_sync(&keypad->pdev->dev); in samsung_keypad_irq()
155 val = readl(keypad->base + SAMSUNG_KEYIFSTSCLR); in samsung_keypad_irq()
157 writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR); in samsung_keypad_irq()
159 samsung_keypad_scan(keypad, row_state); in samsung_keypad_irq()
161 key_down = samsung_keypad_report(keypad, row_state); in samsung_keypad_irq()
163 wait_event_timeout(keypad->wait, keypad->stopped, in samsung_keypad_irq()
166 } while (key_down && !keypad->stopped); in samsung_keypad_irq()
168 pm_runtime_put(&keypad->pdev->dev); in samsung_keypad_irq()
173 static void samsung_keypad_start(struct samsung_keypad *keypad) in samsung_keypad_start() argument
177 pm_runtime_get_sync(&keypad->pdev->dev); in samsung_keypad_start()
180 keypad->stopped = false; in samsung_keypad_start()
182 clk_enable(keypad->clk); in samsung_keypad_start()
185 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_start()
187 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_start()
190 writel(0, keypad->base + SAMSUNG_KEYIFCOL); in samsung_keypad_start()
192 pm_runtime_put(&keypad->pdev->dev); in samsung_keypad_start()
195 static void samsung_keypad_stop(struct samsung_keypad *keypad) in samsung_keypad_stop() argument
199 pm_runtime_get_sync(&keypad->pdev->dev); in samsung_keypad_stop()
202 keypad->stopped = true; in samsung_keypad_stop()
203 wake_up(&keypad->wait); in samsung_keypad_stop()
204 disable_irq(keypad->irq); in samsung_keypad_stop()
207 writel(~0x0, keypad->base + SAMSUNG_KEYIFSTSCLR); in samsung_keypad_stop()
210 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_stop()
212 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_stop()
214 clk_disable(keypad->clk); in samsung_keypad_stop()
220 enable_irq(keypad->irq); in samsung_keypad_stop()
222 pm_runtime_put(&keypad->pdev->dev); in samsung_keypad_stop()
227 struct samsung_keypad *keypad = input_get_drvdata(input_dev); in samsung_keypad_open() local
229 samsung_keypad_start(keypad); in samsung_keypad_open()
236 struct samsung_keypad *keypad = input_get_drvdata(input_dev); in samsung_keypad_close() local
238 samsung_keypad_stop(keypad); in samsung_keypad_close()
262 of_property_read_u32(np, "samsung,keypad-num-rows", &num_rows); in samsung_keypad_parse_dt()
263 of_property_read_u32(np, "samsung,keypad-num-columns", &num_cols); in samsung_keypad_parse_dt()
265 dev_err(dev, "number of keypad rows/columns not specified\n"); in samsung_keypad_parse_dt()
289 of_property_read_u32(key_np, "keypad,row", &row); in samsung_keypad_parse_dt()
290 of_property_read_u32(key_np, "keypad,column", &col); in samsung_keypad_parse_dt()
319 struct samsung_keypad *keypad; in samsung_keypad_probe() local
350 keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]); in samsung_keypad_probe()
352 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size, in samsung_keypad_probe()
355 if (!keypad || !input_dev) in samsung_keypad_probe()
362 keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); in samsung_keypad_probe()
363 if (!keypad->base) in samsung_keypad_probe()
366 keypad->clk = devm_clk_get(&pdev->dev, "keypad"); in samsung_keypad_probe()
367 if (IS_ERR(keypad->clk)) { in samsung_keypad_probe()
368 dev_err(&pdev->dev, "failed to get keypad clk\n"); in samsung_keypad_probe()
369 return PTR_ERR(keypad->clk); in samsung_keypad_probe()
372 error = clk_prepare(keypad->clk); in samsung_keypad_probe()
374 dev_err(&pdev->dev, "keypad clock prepare failed\n"); in samsung_keypad_probe()
378 keypad->input_dev = input_dev; in samsung_keypad_probe()
379 keypad->pdev = pdev; in samsung_keypad_probe()
380 keypad->row_shift = row_shift; in samsung_keypad_probe()
381 keypad->rows = pdata->rows; in samsung_keypad_probe()
382 keypad->cols = pdata->cols; in samsung_keypad_probe()
383 keypad->stopped = true; in samsung_keypad_probe()
384 init_waitqueue_head(&keypad->wait); in samsung_keypad_probe()
387 keypad->type = of_device_is_compatible(pdev->dev.of_node, in samsung_keypad_probe()
388 "samsung,s5pv210-keypad"); in samsung_keypad_probe()
390 keypad->type = platform_get_device_id(pdev)->driver_data; in samsung_keypad_probe()
401 keypad->keycodes, input_dev); in samsung_keypad_probe()
411 input_set_drvdata(input_dev, keypad); in samsung_keypad_probe()
413 keypad->irq = platform_get_irq(pdev, 0); in samsung_keypad_probe()
414 if (keypad->irq < 0) { in samsung_keypad_probe()
415 error = keypad->irq; in samsung_keypad_probe()
419 error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL, in samsung_keypad_probe()
421 dev_name(&pdev->dev), keypad); in samsung_keypad_probe()
423 dev_err(&pdev->dev, "failed to register keypad interrupt\n"); in samsung_keypad_probe()
428 platform_set_drvdata(pdev, keypad); in samsung_keypad_probe()
431 error = input_register_device(keypad->input_dev); in samsung_keypad_probe()
445 clk_unprepare(keypad->clk); in samsung_keypad_probe()
451 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_remove() local
455 input_unregister_device(keypad->input_dev); in samsung_keypad_remove()
457 clk_unprepare(keypad->clk); in samsung_keypad_remove()
466 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_runtime_suspend() local
470 if (keypad->stopped) in samsung_keypad_runtime_suspend()
474 error = enable_irq_wake(keypad->irq); in samsung_keypad_runtime_suspend()
476 keypad->wake_enabled = true; in samsung_keypad_runtime_suspend()
478 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
480 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
482 clk_disable(keypad->clk); in samsung_keypad_runtime_suspend()
490 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_runtime_resume() local
493 if (keypad->stopped) in samsung_keypad_runtime_resume()
496 clk_enable(keypad->clk); in samsung_keypad_runtime_resume()
498 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
500 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
502 if (keypad->wake_enabled) in samsung_keypad_runtime_resume()
503 disable_irq_wake(keypad->irq); in samsung_keypad_runtime_resume()
510 static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad, in samsung_keypad_toggle_wakeup() argument
515 clk_enable(keypad->clk); in samsung_keypad_toggle_wakeup()
517 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
520 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
521 enable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
524 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
525 disable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
527 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
529 clk_disable(keypad->clk); in samsung_keypad_toggle_wakeup()
535 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_suspend() local
536 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_suspend()
541 samsung_keypad_stop(keypad); in samsung_keypad_suspend()
543 samsung_keypad_toggle_wakeup(keypad, true); in samsung_keypad_suspend()
553 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_resume() local
554 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_resume()
558 samsung_keypad_toggle_wakeup(keypad, false); in samsung_keypad_resume()
561 samsung_keypad_start(keypad); in samsung_keypad_resume()
577 { .compatible = "samsung,s3c6410-keypad" },
578 { .compatible = "samsung,s5pv210-keypad" },
586 .name = "samsung-keypad",
589 .name = "s5pv210-keypad",
600 .name = "samsung-keypad",
608 MODULE_DESCRIPTION("Samsung keypad driver");