extcon-arizona.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. /*
  2. * extcon-arizona.c - Extcon driver Wolfson Arizona devices
  3. *
  4. * Copyright (C) 2012 Wolfson Microelectronics plc
  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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/i2c.h>
  19. #include <linux/slab.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/err.h>
  22. #include <linux/gpio.h>
  23. #include <linux/input.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/regulator/consumer.h>
  27. #include <linux/extcon.h>
  28. #include <sound/soc.h>
  29. #include <linux/mfd/arizona/core.h>
  30. #include <linux/mfd/arizona/pdata.h>
  31. #include <linux/mfd/arizona/registers.h>
  32. #define ARIZONA_NUM_BUTTONS 6
  33. #define ARIZONA_ACCDET_MODE_MIC 0
  34. #define ARIZONA_ACCDET_MODE_HPL 1
  35. #define ARIZONA_ACCDET_MODE_HPR 2
  36. struct arizona_extcon_info {
  37. struct device *dev;
  38. struct arizona *arizona;
  39. struct mutex lock;
  40. struct regulator *micvdd;
  41. struct input_dev *input;
  42. int micd_mode;
  43. const struct arizona_micd_config *micd_modes;
  44. int micd_num_modes;
  45. bool micd_reva;
  46. bool micd_clamp;
  47. struct delayed_work hpdet_work;
  48. bool hpdet_active;
  49. bool hpdet_done;
  50. int num_hpdet_res;
  51. unsigned int hpdet_res[3];
  52. bool mic;
  53. bool detecting;
  54. int jack_flips;
  55. int hpdet_ip;
  56. struct extcon_dev edev;
  57. };
  58. static const struct arizona_micd_config micd_default_modes[] = {
  59. { 0, 2 << ARIZONA_MICD_BIAS_SRC_SHIFT, 1 },
  60. { ARIZONA_ACCDET_SRC, 1 << ARIZONA_MICD_BIAS_SRC_SHIFT, 0 },
  61. };
  62. static struct {
  63. u16 status;
  64. int report;
  65. } arizona_lvl_to_key[ARIZONA_NUM_BUTTONS] = {
  66. { 0x1, BTN_0 },
  67. { 0x2, BTN_1 },
  68. { 0x4, BTN_2 },
  69. { 0x8, BTN_3 },
  70. { 0x10, BTN_4 },
  71. { 0x20, BTN_5 },
  72. };
  73. #define ARIZONA_CABLE_MECHANICAL 0
  74. #define ARIZONA_CABLE_MICROPHONE 1
  75. #define ARIZONA_CABLE_HEADPHONE 2
  76. #define ARIZONA_CABLE_LINEOUT 3
  77. static const char *arizona_cable[] = {
  78. "Mechanical",
  79. "Microphone",
  80. "Headphone",
  81. "Line-out",
  82. NULL,
  83. };
  84. static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
  85. {
  86. struct arizona *arizona = info->arizona;
  87. if (arizona->pdata.micd_pol_gpio > 0)
  88. gpio_set_value_cansleep(arizona->pdata.micd_pol_gpio,
  89. info->micd_modes[mode].gpio);
  90. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  91. ARIZONA_MICD_BIAS_SRC_MASK,
  92. info->micd_modes[mode].bias);
  93. regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
  94. ARIZONA_ACCDET_SRC, info->micd_modes[mode].src);
  95. info->micd_mode = mode;
  96. dev_dbg(arizona->dev, "Set jack polarity to %d\n", mode);
  97. }
  98. static const char *arizona_extcon_get_micbias(struct arizona_extcon_info *info)
  99. {
  100. switch (info->micd_modes[0].bias >> ARIZONA_MICD_BIAS_SRC_SHIFT) {
  101. case 1:
  102. return "MICBIAS1";
  103. case 2:
  104. return "MICBIAS2";
  105. case 3:
  106. return "MICBIAS3";
  107. default:
  108. return "MICVDD";
  109. }
  110. }
  111. static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
  112. {
  113. struct arizona *arizona = info->arizona;
  114. const char *widget = arizona_extcon_get_micbias(info);
  115. struct snd_soc_dapm_context *dapm = arizona->dapm;
  116. int ret;
  117. mutex_lock(&dapm->card->dapm_mutex);
  118. ret = snd_soc_dapm_force_enable_pin(dapm, widget);
  119. if (ret != 0)
  120. dev_warn(arizona->dev, "Failed to enable %s: %d\n",
  121. widget, ret);
  122. mutex_unlock(&dapm->card->dapm_mutex);
  123. snd_soc_dapm_sync(dapm);
  124. if (!arizona->pdata.micd_force_micbias) {
  125. mutex_lock(&dapm->card->dapm_mutex);
  126. ret = snd_soc_dapm_disable_pin(arizona->dapm, widget);
  127. if (ret != 0)
  128. dev_warn(arizona->dev, "Failed to disable %s: %d\n",
  129. widget, ret);
  130. mutex_unlock(&dapm->card->dapm_mutex);
  131. snd_soc_dapm_sync(dapm);
  132. }
  133. }
  134. static void arizona_start_mic(struct arizona_extcon_info *info)
  135. {
  136. struct arizona *arizona = info->arizona;
  137. bool change;
  138. int ret;
  139. /* Microphone detection can't use idle mode */
  140. pm_runtime_get(info->dev);
  141. if (info->detecting) {
  142. ret = regulator_allow_bypass(info->micvdd, false);
  143. if (ret != 0) {
  144. dev_err(arizona->dev,
  145. "Failed to regulate MICVDD: %d\n",
  146. ret);
  147. }
  148. }
  149. ret = regulator_enable(info->micvdd);
  150. if (ret != 0) {
  151. dev_err(arizona->dev, "Failed to enable MICVDD: %d\n",
  152. ret);
  153. }
  154. if (info->micd_reva) {
  155. regmap_write(arizona->regmap, 0x80, 0x3);
  156. regmap_write(arizona->regmap, 0x294, 0);
  157. regmap_write(arizona->regmap, 0x80, 0x0);
  158. }
  159. regmap_update_bits(arizona->regmap,
  160. ARIZONA_ACCESSORY_DETECT_MODE_1,
  161. ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
  162. arizona_extcon_pulse_micbias(info);
  163. regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
  164. ARIZONA_MICD_ENA, ARIZONA_MICD_ENA,
  165. &change);
  166. if (!change) {
  167. regulator_disable(info->micvdd);
  168. pm_runtime_put_autosuspend(info->dev);
  169. }
  170. }
  171. static void arizona_stop_mic(struct arizona_extcon_info *info)
  172. {
  173. struct arizona *arizona = info->arizona;
  174. const char *widget = arizona_extcon_get_micbias(info);
  175. struct snd_soc_dapm_context *dapm = arizona->dapm;
  176. bool change;
  177. int ret;
  178. regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
  179. ARIZONA_MICD_ENA, 0,
  180. &change);
  181. mutex_lock(&dapm->card->dapm_mutex);
  182. ret = snd_soc_dapm_disable_pin(dapm, widget);
  183. if (ret != 0)
  184. dev_warn(arizona->dev,
  185. "Failed to disable %s: %d\n",
  186. widget, ret);
  187. mutex_unlock(&dapm->card->dapm_mutex);
  188. snd_soc_dapm_sync(dapm);
  189. if (info->micd_reva) {
  190. regmap_write(arizona->regmap, 0x80, 0x3);
  191. regmap_write(arizona->regmap, 0x294, 2);
  192. regmap_write(arizona->regmap, 0x80, 0x0);
  193. }
  194. ret = regulator_allow_bypass(info->micvdd, true);
  195. if (ret != 0) {
  196. dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
  197. ret);
  198. }
  199. if (change) {
  200. regulator_disable(info->micvdd);
  201. pm_runtime_mark_last_busy(info->dev);
  202. pm_runtime_put_autosuspend(info->dev);
  203. }
  204. }
  205. static struct {
  206. unsigned int factor_a;
  207. unsigned int factor_b;
  208. } arizona_hpdet_b_ranges[] = {
  209. { 5528, 362464 },
  210. { 11084, 6186851 },
  211. { 11065, 65460395 },
  212. };
  213. static struct {
  214. int min;
  215. int max;
  216. } arizona_hpdet_c_ranges[] = {
  217. { 0, 30 },
  218. { 8, 100 },
  219. { 100, 1000 },
  220. { 1000, 10000 },
  221. };
  222. static int arizona_hpdet_read(struct arizona_extcon_info *info)
  223. {
  224. struct arizona *arizona = info->arizona;
  225. unsigned int val, range;
  226. int ret;
  227. ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, &val);
  228. if (ret != 0) {
  229. dev_err(arizona->dev, "Failed to read HPDET status: %d\n",
  230. ret);
  231. return ret;
  232. }
  233. switch (info->hpdet_ip) {
  234. case 0:
  235. if (!(val & ARIZONA_HP_DONE)) {
  236. dev_err(arizona->dev, "HPDET did not complete: %x\n",
  237. val);
  238. return -EAGAIN;
  239. }
  240. val &= ARIZONA_HP_LVL_MASK;
  241. break;
  242. case 1:
  243. if (!(val & ARIZONA_HP_DONE_B)) {
  244. dev_err(arizona->dev, "HPDET did not complete: %x\n",
  245. val);
  246. return -EAGAIN;
  247. }
  248. ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val);
  249. if (ret != 0) {
  250. dev_err(arizona->dev, "Failed to read HP value: %d\n",
  251. ret);
  252. return -EAGAIN;
  253. }
  254. regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  255. &range);
  256. range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
  257. >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
  258. if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
  259. (val < 100 || val > 0x3fb)) {
  260. range++;
  261. dev_dbg(arizona->dev, "Moving to HPDET range %d\n",
  262. range);
  263. regmap_update_bits(arizona->regmap,
  264. ARIZONA_HEADPHONE_DETECT_1,
  265. ARIZONA_HP_IMPEDANCE_RANGE_MASK,
  266. range <<
  267. ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
  268. return -EAGAIN;
  269. }
  270. /* If we go out of range report top of range */
  271. if (val < 100 || val > 0x3fb) {
  272. dev_dbg(arizona->dev, "Measurement out of range\n");
  273. return 10000;
  274. }
  275. dev_dbg(arizona->dev, "HPDET read %d in range %d\n",
  276. val, range);
  277. val = arizona_hpdet_b_ranges[range].factor_b
  278. / ((val * 100) -
  279. arizona_hpdet_b_ranges[range].factor_a);
  280. break;
  281. default:
  282. dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n",
  283. info->hpdet_ip);
  284. case 2:
  285. if (!(val & ARIZONA_HP_DONE_B)) {
  286. dev_err(arizona->dev, "HPDET did not complete: %x\n",
  287. val);
  288. return -EAGAIN;
  289. }
  290. val &= ARIZONA_HP_LVL_B_MASK;
  291. regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  292. &range);
  293. range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
  294. >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
  295. /* Skip up or down a range? */
  296. if (range && (val < arizona_hpdet_c_ranges[range].min)) {
  297. range--;
  298. dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
  299. arizona_hpdet_c_ranges[range].min,
  300. arizona_hpdet_c_ranges[range].max);
  301. regmap_update_bits(arizona->regmap,
  302. ARIZONA_HEADPHONE_DETECT_1,
  303. ARIZONA_HP_IMPEDANCE_RANGE_MASK,
  304. range <<
  305. ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
  306. return -EAGAIN;
  307. }
  308. if (range < ARRAY_SIZE(arizona_hpdet_c_ranges) - 1 &&
  309. (val >= arizona_hpdet_c_ranges[range].max)) {
  310. range++;
  311. dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
  312. arizona_hpdet_c_ranges[range].min,
  313. arizona_hpdet_c_ranges[range].max);
  314. regmap_update_bits(arizona->regmap,
  315. ARIZONA_HEADPHONE_DETECT_1,
  316. ARIZONA_HP_IMPEDANCE_RANGE_MASK,
  317. range <<
  318. ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
  319. return -EAGAIN;
  320. }
  321. }
  322. dev_dbg(arizona->dev, "HP impedance %d ohms\n", val);
  323. return val;
  324. }
  325. static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
  326. {
  327. struct arizona *arizona = info->arizona;
  328. int id_gpio = arizona->pdata.hpdet_id_gpio;
  329. /*
  330. * If we're using HPDET for accessory identification we need
  331. * to take multiple measurements, step through them in sequence.
  332. */
  333. if (arizona->pdata.hpdet_acc_id) {
  334. info->hpdet_res[info->num_hpdet_res++] = *reading;
  335. /*
  336. * If the impedence is too high don't measure the
  337. * second ground.
  338. */
  339. if (info->num_hpdet_res == 1 && *reading >= 45) {
  340. dev_dbg(arizona->dev, "Skipping ground flip\n");
  341. info->hpdet_res[info->num_hpdet_res++] = *reading;
  342. }
  343. if (info->num_hpdet_res == 1) {
  344. dev_dbg(arizona->dev, "Flipping ground\n");
  345. regmap_update_bits(arizona->regmap,
  346. ARIZONA_ACCESSORY_DETECT_MODE_1,
  347. ARIZONA_ACCDET_SRC,
  348. ~info->micd_modes[0].src);
  349. regmap_update_bits(arizona->regmap,
  350. ARIZONA_HEADPHONE_DETECT_1,
  351. ARIZONA_HP_POLL, ARIZONA_HP_POLL);
  352. return -EAGAIN;
  353. }
  354. /* Only check the mic directly if we didn't already ID it */
  355. if (id_gpio && info->num_hpdet_res == 2 &&
  356. !((info->hpdet_res[0] > info->hpdet_res[1] * 2))) {
  357. dev_dbg(arizona->dev, "Measuring mic\n");
  358. regmap_update_bits(arizona->regmap,
  359. ARIZONA_ACCESSORY_DETECT_MODE_1,
  360. ARIZONA_ACCDET_MODE_MASK |
  361. ARIZONA_ACCDET_SRC,
  362. ARIZONA_ACCDET_MODE_HPR |
  363. info->micd_modes[0].src);
  364. gpio_set_value_cansleep(id_gpio, 1);
  365. regmap_update_bits(arizona->regmap,
  366. ARIZONA_HEADPHONE_DETECT_1,
  367. ARIZONA_HP_POLL, ARIZONA_HP_POLL);
  368. return -EAGAIN;
  369. }
  370. /* OK, got both. Now, compare... */
  371. dev_dbg(arizona->dev, "HPDET measured %d %d %d\n",
  372. info->hpdet_res[0], info->hpdet_res[1],
  373. info->hpdet_res[2]);
  374. /* Take the headphone impedance for the main report */
  375. *reading = info->hpdet_res[0];
  376. /*
  377. * Either the two grounds measure differently or we
  378. * measure the mic as high impedance.
  379. */
  380. if ((info->hpdet_res[0] > info->hpdet_res[1] * 2) ||
  381. (id_gpio && info->hpdet_res[2] > 10)) {
  382. dev_dbg(arizona->dev, "Detected mic\n");
  383. info->mic = true;
  384. info->detecting = true;
  385. } else {
  386. dev_dbg(arizona->dev, "Detected headphone\n");
  387. }
  388. /* Make sure everything is reset back to the real polarity */
  389. regmap_update_bits(arizona->regmap,
  390. ARIZONA_ACCESSORY_DETECT_MODE_1,
  391. ARIZONA_ACCDET_SRC,
  392. info->micd_modes[0].src);
  393. }
  394. return 0;
  395. }
  396. static irqreturn_t arizona_hpdet_irq(int irq, void *data)
  397. {
  398. struct arizona_extcon_info *info = data;
  399. struct arizona *arizona = info->arizona;
  400. int id_gpio = arizona->pdata.hpdet_id_gpio;
  401. int report = ARIZONA_CABLE_HEADPHONE;
  402. unsigned int val;
  403. int ret, reading;
  404. mutex_lock(&info->lock);
  405. /* If we got a spurious IRQ for some reason then ignore it */
  406. if (!info->hpdet_active) {
  407. dev_warn(arizona->dev, "Spurious HPDET IRQ\n");
  408. mutex_unlock(&info->lock);
  409. return IRQ_NONE;
  410. }
  411. /* If the cable was removed while measuring ignore the result */
  412. ret = extcon_get_cable_state_(&info->edev, ARIZONA_CABLE_MECHANICAL);
  413. if (ret < 0) {
  414. dev_err(arizona->dev, "Failed to check cable state: %d\n",
  415. ret);
  416. goto out;
  417. } else if (!ret) {
  418. dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n");
  419. goto done;
  420. }
  421. ret = arizona_hpdet_read(info);
  422. if (ret == -EAGAIN) {
  423. goto out;
  424. } else if (ret < 0) {
  425. goto done;
  426. }
  427. reading = ret;
  428. /* Reset back to starting range */
  429. regmap_update_bits(arizona->regmap,
  430. ARIZONA_HEADPHONE_DETECT_1,
  431. ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
  432. 0);
  433. ret = arizona_hpdet_do_id(info, &reading);
  434. if (ret == -EAGAIN) {
  435. goto out;
  436. } else if (ret < 0) {
  437. goto done;
  438. }
  439. /* Report high impedence cables as line outputs */
  440. if (reading >= 5000)
  441. report = ARIZONA_CABLE_LINEOUT;
  442. else
  443. report = ARIZONA_CABLE_HEADPHONE;
  444. ret = extcon_set_cable_state_(&info->edev, report, true);
  445. if (ret != 0)
  446. dev_err(arizona->dev, "Failed to report HP/line: %d\n",
  447. ret);
  448. mutex_lock(&arizona->dapm->card->dapm_mutex);
  449. ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
  450. if (ret != 0) {
  451. dev_err(arizona->dev, "Failed to read output enables: %d\n",
  452. ret);
  453. val = 0;
  454. }
  455. if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
  456. ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0);
  457. if (ret != 0)
  458. dev_warn(arizona->dev, "Failed to undo magic: %d\n",
  459. ret);
  460. ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0);
  461. if (ret != 0)
  462. dev_warn(arizona->dev, "Failed to undo magic: %d\n",
  463. ret);
  464. }
  465. mutex_unlock(&arizona->dapm->card->dapm_mutex);
  466. done:
  467. if (id_gpio)
  468. gpio_set_value_cansleep(id_gpio, 0);
  469. /* Revert back to MICDET mode */
  470. regmap_update_bits(arizona->regmap,
  471. ARIZONA_ACCESSORY_DETECT_MODE_1,
  472. ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
  473. /* If we have a mic then reenable MICDET */
  474. if (info->mic)
  475. arizona_start_mic(info);
  476. if (info->hpdet_active) {
  477. pm_runtime_put_autosuspend(info->dev);
  478. info->hpdet_active = false;
  479. }
  480. info->hpdet_done = true;
  481. out:
  482. mutex_unlock(&info->lock);
  483. return IRQ_HANDLED;
  484. }
  485. static void arizona_identify_headphone(struct arizona_extcon_info *info)
  486. {
  487. struct arizona *arizona = info->arizona;
  488. int ret;
  489. if (info->hpdet_done)
  490. return;
  491. dev_dbg(arizona->dev, "Starting HPDET\n");
  492. /* Make sure we keep the device enabled during the measurement */
  493. pm_runtime_get(info->dev);
  494. info->hpdet_active = true;
  495. if (info->mic)
  496. arizona_stop_mic(info);
  497. ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0x4000);
  498. if (ret != 0)
  499. dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
  500. ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0x4000);
  501. if (ret != 0)
  502. dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
  503. ret = regmap_update_bits(arizona->regmap,
  504. ARIZONA_ACCESSORY_DETECT_MODE_1,
  505. ARIZONA_ACCDET_MODE_MASK,
  506. ARIZONA_ACCDET_MODE_HPL);
  507. if (ret != 0) {
  508. dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret);
  509. goto err;
  510. }
  511. ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  512. ARIZONA_HP_POLL, ARIZONA_HP_POLL);
  513. if (ret != 0) {
  514. dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
  515. ret);
  516. goto err;
  517. }
  518. return;
  519. err:
  520. regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
  521. ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
  522. /* Just report headphone */
  523. ret = extcon_update_state(&info->edev,
  524. 1 << ARIZONA_CABLE_HEADPHONE,
  525. 1 << ARIZONA_CABLE_HEADPHONE);
  526. if (ret != 0)
  527. dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
  528. if (info->mic)
  529. arizona_start_mic(info);
  530. info->hpdet_active = false;
  531. }
  532. static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
  533. {
  534. struct arizona *arizona = info->arizona;
  535. unsigned int val;
  536. int ret;
  537. dev_dbg(arizona->dev, "Starting identification via HPDET\n");
  538. /* Make sure we keep the device enabled during the measurement */
  539. pm_runtime_get_sync(info->dev);
  540. info->hpdet_active = true;
  541. arizona_extcon_pulse_micbias(info);
  542. mutex_lock(&arizona->dapm->card->dapm_mutex);
  543. ret = regmap_read(arizona->regmap, ARIZONA_OUTPUT_ENABLES_1, &val);
  544. if (ret != 0) {
  545. dev_err(arizona->dev, "Failed to read output enables: %d\n",
  546. ret);
  547. val = 0;
  548. }
  549. if (!(val & (ARIZONA_OUT1L_ENA | ARIZONA_OUT1R_ENA))) {
  550. ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000,
  551. 0x4000);
  552. if (ret != 0)
  553. dev_warn(arizona->dev, "Failed to do magic: %d\n",
  554. ret);
  555. ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000,
  556. 0x4000);
  557. if (ret != 0)
  558. dev_warn(arizona->dev, "Failed to do magic: %d\n",
  559. ret);
  560. }
  561. mutex_unlock(&arizona->dapm->card->dapm_mutex);
  562. ret = regmap_update_bits(arizona->regmap,
  563. ARIZONA_ACCESSORY_DETECT_MODE_1,
  564. ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK,
  565. info->micd_modes[0].src |
  566. ARIZONA_ACCDET_MODE_HPL);
  567. if (ret != 0) {
  568. dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret);
  569. goto err;
  570. }
  571. ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  572. ARIZONA_HP_POLL, ARIZONA_HP_POLL);
  573. if (ret != 0) {
  574. dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
  575. ret);
  576. goto err;
  577. }
  578. return;
  579. err:
  580. regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
  581. ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
  582. /* Just report headphone */
  583. ret = extcon_update_state(&info->edev,
  584. 1 << ARIZONA_CABLE_HEADPHONE,
  585. 1 << ARIZONA_CABLE_HEADPHONE);
  586. if (ret != 0)
  587. dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
  588. info->hpdet_active = false;
  589. }
  590. static irqreturn_t arizona_micdet(int irq, void *data)
  591. {
  592. struct arizona_extcon_info *info = data;
  593. struct arizona *arizona = info->arizona;
  594. unsigned int val, lvl;
  595. int ret, i;
  596. mutex_lock(&info->lock);
  597. ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
  598. if (ret != 0) {
  599. dev_err(arizona->dev, "Failed to read MICDET: %d\n", ret);
  600. mutex_unlock(&info->lock);
  601. return IRQ_NONE;
  602. }
  603. dev_dbg(arizona->dev, "MICDET: %x\n", val);
  604. if (!(val & ARIZONA_MICD_VALID)) {
  605. dev_warn(arizona->dev, "Microphone detection state invalid\n");
  606. mutex_unlock(&info->lock);
  607. return IRQ_NONE;
  608. }
  609. /* Due to jack detect this should never happen */
  610. if (!(val & ARIZONA_MICD_STS)) {
  611. dev_warn(arizona->dev, "Detected open circuit\n");
  612. info->detecting = false;
  613. goto handled;
  614. }
  615. /* If we got a high impedence we should have a headset, report it. */
  616. if (info->detecting && (val & 0x400)) {
  617. arizona_identify_headphone(info);
  618. ret = extcon_update_state(&info->edev,
  619. 1 << ARIZONA_CABLE_MICROPHONE,
  620. 1 << ARIZONA_CABLE_MICROPHONE);
  621. if (ret != 0)
  622. dev_err(arizona->dev, "Headset report failed: %d\n",
  623. ret);
  624. /* Don't need to regulate for button detection */
  625. ret = regulator_allow_bypass(info->micvdd, false);
  626. if (ret != 0) {
  627. dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
  628. ret);
  629. }
  630. info->mic = true;
  631. info->detecting = false;
  632. goto handled;
  633. }
  634. /* If we detected a lower impedence during initial startup
  635. * then we probably have the wrong polarity, flip it. Don't
  636. * do this for the lowest impedences to speed up detection of
  637. * plain headphones. If both polarities report a low
  638. * impedence then give up and report headphones.
  639. */
  640. if (info->detecting && (val & 0x3f8)) {
  641. if (info->jack_flips >= info->micd_num_modes) {
  642. dev_dbg(arizona->dev, "Detected HP/line\n");
  643. arizona_identify_headphone(info);
  644. info->detecting = false;
  645. arizona_stop_mic(info);
  646. } else {
  647. info->micd_mode++;
  648. if (info->micd_mode == info->micd_num_modes)
  649. info->micd_mode = 0;
  650. arizona_extcon_set_mode(info, info->micd_mode);
  651. info->jack_flips++;
  652. }
  653. goto handled;
  654. }
  655. /*
  656. * If we're still detecting and we detect a short then we've
  657. * got a headphone. Otherwise it's a button press.
  658. */
  659. if (val & 0x3fc) {
  660. if (info->mic) {
  661. dev_dbg(arizona->dev, "Mic button detected\n");
  662. lvl = val & ARIZONA_MICD_LVL_MASK;
  663. lvl >>= ARIZONA_MICD_LVL_SHIFT;
  664. for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
  665. if (lvl & arizona_lvl_to_key[i].status)
  666. input_report_key(info->input,
  667. arizona_lvl_to_key[i].report,
  668. 1);
  669. input_sync(info->input);
  670. } else if (info->detecting) {
  671. dev_dbg(arizona->dev, "Headphone detected\n");
  672. info->detecting = false;
  673. arizona_stop_mic(info);
  674. arizona_identify_headphone(info);
  675. } else {
  676. dev_warn(arizona->dev, "Button with no mic: %x\n",
  677. val);
  678. }
  679. } else {
  680. dev_dbg(arizona->dev, "Mic button released\n");
  681. for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
  682. input_report_key(info->input,
  683. arizona_lvl_to_key[i].report, 0);
  684. input_sync(info->input);
  685. arizona_extcon_pulse_micbias(info);
  686. }
  687. handled:
  688. pm_runtime_mark_last_busy(info->dev);
  689. mutex_unlock(&info->lock);
  690. return IRQ_HANDLED;
  691. }
  692. static void arizona_hpdet_work(struct work_struct *work)
  693. {
  694. struct arizona_extcon_info *info = container_of(work,
  695. struct arizona_extcon_info,
  696. hpdet_work.work);
  697. mutex_lock(&info->lock);
  698. arizona_start_hpdet_acc_id(info);
  699. mutex_unlock(&info->lock);
  700. }
  701. static irqreturn_t arizona_jackdet(int irq, void *data)
  702. {
  703. struct arizona_extcon_info *info = data;
  704. struct arizona *arizona = info->arizona;
  705. unsigned int val, present, mask;
  706. int ret, i;
  707. pm_runtime_get_sync(info->dev);
  708. cancel_delayed_work_sync(&info->hpdet_work);
  709. mutex_lock(&info->lock);
  710. if (arizona->pdata.jd_gpio5) {
  711. mask = ARIZONA_MICD_CLAMP_STS;
  712. present = 0;
  713. } else {
  714. mask = ARIZONA_JD1_STS;
  715. present = ARIZONA_JD1_STS;
  716. }
  717. ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val);
  718. if (ret != 0) {
  719. dev_err(arizona->dev, "Failed to read jackdet status: %d\n",
  720. ret);
  721. mutex_unlock(&info->lock);
  722. pm_runtime_put_autosuspend(info->dev);
  723. return IRQ_NONE;
  724. }
  725. if ((val & mask) == present) {
  726. dev_dbg(arizona->dev, "Detected jack\n");
  727. ret = extcon_set_cable_state_(&info->edev,
  728. ARIZONA_CABLE_MECHANICAL, true);
  729. if (ret != 0)
  730. dev_err(arizona->dev, "Mechanical report failed: %d\n",
  731. ret);
  732. if (!arizona->pdata.hpdet_acc_id) {
  733. info->detecting = true;
  734. info->mic = false;
  735. info->jack_flips = 0;
  736. arizona_start_mic(info);
  737. } else {
  738. schedule_delayed_work(&info->hpdet_work,
  739. msecs_to_jiffies(250));
  740. }
  741. regmap_update_bits(arizona->regmap,
  742. ARIZONA_JACK_DETECT_DEBOUNCE,
  743. ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB, 0);
  744. } else {
  745. dev_dbg(arizona->dev, "Detected jack removal\n");
  746. arizona_stop_mic(info);
  747. info->num_hpdet_res = 0;
  748. for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
  749. info->hpdet_res[i] = 0;
  750. info->mic = false;
  751. info->hpdet_done = false;
  752. for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
  753. input_report_key(info->input,
  754. arizona_lvl_to_key[i].report, 0);
  755. input_sync(info->input);
  756. ret = extcon_update_state(&info->edev, 0xffffffff, 0);
  757. if (ret != 0)
  758. dev_err(arizona->dev, "Removal report failed: %d\n",
  759. ret);
  760. regmap_update_bits(arizona->regmap,
  761. ARIZONA_JACK_DETECT_DEBOUNCE,
  762. ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
  763. ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
  764. }
  765. /* Clear trig_sts to make sure DCVDD is not forced up */
  766. regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
  767. ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
  768. ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
  769. ARIZONA_JD1_FALL_TRIG_STS |
  770. ARIZONA_JD1_RISE_TRIG_STS);
  771. mutex_unlock(&info->lock);
  772. pm_runtime_mark_last_busy(info->dev);
  773. pm_runtime_put_autosuspend(info->dev);
  774. return IRQ_HANDLED;
  775. }
  776. static int arizona_extcon_probe(struct platform_device *pdev)
  777. {
  778. struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
  779. struct arizona_pdata *pdata;
  780. struct arizona_extcon_info *info;
  781. int jack_irq_fall, jack_irq_rise;
  782. int ret, mode, i;
  783. if (!arizona->dapm || !arizona->dapm->card)
  784. return -EPROBE_DEFER;
  785. pdata = dev_get_platdata(arizona->dev);
  786. info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
  787. if (!info) {
  788. dev_err(&pdev->dev, "Failed to allocate memory\n");
  789. ret = -ENOMEM;
  790. goto err;
  791. }
  792. info->micvdd = devm_regulator_get(arizona->dev, "MICVDD");
  793. if (IS_ERR(info->micvdd)) {
  794. ret = PTR_ERR(info->micvdd);
  795. dev_err(arizona->dev, "Failed to get MICVDD: %d\n", ret);
  796. goto err;
  797. }
  798. mutex_init(&info->lock);
  799. info->arizona = arizona;
  800. info->dev = &pdev->dev;
  801. INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work);
  802. platform_set_drvdata(pdev, info);
  803. switch (arizona->type) {
  804. case WM5102:
  805. switch (arizona->rev) {
  806. case 0:
  807. info->micd_reva = true;
  808. break;
  809. default:
  810. info->micd_clamp = true;
  811. info->hpdet_ip = 1;
  812. break;
  813. }
  814. break;
  815. default:
  816. break;
  817. }
  818. info->edev.name = "Headset Jack";
  819. info->edev.supported_cable = arizona_cable;
  820. ret = extcon_dev_register(&info->edev, arizona->dev);
  821. if (ret < 0) {
  822. dev_err(arizona->dev, "extcon_dev_register() failed: %d\n",
  823. ret);
  824. goto err;
  825. }
  826. if (pdata->num_micd_configs) {
  827. info->micd_modes = pdata->micd_configs;
  828. info->micd_num_modes = pdata->num_micd_configs;
  829. } else {
  830. info->micd_modes = micd_default_modes;
  831. info->micd_num_modes = ARRAY_SIZE(micd_default_modes);
  832. }
  833. if (arizona->pdata.micd_pol_gpio > 0) {
  834. if (info->micd_modes[0].gpio)
  835. mode = GPIOF_OUT_INIT_HIGH;
  836. else
  837. mode = GPIOF_OUT_INIT_LOW;
  838. ret = devm_gpio_request_one(&pdev->dev,
  839. arizona->pdata.micd_pol_gpio,
  840. mode,
  841. "MICD polarity");
  842. if (ret != 0) {
  843. dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
  844. arizona->pdata.micd_pol_gpio, ret);
  845. goto err_register;
  846. }
  847. }
  848. if (arizona->pdata.hpdet_id_gpio > 0) {
  849. ret = devm_gpio_request_one(&pdev->dev,
  850. arizona->pdata.hpdet_id_gpio,
  851. GPIOF_OUT_INIT_LOW,
  852. "HPDET");
  853. if (ret != 0) {
  854. dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
  855. arizona->pdata.hpdet_id_gpio, ret);
  856. goto err_register;
  857. }
  858. }
  859. if (arizona->pdata.micd_bias_start_time)
  860. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  861. ARIZONA_MICD_BIAS_STARTTIME_MASK,
  862. arizona->pdata.micd_bias_start_time
  863. << ARIZONA_MICD_BIAS_STARTTIME_SHIFT);
  864. if (arizona->pdata.micd_rate)
  865. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  866. ARIZONA_MICD_RATE_MASK,
  867. arizona->pdata.micd_rate
  868. << ARIZONA_MICD_RATE_SHIFT);
  869. if (arizona->pdata.micd_dbtime)
  870. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  871. ARIZONA_MICD_DBTIME_MASK,
  872. arizona->pdata.micd_dbtime
  873. << ARIZONA_MICD_DBTIME_SHIFT);
  874. /*
  875. * If we have a clamp use it, activating in conjunction with
  876. * GPIO5 if that is connected for jack detect operation.
  877. */
  878. if (info->micd_clamp) {
  879. if (arizona->pdata.jd_gpio5) {
  880. /* Put the GPIO into input mode */
  881. regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL,
  882. 0xc101);
  883. regmap_update_bits(arizona->regmap,
  884. ARIZONA_MICD_CLAMP_CONTROL,
  885. ARIZONA_MICD_CLAMP_MODE_MASK, 0x9);
  886. } else {
  887. regmap_update_bits(arizona->regmap,
  888. ARIZONA_MICD_CLAMP_CONTROL,
  889. ARIZONA_MICD_CLAMP_MODE_MASK, 0x4);
  890. }
  891. regmap_update_bits(arizona->regmap,
  892. ARIZONA_JACK_DETECT_DEBOUNCE,
  893. ARIZONA_MICD_CLAMP_DB,
  894. ARIZONA_MICD_CLAMP_DB);
  895. }
  896. arizona_extcon_set_mode(info, 0);
  897. info->input = devm_input_allocate_device(&pdev->dev);
  898. if (!info->input) {
  899. dev_err(arizona->dev, "Can't allocate input dev\n");
  900. ret = -ENOMEM;
  901. goto err_register;
  902. }
  903. for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
  904. input_set_capability(info->input, EV_KEY,
  905. arizona_lvl_to_key[i].report);
  906. info->input->name = "Headset";
  907. info->input->phys = "arizona/extcon";
  908. info->input->dev.parent = &pdev->dev;
  909. pm_runtime_enable(&pdev->dev);
  910. pm_runtime_idle(&pdev->dev);
  911. pm_runtime_get_sync(&pdev->dev);
  912. if (arizona->pdata.jd_gpio5) {
  913. jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
  914. jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
  915. } else {
  916. jack_irq_rise = ARIZONA_IRQ_JD_RISE;
  917. jack_irq_fall = ARIZONA_IRQ_JD_FALL;
  918. }
  919. ret = arizona_request_irq(arizona, jack_irq_rise,
  920. "JACKDET rise", arizona_jackdet, info);
  921. if (ret != 0) {
  922. dev_err(&pdev->dev, "Failed to get JACKDET rise IRQ: %d\n",
  923. ret);
  924. goto err_input;
  925. }
  926. ret = arizona_set_irq_wake(arizona, jack_irq_rise, 1);
  927. if (ret != 0) {
  928. dev_err(&pdev->dev, "Failed to set JD rise IRQ wake: %d\n",
  929. ret);
  930. goto err_rise;
  931. }
  932. ret = arizona_request_irq(arizona, jack_irq_fall,
  933. "JACKDET fall", arizona_jackdet, info);
  934. if (ret != 0) {
  935. dev_err(&pdev->dev, "Failed to get JD fall IRQ: %d\n", ret);
  936. goto err_rise_wake;
  937. }
  938. ret = arizona_set_irq_wake(arizona, jack_irq_fall, 1);
  939. if (ret != 0) {
  940. dev_err(&pdev->dev, "Failed to set JD fall IRQ wake: %d\n",
  941. ret);
  942. goto err_fall;
  943. }
  944. ret = arizona_request_irq(arizona, ARIZONA_IRQ_MICDET,
  945. "MICDET", arizona_micdet, info);
  946. if (ret != 0) {
  947. dev_err(&pdev->dev, "Failed to get MICDET IRQ: %d\n", ret);
  948. goto err_fall_wake;
  949. }
  950. ret = arizona_request_irq(arizona, ARIZONA_IRQ_HPDET,
  951. "HPDET", arizona_hpdet_irq, info);
  952. if (ret != 0) {
  953. dev_err(&pdev->dev, "Failed to get HPDET IRQ: %d\n", ret);
  954. goto err_micdet;
  955. }
  956. arizona_clk32k_enable(arizona);
  957. regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE,
  958. ARIZONA_JD1_DB, ARIZONA_JD1_DB);
  959. regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
  960. ARIZONA_JD1_ENA, ARIZONA_JD1_ENA);
  961. ret = regulator_allow_bypass(info->micvdd, true);
  962. if (ret != 0)
  963. dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n",
  964. ret);
  965. pm_runtime_put(&pdev->dev);
  966. ret = input_register_device(info->input);
  967. if (ret) {
  968. dev_err(&pdev->dev, "Can't register input device: %d\n", ret);
  969. goto err_hpdet;
  970. }
  971. return 0;
  972. err_hpdet:
  973. arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
  974. err_micdet:
  975. arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
  976. err_fall_wake:
  977. arizona_set_irq_wake(arizona, jack_irq_fall, 0);
  978. err_fall:
  979. arizona_free_irq(arizona, jack_irq_fall, info);
  980. err_rise_wake:
  981. arizona_set_irq_wake(arizona, jack_irq_rise, 0);
  982. err_rise:
  983. arizona_free_irq(arizona, jack_irq_rise, info);
  984. err_input:
  985. err_register:
  986. pm_runtime_disable(&pdev->dev);
  987. extcon_dev_unregister(&info->edev);
  988. err:
  989. return ret;
  990. }
  991. static int arizona_extcon_remove(struct platform_device *pdev)
  992. {
  993. struct arizona_extcon_info *info = platform_get_drvdata(pdev);
  994. struct arizona *arizona = info->arizona;
  995. int jack_irq_rise, jack_irq_fall;
  996. pm_runtime_disable(&pdev->dev);
  997. regmap_update_bits(arizona->regmap,
  998. ARIZONA_MICD_CLAMP_CONTROL,
  999. ARIZONA_MICD_CLAMP_MODE_MASK, 0);
  1000. if (arizona->pdata.jd_gpio5) {
  1001. jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
  1002. jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
  1003. } else {
  1004. jack_irq_rise = ARIZONA_IRQ_JD_RISE;
  1005. jack_irq_fall = ARIZONA_IRQ_JD_FALL;
  1006. }
  1007. arizona_set_irq_wake(arizona, jack_irq_rise, 0);
  1008. arizona_set_irq_wake(arizona, jack_irq_fall, 0);
  1009. arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
  1010. arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
  1011. arizona_free_irq(arizona, jack_irq_rise, info);
  1012. arizona_free_irq(arizona, jack_irq_fall, info);
  1013. cancel_delayed_work_sync(&info->hpdet_work);
  1014. regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
  1015. ARIZONA_JD1_ENA, 0);
  1016. arizona_clk32k_disable(arizona);
  1017. extcon_dev_unregister(&info->edev);
  1018. return 0;
  1019. }
  1020. static struct platform_driver arizona_extcon_driver = {
  1021. .driver = {
  1022. .name = "arizona-extcon",
  1023. .owner = THIS_MODULE,
  1024. },
  1025. .probe = arizona_extcon_probe,
  1026. .remove = arizona_extcon_remove,
  1027. };
  1028. module_platform_driver(arizona_extcon_driver);
  1029. MODULE_DESCRIPTION("Arizona Extcon driver");
  1030. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  1031. MODULE_LICENSE("GPL");
  1032. MODULE_ALIAS("platform:extcon-arizona");