Commit 6027c077f62f11818a7645151119f8718862d764

Authored by Srinivas Pandruvada
Committed by Jonathan Cameron
1 parent 239670ef48

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>

Showing 2 changed files with 31 additions and 6 deletions Side-by-side Diff

drivers/iio/magnetometer/Kconfig
... ... @@ -11,7 +11,8 @@
11 11 depends on GPIOLIB
12 12 help
13 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 17 To compile this driver as a module, choose M here: the module
17 18 will be called ak8975.
drivers/iio/magnetometer/ak8975.c
... ... @@ -85,8 +85,15 @@
85 85 #define AK8975_MAX_CONVERSION_TIMEOUT 500
86 86 #define AK8975_CONVERSION_DONE_POLL_TIME 10
87 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)
89 90  
  91 +/* Compatible Asahi Kasei Compass parts */
  92 +enum asahi_compass_chipset {
  93 + AK8975,
  94 + AK8963,
  95 +};
  96 +
90 97 /*
91 98 * Per-instance context data for the device.
92 99 */
... ... @@ -101,6 +108,7 @@
101 108 int eoc_irq;
102 109 wait_queue_head_t data_ready_queue;
103 110 unsigned long flags;
  111 + enum asahi_compass_chipset chipset;
104 112 };
105 113  
106 114 static const int ak8975_index_to_reg[] = {
... ... @@ -272,9 +280,21 @@
272 280 * Since ASA doesn't change, we cache the resultant scale factor into the
273 281 * device context in ak8975_setup().
274 282 */
275   - data->raw_to_gauss[0] = RAW_TO_GAUSS(data->asa[0]);
276   - data->raw_to_gauss[1] = RAW_TO_GAUSS(data->asa[1]);
277   - data->raw_to_gauss[2] = RAW_TO_GAUSS(data->asa[2]);
  283 + if (data->chipset == AK8963) {
  284 + /*
  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 299 return 0;
280 300 }
... ... @@ -499,6 +519,9 @@
499 519 data->eoc_gpio = eoc_gpio;
500 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 525 /* Perform some basic start-of-day setup of the device. */
503 526 err = ak8975_setup(client);
504 527 if (err < 0) {
... ... @@ -552,7 +575,8 @@
552 575 }
553 576  
554 577 static const struct i2c_device_id ak8975_id[] = {
555   - {"ak8975", 0},
  578 + {"ak8975", AK8975},
  579 + {"ak8963", AK8963},
556 580 {}
557 581 };
558 582