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)  * LoCoMo keyboard driver for Linux-based ARM PDAs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * 	- SHARP Zaurus Collie (SL-5500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * 	- SHARP Zaurus Poodle (SL-5600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2005 John Lenz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Based on from xtkbd.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/hardware/locomo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) MODULE_DESCRIPTION("LoCoMo keyboard driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define LOCOMOKBD_NUMKEYS	128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define KEY_ACTIVITY		KEY_F16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define KEY_CONTACT		KEY_F18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define KEY_CENTER		KEY_F15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static const unsigned char
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0,				/* 0 - 9 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT,			/* 10 - 19 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,						/* 20 - 29 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	0, 0, 0, KEY_CENTER, 0, KEY_MAIL, 0, 0, 0, 0,				/* 30 - 39 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT,					/* 40 - 49 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T,		/* 50 - 59 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_ENTER, 0, 0,			/* 60 - 69 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0,	/* 70 - 79 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J,		/* 80 - 89 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0,				/* 90 - 99 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	0, 0, KEY_DOT, 0, KEY_COMMA, KEY_N, KEY_B, KEY_C, KEY_Z, KEY_A,		/* 100 - 109 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	KEY_LEFTSHIFT, KEY_TAB, KEY_LEFTCTRL, 0, 0, 0, 0, 0, 0, 0,		/* 110 - 119 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0		/* 120 - 128 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define KB_ROWS			16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define KB_COLS			8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define KB_ROWMASK(r)		(1 << (r))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define SCANCODE(c,r)		( ((c)<<4) + (r) + 1 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define KB_DELAY		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define SCAN_INTERVAL		(HZ/10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) struct locomokbd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	unsigned char keycode[LOCOMOKBD_NUMKEYS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	unsigned long base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	unsigned long suspend_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	unsigned int count_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) /* helper functions for reading the keyboard matrix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static inline void locomokbd_charge_all(unsigned long membase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	locomo_writel(0x00FF, membase + LOCOMO_KSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static inline void locomokbd_activate_all(unsigned long membase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned long r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	locomo_writel(0, membase + LOCOMO_KSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	r = locomo_readl(membase + LOCOMO_KIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	r &= 0xFEFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	locomo_writel(r, membase + LOCOMO_KIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static inline void locomokbd_activate_col(unsigned long membase, int col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	unsigned short nset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	unsigned short nbset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	nset = 0xFF & ~(1 << col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	nbset = (nset << 8) + nset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	locomo_writel(nbset, membase + LOCOMO_KSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static inline void locomokbd_reset_col(unsigned long membase, int col)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	unsigned short nbset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	locomo_writel(nbset, membase + LOCOMO_KSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^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)  * The LoCoMo keyboard only generates interrupts when a key is pressed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * So when a key is pressed, we enable a timer.  This timer scans the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * keyboard, and this is how we detect when the key is released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* Scan the hardware keyboard and push any changes up through the input layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	unsigned int row, col, rowd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unsigned int num_pressed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	unsigned long membase = locomokbd->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	spin_lock_irqsave(&locomokbd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	locomokbd_charge_all(membase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	num_pressed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	for (col = 0; col < KB_COLS; col++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		locomokbd_activate_col(membase, col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		udelay(KB_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		rowd = ~locomo_readl(membase + LOCOMO_KIB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		for (row = 0; row < KB_ROWS; row++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			unsigned int scancode, pressed, key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			scancode = SCANCODE(col, row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			pressed = rowd & KB_ROWMASK(row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			key = locomokbd->keycode[scancode];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			input_report_key(locomokbd->input, key, pressed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			if (likely(!pressed))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			num_pressed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			/* The "Cancel/ESC" key is labeled "On/Off" on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			 * Collie and Poodle and should suspend the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			 * if it was pressed for more than a second. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			if (unlikely(key == KEY_ESC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				if (!time_after(jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 					locomokbd->suspend_jiffies + HZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				if (locomokbd->count_cancel++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					!= (HZ/SCAN_INTERVAL + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				input_event(locomokbd->input, EV_PWR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					KEY_SUSPEND, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				locomokbd->suspend_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				locomokbd->count_cancel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		locomokbd_reset_col(membase, col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	locomokbd_activate_all(membase);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	input_sync(locomokbd->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	/* if any keys are pressed, enable the timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (num_pressed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		locomokbd->count_cancel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	spin_unlock_irqrestore(&locomokbd->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^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)  * LoCoMo keyboard interrupt handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static irqreturn_t locomokbd_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct locomokbd *locomokbd = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	u16 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	r = locomo_readl(locomokbd->base + LOCOMO_KIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if ((r & 0x0001) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	locomo_writel(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	/** wait chattering delay **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	udelay(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	locomokbd_scankeyboard(locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return IRQ_HANDLED;
^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)  * LoCoMo timer checking for released keys
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static void locomokbd_timer_callback(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct locomokbd *locomokbd = from_timer(locomokbd, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	locomokbd_scankeyboard(locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int locomokbd_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	struct locomokbd *locomokbd = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	u16 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	r = locomo_readl(locomokbd->base + LOCOMO_KIC) | 0x0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	locomo_writel(r, locomokbd->base + LOCOMO_KIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static void locomokbd_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct locomokbd *locomokbd = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	u16 r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	r = locomo_readl(locomokbd->base + LOCOMO_KIC) & ~0x0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	locomo_writel(r, locomokbd->base + LOCOMO_KIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int locomokbd_probe(struct locomo_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct locomokbd *locomokbd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (!locomokbd || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		goto err_free_mem;
^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) 	/* try and claim memory region */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (!request_mem_region((unsigned long) dev->mapbase,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				dev->length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				LOCOMO_DRIVER_NAME(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		goto err_free_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	locomo_set_drvdata(dev, locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	locomokbd->base = (unsigned long) dev->mapbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	spin_lock_init(&locomokbd->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	timer_setup(&locomokbd->timer, locomokbd_timer_callback, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	locomokbd->suspend_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	locomokbd->input = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	strcpy(locomokbd->phys, "locomokbd/input0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	input_dev->name = "LoCoMo keyboard";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	input_dev->phys = locomokbd->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	input_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	input_dev->id.vendor = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	input_dev->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	input_dev->open = locomokbd_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	input_dev->close = locomokbd_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	input_dev->dev.parent = &dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				BIT_MASK(EV_PWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	input_dev->keycode = locomokbd->keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	input_dev->keycodesize = sizeof(locomokbd_keycode[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	input_set_drvdata(input_dev, locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	for (i = 0; i < LOCOMOKBD_NUMKEYS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		set_bit(locomokbd->keycode[i], input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	clear_bit(0, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	/* attempt to get the interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		goto err_release_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	err = input_register_device(locomokbd->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		goto err_free_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  err_free_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	free_irq(dev->irq[0], locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  err_release_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	release_mem_region((unsigned long) dev->mapbase, dev->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	locomo_set_drvdata(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  err_free_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	kfree(locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static int locomokbd_remove(struct locomo_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct locomokbd *locomokbd = locomo_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	free_irq(dev->irq[0], locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	del_timer_sync(&locomokbd->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	input_unregister_device(locomokbd->input);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	locomo_set_drvdata(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	release_mem_region((unsigned long) dev->mapbase, dev->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	kfree(locomokbd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static struct locomo_driver keyboard_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	.drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		.name = "locomokbd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	.devid	= LOCOMO_DEVID_KEYBOARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	.probe	= locomokbd_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	.remove	= locomokbd_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static int __init locomokbd_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return locomo_driver_register(&keyboard_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void __exit locomokbd_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	locomo_driver_unregister(&keyboard_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) module_init(locomokbd_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) module_exit(locomokbd_exit);