extcon-arizona.c 31 KB

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