aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse/psmouse-base.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor_core@ameritech.net>2005-09-04 02:40:20 -0400
committerDmitry Torokhov <dtor_core@ameritech.net>2005-09-04 02:40:20 -0400
commitcfe9e88866fe892f4f71bf132c64ec8bd5256e5e (patch)
treec1da19c8a2b1f9f1a32597554660747fe0aa5132 /drivers/input/mouse/psmouse-base.c
parent15c42e5a1f0bccb69508059b8ae0720840068b8e (diff)
Input: rework psmouse attributes to reduce module size
Rearrange attribute code to use generic show and set handlers instead of replicating them for every attribute; switch to using attribute_group instead of creating all attributes manually. All this saves about 4K. Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/mouse/psmouse-base.c')
-rw-r--r--drivers/input/mouse/psmouse-base.c117
1 files changed, 66 insertions, 51 deletions
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index b3508276785f..0830c6e13ef6 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -58,10 +58,30 @@ static unsigned int psmouse_resetafter;
58module_param_named(resetafter, psmouse_resetafter, uint, 0644); 58module_param_named(resetafter, psmouse_resetafter, uint, 0644);
59MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never)."); 59MODULE_PARM_DESC(resetafter, "Reset device after so many bad packets (0 = never).");
60 60
61PSMOUSE_DEFINE_ATTR(protocol); 61PSMOUSE_DEFINE_ATTR(protocol, S_IWUSR | S_IRUGO,
62PSMOUSE_DEFINE_ATTR(rate); 62 NULL,
63PSMOUSE_DEFINE_ATTR(resolution); 63 psmouse_attr_show_protocol, psmouse_attr_set_protocol);
64PSMOUSE_DEFINE_ATTR(resetafter); 64PSMOUSE_DEFINE_ATTR(rate, S_IWUSR | S_IRUGO,
65 (void *) offsetof(struct psmouse, rate),
66 psmouse_show_int_attr, psmouse_attr_set_rate);
67PSMOUSE_DEFINE_ATTR(resolution, S_IWUSR | S_IRUGO,
68 (void *) offsetof(struct psmouse, resolution),
69 psmouse_show_int_attr, psmouse_attr_set_resolution);
70PSMOUSE_DEFINE_ATTR(resetafter, S_IWUSR | S_IRUGO,
71 (void *) offsetof(struct psmouse, resetafter),
72 psmouse_show_int_attr, psmouse_set_int_attr);
73
74static struct attribute *psmouse_attributes[] = {
75 &psmouse_attr_protocol.dattr.attr,
76 &psmouse_attr_rate.dattr.attr,
77 &psmouse_attr_resolution.dattr.attr,
78 &psmouse_attr_resetafter.dattr.attr,
79 NULL
80};
81
82static struct attribute_group psmouse_attribute_group = {
83 .attrs = psmouse_attributes,
84};
65 85
66__obsolete_setup("psmouse_noext"); 86__obsolete_setup("psmouse_noext");
67__obsolete_setup("psmouse_resolution="); 87__obsolete_setup("psmouse_resolution=");
@@ -800,10 +820,7 @@ static void psmouse_disconnect(struct serio *serio)
800 820
801 psmouse = serio_get_drvdata(serio); 821 psmouse = serio_get_drvdata(serio);
802 822
803 device_remove_file(&serio->dev, &psmouse_attr_protocol); 823 sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group);
804 device_remove_file(&serio->dev, &psmouse_attr_rate);
805 device_remove_file(&serio->dev, &psmouse_attr_resolution);
806 device_remove_file(&serio->dev, &psmouse_attr_resetafter);
807 824
808 down(&psmouse_sem); 825 down(&psmouse_sem);
809 826
@@ -940,10 +957,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
940 if (parent && parent->pt_activate) 957 if (parent && parent->pt_activate)
941 parent->pt_activate(parent); 958 parent->pt_activate(parent);
942 959
943 device_create_file(&serio->dev, &psmouse_attr_protocol); 960 sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
944 device_create_file(&serio->dev, &psmouse_attr_rate);
945 device_create_file(&serio->dev, &psmouse_attr_resolution);
946 device_create_file(&serio->dev, &psmouse_attr_resetafter);
947 961
948 psmouse_activate(psmouse); 962 psmouse_activate(psmouse);
949 963
@@ -1040,10 +1054,12 @@ static struct serio_driver psmouse_drv = {
1040 .cleanup = psmouse_cleanup, 1054 .cleanup = psmouse_cleanup,
1041}; 1055};
1042 1056
1043ssize_t psmouse_attr_show_helper(struct device *dev, char *buf, 1057ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *devattr,
1044 ssize_t (*handler)(struct psmouse *, char *)) 1058 char *buf)
1045{ 1059{
1046 struct serio *serio = to_serio_port(dev); 1060 struct serio *serio = to_serio_port(dev);
1061 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1062 struct psmouse *psmouse;
1047 int retval; 1063 int retval;
1048 1064
1049 retval = serio_pin_driver(serio); 1065 retval = serio_pin_driver(serio);
@@ -1055,19 +1071,21 @@ ssize_t psmouse_attr_show_helper(struct device *dev, char *buf,
1055 goto out; 1071 goto out;
1056 } 1072 }
1057 1073
1058 retval = handler(serio_get_drvdata(serio), buf); 1074 psmouse = serio_get_drvdata(serio);
1075
1076 retval = attr->show(psmouse, attr->data, buf);
1059 1077
1060out: 1078out:
1061 serio_unpin_driver(serio); 1079 serio_unpin_driver(serio);
1062 return retval; 1080 return retval;
1063} 1081}
1064 1082
1065ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t count, 1083ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *devattr,
1066 ssize_t (*handler)(struct psmouse *, const char *, size_t)) 1084 const char *buf, size_t count)
1067{ 1085{
1068 struct serio *serio = to_serio_port(dev); 1086 struct serio *serio = to_serio_port(dev);
1069 struct psmouse *psmouse = serio_get_drvdata(serio); 1087 struct psmouse_attribute *attr = to_psmouse_attr(devattr);
1070 struct psmouse *parent = NULL; 1088 struct psmouse *psmouse, *parent = NULL;
1071 int retval; 1089 int retval;
1072 1090
1073 retval = serio_pin_driver(serio); 1091 retval = serio_pin_driver(serio);
@@ -1083,6 +1101,8 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
1083 if (retval) 1101 if (retval)
1084 goto out_unpin; 1102 goto out_unpin;
1085 1103
1104 psmouse = serio_get_drvdata(serio);
1105
1086 if (psmouse->state == PSMOUSE_IGNORE) { 1106 if (psmouse->state == PSMOUSE_IGNORE) {
1087 retval = -ENODEV; 1107 retval = -ENODEV;
1088 goto out_up; 1108 goto out_up;
@@ -1095,7 +1115,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
1095 1115
1096 psmouse_deactivate(psmouse); 1116 psmouse_deactivate(psmouse);
1097 1117
1098 retval = handler(psmouse, buf, count); 1118 retval = attr->set(psmouse, attr->data, buf, count);
1099 1119
1100 if (retval != -ENODEV) 1120 if (retval != -ENODEV)
1101 psmouse_activate(psmouse); 1121 psmouse_activate(psmouse);
@@ -1110,12 +1130,34 @@ ssize_t psmouse_attr_set_helper(struct device *dev, const char *buf, size_t coun
1110 return retval; 1130 return retval;
1111} 1131}
1112 1132
1113static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, char *buf) 1133static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf)
1134{
1135 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset);
1136
1137 return sprintf(buf, "%lu\n", *field);
1138}
1139
1140static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
1141{
1142 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset);
1143 unsigned long value;
1144 char *rest;
1145
1146 value = simple_strtoul(buf, &rest, 10);
1147 if (*rest)
1148 return -EINVAL;
1149
1150 *field = value;
1151
1152 return count;
1153}
1154
1155static ssize_t psmouse_attr_show_protocol(struct psmouse *psmouse, void *data, char *buf)
1114{ 1156{
1115 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name); 1157 return sprintf(buf, "%s\n", psmouse_protocol_by_type(psmouse->type)->name);
1116} 1158}
1117 1159
1118static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, const char *buf, size_t count) 1160static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1119{ 1161{
1120 struct serio *serio = psmouse->ps2dev.serio; 1162 struct serio *serio = psmouse->ps2dev.serio;
1121 struct psmouse *parent = NULL; 1163 struct psmouse *parent = NULL;
@@ -1179,12 +1221,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, const char *bu
1179 return count; 1221 return count;
1180} 1222}
1181 1223
1182static ssize_t psmouse_attr_show_rate(struct psmouse *psmouse, char *buf) 1224static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1183{
1184 return sprintf(buf, "%d\n", psmouse->rate);
1185}
1186
1187static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, const char *buf, size_t count)
1188{ 1225{
1189 unsigned long value; 1226 unsigned long value;
1190 char *rest; 1227 char *rest;
@@ -1197,12 +1234,7 @@ static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, const char *buf, s
1197 return count; 1234 return count;
1198} 1235}
1199 1236
1200static ssize_t psmouse_attr_show_resolution(struct psmouse *psmouse, char *buf) 1237static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1201{
1202 return sprintf(buf, "%d\n", psmouse->resolution);
1203}
1204
1205static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, const char *buf, size_t count)
1206{ 1238{
1207 unsigned long value; 1239 unsigned long value;
1208 char *rest; 1240 char *rest;
@@ -1215,23 +1247,6 @@ static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, const char *
1215 return count; 1247 return count;
1216} 1248}
1217 1249
1218static ssize_t psmouse_attr_show_resetafter(struct psmouse *psmouse, char *buf)
1219{
1220 return sprintf(buf, "%d\n", psmouse->resetafter);
1221}
1222
1223static ssize_t psmouse_attr_set_resetafter(struct psmouse *psmouse, const char *buf, size_t count)
1224{
1225 unsigned long value;
1226 char *rest;
1227
1228 value = simple_strtoul(buf, &rest, 10);
1229 if (*rest)
1230 return -EINVAL;
1231
1232 psmouse->resetafter = value;
1233 return count;
1234}
1235 1250
1236static int psmouse_set_maxproto(const char *val, struct kernel_param *kp) 1251static int psmouse_set_maxproto(const char *val, struct kernel_param *kp)
1237{ 1252{