Lines Matching +full:num +full:- +full:rows
1 // SPDX-License-Identifier: GPL-2.0-or-later
23 #include <linux/input/samsung-keypad.h>
73 unsigned int rows; member
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()
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()
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()
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()
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()
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()
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()
294 if (of_get_property(np, "linux,input-no-autorepeat", NULL)) in samsung_keypad_parse_dt()
295 pdata->no_autorepeat = true; in samsung_keypad_parse_dt()
297 pdata->wakeup = of_property_read_bool(np, "wakeup-source") || in samsung_keypad_parse_dt()
299 of_property_read_bool(np, "linux,input-wakeup"); in samsung_keypad_parse_dt()
310 return ERR_PTR(-EINVAL); in samsung_keypad_parse_dt()
325 pdata = dev_get_platdata(&pdev->dev); in samsung_keypad_probe()
327 pdata = samsung_keypad_parse_dt(&pdev->dev); in samsung_keypad_probe()
332 keymap_data = pdata->keymap_data; in samsung_keypad_probe()
334 dev_err(&pdev->dev, "no keymap data defined\n"); in samsung_keypad_probe()
335 return -EINVAL; in samsung_keypad_probe()
338 if (!pdata->rows || pdata->rows > SAMSUNG_MAX_ROWS) in samsung_keypad_probe()
339 return -EINVAL; in samsung_keypad_probe()
341 if (!pdata->cols || pdata->cols > SAMSUNG_MAX_COLS) in samsung_keypad_probe()
342 return -EINVAL; in samsung_keypad_probe()
345 if (pdata->cfg_gpio) in samsung_keypad_probe()
346 pdata->cfg_gpio(pdata->rows, pdata->cols); in samsung_keypad_probe()
348 row_shift = get_count_order(pdata->cols); in samsung_keypad_probe()
349 keymap_size = (pdata->rows << row_shift) * sizeof(keypad->keycodes[0]); in samsung_keypad_probe()
351 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad) + keymap_size, in samsung_keypad_probe()
353 input_dev = devm_input_allocate_device(&pdev->dev); in samsung_keypad_probe()
355 return -ENOMEM; in samsung_keypad_probe()
359 return -ENODEV; in samsung_keypad_probe()
361 keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); in samsung_keypad_probe()
362 if (!keypad->base) in samsung_keypad_probe()
363 return -EBUSY; in samsung_keypad_probe()
365 keypad->clk = devm_clk_get(&pdev->dev, "keypad"); in samsung_keypad_probe()
366 if (IS_ERR(keypad->clk)) { in samsung_keypad_probe()
367 dev_err(&pdev->dev, "failed to get keypad clk\n"); in samsung_keypad_probe()
368 return PTR_ERR(keypad->clk); in samsung_keypad_probe()
371 error = clk_prepare(keypad->clk); in samsung_keypad_probe()
373 dev_err(&pdev->dev, "keypad clock prepare failed\n"); in samsung_keypad_probe()
377 keypad->input_dev = input_dev; in samsung_keypad_probe()
378 keypad->pdev = pdev; in samsung_keypad_probe()
379 keypad->row_shift = row_shift; in samsung_keypad_probe()
380 keypad->rows = pdata->rows; in samsung_keypad_probe()
381 keypad->cols = pdata->cols; in samsung_keypad_probe()
382 keypad->stopped = true; in samsung_keypad_probe()
383 init_waitqueue_head(&keypad->wait); in samsung_keypad_probe()
385 if (pdev->dev.of_node) in samsung_keypad_probe()
386 keypad->type = of_device_is_compatible(pdev->dev.of_node, in samsung_keypad_probe()
387 "samsung,s5pv210-keypad"); in samsung_keypad_probe()
389 keypad->type = platform_get_device_id(pdev)->driver_data; in samsung_keypad_probe()
391 input_dev->name = pdev->name; in samsung_keypad_probe()
392 input_dev->id.bustype = BUS_HOST; in samsung_keypad_probe()
393 input_dev->dev.parent = &pdev->dev; in samsung_keypad_probe()
395 input_dev->open = samsung_keypad_open; in samsung_keypad_probe()
396 input_dev->close = samsung_keypad_close; in samsung_keypad_probe()
399 pdata->rows, pdata->cols, in samsung_keypad_probe()
400 keypad->keycodes, input_dev); in samsung_keypad_probe()
402 dev_err(&pdev->dev, "failed to build keymap\n"); in samsung_keypad_probe()
407 if (!pdata->no_autorepeat) in samsung_keypad_probe()
408 __set_bit(EV_REP, input_dev->evbit); in samsung_keypad_probe()
412 keypad->irq = platform_get_irq(pdev, 0); in samsung_keypad_probe()
413 if (keypad->irq < 0) { in samsung_keypad_probe()
414 error = keypad->irq; in samsung_keypad_probe()
418 error = devm_request_threaded_irq(&pdev->dev, keypad->irq, NULL, in samsung_keypad_probe()
420 dev_name(&pdev->dev), keypad); in samsung_keypad_probe()
422 dev_err(&pdev->dev, "failed to register keypad interrupt\n"); in samsung_keypad_probe()
426 device_init_wakeup(&pdev->dev, pdata->wakeup); in samsung_keypad_probe()
428 pm_runtime_enable(&pdev->dev); in samsung_keypad_probe()
430 error = input_register_device(keypad->input_dev); in samsung_keypad_probe()
434 if (pdev->dev.of_node) { in samsung_keypad_probe()
435 devm_kfree(&pdev->dev, (void *)pdata->keymap_data->keymap); in samsung_keypad_probe()
436 devm_kfree(&pdev->dev, (void *)pdata->keymap_data); in samsung_keypad_probe()
437 devm_kfree(&pdev->dev, (void *)pdata); in samsung_keypad_probe()
442 pm_runtime_disable(&pdev->dev); in samsung_keypad_probe()
444 clk_unprepare(keypad->clk); in samsung_keypad_probe()
452 pm_runtime_disable(&pdev->dev); in samsung_keypad_remove()
454 input_unregister_device(keypad->input_dev); in samsung_keypad_remove()
456 clk_unprepare(keypad->clk); in samsung_keypad_remove()
469 if (keypad->stopped) in samsung_keypad_runtime_suspend()
473 error = enable_irq_wake(keypad->irq); in samsung_keypad_runtime_suspend()
475 keypad->wake_enabled = true; in samsung_keypad_runtime_suspend()
477 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
479 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_suspend()
481 clk_disable(keypad->clk); in samsung_keypad_runtime_suspend()
492 if (keypad->stopped) in samsung_keypad_runtime_resume()
495 clk_enable(keypad->clk); in samsung_keypad_runtime_resume()
497 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
499 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_runtime_resume()
501 if (keypad->wake_enabled) in samsung_keypad_runtime_resume()
502 disable_irq_wake(keypad->irq); in samsung_keypad_runtime_resume()
514 clk_enable(keypad->clk); in samsung_keypad_toggle_wakeup()
516 val = readl(keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
519 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
520 enable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
523 if (device_may_wakeup(&keypad->pdev->dev)) in samsung_keypad_toggle_wakeup()
524 disable_irq_wake(keypad->irq); in samsung_keypad_toggle_wakeup()
526 writel(val, keypad->base + SAMSUNG_KEYIFCON); in samsung_keypad_toggle_wakeup()
528 clk_disable(keypad->clk); in samsung_keypad_toggle_wakeup()
535 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_suspend()
537 mutex_lock(&input_dev->mutex); in samsung_keypad_suspend()
544 mutex_unlock(&input_dev->mutex); in samsung_keypad_suspend()
553 struct input_dev *input_dev = keypad->input_dev; in samsung_keypad_resume()
555 mutex_lock(&input_dev->mutex); in samsung_keypad_resume()
562 mutex_unlock(&input_dev->mutex); in samsung_keypad_resume()
576 { .compatible = "samsung,s3c6410-keypad" },
577 { .compatible = "samsung,s5pv210-keypad" },
585 .name = "samsung-keypad",
588 .name = "s5pv210-keypad",
599 .name = "samsung-keypad",