diff options
author | Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> | 2014-03-19 12:56:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-03-29 06:40:39 -0400 |
commit | d913971ecaf31d7d5a6836224b669e1972469445 (patch) | |
tree | 41510ab5473c2a8313c3468f9e0b5869d21f3666 /drivers/iio | |
parent | 6027c077f62f11818a7645151119f8718862d764 (diff) |
iio: ak8975: Added ACPI enumeration
Added capability so that this device can be enumerated via ACPI.
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r-- | drivers/iio/magnetometer/ak8975.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 0f1ca5303139..f5c1d41bf39f 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/bitops.h> | 31 | #include <linux/bitops.h> |
32 | #include <linux/gpio.h> | 32 | #include <linux/gpio.h> |
33 | #include <linux/of_gpio.h> | 33 | #include <linux/of_gpio.h> |
34 | #include <linux/acpi.h> | ||
34 | 35 | ||
35 | #include <linux/iio/iio.h> | 36 | #include <linux/iio/iio.h> |
36 | #include <linux/iio/sysfs.h> | 37 | #include <linux/iio/sysfs.h> |
@@ -475,6 +476,27 @@ static const struct iio_info ak8975_info = { | |||
475 | .driver_module = THIS_MODULE, | 476 | .driver_module = THIS_MODULE, |
476 | }; | 477 | }; |
477 | 478 | ||
479 | static const struct acpi_device_id ak_acpi_match[] = { | ||
480 | {"AK8975", AK8975}, | ||
481 | {"AK8963", AK8963}, | ||
482 | {"INVN6500", AK8963}, | ||
483 | { }, | ||
484 | }; | ||
485 | MODULE_DEVICE_TABLE(acpi, ak_acpi_match); | ||
486 | |||
487 | static char *ak8975_match_acpi_device(struct device *dev, | ||
488 | enum asahi_compass_chipset *chipset) | ||
489 | { | ||
490 | const struct acpi_device_id *id; | ||
491 | |||
492 | id = acpi_match_device(dev->driver->acpi_match_table, dev); | ||
493 | if (!id) | ||
494 | return NULL; | ||
495 | *chipset = (int)id->driver_data; | ||
496 | |||
497 | return (char *)dev_name(dev); | ||
498 | } | ||
499 | |||
478 | static int ak8975_probe(struct i2c_client *client, | 500 | static int ak8975_probe(struct i2c_client *client, |
479 | const struct i2c_device_id *id) | 501 | const struct i2c_device_id *id) |
480 | { | 502 | { |
@@ -482,6 +504,7 @@ static int ak8975_probe(struct i2c_client *client, | |||
482 | struct iio_dev *indio_dev; | 504 | struct iio_dev *indio_dev; |
483 | int eoc_gpio; | 505 | int eoc_gpio; |
484 | int err; | 506 | int err; |
507 | char *name = NULL; | ||
485 | 508 | ||
486 | /* Grab and set up the supplied GPIO. */ | 509 | /* Grab and set up the supplied GPIO. */ |
487 | if (client->dev.platform_data) | 510 | if (client->dev.platform_data) |
@@ -519,8 +542,18 @@ static int ak8975_probe(struct i2c_client *client, | |||
519 | data->eoc_gpio = eoc_gpio; | 542 | data->eoc_gpio = eoc_gpio; |
520 | data->eoc_irq = 0; | 543 | data->eoc_irq = 0; |
521 | 544 | ||
522 | data->chipset = (enum asahi_compass_chipset)(id->driver_data); | 545 | /* id will be NULL when enumerated via ACPI */ |
523 | dev_dbg(&client->dev, "Asahi compass chip %s\n", id->name); | 546 | if (id) { |
547 | data->chipset = | ||
548 | (enum asahi_compass_chipset)(id->driver_data); | ||
549 | name = (char *) id->name; | ||
550 | } else if (ACPI_HANDLE(&client->dev)) | ||
551 | name = ak8975_match_acpi_device(&client->dev, &data->chipset); | ||
552 | else { | ||
553 | err = -ENOSYS; | ||
554 | goto exit_free_iio; | ||
555 | } | ||
556 | dev_dbg(&client->dev, "Asahi compass chip %s\n", name); | ||
524 | 557 | ||
525 | /* Perform some basic start-of-day setup of the device. */ | 558 | /* Perform some basic start-of-day setup of the device. */ |
526 | err = ak8975_setup(client); | 559 | err = ak8975_setup(client); |
@@ -538,7 +571,7 @@ static int ak8975_probe(struct i2c_client *client, | |||
538 | indio_dev->info = &ak8975_info; | 571 | indio_dev->info = &ak8975_info; |
539 | indio_dev->name = id->name; | 572 | indio_dev->name = id->name; |
540 | indio_dev->modes = INDIO_DIRECT_MODE; | 573 | indio_dev->modes = INDIO_DIRECT_MODE; |
541 | 574 | indio_dev->name = name; | |
542 | err = iio_device_register(indio_dev); | 575 | err = iio_device_register(indio_dev); |
543 | if (err < 0) | 576 | if (err < 0) |
544 | goto exit_free_iio; | 577 | goto exit_free_iio; |
@@ -593,6 +626,7 @@ static struct i2c_driver ak8975_driver = { | |||
593 | .driver = { | 626 | .driver = { |
594 | .name = "ak8975", | 627 | .name = "ak8975", |
595 | .of_match_table = ak8975_of_match, | 628 | .of_match_table = ak8975_of_match, |
629 | .acpi_match_table = ACPI_PTR(ak_acpi_match), | ||
596 | }, | 630 | }, |
597 | .probe = ak8975_probe, | 631 | .probe = ak8975_probe, |
598 | .remove = ak8975_remove, | 632 | .remove = ak8975_remove, |