extcon-arizona.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * extcon-arizona.c - Extcon driver Wolfson Arizona devices
  4. *
  5. * Copyright (C) 2012-2014 Wolfson Microelectronics plc
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/i2c.h>
  10. #include <linux/slab.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/err.h>
  13. #include <linux/gpio/consumer.h>
  14. #include <linux/gpio.h>
  15. #include <linux/input.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm_runtime.h>
  18. #include <linux/property.h>
  19. #include <linux/regulator/consumer.h>
  20. #include <linux/extcon-provider.h>
  21. #include <sound/soc.h>
  22. #include <linux/mfd/arizona/core.h>
  23. #include <linux/mfd/arizona/pdata.h>
  24. #include <linux/mfd/arizona/registers.h>
  25. #include <dt-bindings/mfd/arizona.h>
  26. #define ARIZONA_MAX_MICD_RANGE 8
  27. #define ARIZONA_MICD_CLAMP_MODE_JDL 0x4
  28. #define ARIZONA_MICD_CLAMP_MODE_JDH 0x5
  29. #define ARIZONA_MICD_CLAMP_MODE_JDL_GP5H 0x9
  30. #define ARIZONA_MICD_CLAMP_MODE_JDH_GP5H 0xb
  31. #define ARIZONA_TST_CAP_DEFAULT 0x3
  32. #define ARIZONA_TST_CAP_CLAMP 0x1
  33. #define ARIZONA_HPDET_MAX 10000
  34. #define HPDET_DEBOUNCE 500
  35. #define DEFAULT_MICD_TIMEOUT 2000
  36. #define ARIZONA_HPDET_WAIT_COUNT 15
  37. #define ARIZONA_HPDET_WAIT_DELAY_MS 20
  38. #define QUICK_HEADPHONE_MAX_OHM 3
  39. #define MICROPHONE_MIN_OHM 1257
  40. #define MICROPHONE_MAX_OHM 30000
  41. #define MICD_DBTIME_TWO_READINGS 2
  42. #define MICD_DBTIME_FOUR_READINGS 4
  43. #define MICD_LVL_1_TO_7 (ARIZONA_MICD_LVL_1 | ARIZONA_MICD_LVL_2 | \
  44. ARIZONA_MICD_LVL_3 | ARIZONA_MICD_LVL_4 | \
  45. ARIZONA_MICD_LVL_5 | ARIZONA_MICD_LVL_6 | \
  46. ARIZONA_MICD_LVL_7)
  47. #define MICD_LVL_0_TO_7 (ARIZONA_MICD_LVL_0 | MICD_LVL_1_TO_7)
  48. #define MICD_LVL_0_TO_8 (MICD_LVL_0_TO_7 | ARIZONA_MICD_LVL_8)
  49. struct arizona_extcon_info {
  50. struct device *dev;
  51. struct arizona *arizona;
  52. struct mutex lock;
  53. struct regulator *micvdd;
  54. struct input_dev *input;
  55. u16 last_jackdet;
  56. int micd_mode;
  57. const struct arizona_micd_config *micd_modes;
  58. int micd_num_modes;
  59. const struct arizona_micd_range *micd_ranges;
  60. int num_micd_ranges;
  61. bool micd_reva;
  62. bool micd_clamp;
  63. struct delayed_work hpdet_work;
  64. struct delayed_work micd_detect_work;
  65. struct delayed_work micd_timeout_work;
  66. bool hpdet_active;
  67. bool hpdet_done;
  68. bool hpdet_retried;
  69. int num_hpdet_res;
  70. unsigned int hpdet_res[3];
  71. bool mic;
  72. bool detecting;
  73. int jack_flips;
  74. int hpdet_ip_version;
  75. struct extcon_dev *edev;
  76. struct gpio_desc *micd_pol_gpio;
  77. };
  78. static const struct arizona_micd_config micd_default_modes[] = {
  79. { ARIZONA_ACCDET_SRC, 1, 0 },
  80. { 0, 2, 1 },
  81. };
  82. static const struct arizona_micd_range micd_default_ranges[] = {
  83. { .max = 11, .key = BTN_0 },
  84. { .max = 28, .key = BTN_1 },
  85. { .max = 54, .key = BTN_2 },
  86. { .max = 100, .key = BTN_3 },
  87. { .max = 186, .key = BTN_4 },
  88. { .max = 430, .key = BTN_5 },
  89. };
  90. /* The number of levels in arizona_micd_levels valid for button thresholds */
  91. #define ARIZONA_NUM_MICD_BUTTON_LEVELS 64
  92. static const int arizona_micd_levels[] = {
  93. 3, 6, 8, 11, 13, 16, 18, 21, 23, 26, 28, 31, 34, 36, 39, 41, 44, 46,
  94. 49, 52, 54, 57, 60, 62, 65, 67, 70, 73, 75, 78, 81, 83, 89, 94, 100,
  95. 105, 111, 116, 122, 127, 139, 150, 161, 173, 186, 196, 209, 220, 245,
  96. 270, 295, 321, 348, 375, 402, 430, 489, 550, 614, 681, 752, 903, 1071,
  97. 1257, 30000,
  98. };
  99. static const unsigned int arizona_cable[] = {
  100. EXTCON_MECHANICAL,
  101. EXTCON_JACK_MICROPHONE,
  102. EXTCON_JACK_HEADPHONE,
  103. EXTCON_JACK_LINE_OUT,
  104. EXTCON_NONE,
  105. };
  106. static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info);
  107. static void arizona_extcon_hp_clamp(struct arizona_extcon_info *info,
  108. bool clamp)
  109. {
  110. struct arizona *arizona = info->arizona;
  111. unsigned int mask = 0, val = 0;
  112. unsigned int cap_sel = 0;
  113. int ret;
  114. switch (arizona->type) {
  115. case WM8998:
  116. case WM1814:
  117. mask = 0;
  118. break;
  119. case WM5110:
  120. case WM8280:
  121. mask = ARIZONA_HP1L_SHRTO | ARIZONA_HP1L_FLWR |
  122. ARIZONA_HP1L_SHRTI;
  123. if (clamp) {
  124. val = ARIZONA_HP1L_SHRTO;
  125. cap_sel = ARIZONA_TST_CAP_CLAMP;
  126. } else {
  127. val = ARIZONA_HP1L_FLWR | ARIZONA_HP1L_SHRTI;
  128. cap_sel = ARIZONA_TST_CAP_DEFAULT;
  129. }
  130. ret = regmap_update_bits(arizona->regmap,
  131. ARIZONA_HP_TEST_CTRL_1,
  132. ARIZONA_HP1_TST_CAP_SEL_MASK,
  133. cap_sel);
  134. if (ret != 0)
  135. dev_warn(arizona->dev,
  136. "Failed to set TST_CAP_SEL: %d\n", ret);
  137. break;
  138. default:
  139. mask = ARIZONA_RMV_SHRT_HP1L;
  140. if (clamp)
  141. val = ARIZONA_RMV_SHRT_HP1L;
  142. break;
  143. }
  144. snd_soc_dapm_mutex_lock(arizona->dapm);
  145. arizona->hpdet_clamp = clamp;
  146. /* Keep the HP output stages disabled while doing the clamp */
  147. if (clamp) {
  148. ret = regmap_update_bits(arizona->regmap,
  149. ARIZONA_OUTPUT_ENABLES_1,
  150. ARIZONA_OUT1L_ENA |
  151. ARIZONA_OUT1R_ENA, 0);
  152. if (ret != 0)
  153. dev_warn(arizona->dev,
  154. "Failed to disable headphone outputs: %d\n",
  155. ret);
  156. }
  157. if (mask) {
  158. ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1L,
  159. mask, val);
  160. if (ret != 0)
  161. dev_warn(arizona->dev, "Failed to do clamp: %d\n",
  162. ret);
  163. ret = regmap_update_bits(arizona->regmap, ARIZONA_HP_CTRL_1R,
  164. mask, val);
  165. if (ret != 0)
  166. dev_warn(arizona->dev, "Failed to do clamp: %d\n",
  167. ret);
  168. }
  169. /* Restore the desired state while not doing the clamp */
  170. if (!clamp) {
  171. ret = regmap_update_bits(arizona->regmap,
  172. ARIZONA_OUTPUT_ENABLES_1,
  173. ARIZONA_OUT1L_ENA |
  174. ARIZONA_OUT1R_ENA, arizona->hp_ena);
  175. if (ret != 0)
  176. dev_warn(arizona->dev,
  177. "Failed to restore headphone outputs: %d\n",
  178. ret);
  179. }
  180. snd_soc_dapm_mutex_unlock(arizona->dapm);
  181. }
  182. static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
  183. {
  184. struct arizona *arizona = info->arizona;
  185. mode %= info->micd_num_modes;
  186. gpiod_set_value_cansleep(info->micd_pol_gpio,
  187. info->micd_modes[mode].gpio);
  188. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  189. ARIZONA_MICD_BIAS_SRC_MASK,
  190. info->micd_modes[mode].bias <<
  191. ARIZONA_MICD_BIAS_SRC_SHIFT);
  192. regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
  193. ARIZONA_ACCDET_SRC, info->micd_modes[mode].src);
  194. info->micd_mode = mode;
  195. dev_dbg(arizona->dev, "Set jack polarity to %d\n", mode);
  196. }
  197. static const char *arizona_extcon_get_micbias(struct arizona_extcon_info *info)
  198. {
  199. switch (info->micd_modes[0].bias) {
  200. case 1:
  201. return "MICBIAS1";
  202. case 2:
  203. return "MICBIAS2";
  204. case 3:
  205. return "MICBIAS3";
  206. default:
  207. return "MICVDD";
  208. }
  209. }
  210. static void arizona_extcon_pulse_micbias(struct arizona_extcon_info *info)
  211. {
  212. struct arizona *arizona = info->arizona;
  213. const char *widget = arizona_extcon_get_micbias(info);
  214. struct snd_soc_dapm_context *dapm = arizona->dapm;
  215. struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
  216. int ret;
  217. ret = snd_soc_component_force_enable_pin(component, widget);
  218. if (ret != 0)
  219. dev_warn(arizona->dev, "Failed to enable %s: %d\n",
  220. widget, ret);
  221. snd_soc_dapm_sync(dapm);
  222. if (!arizona->pdata.micd_force_micbias) {
  223. ret = snd_soc_component_disable_pin(component, widget);
  224. if (ret != 0)
  225. dev_warn(arizona->dev, "Failed to disable %s: %d\n",
  226. widget, ret);
  227. snd_soc_dapm_sync(dapm);
  228. }
  229. }
  230. static void arizona_start_mic(struct arizona_extcon_info *info)
  231. {
  232. struct arizona *arizona = info->arizona;
  233. bool change;
  234. int ret;
  235. unsigned int mode;
  236. /* Microphone detection can't use idle mode */
  237. pm_runtime_get(info->dev);
  238. if (info->detecting) {
  239. ret = regulator_allow_bypass(info->micvdd, false);
  240. if (ret != 0) {
  241. dev_err(arizona->dev,
  242. "Failed to regulate MICVDD: %d\n",
  243. ret);
  244. }
  245. }
  246. ret = regulator_enable(info->micvdd);
  247. if (ret != 0) {
  248. dev_err(arizona->dev, "Failed to enable MICVDD: %d\n",
  249. ret);
  250. }
  251. if (info->micd_reva) {
  252. const struct reg_sequence reva[] = {
  253. { 0x80, 0x3 },
  254. { 0x294, 0x0 },
  255. { 0x80, 0x0 },
  256. };
  257. regmap_multi_reg_write(arizona->regmap, reva, ARRAY_SIZE(reva));
  258. }
  259. if (info->detecting && arizona->pdata.micd_software_compare)
  260. mode = ARIZONA_ACCDET_MODE_ADC;
  261. else
  262. mode = ARIZONA_ACCDET_MODE_MIC;
  263. regmap_update_bits(arizona->regmap,
  264. ARIZONA_ACCESSORY_DETECT_MODE_1,
  265. ARIZONA_ACCDET_MODE_MASK, mode);
  266. arizona_extcon_pulse_micbias(info);
  267. ret = regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
  268. ARIZONA_MICD_ENA, ARIZONA_MICD_ENA,
  269. &change);
  270. if (ret < 0) {
  271. dev_err(arizona->dev, "Failed to enable micd: %d\n", ret);
  272. } else if (!change) {
  273. regulator_disable(info->micvdd);
  274. pm_runtime_put_autosuspend(info->dev);
  275. }
  276. }
  277. static void arizona_stop_mic(struct arizona_extcon_info *info)
  278. {
  279. struct arizona *arizona = info->arizona;
  280. const char *widget = arizona_extcon_get_micbias(info);
  281. struct snd_soc_dapm_context *dapm = arizona->dapm;
  282. struct snd_soc_component *component = snd_soc_dapm_to_component(dapm);
  283. bool change = false;
  284. int ret;
  285. ret = regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
  286. ARIZONA_MICD_ENA, 0,
  287. &change);
  288. if (ret < 0)
  289. dev_err(arizona->dev, "Failed to disable micd: %d\n", ret);
  290. ret = snd_soc_component_disable_pin(component, widget);
  291. if (ret != 0)
  292. dev_warn(arizona->dev,
  293. "Failed to disable %s: %d\n",
  294. widget, ret);
  295. snd_soc_dapm_sync(dapm);
  296. if (info->micd_reva) {
  297. const struct reg_sequence reva[] = {
  298. { 0x80, 0x3 },
  299. { 0x294, 0x2 },
  300. { 0x80, 0x0 },
  301. };
  302. regmap_multi_reg_write(arizona->regmap, reva, ARRAY_SIZE(reva));
  303. }
  304. ret = regulator_allow_bypass(info->micvdd, true);
  305. if (ret != 0) {
  306. dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
  307. ret);
  308. }
  309. if (change) {
  310. regulator_disable(info->micvdd);
  311. pm_runtime_mark_last_busy(info->dev);
  312. pm_runtime_put_autosuspend(info->dev);
  313. }
  314. }
  315. static struct {
  316. unsigned int threshold;
  317. unsigned int factor_a;
  318. unsigned int factor_b;
  319. } arizona_hpdet_b_ranges[] = {
  320. { 100, 5528, 362464 },
  321. { 169, 11084, 6186851 },
  322. { 169, 11065, 65460395 },
  323. };
  324. #define ARIZONA_HPDET_B_RANGE_MAX 0x3fb
  325. static struct {
  326. int min;
  327. int max;
  328. } arizona_hpdet_c_ranges[] = {
  329. { 0, 30 },
  330. { 8, 100 },
  331. { 100, 1000 },
  332. { 1000, 10000 },
  333. };
  334. static int arizona_hpdet_read(struct arizona_extcon_info *info)
  335. {
  336. struct arizona *arizona = info->arizona;
  337. unsigned int val, range;
  338. int ret;
  339. ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, &val);
  340. if (ret != 0) {
  341. dev_err(arizona->dev, "Failed to read HPDET status: %d\n",
  342. ret);
  343. return ret;
  344. }
  345. switch (info->hpdet_ip_version) {
  346. case 0:
  347. if (!(val & ARIZONA_HP_DONE)) {
  348. dev_err(arizona->dev, "HPDET did not complete: %x\n",
  349. val);
  350. return -EAGAIN;
  351. }
  352. val &= ARIZONA_HP_LVL_MASK;
  353. break;
  354. case 1:
  355. if (!(val & ARIZONA_HP_DONE_B)) {
  356. dev_err(arizona->dev, "HPDET did not complete: %x\n",
  357. val);
  358. return -EAGAIN;
  359. }
  360. ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val);
  361. if (ret != 0) {
  362. dev_err(arizona->dev, "Failed to read HP value: %d\n",
  363. ret);
  364. return -EAGAIN;
  365. }
  366. regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  367. &range);
  368. range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
  369. >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
  370. if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
  371. (val < arizona_hpdet_b_ranges[range].threshold ||
  372. val >= ARIZONA_HPDET_B_RANGE_MAX)) {
  373. range++;
  374. dev_dbg(arizona->dev, "Moving to HPDET range %d\n",
  375. range);
  376. regmap_update_bits(arizona->regmap,
  377. ARIZONA_HEADPHONE_DETECT_1,
  378. ARIZONA_HP_IMPEDANCE_RANGE_MASK,
  379. range <<
  380. ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
  381. return -EAGAIN;
  382. }
  383. /* If we go out of range report top of range */
  384. if (val < arizona_hpdet_b_ranges[range].threshold ||
  385. val >= ARIZONA_HPDET_B_RANGE_MAX) {
  386. dev_dbg(arizona->dev, "Measurement out of range\n");
  387. return ARIZONA_HPDET_MAX;
  388. }
  389. dev_dbg(arizona->dev, "HPDET read %d in range %d\n",
  390. val, range);
  391. val = arizona_hpdet_b_ranges[range].factor_b
  392. / ((val * 100) -
  393. arizona_hpdet_b_ranges[range].factor_a);
  394. break;
  395. case 2:
  396. if (!(val & ARIZONA_HP_DONE_B)) {
  397. dev_err(arizona->dev, "HPDET did not complete: %x\n",
  398. val);
  399. return -EAGAIN;
  400. }
  401. val &= ARIZONA_HP_LVL_B_MASK;
  402. /* Convert to ohms, the value is in 0.5 ohm increments */
  403. val /= 2;
  404. regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  405. &range);
  406. range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
  407. >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
  408. /* Skip up a range, or report? */
  409. if (range < ARRAY_SIZE(arizona_hpdet_c_ranges) - 1 &&
  410. (val >= arizona_hpdet_c_ranges[range].max)) {
  411. range++;
  412. dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
  413. arizona_hpdet_c_ranges[range].min,
  414. arizona_hpdet_c_ranges[range].max);
  415. regmap_update_bits(arizona->regmap,
  416. ARIZONA_HEADPHONE_DETECT_1,
  417. ARIZONA_HP_IMPEDANCE_RANGE_MASK,
  418. range <<
  419. ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
  420. return -EAGAIN;
  421. }
  422. if (range && (val < arizona_hpdet_c_ranges[range].min)) {
  423. dev_dbg(arizona->dev, "Reporting range boundary %d\n",
  424. arizona_hpdet_c_ranges[range].min);
  425. val = arizona_hpdet_c_ranges[range].min;
  426. }
  427. break;
  428. default:
  429. dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n",
  430. info->hpdet_ip_version);
  431. return -EINVAL;
  432. }
  433. dev_dbg(arizona->dev, "HP impedance %d ohms\n", val);
  434. return val;
  435. }
  436. static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading,
  437. bool *mic)
  438. {
  439. struct arizona *arizona = info->arizona;
  440. int id_gpio = arizona->pdata.hpdet_id_gpio;
  441. if (!arizona->pdata.hpdet_acc_id)
  442. return 0;
  443. /*
  444. * If we're using HPDET for accessory identification we need
  445. * to take multiple measurements, step through them in sequence.
  446. */
  447. info->hpdet_res[info->num_hpdet_res++] = *reading;
  448. /* Only check the mic directly if we didn't already ID it */
  449. if (id_gpio && info->num_hpdet_res == 1) {
  450. dev_dbg(arizona->dev, "Measuring mic\n");
  451. regmap_update_bits(arizona->regmap,
  452. ARIZONA_ACCESSORY_DETECT_MODE_1,
  453. ARIZONA_ACCDET_MODE_MASK |
  454. ARIZONA_ACCDET_SRC,
  455. ARIZONA_ACCDET_MODE_HPR |
  456. info->micd_modes[0].src);
  457. gpio_set_value_cansleep(id_gpio, 1);
  458. regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  459. ARIZONA_HP_POLL, ARIZONA_HP_POLL);
  460. return -EAGAIN;
  461. }
  462. /* OK, got both. Now, compare... */
  463. dev_dbg(arizona->dev, "HPDET measured %d %d\n",
  464. info->hpdet_res[0], info->hpdet_res[1]);
  465. /* Take the headphone impedance for the main report */
  466. *reading = info->hpdet_res[0];
  467. /* Sometimes we get false readings due to slow insert */
  468. if (*reading >= ARIZONA_HPDET_MAX && !info->hpdet_retried) {
  469. dev_dbg(arizona->dev, "Retrying high impedance\n");
  470. info->num_hpdet_res = 0;
  471. info->hpdet_retried = true;
  472. arizona_start_hpdet_acc_id(info);
  473. pm_runtime_put(info->dev);
  474. return -EAGAIN;
  475. }
  476. /*
  477. * If we measure the mic as high impedance
  478. */
  479. if (!id_gpio || info->hpdet_res[1] > 50) {
  480. dev_dbg(arizona->dev, "Detected mic\n");
  481. *mic = true;
  482. info->detecting = true;
  483. } else {
  484. dev_dbg(arizona->dev, "Detected headphone\n");
  485. }
  486. /* Make sure everything is reset back to the real polarity */
  487. regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
  488. ARIZONA_ACCDET_SRC, info->micd_modes[0].src);
  489. return 0;
  490. }
  491. static irqreturn_t arizona_hpdet_irq(int irq, void *data)
  492. {
  493. struct arizona_extcon_info *info = data;
  494. struct arizona *arizona = info->arizona;
  495. int id_gpio = arizona->pdata.hpdet_id_gpio;
  496. unsigned int report = EXTCON_JACK_HEADPHONE;
  497. int ret, reading, state;
  498. bool mic = false;
  499. mutex_lock(&info->lock);
  500. /* If we got a spurious IRQ for some reason then ignore it */
  501. if (!info->hpdet_active) {
  502. dev_warn(arizona->dev, "Spurious HPDET IRQ\n");
  503. mutex_unlock(&info->lock);
  504. return IRQ_NONE;
  505. }
  506. /* If the cable was removed while measuring ignore the result */
  507. state = extcon_get_state(info->edev, EXTCON_MECHANICAL);
  508. if (state < 0) {
  509. dev_err(arizona->dev, "Failed to check cable state: %d\n", state);
  510. goto out;
  511. } else if (!state) {
  512. dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n");
  513. goto done;
  514. }
  515. ret = arizona_hpdet_read(info);
  516. if (ret == -EAGAIN)
  517. goto out;
  518. else if (ret < 0)
  519. goto done;
  520. reading = ret;
  521. /* Reset back to starting range */
  522. regmap_update_bits(arizona->regmap,
  523. ARIZONA_HEADPHONE_DETECT_1,
  524. ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
  525. 0);
  526. ret = arizona_hpdet_do_id(info, &reading, &mic);
  527. if (ret == -EAGAIN)
  528. goto out;
  529. else if (ret < 0)
  530. goto done;
  531. /* Report high impedence cables as line outputs */
  532. if (reading >= 5000)
  533. report = EXTCON_JACK_LINE_OUT;
  534. else
  535. report = EXTCON_JACK_HEADPHONE;
  536. ret = extcon_set_state_sync(info->edev, report, true);
  537. if (ret != 0)
  538. dev_err(arizona->dev, "Failed to report HP/line: %d\n",
  539. ret);
  540. done:
  541. /* Reset back to starting range */
  542. regmap_update_bits(arizona->regmap,
  543. ARIZONA_HEADPHONE_DETECT_1,
  544. ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
  545. 0);
  546. arizona_extcon_hp_clamp(info, false);
  547. if (id_gpio)
  548. gpio_set_value_cansleep(id_gpio, 0);
  549. /* If we have a mic then reenable MICDET */
  550. if (state && (mic || info->mic))
  551. arizona_start_mic(info);
  552. if (info->hpdet_active) {
  553. pm_runtime_put_autosuspend(info->dev);
  554. info->hpdet_active = false;
  555. }
  556. /* Do not set hp_det done when the cable has been unplugged */
  557. if (state)
  558. info->hpdet_done = true;
  559. out:
  560. mutex_unlock(&info->lock);
  561. return IRQ_HANDLED;
  562. }
  563. static void arizona_identify_headphone(struct arizona_extcon_info *info)
  564. {
  565. struct arizona *arizona = info->arizona;
  566. int ret;
  567. if (info->hpdet_done)
  568. return;
  569. dev_dbg(arizona->dev, "Starting HPDET\n");
  570. /* Make sure we keep the device enabled during the measurement */
  571. pm_runtime_get(info->dev);
  572. info->hpdet_active = true;
  573. arizona_stop_mic(info);
  574. arizona_extcon_hp_clamp(info, true);
  575. ret = regmap_update_bits(arizona->regmap,
  576. ARIZONA_ACCESSORY_DETECT_MODE_1,
  577. ARIZONA_ACCDET_MODE_MASK,
  578. arizona->pdata.hpdet_channel);
  579. if (ret != 0) {
  580. dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
  581. goto err;
  582. }
  583. ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
  584. ARIZONA_HP_POLL, ARIZONA_HP_POLL);
  585. if (ret != 0) {
  586. dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
  587. ret);
  588. goto err;
  589. }
  590. return;
  591. err:
  592. arizona_extcon_hp_clamp(info, false);
  593. pm_runtime_put_autosuspend(info->dev);
  594. /* Just report headphone */
  595. ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true);
  596. if (ret != 0)
  597. dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
  598. if (info->mic)
  599. arizona_start_mic(info);
  600. info->hpdet_active = false;
  601. }
  602. static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
  603. {
  604. struct arizona *arizona = info->arizona;
  605. int hp_reading = 32;
  606. bool mic;
  607. int ret;
  608. dev_dbg(arizona->dev, "Starting identification via HPDET\n");
  609. /* Make sure we keep the device enabled during the measurement */
  610. pm_runtime_get_sync(info->dev);
  611. info->hpdet_active = true;
  612. arizona_extcon_hp_clamp(info, true);
  613. ret = regmap_update_bits(arizona->regmap,
  614. ARIZONA_ACCESSORY_DETECT_MODE_1,
  615. ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK,
  616. info->micd_modes[0].src |
  617. arizona->pdata.hpdet_channel);
  618. if (ret != 0) {
  619. dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret);
  620. goto err;
  621. }
  622. if (arizona->pdata.hpdet_acc_id_line) {
  623. ret = regmap_update_bits(arizona->regmap,
  624. ARIZONA_HEADPHONE_DETECT_1,
  625. ARIZONA_HP_POLL, ARIZONA_HP_POLL);
  626. if (ret != 0) {
  627. dev_err(arizona->dev,
  628. "Can't start HPDETL measurement: %d\n",
  629. ret);
  630. goto err;
  631. }
  632. } else {
  633. arizona_hpdet_do_id(info, &hp_reading, &mic);
  634. }
  635. return;
  636. err:
  637. /* Just report headphone */
  638. ret = extcon_set_state_sync(info->edev, EXTCON_JACK_HEADPHONE, true);
  639. if (ret != 0)
  640. dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
  641. info->hpdet_active = false;
  642. }
  643. static void arizona_micd_timeout_work(struct work_struct *work)
  644. {
  645. struct arizona_extcon_info *info = container_of(work,
  646. struct arizona_extcon_info,
  647. micd_timeout_work.work);
  648. mutex_lock(&info->lock);
  649. dev_dbg(info->arizona->dev, "MICD timed out, reporting HP\n");
  650. info->detecting = false;
  651. arizona_identify_headphone(info);
  652. mutex_unlock(&info->lock);
  653. }
  654. static int arizona_micd_adc_read(struct arizona_extcon_info *info)
  655. {
  656. struct arizona *arizona = info->arizona;
  657. unsigned int val;
  658. int ret;
  659. /* Must disable MICD before we read the ADCVAL */
  660. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  661. ARIZONA_MICD_ENA, 0);
  662. ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_4, &val);
  663. if (ret != 0) {
  664. dev_err(arizona->dev,
  665. "Failed to read MICDET_ADCVAL: %d\n", ret);
  666. return ret;
  667. }
  668. dev_dbg(arizona->dev, "MICDET_ADCVAL: %x\n", val);
  669. val &= ARIZONA_MICDET_ADCVAL_MASK;
  670. if (val < ARRAY_SIZE(arizona_micd_levels))
  671. val = arizona_micd_levels[val];
  672. else
  673. val = INT_MAX;
  674. if (val <= QUICK_HEADPHONE_MAX_OHM)
  675. val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_0;
  676. else if (val <= MICROPHONE_MIN_OHM)
  677. val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_1;
  678. else if (val <= MICROPHONE_MAX_OHM)
  679. val = ARIZONA_MICD_STS | ARIZONA_MICD_LVL_8;
  680. else
  681. val = ARIZONA_MICD_LVL_8;
  682. return val;
  683. }
  684. static int arizona_micd_read(struct arizona_extcon_info *info)
  685. {
  686. struct arizona *arizona = info->arizona;
  687. unsigned int val = 0;
  688. int ret, i;
  689. for (i = 0; i < 10 && !(val & MICD_LVL_0_TO_8); i++) {
  690. ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
  691. if (ret != 0) {
  692. dev_err(arizona->dev,
  693. "Failed to read MICDET: %d\n", ret);
  694. return ret;
  695. }
  696. dev_dbg(arizona->dev, "MICDET: %x\n", val);
  697. if (!(val & ARIZONA_MICD_VALID)) {
  698. dev_warn(arizona->dev,
  699. "Microphone detection state invalid\n");
  700. return -EINVAL;
  701. }
  702. }
  703. if (i == 10 && !(val & MICD_LVL_0_TO_8)) {
  704. dev_err(arizona->dev, "Failed to get valid MICDET value\n");
  705. return -EINVAL;
  706. }
  707. return val;
  708. }
  709. static int arizona_micdet_reading(void *priv)
  710. {
  711. struct arizona_extcon_info *info = priv;
  712. struct arizona *arizona = info->arizona;
  713. int ret, val;
  714. if (info->detecting && arizona->pdata.micd_software_compare)
  715. ret = arizona_micd_adc_read(info);
  716. else
  717. ret = arizona_micd_read(info);
  718. if (ret < 0)
  719. return ret;
  720. val = ret;
  721. /* Due to jack detect this should never happen */
  722. if (!(val & ARIZONA_MICD_STS)) {
  723. dev_warn(arizona->dev, "Detected open circuit\n");
  724. info->mic = false;
  725. info->detecting = false;
  726. arizona_identify_headphone(info);
  727. return 0;
  728. }
  729. /* If we got a high impedence we should have a headset, report it. */
  730. if (val & ARIZONA_MICD_LVL_8) {
  731. info->mic = true;
  732. info->detecting = false;
  733. arizona_identify_headphone(info);
  734. ret = extcon_set_state_sync(info->edev,
  735. EXTCON_JACK_MICROPHONE, true);
  736. if (ret != 0)
  737. dev_err(arizona->dev, "Headset report failed: %d\n",
  738. ret);
  739. /* Don't need to regulate for button detection */
  740. ret = regulator_allow_bypass(info->micvdd, true);
  741. if (ret != 0) {
  742. dev_err(arizona->dev, "Failed to bypass MICVDD: %d\n",
  743. ret);
  744. }
  745. return 0;
  746. }
  747. /* If we detected a lower impedence during initial startup
  748. * then we probably have the wrong polarity, flip it. Don't
  749. * do this for the lowest impedences to speed up detection of
  750. * plain headphones. If both polarities report a low
  751. * impedence then give up and report headphones.
  752. */
  753. if (val & MICD_LVL_1_TO_7) {
  754. if (info->jack_flips >= info->micd_num_modes * 10) {
  755. dev_dbg(arizona->dev, "Detected HP/line\n");
  756. info->detecting = false;
  757. arizona_identify_headphone(info);
  758. } else {
  759. info->micd_mode++;
  760. if (info->micd_mode == info->micd_num_modes)
  761. info->micd_mode = 0;
  762. arizona_extcon_set_mode(info, info->micd_mode);
  763. info->jack_flips++;
  764. if (arizona->pdata.micd_software_compare)
  765. regmap_update_bits(arizona->regmap,
  766. ARIZONA_MIC_DETECT_1,
  767. ARIZONA_MICD_ENA,
  768. ARIZONA_MICD_ENA);
  769. queue_delayed_work(system_power_efficient_wq,
  770. &info->micd_timeout_work,
  771. msecs_to_jiffies(arizona->pdata.micd_timeout));
  772. }
  773. return 0;
  774. }
  775. /*
  776. * If we're still detecting and we detect a short then we've
  777. * got a headphone.
  778. */
  779. dev_dbg(arizona->dev, "Headphone detected\n");
  780. info->detecting = false;
  781. arizona_identify_headphone(info);
  782. return 0;
  783. }
  784. static int arizona_button_reading(void *priv)
  785. {
  786. struct arizona_extcon_info *info = priv;
  787. struct arizona *arizona = info->arizona;
  788. int val, key, lvl, i;
  789. val = arizona_micd_read(info);
  790. if (val < 0)
  791. return val;
  792. /*
  793. * If we're still detecting and we detect a short then we've
  794. * got a headphone. Otherwise it's a button press.
  795. */
  796. if (val & MICD_LVL_0_TO_7) {
  797. if (info->mic) {
  798. dev_dbg(arizona->dev, "Mic button detected\n");
  799. lvl = val & ARIZONA_MICD_LVL_MASK;
  800. lvl >>= ARIZONA_MICD_LVL_SHIFT;
  801. for (i = 0; i < info->num_micd_ranges; i++)
  802. input_report_key(info->input,
  803. info->micd_ranges[i].key, 0);
  804. if (lvl && ffs(lvl) - 1 < info->num_micd_ranges) {
  805. key = info->micd_ranges[ffs(lvl) - 1].key;
  806. input_report_key(info->input, key, 1);
  807. input_sync(info->input);
  808. } else {
  809. dev_err(arizona->dev, "Button out of range\n");
  810. }
  811. } else {
  812. dev_warn(arizona->dev, "Button with no mic: %x\n",
  813. val);
  814. }
  815. } else {
  816. dev_dbg(arizona->dev, "Mic button released\n");
  817. for (i = 0; i < info->num_micd_ranges; i++)
  818. input_report_key(info->input,
  819. info->micd_ranges[i].key, 0);
  820. input_sync(info->input);
  821. arizona_extcon_pulse_micbias(info);
  822. }
  823. return 0;
  824. }
  825. static void arizona_micd_detect(struct work_struct *work)
  826. {
  827. struct arizona_extcon_info *info = container_of(work,
  828. struct arizona_extcon_info,
  829. micd_detect_work.work);
  830. struct arizona *arizona = info->arizona;
  831. int ret;
  832. cancel_delayed_work_sync(&info->micd_timeout_work);
  833. mutex_lock(&info->lock);
  834. /* If the cable was removed while measuring ignore the result */
  835. ret = extcon_get_state(info->edev, EXTCON_MECHANICAL);
  836. if (ret < 0) {
  837. dev_err(arizona->dev, "Failed to check cable state: %d\n",
  838. ret);
  839. mutex_unlock(&info->lock);
  840. return;
  841. } else if (!ret) {
  842. dev_dbg(arizona->dev, "Ignoring MICDET for removed cable\n");
  843. mutex_unlock(&info->lock);
  844. return;
  845. }
  846. if (info->detecting)
  847. arizona_micdet_reading(info);
  848. else
  849. arizona_button_reading(info);
  850. pm_runtime_mark_last_busy(info->dev);
  851. mutex_unlock(&info->lock);
  852. }
  853. static irqreturn_t arizona_micdet(int irq, void *data)
  854. {
  855. struct arizona_extcon_info *info = data;
  856. struct arizona *arizona = info->arizona;
  857. int debounce = arizona->pdata.micd_detect_debounce;
  858. cancel_delayed_work_sync(&info->micd_detect_work);
  859. cancel_delayed_work_sync(&info->micd_timeout_work);
  860. mutex_lock(&info->lock);
  861. if (!info->detecting)
  862. debounce = 0;
  863. mutex_unlock(&info->lock);
  864. if (debounce)
  865. queue_delayed_work(system_power_efficient_wq,
  866. &info->micd_detect_work,
  867. msecs_to_jiffies(debounce));
  868. else
  869. arizona_micd_detect(&info->micd_detect_work.work);
  870. return IRQ_HANDLED;
  871. }
  872. static void arizona_hpdet_work(struct work_struct *work)
  873. {
  874. struct arizona_extcon_info *info = container_of(work,
  875. struct arizona_extcon_info,
  876. hpdet_work.work);
  877. mutex_lock(&info->lock);
  878. arizona_start_hpdet_acc_id(info);
  879. mutex_unlock(&info->lock);
  880. }
  881. static int arizona_hpdet_wait(struct arizona_extcon_info *info)
  882. {
  883. struct arizona *arizona = info->arizona;
  884. unsigned int val;
  885. int i, ret;
  886. for (i = 0; i < ARIZONA_HPDET_WAIT_COUNT; i++) {
  887. ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2,
  888. &val);
  889. if (ret) {
  890. dev_err(arizona->dev,
  891. "Failed to read HPDET state: %d\n", ret);
  892. return ret;
  893. }
  894. switch (info->hpdet_ip_version) {
  895. case 0:
  896. if (val & ARIZONA_HP_DONE)
  897. return 0;
  898. break;
  899. default:
  900. if (val & ARIZONA_HP_DONE_B)
  901. return 0;
  902. break;
  903. }
  904. msleep(ARIZONA_HPDET_WAIT_DELAY_MS);
  905. }
  906. dev_warn(arizona->dev, "HPDET did not appear to complete\n");
  907. return -ETIMEDOUT;
  908. }
  909. static irqreturn_t arizona_jackdet(int irq, void *data)
  910. {
  911. struct arizona_extcon_info *info = data;
  912. struct arizona *arizona = info->arizona;
  913. unsigned int val, present, mask;
  914. bool cancelled_hp, cancelled_mic;
  915. int ret, i;
  916. cancelled_hp = cancel_delayed_work_sync(&info->hpdet_work);
  917. cancelled_mic = cancel_delayed_work_sync(&info->micd_timeout_work);
  918. pm_runtime_get_sync(info->dev);
  919. mutex_lock(&info->lock);
  920. if (info->micd_clamp) {
  921. mask = ARIZONA_MICD_CLAMP_STS;
  922. present = 0;
  923. } else {
  924. mask = ARIZONA_JD1_STS;
  925. if (arizona->pdata.jd_invert)
  926. present = 0;
  927. else
  928. present = ARIZONA_JD1_STS;
  929. }
  930. ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val);
  931. if (ret != 0) {
  932. dev_err(arizona->dev, "Failed to read jackdet status: %d\n",
  933. ret);
  934. mutex_unlock(&info->lock);
  935. pm_runtime_put_autosuspend(info->dev);
  936. return IRQ_NONE;
  937. }
  938. val &= mask;
  939. if (val == info->last_jackdet) {
  940. dev_dbg(arizona->dev, "Suppressing duplicate JACKDET\n");
  941. if (cancelled_hp)
  942. queue_delayed_work(system_power_efficient_wq,
  943. &info->hpdet_work,
  944. msecs_to_jiffies(HPDET_DEBOUNCE));
  945. if (cancelled_mic) {
  946. int micd_timeout = arizona->pdata.micd_timeout;
  947. queue_delayed_work(system_power_efficient_wq,
  948. &info->micd_timeout_work,
  949. msecs_to_jiffies(micd_timeout));
  950. }
  951. goto out;
  952. }
  953. info->last_jackdet = val;
  954. if (info->last_jackdet == present) {
  955. dev_dbg(arizona->dev, "Detected jack\n");
  956. ret = extcon_set_state_sync(info->edev,
  957. EXTCON_MECHANICAL, true);
  958. if (ret != 0)
  959. dev_err(arizona->dev, "Mechanical report failed: %d\n",
  960. ret);
  961. info->detecting = true;
  962. info->mic = false;
  963. info->jack_flips = 0;
  964. if (!arizona->pdata.hpdet_acc_id) {
  965. arizona_start_mic(info);
  966. } else {
  967. queue_delayed_work(system_power_efficient_wq,
  968. &info->hpdet_work,
  969. msecs_to_jiffies(HPDET_DEBOUNCE));
  970. }
  971. if (info->micd_clamp || !arizona->pdata.jd_invert)
  972. regmap_update_bits(arizona->regmap,
  973. ARIZONA_JACK_DETECT_DEBOUNCE,
  974. ARIZONA_MICD_CLAMP_DB |
  975. ARIZONA_JD1_DB, 0);
  976. } else {
  977. dev_dbg(arizona->dev, "Detected jack removal\n");
  978. arizona_stop_mic(info);
  979. info->num_hpdet_res = 0;
  980. for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
  981. info->hpdet_res[i] = 0;
  982. info->mic = false;
  983. info->hpdet_done = false;
  984. info->hpdet_retried = false;
  985. for (i = 0; i < info->num_micd_ranges; i++)
  986. input_report_key(info->input,
  987. info->micd_ranges[i].key, 0);
  988. input_sync(info->input);
  989. for (i = 0; i < ARRAY_SIZE(arizona_cable) - 1; i++) {
  990. ret = extcon_set_state_sync(info->edev,
  991. arizona_cable[i], false);
  992. if (ret != 0)
  993. dev_err(arizona->dev,
  994. "Removal report failed: %d\n", ret);
  995. }
  996. /*
  997. * If the jack was removed during a headphone detection we
  998. * need to wait for the headphone detection to finish, as
  999. * it can not be aborted. We don't want to be able to start
  1000. * a new headphone detection from a fresh insert until this
  1001. * one is finished.
  1002. */
  1003. arizona_hpdet_wait(info);
  1004. regmap_update_bits(arizona->regmap,
  1005. ARIZONA_JACK_DETECT_DEBOUNCE,
  1006. ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
  1007. ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB);
  1008. }
  1009. out:
  1010. /* Clear trig_sts to make sure DCVDD is not forced up */
  1011. regmap_write(arizona->regmap, ARIZONA_AOD_WKUP_AND_TRIG,
  1012. ARIZONA_MICD_CLAMP_FALL_TRIG_STS |
  1013. ARIZONA_MICD_CLAMP_RISE_TRIG_STS |
  1014. ARIZONA_JD1_FALL_TRIG_STS |
  1015. ARIZONA_JD1_RISE_TRIG_STS);
  1016. mutex_unlock(&info->lock);
  1017. pm_runtime_mark_last_busy(info->dev);
  1018. pm_runtime_put_autosuspend(info->dev);
  1019. return IRQ_HANDLED;
  1020. }
  1021. /* Map a level onto a slot in the register bank */
  1022. static void arizona_micd_set_level(struct arizona *arizona, int index,
  1023. unsigned int level)
  1024. {
  1025. int reg;
  1026. unsigned int mask;
  1027. reg = ARIZONA_MIC_DETECT_LEVEL_4 - (index / 2);
  1028. if (!(index % 2)) {
  1029. mask = 0x3f00;
  1030. level <<= 8;
  1031. } else {
  1032. mask = 0x3f;
  1033. }
  1034. /* Program the level itself */
  1035. regmap_update_bits(arizona->regmap, reg, mask, level);
  1036. }
  1037. static int arizona_extcon_get_micd_configs(struct device *dev,
  1038. struct arizona *arizona)
  1039. {
  1040. const char * const prop = "wlf,micd-configs";
  1041. const int entries_per_config = 3;
  1042. struct arizona_micd_config *micd_configs;
  1043. int nconfs, ret;
  1044. int i, j;
  1045. u32 *vals;
  1046. nconfs = device_property_count_u32(arizona->dev, prop);
  1047. if (nconfs <= 0)
  1048. return 0;
  1049. vals = kcalloc(nconfs, sizeof(u32), GFP_KERNEL);
  1050. if (!vals)
  1051. return -ENOMEM;
  1052. ret = device_property_read_u32_array(arizona->dev, prop, vals, nconfs);
  1053. if (ret < 0)
  1054. goto out;
  1055. nconfs /= entries_per_config;
  1056. micd_configs = devm_kcalloc(dev, nconfs, sizeof(*micd_configs),
  1057. GFP_KERNEL);
  1058. if (!micd_configs) {
  1059. ret = -ENOMEM;
  1060. goto out;
  1061. }
  1062. for (i = 0, j = 0; i < nconfs; ++i) {
  1063. micd_configs[i].src = vals[j++] ? ARIZONA_ACCDET_SRC : 0;
  1064. micd_configs[i].bias = vals[j++];
  1065. micd_configs[i].gpio = vals[j++];
  1066. }
  1067. arizona->pdata.micd_configs = micd_configs;
  1068. arizona->pdata.num_micd_configs = nconfs;
  1069. out:
  1070. kfree(vals);
  1071. return ret;
  1072. }
  1073. static int arizona_extcon_device_get_pdata(struct device *dev,
  1074. struct arizona *arizona)
  1075. {
  1076. struct arizona_pdata *pdata = &arizona->pdata;
  1077. unsigned int val = ARIZONA_ACCDET_MODE_HPL;
  1078. int ret;
  1079. device_property_read_u32(arizona->dev, "wlf,hpdet-channel", &val);
  1080. switch (val) {
  1081. case ARIZONA_ACCDET_MODE_HPL:
  1082. case ARIZONA_ACCDET_MODE_HPR:
  1083. pdata->hpdet_channel = val;
  1084. break;
  1085. default:
  1086. dev_err(arizona->dev,
  1087. "Wrong wlf,hpdet-channel DT value %d\n", val);
  1088. pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL;
  1089. }
  1090. device_property_read_u32(arizona->dev, "wlf,micd-detect-debounce",
  1091. &pdata->micd_detect_debounce);
  1092. device_property_read_u32(arizona->dev, "wlf,micd-bias-start-time",
  1093. &pdata->micd_bias_start_time);
  1094. device_property_read_u32(arizona->dev, "wlf,micd-rate",
  1095. &pdata->micd_rate);
  1096. device_property_read_u32(arizona->dev, "wlf,micd-dbtime",
  1097. &pdata->micd_dbtime);
  1098. device_property_read_u32(arizona->dev, "wlf,micd-timeout-ms",
  1099. &pdata->micd_timeout);
  1100. pdata->micd_force_micbias = device_property_read_bool(arizona->dev,
  1101. "wlf,micd-force-micbias");
  1102. pdata->micd_software_compare = device_property_read_bool(arizona->dev,
  1103. "wlf,micd-software-compare");
  1104. pdata->jd_invert = device_property_read_bool(arizona->dev,
  1105. "wlf,jd-invert");
  1106. device_property_read_u32(arizona->dev, "wlf,gpsw", &pdata->gpsw);
  1107. pdata->jd_gpio5 = device_property_read_bool(arizona->dev,
  1108. "wlf,use-jd2");
  1109. pdata->jd_gpio5_nopull = device_property_read_bool(arizona->dev,
  1110. "wlf,use-jd2-nopull");
  1111. ret = arizona_extcon_get_micd_configs(dev, arizona);
  1112. if (ret < 0)
  1113. dev_err(arizona->dev, "Failed to read micd configs: %d\n", ret);
  1114. return 0;
  1115. }
  1116. static int arizona_extcon_probe(struct platform_device *pdev)
  1117. {
  1118. struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
  1119. struct arizona_pdata *pdata = &arizona->pdata;
  1120. struct arizona_extcon_info *info;
  1121. unsigned int val;
  1122. unsigned int clamp_mode;
  1123. int jack_irq_fall, jack_irq_rise;
  1124. int ret, mode, i, j;
  1125. if (!arizona->dapm || !arizona->dapm->card)
  1126. return -EPROBE_DEFER;
  1127. info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
  1128. if (!info)
  1129. return -ENOMEM;
  1130. if (!dev_get_platdata(arizona->dev))
  1131. arizona_extcon_device_get_pdata(&pdev->dev, arizona);
  1132. info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD");
  1133. if (IS_ERR(info->micvdd)) {
  1134. ret = PTR_ERR(info->micvdd);
  1135. dev_err(arizona->dev, "Failed to get MICVDD: %d\n", ret);
  1136. return ret;
  1137. }
  1138. mutex_init(&info->lock);
  1139. info->arizona = arizona;
  1140. info->dev = &pdev->dev;
  1141. info->last_jackdet = ~(ARIZONA_MICD_CLAMP_STS | ARIZONA_JD1_STS);
  1142. INIT_DELAYED_WORK(&info->hpdet_work, arizona_hpdet_work);
  1143. INIT_DELAYED_WORK(&info->micd_detect_work, arizona_micd_detect);
  1144. INIT_DELAYED_WORK(&info->micd_timeout_work, arizona_micd_timeout_work);
  1145. platform_set_drvdata(pdev, info);
  1146. switch (arizona->type) {
  1147. case WM5102:
  1148. switch (arizona->rev) {
  1149. case 0:
  1150. info->micd_reva = true;
  1151. break;
  1152. default:
  1153. info->micd_clamp = true;
  1154. info->hpdet_ip_version = 1;
  1155. break;
  1156. }
  1157. break;
  1158. case WM5110:
  1159. case WM8280:
  1160. switch (arizona->rev) {
  1161. case 0 ... 2:
  1162. break;
  1163. default:
  1164. info->micd_clamp = true;
  1165. info->hpdet_ip_version = 2;
  1166. break;
  1167. }
  1168. break;
  1169. case WM8998:
  1170. case WM1814:
  1171. info->micd_clamp = true;
  1172. info->hpdet_ip_version = 2;
  1173. break;
  1174. default:
  1175. break;
  1176. }
  1177. info->edev = devm_extcon_dev_allocate(&pdev->dev, arizona_cable);
  1178. if (IS_ERR(info->edev)) {
  1179. dev_err(&pdev->dev, "failed to allocate extcon device\n");
  1180. return -ENOMEM;
  1181. }
  1182. ret = devm_extcon_dev_register(&pdev->dev, info->edev);
  1183. if (ret < 0) {
  1184. dev_err(arizona->dev, "extcon_dev_register() failed: %d\n",
  1185. ret);
  1186. return ret;
  1187. }
  1188. info->input = devm_input_allocate_device(&pdev->dev);
  1189. if (!info->input) {
  1190. dev_err(arizona->dev, "Can't allocate input dev\n");
  1191. ret = -ENOMEM;
  1192. return ret;
  1193. }
  1194. info->input->name = "Headset";
  1195. info->input->phys = "arizona/extcon";
  1196. if (!pdata->micd_timeout)
  1197. pdata->micd_timeout = DEFAULT_MICD_TIMEOUT;
  1198. if (pdata->num_micd_configs) {
  1199. info->micd_modes = pdata->micd_configs;
  1200. info->micd_num_modes = pdata->num_micd_configs;
  1201. } else {
  1202. info->micd_modes = micd_default_modes;
  1203. info->micd_num_modes = ARRAY_SIZE(micd_default_modes);
  1204. }
  1205. if (arizona->pdata.gpsw > 0)
  1206. regmap_update_bits(arizona->regmap, ARIZONA_GP_SWITCH_1,
  1207. ARIZONA_SW1_MODE_MASK, arizona->pdata.gpsw);
  1208. if (pdata->micd_pol_gpio > 0) {
  1209. if (info->micd_modes[0].gpio)
  1210. mode = GPIOF_OUT_INIT_HIGH;
  1211. else
  1212. mode = GPIOF_OUT_INIT_LOW;
  1213. ret = devm_gpio_request_one(&pdev->dev, pdata->micd_pol_gpio,
  1214. mode, "MICD polarity");
  1215. if (ret != 0) {
  1216. dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
  1217. pdata->micd_pol_gpio, ret);
  1218. return ret;
  1219. }
  1220. info->micd_pol_gpio = gpio_to_desc(pdata->micd_pol_gpio);
  1221. } else {
  1222. if (info->micd_modes[0].gpio)
  1223. mode = GPIOD_OUT_HIGH;
  1224. else
  1225. mode = GPIOD_OUT_LOW;
  1226. /* We can't use devm here because we need to do the get
  1227. * against the MFD device, as that is where the of_node
  1228. * will reside, but if we devm against that the GPIO
  1229. * will not be freed if the extcon driver is unloaded.
  1230. */
  1231. info->micd_pol_gpio = gpiod_get_optional(arizona->dev,
  1232. "wlf,micd-pol",
  1233. GPIOD_OUT_LOW);
  1234. if (IS_ERR(info->micd_pol_gpio)) {
  1235. ret = PTR_ERR(info->micd_pol_gpio);
  1236. dev_err(arizona->dev,
  1237. "Failed to get microphone polarity GPIO: %d\n",
  1238. ret);
  1239. return ret;
  1240. }
  1241. }
  1242. if (arizona->pdata.hpdet_id_gpio > 0) {
  1243. ret = devm_gpio_request_one(&pdev->dev,
  1244. arizona->pdata.hpdet_id_gpio,
  1245. GPIOF_OUT_INIT_LOW,
  1246. "HPDET");
  1247. if (ret != 0) {
  1248. dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
  1249. arizona->pdata.hpdet_id_gpio, ret);
  1250. goto err_gpio;
  1251. }
  1252. }
  1253. if (arizona->pdata.micd_bias_start_time)
  1254. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  1255. ARIZONA_MICD_BIAS_STARTTIME_MASK,
  1256. arizona->pdata.micd_bias_start_time
  1257. << ARIZONA_MICD_BIAS_STARTTIME_SHIFT);
  1258. if (arizona->pdata.micd_rate)
  1259. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  1260. ARIZONA_MICD_RATE_MASK,
  1261. arizona->pdata.micd_rate
  1262. << ARIZONA_MICD_RATE_SHIFT);
  1263. switch (arizona->pdata.micd_dbtime) {
  1264. case MICD_DBTIME_FOUR_READINGS:
  1265. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  1266. ARIZONA_MICD_DBTIME_MASK,
  1267. ARIZONA_MICD_DBTIME);
  1268. break;
  1269. case MICD_DBTIME_TWO_READINGS:
  1270. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
  1271. ARIZONA_MICD_DBTIME_MASK, 0);
  1272. break;
  1273. default:
  1274. break;
  1275. }
  1276. BUILD_BUG_ON(ARRAY_SIZE(arizona_micd_levels) <
  1277. ARIZONA_NUM_MICD_BUTTON_LEVELS);
  1278. if (arizona->pdata.num_micd_ranges) {
  1279. info->micd_ranges = pdata->micd_ranges;
  1280. info->num_micd_ranges = pdata->num_micd_ranges;
  1281. } else {
  1282. info->micd_ranges = micd_default_ranges;
  1283. info->num_micd_ranges = ARRAY_SIZE(micd_default_ranges);
  1284. }
  1285. if (arizona->pdata.num_micd_ranges > ARIZONA_MAX_MICD_RANGE) {
  1286. dev_err(arizona->dev, "Too many MICD ranges: %d\n",
  1287. arizona->pdata.num_micd_ranges);
  1288. }
  1289. if (info->num_micd_ranges > 1) {
  1290. for (i = 1; i < info->num_micd_ranges; i++) {
  1291. if (info->micd_ranges[i - 1].max >
  1292. info->micd_ranges[i].max) {
  1293. dev_err(arizona->dev,
  1294. "MICD ranges must be sorted\n");
  1295. ret = -EINVAL;
  1296. goto err_gpio;
  1297. }
  1298. }
  1299. }
  1300. /* Disable all buttons by default */
  1301. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
  1302. ARIZONA_MICD_LVL_SEL_MASK, 0x81);
  1303. /* Set up all the buttons the user specified */
  1304. for (i = 0; i < info->num_micd_ranges; i++) {
  1305. for (j = 0; j < ARIZONA_NUM_MICD_BUTTON_LEVELS; j++)
  1306. if (arizona_micd_levels[j] >= info->micd_ranges[i].max)
  1307. break;
  1308. if (j == ARIZONA_NUM_MICD_BUTTON_LEVELS) {
  1309. dev_err(arizona->dev, "Unsupported MICD level %d\n",
  1310. info->micd_ranges[i].max);
  1311. ret = -EINVAL;
  1312. goto err_gpio;
  1313. }
  1314. dev_dbg(arizona->dev, "%d ohms for MICD threshold %d\n",
  1315. arizona_micd_levels[j], i);
  1316. arizona_micd_set_level(arizona, i, j);
  1317. input_set_capability(info->input, EV_KEY,
  1318. info->micd_ranges[i].key);
  1319. /* Enable reporting of that range */
  1320. regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_2,
  1321. 1 << i, 1 << i);
  1322. }
  1323. /* Set all the remaining keys to a maximum */
  1324. for (; i < ARIZONA_MAX_MICD_RANGE; i++)
  1325. arizona_micd_set_level(arizona, i, 0x3f);
  1326. /*
  1327. * If we have a clamp use it, activating in conjunction with
  1328. * GPIO5 if that is connected for jack detect operation.
  1329. */
  1330. if (info->micd_clamp) {
  1331. if (arizona->pdata.jd_gpio5) {
  1332. /* Put the GPIO into input mode with optional pull */
  1333. val = 0xc101;
  1334. if (arizona->pdata.jd_gpio5_nopull)
  1335. val &= ~ARIZONA_GPN_PU;
  1336. regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL,
  1337. val);
  1338. if (arizona->pdata.jd_invert)
  1339. clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH_GP5H;
  1340. else
  1341. clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL_GP5H;
  1342. } else {
  1343. if (arizona->pdata.jd_invert)
  1344. clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDH;
  1345. else
  1346. clamp_mode = ARIZONA_MICD_CLAMP_MODE_JDL;
  1347. }
  1348. regmap_update_bits(arizona->regmap,
  1349. ARIZONA_MICD_CLAMP_CONTROL,
  1350. ARIZONA_MICD_CLAMP_MODE_MASK, clamp_mode);
  1351. regmap_update_bits(arizona->regmap,
  1352. ARIZONA_JACK_DETECT_DEBOUNCE,
  1353. ARIZONA_MICD_CLAMP_DB,
  1354. ARIZONA_MICD_CLAMP_DB);
  1355. }
  1356. arizona_extcon_set_mode(info, 0);
  1357. pm_runtime_enable(&pdev->dev);
  1358. pm_runtime_idle(&pdev->dev);
  1359. pm_runtime_get_sync(&pdev->dev);
  1360. if (info->micd_clamp) {
  1361. jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
  1362. jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
  1363. } else {
  1364. jack_irq_rise = ARIZONA_IRQ_JD_RISE;
  1365. jack_irq_fall = ARIZONA_IRQ_JD_FALL;
  1366. }
  1367. ret = arizona_request_irq(arizona, jack_irq_rise,
  1368. "JACKDET rise", arizona_jackdet, info);
  1369. if (ret != 0) {
  1370. dev_err(&pdev->dev, "Failed to get JACKDET rise IRQ: %d\n",
  1371. ret);
  1372. goto err_pm;
  1373. }
  1374. ret = arizona_set_irq_wake(arizona, jack_irq_rise, 1);
  1375. if (ret != 0) {
  1376. dev_err(&pdev->dev, "Failed to set JD rise IRQ wake: %d\n",
  1377. ret);
  1378. goto err_rise;
  1379. }
  1380. ret = arizona_request_irq(arizona, jack_irq_fall,
  1381. "JACKDET fall", arizona_jackdet, info);
  1382. if (ret != 0) {
  1383. dev_err(&pdev->dev, "Failed to get JD fall IRQ: %d\n", ret);
  1384. goto err_rise_wake;
  1385. }
  1386. ret = arizona_set_irq_wake(arizona, jack_irq_fall, 1);
  1387. if (ret != 0) {
  1388. dev_err(&pdev->dev, "Failed to set JD fall IRQ wake: %d\n",
  1389. ret);
  1390. goto err_fall;
  1391. }
  1392. ret = arizona_request_irq(arizona, ARIZONA_IRQ_MICDET,
  1393. "MICDET", arizona_micdet, info);
  1394. if (ret != 0) {
  1395. dev_err(&pdev->dev, "Failed to get MICDET IRQ: %d\n", ret);
  1396. goto err_fall_wake;
  1397. }
  1398. ret = arizona_request_irq(arizona, ARIZONA_IRQ_HPDET,
  1399. "HPDET", arizona_hpdet_irq, info);
  1400. if (ret != 0) {
  1401. dev_err(&pdev->dev, "Failed to get HPDET IRQ: %d\n", ret);
  1402. goto err_micdet;
  1403. }
  1404. arizona_clk32k_enable(arizona);
  1405. regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE,
  1406. ARIZONA_JD1_DB, ARIZONA_JD1_DB);
  1407. regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
  1408. ARIZONA_JD1_ENA, ARIZONA_JD1_ENA);
  1409. ret = regulator_allow_bypass(info->micvdd, true);
  1410. if (ret != 0)
  1411. dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n",
  1412. ret);
  1413. ret = input_register_device(info->input);
  1414. if (ret) {
  1415. dev_err(&pdev->dev, "Can't register input device: %d\n", ret);
  1416. goto err_hpdet;
  1417. }
  1418. pm_runtime_put(&pdev->dev);
  1419. return 0;
  1420. err_hpdet:
  1421. arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
  1422. err_micdet:
  1423. arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
  1424. err_fall_wake:
  1425. arizona_set_irq_wake(arizona, jack_irq_fall, 0);
  1426. err_fall:
  1427. arizona_free_irq(arizona, jack_irq_fall, info);
  1428. err_rise_wake:
  1429. arizona_set_irq_wake(arizona, jack_irq_rise, 0);
  1430. err_rise:
  1431. arizona_free_irq(arizona, jack_irq_rise, info);
  1432. err_pm:
  1433. pm_runtime_put(&pdev->dev);
  1434. pm_runtime_disable(&pdev->dev);
  1435. err_gpio:
  1436. gpiod_put(info->micd_pol_gpio);
  1437. return ret;
  1438. }
  1439. static int arizona_extcon_remove(struct platform_device *pdev)
  1440. {
  1441. struct arizona_extcon_info *info = platform_get_drvdata(pdev);
  1442. struct arizona *arizona = info->arizona;
  1443. int jack_irq_rise, jack_irq_fall;
  1444. bool change;
  1445. int ret;
  1446. if (info->micd_clamp) {
  1447. jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
  1448. jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
  1449. } else {
  1450. jack_irq_rise = ARIZONA_IRQ_JD_RISE;
  1451. jack_irq_fall = ARIZONA_IRQ_JD_FALL;
  1452. }
  1453. arizona_set_irq_wake(arizona, jack_irq_rise, 0);
  1454. arizona_set_irq_wake(arizona, jack_irq_fall, 0);
  1455. arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
  1456. arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
  1457. arizona_free_irq(arizona, jack_irq_rise, info);
  1458. arizona_free_irq(arizona, jack_irq_fall, info);
  1459. cancel_delayed_work_sync(&info->hpdet_work);
  1460. cancel_delayed_work_sync(&info->micd_detect_work);
  1461. cancel_delayed_work_sync(&info->micd_timeout_work);
  1462. ret = regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
  1463. ARIZONA_MICD_ENA, 0,
  1464. &change);
  1465. if (ret < 0) {
  1466. dev_err(&pdev->dev, "Failed to disable micd on remove: %d\n",
  1467. ret);
  1468. } else if (change) {
  1469. regulator_disable(info->micvdd);
  1470. pm_runtime_put(info->dev);
  1471. }
  1472. regmap_update_bits(arizona->regmap,
  1473. ARIZONA_MICD_CLAMP_CONTROL,
  1474. ARIZONA_MICD_CLAMP_MODE_MASK, 0);
  1475. regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
  1476. ARIZONA_JD1_ENA, 0);
  1477. arizona_clk32k_disable(arizona);
  1478. gpiod_put(info->micd_pol_gpio);
  1479. pm_runtime_disable(&pdev->dev);
  1480. return 0;
  1481. }
  1482. static struct platform_driver arizona_extcon_driver = {
  1483. .driver = {
  1484. .name = "arizona-extcon",
  1485. },
  1486. .probe = arizona_extcon_probe,
  1487. .remove = arizona_extcon_remove,
  1488. };
  1489. module_platform_driver(arizona_extcon_driver);
  1490. MODULE_DESCRIPTION("Arizona Extcon driver");
  1491. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  1492. MODULE_LICENSE("GPL");
  1493. MODULE_ALIAS("platform:extcon-arizona");