serio.h 4.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/*
 * Copyright (C) 1999-2002 Vojtech Pavlik
*
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 */
8 9
#ifndef _SERIO_H
#define _SERIO_H
L
Linus Torvalds 已提交
10 11


12
#include <linux/types.h>
L
Linus Torvalds 已提交
13 14 15
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/spinlock.h>
16
#include <linux/mutex.h>
L
Linus Torvalds 已提交
17 18
#include <linux/device.h>
#include <linux/mod_devicetable.h>
19
#include <uapi/linux/serio.h>
L
Linus Torvalds 已提交
20 21 22 23 24 25 26

struct serio {
	void *port_data;

	char name[32];
	char phys[32];

27
	bool manual_bind;
L
Linus Torvalds 已提交
28 29 30 31 32 33 34 35 36 37 38

	struct serio_device_id id;

	spinlock_t lock;		/* protects critical sections from port's interrupt handler */

	int (*write)(struct serio *, unsigned char);
	int (*open)(struct serio *);
	void (*close)(struct serio *);
	int (*start)(struct serio *);
	void (*stop)(struct serio *);

39 40 41
	struct serio *parent;
	struct list_head child_node;	/* Entry in parent->children list */
	struct list_head children;
42
	unsigned int depth;		/* level of nesting in serio hierarchy */
L
Linus Torvalds 已提交
43 44

	struct serio_driver *drv;	/* accessed from interrupt, must be protected by serio->lock and serio->sem */
45
	struct mutex drv_mutex;		/* protects serio->drv so attributes can pin driver */
L
Linus Torvalds 已提交
46 47 48 49 50 51 52 53

	struct device dev;

	struct list_head node;
};
#define to_serio_port(d)	container_of(d, struct serio, dev)

struct serio_driver {
54
	const char *description;
L
Linus Torvalds 已提交
55

56
	const struct serio_device_id *id_table;
57
	bool manual_bind;
L
Linus Torvalds 已提交
58 59

	void (*write_wakeup)(struct serio *);
60
	irqreturn_t (*interrupt)(struct serio *, unsigned char, unsigned int);
L
Linus Torvalds 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73
	int  (*connect)(struct serio *, struct serio_driver *drv);
	int  (*reconnect)(struct serio *);
	void (*disconnect)(struct serio *);
	void (*cleanup)(struct serio *);

	struct device_driver driver;
};
#define to_serio_driver(d)	container_of(d, struct serio_driver, driver)

int serio_open(struct serio *serio, struct serio_driver *drv);
void serio_close(struct serio *serio);
void serio_rescan(struct serio *serio);
void serio_reconnect(struct serio *serio);
74
irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
L
Linus Torvalds 已提交
75 76

void __serio_register_port(struct serio *serio, struct module *owner);
77 78 79 80

/* use a define to avoid include chaining to get THIS_MODULE */
#define serio_register_port(serio) \
	__serio_register_port(serio, THIS_MODULE)
L
Linus Torvalds 已提交
81 82

void serio_unregister_port(struct serio *serio);
83
void serio_unregister_child_port(struct serio *serio);
L
Linus Torvalds 已提交
84

85 86 87 88 89 90 91
int __must_check __serio_register_driver(struct serio_driver *drv,
				struct module *owner, const char *mod_name);

/* use a define to avoid include chaining to get THIS_MODULE & friends */
#define serio_register_driver(drv) \
	__serio_register_driver(drv, THIS_MODULE, KBUILD_MODNAME)

L
Linus Torvalds 已提交
92 93
void serio_unregister_driver(struct serio_driver *drv);

94 95 96 97 98 99 100 101 102 103 104 105 106
/**
 * module_serio_driver() - Helper macro for registering a serio driver
 * @__serio_driver: serio_driver struct
 *
 * Helper macro for serio drivers which do not do anything special in
 * module init/exit. This eliminates a lot of boilerplate. Each module
 * may only use this macro once, and calling it replaces module_init()
 * and module_exit().
 */
#define module_serio_driver(__serio_driver) \
	module_driver(__serio_driver, serio_register_driver, \
		       serio_unregister_driver)

L
Linus Torvalds 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
static inline int serio_write(struct serio *serio, unsigned char data)
{
	if (serio->write)
		return serio->write(serio, data);
	else
		return -1;
}

static inline void serio_drv_write_wakeup(struct serio *serio)
{
	if (serio->drv && serio->drv->write_wakeup)
		serio->drv->write_wakeup(serio);
}

/*
122
 * Use the following functions to manipulate serio's per-port
L
Linus Torvalds 已提交
123 124 125 126 127 128 129 130 131 132 133 134 135
 * driver-specific data.
 */
static inline void *serio_get_drvdata(struct serio *serio)
{
	return dev_get_drvdata(&serio->dev);
}

static inline void serio_set_drvdata(struct serio *serio, void *data)
{
	dev_set_drvdata(&serio->dev, data);
}

/*
136
 * Use the following functions to protect critical sections in
L
Linus Torvalds 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149
 * driver code from port's interrupt handler
 */
static inline void serio_pause_rx(struct serio *serio)
{
	spin_lock_irq(&serio->lock);
}

static inline void serio_continue_rx(struct serio *serio)
{
	spin_unlock_irq(&serio->lock);
}

#endif