aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/tablet
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@insightbb.com>2007-05-21 00:17:57 -0400
committerDmitry Torokhov <dtor@insightbb.com>2007-07-10 00:35:15 -0400
commitcd438a58c89221d8642455d0cc8ec96d3b822f6e (patch)
tree27d1ee7b01e129bf602fd3736d58d34096d4f814 /drivers/input/tablet
parent02fb6c385c72823af4fac83963a05be9163c73ea (diff)
Input: aiptek - use maps in attributes
Use maps to convert for strings to internal constants and vice versa in aiptek's sysfs attribute methods instead of open-coding it. This results in smaller code that is also easier to maintain. [Rene: fix a typo - stylys instead of stylus] Signed-off-by: Rene van Paassen <rene.vanpaassen@gmail.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/tablet')
-rw-r--r--drivers/input/tablet/aiptek.c362
1 files changed, 138 insertions, 224 deletions
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 274c12f4220b..0c990e61ed73 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -344,6 +344,39 @@ static const int macroKeyEvents[] = {
344}; 344};
345 345
346/*********************************************************************** 346/***********************************************************************
347 * Map values to strings and back. Every map shoudl have the following
348 * as its last element: { NULL, AIPTEK_INVALID_VALUE }.
349 */
350#define AIPTEK_INVALID_VALUE -1
351
352struct aiptek_map {
353 const char *string;
354 int value;
355};
356
357static int map_str_to_val(const struct aiptek_map *map, const char *str, size_t count)
358{
359 const struct aiptek_map *p;
360
361 for (p = map; p->string; p++)
362 if (!strncmp(str, p->string, count))
363 return p->value;
364
365 return AIPTEK_INVALID_VALUE;
366}
367
368static const char *map_val_to_str(const struct aiptek_map *map, int val)
369{
370 const struct aiptek_map *p;
371
372 for (p = map; p->value != AIPTEK_INVALID_VALUE; p++)
373 if (val == p->value)
374 return p->string;
375
376 return "unknown";
377}
378
379/***********************************************************************
347 * Relative reports deliver values in 2's complement format to 380 * Relative reports deliver values in 2's complement format to
348 * deal with negative offsets. 381 * deal with negative offsets.
349 */ 382 */
@@ -1023,44 +1056,32 @@ static DEVICE_ATTR(size, S_IRUGO, show_tabletSize, NULL);
1023 * support routines for the 'pointer_mode' file. Note that this file 1056 * support routines for the 'pointer_mode' file. Note that this file
1024 * both displays current setting and allows reprogramming. 1057 * both displays current setting and allows reprogramming.
1025 */ 1058 */
1059static struct aiptek_map pointer_mode_map[] = {
1060 { "stylus", AIPTEK_POINTER_ONLY_STYLUS_MODE },
1061 { "mouse", AIPTEK_POINTER_ONLY_MOUSE_MODE },
1062 { "either", AIPTEK_POINTER_EITHER_MODE },
1063 { NULL, AIPTEK_INVALID_VALUE }
1064};
1065
1026static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf) 1066static ssize_t show_tabletPointerMode(struct device *dev, struct device_attribute *attr, char *buf)
1027{ 1067{
1028 struct aiptek *aiptek = dev_get_drvdata(dev); 1068 struct aiptek *aiptek = dev_get_drvdata(dev);
1029 char *s;
1030
1031 switch (aiptek->curSetting.pointerMode) {
1032 case AIPTEK_POINTER_ONLY_STYLUS_MODE:
1033 s = "stylus";
1034 break;
1035
1036 case AIPTEK_POINTER_ONLY_MOUSE_MODE:
1037 s = "mouse";
1038 break;
1039
1040 case AIPTEK_POINTER_EITHER_MODE:
1041 s = "either";
1042 break;
1043 1069
1044 default: 1070 return snprintf(buf, PAGE_SIZE, "%s\n",
1045 s = "unknown"; 1071 map_val_to_str(pointer_mode_map,
1046 break; 1072 aiptek->curSetting.pointerMode));
1047 }
1048 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1049} 1073}
1050 1074
1051static ssize_t 1075static ssize_t
1052store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1076store_tabletPointerMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1053{ 1077{
1054 struct aiptek *aiptek = dev_get_drvdata(dev); 1078 struct aiptek *aiptek = dev_get_drvdata(dev);
1079 int new_mode = map_str_to_val(pointer_mode_map, buf, count);
1055 1080
1056 if (strcmp(buf, "stylus") == 0) { 1081 if (new_mode == AIPTEK_INVALID_VALUE)
1057 aiptek->newSetting.pointerMode = 1082 return -EINVAL;
1058 AIPTEK_POINTER_ONLY_STYLUS_MODE; 1083
1059 } else if (strcmp(buf, "mouse") == 0) { 1084 aiptek->newSetting.pointerMode = new_mode;
1060 aiptek->newSetting.pointerMode = AIPTEK_POINTER_ONLY_MOUSE_MODE;
1061 } else if (strcmp(buf, "either") == 0) {
1062 aiptek->newSetting.pointerMode = AIPTEK_POINTER_EITHER_MODE;
1063 }
1064 return count; 1085 return count;
1065} 1086}
1066 1087
@@ -1072,39 +1093,32 @@ static DEVICE_ATTR(pointer_mode,
1072 * support routines for the 'coordinate_mode' file. Note that this file 1093 * support routines for the 'coordinate_mode' file. Note that this file
1073 * both displays current setting and allows reprogramming. 1094 * both displays current setting and allows reprogramming.
1074 */ 1095 */
1096
1097static struct aiptek_map coordinate_mode_map[] = {
1098 { "absolute", AIPTEK_COORDINATE_ABSOLUTE_MODE },
1099 { "relative", AIPTEK_COORDINATE_RELATIVE_MODE },
1100 { NULL, AIPTEK_INVALID_VALUE }
1101};
1102
1075static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf) 1103static ssize_t show_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, char *buf)
1076{ 1104{
1077 struct aiptek *aiptek = dev_get_drvdata(dev); 1105 struct aiptek *aiptek = dev_get_drvdata(dev);
1078 char *s;
1079
1080 switch (aiptek->curSetting.coordinateMode) {
1081 case AIPTEK_COORDINATE_ABSOLUTE_MODE:
1082 s = "absolute";
1083 break;
1084
1085 case AIPTEK_COORDINATE_RELATIVE_MODE:
1086 s = "relative";
1087 break;
1088 1106
1089 default: 1107 return snprintf(buf, PAGE_SIZE, "%s\n",
1090 s = "unknown"; 1108 map_val_to_str(coordinate_mode_map,
1091 break; 1109 aiptek->curSetting.coordinateMode));
1092 }
1093 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1094} 1110}
1095 1111
1096static ssize_t 1112static ssize_t
1097store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1113store_tabletCoordinateMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1098{ 1114{
1099 struct aiptek *aiptek = dev_get_drvdata(dev); 1115 struct aiptek *aiptek = dev_get_drvdata(dev);
1116 int new_mode = map_str_to_val(coordinate_mode_map, buf, count);
1100 1117
1101 if (strcmp(buf, "absolute") == 0) { 1118 if (new_mode == AIPTEK_INVALID_VALUE)
1102 aiptek->newSetting.pointerMode = 1119 return -EINVAL;
1103 AIPTEK_COORDINATE_ABSOLUTE_MODE; 1120
1104 } else if (strcmp(buf, "relative") == 0) { 1121 aiptek->newSetting.coordinateMode = new_mode;
1105 aiptek->newSetting.pointerMode =
1106 AIPTEK_COORDINATE_RELATIVE_MODE;
1107 }
1108 return count; 1122 return count;
1109} 1123}
1110 1124
@@ -1116,68 +1130,37 @@ static DEVICE_ATTR(coordinate_mode,
1116 * support routines for the 'tool_mode' file. Note that this file 1130 * support routines for the 'tool_mode' file. Note that this file
1117 * both displays current setting and allows reprogramming. 1131 * both displays current setting and allows reprogramming.
1118 */ 1132 */
1133
1134static struct aiptek_map tool_mode_map[] = {
1135 { "mouse", AIPTEK_TOOL_BUTTON_MOUSE_MODE },
1136 { "eraser", AIPTEK_TOOL_BUTTON_ERASER_MODE },
1137 { "pencil", AIPTEK_TOOL_BUTTON_PENCIL_MODE },
1138 { "pen", AIPTEK_TOOL_BUTTON_PEN_MODE },
1139 { "brush", AIPTEK_TOOL_BUTTON_BRUSH_MODE },
1140 { "airbrush", AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE },
1141 { "lens", AIPTEK_TOOL_BUTTON_LENS_MODE },
1142 { NULL, AIPTEK_INVALID_VALUE }
1143};
1144
1119static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf) 1145static ssize_t show_tabletToolMode(struct device *dev, struct device_attribute *attr, char *buf)
1120{ 1146{
1121 struct aiptek *aiptek = dev_get_drvdata(dev); 1147 struct aiptek *aiptek = dev_get_drvdata(dev);
1122 char *s;
1123
1124 switch (TOOL_BUTTON(aiptek->curSetting.toolMode)) {
1125 case AIPTEK_TOOL_BUTTON_MOUSE_MODE:
1126 s = "mouse";
1127 break;
1128 1148
1129 case AIPTEK_TOOL_BUTTON_ERASER_MODE: 1149 return snprintf(buf, PAGE_SIZE, "%s\n",
1130 s = "eraser"; 1150 map_val_to_str(tool_mode_map,
1131 break; 1151 aiptek->curSetting.toolMode));
1132
1133 case AIPTEK_TOOL_BUTTON_PENCIL_MODE:
1134 s = "pencil";
1135 break;
1136
1137 case AIPTEK_TOOL_BUTTON_PEN_MODE:
1138 s = "pen";
1139 break;
1140
1141 case AIPTEK_TOOL_BUTTON_BRUSH_MODE:
1142 s = "brush";
1143 break;
1144
1145 case AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE:
1146 s = "airbrush";
1147 break;
1148
1149 case AIPTEK_TOOL_BUTTON_LENS_MODE:
1150 s = "lens";
1151 break;
1152
1153 default:
1154 s = "unknown";
1155 break;
1156 }
1157 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1158} 1152}
1159 1153
1160static ssize_t 1154static ssize_t
1161store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1155store_tabletToolMode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1162{ 1156{
1163 struct aiptek *aiptek = dev_get_drvdata(dev); 1157 struct aiptek *aiptek = dev_get_drvdata(dev);
1158 int new_mode = map_str_to_val(tool_mode_map, buf, count);
1164 1159
1165 if (strcmp(buf, "mouse") == 0) { 1160 if (new_mode == AIPTEK_INVALID_VALUE)
1166 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_MOUSE_MODE; 1161 return -EINVAL;
1167 } else if (strcmp(buf, "eraser") == 0) {
1168 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_ERASER_MODE;
1169 } else if (strcmp(buf, "pencil") == 0) {
1170 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PENCIL_MODE;
1171 } else if (strcmp(buf, "pen") == 0) {
1172 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_PEN_MODE;
1173 } else if (strcmp(buf, "brush") == 0) {
1174 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_BRUSH_MODE;
1175 } else if (strcmp(buf, "airbrush") == 0) {
1176 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_AIRBRUSH_MODE;
1177 } else if (strcmp(buf, "lens") == 0) {
1178 aiptek->newSetting.toolMode = AIPTEK_TOOL_BUTTON_LENS_MODE;
1179 }
1180 1162
1163 aiptek->newSetting.toolMode = new_mode;
1181 return count; 1164 return count;
1182} 1165}
1183 1166
@@ -1362,39 +1345,32 @@ static DEVICE_ATTR(diagnostic, S_IRUGO, show_tabletDiagnosticMessage, NULL);
1362 * support routines for the 'stylus_upper' file. Note that this file 1345 * support routines for the 'stylus_upper' file. Note that this file
1363 * both displays current setting and allows for setting changing. 1346 * both displays current setting and allows for setting changing.
1364 */ 1347 */
1348
1349static struct aiptek_map stylus_button_map[] = {
1350 { "upper", AIPTEK_STYLUS_UPPER_BUTTON },
1351 { "lower", AIPTEK_STYLUS_LOWER_BUTTON },
1352 { NULL, AIPTEK_INVALID_VALUE }
1353};
1354
1365static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf) 1355static ssize_t show_tabletStylusUpper(struct device *dev, struct device_attribute *attr, char *buf)
1366{ 1356{
1367 struct aiptek *aiptek = dev_get_drvdata(dev); 1357 struct aiptek *aiptek = dev_get_drvdata(dev);
1368 char *s;
1369
1370 switch (aiptek->curSetting.stylusButtonUpper) {
1371 case AIPTEK_STYLUS_UPPER_BUTTON:
1372 s = "upper";
1373 break;
1374
1375 case AIPTEK_STYLUS_LOWER_BUTTON:
1376 s = "lower";
1377 break;
1378 1358
1379 default: 1359 return snprintf(buf, PAGE_SIZE, "%s\n",
1380 s = "unknown"; 1360 map_val_to_str(stylus_button_map,
1381 break; 1361 aiptek->curSetting.stylusButtonUpper));
1382 }
1383 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1384} 1362}
1385 1363
1386static ssize_t 1364static ssize_t
1387store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1365store_tabletStylusUpper(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1388{ 1366{
1389 struct aiptek *aiptek = dev_get_drvdata(dev); 1367 struct aiptek *aiptek = dev_get_drvdata(dev);
1368 int new_button = map_str_to_val(stylus_button_map, buf, count);
1390 1369
1391 if (strcmp(buf, "upper") == 0) { 1370 if (new_button == AIPTEK_INVALID_VALUE)
1392 aiptek->newSetting.stylusButtonUpper = 1371 return -EINVAL;
1393 AIPTEK_STYLUS_UPPER_BUTTON; 1372
1394 } else if (strcmp(buf, "lower") == 0) { 1373 aiptek->newSetting.stylusButtonUpper = new_button;
1395 aiptek->newSetting.stylusButtonUpper =
1396 AIPTEK_STYLUS_LOWER_BUTTON;
1397 }
1398 return count; 1374 return count;
1399} 1375}
1400 1376
@@ -1406,39 +1382,26 @@ static DEVICE_ATTR(stylus_upper,
1406 * support routines for the 'stylus_lower' file. Note that this file 1382 * support routines for the 'stylus_lower' file. Note that this file
1407 * both displays current setting and allows for setting changing. 1383 * both displays current setting and allows for setting changing.
1408 */ 1384 */
1385
1409static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf) 1386static ssize_t show_tabletStylusLower(struct device *dev, struct device_attribute *attr, char *buf)
1410{ 1387{
1411 struct aiptek *aiptek = dev_get_drvdata(dev); 1388 struct aiptek *aiptek = dev_get_drvdata(dev);
1412 char *s;
1413
1414 switch (aiptek->curSetting.stylusButtonLower) {
1415 case AIPTEK_STYLUS_UPPER_BUTTON:
1416 s = "upper";
1417 break;
1418
1419 case AIPTEK_STYLUS_LOWER_BUTTON:
1420 s = "lower";
1421 break;
1422 1389
1423 default: 1390 return snprintf(buf, PAGE_SIZE, "%s\n",
1424 s = "unknown"; 1391 map_val_to_str(stylus_button_map,
1425 break; 1392 aiptek->curSetting.stylusButtonLower));
1426 }
1427 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1428} 1393}
1429 1394
1430static ssize_t 1395static ssize_t
1431store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1396store_tabletStylusLower(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1432{ 1397{
1433 struct aiptek *aiptek = dev_get_drvdata(dev); 1398 struct aiptek *aiptek = dev_get_drvdata(dev);
1399 int new_button = map_str_to_val(stylus_button_map, buf, count);
1434 1400
1435 if (strcmp(buf, "upper") == 0) { 1401 if (new_button == AIPTEK_INVALID_VALUE)
1436 aiptek->newSetting.stylusButtonLower = 1402 return -EINVAL;
1437 AIPTEK_STYLUS_UPPER_BUTTON; 1403
1438 } else if (strcmp(buf, "lower") == 0) { 1404 aiptek->newSetting.stylusButtonLower = new_button;
1439 aiptek->newSetting.stylusButtonLower =
1440 AIPTEK_STYLUS_LOWER_BUTTON;
1441 }
1442 return count; 1405 return count;
1443} 1406}
1444 1407
@@ -1450,43 +1413,33 @@ static DEVICE_ATTR(stylus_lower,
1450 * support routines for the 'mouse_left' file. Note that this file 1413 * support routines for the 'mouse_left' file. Note that this file
1451 * both displays current setting and allows for setting changing. 1414 * both displays current setting and allows for setting changing.
1452 */ 1415 */
1416
1417static struct aiptek_map mouse_button_map[] = {
1418 { "left", AIPTEK_MOUSE_LEFT_BUTTON },
1419 { "middle", AIPTEK_MOUSE_MIDDLE_BUTTON },
1420 { "right", AIPTEK_MOUSE_RIGHT_BUTTON },
1421 { NULL, AIPTEK_INVALID_VALUE }
1422};
1423
1453static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf) 1424static ssize_t show_tabletMouseLeft(struct device *dev, struct device_attribute *attr, char *buf)
1454{ 1425{
1455 struct aiptek *aiptek = dev_get_drvdata(dev); 1426 struct aiptek *aiptek = dev_get_drvdata(dev);
1456 char *s;
1457
1458 switch (aiptek->curSetting.mouseButtonLeft) {
1459 case AIPTEK_MOUSE_LEFT_BUTTON:
1460 s = "left";
1461 break;
1462
1463 case AIPTEK_MOUSE_MIDDLE_BUTTON:
1464 s = "middle";
1465 break;
1466 1427
1467 case AIPTEK_MOUSE_RIGHT_BUTTON: 1428 return snprintf(buf, PAGE_SIZE, "%s\n",
1468 s = "right"; 1429 map_val_to_str(mouse_button_map,
1469 break; 1430 aiptek->curSetting.mouseButtonLeft));
1470
1471 default:
1472 s = "unknown";
1473 break;
1474 }
1475 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1476} 1431}
1477 1432
1478static ssize_t 1433static ssize_t
1479store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1434store_tabletMouseLeft(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1480{ 1435{
1481 struct aiptek *aiptek = dev_get_drvdata(dev); 1436 struct aiptek *aiptek = dev_get_drvdata(dev);
1437 int new_button = map_str_to_val(mouse_button_map, buf, count);
1482 1438
1483 if (strcmp(buf, "left") == 0) { 1439 if (new_button == AIPTEK_INVALID_VALUE)
1484 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_LEFT_BUTTON; 1440 return -EINVAL;
1485 } else if (strcmp(buf, "middle") == 0) { 1441
1486 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_MIDDLE_BUTTON; 1442 aiptek->newSetting.mouseButtonLeft = new_button;
1487 } else if (strcmp(buf, "right") == 0) {
1488 aiptek->newSetting.mouseButtonLeft = AIPTEK_MOUSE_RIGHT_BUTTON;
1489 }
1490 return count; 1443 return count;
1491} 1444}
1492 1445
@@ -1501,42 +1454,22 @@ static DEVICE_ATTR(mouse_left,
1501static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf) 1454static ssize_t show_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, char *buf)
1502{ 1455{
1503 struct aiptek *aiptek = dev_get_drvdata(dev); 1456 struct aiptek *aiptek = dev_get_drvdata(dev);
1504 char *s;
1505 1457
1506 switch (aiptek->curSetting.mouseButtonMiddle) { 1458 return snprintf(buf, PAGE_SIZE, "%s\n",
1507 case AIPTEK_MOUSE_LEFT_BUTTON: 1459 map_val_to_str(mouse_button_map,
1508 s = "left"; 1460 aiptek->curSetting.mouseButtonMiddle));
1509 break;
1510
1511 case AIPTEK_MOUSE_MIDDLE_BUTTON:
1512 s = "middle";
1513 break;
1514
1515 case AIPTEK_MOUSE_RIGHT_BUTTON:
1516 s = "right";
1517 break;
1518
1519 default:
1520 s = "unknown";
1521 break;
1522 }
1523 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1524} 1461}
1525 1462
1526static ssize_t 1463static ssize_t
1527store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1464store_tabletMouseMiddle(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1528{ 1465{
1529 struct aiptek *aiptek = dev_get_drvdata(dev); 1466 struct aiptek *aiptek = dev_get_drvdata(dev);
1467 int new_button = map_str_to_val(mouse_button_map, buf, count);
1530 1468
1531 if (strcmp(buf, "left") == 0) { 1469 if (new_button == AIPTEK_INVALID_VALUE)
1532 aiptek->newSetting.mouseButtonMiddle = AIPTEK_MOUSE_LEFT_BUTTON; 1470 return -EINVAL;
1533 } else if (strcmp(buf, "middle") == 0) { 1471
1534 aiptek->newSetting.mouseButtonMiddle = 1472 aiptek->newSetting.mouseButtonMiddle = new_button;
1535 AIPTEK_MOUSE_MIDDLE_BUTTON;
1536 } else if (strcmp(buf, "right") == 0) {
1537 aiptek->newSetting.mouseButtonMiddle =
1538 AIPTEK_MOUSE_RIGHT_BUTTON;
1539 }
1540 return count; 1473 return count;
1541} 1474}
1542 1475
@@ -1551,41 +1484,22 @@ static DEVICE_ATTR(mouse_middle,
1551static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf) 1484static ssize_t show_tabletMouseRight(struct device *dev, struct device_attribute *attr, char *buf)
1552{ 1485{
1553 struct aiptek *aiptek = dev_get_drvdata(dev); 1486 struct aiptek *aiptek = dev_get_drvdata(dev);
1554 char *s;
1555
1556 switch (aiptek->curSetting.mouseButtonRight) {
1557 case AIPTEK_MOUSE_LEFT_BUTTON:
1558 s = "left";
1559 break;
1560
1561 case AIPTEK_MOUSE_MIDDLE_BUTTON:
1562 s = "middle";
1563 break;
1564 1487
1565 case AIPTEK_MOUSE_RIGHT_BUTTON: 1488 return snprintf(buf, PAGE_SIZE, "%s\n",
1566 s = "right"; 1489 map_val_to_str(mouse_button_map,
1567 break; 1490 aiptek->curSetting.mouseButtonRight));
1568
1569 default:
1570 s = "unknown";
1571 break;
1572 }
1573 return snprintf(buf, PAGE_SIZE, "%s\n", s);
1574} 1491}
1575 1492
1576static ssize_t 1493static ssize_t
1577store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1494store_tabletMouseRight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1578{ 1495{
1579 struct aiptek *aiptek = dev_get_drvdata(dev); 1496 struct aiptek *aiptek = dev_get_drvdata(dev);
1497 int new_button = map_str_to_val(mouse_button_map, buf, count);
1580 1498
1581 if (strcmp(buf, "left") == 0) { 1499 if (new_button == AIPTEK_INVALID_VALUE)
1582 aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_LEFT_BUTTON; 1500 return -EINVAL;
1583 } else if (strcmp(buf, "middle") == 0) { 1501
1584 aiptek->newSetting.mouseButtonRight = 1502 aiptek->newSetting.mouseButtonRight = new_button;
1585 AIPTEK_MOUSE_MIDDLE_BUTTON;
1586 } else if (strcmp(buf, "right") == 0) {
1587 aiptek->newSetting.mouseButtonRight = AIPTEK_MOUSE_RIGHT_BUTTON;
1588 }
1589 return count; 1503 return count;
1590} 1504}
1591 1505