diff options
Diffstat (limited to 'drivers/input')
39 files changed, 1887 insertions, 831 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index a1e660e3531..745979f33dc 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -146,6 +146,7 @@ static int evdev_open(struct inode * inode, struct file * file) } #ifdef CONFIG_COMPAT + struct input_event_compat { struct compat_timeval time; __u16 type; @@ -153,10 +154,12 @@ struct input_event_compat { __s32 value; }; +/* Note to the author of this code: did it ever occur to + you why the ifdefs are needed? Think about it again. -AK */ #ifdef CONFIG_X86_64 -# define COMPAT_TEST test_thread_flag(TIF_IA32) +# define COMPAT_TEST is_compat_task() #elif defined(CONFIG_IA64) -# define COMPAT_TEST IS_IA32_PROCESS(ia64_task_regs(current)) +# define COMPAT_TEST IS_IA32_PROCESS(task_pt_regs(current)) #elif defined(CONFIG_S390) # define COMPAT_TEST test_thread_flag(TIF_31BIT) #elif defined(CONFIG_MIPS) @@ -165,98 +168,107 @@ struct input_event_compat { # define COMPAT_TEST test_thread_flag(TIF_32BIT) #endif -static ssize_t evdev_write_compat(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) +static inline size_t evdev_event_size(void) { - struct evdev_list *list = file->private_data; - struct input_event_compat event; - int retval = 0; + return COMPAT_TEST ? + sizeof(struct input_event_compat) : sizeof(struct input_event); +} - while (retval < count) { - if (copy_from_user(&event, buffer + retval, sizeof(struct input_event_compat))) +static int evdev_event_from_user(const char __user *buffer, struct input_event *event) +{ + if (COMPAT_TEST) { + struct input_event_compat compat_event; + + if (copy_from_user(&compat_event, buffer, sizeof(struct input_event_compat))) + return -EFAULT; + + event->time.tv_sec = compat_event.time.tv_sec; + event->time.tv_usec = compat_event.time.tv_usec; + event->type = compat_event.type; + event->code = compat_event.code; + event->value = compat_event.value; + + } else { + if (copy_from_user(event, buffer, sizeof(struct input_event))) return -EFAULT; - input_event(list->evdev->handle.dev, event.type, event.code, event.value); - retval += sizeof(struct input_event_compat); } - return retval; + return 0; } -#endif -static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) +static int evdev_event_to_user(char __user *buffer, const struct input_event *event) { - struct evdev_list *list = file->private_data; - struct input_event event; - int retval = 0; - - if (!list->evdev->exist) return -ENODEV; + if (COMPAT_TEST) { + struct input_event_compat compat_event; -#ifdef CONFIG_COMPAT - if (COMPAT_TEST) - return evdev_write_compat(file, buffer, count, ppos); -#endif + compat_event.time.tv_sec = event->time.tv_sec; + compat_event.time.tv_usec = event->time.tv_usec; + compat_event.type = event->type; + compat_event.code = event->code; + compat_event.value = event->value; - while (retval < count) { + if (copy_to_user(buffer, &compat_event, sizeof(struct input_event_compat))) + return -EFAULT; - if (copy_from_user(&event, buffer + retval, sizeof(struct input_event))) + } else { + if (copy_to_user(buffer, event, sizeof(struct input_event))) return -EFAULT; - input_event(list->evdev->handle.dev, event.type, event.code, event.value); - retval += sizeof(struct input_event); } - return retval; + return 0; } -#ifdef CONFIG_COMPAT -static ssize_t evdev_read_compat(struct file * file, char __user * buffer, size_t count, loff_t *ppos) +#else + +static inline size_t evdev_event_size(void) { - struct evdev_list *list = file->private_data; - int retval; + return sizeof(struct input_event); +} - if (count < sizeof(struct input_event_compat)) - return -EINVAL; +static int evdev_event_from_user(const char __user *buffer, struct input_event *event) +{ + if (copy_from_user(event, buffer, sizeof(struct input_event))) + return -EFAULT; - if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK)) - return -EAGAIN; + return 0; +} - retval = wait_event_interruptible(list->evdev->wait, - list->head != list->tail || (!list->evdev->exist)); +static int evdev_event_to_user(char __user *buffer, const struct input_event *event) +{ + if (copy_to_user(buffer, event, sizeof(struct input_event))) + return -EFAULT; - if (retval) - return retval; + return 0; +} + +#endif /* CONFIG_COMPAT */ + +static ssize_t evdev_write(struct file * file, const char __user * buffer, size_t count, loff_t *ppos) +{ + struct evdev_list *list = file->private_data; + struct input_event event; + int retval = 0; if (!list->evdev->exist) return -ENODEV; - while (list->head != list->tail && retval + sizeof(struct input_event_compat) <= count) { - struct input_event *event = (struct input_event *) list->buffer + list->tail; - struct input_event_compat event_compat; - event_compat.time.tv_sec = event->time.tv_sec; - event_compat.time.tv_usec = event->time.tv_usec; - event_compat.type = event->type; - event_compat.code = event->code; - event_compat.value = event->value; - - if (copy_to_user(buffer + retval, &event_compat, - sizeof(struct input_event_compat))) return -EFAULT; - list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1); - retval += sizeof(struct input_event_compat); + while (retval < count) { + + if (evdev_event_from_user(buffer + retval, &event)) + return -EFAULT; + input_event(list->evdev->handle.dev, event.type, event.code, event.value); + retval += evdev_event_size(); } return retval; } -#endif static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count, loff_t *ppos) { struct evdev_list *list = file->private_data; int retval; -#ifdef CONFIG_COMPAT - if (COMPAT_TEST) - return evdev_read_compat(file, buffer, count, ppos); -#endif - - if (count < sizeof(struct input_event)) + if (count < evdev_event_size()) return -EINVAL; if (list->head == list->tail && list->evdev->exist && (file->f_flags & O_NONBLOCK)) @@ -271,11 +283,15 @@ static ssize_t evdev_read(struct file * file, char __user * buffer, size_t count if (!list->evdev->exist) return -ENODEV; - while (list->head != list->tail && retval + sizeof(struct input_event) <= count) { - if (copy_to_user(buffer + retval, list->buffer + list->tail, - sizeof(struct input_event))) return -EFAULT; + while (list->head != list->tail && retval + evdev_event_size() <= count) { + + struct input_event *event = (struct input_event *) list->buffer + list->tail; + + if (evdev_event_to_user(buffer + retval, event)) + return -EFAULT; + list->tail = (list->tail + 1) & (EVDEV_BUFFER_SIZE - 1); - retval += sizeof(struct input_event); + retval += evdev_event_size(); } return retval; @@ -290,17 +306,95 @@ static unsigned int evdev_poll(struct file *file, poll_table *wait) (list->evdev->exist ? 0 : (POLLHUP | POLLERR)); } -static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +#ifdef CONFIG_COMPAT + +#define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8) +#define NBITS_COMPAT(x) ((((x) - 1) / BITS_PER_LONG_COMPAT) + 1) + +#ifdef __BIG_ENDIAN +static int bits_to_user(unsigned long *bits, unsigned int maxbit, + unsigned int maxlen, void __user *p, int compat) +{ + int len, i; + + if (compat) { + len = NBITS_COMPAT(maxbit) * sizeof(compat_long_t); + if (len < maxlen) + len = maxlen; + + for (i = 0; i < len / sizeof(compat_long_t); i++) + if (copy_to_user((compat_long_t __user *) p + i, + (compat_long_t *) bits + + i + 1 - ((i % 2) << 1), + sizeof(compat_long_t))) + return -EFAULT; + } else { + len = NBITS(maxbit) * sizeof(long); + if (len > maxlen) + len = maxlen; + + if (copy_to_user(p, bits, len)) + return -EFAULT; + } + + return len; +} +#else +static int bits_to_user(unsigned long *bits, unsigned int maxbit, + unsigned int maxlen, void __user *p, int compat) +{ + int len = compat ? + NBITS_COMPAT(maxbit) * sizeof(compat_long_t) : + NBITS(maxbit) * sizeof(long); + + if (len > maxlen) + len = maxlen; + + return copy_to_user(p, bits, len) ? -EFAULT : len; +} +#endif /* __BIG_ENDIAN */ + +#else + +static int bits_to_user(unsigned long *bits, unsigned int maxbit, + unsigned int maxlen, void __user *p, int compat) +{ + int len = NBITS(maxbit) * sizeof(long); + + if (len > maxlen) + len = maxlen; + + return copy_to_user(p, bits, len) ? -EFAULT : len; +} + +#endif /* CONFIG_COMPAT */ + +static int str_to_user(const char *str, unsigned int maxlen, void __user *p) +{ + int len; + + if (!str) + return -ENOENT; + + len = strlen(str) + 1; + if (len > maxlen) + len = maxlen; + + return copy_to_user(p, str, len) ? -EFAULT : len; +} + +static long evdev_ioctl_handler(struct file *file, unsigned int cmd, + void __user *p, int compat_mode) { struct evdev_list *list = file->private_data; struct evdev *evdev = list->evdev; struct input_dev *dev = evdev->handle.dev; struct input_absinfo abs; - void __user *p = (void __user *)arg; - int __user *ip = (int __user *)arg; + int __user *ip = (int __user *)p; int i, t, u, v; - if (!evdev->exist) return -ENODEV; + if (!evdev->exist) + return -ENODEV; switch (cmd) { @@ -308,26 +402,39 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return put_user(EV_VERSION, ip); case EVIOCGID: - return copy_to_user(p, &dev->id, sizeof(struct input_id)) ? -EFAULT : 0; + if (copy_to_user(p, &dev->id, sizeof(struct input_id))) + return -EFAULT; + + return 0; case EVIOCGKEYCODE: - if (get_user(t, ip)) return -EFAULT; - if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) return -EINVAL; - if (put_user(INPUT_KEYCODE(dev, t), ip + 1)) return -EFAULT; + if (get_user(t, ip)) + return -EFAULT; + if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) + return -EINVAL; + if (put_user(INPUT_KEYCODE(dev, t), ip + 1)) + return -EFAULT; return 0; case EVIOCSKEYCODE: - if (get_user(t, ip)) return -EFAULT; - if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) return -EINVAL; - if (get_user(v, ip + 1)) return -EFAULT; - if (v < 0 || v > KEY_MAX) return -EINVAL; - if (dev->keycodesize < sizeof(v) && (v >> (dev->keycodesize * 8))) return -EINVAL; + if (get_user(t, ip)) + return -EFAULT; + if (t < 0 || t >= dev->keycodemax || !dev->keycodesize) + return -EINVAL; + if (get_user(v, ip + 1)) + return -EFAULT; + if (v < 0 || v > KEY_MAX) + return -EINVAL; + if (dev->keycodesize < sizeof(v) && (v >> (dev->keycodesize * 8))) + return -EINVAL; + u = SET_INPUT_KEYCODE(dev, t, v); clear_bit(u, dev->keybit); set_bit(v, dev->keybit); for (i = 0; i < dev->keycodemax; i++) - if (INPUT_KEYCODE(dev,i) == u) + if (INPUT_KEYCODE(dev, i) == u) set_bit(u, dev->keybit); + return 0; case EVIOCSFF: @@ -338,17 +445,17 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (copy_from_user(&effect, p, sizeof(effect))) return -EFAULT; err = dev->upload_effect(dev, &effect); - if (put_user(effect.id, &(((struct ff_effect __user *)arg)->id))) + if (put_user(effect.id, &(((struct ff_effect __user *)p)->id))) return -EFAULT; return err; - } - else return -ENOSYS; + } else + return -ENOSYS; case EVIOCRMFF: - if (dev->erase_effect) { - return dev->erase_effect(dev, (int)arg); - } - else return -ENOSYS; + if (!dev->erase_effect) + return -ENOSYS; + + return dev->erase_effect(dev, (int)(unsigned long) p); case EVIOCGEFFECTS: if (put_user(dev->ff_effects_max, ip)) @@ -356,7 +463,7 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return 0; case EVIOCGRAB: - if (arg) { + if (p) { if (evdev->grab) return -EBUSY; if (input_grab_device(&evdev->handle)) @@ -395,62 +502,33 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case EV_SW: bits = dev->swbit; len = SW_MAX; break; default: return -EINVAL; } - len = NBITS(len) * sizeof(long); - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, bits, len) ? -EFAULT : len; + return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode); } - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) { - int len; - len = NBITS(KEY_MAX) * sizeof(long); - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->key, len) ? -EFAULT : len; - } + if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) + return bits_to_user(dev->key, KEY_MAX, _IOC_SIZE(cmd), + p, compat_mode); - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) { - int len; - len = NBITS(LED_MAX) * sizeof(long); - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->led, len) ? -EFAULT : len; - } + if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) + return bits_to_user(dev->led, LED_MAX, _IOC_SIZE(cmd), + p, compat_mode); - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) { - int len; - len = NBITS(SND_MAX) * sizeof(long); - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->snd, len) ? -EFAULT : len; - } + if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) + return bits_to_user(dev->snd, SND_MAX, _IOC_SIZE(cmd), + p, compat_mode); - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) { - int len; - len = NBITS(SW_MAX) * sizeof(long); - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->sw, len) ? -EFAULT : len; - } + if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) + return bits_to_user(dev->sw, SW_MAX, _IOC_SIZE(cmd), + p, compat_mode); - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) { - int len; - if (!dev->name) return -ENOENT; - len = strlen(dev->name) + 1; - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->name, len) ? -EFAULT : len; - } + if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) + return str_to_user(dev->name, _IOC_SIZE(cmd), p); - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) { - int len; - if (!dev->phys) return -ENOENT; - len = strlen(dev->phys) + 1; - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->phys, len) ? -EFAULT : len; - } + if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) + return str_to_user(dev->phys, _IOC_SIZE(cmd), p); - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) { - int len; - if (!dev->uniq) return -ENOENT; - len = strlen(dev->uniq) + 1; - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->uniq, len) ? -EFAULT : len; - } + if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) + return str_to_user(dev->uniq, _IOC_SIZE(cmd), p); if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { @@ -492,158 +570,15 @@ static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return -EINVAL; } -#ifdef CONFIG_COMPAT - -#define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8) -#define NBITS_COMPAT(x) ((((x)-1)/BITS_PER_LONG_COMPAT)+1) -#define OFF_COMPAT(x) ((x)%BITS_PER_LONG_COMPAT) -#define BIT_COMPAT(x) (1UL<<OFF_COMPAT(x)) -#define LONG_COMPAT(x) ((x)/BITS_PER_LONG_COMPAT) -#define test_bit_compat(bit, array) ((array[LONG_COMPAT(bit)] >> OFF_COMPAT(bit)) & 1) - -#ifdef __BIG_ENDIAN -#define bit_to_user(bit, max) \ -do { \ - int i; \ - int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \ - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \ - for (i = 0; i < len / sizeof(compat_long_t); i++) \ - if (copy_to_user((compat_long_t __user *) p + i, \ - (compat_long_t*) (bit) + i + 1 - ((i % 2) << 1), \ - sizeof(compat_long_t))) \ - return -EFAULT; \ - return len; \ -} while (0) -#else -#define bit_to_user(bit, max) \ -do { \ - int len = NBITS_COMPAT((max)) * sizeof(compat_long_t); \ - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); \ - return copy_to_user(p, (bit), len) ? -EFAULT : len; \ -} while (0) -#endif +static long evdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + return evdev_ioctl_handler(file, cmd, (void __user *)arg, 0); +} +#ifdef CONFIG_COMPAT static long evdev_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { - struct evdev_list *list = file->private_data; - struct evdev *evdev = list->evdev; - struct input_dev *dev = evdev->handle.dev; - struct input_absinfo abs; - void __user *p = compat_ptr(arg); - - if (!evdev->exist) return -ENODEV; - - switch (cmd) { - - case EVIOCGVERSION: - case EVIOCGID: - case EVIOCGKEYCODE: - case EVIOCSKEYCODE: - case EVIOCSFF: - case EVIOCRMFF: - case EVIOCGEFFECTS: - case EVIOCGRAB: - return evdev_ioctl(file, cmd, (unsigned long) p); - - default: - - if (_IOC_TYPE(cmd) != 'E') - return -EINVAL; - - if (_IOC_DIR(cmd) == _IOC_READ) { - - if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0,0))) { - long *bits; - int max; - - switch (_IOC_NR(cmd) & EV_MAX) { - case 0: bits = dev->evbit; max = EV_MAX; break; - case EV_KEY: bits = dev->keybit; max = KEY_MAX; break; - case EV_REL: bits = dev->relbit; max = REL_MAX; break; - case EV_ABS: bits = dev->absbit; max = ABS_MAX; break; - case EV_MSC: bits = dev->mscbit; max = MSC_MAX; break; - case EV_LED: bits = dev->ledbit; max = LED_MAX; break; - case EV_SND: bits = dev->sndbit; max = SND_MAX; break; - case EV_FF: bits = dev->ffbit; max = FF_MAX; break; - case EV_SW: bits = dev->swbit; max = SW_MAX; break; - default: return -EINVAL; - } - bit_to_user(bits, max); - } - - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) - bit_to_user(dev->key, KEY_MAX); - - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) - bit_to_user(dev->led, LED_MAX); - - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) - bit_to_user(dev->snd, SND_MAX); - - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) - bit_to_user(dev->sw, SW_MAX); - - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) { - int len; - if (!dev->name) return -ENOENT; - len = strlen(dev->name) + 1; - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->name, len) ? -EFAULT : len; - } - - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) { - int len; - if (!dev->phys) return -ENOENT; - len = strlen(dev->phys) + 1; - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->phys, len) ? -EFAULT : len; - } - - if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) { - int len; - if (!dev->uniq) return -ENOENT; - len = strlen(dev->uniq) + 1; - if (len > _IOC_SIZE(cmd)) len = _IOC_SIZE(cmd); - return copy_to_user(p, dev->uniq, len) ? -EFAULT : len; - } - - if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { - - int t = _IOC_NR(cmd) & ABS_MAX; - - abs.value = dev->abs[t]; - abs.minimum = dev->absmin[t]; - abs.maximum = dev->absmax[t]; - abs.fuzz = dev->absfuzz[t]; - abs.flat = dev->absflat[t]; - - if (copy_to_user(p, &abs, sizeof(struct input_absinfo))) - return -EFAULT; - - return 0; - } - } - - if (_IOC_DIR(cmd) == _IOC_WRITE) { - - if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { - - int t = _IOC_NR(cmd) & ABS_MAX; - - if (copy_from_user(&abs, p, sizeof(struct input_absinfo))) - return -EFAULT; - - dev->abs[t] = abs.value; - dev->absmin[t] = abs.minimum; - dev->absmax[t] = abs.maximum; - dev->absfuzz[t] = abs.fuzz; - dev->absflat[t] = abs.flat; - - return 0; - } - } - } - return -EINVAL; + return evdev_ioctl_handler(file, cmd, compat_ptr(arg), 1); } #endif diff --git a/drivers/input/gameport/Kconfig b/drivers/input/gameport/Kconfig index 7524bd7d8b8..d279454a5c9 100644 --- a/drivers/input/gameport/Kconfig +++ b/drivers/input/gameport/Kconfig @@ -52,5 +52,12 @@ config GAMEPORT_EMU10K1 config GAMEPORT_FM801 tristate "ForteMedia FM801 gameport support" depends on PCI + help + Say Y here if you have ForteMedia FM801 PCI audio controller + (Abit AU10, Genius Sound Maker, HP Workstation zx2000, + and others), and want to use its gameport. + + To compile this driver as a module, choose M here: the + module will be called fm801-gp. endif diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c index caac6d63d46..b765a155c00 100644 --- a/drivers/input/gameport/gameport.c +++ b/drivers/input/gameport/gameport.c @@ -50,9 +50,7 @@ static DECLARE_MUTEX(gameport_sem); static LIST_HEAD(gameport_list); -static struct bus_type gameport_bus = { - .name = "gameport", -}; +static struct bus_type gameport_bus; static void gameport_add_port(struct gameport *gameport); static void gameport_destroy_port(struct gameport *gameport); @@ -703,11 +701,15 @@ static int gameport_driver_remove(struct device *dev) return 0; } +static struct bus_type gameport_bus = { + .name = "gameport", + .probe = gameport_driver_probe, + .remove = gameport_driver_remove, +}; + void __gameport_register_driver(struct gameport_driver *drv, struct module *owner) { drv->driver.bus = &gameport_bus; - drv->driver.probe = gameport_driver_probe; - drv->driver.remove = gameport_driver_remove; gameport_queue_event(drv, owner, GAMEPORT_REGISTER_DRIVER); } diff --git a/drivers/input/input.c b/drivers/input/input.c index ef5824c8846..4fe3da3c667 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -477,8 +477,8 @@ static int __init input_proc_init(void) entry->owner = THIS_MODULE; input_fileops = *entry->proc_fops; + input_fileops.poll = input_devices_poll; entry->proc_fops = &input_fileops; - entry->proc_fops->poll = input_devices_poll; entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL); if (!entry) @@ -528,40 +528,56 @@ INPUT_DEV_STRING_ATTR_SHOW(name); INPUT_DEV_STRING_ATTR_SHOW(phys); INPUT_DEV_STRING_ATTR_SHOW(uniq); -static int print_modalias_bits(char *buf, char prefix, unsigned long *arr, +static int print_modalias_bits(char *buf, int size, char prefix, unsigned long *arr, unsigned int min, unsigned int max) { int len, i; - len = sprintf(buf, "%c", prefix); + len = snprintf(buf, size, "%c", prefix); for (i = min; i < max; i++) if (arr[LONG(i)] & BIT(i)) - len += sprintf(buf+len, "%X,", i); + len += snprintf(buf + len, size - len, "%X,", i); return len; } -static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf) +static int print_modalias(char *buf, int size, struct input_dev *id) { - struct input_dev *id = to_input_dev(dev); - ssize_t len = 0; + int len; - len += sprintf(buf+len, "input:b%04Xv%04Xp%04Xe%04X-", + len = snprintf(buf, size, "input:b%04Xv%04Xp%04Xe%04X-", id->id.bustype, id->id.vendor, id->id.product, id->id.version); - len += print_modalias_bits(buf+len, 'e', id->evbit, 0, EV_MAX); - len += print_modalias_bits(buf+len, 'k', id->keybit, + len += print_modalias_bits(buf + len, size - len, 'e', id->evbit, + 0, EV_MAX); + len += print_modalias_bits(buf + len, size - len, 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX); - len += print_modalias_bits(buf+len, 'r', id->relbit, 0, REL_MAX); - len += print_modalias_bits(buf+len, 'a', id->absbit, 0, ABS_MAX); - len += print_modalias_bits(buf+len, 'm', id->mscbit, 0, MSC_MAX); - len += print_modalias_bits(buf+len, 'l', id->ledbit, 0, LED_MAX); - len += print_modalias_bits(buf+len, 's', id->sndbit, 0, SND_MAX); - len += print_modalias_bits(buf+len, 'f', id->ffbit, 0, FF_MAX); - len += print_modalias_bits(buf+len, 'w', id->swbit, 0, SW_MAX); - len += sprintf(buf+len, "\n"); + len += print_modalias_bits(buf + len, size - len, 'r', id->relbit, + 0, REL_MAX); + len += print_modalias_bits(buf + len, size - len, 'a', id->absbit, + 0, ABS_MAX); + len += print_modalias_bits(buf + len, size - len, 'm', id->mscbit, + 0, MSC_MAX); + len += print_modalias_bits(buf + len, size - len, 'l', id->ledbit, + 0, LED_MAX); + len += print_modalias_bits(buf + len, size - len, 's', id->sndbit, + 0, SND_MAX); + len += print_modalias_bits(buf + len, size - len, 'f', id->ffbit, + 0, FF_MAX); + len += print_modalias_bits(buf + len, size - len, 'w', id->swbit, + 0, SW_MAX); + return len; +} + +static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf) +{ + struct input_dev *id = to_input_dev(dev); + ssize_t len; + + len = print_modalias(buf, PAGE_SIZE, id); + len += snprintf(buf + len, PAGE_SIZE-len, "\n"); return len; } static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL); @@ -728,8 +744,11 @@ static int input_dev_uevent(struct class_device *cdev, char **envp, if (test_bit(EV_SW, dev->evbit)) INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); - envp[i] = NULL; + envp[i++] = buffer + len; + len += snprintf(buffer + len, buffer_size - len, "MODALIAS="); + len += print_modalias(buffer + len, buffer_size - len, dev) + 1; + envp[i] = NULL; return 0; } diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c index 8558a99f663..ec55a29fc86 100644 --- a/drivers/input/joystick/amijoy.c +++ b/drivers/input/joystick/amijoy.c @@ -64,8 +64,8 @@ static irqreturn_t amijoy_interrupt(int irq, void *dummy, struct pt_regs *fp) if (amijoy[i]) { switch (i) { - case 0: data = ~custom.joy0dat; button = (~ciaa.pra >> 6) & 1; break; - case 1: data = ~custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break; + case 0: data = ~amiga_custom.joy0dat; button = (~ciaa.pra >> 6) & 1; break; + case 1: data = ~amiga_custom.joy1dat; button = (~ciaa.pra >> 7) & 1; break; } input_regs(amijoy_dev[i], fp); diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c index 51a912222e8..62438944a69 100644 --- a/drivers/input/joystick/grip_mp.c +++ b/drivers/input/joystick/grip_mp.c @@ -53,17 +53,8 @@ struct grip_port { struct grip_mp { struct gameport *gameport; struct grip_port *port[GRIP_MAX_PORTS]; -// struct input_dev *dev[4]; -// int mode[4]; -// int registered[4]; int reads; int bads; - - /* individual gamepad states */ -// int buttons[4]; -// int xaxes[4]; -// int yaxes[4]; -// int dirty[4]; /* has the state been updated? */ }; /* diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 4a917748fd9..3b0ac3b43c5 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -143,16 +143,6 @@ config KEYBOARD_SPITZ To compile this driver as a module, choose M here: the module will be called spitzkbd. -config KEYBOARD_MAPLE - tristate "Maple bus keyboard" - depends on SH_DREAMCAST && MAPLE - help - Say Y here if you have a DreamCast console running Linux and have - a keyboard attached to its Maple bus. - - To compile this driver as a module, choose M here: the - module will be called maple_keyb. - config KEYBOARD_AMIGA tristate "Amiga keyboard" depends on AMIGA diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 9ce0b87f2fa..6e0afbb2238 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -5,7 +5,6 @@ # Each configuration option enables a list of files. obj-$(CONFIG_KEYBOARD_ATKBD) += atkbd.o -obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o obj-$(CONFIG_KEYBOARD_SUNKBD) += sunkbd.o obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c index a0256f8de8e..ffacf6eca5f 100644 --- a/drivers/input/keyboard/atkbd.c +++ b/drivers/input/keyboard/atkbd.c @@ -321,7 +321,7 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data, switch (code) { case ATKBD_RET_BAT: atkbd->enabled = 0; - serio_rescan(atkbd->ps2dev.serio); + serio_reconnect(atkbd->ps2dev.serio); goto out; case ATKBD_RET_EMUL0: atkbd->emul = 1; diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c index 64672d49122..e301ee4ca26 100644 --- a/drivers/input/keyboard/corgikbd.c +++ b/drivers/input/keyboard/corgikbd.c @@ -19,7 +19,6 @@ #include <linux/jiffies.h> #include <linux/module.h> #include <linux/slab.h> -#include <asm/irq.h> #include <asm/arch/corgi.h> #include <asm/arch/hardware.h> @@ -343,10 +342,9 @@ static int __init corgikbd_probe(struct platform_device *pdev) for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) { pxa_gpio_mode(CORGI_GPIO_KEY_SENSE(i) | GPIO_IN); if (request_irq(CORGI_IRQ_GPIO_KEY_SENSE(i), corgikbd_interrupt, - SA_INTERRUPT, "corgikbd", corgikbd)) + SA_INTERRUPT | SA_TRIGGER_RISING, + "corgikbd", corgikbd)) printk(KERN_WARNING "corgikbd: Can't get IRQ: %d!\n", i); - else - set_irq_type(CORGI_IRQ_GPIO_KEY_SENSE(i),IRQT_RISING); } /* Set Strobe lines as outputs - set high */ diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c index 6a15fe3bc52..83999d58312 100644 --- a/drivers/input/keyboard/spitzkbd.c +++ b/drivers/input/keyboard/spitzkbd.c @@ -19,7 +19,6 @@ #include <linux/jiffies.h> #include <linux/module.h> #include <linux/slab.h> -#include <asm/irq.h> #include <asm/arch/spitz.h> #include <asm/arch/hardware.h> @@ -407,10 +406,9 @@ static int __init spitzkbd_probe(struct platform_device *dev) for (i = 0; i < SPITZ_KEY_SENSE_NUM; i++) { pxa_gpio_mode(spitz_senses[i] | GPIO_IN); if (request_irq(IRQ_GPIO(spitz_senses[i]), spitzkbd_interrupt, - SA_INTERRUPT, "Spitzkbd Sense", spitzkbd)) + SA_INTERRUPT|SA_TRIGGER_RISING, + "Spitzkbd Sense", spitzkbd)) printk(KERN_WARNING "spitzkbd: Can't get Sense IRQ: %d!\n", i); - else - set_irq_type(IRQ_GPIO(spitz_senses[i]),IRQT_RISING); } /* Set Strobe lines as outputs - set high */ @@ -422,15 +420,18 @@ static int __init spitzkbd_probe(struct platform_device *dev) pxa_gpio_mode(SPITZ_GPIO_SWA | GPIO_IN); pxa_gpio_mode(SPITZ_GPIO_SWB | GPIO_IN); - request_irq(SPITZ_IRQ_GPIO_SYNC, spitzkbd_interrupt, SA_INTERRUPT, "Spitzkbd Sync", spitzkbd); - request_irq(SPITZ_IRQ_GPIO_ON_KEY, spitzkbd_interrupt, SA_INTERRUPT, "Spitzkbd PwrOn", spitzkbd); - request_irq(SPITZ_IRQ_GPIO_SWA, spitzkbd_hinge_isr, SA_INTERRUPT, "Spitzkbd SWA", spitzkbd); - request_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd_hinge_isr, SA_INTERRUPT, "Spitzkbd SWB", spitzkbd); - - set_irq_type(SPITZ_IRQ_GPIO_SYNC, IRQT_BOTHEDGE); - set_irq_type(SPITZ_IRQ_GPIO_ON_KEY, IRQT_BOTHEDGE); - set_irq_type(SPITZ_IRQ_GPIO_SWA, IRQT_BOTHEDGE); - set_irq_type(SPITZ_IRQ_GPIO_SWB, IRQT_BOTHEDGE); + request_irq(SPITZ_IRQ_GPIO_SYNC, spitzkbd_interrupt, + SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING, + "Spitzkbd Sync", spitzkbd); + request_irq(SPITZ_IRQ_GPIO_ON_KEY, spitzkbd_interrupt, + SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING, + "Spitzkbd PwrOn", spitzkbd); + request_irq(SPITZ_IRQ_GPIO_SWA, spitzkbd_hinge_isr, + SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING, + "Spitzkbd SWA", spitzkbd); + request_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd_hinge_isr, + SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING, + "Spitzkbd SWB", spitzkbd); printk(KERN_INFO "input: Spitz Keyboard Registered\n"); diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c index 1cd7657f7e4..1be963961c1 100644 --- a/drivers/input/misc/hp_sdc_rtc.c +++ b/drivers/input/misc/hp_sdc_rtc.c @@ -60,8 +60,6 @@ static struct fasync_struct *hp_sdc_rtc_async_queue; static DECLARE_WAIT_QUEUE_HEAD(hp_sdc_rtc_wait); -static loff_t hp_sdc_rtc_llseek(struct file *file, loff_t offset, int origin); - static ssize_t hp_sdc_rtc_read(struct file *file, char *buf, size_t count, loff_t *ppos); @@ -387,11 +385,6 @@ static int hp_sdc_rtc_set_i8042timer (struct timeval *setto, uint8_t setcmd) return 0; } -static loff_t hp_sdc_rtc_llseek(struct file *file, loff_t offset, int origin) -{ - return -ESPIPE; -} - static ssize_t hp_sdc_rtc_read(struct file *file, char *buf, size_t count, loff_t *ppos) { ssize_t retval; @@ -679,7 +672,7 @@ static int hp_sdc_rtc_ioctl(struct inode *inode, struct file *file, static struct file_operations hp_sdc_rtc_fops = { .owner = THIS_MODULE, - .llseek = hp_sdc_rtc_llseek, + .llseek = no_llseek, .read = hp_sdc_rtc_read, .poll = hp_sdc_rtc_poll, .ioctl = hp_sdc_rtc_ioctl, diff --git a/drivers/input/misc/m68kspkr.c b/drivers/input/misc/m68kspkr.c index 04489ad7702..8d6c3837bad 100644 --- a/drivers/input/misc/m68kspkr.c +++ b/drivers/input/misc/m68kspkr.c @@ -17,6 +17,7 @@ #include <linux/module.h> #include <linux/init.h> #include <linux/input.h> +#include <linux/platform_device.h> #include <asm/machdep.h> #include <asm/io.h> @@ -24,7 +25,7 @@ MODULE_AUTHOR("Richard Zidlicky <rz@linux-m68k.org>"); MODULE_DESCRIPTION("m68k beeper driver"); MODULE_LICENSE("GPL"); -static struct input_dev *m68kspkr_dev; +static struct platform_device *m68kspkr_platform_device; static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { @@ -47,36 +48,103 @@ static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int return 0; } +static int __devinit m68kspkr_probe(struct platform_device *dev) +{ + struct input_dev *input_dev; + int err; + + input_dev = input_allocate_device(); + if (!input_dev) + return -ENOMEM; + + input_dev->name = "m68k beeper"; + input_dev->phys = "m68k/generic"; + input_dev->id.bustype = BUS_HOST; + input_dev->id.vendor = 0x001f; + input_dev->id.product = 0x0001; + input_dev->id.version = 0x0100; + input_dev->cdev.dev = &dev->dev; + + input_dev->evbit[0] = BIT(EV_SND); + input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); + input_dev->event = m68kspkr_event; + + err = input_register_device(input_dev); + if (err) { + input_free_device(input_dev); + return err; + } + + platform_set_drvdata(dev, input_dev); + + return 0; +} + +static int __devexit m68kspkr_remove(struct platform_device *dev) +{ + struct input_dev *input_dev = platform_get_drvdata(dev); + + input_unregister_device(input_dev); + platform_set_drvdata(dev, NULL); + /* turn off the speaker */ + m68kspkr_event(NULL, EV_SND, SND_BELL, 0); + + return 0; +} + +static void m68kspkr_shutdown(struct platform_device *dev) +{ + /* turn off the speaker */ + m68kspkr_event(NULL, EV_SND, SND_BELL, 0); +} + +static struct platform_driver m68kspkr_platform_driver = { + .driver = { + .name = "m68kspkr", + .owner = THIS_MODULE, + }, + .probe = m68kspkr_probe, + .remove = __devexit_p(m68kspkr_remove), + .shutdown = m68kspkr_shutdown, +}; + static int __init m68kspkr_init(void) { - if (!mach_beep) { + int err; + + if (!mach_beep) { printk(KERN_INFO "m68kspkr: no lowlevel beep support\n"); return -ENODEV; } - m68kspkr_dev = input_allocate_device(); - if (!m68kspkr_dev) - return -ENOMEM; - - m68kspkr_dev->name = "m68k beeper"; - m68kspkr_dev->phys = "m68k/generic"; - m68kspkr_dev->id.bustype = BUS_HOST; - m68kspkr_dev->id.vendor = 0x001f; - m68kspkr_dev->id.product = 0x0001; - m68kspkr_dev->id.version = 0x0100; + err = platform_driver_register(&m68kspkr_platform_driver); + if (err) + return err; - m68kspkr_dev->evbit[0] = BIT(EV_SND); - m68kspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); - m68kspkr_dev->event = m68kspkr_event; + m68kspkr_platform_device = platform_device_alloc("m68kspkr", -1); + if (!m68kspkr_platform_device) { + err = -ENOMEM; + goto err_unregister_driver; + } - input_register_device(m68kspkr_dev); + err = platform_device_add(m68kspkr_platform_device); + if (err) + goto err_free_device; return 0; + + err_free_device: + platform_device_put(m68kspkr_platform_device); + err_unregister_driver: + platform_driver_unregister(&m68kspkr_platform_driver); + + return err; } static void __exit m68kspkr_exit(void) { - input_unregister_device(m68kspkr_dev); + platform_device_unregister(m68kspkr_platform_device); + platform_driver_unregister(&m68kspkr_platform_driver); } module_init(m68kspkr_init); diff --git a/drivers/input/misc/pcspkr.c b/drivers/input/misc/pcspkr.c index 68ac97f101b..1ef477f4469 100644 --- a/drivers/input/misc/pcspkr.c +++ b/drivers/input/misc/pcspkr.c @@ -16,6 +16,7 @@ #include <linux/module.h> #include <linux/init.h> #include <linux/input.h> +#include <linux/platform_device.h> #include <asm/8253pit.h> #include <asm/io.h> @@ -23,8 +24,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); MODULE_DESCRIPTION("PC Speaker beeper driver"); MODULE_LICENSE("GPL"); -static struct input_dev *pcspkr_dev; - +static struct platform_device *pcspkr_platform_device; static DEFINE_SPINLOCK(i8253_beep_lock); static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) @@ -64,8 +64,11 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c return 0; } -static int __init pcspkr_init(void) +static int __devinit pcspkr_probe(struct platform_device *dev) { + struct input_dev *pcspkr_dev; + int err; + pcspkr_dev = input_allocate_device(); if (!pcspkr_dev) return -ENOMEM; @@ -76,22 +79,93 @@ static int __init pcspkr_init(void) pcspkr_dev->id.vendor = 0x001f; pcspkr_dev->id.product = 0x0001; pcspkr_dev->id.version = 0x0100; + pcspkr_dev->cdev.dev = &dev->dev; pcspkr_dev->evbit[0] = BIT(EV_SND); pcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); pcspkr_dev->event = pcspkr_event; - input_register_device(pcspkr_dev); + err = input_register_device(pcspkr_dev); + if (err) { + input_free_device(pcspkr_dev); + return err; + } + + platform_set_drvdata(dev, pcspkr_dev); return 0; } -static void __exit pcspkr_exit(void) +static int __devexit pcspkr_remove(struct platform_device *dev) +{ + struct input_dev *pcspkr_dev = platform_get_drvdata(dev); + + input_unregister_device(pcspkr_dev); + platform_set_drvdata(dev, NULL); + /* turn off the speaker */ + pcspkr_event(NULL, EV_SND, SND_BELL, 0); + + return 0; +} + +static int pcspkr_suspend(struct platform_device *dev, pm_message_t state) +{ + pcspkr_event(NULL, EV_SND, SND_BELL, 0); + + return 0; +} + +static void pcspkr_shutdown(struct platform_device *dev) { - input_unregister_device(pcspkr_dev); /* turn off the speaker */ pcspkr_event(NULL, EV_SND, SND_BELL, 0); } +static struct platform_driver pcspkr_platform_driver = { + .driver = { + .name = "pcspkr", + .owner = THIS_MODULE, + }, + .probe = pcspkr_probe, + .remove = __devexit_p(pcspkr_remove), + .suspend = pcspkr_suspend, + .shutdown = pcspkr_shutdown, +}; + + +static int __init pcspkr_init(void) +{ + int err; + + err = platform_driver_register(&pcspkr_platform_driver); + if (err) + return err; + + pcspkr_platform_device = platform_device_alloc("pcspkr", -1); + if (!pcspkr_platform_device) { + err = -ENOMEM; + goto err_unregister_driver; + } + + err = platform_device_add(pcspkr_platform_device); + if (err) + goto err_free_device; + + return 0; + + err_free_device: + platform_device_put(pcspkr_platform_device); + err_unregister_driver: + platform_driver_unregister(&pcspkr_platform_driver); + + return err; +} + +static void __exit pcspkr_exit(void) +{ + platform_device_unregister(pcspkr_platform_device); + platform_driver_unregister(&pcspkr_platform_driver); +} + module_init(pcspkr_init); module_exit(pcspkr_exit); diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c index 29d97b12be7..f0fd2c4740f 100644 --- a/drivers/input/misc/sparcspkr.c +++ b/drivers/input/misc/sparcspkr.c @@ -9,6 +9,7 @@ #include <linux/module.h> #include <linux/init.h> #include <linux/input.h> +#include <linux/platform_device.h> #include <asm/io.h> #include <asm/ebus.h> @@ -20,22 +21,10 @@ MODULE_AUTHOR("David S. Miller <davem@redhat.com>"); MODULE_DESCRIPTION("Sparc Speaker beeper driver"); MODULE_LICENSE("GPL"); +const char *beep_name; static unsigned long beep_iobase; -static struct input_dev *sparcspkr_dev; - -DEFINE_SPINLOCK(beep_lock); - -static void __init init_sparcspkr_struct(void) -{ - sparcspkr_dev->evbit[0] = BIT(EV_SND); - sparcspkr_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); - - sparcspkr_dev->phys = "sparc/input0"; - sparcspkr_dev->id.bustype = BUS_ISA; - sparcspkr_dev->id.vendor = 0x001f; - sparcspkr_dev->id.product = 0x0001; - sparcspkr_dev->id.version = 0x0100; -} +static int (*beep_event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); +static DEFINE_SPINLOCK(beep_lock); static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { @@ -59,39 +48,16 @@ static int ebus_spkr_event(struct input_dev *dev, unsigned int type, unsigned in /* EBUS speaker only has on/off state, the frequency does not * appear to be programmable. */ - if (count) { - if (beep_iobase & 0x2UL) - outb(1, beep_iobase); - else - outl(1, beep_iobase); - } else { - if (beep_iobase & 0x2UL) - outb(0, beep_iobase); - else - outl(0, beep_iobase); - } + if (beep_iobase & 0x2UL) + outb(!!count, beep_iobase); + else + outl(!!count, beep_iobase); spin_unlock_irqrestore(&beep_lock, flags); return 0; } -static int __init init_ebus_beep(struct linux_ebus_device *edev) -{ - beep_iobase = edev->resource[0].start; - - sparcspkr_dev = input_allocate_device(); - if (!sparcspkr_dev) - return -ENOMEM; - - sparcspkr_dev->name = "Sparc EBUS Speaker"; - sparcspkr_dev->event = ebus_spkr_event; - - input_register_device(sparcspkr_dev); - - return 0; -} - #ifdef CONFIG_SPARC64 static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { @@ -129,30 +95,103 @@ static int isa_spkr_event(struct input_dev *dev, unsigned int type, unsigned int return 0; } +#endif -static int __init init_isa_beep(struct sparc_isa_device *isa_dev) +static int __devinit sparcspkr_probe(struct platform_device *dev) { - beep_iobase = isa_dev->resource.start; + struct input_dev *input_dev; + int error; - sparcspkr_dev = input_allocate_device(); - if (!sparcspkr_dev) + input_dev = input_allocate_device(); + if (!input_dev) return -ENOMEM; - init_sparcspkr_struct(); + input_dev->name = beep_name; + input_dev->phys = "sparc/input0"; + input_dev->id.bustype = BUS_ISA; + input_dev->id.vendor = 0x001f; + input_dev->id.product = 0x0001; + input_dev->id.version = 0x0100; + input_dev->cdev.dev = &dev->dev; - sparcspkr_dev->name = "Sparc ISA Speaker"; - sparcspkr_dev->event = isa_spkr_event; + input_dev->evbit[0] = BIT(EV_SND); + input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE); - input_register_device(sparcspkr_dev); + input_dev->event = beep_event; + + error = input_register_device(input_dev); + if (error) { + input_free_device(input_dev); + return error; + } + + platform_set_drvdata(dev, input_dev); return 0; } -#endif + +static int __devexit sparcspkr_remove(struct platform_device *dev) +{ + struct input_dev *input_dev = platform_get_drvdata(dev); + + input_unregister_device(input_dev); + platform_set_drvdata(dev, NULL); + /* turn off the speaker */ + beep_event(NULL, EV_SND, SND_BELL, 0); + + return 0; +} + +static void sparcspkr_shutdown(struct platform_device *dev) +{ + /* turn off the speaker */ + beep_event(NULL, EV_SND, SND_BELL, 0); +} + +static struct platform_driver sparcspkr_platform_driver = { + .driver = { + .name = "sparcspkr", + .owner = THIS_MODULE, + }, + .probe = sparcspkr_probe, + .remove = __devexit_p(sparcspkr_remove), + .shutdown = sparcspkr_shutdown, +}; + +static struct platform_device *sparcspkr_platform_device; + +static int __init sparcspkr_drv_init(void) +{ + int error; + + error = platform_driver_register(&sparcspkr_platform_driver); + if (error) + return error; + + sparcspkr_platform_device = platform_device_alloc("sparcspkr", -1); + if (!sparcspkr_platform_device) { + error = -ENOMEM; + goto err_unregister_driver; + } + + error = platform_device_add(sparcspkr_platform_device); + if (error) + goto err_free_device; + + return 0; + + err_free_device: + platform_device_put(sparcspkr_platform_device); + err_unregister_driver: + platform_driver_unregister(&sparcspkr_platform_driver); + + return error; +} static int __init sparcspkr_init(void) { struct linux_ebus *ebus; - struct linux_ebus_device *edev = NULL; + struct linux_ebus_device *edev; #ifdef CONFIG_SPARC64 struct sparc_isa_bridge *isa_br; struct sparc_isa_device *isa_dev; @@ -160,8 +199,12 @@ static int __init sparcspkr_init(void) for_each_ebus(ebus) { for_each_ebusdev(edev, ebus) { - if (!strcmp(edev->prom_name, "beep")) - return init_ebus_beep(edev); + if (!strcmp(edev->prom_name, "beep")) { + beep_name = "Sparc EBUS Speaker"; + beep_event = ebus_spkr_event; + beep_iobase = edev->resource[0].start; + return sparcspkr_drv_init(); + } } } #ifdef CONFIG_SPARC64 @@ -170,8 +213,12 @@ static int __init sparcspkr_init(void) /* A hack, the beep device's base lives in * the DMA isa node. */ - if (!strcmp(isa_dev->prom_name, "dma")) - return init_isa_beep(isa_dev); + if (!strcmp(isa_dev->prom_name, "dma")) { + beep_name = "Sparc ISA Speaker"; + beep_event = isa_spkr_event, + beep_iobase = isa_dev->resource.start; + return sparcspkr_drv_init(); + } } } #endif @@ -181,7 +228,8 @@ static int __init sparcspkr_init(void) static void __exit sparcspkr_exit(void) { - input_unregister_device(sparcspkr_dev); + platform_device_unregister(sparcspkr_platform_device); + platform_driver_unregister(&sparcspkr_platform_driver); } module_init(sparcspkr_init); diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c index bac3085185f..4b415d9b012 100644 --- a/drivers/input/misc/wistron_btns.c +++ b/drivers/input/misc/wistron_btns.c @@ -92,11 +92,11 @@ static void call_bios(struct regs *regs) preempt_enable(); } -static size_t __init locate_wistron_bios(void __iomem *base) +static ssize_t __init locate_wistron_bios(void __iomem *base) { static const unsigned char __initdata signature[] = { 0x42, 0x21, 0x55, 0x30 }; - size_t offset; + ssize_t offset; for (offset = 0; offset < 0x10000; offset += 0x10) { if (check_signature(base + offset, signature, @@ -109,7 +109,7 @@ static size_t __init locate_wistron_bios(void __iomem *base) static int __init map_bios(void) { void __iomem *base; - size_t offset; + ssize_t offset; u32 entry_point; base = ioremap(0xF0000, 0x10000); /* Can't fail */ @@ -174,7 +174,7 @@ static u16 bios_pop_queue(void) return regs.eax; } -static void __init bios_attach(void) +static void __devinit bios_attach(void) { struct regs regs; @@ -194,7 +194,7 @@ static void bios_detach(void) call_bios(®s); } -static u8 __init bios_get_cmos_address(void) +static u8 __devinit bios_get_cmos_address(void) { struct regs regs; @@ -206,7 +206,7 @@ static u8 __init bios_get_cmos_address(void) return regs.ecx; } -static u16 __init bios_get_default_setting(u8 subsys) +static u16 __devinit bios_get_default_setting(u8 subsys) { struct regs regs; @@ -296,6 +296,16 @@ static struct key_entry keymap_acer_aspire_1500[] = { { KE_END, 0 } }; +static struct key_entry keymap_acer_travelmate_240[] = { + { KE_KEY, 0x31, KEY_MAIL }, + { KE_KEY, 0x36, KEY_WWW }, + { KE_KEY, 0x11, KEY_PROG1 }, + { KE_KEY, 0x12, KEY_PROG2 }, + { KE_BLUETOOTH, 0x44, 0 }, + { KE_WIFI, 0x30, 0 }, + { KE_END, 0 } +}; + /* * If your machine is not here (which is currently rather likely), please send * a list of buttons and their key codes (reported when loading this module @@ -320,6 +330,15 @@ static struct dmi_system_id dmi_ids[] = { }, .driver_data = keymap_acer_aspire_1500 }, + { + .callback = dmi_matched, + .ident = "Acer TravelMate 240", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Acer"), + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 240"), + }, + .driver_data = keymap_acer_travelmate_240 + }, { NULL, } }; @@ -348,7 +367,7 @@ static int __init select_keymap(void) static struct input_dev *input_dev; -static int __init setup_input_dev(void) +static int __devinit setup_input_dev(void) { const struct key_entry *key; int error; @@ -447,6 +466,52 @@ static void poll_bios(unsigned long discard) mod_timer(&poll_timer, jiffies + HZ / POLL_FREQUENCY); } +static int __devinit wistron_probe(struct platform_device *dev) +{ + int err = setup_input_dev(); + if (err) + return err; + + bios_attach(); + cmos_address = bios_get_cmos_address(); + + if (have_wifi) { + u16 wifi = bios_get_default_setting(WIFI); + if (wifi & 1) + wifi_enabled = (wifi & 2) ? 1 : 0; + else + have_wifi = 0; + + if (have_wifi) + bios_set_state(WIFI, wifi_enabled); + } + + if (have_bluetooth) { + u16 bt = bios_get_default_setting(BLUETOOTH); + if (bt & 1) + bluetooth_enabled = (bt & 2) ? 1 : 0; + else + have_bluetooth = 0; + + if (have_bluetooth) + bios_set_state(BLUETOOTH, bluetooth_enabled); + } + + poll_bios(1); /* Flush stale event queue and arm timer */ + + return 0; +} + +static int __devexit wistron_remove(struct platform_device *dev) +{ + del_timer_sync(&poll_timer); + input_unregister_device(input_dev); + bios_detach(); + + return 0; +} + +#ifdef CONFIG_PM static int wistron_suspend(struct platform_device *dev, pm_message_t state) { del_timer_sync(&poll_timer); @@ -472,13 +537,20 @@ static int wistron_resume(struct platform_device *dev) return 0; } +#else +#define wistron_suspend NULL +#define wistron_resume NULL +#endif static struct platform_driver wistron_driver = { - .suspend = wistron_suspend, - .resume = wistron_resume, .driver = { .name = "wistron-bios", + .owner = THIS_MODULE, }, + .probe = wistron_probe, + .remove = __devexit_p(wistron_remove), + .suspend = wistron_suspend, + .resume = wistron_resume, }; static int __init wb_module_init(void) @@ -493,55 +565,27 @@ static int __init wb_module_init(void) if (err) return err; - bios_attach(); - cmos_address = bios_get_cmos_address(); - err = platform_driver_register(&wistron_driver); if (err) - goto err_detach_bios; + goto err_unmap_bios; - wistron_device = platform_device_register_simple("wistron-bios", -1, NULL, 0); - if (IS_ERR(wistron_device)) { - err = PTR_ERR(wistron_device); + wistron_device = platform_device_alloc("wistron-bios", -1); + if (!wistron_device) { + err = -ENOMEM; goto err_unregister_driver; } - if (have_wifi) { - u16 wifi = bios_get_default_setting(WIFI); - if (wifi & 1) - wifi_enabled = (wifi & 2) ? 1 : 0; - else - have_wifi = 0; - - if (have_wifi) - bios_set_state(WIFI, wifi_enabled); - } - - if (have_bluetooth) { - u16 bt = bios_get_default_setting(BLUETOOTH); - if (bt & 1) - bluetooth_enabled = (bt & 2) ? 1 : 0; - else - have_bluetooth = 0; - - if (have_bluetooth) - bios_set_state(BLUETOOTH, bluetooth_enabled); - } - - err = setup_input_dev(); + err = platform_device_add(wistron_device); if (err) - goto err_unregister_device; - - poll_bios(1); /* Flush stale event queue and arm timer */ + goto err_free_device; return 0; - err_unregister_device: - platform_device_unregister(wistron_device); + err_free_device: + platform_device_put(wistron_device); err_unregister_driver: platform_driver_unregister(&wistron_driver); - err_detach_bios: - bios_detach(); + err_unmap_bios: unmap_bios(); return err; @@ -549,11 +593,8 @@ static int __init wb_module_init(void) static void __exit wb_module_exit(void) { - del_timer_sync(&poll_timer); - input_unregister_device(input_dev); platform_device_unregister(wistron_device); platform_driver_unregister(&wistron_driver); - bios_detach(); unmap_bios(); } diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig index 574b18a523a..f15ccf78168 100644 --- a/drivers/input/mouse/Kconfig +++ b/drivers/input/mouse/Kconfig @@ -86,16 +86,6 @@ config MOUSE_PC110PAD To compile this driver as a module, choose M here: the module will be called pc110pad. -config MOUSE_MAPLE - tristate "Maple bus mouse" - depends on SH_DREAMCAST && MAPLE - help - Say Y if you have a DreamCast console and a mouse attached to - its Maple bus. - - To compile this driver as a module, choose M here: the - module will be called maplemouse. - config MOUSE_AMIGA tristate "Amiga mouse" depends on AMIGA diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile index 82b330bbf06..21a1de61a79 100644 --- a/drivers/input/mouse/Makefile +++ b/drivers/input/mouse/Makefile @@ -8,7 +8,6 @@ obj-$(CONFIG_MOUSE_AMIGA) += amimouse.o obj-$(CONFIG_MOUSE_RISCPC) += rpcmouse.o obj-$(CONFIG_MOUSE_INPORT) += inport.o obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o -obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o obj-$(CONFIG_MOUSE_PC110PAD) += pc110pad.o obj-$(CONFIG_MOUSE_PS2) += psmouse.o obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c index 4f41ec3e433..2141501e9f2 100644 --- a/drivers/input/mouse/alps.c +++ b/drivers/input/mouse/alps.c @@ -40,6 +40,7 @@ static struct alps_model_info alps_model_data[] = { { { 0x33, 0x02, 0x0a }, 0x88, 0xf8, ALPS_OLDPROTO }, /* UMAX-530T */ { { 0x53, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, { { 0x53, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, + { { 0x60, 0x03, 0xc8 }, 0xf8, 0xf8, 0 }, /* HP ze1115 */ { { 0x63, 0x02, 0x0a }, 0xf8, 0xf8, 0 }, { { 0x63, 0x02, 0x14 }, 0xf8, 0xf8, 0 }, { { 0x63, 0x02, 0x28 }, 0xf8, 0xf8, ALPS_FW_BK_2 }, /* Fujitsu Siemens S6010 */ @@ -347,6 +348,40 @@ static int alps_tap_mode(struct psmouse *psmouse, int enable) return 0; } +/* + * alps_poll() - poll the touchpad for current motion packet. + * Used in resync. + */ +static int alps_poll(struct psmouse *psmouse) +{ + struct alps_data *priv = psmouse->private; + unsigned char buf[6]; + int poll_failed; + + if (priv->i->flags & ALPS_PASS) + alps_passthrough_mode(psmouse, 1); + + poll_failed = ps2_command(&psmouse->ps2dev, buf, + PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)) < 0; + + if (priv->i->flags & ALPS_PASS) + alps_passthrough_mode(psmouse, 0); + + if (poll_failed || (buf[0] & priv->i->mask0) != priv->i->byte0) + return -1; + + if ((psmouse->badbyte & 0xc8) == 0x08) { +/* + * Poll the track stick ... + */ + if (ps2_command(&psmouse->ps2dev, buf, PSMOUSE_CMD_POLL | (3 << 8))) + return -1; + } + + memcpy(psmouse->packet, buf, sizeof(buf)); + return 0; +} + static int alps_reconnect(struct psmouse *psmouse) { struct alps_data *priv = psmouse->private; @@ -450,10 +485,14 @@ int alps_init(struct psmouse *psmouse) input_register_device(priv->dev2); psmouse->protocol_handler = alps_process_byte; + psmouse->poll = alps_poll; psmouse->disconnect = alps_disconnect; psmouse->reconnect = alps_reconnect; psmouse->pktsize = 6; + /* We are having trouble resyncing ALPS touchpads so disable it for now */ + psmouse->resync_time = 0; + return 0; init_fail: diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c index d13d4c8fe3c..c8b2cc9f184 100644 --- a/drivers/input/mouse/amimouse.c +++ b/drivers/input/mouse/amimouse.c @@ -41,7 +41,7 @@ static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp) unsigned short joy0dat, potgor; int nx, ny, dx, dy; - joy0dat = custom.joy0dat; + joy0dat = amiga_custom.joy0dat; nx = joy0dat & 0xff; ny = joy0dat >> 8; @@ -57,7 +57,7 @@ static irqreturn_t amimouse_interrupt(int irq, void *dummy, struct pt_regs *fp) amimouse_lastx = nx; amimouse_lasty = ny; - potgor = custom.potgor; + potgor = amiga_custom.potgor; input_regs(amimouse_dev, fp); @@ -77,7 +77,7 @@ static int amimouse_open(struct input_dev *dev) { unsigned short joy0dat; - joy0dat = custom.joy0dat; + joy0dat = amiga_custom.joy0dat; amimouse_lastx = joy0dat & 0xff; amimouse_lasty = joy0dat >> 8; diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c index 55991424ac9..5ccc3ef3b89 100644 --- a/drivers/input/mouse/lifebook.c +++ b/drivers/input/mouse/lifebook.c @@ -27,6 +27,13 @@ static struct dmi_system_id lifebook_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"), }, }, + { + .ident = "Lifebook B142", + .matches = { + DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"), + }, + + }, { } }; diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c index 31a59f7abfa..c88520d3d13 100644 --- a/drivers/input/mouse/logips2pp.c +++ b/drivers/input/mouse/logips2pp.c @@ -117,7 +117,7 @@ static int ps2pp_cmd(struct psmouse *psmouse, unsigned char *param, unsigned cha if (psmouse_sliced_command(psmouse, command)) return -1; - if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL)) + if (ps2_command(&psmouse->ps2dev, param, PSMOUSE_CMD_POLL | 0x0300)) return -1; return 0; @@ -226,7 +226,9 @@ static struct ps2pp_info *get_model_info(unsigned char model) { 80, PS2PP_KIND_WHEEL, PS2PP_SIDE_BTN | PS2PP_WHEEL }, { 81, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, { 83, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, + { 85, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, { 86, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, + { 87, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, { 88, PS2PP_KIND_WHEEL, PS2PP_WHEEL }, { 96, 0, 0 }, { 97, PS2PP_KIND_TP3, PS2PP_WHEEL | PS2PP_HWHEEL }, diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c deleted file mode 100644 index b5b34fe4fee..00000000000 --- a/drivers/input/mouse/maplemouse.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * $Id: maplemouse.c,v 1.2 2004/03/22 01:18:15 lethal Exp $ - * SEGA Dreamcast mouse driver - * Based on drivers/usb/usbmouse.c - */ - -#include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/input.h> -#include <linux/module.h> -#include <linux/init.h> -#include <linux/timer.h> -#include <linux/maple.h> - -MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>"); -MODULE_DESCRIPTION("SEGA Dreamcast mouse driver"); - -static void dc_mouse_callback(struct mapleq *mq) -{ - int buttons, relx, rely, relz; - struct maple_device *mapledev = mq->dev; - struct input_dev *dev = mapledev->private_data; - unsigned char *res = mq->recvbuf; - - buttons = ~res[8]; - relx = *(unsigned short *)(res + 12) - 512; - rely = *(unsigned short *)(res + 14) - 512; - relz = *(unsigned short *)(res + 16) - 512; - - input_report_key(dev, BTN_LEFT, buttons & 4); - input_report_key(dev, BTN_MIDDLE, buttons & 9); - input_report_key(dev, BTN_RIGHT, buttons & 2); - input_report_rel(dev, REL_X, relx); - input_report_rel(dev, REL_Y, rely); - input_report_rel(dev, REL_WHEEL, relz); - input_sync(dev); -} - -static int dc_mouse_connect(struct maple_device *dev) -{ - unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]); - struct input_dev *input_dev; - - dev->private_data = input_dev = input_allocate_device(); - if (!input_dev) - return -ENOMEM; - - dev->private_data = input_dev; - - input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); - input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); - input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y) | BIT(REL_WHEEL); - - input_dev->name = dev->product_name; - input_dev->id.bustype = BUS_MAPLE; - - input_register_device(input_dev); - - maple_getcond_callback(dev, dc_mouse_callback, 1, MAPLE_FUNC_MOUSE); - - return 0; -} - - -static void dc_mouse_disconnect(struct maple_device *dev) -{ - struct input_dev *input_dev = dev->private_data; - - input_unregister_device(input_dev); -} - - -static struct maple_driver dc_mouse_driver = { - .function = MAPLE_FUNC_MOUSE, - .name = "Dreamcast mouse", - .connect = dc_mouse_connect, - .disconnect = dc_mouse_disconnect, -}; - - -static int __init dc_mouse_init(void) -{ - maple_register_driver(&dc_mouse_driver); - return 0; -} - - -static void __exit dc_mouse_exit(void) -{ - maple_unregister_driver(&dc_mouse_driver); -} - - -module_init(dc_mouse_init); -module_exit(dc_mouse_exit); - -/* - * Local variables: - * c-basic-offset: 8 - * End: - */ diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index 6ee9999a2ea..7665fd9ce55 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c @@ -54,10 +54,14 @@ static unsigned int psmouse_smartscroll = 1; module_param_named(smartscroll, psmouse_smartscroll, bool, 0644); MODULE_PARM_DESC(smartscroll, "Logitech Smartscroll autorepeat, 1 = enabled (default), 0 = disabled."); -static unsigned int psmouse_resetafter; +static unsigned int psmouse_resetafter = 5; module_param_named(resetafter, psmouse_resetafter, uint, 0644); MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); +static unsigned int psmouse_resync_time = 5; +module_param_named(resync_time, psmouse_resync_time, uint, 0644); +MODULE_PARM_DESC(resync_time, "How long can mouse stay idle before forcing resync (in seconds, 0 = never)."); + PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO, NULL, psmouse_attr_show_protocol, psmouse_attr_set_protocol); @@ -70,12 +74,16 @@ PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO, PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO, (void *) offsetof(struct psmouse, resetafter), psmouse_show_int_attr, psmouse_set_int_attr); +PSMOUSE_DEFINE_ATTR(resync_time, S_IWUSR | S_IRUGO, + (void *) offsetof(struct psmouse, resync_time), + psmouse_show_int_attr, psmouse_set_int_attr); static struct attribute *psmouse_attributes[] = { &psmouse_attr_protocol.dattr.attr, &psmouse_attr_rate.dattr.attr, &psmouse_attr_resolution.dattr.attr, &psmouse_attr_resetafter.dattr.attr, + &psmouse_attr_resync_time.dattr.attr, NULL }; @@ -98,6 +106,8 @@ __obsolete_setup("psmouse_rate="); */ static DECLARE_MUTEX(psmouse_sem); +static struct workqueue_struct *kpsmoused_wq; + struct psmouse_protocol { enum psmouse_type type; char *name; @@ -178,15 +188,79 @@ static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse, struct pt_reg } /* - * psmouse_interrupt() handles incoming characters, either gathering them into - * packets or passing them to the command routine as command output. + * __psmouse_set_state() sets new psmouse state and resets all flags. + */ + +static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) +{ + psmouse->state = new_state; + psmouse->pktcnt = psmouse->out_of_sync = 0; + psmouse->ps2dev.flags = 0; + psmouse->last = jiffies; +} + + +/* + * psmouse_set_state() sets new psmouse state and resets all flags and + * counters while holding serio lock so fighting with interrupt handler + * is not a concern. + */ + +static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) +{ + serio_pause_rx(psmouse->ps2dev.serio); + __psmouse_set_state(psmouse, new_state); + serio_continue_rx(psmouse->ps2dev.serio); +} + +/* + * psmouse_handle_byte() processes one byte of the input data stream + * by calling corresponding protocol handler. + */ + +static int psmouse_handle_byte(struct psmouse *psmouse, struct pt_regs *regs) +{ + psmouse_ret_t rc = psmouse->protocol_handler(psmouse, regs); + + switch (rc) { + case PSMOUSE_BAD_DATA: + if (psmouse->state == PSMOUSE_ACTIVATED) { + printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n", + psmouse->name, psmouse->phys, psmouse->pktcnt); + if (++psmouse->out_of_sync == psmouse->resetafter) { + __psmouse_set_state(psmouse, PSMOUSE_IGNORE); + printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n"); + serio_reconnect(psmouse->ps2dev.serio); + return -1; + } + } + psmouse->pktcnt = 0; + break; + + case PSMOUSE_FULL_PACKET: + psmouse->pktcnt = 0; + if (psmouse->out_of_sync) { + psmouse->out_of_sync = 0; + printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n", + psmouse->name, psmouse->phys); + } + break; + + case PSMOUSE_GOOD_DATA: + break; + } + return 0; +} + +/* + * psmouse_interrupt() handles incoming characters, either passing them + * for normal processing or gathering them as command response. */ static irqreturn_t psmouse_interrupt(struct serio *serio, unsigned char data, unsigned int flags, struct pt_regs *regs) { struct psmouse *psmouse = serio_get_drvdata(serio); - psmouse_ret_t rc; if (psmouse->state == PSMOUSE_IGNORE) goto out; @@ -208,67 +282,58 @@ static irqreturn_t psmouse_interrupt(struct serio *serio, if (ps2_handle_response(&psmouse->ps2dev, data)) goto out; - if (psmouse->state == PSMOUSE_INITIALIZING) + if (psmouse->state <= PSMOUSE_RESYNCING) goto out; if (psmouse->state == PSMOUSE_ACTIVATED && psmouse->pktcnt && time_after(jiffies, psmouse->last + HZ/2)) { - printk(KERN_WARNING "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n", + printk(KERN_INFO "psmouse.c: %s at %s lost synchronization, throwing %d bytes away.\n", psmouse->name, psmouse->phys, psmouse->pktcnt); - psmouse->pktcnt = 0; + psmouse->badbyte = psmouse->packet[0]; + __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); + queue_work(kpsmoused_wq, &psmouse->resync_work); + goto out; } - psmouse->last = jiffies; psmouse->packet[psmouse->pktcnt++] = data; - - if (psmouse->packet[0] == PSMOUSE_RET_BAT) { +/* + * Check if this is a new device announcement (0xAA 0x00) + */ + if (unlikely(psmouse->packet[0] == PSMOUSE_RET_BAT && psmouse->pktcnt <= 2)) { if (psmouse->pktcnt == 1) goto out; - if (psmouse->pktcnt == 2) { - if (psmouse->packet[1] == PSMOUSE_RET_ID) { - psmouse->state = PSMOUSE_IGNORE; - serio_reconnect(serio); - goto out; - } - if (psmouse->type == PSMOUSE_SYNAPTICS) { - /* neither 0xAA nor 0x00 are valid first bytes - * for a packet in absolute mode - */ - psmouse->pktcnt = 0; - goto out; - } + if (psmouse->packet[1] == PSMOUSE_RET_ID) { + __psmouse_set_state(psmouse, PSMOUSE_IGNORE); + serio_reconnect(serio); + goto out; } - } - - rc = psmouse->protocol_handler(psmouse, regs); +/* + * Not a new device, try processing first byte normally + */ + psmouse->pktcnt = 1; + if (psmouse_handle_byte(psmouse, regs)) + goto out; - switch (rc) { - case PSMOUSE_BAD_DATA: - printk(KERN_WARNING "psmouse.c: %s at %s lost sync at byte %d\n", - psmouse->name, psmouse->phys, psmouse->pktcnt); - psmouse->pktcnt = 0; + psmouse->packet[psmouse->pktcnt++] = data; + } - if (++psmouse->out_of_sync == psmouse->resetafter) { - psmouse->state = PSMOUSE_IGNORE; - printk(KERN_NOTICE "psmouse.c: issuing reconnect request\n"); - serio_reconnect(psmouse->ps2dev.serio); - } - break; +/* + * See if we need to force resync because mouse was idle for too long + */ + if (psmouse->state == PSMOUSE_ACTIVATED && + psmouse->pktcnt == 1 && psmouse->resync_time && + time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) { + psmouse->badbyte = psmouse->packet[0]; + __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); + queue_work(kpsmoused_wq, &psmouse->resync_work); + goto out; + } - case PSMOUSE_FULL_PACKET: - psmouse->pktcnt = 0; - if (psmouse->out_of_sync) { - psmouse->out_of_sync = 0; - printk(KERN_NOTICE "psmouse.c: %s at %s - driver resynched.\n", - psmouse->name, psmouse->phys); - } - break; + psmouse->last = jiffies; + psmouse_handle_byte(psmouse, regs); - case PSMOUSE_GOOD_DATA: - break; - } -out: + out: return IRQ_HANDLED; } @@ -527,11 +592,15 @@ static int psmouse_extensions(struct psmouse *psmouse, if (max_proto > PSMOUSE_IMEX && ps2pp_init(psmouse, set_properties) == 0) return PSMOUSE_PS2PP; + if (max_proto > PSMOUSE_IMEX && trackpoint_detect(psmouse, set_properties) == 0) + return PSMOUSE_TRACKPOINT; + /* * Reset to defaults in case the device got confused by extended - * protocol probes. + * protocol probes. Note that we do full reset becuase some mice + * put themselves to sleep when see PSMOUSE_RESET_DIS. */ - ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); + psmouse_reset(psmouse); if (max_proto >= PSMOUSE_IMEX && im_explorer_detect(psmouse, set_properties) == 0) return PSMOUSE_IMEX; @@ -540,12 +609,6 @@ static int psmouse_extensions(struct psmouse *psmouse, return PSMOUSE_IMPS; /* - * Try to initialize the IBM TrackPoint - */ - if (max_proto > PSMOUSE_IMEX && trackpoint_detect(psmouse, set_properties) == 0) - return PSMOUSE_TRACKPOINT; - -/* * Okay, all failed, we have a standard mouse here. The number of the buttons * is still a question, though. We assume 3. */ @@ -559,7 +622,6 @@ static int psmouse_extensions(struct psmouse *psmouse, * extensions. */ psmouse_reset(psmouse); - ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_RESET_DIS); } return PSMOUSE_PS2; @@ -755,21 +817,6 @@ static void psmouse_initialize(struct psmouse *psmouse) } /* - * psmouse_set_state() sets new psmouse state and resets all flags and - * counters while holding serio lock so fighting with interrupt handler - * is not a concern. - */ - -static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) -{ - serio_pause_rx(psmouse->ps2dev.serio); - psmouse->state = new_state; - psmouse->pktcnt = psmouse->out_of_sync = 0; - psmouse->ps2dev.flags = 0; - serio_continue_rx(psmouse->ps2dev.serio); -} - -/* * psmouse_activate() enables the mouse so that we get motion reports from it. */ @@ -797,6 +844,111 @@ static void psmouse_deactivate(struct psmouse *psmouse) psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); } +/* + * psmouse_poll() - default poll hanlder. Everyone except for ALPS uses it. + */ + +static int psmouse_poll(struct psmouse *psmouse) +{ + return ps2_command(&psmouse->ps2dev, psmouse->packet, + PSMOUSE_CMD_POLL | (psmouse->pktsize << 8)); +} + + +/* + * psmouse_resync() attempts to re-validate current protocol. + */ + +static void psmouse_resync(void *p) +{ + struct psmouse *psmouse = p, *parent = NULL; + struct serio *serio = psmouse->ps2dev.serio; + psmouse_ret_t rc = PSMOUSE_GOOD_DATA; + int failed = 0, enabled = 0; + int i; + + down(&psmouse_sem); + + if (psmouse->state != PSMOUSE_RESYNCING) + goto out; + + if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { + parent = serio_get_drvdata(serio->parent); + psmouse_deactivate(parent); + } + +/* + * Some mice don't ACK commands sent while they are in the middle of + * transmitting motion packet. To avoid delay we use ps2_sendbyte() + * instead of ps2_command() which would wait for 200ms for an ACK + * that may never come. + * As an additional quirk ALPS touchpads may not only forget to ACK + * disable command but will stop reporting taps, so if we see that + * mouse at least once ACKs disable we will do full reconnect if ACK + * is missing. + */ + psmouse->num_resyncs++; + + if (ps2_sendbyte(&psmouse->ps2dev, PSMOUSE_CMD_DISABLE, 20)) { + if (psmouse->num_resyncs < 3 || psmouse->acks_disable_command) + failed = 1; + } else + psmouse->acks_disable_command = 1; + +/* + * Poll the mouse. If it was reset the packet will be shorter than + * psmouse->pktsize and ps2_command will fail. We do not expect and + * do not handle scenario when mouse "upgrades" its protocol while + * disconnected since it would require additional delay. If we ever + * see a mouse that does it we'll adjust the code. + */ + if (!failed) { + if (psmouse->poll(psmouse)) + failed = 1; + else { + psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); + for (i = 0; i < psmouse->pktsize; i++) { + psmouse->pktcnt++; + rc = psmouse->protocol_handler(psmouse, NULL); + if (rc != PSMOUSE_GOOD_DATA) + break; + } + if (rc != PSMOUSE_FULL_PACKET) + failed = 1; + psmouse_set_state(psmouse, PSMOUSE_RESYNCING); + } + } +/* + * Now try to enable mouse. We try to do that even if poll failed and also + * repeat our attempts 5 times, otherwise we may be left out with disabled + * mouse. + */ + for (i = 0; i < 5; i++) { + if (!ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE)) { + enabled = 1; + break; + } + msleep(200); + } + + if (!enabled) { + printk(KERN_WARNING "psmouse.c: failed to re-enable mouse on %s\n", + psmouse->ps2dev.serio->phys); + failed = 1; + } + + if (failed) { + psmouse_set_state(psmouse, PSMOUSE_IGNORE); + printk(KERN_INFO "psmouse.c: resync failed, issuing reconnect request\n"); + serio_reconnect(serio); + } else + psmouse_set_state(psmouse, PSMOUSE_ACTIVATED); + + if (parent) + psmouse_activate(parent); + out: + up(&psmouse_sem); +} /* * psmouse_cleanup() resets the mouse into power-on state. @@ -825,6 +977,11 @@ static void psmouse_disconnect(struct serio *serio) psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); + /* make sure we don't have a resync in progress */ + up(&psmouse_sem); + flush_workqueue(kpsmoused_wq); + down(&psmouse_sem); + if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { parent = serio_get_drvdata(serio->parent); psmouse_deactivate(parent); @@ -862,6 +1019,7 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto psmouse->set_rate = psmouse_set_rate; psmouse->set_resolution = psmouse_set_resolution; + psmouse->poll = psmouse_poll; psmouse->protocol_handler = psmouse_process_byte; psmouse->pktsize = 3; @@ -877,6 +1035,23 @@ static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_proto else psmouse->type = psmouse_extensions(psmouse, psmouse_max_proto, 1); + /* + * If mouse's packet size is 3 there is no point in polling the + * device in hopes to detect protocol reset - we won't get less + * than 3 bytes response anyhow. + */ + if (psmouse->pktsize == 3) + psmouse->resync_time = 0; + + /* + * Some smart KVMs fake response to POLL command returning just + * 3 bytes and messing up our resync logic, so if initial poll + * fails we won't try polling the device anymore. Hopefully + * such KVM will maintain initially selected protocol. + */ + if (psmouse->resync_time && psmouse->poll(psmouse)) + psmouse->resync_time = 0; + sprintf(psmouse->devname, "%s %s %s", psmouse_protocol_by_type(psmouse->type)->name, psmouse->vendor, psmouse->name); @@ -917,6 +1092,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) goto out; ps2_init(&psmouse->ps2dev, serio); + INIT_WORK(&psmouse->resync_work, psmouse_resync, psmouse); psmouse->dev = input_dev; sprintf(psmouse->phys, "%s/input0", serio->phys); @@ -937,6 +1113,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) psmouse->rate = psmouse_rate; psmouse->resolution = psmouse_resolution; psmouse->resetafter = psmouse_resetafter; + psmouse->resync_time = parent ? 0 : psmouse_resync_time; psmouse->smartscroll = psmouse_smartscroll; psmouse_switch_protocol(psmouse, NULL); @@ -1281,13 +1458,21 @@ static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp) static int __init psmouse_init(void) { + kpsmoused_wq = create_singlethread_workqueue("kpsmoused"); + if (!kpsmoused_wq) { + printk(KERN_ERR "psmouse: failed to create kpsmoused workqueue\n"); + return -ENOMEM; + } + serio_register_driver(&psmouse_drv); + return 0; } static void __exit psmouse_exit(void) { serio_unregister_driver(&psmouse_drv); + destroy_workqueue(kpsmoused_wq); } module_init(psmouse_init); diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h index 7c4192bd127..4d9107fba6a 100644 --- a/drivers/input/mouse/psmouse.h +++ b/drivers/input/mouse/psmouse.h @@ -7,7 +7,7 @@ #define PSMOUSE_CMD_GETINFO 0x03e9 #define PSMOUSE_CMD_SETSTREAM 0x00ea #define PSMOUSE_CMD_SETPOLL 0x00f0 -#define PSMOUSE_CMD_POLL 0x03eb +#define PSMOUSE_CMD_POLL 0x00eb /* caller sets number of bytes to receive */ #define PSMOUSE_CMD_GETID 0x02f2 #define PSMOUSE_CMD_SETRATE 0x10f3 #define PSMOUSE_CMD_ENABLE 0x00f4 @@ -23,6 +23,7 @@ enum psmouse_state { PSMOUSE_IGNORE, PSMOUSE_INITIALIZING, + PSMOUSE_RESYNCING, PSMOUSE_CMD_MODE, PSMOUSE_ACTIVATED, }; @@ -38,15 +39,19 @@ struct psmouse { void *private; struct input_dev *dev; struct ps2dev ps2dev; + struct work_struct resync_work; char *vendor; char *name; unsigned char packet[8]; + unsigned char badbyte; unsigned char pktcnt; unsigned char pktsize; unsigned char type; + unsigned char acks_disable_command; unsigned int model; unsigned long last; unsigned long out_of_sync; + unsigned long num_resyncs; enum psmouse_state state; char devname[64]; char phys[32]; @@ -54,6 +59,7 @@ struct psmouse { unsigned int rate; unsigned int resolution; unsigned int resetafter; + unsigned int resync_time; unsigned int smartscroll; /* Logitech only */ psmouse_ret_t (*protocol_handler)(struct psmouse *psmouse, struct pt_regs *regs); @@ -62,6 +68,7 @@ struct psmouse { int (*reconnect)(struct psmouse *psmouse); void (*disconnect)(struct psmouse *psmouse); + int (*poll)(struct psmouse *psmouse); void (*pt_activate)(struct psmouse *psmouse); void (*pt_deactivate)(struct psmouse *psmouse); diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index 97cdfd6acac..2051bec2c39 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -652,6 +652,8 @@ int synaptics_init(struct psmouse *psmouse) psmouse->disconnect = synaptics_disconnect; psmouse->reconnect = synaptics_reconnect; psmouse->pktsize = 6; + /* Synaptics can usually stay in sync without extra help */ + psmouse->resync_time = 0; if (SYN_CAP_PASS_THROUGH(priv->capabilities)) synaptics_pt_create(psmouse); diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c index 2d0af44ac4b..81fd7a97a93 100644 --- a/drivers/input/mousedev.c +++ b/drivers/input/mousedev.c @@ -40,15 +40,15 @@ MODULE_LICENSE("GPL"); #endif static int xres = CONFIG_INPUT_MOUSEDEV_SCREEN_X; -module_param(xres, uint, 0); +module_param(xres, uint, 0644); MODULE_PARM_DESC(xres, "Horizontal screen resolution"); static int yres = CONFIG_INPUT_MOUSEDEV_SCREEN_Y; -module_param(yres, uint, 0); +module_param(yres, uint, 0644); MODULE_PARM_DESC(yres, "Vertical screen resolution"); static unsigned tap_time = 200; -module_param(tap_time, uint, 0); +module_param(tap_time, uint, 0644); MODULE_PARM_DESC(tap_time, "Tap time for touchpads in absolute mode (msecs)"); struct mousedev_hw_data { @@ -155,7 +155,7 @@ static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, switch (code) { case ABS_X: size = dev->absmax[ABS_X] - dev->absmin[ABS_X]; - if (size == 0) size = xres; + if (size == 0) size = xres ? : 1; if (value > dev->absmax[ABS_X]) value = dev->absmax[ABS_X]; if (value < dev->absmin[ABS_X]) value = dev->absmin[ABS_X]; mousedev->packet.x = ((value - dev->absmin[ABS_X]) * xres) / size; @@ -164,7 +164,7 @@ static void mousedev_abs_event(struct input_dev *dev, struct mousedev *mousedev, case ABS_Y: size = dev->absmax[ABS_Y] - dev->absmin[ABS_Y]; - if (size == 0) size = yres; + if (size == 0) size = yres ? : 1; if (value > dev->absmax[ABS_Y]) value = dev->absmax[ABS_Y]; if (value < dev->absmin[ABS_Y]) value = dev->absmin[ABS_Y]; mousedev->packet.y = yres - ((value - dev->absmin[ABS_Y]) * yres) / size; diff --git a/drivers/input/serio/ambakmi.c b/drivers/input/serio/ambakmi.c index 9b1ab5e7a98..3df5eedf8f3 100644 --- a/drivers/input/serio/ambakmi.c +++ b/drivers/input/serio/ambakmi.c @@ -19,12 +19,12 @@ #include <linux/delay.h> #include <linux/slab.h> #include <linux/err.h> +#include <linux/amba/bus.h> +#include <linux/amba/kmi.h> +#include <linux/clk.h> #include <asm/io.h> #include <asm/irq.h> -#include <asm/hardware/amba.h> -#include <asm/hardware/amba_kmi.h> -#include <asm/hardware/clock.h> #define KMI_BASE (kmi->base) @@ -72,13 +72,9 @@ static int amba_kmi_open(struct serio *io) unsigned int divisor; int ret; - ret = clk_use(kmi->clk); - if (ret) - goto out; - ret = clk_enable(kmi->clk); if (ret) - goto clk_unuse; + goto out; divisor = clk_get_rate(kmi->clk) / 8000000 - 1; writeb(divisor, KMICLKDIV); @@ -97,8 +93,6 @@ static int amba_kmi_open(struct serio *io) clk_disable: clk_disable(kmi->clk); - clk_unuse: - clk_unuse(kmi->clk); out: return ret; } @@ -111,7 +105,6 @@ static void amba_kmi_close(struct serio *io) free_irq(kmi->irq, kmi); clk_disable(kmi->clk); - clk_unuse(kmi->clk); } static int amba_kmi_probe(struct amba_device *dev, void *id) diff --git a/drivers/input/serio/ct82c710.c b/drivers/input/serio/ct82c710.c index 4da6c86b5d7..096b6a0b5cc 100644 --- a/drivers/input/serio/ct82c710.c +++ b/drivers/input/serio/ct82c710.c @@ -154,7 +154,7 @@ static int ct82c710_write(struct serio *port, unsigned char c) * See if we can find a 82C710 device. Read mouse address. */ -static int __init ct82c710_probe(void) +static int __init ct82c710_detect(void) { outb_p(0x55, 0x2fa); /* Any value except 9, ff or 36 */ outb_p(0xaa, 0x3fa); /* Inverse of 55 */ @@ -163,7 +163,7 @@ static int __init ct82c710_probe(void) outb_p(0x1b, 0x2fa); /* Inverse of e4 */ outb_p(0x0f, 0x390); /* Write index */ if (inb_p(0x391) != 0xe4) /* Config address found? */ - return -1; /* No: no 82C710 here */ + return -ENODEV; /* No: no 82C710 here */ outb_p(0x0d, 0x390); /* Write index */ ct82c710_iores.start = inb_p(0x391) << 2; /* Get mouse I/O address */ @@ -175,51 +175,88 @@ static int __init ct82c710_probe(void) return 0; } -static struct serio * __init ct82c710_allocate_port(void) +static int __devinit ct82c710_probe(struct platform_device *dev) { - struct serio *serio; - - serio = kmalloc(sizeof(struct serio), GFP_KERNEL); - if (serio) { - memset(serio, 0, sizeof(struct serio)); - serio->id.type = SERIO_8042; - serio->open = ct82c710_open; - serio->close = ct82c710_close; - serio->write = ct82c710_write; - serio->dev.parent = &ct82c710_device->dev; - strlcpy(serio->name, "C&T 82c710 mouse port", sizeof(serio->name)); - snprintf(serio->phys, sizeof(serio->phys), "isa%04lx/serio0", CT82C710_DATA); - } + ct82c710_port = kzalloc(sizeof(struct serio), GFP_KERNEL); + if (!ct82c710_port) + return -ENOMEM; + + ct82c710_port->id.type = SERIO_8042; + ct82c710_port->dev.parent = &dev->dev; + ct82c710_port->open = ct82c710_open; + ct82c710_port->close = ct82c710_close; + ct82c710_port->write = ct82c710_write; + strlcpy(ct82c710_port->name, "C&T 82c710 mouse port", + sizeof(ct82c710_port->name)); + snprintf(ct82c710_port->phys, sizeof(ct82c710_port->phys), + "isa%04lx/serio0", CT82C710_DATA); + + serio_register_port(ct82c710_port); + + return 0; +} + +static int __devexit ct82c710_remove(struct platform_device *dev) +{ + serio_unregister_port(ct82c710_port); - return serio; + return 0; } +static struct platform_driver ct82c710_driver = { + .driver = { + .name = "ct82c710", + .owner = THIS_MODULE, + }, + .probe = ct82c710_probe, + .remove = __devexit_p(ct82c710_remove), +}; + + static int __init ct82c710_init(void) { - if (ct82c710_probe()) - return -ENODEV; + int error; - ct82c710_device = platform_device_register_simple("ct82c710", -1, &ct82c710_iores, 1); - if (IS_ERR(ct82c710_device)) - return PTR_ERR(ct82c710_device); + error = ct82c710_detect(); + if (error) + return error; - if (!(ct82c710_port = ct82c710_allocate_port())) { - platform_device_unregister(ct82c710_device); - return -ENOMEM; + error = platform_driver_register(&ct82c710_driver); + if (error) + return error; + + ct82c710_device = platform_device_alloc("ct82c710", -1); + if (!ct82c710_device) { + error = -ENOMEM; + goto err_unregister_driver; } + error = platform_device_add_resources(ct82c710_device, &ct82c710_iores, 1); + if (error) + goto err_free_device; + + error = platform_device_add(ct82c710_device); + if (error) + goto err_free_device; + serio_register_port(ct82c710_port); printk(KERN_INFO "serio: C&T 82c710 mouse port at %#lx irq %d\n", CT82C710_DATA, CT82C710_IRQ); return 0; + + err_free_device: + platform_device_put(ct82c710_device); + err_unregister_driver: + platform_driver_unregister(&ct82c710_driver); + return error; } static void __exit ct82c710_exit(void) { - serio_unregister_port(ct82c710_port); platform_device_unregister(ct82c710_device); + platform_driver_unregister(&ct82c710_driver); } module_init(ct82c710_init); diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h index 273bb3b08cf..a4c6f352272 100644 --- a/drivers/input/serio/i8042-x86ia64io.h +++ b/drivers/input/serio/i8042-x86ia64io.h @@ -84,6 +84,14 @@ static struct dmi_system_id __initdata i8042_dmi_noloop_table[] = { DMI_MATCH(DMI_PRODUCT_VERSION, "DL760"), }, }, + { + .ident = "OQO Model 01", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "OQO"), + DMI_MATCH(DMI_PRODUCT_NAME, "ZEPTO"), + DMI_MATCH(DMI_PRODUCT_VERSION, "00"), + }, + }, { } }; @@ -158,6 +166,20 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Sentia"), }, }, + { + .ident = "Sharp Actius MM20", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SHARP"), + DMI_MATCH(DMI_PRODUCT_NAME, "PC-MM20 Series"), + }, + }, + { + .ident = "Sony Vaio FS-115b", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FS115B"), + }, + }, { } }; diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c index ac86c1d1d83..a7d91d5356a 100644 --- a/drivers/input/serio/i8042.c +++ b/drivers/input/serio/i8042.c @@ -572,7 +572,7 @@ static int i8042_enable_mux_ports(void) * LCS/Telegraphics. */ -static int __init i8042_check_mux(void) +static int __devinit i8042_check_mux(void) { unsigned char mux_version; @@ -600,7 +600,7 @@ static int __init i8042_check_mux(void) * the presence of an AUX interface. */ -static int __init i8042_check_aux(void) +static int __devinit i8042_check_aux(void) { unsigned char param; static int i8042_check_aux_cookie; @@ -678,7 +678,7 @@ static int __init i8042_check_aux(void) * registers it, and reports to the user. */ -static int __init i8042_port_register(struct i8042_port *port) +static int __devinit i8042_port_register(struct i8042_port *port) { i8042_ctr &= ~port->disable; @@ -956,7 +956,6 @@ static int i8042_resume(struct platform_device *dev) panic_blink = i8042_panic_blink; return 0; - } /* @@ -969,16 +968,7 @@ static void i8042_shutdown(struct platform_device *dev) i8042_controller_cleanup(); } -static struct platform_driver i8042_driver = { - .suspend = i8042_suspend, - .resume = i8042_resume, - .shutdown = i8042_shutdown, - .driver = { - .name = "i8042", - }, -}; - -static int __init i8042_create_kbd_port(void) +static int __devinit i8042_create_kbd_port(void) { struct serio *serio; struct i8042_port *port = &i8042_ports[I8042_KBD_PORT_NO]; @@ -1003,7 +993,7 @@ static int __init i8042_create_kbd_port(void) return i8042_port_register(port); } -static int __init i8042_create_aux_port(void) +static int __devinit i8042_create_aux_port(void) { struct serio *serio; struct i8042_port *port = &i8042_ports[I8042_AUX_PORT_NO]; @@ -1028,7 +1018,7 @@ static int __init i8042_create_aux_port(void) return i8042_port_register(port); } -static int __init i8042_create_mux_port(int index) +static int __devinit i8042_create_mux_port(int index) { struct serio *serio; struct i8042_port *port = &i8042_ports[I8042_MUX_PORT_NO + index]; @@ -1057,37 +1047,16 @@ static int __init i8042_create_mux_port(int index) return i8042_port_register(port); } -static int __init i8042_init(void) +static int __devinit i8042_probe(struct platform_device *dev) { int i, have_ports = 0; int err; - dbg_init(); - init_timer(&i8042_timer); i8042_timer.function = i8042_timer_func; - err = i8042_platform_init(); - if (err) - return err; - - i8042_ports[I8042_AUX_PORT_NO].irq = I8042_AUX_IRQ; - i8042_ports[I8042_KBD_PORT_NO].irq = I8042_KBD_IRQ; - - if (i8042_controller_init()) { - err = -ENODEV; - goto err_platform_exit; - } - - err = platform_driver_register(&i8042_driver); - if (err) - goto err_controller_cleanup; - - i8042_platform_device = platform_device_register_simple("i8042", -1, NULL, 0); - if (IS_ERR(i8042_platform_device)) { - err = PTR_ERR(i8042_platform_device); - goto err_unregister_driver; - } + if (i8042_controller_init()) + return -ENODEV; if (!i8042_noaux && !i8042_check_aux()) { if (!i8042_nomux && !i8042_check_mux()) { @@ -1113,30 +1082,23 @@ static int __init i8042_init(void) if (!have_ports) { err = -ENODEV; - goto err_unregister_device; + goto err_controller_cleanup; } mod_timer(&i8042_timer, jiffies + I8042_POLL_PERIOD); - return 0; err_unregister_ports: for (i = 0; i < I8042_NUM_PORTS; i++) if (i8042_ports[i].serio) serio_unregister_port(i8042_ports[i].serio); - err_unregister_device: - platform_device_unregister(i8042_platform_device); - err_unregister_driver: - platform_driver_unregister(&i8042_driver); err_controller_cleanup: i8042_controller_cleanup(); - err_platform_exit: - i8042_platform_exit(); return err; } -static void __exit i8042_exit(void) +static int __devexit i8042_remove(struct platform_device *dev) { int i; @@ -1148,6 +1110,62 @@ static void __exit i8042_exit(void) del_timer_sync(&i8042_timer); + return 0; +} + +static struct platform_driver i8042_driver = { + .driver = { + .name = "i8042", + .owner = THIS_MODULE, + }, + .probe = i8042_probe, + .remove = __devexit_p(i8042_remove), + .suspend = i8042_suspend, + .resume = i8042_resume, + .shutdown = i8042_shutdown, +}; + +static int __init i8042_init(void) +{ + int err; + + dbg_init(); + + err = i8042_platform_init(); + if (err) + return err; + + i8042_ports[I8042_AUX_PORT_NO].irq = I8042_AUX_IRQ; + i8042_ports[I8042_KBD_PORT_NO].irq = I8042_KBD_IRQ; + + err = platform_driver_register(&i8042_driver); + if (err) + goto err_platform_exit; + + i8042_platform_device = platform_device_alloc("i8042", -1); + if (!i8042_platform_device) { + err = -ENOMEM; + goto err_unregister_driver; + } + + err = platform_device_add(i8042_platform_device); + if (err) + goto err_free_device; + + return 0; + + err_free_device: + platform_device_put(i8042_platform_device); + err_unregister_driver: + platform_driver_unregister(&i8042_driver); + err_platform_exit: + i8042_platform_exit(); + + return err; +} + +static void __exit i8042_exit(void) +{ platform_device_unregister(i8042_platform_device); platform_driver_unregister(&i8042_driver); diff --git a/drivers/input/serio/maceps2.c b/drivers/input/serio/maceps2.c index d857f7081ad..f08a5d0cd5f 100644 --- a/drivers/input/serio/maceps2.c +++ b/drivers/input/serio/maceps2.c @@ -118,13 +118,12 @@ static void maceps2_close(struct serio *dev) } -static struct serio * __init maceps2_allocate_port(int idx) +static struct serio * __devinit maceps2_allocate_port(int idx) { struct serio *serio; - serio = kmalloc(sizeof(struct serio), GFP_KERNEL); + serio = kzalloc(sizeof(struct serio), GFP_KERNEL); if (serio) { - memset(serio, 0, sizeof(struct serio)); serio->id.type = SERIO_8042; serio->write = maceps2_write; serio->open = maceps2_open; @@ -138,24 +137,13 @@ static struct serio * __init maceps2_allocate_port(int idx) return serio; } - -static int __init maceps2_init(void) +static int __devinit maceps2_probe(struct platform_device *dev) { - maceps2_device = platform_device_register_simple("maceps2", -1, NULL, 0); - if (IS_ERR(maceps2_device)) - return PTR_ERR(maceps2_device); - - port_data[0].port = &mace->perif.ps2.keyb; - port_data[0].irq = MACEISA_KEYB_IRQ; - port_data[1].port = &mace->perif.ps2.mouse; - port_data[1].irq = MACEISA_MOUSE_IRQ; - maceps2_port[0] = maceps2_allocate_port(0); maceps2_port[1] = maceps2_allocate_port(1); if (!maceps2_port[0] || !maceps2_port[1]) { kfree(maceps2_port[0]); kfree(maceps2_port[1]); - platform_device_unregister(maceps2_device); return -ENOMEM; } @@ -165,11 +153,59 @@ static int __init maceps2_init(void) return 0; } -static void __exit maceps2_exit(void) +static int __devexit maceps2_remove(struct platform_device *dev) { serio_unregister_port(maceps2_port[0]); serio_unregister_port(maceps2_port[1]); + + return 0; +} + +static struct platform_driver maceps2_driver = { + .driver = { + .name = "maceps2", + .owner = THIS_MODULE, + }, + .probe = maceps2_probe, + .remove = __devexit_p(maceps2_remove), +}; + +static int __init maceps2_init(void) +{ + int error; + + error = platform_driver_register(&maceps2_driver); + if (error) + return error; + + maceps2_device = platform_device_alloc("maceps2", -1); + if (!maceps2_device) { + error = -ENOMEM; + goto err_unregister_driver; + } + + port_data[0].port = &mace->perif.ps2.keyb; + port_data[0].irq = MACEISA_KEYB_IRQ; + port_data[1].port = &mace->perif.ps2.mouse; + port_data[1].irq = MACEISA_MOUSE_IRQ; + + error = platform_device_add(maceps2_device); + if (error) + goto err_free_device; + + return 0; + + err_free_device: + platform_device_put(maceps2_device); + err_unregister_driver: + platform_driver_unregister(&maceps2_driver); + return error; +} + +static void __exit maceps2_exit(void) +{ platform_device_unregister(maceps2_device); + platform_driver_unregister(&maceps2_driver); } module_init(maceps2_init); diff --git a/drivers/input/serio/q40kbd.c b/drivers/input/serio/q40kbd.c index b44d255596c..d3827c5fe11 100644 --- a/drivers/input/serio/q40kbd.c +++ b/drivers/input/serio/q40kbd.c @@ -75,13 +75,13 @@ static irqreturn_t q40kbd_interrupt(int irq, void *dev_id, struct pt_regs *regs) static void q40kbd_flush(void) { - int maxread = 100; + int maxread = 100; unsigned long flags; spin_lock_irqsave(&q40kbd_lock, flags); - while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))) - master_inb(KEYCODE_REG); + while (maxread-- && (Q40_IRQ_KEYB_MASK & master_inb(INTERRUPT_REG))) + master_inb(KEYCODE_REG); spin_unlock_irqrestore(&q40kbd_lock, flags); } @@ -97,14 +97,14 @@ static int q40kbd_open(struct serio *port) if (request_irq(Q40_IRQ_KEYBOARD, q40kbd_interrupt, 0, "q40kbd", NULL)) { printk(KERN_ERR "q40kbd.c: Can't get irq %d.\n", Q40_IRQ_KEYBOARD); - return -1; + return -EBUSY; } - /* off we go */ - master_outb(-1, KEYBOARD_UNLOCK_REG); - master_outb(1, KEY_IRQ_ENABLE_REG); + /* off we go */ + master_outb(-1, KEYBOARD_UNLOCK_REG); + master_outb(1, KEY_IRQ_ENABLE_REG); - return 0; + return 0; } static void q40kbd_close(struct serio *port) @@ -116,48 +116,73 @@ static void q40kbd_close(struct serio *port) q40kbd_flush(); } -static struct serio * __init q40kbd_allocate_port(void) +static int __devinit q40kbd_probe(struct platform_device *dev) { - struct serio *serio; - - serio = kmalloc(sizeof(struct serio), GFP_KERNEL); - if (serio) { - memset(serio, 0, sizeof(struct serio)); - serio->id.type = SERIO_8042; - serio->open = q40kbd_open; - serio->close = q40kbd_close; - serio->dev.parent = &q40kbd_device->dev; - strlcpy(serio->name, "Q40 Kbd Port", sizeof(serio->name)); - strlcpy(serio->phys, "Q40", sizeof(serio->phys)); - } + q40kbd_port = kzalloc(sizeof(struct serio), GFP_KERNEL); + if (!q40kbd_port) + return -ENOMEM; + + q40kbd_port->id.type = SERIO_8042; + q40kbd_port->open = q40kbd_open; + q40kbd_port->close = q40kbd_close; + q40kbd_port->dev.parent = &dev->dev; + strlcpy(q40kbd_port->name, "Q40 Kbd Port", sizeof(q40kbd_port->name)); + strlcpy(q40kbd_port->phys, "Q40", sizeof(q40kbd_port->phys)); + + serio_register_port(q40kbd_port); + printk(KERN_INFO "serio: Q40 kbd registered\n"); - return serio; + return 0; } +static int __devexit q40kbd_remove(struct platform_device *dev) +{ + serio_unregister_port(q40kbd_port); + + return 0; +} + +static struct platform_driver q40kbd_driver = { + .driver = { + .name = "q40kbd", + .owner = THIS_MODULE, + }, + .probe = q40kbd_probe, + .remove = __devexit_p(q40kbd_remove), +}; + static int __init q40kbd_init(void) { + int error; + if (!MACH_IS_Q40) return -EIO; - q40kbd_device = platform_device_register_simple("q40kbd", -1, NULL, 0); - if (IS_ERR(q40kbd_device)) - return PTR_ERR(q40kbd_device); + error = platform_driver_register(&q40kbd_driver); + if (error) + return error; - if (!(q40kbd_port = q40kbd_allocate_port())) { - platform_device_unregister(q40kbd_device); - return -ENOMEM; - } + q40kbd_device = platform_device_alloc("q40kbd", -1); + if (!q40kbd_device) + goto err_unregister_driver; - serio_register_port(q40kbd_port); - printk(KERN_INFO "serio: Q40 kbd registered\n"); + error = platform_device_add(q40kbd_device); + if (error) + goto err_free_device; return 0; + + err_free_device: + platform_device_put(q40kbd_device); + err_unregister_driver: + platform_driver_unregister(&q40kbd_driver); + return error; } static void __exit q40kbd_exit(void) { - serio_unregister_port(q40kbd_port); platform_device_unregister(q40kbd_device); + platform_driver_unregister(&q40kbd_driver); } module_init(q40kbd_init); diff --git a/drivers/input/serio/sa1111ps2.c b/drivers/input/serio/sa1111ps2.c index 3f0df3330fb..ebd9976fc81 100644 --- a/drivers/input/serio/sa1111ps2.c +++ b/drivers/input/serio/sa1111ps2.c @@ -20,7 +20,6 @@ #include <linux/spinlock.h> #include <asm/io.h> -#include <asm/irq.h> #include <asm/system.h> #include <asm/hardware/sa1111.h> diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c index 8e530cc970e..2f76813c3a6 100644 --- a/drivers/input/serio/serio.c +++ b/drivers/input/serio/serio.c @@ -59,9 +59,7 @@ static DECLARE_MUTEX(serio_sem); static LIST_HEAD(serio_list); -static struct bus_type serio_bus = { - .name = "serio", -}; +static struct bus_type serio_bus; static void serio_add_port(struct serio *serio); static void serio_destroy_port(struct serio *serio); @@ -750,11 +748,15 @@ static int serio_driver_remove(struct device *dev) return 0; } +static struct bus_type serio_bus = { + .name = "serio", + .probe = serio_driver_probe, + .remove = serio_driver_remove, +}; + void __serio_register_driver(struct serio_driver *drv, struct module *owner) { drv->driver.bus = &serio_bus; - drv->driver.probe = serio_driver_probe; - drv->driver.remove = serio_driver_remove; serio_queue_event(drv, owner, SERIO_REGISTER_DRIVER); } diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c index 1bd88fca054..54a680cc704 100644 --- a/drivers/input/serio/serport.c +++ b/drivers/input/serio/serport.c @@ -96,6 +96,7 @@ static int serport_ldisc_open(struct tty_struct *tty) init_waitqueue_head(&serport->wait); tty->disc_data = serport; + tty->receive_room = 256; set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); return 0; @@ -140,17 +141,6 @@ out: } /* - * serport_ldisc_room() reports how much room we do have for receiving data. - * Although we in fact have infinite room, we need to specify some value - * here, and 256 seems to be reasonable. - */ - -static int serport_ldisc_room(struct tty_struct *tty) -{ - return 256; -} - -/* * serport_ldisc_read() just waits indefinitely if everything goes well. * However, when the serio driver closes the serio port, it finishes, * returning 0 characters. @@ -237,7 +227,6 @@ static struct tty_ldisc serport_ldisc = { .read = serport_ldisc_read, .ioctl = serport_ldisc_ioctl, .receive_buf = serport_ldisc_receive, - .receive_room = serport_ldisc_room, .write_wakeup = serport_ldisc_write_wakeup }; diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 21d55ed4b88..b1b14f8d4dd 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -11,6 +11,19 @@ menuconfig INPUT_TOUCHSCREEN if INPUT_TOUCHSCREEN +config TOUCHSCREEN_ADS7846 + tristate "ADS 7846 based touchscreens" + depends on SPI_MASTER + help + Say Y here if you have a touchscreen interface using the + ADS7846 controller, and your board-specific initialization + code includes that in its table of SPI devices. + + If unsure, say N (but it's safe to say "Y"). + + To compile this driver as a module, choose M here: the + module will be called ads7846. + config TOUCHSCREEN_BITSY tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" depends on SA1100_BITSY @@ -85,7 +98,7 @@ config TOUCHSCREEN_MK712 config TOUCHSCREEN_HP600 tristate "HP Jornada 680/690 touchscreen" - depends on SH_HP600 && SH_ADC + depends on SH_HP6XX && SH_ADC help Say Y here if you have a HP Jornada 680 or 690 and want to support the built-in touchscreen. diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 6842869c9a2..5e5557c4312 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -4,6 +4,7 @@ # Each configuration option enables a list of files. +obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c new file mode 100644 index 00000000000..dd8c6a9ffc7 --- /dev/null +++ b/drivers/input/touchscreen/ads7846.c @@ -0,0 +1,625 @@ +/* + * ADS7846 based touchscreen and sensor driver + * + * Copyright (c) 2005 David Brownell + * + * Using code from: + * - corgi_ts.c + * Copyright (C) 2004-2005 Richard Purdie + * - omap_ts.[hc], ads7846.h, ts_osk.c + * Copyright (C) 2002 MontaVista Software + * Copyright (C) 2004 Texas Instruments + * Copyright (C) 2005 Dirk Behme + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include <linux/device.h> +#include <linux/init.h> +#include <linux/delay.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/slab.h> +#include <linux/spi/spi.h> +#include <linux/spi/ads7846.h> + +#ifdef CONFIG_ARM +#include <asm/mach-types.h> +#ifdef CONFIG_ARCH_OMAP +#include <asm/arch/gpio.h> +#endif + +#else +#define set_irq_type(irq,type) do{}while(0) +#endif + + +/* + * This code has been lightly tested on an ads7846. + * Support for ads7843 and ads7845 has only been stubbed in. + * + * Not yet done: investigate the values reported. Are x/y/pressure + * event values sane enough for X11? How accurate are the temperature + * and voltage readings? (System-specific calibration should support + * accuracy of 0.3 degrees C; otherwise it's 2.0 degrees.) + * + * app note sbaa036 talks in more detail about accurate sampling... + * that ought to help in situations like LCDs inducing noise (which + * can also be helped by using synch signals) and more generally. + */ + +#define TS_POLL_PERIOD msecs_to_jiffies(10) + +struct ts_event { + /* For portability, we can't read 12 bit values using SPI (which + * would make the controller deliver them as native byteorder u16 + * with msbs zeroed). Instead, we read them as two 8-byte values, + * which need byteswapping then range adjustment. + */ + __be16 x; + __be16 y; + __be16 z1, z2; +}; + +struct ads7846 { + struct input_dev input; + char phys[32]; + + struct spi_device *spi; + u16 model; + u16 vref_delay_usecs; + u16 x_plate_ohms; + + struct ts_event tc; + + struct spi_transfer xfer[8]; + struct spi_message msg; + + spinlock_t lock; + struct timer_list timer; /* P: lock */ + unsigned pendown:1; /* P: lock */ + unsigned pending:1; /* P: lock */ +// FIXME remove "irq_disabled" + unsigned irq_disabled:1; /* P: lock */ +}; + +/* leave chip selected when we're done, for quicker re-select? */ +#if 0 +#define CS_CHANGE(xfer) ((xfer).cs_change = 1) +#else +#define CS_CHANGE(xfer) ((xfer).cs_change = 0) +#endif + +/*--------------------------------------------------------------------------*/ + +/* The ADS7846 has touchscreen and other sensors. + * Earlier ads784x chips are somewhat compatible. + */ +#define ADS_START (1 << 7) +#define ADS_A2A1A0_d_y (1 << 4) /* differential */ +#define ADS_A2A1A0_d_z1 (3 << 4) /* differential */ +#define ADS_A2A1A0_d_z2 (4 << 4) /* differential */ +#define ADS_A2A1A0_d_x (5 << 4) /* differential */ +#define ADS_A2A1A0_temp0 (0 << 4) /* non-differential */ +#define ADS_A2A1A0_vbatt (2 << 4) /* non-differential */ +#define ADS_A2A1A0_vaux (6 << 4) /* non-differential */ +#define ADS_A2A1A0_temp1 (7 << 4) /* non-differential */ +#define ADS_8_BIT (1 << 3) +#define ADS_12_BIT (0 << 3) +#define ADS_SER (1 << 2) /* non-differential */ +#define ADS_DFR (0 << 2) /* differential */ +#define ADS_PD10_PDOWN (0 << 0) /* lowpower mode + penirq */ +#define ADS_PD10_ADC_ON (1 << 0) /* ADC on */ +#define ADS_PD10_REF_ON (2 << 0) /* vREF on + penirq */ +#define ADS_PD10_ALL_ON (3 << 0) /* ADC + vREF on */ + +#define MAX_12BIT ((1<<12)-1) + +/* leave ADC powered up (disables penirq) between differential samples */ +#define READ_12BIT_DFR(x) (ADS_START | ADS_A2A1A0_d_ ## x \ + | ADS_12_BIT | ADS_DFR) + +static const u8 read_y = READ_12BIT_DFR(y) | ADS_PD10_ADC_ON; +static const u8 read_z1 = READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON; +static const u8 read_z2 = READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON; +static const u8 read_x = READ_12BIT_DFR(x) | ADS_PD10_PDOWN; /* LAST */ + +/* single-ended samples need to first power up reference voltage; + * we leave both ADC and VREF powered + */ +#define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \ + | ADS_12_BIT | ADS_SER) + +static const u8 ref_on = READ_12BIT_DFR(x) | ADS_PD10_ALL_ON; +static const u8 ref_off = READ_12BIT_DFR(y) | ADS_PD10_PDOWN; + +/*--------------------------------------------------------------------------*/ + +/* + * Non-touchscreen sensors only use single-ended conversions. + */ + +struct ser_req { + u8 command; + u16 scratch; + __be16 sample; + struct spi_message msg; + struct spi_transfer xfer[6]; +}; + +static int ads7846_read12_ser(struct device *dev, unsigned command) +{ + struct spi_device *spi = to_spi_device(dev); + struct ads7846 *ts = dev_get_drvdata(dev); + struct ser_req *req = kzalloc(sizeof *req, SLAB_KERNEL); + int status; + int sample; + int i; + + if (!req) + return -ENOMEM; + + INIT_LIST_HEAD(&req->msg.transfers); + + /* activate reference, so it has time to settle; */ + req->xfer[0].tx_buf = &ref_on; + req->xfer[0].len = 1; + req->xfer[1].rx_buf = &req->scratch; + req->xfer[1].len = 2; + + /* + * for external VREF, 0 usec (and assume it's always on); + * for 1uF, use 800 usec; + * no cap, 100 usec. + */ + req->xfer[1].delay_usecs = ts->vref_delay_usecs; + + /* take sample */ + req->command = (u8) command; + req->xfer[2].tx_buf = &req->command; + req->xfer[2].len = 1; + req->xfer[3].rx_buf = &req->sample; + req->xfer[3].len = 2; + + /* REVISIT: take a few more samples, and compare ... */ + + /* turn off reference */ + req->xfer[4].tx_buf = &ref_off; + req->xfer[4].len = 1; + req->xfer[5].rx_buf = &req->scratch; + req->xfer[5].len = 2; + + CS_CHANGE(req->xfer[5]); + + /* group all the transfers together, so we can't interfere with + * reading touchscreen state; disable penirq while sampling + */ + for (i = 0; i < 6; i++) + spi_message_add_tail(&req->xfer[i], &req->msg); + + disable_irq(spi->irq); + status = spi_sync(spi, &req->msg); + enable_irq(spi->irq); + + if (req->msg.status) + status = req->msg.status; + sample = be16_to_cpu(req->sample); + sample = sample >> 4; + kfree(req); + + return status ? status : sample; +} + +#define SHOW(name) static ssize_t \ +name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ +{ \ + ssize_t v = ads7846_read12_ser(dev, \ + READ_12BIT_SER(name) | ADS_PD10_ALL_ON); \ + if (v < 0) \ + return v; \ + return sprintf(buf, "%u\n", (unsigned) v); \ +} \ +static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL); + +SHOW(temp0) +SHOW(temp1) +SHOW(vaux) +SHOW(vbatt) + +/*--------------------------------------------------------------------------*/ + +/* + * PENIRQ only kicks the timer. The timer only reissues the SPI transfer, + * to retrieve touchscreen status. + * + * The SPI transfer completion callback does the real work. It reports + * touchscreen events and reactivates the timer (or IRQ) as appropriate. + */ + +static void ads7846_rx(void *ads) +{ + struct ads7846 *ts = ads; + unsigned Rt; + unsigned sync = 0; + u16 x, y, z1, z2; + unsigned long flags; + + /* adjust: 12 bit samples (left aligned), built from + * two 8 bit values writen msb-first. + */ + x = be16_to_cpu(ts->tc.x) >> 4; + y = be16_to_cpu(ts->tc.y) >> 4; + z1 = be16_to_cpu(ts->tc.z1) >> 4; + z2 = be16_to_cpu(ts->tc.z2) >> 4; + + /* range filtering */ + if (x == MAX_12BIT) + x = 0; + + if (x && z1 && ts->spi->dev.power.power_state.event == PM_EVENT_ON) { + /* compute touch pressure resistance using equation #2 */ + Rt = z2; + Rt -= z1; + Rt *= x; + Rt *= ts->x_plate_ohms; + Rt /= z1; + Rt = (Rt + 2047) >> 12; + } else + Rt = 0; + + /* NOTE: "pendown" is inferred from pressure; we don't rely on + * being able to check nPENIRQ status, or "friendly" trigger modes + * (both-edges is much better than just-falling or low-level). + * + * REVISIT: some boards may require reading nPENIRQ; it's + * needed on 7843. and 7845 reads pressure differently... + * + * REVISIT: the touchscreen might not be connected; this code + * won't notice that, even if nPENIRQ never fires ... + */ + if (!ts->pendown && Rt != 0) { + input_report_key(&ts->input, BTN_TOUCH, 1); + sync = 1; + } else if (ts->pendown && Rt == 0) { + input_report_key(&ts->input, BTN_TOUCH, 0); + sync = 1; + } + + if (Rt) { + input_report_abs(&ts->input, ABS_X, x); + input_report_abs(&ts->input, ABS_Y, y); + input_report_abs(&ts->input, ABS_PRESSURE, Rt); + sync = 1; + } + if (sync) + input_sync(&ts->input); + +#ifdef VERBOSE + if (Rt || ts->pendown) + pr_debug("%s: %d/%d/%d%s\n", ts->spi->dev.bus_id, + x, y, Rt, Rt ? "" : " UP"); +#endif + + /* don't retrigger while we're suspended */ + spin_lock_irqsave(&ts->lock, flags); + + ts->pendown = (Rt != 0); + ts->pending = 0; + + if (ts->spi->dev.power.power_state.event == PM_EVENT_ON) { + if (ts->pendown) + mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD); + else if (ts->irq_disabled) { + ts->irq_disabled = 0; + enable_irq(ts->spi->irq); + } + } + + spin_unlock_irqrestore(&ts->lock, flags); +} + +static void ads7846_timer(unsigned long handle) +{ + struct ads7846 *ts = (void *)handle; + int status = 0; + unsigned long flags; + + spin_lock_irqsave(&ts->lock, flags); + if (!ts->pending) { + ts->pending = 1; + if (!ts->irq_disabled) { + ts->irq_disabled = 1; + disable_irq(ts->spi->irq); + } + status = spi_async(ts->spi, &ts->msg); + if (status) + dev_err(&ts->spi->dev, "spi_async --> %d\n", + status); + } + spin_unlock_irqrestore(&ts->lock, flags); +} + +static irqreturn_t ads7846_irq(int irq, void *handle, struct pt_regs *regs) +{ + ads7846_timer((unsigned long) handle); + return IRQ_HANDLED; +} + +/*--------------------------------------------------------------------------*/ + +static int +ads7846_suspend(struct spi_device *spi, pm_message_t message) +{ + struct ads7846 *ts = dev_get_drvdata(&spi->dev); + unsigned long flags; + + spin_lock_irqsave(&ts->lock, flags); + + spi->dev.power.power_state = message; + + /* are we waiting for IRQ, or polling? */ + if (!ts->pendown) { + if (!ts->irq_disabled) { + ts->irq_disabled = 1; + disable_irq(ts->spi->irq); + } + } else { + /* polling; force a final SPI completion; + * that will clean things up neatly + */ + if (!ts->pending) + mod_timer(&ts->timer, jiffies); + + while (ts->pendown || ts->pending) { + spin_unlock_irqrestore(&ts->lock, flags); + udelay(10); + spin_lock_irqsave(&ts->lock, flags); + } + } + + /* we know the chip's in lowpower mode since we always + * leave it that way after every request + */ + + spin_unlock_irqrestore(&ts->lock, flags); + return 0; +} + +static int ads7846_resume(struct spi_device *spi) +{ + struct ads7846 *ts = dev_get_drvdata(&spi->dev); + + ts->irq_disabled = 0; + enable_irq(ts->spi->irq); + spi->dev.power.power_state = PMSG_ON; + return 0; +} + +static int __devinit ads7846_probe(struct spi_device *spi) +{ + struct ads7846 *ts; + struct ads7846_platform_data *pdata = spi->dev.platform_data; + struct spi_transfer *x; + int i; + + if (!spi->irq) { + dev_dbg(&spi->dev, "no IRQ?\n"); + return -ENODEV; + } + + if (!pdata) { + dev_dbg(&spi->dev, "no platform data?\n"); + return -ENODEV; + } + + /* don't exceed max specified sample rate */ + if (spi->max_speed_hz > (125000 * 16)) { + dev_dbg(&spi->dev, "f(sample) %d KHz?\n", + (spi->max_speed_hz/16)/1000); + return -EINVAL; + } + + /* We'd set the wordsize to 12 bits ... except that some controllers + * will then treat the 8 bit command words as 12 bits (and drop the + * four MSBs of the 12 bit result). Result: inputs must be shifted + * to discard the four garbage LSBs. + */ + + if (!(ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL))) + return -ENOMEM; + + dev_set_drvdata(&spi->dev, ts); + + ts->spi = spi; + spi->dev.power.power_state = PMSG_ON; + + init_timer(&ts->timer); + ts->timer.data = (unsigned long) ts; + ts->timer.function = ads7846_timer; + + ts->model = pdata->model ? : 7846; + ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; + ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; + + init_input_dev(&ts->input); + + ts->input.dev = &spi->dev; + ts->input.name = "ADS784x Touchscreen"; + snprintf(ts->phys, sizeof ts->phys, "%s/input0", spi->dev.bus_id); + ts->input.phys = ts->phys; + + ts->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); + ts->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); + input_set_abs_params(&ts->input, ABS_X, + pdata->x_min ? : 0, + pdata->x_max ? : MAX_12BIT, + 0, 0); + input_set_abs_params(&ts->input, ABS_Y, + pdata->y_min ? : 0, + pdata->y_max ? : MAX_12BIT, + 0, 0); + input_set_abs_params(&ts->input, ABS_PRESSURE, + pdata->pressure_min, pdata->pressure_max, 0, 0); + + input_register_device(&ts->input); + + /* set up the transfers to read touchscreen state; this assumes we + * use formula #2 for pressure, not #3. + */ + x = ts->xfer; + + /* y- still on; turn on only y+ (and ADC) */ + x->tx_buf = &read_y; + x->len = 1; + x++; + x->rx_buf = &ts->tc.y; + x->len = 2; + x++; + + /* turn y+ off, x- on; we'll use formula #2 */ + if (ts->model == 7846) { + x->tx_buf = &read_z1; + x->len = 1; + x++; + x->rx_buf = &ts->tc.z1; + x->len = 2; + x++; + + x->tx_buf = &read_z2; + x->len = 1; + x++; + x->rx_buf = &ts->tc.z2; + x->len = 2; + x++; + } + + /* turn y- off, x+ on, then leave in lowpower */ + x->tx_buf = &read_x; + x->len = 1; + x++; + x->rx_buf = &ts->tc.x; + x->len = 2; + x++; + + CS_CHANGE(x[-1]); + + for (i = 0; i < x - ts->xfer; i++) + spi_message_add_tail(&ts->xfer[i], &ts->msg); + ts->msg.complete = ads7846_rx; + ts->msg.context = ts; + + if (request_irq(spi->irq, ads7846_irq, SA_SAMPLE_RANDOM, + spi->dev.bus_id, ts)) { + dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); + input_unregister_device(&ts->input); + kfree(ts); + return -EBUSY; + } + set_irq_type(spi->irq, IRQT_FALLING); + + dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); + + /* take a first sample, leaving nPENIRQ active; avoid + * the touchscreen, in case it's not connected. + */ + (void) ads7846_read12_ser(&spi->dev, + READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); + + /* ads7843/7845 don't have temperature sensors, and + * use the other sensors a bit differently too + */ + if (ts->model == 7846) { + device_create_file(&spi->dev, &dev_attr_temp0); + device_create_file(&spi->dev, &dev_attr_temp1); + } + if (ts->model != 7845) + device_create_file(&spi->dev, &dev_attr_vbatt); + device_create_file(&spi->dev, &dev_attr_vaux); + + return 0; +} + +static int __devexit ads7846_remove(struct spi_device *spi) +{ + struct ads7846 *ts = dev_get_drvdata(&spi->dev); + + ads7846_suspend(spi, PMSG_SUSPEND); + free_irq(ts->spi->irq, ts); + if (ts->irq_disabled) + enable_irq(ts->spi->irq); + + if (ts->model == 7846) { + device_remove_file(&spi->dev, &dev_attr_temp0); + device_remove_file(&spi->dev, &dev_attr_temp1); + } + if (ts->model != 7845) + device_remove_file(&spi->dev, &dev_attr_vbatt); + device_remove_file(&spi->dev, &dev_attr_vaux); + + input_unregister_device(&ts->input); + kfree(ts); + + dev_dbg(&spi->dev, "unregistered touchscreen\n"); + return 0; +} + +static struct spi_driver ads7846_driver = { + .driver = { + .name = "ads7846", + .bus = &spi_bus_type, + .owner = THIS_MODULE, + }, + .probe = ads7846_probe, + .remove = __devexit_p(ads7846_remove), + .suspend = ads7846_suspend, + .resume = ads7846_resume, +}; + +static int __init ads7846_init(void) +{ + /* grr, board-specific init should stay out of drivers!! */ + +#ifdef CONFIG_ARCH_OMAP + if (machine_is_omap_osk()) { + /* GPIO4 = PENIRQ; GPIO6 = BUSY */ + omap_request_gpio(4); + omap_set_gpio_direction(4, 1); + omap_request_gpio(6); + omap_set_gpio_direction(6, 1); + } + // also TI 1510 Innovator, bitbanging through FPGA + // also Nokia 770 + // also Palm Tungsten T2 +#endif + + // PXA: + // also Dell Axim X50 + // also HP iPaq H191x/H192x/H415x/H435x + // also Intel Lubbock (additional to UCB1400; as temperature sensor) + // also Sharp Zaurus C7xx, C8xx (corgi/sheperd/husky) + + // Atmel at91sam9261-EK uses ads7843 + + // also various AMD Au1x00 devel boards + + return spi_register_driver(&ads7846_driver); +} +module_init(ads7846_init); + +static void __exit ads7846_exit(void) +{ + spi_unregister_driver(&ads7846_driver); + +#ifdef CONFIG_ARCH_OMAP + if (machine_is_omap_osk()) { + omap_free_gpio(4); + omap_free_gpio(6); + } +#endif + +} +module_exit(ads7846_exit); + +MODULE_DESCRIPTION("ADS7846 TouchScreen Driver"); +MODULE_LICENSE("GPL"); |