Commit ae87dff7 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: serio - add modalias attribute and environment variable to

       simplify hotplug scripts.
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 0048e603
...@@ -389,6 +389,14 @@ static ssize_t serio_show_description(struct device *dev, struct device_attribut ...@@ -389,6 +389,14 @@ static ssize_t serio_show_description(struct device *dev, struct device_attribut
return sprintf(buf, "%s\n", serio->name); return sprintf(buf, "%s\n", serio->name);
} }
static ssize_t serio_show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
{
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);
}
static ssize_t serio_show_id_type(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t serio_show_id_type(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct serio *serio = to_serio_port(dev); struct serio *serio = to_serio_port(dev);
...@@ -487,6 +495,7 @@ static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute * ...@@ -487,6 +495,7 @@ static ssize_t serio_set_bind_mode(struct device *dev, struct device_attribute *
static struct device_attribute serio_device_attrs[] = { static struct device_attribute serio_device_attrs[] = {
__ATTR(description, S_IRUGO, serio_show_description, NULL), __ATTR(description, S_IRUGO, serio_show_description, NULL),
__ATTR(modalias, S_IRUGO, serio_show_modalias, NULL),
__ATTR(drvctl, S_IWUSR, NULL, serio_rebind_driver), __ATTR(drvctl, S_IWUSR, NULL, serio_rebind_driver),
__ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode), __ATTR(bind_mode, S_IWUSR | S_IRUGO, serio_show_bind_mode, serio_set_bind_mode),
__ATTR_NULL __ATTR_NULL
...@@ -785,36 +794,37 @@ static int serio_bus_match(struct device *dev, struct device_driver *drv) ...@@ -785,36 +794,37 @@ static int serio_bus_match(struct device *dev, struct device_driver *drv)
#ifdef CONFIG_HOTPLUG #ifdef CONFIG_HOTPLUG
#define PUT_ENVP(fmt, val) \ #define SERIO_ADD_HOTPLUG_VAR(fmt, val...) \
do { \ do { \
envp[i++] = buffer; \ int err = add_hotplug_env_var(envp, num_envp, &i, \
length += snprintf(buffer, buffer_size - length, fmt, val); \ buffer, buffer_size, &len, \
if (buffer_size - length <= 0 || i >= num_envp) \ fmt, val); \
return -ENOMEM; \ if (err) \
length++; \ return err; \
buffer += length; \ } while (0)
} while (0)
static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size) static int serio_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
{ {
struct serio *serio; struct serio *serio;
int i = 0; int i = 0;
int length = 0; int len = 0;
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
serio = to_serio_port(dev); serio = to_serio_port(dev);
PUT_ENVP("SERIO_TYPE=%02x", serio->id.type); SERIO_ADD_HOTPLUG_VAR("SERIO_TYPE=%02x", serio->id.type);
PUT_ENVP("SERIO_PROTO=%02x", serio->id.proto); SERIO_ADD_HOTPLUG_VAR("SERIO_PROTO=%02x", serio->id.proto);
PUT_ENVP("SERIO_ID=%02x", serio->id.id); SERIO_ADD_HOTPLUG_VAR("SERIO_ID=%02x", serio->id.id);
PUT_ENVP("SERIO_EXTRA=%02x", serio->id.extra); SERIO_ADD_HOTPLUG_VAR("SERIO_EXTRA=%02x", serio->id.extra);
SERIO_ADD_HOTPLUG_VAR("MODALIAS=serio:ty%02Xpr%02Xid%02Xex%02X",
serio->id.type, serio->id.proto, serio->id.id, serio->id.extra);
envp[i] = NULL; envp[i] = NULL;
return 0; return 0;
} }
#undef PUT_ENVP #undef SERIO_ADD_HOTPLUG_VAR
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment