akm8975.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /* drivers/misc/akm8975.c - akm8975 compass driver
  2. *
  3. * Copyright (C) 2007-2008 HTC Corporation.
  4. * Author: Hou-Kun Chen <houkun.chen@gmail.com>
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. /*
  17. * Revised by AKM 2009/04/02
  18. * Revised by Motorola 2010/05/27
  19. *
  20. */
  21. #include <linux/interrupt.h>
  22. #include <linux/i2c.h>
  23. #include <linux/slab.h>
  24. #include <linux/irq.h>
  25. #include <linux/miscdevice.h>
  26. #include <linux/gpio.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/delay.h>
  29. #include <linux/input.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/freezer.h>
  32. #include <linux/akm8975.h>
  33. #include <linux/earlysuspend.h>
  34. #define AK8975DRV_CALL_DBG 0
  35. #if AK8975DRV_CALL_DBG
  36. #define FUNCDBG(msg) pr_err("%s:%s\n", __func__, msg);
  37. #else
  38. #define FUNCDBG(msg)
  39. #endif
  40. #define AK8975DRV_DATA_DBG 0
  41. #define MAX_FAILURE_COUNT 10
  42. struct akm8975_data {
  43. struct i2c_client *this_client;
  44. struct akm8975_platform_data *pdata;
  45. struct input_dev *input_dev;
  46. struct work_struct work;
  47. struct mutex flags_lock;
  48. #ifdef CONFIG_HAS_EARLYSUSPEND
  49. struct early_suspend early_suspend;
  50. #endif
  51. };
  52. /*
  53. * Because misc devices can not carry a pointer from driver register to
  54. * open, we keep this global. This limits the driver to a single instance.
  55. */
  56. struct akm8975_data *akmd_data;
  57. static DECLARE_WAIT_QUEUE_HEAD(open_wq);
  58. static atomic_t open_flag;
  59. static short m_flag;
  60. static short a_flag;
  61. static short t_flag;
  62. static short mv_flag;
  63. static short akmd_delay;
  64. static ssize_t akm8975_show(struct device *dev, struct device_attribute *attr,
  65. char *buf)
  66. {
  67. struct i2c_client *client = to_i2c_client(dev);
  68. return sprintf(buf, "%u\n", i2c_smbus_read_byte_data(client,
  69. AK8975_REG_CNTL));
  70. }
  71. static ssize_t akm8975_store(struct device *dev, struct device_attribute *attr,
  72. const char *buf, size_t count)
  73. {
  74. struct i2c_client *client = to_i2c_client(dev);
  75. unsigned long val;
  76. strict_strtoul(buf, 10, &val);
  77. if (val > 0xff)
  78. return -EINVAL;
  79. i2c_smbus_write_byte_data(client, AK8975_REG_CNTL, val);
  80. return count;
  81. }
  82. static DEVICE_ATTR(akm_ms1, S_IWUSR | S_IRUGO, akm8975_show, akm8975_store);
  83. static int akm8975_i2c_rxdata(struct akm8975_data *akm, char *buf, int length)
  84. {
  85. struct i2c_msg msgs[] = {
  86. {
  87. .addr = akm->this_client->addr,
  88. .flags = 0,
  89. .len = 1,
  90. .buf = buf,
  91. },
  92. {
  93. .addr = akm->this_client->addr,
  94. .flags = I2C_M_RD,
  95. .len = length,
  96. .buf = buf,
  97. },
  98. };
  99. FUNCDBG("called");
  100. if (i2c_transfer(akm->this_client->adapter, msgs, 2) < 0) {
  101. pr_err("akm8975_i2c_rxdata: transfer error\n");
  102. return EIO;
  103. } else
  104. return 0;
  105. }
  106. static int akm8975_i2c_txdata(struct akm8975_data *akm, char *buf, int length)
  107. {
  108. struct i2c_msg msgs[] = {
  109. {
  110. .addr = akm->this_client->addr,
  111. .flags = 0,
  112. .len = length,
  113. .buf = buf,
  114. },
  115. };
  116. FUNCDBG("called");
  117. if (i2c_transfer(akm->this_client->adapter, msgs, 1) < 0) {
  118. pr_err("akm8975_i2c_txdata: transfer error\n");
  119. return -EIO;
  120. } else
  121. return 0;
  122. }
  123. static void akm8975_ecs_report_value(struct akm8975_data *akm, short *rbuf)
  124. {
  125. struct akm8975_data *data = i2c_get_clientdata(akm->this_client);
  126. FUNCDBG("called");
  127. #if AK8975DRV_DATA_DBG
  128. pr_info("akm8975_ecs_report_value: yaw = %d, pitch = %d, roll = %d\n",
  129. rbuf[0], rbuf[1], rbuf[2]);
  130. pr_info("tmp = %d, m_stat= %d, g_stat=%d\n", rbuf[3], rbuf[4], rbuf[5]);
  131. pr_info("Acceleration: x = %d LSB, y = %d LSB, z = %d LSB\n",
  132. rbuf[6], rbuf[7], rbuf[8]);
  133. pr_info("Magnetic: x = %d LSB, y = %d LSB, z = %d LSB\n\n",
  134. rbuf[9], rbuf[10], rbuf[11]);
  135. #endif
  136. mutex_lock(&akm->flags_lock);
  137. /* Report magnetic sensor information */
  138. if (m_flag) {
  139. input_report_abs(data->input_dev, ABS_RX, rbuf[0]);
  140. input_report_abs(data->input_dev, ABS_RY, rbuf[1]);
  141. input_report_abs(data->input_dev, ABS_RZ, rbuf[2]);
  142. input_report_abs(data->input_dev, ABS_RUDDER, rbuf[4]);
  143. }
  144. /* Report acceleration sensor information */
  145. if (a_flag) {
  146. input_report_abs(data->input_dev, ABS_X, rbuf[6]);
  147. input_report_abs(data->input_dev, ABS_Y, rbuf[7]);
  148. input_report_abs(data->input_dev, ABS_Z, rbuf[8]);
  149. input_report_abs(data->input_dev, ABS_WHEEL, rbuf[5]);
  150. }
  151. /* Report temperature information */
  152. if (t_flag)
  153. input_report_abs(data->input_dev, ABS_THROTTLE, rbuf[3]);
  154. if (mv_flag) {
  155. input_report_abs(data->input_dev, ABS_HAT0X, rbuf[9]);
  156. input_report_abs(data->input_dev, ABS_HAT0Y, rbuf[10]);
  157. input_report_abs(data->input_dev, ABS_BRAKE, rbuf[11]);
  158. }
  159. mutex_unlock(&akm->flags_lock);
  160. input_sync(data->input_dev);
  161. }
  162. static void akm8975_ecs_close_done(struct akm8975_data *akm)
  163. {
  164. FUNCDBG("called");
  165. mutex_lock(&akm->flags_lock);
  166. m_flag = 1;
  167. a_flag = 1;
  168. t_flag = 1;
  169. mv_flag = 1;
  170. mutex_unlock(&akm->flags_lock);
  171. }
  172. static int akm_aot_open(struct inode *inode, struct file *file)
  173. {
  174. int ret = -1;
  175. FUNCDBG("called");
  176. if (atomic_cmpxchg(&open_flag, 0, 1) == 0) {
  177. wake_up(&open_wq);
  178. ret = 0;
  179. }
  180. ret = nonseekable_open(inode, file);
  181. if (ret)
  182. return ret;
  183. file->private_data = akmd_data;
  184. return ret;
  185. }
  186. static int akm_aot_release(struct inode *inode, struct file *file)
  187. {
  188. FUNCDBG("called");
  189. atomic_set(&open_flag, 0);
  190. wake_up(&open_wq);
  191. return 0;
  192. }
  193. static int akm_aot_ioctl(struct inode *inode, struct file *file,
  194. unsigned int cmd, unsigned long arg)
  195. {
  196. void __user *argp = (void __user *) arg;
  197. short flag;
  198. struct akm8975_data *akm = file->private_data;
  199. FUNCDBG("called");
  200. switch (cmd) {
  201. case ECS_IOCTL_APP_SET_MFLAG:
  202. case ECS_IOCTL_APP_SET_AFLAG:
  203. case ECS_IOCTL_APP_SET_MVFLAG:
  204. if (copy_from_user(&flag, argp, sizeof(flag)))
  205. return -EFAULT;
  206. if (flag < 0 || flag > 1)
  207. return -EINVAL;
  208. break;
  209. case ECS_IOCTL_APP_SET_DELAY:
  210. if (copy_from_user(&flag, argp, sizeof(flag)))
  211. return -EFAULT;
  212. break;
  213. default:
  214. break;
  215. }
  216. mutex_lock(&akm->flags_lock);
  217. switch (cmd) {
  218. case ECS_IOCTL_APP_SET_MFLAG:
  219. m_flag = flag;
  220. break;
  221. case ECS_IOCTL_APP_GET_MFLAG:
  222. flag = m_flag;
  223. break;
  224. case ECS_IOCTL_APP_SET_AFLAG:
  225. a_flag = flag;
  226. break;
  227. case ECS_IOCTL_APP_GET_AFLAG:
  228. flag = a_flag;
  229. break;
  230. case ECS_IOCTL_APP_SET_MVFLAG:
  231. mv_flag = flag;
  232. break;
  233. case ECS_IOCTL_APP_GET_MVFLAG:
  234. flag = mv_flag;
  235. break;
  236. case ECS_IOCTL_APP_SET_DELAY:
  237. akmd_delay = flag;
  238. break;
  239. case ECS_IOCTL_APP_GET_DELAY:
  240. flag = akmd_delay;
  241. break;
  242. default:
  243. return -ENOTTY;
  244. }
  245. mutex_unlock(&akm->flags_lock);
  246. switch (cmd) {
  247. case ECS_IOCTL_APP_GET_MFLAG:
  248. case ECS_IOCTL_APP_GET_AFLAG:
  249. case ECS_IOCTL_APP_GET_MVFLAG:
  250. case ECS_IOCTL_APP_GET_DELAY:
  251. if (copy_to_user(argp, &flag, sizeof(flag)))
  252. return -EFAULT;
  253. break;
  254. default:
  255. break;
  256. }
  257. return 0;
  258. }
  259. static int akmd_open(struct inode *inode, struct file *file)
  260. {
  261. int err = 0;
  262. FUNCDBG("called");
  263. err = nonseekable_open(inode, file);
  264. if (err)
  265. return err;
  266. file->private_data = akmd_data;
  267. return 0;
  268. }
  269. static int akmd_release(struct inode *inode, struct file *file)
  270. {
  271. struct akm8975_data *akm = file->private_data;
  272. FUNCDBG("called");
  273. akm8975_ecs_close_done(akm);
  274. return 0;
  275. }
  276. static int akmd_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
  277. unsigned long arg)
  278. {
  279. void __user *argp = (void __user *) arg;
  280. char rwbuf[16];
  281. int ret = -1;
  282. int status;
  283. short value[12];
  284. short delay;
  285. struct akm8975_data *akm = file->private_data;
  286. FUNCDBG("called");
  287. switch (cmd) {
  288. case ECS_IOCTL_READ:
  289. case ECS_IOCTL_WRITE:
  290. if (copy_from_user(&rwbuf, argp, sizeof(rwbuf)))
  291. return -EFAULT;
  292. break;
  293. case ECS_IOCTL_SET_YPR:
  294. if (copy_from_user(&value, argp, sizeof(value)))
  295. return -EFAULT;
  296. break;
  297. default:
  298. break;
  299. }
  300. switch (cmd) {
  301. case ECS_IOCTL_READ:
  302. if (rwbuf[0] < 1)
  303. return -EINVAL;
  304. ret = akm8975_i2c_rxdata(akm, &rwbuf[1], rwbuf[0]);
  305. if (ret < 0)
  306. return ret;
  307. break;
  308. case ECS_IOCTL_WRITE:
  309. if (rwbuf[0] < 2)
  310. return -EINVAL;
  311. ret = akm8975_i2c_txdata(akm, &rwbuf[1], rwbuf[0]);
  312. if (ret < 0)
  313. return ret;
  314. break;
  315. case ECS_IOCTL_SET_YPR:
  316. akm8975_ecs_report_value(akm, value);
  317. break;
  318. case ECS_IOCTL_GET_OPEN_STATUS:
  319. wait_event_interruptible(open_wq,
  320. (atomic_read(&open_flag) != 0));
  321. status = atomic_read(&open_flag);
  322. break;
  323. case ECS_IOCTL_GET_CLOSE_STATUS:
  324. wait_event_interruptible(open_wq,
  325. (atomic_read(&open_flag) == 0));
  326. status = atomic_read(&open_flag);
  327. break;
  328. case ECS_IOCTL_GET_DELAY:
  329. delay = akmd_delay;
  330. break;
  331. default:
  332. FUNCDBG("Unknown cmd\n");
  333. return -ENOTTY;
  334. }
  335. switch (cmd) {
  336. case ECS_IOCTL_READ:
  337. if (copy_to_user(argp, &rwbuf, sizeof(rwbuf)))
  338. return -EFAULT;
  339. break;
  340. case ECS_IOCTL_GET_OPEN_STATUS:
  341. case ECS_IOCTL_GET_CLOSE_STATUS:
  342. if (copy_to_user(argp, &status, sizeof(status)))
  343. return -EFAULT;
  344. break;
  345. case ECS_IOCTL_GET_DELAY:
  346. if (copy_to_user(argp, &delay, sizeof(delay)))
  347. return -EFAULT;
  348. break;
  349. default:
  350. break;
  351. }
  352. return 0;
  353. }
  354. /* needed to clear the int. pin */
  355. static void akm_work_func(struct work_struct *work)
  356. {
  357. struct akm8975_data *akm =
  358. container_of(work, struct akm8975_data, work);
  359. FUNCDBG("called");
  360. enable_irq(akm->this_client->irq);
  361. }
  362. static irqreturn_t akm8975_interrupt(int irq, void *dev_id)
  363. {
  364. struct akm8975_data *akm = dev_id;
  365. FUNCDBG("called");
  366. disable_irq_nosync(akm->this_client->irq);
  367. schedule_work(&akm->work);
  368. return IRQ_HANDLED;
  369. }
  370. static int akm8975_power_off(struct akm8975_data *akm)
  371. {
  372. #if AK8975DRV_CALL_DBG
  373. pr_info("%s\n", __func__);
  374. #endif
  375. if (akm->pdata->power_off)
  376. akm->pdata->power_off();
  377. return 0;
  378. }
  379. static int akm8975_power_on(struct akm8975_data *akm)
  380. {
  381. int err;
  382. #if AK8975DRV_CALL_DBG
  383. pr_info("%s\n", __func__);
  384. #endif
  385. if (akm->pdata->power_on) {
  386. err = akm->pdata->power_on();
  387. if (err < 0)
  388. return err;
  389. }
  390. return 0;
  391. }
  392. static int akm8975_suspend(struct i2c_client *client, pm_message_t mesg)
  393. {
  394. struct akm8975_data *akm = i2c_get_clientdata(client);
  395. #if AK8975DRV_CALL_DBG
  396. pr_info("%s\n", __func__);
  397. #endif
  398. /* TO DO: might need more work after power mgmt
  399. is enabled */
  400. return akm8975_power_off(akm);
  401. }
  402. static int akm8975_resume(struct i2c_client *client)
  403. {
  404. struct akm8975_data *akm = i2c_get_clientdata(client);
  405. #if AK8975DRV_CALL_DBG
  406. pr_info("%s\n", __func__);
  407. #endif
  408. /* TO DO: might need more work after power mgmt
  409. is enabled */
  410. return akm8975_power_on(akm);
  411. }
  412. #ifdef CONFIG_HAS_EARLYSUSPEND
  413. static void akm8975_early_suspend(struct early_suspend *handler)
  414. {
  415. struct akm8975_data *akm;
  416. akm = container_of(handler, struct akm8975_data, early_suspend);
  417. #if AK8975DRV_CALL_DBG
  418. pr_info("%s\n", __func__);
  419. #endif
  420. akm8975_suspend(akm->this_client, PMSG_SUSPEND);
  421. }
  422. static void akm8975_early_resume(struct early_suspend *handler)
  423. {
  424. struct akm8975_data *akm;
  425. akm = container_of(handler, struct akm8975_data, early_suspend);
  426. #if AK8975DRV_CALL_DBG
  427. pr_info("%s\n", __func__);
  428. #endif
  429. akm8975_resume(akm->this_client);
  430. }
  431. #endif
  432. static int akm8975_init_client(struct i2c_client *client)
  433. {
  434. struct akm8975_data *data;
  435. int ret;
  436. data = i2c_get_clientdata(client);
  437. ret = request_irq(client->irq, akm8975_interrupt, IRQF_TRIGGER_RISING,
  438. "akm8975", data);
  439. if (ret < 0) {
  440. pr_err("akm8975_init_client: request irq failed\n");
  441. goto err;
  442. }
  443. init_waitqueue_head(&open_wq);
  444. mutex_lock(&data->flags_lock);
  445. m_flag = 1;
  446. a_flag = 1;
  447. t_flag = 1;
  448. mv_flag = 1;
  449. mutex_unlock(&data->flags_lock);
  450. return 0;
  451. err:
  452. return ret;
  453. }
  454. static const struct file_operations akmd_fops = {
  455. .owner = THIS_MODULE,
  456. .open = akmd_open,
  457. .release = akmd_release,
  458. .ioctl = akmd_ioctl,
  459. };
  460. static const struct file_operations akm_aot_fops = {
  461. .owner = THIS_MODULE,
  462. .open = akm_aot_open,
  463. .release = akm_aot_release,
  464. .ioctl = akm_aot_ioctl,
  465. };
  466. static struct miscdevice akm_aot_device = {
  467. .minor = MISC_DYNAMIC_MINOR,
  468. .name = "akm8975_aot",
  469. .fops = &akm_aot_fops,
  470. };
  471. static struct miscdevice akmd_device = {
  472. .minor = MISC_DYNAMIC_MINOR,
  473. .name = "akm8975_dev",
  474. .fops = &akmd_fops,
  475. };
  476. int akm8975_probe(struct i2c_client *client,
  477. const struct i2c_device_id *devid)
  478. {
  479. struct akm8975_data *akm;
  480. int err;
  481. FUNCDBG("called");
  482. if (client->dev.platform_data == NULL) {
  483. dev_err(&client->dev, "platform data is NULL. exiting.\n");
  484. err = -ENODEV;
  485. goto exit_platform_data_null;
  486. }
  487. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  488. dev_err(&client->dev, "platform data is NULL. exiting.\n");
  489. err = -ENODEV;
  490. goto exit_check_functionality_failed;
  491. }
  492. akm = kzalloc(sizeof(struct akm8975_data), GFP_KERNEL);
  493. if (!akm) {
  494. dev_err(&client->dev,
  495. "failed to allocate memory for module data\n");
  496. err = -ENOMEM;
  497. goto exit_alloc_data_failed;
  498. }
  499. akm->pdata = client->dev.platform_data;
  500. mutex_init(&akm->flags_lock);
  501. INIT_WORK(&akm->work, akm_work_func);
  502. i2c_set_clientdata(client, akm);
  503. err = akm8975_power_on(akm);
  504. if (err < 0)
  505. goto exit_power_on_failed;
  506. akm8975_init_client(client);
  507. akm->this_client = client;
  508. akmd_data = akm;
  509. akm->input_dev = input_allocate_device();
  510. if (!akm->input_dev) {
  511. err = -ENOMEM;
  512. dev_err(&akm->this_client->dev,
  513. "input device allocate failed\n");
  514. goto exit_input_dev_alloc_failed;
  515. }
  516. set_bit(EV_ABS, akm->input_dev->evbit);
  517. /* yaw */
  518. input_set_abs_params(akm->input_dev, ABS_RX, 0, 23040, 0, 0);
  519. /* pitch */
  520. input_set_abs_params(akm->input_dev, ABS_RY, -11520, 11520, 0, 0);
  521. /* roll */
  522. input_set_abs_params(akm->input_dev, ABS_RZ, -5760, 5760, 0, 0);
  523. /* x-axis acceleration */
  524. input_set_abs_params(akm->input_dev, ABS_X, -5760, 5760, 0, 0);
  525. /* y-axis acceleration */
  526. input_set_abs_params(akm->input_dev, ABS_Y, -5760, 5760, 0, 0);
  527. /* z-axis acceleration */
  528. input_set_abs_params(akm->input_dev, ABS_Z, -5760, 5760, 0, 0);
  529. /* temparature */
  530. input_set_abs_params(akm->input_dev, ABS_THROTTLE, -30, 85, 0, 0);
  531. /* status of magnetic sensor */
  532. input_set_abs_params(akm->input_dev, ABS_RUDDER, 0, 3, 0, 0);
  533. /* status of acceleration sensor */
  534. input_set_abs_params(akm->input_dev, ABS_WHEEL, 0, 3, 0, 0);
  535. /* x-axis of raw magnetic vector */
  536. input_set_abs_params(akm->input_dev, ABS_HAT0X, -20480, 20479, 0, 0);
  537. /* y-axis of raw magnetic vector */
  538. input_set_abs_params(akm->input_dev, ABS_HAT0Y, -20480, 20479, 0, 0);
  539. /* z-axis of raw magnetic vector */
  540. input_set_abs_params(akm->input_dev, ABS_BRAKE, -20480, 20479, 0, 0);
  541. akm->input_dev->name = "compass";
  542. err = input_register_device(akm->input_dev);
  543. if (err) {
  544. pr_err("akm8975_probe: Unable to register input device: %s\n",
  545. akm->input_dev->name);
  546. goto exit_input_register_device_failed;
  547. }
  548. err = misc_register(&akmd_device);
  549. if (err) {
  550. pr_err("akm8975_probe: akmd_device register failed\n");
  551. goto exit_misc_device_register_failed;
  552. }
  553. err = misc_register(&akm_aot_device);
  554. if (err) {
  555. pr_err("akm8975_probe: akm_aot_device register failed\n");
  556. goto exit_misc_device_register_failed;
  557. }
  558. err = device_create_file(&client->dev, &dev_attr_akm_ms1);
  559. #ifdef CONFIG_HAS_EARLYSUSPEND
  560. akm->early_suspend.suspend = akm8975_early_suspend;
  561. akm->early_suspend.resume = akm8975_early_resume;
  562. register_early_suspend(&akm->early_suspend);
  563. #endif
  564. return 0;
  565. exit_misc_device_register_failed:
  566. exit_input_register_device_failed:
  567. input_free_device(akm->input_dev);
  568. exit_input_dev_alloc_failed:
  569. akm8975_power_off(akm);
  570. exit_power_on_failed:
  571. kfree(akm);
  572. exit_alloc_data_failed:
  573. exit_check_functionality_failed:
  574. exit_platform_data_null:
  575. return err;
  576. }
  577. static int __devexit akm8975_remove(struct i2c_client *client)
  578. {
  579. struct akm8975_data *akm = i2c_get_clientdata(client);
  580. FUNCDBG("called");
  581. free_irq(client->irq, NULL);
  582. input_unregister_device(akm->input_dev);
  583. misc_deregister(&akmd_device);
  584. misc_deregister(&akm_aot_device);
  585. akm8975_power_off(akm);
  586. kfree(akm);
  587. return 0;
  588. }
  589. static const struct i2c_device_id akm8975_id[] = {
  590. { "akm8975", 0 },
  591. { }
  592. };
  593. MODULE_DEVICE_TABLE(i2c, akm8975_id);
  594. static struct i2c_driver akm8975_driver = {
  595. .probe = akm8975_probe,
  596. .remove = akm8975_remove,
  597. #ifndef CONFIG_HAS_EARLYSUSPEND
  598. .resume = akm8975_resume,
  599. .suspend = akm8975_suspend,
  600. #endif
  601. .id_table = akm8975_id,
  602. .driver = {
  603. .name = "akm8975",
  604. },
  605. };
  606. static int __init akm8975_init(void)
  607. {
  608. pr_info("AK8975 compass driver: init\n");
  609. FUNCDBG("AK8975 compass driver: init\n");
  610. return i2c_add_driver(&akm8975_driver);
  611. }
  612. static void __exit akm8975_exit(void)
  613. {
  614. FUNCDBG("AK8975 compass driver: exit\n");
  615. i2c_del_driver(&akm8975_driver);
  616. }
  617. module_init(akm8975_init);
  618. module_exit(akm8975_exit);
  619. MODULE_AUTHOR("Hou-Kun Chen <hk_chen@htc.com>");
  620. MODULE_DESCRIPTION("AK8975 compass driver");
  621. MODULE_LICENSE("GPL");