2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* The Serio abstraction module
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999-2004 Vojtech Pavlik
|
|
|
|
* Copyright (c) 2004 Dmitry Torokhov
|
|
|
|
* Copyright (c) 2003 Daniele Bellucci
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Should you need to contact me, the author, you can do so either by
|
|
|
|
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
|
|
|
|
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
|
|
|
|
*/
|
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/serio.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
2010-11-15 17:39:57 +08:00
|
|
|
#include <linux/workqueue.h>
|
2006-02-19 13:21:55 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
|
|
|
|
MODULE_DESCRIPTION("Serio abstraction core");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
/*
|
2006-02-19 13:21:55 +08:00
|
|
|
* serio_mutex protects entire serio subsystem and is taken every time
|
2010-11-15 17:39:57 +08:00
|
|
|
* serio port or driver registered or unregistered.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2006-02-19 13:21:55 +08:00
|
|
|
static DEFINE_MUTEX(serio_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static LIST_HEAD(serio_list);
|
|
|
|
|
|
|
|
static void serio_add_port(struct serio *serio);
|
2008-07-03 22:45:38 +08:00
|
|
|
static int serio_reconnect_port(struct serio *serio);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void serio_disconnect_port(struct serio *serio);
|
2010-10-05 12:46:10 +08:00
|
|
|
static void serio_reconnect_subtree(struct serio *serio);
|
2006-11-24 12:34:49 +08:00
|
|
|
static void serio_attach_driver(struct serio_driver *drv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-28 08:49:45 +08:00
|
|
|
static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_lock(&serio->drv_mutex);
|
2005-06-28 08:49:45 +08:00
|
|
|
retval = drv->connect(serio, drv);
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio->drv_mutex);
|
2005-06-28 08:49:45 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serio_reconnect_driver(struct serio *serio)
|
|
|
|
{
|
|
|
|
int retval = -1;
|
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_lock(&serio->drv_mutex);
|
2005-06-28 08:49:45 +08:00
|
|
|
if (serio->drv && serio->drv->reconnect)
|
|
|
|
retval = serio->drv->reconnect(serio);
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio->drv_mutex);
|
2005-06-28 08:49:45 +08:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void serio_disconnect_driver(struct serio *serio)
|
|
|
|
{
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_lock(&serio->drv_mutex);
|
2005-06-28 08:49:45 +08:00
|
|
|
if (serio->drv)
|
|
|
|
serio->drv->disconnect(serio);
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio->drv_mutex);
|
2005-06-28 08:49:45 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int serio_match_port(const struct serio_device_id *ids, struct serio *serio)
|
|
|
|
{
|
|
|
|
while (ids->type || ids->proto) {
|
|
|
|
if ((ids->type == SERIO_ANY || ids->type == serio->id.type) &&
|
|
|
|
(ids->proto == SERIO_ANY || ids->proto == serio->id.proto) &&
|
|
|
|
(ids->extra == SERIO_ANY || ids->extra == serio->id.extra) &&
|
|
|
|
(ids->id == SERIO_ANY || ids->id == serio->id.id))
|
|
|
|
return 1;
|
|
|
|
ids++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic serio -> driver core mappings
|
|
|
|
*/
|
|
|
|
|
2007-04-10 12:40:27 +08:00
|
|
|
static int serio_bind_driver(struct serio *serio, struct serio_driver *drv)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-10-12 13:06:23 +08:00
|
|
|
int error;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serio_match_port(drv->id_table, serio)) {
|
2007-04-10 12:40:27 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
serio->dev.driver = &drv->driver;
|
2005-06-28 08:49:45 +08:00
|
|
|
if (serio_connect_driver(serio, drv)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
serio->dev.driver = NULL;
|
2007-04-10 12:40:27 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-10 12:40:27 +08:00
|
|
|
|
2006-10-12 13:06:23 +08:00
|
|
|
error = device_bind_driver(&serio->dev);
|
|
|
|
if (error) {
|
2010-01-06 09:56:04 +08:00
|
|
|
dev_warn(&serio->dev,
|
|
|
|
"device_bind_driver() failed for %s (%s) and %s, error: %d\n",
|
|
|
|
serio->phys, serio->name,
|
|
|
|
drv->description, error);
|
2006-10-12 13:06:23 +08:00
|
|
|
serio_disconnect_driver(serio);
|
|
|
|
serio->dev.driver = NULL;
|
2007-04-10 12:40:27 +08:00
|
|
|
return error;
|
2006-10-12 13:06:23 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-10 12:40:27 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serio_find_driver(struct serio *serio)
|
|
|
|
{
|
2006-07-19 13:14:55 +08:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = device_attach(&serio->dev);
|
2016-01-17 02:35:47 +08:00
|
|
|
if (error < 0 && error != -EPROBE_DEFER)
|
2010-01-06 09:56:04 +08:00
|
|
|
dev_warn(&serio->dev,
|
|
|
|
"device_attach() failed for %s (%s), error: %d\n",
|
|
|
|
serio->phys, serio->name, error);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Serio event processing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum serio_event_type {
|
2006-11-24 12:34:49 +08:00
|
|
|
SERIO_RESCAN_PORT,
|
|
|
|
SERIO_RECONNECT_PORT,
|
2010-10-05 12:46:10 +08:00
|
|
|
SERIO_RECONNECT_SUBTREE,
|
2005-04-17 06:20:36 +08:00
|
|
|
SERIO_REGISTER_PORT,
|
2006-11-24 12:34:49 +08:00
|
|
|
SERIO_ATTACH_DRIVER,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct serio_event {
|
|
|
|
enum serio_event_type type;
|
|
|
|
void *object;
|
|
|
|
struct module *owner;
|
|
|
|
struct list_head node;
|
|
|
|
};
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(serio_event_lock); /* protects serio_event_list */
|
|
|
|
static LIST_HEAD(serio_event_list);
|
|
|
|
|
2010-11-15 17:39:57 +08:00
|
|
|
static struct serio_event *serio_get_event(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-11-15 17:39:57 +08:00
|
|
|
struct serio_event *event = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&serio_event_lock, flags);
|
|
|
|
|
2010-11-15 17:39:57 +08:00
|
|
|
if (!list_empty(&serio_event_list)) {
|
|
|
|
event = list_first_entry(&serio_event_list,
|
|
|
|
struct serio_event, node);
|
|
|
|
list_del_init(&event->node);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-11-24 12:34:49 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&serio_event_lock, flags);
|
2010-11-15 17:39:57 +08:00
|
|
|
return event;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serio_free_event(struct serio_event *event)
|
|
|
|
{
|
|
|
|
module_put(event->owner);
|
|
|
|
kfree(event);
|
|
|
|
}
|
|
|
|
|
2011-02-03 14:59:54 +08:00
|
|
|
static void serio_remove_duplicate_events(void *object,
|
|
|
|
enum serio_event_type type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-01-06 09:56:04 +08:00
|
|
|
struct serio_event *e, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&serio_event_lock, flags);
|
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
list_for_each_entry_safe(e, next, &serio_event_list, node) {
|
2011-02-03 14:59:54 +08:00
|
|
|
if (object == e->object) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* If this event is of different type we should not
|
|
|
|
* look further - we only suppress duplicate events
|
|
|
|
* that were sent back-to-back.
|
|
|
|
*/
|
2011-02-03 14:59:54 +08:00
|
|
|
if (type != e->type)
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
list_del_init(&e->node);
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_free_event(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&serio_event_lock, flags);
|
|
|
|
}
|
|
|
|
|
2010-11-15 17:39:57 +08:00
|
|
|
static void serio_handle_event(struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio_event *event;
|
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_lock(&serio_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-12-25 13:40:43 +08:00
|
|
|
while ((event = serio_get_event())) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
case SERIO_REGISTER_PORT:
|
|
|
|
serio_add_port(event->object);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
case SERIO_RECONNECT_PORT:
|
|
|
|
serio_reconnect_port(event->object);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
case SERIO_RESCAN_PORT:
|
|
|
|
serio_disconnect_port(event->object);
|
|
|
|
serio_find_driver(event->object);
|
|
|
|
break;
|
2008-07-03 22:45:38 +08:00
|
|
|
|
2010-10-05 12:46:10 +08:00
|
|
|
case SERIO_RECONNECT_SUBTREE:
|
|
|
|
serio_reconnect_subtree(event->object);
|
2010-01-06 09:56:04 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
case SERIO_ATTACH_DRIVER:
|
|
|
|
serio_attach_driver(event->object);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-02-03 14:59:54 +08:00
|
|
|
serio_remove_duplicate_events(event->object, event->type);
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_free_event(event);
|
|
|
|
}
|
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-11-15 17:39:57 +08:00
|
|
|
static DECLARE_WORK(serio_event_work, serio_handle_event);
|
|
|
|
|
|
|
|
static int serio_queue_event(void *object, struct module *owner,
|
|
|
|
enum serio_event_type event_type)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
struct serio_event *event;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&serio_event_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan event list for the other events for the same serio port,
|
|
|
|
* starting with the most recent one. If event is the same we
|
|
|
|
* do not need add new one. If event is of different type we
|
|
|
|
* need to add this event and should not look further because
|
|
|
|
* we need to preseve sequence of distinct events.
|
|
|
|
*/
|
|
|
|
list_for_each_entry_reverse(event, &serio_event_list, node) {
|
|
|
|
if (event->object == object) {
|
|
|
|
if (event->type == event_type)
|
|
|
|
goto out;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC);
|
|
|
|
if (!event) {
|
|
|
|
pr_err("Not enough memory to queue event %d\n", event_type);
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!try_module_get(owner)) {
|
2017-03-18 08:15:38 +08:00
|
|
|
pr_warn("Can't get module reference, dropping event %d\n",
|
|
|
|
event_type);
|
2010-11-15 17:39:57 +08:00
|
|
|
kfree(event);
|
|
|
|
retval = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
event->type = event_type;
|
|
|
|
event->object = object;
|
|
|
|
event->owner = owner;
|
|
|
|
|
|
|
|
list_add_tail(&event->node, &serio_event_list);
|
2011-02-24 00:51:28 +08:00
|
|
|
queue_work(system_long_wq, &serio_event_work);
|
2010-11-15 17:39:57 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&serio_event_lock, flags);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2008-06-02 12:41:57 +08:00
|
|
|
* Remove all events that have been submitted for a given
|
|
|
|
* object, be it serio port or driver.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-06-02 12:41:57 +08:00
|
|
|
static void serio_remove_pending_events(void *object)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-01-06 09:56:04 +08:00
|
|
|
struct serio_event *event, *next;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&serio_event_lock, flags);
|
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
list_for_each_entry_safe(event, next, &serio_event_list, node) {
|
2008-06-02 12:41:57 +08:00
|
|
|
if (event->object == object) {
|
2010-01-06 09:56:04 +08:00
|
|
|
list_del_init(&event->node);
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_free_event(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&serio_event_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-05 12:46:10 +08:00
|
|
|
* Locate child serio port (if any) that has not been fully registered yet.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2010-10-05 12:46:10 +08:00
|
|
|
* Children are registered by driver's connect() handler so there can't be a
|
|
|
|
* grandchild pending registration together with a child.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static struct serio *serio_get_pending_child(struct serio *parent)
|
|
|
|
{
|
|
|
|
struct serio_event *event;
|
|
|
|
struct serio *serio, *child = NULL;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&serio_event_lock, flags);
|
|
|
|
|
|
|
|
list_for_each_entry(event, &serio_event_list, node) {
|
|
|
|
if (event->type == SERIO_REGISTER_PORT) {
|
|
|
|
serio = event->object;
|
|
|
|
if (serio->parent == parent) {
|
|
|
|
child = serio;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&serio_event_lock, flags);
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Serio port operations
|
|
|
|
*/
|
|
|
|
|
2005-05-17 18:42:58 +08:00
|
|
|
static ssize_t serio_show_description(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
return sprintf(buf, "%s\n", serio->name);
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:09:08 +08:00
|
|
|
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-06-30 13:48:34 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "serio:ty%02Xpr%02Xid%02Xex%02X\n",
|
|
|
|
serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:08:23 +08:00
|
|
|
static ssize_t type_show(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
return sprintf(buf, "%02x\n", serio->id.type);
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:08:23 +08:00
|
|
|
static ssize_t proto_show(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
return sprintf(buf, "%02x\n", serio->id.proto);
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:08:23 +08:00
|
|
|
static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
return sprintf(buf, "%02x\n", serio->id.id);
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:08:23 +08:00
|
|
|
static ssize_t extra_show(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
return sprintf(buf, "%02x\n", serio->id.extra);
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:09:08 +08:00
|
|
|
static ssize_t drvctl_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
struct device_driver *drv;
|
2007-04-10 12:40:27 +08:00
|
|
|
int error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-10 12:40:27 +08:00
|
|
|
error = mutex_lock_interruptible(&serio_mutex);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!strncmp(buf, "none", count)) {
|
|
|
|
serio_disconnect_port(serio);
|
|
|
|
} else if (!strncmp(buf, "reconnect", count)) {
|
2010-10-05 12:46:10 +08:00
|
|
|
serio_reconnect_subtree(serio);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (!strncmp(buf, "rescan", count)) {
|
|
|
|
serio_disconnect_port(serio);
|
|
|
|
serio_find_driver(serio);
|
2011-02-03 14:59:54 +08:00
|
|
|
serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if ((drv = driver_find(buf, &serio_bus)) != NULL) {
|
|
|
|
serio_disconnect_port(serio);
|
2007-04-10 12:40:27 +08:00
|
|
|
error = serio_bind_driver(serio, to_serio_driver(drv));
|
2011-02-03 14:59:54 +08:00
|
|
|
serio_remove_duplicate_events(serio, SERIO_RESCAN_PORT);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2007-04-10 12:40:27 +08:00
|
|
|
error = -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-10 12:40:27 +08:00
|
|
|
return error ? error : count;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-05-17 18:42:58 +08:00
|
|
|
static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
return sprintf(buf, "%s\n", serio->manual_bind ? "manual" : "auto");
|
|
|
|
}
|
|
|
|
|
2005-05-17 18:42:58 +08:00
|
|
|
static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = count;
|
|
|
|
if (!strncmp(buf, "manual", count)) {
|
2009-05-10 07:08:05 +08:00
|
|
|
serio->manual_bind = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (!strncmp(buf, "auto", count)) {
|
2009-05-10 07:08:05 +08:00
|
|
|
serio->manual_bind = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
retval = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-04-20 11:39:35 +08:00
|
|
|
static ssize_t firmware_id_show(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", serio->firmware_id);
|
|
|
|
}
|
|
|
|
|
2013-10-08 09:09:08 +08:00
|
|
|
static DEVICE_ATTR_RO(type);
|
|
|
|
static DEVICE_ATTR_RO(proto);
|
|
|
|
static DEVICE_ATTR_RO(id);
|
|
|
|
static DEVICE_ATTR_RO(extra);
|
|
|
|
|
|
|
|
static struct attribute *serio_device_id_attrs[] = {
|
|
|
|
&dev_attr_type.attr,
|
|
|
|
&dev_attr_proto.attr,
|
|
|
|
&dev_attr_id.attr,
|
|
|
|
&dev_attr_extra.attr,
|
2013-12-07 23:13:56 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group serio_id_attr_group = {
|
|
|
|
.name = "id",
|
|
|
|
.attrs = serio_device_id_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static DEVICE_ATTR_RO(modalias);
|
|
|
|
static DEVICE_ATTR_WO(drvctl);
|
|
|
|
static DEVICE_ATTR(description, S_IRUGO, serio_show_description, NULL);
|
|
|
|
static DEVICE_ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode);
|
2014-04-20 11:39:35 +08:00
|
|
|
static DEVICE_ATTR_RO(firmware_id);
|
2013-12-07 23:13:56 +08:00
|
|
|
|
|
|
|
static struct attribute *serio_device_attrs[] = {
|
2013-10-08 09:09:08 +08:00
|
|
|
&dev_attr_modalias.attr,
|
|
|
|
&dev_attr_description.attr,
|
|
|
|
&dev_attr_drvctl.attr,
|
|
|
|
&dev_attr_bind_mode.attr,
|
2014-04-20 11:39:35 +08:00
|
|
|
&dev_attr_firmware_id.attr,
|
2013-10-08 09:09:08 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-12-07 23:13:56 +08:00
|
|
|
static struct attribute_group serio_device_attr_group = {
|
|
|
|
.attrs = serio_device_attrs,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2013-10-08 09:09:08 +08:00
|
|
|
static const struct attribute_group *serio_device_attr_groups[] = {
|
|
|
|
&serio_id_attr_group,
|
2013-12-07 23:13:56 +08:00
|
|
|
&serio_device_attr_group,
|
2013-10-08 09:09:08 +08:00
|
|
|
NULL
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void serio_release_port(struct device *dev)
|
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
|
|
|
|
kfree(serio);
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare serio port for registration.
|
|
|
|
*/
|
|
|
|
static void serio_init_port(struct serio *serio)
|
|
|
|
{
|
2014-12-04 06:27:42 +08:00
|
|
|
static atomic_t serio_no = ATOMIC_INIT(-1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
__module_get(THIS_MODULE);
|
|
|
|
|
2006-07-19 13:14:55 +08:00
|
|
|
INIT_LIST_HEAD(&serio->node);
|
2010-10-05 12:46:10 +08:00
|
|
|
INIT_LIST_HEAD(&serio->child_node);
|
|
|
|
INIT_LIST_HEAD(&serio->children);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_init(&serio->lock);
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_init(&serio->drv_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
device_initialize(&serio->dev);
|
2014-10-09 06:21:32 +08:00
|
|
|
dev_set_name(&serio->dev, "serio%lu",
|
2014-12-04 06:27:42 +08:00
|
|
|
(unsigned long)atomic_inc_return(&serio_no));
|
2005-04-17 06:20:36 +08:00
|
|
|
serio->dev.bus = &serio_bus;
|
|
|
|
serio->dev.release = serio_release_port;
|
2010-01-06 09:56:03 +08:00
|
|
|
serio->dev.groups = serio_device_attr_groups;
|
2006-10-11 13:45:31 +08:00
|
|
|
if (serio->parent) {
|
2005-04-17 06:20:36 +08:00
|
|
|
serio->dev.parent = &serio->parent->dev;
|
2006-10-11 13:45:31 +08:00
|
|
|
serio->depth = serio->parent->depth + 1;
|
|
|
|
} else
|
|
|
|
serio->depth = 0;
|
|
|
|
lockdep_set_subclass(&serio->lock, serio->depth);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Complete serio port registration.
|
|
|
|
* Driver core will attempt to find appropriate driver for the port.
|
|
|
|
*/
|
|
|
|
static void serio_add_port(struct serio *serio)
|
|
|
|
{
|
2010-10-05 12:46:10 +08:00
|
|
|
struct serio *parent = serio->parent;
|
2006-07-19 13:14:55 +08:00
|
|
|
int error;
|
|
|
|
|
2010-10-05 12:46:10 +08:00
|
|
|
if (parent) {
|
|
|
|
serio_pause_rx(parent);
|
|
|
|
list_add_tail(&serio->child_node, &parent->children);
|
|
|
|
serio_continue_rx(parent);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&serio->node, &serio_list);
|
2010-01-06 09:56:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (serio->start)
|
|
|
|
serio->start(serio);
|
2010-01-06 09:56:03 +08:00
|
|
|
|
2006-07-19 13:14:55 +08:00
|
|
|
error = device_add(&serio->dev);
|
|
|
|
if (error)
|
2010-01-06 09:56:04 +08:00
|
|
|
dev_err(&serio->dev,
|
|
|
|
"device_add() failed for %s (%s), error: %d\n",
|
2006-07-19 13:14:55 +08:00
|
|
|
serio->phys, serio->name, error);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-05 12:46:10 +08:00
|
|
|
* serio_destroy_port() completes unregistration process and removes
|
2005-04-17 06:20:36 +08:00
|
|
|
* port from the system
|
|
|
|
*/
|
|
|
|
static void serio_destroy_port(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct serio *child;
|
|
|
|
|
2010-10-05 12:46:10 +08:00
|
|
|
while ((child = serio_get_pending_child(serio)) != NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_remove_pending_events(child);
|
|
|
|
put_device(&child->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serio->stop)
|
|
|
|
serio->stop(serio);
|
|
|
|
|
|
|
|
if (serio->parent) {
|
|
|
|
serio_pause_rx(serio->parent);
|
2010-10-05 12:46:10 +08:00
|
|
|
list_del_init(&serio->child_node);
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_continue_rx(serio->parent);
|
|
|
|
serio->parent = NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-06 09:56:04 +08:00
|
|
|
if (device_is_registered(&serio->dev))
|
2005-04-17 06:20:36 +08:00
|
|
|
device_del(&serio->dev);
|
|
|
|
|
2006-07-19 13:14:55 +08:00
|
|
|
list_del_init(&serio->node);
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_remove_pending_events(serio);
|
|
|
|
put_device(&serio->dev);
|
|
|
|
}
|
|
|
|
|
2008-07-03 22:45:38 +08:00
|
|
|
/*
|
|
|
|
* Reconnect serio port (re-initialize attached device).
|
|
|
|
* If reconnect fails (old device is no longer attached or
|
|
|
|
* there was no device to begin with) we do full rescan in
|
|
|
|
* hope of finding a driver for the port.
|
|
|
|
*/
|
|
|
|
static int serio_reconnect_port(struct serio *serio)
|
|
|
|
{
|
|
|
|
int error = serio_reconnect_driver(serio);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
serio_disconnect_port(serio);
|
|
|
|
serio_find_driver(serio);
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2010-10-05 12:46:10 +08:00
|
|
|
* Reconnect serio port and all its children (re-initialize attached
|
|
|
|
* devices).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2010-10-05 12:46:10 +08:00
|
|
|
static void serio_reconnect_subtree(struct serio *root)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-10-05 12:46:10 +08:00
|
|
|
struct serio *s = root;
|
|
|
|
int error;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
do {
|
2010-10-05 12:46:10 +08:00
|
|
|
error = serio_reconnect_port(s);
|
|
|
|
if (!error) {
|
|
|
|
/*
|
|
|
|
* Reconnect was successful, move on to do the
|
|
|
|
* first child.
|
|
|
|
*/
|
|
|
|
if (!list_empty(&s->children)) {
|
|
|
|
s = list_first_entry(&s->children,
|
|
|
|
struct serio, child_node);
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2010-10-05 12:46:10 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Either it was a leaf node or reconnect failed and it
|
|
|
|
* became a leaf node. Continue reconnecting starting with
|
|
|
|
* the next sibling of the parent node.
|
|
|
|
*/
|
|
|
|
while (s != root) {
|
|
|
|
struct serio *parent = s->parent;
|
|
|
|
|
|
|
|
if (!list_is_last(&s->child_node, &parent->children)) {
|
|
|
|
s = list_entry(s->child_node.next,
|
|
|
|
struct serio, child_node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = parent;
|
|
|
|
}
|
|
|
|
} while (s != root);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* serio_disconnect_port() unbinds a port from its driver. As a side effect
|
2010-10-05 12:46:10 +08:00
|
|
|
* all children ports are unbound and destroyed.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static void serio_disconnect_port(struct serio *serio)
|
|
|
|
{
|
2010-10-05 12:46:10 +08:00
|
|
|
struct serio *s = serio;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Children ports should be disconnected and destroyed
|
|
|
|
* first; we travel the tree in depth-first order.
|
|
|
|
*/
|
|
|
|
while (!list_empty(&serio->children)) {
|
|
|
|
|
|
|
|
/* Locate a leaf */
|
|
|
|
while (!list_empty(&s->children))
|
|
|
|
s = list_first_entry(&s->children,
|
|
|
|
struct serio, child_node);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2010-10-05 12:46:10 +08:00
|
|
|
* Prune this leaf node unless it is the one we
|
|
|
|
* started with.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2010-10-05 12:46:10 +08:00
|
|
|
if (s != serio) {
|
|
|
|
struct serio *parent = s->parent;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-04-10 12:40:27 +08:00
|
|
|
device_release_driver(&s->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_destroy_port(s);
|
2010-10-05 12:46:10 +08:00
|
|
|
|
|
|
|
s = parent;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-05 12:46:10 +08:00
|
|
|
* OK, no children left, now disconnect this port.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-04-10 12:40:27 +08:00
|
|
|
device_release_driver(&serio->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void serio_rescan(struct serio *serio)
|
|
|
|
{
|
2006-11-24 12:34:49 +08:00
|
|
|
serio_queue_event(serio, NULL, SERIO_RESCAN_PORT);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_rescan);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void serio_reconnect(struct serio *serio)
|
|
|
|
{
|
2010-10-05 12:46:10 +08:00
|
|
|
serio_queue_event(serio, NULL, SERIO_RECONNECT_SUBTREE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_reconnect);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Submits register request to kseriod for subsequent execution.
|
|
|
|
* Note that port registration is always asynchronous.
|
|
|
|
*/
|
|
|
|
void __serio_register_port(struct serio *serio, struct module *owner)
|
|
|
|
{
|
|
|
|
serio_init_port(serio);
|
|
|
|
serio_queue_event(serio, owner, SERIO_REGISTER_PORT);
|
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(__serio_register_port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Synchronously unregisters serio port.
|
|
|
|
*/
|
|
|
|
void serio_unregister_port(struct serio *serio)
|
|
|
|
{
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_lock(&serio_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_disconnect_port(serio);
|
|
|
|
serio_destroy_port(serio);
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_unregister_port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-28 08:49:45 +08:00
|
|
|
/*
|
2010-10-05 12:46:10 +08:00
|
|
|
* Safely unregisters children ports if they are present.
|
2005-06-28 08:49:45 +08:00
|
|
|
*/
|
|
|
|
void serio_unregister_child_port(struct serio *serio)
|
|
|
|
{
|
2010-10-05 12:46:10 +08:00
|
|
|
struct serio *s, *next;
|
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_lock(&serio_mutex);
|
2010-10-05 12:46:10 +08:00
|
|
|
list_for_each_entry_safe(s, next, &serio->children, child_node) {
|
|
|
|
serio_disconnect_port(s);
|
|
|
|
serio_destroy_port(s);
|
2005-06-28 08:49:45 +08:00
|
|
|
}
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio_mutex);
|
2005-06-28 08:49:45 +08:00
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_unregister_child_port);
|
2005-06-28 08:49:45 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Serio driver operations
|
|
|
|
*/
|
|
|
|
|
2013-08-24 05:24:34 +08:00
|
|
|
static ssize_t description_show(struct device_driver *drv, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio_driver *driver = to_serio_driver(drv);
|
|
|
|
return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)");
|
|
|
|
}
|
2013-08-24 05:24:34 +08:00
|
|
|
static DRIVER_ATTR_RO(description);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-08-24 05:24:34 +08:00
|
|
|
static ssize_t bind_mode_show(struct device_driver *drv, char *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio_driver *serio_drv = to_serio_driver(drv);
|
|
|
|
return sprintf(buf, "%s\n", serio_drv->manual_bind ? "manual" : "auto");
|
|
|
|
}
|
|
|
|
|
2013-08-24 05:24:34 +08:00
|
|
|
static ssize_t bind_mode_store(struct device_driver *drv, const char *buf, size_t count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio_driver *serio_drv = to_serio_driver(drv);
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = count;
|
|
|
|
if (!strncmp(buf, "manual", count)) {
|
2009-05-10 07:08:05 +08:00
|
|
|
serio_drv->manual_bind = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (!strncmp(buf, "auto", count)) {
|
2009-05-10 07:08:05 +08:00
|
|
|
serio_drv->manual_bind = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
retval = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2013-08-24 05:24:34 +08:00
|
|
|
static DRIVER_ATTR_RW(bind_mode);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-08-24 05:24:34 +08:00
|
|
|
static struct attribute *serio_driver_attrs[] = {
|
|
|
|
&driver_attr_description.attr,
|
|
|
|
&driver_attr_bind_mode.attr,
|
|
|
|
NULL,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
2013-08-24 05:24:34 +08:00
|
|
|
ATTRIBUTE_GROUPS(serio_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static int serio_driver_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
struct serio_driver *drv = to_serio_driver(dev->driver);
|
|
|
|
|
2005-06-28 08:49:45 +08:00
|
|
|
return serio_connect_driver(serio, drv);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int serio_driver_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
|
2005-06-28 08:49:45 +08:00
|
|
|
serio_disconnect_driver(serio);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-18 14:40:30 +08:00
|
|
|
static void serio_cleanup(struct serio *serio)
|
|
|
|
{
|
2007-06-29 13:06:35 +08:00
|
|
|
mutex_lock(&serio->drv_mutex);
|
2007-02-18 14:40:30 +08:00
|
|
|
if (serio->drv && serio->drv->cleanup)
|
|
|
|
serio->drv->cleanup(serio);
|
2007-06-29 13:06:35 +08:00
|
|
|
mutex_unlock(&serio->drv_mutex);
|
2007-02-18 14:40:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void serio_shutdown(struct device *dev)
|
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
|
|
|
|
serio_cleanup(serio);
|
|
|
|
}
|
|
|
|
|
2006-11-24 12:34:49 +08:00
|
|
|
static void serio_attach_driver(struct serio_driver *drv)
|
2006-07-19 13:14:55 +08:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2006-11-24 12:34:49 +08:00
|
|
|
error = driver_attach(&drv->driver);
|
2006-07-19 13:14:55 +08:00
|
|
|
if (error)
|
2017-03-18 08:15:38 +08:00
|
|
|
pr_warn("driver_attach() failed for %s with error %d\n",
|
|
|
|
drv->driver.name, error);
|
2006-07-19 13:14:55 +08:00
|
|
|
}
|
|
|
|
|
2007-01-16 03:50:02 +08:00
|
|
|
int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-05-10 07:08:05 +08:00
|
|
|
bool manual_bind = drv->manual_bind;
|
2006-11-24 12:34:49 +08:00
|
|
|
int error;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
drv->driver.bus = &serio_bus;
|
2007-01-16 03:50:02 +08:00
|
|
|
drv->driver.owner = owner;
|
|
|
|
drv->driver.mod_name = mod_name;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-11-24 12:34:49 +08:00
|
|
|
/*
|
|
|
|
* Temporarily disable automatic binding because probing
|
|
|
|
* takes long time and we are better off doing it in kseriod
|
|
|
|
*/
|
2009-05-10 07:08:05 +08:00
|
|
|
drv->manual_bind = true;
|
2006-11-24 12:34:49 +08:00
|
|
|
|
|
|
|
error = driver_register(&drv->driver);
|
|
|
|
if (error) {
|
2010-01-06 09:56:04 +08:00
|
|
|
pr_err("driver_register() failed for %s, error: %d\n",
|
2006-11-24 12:34:49 +08:00
|
|
|
drv->driver.name, error);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore original bind mode and let kseriod bind the
|
|
|
|
* driver to free ports
|
|
|
|
*/
|
|
|
|
if (!manual_bind) {
|
2009-05-10 07:08:05 +08:00
|
|
|
drv->manual_bind = false;
|
2006-11-24 12:34:49 +08:00
|
|
|
error = serio_queue_event(drv, NULL, SERIO_ATTACH_DRIVER);
|
|
|
|
if (error) {
|
|
|
|
driver_unregister(&drv->driver);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(__serio_register_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
void serio_unregister_driver(struct serio_driver *drv)
|
|
|
|
{
|
|
|
|
struct serio *serio;
|
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_lock(&serio_mutex);
|
2008-06-02 12:41:57 +08:00
|
|
|
|
2009-05-10 07:08:05 +08:00
|
|
|
drv->manual_bind = true; /* so serio_find_driver ignores it */
|
2008-06-02 12:41:57 +08:00
|
|
|
serio_remove_pending_events(drv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
start_over:
|
|
|
|
list_for_each_entry(serio, &serio_list, node) {
|
|
|
|
if (serio->drv == drv) {
|
|
|
|
serio_disconnect_port(serio);
|
|
|
|
serio_find_driver(serio);
|
|
|
|
/* we could've deleted some ports, restart */
|
|
|
|
goto start_over;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
driver_unregister(&drv->driver);
|
2006-02-19 13:21:55 +08:00
|
|
|
mutex_unlock(&serio_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_unregister_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
|
|
|
|
{
|
|
|
|
serio_pause_rx(serio);
|
|
|
|
serio->drv = drv;
|
|
|
|
serio_continue_rx(serio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int serio_bus_match(struct device *dev, struct device_driver *drv)
|
|
|
|
{
|
|
|
|
struct serio *serio = to_serio_port(dev);
|
|
|
|
struct serio_driver *serio_drv = to_serio_driver(drv);
|
|
|
|
|
|
|
|
if (serio->manual_bind || serio_drv->manual_bind)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return serio_match_port(serio_drv->id_table, serio);
|
|
|
|
}
|
|
|
|
|
2005-11-16 16:00:00 +08:00
|
|
|
#define SERIO_ADD_UEVENT_VAR(fmt, val...) \
|
2005-06-30 13:48:34 +08:00
|
|
|
do { \
|
2007-08-14 21:15:12 +08:00
|
|
|
int err = add_uevent_var(env, fmt, val); \
|
2005-06-30 13:48:34 +08:00
|
|
|
if (err) \
|
|
|
|
return err; \
|
|
|
|
} while (0)
|
|
|
|
|
2007-08-14 21:15:12 +08:00
|
|
|
static int serio_uevent(struct device *dev, struct kobj_uevent_env *env)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct serio *serio;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
serio = to_serio_port(dev);
|
|
|
|
|
2005-11-16 16:00:00 +08:00
|
|
|
SERIO_ADD_UEVENT_VAR("SERIO_TYPE=%02x", serio->id.type);
|
|
|
|
SERIO_ADD_UEVENT_VAR("SERIO_PROTO=%02x", serio->id.proto);
|
|
|
|
SERIO_ADD_UEVENT_VAR("SERIO_ID=%02x", serio->id.id);
|
|
|
|
SERIO_ADD_UEVENT_VAR("SERIO_EXTRA=%02x", serio->id.extra);
|
2014-04-20 11:39:35 +08:00
|
|
|
|
2005-11-16 16:00:00 +08:00
|
|
|
SERIO_ADD_UEVENT_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
|
2005-06-30 13:48:34 +08:00
|
|
|
serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-04-20 11:39:35 +08:00
|
|
|
if (serio->firmware_id[0])
|
|
|
|
SERIO_ADD_UEVENT_VAR("SERIO_FIRMWARE_ID=%s",
|
|
|
|
serio->firmware_id);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-11-16 16:00:00 +08:00
|
|
|
#undef SERIO_ADD_UEVENT_VAR
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-18 14:40:30 +08:00
|
|
|
#ifdef CONFIG_PM
|
2009-07-23 12:51:36 +08:00
|
|
|
static int serio_suspend(struct device *dev)
|
2007-02-18 14:40:30 +08:00
|
|
|
{
|
2009-05-10 07:08:05 +08:00
|
|
|
struct serio *serio = to_serio_port(dev);
|
2007-02-18 14:40:30 +08:00
|
|
|
|
2009-07-23 12:51:36 +08:00
|
|
|
serio_cleanup(serio);
|
2007-02-18 14:40:30 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int serio_resume(struct device *dev)
|
|
|
|
{
|
2009-05-10 07:08:05 +08:00
|
|
|
struct serio *serio = to_serio_port(dev);
|
2017-03-04 03:47:40 +08:00
|
|
|
int error = -ENOENT;
|
2009-05-10 07:08:05 +08:00
|
|
|
|
2017-03-04 03:47:40 +08:00
|
|
|
mutex_lock(&serio->drv_mutex);
|
|
|
|
if (serio->drv && serio->drv->fast_reconnect) {
|
|
|
|
error = serio->drv->fast_reconnect(serio);
|
|
|
|
if (error && error != -ENOENT)
|
|
|
|
dev_warn(dev, "fast reconnect failed with error %d\n",
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
mutex_unlock(&serio->drv_mutex);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
/*
|
|
|
|
* Driver reconnect can take a while, so better let
|
|
|
|
* kseriod deal with it.
|
|
|
|
*/
|
|
|
|
serio_queue_event(serio, NULL, SERIO_RECONNECT_PORT);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-23 12:51:36 +08:00
|
|
|
|
|
|
|
static const struct dev_pm_ops serio_pm_ops = {
|
|
|
|
.suspend = serio_suspend,
|
|
|
|
.resume = serio_resume,
|
|
|
|
.poweroff = serio_suspend,
|
|
|
|
.restore = serio_resume,
|
|
|
|
};
|
2007-02-18 14:40:30 +08:00
|
|
|
#endif /* CONFIG_PM */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
/* called from serio_driver->connect/disconnect methods under serio_mutex */
|
2005-04-17 06:20:36 +08:00
|
|
|
int serio_open(struct serio *serio, struct serio_driver *drv)
|
|
|
|
{
|
|
|
|
serio_set_drv(serio, drv);
|
|
|
|
|
|
|
|
if (serio->open && serio->open(serio)) {
|
|
|
|
serio_set_drv(serio, NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_open);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-02-19 13:21:55 +08:00
|
|
|
/* called from serio_driver->connect/disconnect methods under serio_mutex */
|
2005-04-17 06:20:36 +08:00
|
|
|
void serio_close(struct serio *serio)
|
|
|
|
{
|
|
|
|
if (serio->close)
|
|
|
|
serio->close(serio);
|
|
|
|
|
|
|
|
serio_set_drv(serio, NULL);
|
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_close);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
irqreturn_t serio_interrupt(struct serio *serio,
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
unsigned char data, unsigned int dfl)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
irqreturn_t ret = IRQ_NONE;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&serio->lock, flags);
|
|
|
|
|
|
|
|
if (likely(serio->drv)) {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
ret = serio->drv->interrupt(serio, data, dfl);
|
2010-01-06 09:56:04 +08:00
|
|
|
} else if (!dfl && device_is_registered(&serio->dev)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
serio_rescan(serio);
|
|
|
|
ret = IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&serio->lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-04-18 11:12:34 +08:00
|
|
|
EXPORT_SYMBOL(serio_interrupt);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-07-16 01:20:17 +08:00
|
|
|
struct bus_type serio_bus = {
|
2006-11-03 12:27:21 +08:00
|
|
|
.name = "serio",
|
2013-08-24 05:24:34 +08:00
|
|
|
.drv_groups = serio_driver_groups,
|
2006-11-03 12:27:21 +08:00
|
|
|
.match = serio_bus_match,
|
|
|
|
.uevent = serio_uevent,
|
|
|
|
.probe = serio_driver_probe,
|
|
|
|
.remove = serio_driver_remove,
|
2007-02-18 14:40:30 +08:00
|
|
|
.shutdown = serio_shutdown,
|
|
|
|
#ifdef CONFIG_PM
|
2009-07-23 12:51:36 +08:00
|
|
|
.pm = &serio_pm_ops,
|
2007-02-18 14:40:30 +08:00
|
|
|
#endif
|
2006-11-03 12:27:21 +08:00
|
|
|
};
|
2015-07-16 01:20:17 +08:00
|
|
|
EXPORT_SYMBOL(serio_bus);
|
2006-11-03 12:27:21 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init serio_init(void)
|
|
|
|
{
|
2006-07-19 13:14:55 +08:00
|
|
|
int error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-19 13:14:55 +08:00
|
|
|
error = bus_register(&serio_bus);
|
|
|
|
if (error) {
|
2010-01-06 09:56:04 +08:00
|
|
|
pr_err("Failed to register serio bus, error: %d\n", error);
|
2006-07-19 13:14:55 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit serio_exit(void)
|
|
|
|
{
|
|
|
|
bus_unregister(&serio_bus);
|
2010-11-15 17:39:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* There should not be any outstanding events but work may
|
|
|
|
* still be scheduled so simply cancel it.
|
|
|
|
*/
|
|
|
|
cancel_work_sync(&serio_event_work);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-02-19 13:22:51 +08:00
|
|
|
subsys_initcall(serio_init);
|
2005-04-17 06:20:36 +08:00
|
|
|
module_exit(serio_exit);
|