Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * linux/drivers/input/keyboard/omap-keypad.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * OMAP Keypad Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2003 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Written by Timo Teräs <ext-timo.teras@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Added support for H2 & H3 Keypad
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (C) 2004 Texas Instruments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/types.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/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/platform_data/gpio-omap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/platform_data/keypad-omap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #undef NEW_BOARD_LEARNING_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static void omap_kp_tasklet(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static void omap_kp_timer(struct timer_list *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static unsigned char keypad_state[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static DEFINE_MUTEX(kp_enable_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int kp_enable = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int kp_cur_group = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) struct omap_kp {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned int rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned int cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	unsigned int debounce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	unsigned short keymap[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static DECLARE_TASKLET_DISABLED_OLD(kp_tasklet, omap_kp_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static unsigned int *row_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static unsigned int *col_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static irqreturn_t omap_kp_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* disable keyboard interrupt and schedule for handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	tasklet_schedule(&kp_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static void omap_kp_timer(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	tasklet_schedule(&kp_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static void omap_kp_scan_keypad(struct omap_kp *omap_kp, unsigned char *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	int col = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* disable keyboard interrupt and schedule for handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* read the keypad status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	omap_writew(0xff, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	for (col = 0; col < omap_kp->cols; col++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		omap_writew(~(1 << col) & 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			    OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		udelay(omap_kp->delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		state[col] = ~omap_readw(OMAP1_MPUIO_BASE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 					 OMAP_MPUIO_KBR_LATCH) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	omap_writew(0x00, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static void omap_kp_tasklet(unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct omap_kp *omap_kp_data = (struct omap_kp *) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	unsigned short *keycodes = omap_kp_data->input->keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned int row_shift = get_count_order(omap_kp_data->cols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	unsigned char new_state[8], changed, key_down = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	int col, row;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* check for any changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	omap_kp_scan_keypad(omap_kp_data, new_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	/* check for changes and print those */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	for (col = 0; col < omap_kp_data->cols; col++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		changed = new_state[col] ^ keypad_state[col];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		key_down |= new_state[col];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (changed == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		for (row = 0; row < omap_kp_data->rows; row++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			int key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			if (!(changed & (1 << row)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #ifdef NEW_BOARD_LEARNING_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			printk(KERN_INFO "omap-keypad: key %d-%d %s\n", col,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			       row, (new_state[col] & (1 << row)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			       "pressed" : "released");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			key = keycodes[MATRIX_SCAN_CODE(row, col, row_shift)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			if (!(kp_cur_group == (key & GROUP_MASK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			      kp_cur_group == -1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			kp_cur_group = key & GROUP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			input_report_key(omap_kp_data->input, key & ~GROUP_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 					 new_state[col] & (1 << row));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	input_sync(omap_kp_data->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	memcpy(keypad_state, new_state, sizeof(keypad_state));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (key_down) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		/* some key is pressed - keep irq disabled and use timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		 * to poll the keypad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		mod_timer(&omap_kp_data->timer, jiffies + HZ / 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		/* enable interrupts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		omap_writew(0, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		kp_cur_group = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static ssize_t omap_kp_enable_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				   struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return sprintf(buf, "%u\n", kp_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static ssize_t omap_kp_enable_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct omap_kp *omap_kp = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (sscanf(buf, "%u", &state) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if ((state != 1) && (state != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	mutex_lock(&kp_enable_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (state != kp_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		if (state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			enable_irq(omap_kp->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			disable_irq(omap_kp->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		kp_enable = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	mutex_unlock(&kp_enable_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return strnlen(buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, omap_kp_enable_show, omap_kp_enable_store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int omap_kp_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct omap_kp *omap_kp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct omap_kp_platform_data *pdata = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	int i, col_idx, row_idx, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	unsigned int row_shift, keycodemax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (!pdata->rows || !pdata->cols || !pdata->keymap_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		printk(KERN_ERR "No rows, cols or keymap_data from pdata\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	row_shift = get_count_order(pdata->cols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	keycodemax = pdata->rows << row_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	omap_kp = kzalloc(sizeof(struct omap_kp) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			keycodemax * sizeof(unsigned short), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (!omap_kp || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		kfree(omap_kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	platform_set_drvdata(pdev, omap_kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	omap_kp->input = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	/* Disable the interrupt for the MPUIO keyboard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (pdata->delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		omap_kp->delay = pdata->delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (pdata->row_gpios && pdata->col_gpios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		row_gpios = pdata->row_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		col_gpios = pdata->col_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	omap_kp->rows = pdata->rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	omap_kp->cols = pdata->cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	col_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	row_idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	timer_setup(&omap_kp->timer, omap_kp_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/* get the irq and init timer*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	kp_tasklet.data = (unsigned long) omap_kp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	tasklet_enable(&kp_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	ret = device_create_file(&pdev->dev, &dev_attr_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		goto err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/* setup input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	input_dev->name = "omap-keypad";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	input_dev->phys = "omap-keypad/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	input_dev->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	input_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	input_dev->id.vendor = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	input_dev->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (pdata->rep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		__set_bit(EV_REP, input_dev->evbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	ret = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 					 pdata->rows, pdata->cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 					 omap_kp->keymap, input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		goto err3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	ret = input_register_device(omap_kp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		printk(KERN_ERR "Unable to register omap-keypad input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		goto err3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (pdata->dbounce)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		omap_writew(0xff, OMAP1_MPUIO_BASE + OMAP_MPUIO_GPIO_DEBOUNCING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* scan current status and enable interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	omap_kp_scan_keypad(omap_kp, keypad_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	omap_kp->irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (omap_kp->irq >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		if (request_irq(omap_kp->irq, omap_kp_interrupt, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 				"omap-keypad", omap_kp) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			goto err4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	omap_writew(0, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) err4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	input_unregister_device(omap_kp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	input_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) err3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	device_remove_file(&pdev->dev, &dev_attr_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) err2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	for (i = row_idx - 1; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		gpio_free(row_gpios[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	for (i = col_idx - 1; i >= 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		gpio_free(col_gpios[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	kfree(omap_kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static int omap_kp_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct omap_kp *omap_kp = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/* disable keypad interrupt handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	tasklet_disable(&kp_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	omap_writew(1, OMAP1_MPUIO_BASE + OMAP_MPUIO_KBD_MASKIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	free_irq(omap_kp->irq, omap_kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	del_timer_sync(&omap_kp->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	tasklet_kill(&kp_tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/* unregister everything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	input_unregister_device(omap_kp->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	kfree(omap_kp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static struct platform_driver omap_kp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	.probe		= omap_kp_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	.remove		= omap_kp_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		.name	= "omap-keypad",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) module_platform_driver(omap_kp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) MODULE_AUTHOR("Timo Teräs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) MODULE_DESCRIPTION("OMAP Keypad Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) MODULE_ALIAS("platform:omap-keypad");