Input: ads7846 - convert to to dynamic input_dev allocation

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

+47 -32
+47 -32
drivers/input/touchscreen/ads7846.c
··· 60 60 }; 61 61 62 62 struct ads7846 { 63 - struct input_dev input; 63 + struct input_dev *input; 64 64 char phys[32]; 65 65 66 66 struct spi_device *spi; ··· 152 152 struct ser_req *req = kzalloc(sizeof *req, SLAB_KERNEL); 153 153 int status; 154 154 int sample; 155 - int i; 155 + int i; 156 156 157 157 if (!req) 158 158 return -ENOMEM; ··· 236 236 237 237 static void ads7846_rx(void *ads) 238 238 { 239 - struct ads7846 *ts = ads; 240 - unsigned Rt; 241 - unsigned sync = 0; 242 - u16 x, y, z1, z2; 243 - unsigned long flags; 239 + struct ads7846 *ts = ads; 240 + struct input_dev *input_dev = ts->input; 241 + unsigned Rt; 242 + unsigned sync = 0; 243 + u16 x, y, z1, z2; 244 + unsigned long flags; 244 245 245 246 /* adjust: 12 bit samples (left aligned), built from 246 247 * two 8 bit values writen msb-first. ··· 277 276 * won't notice that, even if nPENIRQ never fires ... 278 277 */ 279 278 if (!ts->pendown && Rt != 0) { 280 - input_report_key(&ts->input, BTN_TOUCH, 1); 279 + input_report_key(input_dev, BTN_TOUCH, 1); 281 280 sync = 1; 282 281 } else if (ts->pendown && Rt == 0) { 283 - input_report_key(&ts->input, BTN_TOUCH, 0); 282 + input_report_key(input_dev, BTN_TOUCH, 0); 284 283 sync = 1; 285 284 } 286 285 287 286 if (Rt) { 288 - input_report_abs(&ts->input, ABS_X, x); 289 - input_report_abs(&ts->input, ABS_Y, y); 290 - input_report_abs(&ts->input, ABS_PRESSURE, Rt); 287 + input_report_abs(input_dev, ABS_X, x); 288 + input_report_abs(input_dev, ABS_Y, y); 289 + input_report_abs(input_dev, ABS_PRESSURE, Rt); 291 290 sync = 1; 292 291 } 293 292 if (sync) 294 - input_sync(&ts->input); 293 + input_sync(input_dev); 295 294 296 295 #ifdef VERBOSE 297 296 if (Rt || ts->pendown) ··· 397 396 static int __devinit ads7846_probe(struct spi_device *spi) 398 397 { 399 398 struct ads7846 *ts; 399 + struct input_dev *input_dev; 400 400 struct ads7846_platform_data *pdata = spi->dev.platform_data; 401 401 struct spi_transfer *x; 402 402 int i; 403 + int err; 403 404 404 405 if (!spi->irq) { 405 406 dev_dbg(&spi->dev, "no IRQ?\n"); ··· 426 423 * to discard the four garbage LSBs. 427 424 */ 428 425 429 - if (!(ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL))) 430 - return -ENOMEM; 426 + ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 427 + input_dev = input_allocate_device(); 428 + if (!ts || !input_dev) { 429 + err = -ENOMEM; 430 + goto err_free_mem; 431 + } 431 432 432 433 dev_set_drvdata(&spi->dev, ts); 434 + spi->dev.power.power_state = PMSG_ON; 433 435 434 436 ts->spi = spi; 435 - spi->dev.power.power_state = PMSG_ON; 437 + ts->input = input_dev; 436 438 437 439 init_timer(&ts->timer); 438 440 ts->timer.data = (unsigned long) ts; ··· 447 439 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; 448 440 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; 449 441 450 - init_input_dev(&ts->input); 442 + snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id); 451 443 452 - ts->input.dev = &spi->dev; 453 - ts->input.name = "ADS784x Touchscreen"; 454 - snprintf(ts->phys, sizeof ts->phys, "%s/input0", spi->dev.bus_id); 455 - ts->input.phys = ts->phys; 444 + input_dev->name = "ADS784x Touchscreen"; 445 + input_dev->phys = ts->phys; 446 + input_dev->cdev.dev = &spi->dev; 456 447 457 - ts->input.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 458 - ts->input.keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 459 - input_set_abs_params(&ts->input, ABS_X, 448 + input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 449 + input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 450 + input_set_abs_params(input_dev, ABS_X, 460 451 pdata->x_min ? : 0, 461 452 pdata->x_max ? : MAX_12BIT, 462 453 0, 0); 463 - input_set_abs_params(&ts->input, ABS_Y, 454 + input_set_abs_params(input_dev, ABS_Y, 464 455 pdata->y_min ? : 0, 465 456 pdata->y_max ? : MAX_12BIT, 466 457 0, 0); 467 - input_set_abs_params(&ts->input, ABS_PRESSURE, 458 + input_set_abs_params(input_dev, ABS_PRESSURE, 468 459 pdata->pressure_min, pdata->pressure_max, 0, 0); 469 - 470 - input_register_device(&ts->input); 471 460 472 461 /* set up the transfers to read touchscreen state; this assumes we 473 462 * use formula #2 for pressure, not #3. ··· 515 510 SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING, 516 511 spi->dev.bus_id, ts)) { 517 512 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 518 - input_unregister_device(&ts->input); 519 - kfree(ts); 520 - return -EBUSY; 513 + err = -EBUSY; 514 + goto err_free_mem; 521 515 } 522 516 523 517 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); ··· 538 534 device_create_file(&spi->dev, &dev_attr_vbatt); 539 535 device_create_file(&spi->dev, &dev_attr_vaux); 540 536 537 + err = input_register_device(input_dev); 538 + if (err) 539 + goto err_free_irq; 540 + 541 541 return 0; 542 + 543 + err_free_irq: 544 + free_irq(spi->irq, ts); 545 + err_free_mem: 546 + input_free_device(input_dev); 547 + kfree(ts); 548 + return err; 542 549 } 543 550 544 551 static int __devexit ads7846_remove(struct spi_device *spi) ··· 569 554 device_remove_file(&spi->dev, &dev_attr_vbatt); 570 555 device_remove_file(&spi->dev, &dev_attr_vaux); 571 556 572 - input_unregister_device(&ts->input); 557 + input_unregister_device(ts->input); 573 558 kfree(ts); 574 559 575 560 dev_dbg(&spi->dev, "unregistered touchscreen\n");