diff options
author | Beomho Seo <beomho.seo@samsung.com> | 2014-06-23 08:34:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-06-29 07:03:45 -0400 |
commit | a845a3aab8a925f675ca8520435b1218b6198a26 (patch) | |
tree | ec1bbd19e559d1772e3c1eecb14ca1ff952a6e83 /drivers/iio/magnetometer | |
parent | cfcd185e708f7a3543b1dc585dfb1a849c019e14 (diff) |
iio: magnetometer: ak8975: Use devm_* APIs
This patch use devm_* APIs make driver simpler.
Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/magnetometer')
-rw-r--r-- | drivers/iio/magnetometer/ak8975.c | 58 |
1 files changed, 14 insertions, 44 deletions
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 09ea5c481f4c..a29592cae301 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) { |
@@ -520,21 +520,21 @@ static int ak8975_probe(struct i2c_client *client, | |||
520 | /* We may not have a GPIO based IRQ to scan, that is fine, we will | 520 | /* We may not have a GPIO based IRQ to scan, that is fine, we will |
521 | poll if so */ | 521 | poll if so */ |
522 | if (gpio_is_valid(eoc_gpio)) { | 522 | if (gpio_is_valid(eoc_gpio)) { |
523 | err = gpio_request_one(eoc_gpio, GPIOF_IN, "ak_8975"); | 523 | err = devm_gpio_request_one(&client->dev, eoc_gpio, |
524 | GPIOF_IN, "ak_8975"); | ||
524 | if (err < 0) { | 525 | if (err < 0) { |
525 | dev_err(&client->dev, | 526 | dev_err(&client->dev, |
526 | "failed to request GPIO %d, error %d\n", | 527 | "failed to request GPIO %d, error %d\n", |
527 | eoc_gpio, err); | 528 | eoc_gpio, err); |
528 | goto exit; | 529 | return err; |
529 | } | 530 | } |
530 | } | 531 | } |
531 | 532 | ||
532 | /* Register with IIO */ | 533 | /* Register with IIO */ |
533 | indio_dev = iio_device_alloc(sizeof(*data)); | 534 | indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); |
534 | if (indio_dev == NULL) { | 535 | if (indio_dev == NULL) |
535 | err = -ENOMEM; | 536 | return -ENOMEM; |
536 | goto exit_gpio; | 537 | |
537 | } | ||
538 | data = iio_priv(indio_dev); | 538 | data = iio_priv(indio_dev); |
539 | i2c_set_clientdata(client, indio_dev); | 539 | i2c_set_clientdata(client, indio_dev); |
540 | 540 | ||
@@ -549,17 +549,16 @@ static int ak8975_probe(struct i2c_client *client, | |||
549 | name = (char *) id->name; | 549 | name = (char *) id->name; |
550 | } else if (ACPI_HANDLE(&client->dev)) | 550 | } else if (ACPI_HANDLE(&client->dev)) |
551 | name = ak8975_match_acpi_device(&client->dev, &data->chipset); | 551 | name = ak8975_match_acpi_device(&client->dev, &data->chipset); |
552 | else { | 552 | else |
553 | err = -ENOSYS; | 553 | return -ENOSYS; |
554 | goto exit_free_iio; | 554 | |
555 | } | ||
556 | dev_dbg(&client->dev, "Asahi compass chip %s\n", name); | 555 | dev_dbg(&client->dev, "Asahi compass chip %s\n", name); |
557 | 556 | ||
558 | /* Perform some basic start-of-day setup of the device. */ | 557 | /* Perform some basic start-of-day setup of the device. */ |
559 | err = ak8975_setup(client); | 558 | err = ak8975_setup(client); |
560 | if (err < 0) { | 559 | if (err < 0) { |
561 | dev_err(&client->dev, "AK8975 initialization fails\n"); | 560 | dev_err(&client->dev, "AK8975 initialization fails\n"); |
562 | goto exit_free_iio; | 561 | return err; |
563 | } | 562 | } |
564 | 563 | ||
565 | data->client = client; | 564 | data->client = client; |
@@ -571,37 +570,9 @@ static int ak8975_probe(struct i2c_client *client, | |||
571 | indio_dev->info = &ak8975_info; | 570 | indio_dev->info = &ak8975_info; |
572 | indio_dev->modes = INDIO_DIRECT_MODE; | 571 | indio_dev->modes = INDIO_DIRECT_MODE; |
573 | indio_dev->name = name; | 572 | indio_dev->name = name; |
574 | err = iio_device_register(indio_dev); | 573 | err = devm_iio_device_register(&client->dev, indio_dev); |
575 | if (err < 0) | 574 | if (err < 0) |
576 | goto exit_free_iio; | 575 | return err; |
577 | |||
578 | return 0; | ||
579 | |||
580 | exit_free_iio: | ||
581 | iio_device_free(indio_dev); | ||
582 | if (data->eoc_irq) | ||
583 | free_irq(data->eoc_irq, data); | ||
584 | exit_gpio: | ||
585 | if (gpio_is_valid(eoc_gpio)) | ||
586 | gpio_free(eoc_gpio); | ||
587 | exit: | ||
588 | return err; | ||
589 | } | ||
590 | |||
591 | static int ak8975_remove(struct i2c_client *client) | ||
592 | { | ||
593 | struct iio_dev *indio_dev = i2c_get_clientdata(client); | ||
594 | struct ak8975_data *data = iio_priv(indio_dev); | ||
595 | |||
596 | iio_device_unregister(indio_dev); | ||
597 | |||
598 | if (data->eoc_irq) | ||
599 | free_irq(data->eoc_irq, data); | ||
600 | |||
601 | if (gpio_is_valid(data->eoc_gpio)) | ||
602 | gpio_free(data->eoc_gpio); | ||
603 | |||
604 | iio_device_free(indio_dev); | ||
605 | 576 | ||
606 | return 0; | 577 | return 0; |
607 | } | 578 | } |
@@ -628,7 +599,6 @@ static struct i2c_driver ak8975_driver = { | |||
628 | .acpi_match_table = ACPI_PTR(ak_acpi_match), | 599 | .acpi_match_table = ACPI_PTR(ak_acpi_match), |
629 | }, | 600 | }, |
630 | .probe = ak8975_probe, | 601 | .probe = ak8975_probe, |
631 | .remove = ak8975_remove, | ||
632 | .id_table = ak8975_id, | 602 | .id_table = ak8975_id, |
633 | }; | 603 | }; |
634 | module_i2c_driver(ak8975_driver); | 604 | module_i2c_driver(ak8975_driver); |