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-22 08:41:37 -0400 |
commit | 6027c077f62f11818a7645151119f8718862d764 (patch) | |
tree | 26e1650162cb045f4806f06d328cbf05d64a608d /drivers/iio | |
parent | 239670ef48dfff9cf07675acdb3bb7deee4853e1 (diff) |
iio: ak8975 : Add AK8963 compatibility mode support
AK8963 and AK8975 use same register definitions, except the range
of X,Y,Z values. Added support of 8963 based on i2c_device_id.
Unfortunately there is no way to detect the type via registers,
both device registers return 0x48 as id of chipset.
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/Kconfig | 3 | ||||
-rw-r--r-- | drivers/iio/magnetometer/ak8975.c | 34 |
2 files changed, 31 insertions, 6 deletions
diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig index d86d226dcd67..05a364c543f8 100644 --- a/drivers/iio/magnetometer/Kconfig +++ b/drivers/iio/magnetometer/Kconfig | |||
@@ -11,7 +11,8 @@ config AK8975 | |||
11 | depends on GPIOLIB | 11 | depends on GPIOLIB |
12 | help | 12 | help |
13 | Say yes here to build support for Asahi Kasei AK8975 3-Axis | 13 | Say yes here to build support for Asahi Kasei AK8975 3-Axis |
14 | Magnetometer. | 14 | Magnetometer. This driver can also support AK8963, if i2c |
15 | device name is identified as ak8963. | ||
15 | 16 | ||
16 | To compile this driver as a module, choose M here: the module | 17 | To compile this driver as a module, choose M here: the module |
17 | will be called ak8975. | 18 | will be called ak8975. |
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index 74866d1efd1b..0f1ca5303139 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c | |||
@@ -85,7 +85,14 @@ | |||
85 | #define AK8975_MAX_CONVERSION_TIMEOUT 500 | 85 | #define AK8975_MAX_CONVERSION_TIMEOUT 500 |
86 | #define AK8975_CONVERSION_DONE_POLL_TIME 10 | 86 | #define AK8975_CONVERSION_DONE_POLL_TIME 10 |
87 | #define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000) | 87 | #define AK8975_DATA_READY_TIMEOUT ((100*HZ)/1000) |
88 | #define RAW_TO_GAUSS(asa) ((((asa) + 128) * 3000) / 256) | 88 | #define RAW_TO_GAUSS_8975(asa) ((((asa) + 128) * 3000) / 256) |
89 | #define RAW_TO_GAUSS_8963(asa) ((((asa) + 128) * 6000) / 256) | ||
90 | |||
91 | /* Compatible Asahi Kasei Compass parts */ | ||
92 | enum asahi_compass_chipset { | ||
93 | AK8975, | ||
94 | AK8963, | ||
95 | }; | ||
89 | 96 | ||
90 | /* | 97 | /* |
91 | * Per-instance context data for the device. | 98 | * Per-instance context data for the device. |
@@ -101,6 +108,7 @@ struct ak8975_data { | |||
101 | int eoc_irq; | 108 | int eoc_irq; |
102 | wait_queue_head_t data_ready_queue; | 109 | wait_queue_head_t data_ready_queue; |
103 | unsigned long flags; | 110 | unsigned long flags; |
111 | enum asahi_compass_chipset chipset; | ||
104 | }; | 112 | }; |
105 | 113 | ||
106 | static const int ak8975_index_to_reg[] = { | 114 | static const int ak8975_index_to_reg[] = { |
@@ -272,9 +280,21 @@ static int ak8975_setup(struct i2c_client *client) | |||
272 | * Since ASA doesn't change, we cache the resultant scale factor into the | 280 | * Since ASA doesn't change, we cache the resultant scale factor into the |
273 | * device context in ak8975_setup(). | 281 | * device context in ak8975_setup(). |
274 | */ | 282 | */ |
275 | data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]); | 283 | if (data->chipset == AK8963) { |
276 | data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]); | 284 | /* |
277 | data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]); | 285 | * H range is +-8190 and magnetometer range is +-4912. |
286 | * So HuT using the above explanation for 8975, | ||
287 | * 4912/8190 = ~ 6/10. | ||
288 | * So the Hadj should use 6/10 instead of 3/10. | ||
289 | */ | ||
290 | data->raw_to_gauss[0] = RAW_TO_GAUSS_8963(data->asa[0]); | ||
291 | data->raw_to_gauss[1] = RAW_TO_GAUSS_8963(data->asa[1]); | ||
292 | data->raw_to_gauss[2] = RAW_TO_GAUSS_8963(data->asa[2]); | ||
293 | } else { | ||
294 | data->raw_to_gauss[0] = RAW_TO_GAUSS_8975(data->asa[0]); | ||
295 | data->raw_to_gauss[1] = RAW_TO_GAUSS_8975(data->asa[1]); | ||
296 | data->raw_to_gauss[2] = RAW_TO_GAUSS_8975(data->asa[2]); | ||
297 | } | ||
278 | 298 | ||
279 | return 0; | 299 | return 0; |
280 | } | 300 | } |
@@ -499,6 +519,9 @@ static int ak8975_probe(struct i2c_client *client, | |||
499 | data->eoc_gpio = eoc_gpio; | 519 | data->eoc_gpio = eoc_gpio; |
500 | data->eoc_irq = 0; | 520 | data->eoc_irq = 0; |
501 | 521 | ||
522 | data->chipset = (enum asahi_compass_chipset)(id->driver_data); | ||
523 | dev_dbg(&client->dev, "Asahi compass chip %s\n", id->name); | ||
524 | |||
502 | /* Perform some basic start-of-day setup of the device. */ | 525 | /* Perform some basic start-of-day setup of the device. */ |
503 | err = ak8975_setup(client); | 526 | err = ak8975_setup(client); |
504 | if (err < 0) { | 527 | if (err < 0) { |
@@ -552,7 +575,8 @@ static int ak8975_remove(struct i2c_client *client) | |||
552 | } | 575 | } |
553 | 576 | ||
554 | static const struct i2c_device_id ak8975_id[] = { | 577 | static const struct i2c_device_id ak8975_id[] = { |
555 | {"ak8975", 0}, | 578 | {"ak8975", AK8975}, |
579 | {"ak8963", AK8963}, | ||
556 | {} | 580 | {} |
557 | }; | 581 | }; |
558 | 582 | ||