extcon-arizona.c 45 KB

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