aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/accel/bma180.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/drivers/iio/accel/bma180.c b/drivers/iio/accel/bma180.c
index a077cc86421b..f5e26fb697a3 100644
--- a/drivers/iio/accel/bma180.c
+++ b/drivers/iio/accel/bma180.c
@@ -529,7 +529,6 @@ static int bma180_probe(struct i2c_client *client,
529{ 529{
530 struct bma180_data *data; 530 struct bma180_data *data;
531 struct iio_dev *indio_dev; 531 struct iio_dev *indio_dev;
532 struct iio_trigger *trig;
533 int ret; 532 int ret;
534 533
535 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 534 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
@@ -553,29 +552,31 @@ static int bma180_probe(struct i2c_client *client,
553 indio_dev->modes = INDIO_DIRECT_MODE; 552 indio_dev->modes = INDIO_DIRECT_MODE;
554 indio_dev->info = &bma180_info; 553 indio_dev->info = &bma180_info;
555 554
556 trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, indio_dev->id); 555 if (client->irq > 0) {
557 if (!trig) { 556 data->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
558 ret = -ENOMEM; 557 indio_dev->id);
559 goto err_chip_disable; 558 if (!data->trig) {
560 } 559 ret = -ENOMEM;
560 goto err_chip_disable;
561 }
561 562
562 ret = devm_request_irq(&client->dev, client->irq, 563 ret = devm_request_irq(&client->dev, client->irq,
563 iio_trigger_generic_data_rdy_poll, 564 iio_trigger_generic_data_rdy_poll, IRQF_TRIGGER_RISING,
564 IRQF_TRIGGER_RISING, BMA180_IRQ_NAME, trig); 565 BMA180_IRQ_NAME, data->trig);
565 if (ret) { 566 if (ret) {
566 dev_err(&client->dev, "unable to request IRQ\n"); 567 dev_err(&client->dev, "unable to request IRQ\n");
567 goto err_trigger_free; 568 goto err_trigger_free;
568 } 569 }
569 570
570 trig->dev.parent = &client->dev; 571 data->trig->dev.parent = &client->dev;
571 trig->ops = &bma180_trigger_ops; 572 data->trig->ops = &bma180_trigger_ops;
572 iio_trigger_set_drvdata(trig, indio_dev); 573 iio_trigger_set_drvdata(data->trig, indio_dev);
573 data->trig = trig; 574 indio_dev->trig = data->trig;
574 indio_dev->trig = trig;
575 575
576 ret = iio_trigger_register(trig); 576 ret = iio_trigger_register(data->trig);
577 if (ret) 577 if (ret)
578 goto err_trigger_free; 578 goto err_trigger_free;
579 }
579 580
580 ret = iio_triggered_buffer_setup(indio_dev, NULL, 581 ret = iio_triggered_buffer_setup(indio_dev, NULL,
581 bma180_trigger_handler, NULL); 582 bma180_trigger_handler, NULL);
@@ -595,9 +596,10 @@ static int bma180_probe(struct i2c_client *client,
595err_buffer_cleanup: 596err_buffer_cleanup:
596 iio_triggered_buffer_cleanup(indio_dev); 597 iio_triggered_buffer_cleanup(indio_dev);
597err_trigger_unregister: 598err_trigger_unregister:
598 iio_trigger_unregister(trig); 599 if (data->trig)
600 iio_trigger_unregister(data->trig);
599err_trigger_free: 601err_trigger_free:
600 iio_trigger_free(trig); 602 iio_trigger_free(data->trig);
601err_chip_disable: 603err_chip_disable:
602 bma180_chip_disable(data); 604 bma180_chip_disable(data);
603 605
@@ -611,8 +613,10 @@ static int bma180_remove(struct i2c_client *client)
611 613
612 iio_device_unregister(indio_dev); 614 iio_device_unregister(indio_dev);
613 iio_triggered_buffer_cleanup(indio_dev); 615 iio_triggered_buffer_cleanup(indio_dev);
614 iio_trigger_unregister(data->trig); 616 if (data->trig) {
615 iio_trigger_free(data->trig); 617 iio_trigger_unregister(data->trig);
618 iio_trigger_free(data->trig);
619 }
616 620
617 mutex_lock(&data->mutex); 621 mutex_lock(&data->mutex);
618 bma180_chip_disable(data); 622 bma180_chip_disable(data);