17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/i2c.h>
20 #include <linux/slab.h>
24 #include <linux/input.h>
34 #define ARIZONA_NUM_BUTTONS 6
73 #define ARIZONA_CABLE_MECHANICAL 0
74 #define ARIZONA_CABLE_MICROPHONE 1
75 #define ARIZONA_CABLE_HEADPHONE 2
77 static const char *arizona_cable[] = {
98 dev_dbg(arizona->
dev,
"Set jack polarity to %d\n", mode);
112 pm_runtime_get(info->
dev);
116 dev_err(arizona->
dev,
"Failed to enable MICVDD: %d\n",
131 pm_runtime_put_autosuspend(info->
dev);
137 struct arizona *arizona = info->
arizona;
152 pm_runtime_mark_last_busy(info->
dev);
153 pm_runtime_put_autosuspend(info->
dev);
160 struct arizona *arizona = info->
arizona;
161 unsigned int val, lvl;
168 dev_err(arizona->
dev,
"Failed to read MICDET: %d\n", ret);
175 dev_warn(arizona->
dev,
"Microphone detection state invalid\n");
196 dev_err(arizona->
dev,
"Headset report failed: %d\n",
214 dev_dbg(arizona->
dev,
"Detected headphone\n");
216 arizona_stop_mic(info);
223 "Headphone report failed: %d\n",
229 arizona_extcon_set_mode(info, info->
micd_mode);
243 dev_dbg(arizona->
dev,
"Mic button detected\n");
249 if (lvl & arizona_lvl_to_key[i].
status)
250 input_report_key(info->
input,
251 arizona_lvl_to_key[i].report,
253 input_sync(info->
input);
256 dev_dbg(arizona->
dev,
"Headphone detected\n");
258 arizona_stop_mic(info);
265 "Headphone report failed: %d\n",
272 dev_dbg(arizona->
dev,
"Mic button released\n");
274 input_report_key(info->
input,
275 arizona_lvl_to_key[i].report, 0);
276 input_sync(info->
input);
280 pm_runtime_mark_last_busy(info->
dev);
286 static irqreturn_t arizona_jackdet(
int irq,
void *data)
289 struct arizona *arizona = info->
arizona;
293 pm_runtime_get_sync(info->
dev);
299 dev_err(arizona->
dev,
"Failed to read jackdet status: %d\n",
302 pm_runtime_put_autosuspend(info->
dev);
312 dev_err(arizona->
dev,
"Mechanical report failed: %d\n",
315 arizona_start_mic(info);
317 dev_dbg(arizona->
dev,
"Detected jack removal\n");
319 arizona_stop_mic(info);
322 input_report_key(info->
input,
323 arizona_lvl_to_key[i].report, 0);
324 input_sync(info->
input);
328 dev_err(arizona->
dev,
"Removal report failed: %d\n",
334 pm_runtime_mark_last_busy(info->
dev);
335 pm_runtime_put_autosuspend(info->
dev);
347 pdata = dev_get_platdata(arizona->
dev);
351 dev_err(&pdev->
dev,
"Failed to allocate memory\n");
357 if (IS_ERR(info->
micvdd)) {
358 ret = PTR_ERR(info->
micvdd);
359 dev_err(arizona->
dev,
"Failed to get MICVDD: %d\n", ret);
367 platform_set_drvdata(pdev, info);
369 switch (arizona->
type) {
371 switch (arizona->
rev) {
383 info->
edev.name =
"Headset Jack";
384 info->
edev.supported_cable = arizona_cable;
388 dev_err(arizona->
dev,
"extcon_dev_register() failed: %d\n",
401 if (arizona->
pdata.micd_pol_gpio > 0) {
408 arizona->
pdata.micd_pol_gpio,
412 dev_err(arizona->
dev,
"Failed to request GPIO%d: %d\n",
413 arizona->
pdata.micd_pol_gpio, ret);
418 arizona_extcon_set_mode(info, 0);
420 info->
input = input_allocate_device();
422 dev_err(arizona->
dev,
"Can't allocate input dev\n");
429 arizona_lvl_to_key[i].report);
430 info->
input->name =
"Headset";
431 info->
input->phys =
"arizona/extcon";
432 info->
input->dev.parent = &pdev->
dev;
435 pm_runtime_idle(&pdev->
dev);
436 pm_runtime_get_sync(&pdev->
dev);
439 "JACKDET rise", arizona_jackdet, info);
441 dev_err(&pdev->
dev,
"Failed to get JACKDET rise IRQ: %d\n",
448 dev_err(&pdev->
dev,
"Failed to set JD rise IRQ wake: %d\n",
454 "JACKDET fall", arizona_jackdet, info);
456 dev_err(&pdev->
dev,
"Failed to get JD fall IRQ: %d\n", ret);
462 dev_err(&pdev->
dev,
"Failed to set JD fall IRQ wake: %d\n",
468 "MICDET", arizona_micdet, info);
470 dev_err(&pdev->
dev,
"Failed to get MICDET IRQ: %d\n", ret);
488 dev_warn(arizona->
dev,
"Failed to set MICVDD to bypass: %d\n",
491 pm_runtime_put(&pdev->
dev);
493 ret = input_register_device(info->
input);
495 dev_err(&pdev->
dev,
"Can't register input device: %d\n", ret);
512 input_free_device(info->
input);
514 pm_runtime_disable(&pdev->
dev);
523 struct arizona *arizona = info->
arizona;
525 pm_runtime_disable(&pdev->
dev);
535 input_unregister_device(info->
input);
543 .name =
"arizona-extcon",
546 .probe = arizona_extcon_probe,