Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics Co.Ltd |
| 3 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/delay.h> |
Tomasz Figa | ad5396e | 2012-10-11 01:03:50 -0700 | [diff] [blame] | 13 | #include <linux/of.h> |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 14 | #include <linux/i2c.h> |
| 15 | #include <linux/i2c/mms114.h> |
| 16 | #include <linux/input/mt.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/regulator/consumer.h> |
| 19 | #include <linux/slab.h> |
| 20 | |
| 21 | /* Write only registers */ |
| 22 | #define MMS114_MODE_CONTROL 0x01 |
| 23 | #define MMS114_OPERATION_MODE_MASK 0xE |
| 24 | #define MMS114_ACTIVE (1 << 1) |
| 25 | |
| 26 | #define MMS114_XY_RESOLUTION_H 0x02 |
| 27 | #define MMS114_X_RESOLUTION 0x03 |
| 28 | #define MMS114_Y_RESOLUTION 0x04 |
| 29 | #define MMS114_CONTACT_THRESHOLD 0x05 |
| 30 | #define MMS114_MOVING_THRESHOLD 0x06 |
| 31 | |
| 32 | /* Read only registers */ |
| 33 | #define MMS114_PACKET_SIZE 0x0F |
| 34 | #define MMS114_INFOMATION 0x10 |
| 35 | #define MMS114_TSP_REV 0xF0 |
| 36 | |
| 37 | /* Minimum delay time is 50us between stop and start signal of i2c */ |
| 38 | #define MMS114_I2C_DELAY 50 |
| 39 | |
| 40 | /* 200ms needs after power on */ |
| 41 | #define MMS114_POWERON_DELAY 200 |
| 42 | |
| 43 | /* Touchscreen absolute values */ |
| 44 | #define MMS114_MAX_AREA 0xff |
| 45 | |
| 46 | #define MMS114_MAX_TOUCH 10 |
| 47 | #define MMS114_PACKET_NUM 8 |
| 48 | |
| 49 | /* Touch type */ |
| 50 | #define MMS114_TYPE_NONE 0 |
| 51 | #define MMS114_TYPE_TOUCHSCREEN 1 |
| 52 | #define MMS114_TYPE_TOUCHKEY 2 |
| 53 | |
| 54 | struct mms114_data { |
| 55 | struct i2c_client *client; |
| 56 | struct input_dev *input_dev; |
| 57 | struct regulator *core_reg; |
| 58 | struct regulator *io_reg; |
| 59 | const struct mms114_platform_data *pdata; |
| 60 | |
| 61 | /* Use cache data for mode control register(write only) */ |
| 62 | u8 cache_mode_control; |
| 63 | }; |
| 64 | |
| 65 | struct mms114_touch { |
| 66 | u8 id:4, reserved_bit4:1, type:2, pressed:1; |
| 67 | u8 x_hi:4, y_hi:4; |
| 68 | u8 x_lo; |
| 69 | u8 y_lo; |
| 70 | u8 width; |
| 71 | u8 strength; |
| 72 | u8 reserved[2]; |
| 73 | } __packed; |
| 74 | |
| 75 | static int __mms114_read_reg(struct mms114_data *data, unsigned int reg, |
| 76 | unsigned int len, u8 *val) |
| 77 | { |
| 78 | struct i2c_client *client = data->client; |
| 79 | struct i2c_msg xfer[2]; |
| 80 | u8 buf = reg & 0xff; |
| 81 | int error; |
| 82 | |
| 83 | if (reg <= MMS114_MODE_CONTROL && reg + len > MMS114_MODE_CONTROL) |
| 84 | BUG(); |
| 85 | |
| 86 | /* Write register: use repeated start */ |
| 87 | xfer[0].addr = client->addr; |
| 88 | xfer[0].flags = I2C_M_TEN | I2C_M_NOSTART; |
| 89 | xfer[0].len = 1; |
| 90 | xfer[0].buf = &buf; |
| 91 | |
| 92 | /* Read data */ |
| 93 | xfer[1].addr = client->addr; |
| 94 | xfer[1].flags = I2C_M_RD; |
| 95 | xfer[1].len = len; |
| 96 | xfer[1].buf = val; |
| 97 | |
| 98 | error = i2c_transfer(client->adapter, xfer, 2); |
| 99 | if (error != 2) { |
| 100 | dev_err(&client->dev, |
| 101 | "%s: i2c transfer failed (%d)\n", __func__, error); |
| 102 | return error < 0 ? error : -EIO; |
| 103 | } |
| 104 | udelay(MMS114_I2C_DELAY); |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int mms114_read_reg(struct mms114_data *data, unsigned int reg) |
| 110 | { |
| 111 | u8 val; |
| 112 | int error; |
| 113 | |
| 114 | if (reg == MMS114_MODE_CONTROL) |
| 115 | return data->cache_mode_control; |
| 116 | |
| 117 | error = __mms114_read_reg(data, reg, 1, &val); |
| 118 | return error < 0 ? error : val; |
| 119 | } |
| 120 | |
| 121 | static int mms114_write_reg(struct mms114_data *data, unsigned int reg, |
| 122 | unsigned int val) |
| 123 | { |
| 124 | struct i2c_client *client = data->client; |
| 125 | u8 buf[2]; |
| 126 | int error; |
| 127 | |
| 128 | buf[0] = reg & 0xff; |
| 129 | buf[1] = val & 0xff; |
| 130 | |
| 131 | error = i2c_master_send(client, buf, 2); |
| 132 | if (error != 2) { |
| 133 | dev_err(&client->dev, |
| 134 | "%s: i2c send failed (%d)\n", __func__, error); |
| 135 | return error < 0 ? error : -EIO; |
| 136 | } |
| 137 | udelay(MMS114_I2C_DELAY); |
| 138 | |
| 139 | if (reg == MMS114_MODE_CONTROL) |
| 140 | data->cache_mode_control = val; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *touch) |
| 146 | { |
| 147 | const struct mms114_platform_data *pdata = data->pdata; |
| 148 | struct i2c_client *client = data->client; |
| 149 | struct input_dev *input_dev = data->input_dev; |
| 150 | unsigned int id; |
| 151 | unsigned int x; |
| 152 | unsigned int y; |
| 153 | |
| 154 | if (touch->id > MMS114_MAX_TOUCH) { |
| 155 | dev_err(&client->dev, "Wrong touch id (%d)\n", touch->id); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | if (touch->type != MMS114_TYPE_TOUCHSCREEN) { |
| 160 | dev_err(&client->dev, "Wrong touch type (%d)\n", touch->type); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | id = touch->id - 1; |
| 165 | x = touch->x_lo | touch->x_hi << 8; |
| 166 | y = touch->y_lo | touch->y_hi << 8; |
| 167 | if (x > pdata->x_size || y > pdata->y_size) { |
| 168 | dev_dbg(&client->dev, |
| 169 | "Wrong touch coordinates (%d, %d)\n", x, y); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | if (pdata->x_invert) |
| 174 | x = pdata->x_size - x; |
| 175 | if (pdata->y_invert) |
| 176 | y = pdata->y_size - y; |
| 177 | |
| 178 | dev_dbg(&client->dev, |
| 179 | "id: %d, type: %d, pressed: %d, x: %d, y: %d, width: %d, strength: %d\n", |
| 180 | id, touch->type, touch->pressed, |
| 181 | x, y, touch->width, touch->strength); |
| 182 | |
| 183 | input_mt_slot(input_dev, id); |
| 184 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, touch->pressed); |
| 185 | |
| 186 | if (touch->pressed) { |
| 187 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, touch->width); |
| 188 | input_report_abs(input_dev, ABS_MT_POSITION_X, x); |
| 189 | input_report_abs(input_dev, ABS_MT_POSITION_Y, y); |
| 190 | input_report_abs(input_dev, ABS_MT_PRESSURE, touch->strength); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | static irqreturn_t mms114_interrupt(int irq, void *dev_id) |
| 195 | { |
| 196 | struct mms114_data *data = dev_id; |
| 197 | struct input_dev *input_dev = data->input_dev; |
| 198 | struct mms114_touch touch[MMS114_MAX_TOUCH]; |
| 199 | int packet_size; |
| 200 | int touch_size; |
| 201 | int index; |
| 202 | int error; |
| 203 | |
| 204 | mutex_lock(&input_dev->mutex); |
| 205 | if (!input_dev->users) { |
| 206 | mutex_unlock(&input_dev->mutex); |
| 207 | goto out; |
| 208 | } |
| 209 | mutex_unlock(&input_dev->mutex); |
| 210 | |
| 211 | packet_size = mms114_read_reg(data, MMS114_PACKET_SIZE); |
| 212 | if (packet_size <= 0) |
| 213 | goto out; |
| 214 | |
| 215 | touch_size = packet_size / MMS114_PACKET_NUM; |
| 216 | |
| 217 | error = __mms114_read_reg(data, MMS114_INFOMATION, packet_size, |
| 218 | (u8 *)touch); |
| 219 | if (error < 0) |
| 220 | goto out; |
| 221 | |
| 222 | for (index = 0; index < touch_size; index++) |
| 223 | mms114_process_mt(data, touch + index); |
| 224 | |
| 225 | input_mt_report_pointer_emulation(data->input_dev, true); |
| 226 | input_sync(data->input_dev); |
| 227 | |
| 228 | out: |
| 229 | return IRQ_HANDLED; |
| 230 | } |
| 231 | |
| 232 | static int mms114_set_active(struct mms114_data *data, bool active) |
| 233 | { |
| 234 | int val; |
| 235 | |
| 236 | val = mms114_read_reg(data, MMS114_MODE_CONTROL); |
| 237 | if (val < 0) |
| 238 | return val; |
| 239 | |
| 240 | val &= ~MMS114_OPERATION_MODE_MASK; |
| 241 | |
| 242 | /* If active is false, sleep mode */ |
| 243 | if (active) |
| 244 | val |= MMS114_ACTIVE; |
| 245 | |
| 246 | return mms114_write_reg(data, MMS114_MODE_CONTROL, val); |
| 247 | } |
| 248 | |
| 249 | static int mms114_get_version(struct mms114_data *data) |
| 250 | { |
| 251 | struct device *dev = &data->client->dev; |
| 252 | u8 buf[6]; |
| 253 | int error; |
| 254 | |
| 255 | error = __mms114_read_reg(data, MMS114_TSP_REV, 6, buf); |
| 256 | if (error < 0) |
| 257 | return error; |
| 258 | |
| 259 | dev_info(dev, "TSP Rev: 0x%x, HW Rev: 0x%x, Firmware Ver: 0x%x\n", |
| 260 | buf[0], buf[1], buf[3]); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | static int mms114_setup_regs(struct mms114_data *data) |
| 266 | { |
| 267 | const struct mms114_platform_data *pdata = data->pdata; |
| 268 | int val; |
| 269 | int error; |
| 270 | |
| 271 | error = mms114_get_version(data); |
| 272 | if (error < 0) |
| 273 | return error; |
| 274 | |
| 275 | error = mms114_set_active(data, true); |
| 276 | if (error < 0) |
| 277 | return error; |
| 278 | |
| 279 | val = (pdata->x_size >> 8) & 0xf; |
| 280 | val |= ((pdata->y_size >> 8) & 0xf) << 4; |
| 281 | error = mms114_write_reg(data, MMS114_XY_RESOLUTION_H, val); |
| 282 | if (error < 0) |
| 283 | return error; |
| 284 | |
| 285 | val = pdata->x_size & 0xff; |
| 286 | error = mms114_write_reg(data, MMS114_X_RESOLUTION, val); |
| 287 | if (error < 0) |
| 288 | return error; |
| 289 | |
| 290 | val = pdata->y_size & 0xff; |
| 291 | error = mms114_write_reg(data, MMS114_Y_RESOLUTION, val); |
| 292 | if (error < 0) |
| 293 | return error; |
| 294 | |
| 295 | if (pdata->contact_threshold) { |
| 296 | error = mms114_write_reg(data, MMS114_CONTACT_THRESHOLD, |
| 297 | pdata->contact_threshold); |
| 298 | if (error < 0) |
| 299 | return error; |
| 300 | } |
| 301 | |
| 302 | if (pdata->moving_threshold) { |
| 303 | error = mms114_write_reg(data, MMS114_MOVING_THRESHOLD, |
| 304 | pdata->moving_threshold); |
| 305 | if (error < 0) |
| 306 | return error; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static int mms114_start(struct mms114_data *data) |
| 313 | { |
| 314 | struct i2c_client *client = data->client; |
| 315 | int error; |
| 316 | |
| 317 | if (data->core_reg) |
| 318 | regulator_enable(data->core_reg); |
| 319 | if (data->io_reg) |
| 320 | regulator_enable(data->io_reg); |
| 321 | mdelay(MMS114_POWERON_DELAY); |
| 322 | |
| 323 | error = mms114_setup_regs(data); |
| 324 | if (error < 0) |
| 325 | return error; |
| 326 | |
| 327 | if (data->pdata->cfg_pin) |
| 328 | data->pdata->cfg_pin(true); |
| 329 | |
| 330 | enable_irq(client->irq); |
| 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static void mms114_stop(struct mms114_data *data) |
| 336 | { |
| 337 | struct i2c_client *client = data->client; |
| 338 | |
| 339 | disable_irq(client->irq); |
| 340 | |
| 341 | if (data->pdata->cfg_pin) |
| 342 | data->pdata->cfg_pin(false); |
| 343 | |
| 344 | if (data->io_reg) |
| 345 | regulator_disable(data->io_reg); |
| 346 | if (data->core_reg) |
| 347 | regulator_disable(data->core_reg); |
| 348 | } |
| 349 | |
| 350 | static int mms114_input_open(struct input_dev *dev) |
| 351 | { |
| 352 | struct mms114_data *data = input_get_drvdata(dev); |
| 353 | |
| 354 | return mms114_start(data); |
| 355 | } |
| 356 | |
| 357 | static void mms114_input_close(struct input_dev *dev) |
| 358 | { |
| 359 | struct mms114_data *data = input_get_drvdata(dev); |
| 360 | |
| 361 | mms114_stop(data); |
| 362 | } |
| 363 | |
Tomasz Figa | ad5396e | 2012-10-11 01:03:50 -0700 | [diff] [blame] | 364 | #ifdef CONFIG_OF |
| 365 | static struct mms114_platform_data * __devinit mms114_parse_dt(struct device *dev) |
| 366 | { |
| 367 | struct mms114_platform_data *pdata; |
| 368 | struct device_node *np = dev->of_node; |
| 369 | |
| 370 | if (!np) |
| 371 | return NULL; |
| 372 | |
| 373 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 374 | if (!pdata) { |
| 375 | dev_err(dev, "failed to allocate platform data\n"); |
| 376 | return NULL; |
| 377 | } |
| 378 | |
| 379 | if (of_property_read_u32(np, "x-size", &pdata->x_size)) { |
| 380 | dev_err(dev, "failed to get x-size property\n"); |
| 381 | return NULL; |
| 382 | }; |
| 383 | |
| 384 | if (of_property_read_u32(np, "y-size", &pdata->y_size)) { |
| 385 | dev_err(dev, "failed to get y-size property\n"); |
| 386 | return NULL; |
| 387 | }; |
| 388 | |
| 389 | of_property_read_u32(np, "contact-threshold", |
| 390 | &pdata->contact_threshold); |
| 391 | of_property_read_u32(np, "moving-threshold", |
| 392 | &pdata->moving_threshold); |
| 393 | |
| 394 | if (of_find_property(np, "x-invert", NULL)) |
| 395 | pdata->x_invert = true; |
| 396 | if (of_find_property(np, "y-invert", NULL)) |
| 397 | pdata->y_invert = true; |
| 398 | |
| 399 | return pdata; |
| 400 | } |
| 401 | #else |
| 402 | static inline struct mms114_platform_data *mms114_parse_dt(struct device *dev) |
| 403 | { |
| 404 | return NULL; |
| 405 | } |
| 406 | #endif |
| 407 | |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 408 | static int __devinit mms114_probe(struct i2c_client *client, |
| 409 | const struct i2c_device_id *id) |
| 410 | { |
Tomasz Figa | ad5396e | 2012-10-11 01:03:50 -0700 | [diff] [blame] | 411 | const struct mms114_platform_data *pdata; |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 412 | struct mms114_data *data; |
| 413 | struct input_dev *input_dev; |
| 414 | int error; |
| 415 | |
Tomasz Figa | ad5396e | 2012-10-11 01:03:50 -0700 | [diff] [blame] | 416 | pdata = dev_get_platdata(&client->dev); |
| 417 | if (!pdata) |
| 418 | pdata = mms114_parse_dt(&client->dev); |
| 419 | |
| 420 | if (!pdata) { |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 421 | dev_err(&client->dev, "Need platform data\n"); |
| 422 | return -EINVAL; |
| 423 | } |
| 424 | |
| 425 | if (!i2c_check_functionality(client->adapter, |
| 426 | I2C_FUNC_PROTOCOL_MANGLING)) { |
| 427 | dev_err(&client->dev, |
| 428 | "Need i2c bus that supports protocol mangling\n"); |
| 429 | return -ENODEV; |
| 430 | } |
| 431 | |
| 432 | data = kzalloc(sizeof(struct mms114_data), GFP_KERNEL); |
| 433 | input_dev = input_allocate_device(); |
| 434 | if (!data || !input_dev) { |
| 435 | dev_err(&client->dev, "Failed to allocate memory\n"); |
| 436 | error = -ENOMEM; |
| 437 | goto err_free_mem; |
| 438 | } |
| 439 | |
| 440 | data->client = client; |
| 441 | data->input_dev = input_dev; |
Tomasz Figa | ad5396e | 2012-10-11 01:03:50 -0700 | [diff] [blame] | 442 | data->pdata = pdata; |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 443 | |
| 444 | input_dev->name = "MELPAS MMS114 Touchscreen"; |
| 445 | input_dev->id.bustype = BUS_I2C; |
| 446 | input_dev->dev.parent = &client->dev; |
| 447 | input_dev->open = mms114_input_open; |
| 448 | input_dev->close = mms114_input_close; |
| 449 | |
| 450 | __set_bit(EV_ABS, input_dev->evbit); |
| 451 | __set_bit(EV_KEY, input_dev->evbit); |
| 452 | __set_bit(BTN_TOUCH, input_dev->keybit); |
| 453 | input_set_abs_params(input_dev, ABS_X, 0, data->pdata->x_size, 0, 0); |
| 454 | input_set_abs_params(input_dev, ABS_Y, 0, data->pdata->y_size, 0, 0); |
| 455 | |
| 456 | /* For multi touch */ |
Henrik Rydberg | b4adbbe | 2012-08-11 22:07:55 +0200 | [diff] [blame] | 457 | input_mt_init_slots(input_dev, MMS114_MAX_TOUCH, 0); |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 458 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, |
| 459 | 0, MMS114_MAX_AREA, 0, 0); |
| 460 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, |
| 461 | 0, data->pdata->x_size, 0, 0); |
| 462 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, |
| 463 | 0, data->pdata->y_size, 0, 0); |
| 464 | input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0); |
| 465 | |
| 466 | input_set_drvdata(input_dev, data); |
| 467 | i2c_set_clientdata(client, data); |
| 468 | |
| 469 | data->core_reg = regulator_get(&client->dev, "avdd"); |
| 470 | if (IS_ERR(data->core_reg)) { |
| 471 | error = PTR_ERR(data->core_reg); |
| 472 | dev_err(&client->dev, |
| 473 | "Unable to get the Core regulator (%d)\n", error); |
| 474 | goto err_free_mem; |
| 475 | } |
| 476 | |
| 477 | data->io_reg = regulator_get(&client->dev, "vdd"); |
| 478 | if (IS_ERR(data->io_reg)) { |
| 479 | error = PTR_ERR(data->io_reg); |
| 480 | dev_err(&client->dev, |
| 481 | "Unable to get the IO regulator (%d)\n", error); |
| 482 | goto err_core_reg; |
| 483 | } |
| 484 | |
| 485 | error = request_threaded_irq(client->irq, NULL, mms114_interrupt, |
| 486 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "mms114", data); |
| 487 | if (error) { |
| 488 | dev_err(&client->dev, "Failed to register interrupt\n"); |
| 489 | goto err_io_reg; |
| 490 | } |
| 491 | disable_irq(client->irq); |
| 492 | |
| 493 | error = input_register_device(data->input_dev); |
| 494 | if (error) |
| 495 | goto err_free_irq; |
| 496 | |
| 497 | return 0; |
| 498 | |
| 499 | err_free_irq: |
| 500 | free_irq(client->irq, data); |
| 501 | err_io_reg: |
| 502 | regulator_put(data->io_reg); |
| 503 | err_core_reg: |
| 504 | regulator_put(data->core_reg); |
| 505 | err_free_mem: |
| 506 | input_free_device(input_dev); |
| 507 | kfree(data); |
| 508 | return error; |
| 509 | } |
| 510 | |
| 511 | static int __devexit mms114_remove(struct i2c_client *client) |
| 512 | { |
| 513 | struct mms114_data *data = i2c_get_clientdata(client); |
| 514 | |
| 515 | free_irq(client->irq, data); |
| 516 | regulator_put(data->io_reg); |
| 517 | regulator_put(data->core_reg); |
| 518 | input_unregister_device(data->input_dev); |
| 519 | kfree(data); |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | #ifdef CONFIG_PM_SLEEP |
| 525 | static int mms114_suspend(struct device *dev) |
| 526 | { |
| 527 | struct i2c_client *client = to_i2c_client(dev); |
| 528 | struct mms114_data *data = i2c_get_clientdata(client); |
| 529 | struct input_dev *input_dev = data->input_dev; |
| 530 | int id; |
| 531 | |
| 532 | /* Release all touch */ |
| 533 | for (id = 0; id < MMS114_MAX_TOUCH; id++) { |
| 534 | input_mt_slot(input_dev, id); |
| 535 | input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false); |
| 536 | } |
| 537 | |
| 538 | input_mt_report_pointer_emulation(input_dev, true); |
| 539 | input_sync(input_dev); |
| 540 | |
| 541 | mutex_lock(&input_dev->mutex); |
| 542 | if (input_dev->users) |
| 543 | mms114_stop(data); |
| 544 | mutex_unlock(&input_dev->mutex); |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | static int mms114_resume(struct device *dev) |
| 550 | { |
| 551 | struct i2c_client *client = to_i2c_client(dev); |
| 552 | struct mms114_data *data = i2c_get_clientdata(client); |
| 553 | struct input_dev *input_dev = data->input_dev; |
| 554 | int error; |
| 555 | |
| 556 | mutex_lock(&input_dev->mutex); |
| 557 | if (input_dev->users) { |
| 558 | error = mms114_start(data); |
| 559 | if (error < 0) { |
| 560 | mutex_unlock(&input_dev->mutex); |
| 561 | return error; |
| 562 | } |
| 563 | } |
| 564 | mutex_unlock(&input_dev->mutex); |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | #endif |
| 569 | |
| 570 | static SIMPLE_DEV_PM_OPS(mms114_pm_ops, mms114_suspend, mms114_resume); |
| 571 | |
| 572 | static const struct i2c_device_id mms114_id[] = { |
| 573 | { "mms114", 0 }, |
| 574 | { } |
| 575 | }; |
| 576 | MODULE_DEVICE_TABLE(i2c, mms114_id); |
| 577 | |
Tomasz Figa | ad5396e | 2012-10-11 01:03:50 -0700 | [diff] [blame] | 578 | #ifdef CONFIG_OF |
| 579 | static struct of_device_id __devinitdata mms114_dt_match[] = { |
| 580 | { .compatible = "melfas,mms114" }, |
| 581 | { } |
| 582 | }; |
| 583 | #endif |
| 584 | |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 585 | static struct i2c_driver mms114_driver = { |
| 586 | .driver = { |
| 587 | .name = "mms114", |
| 588 | .owner = THIS_MODULE, |
| 589 | .pm = &mms114_pm_ops, |
Tomasz Figa | ad5396e | 2012-10-11 01:03:50 -0700 | [diff] [blame] | 590 | .of_match_table = of_match_ptr(mms114_dt_match), |
Joonyoung Shim | 07b8481 | 2012-07-13 00:25:45 -0700 | [diff] [blame] | 591 | }, |
| 592 | .probe = mms114_probe, |
| 593 | .remove = __devexit_p(mms114_remove), |
| 594 | .id_table = mms114_id, |
| 595 | }; |
| 596 | |
| 597 | module_i2c_driver(mms114_driver); |
| 598 | |
| 599 | /* Module information */ |
| 600 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
| 601 | MODULE_DESCRIPTION("MELFAS mms114 Touchscreen driver"); |
| 602 | MODULE_LICENSE("GPL"); |