Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _SERIO_H |
| 2 | #define _SERIO_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 1999-2002 Vojtech Pavlik |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/ioctl.h> |
| 13 | |
| 14 | #define SPIOCSTYPE _IOW('q', 0x01, unsigned long) |
| 15 | |
| 16 | #ifdef __KERNEL__ |
| 17 | |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 18 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/list.h> |
| 21 | #include <linux/spinlock.h> |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/device.h> |
| 24 | #include <linux/mod_devicetable.h> |
| 25 | |
| 26 | struct serio { |
| 27 | void *port_data; |
| 28 | |
| 29 | char name[32]; |
| 30 | char phys[32]; |
| 31 | |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 32 | bool manual_bind; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | struct serio_device_id id; |
| 35 | |
| 36 | spinlock_t lock; /* protects critical sections from port's interrupt handler */ |
| 37 | |
| 38 | int (*write)(struct serio *, unsigned char); |
| 39 | int (*open)(struct serio *); |
| 40 | void (*close)(struct serio *); |
| 41 | int (*start)(struct serio *); |
| 42 | void (*stop)(struct serio *); |
| 43 | |
Dmitry Eremin-Solenikov | 0982258 | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 44 | struct serio *parent; |
| 45 | struct list_head child_node; /* Entry in parent->children list */ |
| 46 | struct list_head children; |
Jiri Kosina | 88aa010 | 2006-10-11 01:45:31 -0400 | [diff] [blame] | 47 | unsigned int depth; /* level of nesting in serio hierarchy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | struct serio_driver *drv; /* accessed from interrupt, must be protected by serio->lock and serio->sem */ |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 50 | struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | struct list_head node; |
| 55 | }; |
| 56 | #define to_serio_port(d) container_of(d, struct serio, dev) |
| 57 | |
| 58 | struct serio_driver { |
Dmitry Torokhov | ceee427 | 2010-09-13 23:53:55 -0700 | [diff] [blame] | 59 | const char *description; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Dmitry Torokhov | ceee427 | 2010-09-13 23:53:55 -0700 | [diff] [blame] | 61 | const struct serio_device_id *id_table; |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 62 | bool manual_bind; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | void (*write_wakeup)(struct serio *); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 65 | irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | int (*connect)(struct serio *, struct serio_driver *drv); |
| 67 | int (*reconnect)(struct serio *); |
| 68 | void (*disconnect)(struct serio *); |
| 69 | void (*cleanup)(struct serio *); |
| 70 | |
| 71 | struct device_driver driver; |
| 72 | }; |
| 73 | #define to_serio_driver(d) container_of(d, struct serio_driver, driver) |
| 74 | |
| 75 | int serio_open(struct serio *serio, struct serio_driver *drv); |
| 76 | void serio_close(struct serio *serio); |
| 77 | void serio_rescan(struct serio *serio); |
| 78 | void serio_reconnect(struct serio *serio); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 79 | irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | void __serio_register_port(struct serio *serio, struct module *owner); |
Paul Gortmaker | eb5589a | 2011-05-27 09:02:11 -0400 | [diff] [blame] | 82 | |
| 83 | /* use a define to avoid include chaining to get THIS_MODULE */ |
| 84 | #define serio_register_port(serio) \ |
| 85 | __serio_register_port(serio, THIS_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | void serio_unregister_port(struct serio *serio); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 88 | void serio_unregister_child_port(struct serio *serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Paul Gortmaker | eb5589a | 2011-05-27 09:02:11 -0400 | [diff] [blame] | 90 | int __must_check __serio_register_driver(struct serio_driver *drv, |
| 91 | struct module *owner, const char *mod_name); |
| 92 | |
| 93 | /* use a define to avoid include chaining to get THIS_MODULE & friends */ |
| 94 | #define serio_register_driver(drv) \ |
| 95 | __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME) |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | void serio_unregister_driver(struct serio_driver *drv); |
| 98 | |
Axel Lin | fa7f86d | 2012-04-03 23:50:15 -0700 | [diff] [blame^] | 99 | /** |
| 100 | * module_serio_driver() - Helper macro for registering a serio driver |
| 101 | * @__serio_driver: serio_driver struct |
| 102 | * |
| 103 | * Helper macro for serio drivers which do not do anything special in |
| 104 | * module init/exit. This eliminates a lot of boilerplate. Each module |
| 105 | * may only use this macro once, and calling it replaces module_init() |
| 106 | * and module_exit(). |
| 107 | */ |
| 108 | #define module_serio_driver(__serio_driver) \ |
| 109 | module_driver(__serio_driver, serio_register_driver, \ |
| 110 | serio_unregister_driver) |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | static inline int serio_write(struct serio *serio, unsigned char data) |
| 113 | { |
| 114 | if (serio->write) |
| 115 | return serio->write(serio, data); |
| 116 | else |
| 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | static inline void serio_drv_write_wakeup(struct serio *serio) |
| 121 | { |
| 122 | if (serio->drv && serio->drv->write_wakeup) |
| 123 | serio->drv->write_wakeup(serio); |
| 124 | } |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | /* |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 127 | * Use the following functions to manipulate serio's per-port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | * driver-specific data. |
| 129 | */ |
| 130 | static inline void *serio_get_drvdata(struct serio *serio) |
| 131 | { |
| 132 | return dev_get_drvdata(&serio->dev); |
| 133 | } |
| 134 | |
| 135 | static inline void serio_set_drvdata(struct serio *serio, void *data) |
| 136 | { |
| 137 | dev_set_drvdata(&serio->dev, data); |
| 138 | } |
| 139 | |
| 140 | /* |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 141 | * Use the following functions to protect critical sections in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | * driver code from port's interrupt handler |
| 143 | */ |
| 144 | static inline void serio_pause_rx(struct serio *serio) |
| 145 | { |
| 146 | spin_lock_irq(&serio->lock); |
| 147 | } |
| 148 | |
| 149 | static inline void serio_continue_rx(struct serio *serio) |
| 150 | { |
| 151 | spin_unlock_irq(&serio->lock); |
| 152 | } |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | #endif |
| 155 | |
| 156 | /* |
| 157 | * bit masks for use in "interrupt" flags (3rd argument) |
| 158 | */ |
| 159 | #define SERIO_TIMEOUT 1 |
| 160 | #define SERIO_PARITY 2 |
| 161 | #define SERIO_FRAME 4 |
| 162 | |
| 163 | /* |
| 164 | * Serio types |
| 165 | */ |
| 166 | #define SERIO_XT 0x00 |
| 167 | #define SERIO_8042 0x01 |
| 168 | #define SERIO_RS232 0x02 |
| 169 | #define SERIO_HIL_MLC 0x03 |
| 170 | #define SERIO_PS_PSTHRU 0x05 |
| 171 | #define SERIO_8042_XL 0x06 |
| 172 | |
| 173 | /* |
Niels de Vos | f3d1eb1 | 2008-07-08 10:30:27 -0400 | [diff] [blame] | 174 | * Serio protocols |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | */ |
| 176 | #define SERIO_UNKNOWN 0x00 |
| 177 | #define SERIO_MSC 0x01 |
| 178 | #define SERIO_SUN 0x02 |
| 179 | #define SERIO_MS 0x03 |
| 180 | #define SERIO_MP 0x04 |
| 181 | #define SERIO_MZ 0x05 |
| 182 | #define SERIO_MZP 0x06 |
| 183 | #define SERIO_MZPP 0x07 |
| 184 | #define SERIO_VSXXXAA 0x08 |
| 185 | #define SERIO_SUNKBD 0x10 |
| 186 | #define SERIO_WARRIOR 0x18 |
| 187 | #define SERIO_SPACEORB 0x19 |
| 188 | #define SERIO_MAGELLAN 0x1a |
| 189 | #define SERIO_SPACEBALL 0x1b |
| 190 | #define SERIO_GUNZE 0x1c |
| 191 | #define SERIO_IFORCE 0x1d |
| 192 | #define SERIO_STINGER 0x1e |
| 193 | #define SERIO_NEWTON 0x1f |
| 194 | #define SERIO_STOWAWAY 0x20 |
| 195 | #define SERIO_H3600 0x21 |
| 196 | #define SERIO_PS2SER 0x22 |
| 197 | #define SERIO_TWIDKBD 0x23 |
| 198 | #define SERIO_TWIDJOY 0x24 |
| 199 | #define SERIO_HIL 0x25 |
| 200 | #define SERIO_SNES232 0x26 |
| 201 | #define SERIO_SEMTECH 0x27 |
| 202 | #define SERIO_LKKBD 0x28 |
| 203 | #define SERIO_ELO 0x29 |
| 204 | #define SERIO_MICROTOUCH 0x30 |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 205 | #define SERIO_PENMOUNT 0x31 |
Rick Koch | 4003dff | 2006-08-05 00:32:24 -0400 | [diff] [blame] | 206 | #define SERIO_TOUCHRIGHT 0x32 |
Rick Koch | 11ea317 | 2006-08-05 00:32:30 -0400 | [diff] [blame] | 207 | #define SERIO_TOUCHWIN 0x33 |
Jean Delvare | b9cdad7 | 2007-07-12 14:12:31 +0200 | [diff] [blame] | 208 | #define SERIO_TAOSEVM 0x34 |
Dmitry Torokhov | 85f202d | 2007-07-18 00:37:01 -0400 | [diff] [blame] | 209 | #define SERIO_FUJITSU 0x35 |
Martin Kebert | 3e24e2b | 2008-03-10 13:40:36 +0100 | [diff] [blame] | 210 | #define SERIO_ZHENHUA 0x36 |
Richard Lemon | 3cadd2d | 2008-06-26 10:10:41 -0400 | [diff] [blame] | 211 | #define SERIO_INEXIO 0x37 |
Dmitry Torokhov | ab96dde | 2009-03-07 13:39:22 -0800 | [diff] [blame] | 212 | #define SERIO_TOUCHIT213 0x38 |
Jaya Kumar | 3eb1aa4 | 2008-11-19 16:58:50 -0500 | [diff] [blame] | 213 | #define SERIO_W8001 0x39 |
Tias Guns | a5f523b | 2009-10-25 12:13:58 -0700 | [diff] [blame] | 214 | #define SERIO_DYNAPRO 0x3a |
Adam Bennett | 422dee5 | 2010-04-12 19:54:38 -0700 | [diff] [blame] | 215 | #define SERIO_HAMPSHIRE 0x3b |
Dmitry Eremin-Solenikov | fc58d12 | 2010-10-18 09:18:13 -0700 | [diff] [blame] | 216 | #define SERIO_PS2MULT 0x3c |
Sebastian Andrzej Siewior | f01536e3 | 2011-09-28 10:04:21 -0700 | [diff] [blame] | 217 | #define SERIO_TSC40 0x3d |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | #endif |