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