Lines Matching +full:input +full:- +full:debounce
1 // SPDX-License-Identifier: GPL-2.0-only
8 #include <linux/input.h>
9 #include <linux/input/matrix_keypad.h>
65 /* Structure representing various run-time entities */
82 * Returns the keycode from the input device keymap given the row and
87 unsigned int row_shift = get_count_order(kp->n_cols); in bcm_kp_get_keycode()
88 unsigned short *keymap = kp->input_dev->keycode; in bcm_kp_get_keycode()
102 writel(0xFFFFFFFF, kp->base + KPICRN_OFFSET(reg_num)); in bcm_kp_report_keys()
104 state = readl(kp->base + KPSSRN_OFFSET(reg_num)); in bcm_kp_report_keys()
105 change = kp->last_state[reg_num] ^ state; in bcm_kp_report_keys()
106 kp->last_state[reg_num] = state; in bcm_kp_report_keys()
115 input_report_key(kp->input_dev, keycode, key_press); in bcm_kp_report_keys()
122 int pull_mode = (kp->kpcr >> KPCR_MODE_SHIFT) & KPCR_MODE_MASK; in bcm_kp_isr_thread()
128 input_sync(kp->input_dev); in bcm_kp_isr_thread()
137 if (kp->clk) { in bcm_kp_start()
138 error = clk_prepare_enable(kp->clk); in bcm_kp_start()
143 writel(kp->kpior, kp->base + KPIOR_OFFSET); in bcm_kp_start()
145 writel(kp->imr0_val, kp->base + KPIMR0_OFFSET); in bcm_kp_start()
146 writel(kp->imr1_val, kp->base + KPIMR1_OFFSET); in bcm_kp_start()
148 writel(kp->kpemr, kp->base + KPEMR0_OFFSET); in bcm_kp_start()
149 writel(kp->kpemr, kp->base + KPEMR1_OFFSET); in bcm_kp_start()
150 writel(kp->kpemr, kp->base + KPEMR2_OFFSET); in bcm_kp_start()
151 writel(kp->kpemr, kp->base + KPEMR3_OFFSET); in bcm_kp_start()
153 writel(0xFFFFFFFF, kp->base + KPICR0_OFFSET); in bcm_kp_start()
154 writel(0xFFFFFFFF, kp->base + KPICR1_OFFSET); in bcm_kp_start()
156 kp->last_state[0] = readl(kp->base + KPSSR0_OFFSET); in bcm_kp_start()
157 kp->last_state[0] = readl(kp->base + KPSSR1_OFFSET); in bcm_kp_start()
159 writel(kp->kpcr | KPCR_ENABLE, kp->base + KPCR_OFFSET); in bcm_kp_start()
168 val = readl(kp->base + KPCR_OFFSET); in bcm_kp_stop()
170 writel(0, kp->base + KPCR_OFFSET); in bcm_kp_stop()
171 writel(0, kp->base + KPIMR0_OFFSET); in bcm_kp_stop()
172 writel(0, kp->base + KPIMR1_OFFSET); in bcm_kp_stop()
173 writel(0xFFFFFFFF, kp->base + KPICR0_OFFSET); in bcm_kp_stop()
174 writel(0xFFFFFFFF, kp->base + KPICR1_OFFSET); in bcm_kp_stop()
176 clk_disable_unprepare(kp->clk); in bcm_kp_stop()
195 struct device *dev = kp->input_dev->dev.parent; in bcm_kp_matrix_key_parse_dt()
196 struct device_node *np = dev->of_node; in bcm_kp_matrix_key_parse_dt()
203 kp->kpcr = KPCR_STATUSFILTERENABLE | KPCR_COLFILTERENABLE; in bcm_kp_matrix_key_parse_dt()
205 error = matrix_keypad_parse_properties(dev, &kp->n_rows, &kp->n_cols); in bcm_kp_matrix_key_parse_dt()
212 kp->kpcr |= (kp->n_rows - 1) << KPCR_ROWWIDTH_SHIFT; in bcm_kp_matrix_key_parse_dt()
215 kp->kpcr |= (kp->n_cols - 1) << KPCR_COLUMNWIDTH_SHIFT; in bcm_kp_matrix_key_parse_dt()
224 col_mask = (1 << (kp->n_cols)) - 1; in bcm_kp_matrix_key_parse_dt()
225 num_rows = kp->n_rows; in bcm_kp_matrix_key_parse_dt()
228 kp->imr0_val = col_mask; in bcm_kp_matrix_key_parse_dt()
231 while (--num_rows && rows_set++ < 4) in bcm_kp_matrix_key_parse_dt()
232 kp->imr0_val |= kp->imr0_val << MAX_COLS; in bcm_kp_matrix_key_parse_dt()
235 kp->imr1_val = 0; in bcm_kp_matrix_key_parse_dt()
237 kp->imr1_val = col_mask; in bcm_kp_matrix_key_parse_dt()
238 while (--num_rows) in bcm_kp_matrix_key_parse_dt()
239 kp->imr1_val |= kp->imr1_val << MAX_COLS; in bcm_kp_matrix_key_parse_dt()
244 kp->kpemr = 0; in bcm_kp_matrix_key_parse_dt()
246 kp->kpemr |= (KPEMR_EDGETYPE_BOTH << i); in bcm_kp_matrix_key_parse_dt()
249 * Obtain the Status filter debounce value and verify against the in bcm_kp_matrix_key_parse_dt()
252 of_property_read_u32(np, "status-debounce-filter-period", &dt_val); in bcm_kp_matrix_key_parse_dt()
255 dev_err(dev, "Invalid Status filter debounce value %d\n", in bcm_kp_matrix_key_parse_dt()
257 return -EINVAL; in bcm_kp_matrix_key_parse_dt()
260 kp->kpcr |= dt_val << KPCR_STATUSFILTERTYPE_SHIFT; in bcm_kp_matrix_key_parse_dt()
263 * Obtain the Column filter debounce value and verify against the in bcm_kp_matrix_key_parse_dt()
266 of_property_read_u32(np, "col-debounce-filter-period", &dt_val); in bcm_kp_matrix_key_parse_dt()
269 dev_err(dev, "Invalid Column filter debounce value %d\n", in bcm_kp_matrix_key_parse_dt()
271 return -EINVAL; in bcm_kp_matrix_key_parse_dt()
274 kp->kpcr |= dt_val << KPCR_COLFILTERTYPE_SHIFT; in bcm_kp_matrix_key_parse_dt()
280 if (of_property_read_bool(np, "row-output-enabled")) { in bcm_kp_matrix_key_parse_dt()
285 kp->kpior = ((1 << kp->n_rows) - 1) << in bcm_kp_matrix_key_parse_dt()
288 kp->kpior = ((1 << kp->n_cols) - 1) << in bcm_kp_matrix_key_parse_dt()
295 if (of_property_read_bool(np, "pull-up-enabled")) in bcm_kp_matrix_key_parse_dt()
296 kp->kpcr |= KPCR_MODE; in bcm_kp_matrix_key_parse_dt()
299 kp->n_rows, kp->n_cols, in bcm_kp_matrix_key_parse_dt()
300 kp->kpcr, kp->kpior, kp->kpemr); in bcm_kp_matrix_key_parse_dt()
313 kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); in bcm_kp_probe()
315 return -ENOMEM; in bcm_kp_probe()
317 input_dev = devm_input_allocate_device(&pdev->dev); in bcm_kp_probe()
319 dev_err(&pdev->dev, "failed to allocate the input device\n"); in bcm_kp_probe()
320 return -ENOMEM; in bcm_kp_probe()
323 __set_bit(EV_KEY, input_dev->evbit); in bcm_kp_probe()
325 /* Enable auto repeat feature of Linux input subsystem */ in bcm_kp_probe()
326 if (of_property_read_bool(pdev->dev.of_node, "autorepeat")) in bcm_kp_probe()
327 __set_bit(EV_REP, input_dev->evbit); in bcm_kp_probe()
329 input_dev->name = pdev->name; in bcm_kp_probe()
330 input_dev->phys = "keypad/input0"; in bcm_kp_probe()
331 input_dev->dev.parent = &pdev->dev; in bcm_kp_probe()
332 input_dev->open = bcm_kp_open; in bcm_kp_probe()
333 input_dev->close = bcm_kp_close; in bcm_kp_probe()
335 input_dev->id.bustype = BUS_HOST; in bcm_kp_probe()
336 input_dev->id.vendor = 0x0001; in bcm_kp_probe()
337 input_dev->id.product = 0x0001; in bcm_kp_probe()
338 input_dev->id.version = 0x0100; in bcm_kp_probe()
342 kp->input_dev = input_dev; in bcm_kp_probe()
349 kp->n_rows, kp->n_cols, in bcm_kp_probe()
352 dev_err(&pdev->dev, "failed to build keymap\n"); in bcm_kp_probe()
359 dev_err(&pdev->dev, "Missing keypad base address resource\n"); in bcm_kp_probe()
360 return -ENODEV; in bcm_kp_probe()
363 kp->base = devm_ioremap_resource(&pdev->dev, res); in bcm_kp_probe()
364 if (IS_ERR(kp->base)) in bcm_kp_probe()
365 return PTR_ERR(kp->base); in bcm_kp_probe()
368 kp->clk = devm_clk_get(&pdev->dev, "peri_clk"); in bcm_kp_probe()
369 if (IS_ERR(kp->clk)) { in bcm_kp_probe()
370 error = PTR_ERR(kp->clk); in bcm_kp_probe()
371 if (error != -ENOENT) { in bcm_kp_probe()
372 if (error != -EPROBE_DEFER) in bcm_kp_probe()
373 dev_err(&pdev->dev, "Failed to get clock\n"); in bcm_kp_probe()
376 dev_dbg(&pdev->dev, in bcm_kp_probe()
378 kp->clk = NULL; in bcm_kp_probe()
383 error = of_property_read_u32(pdev->dev.of_node, in bcm_kp_probe()
384 "clock-frequency", &desired_rate); in bcm_kp_probe()
388 actual_rate = clk_round_rate(kp->clk, desired_rate); in bcm_kp_probe()
390 return -EINVAL; in bcm_kp_probe()
392 error = clk_set_rate(kp->clk, actual_rate); in bcm_kp_probe()
396 error = clk_prepare_enable(kp->clk); in bcm_kp_probe()
404 kp->irq = platform_get_irq(pdev, 0); in bcm_kp_probe()
405 if (kp->irq < 0) in bcm_kp_probe()
406 return -EINVAL; in bcm_kp_probe()
408 error = devm_request_threaded_irq(&pdev->dev, kp->irq, in bcm_kp_probe()
410 IRQF_ONESHOT, pdev->name, kp); in bcm_kp_probe()
412 dev_err(&pdev->dev, "failed to request IRQ\n"); in bcm_kp_probe()
418 dev_err(&pdev->dev, "failed to register input device\n"); in bcm_kp_probe()
426 { .compatible = "brcm,bcm-keypad" },
434 .name = "bcm-keypad",