Lines Matching refs:kp
95 static int bcm_kp_get_keycode(struct bcm_kp *kp, int row, int col) in bcm_kp_get_keycode() argument
97 unsigned int row_shift = get_count_order(kp->n_cols); in bcm_kp_get_keycode()
98 unsigned short *keymap = kp->input_dev->keycode; in bcm_kp_get_keycode()
103 static void bcm_kp_report_keys(struct bcm_kp *kp, int reg_num, int pull_mode) in bcm_kp_report_keys() argument
112 writel(0xFFFFFFFF, kp->base + KPICRN_OFFSET(reg_num)); in bcm_kp_report_keys()
114 state = readl(kp->base + KPSSRN_OFFSET(reg_num)); in bcm_kp_report_keys()
115 change = kp->last_state[reg_num] ^ state; in bcm_kp_report_keys()
116 kp->last_state[reg_num] = state; in bcm_kp_report_keys()
124 keycode = bcm_kp_get_keycode(kp, row, col); in bcm_kp_report_keys()
125 input_report_key(kp->input_dev, keycode, key_press); in bcm_kp_report_keys()
131 struct bcm_kp *kp = dev_id; in bcm_kp_isr_thread() local
132 int pull_mode = (kp->kpcr >> KPCR_MODE_SHIFT) & KPCR_MODE_MASK; in bcm_kp_isr_thread()
136 bcm_kp_report_keys(kp, reg_num, pull_mode); in bcm_kp_isr_thread()
138 input_sync(kp->input_dev); in bcm_kp_isr_thread()
143 static int bcm_kp_start(struct bcm_kp *kp) in bcm_kp_start() argument
147 if (kp->clk) { in bcm_kp_start()
148 error = clk_prepare_enable(kp->clk); in bcm_kp_start()
153 writel(kp->kpior, kp->base + KPIOR_OFFSET); in bcm_kp_start()
155 writel(kp->imr0_val, kp->base + KPIMR0_OFFSET); in bcm_kp_start()
156 writel(kp->imr1_val, kp->base + KPIMR1_OFFSET); in bcm_kp_start()
158 writel(kp->kpemr, kp->base + KPEMR0_OFFSET); in bcm_kp_start()
159 writel(kp->kpemr, kp->base + KPEMR1_OFFSET); in bcm_kp_start()
160 writel(kp->kpemr, kp->base + KPEMR2_OFFSET); in bcm_kp_start()
161 writel(kp->kpemr, kp->base + KPEMR3_OFFSET); in bcm_kp_start()
163 writel(0xFFFFFFFF, kp->base + KPICR0_OFFSET); in bcm_kp_start()
164 writel(0xFFFFFFFF, kp->base + KPICR1_OFFSET); in bcm_kp_start()
166 kp->last_state[0] = readl(kp->base + KPSSR0_OFFSET); in bcm_kp_start()
167 kp->last_state[0] = readl(kp->base + KPSSR1_OFFSET); in bcm_kp_start()
169 writel(kp->kpcr | KPCR_ENABLE, kp->base + KPCR_OFFSET); in bcm_kp_start()
174 static void bcm_kp_stop(const struct bcm_kp *kp) in bcm_kp_stop() argument
178 val = readl(kp->base + KPCR_OFFSET); in bcm_kp_stop()
180 writel(0, kp->base + KPCR_OFFSET); in bcm_kp_stop()
181 writel(0, kp->base + KPIMR0_OFFSET); in bcm_kp_stop()
182 writel(0, kp->base + KPIMR1_OFFSET); in bcm_kp_stop()
183 writel(0xFFFFFFFF, kp->base + KPICR0_OFFSET); in bcm_kp_stop()
184 writel(0xFFFFFFFF, kp->base + KPICR1_OFFSET); in bcm_kp_stop()
186 if (kp->clk) in bcm_kp_stop()
187 clk_disable_unprepare(kp->clk); in bcm_kp_stop()
192 struct bcm_kp *kp = input_get_drvdata(dev); in bcm_kp_open() local
194 return bcm_kp_start(kp); in bcm_kp_open()
199 struct bcm_kp *kp = input_get_drvdata(dev); in bcm_kp_close() local
201 bcm_kp_stop(kp); in bcm_kp_close()
204 static int bcm_kp_matrix_key_parse_dt(struct bcm_kp *kp) in bcm_kp_matrix_key_parse_dt() argument
206 struct device *dev = kp->input_dev->dev.parent; in bcm_kp_matrix_key_parse_dt()
214 kp->kpcr = KPCR_STATUSFILTERENABLE | KPCR_COLFILTERENABLE; in bcm_kp_matrix_key_parse_dt()
216 error = matrix_keypad_parse_properties(dev, &kp->n_rows, &kp->n_cols); in bcm_kp_matrix_key_parse_dt()
223 kp->kpcr |= (kp->n_rows - 1) << KPCR_ROWWIDTH_SHIFT; in bcm_kp_matrix_key_parse_dt()
226 kp->kpcr |= (kp->n_cols - 1) << KPCR_COLUMNWIDTH_SHIFT; in bcm_kp_matrix_key_parse_dt()
235 col_mask = (1 << (kp->n_cols)) - 1; in bcm_kp_matrix_key_parse_dt()
236 num_rows = kp->n_rows; in bcm_kp_matrix_key_parse_dt()
239 kp->imr0_val = col_mask; in bcm_kp_matrix_key_parse_dt()
243 kp->imr0_val |= kp->imr0_val << MAX_COLS; in bcm_kp_matrix_key_parse_dt()
246 kp->imr1_val = 0; in bcm_kp_matrix_key_parse_dt()
248 kp->imr1_val = col_mask; in bcm_kp_matrix_key_parse_dt()
250 kp->imr1_val |= kp->imr1_val << MAX_COLS; in bcm_kp_matrix_key_parse_dt()
255 kp->kpemr = 0; in bcm_kp_matrix_key_parse_dt()
257 kp->kpemr |= (KPEMR_EDGETYPE_BOTH << i); in bcm_kp_matrix_key_parse_dt()
271 kp->kpcr |= dt_val << KPCR_STATUSFILTERTYPE_SHIFT; in bcm_kp_matrix_key_parse_dt()
285 kp->kpcr |= dt_val << KPCR_COLFILTERTYPE_SHIFT; in bcm_kp_matrix_key_parse_dt()
296 kp->kpior = ((1 << kp->n_rows) - 1) << in bcm_kp_matrix_key_parse_dt()
299 kp->kpior = ((1 << kp->n_cols) - 1) << in bcm_kp_matrix_key_parse_dt()
307 kp->kpcr |= KPCR_MODE; in bcm_kp_matrix_key_parse_dt()
310 kp->n_rows, kp->n_cols, in bcm_kp_matrix_key_parse_dt()
311 kp->kpcr, kp->kpior, kp->kpemr); in bcm_kp_matrix_key_parse_dt()
319 struct bcm_kp *kp; in bcm_kp_probe() local
324 kp = devm_kzalloc(&pdev->dev, sizeof(*kp), GFP_KERNEL); in bcm_kp_probe()
325 if (!kp) in bcm_kp_probe()
351 input_set_drvdata(input_dev, kp); in bcm_kp_probe()
353 kp->input_dev = input_dev; in bcm_kp_probe()
355 error = bcm_kp_matrix_key_parse_dt(kp); in bcm_kp_probe()
360 kp->n_rows, kp->n_cols, in bcm_kp_probe()
374 kp->base = devm_ioremap_resource(&pdev->dev, res); in bcm_kp_probe()
375 if (IS_ERR(kp->base)) in bcm_kp_probe()
376 return PTR_ERR(kp->base); in bcm_kp_probe()
379 kp->clk = devm_clk_get(&pdev->dev, "peri_clk"); in bcm_kp_probe()
380 if (IS_ERR(kp->clk)) { in bcm_kp_probe()
381 error = PTR_ERR(kp->clk); in bcm_kp_probe()
389 kp->clk = NULL; in bcm_kp_probe()
399 actual_rate = clk_round_rate(kp->clk, desired_rate); in bcm_kp_probe()
403 error = clk_set_rate(kp->clk, actual_rate); in bcm_kp_probe()
407 error = clk_prepare_enable(kp->clk); in bcm_kp_probe()
413 bcm_kp_stop(kp); in bcm_kp_probe()
415 kp->irq = platform_get_irq(pdev, 0); in bcm_kp_probe()
416 if (kp->irq < 0) in bcm_kp_probe()
419 error = devm_request_threaded_irq(&pdev->dev, kp->irq, in bcm_kp_probe()
421 IRQF_ONESHOT, pdev->name, kp); in bcm_kp_probe()