af46094d97d549bbd4b2bce38d4ddfad1a97c384
[firefly-linux-kernel-4.4.55.git] / drivers / staging / iio / imu / inv_mpu / inv_mpu_i2c.c
1 /*
2 * Copyright (C) 2012 Invensense, Inc.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12 *
13 */
14
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/i2c.h>
21 #include <linux/err.h>
22 #include <linux/delay.h>
23 #include <linux/sysfs.h>
24 #include <linux/jiffies.h>
25 #include <linux/irq.h>
26 #include <linux/interrupt.h>
27 #include <linux/kfifo.h>
28 #include <linux/poll.h>
29 #include <linux/miscdevice.h>
30 #include <linux/spinlock.h>
31
32 #include "inv_mpu_iio.h"
33 #ifdef INV_KERNEL_3_10
34 #include <linux/iio/sysfs.h>
35 #else
36 #include "sysfs.h"
37 #endif
38 #include "inv_counters.h"
39
40 /**
41  *  inv_i2c_read_base() - Read one or more bytes from the device registers.
42  *  @st:        Device driver instance.
43  *  @reg:       First device register to be read from.
44  *  @length:    Number of bytes to read.
45  *  @data:      Data read from device.
46  *  NOTE:This is not re-implementation of i2c_smbus_read because i2c
47  *       address could be specified in this case. We could have two different
48  *       i2c address due to secondary i2c interface.
49  */
50 static int inv_i2c_read_base(struct inv_mpu_iio_s *st, u16 i2c_addr,
51         u8 reg, u16 length, u8 *data)
52 {
53         struct i2c_msg msgs[2];
54         int res;
55
56         if (!data)
57                 return -EINVAL;
58
59         msgs[0].addr = i2c_addr;
60         msgs[0].flags = 0;      /* write */
61         msgs[0].buf = &reg;
62         msgs[0].len = 1;
63         /* msgs[0].scl_rate = 200*1000; */
64
65         msgs[1].addr = i2c_addr;
66         msgs[1].flags = I2C_M_RD;
67         msgs[1].buf = data;
68         msgs[1].len = length;
69         /* msgs[1].scl_rate = 200*1000; */
70
71         res = i2c_transfer(st->sl_handle, msgs, 2);
72
73         if (res < 2) {
74                 if (res >= 0)
75                         res = -EIO;
76         } else
77                 res = 0;
78
79         INV_I2C_INC_MPUWRITE(3);
80         INV_I2C_INC_MPUREAD(length);
81         {
82                 char *read = 0;
83                 pr_debug("%s RD%02X%02X%02X -> %s%s\n", st->hw->name,
84                          i2c_addr, reg, length,
85                          wr_pr_debug_begin(data, length, read),
86                          wr_pr_debug_end(read));
87         }
88         return res;
89 }
90
91 /**
92  *  inv_i2c_single_write_base() - Write a byte to a device register.
93  *  @st:        Device driver instance.
94  *  @reg:       Device register to be written to.
95  *  @data:      Byte to write to device.
96  *  NOTE:This is not re-implementation of i2c_smbus_write because i2c
97  *       address could be specified in this case. We could have two different
98  *       i2c address due to secondary i2c interface.
99  */
100 static int inv_i2c_single_write_base(struct inv_mpu_iio_s *st,
101         u16 i2c_addr, u8 reg, u8 data)
102 {
103         u8 tmp[2];
104         struct i2c_msg msg;
105         int res;
106         tmp[0] = reg;
107         tmp[1] = data;
108
109         msg.addr = i2c_addr;
110         msg.flags = 0;  /* write */
111         msg.buf = tmp;
112         msg.len = 2;
113         /* msg.scl_rate = 200*1000; */
114
115         pr_debug("%s WR%02X%02X%02X\n", st->hw->name, i2c_addr, reg, data);
116         INV_I2C_INC_MPUWRITE(3);
117
118         res = i2c_transfer(st->sl_handle, &msg, 1);
119         if (res < 1) {
120                 if (res == 0)
121                         res = -EIO;
122                 return res;
123         } else
124                 return 0;
125 }
126
127 static int inv_i2c_single_write(struct inv_mpu_iio_s *st, u8 reg, u8 data)
128 {
129         return inv_i2c_single_write_base(st, st->i2c_addr, reg, data);
130 }
131
132 static int inv_i2c_read(struct inv_mpu_iio_s *st, u8 reg, int len, u8 *data)
133 {
134         return inv_i2c_read_base(st, st->i2c_addr, reg, len, data);
135 }
136
137 static int inv_i2c_secondary_read(struct inv_mpu_iio_s *st, u8 reg, int len, u8 *data)
138 {
139         return inv_i2c_read_base(st, st->plat_data.secondary_i2c_addr, reg, len, data);
140 }
141
142 static int inv_i2c_secondary_write(struct inv_mpu_iio_s *st, u8 reg, u8 data)
143 {
144         return inv_i2c_single_write_base(st, st->plat_data.secondary_i2c_addr, reg, data);
145 }
146
147 static int mpu_i2c_memory_write(struct inv_mpu_iio_s *st, u8 mpu_addr, u16 mem_addr,
148                      u32 len, u8 const *data)
149 {
150         u8 bank[2];
151         u8 addr[2];
152         u8 buf[513];
153
154         struct i2c_msg msg;
155         int res;
156
157         if (!data || !st)
158                 return -EINVAL;
159
160         if (len >= (sizeof(buf) - 1))
161                 return -ENOMEM;
162
163         bank[0] = REG_BANK_SEL;
164         bank[1] = mem_addr >> 8;
165
166         addr[0] = REG_MEM_START_ADDR;
167         addr[1] = mem_addr & 0xFF;
168
169         buf[0] = REG_MEM_RW;
170         memcpy(buf + 1, data, len);
171
172         /* write message */
173         msg.addr = mpu_addr;
174         msg.flags = 0;
175         msg.buf = bank;
176         msg.len = sizeof(bank);
177         /* msg.scl_rate = 200*1000; */
178         INV_I2C_INC_MPUWRITE(3);
179         res = i2c_transfer(st->sl_handle, &msg, 1);
180         if (res < 1) {
181                 if (res >= 0)
182                         res = -EIO;
183                 return res;
184         }
185
186         msg.addr = mpu_addr;
187         msg.flags = 0;
188         msg.buf = addr;
189         msg.len = sizeof(addr);
190         /* msg.scl_rate = 200*1000; */
191         INV_I2C_INC_MPUWRITE(3);
192         res = i2c_transfer(st->sl_handle, &msg, 1);
193         if (res < 1) {
194                 if (res >= 0)
195                         res = -EIO;
196                 return res;
197         }
198
199         msg.addr = mpu_addr;
200         msg.flags = 0;
201         msg.buf = (u8 *)buf;
202         msg.len = len + 1;
203         /* msg.scl_rate = 200*1000; */
204         INV_I2C_INC_MPUWRITE(2+len);
205         res = i2c_transfer(st->sl_handle, &msg, 1);
206         if (res < 1) {
207                 if (res >= 0)
208                         res = -EIO;
209                 return res;
210         }
211
212         {
213                 char *write = 0;
214                 pr_debug("%s WM%02X%02X%02X%s%s - %d\n", st->hw->name,
215                          mpu_addr, bank[1], addr[1],
216                          wr_pr_debug_begin(data, len, write),
217                          wr_pr_debug_end(write),
218                          len);
219         }
220         return 0;
221 }
222
223 static int mpu_i2c_memory_read(struct inv_mpu_iio_s *st, u8 mpu_addr, u16 mem_addr,
224                     u32 len, u8 *data)
225 {
226         u8 bank[2];
227         u8 addr[2];
228         u8 buf;
229
230         struct i2c_msg msg;
231         int res;
232
233         if (!data || !st)
234                 return -EINVAL;
235
236         bank[0] = REG_BANK_SEL;
237         bank[1] = mem_addr >> 8;
238
239         addr[0] = REG_MEM_START_ADDR;
240         addr[1] = mem_addr & 0xFF;
241
242         buf = REG_MEM_RW;
243
244         /* write message */
245         msg.addr = mpu_addr;
246         msg.flags = 0;
247         msg.buf = bank;
248         msg.len = sizeof(bank);
249         /* msg.scl_rate = 200*1000; */
250         INV_I2C_INC_MPUWRITE(3);
251         res = i2c_transfer(st->sl_handle, &msg, 1);
252         if (res < 1) {
253                 if (res >= 0)
254                         res = -EIO;
255                 return res;
256         }
257
258         msg.addr = mpu_addr;
259         msg.flags = 0;
260         msg.buf = addr;
261         msg.len = sizeof(addr);
262         /* msg.scl_rate = 200*1000; */
263         INV_I2C_INC_MPUWRITE(3);
264         res = i2c_transfer(st->sl_handle, &msg, 1);
265         if (res < 1) {
266                 if (res >= 0)
267                         res = -EIO;
268                 return res;
269         }
270
271         msg.addr = mpu_addr;
272         msg.flags = 0;
273         msg.buf = &buf;
274         msg.len = 1;
275         /* msg.scl_rate = 200*1000; */
276         INV_I2C_INC_MPUWRITE(3);
277         res = i2c_transfer(st->sl_handle, &msg, 1);
278         if (res < 1) {
279                 if (res >= 0)
280                         res = -EIO;
281                 return res;
282         }
283
284         msg.addr = mpu_addr;
285         msg.flags = I2C_M_RD;
286         msg.buf = data;
287         msg.len = len;
288         /* msg.scl_rate = 200*1000; */
289         INV_I2C_INC_MPUREAD(len);
290         res = i2c_transfer(st->sl_handle, &msg, 1);
291         if (res < 1) {
292                 if (res >= 0)
293                         res = -EIO;
294                 return res;
295         }
296         {
297                 char *read = 0;
298                 pr_debug("%s RM%02X%02X%02X%02X - %s%s\n", st->hw->name,
299                          mpu_addr, bank[1], addr[1], len,
300                          wr_pr_debug_begin(data, len, read),
301                          wr_pr_debug_end(read));
302         }
303
304         return 0;
305 }
306
307 #include <linux/gpio.h>
308 #include <linux/of_gpio.h>
309 #include <linux/of.h>
310
311 static struct mpu_platform_data mpu_data = {
312         .int_config  = 0x00,
313         .level_shifter = 0,
314         .orientation = {
315                         0,  1,  0,
316                         -1,  0,  0,
317                         0,  0, -1,
318         },
319 /*
320         .sec_slave_type = SECONDARY_SLAVE_TYPE_COMPASS,
321         .sec_slave_id = COMPASS_ID_AK8963,
322         .secondary_i2c_addr = 0x0d,
323         .secondary_orientation = {
324                         -1,  0,  0,
325                         0,  1,  0,
326                         0,  0, -1,
327         },
328         .key = {
329                 221,  22, 205,   7, 217, 186, 151, 55,
330                 206, 254,  35, 144, 225, 102,  47, 50,
331         },
332 */
333 };
334
335 static int of_inv_parse_platform_data(struct i2c_client *client,
336                                       struct mpu_platform_data *pdata)
337 {
338         int ret;
339         int length = 0, size = 0;
340         struct property *prop;
341         u32 orientation[9];
342         int orig_x, orig_y, orig_z;
343         int i;
344         struct device_node *np = client->dev.of_node;
345         unsigned long irq_flags;
346         int irq_pin;
347         int gpio_pin;
348         int debug;
349
350         gpio_pin = of_get_named_gpio_flags(np, "irq-gpio", 0, (enum of_gpio_flags *)&irq_flags);
351         gpio_request(gpio_pin, "mpu6500");
352         irq_pin = gpio_to_irq(gpio_pin);
353         client->irq = irq_pin;
354
355         i2c_set_clientdata(client, &mpu_data);
356
357         ret = of_property_read_u8(np, "mpu-int_config", &mpu_data.int_config);
358         if (ret != 0) {
359                 dev_err(&client->dev, "get mpu-int_config error\n");
360                 return -EIO;
361         }
362
363         ret = of_property_read_u8(np, "mpu-level_shifter", &mpu_data.level_shifter);
364         if (ret != 0) {
365                 dev_err(&client->dev, "get mpu-level_shifter error\n");
366                 return -EIO;
367         }
368
369         prop = of_find_property(np, "mpu-orientation", &length);
370         if (!prop) {
371                 dev_err(&client->dev, "get mpu-orientation length error\n");
372                 return -EINVAL;
373         }
374         size = length / sizeof(u32);
375         if ((size > 0) && (size < 10)) {
376                 ret = of_property_read_u32_array(np, "mpu-orientation", orientation, size);
377                 if (ret < 0) {
378                         dev_err(&client->dev, "get mpu-orientation data error\n");
379                         return -EINVAL;
380                 }
381                 for (i = 0; i < 9; i++)
382                         mpu_data.orientation[i] = orientation[i];
383         } else {
384                 dev_info(&client->dev, "use default orientation\n");
385         }
386
387         ret = of_property_read_u32(np, "orientation-x", &orig_x);
388         if (ret != 0) {
389                 dev_err(&client->dev, "get orientation-x error\n");
390                 return -EIO;
391         }
392         if (orig_x > 0) {
393                 for (i = 0; i < 3; i++)
394                         if (mpu_data.orientation[i])
395                                 mpu_data.orientation[i] = -1;
396         }
397
398         ret = of_property_read_u32(np, "orientation-y", &orig_y);
399         if (ret != 0) {
400                 dev_err(&client->dev, "get orientation-y error\n");
401                 return -EIO;
402         }
403         if (orig_y > 0) {
404                 for (i = 3; i < 6; i++)
405                         if (mpu_data.orientation[i])
406                                 mpu_data.orientation[i] = -1;
407         }
408
409         ret = of_property_read_u32(np, "orientation-z", &orig_z);
410         if (ret != 0) {
411                 dev_err(&client->dev, "get orientation-z error\n");
412                 return -EIO;
413         }
414         if (orig_z > 0) {
415                 for (i = 6; i < 9; i++)
416                         if (mpu_data.orientation[i])
417                                 mpu_data.orientation[i] = -1;
418         }
419
420         ret = of_property_read_u32(np, "mpu-debug", &debug);
421         if (ret != 0) {
422                 dev_err(&client->dev, "get mpu-debug error\n");
423                 return -EINVAL;
424         }
425         if (debug) {
426                 dev_info(&client->dev, "int_config=%d,level_shifter=%d,client.addr=%x,client.irq=%x\n",
427                                                         mpu_data.int_config,
428                                                         mpu_data.level_shifter,
429                                                         client->addr,
430                                                         client->irq);
431                 for (i = 0; i < size; i++)
432                         dev_info(&client->dev, "%d ", mpu_data.orientation[i]);
433                 dev_info(&client->dev, "\n");
434         }
435
436         return 0;
437 }
438
439 /**
440  *  inv_mpu_probe() - probe function.
441  */
442 static int inv_mpu_probe(struct i2c_client *client,
443         const struct i2c_device_id *id)
444 {
445         struct inv_mpu_iio_s *st;
446         struct iio_dev *indio_dev;
447         int result;
448
449         if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
450                 result = -ENOSYS;
451                 pr_err("I2c function error\n");
452                 goto out_no_free;
453         }
454 #ifdef INV_KERNEL_3_10
455     indio_dev = iio_device_alloc(sizeof(*st));
456 #else
457         indio_dev = iio_allocate_device(sizeof(*st));
458 #endif
459         if (indio_dev == NULL) {
460                 pr_err("memory allocation failed\n");
461                 result =  -ENOMEM;
462                 goto out_no_free;
463         }
464         st = iio_priv(indio_dev);
465         st->client = client;
466         st->sl_handle = client->adapter;
467         st->i2c_addr = client->addr;
468         if (client->dev.of_node) {
469                 result = of_inv_parse_platform_data(client, &st->plat_data);
470                 if (result)
471                         goto out_free;
472                 st->plat_data = mpu_data;
473                 pr_info("secondary_i2c_addr=%x\n", st->plat_data.secondary_i2c_addr);
474         } else
475                 st->plat_data =
476                         *(struct mpu_platform_data *)dev_get_platdata(&client->dev);
477
478         st->plat_read = inv_i2c_read;
479         st->plat_single_write = inv_i2c_single_write;
480         st->secondary_read = inv_i2c_secondary_read;
481         st->secondary_write = inv_i2c_secondary_write;
482         st->memory_read = mpu_i2c_memory_read;
483         st->memory_write = mpu_i2c_memory_write;
484
485         /* power is turned on inside check chip type*/
486         result = inv_check_chip_type(st, id->name);
487         if (result)
488                 goto out_free;
489
490         result = st->init_config(indio_dev);
491         if (result) {
492                 dev_err(&client->adapter->dev,
493                         "Could not initialize device.\n");
494                 goto out_free;
495         }
496         result = st->set_power_state(st, false);
497         if (result) {
498                 dev_err(&client->adapter->dev,
499                         "%s could not be turned off.\n", st->hw->name);
500                 goto out_free;
501         }
502
503         /* Make state variables available to all _show and _store functions. */
504         i2c_set_clientdata(client, indio_dev);
505         indio_dev->dev.parent = &client->dev;
506         if (!strcmp(id->name, "mpu6xxx"))
507                 indio_dev->name = st->name;
508         else
509                 indio_dev->name = id->name;
510
511         inv_set_iio_info(st, indio_dev);
512
513         result = inv_mpu_configure_ring(indio_dev);
514         if (result) {
515                 pr_err("configure ring buffer fail\n");
516                 goto out_free;
517         }
518         st->irq = client->irq;
519         st->dev = &client->dev;
520         result = inv_mpu_probe_trigger(indio_dev);
521         if (result) {
522                 pr_err("trigger probe fail\n");
523                 goto out_unreg_ring;
524         }
525
526         /* Tell the i2c counter, we have an IRQ */
527         INV_I2C_SETIRQ(IRQ_MPU, client->irq);
528
529         result = iio_device_register(indio_dev);
530         if (result) {
531                 pr_err("IIO device register fail\n");
532                 goto out_remove_trigger;
533         }
534
535         if (INV_MPU6050 == st->chip_type ||
536             INV_MPU6500 == st->chip_type) {
537                 result = inv_create_dmp_sysfs(indio_dev);
538                 if (result) {
539                         pr_err("create dmp sysfs failed\n");
540                         goto out_unreg_iio;
541                 }
542         }
543
544         INIT_KFIFO(st->timestamps);
545         spin_lock_init(&st->time_stamp_lock);
546         dev_info(&client->dev, "%s is ready to go!\n",
547                                         indio_dev->name);
548
549         return 0;
550 out_unreg_iio:
551         iio_device_unregister(indio_dev);
552 out_remove_trigger:
553         if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
554                 inv_mpu_remove_trigger(indio_dev);
555 out_unreg_ring:
556         inv_mpu_unconfigure_ring(indio_dev);
557 out_free:
558 #ifdef INV_KERNEL_3_10
559     iio_device_free(indio_dev);
560 #else
561         iio_free_device(indio_dev);
562 #endif
563 out_no_free:
564         dev_err(&client->adapter->dev, "%s failed %d\n", __func__, result);
565
566         return -EIO;
567 }
568
569 static void inv_mpu_shutdown(struct i2c_client *client)
570 {
571         struct iio_dev *indio_dev = i2c_get_clientdata(client);
572         struct inv_mpu_iio_s *st = iio_priv(indio_dev);
573         struct inv_reg_map_s *reg;
574         int result;
575
576         reg = &st->reg;
577         dev_dbg(&client->adapter->dev, "Shutting down %s...\n", st->hw->name);
578
579         /* reset to make sure previous state are not there */
580         result = inv_plat_single_write(st, reg->pwr_mgmt_1, BIT_H_RESET);
581         if (result)
582                 dev_err(&client->adapter->dev, "Failed to reset %s\n",
583                         st->hw->name);
584         msleep(POWER_UP_TIME);
585         /* turn off power to ensure gyro engine is off */
586         result = st->set_power_state(st, false);
587         if (result)
588                 dev_err(&client->adapter->dev, "Failed to turn off %s\n",
589                         st->hw->name);
590 }
591
592 /**
593  *  inv_mpu_remove() - remove function.
594  */
595 static int inv_mpu_remove(struct i2c_client *client)
596 {
597         struct iio_dev *indio_dev = i2c_get_clientdata(client);
598         struct inv_mpu_iio_s *st = iio_priv(indio_dev);
599         kfifo_free(&st->timestamps);
600         iio_device_unregister(indio_dev);
601         if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
602                 inv_mpu_remove_trigger(indio_dev);
603         inv_mpu_unconfigure_ring(indio_dev);
604 #ifdef INV_KERNEL_3_10
605     iio_device_free(indio_dev);
606 #else
607         iio_free_device(indio_dev);
608 #endif
609
610         dev_info(&client->adapter->dev, "inv-mpu-iio module removed.\n");
611
612         return 0;
613 }
614
615 #ifdef CONFIG_PM
616 static int inv_mpu_resume(struct device *dev)
617 {
618         struct inv_mpu_iio_s *st =
619                         iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
620         pr_debug("%s inv_mpu_resume\n", st->hw->name);
621         return st->set_power_state(st, true);
622 }
623
624 static int inv_mpu_suspend(struct device *dev)
625 {
626         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
627         struct inv_mpu_iio_s *st = iio_priv(indio_dev);
628         int result;
629
630         pr_debug("%s inv_mpu_suspend\n", st->hw->name);
631         mutex_lock(&indio_dev->mlock);
632         result = 0;
633         if ((!st->chip_config.dmp_on) ||
634                 (!st->chip_config.enable) ||
635                 (!st->chip_config.dmp_event_int_on))
636                 result = st->set_power_state(st, false);
637         mutex_unlock(&indio_dev->mlock);
638
639         return result;
640 }
641 static const struct dev_pm_ops inv_mpu_pmops = {
642         SET_SYSTEM_SLEEP_PM_OPS(inv_mpu_suspend, inv_mpu_resume)
643 };
644 #define INV_MPU_PMOPS (&inv_mpu_pmops)
645 #else
646 #define INV_MPU_PMOPS NULL
647 #endif /* CONFIG_PM */
648
649 static const u16 normal_i2c[] = { I2C_CLIENT_END };
650 /* device id table is used to identify what device can be
651  * supported by this driver
652  */
653 static const struct i2c_device_id inv_mpu_id[] = {
654         {"itg3500", INV_ITG3500},
655         {"mpu3050", INV_MPU3050},
656         {"mpu6050", INV_MPU6050},
657         {"mpu9150", INV_MPU9150},
658         {"mpu6500", INV_MPU6500},
659         {"mpu9250", INV_MPU9250},
660         {"mpu6xxx", INV_MPU6XXX},
661         {"mpu6515", INV_MPU6515},
662         {}
663 };
664
665 MODULE_DEVICE_TABLE(i2c, inv_mpu_id);
666
667 static const struct of_device_id inv_mpu_of_match[] = {
668         { .compatible = "invensense,itg3500", },
669         { .compatible = "invensense,mpu3050", },
670         { .compatible = "invensense,mpu6050", },
671         { .compatible = "invensense,mpu9150", },
672         { .compatible = "invensense,mpu6500", },
673         { .compatible = "invensense,mpu9250", },
674         { .compatible = "invensense,mpu6xxx", },
675         { .compatible = "invensense,mpu9350", },
676         { .compatible = "invensense,mpu6515", },
677         {}
678 };
679
680 MODULE_DEVICE_TABLE(of, inv_mpu_of_match);
681
682 static struct i2c_driver inv_mpu_driver = {
683         .class = I2C_CLASS_HWMON,
684         .probe          =       inv_mpu_probe,
685         .remove         =       inv_mpu_remove,
686         .shutdown       =       inv_mpu_shutdown,
687         .id_table       =       inv_mpu_id,
688         .driver = {
689                 .owner  =       THIS_MODULE,
690                 .name   =       "inv-mpu-iio",
691                 .pm     =       INV_MPU_PMOPS,
692                 .of_match_table = of_match_ptr(inv_mpu_of_match),
693         },
694         .address_list = normal_i2c,
695 };
696
697 static int __init inv_mpu_init(void)
698 {
699         int result = i2c_add_driver(&inv_mpu_driver);
700     pr_info("%s:%d\n", __func__, __LINE__);
701         if (result) {
702                 pr_err("failed\n");
703                 return result;
704         }
705         return 0;
706 }
707
708 static void __exit inv_mpu_exit(void)
709 {
710         i2c_del_driver(&inv_mpu_driver);
711 }
712
713 module_init(inv_mpu_init);
714 module_exit(inv_mpu_exit);
715
716 MODULE_AUTHOR("Invensense Corporation");
717 MODULE_DESCRIPTION("Invensense device driver");
718 MODULE_LICENSE("GPL");
719 MODULE_ALIAS("inv-mpu-iio");
720
721 /**
722  *  @}
723  */