blob: 9c5338396d7eb856ba33e5c8f44393ec6c6db43a [file] [log] [blame]
Andrew Chew3285aae2010-09-08 22:02:17 -07001/*
2 * A sensor driver for the magnetometer AK8975.
3 *
4 * Magnetic compass sensor driver for monitoring magnetic flux information.
5 *
6 * Copyright (c) 2010, NVIDIA Corporation.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/slab.h>
26#include <linux/i2c.h>
27#include <linux/err.h>
28#include <linux/mutex.h>
29#include <linux/delay.h>
30
31#include <linux/gpio.h>
32
33#include "../iio.h"
Jonathan Cameron9dd1cb32011-08-30 12:41:15 +010034#include "../sysfs.h"
Andrew Chew3285aae2010-09-08 22:02:17 -070035/*
36 * Register definitions, as well as various shifts and masks to get at the
37 * individual fields of the registers.
38 */
39#define AK8975_REG_WIA 0x00
40#define AK8975_DEVICE_ID 0x48
41
42#define AK8975_REG_INFO 0x01
43
44#define AK8975_REG_ST1 0x02
45#define AK8975_REG_ST1_DRDY_SHIFT 0
46#define AK8975_REG_ST1_DRDY_MASK (1 << AK8975_REG_ST1_DRDY_SHIFT)
47
48#define AK8975_REG_HXL 0x03
49#define AK8975_REG_HXH 0x04
50#define AK8975_REG_HYL 0x05
51#define AK8975_REG_HYH 0x06
52#define AK8975_REG_HZL 0x07
53#define AK8975_REG_HZH 0x08
54#define AK8975_REG_ST2 0x09
55#define AK8975_REG_ST2_DERR_SHIFT 2
56#define AK8975_REG_ST2_DERR_MASK (1 << AK8975_REG_ST2_DERR_SHIFT)
57
58#define AK8975_REG_ST2_HOFL_SHIFT 3
59#define AK8975_REG_ST2_HOFL_MASK (1 << AK8975_REG_ST2_HOFL_SHIFT)
60
61#define AK8975_REG_CNTL 0x0A
62#define AK8975_REG_CNTL_MODE_SHIFT 0
63#define AK8975_REG_CNTL_MODE_MASK (0xF << AK8975_REG_CNTL_MODE_SHIFT)
64#define AK8975_REG_CNTL_MODE_POWER_DOWN 0
65#define AK8975_REG_CNTL_MODE_ONCE 1
66#define AK8975_REG_CNTL_MODE_SELF_TEST 8
67#define AK8975_REG_CNTL_MODE_FUSE_ROM 0xF
68
69#define AK8975_REG_RSVC 0x0B
70#define AK8975_REG_ASTC 0x0C
71#define AK8975_REG_TS1 0x0D
72#define AK8975_REG_TS2 0x0E
73#define AK8975_REG_I2CDIS 0x0F
74#define AK8975_REG_ASAX 0x10
75#define AK8975_REG_ASAY 0x11
76#define AK8975_REG_ASAZ 0x12
77
78#define AK8975_MAX_REGS AK8975_REG_ASAZ
79
80/*
81 * Miscellaneous values.
82 */
83#define AK8975_MAX_CONVERSION_TIMEOUT 500
84#define AK8975_CONVERSION_DONE_POLL_TIME 10
85
86/*
87 * Per-instance context data for the device.
88 */
89struct ak8975_data {
90 struct i2c_client *client;
Andrew Chew3285aae2010-09-08 22:02:17 -070091 struct attribute_group attrs;
92 struct mutex lock;
93 u8 asa[3];
94 long raw_to_gauss[3];
Jonathan Cameron694e1b52011-08-12 17:48:03 +010095 bool mode;
Andrew Chew3285aae2010-09-08 22:02:17 -070096 u8 reg_cache[AK8975_MAX_REGS];
97 int eoc_gpio;
98 int eoc_irq;
99};
100
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100101static const int ak8975_index_to_reg[] = {
102 AK8975_REG_HXL, AK8975_REG_HYL, AK8975_REG_HZL,
103};
104
Andrew Chew3285aae2010-09-08 22:02:17 -0700105/*
106 * Helper function to write to the I2C device's registers.
107 */
108static int ak8975_write_data(struct i2c_client *client,
109 u8 reg, u8 val, u8 mask, u8 shift)
110{
Andrew Chew3285aae2010-09-08 22:02:17 -0700111 struct ak8975_data *data = i2c_get_clientdata(client);
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100112 u8 regval;
113 int ret;
Andrew Chew3285aae2010-09-08 22:02:17 -0700114
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100115 regval = (data->reg_cache[reg] & ~mask) | (val << shift);
116 ret = i2c_smbus_write_byte_data(client, reg, regval);
Andrew Chew3285aae2010-09-08 22:02:17 -0700117 if (ret < 0) {
118 dev_err(&client->dev, "Write to device fails status %x\n", ret);
119 return ret;
120 }
121 data->reg_cache[reg] = regval;
122
123 return 0;
124}
125
126/*
127 * Helper function to read a contiguous set of the I2C device's registers.
128 */
129static int ak8975_read_data(struct i2c_client *client,
130 u8 reg, u8 length, u8 *buffer)
131{
Andrew Chew3285aae2010-09-08 22:02:17 -0700132 int ret;
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100133 struct i2c_msg msg[2] = {
134 {
135 .addr = client->addr,
136 .flags = I2C_M_NOSTART,
137 .len = 1,
138 .buf = &reg,
139 }, {
140 .addr = client->addr,
141 .flags = I2C_M_RD,
142 .len = length,
143 .buf = buffer,
144 }
145 };
Andrew Chew3285aae2010-09-08 22:02:17 -0700146
147 ret = i2c_transfer(client->adapter, msg, 2);
148 if (ret < 0) {
149 dev_err(&client->dev, "Read from device fails\n");
150 return ret;
151 }
152
153 return 0;
154}
155
156/*
157 * Perform some start-of-day setup, including reading the asa calibration
158 * values and caching them.
159 */
160static int ak8975_setup(struct i2c_client *client)
161{
162 struct ak8975_data *data = i2c_get_clientdata(client);
163 u8 device_id;
164 int ret;
165
166 /* Confirm that the device we're talking to is really an AK8975. */
167 ret = ak8975_read_data(client, AK8975_REG_WIA, 1, &device_id);
168 if (ret < 0) {
169 dev_err(&client->dev, "Error reading WIA\n");
170 return ret;
171 }
172 if (device_id != AK8975_DEVICE_ID) {
173 dev_err(&client->dev, "Device ak8975 not found\n");
174 return -ENODEV;
175 }
176
177 /* Write the fused rom access mode. */
178 ret = ak8975_write_data(client,
179 AK8975_REG_CNTL,
180 AK8975_REG_CNTL_MODE_FUSE_ROM,
181 AK8975_REG_CNTL_MODE_MASK,
182 AK8975_REG_CNTL_MODE_SHIFT);
183 if (ret < 0) {
184 dev_err(&client->dev, "Error in setting fuse access mode\n");
185 return ret;
186 }
187
188 /* Get asa data and store in the device data. */
189 ret = ak8975_read_data(client, AK8975_REG_ASAX, 3, data->asa);
190 if (ret < 0) {
191 dev_err(&client->dev, "Not able to read asa data\n");
192 return ret;
193 }
194
Andrew Chew3285aae2010-09-08 22:02:17 -0700195/*
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100196 * Precalculate scale factor (in Gauss units) for each axis and
197 * store in the device data.
Andrew Chew3285aae2010-09-08 22:02:17 -0700198 *
199 * This scale factor is axis-dependent, and is derived from 3 calibration
200 * factors ASA(x), ASA(y), and ASA(z).
201 *
202 * These ASA values are read from the sensor device at start of day, and
203 * cached in the device context struct.
204 *
205 * Adjusting the flux value with the sensitivity adjustment value should be
206 * done via the following formula:
207 *
208 * Hadj = H * ( ( ( (ASA-128)*0.5 ) / 128 ) + 1 )
209 *
210 * where H is the raw value, ASA is the sensitivity adjustment, and Hadj
211 * is the resultant adjusted value.
212 *
213 * We reduce the formula to:
214 *
215 * Hadj = H * (ASA + 128) / 256
216 *
217 * H is in the range of -4096 to 4095. The magnetometer has a range of
218 * +-1229uT. To go from the raw value to uT is:
219 *
220 * HuT = H * 1229/4096, or roughly, 3/10.
221 *
222 * Since 1uT = 100 gauss, our final scale factor becomes:
223 *
224 * Hadj = H * ((ASA + 128) / 256) * 3/10 * 100
225 * Hadj = H * ((ASA + 128) * 30 / 256
226 *
227 * Since ASA doesn't change, we cache the resultant scale factor into the
228 * device context in ak8975_setup().
229 */
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100230 data->raw_to_gauss[0] = ((data->asa[0] + 128) * 30) >> 8;
231 data->raw_to_gauss[1] = ((data->asa[1] + 128) * 30) >> 8;
232 data->raw_to_gauss[2] = ((data->asa[2] + 128) * 30) >> 8;
233
234 return 0;
235}
236
237/*
238 * Shows the device's mode. 0 = off, 1 = on.
239 */
240static ssize_t show_mode(struct device *dev, struct device_attribute *devattr,
241 char *buf)
Andrew Chew3285aae2010-09-08 22:02:17 -0700242{
243 struct iio_dev *indio_dev = dev_get_drvdata(dev);
Jonathan Cameron338473c2011-06-27 13:07:54 +0100244 struct ak8975_data *data = iio_priv(indio_dev);
Andrew Chew3285aae2010-09-08 22:02:17 -0700245
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100246 return sprintf(buf, "%u\n", data->mode);
247}
248
249/*
250 * Sets the device's mode. 0 = off, 1 = on. The device's mode must be on
251 * for the magn raw attributes to be available.
252 */
253static ssize_t store_mode(struct device *dev, struct device_attribute *devattr,
254 const char *buf, size_t count)
255{
256 struct iio_dev *indio_dev = dev_get_drvdata(dev);
257 struct ak8975_data *data = iio_priv(indio_dev);
258 struct i2c_client *client = data->client;
259 bool value;
260 int ret;
261
262 /* Convert mode string and do some basic sanity checking on it.
263 only 0 or 1 are valid. */
264 ret = strtobool(buf, &value);
265 if (ret < 0)
266 return ret;
267
268 mutex_lock(&data->lock);
269
270 /* Write the mode to the device. */
271 if (data->mode != value) {
272 ret = ak8975_write_data(client,
273 AK8975_REG_CNTL,
274 (u8)value,
275 AK8975_REG_CNTL_MODE_MASK,
276 AK8975_REG_CNTL_MODE_SHIFT);
277
278 if (ret < 0) {
279 dev_err(&client->dev, "Error in setting mode\n");
280 mutex_unlock(&data->lock);
281 return ret;
282 }
283 data->mode = value;
284 }
285
286 mutex_unlock(&data->lock);
287
288 return count;
Andrew Chew3285aae2010-09-08 22:02:17 -0700289}
290
Alan Cox01fbb472011-04-06 13:31:40 +0100291static int wait_conversion_complete_gpio(struct ak8975_data *data)
292{
293 struct i2c_client *client = data->client;
294 u8 read_status;
295 u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT;
296 int ret;
297
298 /* Wait for the conversion to complete. */
299 while (timeout_ms) {
300 msleep(AK8975_CONVERSION_DONE_POLL_TIME);
301 if (gpio_get_value(data->eoc_gpio))
302 break;
303 timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
304 }
305 if (!timeout_ms) {
306 dev_err(&client->dev, "Conversion timeout happened\n");
307 return -EINVAL;
308 }
309
310 ret = ak8975_read_data(client, AK8975_REG_ST1, 1, &read_status);
311 if (ret < 0) {
312 dev_err(&client->dev, "Error in reading ST1\n");
313 return ret;
314 }
315 return read_status;
316}
317
318static int wait_conversion_complete_polled(struct ak8975_data *data)
319{
320 struct i2c_client *client = data->client;
321 u8 read_status;
322 u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT;
323 int ret;
324
325 /* Wait for the conversion to complete. */
326 while (timeout_ms) {
327 msleep(AK8975_CONVERSION_DONE_POLL_TIME);
328 ret = ak8975_read_data(client, AK8975_REG_ST1, 1, &read_status);
329 if (ret < 0) {
330 dev_err(&client->dev, "Error in reading ST1\n");
331 return ret;
332 }
333 if (read_status)
334 break;
335 timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME;
336 }
337 if (!timeout_ms) {
338 dev_err(&client->dev, "Conversion timeout happened\n");
339 return -EINVAL;
340 }
341 return read_status;
342}
343
Andrew Chew3285aae2010-09-08 22:02:17 -0700344/*
345 * Emits the raw flux value for the x, y, or z axis.
346 */
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100347static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
Andrew Chew3285aae2010-09-08 22:02:17 -0700348{
Jonathan Cameron338473c2011-06-27 13:07:54 +0100349 struct ak8975_data *data = iio_priv(indio_dev);
Andrew Chew3285aae2010-09-08 22:02:17 -0700350 struct i2c_client *client = data->client;
Andrew Chew3285aae2010-09-08 22:02:17 -0700351 u16 meas_reg;
352 s16 raw;
353 u8 read_status;
354 int ret;
355
356 mutex_lock(&data->lock);
357
358 if (data->mode == 0) {
359 dev_err(&client->dev, "Operating mode is in power down mode\n");
360 ret = -EBUSY;
361 goto exit;
362 }
363
364 /* Set up the device for taking a sample. */
365 ret = ak8975_write_data(client,
366 AK8975_REG_CNTL,
367 AK8975_REG_CNTL_MODE_ONCE,
368 AK8975_REG_CNTL_MODE_MASK,
369 AK8975_REG_CNTL_MODE_SHIFT);
370 if (ret < 0) {
371 dev_err(&client->dev, "Error in setting operating mode\n");
372 goto exit;
373 }
374
375 /* Wait for the conversion to complete. */
Stephen Warren7c6c9362011-09-21 11:16:00 +0100376 if (gpio_is_valid(data->eoc_gpio))
Alan Cox01fbb472011-04-06 13:31:40 +0100377 ret = wait_conversion_complete_gpio(data);
378 else
379 ret = wait_conversion_complete_polled(data);
380 if (ret < 0)
Andrew Chew3285aae2010-09-08 22:02:17 -0700381 goto exit;
Andrew Chew3285aae2010-09-08 22:02:17 -0700382
Alan Cox01fbb472011-04-06 13:31:40 +0100383 read_status = ret;
Andrew Chew3285aae2010-09-08 22:02:17 -0700384
385 if (read_status & AK8975_REG_ST1_DRDY_MASK) {
386 ret = ak8975_read_data(client, AK8975_REG_ST2, 1, &read_status);
387 if (ret < 0) {
388 dev_err(&client->dev, "Error in reading ST2\n");
389 goto exit;
390 }
391 if (read_status & (AK8975_REG_ST2_DERR_MASK |
392 AK8975_REG_ST2_HOFL_MASK)) {
393 dev_err(&client->dev, "ST2 status error 0x%x\n",
394 read_status);
395 ret = -EINVAL;
396 goto exit;
397 }
398 }
399
400 /* Read the flux value from the appropriate register
401 (the register is specified in the iio device attributes). */
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100402 ret = ak8975_read_data(client, ak8975_index_to_reg[index],
403 2, (u8 *)&meas_reg);
Andrew Chew3285aae2010-09-08 22:02:17 -0700404 if (ret < 0) {
405 dev_err(&client->dev, "Read axis data fails\n");
406 goto exit;
407 }
408
409 mutex_unlock(&data->lock);
410
411 /* Endian conversion of the measured values. */
412 raw = (s16) (le16_to_cpu(meas_reg));
413
414 /* Clamp to valid range. */
415 raw = clamp_t(s16, raw, -4096, 4095);
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100416 *val = raw;
417 return IIO_VAL_INT;
Andrew Chew3285aae2010-09-08 22:02:17 -0700418
419exit:
420 mutex_unlock(&data->lock);
421 return ret;
422}
423
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100424static int ak8975_read_raw(struct iio_dev *indio_dev,
425 struct iio_chan_spec const *chan,
426 int *val, int *val2,
427 long mask)
428{
429 struct ak8975_data *data = iio_priv(indio_dev);
430
431 switch (mask) {
432 case 0:
433 return ak8975_read_axis(indio_dev, chan->address, val);
434 case (1 << IIO_CHAN_INFO_SCALE_SEPARATE):
435 *val = data->raw_to_gauss[chan->address];
436 return IIO_VAL_INT;
437 }
438 return -EINVAL;
439}
440
441#define AK8975_CHANNEL(axis, index) \
442 { \
443 .type = IIO_MAGN, \
444 .modified = 1, \
445 .channel2 = IIO_MOD_##axis, \
446 .info_mask = (1 << IIO_CHAN_INFO_SCALE_SEPARATE), \
447 .address = index, \
448 }
449
450static const struct iio_chan_spec ak8975_channels[] = {
451 AK8975_CHANNEL(X, 0), AK8975_CHANNEL(Y, 1), AK8975_CHANNEL(Z, 2),
452};
453
Andrew Chew3285aae2010-09-08 22:02:17 -0700454static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, show_mode, store_mode, 0);
Andrew Chew3285aae2010-09-08 22:02:17 -0700455
456static struct attribute *ak8975_attr[] = {
457 &iio_dev_attr_mode.dev_attr.attr,
Andrew Chew3285aae2010-09-08 22:02:17 -0700458 NULL
459};
460
461static struct attribute_group ak8975_attr_group = {
462 .attrs = ak8975_attr,
463};
464
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100465static const struct iio_info ak8975_info = {
466 .attrs = &ak8975_attr_group,
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100467 .read_raw = &ak8975_read_raw,
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100468 .driver_module = THIS_MODULE,
469};
470
Andrew Chew3285aae2010-09-08 22:02:17 -0700471static int ak8975_probe(struct i2c_client *client,
472 const struct i2c_device_id *id)
473{
474 struct ak8975_data *data;
Jonathan Cameron338473c2011-06-27 13:07:54 +0100475 struct iio_dev *indio_dev;
476 int eoc_gpio;
Andrew Chew3285aae2010-09-08 22:02:17 -0700477 int err;
478
Andrew Chew3285aae2010-09-08 22:02:17 -0700479 /* Grab and set up the supplied GPIO. */
Jonathan Cameronf6d838d2011-09-21 11:15:59 +0100480 if (client->dev.platform_data == NULL)
481 eoc_gpio = -1;
482 else
483 eoc_gpio = *(int *)(client->dev.platform_data);
Andrew Chew3285aae2010-09-08 22:02:17 -0700484
Alan Cox01fbb472011-04-06 13:31:40 +0100485 /* We may not have a GPIO based IRQ to scan, that is fine, we will
486 poll if so */
Stephen Warren7c6c9362011-09-21 11:16:00 +0100487 if (gpio_is_valid(eoc_gpio)) {
Jonathan Cameron338473c2011-06-27 13:07:54 +0100488 err = gpio_request(eoc_gpio, "ak_8975");
Alan Cox01fbb472011-04-06 13:31:40 +0100489 if (err < 0) {
490 dev_err(&client->dev,
491 "failed to request GPIO %d, error %d\n",
Jonathan Cameron338473c2011-06-27 13:07:54 +0100492 eoc_gpio, err);
493 goto exit;
Alan Cox01fbb472011-04-06 13:31:40 +0100494 }
Andrew Chew3285aae2010-09-08 22:02:17 -0700495
Jonathan Cameron338473c2011-06-27 13:07:54 +0100496 err = gpio_direction_input(eoc_gpio);
Alan Cox01fbb472011-04-06 13:31:40 +0100497 if (err < 0) {
498 dev_err(&client->dev,
499 "Failed to configure input direction for GPIO %d, error %d\n",
Jonathan Cameron338473c2011-06-27 13:07:54 +0100500 eoc_gpio, err);
Alan Cox01fbb472011-04-06 13:31:40 +0100501 goto exit_gpio;
502 }
Stephen Warren7c6c9362011-09-21 11:16:00 +0100503 }
Andrew Chew3285aae2010-09-08 22:02:17 -0700504
Jonathan Cameron338473c2011-06-27 13:07:54 +0100505 /* Register with IIO */
506 indio_dev = iio_allocate_device(sizeof(*data));
507 if (indio_dev == NULL) {
508 err = -ENOMEM;
509 goto exit_gpio;
510 }
511 data = iio_priv(indio_dev);
Andrew Chew3285aae2010-09-08 22:02:17 -0700512 /* Perform some basic start-of-day setup of the device. */
513 err = ak8975_setup(client);
514 if (err < 0) {
515 dev_err(&client->dev, "AK8975 initialization fails\n");
516 goto exit_gpio;
517 }
518
Jonathan Cameron338473c2011-06-27 13:07:54 +0100519 i2c_set_clientdata(client, indio_dev);
520 data->client = client;
521 mutex_init(&data->lock);
522 data->eoc_irq = client->irq;
523 data->eoc_gpio = eoc_gpio;
524 indio_dev->dev.parent = &client->dev;
Jonathan Cameron694e1b52011-08-12 17:48:03 +0100525 indio_dev->channels = ak8975_channels;
526 indio_dev->num_channels = ARRAY_SIZE(ak8975_channels);
Jonathan Cameron338473c2011-06-27 13:07:54 +0100527 indio_dev->info = &ak8975_info;
528 indio_dev->modes = INDIO_DIRECT_MODE;
Andrew Chew3285aae2010-09-08 22:02:17 -0700529
Jonathan Cameron338473c2011-06-27 13:07:54 +0100530 err = iio_device_register(indio_dev);
Andrew Chew3285aae2010-09-08 22:02:17 -0700531 if (err < 0)
532 goto exit_free_iio;
533
534 return 0;
535
536exit_free_iio:
Jonathan Cameron338473c2011-06-27 13:07:54 +0100537 iio_free_device(indio_dev);
Andrew Chew3285aae2010-09-08 22:02:17 -0700538exit_gpio:
Stephen Warren7c6c9362011-09-21 11:16:00 +0100539 if (gpio_is_valid(eoc_gpio))
Jonathan Cameron338473c2011-06-27 13:07:54 +0100540 gpio_free(eoc_gpio);
Andrew Chew3285aae2010-09-08 22:02:17 -0700541exit:
542 return err;
543}
544
545static int ak8975_remove(struct i2c_client *client)
546{
Jonathan Cameron338473c2011-06-27 13:07:54 +0100547 struct iio_dev *indio_dev = i2c_get_clientdata(client);
548 struct ak8975_data *data = iio_priv(indio_dev);
549 int eoc_gpio = data->eoc_gpio;
Andrew Chew3285aae2010-09-08 22:02:17 -0700550
Jonathan Cameron338473c2011-06-27 13:07:54 +0100551 iio_device_unregister(indio_dev);
Andrew Chew3285aae2010-09-08 22:02:17 -0700552
Stephen Warren7c6c9362011-09-21 11:16:00 +0100553 if (gpio_is_valid(eoc_gpio))
Jonathan Cameron338473c2011-06-27 13:07:54 +0100554 gpio_free(eoc_gpio);
Andrew Chew3285aae2010-09-08 22:02:17 -0700555
556 return 0;
557}
558
559static const struct i2c_device_id ak8975_id[] = {
560 {"ak8975", 0},
561 {}
562};
563
564MODULE_DEVICE_TABLE(i2c, ak8975_id);
565
566static struct i2c_driver ak8975_driver = {
567 .driver = {
568 .name = "ak8975",
569 },
570 .probe = ak8975_probe,
571 .remove = __devexit_p(ak8975_remove),
572 .id_table = ak8975_id,
573};
574
575static int __init ak8975_init(void)
576{
577 return i2c_add_driver(&ak8975_driver);
578}
579
580static void __exit ak8975_exit(void)
581{
582 i2c_del_driver(&ak8975_driver);
583}
584
585module_init(ak8975_init);
586module_exit(ak8975_exit);
587
588MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
589MODULE_DESCRIPTION("AK8975 magnetometer driver");
590MODULE_LICENSE("GPL");