marimba-tsadc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * Marimba TSADC driver.
  3. *
  4. * Copyright (c) 2009-2010, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  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. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/err.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/clk.h>
  21. #include <linux/mfd/marimba.h>
  22. #include <linux/mfd/marimba-tsadc.h>
  23. #include <linux/pm.h>
  24. #include <linux/slab.h>
  25. #if defined(CONFIG_HAS_EARLYSUSPEND)
  26. #include <linux/earlysuspend.h>
  27. #endif
  28. /* marimba configuration block: TS_CTL0 */
  29. #define TS_CTL0 0xFF
  30. #define TS_CTL0_RESET BIT(0)
  31. #define TS_CTL0_CLK_EN BIT(1)
  32. #define TS_CTL0_XO_EN BIT(2)
  33. #define TS_CTL0_EOC_EN BIT(3)
  34. #define TS_CTL0_PENIRQ_EN BIT(4)
  35. /* TSADC registers */
  36. #define SSBI_PRESET 0x00
  37. #define TSHK_DIG_CONFIG 0x4F
  38. #define TSHK_INTF_CONFIG 0x50
  39. #define TSHK_SETUP 0x51
  40. #define TSHK_SETUP_EN_ADC BIT(0)
  41. #define TSHK_SETUP_EN_PIRQ BIT(7)
  42. #define TSHK_PARAM 0x52
  43. #define TSHK_DATA_RD 0x53
  44. #define TSHK_STATUS 0x54
  45. #define TSHK_SETUP2 0x55
  46. #define TSHK_RSV1 0x56
  47. #define TSHK_RSV1_PRECHARGE_EN BIT(0)
  48. #define TSHK_COMMAND 0x57
  49. #define TSHK_PARAM2 0x58
  50. #define TSHK_INPUT_CLK_MASK 0x3F
  51. #define TSHK_SAMPLE_PRD_MASK 0xC7
  52. #define TSHK_INPUT_CLK_SHIFT 0x6
  53. #define TSHK_SAMPLE_PRD_SHIFT 0x3
  54. #define TSHK_PARAM3 0x59
  55. #define TSHK_PARAM3_MODE_MASK 0xFC
  56. #define TSHK_PARAM3_PRE_CHG_SHIFT (5)
  57. #define TSHK_PARAM3_STABIZ_SHIFT (2)
  58. #define TSHK_STABLE_TIME_MASK 0xE3
  59. #define TSHK_PRECHG_TIME_MASK 0x1F
  60. #define TSHK_PARAM4 0x5A
  61. #define TSHK_RSV2 0x5B
  62. #define TSHK_RSV3 0x5C
  63. #define TSHK_RSV4 0x5D
  64. #define TSHK_RSV5 0x5E
  65. struct marimba_tsadc_client {
  66. unsigned int is_ts;
  67. struct platform_device *pdev;
  68. };
  69. struct marimba_tsadc {
  70. struct marimba *marimba;
  71. struct device *dev;
  72. struct marimba_tsadc_platform_data *pdata;
  73. struct clk *codec_ssbi;
  74. struct device *child_tssc;
  75. bool clk_enabled;
  76. #if defined(CONFIG_HAS_EARLYSUSPEND)
  77. struct early_suspend early_suspend;
  78. #endif
  79. };
  80. static struct marimba_tsadc *tsadc_dev;
  81. static int marimba_write_u8(struct marimba_tsadc *tsadc, u8 reg, u8 data)
  82. {
  83. int rc;
  84. tsadc->marimba->mod_id = MARIMBA_SLAVE_ID_MARIMBA;
  85. rc = marimba_write(tsadc->marimba, reg, &data, 1);
  86. if (!rc)
  87. dev_warn(tsadc->dev, "Error writing marimba reg %X - ret %X\n",
  88. reg, data);
  89. return 0;
  90. }
  91. static int marimba_tsadc_write(struct marimba_tsadc *tsadc, u8 reg, u8 data)
  92. {
  93. int rc;
  94. tsadc->marimba->mod_id = MARIMBA_ID_TSADC;
  95. rc = marimba_ssbi_write(tsadc->marimba, reg, &data, 1);
  96. if (!rc)
  97. dev_warn(tsadc->dev, "Error writing marimba reg %X - ret %X\n",
  98. reg, data);
  99. return rc;
  100. }
  101. static int marimba_tsadc_shutdown(struct marimba_tsadc *tsadc)
  102. {
  103. u8 val;
  104. int rc;
  105. /* force reset */
  106. val = TS_CTL0_XO_EN | TS_CTL0_EOC_EN | TS_CTL0_PENIRQ_EN |
  107. TS_CTL0_CLK_EN;
  108. rc = marimba_write_u8(tsadc, TS_CTL0, val);
  109. if (rc < 0)
  110. return rc;
  111. /* disable xo, clock */
  112. val = TS_CTL0_PENIRQ_EN | TS_CTL0_EOC_EN;
  113. rc = marimba_write_u8(tsadc, TS_CTL0, val);
  114. if (rc < 0)
  115. return rc;
  116. /* de-vote S2 1.3v */
  117. if (tsadc->pdata->level_vote)
  118. /* REVISIT: Ignore error for level_vote(0) for now*/
  119. tsadc->pdata->level_vote(0);
  120. return 0;
  121. }
  122. static int marimba_tsadc_startup(struct marimba_tsadc *tsadc)
  123. {
  124. u8 val;
  125. int rc = 0;
  126. /* vote for S2 1.3v */
  127. if (tsadc->pdata->level_vote) {
  128. rc = tsadc->pdata->level_vote(1);
  129. if (rc < 0)
  130. return rc;
  131. }
  132. /* disable XO, clock and output enables */
  133. rc = marimba_write_u8(tsadc, TS_CTL0, 0x00);
  134. if (rc < 0)
  135. goto fail_marimba_write;
  136. /* Enable output enables */
  137. val = TS_CTL0_XO_EN | TS_CTL0_EOC_EN | TS_CTL0_PENIRQ_EN;
  138. rc = marimba_write_u8(tsadc, TS_CTL0, val);
  139. if (rc < 0)
  140. goto fail_marimba_write;
  141. /* Enable clock */
  142. val = val | TS_CTL0_CLK_EN;
  143. rc = marimba_write_u8(tsadc, TS_CTL0, val);
  144. if (rc < 0)
  145. goto fail_marimba_write;
  146. /* remove reset */
  147. val = val | TS_CTL0_RESET;
  148. rc = marimba_write_u8(tsadc, TS_CTL0, val);
  149. if (rc < 0)
  150. goto fail_marimba_write;
  151. return 0;
  152. fail_marimba_write:
  153. if (tsadc->pdata->level_vote)
  154. /* REVISIT: Ignore error for level_vote(0) for now*/
  155. tsadc->pdata->level_vote(0);
  156. return rc;
  157. }
  158. static int marimba_tsadc_configure(struct marimba_tsadc *tsadc)
  159. {
  160. u8 rsv1 = 0, setup = 0, i, count = 0;
  161. u8 param2 = 0, param3 = 0;
  162. unsigned long val;
  163. int rc;
  164. rc = marimba_tsadc_write(tsadc, SSBI_PRESET, 0x00);
  165. if (rc < 0)
  166. return rc;
  167. if (!tsadc->pdata)
  168. return -EINVAL;
  169. /* Configure RSV1 register*/
  170. if (tsadc->pdata->tsadc_prechg_en == true)
  171. rsv1 |= TSHK_RSV1_PRECHARGE_EN;
  172. else
  173. rsv1 &= ~TSHK_RSV1_PRECHARGE_EN;
  174. /* Set RSV1 register*/
  175. rc = marimba_tsadc_write(tsadc, TSHK_RSV1, rsv1);
  176. if (rc < 0)
  177. return rc;
  178. /* Configure PARAM2 register */
  179. /* Input clk */
  180. val = tsadc->pdata->params2.input_clk_khz;
  181. param2 &= TSHK_INPUT_CLK_MASK;
  182. val /= 600;
  183. if (val >= 1 && val <= 8 && !(val & (val - 1))) {
  184. /* Input clk can be .6, 1.2, 2.4, 4.8Mhz */
  185. if (val % 4 != 0)
  186. param2 = (4 - (val % 4)) << TSHK_INPUT_CLK_SHIFT;
  187. else
  188. param2 = ((val / 4) - 1) << TSHK_INPUT_CLK_SHIFT;
  189. } else /* Configure the default clk 2.4Mhz */
  190. param2 = 0x00 << TSHK_INPUT_CLK_SHIFT;
  191. /* Sample period */
  192. param2 &= TSHK_SAMPLE_PRD_MASK;
  193. param2 |= tsadc->pdata->params2.sample_prd << TSHK_SAMPLE_PRD_SHIFT;
  194. /* Write PARAM2 register */
  195. rc = marimba_tsadc_write(tsadc, TSHK_PARAM2, param2);
  196. if (rc < 0)
  197. return rc;
  198. /* REVISIT: If Precharge time, stabilization time > 409.6us */
  199. /* Configure PARAM3 register */
  200. val = tsadc->pdata->params3.prechg_time_nsecs;
  201. param3 &= TSHK_PRECHG_TIME_MASK;
  202. val /= 6400;
  203. if (val >= 1 && val <= 64 && !(val & (val - 1))) {
  204. count = 0;
  205. while ((val = val >> 1) != 0)
  206. count++;
  207. param3 |= count << TSHK_PARAM3_PRE_CHG_SHIFT;
  208. } else /* Set default value if the input is wrong */
  209. param3 |= 0x00 << TSHK_PARAM3_PRE_CHG_SHIFT;
  210. val = tsadc->pdata->params3.stable_time_nsecs;
  211. param3 &= TSHK_STABLE_TIME_MASK;
  212. val /= 6400;
  213. if (val >= 1 && val <= 64 && !(val & (val - 1))) {
  214. count = 0;
  215. while ((val = val >> 1) != 0)
  216. count++;
  217. param3 |= count << TSHK_PARAM3_STABIZ_SHIFT;
  218. } else /* Set default value if the input is wrong */
  219. param3 |= 0x00 << TSHK_PARAM3_STABIZ_SHIFT;
  220. /* Get TSADC mode */
  221. val = tsadc->pdata->params3.tsadc_test_mode;
  222. param3 &= TSHK_PARAM3_MODE_MASK;
  223. if (val == 0)
  224. param3 |= 0x00;
  225. else
  226. for (i = 0; i < 3 ; i++) {
  227. if (((val + i) % 39322) == 0) {
  228. param3 |= (i + 1);
  229. break;
  230. }
  231. }
  232. if (i == 3) /* Set to normal mode if input is wrong */
  233. param3 |= 0x00;
  234. rc = marimba_tsadc_write(tsadc, TSHK_PARAM3, param3);
  235. if (rc < 0)
  236. return rc;
  237. /* Configure TSHK SETUP Register */
  238. if (tsadc->pdata->setup.pen_irq_en == true)
  239. setup |= TSHK_SETUP_EN_PIRQ;
  240. else
  241. setup &= ~TSHK_SETUP_EN_PIRQ;
  242. if (tsadc->pdata->setup.tsadc_en == true)
  243. setup |= TSHK_SETUP_EN_ADC;
  244. else
  245. setup &= ~TSHK_SETUP_EN_ADC;
  246. /* Enable signals to ADC, pen irq assertion */
  247. rc = marimba_tsadc_write(tsadc, TSHK_SETUP, setup);
  248. if (rc < 0)
  249. return rc;
  250. return 0;
  251. }
  252. int marimba_tsadc_start(struct marimba_tsadc_client *client)
  253. {
  254. int rc = 0;
  255. if (!client) {
  256. pr_err("%s: Not a valid client\n", __func__);
  257. return -ENODEV;
  258. }
  259. if (!tsadc_dev) {
  260. dev_err(&client->pdev->dev,
  261. "%s: No tsadc device available\n", __func__);
  262. return -ENODEV;
  263. }
  264. /* REVISIT - add locks */
  265. if (client->is_ts) {
  266. rc = marimba_tsadc_startup(tsadc_dev);
  267. if (rc < 0)
  268. goto fail_tsadc_startup;
  269. rc = marimba_tsadc_configure(tsadc_dev);
  270. if (rc < 0)
  271. goto fail_tsadc_conf;
  272. }
  273. return 0;
  274. fail_tsadc_conf:
  275. marimba_tsadc_shutdown(tsadc_dev);
  276. fail_tsadc_startup:
  277. return rc;
  278. }
  279. EXPORT_SYMBOL(marimba_tsadc_start);
  280. struct marimba_tsadc_client *
  281. marimba_tsadc_register(struct platform_device *pdev, unsigned int is_ts)
  282. {
  283. struct marimba_tsadc_client *client;
  284. if (!pdev) {
  285. pr_err("%s: valid platform device pointer please\n", __func__);
  286. return ERR_PTR(-EINVAL);
  287. }
  288. if (!is_ts) {
  289. dev_err(&pdev->dev, "%s: only TS right now\n", __func__);
  290. return ERR_PTR(-EINVAL);
  291. }
  292. if (!tsadc_dev) {
  293. dev_err(&pdev->dev,
  294. "%s: No tsadc device available\n", __func__);
  295. return ERR_PTR(-ENODEV);
  296. }
  297. client = kzalloc(sizeof *client, GFP_KERNEL);
  298. if (!client)
  299. return ERR_PTR(-ENOMEM);
  300. client->pdev = pdev;
  301. client->is_ts = is_ts;
  302. return client;
  303. }
  304. EXPORT_SYMBOL(marimba_tsadc_register);
  305. void marimba_tsadc_unregister(struct marimba_tsadc_client *client)
  306. {
  307. if (client->is_ts)
  308. marimba_tsadc_shutdown(tsadc_dev);
  309. kfree(client);
  310. }
  311. EXPORT_SYMBOL(marimba_tsadc_unregister);
  312. static struct resource resources_tssc[] = {
  313. {
  314. .start = 0xAD300000,
  315. .end = 0xAD300000 + SZ_4K - 1,
  316. .name = "tssc",
  317. .flags = IORESOURCE_MEM,
  318. },
  319. {
  320. .start = 55,
  321. .end = 55,
  322. .name = "tssc1",
  323. .flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING,
  324. },
  325. {
  326. .start = 56,
  327. .end = 56,
  328. .name = "tssc2",
  329. .flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING,
  330. },
  331. };
  332. static struct device *
  333. marimba_add_tssc_subdev(struct device *parent, const char *name, int num,
  334. struct resource *resources, int num_resources,
  335. void *pdata, int pdata_len)
  336. {
  337. struct platform_device *pdev;
  338. int status;
  339. pdev = platform_device_alloc(name, num);
  340. if (!pdev) {
  341. dev_dbg(parent, "can't alloc dev\n");
  342. status = -ENOMEM;
  343. goto err;
  344. }
  345. pdev->dev.parent = parent;
  346. if (pdata) {
  347. status = platform_device_add_data(pdev, pdata, pdata_len);
  348. if (status < 0) {
  349. dev_dbg(&pdev->dev, "can't add platform_data\n");
  350. goto err;
  351. }
  352. }
  353. status = platform_device_add_resources(pdev, resources, num_resources);
  354. if (status < 0) {
  355. dev_dbg(&pdev->dev, "can't add resources\n");
  356. goto err;
  357. }
  358. status = platform_device_add(pdev);
  359. err:
  360. if (status < 0) {
  361. platform_device_put(pdev);
  362. dev_err(parent, "can't add %s dev\n", name);
  363. return ERR_PTR(status);
  364. }
  365. return &pdev->dev;
  366. }
  367. #ifdef CONFIG_PM
  368. static int
  369. marimba_tsadc_suspend(struct device *dev)
  370. {
  371. int rc = 0, ret = 0;
  372. struct marimba_tsadc *tsadc = dev_get_drvdata(dev);
  373. if (tsadc->clk_enabled == true) {
  374. clk_disable_unprepare(tsadc->codec_ssbi);
  375. tsadc->clk_enabled = false;
  376. }
  377. if (!(device_may_wakeup(dev) &&
  378. device_may_wakeup(tsadc->child_tssc))) {
  379. rc = marimba_tsadc_shutdown(tsadc);
  380. if (rc < 0) {
  381. pr_err("%s: Unable to shutdown TSADC\n", __func__);
  382. goto fail_shutdown;
  383. }
  384. if (tsadc->pdata->marimba_tsadc_power) {
  385. rc = tsadc->pdata->marimba_tsadc_power(0);
  386. if (rc < 0)
  387. goto fail_tsadc_power;
  388. }
  389. }
  390. return rc;
  391. fail_tsadc_power:
  392. marimba_tsadc_startup(tsadc_dev);
  393. marimba_tsadc_configure(tsadc_dev);
  394. fail_shutdown:
  395. if (tsadc->clk_enabled == false) {
  396. ret = clk_prepare_enable(tsadc->codec_ssbi);
  397. if (ret == 0)
  398. tsadc->clk_enabled = true;
  399. }
  400. return rc;
  401. }
  402. static int marimba_tsadc_resume(struct device *dev)
  403. {
  404. int rc = 0;
  405. struct marimba_tsadc *tsadc = dev_get_drvdata(dev);
  406. if (tsadc->clk_enabled == false) {
  407. rc = clk_prepare_enable(tsadc->codec_ssbi);
  408. if (rc != 0) {
  409. pr_err("%s: Clk enable failed\n", __func__);
  410. return rc;
  411. }
  412. tsadc->clk_enabled = true;
  413. }
  414. if (!(device_may_wakeup(dev) &&
  415. device_may_wakeup(tsadc->child_tssc))) {
  416. if (tsadc->pdata->marimba_tsadc_power) {
  417. rc = tsadc->pdata->marimba_tsadc_power(1);
  418. if (rc) {
  419. pr_err("%s: Unable to power on TSADC \n",
  420. __func__);
  421. goto fail_tsadc_power;
  422. }
  423. }
  424. rc = marimba_tsadc_startup(tsadc_dev);
  425. if (rc < 0) {
  426. pr_err("%s: Unable to startup TSADC\n", __func__);
  427. goto fail_tsadc_startup;
  428. }
  429. rc = marimba_tsadc_configure(tsadc_dev);
  430. if (rc < 0) {
  431. pr_err("%s: Unable to configure TSADC\n", __func__);
  432. goto fail_tsadc_configure;
  433. }
  434. }
  435. return rc;
  436. fail_tsadc_configure:
  437. marimba_tsadc_shutdown(tsadc_dev);
  438. fail_tsadc_startup:
  439. if (tsadc->pdata->marimba_tsadc_power)
  440. tsadc->pdata->marimba_tsadc_power(0);
  441. fail_tsadc_power:
  442. if (tsadc->clk_enabled == true) {
  443. clk_disable_unprepare(tsadc->codec_ssbi);
  444. tsadc->clk_enabled = false;
  445. }
  446. return rc;
  447. }
  448. static struct dev_pm_ops tsadc_pm_ops = {
  449. #ifndef CONFIG_HAS_EARLYSUSPEND
  450. .suspend = marimba_tsadc_suspend,
  451. .resume = marimba_tsadc_resume,
  452. #endif
  453. };
  454. #endif
  455. #ifdef CONFIG_HAS_EARLYSUSPEND
  456. static void marimba_tsadc_early_suspend(struct early_suspend *h)
  457. {
  458. struct marimba_tsadc *tsadc = container_of(h, struct marimba_tsadc,
  459. early_suspend);
  460. marimba_tsadc_suspend(tsadc->dev);
  461. }
  462. static void marimba_tsadc_late_resume(struct early_suspend *h)
  463. {
  464. struct marimba_tsadc *tsadc = container_of(h, struct marimba_tsadc,
  465. early_suspend);
  466. marimba_tsadc_resume(tsadc->dev);
  467. }
  468. #endif
  469. static int __devinit marimba_tsadc_probe(struct platform_device *pdev)
  470. {
  471. struct marimba *marimba = platform_get_drvdata(pdev);
  472. struct marimba_tsadc *tsadc;
  473. struct marimba_tsadc_platform_data *pdata = pdev->dev.platform_data;
  474. int rc = 0;
  475. struct device *child;
  476. printk("%s\n", __func__);
  477. if (!pdata) {
  478. dev_dbg(&pdev->dev, "no tsadc platform data?\n");
  479. return -EINVAL;
  480. }
  481. tsadc = kzalloc(sizeof *tsadc, GFP_KERNEL);
  482. if (!tsadc)
  483. return -ENOMEM;
  484. tsadc->marimba = marimba;
  485. tsadc->dev = &pdev->dev;
  486. tsadc->pdata = pdata;
  487. platform_set_drvdata(pdev, tsadc);
  488. if (tsadc->pdata->init) {
  489. rc = tsadc->pdata->init();
  490. if (rc < 0)
  491. goto fail_tsadc_init;
  492. }
  493. if (tsadc->pdata->marimba_tsadc_power) {
  494. rc = tsadc->pdata->marimba_tsadc_power(1);
  495. if (rc) {
  496. pr_err("%s: Unable to power up TSADC \n", __func__);
  497. goto fail_tsadc_power;
  498. }
  499. }
  500. tsadc->codec_ssbi = clk_get(NULL, "codec_ssbi_clk");
  501. if (IS_ERR(tsadc->codec_ssbi)) {
  502. rc = PTR_ERR(tsadc->codec_ssbi);
  503. goto fail_clk_get;
  504. }
  505. rc = clk_prepare_enable(tsadc->codec_ssbi);
  506. if (rc != 0)
  507. goto fail_clk_enable;
  508. tsadc->clk_enabled = true;
  509. child = marimba_add_tssc_subdev(&pdev->dev, "msm_touchscreen", -1,
  510. resources_tssc, ARRAY_SIZE(resources_tssc),
  511. pdata->tssc_data, sizeof(*pdata->tssc_data));
  512. if (IS_ERR(child)) {
  513. rc = PTR_ERR(child);
  514. goto fail_add_subdev;
  515. }
  516. tsadc->child_tssc = child;
  517. platform_set_drvdata(pdev, tsadc);
  518. #ifdef CONFIG_HAS_EARLYSUSPEND
  519. tsadc->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN +
  520. TSADC_SUSPEND_LEVEL;
  521. tsadc->early_suspend.suspend = marimba_tsadc_early_suspend;
  522. tsadc->early_suspend.resume = marimba_tsadc_late_resume;
  523. register_early_suspend(&tsadc->early_suspend);
  524. #endif
  525. tsadc_dev = tsadc;
  526. device_init_wakeup(&pdev->dev, pdata->can_wakeup);
  527. return rc;
  528. fail_add_subdev:
  529. clk_disable_unprepare(tsadc->codec_ssbi);
  530. fail_clk_enable:
  531. clk_put(tsadc->codec_ssbi);
  532. fail_clk_get:
  533. if (tsadc->pdata->marimba_tsadc_power)
  534. rc = tsadc->pdata->marimba_tsadc_power(0);
  535. fail_tsadc_power:
  536. if (tsadc->pdata->exit)
  537. rc = tsadc->pdata->exit();
  538. fail_tsadc_init:
  539. kfree(tsadc);
  540. return rc;
  541. }
  542. static int __devexit marimba_tsadc_remove(struct platform_device *pdev)
  543. {
  544. int rc = 0;
  545. struct marimba_tsadc *tsadc = platform_get_drvdata(pdev);
  546. device_init_wakeup(&pdev->dev, 0);
  547. if (tsadc->clk_enabled == true)
  548. clk_disable_unprepare(tsadc->codec_ssbi);
  549. clk_put(tsadc->codec_ssbi);
  550. if (tsadc->pdata->exit)
  551. rc = tsadc->pdata->exit();
  552. if (tsadc->pdata->marimba_tsadc_power)
  553. rc = tsadc->pdata->marimba_tsadc_power(0);
  554. #ifdef CONFIG_HAS_EARLYSUSPEND
  555. unregister_early_suspend(&tsadc->early_suspend);
  556. #endif
  557. platform_set_drvdata(pdev, NULL);
  558. kfree(tsadc);
  559. return rc;
  560. }
  561. static struct platform_driver tsadc_driver = {
  562. .probe = marimba_tsadc_probe,
  563. .remove = __devexit_p(marimba_tsadc_remove),
  564. .driver = {
  565. .name = "marimba_tsadc",
  566. .owner = THIS_MODULE,
  567. #ifdef CONFIG_PM
  568. .pm = &tsadc_pm_ops,
  569. #endif
  570. },
  571. };
  572. static int __init marimba_tsadc_init(void)
  573. {
  574. return platform_driver_register(&tsadc_driver);
  575. }
  576. device_initcall(marimba_tsadc_init);
  577. static void __exit marimba_tsadc_exit(void)
  578. {
  579. return platform_driver_unregister(&tsadc_driver);
  580. }
  581. module_exit(marimba_tsadc_exit);
  582. MODULE_DESCRIPTION("Marimba TSADC driver");
  583. MODULE_VERSION("0.1");
  584. MODULE_LICENSE("GPL v2");
  585. MODULE_ALIAS("platform:marimba_tsadc");