1914b881fSChanwoo Choi /* 2914b881fSChanwoo Choi * extcon-sm5502.c - Silicon Mitus SM5502 extcon drvier to support USB switches 3914b881fSChanwoo Choi * 4914b881fSChanwoo Choi * Copyright (c) 2014 Samsung Electronics Co., Ltd 5914b881fSChanwoo Choi * Author: Chanwoo Choi <cw00.choi@samsung.com> 6914b881fSChanwoo Choi * 7914b881fSChanwoo Choi * This program is free software; you can redistribute it and/or modify it 8914b881fSChanwoo Choi * under the terms of the GNU General Public License as published by the 9914b881fSChanwoo Choi * Free Software Foundation; either version 2 of the License, or (at your 10914b881fSChanwoo Choi * option) any later version. 11914b881fSChanwoo Choi * 12914b881fSChanwoo Choi * This program is distributed in the hope that it will be useful, 13914b881fSChanwoo Choi * but WITHOUT ANY WARRANTY; without even the implied warranty of 14914b881fSChanwoo Choi * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15914b881fSChanwoo Choi * GNU General Public License for more details. 16914b881fSChanwoo Choi */ 17914b881fSChanwoo Choi 18914b881fSChanwoo Choi #include <linux/err.h> 19914b881fSChanwoo Choi #include <linux/i2c.h> 20914b881fSChanwoo Choi #include <linux/input.h> 21914b881fSChanwoo Choi #include <linux/interrupt.h> 22914b881fSChanwoo Choi #include <linux/irqdomain.h> 23914b881fSChanwoo Choi #include <linux/kernel.h> 24914b881fSChanwoo Choi #include <linux/module.h> 25914b881fSChanwoo Choi #include <linux/platform_device.h> 26914b881fSChanwoo Choi #include <linux/regmap.h> 27914b881fSChanwoo Choi #include <linux/slab.h> 28914b881fSChanwoo Choi #include <linux/extcon.h> 29914b881fSChanwoo Choi #include <linux/extcon/sm5502.h> 30914b881fSChanwoo Choi 31e1954452SChanwoo Choi #define DELAY_MS_DEFAULT 17000 /* unit: millisecond */ 32e1954452SChanwoo Choi 33914b881fSChanwoo Choi struct muic_irq { 34914b881fSChanwoo Choi unsigned int irq; 35914b881fSChanwoo Choi const char *name; 36914b881fSChanwoo Choi unsigned int virq; 37914b881fSChanwoo Choi }; 38914b881fSChanwoo Choi 39914b881fSChanwoo Choi struct reg_data { 40914b881fSChanwoo Choi u8 reg; 41914b881fSChanwoo Choi unsigned int val; 42914b881fSChanwoo Choi bool invert; 43914b881fSChanwoo Choi }; 44914b881fSChanwoo Choi 45914b881fSChanwoo Choi struct sm5502_muic_info { 46914b881fSChanwoo Choi struct device *dev; 47914b881fSChanwoo Choi struct extcon_dev *edev; 48914b881fSChanwoo Choi 49914b881fSChanwoo Choi struct i2c_client *i2c; 50914b881fSChanwoo Choi struct regmap *regmap; 51914b881fSChanwoo Choi 52914b881fSChanwoo Choi struct regmap_irq_chip_data *irq_data; 53914b881fSChanwoo Choi struct muic_irq *muic_irqs; 54914b881fSChanwoo Choi unsigned int num_muic_irqs; 55914b881fSChanwoo Choi int irq; 56914b881fSChanwoo Choi bool irq_attach; 57914b881fSChanwoo Choi bool irq_detach; 58914b881fSChanwoo Choi struct work_struct irq_work; 59914b881fSChanwoo Choi 60914b881fSChanwoo Choi struct reg_data *reg_data; 61914b881fSChanwoo Choi unsigned int num_reg_data; 62914b881fSChanwoo Choi 63914b881fSChanwoo Choi struct mutex mutex; 64e1954452SChanwoo Choi 65e1954452SChanwoo Choi /* 66e1954452SChanwoo Choi * Use delayed workqueue to detect cable state and then 67e1954452SChanwoo Choi * notify cable state to notifiee/platform through uevent. 68e1954452SChanwoo Choi * After completing the booting of platform, the extcon provider 69e1954452SChanwoo Choi * driver should notify cable state to upper layer. 70e1954452SChanwoo Choi */ 71e1954452SChanwoo Choi struct delayed_work wq_detcable; 72914b881fSChanwoo Choi }; 73914b881fSChanwoo Choi 74914b881fSChanwoo Choi /* Default value of SM5502 register to bring up MUIC device. */ 75914b881fSChanwoo Choi static struct reg_data sm5502_reg_data[] = { 76914b881fSChanwoo Choi { 77914b881fSChanwoo Choi .reg = SM5502_REG_CONTROL, 78914b881fSChanwoo Choi .val = SM5502_REG_CONTROL_MASK_INT_MASK, 79914b881fSChanwoo Choi .invert = false, 80914b881fSChanwoo Choi }, { 81914b881fSChanwoo Choi .reg = SM5502_REG_INTMASK1, 82914b881fSChanwoo Choi .val = SM5502_REG_INTM1_KP_MASK 83914b881fSChanwoo Choi | SM5502_REG_INTM1_LKP_MASK 84914b881fSChanwoo Choi | SM5502_REG_INTM1_LKR_MASK, 85914b881fSChanwoo Choi .invert = true, 86914b881fSChanwoo Choi }, { 87914b881fSChanwoo Choi .reg = SM5502_REG_INTMASK2, 88914b881fSChanwoo Choi .val = SM5502_REG_INTM2_VBUS_DET_MASK 89914b881fSChanwoo Choi | SM5502_REG_INTM2_REV_ACCE_MASK 90914b881fSChanwoo Choi | SM5502_REG_INTM2_ADC_CHG_MASK 91914b881fSChanwoo Choi | SM5502_REG_INTM2_STUCK_KEY_MASK 92914b881fSChanwoo Choi | SM5502_REG_INTM2_STUCK_KEY_RCV_MASK 93914b881fSChanwoo Choi | SM5502_REG_INTM2_MHL_MASK, 94914b881fSChanwoo Choi .invert = true, 95914b881fSChanwoo Choi }, 96914b881fSChanwoo Choi { } 97914b881fSChanwoo Choi }; 98914b881fSChanwoo Choi 99914b881fSChanwoo Choi /* List of detectable cables */ 100914b881fSChanwoo Choi enum { 101914b881fSChanwoo Choi EXTCON_CABLE_USB = 0, 102914b881fSChanwoo Choi EXTCON_CABLE_USB_HOST, 103914b881fSChanwoo Choi EXTCON_CABLE_TA, 104914b881fSChanwoo Choi 105914b881fSChanwoo Choi EXTCON_CABLE_END, 106914b881fSChanwoo Choi }; 107914b881fSChanwoo Choi 108914b881fSChanwoo Choi static const char *sm5502_extcon_cable[] = { 109914b881fSChanwoo Choi [EXTCON_CABLE_USB] = "USB", 110914b881fSChanwoo Choi [EXTCON_CABLE_USB_HOST] = "USB-Host", 111914b881fSChanwoo Choi [EXTCON_CABLE_TA] = "TA", 112914b881fSChanwoo Choi NULL, 113914b881fSChanwoo Choi }; 114914b881fSChanwoo Choi 115914b881fSChanwoo Choi /* Define supported accessory type */ 116914b881fSChanwoo Choi enum sm5502_muic_acc_type { 117914b881fSChanwoo Choi SM5502_MUIC_ADC_GROUND = 0x0, 118914b881fSChanwoo Choi SM5502_MUIC_ADC_SEND_END_BUTTON, 119914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S1_BUTTON, 120914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S2_BUTTON, 121914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S3_BUTTON, 122914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S4_BUTTON, 123914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S5_BUTTON, 124914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S6_BUTTON, 125914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S7_BUTTON, 126914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S8_BUTTON, 127914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S9_BUTTON, 128914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S10_BUTTON, 129914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S11_BUTTON, 130914b881fSChanwoo Choi SM5502_MUIC_ADC_REMOTE_S12_BUTTON, 131914b881fSChanwoo Choi SM5502_MUIC_ADC_RESERVED_ACC_1, 132914b881fSChanwoo Choi SM5502_MUIC_ADC_RESERVED_ACC_2, 133914b881fSChanwoo Choi SM5502_MUIC_ADC_RESERVED_ACC_3, 134914b881fSChanwoo Choi SM5502_MUIC_ADC_RESERVED_ACC_4, 135914b881fSChanwoo Choi SM5502_MUIC_ADC_RESERVED_ACC_5, 136914b881fSChanwoo Choi SM5502_MUIC_ADC_AUDIO_TYPE2, 137914b881fSChanwoo Choi SM5502_MUIC_ADC_PHONE_POWERED_DEV, 138914b881fSChanwoo Choi SM5502_MUIC_ADC_TTY_CONVERTER, 139914b881fSChanwoo Choi SM5502_MUIC_ADC_UART_CABLE, 140914b881fSChanwoo Choi SM5502_MUIC_ADC_TYPE1_CHARGER, 141914b881fSChanwoo Choi SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB, 142914b881fSChanwoo Choi SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB, 143914b881fSChanwoo Choi SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE, 144914b881fSChanwoo Choi SM5502_MUIC_ADC_TYPE2_CHARGER, 145914b881fSChanwoo Choi SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART, 146914b881fSChanwoo Choi SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART, 147914b881fSChanwoo Choi SM5502_MUIC_ADC_AUDIO_TYPE1, 148914b881fSChanwoo Choi SM5502_MUIC_ADC_OPEN = 0x1f, 149914b881fSChanwoo Choi 150914b881fSChanwoo Choi /* The below accessories have same ADC value (0x1f or 0x1e). 151914b881fSChanwoo Choi So, Device type1 is used to separate specific accessory. */ 152914b881fSChanwoo Choi /* |---------|--ADC| */ 153914b881fSChanwoo Choi /* | [7:5]|[4:0]| */ 154914b881fSChanwoo Choi SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE = 0x3e, /* | 001|11110| */ 155914b881fSChanwoo Choi SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END = 0x5e, /* | 010|11110| */ 156914b881fSChanwoo Choi /* |Dev Type1|--ADC| */ 157914b881fSChanwoo Choi SM5502_MUIC_ADC_OPEN_USB = 0x5f, /* | 010|11111| */ 158914b881fSChanwoo Choi SM5502_MUIC_ADC_OPEN_TA = 0xdf, /* | 110|11111| */ 159914b881fSChanwoo Choi SM5502_MUIC_ADC_OPEN_USB_OTG = 0xff, /* | 111|11111| */ 160914b881fSChanwoo Choi }; 161914b881fSChanwoo Choi 162914b881fSChanwoo Choi /* List of supported interrupt for SM5502 */ 163914b881fSChanwoo Choi static struct muic_irq sm5502_muic_irqs[] = { 164914b881fSChanwoo Choi { SM5502_IRQ_INT1_ATTACH, "muic-attach" }, 165914b881fSChanwoo Choi { SM5502_IRQ_INT1_DETACH, "muic-detach" }, 166914b881fSChanwoo Choi { SM5502_IRQ_INT1_KP, "muic-kp" }, 167914b881fSChanwoo Choi { SM5502_IRQ_INT1_LKP, "muic-lkp" }, 168914b881fSChanwoo Choi { SM5502_IRQ_INT1_LKR, "muic-lkr" }, 169914b881fSChanwoo Choi { SM5502_IRQ_INT1_OVP_EVENT, "muic-ovp-event" }, 170914b881fSChanwoo Choi { SM5502_IRQ_INT1_OCP_EVENT, "muic-ocp-event" }, 171914b881fSChanwoo Choi { SM5502_IRQ_INT1_OVP_OCP_DIS, "muic-ovp-ocp-dis" }, 172914b881fSChanwoo Choi { SM5502_IRQ_INT2_VBUS_DET, "muic-vbus-det" }, 173914b881fSChanwoo Choi { SM5502_IRQ_INT2_REV_ACCE, "muic-rev-acce" }, 174914b881fSChanwoo Choi { SM5502_IRQ_INT2_ADC_CHG, "muic-adc-chg" }, 175914b881fSChanwoo Choi { SM5502_IRQ_INT2_STUCK_KEY, "muic-stuck-key" }, 176914b881fSChanwoo Choi { SM5502_IRQ_INT2_STUCK_KEY_RCV, "muic-stuck-key-rcv" }, 177914b881fSChanwoo Choi { SM5502_IRQ_INT2_MHL, "muic-mhl" }, 178914b881fSChanwoo Choi }; 179914b881fSChanwoo Choi 180914b881fSChanwoo Choi /* Define interrupt list of SM5502 to register regmap_irq */ 181914b881fSChanwoo Choi static const struct regmap_irq sm5502_irqs[] = { 182914b881fSChanwoo Choi /* INT1 interrupts */ 183914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_ATTACH_MASK, }, 184914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_DETACH_MASK, }, 185914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_KP_MASK, }, 186914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKP_MASK, }, 187914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKR_MASK, }, 188914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_EVENT_MASK, }, 189914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OCP_EVENT_MASK, }, 190914b881fSChanwoo Choi { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_OCP_DIS_MASK, }, 191914b881fSChanwoo Choi 192914b881fSChanwoo Choi /* INT2 interrupts */ 193914b881fSChanwoo Choi { .reg_offset = 1, .mask = SM5502_IRQ_INT2_VBUS_DET_MASK,}, 194914b881fSChanwoo Choi { .reg_offset = 1, .mask = SM5502_IRQ_INT2_REV_ACCE_MASK, }, 195914b881fSChanwoo Choi { .reg_offset = 1, .mask = SM5502_IRQ_INT2_ADC_CHG_MASK, }, 196914b881fSChanwoo Choi { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_MASK, }, 197914b881fSChanwoo Choi { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_RCV_MASK, }, 198914b881fSChanwoo Choi { .reg_offset = 1, .mask = SM5502_IRQ_INT2_MHL_MASK, }, 199914b881fSChanwoo Choi }; 200914b881fSChanwoo Choi 201914b881fSChanwoo Choi static const struct regmap_irq_chip sm5502_muic_irq_chip = { 202914b881fSChanwoo Choi .name = "sm5502", 203914b881fSChanwoo Choi .status_base = SM5502_REG_INT1, 204914b881fSChanwoo Choi .mask_base = SM5502_REG_INTMASK1, 205914b881fSChanwoo Choi .mask_invert = false, 206914b881fSChanwoo Choi .num_regs = 2, 207914b881fSChanwoo Choi .irqs = sm5502_irqs, 208914b881fSChanwoo Choi .num_irqs = ARRAY_SIZE(sm5502_irqs), 209914b881fSChanwoo Choi }; 210914b881fSChanwoo Choi 211914b881fSChanwoo Choi /* Define regmap configuration of SM5502 for I2C communication */ 212914b881fSChanwoo Choi static bool sm5502_muic_volatile_reg(struct device *dev, unsigned int reg) 213914b881fSChanwoo Choi { 214914b881fSChanwoo Choi switch (reg) { 215914b881fSChanwoo Choi case SM5502_REG_INTMASK1: 216914b881fSChanwoo Choi case SM5502_REG_INTMASK2: 217914b881fSChanwoo Choi return true; 218914b881fSChanwoo Choi default: 219914b881fSChanwoo Choi break; 220914b881fSChanwoo Choi } 221914b881fSChanwoo Choi return false; 222914b881fSChanwoo Choi } 223914b881fSChanwoo Choi 224914b881fSChanwoo Choi static const struct regmap_config sm5502_muic_regmap_config = { 225914b881fSChanwoo Choi .reg_bits = 8, 226914b881fSChanwoo Choi .val_bits = 8, 227914b881fSChanwoo Choi .volatile_reg = sm5502_muic_volatile_reg, 228914b881fSChanwoo Choi .max_register = SM5502_REG_END, 229914b881fSChanwoo Choi }; 230914b881fSChanwoo Choi 231*a75fed2eSChanwoo Choi /* Change DM_CON/DP_CON/VBUSIN switch according to cable type */ 232*a75fed2eSChanwoo Choi static int sm5502_muic_set_path(struct sm5502_muic_info *info, 233*a75fed2eSChanwoo Choi unsigned int con_sw, unsigned int vbus_sw, 234*a75fed2eSChanwoo Choi bool attached) 235*a75fed2eSChanwoo Choi { 236*a75fed2eSChanwoo Choi int ret; 237*a75fed2eSChanwoo Choi 238*a75fed2eSChanwoo Choi if (!attached) { 239*a75fed2eSChanwoo Choi con_sw = DM_DP_SWITCH_OPEN; 240*a75fed2eSChanwoo Choi vbus_sw = VBUSIN_SWITCH_OPEN; 241*a75fed2eSChanwoo Choi } 242*a75fed2eSChanwoo Choi 243*a75fed2eSChanwoo Choi switch (con_sw) { 244*a75fed2eSChanwoo Choi case DM_DP_SWITCH_OPEN: 245*a75fed2eSChanwoo Choi case DM_DP_SWITCH_USB: 246*a75fed2eSChanwoo Choi case DM_DP_SWITCH_AUDIO: 247*a75fed2eSChanwoo Choi case DM_DP_SWITCH_UART: 248*a75fed2eSChanwoo Choi ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1, 249*a75fed2eSChanwoo Choi SM5502_REG_MANUAL_SW1_DP_MASK | 250*a75fed2eSChanwoo Choi SM5502_REG_MANUAL_SW1_DM_MASK, 251*a75fed2eSChanwoo Choi con_sw); 252*a75fed2eSChanwoo Choi if (ret < 0) { 253*a75fed2eSChanwoo Choi dev_err(info->dev, 254*a75fed2eSChanwoo Choi "cannot update DM_CON/DP_CON switch\n"); 255*a75fed2eSChanwoo Choi return ret; 256*a75fed2eSChanwoo Choi } 257*a75fed2eSChanwoo Choi break; 258*a75fed2eSChanwoo Choi default: 259*a75fed2eSChanwoo Choi dev_err(info->dev, "Unknown DM_CON/DP_CON switch type (%d)\n", 260*a75fed2eSChanwoo Choi con_sw); 261*a75fed2eSChanwoo Choi return -EINVAL; 262*a75fed2eSChanwoo Choi }; 263*a75fed2eSChanwoo Choi 264*a75fed2eSChanwoo Choi switch (vbus_sw) { 265*a75fed2eSChanwoo Choi case VBUSIN_SWITCH_OPEN: 266*a75fed2eSChanwoo Choi case VBUSIN_SWITCH_VBUSOUT: 267*a75fed2eSChanwoo Choi case VBUSIN_SWITCH_MIC: 268*a75fed2eSChanwoo Choi case VBUSIN_SWITCH_VBUSOUT_WITH_USB: 269*a75fed2eSChanwoo Choi ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1, 270*a75fed2eSChanwoo Choi SM5502_REG_MANUAL_SW1_VBUSIN_MASK, 271*a75fed2eSChanwoo Choi vbus_sw); 272*a75fed2eSChanwoo Choi if (ret < 0) { 273*a75fed2eSChanwoo Choi dev_err(info->dev, 274*a75fed2eSChanwoo Choi "cannot update VBUSIN switch\n"); 275*a75fed2eSChanwoo Choi return ret; 276*a75fed2eSChanwoo Choi } 277*a75fed2eSChanwoo Choi break; 278*a75fed2eSChanwoo Choi default: 279*a75fed2eSChanwoo Choi dev_err(info->dev, "Unknown VBUS switch type (%d)\n", vbus_sw); 280*a75fed2eSChanwoo Choi return -EINVAL; 281*a75fed2eSChanwoo Choi }; 282*a75fed2eSChanwoo Choi 283*a75fed2eSChanwoo Choi return 0; 284*a75fed2eSChanwoo Choi } 285*a75fed2eSChanwoo Choi 286914b881fSChanwoo Choi /* Return cable type of attached or detached accessories */ 287914b881fSChanwoo Choi static unsigned int sm5502_muic_get_cable_type(struct sm5502_muic_info *info) 288914b881fSChanwoo Choi { 289914b881fSChanwoo Choi unsigned int cable_type = -1, adc, dev_type1; 290914b881fSChanwoo Choi int ret; 291914b881fSChanwoo Choi 292914b881fSChanwoo Choi /* Read ADC value according to external cable or button */ 293914b881fSChanwoo Choi ret = regmap_read(info->regmap, SM5502_REG_ADC, &adc); 294914b881fSChanwoo Choi if (ret) { 295914b881fSChanwoo Choi dev_err(info->dev, "failed to read ADC register\n"); 296914b881fSChanwoo Choi return ret; 297914b881fSChanwoo Choi } 298914b881fSChanwoo Choi 299914b881fSChanwoo Choi /* 300914b881fSChanwoo Choi * If ADC is SM5502_MUIC_ADC_GROUND(0x0), external cable hasn't 301914b881fSChanwoo Choi * connected with to MUIC device. 302914b881fSChanwoo Choi */ 303914b881fSChanwoo Choi cable_type &= SM5502_REG_ADC_MASK; 304914b881fSChanwoo Choi if (cable_type == SM5502_MUIC_ADC_GROUND) 305914b881fSChanwoo Choi return SM5502_MUIC_ADC_GROUND; 306914b881fSChanwoo Choi 307914b881fSChanwoo Choi switch (cable_type) { 308914b881fSChanwoo Choi case SM5502_MUIC_ADC_GROUND: 309914b881fSChanwoo Choi case SM5502_MUIC_ADC_SEND_END_BUTTON: 310914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S1_BUTTON: 311914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S2_BUTTON: 312914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S3_BUTTON: 313914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S4_BUTTON: 314914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S5_BUTTON: 315914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S6_BUTTON: 316914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S7_BUTTON: 317914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S8_BUTTON: 318914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S9_BUTTON: 319914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S10_BUTTON: 320914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S11_BUTTON: 321914b881fSChanwoo Choi case SM5502_MUIC_ADC_REMOTE_S12_BUTTON: 322914b881fSChanwoo Choi case SM5502_MUIC_ADC_RESERVED_ACC_1: 323914b881fSChanwoo Choi case SM5502_MUIC_ADC_RESERVED_ACC_2: 324914b881fSChanwoo Choi case SM5502_MUIC_ADC_RESERVED_ACC_3: 325914b881fSChanwoo Choi case SM5502_MUIC_ADC_RESERVED_ACC_4: 326914b881fSChanwoo Choi case SM5502_MUIC_ADC_RESERVED_ACC_5: 327914b881fSChanwoo Choi case SM5502_MUIC_ADC_AUDIO_TYPE2: 328914b881fSChanwoo Choi case SM5502_MUIC_ADC_PHONE_POWERED_DEV: 329914b881fSChanwoo Choi case SM5502_MUIC_ADC_TTY_CONVERTER: 330914b881fSChanwoo Choi case SM5502_MUIC_ADC_UART_CABLE: 331914b881fSChanwoo Choi case SM5502_MUIC_ADC_TYPE1_CHARGER: 332914b881fSChanwoo Choi case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB: 333914b881fSChanwoo Choi case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB: 334914b881fSChanwoo Choi case SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE: 335914b881fSChanwoo Choi case SM5502_MUIC_ADC_TYPE2_CHARGER: 336914b881fSChanwoo Choi case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART: 337914b881fSChanwoo Choi case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART: 338914b881fSChanwoo Choi break; 339914b881fSChanwoo Choi case SM5502_MUIC_ADC_AUDIO_TYPE1: 340914b881fSChanwoo Choi /* 341914b881fSChanwoo Choi * Check whether cable type is 342914b881fSChanwoo Choi * SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE 343914b881fSChanwoo Choi * or SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END 344914b881fSChanwoo Choi * by using Button event. 345914b881fSChanwoo Choi */ 346914b881fSChanwoo Choi break; 347914b881fSChanwoo Choi case SM5502_MUIC_ADC_OPEN: 348914b881fSChanwoo Choi ret = regmap_read(info->regmap, SM5502_REG_DEV_TYPE1, 349914b881fSChanwoo Choi &dev_type1); 350914b881fSChanwoo Choi if (ret) { 351914b881fSChanwoo Choi dev_err(info->dev, "failed to read DEV_TYPE1 reg\n"); 352914b881fSChanwoo Choi return ret; 353914b881fSChanwoo Choi } 354914b881fSChanwoo Choi 355914b881fSChanwoo Choi switch (dev_type1) { 356914b881fSChanwoo Choi case SM5502_REG_DEV_TYPE1_USB_SDP_MASK: 357914b881fSChanwoo Choi cable_type = SM5502_MUIC_ADC_OPEN_USB; 358914b881fSChanwoo Choi break; 359914b881fSChanwoo Choi case SM5502_REG_DEV_TYPE1_DEDICATED_CHG_MASK: 360914b881fSChanwoo Choi cable_type = SM5502_MUIC_ADC_OPEN_TA; 361914b881fSChanwoo Choi break; 362914b881fSChanwoo Choi case SM5502_REG_DEV_TYPE1_USB_OTG_MASK: 363914b881fSChanwoo Choi cable_type = SM5502_MUIC_ADC_OPEN_USB_OTG; 364914b881fSChanwoo Choi break; 365914b881fSChanwoo Choi default: 366914b881fSChanwoo Choi dev_dbg(info->dev, 367914b881fSChanwoo Choi "cannot identify the cable type: adc(0x%x) " 368914b881fSChanwoo Choi "dev_type1(0x%x)\n", adc, dev_type1); 369914b881fSChanwoo Choi return -EINVAL; 370914b881fSChanwoo Choi }; 371914b881fSChanwoo Choi break; 372914b881fSChanwoo Choi default: 373914b881fSChanwoo Choi dev_err(info->dev, 374914b881fSChanwoo Choi "failed to identify the cable type: adc(0x%x)\n", adc); 375914b881fSChanwoo Choi return -EINVAL; 376914b881fSChanwoo Choi }; 377914b881fSChanwoo Choi 378914b881fSChanwoo Choi return cable_type; 379914b881fSChanwoo Choi } 380914b881fSChanwoo Choi 381914b881fSChanwoo Choi static int sm5502_muic_cable_handler(struct sm5502_muic_info *info, 382914b881fSChanwoo Choi bool attached) 383914b881fSChanwoo Choi { 384914b881fSChanwoo Choi static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND; 385914b881fSChanwoo Choi const char **cable_names = info->edev->supported_cable; 386914b881fSChanwoo Choi unsigned int cable_type = SM5502_MUIC_ADC_GROUND; 387*a75fed2eSChanwoo Choi unsigned int con_sw = DM_DP_SWITCH_OPEN; 388*a75fed2eSChanwoo Choi unsigned int vbus_sw = VBUSIN_SWITCH_OPEN; 389914b881fSChanwoo Choi unsigned int idx = 0; 390*a75fed2eSChanwoo Choi int ret; 391914b881fSChanwoo Choi 392914b881fSChanwoo Choi if (!cable_names) 393914b881fSChanwoo Choi return 0; 394914b881fSChanwoo Choi 395914b881fSChanwoo Choi /* Get the type of attached or detached cable */ 396914b881fSChanwoo Choi if (attached) 397914b881fSChanwoo Choi cable_type = sm5502_muic_get_cable_type(info); 398914b881fSChanwoo Choi else if (!attached) 399914b881fSChanwoo Choi cable_type = prev_cable_type; 400914b881fSChanwoo Choi prev_cable_type = cable_type; 401914b881fSChanwoo Choi 402914b881fSChanwoo Choi switch (cable_type) { 403914b881fSChanwoo Choi case SM5502_MUIC_ADC_OPEN_USB: 404914b881fSChanwoo Choi idx = EXTCON_CABLE_USB; 405*a75fed2eSChanwoo Choi con_sw = DM_DP_SWITCH_USB; 406*a75fed2eSChanwoo Choi vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB; 407914b881fSChanwoo Choi break; 408914b881fSChanwoo Choi case SM5502_MUIC_ADC_OPEN_TA: 409914b881fSChanwoo Choi idx = EXTCON_CABLE_TA; 410*a75fed2eSChanwoo Choi con_sw = DM_DP_SWITCH_OPEN; 411*a75fed2eSChanwoo Choi vbus_sw = VBUSIN_SWITCH_VBUSOUT; 412914b881fSChanwoo Choi break; 413914b881fSChanwoo Choi case SM5502_MUIC_ADC_OPEN_USB_OTG: 414914b881fSChanwoo Choi idx = EXTCON_CABLE_USB_HOST; 415*a75fed2eSChanwoo Choi con_sw = DM_DP_SWITCH_USB; 416*a75fed2eSChanwoo Choi vbus_sw = VBUSIN_SWITCH_OPEN; 417e1954452SChanwoo Choi break; 418914b881fSChanwoo Choi default: 419914b881fSChanwoo Choi dev_dbg(info->dev, 420914b881fSChanwoo Choi "cannot handle this cable_type (0x%x)\n", cable_type); 421914b881fSChanwoo Choi return 0; 422914b881fSChanwoo Choi }; 423914b881fSChanwoo Choi 424*a75fed2eSChanwoo Choi /* Change internal hardware path(DM_CON/DP_CON, VBUSIN) */ 425*a75fed2eSChanwoo Choi ret = sm5502_muic_set_path(info, con_sw, vbus_sw, attached); 426*a75fed2eSChanwoo Choi if (ret < 0) 427*a75fed2eSChanwoo Choi return ret; 428*a75fed2eSChanwoo Choi 429*a75fed2eSChanwoo Choi /* Change the state of external accessory */ 430914b881fSChanwoo Choi extcon_set_cable_state(info->edev, cable_names[idx], attached); 431914b881fSChanwoo Choi 432914b881fSChanwoo Choi return 0; 433914b881fSChanwoo Choi } 434914b881fSChanwoo Choi 435914b881fSChanwoo Choi static void sm5502_muic_irq_work(struct work_struct *work) 436914b881fSChanwoo Choi { 437914b881fSChanwoo Choi struct sm5502_muic_info *info = container_of(work, 438914b881fSChanwoo Choi struct sm5502_muic_info, irq_work); 439914b881fSChanwoo Choi int ret = 0; 440914b881fSChanwoo Choi 441914b881fSChanwoo Choi if (!info->edev) 442914b881fSChanwoo Choi return; 443914b881fSChanwoo Choi 444914b881fSChanwoo Choi mutex_lock(&info->mutex); 445914b881fSChanwoo Choi 446914b881fSChanwoo Choi /* Detect attached or detached cables */ 447914b881fSChanwoo Choi if (info->irq_attach) { 448914b881fSChanwoo Choi ret = sm5502_muic_cable_handler(info, true); 449914b881fSChanwoo Choi info->irq_attach = false; 450914b881fSChanwoo Choi } 451914b881fSChanwoo Choi if (info->irq_detach) { 452914b881fSChanwoo Choi ret = sm5502_muic_cable_handler(info, false); 453914b881fSChanwoo Choi info->irq_detach = false; 454914b881fSChanwoo Choi } 455914b881fSChanwoo Choi 456914b881fSChanwoo Choi if (ret < 0) 457914b881fSChanwoo Choi dev_err(info->dev, "failed to handle MUIC interrupt\n"); 458914b881fSChanwoo Choi 459914b881fSChanwoo Choi mutex_unlock(&info->mutex); 460914b881fSChanwoo Choi 461914b881fSChanwoo Choi return; 462914b881fSChanwoo Choi } 463914b881fSChanwoo Choi 464914b881fSChanwoo Choi /* 465914b881fSChanwoo Choi * Sets irq_attach or irq_detach in sm5502_muic_info and returns 0. 466914b881fSChanwoo Choi * Returns -ESRCH if irq_type does not match registered IRQ for this dev type. 467914b881fSChanwoo Choi */ 468914b881fSChanwoo Choi static int sm5502_parse_irq(struct sm5502_muic_info *info, int irq_type) 469914b881fSChanwoo Choi { 470914b881fSChanwoo Choi switch (irq_type) { 471914b881fSChanwoo Choi case SM5502_IRQ_INT1_ATTACH: 472914b881fSChanwoo Choi info->irq_attach = true; 473914b881fSChanwoo Choi break; 474914b881fSChanwoo Choi case SM5502_IRQ_INT1_DETACH: 475914b881fSChanwoo Choi info->irq_detach = true; 476914b881fSChanwoo Choi break; 477914b881fSChanwoo Choi case SM5502_IRQ_INT1_KP: 478914b881fSChanwoo Choi case SM5502_IRQ_INT1_LKP: 479914b881fSChanwoo Choi case SM5502_IRQ_INT1_LKR: 480914b881fSChanwoo Choi case SM5502_IRQ_INT1_OVP_EVENT: 481914b881fSChanwoo Choi case SM5502_IRQ_INT1_OCP_EVENT: 482914b881fSChanwoo Choi case SM5502_IRQ_INT1_OVP_OCP_DIS: 483914b881fSChanwoo Choi case SM5502_IRQ_INT2_VBUS_DET: 484914b881fSChanwoo Choi case SM5502_IRQ_INT2_REV_ACCE: 485914b881fSChanwoo Choi case SM5502_IRQ_INT2_ADC_CHG: 486914b881fSChanwoo Choi case SM5502_IRQ_INT2_STUCK_KEY: 487914b881fSChanwoo Choi case SM5502_IRQ_INT2_STUCK_KEY_RCV: 488914b881fSChanwoo Choi case SM5502_IRQ_INT2_MHL: 489914b881fSChanwoo Choi default: 490914b881fSChanwoo Choi break; 491914b881fSChanwoo Choi } 492914b881fSChanwoo Choi 493914b881fSChanwoo Choi return 0; 494914b881fSChanwoo Choi } 495914b881fSChanwoo Choi 496914b881fSChanwoo Choi static irqreturn_t sm5502_muic_irq_handler(int irq, void *data) 497914b881fSChanwoo Choi { 498914b881fSChanwoo Choi struct sm5502_muic_info *info = data; 499914b881fSChanwoo Choi int i, irq_type = -1, ret; 500914b881fSChanwoo Choi 501914b881fSChanwoo Choi for (i = 0; i < info->num_muic_irqs; i++) 502914b881fSChanwoo Choi if (irq == info->muic_irqs[i].virq) 503914b881fSChanwoo Choi irq_type = info->muic_irqs[i].irq; 504914b881fSChanwoo Choi 505914b881fSChanwoo Choi ret = sm5502_parse_irq(info, irq_type); 506914b881fSChanwoo Choi if (ret < 0) { 507914b881fSChanwoo Choi dev_warn(info->dev, "cannot handle is interrupt:%d\n", 508914b881fSChanwoo Choi irq_type); 509914b881fSChanwoo Choi return IRQ_HANDLED; 510914b881fSChanwoo Choi } 511914b881fSChanwoo Choi schedule_work(&info->irq_work); 512914b881fSChanwoo Choi 513914b881fSChanwoo Choi return IRQ_HANDLED; 514914b881fSChanwoo Choi } 515914b881fSChanwoo Choi 516e1954452SChanwoo Choi static void sm5502_muic_detect_cable_wq(struct work_struct *work) 517e1954452SChanwoo Choi { 518e1954452SChanwoo Choi struct sm5502_muic_info *info = container_of(to_delayed_work(work), 519e1954452SChanwoo Choi struct sm5502_muic_info, wq_detcable); 520e1954452SChanwoo Choi int ret; 521e1954452SChanwoo Choi 522e1954452SChanwoo Choi /* Notify the state of connector cable or not */ 523e1954452SChanwoo Choi ret = sm5502_muic_cable_handler(info, true); 524e1954452SChanwoo Choi if (ret < 0) 525e1954452SChanwoo Choi dev_warn(info->dev, "failed to detect cable state\n"); 526e1954452SChanwoo Choi } 527e1954452SChanwoo Choi 528914b881fSChanwoo Choi static void sm5502_init_dev_type(struct sm5502_muic_info *info) 529914b881fSChanwoo Choi { 530914b881fSChanwoo Choi unsigned int reg_data, vendor_id, version_id; 531914b881fSChanwoo Choi int i, ret; 532914b881fSChanwoo Choi 533914b881fSChanwoo Choi /* To test I2C, Print version_id and vendor_id of SM5502 */ 534914b881fSChanwoo Choi ret = regmap_read(info->regmap, SM5502_REG_DEVICE_ID, ®_data); 535914b881fSChanwoo Choi if (ret) { 536914b881fSChanwoo Choi dev_err(info->dev, 537914b881fSChanwoo Choi "failed to read DEVICE_ID register: %d\n", ret); 538914b881fSChanwoo Choi return; 539914b881fSChanwoo Choi } 540914b881fSChanwoo Choi 541914b881fSChanwoo Choi vendor_id = ((reg_data & SM5502_REG_DEVICE_ID_VENDOR_MASK) >> 542914b881fSChanwoo Choi SM5502_REG_DEVICE_ID_VENDOR_SHIFT); 543914b881fSChanwoo Choi version_id = ((reg_data & SM5502_REG_DEVICE_ID_VERSION_MASK) >> 544914b881fSChanwoo Choi SM5502_REG_DEVICE_ID_VERSION_SHIFT); 545914b881fSChanwoo Choi 546914b881fSChanwoo Choi dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", 547914b881fSChanwoo Choi version_id, vendor_id); 548914b881fSChanwoo Choi 549914b881fSChanwoo Choi /* Initiazle the register of SM5502 device to bring-up */ 550914b881fSChanwoo Choi for (i = 0; i < info->num_reg_data; i++) { 551914b881fSChanwoo Choi unsigned int val = 0; 552914b881fSChanwoo Choi 553914b881fSChanwoo Choi if (!info->reg_data[i].invert) 554914b881fSChanwoo Choi val |= ~info->reg_data[i].val; 555914b881fSChanwoo Choi else 556914b881fSChanwoo Choi val = info->reg_data[i].val; 557914b881fSChanwoo Choi regmap_write(info->regmap, info->reg_data[i].reg, val); 558914b881fSChanwoo Choi } 559914b881fSChanwoo Choi } 560914b881fSChanwoo Choi 561914b881fSChanwoo Choi static int sm5022_muic_i2c_probe(struct i2c_client *i2c, 562914b881fSChanwoo Choi const struct i2c_device_id *id) 563914b881fSChanwoo Choi { 564914b881fSChanwoo Choi struct device_node *np = i2c->dev.of_node; 565914b881fSChanwoo Choi struct sm5502_muic_info *info; 566914b881fSChanwoo Choi int i, ret, irq_flags; 567914b881fSChanwoo Choi 568914b881fSChanwoo Choi if (!np) 569914b881fSChanwoo Choi return -EINVAL; 570914b881fSChanwoo Choi 571914b881fSChanwoo Choi info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); 572914b881fSChanwoo Choi if (!info) 573914b881fSChanwoo Choi return -ENOMEM; 574914b881fSChanwoo Choi i2c_set_clientdata(i2c, info); 575914b881fSChanwoo Choi 576914b881fSChanwoo Choi info->dev = &i2c->dev; 577914b881fSChanwoo Choi info->i2c = i2c; 578914b881fSChanwoo Choi info->irq = i2c->irq; 579914b881fSChanwoo Choi info->muic_irqs = sm5502_muic_irqs; 580914b881fSChanwoo Choi info->num_muic_irqs = ARRAY_SIZE(sm5502_muic_irqs); 581914b881fSChanwoo Choi info->reg_data = sm5502_reg_data; 582914b881fSChanwoo Choi info->num_reg_data = ARRAY_SIZE(sm5502_reg_data); 583914b881fSChanwoo Choi 584914b881fSChanwoo Choi mutex_init(&info->mutex); 585914b881fSChanwoo Choi 586914b881fSChanwoo Choi INIT_WORK(&info->irq_work, sm5502_muic_irq_work); 587914b881fSChanwoo Choi 588914b881fSChanwoo Choi info->regmap = devm_regmap_init_i2c(i2c, &sm5502_muic_regmap_config); 589914b881fSChanwoo Choi if (IS_ERR(info->regmap)) { 590914b881fSChanwoo Choi ret = PTR_ERR(info->regmap); 591914b881fSChanwoo Choi dev_err(info->dev, "failed to allocate register map: %d\n", 592914b881fSChanwoo Choi ret); 593914b881fSChanwoo Choi return ret; 594914b881fSChanwoo Choi } 595914b881fSChanwoo Choi 596914b881fSChanwoo Choi /* Support irq domain for SM5502 MUIC device */ 597914b881fSChanwoo Choi irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED; 598914b881fSChanwoo Choi ret = regmap_add_irq_chip(info->regmap, info->irq, irq_flags, 0, 599914b881fSChanwoo Choi &sm5502_muic_irq_chip, &info->irq_data); 600914b881fSChanwoo Choi if (ret != 0) { 601914b881fSChanwoo Choi dev_err(info->dev, "failed to request IRQ %d: %d\n", 602914b881fSChanwoo Choi info->irq, ret); 603914b881fSChanwoo Choi return ret; 604914b881fSChanwoo Choi } 605914b881fSChanwoo Choi 606914b881fSChanwoo Choi for (i = 0; i < info->num_muic_irqs; i++) { 607914b881fSChanwoo Choi struct muic_irq *muic_irq = &info->muic_irqs[i]; 608914b881fSChanwoo Choi unsigned int virq = 0; 609914b881fSChanwoo Choi 610914b881fSChanwoo Choi virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq); 611914b881fSChanwoo Choi if (virq <= 0) 612914b881fSChanwoo Choi return -EINVAL; 613914b881fSChanwoo Choi muic_irq->virq = virq; 614914b881fSChanwoo Choi 615914b881fSChanwoo Choi ret = devm_request_threaded_irq(info->dev, virq, NULL, 616914b881fSChanwoo Choi sm5502_muic_irq_handler, 617914b881fSChanwoo Choi IRQF_NO_SUSPEND, 618914b881fSChanwoo Choi muic_irq->name, info); 619914b881fSChanwoo Choi if (ret) { 620914b881fSChanwoo Choi dev_err(info->dev, "failed: irq request (IRQ: %d," 621914b881fSChanwoo Choi " error :%d)\n", muic_irq->irq, ret); 622914b881fSChanwoo Choi return ret; 623914b881fSChanwoo Choi } 624914b881fSChanwoo Choi } 625914b881fSChanwoo Choi 626914b881fSChanwoo Choi /* Allocate extcon device */ 627914b881fSChanwoo Choi info->edev = devm_extcon_dev_allocate(info->dev, sm5502_extcon_cable); 628914b881fSChanwoo Choi if (IS_ERR(info->edev)) { 629914b881fSChanwoo Choi dev_err(info->dev, "failed to allocate memory for extcon\n"); 630914b881fSChanwoo Choi return -ENOMEM; 631914b881fSChanwoo Choi } 632914b881fSChanwoo Choi info->edev->name = np->name; 633914b881fSChanwoo Choi 634914b881fSChanwoo Choi /* Register extcon device */ 635914b881fSChanwoo Choi ret = devm_extcon_dev_register(info->dev, info->edev); 636914b881fSChanwoo Choi if (ret) { 637914b881fSChanwoo Choi dev_err(info->dev, "failed to register extcon device\n"); 638914b881fSChanwoo Choi return ret; 639914b881fSChanwoo Choi } 640914b881fSChanwoo Choi 641e1954452SChanwoo Choi /* 642e1954452SChanwoo Choi * Detect accessory after completing the initialization of platform 643e1954452SChanwoo Choi * 644e1954452SChanwoo Choi * - Use delayed workqueue to detect cable state and then 645e1954452SChanwoo Choi * notify cable state to notifiee/platform through uevent. 646e1954452SChanwoo Choi * After completing the booting of platform, the extcon provider 647e1954452SChanwoo Choi * driver should notify cable state to upper layer. 648e1954452SChanwoo Choi */ 649e1954452SChanwoo Choi INIT_DELAYED_WORK(&info->wq_detcable, sm5502_muic_detect_cable_wq); 650e1954452SChanwoo Choi queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, 651e1954452SChanwoo Choi msecs_to_jiffies(DELAY_MS_DEFAULT)); 652e1954452SChanwoo Choi 653914b881fSChanwoo Choi /* Initialize SM5502 device and print vendor id and version id */ 654914b881fSChanwoo Choi sm5502_init_dev_type(info); 655914b881fSChanwoo Choi 656914b881fSChanwoo Choi return 0; 657914b881fSChanwoo Choi } 658914b881fSChanwoo Choi 659914b881fSChanwoo Choi static int sm5502_muic_i2c_remove(struct i2c_client *i2c) 660914b881fSChanwoo Choi { 661914b881fSChanwoo Choi struct sm5502_muic_info *info = i2c_get_clientdata(i2c); 662914b881fSChanwoo Choi 663914b881fSChanwoo Choi regmap_del_irq_chip(info->irq, info->irq_data); 664914b881fSChanwoo Choi 665914b881fSChanwoo Choi return 0; 666914b881fSChanwoo Choi } 667914b881fSChanwoo Choi 668914b881fSChanwoo Choi static struct of_device_id sm5502_dt_match[] = { 669914b881fSChanwoo Choi { .compatible = "siliconmitus,sm5502-muic" }, 670914b881fSChanwoo Choi { }, 671914b881fSChanwoo Choi }; 672914b881fSChanwoo Choi 673914b881fSChanwoo Choi #ifdef CONFIG_PM_SLEEP 674914b881fSChanwoo Choi static int sm5502_muic_suspend(struct device *dev) 675914b881fSChanwoo Choi { 676914b881fSChanwoo Choi struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); 677914b881fSChanwoo Choi struct sm5502_muic_info *info = i2c_get_clientdata(i2c); 678914b881fSChanwoo Choi 679914b881fSChanwoo Choi enable_irq_wake(info->irq); 680914b881fSChanwoo Choi 681914b881fSChanwoo Choi return 0; 682914b881fSChanwoo Choi } 683914b881fSChanwoo Choi 684914b881fSChanwoo Choi static int sm5502_muic_resume(struct device *dev) 685914b881fSChanwoo Choi { 686914b881fSChanwoo Choi struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); 687914b881fSChanwoo Choi struct sm5502_muic_info *info = i2c_get_clientdata(i2c); 688914b881fSChanwoo Choi 689914b881fSChanwoo Choi disable_irq_wake(info->irq); 690914b881fSChanwoo Choi 691914b881fSChanwoo Choi return 0; 692914b881fSChanwoo Choi } 693914b881fSChanwoo Choi #endif 694914b881fSChanwoo Choi 695914b881fSChanwoo Choi static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops, 696914b881fSChanwoo Choi sm5502_muic_suspend, sm5502_muic_resume); 697914b881fSChanwoo Choi 698914b881fSChanwoo Choi static const struct i2c_device_id sm5502_i2c_id[] = { 699914b881fSChanwoo Choi { "sm5502", TYPE_SM5502 }, 700914b881fSChanwoo Choi { } 701914b881fSChanwoo Choi }; 702914b881fSChanwoo Choi MODULE_DEVICE_TABLE(i2c, sm5502_i2c_id); 703914b881fSChanwoo Choi 704914b881fSChanwoo Choi static struct i2c_driver sm5502_muic_i2c_driver = { 705914b881fSChanwoo Choi .driver = { 706914b881fSChanwoo Choi .name = "sm5502", 707914b881fSChanwoo Choi .owner = THIS_MODULE, 708914b881fSChanwoo Choi .pm = &sm5502_muic_pm_ops, 709914b881fSChanwoo Choi .of_match_table = sm5502_dt_match, 710914b881fSChanwoo Choi }, 711914b881fSChanwoo Choi .probe = sm5022_muic_i2c_probe, 712914b881fSChanwoo Choi .remove = sm5502_muic_i2c_remove, 713914b881fSChanwoo Choi .id_table = sm5502_i2c_id, 714914b881fSChanwoo Choi }; 715914b881fSChanwoo Choi 716914b881fSChanwoo Choi static int __init sm5502_muic_i2c_init(void) 717914b881fSChanwoo Choi { 718914b881fSChanwoo Choi return i2c_add_driver(&sm5502_muic_i2c_driver); 719914b881fSChanwoo Choi } 720914b881fSChanwoo Choi subsys_initcall(sm5502_muic_i2c_init); 721914b881fSChanwoo Choi 722914b881fSChanwoo Choi MODULE_DESCRIPTION("Silicon Mitus SM5502 Extcon driver"); 723914b881fSChanwoo Choi MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); 724914b881fSChanwoo Choi MODULE_LICENSE("GPL"); 725