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 | |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/list.h> |
| 20 | #include <linux/spinlock.h> |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 21 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/device.h> |
| 23 | #include <linux/mod_devicetable.h> |
| 24 | |
| 25 | struct serio { |
| 26 | void *port_data; |
| 27 | |
| 28 | char name[32]; |
| 29 | char phys[32]; |
| 30 | |
| 31 | unsigned int manual_bind; |
| 32 | |
| 33 | struct serio_device_id id; |
| 34 | |
| 35 | spinlock_t lock; /* protects critical sections from port's interrupt handler */ |
| 36 | |
| 37 | int (*write)(struct serio *, unsigned char); |
| 38 | int (*open)(struct serio *); |
| 39 | void (*close)(struct serio *); |
| 40 | int (*start)(struct serio *); |
| 41 | void (*stop)(struct serio *); |
| 42 | |
| 43 | struct serio *parent, *child; |
Jiri Kosina | 88aa010 | 2006-10-11 01:45:31 -0400 | [diff] [blame] | 44 | unsigned int depth; /* level of nesting in serio hierarchy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | 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] | 47 | struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | struct device dev; |
| 50 | unsigned int registered; /* port has been fully registered with driver core */ |
| 51 | |
| 52 | struct list_head node; |
| 53 | }; |
| 54 | #define to_serio_port(d) container_of(d, struct serio, dev) |
| 55 | |
| 56 | struct serio_driver { |
| 57 | void *private; |
| 58 | char *description; |
| 59 | |
| 60 | struct serio_device_id *id_table; |
| 61 | unsigned int manual_bind; |
| 62 | |
| 63 | void (*write_wakeup)(struct serio *); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 64 | irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | int (*connect)(struct serio *, struct serio_driver *drv); |
| 66 | int (*reconnect)(struct serio *); |
| 67 | void (*disconnect)(struct serio *); |
| 68 | void (*cleanup)(struct serio *); |
| 69 | |
| 70 | struct device_driver driver; |
| 71 | }; |
| 72 | #define to_serio_driver(d) container_of(d, struct serio_driver, driver) |
| 73 | |
| 74 | int serio_open(struct serio *serio, struct serio_driver *drv); |
| 75 | void serio_close(struct serio *serio); |
| 76 | void serio_rescan(struct serio *serio); |
| 77 | void serio_reconnect(struct serio *serio); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 78 | 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] | 79 | |
| 80 | void __serio_register_port(struct serio *serio, struct module *owner); |
| 81 | static inline void serio_register_port(struct serio *serio) |
| 82 | { |
| 83 | __serio_register_port(serio, THIS_MODULE); |
| 84 | } |
| 85 | |
| 86 | void serio_unregister_port(struct serio *serio); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 87 | void serio_unregister_child_port(struct serio *serio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | void __serio_unregister_port_delayed(struct serio *serio, struct module *owner); |
| 89 | static inline void serio_unregister_port_delayed(struct serio *serio) |
| 90 | { |
| 91 | __serio_unregister_port_delayed(serio, THIS_MODULE); |
| 92 | } |
| 93 | |
| 94 | void __serio_register_driver(struct serio_driver *drv, struct module *owner); |
| 95 | static inline void serio_register_driver(struct serio_driver *drv) |
| 96 | { |
| 97 | __serio_register_driver(drv, THIS_MODULE); |
| 98 | } |
| 99 | |
| 100 | void serio_unregister_driver(struct serio_driver *drv); |
| 101 | |
| 102 | static inline int serio_write(struct serio *serio, unsigned char data) |
| 103 | { |
| 104 | if (serio->write) |
| 105 | return serio->write(serio, data); |
| 106 | else |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | static inline void serio_drv_write_wakeup(struct serio *serio) |
| 111 | { |
| 112 | if (serio->drv && serio->drv->write_wakeup) |
| 113 | serio->drv->write_wakeup(serio); |
| 114 | } |
| 115 | |
| 116 | static inline void serio_cleanup(struct serio *serio) |
| 117 | { |
| 118 | if (serio->drv && serio->drv->cleanup) |
| 119 | serio->drv->cleanup(serio); |
| 120 | } |
| 121 | |
| 122 | /* |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 123 | * Use the following functions to manipulate serio's per-port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * driver-specific data. |
| 125 | */ |
| 126 | static inline void *serio_get_drvdata(struct serio *serio) |
| 127 | { |
| 128 | return dev_get_drvdata(&serio->dev); |
| 129 | } |
| 130 | |
| 131 | static inline void serio_set_drvdata(struct serio *serio, void *data) |
| 132 | { |
| 133 | dev_set_drvdata(&serio->dev, data); |
| 134 | } |
| 135 | |
| 136 | /* |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 137 | * Use the following functions to protect critical sections in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | * driver code from port's interrupt handler |
| 139 | */ |
| 140 | static inline void serio_pause_rx(struct serio *serio) |
| 141 | { |
| 142 | spin_lock_irq(&serio->lock); |
| 143 | } |
| 144 | |
| 145 | static inline void serio_continue_rx(struct serio *serio) |
| 146 | { |
| 147 | spin_unlock_irq(&serio->lock); |
| 148 | } |
| 149 | |
| 150 | /* |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 151 | * Use the following functions to pin serio's driver in process context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | */ |
| 153 | static inline int serio_pin_driver(struct serio *serio) |
| 154 | { |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 155 | return mutex_lock_interruptible(&serio->drv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 158 | static inline void serio_pin_driver_uninterruptible(struct serio *serio) |
| 159 | { |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 160 | mutex_lock(&serio->drv_mutex); |
Dmitry Torokhov | dbf4ccd | 2005-06-01 02:40:01 -0500 | [diff] [blame] | 161 | } |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | static inline void serio_unpin_driver(struct serio *serio) |
| 164 | { |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 165 | mutex_unlock(&serio->drv_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | |
| 169 | #endif |
| 170 | |
| 171 | /* |
| 172 | * bit masks for use in "interrupt" flags (3rd argument) |
| 173 | */ |
| 174 | #define SERIO_TIMEOUT 1 |
| 175 | #define SERIO_PARITY 2 |
| 176 | #define SERIO_FRAME 4 |
| 177 | |
| 178 | /* |
| 179 | * Serio types |
| 180 | */ |
| 181 | #define SERIO_XT 0x00 |
| 182 | #define SERIO_8042 0x01 |
| 183 | #define SERIO_RS232 0x02 |
| 184 | #define SERIO_HIL_MLC 0x03 |
| 185 | #define SERIO_PS_PSTHRU 0x05 |
| 186 | #define SERIO_8042_XL 0x06 |
| 187 | |
| 188 | /* |
| 189 | * Serio types |
| 190 | */ |
| 191 | #define SERIO_UNKNOWN 0x00 |
| 192 | #define SERIO_MSC 0x01 |
| 193 | #define SERIO_SUN 0x02 |
| 194 | #define SERIO_MS 0x03 |
| 195 | #define SERIO_MP 0x04 |
| 196 | #define SERIO_MZ 0x05 |
| 197 | #define SERIO_MZP 0x06 |
| 198 | #define SERIO_MZPP 0x07 |
| 199 | #define SERIO_VSXXXAA 0x08 |
| 200 | #define SERIO_SUNKBD 0x10 |
| 201 | #define SERIO_WARRIOR 0x18 |
| 202 | #define SERIO_SPACEORB 0x19 |
| 203 | #define SERIO_MAGELLAN 0x1a |
| 204 | #define SERIO_SPACEBALL 0x1b |
| 205 | #define SERIO_GUNZE 0x1c |
| 206 | #define SERIO_IFORCE 0x1d |
| 207 | #define SERIO_STINGER 0x1e |
| 208 | #define SERIO_NEWTON 0x1f |
| 209 | #define SERIO_STOWAWAY 0x20 |
| 210 | #define SERIO_H3600 0x21 |
| 211 | #define SERIO_PS2SER 0x22 |
| 212 | #define SERIO_TWIDKBD 0x23 |
| 213 | #define SERIO_TWIDJOY 0x24 |
| 214 | #define SERIO_HIL 0x25 |
| 215 | #define SERIO_SNES232 0x26 |
| 216 | #define SERIO_SEMTECH 0x27 |
| 217 | #define SERIO_LKKBD 0x28 |
| 218 | #define SERIO_ELO 0x29 |
| 219 | #define SERIO_MICROTOUCH 0x30 |
Rick Koch | ee47999 | 2006-08-05 00:32:18 -0400 | [diff] [blame] | 220 | #define SERIO_PENMOUNT 0x31 |
Rick Koch | 4003dff | 2006-08-05 00:32:24 -0400 | [diff] [blame] | 221 | #define SERIO_TOUCHRIGHT 0x32 |
Rick Koch | 11ea317 | 2006-08-05 00:32:30 -0400 | [diff] [blame] | 222 | #define SERIO_TOUCHWIN 0x33 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | #endif |