aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/magnetometer
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-06-29 12:49:28 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-06-29 12:49:28 -0400
commit3dc50c1af30bf79c4fca3065acfb34adf05e90c2 (patch)
tree38677ba815b1ec8f3c4ec3eea5dafb34f294b5f7 /drivers/iio/magnetometer
parentac4ddad67acb9f67b42902939df64980fcbdbae5 (diff)
parent9dd4694dafbd8b44ac4ca740beede18ca67d725f (diff)
Merge tag 'iio-for-3.17b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes: Second round of new drivers and cleanups for IIO in the 3.17 cycle. New drivers * mcp4902, mcp4912 and mcp4922 SPI DAC driver. * max1027, max1029 and max1031 SPI ADC driver. Cleanups * cm32181 - use devm APIs to simplify error paths. * ak8975 - use devm APIs to simplify error paths. * ad9850 - drop some unused defines and an unnecessary goto. * hmc5843 - add missing devices to the device id table and the documentation. * ad9832 - small formatting cleanups. * sca3000 - hide direct use of the stufftoread element by adding a data_available function. This is a precursor for the addition of buffer watermarks to the subsystem but stands as a good cleanup on its own.
Diffstat (limited to 'drivers/iio/magnetometer')
-rw-r--r--drivers/iio/magnetometer/ak8975.c58
1 files changed, 14 insertions, 44 deletions
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index ea08313af0d2..a2357921d761 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -165,7 +165,7 @@ static int ak8975_setup_irq(struct ak8975_data *data)
165 else 165 else
166 irq = gpio_to_irq(data->eoc_gpio); 166 irq = gpio_to_irq(data->eoc_gpio);
167 167
168 rc = request_irq(irq, ak8975_irq_handler, 168 rc = devm_request_irq(&client->dev, irq, ak8975_irq_handler,
169 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 169 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
170 dev_name(&client->dev), data); 170 dev_name(&client->dev), data);
171 if (rc < 0) { 171 if (rc < 0) {
@@ -513,21 +513,21 @@ static int ak8975_probe(struct i2c_client *client,
513 /* We may not have a GPIO based IRQ to scan, that is fine, we will 513 /* We may not have a GPIO based IRQ to scan, that is fine, we will
514 poll if so */ 514 poll if so */
515 if (gpio_is_valid(eoc_gpio)) { 515 if (gpio_is_valid(eoc_gpio)) {
516 err = gpio_request_one(eoc_gpio, GPIOF_IN, "ak_8975"); 516 err = devm_gpio_request_one(&client->dev, eoc_gpio,
517 GPIOF_IN, "ak_8975");
517 if (err < 0) { 518 if (err < 0) {
518 dev_err(&client->dev, 519 dev_err(&client->dev,
519 "failed to request GPIO %d, error %d\n", 520 "failed to request GPIO %d, error %d\n",
520 eoc_gpio, err); 521 eoc_gpio, err);
521 goto exit; 522 return err;
522 } 523 }
523 } 524 }
524 525
525 /* Register with IIO */ 526 /* Register with IIO */
526 indio_dev = iio_device_alloc(sizeof(*data)); 527 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
527 if (indio_dev == NULL) { 528 if (indio_dev == NULL)
528 err = -ENOMEM; 529 return -ENOMEM;
529 goto exit_gpio; 530
530 }
531 data = iio_priv(indio_dev); 531 data = iio_priv(indio_dev);
532 i2c_set_clientdata(client, indio_dev); 532 i2c_set_clientdata(client, indio_dev);
533 533
@@ -542,17 +542,16 @@ static int ak8975_probe(struct i2c_client *client,
542 name = (char *) id->name; 542 name = (char *) id->name;
543 } else if (ACPI_HANDLE(&client->dev)) 543 } else if (ACPI_HANDLE(&client->dev))
544 name = ak8975_match_acpi_device(&client->dev, &data->chipset); 544 name = ak8975_match_acpi_device(&client->dev, &data->chipset);
545 else { 545 else
546 err = -ENOSYS; 546 return -ENOSYS;
547 goto exit_free_iio; 547
548 }
549 dev_dbg(&client->dev, "Asahi compass chip %s\n", name); 548 dev_dbg(&client->dev, "Asahi compass chip %s\n", name);
550 549
551 /* Perform some basic start-of-day setup of the device. */ 550 /* Perform some basic start-of-day setup of the device. */
552 err = ak8975_setup(client); 551 err = ak8975_setup(client);
553 if (err < 0) { 552 if (err < 0) {
554 dev_err(&client->dev, "AK8975 initialization fails\n"); 553 dev_err(&client->dev, "AK8975 initialization fails\n");
555 goto exit_free_iio; 554 return err;
556 } 555 }
557 556
558 data->client = client; 557 data->client = client;
@@ -564,37 +563,9 @@ static int ak8975_probe(struct i2c_client *client,
564 indio_dev->info = &ak8975_info; 563 indio_dev->info = &ak8975_info;
565 indio_dev->modes = INDIO_DIRECT_MODE; 564 indio_dev->modes = INDIO_DIRECT_MODE;
566 indio_dev->name = name; 565 indio_dev->name = name;
567 err = iio_device_register(indio_dev); 566 err = devm_iio_device_register(&client->dev, indio_dev);
568 if (err < 0) 567 if (err < 0)
569 goto exit_free_iio; 568 return err;
570
571 return 0;
572
573exit_free_iio:
574 iio_device_free(indio_dev);
575 if (data->eoc_irq)
576 free_irq(data->eoc_irq, data);
577exit_gpio:
578 if (gpio_is_valid(eoc_gpio))
579 gpio_free(eoc_gpio);
580exit:
581 return err;
582}
583
584static int ak8975_remove(struct i2c_client *client)
585{
586 struct iio_dev *indio_dev = i2c_get_clientdata(client);
587 struct ak8975_data *data = iio_priv(indio_dev);
588
589 iio_device_unregister(indio_dev);
590
591 if (data->eoc_irq)
592 free_irq(data->eoc_irq, data);
593
594 if (gpio_is_valid(data->eoc_gpio))
595 gpio_free(data->eoc_gpio);
596
597 iio_device_free(indio_dev);
598 569
599 return 0; 570 return 0;
600} 571}
@@ -621,7 +592,6 @@ static struct i2c_driver ak8975_driver = {
621 .acpi_match_table = ACPI_PTR(ak_acpi_match), 592 .acpi_match_table = ACPI_PTR(ak_acpi_match),
622 }, 593 },
623 .probe = ak8975_probe, 594 .probe = ak8975_probe,
624 .remove = ak8975_remove,
625 .id_table = ak8975_id, 595 .id_table = ak8975_id,
626}; 596};
627module_i2c_driver(ak8975_driver); 597module_i2c_driver(ak8975_driver);