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