README 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. Kernel driver mpu
  2. =====================
  3. Supported chips:
  4. * InvenSense IMU3050
  5. Prefix: 'mpu3050'
  6. Datasheet:
  7. PS-MPU-3000A-00.2.4b.pdf
  8. * InvenSense IMU6000
  9. Prefix: 'mpu6000'
  10. Datasheet:
  11. MPU-6000A-00 v1.0.pdf
  12. Author: InvenSense <http://invensense.com>
  13. Description
  14. -----------
  15. The mpu is a motion processor unit that controls the mpu3050 gyroscope, a slave
  16. accelerometer, a compass and a pressure sensor, or the mpu6000 and slave
  17. compass. This document describes how to install the driver into a Linux kernel
  18. and a small note about how to set up the file permissions in an android file
  19. system.
  20. Sysfs entries
  21. -------------
  22. /dev/mpu
  23. /dev/mpuirq
  24. /dev/accelirq
  25. /dev/compassirq
  26. /dev/pressureirq
  27. General Remarks MPU3050
  28. -----------------------
  29. * Valid addresses for the MPU3050 is 0x68.
  30. * Accelerometer must be on the secondary I2C bus for MPU3050, the
  31. magnetometer must be on the primary bus and pressure sensor must
  32. be on the primary bus.
  33. General Remarks MPU6000
  34. -----------------------
  35. * Valid addresses for the MPU6000 is 0x68.
  36. * Magnetometer must be on the secondary I2C bus for the MPU6000.
  37. * Accelerometer slave address must be set to 0x68
  38. * Gyro and Accel orientation matrices should be the same
  39. Programming the chip using /dev/mpu
  40. ----------------------------------
  41. Programming of MPU3050 or MPU6000 is done by first opening the /dev/mpu file and
  42. then performing a series of IOCTLS on the handle returned. The IOCTL codes can
  43. be found in mpu.h. Typically this is done by the mllite library in user
  44. space.
  45. Adding to a Kernel
  46. ==================
  47. The mpu driver is designed to be inserted in the drivers/misc part of the
  48. kernel. Extracting the tarball from the root kernel dir will place the
  49. contents of the tarball here:
  50. <kernel root dir>/drivers/misc/mpu3050
  51. <kernel root dir>/include/linux/mpu.h
  52. <kernel root dir>/include/linux/mpu3050.h
  53. <kernel root dir>/include/linux/mpu6000.h
  54. After this is done the drivers/misc/Kconfig must be edited to add the line:
  55. source "drivers/misc/mpu3050/Kconfig"
  56. Similarly drivers/misc/Makefile must be edited to add the line:
  57. obj-y += mpu3050/
  58. Configuration can then be done as normal.
  59. NOTE: This driver depends on a kernel patch to drivers/char/char.c. This patch
  60. started to be included in most 2.6.35 based kernels.
  61. drivers: misc: pass miscdevice pointer via file private data
  62. https://patchwork.kernel.org/patch/96412/
  63. ---
  64. drivers/char/misc.c | 1 +
  65. 1 files changed, 1 insertions(+), 0 deletions(-)
  66. diff --git a/drivers/char/misc.c b/drivers/char/misc.c
  67. index 92ab03d..cd650ca 100644
  68. --- a/drivers/char/misc.c
  69. +++ b/drivers/char/misc.c
  70. @@ -144,6 +144,7 @@ static int misc_open(struct inode * inode, struct file * file)
  71. old_fops = file->f_op;
  72. file->f_op = new_fops;
  73. if (file->f_op->open) {
  74. + file->private_data = c;
  75. err=file->f_op->open(inode,file);
  76. if (err) {
  77. fops_put(file->f_op);
  78. ---
  79. Board and Platform Data
  80. -----------------------
  81. In order for the driver to work, board and platform data specific to the device
  82. needs to be added to the board file. A mpu3050_platform_data structure must
  83. be created and populated and set in the i2c_board_info_structure. For details
  84. of each structure member see mpu.h. All values below are simply an example and
  85. should be modified for your platform.
  86. #include <linux/mpu.h>
  87. #if defined(CONFIG_MPU_SENSORS_MPU3050) || defined(CONFIG_MPU_SENSORS_MPU3050_MODULE)
  88. #define SENSOR_MPU_NAME "mpu3050"
  89. static struct mpu3050_platform_data mpu_data = {
  90. .int_config = 0x10,
  91. .orientation = { -1, 0, 0,
  92. 0, 1, 0,
  93. 0, 0, -1 },
  94. /* accel */
  95. .accel = {
  96. #ifdef CONFIG_MPU_SENSORS_MPU3050_MODULE
  97. .get_slave_descr = NULL,
  98. #else
  99. .get_slave_descr = get_accel_slave_descr,
  100. #endif
  101. .adapt_num = 2,
  102. .bus = EXT_SLAVE_BUS_SECONDARY,
  103. .address = 0x0F,
  104. .orientation = { -1, 0, 0,
  105. 0, 1, 0,
  106. 0, 0, -1 },
  107. },
  108. /* compass */
  109. .compass = {
  110. #ifdef CONFIG_MPU_SENSORS_MPU3050_MODULE
  111. .get_slave_descr = NULL,
  112. #else
  113. .get_slave_descr = get_compass_slave_descr,
  114. #endif
  115. .adapt_num = 2,
  116. .bus = EXT_SLAVE_BUS_PRIMARY,
  117. .address = 0x0E,
  118. .orientation = { 1, 0, 0,
  119. 0, 1, 0,
  120. 0, 0, 1 },
  121. },
  122. /* pressure */
  123. .pressure = {
  124. #ifdef CONFIG_MPU_SENSORS_MPU3050_MODULE
  125. .get_slave_descr = NULL,
  126. #else
  127. .get_slave_descr = get_pressure_slave_descr,
  128. #endif
  129. .adapt_num = 2,
  130. .bus = EXT_SLAVE_BUS_PRIMARY,
  131. .address = 0x77,
  132. .orientation = { 1, 0, 0,
  133. 0, 1, 0,
  134. 0, 0, 1 },
  135. },
  136. };
  137. #endif
  138. #if defined(CONFIG_MPU_SENSORS_MPU6000) || defined(CONFIG_MPU_SENSORS_MPU6000_MODULE)
  139. #define SENSOR_MPU_NAME "mpu6000"
  140. static struct mpu3050_platform_data mpu_data = {
  141. .int_config = 0x10,
  142. .orientation = { -1, 0, 0,
  143. 0, 1, 0,
  144. 0, 0, -1 },
  145. /* accel */
  146. .accel = {
  147. #ifdef CONFIG_MPU_SENSORS_MPU6000_MODULE
  148. .get_slave_descr = NULL,
  149. #else
  150. .get_slave_descr = get_accel_slave_descr,
  151. #endif
  152. .adapt_num = 2,
  153. .bus = EXT_SLAVE_BUS_PRIMARY,
  154. .address = 0x68,
  155. .orientation = { -1, 0, 0,
  156. 0, 1, 0,
  157. 0, 0, -1 },
  158. },
  159. /* compass */
  160. .compass = {
  161. #ifdef CONFIG_MPU_SENSORS_MPU6000_MODULE
  162. .get_slave_descr = NULL,
  163. #else
  164. .get_slave_descr = get_compass_slave_descr,
  165. #endif
  166. .adapt_num = 2,
  167. .bus = EXT_SLAVE_BUS_SECONDARY,
  168. .address = 0x0E,
  169. .orientation = { 1, 0, 0,
  170. 0, 1, 0,
  171. 0, 0, 1 },
  172. },
  173. /* pressure */
  174. .pressure = {
  175. #ifdef CONFIG_MPU_SENSORS_MPU6000_MODULE
  176. .get_slave_descr = NULL,
  177. #else
  178. .get_slave_descr = get_pressure_slave_descr,
  179. #endif
  180. .adapt_num = 2,
  181. .bus = EXT_SLAVE_BUS_PRIMARY,
  182. .address = 0x77,
  183. .orientation = { 1, 0, 0,
  184. 0, 1, 0,
  185. 0, 0, 1 },
  186. },
  187. };
  188. #endif
  189. static struct i2c_board_info __initdata beagle_i2c_2_boardinfo[] = {
  190. {
  191. I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
  192. .irq = (IH_GPIO_BASE + MPU_GPIO_IRQ),
  193. .platform_data = &mpu_data,
  194. },
  195. };
  196. Typically the IRQ is a GPIO input pin and needs to be configured properly. If
  197. in the above example GPIO 168 corresponds to IRQ 299, the following should be
  198. done as well:
  199. #define MPU_GPIO_IRQ 168
  200. gpio_request(MPU_GPIO_IRQ,"MPUIRQ");
  201. gpio_direction_input(MPU_GPIO_IRQ)
  202. NOTE:
  203. =====
  204. In previous releases, the sensors were defined using CONFIG_SENSORS_SENSORNAME convention.
  205. From this release onwards this convention will be changed to CONFIG_MPU_SENSORS_SENSORNAME.
  206. Please make note of this change.
  207. Dynamic Debug
  208. =============
  209. The mpu3050 makes use of dynamic debug. For details on how to use this
  210. refer to Documentation/dynamic-debug-howto.txt
  211. Android File Permissions
  212. ========================
  213. To set up the file permissions on an android system, the /dev/mpu and
  214. /dev/mpuirq files needs to be added to the system/core/init/devices.c file
  215. inside the perms_ structure.
  216. static struct perms_ devperms[] = {
  217. { "/dev/mpu" ,0660, AID_SYSTEM, AID_SYSTEM, 1 },
  218. };
  219. Sufficient file permissions need to be give to read and write it by the system.
  220. For gingerbread and later the system/core/rootdir/ueventd.rc file needs to be
  221. modified with the appripriate lines added.
  222. # MPU sensors and IRQ
  223. /dev/mpu 0660 system system
  224. /dev/mpuirq 0660 system system
  225. /dev/accelirq 0660 system system
  226. /dev/compassirq 0660 system system
  227. /dev/pressureirq 0660 system system