2 * Driver for the Asahi Kasei EMD Corporation AK8974
3 * and Aichi Steel AMI305 magnetometer chips.
4 * Based on a patch from Samu Onkalo and the AK8975 IIO driver.
6 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 * Copyright (c) 2010 NVIDIA Corporation.
8 * Copyright (C) 2016 Linaro Ltd.
10 * Author: Samu Onkalo <samu.p.onkalo@nokia.com>
11 * Author: Linus Walleij <linus.walleij@linaro.org>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/i2c.h>
16 #include <linux/interrupt.h>
17 #include <linux/irq.h> /* For irq_get_irq_data() */
18 #include <linux/completion.h>
19 #include <linux/err.h>
20 #include <linux/mutex.h>
21 #include <linux/delay.h>
22 #include <linux/bitops.h>
23 #include <linux/regmap.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/pm_runtime.h>
27 #include <linux/iio/iio.h>
28 #include <linux/iio/sysfs.h>
29 #include <linux/iio/buffer.h>
30 #include <linux/iio/trigger.h>
31 #include <linux/iio/trigger_consumer.h>
32 #include <linux/iio/triggered_buffer.h>
35 * 16-bit registers are little-endian. LSB is at the address defined below
36 * and MSB is at the next higher address.
39 /* These registers are common for AK8974 and AMI305 */
40 #define AK8974_SELFTEST 0x0C
41 #define AK8974_SELFTEST_IDLE 0x55
42 #define AK8974_SELFTEST_OK 0xAA
44 #define AK8974_INFO 0x0D
46 #define AK8974_WHOAMI 0x0F
47 #define AK8974_WHOAMI_VALUE_AMI305 0x47
48 #define AK8974_WHOAMI_VALUE_AK8974 0x48
50 #define AK8974_DATA_X 0x10
51 #define AK8974_DATA_Y 0x12
52 #define AK8974_DATA_Z 0x14
53 #define AK8974_INT_SRC 0x16
54 #define AK8974_STATUS 0x18
55 #define AK8974_INT_CLEAR 0x1A
56 #define AK8974_CTRL1 0x1B
57 #define AK8974_CTRL2 0x1C
58 #define AK8974_CTRL3 0x1D
59 #define AK8974_INT_CTRL 0x1E
60 #define AK8974_INT_THRES 0x26 /* Absolute any axis value threshold */
61 #define AK8974_PRESET 0x30
63 /* AK8974-specific offsets */
64 #define AK8974_OFFSET_X 0x20
65 #define AK8974_OFFSET_Y 0x22
66 #define AK8974_OFFSET_Z 0x24
67 /* AMI305-specific offsets */
68 #define AMI305_OFFSET_X 0x6C
69 #define AMI305_OFFSET_Y 0x72
70 #define AMI305_OFFSET_Z 0x78
72 /* Different temperature registers */
73 #define AK8974_TEMP 0x31
74 #define AMI305_TEMP 0x60
76 #define AK8974_INT_X_HIGH BIT(7) /* Axis over +threshold */
77 #define AK8974_INT_Y_HIGH BIT(6)
78 #define AK8974_INT_Z_HIGH BIT(5)
79 #define AK8974_INT_X_LOW BIT(4) /* Axis below -threshold */
80 #define AK8974_INT_Y_LOW BIT(3)
81 #define AK8974_INT_Z_LOW BIT(2)
82 #define AK8974_INT_RANGE BIT(1) /* Range overflow (any axis) */
84 #define AK8974_STATUS_DRDY BIT(6) /* Data ready */
85 #define AK8974_STATUS_OVERRUN BIT(5) /* Data overrun */
86 #define AK8974_STATUS_INT BIT(4) /* Interrupt occurred */
88 #define AK8974_CTRL1_POWER BIT(7) /* 0 = standby; 1 = active */
89 #define AK8974_CTRL1_RATE BIT(4) /* 0 = 10 Hz; 1 = 20 Hz */
90 #define AK8974_CTRL1_FORCE_EN BIT(1) /* 0 = normal; 1 = force */
91 #define AK8974_CTRL1_MODE2 BIT(0) /* 0 */
93 #define AK8974_CTRL2_INT_EN BIT(4) /* 1 = enable interrupts */
94 #define AK8974_CTRL2_DRDY_EN BIT(3) /* 1 = enable data ready signal */
95 #define AK8974_CTRL2_DRDY_POL BIT(2) /* 1 = data ready active high */
96 #define AK8974_CTRL2_RESDEF (AK8974_CTRL2_DRDY_POL)
98 #define AK8974_CTRL3_RESET BIT(7) /* Software reset */
99 #define AK8974_CTRL3_FORCE BIT(6) /* Start forced measurement */
100 #define AK8974_CTRL3_SELFTEST BIT(4) /* Set selftest register */
101 #define AK8974_CTRL3_RESDEF 0x00
103 #define AK8974_INT_CTRL_XEN BIT(7) /* Enable interrupt for this axis */
104 #define AK8974_INT_CTRL_YEN BIT(6)
105 #define AK8974_INT_CTRL_ZEN BIT(5)
106 #define AK8974_INT_CTRL_XYZEN (BIT(7)|BIT(6)|BIT(5))
107 #define AK8974_INT_CTRL_POL BIT(3) /* 0 = active low; 1 = active high */
108 #define AK8974_INT_CTRL_PULSE BIT(1) /* 0 = latched; 1 = pulse (50 usec) */
109 #define AK8974_INT_CTRL_RESDEF (AK8974_INT_CTRL_XYZEN | AK8974_INT_CTRL_POL)
111 /* The AMI305 has elaborate FW version and serial number registers */
112 #define AMI305_VER 0xE8
113 #define AMI305_SN 0xEA
115 #define AK8974_MAX_RANGE 2048
117 #define AK8974_POWERON_DELAY 50
118 #define AK8974_ACTIVATE_DELAY 1
119 #define AK8974_SELFTEST_DELAY 1
121 * Set the autosuspend to two orders of magnitude larger than the poweron
122 * delay to make sane reasonable power tradeoff savings (5 seconds in
125 #define AK8974_AUTOSUSPEND_DELAY 5000
127 #define AK8974_MEASTIME 3
129 #define AK8974_PWR_ON 1
130 #define AK8974_PWR_OFF 0
133 * struct ak8974 - state container for the AK8974 driver
134 * @i2c: parent I2C client
135 * @orientation: mounting matrix, flipped axis etc
136 * @map: regmap to access the AK8974 registers over I2C
137 * @regs: the avdd and dvdd power regulators
138 * @name: the name of the part
139 * @variant: the whoami ID value (for selecting code paths)
140 * @lock: locks the magnetometer for exclusive use during a measurement
141 * @drdy_irq: uses the DRDY IRQ line
142 * @drdy_complete: completion for DRDY
143 * @drdy_active_low: the DRDY IRQ is active low
146 struct i2c_client *i2c;
147 struct iio_mount_matrix orientation;
149 struct regulator_bulk_data regs[2];
154 struct completion drdy_complete;
155 bool drdy_active_low;
156 /* Ensure timestamp is naturally aligned */
163 static const char ak8974_reg_avdd[] = "avdd";
164 static const char ak8974_reg_dvdd[] = "dvdd";
166 static int ak8974_set_power(struct ak8974 *ak8974, bool mode)
171 val = mode ? AK8974_CTRL1_POWER : 0;
172 val |= AK8974_CTRL1_FORCE_EN;
173 ret = regmap_write(ak8974->map, AK8974_CTRL1, val);
178 msleep(AK8974_ACTIVATE_DELAY);
183 static int ak8974_reset(struct ak8974 *ak8974)
187 /* Power on to get register access. Sets CTRL1 reg to reset state */
188 ret = ak8974_set_power(ak8974, AK8974_PWR_ON);
191 ret = regmap_write(ak8974->map, AK8974_CTRL2, AK8974_CTRL2_RESDEF);
194 ret = regmap_write(ak8974->map, AK8974_CTRL3, AK8974_CTRL3_RESDEF);
197 ret = regmap_write(ak8974->map, AK8974_INT_CTRL,
198 AK8974_INT_CTRL_RESDEF);
202 /* After reset, power off is default state */
203 return ak8974_set_power(ak8974, AK8974_PWR_OFF);
206 static int ak8974_configure(struct ak8974 *ak8974)
210 ret = regmap_write(ak8974->map, AK8974_CTRL2, AK8974_CTRL2_DRDY_EN |
211 AK8974_CTRL2_INT_EN);
214 ret = regmap_write(ak8974->map, AK8974_CTRL3, 0);
217 ret = regmap_write(ak8974->map, AK8974_INT_CTRL, AK8974_INT_CTRL_POL);
221 return regmap_write(ak8974->map, AK8974_PRESET, 0);
224 static int ak8974_trigmeas(struct ak8974 *ak8974)
231 /* Clear any previous measurement overflow status */
232 ret = regmap_read(ak8974->map, AK8974_INT_CLEAR, &clear);
236 /* If we have a DRDY IRQ line, use it */
237 if (ak8974->drdy_irq) {
238 mask = AK8974_CTRL2_INT_EN |
239 AK8974_CTRL2_DRDY_EN |
240 AK8974_CTRL2_DRDY_POL;
241 val = AK8974_CTRL2_DRDY_EN;
243 if (!ak8974->drdy_active_low)
244 val |= AK8974_CTRL2_DRDY_POL;
246 init_completion(&ak8974->drdy_complete);
247 ret = regmap_update_bits(ak8974->map, AK8974_CTRL2,
253 /* Force a measurement */
254 return regmap_update_bits(ak8974->map,
260 static int ak8974_await_drdy(struct ak8974 *ak8974)
266 if (ak8974->drdy_irq) {
267 ret = wait_for_completion_timeout(&ak8974->drdy_complete,
268 1 + msecs_to_jiffies(1000));
270 dev_err(&ak8974->i2c->dev,
271 "timeout waiting for DRDY IRQ\n");
277 /* Default delay-based poll loop */
279 msleep(AK8974_MEASTIME);
280 ret = regmap_read(ak8974->map, AK8974_STATUS, &val);
283 if (val & AK8974_STATUS_DRDY)
287 dev_err(&ak8974->i2c->dev,
288 "timeout waiting for DRDY\n");
295 static int ak8974_getresult(struct ak8974 *ak8974, s16 *result)
300 ret = ak8974_await_drdy(ak8974);
303 ret = regmap_read(ak8974->map, AK8974_INT_SRC, &src);
307 /* Out of range overflow! Strong magnet close? */
308 if (src & AK8974_INT_RANGE) {
309 dev_err(&ak8974->i2c->dev,
310 "range overflow in sensor\n");
314 ret = regmap_bulk_read(ak8974->map, AK8974_DATA_X, result, 6);
321 static irqreturn_t ak8974_drdy_irq(int irq, void *d)
323 struct ak8974 *ak8974 = d;
325 if (!ak8974->drdy_irq)
328 /* TODO: timestamp here to get good measurement stamps */
329 return IRQ_WAKE_THREAD;
332 static irqreturn_t ak8974_drdy_irq_thread(int irq, void *d)
334 struct ak8974 *ak8974 = d;
338 /* Check if this was a DRDY from us */
339 ret = regmap_read(ak8974->map, AK8974_STATUS, &val);
341 dev_err(&ak8974->i2c->dev, "error reading DRDY status\n");
344 if (val & AK8974_STATUS_DRDY) {
345 /* Yes this was our IRQ */
346 complete(&ak8974->drdy_complete);
350 /* We may be on a shared IRQ, let the next client check */
354 static int ak8974_selftest(struct ak8974 *ak8974)
356 struct device *dev = &ak8974->i2c->dev;
360 ret = regmap_read(ak8974->map, AK8974_SELFTEST, &val);
363 if (val != AK8974_SELFTEST_IDLE) {
364 dev_err(dev, "selftest not idle before test\n");
368 /* Trigger self-test */
369 ret = regmap_update_bits(ak8974->map,
371 AK8974_CTRL3_SELFTEST,
372 AK8974_CTRL3_SELFTEST);
374 dev_err(dev, "could not write CTRL3\n");
378 msleep(AK8974_SELFTEST_DELAY);
380 ret = regmap_read(ak8974->map, AK8974_SELFTEST, &val);
383 if (val != AK8974_SELFTEST_OK) {
384 dev_err(dev, "selftest result NOT OK (%02x)\n", val);
388 ret = regmap_read(ak8974->map, AK8974_SELFTEST, &val);
391 if (val != AK8974_SELFTEST_IDLE) {
392 dev_err(dev, "selftest not idle after test (%02x)\n", val);
395 dev_dbg(dev, "passed self-test\n");
400 static int ak8974_get_u16_val(struct ak8974 *ak8974, u8 reg, u16 *val)
405 ret = regmap_bulk_read(ak8974->map, reg, &bulk, 2);
408 *val = le16_to_cpu(bulk);
413 static int ak8974_detect(struct ak8974 *ak8974)
421 ret = regmap_read(ak8974->map, AK8974_WHOAMI, &whoami);
426 case AK8974_WHOAMI_VALUE_AMI305:
428 ret = regmap_read(ak8974->map, AMI305_VER, &fw);
431 fw &= 0x7f; /* only bits 0 thru 6 valid */
432 ret = ak8974_get_u16_val(ak8974, AMI305_SN, &sn);
435 dev_info(&ak8974->i2c->dev,
436 "detected %s, FW ver %02x, S/N: %04x\n",
439 case AK8974_WHOAMI_VALUE_AK8974:
441 dev_info(&ak8974->i2c->dev, "detected AK8974\n");
444 dev_err(&ak8974->i2c->dev, "unsupported device (%02x) ",
450 ak8974->variant = whoami;
455 static int ak8974_read_raw(struct iio_dev *indio_dev,
456 struct iio_chan_spec const *chan,
460 struct ak8974 *ak8974 = iio_priv(indio_dev);
464 pm_runtime_get_sync(&ak8974->i2c->dev);
465 mutex_lock(&ak8974->lock);
468 case IIO_CHAN_INFO_RAW:
469 if (chan->address > 2) {
470 dev_err(&ak8974->i2c->dev, "faulty channel address\n");
474 ret = ak8974_trigmeas(ak8974);
477 ret = ak8974_getresult(ak8974, hw_values);
482 * We read all axes and discard all but one, for optimized
483 * reading, use the triggered buffer.
485 *val = (s16)le16_to_cpu(hw_values[chan->address]);
491 mutex_unlock(&ak8974->lock);
492 pm_runtime_mark_last_busy(&ak8974->i2c->dev);
493 pm_runtime_put_autosuspend(&ak8974->i2c->dev);
498 static void ak8974_fill_buffer(struct iio_dev *indio_dev)
500 struct ak8974 *ak8974 = iio_priv(indio_dev);
503 pm_runtime_get_sync(&ak8974->i2c->dev);
504 mutex_lock(&ak8974->lock);
506 ret = ak8974_trigmeas(ak8974);
508 dev_err(&ak8974->i2c->dev, "error triggering measure\n");
511 ret = ak8974_getresult(ak8974, ak8974->scan.channels);
513 dev_err(&ak8974->i2c->dev, "error getting measures\n");
517 iio_push_to_buffers_with_timestamp(indio_dev, &ak8974->scan,
518 iio_get_time_ns(indio_dev));
521 mutex_unlock(&ak8974->lock);
522 pm_runtime_mark_last_busy(&ak8974->i2c->dev);
523 pm_runtime_put_autosuspend(&ak8974->i2c->dev);
526 static irqreturn_t ak8974_handle_trigger(int irq, void *p)
528 const struct iio_poll_func *pf = p;
529 struct iio_dev *indio_dev = pf->indio_dev;
531 ak8974_fill_buffer(indio_dev);
532 iio_trigger_notify_done(indio_dev->trig);
537 static const struct iio_mount_matrix *
538 ak8974_get_mount_matrix(const struct iio_dev *indio_dev,
539 const struct iio_chan_spec *chan)
541 struct ak8974 *ak8974 = iio_priv(indio_dev);
543 return &ak8974->orientation;
546 static const struct iio_chan_spec_ext_info ak8974_ext_info[] = {
547 IIO_MOUNT_MATRIX(IIO_SHARED_BY_DIR, ak8974_get_mount_matrix),
551 #define AK8974_AXIS_CHANNEL(axis, index) \
555 .channel2 = IIO_MOD_##axis, \
556 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
557 .ext_info = ak8974_ext_info, \
559 .scan_index = index, \
564 .endianness = IIO_LE \
568 static const struct iio_chan_spec ak8974_channels[] = {
569 AK8974_AXIS_CHANNEL(X, 0),
570 AK8974_AXIS_CHANNEL(Y, 1),
571 AK8974_AXIS_CHANNEL(Z, 2),
572 IIO_CHAN_SOFT_TIMESTAMP(3),
575 static const unsigned long ak8974_scan_masks[] = { 0x7, 0 };
577 static const struct iio_info ak8974_info = {
578 .read_raw = &ak8974_read_raw,
579 .driver_module = THIS_MODULE,
582 static bool ak8974_writeable_reg(struct device *dev, unsigned int reg)
584 struct i2c_client *i2c = to_i2c_client(dev);
585 struct iio_dev *indio_dev = i2c_get_clientdata(i2c);
586 struct ak8974 *ak8974 = iio_priv(indio_dev);
592 case AK8974_INT_CTRL:
593 case AK8974_INT_THRES:
594 case AK8974_INT_THRES + 1:
596 case AK8974_PRESET + 1:
598 case AK8974_OFFSET_X:
599 case AK8974_OFFSET_X + 1:
600 case AK8974_OFFSET_Y:
601 case AK8974_OFFSET_Y + 1:
602 case AK8974_OFFSET_Z:
603 case AK8974_OFFSET_Z + 1:
604 if (ak8974->variant == AK8974_WHOAMI_VALUE_AK8974)
607 case AMI305_OFFSET_X:
608 case AMI305_OFFSET_X + 1:
609 case AMI305_OFFSET_Y:
610 case AMI305_OFFSET_Y + 1:
611 case AMI305_OFFSET_Z:
612 case AMI305_OFFSET_Z + 1:
613 if (ak8974->variant == AK8974_WHOAMI_VALUE_AMI305)
621 static const struct regmap_config ak8974_regmap_config = {
624 .max_register = 0xff,
625 .writeable_reg = ak8974_writeable_reg,
628 static int ak8974_probe(struct i2c_client *i2c,
629 const struct i2c_device_id *id)
631 struct iio_dev *indio_dev;
632 struct ak8974 *ak8974;
633 unsigned long irq_trig;
637 /* Register with IIO */
638 indio_dev = devm_iio_device_alloc(&i2c->dev, sizeof(*ak8974));
639 if (indio_dev == NULL)
642 ak8974 = iio_priv(indio_dev);
643 i2c_set_clientdata(i2c, indio_dev);
645 mutex_init(&ak8974->lock);
647 ret = of_iio_read_mount_matrix(&i2c->dev,
649 &ak8974->orientation);
653 ak8974->regs[0].supply = ak8974_reg_avdd;
654 ak8974->regs[1].supply = ak8974_reg_dvdd;
656 ret = devm_regulator_bulk_get(&i2c->dev,
657 ARRAY_SIZE(ak8974->regs),
660 dev_err(&i2c->dev, "cannot get regulators\n");
664 ret = regulator_bulk_enable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
666 dev_err(&i2c->dev, "cannot enable regulators\n");
670 /* Take runtime PM online */
671 pm_runtime_get_noresume(&i2c->dev);
672 pm_runtime_set_active(&i2c->dev);
673 pm_runtime_enable(&i2c->dev);
675 ak8974->map = devm_regmap_init_i2c(i2c, &ak8974_regmap_config);
676 if (IS_ERR(ak8974->map)) {
677 dev_err(&i2c->dev, "failed to allocate register map\n");
678 pm_runtime_put_noidle(&i2c->dev);
679 pm_runtime_disable(&i2c->dev);
680 return PTR_ERR(ak8974->map);
683 ret = ak8974_set_power(ak8974, AK8974_PWR_ON);
685 dev_err(&i2c->dev, "could not power on\n");
689 ret = ak8974_detect(ak8974);
691 dev_err(&i2c->dev, "neither AK8974 nor AMI305 found\n");
695 ret = ak8974_selftest(ak8974);
697 dev_err(&i2c->dev, "selftest failed (continuing anyway)\n");
699 ret = ak8974_reset(ak8974);
701 dev_err(&i2c->dev, "AK8974 reset failed\n");
705 indio_dev->dev.parent = &i2c->dev;
706 indio_dev->channels = ak8974_channels;
707 indio_dev->num_channels = ARRAY_SIZE(ak8974_channels);
708 indio_dev->info = &ak8974_info;
709 indio_dev->available_scan_masks = ak8974_scan_masks;
710 indio_dev->modes = INDIO_DIRECT_MODE;
711 indio_dev->name = ak8974->name;
713 ret = iio_triggered_buffer_setup(indio_dev, NULL,
714 ak8974_handle_trigger,
717 dev_err(&i2c->dev, "triggered buffer setup failed\n");
721 /* If we have a valid DRDY IRQ, make use of it */
723 irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
724 if (irq_trig == IRQF_TRIGGER_RISING) {
725 dev_info(&i2c->dev, "enable rising edge DRDY IRQ\n");
726 } else if (irq_trig == IRQF_TRIGGER_FALLING) {
727 ak8974->drdy_active_low = true;
728 dev_info(&i2c->dev, "enable falling edge DRDY IRQ\n");
730 irq_trig = IRQF_TRIGGER_RISING;
732 irq_trig |= IRQF_ONESHOT;
733 irq_trig |= IRQF_SHARED;
735 ret = devm_request_threaded_irq(&i2c->dev,
738 ak8974_drdy_irq_thread,
743 dev_err(&i2c->dev, "unable to request DRDY IRQ "
744 "- proceeding without IRQ\n");
747 ak8974->drdy_irq = true;
751 ret = iio_device_register(indio_dev);
753 dev_err(&i2c->dev, "device register failed\n");
757 pm_runtime_set_autosuspend_delay(&i2c->dev,
758 AK8974_AUTOSUSPEND_DELAY);
759 pm_runtime_use_autosuspend(&i2c->dev);
760 pm_runtime_put(&i2c->dev);
765 iio_triggered_buffer_cleanup(indio_dev);
767 pm_runtime_put_noidle(&i2c->dev);
768 pm_runtime_disable(&i2c->dev);
769 ak8974_set_power(ak8974, AK8974_PWR_OFF);
770 regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
775 static int ak8974_remove(struct i2c_client *i2c)
777 struct iio_dev *indio_dev = i2c_get_clientdata(i2c);
778 struct ak8974 *ak8974 = iio_priv(indio_dev);
780 iio_device_unregister(indio_dev);
781 iio_triggered_buffer_cleanup(indio_dev);
782 pm_runtime_get_sync(&i2c->dev);
783 pm_runtime_put_noidle(&i2c->dev);
784 pm_runtime_disable(&i2c->dev);
785 ak8974_set_power(ak8974, AK8974_PWR_OFF);
786 regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
791 static int __maybe_unused ak8974_runtime_suspend(struct device *dev)
793 struct ak8974 *ak8974 =
794 iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
796 ak8974_set_power(ak8974, AK8974_PWR_OFF);
797 regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
802 static int __maybe_unused ak8974_runtime_resume(struct device *dev)
804 struct ak8974 *ak8974 =
805 iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
808 ret = regulator_bulk_enable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
811 msleep(AK8974_POWERON_DELAY);
812 ret = ak8974_set_power(ak8974, AK8974_PWR_ON);
814 goto out_regulator_disable;
816 ret = ak8974_configure(ak8974);
818 goto out_disable_power;
823 ak8974_set_power(ak8974, AK8974_PWR_OFF);
824 out_regulator_disable:
825 regulator_bulk_disable(ARRAY_SIZE(ak8974->regs), ak8974->regs);
830 static const struct dev_pm_ops ak8974_dev_pm_ops = {
831 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
832 pm_runtime_force_resume)
833 SET_RUNTIME_PM_OPS(ak8974_runtime_suspend,
834 ak8974_runtime_resume, NULL)
837 static const struct i2c_device_id ak8974_id[] = {
842 MODULE_DEVICE_TABLE(i2c, ak8974_id);
844 static const struct of_device_id ak8974_of_match[] = {
845 { .compatible = "asahi-kasei,ak8974", },
848 MODULE_DEVICE_TABLE(of, ak8974_of_match);
850 static struct i2c_driver ak8974_driver = {
853 .pm = &ak8974_dev_pm_ops,
854 .of_match_table = of_match_ptr(ak8974_of_match),
856 .probe = ak8974_probe,
857 .remove = ak8974_remove,
858 .id_table = ak8974_id,
860 module_i2c_driver(ak8974_driver);
862 MODULE_DESCRIPTION("AK8974 and AMI305 3-axis magnetometer driver");
863 MODULE_AUTHOR("Samu Onkalo");
864 MODULE_AUTHOR("Linus Walleij");
865 MODULE_LICENSE("GPL v2");