aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard/newtonkbd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/keyboard/newtonkbd.c')
-rw-r--r--drivers/input/keyboard/newtonkbd.c83
1 files changed, 39 insertions, 44 deletions
diff --git a/drivers/input/keyboard/newtonkbd.c b/drivers/input/keyboard/newtonkbd.c
index 2e8ce1613eec..d10983c521e6 100644
--- a/drivers/input/keyboard/newtonkbd.c
+++ b/drivers/input/keyboard/newtonkbd.c
@@ -57,11 +57,9 @@ static unsigned char nkbd_keycode[128] = {
57 KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0 57 KEY_LEFT, KEY_RIGHT, KEY_DOWN, KEY_UP, 0
58}; 58};
59 59
60static char *nkbd_name = "Newton Keyboard";
61
62struct nkbd { 60struct nkbd {
63 unsigned char keycode[128]; 61 unsigned char keycode[128];
64 struct input_dev dev; 62 struct input_dev *dev;
65 struct serio *serio; 63 struct serio *serio;
66 char phys[32]; 64 char phys[32];
67}; 65};
@@ -73,13 +71,13 @@ static irqreturn_t nkbd_interrupt(struct serio *serio,
73 71
74 /* invalid scan codes are probably the init sequence, so we ignore them */ 72 /* invalid scan codes are probably the init sequence, so we ignore them */
75 if (nkbd->keycode[data & NKBD_KEY]) { 73 if (nkbd->keycode[data & NKBD_KEY]) {
76 input_regs(&nkbd->dev, regs); 74 input_regs(nkbd->dev, regs);
77 input_report_key(&nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS); 75 input_report_key(nkbd->dev, nkbd->keycode[data & NKBD_KEY], data & NKBD_PRESS);
78 input_sync(&nkbd->dev); 76 input_sync(nkbd->dev);
79 } 77 }
80 78
81 else if (data == 0xe7) /* end of init sequence */ 79 else if (data == 0xe7) /* end of init sequence */
82 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys); 80 printk(KERN_INFO "input: %s on %s\n", nkbd->dev->name, serio->phys);
83 return IRQ_HANDLED; 81 return IRQ_HANDLED;
84 82
85} 83}
@@ -87,62 +85,59 @@ static irqreturn_t nkbd_interrupt(struct serio *serio,
87static int nkbd_connect(struct serio *serio, struct serio_driver *drv) 85static int nkbd_connect(struct serio *serio, struct serio_driver *drv)
88{ 86{
89 struct nkbd *nkbd; 87 struct nkbd *nkbd;
88 struct input_dev *input_dev;
89 int err = -ENOMEM;
90 int i; 90 int i;
91 int err;
92
93 if (!(nkbd = kmalloc(sizeof(struct nkbd), GFP_KERNEL)))
94 return -ENOMEM;
95
96 memset(nkbd, 0, sizeof(struct nkbd));
97 91
98 nkbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 92 nkbd = kzalloc(sizeof(struct nkbd), GFP_KERNEL);
93 input_dev = input_allocate_device();
94 if (!nkbd || !input_dev)
95 goto fail;
99 96
100 nkbd->serio = serio; 97 nkbd->serio = serio;
98 nkbd->dev = input_dev;
99 sprintf(nkbd->phys, "%s/input0", serio->phys);
100 memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode));
101 101
102 init_input_dev(&nkbd->dev); 102 input_dev->name = "Newton Keyboard";
103 nkbd->dev.keycode = nkbd->keycode; 103 input_dev->phys = nkbd->phys;
104 nkbd->dev.keycodesize = sizeof(unsigned char); 104 input_dev->id.bustype = BUS_RS232;
105 nkbd->dev.keycodemax = ARRAY_SIZE(nkbd_keycode); 105 input_dev->id.vendor = SERIO_NEWTON;
106 nkbd->dev.private = nkbd; 106 input_dev->id.product = 0x0001;
107 input_dev->id.version = 0x0100;
108 input_dev->cdev.dev = &serio->dev;
109 input_dev->private = nkbd;
110
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 input_dev->keycode = nkbd->keycode;
113 input_dev->keycodesize = sizeof(unsigned char);
114 input_dev->keycodemax = ARRAY_SIZE(nkbd_keycode);
115 for (i = 0; i < 128; i++)
116 set_bit(nkbd->keycode[i], input_dev->keybit);
117 clear_bit(0, input_dev->keybit);
107 118
108 serio_set_drvdata(serio, nkbd); 119 serio_set_drvdata(serio, nkbd);
109 120
110 err = serio_open(serio, drv); 121 err = serio_open(serio, drv);
111 if (err) { 122 if (err)
112 serio_set_drvdata(serio, NULL); 123 goto fail;
113 kfree(nkbd);
114 return err;
115 }
116
117 memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode));
118 for (i = 0; i < 128; i++)
119 set_bit(nkbd->keycode[i], nkbd->dev.keybit);
120 clear_bit(0, nkbd->dev.keybit);
121
122 sprintf(nkbd->phys, "%s/input0", serio->phys);
123
124 nkbd->dev.name = nkbd_name;
125 nkbd->dev.phys = nkbd->phys;
126 nkbd->dev.id.bustype = BUS_RS232;
127 nkbd->dev.id.vendor = SERIO_NEWTON;
128 nkbd->dev.id.product = 0x0001;
129 nkbd->dev.id.version = 0x0100;
130 nkbd->dev.dev = &serio->dev;
131
132 input_register_device(&nkbd->dev);
133
134 printk(KERN_INFO "input: %s on %s\n", nkbd_name, serio->phys);
135 124
125 input_register_device(nkbd->dev);
136 return 0; 126 return 0;
127
128 fail: serio_set_drvdata(serio, NULL);
129 input_free_device(input_dev);
130 kfree(nkbd);
131 return err;
137} 132}
138 133
139static void nkbd_disconnect(struct serio *serio) 134static void nkbd_disconnect(struct serio *serio)
140{ 135{
141 struct nkbd *nkbd = serio_get_drvdata(serio); 136 struct nkbd *nkbd = serio_get_drvdata(serio);
142 137
143 input_unregister_device(&nkbd->dev);
144 serio_close(serio); 138 serio_close(serio);
145 serio_set_drvdata(serio, NULL); 139 serio_set_drvdata(serio, NULL);
140 input_unregister_device(nkbd->dev);
146 kfree(nkbd); 141 kfree(nkbd);
147} 142}
148 143