blob: de141f72c8e5cce51e2ca9b24dd626cc87a49fb1 [file] [log] [blame]
Mark Brownf2c32a82012-06-24 12:09:45 +01001/*
2 * extcon-arizona.c - Extcon driver Wolfson Arizona devices
3 *
4 * Copyright (C) 2012 Wolfson Microelectronics plc
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/i2c.h>
20#include <linux/slab.h>
21#include <linux/interrupt.h>
22#include <linux/err.h>
23#include <linux/gpio.h>
Mark Brown34efe4d2012-07-20 17:07:29 +010024#include <linux/input.h>
Mark Brownf2c32a82012-06-24 12:09:45 +010025#include <linux/platform_device.h>
26#include <linux/pm_runtime.h>
27#include <linux/regulator/consumer.h>
28#include <linux/extcon.h>
29
30#include <linux/mfd/arizona/core.h>
31#include <linux/mfd/arizona/pdata.h>
32#include <linux/mfd/arizona/registers.h>
33
Mark Brown4f340332013-01-11 08:55:43 +090034#define ARIZONA_DEFAULT_HP 32
35
Mark Brown34efe4d2012-07-20 17:07:29 +010036#define ARIZONA_NUM_BUTTONS 6
37
Mark Brown4f340332013-01-11 08:55:43 +090038#define ARIZONA_ACCDET_MODE_MIC 0
39#define ARIZONA_ACCDET_MODE_HPL 1
40#define ARIZONA_ACCDET_MODE_HPR 2
41
Mark Brownf2c32a82012-06-24 12:09:45 +010042struct arizona_extcon_info {
43 struct device *dev;
44 struct arizona *arizona;
45 struct mutex lock;
46 struct regulator *micvdd;
Mark Brown34efe4d2012-07-20 17:07:29 +010047 struct input_dev *input;
Mark Brownf2c32a82012-06-24 12:09:45 +010048
49 int micd_mode;
50 const struct arizona_micd_config *micd_modes;
51 int micd_num_modes;
52
53 bool micd_reva;
Mark Browndab63eb2013-01-11 08:55:36 +090054 bool micd_clamp;
Mark Brownf2c32a82012-06-24 12:09:45 +010055
Mark Brown4f340332013-01-11 08:55:43 +090056 bool hpdet_active;
57
Mark Browndd235ee2013-01-11 08:55:51 +090058 int num_hpdet_res;
Mark Brown1eda6aa2013-01-11 08:55:54 +090059 unsigned int hpdet_res[3];
Mark Browndd235ee2013-01-11 08:55:51 +090060
Mark Brownf2c32a82012-06-24 12:09:45 +010061 bool mic;
62 bool detecting;
63 int jack_flips;
64
Mark Brown4f340332013-01-11 08:55:43 +090065 int hpdet_ip;
66
Mark Brownf2c32a82012-06-24 12:09:45 +010067 struct extcon_dev edev;
68};
69
70static const struct arizona_micd_config micd_default_modes[] = {
Mark Brownf2c32a82012-06-24 12:09:45 +010071 { 0, 2 << ARIZONA_MICD_BIAS_SRC_SHIFT, 1 },
Mark Browndd235ee2013-01-11 08:55:51 +090072 { ARIZONA_ACCDET_SRC, 1 << ARIZONA_MICD_BIAS_SRC_SHIFT, 0 },
Mark Brownf2c32a82012-06-24 12:09:45 +010073};
74
Mark Brown34efe4d2012-07-20 17:07:29 +010075static struct {
76 u16 status;
77 int report;
78} arizona_lvl_to_key[ARIZONA_NUM_BUTTONS] = {
79 { 0x1, BTN_0 },
80 { 0x2, BTN_1 },
81 { 0x4, BTN_2 },
82 { 0x8, BTN_3 },
83 { 0x10, BTN_4 },
84 { 0x20, BTN_5 },
85};
86
Mark Brown325c6422012-06-28 13:08:30 +010087#define ARIZONA_CABLE_MECHANICAL 0
88#define ARIZONA_CABLE_MICROPHONE 1
89#define ARIZONA_CABLE_HEADPHONE 2
Mark Brown4f340332013-01-11 08:55:43 +090090#define ARIZONA_CABLE_LINEOUT 3
Mark Brownf2c32a82012-06-24 12:09:45 +010091
92static const char *arizona_cable[] = {
Mark Brown325c6422012-06-28 13:08:30 +010093 "Mechanical",
94 "Microphone",
95 "Headphone",
Mark Brown4f340332013-01-11 08:55:43 +090096 "Line-out",
Mark Brownf2c32a82012-06-24 12:09:45 +010097 NULL,
98};
99
Mark Brownf2c32a82012-06-24 12:09:45 +0100100static void arizona_extcon_set_mode(struct arizona_extcon_info *info, int mode)
101{
102 struct arizona *arizona = info->arizona;
103
Mark Browncd74f7b2012-11-27 16:14:26 +0900104 if (arizona->pdata.micd_pol_gpio > 0)
105 gpio_set_value_cansleep(arizona->pdata.micd_pol_gpio,
106 info->micd_modes[mode].gpio);
Mark Brownf2c32a82012-06-24 12:09:45 +0100107 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
108 ARIZONA_MICD_BIAS_SRC_MASK,
109 info->micd_modes[mode].bias);
110 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
111 ARIZONA_ACCDET_SRC, info->micd_modes[mode].src);
112
113 info->micd_mode = mode;
114
115 dev_dbg(arizona->dev, "Set jack polarity to %d\n", mode);
116}
117
Mark Brown9b1270c2013-01-11 08:55:46 +0900118static void arizona_start_mic(struct arizona_extcon_info *info)
119{
120 struct arizona *arizona = info->arizona;
121 bool change;
122 int ret;
123
Mark Brown9b1270c2013-01-11 08:55:46 +0900124 /* Microphone detection can't use idle mode */
125 pm_runtime_get(info->dev);
126
127 ret = regulator_enable(info->micvdd);
128 if (ret != 0) {
129 dev_err(arizona->dev, "Failed to enable MICVDD: %d\n",
130 ret);
131 }
132
133 if (info->micd_reva) {
134 regmap_write(arizona->regmap, 0x80, 0x3);
135 regmap_write(arizona->regmap, 0x294, 0);
136 regmap_write(arizona->regmap, 0x80, 0x0);
137 }
138
139 regmap_update_bits(arizona->regmap,
140 ARIZONA_ACCESSORY_DETECT_MODE_1,
141 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
142
143 regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
144 ARIZONA_MICD_ENA, ARIZONA_MICD_ENA,
145 &change);
146 if (!change) {
147 regulator_disable(info->micvdd);
148 pm_runtime_put_autosuspend(info->dev);
149 }
150}
151
152static void arizona_stop_mic(struct arizona_extcon_info *info)
153{
154 struct arizona *arizona = info->arizona;
155 bool change;
156
157 regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
158 ARIZONA_MICD_ENA, 0,
159 &change);
160
161 if (info->micd_reva) {
162 regmap_write(arizona->regmap, 0x80, 0x3);
163 regmap_write(arizona->regmap, 0x294, 2);
164 regmap_write(arizona->regmap, 0x80, 0x0);
165 }
166
167 if (change) {
168 regulator_disable(info->micvdd);
169 pm_runtime_mark_last_busy(info->dev);
170 pm_runtime_put_autosuspend(info->dev);
171 }
172}
173
Mark Brown4f340332013-01-11 08:55:43 +0900174static struct {
175 unsigned int factor_a;
176 unsigned int factor_b;
177} arizona_hpdet_b_ranges[] = {
178 { 5528, 362464 },
179 { 11084, 6186851 },
180 { 11065, 65460395 },
181};
182
183static struct {
184 int min;
185 int max;
186} arizona_hpdet_c_ranges[] = {
187 { 0, 30 },
188 { 8, 100 },
189 { 100, 1000 },
190 { 1000, 10000 },
191};
192
193static int arizona_hpdet_read(struct arizona_extcon_info *info)
194{
195 struct arizona *arizona = info->arizona;
196 unsigned int val, range;
197 int ret;
198
199 ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2, &val);
200 if (ret != 0) {
201 dev_err(arizona->dev, "Failed to read HPDET status: %d\n",
202 ret);
203 return ret;
204 }
205
206 switch (info->hpdet_ip) {
207 case 0:
208 if (!(val & ARIZONA_HP_DONE)) {
209 dev_err(arizona->dev, "HPDET did not complete: %x\n",
210 val);
211 val = ARIZONA_DEFAULT_HP;
212 }
213
214 val &= ARIZONA_HP_LVL_MASK;
215 break;
216
217 case 1:
218 if (!(val & ARIZONA_HP_DONE_B)) {
219 dev_err(arizona->dev, "HPDET did not complete: %x\n",
220 val);
221 return ARIZONA_DEFAULT_HP;
222 }
223
224 ret = regmap_read(arizona->regmap, ARIZONA_HP_DACVAL, &val);
225 if (ret != 0) {
226 dev_err(arizona->dev, "Failed to read HP value: %d\n",
227 ret);
228 return ARIZONA_DEFAULT_HP;
229 }
230
231 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
232 &range);
233 range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
234 >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
235
236 if (range < ARRAY_SIZE(arizona_hpdet_b_ranges) - 1 &&
237 (val < 100 || val > 0x3fb)) {
238 range++;
239 dev_dbg(arizona->dev, "Moving to HPDET range %d\n",
240 range);
241 regmap_update_bits(arizona->regmap,
242 ARIZONA_HEADPHONE_DETECT_1,
243 ARIZONA_HP_IMPEDANCE_RANGE_MASK,
244 range <<
245 ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
246 return -EAGAIN;
247 }
248
249 /* If we go out of range report top of range */
250 if (val < 100 || val > 0x3fb) {
251 dev_dbg(arizona->dev, "Measurement out of range\n");
252 return 10000;
253 }
254
255 dev_dbg(arizona->dev, "HPDET read %d in range %d\n",
256 val, range);
257
258 val = arizona_hpdet_b_ranges[range].factor_b
259 / ((val * 100) -
260 arizona_hpdet_b_ranges[range].factor_a);
261 break;
262
263 default:
264 dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n",
265 info->hpdet_ip);
266 case 2:
267 if (!(val & ARIZONA_HP_DONE_B)) {
268 dev_err(arizona->dev, "HPDET did not complete: %x\n",
269 val);
270 return ARIZONA_DEFAULT_HP;
271 }
272
273 val &= ARIZONA_HP_LVL_B_MASK;
274
275 regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
276 &range);
277 range = (range & ARIZONA_HP_IMPEDANCE_RANGE_MASK)
278 >> ARIZONA_HP_IMPEDANCE_RANGE_SHIFT;
279
280 /* Skip up or down a range? */
281 if (range && (val < arizona_hpdet_c_ranges[range].min)) {
282 range--;
283 dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
284 arizona_hpdet_c_ranges[range].min,
285 arizona_hpdet_c_ranges[range].max);
286 regmap_update_bits(arizona->regmap,
287 ARIZONA_HEADPHONE_DETECT_1,
288 ARIZONA_HP_IMPEDANCE_RANGE_MASK,
289 range <<
290 ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
291 return -EAGAIN;
292 }
293
294 if (range < ARRAY_SIZE(arizona_hpdet_c_ranges) - 1 &&
295 (val >= arizona_hpdet_c_ranges[range].max)) {
296 range++;
297 dev_dbg(arizona->dev, "Moving to HPDET range %d-%d\n",
298 arizona_hpdet_c_ranges[range].min,
299 arizona_hpdet_c_ranges[range].max);
300 regmap_update_bits(arizona->regmap,
301 ARIZONA_HEADPHONE_DETECT_1,
302 ARIZONA_HP_IMPEDANCE_RANGE_MASK,
303 range <<
304 ARIZONA_HP_IMPEDANCE_RANGE_SHIFT);
305 return -EAGAIN;
306 }
307 }
308
309 dev_dbg(arizona->dev, "HP impedance %d ohms\n", val);
310 return val;
311}
312
Mark Browndd235ee2013-01-11 08:55:51 +0900313static int arizona_hpdet_do_id(struct arizona_extcon_info *info, int *reading)
314{
315 struct arizona *arizona = info->arizona;
Mark Brown1eda6aa2013-01-11 08:55:54 +0900316 int id_gpio = arizona->pdata.hpdet_id_gpio;
Mark Browndd235ee2013-01-11 08:55:51 +0900317 int ret;
318
319 /*
320 * If we're using HPDET for accessory identification we need
321 * to take multiple measurements, step through them in sequence.
322 */
323 if (arizona->pdata.hpdet_acc_id) {
324 info->hpdet_res[info->num_hpdet_res++] = *reading;
325
326 /*
327 * If the impedence is too high don't measure the
328 * second ground.
329 */
330 if (info->num_hpdet_res == 1 && *reading >= 45) {
331 dev_dbg(arizona->dev, "Skipping ground flip\n");
332 info->hpdet_res[info->num_hpdet_res++] = *reading;
333 }
334
335 if (info->num_hpdet_res == 1) {
336 dev_dbg(arizona->dev, "Flipping ground\n");
337
338 regmap_update_bits(arizona->regmap,
339 ARIZONA_ACCESSORY_DETECT_MODE_1,
340 ARIZONA_ACCDET_SRC,
341 ~info->micd_modes[0].src);
Mark Brown1eda6aa2013-01-11 08:55:54 +0900342
Mark Browndd235ee2013-01-11 08:55:51 +0900343 regmap_update_bits(arizona->regmap,
344 ARIZONA_HEADPHONE_DETECT_1,
Mark Brown1eda6aa2013-01-11 08:55:54 +0900345 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
346 return -EAGAIN;
347 }
348
349 /* Only check the mic directly if we didn't already ID it */
350 if (id_gpio && info->num_hpdet_res == 2 &&
351 !((info->hpdet_res[0] > info->hpdet_res[1] * 2))) {
352 dev_dbg(arizona->dev, "Measuring mic\n");
353
354 regmap_update_bits(arizona->regmap,
355 ARIZONA_ACCESSORY_DETECT_MODE_1,
356 ARIZONA_ACCDET_MODE_MASK |
357 ARIZONA_ACCDET_SRC,
358 ARIZONA_ACCDET_MODE_HPR |
359 info->micd_modes[0].src);
360
361 gpio_set_value_cansleep(id_gpio, 1);
362
Mark Browndd235ee2013-01-11 08:55:51 +0900363 regmap_update_bits(arizona->regmap,
364 ARIZONA_HEADPHONE_DETECT_1,
365 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
366 return -EAGAIN;
367 }
368
369 /* OK, got both. Now, compare... */
Mark Brown1eda6aa2013-01-11 08:55:54 +0900370 dev_dbg(arizona->dev, "HPDET measured %d %d %d\n",
371 info->hpdet_res[0], info->hpdet_res[1],
372 info->hpdet_res[2]);
Mark Browndd235ee2013-01-11 08:55:51 +0900373
Mark Brown1eda6aa2013-01-11 08:55:54 +0900374 /*
375 * Either the two grounds measure differently or we
376 * measure the mic as high impedance.
377 */
378 if ((info->hpdet_res[0] > info->hpdet_res[1] * 2) ||
379 (id_gpio && info->hpdet_res[2] > 10)) {
Mark Browndd235ee2013-01-11 08:55:51 +0900380 dev_dbg(arizona->dev, "Detected mic\n");
381 info->mic = true;
382 ret = extcon_set_cable_state_(&info->edev,
383 ARIZONA_CABLE_MICROPHONE,
384 true);
385 if (ret != 0) {
386 dev_err(arizona->dev,
387 "Failed to report mic: %d\n", ret);
388 }
389
390 /* Take the headphone impedance for the main report */
391 *reading = info->hpdet_res[1];
392 } else {
393 dev_dbg(arizona->dev, "Detected headphone\n");
394 }
395
396 /* Make sure everything is reset back to the real polarity */
397 regmap_update_bits(arizona->regmap,
398 ARIZONA_ACCESSORY_DETECT_MODE_1,
399 ARIZONA_ACCDET_SRC,
400 info->micd_modes[0].src);
401 }
402
403 return 0;
404}
405
Mark Brown4f340332013-01-11 08:55:43 +0900406static irqreturn_t arizona_hpdet_irq(int irq, void *data)
407{
408 struct arizona_extcon_info *info = data;
409 struct arizona *arizona = info->arizona;
Mark Brown1eda6aa2013-01-11 08:55:54 +0900410 int id_gpio = arizona->pdata.hpdet_id_gpio;
Mark Brown4f340332013-01-11 08:55:43 +0900411 int report = ARIZONA_CABLE_HEADPHONE;
Mark Browndd235ee2013-01-11 08:55:51 +0900412 int ret, reading;
Mark Brown4f340332013-01-11 08:55:43 +0900413
414 mutex_lock(&info->lock);
415
416 /* If we got a spurious IRQ for some reason then ignore it */
417 if (!info->hpdet_active) {
418 dev_warn(arizona->dev, "Spurious HPDET IRQ\n");
419 mutex_unlock(&info->lock);
420 return IRQ_NONE;
421 }
422
423 /* If the cable was removed while measuring ignore the result */
424 ret = extcon_get_cable_state_(&info->edev, ARIZONA_CABLE_MECHANICAL);
425 if (ret < 0) {
426 dev_err(arizona->dev, "Failed to check cable state: %d\n",
427 ret);
428 goto out;
429 } else if (!ret) {
430 dev_dbg(arizona->dev, "Ignoring HPDET for removed cable\n");
431 goto done;
432 }
433
434 ret = arizona_hpdet_read(info);
435 if (ret == -EAGAIN) {
436 goto out;
437 } else if (ret < 0) {
438 goto done;
439 }
Mark Browndd235ee2013-01-11 08:55:51 +0900440 reading = ret;
Mark Brown4f340332013-01-11 08:55:43 +0900441
442 /* Reset back to starting range */
443 regmap_update_bits(arizona->regmap,
444 ARIZONA_HEADPHONE_DETECT_1,
Mark Browndd235ee2013-01-11 08:55:51 +0900445 ARIZONA_HP_IMPEDANCE_RANGE_MASK | ARIZONA_HP_POLL,
446 0);
447
448 ret = arizona_hpdet_do_id(info, &reading);
449 if (ret == -EAGAIN) {
450 goto out;
451 } else if (ret < 0) {
452 goto done;
453 }
Mark Brown4f340332013-01-11 08:55:43 +0900454
455 /* Report high impedence cables as line outputs */
Mark Browndd235ee2013-01-11 08:55:51 +0900456 if (reading >= 5000)
Mark Brown4f340332013-01-11 08:55:43 +0900457 report = ARIZONA_CABLE_LINEOUT;
458 else
459 report = ARIZONA_CABLE_HEADPHONE;
460
461 ret = extcon_set_cable_state_(&info->edev, report, true);
462 if (ret != 0)
463 dev_err(arizona->dev, "Failed to report HP/line: %d\n",
464 ret);
465
466 ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0);
467 if (ret != 0)
468 dev_warn(arizona->dev, "Failed to undo magic: %d\n", ret);
469
470 ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0);
471 if (ret != 0)
472 dev_warn(arizona->dev, "Failed to undo magic: %d\n", ret);
473
474done:
Mark Brown1eda6aa2013-01-11 08:55:54 +0900475 if (id_gpio)
476 gpio_set_value_cansleep(id_gpio, 0);
Mark Brown4f340332013-01-11 08:55:43 +0900477
478 /* Revert back to MICDET mode */
479 regmap_update_bits(arizona->regmap,
480 ARIZONA_ACCESSORY_DETECT_MODE_1,
481 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
482
483 /* If we have a mic then reenable MICDET */
484 if (info->mic)
485 arizona_start_mic(info);
486
487 if (info->hpdet_active) {
488 pm_runtime_put_autosuspend(info->dev);
489 info->hpdet_active = false;
490 }
491
492out:
493 mutex_unlock(&info->lock);
494
495 return IRQ_HANDLED;
496}
497
498static void arizona_identify_headphone(struct arizona_extcon_info *info)
499{
500 struct arizona *arizona = info->arizona;
501 int ret;
502
503 dev_dbg(arizona->dev, "Starting HPDET\n");
504
505 /* Make sure we keep the device enabled during the measurement */
506 pm_runtime_get(info->dev);
507
508 info->hpdet_active = true;
509
510 if (info->mic)
511 arizona_stop_mic(info);
512
513 ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0x4000);
514 if (ret != 0)
515 dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
516
517 ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0x4000);
518 if (ret != 0)
519 dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
520
521 ret = regmap_update_bits(arizona->regmap,
522 ARIZONA_ACCESSORY_DETECT_MODE_1,
523 ARIZONA_ACCDET_MODE_MASK,
524 ARIZONA_ACCDET_MODE_HPL);
525 if (ret != 0) {
526 dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret);
527 goto err;
528 }
529
530 ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
531 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
532 if (ret != 0) {
533 dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
534 ret);
535 goto err;
536 }
537
538 return;
539
540err:
541 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
542 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
543
544 /* Just report headphone */
545 ret = extcon_update_state(&info->edev,
546 1 << ARIZONA_CABLE_HEADPHONE,
547 1 << ARIZONA_CABLE_HEADPHONE);
548 if (ret != 0)
549 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
550
551 if (info->mic)
552 arizona_start_mic(info);
553
554 info->hpdet_active = false;
555}
Mark Browndd235ee2013-01-11 08:55:51 +0900556
557static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info)
558{
559 struct arizona *arizona = info->arizona;
560 int ret;
561
562 dev_dbg(arizona->dev, "Starting identification via HPDET\n");
563
564 /* Make sure we keep the device enabled during the measurement */
565 pm_runtime_get(info->dev);
566
567 info->hpdet_active = true;
568
569 ret = regmap_update_bits(arizona->regmap, 0x225, 0x4000, 0x4000);
570 if (ret != 0)
571 dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
572
573 ret = regmap_update_bits(arizona->regmap, 0x226, 0x4000, 0x4000);
574 if (ret != 0)
575 dev_warn(arizona->dev, "Failed to do magic: %d\n", ret);
576
577 ret = regmap_update_bits(arizona->regmap,
578 ARIZONA_ACCESSORY_DETECT_MODE_1,
579 ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK,
580 info->micd_modes[0].src |
581 ARIZONA_ACCDET_MODE_HPL);
582 if (ret != 0) {
583 dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret);
584 goto err;
Mark Brown4f340332013-01-11 08:55:43 +0900585 }
586
Mark Browndd235ee2013-01-11 08:55:51 +0900587 ret = regmap_update_bits(arizona->regmap, ARIZONA_HEADPHONE_DETECT_1,
588 ARIZONA_HP_POLL, ARIZONA_HP_POLL);
589 if (ret != 0) {
590 dev_err(arizona->dev, "Can't start HPDETL measurement: %d\n",
591 ret);
592 goto err;
593 }
594
595 return;
596
597err:
598 regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1,
599 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
600
601 /* Just report headphone */
602 ret = extcon_update_state(&info->edev,
603 1 << ARIZONA_CABLE_HEADPHONE,
604 1 << ARIZONA_CABLE_HEADPHONE);
605 if (ret != 0)
606 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
607
Mark Brown4f340332013-01-11 08:55:43 +0900608 info->hpdet_active = false;
609}
610
Mark Brownf2c32a82012-06-24 12:09:45 +0100611static irqreturn_t arizona_micdet(int irq, void *data)
612{
613 struct arizona_extcon_info *info = data;
614 struct arizona *arizona = info->arizona;
Mark Brown34efe4d2012-07-20 17:07:29 +0100615 unsigned int val, lvl;
616 int ret, i;
Mark Brownf2c32a82012-06-24 12:09:45 +0100617
618 mutex_lock(&info->lock);
619
620 ret = regmap_read(arizona->regmap, ARIZONA_MIC_DETECT_3, &val);
621 if (ret != 0) {
622 dev_err(arizona->dev, "Failed to read MICDET: %d\n", ret);
Alexey Khoroshilovbe31cc02012-11-05 17:11:41 +0900623 mutex_unlock(&info->lock);
Mark Brownf2c32a82012-06-24 12:09:45 +0100624 return IRQ_NONE;
625 }
626
627 dev_dbg(arizona->dev, "MICDET: %x\n", val);
628
629 if (!(val & ARIZONA_MICD_VALID)) {
630 dev_warn(arizona->dev, "Microphone detection state invalid\n");
631 mutex_unlock(&info->lock);
632 return IRQ_NONE;
633 }
634
635 /* Due to jack detect this should never happen */
636 if (!(val & ARIZONA_MICD_STS)) {
637 dev_warn(arizona->dev, "Detected open circuit\n");
638 info->detecting = false;
639 goto handled;
640 }
641
642 /* If we got a high impedence we should have a headset, report it. */
643 if (info->detecting && (val & 0x400)) {
Mark Brown4f340332013-01-11 08:55:43 +0900644 arizona_identify_headphone(info);
645
Mark Brown325c6422012-06-28 13:08:30 +0100646 ret = extcon_update_state(&info->edev,
Mark Brown4f340332013-01-11 08:55:43 +0900647 1 << ARIZONA_CABLE_MICROPHONE,
648 1 << ARIZONA_CABLE_MICROPHONE);
Mark Brownf2c32a82012-06-24 12:09:45 +0100649
650 if (ret != 0)
651 dev_err(arizona->dev, "Headset report failed: %d\n",
652 ret);
653
654 info->mic = true;
655 info->detecting = false;
656 goto handled;
657 }
658
659 /* If we detected a lower impedence during initial startup
660 * then we probably have the wrong polarity, flip it. Don't
661 * do this for the lowest impedences to speed up detection of
662 * plain headphones. If both polarities report a low
663 * impedence then give up and report headphones.
664 */
665 if (info->detecting && (val & 0x3f8)) {
666 info->jack_flips++;
667
668 if (info->jack_flips >= info->micd_num_modes) {
Mark Brown4f340332013-01-11 08:55:43 +0900669 dev_dbg(arizona->dev, "Detected HP/line\n");
670 arizona_identify_headphone(info);
Mark Brown9ef2224d2012-06-28 13:08:31 +0100671
Mark Brown4f340332013-01-11 08:55:43 +0900672 info->detecting = false;
673
674 arizona_stop_mic(info);
Mark Brownf2c32a82012-06-24 12:09:45 +0100675 } else {
676 info->micd_mode++;
677 if (info->micd_mode == info->micd_num_modes)
678 info->micd_mode = 0;
679 arizona_extcon_set_mode(info, info->micd_mode);
680
681 info->jack_flips++;
682 }
683
684 goto handled;
685 }
686
687 /*
688 * If we're still detecting and we detect a short then we've
Mark Brown34efe4d2012-07-20 17:07:29 +0100689 * got a headphone. Otherwise it's a button press.
Mark Brownf2c32a82012-06-24 12:09:45 +0100690 */
691 if (val & 0x3fc) {
692 if (info->mic) {
693 dev_dbg(arizona->dev, "Mic button detected\n");
694
Mark Brown34efe4d2012-07-20 17:07:29 +0100695 lvl = val & ARIZONA_MICD_LVL_MASK;
696 lvl >>= ARIZONA_MICD_LVL_SHIFT;
697
698 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
699 if (lvl & arizona_lvl_to_key[i].status)
700 input_report_key(info->input,
701 arizona_lvl_to_key[i].report,
702 1);
703 input_sync(info->input);
704
Mark Brownf2c32a82012-06-24 12:09:45 +0100705 } else if (info->detecting) {
706 dev_dbg(arizona->dev, "Headphone detected\n");
707 info->detecting = false;
708 arizona_stop_mic(info);
709
Mark Brown4f340332013-01-11 08:55:43 +0900710 arizona_identify_headphone(info);
Mark Brownf2c32a82012-06-24 12:09:45 +0100711 } else {
712 dev_warn(arizona->dev, "Button with no mic: %x\n",
713 val);
714 }
715 } else {
716 dev_dbg(arizona->dev, "Mic button released\n");
Mark Brown34efe4d2012-07-20 17:07:29 +0100717 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
718 input_report_key(info->input,
719 arizona_lvl_to_key[i].report, 0);
720 input_sync(info->input);
Mark Brownf2c32a82012-06-24 12:09:45 +0100721 }
722
723handled:
724 pm_runtime_mark_last_busy(info->dev);
725 mutex_unlock(&info->lock);
726
727 return IRQ_HANDLED;
728}
729
730static irqreturn_t arizona_jackdet(int irq, void *data)
731{
732 struct arizona_extcon_info *info = data;
733 struct arizona *arizona = info->arizona;
Mark Brown92a49872013-01-11 08:55:39 +0900734 unsigned int val, present, mask;
Mark Brown34efe4d2012-07-20 17:07:29 +0100735 int ret, i;
Mark Brownf2c32a82012-06-24 12:09:45 +0100736
737 pm_runtime_get_sync(info->dev);
738
739 mutex_lock(&info->lock);
740
Mark Brown92a49872013-01-11 08:55:39 +0900741 if (arizona->pdata.jd_gpio5) {
742 mask = ARIZONA_MICD_CLAMP_STS;
743 present = 0;
744 } else {
745 mask = ARIZONA_JD1_STS;
746 present = ARIZONA_JD1_STS;
747 }
748
Mark Brownf2c32a82012-06-24 12:09:45 +0100749 ret = regmap_read(arizona->regmap, ARIZONA_AOD_IRQ_RAW_STATUS, &val);
750 if (ret != 0) {
751 dev_err(arizona->dev, "Failed to read jackdet status: %d\n",
752 ret);
753 mutex_unlock(&info->lock);
754 pm_runtime_put_autosuspend(info->dev);
755 return IRQ_NONE;
756 }
757
Mark Brown92a49872013-01-11 08:55:39 +0900758 if ((val & mask) == present) {
Mark Brownf2c32a82012-06-24 12:09:45 +0100759 dev_dbg(arizona->dev, "Detected jack\n");
Mark Brown325c6422012-06-28 13:08:30 +0100760 ret = extcon_set_cable_state_(&info->edev,
761 ARIZONA_CABLE_MECHANICAL, true);
Mark Brownf2c32a82012-06-24 12:09:45 +0100762
763 if (ret != 0)
764 dev_err(arizona->dev, "Mechanical report failed: %d\n",
765 ret);
766
Mark Browndd235ee2013-01-11 08:55:51 +0900767 if (!arizona->pdata.hpdet_acc_id) {
768 info->detecting = true;
769 info->mic = false;
770 info->jack_flips = 0;
771
772 arizona_start_mic(info);
773 } else {
774 arizona_start_hpdet_acc_id(info);
775 }
Mark Brownf2c32a82012-06-24 12:09:45 +0100776 } else {
777 dev_dbg(arizona->dev, "Detected jack removal\n");
778
779 arizona_stop_mic(info);
780
Mark Browndd235ee2013-01-11 08:55:51 +0900781 info->num_hpdet_res = 0;
782 for (i = 0; i < ARRAY_SIZE(info->hpdet_res); i++)
783 info->hpdet_res[i] = 0;
784 info->mic = false;
Mark Brown92a49872013-01-11 08:55:39 +0900785
Mark Brown34efe4d2012-07-20 17:07:29 +0100786 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
787 input_report_key(info->input,
788 arizona_lvl_to_key[i].report, 0);
789 input_sync(info->input);
790
Mark Brownf2c32a82012-06-24 12:09:45 +0100791 ret = extcon_update_state(&info->edev, 0xffffffff, 0);
792 if (ret != 0)
793 dev_err(arizona->dev, "Removal report failed: %d\n",
794 ret);
795 }
796
797 mutex_unlock(&info->lock);
798
799 pm_runtime_mark_last_busy(info->dev);
800 pm_runtime_put_autosuspend(info->dev);
801
802 return IRQ_HANDLED;
803}
804
Bill Pemberton44f34fd2012-11-19 13:23:21 -0500805static int arizona_extcon_probe(struct platform_device *pdev)
Mark Brownf2c32a82012-06-24 12:09:45 +0100806{
807 struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
808 struct arizona_pdata *pdata;
809 struct arizona_extcon_info *info;
Mark Brown92a49872013-01-11 08:55:39 +0900810 int jack_irq_fall, jack_irq_rise;
Mark Brown34efe4d2012-07-20 17:07:29 +0100811 int ret, mode, i;
Mark Brownf2c32a82012-06-24 12:09:45 +0100812
813 pdata = dev_get_platdata(arizona->dev);
814
815 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
816 if (!info) {
Peter Meerwald8e5f5012012-08-23 09:11:50 +0900817 dev_err(&pdev->dev, "Failed to allocate memory\n");
Mark Brownf2c32a82012-06-24 12:09:45 +0100818 ret = -ENOMEM;
819 goto err;
820 }
821
822 info->micvdd = devm_regulator_get(arizona->dev, "MICVDD");
823 if (IS_ERR(info->micvdd)) {
824 ret = PTR_ERR(info->micvdd);
825 dev_err(arizona->dev, "Failed to get MICVDD: %d\n", ret);
826 goto err;
827 }
828
829 mutex_init(&info->lock);
830 info->arizona = arizona;
831 info->dev = &pdev->dev;
Mark Brownf2c32a82012-06-24 12:09:45 +0100832 platform_set_drvdata(pdev, info);
833
834 switch (arizona->type) {
835 case WM5102:
836 switch (arizona->rev) {
837 case 0:
838 info->micd_reva = true;
839 break;
840 default:
Mark Browndab63eb2013-01-11 08:55:36 +0900841 info->micd_clamp = true;
Mark Brown4f340332013-01-11 08:55:43 +0900842 info->hpdet_ip = 1;
Mark Brownf2c32a82012-06-24 12:09:45 +0100843 break;
844 }
845 break;
846 default:
847 break;
848 }
849
850 info->edev.name = "Headset Jack";
851 info->edev.supported_cable = arizona_cable;
Mark Brownf2c32a82012-06-24 12:09:45 +0100852
853 ret = extcon_dev_register(&info->edev, arizona->dev);
854 if (ret < 0) {
Peter Meerwald8e5f5012012-08-23 09:11:50 +0900855 dev_err(arizona->dev, "extcon_dev_register() failed: %d\n",
Mark Brownf2c32a82012-06-24 12:09:45 +0100856 ret);
857 goto err;
858 }
859
860 if (pdata->num_micd_configs) {
861 info->micd_modes = pdata->micd_configs;
862 info->micd_num_modes = pdata->num_micd_configs;
863 } else {
864 info->micd_modes = micd_default_modes;
865 info->micd_num_modes = ARRAY_SIZE(micd_default_modes);
866 }
867
868 if (arizona->pdata.micd_pol_gpio > 0) {
869 if (info->micd_modes[0].gpio)
870 mode = GPIOF_OUT_INIT_HIGH;
871 else
872 mode = GPIOF_OUT_INIT_LOW;
873
874 ret = devm_gpio_request_one(&pdev->dev,
875 arizona->pdata.micd_pol_gpio,
876 mode,
877 "MICD polarity");
878 if (ret != 0) {
879 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
880 arizona->pdata.micd_pol_gpio, ret);
881 goto err_register;
882 }
883 }
884
Mark Brown1eda6aa2013-01-11 08:55:54 +0900885 if (arizona->pdata.hpdet_id_gpio > 0) {
886 ret = devm_gpio_request_one(&pdev->dev,
887 arizona->pdata.hpdet_id_gpio,
888 GPIOF_OUT_INIT_LOW,
889 "HPDET");
890 if (ret != 0) {
891 dev_err(arizona->dev, "Failed to request GPIO%d: %d\n",
892 arizona->pdata.hpdet_id_gpio, ret);
893 goto err_register;
894 }
895 }
896
Mark Brownb17e5462013-01-11 08:55:24 +0900897 if (arizona->pdata.micd_bias_start_time)
898 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
899 ARIZONA_MICD_BIAS_STARTTIME_MASK,
900 arizona->pdata.micd_bias_start_time
901 << ARIZONA_MICD_BIAS_STARTTIME_SHIFT);
902
Mark Browndab63eb2013-01-11 08:55:36 +0900903 /*
Mark Brown92a49872013-01-11 08:55:39 +0900904 * If we have a clamp use it, activating in conjunction with
905 * GPIO5 if that is connected for jack detect operation.
Mark Browndab63eb2013-01-11 08:55:36 +0900906 */
907 if (info->micd_clamp) {
Mark Brown92a49872013-01-11 08:55:39 +0900908 if (arizona->pdata.jd_gpio5) {
909 /* Put the GPIO into input mode */
910 regmap_write(arizona->regmap, ARIZONA_GPIO5_CTRL,
911 0xc101);
912
913 regmap_update_bits(arizona->regmap,
914 ARIZONA_MICD_CLAMP_CONTROL,
915 ARIZONA_MICD_CLAMP_MODE_MASK, 0x9);
916 } else {
917 regmap_update_bits(arizona->regmap,
918 ARIZONA_MICD_CLAMP_CONTROL,
919 ARIZONA_MICD_CLAMP_MODE_MASK, 0x4);
920 }
921
Mark Browndab63eb2013-01-11 08:55:36 +0900922 regmap_update_bits(arizona->regmap,
923 ARIZONA_JACK_DETECT_DEBOUNCE,
924 ARIZONA_MICD_CLAMP_DB,
925 ARIZONA_MICD_CLAMP_DB);
926 }
927
Mark Brownf2c32a82012-06-24 12:09:45 +0100928 arizona_extcon_set_mode(info, 0);
929
Mark Brown3d44ea12013-01-11 08:51:13 +0900930 info->input = devm_input_allocate_device(&pdev->dev);
Mark Brown34efe4d2012-07-20 17:07:29 +0100931 if (!info->input) {
932 dev_err(arizona->dev, "Can't allocate input dev\n");
933 ret = -ENOMEM;
934 goto err_register;
935 }
936
937 for (i = 0; i < ARIZONA_NUM_BUTTONS; i++)
938 input_set_capability(info->input, EV_KEY,
939 arizona_lvl_to_key[i].report);
940 info->input->name = "Headset";
941 info->input->phys = "arizona/extcon";
942 info->input->dev.parent = &pdev->dev;
943
Mark Brownf2c32a82012-06-24 12:09:45 +0100944 pm_runtime_enable(&pdev->dev);
945 pm_runtime_idle(&pdev->dev);
946 pm_runtime_get_sync(&pdev->dev);
947
Mark Brown92a49872013-01-11 08:55:39 +0900948 if (arizona->pdata.jd_gpio5) {
949 jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
950 jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
951 } else {
952 jack_irq_rise = ARIZONA_IRQ_JD_RISE;
953 jack_irq_fall = ARIZONA_IRQ_JD_FALL;
954 }
955
956 ret = arizona_request_irq(arizona, jack_irq_rise,
Mark Brownf2c32a82012-06-24 12:09:45 +0100957 "JACKDET rise", arizona_jackdet, info);
958 if (ret != 0) {
959 dev_err(&pdev->dev, "Failed to get JACKDET rise IRQ: %d\n",
960 ret);
Mark Brown34efe4d2012-07-20 17:07:29 +0100961 goto err_input;
Mark Brownf2c32a82012-06-24 12:09:45 +0100962 }
963
Mark Brown92a49872013-01-11 08:55:39 +0900964 ret = arizona_set_irq_wake(arizona, jack_irq_rise, 1);
Mark Brownf2c32a82012-06-24 12:09:45 +0100965 if (ret != 0) {
966 dev_err(&pdev->dev, "Failed to set JD rise IRQ wake: %d\n",
967 ret);
968 goto err_rise;
969 }
970
Mark Brown92a49872013-01-11 08:55:39 +0900971 ret = arizona_request_irq(arizona, jack_irq_fall,
Mark Brownf2c32a82012-06-24 12:09:45 +0100972 "JACKDET fall", arizona_jackdet, info);
973 if (ret != 0) {
974 dev_err(&pdev->dev, "Failed to get JD fall IRQ: %d\n", ret);
975 goto err_rise_wake;
976 }
977
Mark Brown92a49872013-01-11 08:55:39 +0900978 ret = arizona_set_irq_wake(arizona, jack_irq_fall, 1);
Mark Brownf2c32a82012-06-24 12:09:45 +0100979 if (ret != 0) {
980 dev_err(&pdev->dev, "Failed to set JD fall IRQ wake: %d\n",
981 ret);
982 goto err_fall;
983 }
984
985 ret = arizona_request_irq(arizona, ARIZONA_IRQ_MICDET,
986 "MICDET", arizona_micdet, info);
987 if (ret != 0) {
988 dev_err(&pdev->dev, "Failed to get MICDET IRQ: %d\n", ret);
989 goto err_fall_wake;
990 }
991
Mark Brown4f340332013-01-11 08:55:43 +0900992 ret = arizona_request_irq(arizona, ARIZONA_IRQ_HPDET,
993 "HPDET", arizona_hpdet_irq, info);
994 if (ret != 0) {
995 dev_err(&pdev->dev, "Failed to get HPDET IRQ: %d\n", ret);
996 goto err_micdet;
997 }
998
Mark Brownf2c32a82012-06-24 12:09:45 +0100999 regmap_update_bits(arizona->regmap, ARIZONA_MIC_DETECT_1,
Mark Brownf2c32a82012-06-24 12:09:45 +01001000 ARIZONA_MICD_RATE_MASK,
Mark Brownf2c32a82012-06-24 12:09:45 +01001001 8 << ARIZONA_MICD_RATE_SHIFT);
1002
1003 arizona_clk32k_enable(arizona);
1004 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_DEBOUNCE,
1005 ARIZONA_JD1_DB, ARIZONA_JD1_DB);
1006 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
1007 ARIZONA_JD1_ENA, ARIZONA_JD1_ENA);
1008
Mark Brownb8575a12012-09-07 17:01:15 +08001009 ret = regulator_allow_bypass(info->micvdd, true);
1010 if (ret != 0)
1011 dev_warn(arizona->dev, "Failed to set MICVDD to bypass: %d\n",
1012 ret);
1013
Mark Brownf2c32a82012-06-24 12:09:45 +01001014 pm_runtime_put(&pdev->dev);
1015
Mark Brown34efe4d2012-07-20 17:07:29 +01001016 ret = input_register_device(info->input);
1017 if (ret) {
1018 dev_err(&pdev->dev, "Can't register input device: %d\n", ret);
Mark Brown4f340332013-01-11 08:55:43 +09001019 goto err_hpdet;
Mark Brown34efe4d2012-07-20 17:07:29 +01001020 }
1021
Mark Brownf2c32a82012-06-24 12:09:45 +01001022 return 0;
1023
Mark Brown4f340332013-01-11 08:55:43 +09001024err_hpdet:
1025 arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
Mark Brown80732cc2012-08-26 13:58:20 -07001026err_micdet:
1027 arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
Mark Brownf2c32a82012-06-24 12:09:45 +01001028err_fall_wake:
Mark Brown92a49872013-01-11 08:55:39 +09001029 arizona_set_irq_wake(arizona, jack_irq_fall, 0);
Mark Brownf2c32a82012-06-24 12:09:45 +01001030err_fall:
Mark Brown92a49872013-01-11 08:55:39 +09001031 arizona_free_irq(arizona, jack_irq_fall, info);
Mark Brownf2c32a82012-06-24 12:09:45 +01001032err_rise_wake:
Mark Brown92a49872013-01-11 08:55:39 +09001033 arizona_set_irq_wake(arizona, jack_irq_rise, 0);
Mark Brownf2c32a82012-06-24 12:09:45 +01001034err_rise:
Mark Brown92a49872013-01-11 08:55:39 +09001035 arizona_free_irq(arizona, jack_irq_rise, info);
Mark Brown34efe4d2012-07-20 17:07:29 +01001036err_input:
Mark Brownf2c32a82012-06-24 12:09:45 +01001037err_register:
1038 pm_runtime_disable(&pdev->dev);
1039 extcon_dev_unregister(&info->edev);
1040err:
1041 return ret;
1042}
1043
Bill Pemberton93ed0322012-11-19 13:25:49 -05001044static int arizona_extcon_remove(struct platform_device *pdev)
Mark Brownf2c32a82012-06-24 12:09:45 +01001045{
1046 struct arizona_extcon_info *info = platform_get_drvdata(pdev);
1047 struct arizona *arizona = info->arizona;
Mark Brown92a49872013-01-11 08:55:39 +09001048 int jack_irq_rise, jack_irq_fall;
Mark Brownf2c32a82012-06-24 12:09:45 +01001049
1050 pm_runtime_disable(&pdev->dev);
1051
Mark Browndab63eb2013-01-11 08:55:36 +09001052 regmap_update_bits(arizona->regmap,
1053 ARIZONA_MICD_CLAMP_CONTROL,
1054 ARIZONA_MICD_CLAMP_MODE_MASK, 0);
1055
Mark Brown92a49872013-01-11 08:55:39 +09001056 if (arizona->pdata.jd_gpio5) {
1057 jack_irq_rise = ARIZONA_IRQ_MICD_CLAMP_RISE;
1058 jack_irq_fall = ARIZONA_IRQ_MICD_CLAMP_FALL;
1059 } else {
1060 jack_irq_rise = ARIZONA_IRQ_JD_RISE;
1061 jack_irq_fall = ARIZONA_IRQ_JD_FALL;
1062 }
1063
1064 arizona_set_irq_wake(arizona, jack_irq_rise, 0);
1065 arizona_set_irq_wake(arizona, jack_irq_fall, 0);
1066 arizona_free_irq(arizona, ARIZONA_IRQ_HPDET, info);
Mark Brownf2c32a82012-06-24 12:09:45 +01001067 arizona_free_irq(arizona, ARIZONA_IRQ_MICDET, info);
Mark Brown92a49872013-01-11 08:55:39 +09001068 arizona_free_irq(arizona, jack_irq_rise, info);
1069 arizona_free_irq(arizona, jack_irq_fall, info);
Mark Brownf2c32a82012-06-24 12:09:45 +01001070 regmap_update_bits(arizona->regmap, ARIZONA_JACK_DETECT_ANALOGUE,
1071 ARIZONA_JD1_ENA, 0);
1072 arizona_clk32k_disable(arizona);
Mark Brownf2c32a82012-06-24 12:09:45 +01001073 extcon_dev_unregister(&info->edev);
1074
1075 return 0;
1076}
1077
1078static struct platform_driver arizona_extcon_driver = {
1079 .driver = {
1080 .name = "arizona-extcon",
1081 .owner = THIS_MODULE,
1082 },
1083 .probe = arizona_extcon_probe,
Bill Pemberton5f7e2222012-11-19 13:20:06 -05001084 .remove = arizona_extcon_remove,
Mark Brownf2c32a82012-06-24 12:09:45 +01001085};
1086
1087module_platform_driver(arizona_extcon_driver);
1088
1089MODULE_DESCRIPTION("Arizona Extcon driver");
1090MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
1091MODULE_LICENSE("GPL");
1092MODULE_ALIAS("platform:extcon-arizona");