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