Lines Matching +full:ep9307 +full:- +full:keypad

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for the Cirrus EP93xx matrix keypad controller.
7 * Based on the pxa27x matrix keypad controller by Rodolfo Giometti.
26 * Keypad Interface Register offsets
81 struct ep93xx_keypad *keypad = dev_id; in ep93xx_keypad_irq_handler() local
82 struct input_dev *input_dev = keypad->input_dev; in ep93xx_keypad_irq_handler()
86 status = __raw_readl(keypad->mmio_base + KEY_REG); in ep93xx_keypad_irq_handler()
89 key1 = keypad->keycodes[keycode]; in ep93xx_keypad_irq_handler()
92 key2 = keypad->keycodes[keycode]; in ep93xx_keypad_irq_handler()
95 if (keypad->key1 && key1 != keypad->key1 && key2 != keypad->key1) in ep93xx_keypad_irq_handler()
96 input_report_key(input_dev, keypad->key1, 0); in ep93xx_keypad_irq_handler()
98 if (keypad->key2 && key1 != keypad->key2 && key2 != keypad->key2) in ep93xx_keypad_irq_handler()
99 input_report_key(input_dev, keypad->key2, 0); in ep93xx_keypad_irq_handler()
104 keypad->key1 = key1; in ep93xx_keypad_irq_handler()
105 keypad->key2 = key2; in ep93xx_keypad_irq_handler()
108 if (keypad->key1 && key1 != keypad->key1) in ep93xx_keypad_irq_handler()
109 input_report_key(input_dev, keypad->key1, 0); in ep93xx_keypad_irq_handler()
111 if (keypad->key2 && key1 != keypad->key2) in ep93xx_keypad_irq_handler()
112 input_report_key(input_dev, keypad->key2, 0); in ep93xx_keypad_irq_handler()
116 keypad->key1 = key1; in ep93xx_keypad_irq_handler()
117 keypad->key2 = 0; in ep93xx_keypad_irq_handler()
120 input_report_key(input_dev, keypad->key1, 0); in ep93xx_keypad_irq_handler()
121 input_report_key(input_dev, keypad->key2, 0); in ep93xx_keypad_irq_handler()
123 keypad->key1 = keypad->key2 = 0; in ep93xx_keypad_irq_handler()
130 static void ep93xx_keypad_config(struct ep93xx_keypad *keypad) in ep93xx_keypad_config() argument
134 val |= (keypad->debounce << KEY_INIT_DBNC_SHIFT) & KEY_INIT_DBNC_MASK; in ep93xx_keypad_config()
136 val |= (keypad->prescale << KEY_INIT_PRSCL_SHIFT) & KEY_INIT_PRSCL_MASK; in ep93xx_keypad_config()
138 __raw_writel(val, keypad->mmio_base + KEY_INIT); in ep93xx_keypad_config()
143 struct ep93xx_keypad *keypad = input_get_drvdata(pdev); in ep93xx_keypad_open() local
145 if (!keypad->enabled) { in ep93xx_keypad_open()
146 ep93xx_keypad_config(keypad); in ep93xx_keypad_open()
147 clk_prepare_enable(keypad->clk); in ep93xx_keypad_open()
148 keypad->enabled = true; in ep93xx_keypad_open()
156 struct ep93xx_keypad *keypad = input_get_drvdata(pdev); in ep93xx_keypad_close() local
158 if (keypad->enabled) { in ep93xx_keypad_close()
159 clk_disable_unprepare(keypad->clk); in ep93xx_keypad_close()
160 keypad->enabled = false; in ep93xx_keypad_close()
168 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); in ep93xx_keypad_suspend() local
169 struct input_dev *input_dev = keypad->input_dev; in ep93xx_keypad_suspend()
171 guard(mutex)(&input_dev->mutex); in ep93xx_keypad_suspend()
173 if (keypad->enabled) { in ep93xx_keypad_suspend()
174 clk_disable(keypad->clk); in ep93xx_keypad_suspend()
175 keypad->enabled = false; in ep93xx_keypad_suspend()
184 struct ep93xx_keypad *keypad = platform_get_drvdata(pdev); in ep93xx_keypad_resume() local
185 struct input_dev *input_dev = keypad->input_dev; in ep93xx_keypad_resume()
187 guard(mutex)(&input_dev->mutex); in ep93xx_keypad_resume()
190 if (!keypad->enabled) { in ep93xx_keypad_resume()
191 ep93xx_keypad_config(keypad); in ep93xx_keypad_resume()
192 clk_enable(keypad->clk); in ep93xx_keypad_resume()
193 keypad->enabled = true; in ep93xx_keypad_resume()
205 struct device *dev = &pdev->dev; in ep93xx_keypad_probe()
206 struct ep93xx_keypad *keypad; in ep93xx_keypad_probe() local
210 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); in ep93xx_keypad_probe()
211 if (!keypad) in ep93xx_keypad_probe()
212 return -ENOMEM; in ep93xx_keypad_probe()
214 keypad->irq = platform_get_irq(pdev, 0); in ep93xx_keypad_probe()
215 if (keypad->irq < 0) in ep93xx_keypad_probe()
216 return keypad->irq; in ep93xx_keypad_probe()
218 keypad->mmio_base = devm_platform_ioremap_resource(pdev, 0); in ep93xx_keypad_probe()
219 if (IS_ERR(keypad->mmio_base)) in ep93xx_keypad_probe()
220 return PTR_ERR(keypad->mmio_base); in ep93xx_keypad_probe()
222 keypad->clk = devm_clk_get(&pdev->dev, NULL); in ep93xx_keypad_probe()
223 if (IS_ERR(keypad->clk)) in ep93xx_keypad_probe()
224 return PTR_ERR(keypad->clk); in ep93xx_keypad_probe()
226 device_property_read_u32(dev, "debounce-delay-ms", &keypad->debounce); in ep93xx_keypad_probe()
227 device_property_read_u16(dev, "cirrus,prescale", &keypad->prescale); in ep93xx_keypad_probe()
229 input_dev = devm_input_allocate_device(&pdev->dev); in ep93xx_keypad_probe()
231 return -ENOMEM; in ep93xx_keypad_probe()
233 keypad->input_dev = input_dev; in ep93xx_keypad_probe()
235 input_dev->name = pdev->name; in ep93xx_keypad_probe()
236 input_dev->id.bustype = BUS_HOST; in ep93xx_keypad_probe()
237 input_dev->open = ep93xx_keypad_open; in ep93xx_keypad_probe()
238 input_dev->close = ep93xx_keypad_close; in ep93xx_keypad_probe()
242 keypad->keycodes, input_dev); in ep93xx_keypad_probe()
246 if (device_property_read_bool(&pdev->dev, "autorepeat")) in ep93xx_keypad_probe()
247 __set_bit(EV_REP, input_dev->evbit); in ep93xx_keypad_probe()
248 input_set_drvdata(input_dev, keypad); in ep93xx_keypad_probe()
250 err = devm_request_irq(&pdev->dev, keypad->irq, in ep93xx_keypad_probe()
252 0, pdev->name, keypad); in ep93xx_keypad_probe()
260 platform_set_drvdata(pdev, keypad); in ep93xx_keypad_probe()
262 device_init_wakeup(&pdev->dev, 1); in ep93xx_keypad_probe()
263 err = dev_pm_set_wake_irq(&pdev->dev, keypad->irq); in ep93xx_keypad_probe()
265 dev_warn(&pdev->dev, "failed to set up wakeup irq: %d\n", err); in ep93xx_keypad_probe()
272 dev_pm_clear_wake_irq(&pdev->dev); in ep93xx_keypad_remove()
276 { .compatible = "cirrus,ep9307-keypad" },
283 .name = "ep93xx-keypad",
294 MODULE_DESCRIPTION("EP93xx Matrix Keypad Controller");
295 MODULE_ALIAS("platform:ep93xx-keypad");