Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: wacom_w8001 - simplify querying logic

There is no need for locking when we send query and start commands
to the touchscreen since there is no concurrency.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

+41 -82
+41 -82
drivers/input/touchscreen/wacom_w8001.c
··· 25 25 MODULE_DESCRIPTION(DRIVER_DESC); 26 26 MODULE_LICENSE("GPL"); 27 27 28 - /* 29 - * Definitions & global arrays. 30 - */ 31 - 32 28 #define W8001_MAX_LENGTH 11 33 - #define W8001_PACKET_LEN 11 34 - #define W8001_LEAD_MASK 0x80 35 - #define W8001_LEAD_BYTE 0x80 36 - #define W8001_TAB_MASK 0x40 37 - #define W8001_TAB_BYTE 0x40 29 + #define W8001_LEAD_MASK 0x80 30 + #define W8001_LEAD_BYTE 0x80 31 + #define W8001_TAB_MASK 0x40 32 + #define W8001_TAB_BYTE 0x40 38 33 39 - #define W8001_QUERY_PACKET 0x20 34 + #define W8001_QUERY_PACKET 0x20 35 + 36 + #define W8001_CMD_START '1' 37 + #define W8001_CMD_QUERY '*' 40 38 41 39 struct w8001_coord { 42 40 u8 rdy; ··· 55 57 struct w8001 { 56 58 struct input_dev *dev; 57 59 struct serio *serio; 58 - struct mutex cmd_mutex; 59 60 struct completion cmd_done; 60 61 int id; 61 62 int idx; 62 - unsigned char expected_packet; 63 + unsigned char response_type; 64 + unsigned char response[W8001_MAX_LENGTH]; 63 65 unsigned char data[W8001_MAX_LENGTH]; 64 - unsigned char response[W8001_PACKET_LEN]; 65 66 char phys[32]; 66 67 }; 67 68 68 - static int parse_data(u8 *data, struct w8001_coord *coord) 69 + static void parse_data(u8 *data, struct w8001_coord *coord) 69 70 { 71 + memset(coord, 0, sizeof(*coord)); 72 + 70 73 coord->rdy = data[0] & 0x20; 71 74 coord->tsw = data[0] & 0x01; 72 75 coord->f1 = data[0] & 0x02; ··· 86 87 87 88 coord->tilt_x = data[7] & 0x7F; 88 89 coord->tilt_y = data[8] & 0x7F; 89 - 90 - return 0; 91 90 } 92 91 93 - static void w8001_process_data(struct w8001 *w8001, unsigned char data) 92 + static irqreturn_t w8001_interrupt(struct serio *serio, 93 + unsigned char data, unsigned int flags) 94 94 { 95 + struct w8001 *w8001 = serio_get_drvdata(serio); 95 96 struct input_dev *dev = w8001->dev; 96 - u8 tmp; 97 97 struct w8001_coord coord; 98 + unsigned char tmp; 98 99 99 100 w8001->data[w8001->idx] = data; 100 101 switch (w8001->idx++) { ··· 104 105 w8001->idx = 0; 105 106 } 106 107 break; 108 + 107 109 case 8: 108 110 tmp = w8001->data[0] & W8001_TAB_MASK; 109 111 if (unlikely(tmp == W8001_TAB_BYTE)) 110 112 break; 113 + 111 114 w8001->idx = 0; 112 - memset(&coord, 0, sizeof(coord)); 113 115 parse_data(w8001->data, &coord); 114 116 input_report_abs(dev, ABS_X, coord.x); 115 117 input_report_abs(dev, ABS_Y, coord.y); ··· 118 118 input_report_key(dev, BTN_TOUCH, coord.tsw); 119 119 input_sync(dev); 120 120 break; 121 + 121 122 case 10: 122 123 w8001->idx = 0; 123 - memcpy(w8001->response, &w8001->data, W8001_PACKET_LEN); 124 - w8001->expected_packet = W8001_QUERY_PACKET; 124 + memcpy(w8001->response, w8001->data, W8001_MAX_LENGTH); 125 + w8001->response_type = W8001_QUERY_PACKET; 125 126 complete(&w8001->cmd_done); 126 127 break; 127 128 } 128 - } 129 - 130 - 131 - static irqreturn_t w8001_interrupt(struct serio *serio, 132 - unsigned char data, unsigned int flags) 133 - { 134 - struct w8001 *w8001 = serio_get_drvdata(serio); 135 - 136 - w8001_process_data(w8001, data); 137 129 138 130 return IRQ_HANDLED; 139 131 } 140 132 141 - static int w8001_async_command(struct w8001 *w8001, unsigned char *packet, 142 - int len) 133 + static int w8001_command(struct w8001 *w8001, unsigned char command, 134 + bool wait_response) 143 135 { 144 - int rc = -1; 145 - int i; 136 + int rc; 146 137 147 - mutex_lock(&w8001->cmd_mutex); 148 - 149 - for (i = 0; i < len; i++) { 150 - if (serio_write(w8001->serio, packet[i])) 151 - goto out; 152 - } 153 - rc = 0; 154 - 155 - out: 156 - mutex_unlock(&w8001->cmd_mutex); 157 - return rc; 158 - } 159 - 160 - static int w8001_command(struct w8001 *w8001, unsigned char *packet, int len) 161 - { 162 - int rc = -1; 163 - int i; 164 - 165 - mutex_lock(&w8001->cmd_mutex); 166 - 167 - serio_pause_rx(w8001->serio); 138 + w8001->response_type = 0; 168 139 init_completion(&w8001->cmd_done); 169 - serio_continue_rx(w8001->serio); 170 140 171 - for (i = 0; i < len; i++) { 172 - if (serio_write(w8001->serio, packet[i])) 173 - goto out; 141 + rc = serio_write(w8001->serio, command); 142 + if (rc == 0 && wait_response) { 143 + 144 + wait_for_completion_timeout(&w8001->cmd_done, HZ); 145 + if (w8001->response_type != W8001_QUERY_PACKET) 146 + rc = -EIO; 174 147 } 175 148 176 - wait_for_completion_timeout(&w8001->cmd_done, HZ); 177 - 178 - if (w8001->expected_packet == W8001_QUERY_PACKET) { 179 - /* We are back in reporting mode, the query was ACKed */ 180 - memcpy(packet, w8001->response, W8001_PACKET_LEN); 181 - rc = 0; 182 - } 183 - 184 - out: 185 - mutex_unlock(&w8001->cmd_mutex); 186 149 return rc; 187 150 } 188 151 189 152 static int w8001_setup(struct w8001 *w8001) 190 153 { 191 - struct w8001_coord coord; 192 154 struct input_dev *dev = w8001->dev; 193 - unsigned char start[1] = { '1' }; 194 - unsigned char query[11] = { '*' }; 155 + struct w8001_coord coord; 156 + int error; 195 157 196 - if (w8001_command(w8001, query, 1)) 197 - return -1; 158 + error = w8001_command(w8001, W8001_CMD_QUERY, true); 159 + if (error) 160 + return error; 198 161 199 - memset(&coord, 0, sizeof(coord)); 200 - parse_data(query, &coord); 162 + parse_data(w8001->response, &coord); 201 163 202 164 input_set_abs_params(dev, ABS_X, 0, coord.x, 0, 0); 203 165 input_set_abs_params(dev, ABS_Y, 0, coord.y, 0, 0); ··· 167 205 input_set_abs_params(dev, ABS_TILT_X, 0, coord.tilt_x, 0, 0); 168 206 input_set_abs_params(dev, ABS_TILT_Y, 0, coord.tilt_y, 0, 0); 169 207 170 - if (w8001_async_command(w8001, start, 1)) 171 - return -1; 172 - 173 - return 0; 208 + return w8001_command(w8001, W8001_CMD_START, false); 174 209 } 175 210 176 211 /* ··· 208 249 w8001->serio = serio; 209 250 w8001->id = serio->id.id; 210 251 w8001->dev = input_dev; 211 - mutex_init(&w8001->cmd_mutex); 212 252 init_completion(&w8001->cmd_done); 213 253 snprintf(w8001->phys, sizeof(w8001->phys), "%s/input0", serio->phys); 214 254 ··· 227 269 if (err) 228 270 goto fail2; 229 271 230 - if (w8001_setup(w8001)) 272 + err = w8001_setup(w8001); 273 + if (err) 231 274 goto fail3; 232 275 233 276 err = input_register_device(w8001->dev);