diff options
author | Daniel Baluta <daniel.baluta@intel.com> | 2014-12-03 08:31:49 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-12-12 08:43:57 -0500 |
commit | b25862c577979659020f3575838d366f480ec3bf (patch) | |
tree | 9f9cd9edf2fe11e874640f86c88b784514a3476c /drivers/iio | |
parent | 20ffac278ebd64ad031149628560f47990910dd7 (diff) |
iio: imu: kmx61: Add acpi support
Signed-off-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/imu/kmx61.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c index 5231d8f3b167..efb2f8b450c1 100644 --- a/drivers/iio/imu/kmx61.c +++ b/drivers/iio/imu/kmx61.c | |||
@@ -13,10 +13,13 @@ | |||
13 | 13 | ||
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/i2c.h> | 15 | #include <linux/i2c.h> |
16 | #include <linux/acpi.h> | ||
17 | #include <linux/gpio/consumer.h> | ||
16 | #include <linux/iio/iio.h> | 18 | #include <linux/iio/iio.h> |
17 | #include <linux/iio/sysfs.h> | 19 | #include <linux/iio/sysfs.h> |
18 | 20 | ||
19 | #define KMX61_DRV_NAME "kmx61" | 21 | #define KMX61_DRV_NAME "kmx61" |
22 | #define KMX61_GPIO_NAME "kmx61_int" | ||
20 | 23 | ||
21 | #define KMX61_REG_WHO_AM_I 0x00 | 24 | #define KMX61_REG_WHO_AM_I 0x00 |
22 | 25 | ||
@@ -573,6 +576,44 @@ static const struct iio_info kmx61_mag_info = { | |||
573 | .attrs = &kmx61_mag_attribute_group, | 576 | .attrs = &kmx61_mag_attribute_group, |
574 | }; | 577 | }; |
575 | 578 | ||
579 | static const char *kmx61_match_acpi_device(struct device *dev) | ||
580 | { | ||
581 | const struct acpi_device_id *id; | ||
582 | |||
583 | id = acpi_match_device(dev->driver->acpi_match_table, dev); | ||
584 | if (!id) | ||
585 | return NULL; | ||
586 | return dev_name(dev); | ||
587 | } | ||
588 | |||
589 | static int kmx61_gpio_probe(struct i2c_client *client, struct kmx61_data *data) | ||
590 | { | ||
591 | struct device *dev; | ||
592 | struct gpio_desc *gpio; | ||
593 | int ret; | ||
594 | |||
595 | if (!client) | ||
596 | return -EINVAL; | ||
597 | |||
598 | dev = &client->dev; | ||
599 | |||
600 | /* data ready gpio interrupt pin */ | ||
601 | gpio = devm_gpiod_get_index(dev, KMX61_GPIO_NAME, 0); | ||
602 | if (IS_ERR(gpio)) { | ||
603 | dev_err(dev, "acpi gpio get index failed\n"); | ||
604 | return PTR_ERR(gpio); | ||
605 | } | ||
606 | |||
607 | ret = gpiod_direction_input(gpio); | ||
608 | if (ret) | ||
609 | return ret; | ||
610 | |||
611 | ret = gpiod_to_irq(gpio); | ||
612 | |||
613 | dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret); | ||
614 | return ret; | ||
615 | } | ||
616 | |||
576 | static struct iio_dev *kmx61_indiodev_setup(struct kmx61_data *data, | 617 | static struct iio_dev *kmx61_indiodev_setup(struct kmx61_data *data, |
577 | const struct iio_info *info, | 618 | const struct iio_info *info, |
578 | const struct iio_chan_spec *chan, | 619 | const struct iio_chan_spec *chan, |
@@ -613,6 +654,13 @@ static int kmx61_probe(struct i2c_client *client, | |||
613 | 654 | ||
614 | mutex_init(&data->lock); | 655 | mutex_init(&data->lock); |
615 | 656 | ||
657 | if (id) | ||
658 | name = id->name; | ||
659 | else if (ACPI_HANDLE(&client->dev)) | ||
660 | name = kmx61_match_acpi_device(&client->dev); | ||
661 | else | ||
662 | return -ENODEV; | ||
663 | |||
616 | data->acc_indio_dev = | 664 | data->acc_indio_dev = |
617 | kmx61_indiodev_setup(data, &kmx61_acc_info, | 665 | kmx61_indiodev_setup(data, &kmx61_acc_info, |
618 | kmx61_acc_channels, | 666 | kmx61_acc_channels, |
@@ -633,6 +681,9 @@ static int kmx61_probe(struct i2c_client *client, | |||
633 | if (ret < 0) | 681 | if (ret < 0) |
634 | return ret; | 682 | return ret; |
635 | 683 | ||
684 | if (client->irq < 0) | ||
685 | client->irq = kmx61_gpio_probe(client, data); | ||
686 | |||
636 | ret = iio_device_register(data->acc_indio_dev); | 687 | ret = iio_device_register(data->acc_indio_dev); |
637 | if (ret < 0) { | 688 | if (ret < 0) { |
638 | dev_err(&client->dev, "Failed to register acc iio device\n"); | 689 | dev_err(&client->dev, "Failed to register acc iio device\n"); |
@@ -668,6 +719,13 @@ static int kmx61_remove(struct i2c_client *client) | |||
668 | return 0; | 719 | return 0; |
669 | } | 720 | } |
670 | 721 | ||
722 | static const struct acpi_device_id kmx61_acpi_match[] = { | ||
723 | {"KMX61021", 0}, | ||
724 | {} | ||
725 | }; | ||
726 | |||
727 | MODULE_DEVICE_TABLE(acpi, kmx61_acpi_match); | ||
728 | |||
671 | static const struct i2c_device_id kmx61_id[] = { | 729 | static const struct i2c_device_id kmx61_id[] = { |
672 | {"kmx611021", 0}, | 730 | {"kmx611021", 0}, |
673 | {} | 731 | {} |
@@ -678,6 +736,7 @@ MODULE_DEVICE_TABLE(i2c, kmx61_id); | |||
678 | static struct i2c_driver kmx61_driver = { | 736 | static struct i2c_driver kmx61_driver = { |
679 | .driver = { | 737 | .driver = { |
680 | .name = KMX61_DRV_NAME, | 738 | .name = KMX61_DRV_NAME, |
739 | .acpi_match_table = ACPI_PTR(kmx61_acpi_match), | ||
681 | }, | 740 | }, |
682 | .probe = kmx61_probe, | 741 | .probe = kmx61_probe, |
683 | .remove = kmx61_remove, | 742 | .remove = kmx61_remove, |