^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) ST-Ericsson SA 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Keypad controller driver for the SKE (Scroll Key Encoder) module used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * the Nomadik 8815 and Ux500 platforms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/platform_data/keypad-nomadik-ske.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* SKE_CR bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define SKE_KPMLT (0x1 << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define SKE_KPCN (0x7 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define SKE_KPASEN (0x1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SKE_KPASON (0x1 << 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* SKE_IMSC bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define SKE_KPIMA (0x1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* SKE_ICR bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define SKE_KPICS (0x1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define SKE_KPICA (0x1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* SKE_RIS bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define SKE_KPRISA (0x1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define SKE_KEYPAD_ROW_SHIFT 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define SKE_KPD_NUM_ROWS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define SKE_KPD_NUM_COLS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* keypad auto scan registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define SKE_ASR0 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define SKE_ASR1 0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define SKE_ASR2 0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define SKE_ASR3 0x2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define SKE_NUM_ASRX_REGISTERS (4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define KEY_PRESSED_DELAY 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * struct ske_keypad - data structure used by keypad driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * @irq: irq no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * @reg_base: ske registers base address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * @input: pointer to input device object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * @board: keypad platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * @keymap: matrix scan code table for keycodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * @clk: clock structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct ske_keypad {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void __iomem *reg_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) const struct ske_keypad_platform_data *board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned short keymap[SKE_KPD_NUM_ROWS * SKE_KPD_NUM_COLS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct clk *pclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) spinlock_t ske_keypad_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static void ske_keypad_set_bits(struct ske_keypad *keypad, u16 addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u8 mask, u8 data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u32 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) spin_lock(&keypad->ske_keypad_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = readl(keypad->reg_base + addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) ret &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ret |= data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) writel(ret, keypad->reg_base + addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) spin_unlock(&keypad->ske_keypad_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * ske_keypad_chip_init: init keypad controller configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Enable Multi key press detection, auto scan mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int __init ske_keypad_chip_init(struct ske_keypad *keypad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int timeout = keypad->board->debounce_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* check SKE_RIS to be 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) while ((readl(keypad->reg_base + SKE_RIS) != 0x00000000) && timeout--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (timeout == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * set debounce value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * keypad dbounce is configured in DBCR[15:8]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * dbounce value in steps of 32/32.768 ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) spin_lock(&keypad->ske_keypad_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) value = readl(keypad->reg_base + SKE_DBCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) value = value & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) value |= ((keypad->board->debounce_ms * 32000)/32768) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) writel(value, keypad->reg_base + SKE_DBCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) spin_unlock(&keypad->ske_keypad_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* enable multi key detection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPMLT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * set up the number of columns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * KPCN[5:3] defines no. of keypad columns to be auto scanned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) value = (keypad->board->kcol - 1) << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) ske_keypad_set_bits(keypad, SKE_CR, SKE_KPCN, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* clear keypad interrupt for auto(and pending SW) scans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA | SKE_KPICS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* un-mask keypad interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* enable automatic scan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ske_keypad_set_bits(keypad, SKE_CR, 0x0, SKE_KPASEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static void ske_keypad_report(struct ske_keypad *keypad, u8 status, int col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int row = 0, code, pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct input_dev *input = keypad->input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u32 ske_ris;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int key_pressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int num_of_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* find out the row */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) num_of_rows = hweight8(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) pos = __ffs(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) row = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) status &= ~(1 << pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) code = MATRIX_SCAN_CODE(row, col, SKE_KEYPAD_ROW_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ske_ris = readl(keypad->reg_base + SKE_RIS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) key_pressed = ske_ris & SKE_KPRISA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) input_event(input, EV_MSC, MSC_SCAN, code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) input_report_key(input, keypad->keymap[code], key_pressed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) input_sync(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) num_of_rows--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) } while (num_of_rows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void ske_keypad_read_data(struct ske_keypad *keypad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int col = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int ske_asr, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Read the auto scan registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * Each SKE_ASRx (x=0 to x=3) contains two row values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * lower byte contains row value for column 2*x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * upper byte contains row value for column 2*x + 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) for (i = 0; i < SKE_NUM_ASRX_REGISTERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ske_asr = readl(keypad->reg_base + SKE_ASR0 + (4 * i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!ske_asr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* now that ASRx is zero, find out the coloumn x and row y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) status = ske_asr & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) col = i * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ske_keypad_report(keypad, status, col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) status = (ske_asr & 0xff00) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) col = (i * 2) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) ske_keypad_report(keypad, status, col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static irqreturn_t ske_keypad_irq(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct ske_keypad *keypad = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int timeout = keypad->board->debounce_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* disable auto scan interrupt; mask the interrupt generated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ske_keypad_set_bits(keypad, SKE_ICR, 0x0, SKE_KPICA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) while ((readl(keypad->reg_base + SKE_CR) & SKE_KPASON) && --timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* SKEx registers are stable and can be read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ske_keypad_read_data(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* wait until raw interrupt is clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) while ((readl(keypad->reg_base + SKE_RIS)) && --timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) msleep(KEY_PRESSED_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* enable auto scan interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int __init ske_keypad_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) const struct ske_keypad_platform_data *plat =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct ske_keypad *keypad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!plat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) dev_err(&pdev->dev, "invalid keypad platform data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) dev_err(&pdev->dev, "missing platform resources\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) keypad = kzalloc(sizeof(struct ske_keypad), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) input = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!keypad || !input) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) dev_err(&pdev->dev, "failed to allocate keypad memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) keypad->irq = irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) keypad->board = plat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) keypad->input = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) spin_lock_init(&keypad->ske_keypad_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) dev_err(&pdev->dev, "failed to request I/O memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) error = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) keypad->reg_base = ioremap(res->start, resource_size(res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (!keypad->reg_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) dev_err(&pdev->dev, "failed to remap I/O memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) error = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) goto err_free_mem_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) keypad->pclk = clk_get(&pdev->dev, "apb_pclk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (IS_ERR(keypad->pclk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) dev_err(&pdev->dev, "failed to get pclk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) error = PTR_ERR(keypad->pclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) goto err_iounmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) keypad->clk = clk_get(&pdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (IS_ERR(keypad->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) dev_err(&pdev->dev, "failed to get clk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) error = PTR_ERR(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) goto err_pclk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) input->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) input->name = "ux500-ske-keypad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) input->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) error = matrix_keypad_build_keymap(plat->keymap_data, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) SKE_KPD_NUM_ROWS, SKE_KPD_NUM_COLS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) keypad->keymap, input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) dev_err(&pdev->dev, "Failed to build keymap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) goto err_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) input_set_capability(input, EV_MSC, MSC_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (!plat->no_autorepeat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) __set_bit(EV_REP, input->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) error = clk_prepare_enable(keypad->pclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) dev_err(&pdev->dev, "Failed to prepare/enable pclk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto err_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) error = clk_prepare_enable(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) dev_err(&pdev->dev, "Failed to prepare/enable clk\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) goto err_pclk_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* go through board initialization helpers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (keypad->board->init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) keypad->board->init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) error = ske_keypad_chip_init(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) dev_err(&pdev->dev, "unable to init keypad hardware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) goto err_clk_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) error = request_threaded_irq(keypad->irq, NULL, ske_keypad_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) IRQF_ONESHOT, "ske-keypad", keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) dev_err(&pdev->dev, "allocate irq %d failed\n", keypad->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) goto err_clk_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) error = input_register_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) "unable to register input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (plat->wakeup_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) device_init_wakeup(&pdev->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) platform_set_drvdata(pdev, keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) free_irq(keypad->irq, keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) err_clk_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) clk_disable_unprepare(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) err_pclk_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) clk_disable_unprepare(keypad->pclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) err_clk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) clk_put(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) err_pclk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) clk_put(keypad->pclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) err_iounmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) iounmap(keypad->reg_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) err_free_mem_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) release_mem_region(res->start, resource_size(res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) input_free_device(input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) kfree(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static int ske_keypad_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct ske_keypad *keypad = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) free_irq(keypad->irq, keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) input_unregister_device(keypad->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) clk_disable_unprepare(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) clk_put(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (keypad->board->exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) keypad->board->exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) iounmap(keypad->reg_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) release_mem_region(res->start, resource_size(res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) kfree(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static int ske_keypad_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct ske_keypad *keypad = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) enable_irq_wake(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) ske_keypad_set_bits(keypad, SKE_IMSC, ~SKE_KPIMA, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int ske_keypad_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct ske_keypad *keypad = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) int irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) disable_irq_wake(irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ske_keypad_set_bits(keypad, SKE_IMSC, 0x0, SKE_KPIMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static SIMPLE_DEV_PM_OPS(ske_keypad_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ske_keypad_suspend, ske_keypad_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static struct platform_driver ske_keypad_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .name = "nmk-ske-keypad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .pm = &ske_keypad_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) .remove = ske_keypad_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) module_platform_driver_probe(ske_keypad_driver, ske_keypad_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) MODULE_AUTHOR("Naveen Kumar <naveen.gaddipati@stericsson.com> / Sundar Iyer <sundar.iyer@stericsson.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) MODULE_DESCRIPTION("Nomadik Scroll-Key-Encoder Keypad Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) MODULE_ALIAS("platform:nomadik-ske-keypad");