Lines Matching +full:s5pv210 +full:- +full:keypad
1 // SPDX-License-Identifier: GPL-2.0-or-later
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()
217 * re-enable the handler. 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()
247 struct device_node *np = dev->of_node, *key_np; in samsung_keypad_parse_dt()
252 return ERR_PTR(-EINVAL); in samsung_keypad_parse_dt()
258 return ERR_PTR(-ENOMEM); in samsung_keypad_parse_dt()
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()
265 return ERR_PTR(-EINVAL); in samsung_keypad_parse_dt()
267 pdata->rows = num_rows; in samsung_keypad_parse_dt()
268 pdata->cols = num_cols; in samsung_keypad_parse_dt()
273 return ERR_PTR(-ENOMEM); in samsung_keypad_parse_dt()
275 pdata->keymap_data = keymap_data; in samsung_keypad_parse_dt()
278 keymap_data->keymap_size = key_count; in samsung_keypad_parse_dt()
282 return ERR_PTR(-ENOMEM); in samsung_keypad_parse_dt()
284 keymap_data->keymap = keymap; 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()
294 pdata->no_autorepeat = of_property_read_bool(np, "linux,input-no-autorepeat"); in samsung_keypad_parse_dt()
296 pdata->wakeup = of_property_read_bool(np, "wakeup-source") || in samsung_keypad_parse_dt()
298 of_property_read_bool(np, "linux,input-wakeup"); in samsung_keypad_parse_dt()
309 return ERR_PTR(-EINVAL); in samsung_keypad_parse_dt()
317 struct samsung_keypad *keypad; in samsung_keypad_probe() local
324 pdata = dev_get_platdata(&pdev->dev); in samsung_keypad_probe()
326 pdata = samsung_keypad_parse_dt(&pdev->dev); in samsung_keypad_probe()
331 keymap_data = pdata->keymap_data; in samsung_keypad_probe()
333 dev_err(&pdev->dev, "no keymap data defined\n"); in samsung_keypad_probe()
334 return -EINVAL; in samsung_keypad_probe()
337 if (!pdata->rows || pdata->rows > SAMSUNG_MAX_ROWS) in samsung_keypad_probe()
338 return -EINVAL; in samsung_keypad_probe()
340 if (!pdata->cols || pdata->cols > SAMSUNG_MAX_COLS) in samsung_keypad_probe()
341 return -EINVAL; in samsung_keypad_probe()
344 if (pdata->cfg_gpio) in samsung_keypad_probe()
345 pdata->cfg_gpio(pdata->rows, pdata->cols); in samsung_keypad_probe()
347 row_shift = get_count_order(pdata->cols); in samsung_keypad_probe()
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()
352 input_dev = devm_input_allocate_device(&pdev->dev); in samsung_keypad_probe()
353 if (!keypad || !input_dev) in samsung_keypad_probe()
354 return -ENOMEM; in samsung_keypad_probe()
358 return -ENODEV; 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()
362 return -EBUSY; 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()
384 if (pdev->dev.of_node) 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()
390 input_dev->name = pdev->name; in samsung_keypad_probe()
391 input_dev->id.bustype = BUS_HOST; in samsung_keypad_probe()
392 input_dev->dev.parent = &pdev->dev; in samsung_keypad_probe()
394 input_dev->open = samsung_keypad_open; in samsung_keypad_probe()
395 input_dev->close = samsung_keypad_close; in samsung_keypad_probe()
398 pdata->rows, pdata->cols, in samsung_keypad_probe()
399 keypad->keycodes, input_dev); in samsung_keypad_probe()
401 dev_err(&pdev->dev, "failed to build keymap\n"); in samsung_keypad_probe()
406 if (!pdata->no_autorepeat) in samsung_keypad_probe()
407 __set_bit(EV_REP, input_dev->evbit); 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()
425 device_init_wakeup(&pdev->dev, pdata->wakeup); in samsung_keypad_probe()
426 platform_set_drvdata(pdev, keypad); in samsung_keypad_probe()
427 pm_runtime_enable(&pdev->dev); in samsung_keypad_probe()
429 error = input_register_device(keypad->input_dev); in samsung_keypad_probe()
433 if (pdev->dev.of_node) { in samsung_keypad_probe()
434 devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap); in samsung_keypad_probe()
435 devm_kfree(&pdev->dev, (void *)pdata->keymap_data); in samsung_keypad_probe()
436 devm_kfree(&pdev->dev, (void *)pdata); in samsung_keypad_probe()
441 pm_runtime_disable(&pdev->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
451 pm_runtime_disable(&pdev->dev); in samsung_keypad_remove()
453 input_unregister_device(keypad->input_dev); in samsung_keypad_remove()
455 clk_unprepare(keypad->clk); in samsung_keypad_remove()
461 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_runtime_suspend() local
465 if (keypad->stopped) in samsung_keypad_runtime_suspend()
469 error = enable_irq_wake(keypad->irq); in samsung_keypad_runtime_suspend()
471 keypad->wake_enabled = true; in samsung_keypad_runtime_suspend()
473 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
475 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
477 clk_disable(keypad->clk); in samsung_keypad_runtime_suspend()
485 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_runtime_resume() local
488 if (keypad->stopped) in samsung_keypad_runtime_resume()
491 clk_enable(keypad->clk); in samsung_keypad_runtime_resume()
493 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
495 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
497 if (keypad->wake_enabled) in samsung_keypad_runtime_resume()
498 disable_irq_wake(keypad->irq); in samsung_keypad_runtime_resume()
503 static void samsung_keypad_toggle_wakeup(struct samsung_keypad *keypad, in samsung_keypad_toggle_wakeup() argument
508 clk_enable(keypad->clk); in samsung_keypad_toggle_wakeup()
510 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
513 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
514 enable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
517 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
518 disable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
520 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
522 clk_disable(keypad->clk); in samsung_keypad_toggle_wakeup()
528 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_suspend() local
529 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_suspend()
531 mutex_lock(&input_dev->mutex); in samsung_keypad_suspend()
534 samsung_keypad_stop(keypad); in samsung_keypad_suspend()
536 samsung_keypad_toggle_wakeup(keypad, true); in samsung_keypad_suspend()
538 mutex_unlock(&input_dev->mutex); in samsung_keypad_suspend()
546 struct samsung_keypad *keypad = platform_get_drvdata(pdev); in samsung_keypad_resume() local
547 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_resume()
549 mutex_lock(&input_dev->mutex); in samsung_keypad_resume()
551 samsung_keypad_toggle_wakeup(keypad, false); in samsung_keypad_resume()
554 samsung_keypad_start(keypad); in samsung_keypad_resume()
556 mutex_unlock(&input_dev->mutex); in samsung_keypad_resume()
569 { .compatible = "samsung,s3c6410-keypad" },
570 { .compatible = "samsung,s5pv210-keypad" },
578 .name = "samsung-keypad",
581 .name = "s5pv210-keypad",
592 .name = "samsung-keypad",
600 MODULE_DESCRIPTION("Samsung keypad driver");