Lines Matching +full:mt6779 +full:- +full:keypad
1 // SPDX-License-Identifier: GPL-2.0
16 #define MTK_KPD_NAME "mt6779-keypad"
50 struct mt6779_keypad *keypad = dev_id; in mt6779_keypad_irq_handler() local
51 const unsigned short *keycode = keypad->input_dev->keycode; in mt6779_keypad_irq_handler()
57 unsigned int row_shift = get_count_order(keypad->n_cols); in mt6779_keypad_irq_handler()
60 regmap_bulk_read(keypad->regmap, MTK_KPD_MEM, in mt6779_keypad_irq_handler()
63 bitmap_xor(change, new_state, keypad->keymap_state, MTK_KPD_NUM_BITS); in mt6779_keypad_irq_handler()
74 keypad->calc_row_col(key, &row, &col); in mt6779_keypad_irq_handler()
79 dev_dbg(&keypad->input_dev->dev, "%s", in mt6779_keypad_irq_handler()
82 input_event(keypad->input_dev, EV_MSC, MSC_SCAN, scancode); in mt6779_keypad_irq_handler()
83 input_report_key(keypad->input_dev, keycode[scancode], pressed); in mt6779_keypad_irq_handler()
84 input_sync(keypad->input_dev); in mt6779_keypad_irq_handler()
86 dev_dbg(&keypad->input_dev->dev, in mt6779_keypad_irq_handler()
90 bitmap_copy(keypad->keymap_state, new_state, MTK_KPD_NUM_BITS); in mt6779_keypad_irq_handler()
118 struct mt6779_keypad *keypad; in mt6779_keypad_pdrv_probe() local
126 keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); in mt6779_keypad_pdrv_probe()
127 if (!keypad) in mt6779_keypad_pdrv_probe()
128 return -ENOMEM; in mt6779_keypad_pdrv_probe()
134 keypad->regmap = devm_regmap_init_mmio(&pdev->dev, base, in mt6779_keypad_pdrv_probe()
136 if (IS_ERR(keypad->regmap)) { in mt6779_keypad_pdrv_probe()
137 dev_err(&pdev->dev, in mt6779_keypad_pdrv_probe()
138 "regmap init failed:%pe\n", keypad->regmap); in mt6779_keypad_pdrv_probe()
139 return PTR_ERR(keypad->regmap); in mt6779_keypad_pdrv_probe()
142 bitmap_fill(keypad->keymap_state, MTK_KPD_NUM_BITS); in mt6779_keypad_pdrv_probe()
144 keypad->input_dev = devm_input_allocate_device(&pdev->dev); in mt6779_keypad_pdrv_probe()
145 if (!keypad->input_dev) { in mt6779_keypad_pdrv_probe()
146 dev_err(&pdev->dev, "Failed to allocate input dev\n"); in mt6779_keypad_pdrv_probe()
147 return -ENOMEM; in mt6779_keypad_pdrv_probe()
150 keypad->input_dev->name = MTK_KPD_NAME; in mt6779_keypad_pdrv_probe()
151 keypad->input_dev->id.bustype = BUS_HOST; in mt6779_keypad_pdrv_probe()
153 error = matrix_keypad_parse_properties(&pdev->dev, &keypad->n_rows, in mt6779_keypad_pdrv_probe()
154 &keypad->n_cols); in mt6779_keypad_pdrv_probe()
156 dev_err(&pdev->dev, "Failed to parse keypad params\n"); in mt6779_keypad_pdrv_probe()
160 if (device_property_read_u32(&pdev->dev, "debounce-delay-ms", in mt6779_keypad_pdrv_probe()
165 dev_err(&pdev->dev, in mt6779_keypad_pdrv_probe()
168 return -EINVAL; in mt6779_keypad_pdrv_probe()
171 if (device_property_read_u32(&pdev->dev, "mediatek,keys-per-group", in mt6779_keypad_pdrv_probe()
177 keypad->calc_row_col = mt6779_keypad_calc_row_col_single; in mt6779_keypad_pdrv_probe()
180 keypad->calc_row_col = mt6779_keypad_calc_row_col_double; in mt6779_keypad_pdrv_probe()
183 dev_err(&pdev->dev, in mt6779_keypad_pdrv_probe()
184 "Invalid keys-per-group: %d\n", keys_per_group); in mt6779_keypad_pdrv_probe()
185 return -EINVAL; in mt6779_keypad_pdrv_probe()
188 wakeup = device_property_read_bool(&pdev->dev, "wakeup-source"); in mt6779_keypad_pdrv_probe()
190 dev_dbg(&pdev->dev, "n_row=%d n_col=%d debounce=%d\n", in mt6779_keypad_pdrv_probe()
191 keypad->n_rows, keypad->n_cols, debounce); in mt6779_keypad_pdrv_probe()
194 keypad->n_rows, keypad->n_cols, in mt6779_keypad_pdrv_probe()
195 NULL, keypad->input_dev); in mt6779_keypad_pdrv_probe()
197 dev_err(&pdev->dev, "Failed to build keymap\n"); in mt6779_keypad_pdrv_probe()
201 input_set_capability(keypad->input_dev, EV_MSC, MSC_SCAN); in mt6779_keypad_pdrv_probe()
203 regmap_write(keypad->regmap, MTK_KPD_DEBOUNCE, in mt6779_keypad_pdrv_probe()
207 regmap_update_bits(keypad->regmap, MTK_KPD_SEL, in mt6779_keypad_pdrv_probe()
211 regmap_update_bits(keypad->regmap, MTK_KPD_SEL, MTK_KPD_SEL_ROW, in mt6779_keypad_pdrv_probe()
212 MTK_KPD_SEL_ROWMASK(keypad->n_rows)); in mt6779_keypad_pdrv_probe()
213 regmap_update_bits(keypad->regmap, MTK_KPD_SEL, MTK_KPD_SEL_COL, in mt6779_keypad_pdrv_probe()
214 MTK_KPD_SEL_COLMASK(keypad->n_cols)); in mt6779_keypad_pdrv_probe()
216 keypad->clk = devm_clk_get(&pdev->dev, "kpd"); in mt6779_keypad_pdrv_probe()
217 if (IS_ERR(keypad->clk)) in mt6779_keypad_pdrv_probe()
218 return PTR_ERR(keypad->clk); in mt6779_keypad_pdrv_probe()
220 error = clk_prepare_enable(keypad->clk); in mt6779_keypad_pdrv_probe()
222 dev_err(&pdev->dev, "cannot prepare/enable keypad clock\n"); in mt6779_keypad_pdrv_probe()
226 error = devm_add_action_or_reset(&pdev->dev, mt6779_keypad_clk_disable, in mt6779_keypad_pdrv_probe()
227 keypad->clk); in mt6779_keypad_pdrv_probe()
235 error = devm_request_threaded_irq(&pdev->dev, irq, in mt6779_keypad_pdrv_probe()
237 IRQF_ONESHOT, MTK_KPD_NAME, keypad); in mt6779_keypad_pdrv_probe()
239 dev_err(&pdev->dev, "Failed to request IRQ#%d: %d\n", in mt6779_keypad_pdrv_probe()
244 error = input_register_device(keypad->input_dev); in mt6779_keypad_pdrv_probe()
246 dev_err(&pdev->dev, "Failed to register device\n"); in mt6779_keypad_pdrv_probe()
250 error = device_init_wakeup(&pdev->dev, wakeup); in mt6779_keypad_pdrv_probe()
252 dev_warn(&pdev->dev, "device_init_wakeup() failed: %d\n", in mt6779_keypad_pdrv_probe()
259 { .compatible = "mediatek,mt6779-keypad" },
260 { .compatible = "mediatek,mt6873-keypad" },
274 MODULE_DESCRIPTION("MTK Keypad (KPD) Driver");