.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) ST-Ericsson SA 2010 |
---|
3 | 4 | * Author: Naveen Kumar G <naveen.gaddipati@stericsson.com> for ST-Ericsson |
---|
4 | | - * License terms:GNU General Public License (GPL) version 2 |
---|
5 | 5 | */ |
---|
6 | 6 | |
---|
7 | | -#include <linux/kernel.h> |
---|
| 7 | +#include <linux/bitops.h> |
---|
8 | 8 | #include <linux/delay.h> |
---|
9 | | -#include <linux/interrupt.h> |
---|
| 9 | +#include <linux/gpio/consumer.h> |
---|
10 | 10 | #include <linux/i2c.h> |
---|
11 | | -#include <linux/workqueue.h> |
---|
12 | 11 | #include <linux/input.h> |
---|
13 | | -#include <linux/input/bu21013.h> |
---|
14 | | -#include <linux/slab.h> |
---|
15 | | -#include <linux/regulator/consumer.h> |
---|
| 12 | +#include <linux/input/mt.h> |
---|
| 13 | +#include <linux/input/touchscreen.h> |
---|
| 14 | +#include <linux/interrupt.h> |
---|
| 15 | +#include <linux/kernel.h> |
---|
16 | 16 | #include <linux/module.h> |
---|
17 | | -#include <linux/gpio.h> |
---|
18 | | -#include <linux/of.h> |
---|
19 | | -#include <linux/of_gpio.h> |
---|
| 17 | +#include <linux/property.h> |
---|
| 18 | +#include <linux/regulator/consumer.h> |
---|
| 19 | +#include <linux/slab.h> |
---|
| 20 | +#include <linux/types.h> |
---|
20 | 21 | |
---|
21 | | -#define PEN_DOWN_INTR 0 |
---|
22 | 22 | #define MAX_FINGERS 2 |
---|
23 | 23 | #define RESET_DELAY 30 |
---|
24 | 24 | #define PENUP_TIMEOUT (10) |
---|
.. | .. |
---|
137 | 137 | #define DRIVER_TP "bu21013_tp" |
---|
138 | 138 | |
---|
139 | 139 | /** |
---|
140 | | - * struct bu21013_ts_data - touch panel data structure |
---|
| 140 | + * struct bu21013_ts - touch panel data structure |
---|
141 | 141 | * @client: pointer to the i2c client |
---|
142 | | - * @wait: variable to wait_queue_head_t structure |
---|
143 | | - * @touch_stopped: touch stop flag |
---|
144 | | - * @chip: pointer to the touch panel controller |
---|
145 | 142 | * @in_dev: pointer to the input device structure |
---|
146 | | - * @intr_pin: interrupt pin value |
---|
| 143 | + * @props: the device coordinate transformation properties |
---|
147 | 144 | * @regulator: pointer to the Regulator used for touch screen |
---|
| 145 | + * @cs_gpiod: chip select GPIO line |
---|
| 146 | + * @int_gpiod: touch interrupt GPIO line |
---|
| 147 | + * @touch_x_max: maximum X coordinate reported by the device |
---|
| 148 | + * @touch_y_max: maximum Y coordinate reported by the device |
---|
| 149 | + * @x_flip: indicates that the driver should invert X coordinate before |
---|
| 150 | + * reporting |
---|
| 151 | + * @y_flip: indicates that the driver should invert Y coordinate before |
---|
| 152 | + * reporting |
---|
| 153 | + * @touch_stopped: touch stop flag |
---|
148 | 154 | * |
---|
149 | 155 | * Touch panel device data structure |
---|
150 | 156 | */ |
---|
151 | | -struct bu21013_ts_data { |
---|
| 157 | +struct bu21013_ts { |
---|
152 | 158 | struct i2c_client *client; |
---|
153 | | - wait_queue_head_t wait; |
---|
154 | | - const struct bu21013_platform_device *chip; |
---|
155 | 159 | struct input_dev *in_dev; |
---|
| 160 | + struct touchscreen_properties props; |
---|
156 | 161 | struct regulator *regulator; |
---|
157 | | - unsigned int irq; |
---|
158 | | - unsigned int intr_pin; |
---|
| 162 | + struct gpio_desc *cs_gpiod; |
---|
| 163 | + struct gpio_desc *int_gpiod; |
---|
| 164 | + u32 touch_x_max; |
---|
| 165 | + u32 touch_y_max; |
---|
| 166 | + bool x_flip; |
---|
| 167 | + bool y_flip; |
---|
159 | 168 | bool touch_stopped; |
---|
160 | 169 | }; |
---|
161 | 170 | |
---|
162 | | -/** |
---|
163 | | - * bu21013_read_block_data(): read the touch co-ordinates |
---|
164 | | - * @data: bu21013_ts_data structure pointer |
---|
165 | | - * @buf: byte pointer |
---|
166 | | - * |
---|
167 | | - * Read the touch co-ordinates using i2c read block into buffer |
---|
168 | | - * and returns integer. |
---|
169 | | - */ |
---|
170 | | -static int bu21013_read_block_data(struct bu21013_ts_data *data, u8 *buf) |
---|
| 171 | +static int bu21013_read_block_data(struct bu21013_ts *ts, u8 *buf) |
---|
171 | 172 | { |
---|
172 | 173 | int ret, i; |
---|
173 | 174 | |
---|
174 | 175 | for (i = 0; i < I2C_RETRY_COUNT; i++) { |
---|
175 | | - ret = i2c_smbus_read_i2c_block_data |
---|
176 | | - (data->client, BU21013_SENSORS_BTN_0_7_REG, |
---|
177 | | - LENGTH_OF_BUFFER, buf); |
---|
| 176 | + ret = i2c_smbus_read_i2c_block_data(ts->client, |
---|
| 177 | + BU21013_SENSORS_BTN_0_7_REG, |
---|
| 178 | + LENGTH_OF_BUFFER, buf); |
---|
178 | 179 | if (ret == LENGTH_OF_BUFFER) |
---|
179 | 180 | return 0; |
---|
180 | 181 | } |
---|
| 182 | + |
---|
181 | 183 | return -EINVAL; |
---|
182 | 184 | } |
---|
183 | 185 | |
---|
184 | | -/** |
---|
185 | | - * bu21013_do_touch_report(): Get the touch co-ordinates |
---|
186 | | - * @data: bu21013_ts_data structure pointer |
---|
187 | | - * |
---|
188 | | - * Get the touch co-ordinates from touch sensor registers and writes |
---|
189 | | - * into device structure and returns integer. |
---|
190 | | - */ |
---|
191 | | -static int bu21013_do_touch_report(struct bu21013_ts_data *data) |
---|
| 186 | +static int bu21013_do_touch_report(struct bu21013_ts *ts) |
---|
192 | 187 | { |
---|
193 | | - u8 buf[LENGTH_OF_BUFFER]; |
---|
194 | | - unsigned int pos_x[2], pos_y[2]; |
---|
195 | | - bool has_x_sensors, has_y_sensors; |
---|
196 | | - int finger_down_count = 0; |
---|
197 | | - int i; |
---|
| 188 | + struct input_dev *input = ts->in_dev; |
---|
| 189 | + struct input_mt_pos pos[MAX_FINGERS]; |
---|
| 190 | + int slots[MAX_FINGERS]; |
---|
| 191 | + u8 buf[LENGTH_OF_BUFFER]; |
---|
| 192 | + bool has_x_sensors, has_y_sensors; |
---|
| 193 | + int finger_down_count = 0; |
---|
| 194 | + int i; |
---|
198 | 195 | |
---|
199 | | - if (data == NULL) |
---|
200 | | - return -EINVAL; |
---|
201 | | - |
---|
202 | | - if (bu21013_read_block_data(data, buf) < 0) |
---|
| 196 | + if (bu21013_read_block_data(ts, buf) < 0) |
---|
203 | 197 | return -EINVAL; |
---|
204 | 198 | |
---|
205 | 199 | has_x_sensors = hweight32(buf[0] & BU21013_SENSORS_EN_0_7); |
---|
.. | .. |
---|
209 | 203 | return 0; |
---|
210 | 204 | |
---|
211 | 205 | for (i = 0; i < MAX_FINGERS; i++) { |
---|
212 | | - const u8 *p = &buf[4 * i + 3]; |
---|
213 | | - unsigned int x = p[0] << SHIFT_2 | (p[1] & MASK_BITS); |
---|
214 | | - unsigned int y = p[2] << SHIFT_2 | (p[3] & MASK_BITS); |
---|
215 | | - if (x == 0 || y == 0) |
---|
216 | | - continue; |
---|
217 | | - pos_x[finger_down_count] = x; |
---|
218 | | - pos_y[finger_down_count] = y; |
---|
219 | | - finger_down_count++; |
---|
| 206 | + const u8 *data = &buf[4 * i + 3]; |
---|
| 207 | + unsigned int x, y; |
---|
| 208 | + |
---|
| 209 | + x = data[0] << SHIFT_2 | (data[1] & MASK_BITS); |
---|
| 210 | + y = data[2] << SHIFT_2 | (data[3] & MASK_BITS); |
---|
| 211 | + if (x != 0 && y != 0) |
---|
| 212 | + touchscreen_set_mt_pos(&pos[finger_down_count++], |
---|
| 213 | + &ts->props, x, y); |
---|
220 | 214 | } |
---|
221 | 215 | |
---|
222 | | - if (finger_down_count) { |
---|
223 | | - if (finger_down_count == 2 && |
---|
224 | | - (abs(pos_x[0] - pos_x[1]) < DELTA_MIN || |
---|
225 | | - abs(pos_y[0] - pos_y[1]) < DELTA_MIN)) { |
---|
226 | | - return 0; |
---|
227 | | - } |
---|
| 216 | + if (finger_down_count == 2 && |
---|
| 217 | + (abs(pos[0].x - pos[1].x) < DELTA_MIN || |
---|
| 218 | + abs(pos[0].y - pos[1].y) < DELTA_MIN)) { |
---|
| 219 | + return 0; |
---|
| 220 | + } |
---|
228 | 221 | |
---|
229 | | - for (i = 0; i < finger_down_count; i++) { |
---|
230 | | - if (data->chip->x_flip) |
---|
231 | | - pos_x[i] = data->chip->touch_x_max - pos_x[i]; |
---|
232 | | - if (data->chip->y_flip) |
---|
233 | | - pos_y[i] = data->chip->touch_y_max - pos_y[i]; |
---|
| 222 | + input_mt_assign_slots(input, slots, pos, finger_down_count, DELTA_MIN); |
---|
| 223 | + for (i = 0; i < finger_down_count; i++) { |
---|
| 224 | + input_mt_slot(input, slots[i]); |
---|
| 225 | + input_mt_report_slot_state(input, MT_TOOL_FINGER, true); |
---|
| 226 | + input_report_abs(input, ABS_MT_POSITION_X, pos[i].x); |
---|
| 227 | + input_report_abs(input, ABS_MT_POSITION_Y, pos[i].y); |
---|
| 228 | + } |
---|
234 | 229 | |
---|
235 | | - input_report_abs(data->in_dev, |
---|
236 | | - ABS_MT_POSITION_X, pos_x[i]); |
---|
237 | | - input_report_abs(data->in_dev, |
---|
238 | | - ABS_MT_POSITION_Y, pos_y[i]); |
---|
239 | | - input_mt_sync(data->in_dev); |
---|
240 | | - } |
---|
241 | | - } else |
---|
242 | | - input_mt_sync(data->in_dev); |
---|
243 | | - |
---|
244 | | - input_sync(data->in_dev); |
---|
| 230 | + input_mt_sync_frame(input); |
---|
| 231 | + input_sync(input); |
---|
245 | 232 | |
---|
246 | 233 | return 0; |
---|
247 | 234 | } |
---|
248 | | -/** |
---|
249 | | - * bu21013_gpio_irq() - gpio thread function for touch interrupt |
---|
250 | | - * @irq: irq value |
---|
251 | | - * @device_data: void pointer |
---|
252 | | - * |
---|
253 | | - * This gpio thread function for touch interrupt |
---|
254 | | - * and returns irqreturn_t. |
---|
255 | | - */ |
---|
| 235 | + |
---|
256 | 236 | static irqreturn_t bu21013_gpio_irq(int irq, void *device_data) |
---|
257 | 237 | { |
---|
258 | | - struct bu21013_ts_data *data = device_data; |
---|
259 | | - struct i2c_client *i2c = data->client; |
---|
260 | | - int retval; |
---|
| 238 | + struct bu21013_ts *ts = device_data; |
---|
| 239 | + int keep_polling; |
---|
| 240 | + int error; |
---|
261 | 241 | |
---|
262 | 242 | do { |
---|
263 | | - retval = bu21013_do_touch_report(data); |
---|
264 | | - if (retval < 0) { |
---|
265 | | - dev_err(&i2c->dev, "bu21013_do_touch_report failed\n"); |
---|
266 | | - return IRQ_NONE; |
---|
| 243 | + error = bu21013_do_touch_report(ts); |
---|
| 244 | + if (error) { |
---|
| 245 | + dev_err(&ts->client->dev, "%s failed\n", __func__); |
---|
| 246 | + break; |
---|
267 | 247 | } |
---|
268 | 248 | |
---|
269 | | - data->intr_pin = gpio_get_value(data->chip->touch_pin); |
---|
270 | | - if (data->intr_pin == PEN_DOWN_INTR) |
---|
271 | | - wait_event_timeout(data->wait, data->touch_stopped, |
---|
272 | | - msecs_to_jiffies(2)); |
---|
273 | | - } while (!data->intr_pin && !data->touch_stopped); |
---|
| 249 | + if (unlikely(ts->touch_stopped)) |
---|
| 250 | + break; |
---|
| 251 | + |
---|
| 252 | + keep_polling = ts->int_gpiod ? |
---|
| 253 | + gpiod_get_value(ts->int_gpiod) : false; |
---|
| 254 | + if (keep_polling) |
---|
| 255 | + usleep_range(2000, 2500); |
---|
| 256 | + } while (keep_polling); |
---|
274 | 257 | |
---|
275 | 258 | return IRQ_HANDLED; |
---|
276 | 259 | } |
---|
277 | 260 | |
---|
278 | | -/** |
---|
279 | | - * bu21013_init_chip() - power on sequence for the bu21013 controller |
---|
280 | | - * @data: device structure pointer |
---|
281 | | - * |
---|
282 | | - * This function is used to power on |
---|
283 | | - * the bu21013 controller and returns integer. |
---|
284 | | - */ |
---|
285 | | -static int bu21013_init_chip(struct bu21013_ts_data *data) |
---|
| 261 | +static int bu21013_init_chip(struct bu21013_ts *ts) |
---|
286 | 262 | { |
---|
287 | | - int retval; |
---|
288 | | - struct i2c_client *i2c = data->client; |
---|
| 263 | + struct i2c_client *client = ts->client; |
---|
| 264 | + int error; |
---|
289 | 265 | |
---|
290 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_RESET_REG, |
---|
291 | | - BU21013_RESET_ENABLE); |
---|
292 | | - if (retval < 0) { |
---|
293 | | - dev_err(&i2c->dev, "BU21013_RESET reg write failed\n"); |
---|
294 | | - return retval; |
---|
| 266 | + error = i2c_smbus_write_byte_data(client, BU21013_RESET_REG, |
---|
| 267 | + BU21013_RESET_ENABLE); |
---|
| 268 | + if (error) { |
---|
| 269 | + dev_err(&client->dev, "BU21013_RESET reg write failed\n"); |
---|
| 270 | + return error; |
---|
295 | 271 | } |
---|
296 | 272 | msleep(RESET_DELAY); |
---|
297 | 273 | |
---|
298 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_0_7_REG, |
---|
299 | | - BU21013_SENSORS_EN_0_7); |
---|
300 | | - if (retval < 0) { |
---|
301 | | - dev_err(&i2c->dev, "BU21013_SENSOR_0_7 reg write failed\n"); |
---|
302 | | - return retval; |
---|
| 274 | + error = i2c_smbus_write_byte_data(client, BU21013_SENSOR_0_7_REG, |
---|
| 275 | + BU21013_SENSORS_EN_0_7); |
---|
| 276 | + if (error) { |
---|
| 277 | + dev_err(&client->dev, "BU21013_SENSOR_0_7 reg write failed\n"); |
---|
| 278 | + return error; |
---|
303 | 279 | } |
---|
304 | 280 | |
---|
305 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_8_15_REG, |
---|
306 | | - BU21013_SENSORS_EN_8_15); |
---|
307 | | - if (retval < 0) { |
---|
308 | | - dev_err(&i2c->dev, "BU21013_SENSOR_8_15 reg write failed\n"); |
---|
309 | | - return retval; |
---|
| 281 | + error = i2c_smbus_write_byte_data(client, BU21013_SENSOR_8_15_REG, |
---|
| 282 | + BU21013_SENSORS_EN_8_15); |
---|
| 283 | + if (error) { |
---|
| 284 | + dev_err(&client->dev, "BU21013_SENSOR_8_15 reg write failed\n"); |
---|
| 285 | + return error; |
---|
310 | 286 | } |
---|
311 | 287 | |
---|
312 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_SENSOR_16_23_REG, |
---|
313 | | - BU21013_SENSORS_EN_16_23); |
---|
314 | | - if (retval < 0) { |
---|
315 | | - dev_err(&i2c->dev, "BU21013_SENSOR_16_23 reg write failed\n"); |
---|
316 | | - return retval; |
---|
| 288 | + error = i2c_smbus_write_byte_data(client, BU21013_SENSOR_16_23_REG, |
---|
| 289 | + BU21013_SENSORS_EN_16_23); |
---|
| 290 | + if (error) { |
---|
| 291 | + dev_err(&client->dev, "BU21013_SENSOR_16_23 reg write failed\n"); |
---|
| 292 | + return error; |
---|
317 | 293 | } |
---|
318 | 294 | |
---|
319 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_POS_MODE1_REG, |
---|
320 | | - (BU21013_POS_MODE1_0 | BU21013_POS_MODE1_1)); |
---|
321 | | - if (retval < 0) { |
---|
322 | | - dev_err(&i2c->dev, "BU21013_POS_MODE1 reg write failed\n"); |
---|
323 | | - return retval; |
---|
| 295 | + error = i2c_smbus_write_byte_data(client, BU21013_POS_MODE1_REG, |
---|
| 296 | + BU21013_POS_MODE1_0 | |
---|
| 297 | + BU21013_POS_MODE1_1); |
---|
| 298 | + if (error) { |
---|
| 299 | + dev_err(&client->dev, "BU21013_POS_MODE1 reg write failed\n"); |
---|
| 300 | + return error; |
---|
324 | 301 | } |
---|
325 | 302 | |
---|
326 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_POS_MODE2_REG, |
---|
327 | | - (BU21013_POS_MODE2_ZERO | BU21013_POS_MODE2_AVG1 | |
---|
328 | | - BU21013_POS_MODE2_AVG2 | BU21013_POS_MODE2_EN_RAW | |
---|
329 | | - BU21013_POS_MODE2_MULTI)); |
---|
330 | | - if (retval < 0) { |
---|
331 | | - dev_err(&i2c->dev, "BU21013_POS_MODE2 reg write failed\n"); |
---|
332 | | - return retval; |
---|
| 303 | + error = i2c_smbus_write_byte_data(client, BU21013_POS_MODE2_REG, |
---|
| 304 | + BU21013_POS_MODE2_ZERO | |
---|
| 305 | + BU21013_POS_MODE2_AVG1 | |
---|
| 306 | + BU21013_POS_MODE2_AVG2 | |
---|
| 307 | + BU21013_POS_MODE2_EN_RAW | |
---|
| 308 | + BU21013_POS_MODE2_MULTI); |
---|
| 309 | + if (error) { |
---|
| 310 | + dev_err(&client->dev, "BU21013_POS_MODE2 reg write failed\n"); |
---|
| 311 | + return error; |
---|
333 | 312 | } |
---|
334 | 313 | |
---|
335 | | - if (data->chip->ext_clk) |
---|
336 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_CLK_MODE_REG, |
---|
337 | | - (BU21013_CLK_MODE_EXT | BU21013_CLK_MODE_CALIB)); |
---|
338 | | - else |
---|
339 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_CLK_MODE_REG, |
---|
340 | | - (BU21013_CLK_MODE_DIV | BU21013_CLK_MODE_CALIB)); |
---|
341 | | - if (retval < 0) { |
---|
342 | | - dev_err(&i2c->dev, "BU21013_CLK_MODE reg write failed\n"); |
---|
343 | | - return retval; |
---|
| 314 | + error = i2c_smbus_write_byte_data(client, BU21013_CLK_MODE_REG, |
---|
| 315 | + BU21013_CLK_MODE_DIV | |
---|
| 316 | + BU21013_CLK_MODE_CALIB); |
---|
| 317 | + if (error) { |
---|
| 318 | + dev_err(&client->dev, "BU21013_CLK_MODE reg write failed\n"); |
---|
| 319 | + return error; |
---|
344 | 320 | } |
---|
345 | 321 | |
---|
346 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_IDLE_REG, |
---|
347 | | - (BU21013_IDLET_0 | BU21013_IDLE_INTERMIT_EN)); |
---|
348 | | - if (retval < 0) { |
---|
349 | | - dev_err(&i2c->dev, "BU21013_IDLE reg write failed\n"); |
---|
350 | | - return retval; |
---|
| 322 | + error = i2c_smbus_write_byte_data(client, BU21013_IDLE_REG, |
---|
| 323 | + BU21013_IDLET_0 | |
---|
| 324 | + BU21013_IDLE_INTERMIT_EN); |
---|
| 325 | + if (error) { |
---|
| 326 | + dev_err(&client->dev, "BU21013_IDLE reg write failed\n"); |
---|
| 327 | + return error; |
---|
351 | 328 | } |
---|
352 | 329 | |
---|
353 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_INT_MODE_REG, |
---|
354 | | - BU21013_INT_MODE_LEVEL); |
---|
355 | | - if (retval < 0) { |
---|
356 | | - dev_err(&i2c->dev, "BU21013_INT_MODE reg write failed\n"); |
---|
357 | | - return retval; |
---|
| 330 | + error = i2c_smbus_write_byte_data(client, BU21013_INT_MODE_REG, |
---|
| 331 | + BU21013_INT_MODE_LEVEL); |
---|
| 332 | + if (error) { |
---|
| 333 | + dev_err(&client->dev, "BU21013_INT_MODE reg write failed\n"); |
---|
| 334 | + return error; |
---|
358 | 335 | } |
---|
359 | 336 | |
---|
360 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_FILTER_REG, |
---|
361 | | - (BU21013_DELTA_0_6 | |
---|
362 | | - BU21013_FILTER_EN)); |
---|
363 | | - if (retval < 0) { |
---|
364 | | - dev_err(&i2c->dev, "BU21013_FILTER reg write failed\n"); |
---|
365 | | - return retval; |
---|
| 337 | + error = i2c_smbus_write_byte_data(client, BU21013_FILTER_REG, |
---|
| 338 | + BU21013_DELTA_0_6 | |
---|
| 339 | + BU21013_FILTER_EN); |
---|
| 340 | + if (error) { |
---|
| 341 | + dev_err(&client->dev, "BU21013_FILTER reg write failed\n"); |
---|
| 342 | + return error; |
---|
366 | 343 | } |
---|
367 | 344 | |
---|
368 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_TH_ON_REG, |
---|
369 | | - BU21013_TH_ON_5); |
---|
370 | | - if (retval < 0) { |
---|
371 | | - dev_err(&i2c->dev, "BU21013_TH_ON reg write failed\n"); |
---|
372 | | - return retval; |
---|
| 345 | + error = i2c_smbus_write_byte_data(client, BU21013_TH_ON_REG, |
---|
| 346 | + BU21013_TH_ON_5); |
---|
| 347 | + if (error) { |
---|
| 348 | + dev_err(&client->dev, "BU21013_TH_ON reg write failed\n"); |
---|
| 349 | + return error; |
---|
373 | 350 | } |
---|
374 | 351 | |
---|
375 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_TH_OFF_REG, |
---|
376 | | - BU21013_TH_OFF_4 | BU21013_TH_OFF_3); |
---|
377 | | - if (retval < 0) { |
---|
378 | | - dev_err(&i2c->dev, "BU21013_TH_OFF reg write failed\n"); |
---|
379 | | - return retval; |
---|
| 352 | + error = i2c_smbus_write_byte_data(client, BU21013_TH_OFF_REG, |
---|
| 353 | + BU21013_TH_OFF_4 | BU21013_TH_OFF_3); |
---|
| 354 | + if (error) { |
---|
| 355 | + dev_err(&client->dev, "BU21013_TH_OFF reg write failed\n"); |
---|
| 356 | + return error; |
---|
380 | 357 | } |
---|
381 | 358 | |
---|
382 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_GAIN_REG, |
---|
383 | | - (BU21013_GAIN_0 | BU21013_GAIN_1)); |
---|
384 | | - if (retval < 0) { |
---|
385 | | - dev_err(&i2c->dev, "BU21013_GAIN reg write failed\n"); |
---|
386 | | - return retval; |
---|
| 359 | + error = i2c_smbus_write_byte_data(client, BU21013_GAIN_REG, |
---|
| 360 | + BU21013_GAIN_0 | BU21013_GAIN_1); |
---|
| 361 | + if (error) { |
---|
| 362 | + dev_err(&client->dev, "BU21013_GAIN reg write failed\n"); |
---|
| 363 | + return error; |
---|
387 | 364 | } |
---|
388 | 365 | |
---|
389 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_OFFSET_MODE_REG, |
---|
390 | | - BU21013_OFFSET_MODE_DEFAULT); |
---|
391 | | - if (retval < 0) { |
---|
392 | | - dev_err(&i2c->dev, "BU21013_OFFSET_MODE reg write failed\n"); |
---|
393 | | - return retval; |
---|
| 366 | + error = i2c_smbus_write_byte_data(client, BU21013_OFFSET_MODE_REG, |
---|
| 367 | + BU21013_OFFSET_MODE_DEFAULT); |
---|
| 368 | + if (error) { |
---|
| 369 | + dev_err(&client->dev, "BU21013_OFFSET_MODE reg write failed\n"); |
---|
| 370 | + return error; |
---|
394 | 371 | } |
---|
395 | 372 | |
---|
396 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_XY_EDGE_REG, |
---|
397 | | - (BU21013_X_EDGE_0 | BU21013_X_EDGE_2 | |
---|
398 | | - BU21013_Y_EDGE_1 | BU21013_Y_EDGE_3)); |
---|
399 | | - if (retval < 0) { |
---|
400 | | - dev_err(&i2c->dev, "BU21013_XY_EDGE reg write failed\n"); |
---|
401 | | - return retval; |
---|
| 373 | + error = i2c_smbus_write_byte_data(client, BU21013_XY_EDGE_REG, |
---|
| 374 | + BU21013_X_EDGE_0 | |
---|
| 375 | + BU21013_X_EDGE_2 | |
---|
| 376 | + BU21013_Y_EDGE_1 | |
---|
| 377 | + BU21013_Y_EDGE_3); |
---|
| 378 | + if (error) { |
---|
| 379 | + dev_err(&client->dev, "BU21013_XY_EDGE reg write failed\n"); |
---|
| 380 | + return error; |
---|
402 | 381 | } |
---|
403 | 382 | |
---|
404 | | - retval = i2c_smbus_write_byte_data(i2c, BU21013_DONE_REG, |
---|
405 | | - BU21013_DONE); |
---|
406 | | - if (retval < 0) { |
---|
407 | | - dev_err(&i2c->dev, "BU21013_REG_DONE reg write failed\n"); |
---|
408 | | - return retval; |
---|
| 383 | + error = i2c_smbus_write_byte_data(client, BU21013_DONE_REG, |
---|
| 384 | + BU21013_DONE); |
---|
| 385 | + if (error) { |
---|
| 386 | + dev_err(&client->dev, "BU21013_REG_DONE reg write failed\n"); |
---|
| 387 | + return error; |
---|
409 | 388 | } |
---|
410 | 389 | |
---|
411 | 390 | return 0; |
---|
412 | 391 | } |
---|
413 | 392 | |
---|
414 | | -/** |
---|
415 | | - * bu21013_free_irq() - frees IRQ registered for touchscreen |
---|
416 | | - * @bu21013_data: device structure pointer |
---|
417 | | - * |
---|
418 | | - * This function signals interrupt thread to stop processing and |
---|
419 | | - * frees interrupt. |
---|
420 | | - */ |
---|
421 | | -static void bu21013_free_irq(struct bu21013_ts_data *bu21013_data) |
---|
| 393 | +static void bu21013_power_off(void *_ts) |
---|
422 | 394 | { |
---|
423 | | - bu21013_data->touch_stopped = true; |
---|
424 | | - wake_up(&bu21013_data->wait); |
---|
425 | | - free_irq(bu21013_data->irq, bu21013_data); |
---|
| 395 | + struct bu21013_ts *ts = _ts; |
---|
| 396 | + |
---|
| 397 | + regulator_disable(ts->regulator); |
---|
426 | 398 | } |
---|
427 | 399 | |
---|
428 | | -/** |
---|
429 | | - * bu21013_cs_disable() - deconfigures the touch panel controller |
---|
430 | | - * @bu21013_data: device structure pointer |
---|
431 | | - * |
---|
432 | | - * This function is used to deconfigure the chip selection |
---|
433 | | - * for touch panel controller. |
---|
434 | | - */ |
---|
435 | | -static void bu21013_cs_disable(struct bu21013_ts_data *bu21013_data) |
---|
| 400 | +static void bu21013_disable_chip(void *_ts) |
---|
436 | 401 | { |
---|
437 | | - int error; |
---|
| 402 | + struct bu21013_ts *ts = _ts; |
---|
438 | 403 | |
---|
439 | | - error = gpio_direction_output(bu21013_data->chip->cs_pin, 0); |
---|
440 | | - if (error < 0) |
---|
441 | | - dev_warn(&bu21013_data->client->dev, |
---|
442 | | - "%s: gpio direction failed, error: %d\n", |
---|
443 | | - __func__, error); |
---|
444 | | - else |
---|
445 | | - gpio_set_value(bu21013_data->chip->cs_pin, 0); |
---|
446 | | - |
---|
447 | | - gpio_free(bu21013_data->chip->cs_pin); |
---|
| 404 | + gpiod_set_value(ts->cs_gpiod, 0); |
---|
448 | 405 | } |
---|
449 | 406 | |
---|
450 | | -#ifdef CONFIG_OF |
---|
451 | | -static const struct bu21013_platform_device * |
---|
452 | | -bu21013_parse_dt(struct device *dev) |
---|
453 | | -{ |
---|
454 | | - struct device_node *np = dev->of_node; |
---|
455 | | - struct bu21013_platform_device *pdata; |
---|
456 | | - |
---|
457 | | - if (!np) { |
---|
458 | | - dev_err(dev, "no device tree or platform data\n"); |
---|
459 | | - return ERR_PTR(-EINVAL); |
---|
460 | | - } |
---|
461 | | - |
---|
462 | | - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
---|
463 | | - if (!pdata) |
---|
464 | | - return ERR_PTR(-ENOMEM); |
---|
465 | | - |
---|
466 | | - pdata->y_flip = pdata->x_flip = false; |
---|
467 | | - |
---|
468 | | - pdata->x_flip = of_property_read_bool(np, "rohm,flip-x"); |
---|
469 | | - pdata->y_flip = of_property_read_bool(np, "rohm,flip-y"); |
---|
470 | | - |
---|
471 | | - of_property_read_u32(np, "rohm,touch-max-x", &pdata->touch_x_max); |
---|
472 | | - of_property_read_u32(np, "rohm,touch-max-y", &pdata->touch_y_max); |
---|
473 | | - |
---|
474 | | - pdata->touch_pin = of_get_named_gpio(np, "touch-gpio", 0); |
---|
475 | | - pdata->cs_pin = of_get_named_gpio(np, "reset-gpio", 0); |
---|
476 | | - |
---|
477 | | - pdata->ext_clk = false; |
---|
478 | | - |
---|
479 | | - return pdata; |
---|
480 | | -} |
---|
481 | | -#else |
---|
482 | | -static inline const struct bu21013_platform_device * |
---|
483 | | -bu21013_parse_dt(struct device *dev) |
---|
484 | | -{ |
---|
485 | | - dev_err(dev, "no platform data available\n"); |
---|
486 | | - return ERR_PTR(-EINVAL); |
---|
487 | | -} |
---|
488 | | -#endif |
---|
489 | | - |
---|
490 | | -/** |
---|
491 | | - * bu21013_probe() - initializes the i2c-client touchscreen driver |
---|
492 | | - * @client: i2c client structure pointer |
---|
493 | | - * @id: i2c device id pointer |
---|
494 | | - * |
---|
495 | | - * This function used to initializes the i2c-client touchscreen |
---|
496 | | - * driver and returns integer. |
---|
497 | | - */ |
---|
498 | 407 | static int bu21013_probe(struct i2c_client *client, |
---|
499 | 408 | const struct i2c_device_id *id) |
---|
500 | 409 | { |
---|
501 | | - const struct bu21013_platform_device *pdata = |
---|
502 | | - dev_get_platdata(&client->dev); |
---|
503 | | - struct bu21013_ts_data *bu21013_data; |
---|
| 410 | + struct bu21013_ts *ts; |
---|
504 | 411 | struct input_dev *in_dev; |
---|
| 412 | + struct input_absinfo *info; |
---|
| 413 | + u32 max_x = 0, max_y = 0; |
---|
505 | 414 | int error; |
---|
506 | 415 | |
---|
507 | 416 | if (!i2c_check_functionality(client->adapter, |
---|
508 | | - I2C_FUNC_SMBUS_BYTE_DATA)) { |
---|
| 417 | + I2C_FUNC_SMBUS_BYTE_DATA)) { |
---|
509 | 418 | dev_err(&client->dev, "i2c smbus byte data not supported\n"); |
---|
510 | 419 | return -EIO; |
---|
511 | 420 | } |
---|
512 | 421 | |
---|
513 | | - if (!pdata) { |
---|
514 | | - pdata = bu21013_parse_dt(&client->dev); |
---|
515 | | - if (IS_ERR(pdata)) |
---|
516 | | - return PTR_ERR(pdata); |
---|
517 | | - } |
---|
518 | | - |
---|
519 | | - if (!gpio_is_valid(pdata->touch_pin)) { |
---|
520 | | - dev_err(&client->dev, "invalid touch_pin supplied\n"); |
---|
| 422 | + if (!client->irq) { |
---|
| 423 | + dev_err(&client->dev, "No IRQ set up\n"); |
---|
521 | 424 | return -EINVAL; |
---|
522 | 425 | } |
---|
523 | 426 | |
---|
524 | | - bu21013_data = kzalloc(sizeof(struct bu21013_ts_data), GFP_KERNEL); |
---|
525 | | - in_dev = input_allocate_device(); |
---|
526 | | - if (!bu21013_data || !in_dev) { |
---|
| 427 | + ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL); |
---|
| 428 | + if (!ts) |
---|
| 429 | + return -ENOMEM; |
---|
| 430 | + |
---|
| 431 | + ts->client = client; |
---|
| 432 | + |
---|
| 433 | + ts->x_flip = device_property_read_bool(&client->dev, "rohm,flip-x"); |
---|
| 434 | + ts->y_flip = device_property_read_bool(&client->dev, "rohm,flip-y"); |
---|
| 435 | + |
---|
| 436 | + in_dev = devm_input_allocate_device(&client->dev); |
---|
| 437 | + if (!in_dev) { |
---|
527 | 438 | dev_err(&client->dev, "device memory alloc failed\n"); |
---|
528 | | - error = -ENOMEM; |
---|
529 | | - goto err_free_mem; |
---|
| 439 | + return -ENOMEM; |
---|
530 | 440 | } |
---|
531 | | - |
---|
532 | | - bu21013_data->in_dev = in_dev; |
---|
533 | | - bu21013_data->chip = pdata; |
---|
534 | | - bu21013_data->client = client; |
---|
535 | | - bu21013_data->irq = gpio_to_irq(pdata->touch_pin); |
---|
536 | | - |
---|
537 | | - bu21013_data->regulator = regulator_get(&client->dev, "avdd"); |
---|
538 | | - if (IS_ERR(bu21013_data->regulator)) { |
---|
539 | | - dev_err(&client->dev, "regulator_get failed\n"); |
---|
540 | | - error = PTR_ERR(bu21013_data->regulator); |
---|
541 | | - goto err_free_mem; |
---|
542 | | - } |
---|
543 | | - |
---|
544 | | - error = regulator_enable(bu21013_data->regulator); |
---|
545 | | - if (error < 0) { |
---|
546 | | - dev_err(&client->dev, "regulator enable failed\n"); |
---|
547 | | - goto err_put_regulator; |
---|
548 | | - } |
---|
549 | | - |
---|
550 | | - bu21013_data->touch_stopped = false; |
---|
551 | | - init_waitqueue_head(&bu21013_data->wait); |
---|
552 | | - |
---|
553 | | - /* configure the gpio pins */ |
---|
554 | | - error = gpio_request_one(pdata->cs_pin, GPIOF_OUT_INIT_HIGH, |
---|
555 | | - "touchp_reset"); |
---|
556 | | - if (error < 0) { |
---|
557 | | - dev_err(&client->dev, "Unable to request gpio reset_pin\n"); |
---|
558 | | - goto err_disable_regulator; |
---|
559 | | - } |
---|
560 | | - |
---|
561 | | - /* configure the touch panel controller */ |
---|
562 | | - error = bu21013_init_chip(bu21013_data); |
---|
563 | | - if (error) { |
---|
564 | | - dev_err(&client->dev, "error in bu21013 config\n"); |
---|
565 | | - goto err_cs_disable; |
---|
566 | | - } |
---|
| 441 | + ts->in_dev = in_dev; |
---|
| 442 | + input_set_drvdata(in_dev, ts); |
---|
567 | 443 | |
---|
568 | 444 | /* register the device to input subsystem */ |
---|
569 | 445 | in_dev->name = DRIVER_TP; |
---|
570 | 446 | in_dev->id.bustype = BUS_I2C; |
---|
571 | | - in_dev->dev.parent = &client->dev; |
---|
572 | 447 | |
---|
573 | | - __set_bit(EV_SYN, in_dev->evbit); |
---|
574 | | - __set_bit(EV_KEY, in_dev->evbit); |
---|
575 | | - __set_bit(EV_ABS, in_dev->evbit); |
---|
| 448 | + device_property_read_u32(&client->dev, "rohm,touch-max-x", &max_x); |
---|
| 449 | + device_property_read_u32(&client->dev, "rohm,touch-max-y", &max_y); |
---|
576 | 450 | |
---|
577 | | - input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0, |
---|
578 | | - pdata->touch_x_max, 0, 0); |
---|
579 | | - input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0, |
---|
580 | | - pdata->touch_y_max, 0, 0); |
---|
581 | | - input_set_drvdata(in_dev, bu21013_data); |
---|
| 451 | + input_set_abs_params(in_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0); |
---|
| 452 | + input_set_abs_params(in_dev, ABS_MT_POSITION_Y, 0, max_y, 0, 0); |
---|
582 | 453 | |
---|
583 | | - error = request_threaded_irq(bu21013_data->irq, NULL, bu21013_gpio_irq, |
---|
584 | | - IRQF_TRIGGER_FALLING | IRQF_SHARED | |
---|
585 | | - IRQF_ONESHOT, |
---|
586 | | - DRIVER_TP, bu21013_data); |
---|
| 454 | + touchscreen_parse_properties(in_dev, true, &ts->props); |
---|
| 455 | + |
---|
| 456 | + /* Adjust for the legacy "flip" properties, if present */ |
---|
| 457 | + if (!ts->props.invert_x && |
---|
| 458 | + device_property_read_bool(&client->dev, "rohm,flip-x")) { |
---|
| 459 | + info = &in_dev->absinfo[ABS_MT_POSITION_X]; |
---|
| 460 | + info->maximum -= info->minimum; |
---|
| 461 | + info->minimum = 0; |
---|
| 462 | + } |
---|
| 463 | + |
---|
| 464 | + if (!ts->props.invert_y && |
---|
| 465 | + device_property_read_bool(&client->dev, "rohm,flip-y")) { |
---|
| 466 | + info = &in_dev->absinfo[ABS_MT_POSITION_Y]; |
---|
| 467 | + info->maximum -= info->minimum; |
---|
| 468 | + info->minimum = 0; |
---|
| 469 | + } |
---|
| 470 | + |
---|
| 471 | + error = input_mt_init_slots(in_dev, MAX_FINGERS, |
---|
| 472 | + INPUT_MT_DIRECT | INPUT_MT_TRACK | |
---|
| 473 | + INPUT_MT_DROP_UNUSED); |
---|
| 474 | + if (error) { |
---|
| 475 | + dev_err(&client->dev, "failed to initialize MT slots"); |
---|
| 476 | + return error; |
---|
| 477 | + } |
---|
| 478 | + |
---|
| 479 | + ts->regulator = devm_regulator_get(&client->dev, "avdd"); |
---|
| 480 | + if (IS_ERR(ts->regulator)) { |
---|
| 481 | + dev_err(&client->dev, "regulator_get failed\n"); |
---|
| 482 | + return PTR_ERR(ts->regulator); |
---|
| 483 | + } |
---|
| 484 | + |
---|
| 485 | + error = regulator_enable(ts->regulator); |
---|
| 486 | + if (error) { |
---|
| 487 | + dev_err(&client->dev, "regulator enable failed\n"); |
---|
| 488 | + return error; |
---|
| 489 | + } |
---|
| 490 | + |
---|
| 491 | + error = devm_add_action_or_reset(&client->dev, bu21013_power_off, ts); |
---|
| 492 | + if (error) { |
---|
| 493 | + dev_err(&client->dev, "failed to install power off handler\n"); |
---|
| 494 | + return error; |
---|
| 495 | + } |
---|
| 496 | + |
---|
| 497 | + /* Named "CS" on the chip, DT binding is "reset" */ |
---|
| 498 | + ts->cs_gpiod = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH); |
---|
| 499 | + error = PTR_ERR_OR_ZERO(ts->cs_gpiod); |
---|
| 500 | + if (error) { |
---|
| 501 | + if (error != -EPROBE_DEFER) |
---|
| 502 | + dev_err(&client->dev, "failed to get CS GPIO\n"); |
---|
| 503 | + return error; |
---|
| 504 | + } |
---|
| 505 | + gpiod_set_consumer_name(ts->cs_gpiod, "BU21013 CS"); |
---|
| 506 | + |
---|
| 507 | + error = devm_add_action_or_reset(&client->dev, |
---|
| 508 | + bu21013_disable_chip, ts); |
---|
| 509 | + if (error) { |
---|
| 510 | + dev_err(&client->dev, |
---|
| 511 | + "failed to install chip disable handler\n"); |
---|
| 512 | + return error; |
---|
| 513 | + } |
---|
| 514 | + |
---|
| 515 | + /* Named "INT" on the chip, DT binding is "touch" */ |
---|
| 516 | + ts->int_gpiod = devm_gpiod_get_optional(&client->dev, |
---|
| 517 | + "touch", GPIOD_IN); |
---|
| 518 | + error = PTR_ERR_OR_ZERO(ts->int_gpiod); |
---|
| 519 | + if (error) { |
---|
| 520 | + if (error != -EPROBE_DEFER) |
---|
| 521 | + dev_err(&client->dev, "failed to get INT GPIO\n"); |
---|
| 522 | + return error; |
---|
| 523 | + } |
---|
| 524 | + |
---|
| 525 | + if (ts->int_gpiod) |
---|
| 526 | + gpiod_set_consumer_name(ts->int_gpiod, "BU21013 INT"); |
---|
| 527 | + |
---|
| 528 | + /* configure the touch panel controller */ |
---|
| 529 | + error = bu21013_init_chip(ts); |
---|
| 530 | + if (error) { |
---|
| 531 | + dev_err(&client->dev, "error in bu21013 config\n"); |
---|
| 532 | + return error; |
---|
| 533 | + } |
---|
| 534 | + |
---|
| 535 | + error = devm_request_threaded_irq(&client->dev, client->irq, |
---|
| 536 | + NULL, bu21013_gpio_irq, |
---|
| 537 | + IRQF_ONESHOT, DRIVER_TP, ts); |
---|
587 | 538 | if (error) { |
---|
588 | 539 | dev_err(&client->dev, "request irq %d failed\n", |
---|
589 | | - bu21013_data->irq); |
---|
590 | | - goto err_cs_disable; |
---|
| 540 | + client->irq); |
---|
| 541 | + return error; |
---|
591 | 542 | } |
---|
592 | 543 | |
---|
593 | 544 | error = input_register_device(in_dev); |
---|
594 | 545 | if (error) { |
---|
595 | 546 | dev_err(&client->dev, "failed to register input device\n"); |
---|
596 | | - goto err_free_irq; |
---|
| 547 | + return error; |
---|
597 | 548 | } |
---|
598 | 549 | |
---|
599 | | - device_init_wakeup(&client->dev, pdata->wakeup); |
---|
600 | | - i2c_set_clientdata(client, bu21013_data); |
---|
| 550 | + i2c_set_clientdata(client, ts); |
---|
601 | 551 | |
---|
602 | 552 | return 0; |
---|
603 | | - |
---|
604 | | -err_free_irq: |
---|
605 | | - bu21013_free_irq(bu21013_data); |
---|
606 | | -err_cs_disable: |
---|
607 | | - bu21013_cs_disable(bu21013_data); |
---|
608 | | -err_disable_regulator: |
---|
609 | | - regulator_disable(bu21013_data->regulator); |
---|
610 | | -err_put_regulator: |
---|
611 | | - regulator_put(bu21013_data->regulator); |
---|
612 | | -err_free_mem: |
---|
613 | | - input_free_device(in_dev); |
---|
614 | | - kfree(bu21013_data); |
---|
615 | | - |
---|
616 | | - return error; |
---|
617 | 553 | } |
---|
618 | | -/** |
---|
619 | | - * bu21013_remove() - removes the i2c-client touchscreen driver |
---|
620 | | - * @client: i2c client structure pointer |
---|
621 | | - * |
---|
622 | | - * This function uses to remove the i2c-client |
---|
623 | | - * touchscreen driver and returns integer. |
---|
624 | | - */ |
---|
| 554 | + |
---|
625 | 555 | static int bu21013_remove(struct i2c_client *client) |
---|
626 | 556 | { |
---|
627 | | - struct bu21013_ts_data *bu21013_data = i2c_get_clientdata(client); |
---|
| 557 | + struct bu21013_ts *ts = i2c_get_clientdata(client); |
---|
628 | 558 | |
---|
629 | | - bu21013_free_irq(bu21013_data); |
---|
630 | | - |
---|
631 | | - bu21013_cs_disable(bu21013_data); |
---|
632 | | - |
---|
633 | | - input_unregister_device(bu21013_data->in_dev); |
---|
634 | | - |
---|
635 | | - regulator_disable(bu21013_data->regulator); |
---|
636 | | - regulator_put(bu21013_data->regulator); |
---|
637 | | - |
---|
638 | | - kfree(bu21013_data); |
---|
| 559 | + /* Make sure IRQ will exit quickly even if there is contact */ |
---|
| 560 | + ts->touch_stopped = true; |
---|
| 561 | + /* The resources will be freed by devm */ |
---|
639 | 562 | |
---|
640 | 563 | return 0; |
---|
641 | 564 | } |
---|
642 | 565 | |
---|
643 | | -#ifdef CONFIG_PM |
---|
644 | | -/** |
---|
645 | | - * bu21013_suspend() - suspend the touch screen controller |
---|
646 | | - * @dev: pointer to device structure |
---|
647 | | - * |
---|
648 | | - * This function is used to suspend the |
---|
649 | | - * touch panel controller and returns integer |
---|
650 | | - */ |
---|
651 | | -static int bu21013_suspend(struct device *dev) |
---|
| 566 | +static int __maybe_unused bu21013_suspend(struct device *dev) |
---|
652 | 567 | { |
---|
653 | | - struct bu21013_ts_data *bu21013_data = dev_get_drvdata(dev); |
---|
654 | | - struct i2c_client *client = bu21013_data->client; |
---|
| 568 | + struct i2c_client *client = to_i2c_client(dev); |
---|
| 569 | + struct bu21013_ts *ts = i2c_get_clientdata(client); |
---|
655 | 570 | |
---|
656 | | - bu21013_data->touch_stopped = true; |
---|
657 | | - if (device_may_wakeup(&client->dev)) |
---|
658 | | - enable_irq_wake(bu21013_data->irq); |
---|
659 | | - else |
---|
660 | | - disable_irq(bu21013_data->irq); |
---|
| 571 | + ts->touch_stopped = true; |
---|
| 572 | + mb(); |
---|
| 573 | + disable_irq(client->irq); |
---|
661 | 574 | |
---|
662 | | - regulator_disable(bu21013_data->regulator); |
---|
| 575 | + if (!device_may_wakeup(&client->dev)) |
---|
| 576 | + regulator_disable(ts->regulator); |
---|
663 | 577 | |
---|
664 | 578 | return 0; |
---|
665 | 579 | } |
---|
666 | 580 | |
---|
667 | | -/** |
---|
668 | | - * bu21013_resume() - resume the touch screen controller |
---|
669 | | - * @dev: pointer to device structure |
---|
670 | | - * |
---|
671 | | - * This function is used to resume the touch panel |
---|
672 | | - * controller and returns integer. |
---|
673 | | - */ |
---|
674 | | -static int bu21013_resume(struct device *dev) |
---|
| 581 | +static int __maybe_unused bu21013_resume(struct device *dev) |
---|
675 | 582 | { |
---|
676 | | - struct bu21013_ts_data *bu21013_data = dev_get_drvdata(dev); |
---|
677 | | - struct i2c_client *client = bu21013_data->client; |
---|
678 | | - int retval; |
---|
| 583 | + struct i2c_client *client = to_i2c_client(dev); |
---|
| 584 | + struct bu21013_ts *ts = i2c_get_clientdata(client); |
---|
| 585 | + int error; |
---|
679 | 586 | |
---|
680 | | - retval = regulator_enable(bu21013_data->regulator); |
---|
681 | | - if (retval < 0) { |
---|
682 | | - dev_err(&client->dev, "bu21013 regulator enable failed\n"); |
---|
683 | | - return retval; |
---|
| 587 | + if (!device_may_wakeup(&client->dev)) { |
---|
| 588 | + error = regulator_enable(ts->regulator); |
---|
| 589 | + if (error) { |
---|
| 590 | + dev_err(&client->dev, |
---|
| 591 | + "failed to re-enable regulator when resuming\n"); |
---|
| 592 | + return error; |
---|
| 593 | + } |
---|
| 594 | + |
---|
| 595 | + error = bu21013_init_chip(ts); |
---|
| 596 | + if (error) { |
---|
| 597 | + dev_err(&client->dev, |
---|
| 598 | + "failed to reinitialize chip when resuming\n"); |
---|
| 599 | + return error; |
---|
| 600 | + } |
---|
684 | 601 | } |
---|
685 | 602 | |
---|
686 | | - retval = bu21013_init_chip(bu21013_data); |
---|
687 | | - if (retval < 0) { |
---|
688 | | - dev_err(&client->dev, "bu21013 controller config failed\n"); |
---|
689 | | - return retval; |
---|
690 | | - } |
---|
691 | | - |
---|
692 | | - bu21013_data->touch_stopped = false; |
---|
693 | | - |
---|
694 | | - if (device_may_wakeup(&client->dev)) |
---|
695 | | - disable_irq_wake(bu21013_data->irq); |
---|
696 | | - else |
---|
697 | | - enable_irq(bu21013_data->irq); |
---|
| 603 | + ts->touch_stopped = false; |
---|
| 604 | + mb(); |
---|
| 605 | + enable_irq(client->irq); |
---|
698 | 606 | |
---|
699 | 607 | return 0; |
---|
700 | 608 | } |
---|
701 | 609 | |
---|
702 | | -static const struct dev_pm_ops bu21013_dev_pm_ops = { |
---|
703 | | - .suspend = bu21013_suspend, |
---|
704 | | - .resume = bu21013_resume, |
---|
705 | | -}; |
---|
706 | | -#endif |
---|
| 610 | +static SIMPLE_DEV_PM_OPS(bu21013_dev_pm_ops, bu21013_suspend, bu21013_resume); |
---|
707 | 611 | |
---|
708 | 612 | static const struct i2c_device_id bu21013_id[] = { |
---|
709 | 613 | { DRIVER_TP, 0 }, |
---|
.. | .. |
---|
714 | 618 | static struct i2c_driver bu21013_driver = { |
---|
715 | 619 | .driver = { |
---|
716 | 620 | .name = DRIVER_TP, |
---|
717 | | -#ifdef CONFIG_PM |
---|
718 | 621 | .pm = &bu21013_dev_pm_ops, |
---|
719 | | -#endif |
---|
720 | 622 | }, |
---|
721 | 623 | .probe = bu21013_probe, |
---|
722 | 624 | .remove = bu21013_remove, |
---|