Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1 | /* |
| 2 | * extcon-max77693.c - MAX77693 extcon driver to support MAX77693 MUIC |
| 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electrnoics |
| 5 | * Chanwoo Choi <cw00.choi@samsung.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/i2c.h> |
| 21 | #include <linux/slab.h> |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 22 | #include <linux/input.h> |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/err.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/mfd/max77693.h> |
| 27 | #include <linux/mfd/max77693-private.h> |
| 28 | #include <linux/extcon.h> |
| 29 | #include <linux/regmap.h> |
| 30 | #include <linux/irqdomain.h> |
| 31 | |
| 32 | #define DEV_NAME "max77693-muic" |
Chanwoo Choi | 297620f | 2012-12-26 13:10:11 +0900 | [diff] [blame^] | 33 | #define DELAY_MS_DEFAULT 20000 /* unit: millisecond */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 34 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 35 | enum max77693_muic_adc_debounce_time { |
| 36 | ADC_DEBOUNCE_TIME_5MS = 0, |
| 37 | ADC_DEBOUNCE_TIME_10MS, |
| 38 | ADC_DEBOUNCE_TIME_25MS, |
| 39 | ADC_DEBOUNCE_TIME_38_62MS, |
| 40 | }; |
| 41 | |
| 42 | struct max77693_muic_info { |
| 43 | struct device *dev; |
| 44 | struct max77693_dev *max77693; |
| 45 | struct extcon_dev *edev; |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 46 | int prev_cable_type; |
| 47 | int prev_cable_type_gnd; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 48 | int prev_chg_type; |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 49 | int prev_button_type; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 50 | u8 status[2]; |
| 51 | |
| 52 | int irq; |
| 53 | struct work_struct irq_work; |
| 54 | struct mutex mutex; |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 55 | |
Chanwoo Choi | 297620f | 2012-12-26 13:10:11 +0900 | [diff] [blame^] | 56 | /* |
| 57 | * Use delayed workqueue to detect cable state and then |
| 58 | * notify cable state to notifiee/platform through uevent. |
| 59 | * After completing the booting of platform, the extcon provider |
| 60 | * driver should notify cable state to upper layer. |
| 61 | */ |
| 62 | struct delayed_work wq_detcable; |
| 63 | |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 64 | /* Button of dock device */ |
| 65 | struct input_dev *dock; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 66 | }; |
| 67 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 68 | enum max77693_muic_cable_group { |
| 69 | MAX77693_CABLE_GROUP_ADC = 0, |
| 70 | MAX77693_CABLE_GROUP_ADC_GND, |
| 71 | MAX77693_CABLE_GROUP_CHG, |
| 72 | MAX77693_CABLE_GROUP_VBVOLT, |
| 73 | }; |
| 74 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 75 | enum max77693_muic_charger_type { |
| 76 | MAX77693_CHARGER_TYPE_NONE = 0, |
| 77 | MAX77693_CHARGER_TYPE_USB, |
| 78 | MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT, |
| 79 | MAX77693_CHARGER_TYPE_DEDICATED_CHG, |
| 80 | MAX77693_CHARGER_TYPE_APPLE_500MA, |
| 81 | MAX77693_CHARGER_TYPE_APPLE_1A_2A, |
| 82 | MAX77693_CHARGER_TYPE_DEAD_BATTERY = 7, |
| 83 | }; |
| 84 | |
| 85 | /** |
| 86 | * struct max77693_muic_irq |
| 87 | * @irq: the index of irq list of MUIC device. |
| 88 | * @name: the name of irq. |
| 89 | * @virq: the virtual irq to use irq domain |
| 90 | */ |
| 91 | struct max77693_muic_irq { |
| 92 | unsigned int irq; |
| 93 | const char *name; |
| 94 | unsigned int virq; |
| 95 | }; |
| 96 | |
| 97 | static struct max77693_muic_irq muic_irqs[] = { |
| 98 | { MAX77693_MUIC_IRQ_INT1_ADC, "muic-ADC" }, |
| 99 | { MAX77693_MUIC_IRQ_INT1_ADC_LOW, "muic-ADCLOW" }, |
| 100 | { MAX77693_MUIC_IRQ_INT1_ADC_ERR, "muic-ADCError" }, |
| 101 | { MAX77693_MUIC_IRQ_INT1_ADC1K, "muic-ADC1K" }, |
| 102 | { MAX77693_MUIC_IRQ_INT2_CHGTYP, "muic-CHGTYP" }, |
| 103 | { MAX77693_MUIC_IRQ_INT2_CHGDETREUN, "muic-CHGDETREUN" }, |
| 104 | { MAX77693_MUIC_IRQ_INT2_DCDTMR, "muic-DCDTMR" }, |
| 105 | { MAX77693_MUIC_IRQ_INT2_DXOVP, "muic-DXOVP" }, |
| 106 | { MAX77693_MUIC_IRQ_INT2_VBVOLT, "muic-VBVOLT" }, |
| 107 | { MAX77693_MUIC_IRQ_INT2_VIDRM, "muic-VIDRM" }, |
| 108 | { MAX77693_MUIC_IRQ_INT3_EOC, "muic-EOC" }, |
| 109 | { MAX77693_MUIC_IRQ_INT3_CGMBC, "muic-CGMBC" }, |
| 110 | { MAX77693_MUIC_IRQ_INT3_OVP, "muic-OVP" }, |
| 111 | { MAX77693_MUIC_IRQ_INT3_MBCCHG_ERR, "muic-MBCCHG_ERR" }, |
| 112 | { MAX77693_MUIC_IRQ_INT3_CHG_ENABLED, "muic-CHG_ENABLED" }, |
| 113 | { MAX77693_MUIC_IRQ_INT3_BAT_DET, "muic-BAT_DET" }, |
| 114 | }; |
| 115 | |
| 116 | /* Define supported accessory type */ |
| 117 | enum max77693_muic_acc_type { |
| 118 | MAX77693_MUIC_ADC_GROUND = 0x0, |
| 119 | MAX77693_MUIC_ADC_SEND_END_BUTTON, |
| 120 | MAX77693_MUIC_ADC_REMOTE_S1_BUTTON, |
| 121 | MAX77693_MUIC_ADC_REMOTE_S2_BUTTON, |
| 122 | MAX77693_MUIC_ADC_REMOTE_S3_BUTTON, |
| 123 | MAX77693_MUIC_ADC_REMOTE_S4_BUTTON, |
| 124 | MAX77693_MUIC_ADC_REMOTE_S5_BUTTON, |
| 125 | MAX77693_MUIC_ADC_REMOTE_S6_BUTTON, |
| 126 | MAX77693_MUIC_ADC_REMOTE_S7_BUTTON, |
| 127 | MAX77693_MUIC_ADC_REMOTE_S8_BUTTON, |
| 128 | MAX77693_MUIC_ADC_REMOTE_S9_BUTTON, |
| 129 | MAX77693_MUIC_ADC_REMOTE_S10_BUTTON, |
| 130 | MAX77693_MUIC_ADC_REMOTE_S11_BUTTON, |
| 131 | MAX77693_MUIC_ADC_REMOTE_S12_BUTTON, |
| 132 | MAX77693_MUIC_ADC_RESERVED_ACC_1, |
| 133 | MAX77693_MUIC_ADC_RESERVED_ACC_2, |
| 134 | MAX77693_MUIC_ADC_RESERVED_ACC_3, |
| 135 | MAX77693_MUIC_ADC_RESERVED_ACC_4, |
| 136 | MAX77693_MUIC_ADC_RESERVED_ACC_5, |
| 137 | MAX77693_MUIC_ADC_CEA936_AUDIO, |
| 138 | MAX77693_MUIC_ADC_PHONE_POWERED_DEV, |
| 139 | MAX77693_MUIC_ADC_TTY_CONVERTER, |
| 140 | MAX77693_MUIC_ADC_UART_CABLE, |
| 141 | MAX77693_MUIC_ADC_CEA936A_TYPE1_CHG, |
| 142 | MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF, |
| 143 | MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON, |
| 144 | MAX77693_MUIC_ADC_AV_CABLE_NOLOAD, |
| 145 | MAX77693_MUIC_ADC_CEA936A_TYPE2_CHG, |
| 146 | MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF, |
| 147 | MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON, |
| 148 | MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE, |
| 149 | MAX77693_MUIC_ADC_OPEN, |
| 150 | |
| 151 | /* The below accessories have same ADC value so ADCLow and |
| 152 | ADC1K bit is used to separate specific accessory */ |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 153 | MAX77693_MUIC_GND_USB_OTG = 0x100, /* ADC:0x0, VBVolot:0, ADCLow:0, ADC1K:0 */ |
| 154 | MAX77693_MUIC_GND_USB_OTG_VB = 0x104, /* ADC:0x0, VBVolot:1, ADCLow:0, ADC1K:0 */ |
| 155 | MAX77693_MUIC_GND_AV_CABLE_LOAD = 0x102,/* ADC:0x0, VBVolot:0, ADCLow:1, ADC1K:0 */ |
| 156 | MAX77693_MUIC_GND_MHL = 0x103, /* ADC:0x0, VBVolot:0, ADCLow:1, ADC1K:1 */ |
| 157 | MAX77693_MUIC_GND_MHL_VB = 0x107, /* ADC:0x0, VBVolot:1, ADCLow:1, ADC1K:1 */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | /* MAX77693 MUIC device support below list of accessories(external connector) */ |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 161 | enum { |
| 162 | EXTCON_CABLE_USB = 0, |
| 163 | EXTCON_CABLE_USB_HOST, |
| 164 | EXTCON_CABLE_TA, |
| 165 | EXTCON_CABLE_FAST_CHARGER, |
| 166 | EXTCON_CABLE_SLOW_CHARGER, |
| 167 | EXTCON_CABLE_CHARGE_DOWNSTREAM, |
| 168 | EXTCON_CABLE_MHL, |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 169 | EXTCON_CABLE_MHL_TA, |
Chanwoo Choi | d0587eb | 2012-11-27 12:06:49 +0900 | [diff] [blame] | 170 | EXTCON_CABLE_JIG_USB_ON, |
| 171 | EXTCON_CABLE_JIG_USB_OFF, |
| 172 | EXTCON_CABLE_JIG_UART_OFF, |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 173 | EXTCON_CABLE_JIG_UART_ON, |
| 174 | EXTCON_CABLE_DOCK_SMART, |
| 175 | EXTCON_CABLE_DOCK_DESK, |
| 176 | EXTCON_CABLE_DOCK_AUDIO, |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 177 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 178 | _EXTCON_CABLE_NUM, |
| 179 | }; |
| 180 | |
| 181 | const char *max77693_extcon_cable[] = { |
| 182 | [EXTCON_CABLE_USB] = "USB", |
| 183 | [EXTCON_CABLE_USB_HOST] = "USB-Host", |
| 184 | [EXTCON_CABLE_TA] = "TA", |
| 185 | [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger", |
| 186 | [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", |
| 187 | [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", |
| 188 | [EXTCON_CABLE_MHL] = "MHL", |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 189 | [EXTCON_CABLE_MHL_TA] = "MHL_TA", |
Chanwoo Choi | d0587eb | 2012-11-27 12:06:49 +0900 | [diff] [blame] | 190 | [EXTCON_CABLE_JIG_USB_ON] = "JIG-USB-ON", |
| 191 | [EXTCON_CABLE_JIG_USB_OFF] = "JIG-USB-OFF", |
| 192 | [EXTCON_CABLE_JIG_UART_OFF] = "JIG-UART-OFF", |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 193 | [EXTCON_CABLE_JIG_UART_ON] = "Dock-Car", |
| 194 | [EXTCON_CABLE_DOCK_SMART] = "Dock-Smart", |
| 195 | [EXTCON_CABLE_DOCK_DESK] = "Dock-Desk", |
| 196 | [EXTCON_CABLE_DOCK_AUDIO] = "Dock-Audio", |
Chanwoo Choi | d0587eb | 2012-11-27 12:06:49 +0900 | [diff] [blame] | 197 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 198 | NULL, |
| 199 | }; |
| 200 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 201 | /* |
| 202 | * max77693_muic_set_debounce_time - Set the debounce time of ADC |
| 203 | * @info: the instance including private data of max77693 MUIC |
| 204 | * @time: the debounce time of ADC |
| 205 | */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 206 | static int max77693_muic_set_debounce_time(struct max77693_muic_info *info, |
| 207 | enum max77693_muic_adc_debounce_time time) |
| 208 | { |
Axel Lin | bf2627d | 2012-10-04 09:55:23 +0900 | [diff] [blame] | 209 | int ret; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 210 | |
| 211 | switch (time) { |
| 212 | case ADC_DEBOUNCE_TIME_5MS: |
| 213 | case ADC_DEBOUNCE_TIME_10MS: |
| 214 | case ADC_DEBOUNCE_TIME_25MS: |
| 215 | case ADC_DEBOUNCE_TIME_38_62MS: |
Axel Lin | bf2627d | 2012-10-04 09:55:23 +0900 | [diff] [blame] | 216 | ret = max77693_update_reg(info->max77693->regmap_muic, |
| 217 | MAX77693_MUIC_REG_CTRL3, |
| 218 | time << CONTROL3_ADCDBSET_SHIFT, |
| 219 | CONTROL3_ADCDBSET_MASK); |
| 220 | if (ret) |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 221 | dev_err(info->dev, "failed to set ADC debounce time\n"); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 222 | break; |
| 223 | default: |
| 224 | dev_err(info->dev, "invalid ADC debounce time\n"); |
| 225 | ret = -EINVAL; |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | return ret; |
| 230 | }; |
| 231 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 232 | /* |
| 233 | * max77693_muic_set_path - Set hardware line according to attached cable |
| 234 | * @info: the instance including private data of max77693 MUIC |
| 235 | * @value: the path according to attached cable |
| 236 | * @attached: the state of cable (true:attached, false:detached) |
| 237 | * |
| 238 | * The max77693 MUIC device share outside H/W line among a varity of cables |
| 239 | * so, this function set internal path of H/W line according to the type of |
| 240 | * attached cable. |
| 241 | */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 242 | static int max77693_muic_set_path(struct max77693_muic_info *info, |
| 243 | u8 val, bool attached) |
| 244 | { |
| 245 | int ret = 0; |
| 246 | u8 ctrl1, ctrl2 = 0; |
| 247 | |
| 248 | if (attached) |
| 249 | ctrl1 = val; |
| 250 | else |
| 251 | ctrl1 = CONTROL1_SW_OPEN; |
| 252 | |
| 253 | ret = max77693_update_reg(info->max77693->regmap_muic, |
| 254 | MAX77693_MUIC_REG_CTRL1, ctrl1, COMP_SW_MASK); |
| 255 | if (ret < 0) { |
| 256 | dev_err(info->dev, "failed to update MUIC register\n"); |
| 257 | goto out; |
| 258 | } |
| 259 | |
| 260 | if (attached) |
| 261 | ctrl2 |= CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */ |
| 262 | else |
| 263 | ctrl2 |= CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */ |
| 264 | |
| 265 | ret = max77693_update_reg(info->max77693->regmap_muic, |
| 266 | MAX77693_MUIC_REG_CTRL2, ctrl2, |
| 267 | CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK); |
| 268 | if (ret < 0) { |
| 269 | dev_err(info->dev, "failed to update MUIC register\n"); |
| 270 | goto out; |
| 271 | } |
| 272 | |
| 273 | dev_info(info->dev, |
| 274 | "CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n", |
| 275 | ctrl1, ctrl2, attached ? "attached" : "detached"); |
| 276 | out: |
| 277 | return ret; |
| 278 | } |
| 279 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 280 | /* |
| 281 | * max77693_muic_get_cable_type - Return cable type and check cable state |
| 282 | * @info: the instance including private data of max77693 MUIC |
| 283 | * @group: the path according to attached cable |
| 284 | * @attached: store cable state and return |
| 285 | * |
| 286 | * This function check the cable state either attached or detached, |
| 287 | * and then divide precise type of cable according to cable group. |
| 288 | * - MAX77693_CABLE_GROUP_ADC |
| 289 | * - MAX77693_CABLE_GROUP_ADC_GND |
| 290 | * - MAX77693_CABLE_GROUP_CHG |
| 291 | * - MAX77693_CABLE_GROUP_VBVOLT |
| 292 | */ |
| 293 | static int max77693_muic_get_cable_type(struct max77693_muic_info *info, |
| 294 | enum max77693_muic_cable_group group, bool *attached) |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 295 | { |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 296 | int cable_type = 0; |
| 297 | int adc; |
| 298 | int adc1k; |
| 299 | int adclow; |
| 300 | int vbvolt; |
| 301 | int chg_type; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 302 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 303 | switch (group) { |
| 304 | case MAX77693_CABLE_GROUP_ADC: |
| 305 | /* |
| 306 | * Read ADC value to check cable type and decide cable state |
| 307 | * according to cable type |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 308 | */ |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 309 | adc = info->status[0] & STATUS1_ADC_MASK; |
| 310 | adc >>= STATUS1_ADC_SHIFT; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 311 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 312 | /* |
| 313 | * Check current cable state/cable type and store cable type |
| 314 | * (info->prev_cable_type) for handling cable when cable is |
| 315 | * detached. |
| 316 | */ |
| 317 | if (adc == MAX77693_MUIC_ADC_OPEN) { |
| 318 | *attached = false; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 319 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 320 | cable_type = info->prev_cable_type; |
| 321 | info->prev_cable_type = MAX77693_MUIC_ADC_OPEN; |
| 322 | } else { |
| 323 | *attached = true; |
| 324 | |
| 325 | cable_type = info->prev_cable_type = adc; |
| 326 | } |
| 327 | break; |
| 328 | case MAX77693_CABLE_GROUP_ADC_GND: |
| 329 | /* |
| 330 | * Read ADC value to check cable type and decide cable state |
| 331 | * according to cable type |
| 332 | */ |
| 333 | adc = info->status[0] & STATUS1_ADC_MASK; |
| 334 | adc >>= STATUS1_ADC_SHIFT; |
| 335 | |
| 336 | /* |
| 337 | * Check current cable state/cable type and store cable type |
| 338 | * (info->prev_cable_type/_gnd) for handling cable when cable |
| 339 | * is detached. |
| 340 | */ |
| 341 | if (adc == MAX77693_MUIC_ADC_OPEN) { |
| 342 | *attached = false; |
| 343 | |
| 344 | cable_type = info->prev_cable_type_gnd; |
| 345 | info->prev_cable_type_gnd = MAX77693_MUIC_ADC_OPEN; |
| 346 | } else { |
| 347 | *attached = true; |
| 348 | |
| 349 | adclow = info->status[0] & STATUS1_ADCLOW_MASK; |
| 350 | adclow >>= STATUS1_ADCLOW_SHIFT; |
| 351 | adc1k = info->status[0] & STATUS1_ADC1K_MASK; |
| 352 | adc1k >>= STATUS1_ADC1K_SHIFT; |
| 353 | |
| 354 | vbvolt = info->status[1] & STATUS2_VBVOLT_MASK; |
| 355 | vbvolt >>= STATUS2_VBVOLT_SHIFT; |
| 356 | |
| 357 | /** |
| 358 | * [0x1][VBVolt][ADCLow][ADC1K] |
| 359 | * [0x1 0 0 0 ] : USB_OTG |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 360 | * [0x1 1 0 0 ] : USB_OTG_VB |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 361 | * [0x1 0 1 0 ] : Audio Video Cable with load |
| 362 | * [0x1 0 1 1 ] : MHL without charging connector |
| 363 | * [0x1 1 1 1 ] : MHL with charging connector |
| 364 | */ |
| 365 | cable_type = ((0x1 << 8) |
| 366 | | (vbvolt << 2) |
| 367 | | (adclow << 1) |
| 368 | | adc1k); |
| 369 | |
| 370 | info->prev_cable_type = adc; |
| 371 | info->prev_cable_type_gnd = cable_type; |
| 372 | } |
| 373 | |
| 374 | break; |
| 375 | case MAX77693_CABLE_GROUP_CHG: |
| 376 | /* |
| 377 | * Read charger type to check cable type and decide cable state |
| 378 | * according to type of charger cable. |
| 379 | */ |
| 380 | chg_type = info->status[1] & STATUS2_CHGTYP_MASK; |
| 381 | chg_type >>= STATUS2_CHGTYP_SHIFT; |
| 382 | |
| 383 | if (chg_type == MAX77693_CHARGER_TYPE_NONE) { |
| 384 | *attached = false; |
| 385 | |
| 386 | cable_type = info->prev_chg_type; |
| 387 | info->prev_chg_type = MAX77693_CHARGER_TYPE_NONE; |
| 388 | } else { |
| 389 | *attached = true; |
| 390 | |
| 391 | /* |
| 392 | * Check current cable state/cable type and store cable |
| 393 | * type(info->prev_chg_type) for handling cable when |
| 394 | * charger cable is detached. |
| 395 | */ |
| 396 | cable_type = info->prev_chg_type = chg_type; |
| 397 | } |
| 398 | |
| 399 | break; |
| 400 | case MAX77693_CABLE_GROUP_VBVOLT: |
| 401 | /* |
| 402 | * Read ADC value to check cable type and decide cable state |
| 403 | * according to cable type |
| 404 | */ |
| 405 | adc = info->status[0] & STATUS1_ADC_MASK; |
| 406 | adc >>= STATUS1_ADC_SHIFT; |
| 407 | chg_type = info->status[1] & STATUS2_CHGTYP_MASK; |
| 408 | chg_type >>= STATUS2_CHGTYP_SHIFT; |
| 409 | |
| 410 | if (adc == MAX77693_MUIC_ADC_OPEN |
| 411 | && chg_type == MAX77693_CHARGER_TYPE_NONE) |
| 412 | *attached = false; |
| 413 | else |
| 414 | *attached = true; |
| 415 | |
| 416 | /* |
| 417 | * Read vbvolt field, if vbvolt is 1, |
| 418 | * this cable is used for charging. |
| 419 | */ |
| 420 | vbvolt = info->status[1] & STATUS2_VBVOLT_MASK; |
| 421 | vbvolt >>= STATUS2_VBVOLT_SHIFT; |
| 422 | |
| 423 | cable_type = vbvolt; |
| 424 | break; |
| 425 | default: |
| 426 | dev_err(info->dev, "Unknown cable group (%d)\n", group); |
| 427 | cable_type = -EINVAL; |
| 428 | break; |
| 429 | } |
| 430 | |
| 431 | return cable_type; |
| 432 | } |
| 433 | |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 434 | static int max77693_muic_dock_handler(struct max77693_muic_info *info, |
| 435 | int cable_type, bool attached) |
| 436 | { |
| 437 | int ret = 0; |
| 438 | char dock_name[CABLE_NAME_MAX]; |
| 439 | |
| 440 | dev_info(info->dev, |
| 441 | "external connector is %s (adc:0x%02x)\n", |
| 442 | attached ? "attached" : "detached", cable_type); |
| 443 | |
| 444 | switch (cable_type) { |
| 445 | case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */ |
| 446 | /* PATH:AP_USB */ |
| 447 | ret = max77693_muic_set_path(info, |
| 448 | CONTROL1_SW_USB, attached); |
| 449 | if (ret < 0) |
| 450 | goto out; |
| 451 | |
| 452 | /* Dock-Smart */ |
| 453 | extcon_set_cable_state(info->edev, "Dock-Smart", attached); |
| 454 | goto out; |
| 455 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* Dock-Car */ |
| 456 | strcpy(dock_name, "Dock-Car"); |
| 457 | break; |
| 458 | case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */ |
| 459 | strcpy(dock_name, "Dock-Desk"); |
| 460 | break; |
| 461 | case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */ |
| 462 | strcpy(dock_name, "Dock-Audio"); |
| 463 | if (!attached) |
| 464 | extcon_set_cable_state(info->edev, "USB", false); |
| 465 | break; |
| 466 | } |
| 467 | |
| 468 | /* Dock-Car/Desk/Audio, PATH:AUDIO */ |
| 469 | ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); |
| 470 | if (ret < 0) |
| 471 | goto out; |
| 472 | extcon_set_cable_state(info->edev, dock_name, attached); |
| 473 | |
| 474 | out: |
| 475 | return ret; |
| 476 | } |
| 477 | |
| 478 | static int max77693_muic_dock_button_handler(struct max77693_muic_info *info, |
| 479 | int button_type, bool attached) |
| 480 | { |
| 481 | struct input_dev *dock = info->dock; |
| 482 | unsigned int code; |
| 483 | int ret = 0; |
| 484 | |
| 485 | switch (button_type) { |
| 486 | case MAX77693_MUIC_ADC_REMOTE_S3_BUTTON-1 |
| 487 | ... MAX77693_MUIC_ADC_REMOTE_S3_BUTTON+1: |
| 488 | /* DOCK_KEY_PREV */ |
| 489 | code = KEY_PREVIOUSSONG; |
| 490 | break; |
| 491 | case MAX77693_MUIC_ADC_REMOTE_S7_BUTTON-1 |
| 492 | ... MAX77693_MUIC_ADC_REMOTE_S7_BUTTON+1: |
| 493 | /* DOCK_KEY_NEXT */ |
| 494 | code = KEY_NEXTSONG; |
| 495 | break; |
| 496 | case MAX77693_MUIC_ADC_REMOTE_S9_BUTTON: |
| 497 | /* DOCK_VOL_DOWN */ |
| 498 | code = KEY_VOLUMEDOWN; |
| 499 | break; |
| 500 | case MAX77693_MUIC_ADC_REMOTE_S10_BUTTON: |
| 501 | /* DOCK_VOL_UP */ |
| 502 | code = KEY_VOLUMEUP; |
| 503 | break; |
| 504 | case MAX77693_MUIC_ADC_REMOTE_S12_BUTTON-1 |
| 505 | ... MAX77693_MUIC_ADC_REMOTE_S12_BUTTON+1: |
| 506 | /* DOCK_KEY_PLAY_PAUSE */ |
| 507 | code = KEY_PLAYPAUSE; |
| 508 | break; |
| 509 | default: |
| 510 | dev_err(info->dev, |
| 511 | "failed to detect %s key (adc:0x%x)\n", |
| 512 | attached ? "pressed" : "released", button_type); |
| 513 | ret = -EINVAL; |
| 514 | goto out; |
| 515 | } |
| 516 | |
| 517 | input_event(dock, EV_KEY, code, attached); |
| 518 | input_sync(dock); |
| 519 | |
| 520 | out: |
| 521 | return 0; |
| 522 | } |
| 523 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 524 | static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info) |
| 525 | { |
| 526 | int cable_type_gnd; |
| 527 | int ret = 0; |
| 528 | bool attached; |
| 529 | |
| 530 | cable_type_gnd = max77693_muic_get_cable_type(info, |
| 531 | MAX77693_CABLE_GROUP_ADC_GND, &attached); |
| 532 | |
| 533 | switch (cable_type_gnd) { |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 534 | case MAX77693_MUIC_GND_USB_OTG: |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 535 | case MAX77693_MUIC_GND_USB_OTG_VB: |
| 536 | /* USB_OTG, PATH: AP_USB */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 537 | ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached); |
| 538 | if (ret < 0) |
| 539 | goto out; |
| 540 | extcon_set_cable_state(info->edev, "USB-Host", attached); |
| 541 | break; |
| 542 | case MAX77693_MUIC_GND_AV_CABLE_LOAD: |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 543 | /* Audio Video Cable with load, PATH:AUDIO */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 544 | ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); |
| 545 | if (ret < 0) |
| 546 | goto out; |
| 547 | extcon_set_cable_state(info->edev, |
| 548 | "Audio-video-load", attached); |
| 549 | break; |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 550 | case MAX77693_MUIC_GND_MHL: |
| 551 | case MAX77693_MUIC_GND_MHL_VB: |
| 552 | /* MHL or MHL with USB/TA cable */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 553 | extcon_set_cable_state(info->edev, "MHL", attached); |
| 554 | break; |
| 555 | default: |
Peter Meerwald | afcfaa8 | 2012-08-23 09:11:47 +0900 | [diff] [blame] | 556 | dev_err(info->dev, "failed to detect %s accessory\n", |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 557 | attached ? "attached" : "detached"); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 558 | ret = -EINVAL; |
| 559 | break; |
| 560 | } |
| 561 | |
| 562 | out: |
| 563 | return ret; |
| 564 | } |
| 565 | |
Chanwoo Choi | d0587eb | 2012-11-27 12:06:49 +0900 | [diff] [blame] | 566 | static int max77693_muic_jig_handler(struct max77693_muic_info *info, |
| 567 | int cable_type, bool attached) |
| 568 | { |
| 569 | char cable_name[32]; |
| 570 | int ret = 0; |
| 571 | u8 path = CONTROL1_SW_OPEN; |
| 572 | |
| 573 | dev_info(info->dev, |
| 574 | "external connector is %s (adc:0x%02x)\n", |
| 575 | attached ? "attached" : "detached", cable_type); |
| 576 | |
| 577 | switch (cable_type) { |
| 578 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */ |
| 579 | /* PATH:AP_USB */ |
| 580 | strcpy(cable_name, "JIG-USB-OFF"); |
| 581 | path = CONTROL1_SW_USB; |
| 582 | break; |
| 583 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */ |
| 584 | /* PATH:AP_USB */ |
| 585 | strcpy(cable_name, "JIG-USB-ON"); |
| 586 | path = CONTROL1_SW_USB; |
| 587 | break; |
| 588 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */ |
| 589 | /* PATH:AP_UART */ |
| 590 | strcpy(cable_name, "JIG-UART-OFF"); |
| 591 | path = CONTROL1_SW_UART; |
| 592 | break; |
| 593 | } |
| 594 | |
| 595 | ret = max77693_muic_set_path(info, path, attached); |
| 596 | if (ret < 0) |
| 597 | goto out; |
| 598 | |
| 599 | extcon_set_cable_state(info->edev, cable_name, attached); |
| 600 | out: |
| 601 | return ret; |
| 602 | } |
| 603 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 604 | static int max77693_muic_adc_handler(struct max77693_muic_info *info) |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 605 | { |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 606 | int cable_type; |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 607 | int button_type; |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 608 | bool attached; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 609 | int ret = 0; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 610 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 611 | /* Check accessory state which is either detached or attached */ |
| 612 | cable_type = max77693_muic_get_cable_type(info, |
| 613 | MAX77693_CABLE_GROUP_ADC, &attached); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 614 | |
| 615 | dev_info(info->dev, |
| 616 | "external connector is %s (adc:0x%02x, prev_adc:0x%x)\n", |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 617 | attached ? "attached" : "detached", cable_type, |
| 618 | info->prev_cable_type); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 619 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 620 | switch (cable_type) { |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 621 | case MAX77693_MUIC_ADC_GROUND: |
| 622 | /* USB_OTG/MHL/Audio */ |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 623 | max77693_muic_adc_ground_handler(info); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 624 | break; |
| 625 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: |
| 626 | case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 627 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 628 | /* JIG */ |
Chanwoo Choi | d0587eb | 2012-11-27 12:06:49 +0900 | [diff] [blame] | 629 | ret = max77693_muic_jig_handler(info, cable_type, attached); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 630 | if (ret < 0) |
| 631 | goto out; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 632 | break; |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 633 | case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */ |
| 634 | case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* Dock-Car */ |
| 635 | case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */ |
| 636 | case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */ |
| 637 | /* |
| 638 | * DOCK device |
| 639 | * |
| 640 | * The MAX77693 MUIC device can detect total 34 cable type |
| 641 | * except of charger cable and MUIC device didn't define |
| 642 | * specfic role of cable in the range of from 0x01 to 0x12 |
| 643 | * of ADC value. So, can use/define cable with no role according |
| 644 | * to schema of hardware board. |
| 645 | */ |
| 646 | ret = max77693_muic_dock_handler(info, cable_type, attached); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 647 | if (ret < 0) |
| 648 | goto out; |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 649 | break; |
| 650 | case MAX77693_MUIC_ADC_REMOTE_S3_BUTTON: /* DOCK_KEY_PREV */ |
| 651 | case MAX77693_MUIC_ADC_REMOTE_S7_BUTTON: /* DOCK_KEY_NEXT */ |
| 652 | case MAX77693_MUIC_ADC_REMOTE_S9_BUTTON: /* DOCK_VOL_DOWN */ |
| 653 | case MAX77693_MUIC_ADC_REMOTE_S10_BUTTON: /* DOCK_VOL_UP */ |
| 654 | case MAX77693_MUIC_ADC_REMOTE_S12_BUTTON: /* DOCK_KEY_PLAY_PAUSE */ |
| 655 | /* |
| 656 | * Button of DOCK device |
| 657 | * - the Prev/Next/Volume Up/Volume Down/Play-Pause button |
| 658 | * |
| 659 | * The MAX77693 MUIC device can detect total 34 cable type |
| 660 | * except of charger cable and MUIC device didn't define |
| 661 | * specfic role of cable in the range of from 0x01 to 0x12 |
| 662 | * of ADC value. So, can use/define cable with no role according |
| 663 | * to schema of hardware board. |
| 664 | */ |
| 665 | if (attached) |
| 666 | button_type = info->prev_button_type = cable_type; |
| 667 | else |
| 668 | button_type = info->prev_button_type; |
| 669 | |
| 670 | ret = max77693_muic_dock_button_handler(info, button_type, |
| 671 | attached); |
| 672 | if (ret < 0) |
| 673 | goto out; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 674 | break; |
| 675 | case MAX77693_MUIC_ADC_SEND_END_BUTTON: |
| 676 | case MAX77693_MUIC_ADC_REMOTE_S1_BUTTON: |
| 677 | case MAX77693_MUIC_ADC_REMOTE_S2_BUTTON: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 678 | case MAX77693_MUIC_ADC_REMOTE_S4_BUTTON: |
| 679 | case MAX77693_MUIC_ADC_REMOTE_S5_BUTTON: |
| 680 | case MAX77693_MUIC_ADC_REMOTE_S6_BUTTON: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 681 | case MAX77693_MUIC_ADC_REMOTE_S8_BUTTON: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 682 | case MAX77693_MUIC_ADC_REMOTE_S11_BUTTON: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 683 | case MAX77693_MUIC_ADC_RESERVED_ACC_1: |
| 684 | case MAX77693_MUIC_ADC_RESERVED_ACC_2: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 685 | case MAX77693_MUIC_ADC_RESERVED_ACC_4: |
| 686 | case MAX77693_MUIC_ADC_RESERVED_ACC_5: |
| 687 | case MAX77693_MUIC_ADC_CEA936_AUDIO: |
| 688 | case MAX77693_MUIC_ADC_PHONE_POWERED_DEV: |
| 689 | case MAX77693_MUIC_ADC_TTY_CONVERTER: |
| 690 | case MAX77693_MUIC_ADC_UART_CABLE: |
| 691 | case MAX77693_MUIC_ADC_CEA936A_TYPE1_CHG: |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 692 | case MAX77693_MUIC_ADC_CEA936A_TYPE2_CHG: |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 693 | /* |
| 694 | * This accessory isn't used in general case if it is specially |
| 695 | * needed to detect additional accessory, should implement |
| 696 | * proper operation when this accessory is attached/detached. |
| 697 | */ |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 698 | dev_info(info->dev, |
| 699 | "accessory is %s but it isn't used (adc:0x%x)\n", |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 700 | attached ? "attached" : "detached", cable_type); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 701 | goto out; |
| 702 | default: |
| 703 | dev_err(info->dev, |
| 704 | "failed to detect %s accessory (adc:0x%x)\n", |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 705 | attached ? "attached" : "detached", cable_type); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 706 | ret = -EINVAL; |
| 707 | goto out; |
| 708 | } |
| 709 | |
| 710 | out: |
| 711 | return ret; |
| 712 | } |
| 713 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 714 | static int max77693_muic_chg_handler(struct max77693_muic_info *info) |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 715 | { |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 716 | int chg_type; |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 717 | int cable_type_gnd; |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 718 | int cable_type; |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 719 | bool attached; |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 720 | bool cable_attached; |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 721 | int ret = 0; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 722 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 723 | chg_type = max77693_muic_get_cable_type(info, |
| 724 | MAX77693_CABLE_GROUP_CHG, &attached); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 725 | |
| 726 | dev_info(info->dev, |
| 727 | "external connector is %s(chg_type:0x%x, prev_chg_type:0x%x)\n", |
| 728 | attached ? "attached" : "detached", |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 729 | chg_type, info->prev_chg_type); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 730 | |
| 731 | switch (chg_type) { |
| 732 | case MAX77693_CHARGER_TYPE_USB: |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 733 | /* |
| 734 | * MHL_TA(USB/TA) with MHL cable |
| 735 | * - MHL cable include two port(HDMI line and separate micro |
| 736 | * -usb port. When the target connect MHL cable, extcon driver |
| 737 | * check whether MHL_TA(USB/TA) cable is connected. If MHL_TA |
| 738 | * cable is connected, extcon driver notify state to notifiee |
| 739 | * for charging battery. |
| 740 | */ |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 741 | cable_type_gnd = max77693_muic_get_cable_type(info, |
| 742 | MAX77693_CABLE_GROUP_ADC_GND, |
| 743 | &cable_attached); |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 744 | if (cable_type_gnd == MAX77693_MUIC_GND_MHL |
| 745 | || cable_type_gnd == MAX77693_MUIC_GND_MHL_VB) { |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 746 | extcon_set_cable_state(info->edev, "MHL_TA", attached); |
| 747 | |
| 748 | if (!cable_attached) |
| 749 | extcon_set_cable_state(info->edev, |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 750 | "MHL", false); |
| 751 | goto out; |
Chanwoo Choi | 06bed0a | 2012-11-27 11:30:35 +0900 | [diff] [blame] | 752 | } |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 753 | |
| 754 | /* |
| 755 | * USB/TA cable with Dock-Audio device |
| 756 | * - Dock device include two port(Dock-Audio and micro-usb |
| 757 | * port). When the target connect Dock-Audio device, extcon |
| 758 | * driver check whether USB/TA cable is connected. |
| 759 | * If USB/TA cable is connected, extcon driver notify state |
| 760 | * to notifiee for charging battery. |
| 761 | */ |
| 762 | cable_type = max77693_muic_get_cable_type(info, |
| 763 | MAX77693_CABLE_GROUP_ADC, |
| 764 | &cable_attached); |
| 765 | if (cable_type == MAX77693_MUIC_ADC_AV_CABLE_NOLOAD) { |
| 766 | extcon_set_cable_state(info->edev, "USB", attached); |
| 767 | |
| 768 | if (!cable_attached) |
| 769 | extcon_set_cable_state(info->edev, |
| 770 | "Dock-Audio", false); |
| 771 | goto out; |
| 772 | } |
| 773 | |
| 774 | /* Only USB cable, PATH:AP_USB */ |
| 775 | ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached); |
| 776 | if (ret < 0) |
| 777 | goto out; |
| 778 | extcon_set_cable_state(info->edev, "USB", attached); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 779 | break; |
| 780 | case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT: |
| 781 | extcon_set_cable_state(info->edev, |
| 782 | "Charge-downstream", attached); |
| 783 | break; |
| 784 | case MAX77693_CHARGER_TYPE_DEDICATED_CHG: |
| 785 | extcon_set_cable_state(info->edev, "TA", attached); |
| 786 | break; |
| 787 | case MAX77693_CHARGER_TYPE_APPLE_500MA: |
| 788 | extcon_set_cable_state(info->edev, "Slow-charger", attached); |
| 789 | break; |
| 790 | case MAX77693_CHARGER_TYPE_APPLE_1A_2A: |
| 791 | extcon_set_cable_state(info->edev, "Fast-charger", attached); |
| 792 | break; |
| 793 | case MAX77693_CHARGER_TYPE_DEAD_BATTERY: |
| 794 | break; |
| 795 | default: |
| 796 | dev_err(info->dev, |
| 797 | "failed to detect %s accessory (chg_type:0x%x)\n", |
| 798 | attached ? "attached" : "detached", chg_type); |
| 799 | ret = -EINVAL; |
| 800 | goto out; |
| 801 | } |
| 802 | |
| 803 | out: |
| 804 | return ret; |
| 805 | } |
| 806 | |
| 807 | static void max77693_muic_irq_work(struct work_struct *work) |
| 808 | { |
| 809 | struct max77693_muic_info *info = container_of(work, |
| 810 | struct max77693_muic_info, irq_work); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 811 | int irq_type = -1; |
| 812 | int i, ret = 0; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 813 | |
| 814 | if (!info->edev) |
| 815 | return; |
| 816 | |
| 817 | mutex_lock(&info->mutex); |
| 818 | |
| 819 | for (i = 0 ; i < ARRAY_SIZE(muic_irqs) ; i++) |
| 820 | if (info->irq == muic_irqs[i].virq) |
| 821 | irq_type = muic_irqs[i].irq; |
| 822 | |
| 823 | ret = max77693_bulk_read(info->max77693->regmap_muic, |
| 824 | MAX77693_MUIC_REG_STATUS1, 2, info->status); |
| 825 | if (ret) { |
| 826 | dev_err(info->dev, "failed to read MUIC register\n"); |
| 827 | mutex_unlock(&info->mutex); |
| 828 | return; |
| 829 | } |
| 830 | |
| 831 | switch (irq_type) { |
| 832 | case MAX77693_MUIC_IRQ_INT1_ADC: |
| 833 | case MAX77693_MUIC_IRQ_INT1_ADC_LOW: |
| 834 | case MAX77693_MUIC_IRQ_INT1_ADC_ERR: |
| 835 | case MAX77693_MUIC_IRQ_INT1_ADC1K: |
| 836 | /* Handle all of accessory except for |
| 837 | type of charger accessory */ |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 838 | ret = max77693_muic_adc_handler(info); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 839 | break; |
| 840 | case MAX77693_MUIC_IRQ_INT2_CHGTYP: |
| 841 | case MAX77693_MUIC_IRQ_INT2_CHGDETREUN: |
| 842 | case MAX77693_MUIC_IRQ_INT2_DCDTMR: |
| 843 | case MAX77693_MUIC_IRQ_INT2_DXOVP: |
| 844 | case MAX77693_MUIC_IRQ_INT2_VBVOLT: |
| 845 | case MAX77693_MUIC_IRQ_INT2_VIDRM: |
| 846 | /* Handle charger accessory */ |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 847 | ret = max77693_muic_chg_handler(info); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 848 | break; |
| 849 | case MAX77693_MUIC_IRQ_INT3_EOC: |
| 850 | case MAX77693_MUIC_IRQ_INT3_CGMBC: |
| 851 | case MAX77693_MUIC_IRQ_INT3_OVP: |
| 852 | case MAX77693_MUIC_IRQ_INT3_MBCCHG_ERR: |
| 853 | case MAX77693_MUIC_IRQ_INT3_CHG_ENABLED: |
| 854 | case MAX77693_MUIC_IRQ_INT3_BAT_DET: |
| 855 | break; |
| 856 | default: |
| 857 | dev_err(info->dev, "muic interrupt: irq %d occurred\n", |
| 858 | irq_type); |
| 859 | break; |
| 860 | } |
| 861 | |
| 862 | if (ret < 0) |
| 863 | dev_err(info->dev, "failed to handle MUIC interrupt\n"); |
| 864 | |
| 865 | mutex_unlock(&info->mutex); |
| 866 | |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | static irqreturn_t max77693_muic_irq_handler(int irq, void *data) |
| 871 | { |
| 872 | struct max77693_muic_info *info = data; |
| 873 | |
| 874 | info->irq = irq; |
| 875 | schedule_work(&info->irq_work); |
| 876 | |
| 877 | return IRQ_HANDLED; |
| 878 | } |
| 879 | |
| 880 | static struct regmap_config max77693_muic_regmap_config = { |
| 881 | .reg_bits = 8, |
| 882 | .val_bits = 8, |
| 883 | }; |
| 884 | |
| 885 | static int max77693_muic_detect_accessory(struct max77693_muic_info *info) |
| 886 | { |
| 887 | int ret = 0; |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 888 | int adc; |
| 889 | int chg_type; |
| 890 | bool attached; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 891 | |
| 892 | mutex_lock(&info->mutex); |
| 893 | |
| 894 | /* Read STATUSx register to detect accessory */ |
| 895 | ret = max77693_bulk_read(info->max77693->regmap_muic, |
| 896 | MAX77693_MUIC_REG_STATUS1, 2, info->status); |
| 897 | if (ret) { |
| 898 | dev_err(info->dev, "failed to read MUIC register\n"); |
| 899 | mutex_unlock(&info->mutex); |
| 900 | return -EINVAL; |
| 901 | } |
| 902 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 903 | adc = max77693_muic_get_cable_type(info, MAX77693_CABLE_GROUP_ADC, |
| 904 | &attached); |
| 905 | if (attached && adc != MAX77693_MUIC_ADC_OPEN) { |
| 906 | ret = max77693_muic_adc_handler(info); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 907 | if (ret < 0) |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 908 | dev_err(info->dev, "Cannot detect accessory\n"); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 909 | } |
| 910 | |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 911 | chg_type = max77693_muic_get_cable_type(info, MAX77693_CABLE_GROUP_CHG, |
| 912 | &attached); |
| 913 | if (attached && chg_type != MAX77693_CHARGER_TYPE_NONE) { |
| 914 | ret = max77693_muic_chg_handler(info); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 915 | if (ret < 0) |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 916 | dev_err(info->dev, "Cannot detect charger accessory\n"); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 917 | } |
| 918 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 919 | mutex_unlock(&info->mutex); |
Chanwoo Choi | 154f757f | 2012-11-27 09:40:32 +0900 | [diff] [blame] | 920 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 921 | return ret; |
| 922 | } |
| 923 | |
Chanwoo Choi | 297620f | 2012-12-26 13:10:11 +0900 | [diff] [blame^] | 924 | static void max77693_muic_detect_cable_wq(struct work_struct *work) |
| 925 | { |
| 926 | struct max77693_muic_info *info = container_of(to_delayed_work(work), |
| 927 | struct max77693_muic_info, wq_detcable); |
| 928 | |
| 929 | max77693_muic_detect_accessory(info); |
| 930 | } |
| 931 | |
Bill Pemberton | 44f34fd | 2012-11-19 13:23:21 -0500 | [diff] [blame] | 932 | static int max77693_muic_probe(struct platform_device *pdev) |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 933 | { |
| 934 | struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); |
Chanwoo Choi | f8457d5 | 2012-10-08 14:41:49 +0900 | [diff] [blame] | 935 | struct max77693_platform_data *pdata = dev_get_platdata(max77693->dev); |
| 936 | struct max77693_muic_platform_data *muic_pdata = pdata->muic_data; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 937 | struct max77693_muic_info *info; |
Chanwoo Choi | 297620f | 2012-12-26 13:10:11 +0900 | [diff] [blame^] | 938 | int delay_jiffies; |
| 939 | int ret; |
| 940 | int i; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 941 | u8 id; |
| 942 | |
Sachin Kamat | f4bb5cb | 2012-11-20 15:46:50 +0900 | [diff] [blame] | 943 | info = devm_kzalloc(&pdev->dev, sizeof(struct max77693_muic_info), |
| 944 | GFP_KERNEL); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 945 | if (!info) { |
| 946 | dev_err(&pdev->dev, "failed to allocate memory\n"); |
Sachin Kamat | f4bb5cb | 2012-11-20 15:46:50 +0900 | [diff] [blame] | 947 | return -ENOMEM; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 948 | } |
| 949 | info->dev = &pdev->dev; |
| 950 | info->max77693 = max77693; |
Sachin Kamat | 1967fa0 | 2012-11-21 10:04:58 +0530 | [diff] [blame] | 951 | if (info->max77693->regmap_muic) { |
Chanwoo Choi | b186b12 | 2012-08-21 15:16:23 +0900 | [diff] [blame] | 952 | dev_dbg(&pdev->dev, "allocate register map\n"); |
Sachin Kamat | 1967fa0 | 2012-11-21 10:04:58 +0530 | [diff] [blame] | 953 | } else { |
Chanwoo Choi | b186b12 | 2012-08-21 15:16:23 +0900 | [diff] [blame] | 954 | info->max77693->regmap_muic = devm_regmap_init_i2c( |
| 955 | info->max77693->muic, |
| 956 | &max77693_muic_regmap_config); |
| 957 | if (IS_ERR(info->max77693->regmap_muic)) { |
| 958 | ret = PTR_ERR(info->max77693->regmap_muic); |
| 959 | dev_err(max77693->dev, |
| 960 | "failed to allocate register map: %d\n", ret); |
Sachin Kamat | 3bf742f | 2012-11-21 10:04:57 +0530 | [diff] [blame] | 961 | return ret; |
Chanwoo Choi | b186b12 | 2012-08-21 15:16:23 +0900 | [diff] [blame] | 962 | } |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 963 | } |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 964 | |
| 965 | /* Register input device for button of dock device */ |
| 966 | info->dock = input_allocate_device(); |
| 967 | if (!info->dock) { |
| 968 | dev_err(&pdev->dev, "%s: failed to allocate input\n", __func__); |
| 969 | return -ENOMEM; |
| 970 | } |
| 971 | info->dock->name = "max77693-muic/dock"; |
| 972 | info->dock->phys = "max77693-muic/extcon"; |
| 973 | info->dock->dev.parent = &pdev->dev; |
| 974 | |
| 975 | __set_bit(EV_REP, info->dock->evbit); |
| 976 | |
| 977 | input_set_capability(info->dock, EV_KEY, KEY_VOLUMEUP); |
| 978 | input_set_capability(info->dock, EV_KEY, KEY_VOLUMEDOWN); |
| 979 | input_set_capability(info->dock, EV_KEY, KEY_PLAYPAUSE); |
| 980 | input_set_capability(info->dock, EV_KEY, KEY_PREVIOUSSONG); |
| 981 | input_set_capability(info->dock, EV_KEY, KEY_NEXTSONG); |
| 982 | |
| 983 | ret = input_register_device(info->dock); |
| 984 | if (ret < 0) { |
| 985 | dev_err(&pdev->dev, "Cannot register input device error(%d)\n", |
| 986 | ret); |
| 987 | return ret; |
| 988 | } |
| 989 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 990 | platform_set_drvdata(pdev, info); |
| 991 | mutex_init(&info->mutex); |
| 992 | |
| 993 | INIT_WORK(&info->irq_work, max77693_muic_irq_work); |
| 994 | |
| 995 | /* Support irq domain for MAX77693 MUIC device */ |
| 996 | for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) { |
| 997 | struct max77693_muic_irq *muic_irq = &muic_irqs[i]; |
Sachin Kamat | 00af4b1 | 2012-11-20 15:46:44 +0900 | [diff] [blame] | 998 | unsigned int virq = 0; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 999 | |
| 1000 | virq = irq_create_mapping(max77693->irq_domain, muic_irq->irq); |
Sachin Kamat | 00af4b1 | 2012-11-20 15:46:44 +0900 | [diff] [blame] | 1001 | if (!virq) { |
| 1002 | ret = -EINVAL; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1003 | goto err_irq; |
Sachin Kamat | 00af4b1 | 2012-11-20 15:46:44 +0900 | [diff] [blame] | 1004 | } |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1005 | muic_irq->virq = virq; |
| 1006 | |
| 1007 | ret = request_threaded_irq(virq, NULL, |
| 1008 | max77693_muic_irq_handler, |
Fengguang Wu | aa49312 | 2012-09-06 11:56:35 +0800 | [diff] [blame] | 1009 | IRQF_ONESHOT, muic_irq->name, info); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1010 | if (ret) { |
| 1011 | dev_err(&pdev->dev, |
| 1012 | "failed: irq request (IRQ: %d," |
| 1013 | " error :%d)\n", |
| 1014 | muic_irq->irq, ret); |
| 1015 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1016 | goto err_irq; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | /* Initialize extcon device */ |
Sachin Kamat | f4bb5cb | 2012-11-20 15:46:50 +0900 | [diff] [blame] | 1021 | info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev), |
| 1022 | GFP_KERNEL); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1023 | if (!info->edev) { |
| 1024 | dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); |
| 1025 | ret = -ENOMEM; |
| 1026 | goto err_irq; |
| 1027 | } |
| 1028 | info->edev->name = DEV_NAME; |
| 1029 | info->edev->supported_cable = max77693_extcon_cable; |
| 1030 | ret = extcon_dev_register(info->edev, NULL); |
| 1031 | if (ret) { |
| 1032 | dev_err(&pdev->dev, "failed to register extcon device\n"); |
Sachin Kamat | f4bb5cb | 2012-11-20 15:46:50 +0900 | [diff] [blame] | 1033 | goto err_irq; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1034 | } |
| 1035 | |
Chanwoo Choi | f8457d5 | 2012-10-08 14:41:49 +0900 | [diff] [blame] | 1036 | /* Initialize MUIC register by using platform data */ |
| 1037 | for (i = 0 ; i < muic_pdata->num_init_data ; i++) { |
| 1038 | enum max77693_irq_source irq_src = MAX77693_IRQ_GROUP_NR; |
| 1039 | |
| 1040 | max77693_write_reg(info->max77693->regmap_muic, |
| 1041 | muic_pdata->init_data[i].addr, |
| 1042 | muic_pdata->init_data[i].data); |
| 1043 | |
| 1044 | switch (muic_pdata->init_data[i].addr) { |
| 1045 | case MAX77693_MUIC_REG_INTMASK1: |
| 1046 | irq_src = MUIC_INT1; |
| 1047 | break; |
| 1048 | case MAX77693_MUIC_REG_INTMASK2: |
| 1049 | irq_src = MUIC_INT2; |
| 1050 | break; |
| 1051 | case MAX77693_MUIC_REG_INTMASK3: |
| 1052 | irq_src = MUIC_INT3; |
| 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | if (irq_src < MAX77693_IRQ_GROUP_NR) |
| 1057 | info->max77693->irq_masks_cur[irq_src] |
| 1058 | = muic_pdata->init_data[i].data; |
| 1059 | } |
| 1060 | |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1061 | /* Check revision number of MUIC device*/ |
| 1062 | ret = max77693_read_reg(info->max77693->regmap_muic, |
| 1063 | MAX77693_MUIC_REG_ID, &id); |
| 1064 | if (ret < 0) { |
| 1065 | dev_err(&pdev->dev, "failed to read revision number\n"); |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 1066 | goto err_extcon; |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1067 | } |
| 1068 | dev_info(info->dev, "device ID : 0x%x\n", id); |
| 1069 | |
| 1070 | /* Set ADC debounce time */ |
| 1071 | max77693_muic_set_debounce_time(info, ADC_DEBOUNCE_TIME_25MS); |
| 1072 | |
Chanwoo Choi | 297620f | 2012-12-26 13:10:11 +0900 | [diff] [blame^] | 1073 | /* |
| 1074 | * Detect accessory after completing the initialization of platform |
| 1075 | * |
| 1076 | * - Use delayed workqueue to detect cable state and then |
| 1077 | * notify cable state to notifiee/platform through uevent. |
| 1078 | * After completing the booting of platform, the extcon provider |
| 1079 | * driver should notify cable state to upper layer. |
| 1080 | */ |
| 1081 | INIT_DELAYED_WORK(&info->wq_detcable, max77693_muic_detect_cable_wq); |
| 1082 | if (muic_pdata->detcable_delay_ms) |
| 1083 | delay_jiffies = msecs_to_jiffies(muic_pdata->detcable_delay_ms); |
| 1084 | else |
| 1085 | delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT); |
| 1086 | schedule_delayed_work(&info->wq_detcable, delay_jiffies); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1087 | |
| 1088 | return ret; |
| 1089 | |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 1090 | err_extcon: |
| 1091 | extcon_dev_unregister(info->edev); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1092 | err_irq: |
Sachin Kamat | 00af4b1 | 2012-11-20 15:46:44 +0900 | [diff] [blame] | 1093 | while (--i >= 0) |
| 1094 | free_irq(muic_irqs[i].virq, info); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1095 | return ret; |
| 1096 | } |
| 1097 | |
Bill Pemberton | 93ed032 | 2012-11-19 13:25:49 -0500 | [diff] [blame] | 1098 | static int max77693_muic_remove(struct platform_device *pdev) |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1099 | { |
| 1100 | struct max77693_muic_info *info = platform_get_drvdata(pdev); |
| 1101 | int i; |
| 1102 | |
| 1103 | for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) |
| 1104 | free_irq(muic_irqs[i].virq, info); |
| 1105 | cancel_work_sync(&info->irq_work); |
Chanwoo Choi | 39bf369 | 2012-12-03 13:09:41 +0900 | [diff] [blame] | 1106 | input_unregister_device(info->dock); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1107 | extcon_dev_unregister(info->edev); |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
| 1112 | static struct platform_driver max77693_muic_driver = { |
| 1113 | .driver = { |
| 1114 | .name = DEV_NAME, |
| 1115 | .owner = THIS_MODULE, |
| 1116 | }, |
| 1117 | .probe = max77693_muic_probe, |
Bill Pemberton | 5f7e222 | 2012-11-19 13:20:06 -0500 | [diff] [blame] | 1118 | .remove = max77693_muic_remove, |
Chanwoo Choi | db1b903 | 2012-07-17 13:28:28 +0900 | [diff] [blame] | 1119 | }; |
| 1120 | |
| 1121 | module_platform_driver(max77693_muic_driver); |
| 1122 | |
| 1123 | MODULE_DESCRIPTION("Maxim MAX77693 Extcon driver"); |
| 1124 | MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); |
| 1125 | MODULE_LICENSE("GPL"); |
| 1126 | MODULE_ALIAS("platform:extcon-max77693"); |