Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999-2002 Vojtech Pavlik |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 as published by |
| 6 | * the Free Software Foundation. |
| 7 | */ |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 8 | #ifndef _SERIO_H |
| 9 | #define _SERIO_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 12 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/spinlock.h> |
Arjan van de Ven | c4e32e9 | 2006-02-19 00:21:55 -0500 | [diff] [blame] | 16 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/device.h> |
| 18 | #include <linux/mod_devicetable.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 19 | #include <uapi/linux/serio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Stephen Chandler Paul | e1443d2 | 2015-07-15 10:20:17 -0700 | [diff] [blame] | 21 | extern struct bus_type serio_bus; |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | struct serio { |
| 24 | void *port_data; |
| 25 | |
| 26 | char name[32]; |
| 27 | char phys[32]; |
Hans de Goede | 0456c66 | 2014-04-19 20:39:35 -0700 | [diff] [blame] | 28 | char firmware_id[128]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 30 | bool manual_bind; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dmitry Eremin-Solenikov | 0982258 | 2010-10-04 21:46:10 -0700 | [diff] [blame] | 42 | struct serio *parent; |
| 43 | struct list_head child_node; /* Entry in parent->children list */ |
| 44 | struct list_head children; |
Jiri Kosina | 88aa010 | 2006-10-11 01:45:31 -0400 | [diff] [blame] | 45 | unsigned int depth; /* level of nesting in serio hierarchy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | 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] | 48 | struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | struct list_head node; |
| 53 | }; |
| 54 | #define to_serio_port(d) container_of(d, struct serio, dev) |
| 55 | |
| 56 | struct serio_driver { |
Dmitry Torokhov | ceee427 | 2010-09-13 23:53:55 -0700 | [diff] [blame] | 57 | const char *description; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Dmitry Torokhov | ceee427 | 2010-09-13 23:53:55 -0700 | [diff] [blame] | 59 | const struct serio_device_id *id_table; |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 60 | bool manual_bind; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | void (*write_wakeup)(struct serio *); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 63 | irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 77 | 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] | 78 | |
| 79 | void __serio_register_port(struct serio *serio, struct module *owner); |
Paul Gortmaker | eb5589a | 2011-05-27 09:02:11 -0400 | [diff] [blame] | 80 | |
| 81 | /* use a define to avoid include chaining to get THIS_MODULE */ |
| 82 | #define serio_register_port(serio) \ |
| 83 | __serio_register_port(serio, THIS_MODULE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Paul Gortmaker | eb5589a | 2011-05-27 09:02:11 -0400 | [diff] [blame] | 88 | int __must_check __serio_register_driver(struct serio_driver *drv, |
| 89 | struct module *owner, const char *mod_name); |
| 90 | |
| 91 | /* use a define to avoid include chaining to get THIS_MODULE & friends */ |
| 92 | #define serio_register_driver(drv) \ |
| 93 | __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME) |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | void serio_unregister_driver(struct serio_driver *drv); |
| 96 | |
Axel Lin | fa7f86d | 2012-04-03 23:50:15 -0700 | [diff] [blame] | 97 | /** |
| 98 | * module_serio_driver() - Helper macro for registering a serio driver |
| 99 | * @__serio_driver: serio_driver struct |
| 100 | * |
| 101 | * Helper macro for serio drivers which do not do anything special in |
| 102 | * module init/exit. This eliminates a lot of boilerplate. Each module |
| 103 | * may only use this macro once, and calling it replaces module_init() |
| 104 | * and module_exit(). |
| 105 | */ |
| 106 | #define module_serio_driver(__serio_driver) \ |
| 107 | module_driver(__serio_driver, serio_register_driver, \ |
| 108 | serio_unregister_driver) |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | static inline int serio_write(struct serio *serio, unsigned char data) |
| 111 | { |
| 112 | if (serio->write) |
| 113 | return serio->write(serio, data); |
| 114 | else |
| 115 | return -1; |
| 116 | } |
| 117 | |
| 118 | static inline void serio_drv_write_wakeup(struct serio *serio) |
| 119 | { |
| 120 | if (serio->drv && serio->drv->write_wakeup) |
| 121 | serio->drv->write_wakeup(serio); |
| 122 | } |
| 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | /* |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 125 | * Use the following functions to manipulate serio's per-port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | * driver-specific data. |
| 127 | */ |
| 128 | static inline void *serio_get_drvdata(struct serio *serio) |
| 129 | { |
| 130 | return dev_get_drvdata(&serio->dev); |
| 131 | } |
| 132 | |
| 133 | static inline void serio_set_drvdata(struct serio *serio, void *data) |
| 134 | { |
| 135 | dev_set_drvdata(&serio->dev, data); |
| 136 | } |
| 137 | |
| 138 | /* |
Akinobu Mita | 0b28002 | 2006-03-26 01:38:58 -0800 | [diff] [blame] | 139 | * Use the following functions to protect critical sections in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * driver code from port's interrupt handler |
| 141 | */ |
| 142 | static inline void serio_pause_rx(struct serio *serio) |
| 143 | { |
| 144 | spin_lock_irq(&serio->lock); |
| 145 | } |
| 146 | |
| 147 | static inline void serio_continue_rx(struct serio *serio) |
| 148 | { |
| 149 | spin_unlock_irq(&serio->lock); |
| 150 | } |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | #endif |