Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 1999-2002 Vojtech Pavlik
0004  */
0005 #ifndef _SERIO_H
0006 #define _SERIO_H
0007 
0008 
0009 #include <linux/types.h>
0010 #include <linux/interrupt.h>
0011 #include <linux/list.h>
0012 #include <linux/spinlock.h>
0013 #include <linux/mutex.h>
0014 #include <linux/device.h>
0015 #include <linux/mod_devicetable.h>
0016 #include <uapi/linux/serio.h>
0017 
0018 extern struct bus_type serio_bus;
0019 
0020 struct serio {
0021     void *port_data;
0022 
0023     char name[32];
0024     char phys[32];
0025     char firmware_id[128];
0026 
0027     bool manual_bind;
0028 
0029     struct serio_device_id id;
0030 
0031     /* Protects critical sections from port's interrupt handler */
0032     spinlock_t lock;
0033 
0034     int (*write)(struct serio *, unsigned char);
0035     int (*open)(struct serio *);
0036     void (*close)(struct serio *);
0037     int (*start)(struct serio *);
0038     void (*stop)(struct serio *);
0039 
0040     struct serio *parent;
0041     /* Entry in parent->children list */
0042     struct list_head child_node;
0043     struct list_head children;
0044     /* Level of nesting in serio hierarchy */
0045     unsigned int depth;
0046 
0047     /*
0048      * serio->drv is accessed from interrupt handlers; when modifying
0049      * caller should acquire serio->drv_mutex and serio->lock.
0050      */
0051     struct serio_driver *drv;
0052     /* Protects serio->drv so attributes can pin current driver */
0053     struct mutex drv_mutex;
0054 
0055     struct device dev;
0056 
0057     struct list_head node;
0058 
0059     /*
0060      * For use by PS/2 layer when several ports share hardware and
0061      * may get indigestion when exposed to concurrent access (i8042).
0062      */
0063     struct mutex *ps2_cmd_mutex;
0064 };
0065 #define to_serio_port(d)    container_of(d, struct serio, dev)
0066 
0067 struct serio_driver {
0068     const char *description;
0069 
0070     const struct serio_device_id *id_table;
0071     bool manual_bind;
0072 
0073     void (*write_wakeup)(struct serio *);
0074     irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
0075     int  (*connect)(struct serio *, struct serio_driver *drv);
0076     int  (*reconnect)(struct serio *);
0077     int  (*fast_reconnect)(struct serio *);
0078     void (*disconnect)(struct serio *);
0079     void (*cleanup)(struct serio *);
0080 
0081     struct device_driver driver;
0082 };
0083 #define to_serio_driver(d)  container_of(d, struct serio_driver, driver)
0084 
0085 int serio_open(struct serio *serio, struct serio_driver *drv);
0086 void serio_close(struct serio *serio);
0087 void serio_rescan(struct serio *serio);
0088 void serio_reconnect(struct serio *serio);
0089 irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
0090 
0091 void __serio_register_port(struct serio *serio, struct module *owner);
0092 
0093 /* use a define to avoid include chaining to get THIS_MODULE */
0094 #define serio_register_port(serio) \
0095     __serio_register_port(serio, THIS_MODULE)
0096 
0097 void serio_unregister_port(struct serio *serio);
0098 void serio_unregister_child_port(struct serio *serio);
0099 
0100 int __must_check __serio_register_driver(struct serio_driver *drv,
0101                 struct module *owner, const char *mod_name);
0102 
0103 /* use a define to avoid include chaining to get THIS_MODULE & friends */
0104 #define serio_register_driver(drv) \
0105     __serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME)
0106 
0107 void serio_unregister_driver(struct serio_driver *drv);
0108 
0109 /**
0110  * module_serio_driver() - Helper macro for registering a serio driver
0111  * @__serio_driver: serio_driver struct
0112  *
0113  * Helper macro for serio drivers which do not do anything special in
0114  * module init/exit. This eliminates a lot of boilerplate. Each module
0115  * may only use this macro once, and calling it replaces module_init()
0116  * and module_exit().
0117  */
0118 #define module_serio_driver(__serio_driver) \
0119     module_driver(__serio_driver, serio_register_driver, \
0120                serio_unregister_driver)
0121 
0122 static inline int serio_write(struct serio *serio, unsigned char data)
0123 {
0124     if (serio->write)
0125         return serio->write(serio, data);
0126     else
0127         return -1;
0128 }
0129 
0130 static inline void serio_drv_write_wakeup(struct serio *serio)
0131 {
0132     if (serio->drv && serio->drv->write_wakeup)
0133         serio->drv->write_wakeup(serio);
0134 }
0135 
0136 /*
0137  * Use the following functions to manipulate serio's per-port
0138  * driver-specific data.
0139  */
0140 static inline void *serio_get_drvdata(struct serio *serio)
0141 {
0142     return dev_get_drvdata(&serio->dev);
0143 }
0144 
0145 static inline void serio_set_drvdata(struct serio *serio, void *data)
0146 {
0147     dev_set_drvdata(&serio->dev, data);
0148 }
0149 
0150 /*
0151  * Use the following functions to protect critical sections in
0152  * driver code from port's interrupt handler
0153  */
0154 static inline void serio_pause_rx(struct serio *serio)
0155 {
0156     spin_lock_irq(&serio->lock);
0157 }
0158 
0159 static inline void serio_continue_rx(struct serio *serio)
0160 {
0161     spin_unlock_irq(&serio->lock);
0162 }
0163 
0164 #endif