Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 2 | /* |
| 3 | * extcon-sm5502.c - Silicon Mitus SM5502 extcon drvier to support USB switches |
| 4 | * |
| 5 | * Copyright (c) 2014 Samsung Electronics Co., Ltd |
| 6 | * Author: Chanwoo Choi <cw00.choi@samsung.com> |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/err.h> |
| 10 | #include <linux/i2c.h> |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/irqdomain.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/regmap.h> |
| 17 | #include <linux/slab.h> |
Chanwoo Choi | 176aa36 | 2017-09-21 12:11:24 +0900 | [diff] [blame] | 18 | #include <linux/extcon-provider.h> |
Chanwoo Choi | ca2a07e | 2014-07-31 16:32:46 +0900 | [diff] [blame] | 19 | |
| 20 | #include "extcon-sm5502.h" |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 21 | |
Chanwoo Choi | e195445 | 2014-05-28 14:21:55 +0900 | [diff] [blame] | 22 | #define DELAY_MS_DEFAULT 17000 /* unit: millisecond */ |
| 23 | |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 24 | struct muic_irq { |
| 25 | unsigned int irq; |
| 26 | const char *name; |
| 27 | unsigned int virq; |
| 28 | }; |
| 29 | |
| 30 | struct reg_data { |
| 31 | u8 reg; |
| 32 | unsigned int val; |
| 33 | bool invert; |
| 34 | }; |
| 35 | |
| 36 | struct sm5502_muic_info { |
| 37 | struct device *dev; |
| 38 | struct extcon_dev *edev; |
| 39 | |
| 40 | struct i2c_client *i2c; |
| 41 | struct regmap *regmap; |
| 42 | |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 43 | const struct sm5502_type *type; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 44 | struct regmap_irq_chip_data *irq_data; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 45 | int irq; |
| 46 | bool irq_attach; |
| 47 | bool irq_detach; |
| 48 | struct work_struct irq_work; |
| 49 | |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 50 | struct mutex mutex; |
Chanwoo Choi | e195445 | 2014-05-28 14:21:55 +0900 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Use delayed workqueue to detect cable state and then |
| 54 | * notify cable state to notifiee/platform through uevent. |
| 55 | * After completing the booting of platform, the extcon provider |
| 56 | * driver should notify cable state to upper layer. |
| 57 | */ |
| 58 | struct delayed_work wq_detcable; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 59 | }; |
| 60 | |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 61 | struct sm5502_type { |
| 62 | struct muic_irq *muic_irqs; |
| 63 | unsigned int num_muic_irqs; |
| 64 | const struct regmap_irq_chip *irq_chip; |
| 65 | |
| 66 | struct reg_data *reg_data; |
| 67 | unsigned int num_reg_data; |
| 68 | |
| 69 | int (*parse_irq)(struct sm5502_muic_info *info, int irq_type); |
| 70 | }; |
| 71 | |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 72 | /* Default value of SM5502 register to bring up MUIC device. */ |
| 73 | static struct reg_data sm5502_reg_data[] = { |
| 74 | { |
Stephan Gerhold | 6942635 | 2019-10-10 17:47:20 +0200 | [diff] [blame] | 75 | .reg = SM5502_REG_RESET, |
| 76 | .val = SM5502_REG_RESET_MASK, |
| 77 | .invert = true, |
| 78 | }, { |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 79 | .reg = SM5502_REG_CONTROL, |
| 80 | .val = SM5502_REG_CONTROL_MASK_INT_MASK, |
| 81 | .invert = false, |
| 82 | }, { |
| 83 | .reg = SM5502_REG_INTMASK1, |
| 84 | .val = SM5502_REG_INTM1_KP_MASK |
| 85 | | SM5502_REG_INTM1_LKP_MASK |
| 86 | | SM5502_REG_INTM1_LKR_MASK, |
| 87 | .invert = true, |
| 88 | }, { |
| 89 | .reg = SM5502_REG_INTMASK2, |
| 90 | .val = SM5502_REG_INTM2_VBUS_DET_MASK |
| 91 | | SM5502_REG_INTM2_REV_ACCE_MASK |
| 92 | | SM5502_REG_INTM2_ADC_CHG_MASK |
| 93 | | SM5502_REG_INTM2_STUCK_KEY_MASK |
| 94 | | SM5502_REG_INTM2_STUCK_KEY_RCV_MASK |
| 95 | | SM5502_REG_INTM2_MHL_MASK, |
| 96 | .invert = true, |
| 97 | }, |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | /* List of detectable cables */ |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 101 | static const unsigned int sm5502_extcon_cable[] = { |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 102 | EXTCON_USB, |
| 103 | EXTCON_USB_HOST, |
Chanwoo Choi | 8b45b6a | 2015-11-09 10:10:15 +0900 | [diff] [blame] | 104 | EXTCON_CHG_USB_SDP, |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 105 | EXTCON_CHG_USB_DCP, |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 106 | EXTCON_NONE, |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | /* Define supported accessory type */ |
| 110 | enum sm5502_muic_acc_type { |
| 111 | SM5502_MUIC_ADC_GROUND = 0x0, |
| 112 | SM5502_MUIC_ADC_SEND_END_BUTTON, |
| 113 | SM5502_MUIC_ADC_REMOTE_S1_BUTTON, |
| 114 | SM5502_MUIC_ADC_REMOTE_S2_BUTTON, |
| 115 | SM5502_MUIC_ADC_REMOTE_S3_BUTTON, |
| 116 | SM5502_MUIC_ADC_REMOTE_S4_BUTTON, |
| 117 | SM5502_MUIC_ADC_REMOTE_S5_BUTTON, |
| 118 | SM5502_MUIC_ADC_REMOTE_S6_BUTTON, |
| 119 | SM5502_MUIC_ADC_REMOTE_S7_BUTTON, |
| 120 | SM5502_MUIC_ADC_REMOTE_S8_BUTTON, |
| 121 | SM5502_MUIC_ADC_REMOTE_S9_BUTTON, |
| 122 | SM5502_MUIC_ADC_REMOTE_S10_BUTTON, |
| 123 | SM5502_MUIC_ADC_REMOTE_S11_BUTTON, |
| 124 | SM5502_MUIC_ADC_REMOTE_S12_BUTTON, |
| 125 | SM5502_MUIC_ADC_RESERVED_ACC_1, |
| 126 | SM5502_MUIC_ADC_RESERVED_ACC_2, |
| 127 | SM5502_MUIC_ADC_RESERVED_ACC_3, |
| 128 | SM5502_MUIC_ADC_RESERVED_ACC_4, |
| 129 | SM5502_MUIC_ADC_RESERVED_ACC_5, |
| 130 | SM5502_MUIC_ADC_AUDIO_TYPE2, |
| 131 | SM5502_MUIC_ADC_PHONE_POWERED_DEV, |
| 132 | SM5502_MUIC_ADC_TTY_CONVERTER, |
| 133 | SM5502_MUIC_ADC_UART_CABLE, |
| 134 | SM5502_MUIC_ADC_TYPE1_CHARGER, |
| 135 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB, |
| 136 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB, |
| 137 | SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE, |
| 138 | SM5502_MUIC_ADC_TYPE2_CHARGER, |
| 139 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART, |
| 140 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART, |
| 141 | SM5502_MUIC_ADC_AUDIO_TYPE1, |
| 142 | SM5502_MUIC_ADC_OPEN = 0x1f, |
| 143 | |
Srikant Ritolia | af57fa4 | 2016-12-07 17:29:39 +0530 | [diff] [blame] | 144 | /* |
| 145 | * The below accessories have same ADC value (0x1f or 0x1e). |
| 146 | * So, Device type1 is used to separate specific accessory. |
| 147 | */ |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 148 | /* |---------|--ADC| */ |
| 149 | /* | [7:5]|[4:0]| */ |
| 150 | SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE = 0x3e, /* | 001|11110| */ |
| 151 | SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END = 0x5e, /* | 010|11110| */ |
| 152 | /* |Dev Type1|--ADC| */ |
Nikita Travkin | e3f6032 | 2021-01-19 18:33:47 +0500 | [diff] [blame] | 153 | SM5502_MUIC_ADC_GROUND_USB_OTG = 0x80, /* | 100|00000| */ |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 154 | SM5502_MUIC_ADC_OPEN_USB = 0x5f, /* | 010|11111| */ |
| 155 | SM5502_MUIC_ADC_OPEN_TA = 0xdf, /* | 110|11111| */ |
| 156 | SM5502_MUIC_ADC_OPEN_USB_OTG = 0xff, /* | 111|11111| */ |
| 157 | }; |
| 158 | |
| 159 | /* List of supported interrupt for SM5502 */ |
| 160 | static struct muic_irq sm5502_muic_irqs[] = { |
| 161 | { SM5502_IRQ_INT1_ATTACH, "muic-attach" }, |
| 162 | { SM5502_IRQ_INT1_DETACH, "muic-detach" }, |
| 163 | { SM5502_IRQ_INT1_KP, "muic-kp" }, |
| 164 | { SM5502_IRQ_INT1_LKP, "muic-lkp" }, |
| 165 | { SM5502_IRQ_INT1_LKR, "muic-lkr" }, |
| 166 | { SM5502_IRQ_INT1_OVP_EVENT, "muic-ovp-event" }, |
| 167 | { SM5502_IRQ_INT1_OCP_EVENT, "muic-ocp-event" }, |
| 168 | { SM5502_IRQ_INT1_OVP_OCP_DIS, "muic-ovp-ocp-dis" }, |
| 169 | { SM5502_IRQ_INT2_VBUS_DET, "muic-vbus-det" }, |
| 170 | { SM5502_IRQ_INT2_REV_ACCE, "muic-rev-acce" }, |
| 171 | { SM5502_IRQ_INT2_ADC_CHG, "muic-adc-chg" }, |
| 172 | { SM5502_IRQ_INT2_STUCK_KEY, "muic-stuck-key" }, |
| 173 | { SM5502_IRQ_INT2_STUCK_KEY_RCV, "muic-stuck-key-rcv" }, |
| 174 | { SM5502_IRQ_INT2_MHL, "muic-mhl" }, |
| 175 | }; |
| 176 | |
| 177 | /* Define interrupt list of SM5502 to register regmap_irq */ |
| 178 | static const struct regmap_irq sm5502_irqs[] = { |
| 179 | /* INT1 interrupts */ |
| 180 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_ATTACH_MASK, }, |
| 181 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_DETACH_MASK, }, |
| 182 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_KP_MASK, }, |
| 183 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKP_MASK, }, |
| 184 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKR_MASK, }, |
| 185 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_EVENT_MASK, }, |
| 186 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OCP_EVENT_MASK, }, |
| 187 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_OCP_DIS_MASK, }, |
| 188 | |
| 189 | /* INT2 interrupts */ |
| 190 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_VBUS_DET_MASK,}, |
| 191 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_REV_ACCE_MASK, }, |
| 192 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_ADC_CHG_MASK, }, |
| 193 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_MASK, }, |
| 194 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_RCV_MASK, }, |
| 195 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_MHL_MASK, }, |
| 196 | }; |
| 197 | |
| 198 | static const struct regmap_irq_chip sm5502_muic_irq_chip = { |
| 199 | .name = "sm5502", |
| 200 | .status_base = SM5502_REG_INT1, |
| 201 | .mask_base = SM5502_REG_INTMASK1, |
| 202 | .mask_invert = false, |
| 203 | .num_regs = 2, |
| 204 | .irqs = sm5502_irqs, |
| 205 | .num_irqs = ARRAY_SIZE(sm5502_irqs), |
| 206 | }; |
| 207 | |
| 208 | /* Define regmap configuration of SM5502 for I2C communication */ |
| 209 | static bool sm5502_muic_volatile_reg(struct device *dev, unsigned int reg) |
| 210 | { |
| 211 | switch (reg) { |
| 212 | case SM5502_REG_INTMASK1: |
| 213 | case SM5502_REG_INTMASK2: |
| 214 | return true; |
| 215 | default: |
| 216 | break; |
| 217 | } |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | static const struct regmap_config sm5502_muic_regmap_config = { |
| 222 | .reg_bits = 8, |
| 223 | .val_bits = 8, |
| 224 | .volatile_reg = sm5502_muic_volatile_reg, |
| 225 | .max_register = SM5502_REG_END, |
| 226 | }; |
| 227 | |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 228 | /* Change DM_CON/DP_CON/VBUSIN switch according to cable type */ |
| 229 | static int sm5502_muic_set_path(struct sm5502_muic_info *info, |
| 230 | unsigned int con_sw, unsigned int vbus_sw, |
| 231 | bool attached) |
| 232 | { |
| 233 | int ret; |
| 234 | |
| 235 | if (!attached) { |
| 236 | con_sw = DM_DP_SWITCH_OPEN; |
| 237 | vbus_sw = VBUSIN_SWITCH_OPEN; |
| 238 | } |
| 239 | |
| 240 | switch (con_sw) { |
| 241 | case DM_DP_SWITCH_OPEN: |
| 242 | case DM_DP_SWITCH_USB: |
| 243 | case DM_DP_SWITCH_AUDIO: |
| 244 | case DM_DP_SWITCH_UART: |
| 245 | ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1, |
| 246 | SM5502_REG_MANUAL_SW1_DP_MASK | |
| 247 | SM5502_REG_MANUAL_SW1_DM_MASK, |
| 248 | con_sw); |
| 249 | if (ret < 0) { |
| 250 | dev_err(info->dev, |
| 251 | "cannot update DM_CON/DP_CON switch\n"); |
| 252 | return ret; |
| 253 | } |
| 254 | break; |
| 255 | default: |
| 256 | dev_err(info->dev, "Unknown DM_CON/DP_CON switch type (%d)\n", |
| 257 | con_sw); |
| 258 | return -EINVAL; |
Xu Wang | 2ddf50a | 2019-12-13 09:48:34 +0000 | [diff] [blame] | 259 | } |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 260 | |
| 261 | switch (vbus_sw) { |
| 262 | case VBUSIN_SWITCH_OPEN: |
| 263 | case VBUSIN_SWITCH_VBUSOUT: |
| 264 | case VBUSIN_SWITCH_MIC: |
| 265 | case VBUSIN_SWITCH_VBUSOUT_WITH_USB: |
| 266 | ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1, |
| 267 | SM5502_REG_MANUAL_SW1_VBUSIN_MASK, |
| 268 | vbus_sw); |
| 269 | if (ret < 0) { |
| 270 | dev_err(info->dev, |
| 271 | "cannot update VBUSIN switch\n"); |
| 272 | return ret; |
| 273 | } |
| 274 | break; |
| 275 | default: |
| 276 | dev_err(info->dev, "Unknown VBUS switch type (%d)\n", vbus_sw); |
| 277 | return -EINVAL; |
Xu Wang | 2ddf50a | 2019-12-13 09:48:34 +0000 | [diff] [blame] | 278 | } |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 283 | /* Return cable type of attached or detached accessories */ |
| 284 | static unsigned int sm5502_muic_get_cable_type(struct sm5502_muic_info *info) |
| 285 | { |
Colin Ian King | ddd1bbb | 2019-10-25 14:12:27 +0100 | [diff] [blame] | 286 | unsigned int cable_type, adc, dev_type1; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 287 | int ret; |
| 288 | |
| 289 | /* Read ADC value according to external cable or button */ |
| 290 | ret = regmap_read(info->regmap, SM5502_REG_ADC, &adc); |
| 291 | if (ret) { |
| 292 | dev_err(info->dev, "failed to read ADC register\n"); |
| 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * If ADC is SM5502_MUIC_ADC_GROUND(0x0), external cable hasn't |
| 298 | * connected with to MUIC device. |
| 299 | */ |
Chanwoo Choi | 0ccc795 | 2014-07-30 15:39:02 +0900 | [diff] [blame] | 300 | cable_type = adc & SM5502_REG_ADC_MASK; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 301 | |
| 302 | switch (cable_type) { |
| 303 | case SM5502_MUIC_ADC_GROUND: |
Nikita Travkin | e3f6032 | 2021-01-19 18:33:47 +0500 | [diff] [blame] | 304 | ret = regmap_read(info->regmap, SM5502_REG_DEV_TYPE1, |
| 305 | &dev_type1); |
| 306 | if (ret) { |
| 307 | dev_err(info->dev, "failed to read DEV_TYPE1 reg\n"); |
| 308 | return ret; |
| 309 | } |
| 310 | |
| 311 | switch (dev_type1) { |
| 312 | case SM5502_REG_DEV_TYPE1_USB_OTG_MASK: |
| 313 | cable_type = SM5502_MUIC_ADC_GROUND_USB_OTG; |
| 314 | break; |
| 315 | default: |
| 316 | dev_dbg(info->dev, |
| 317 | "cannot identify the cable type: adc(0x%x), dev_type1(0x%x)\n", |
| 318 | adc, dev_type1); |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | break; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 322 | case SM5502_MUIC_ADC_SEND_END_BUTTON: |
| 323 | case SM5502_MUIC_ADC_REMOTE_S1_BUTTON: |
| 324 | case SM5502_MUIC_ADC_REMOTE_S2_BUTTON: |
| 325 | case SM5502_MUIC_ADC_REMOTE_S3_BUTTON: |
| 326 | case SM5502_MUIC_ADC_REMOTE_S4_BUTTON: |
| 327 | case SM5502_MUIC_ADC_REMOTE_S5_BUTTON: |
| 328 | case SM5502_MUIC_ADC_REMOTE_S6_BUTTON: |
| 329 | case SM5502_MUIC_ADC_REMOTE_S7_BUTTON: |
| 330 | case SM5502_MUIC_ADC_REMOTE_S8_BUTTON: |
| 331 | case SM5502_MUIC_ADC_REMOTE_S9_BUTTON: |
| 332 | case SM5502_MUIC_ADC_REMOTE_S10_BUTTON: |
| 333 | case SM5502_MUIC_ADC_REMOTE_S11_BUTTON: |
| 334 | case SM5502_MUIC_ADC_REMOTE_S12_BUTTON: |
| 335 | case SM5502_MUIC_ADC_RESERVED_ACC_1: |
| 336 | case SM5502_MUIC_ADC_RESERVED_ACC_2: |
| 337 | case SM5502_MUIC_ADC_RESERVED_ACC_3: |
| 338 | case SM5502_MUIC_ADC_RESERVED_ACC_4: |
| 339 | case SM5502_MUIC_ADC_RESERVED_ACC_5: |
| 340 | case SM5502_MUIC_ADC_AUDIO_TYPE2: |
| 341 | case SM5502_MUIC_ADC_PHONE_POWERED_DEV: |
| 342 | case SM5502_MUIC_ADC_TTY_CONVERTER: |
| 343 | case SM5502_MUIC_ADC_UART_CABLE: |
| 344 | case SM5502_MUIC_ADC_TYPE1_CHARGER: |
| 345 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB: |
| 346 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB: |
| 347 | case SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE: |
| 348 | case SM5502_MUIC_ADC_TYPE2_CHARGER: |
| 349 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART: |
| 350 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART: |
| 351 | break; |
| 352 | case SM5502_MUIC_ADC_AUDIO_TYPE1: |
| 353 | /* |
| 354 | * Check whether cable type is |
| 355 | * SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE |
| 356 | * or SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END |
| 357 | * by using Button event. |
| 358 | */ |
| 359 | break; |
| 360 | case SM5502_MUIC_ADC_OPEN: |
| 361 | ret = regmap_read(info->regmap, SM5502_REG_DEV_TYPE1, |
| 362 | &dev_type1); |
| 363 | if (ret) { |
| 364 | dev_err(info->dev, "failed to read DEV_TYPE1 reg\n"); |
| 365 | return ret; |
| 366 | } |
| 367 | |
| 368 | switch (dev_type1) { |
| 369 | case SM5502_REG_DEV_TYPE1_USB_SDP_MASK: |
| 370 | cable_type = SM5502_MUIC_ADC_OPEN_USB; |
| 371 | break; |
| 372 | case SM5502_REG_DEV_TYPE1_DEDICATED_CHG_MASK: |
| 373 | cable_type = SM5502_MUIC_ADC_OPEN_TA; |
| 374 | break; |
| 375 | case SM5502_REG_DEV_TYPE1_USB_OTG_MASK: |
| 376 | cable_type = SM5502_MUIC_ADC_OPEN_USB_OTG; |
| 377 | break; |
| 378 | default: |
| 379 | dev_dbg(info->dev, |
Chanwoo Choi | 34825e5 | 2015-03-07 01:41:36 +0900 | [diff] [blame] | 380 | "cannot identify the cable type: adc(0x%x)\n", |
| 381 | adc); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 382 | return -EINVAL; |
Xu Wang | 2ddf50a | 2019-12-13 09:48:34 +0000 | [diff] [blame] | 383 | } |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 384 | break; |
| 385 | default: |
| 386 | dev_err(info->dev, |
| 387 | "failed to identify the cable type: adc(0x%x)\n", adc); |
| 388 | return -EINVAL; |
Xu Wang | 2ddf50a | 2019-12-13 09:48:34 +0000 | [diff] [blame] | 389 | } |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 390 | |
| 391 | return cable_type; |
| 392 | } |
| 393 | |
| 394 | static int sm5502_muic_cable_handler(struct sm5502_muic_info *info, |
| 395 | bool attached) |
| 396 | { |
| 397 | static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 398 | unsigned int cable_type = SM5502_MUIC_ADC_GROUND; |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 399 | unsigned int con_sw = DM_DP_SWITCH_OPEN; |
| 400 | unsigned int vbus_sw = VBUSIN_SWITCH_OPEN; |
Chanwoo Choi | 73b6ecd | 2015-06-12 11:10:06 +0900 | [diff] [blame] | 401 | unsigned int id; |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 402 | int ret; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 403 | |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 404 | /* Get the type of attached or detached cable */ |
| 405 | if (attached) |
| 406 | cable_type = sm5502_muic_get_cable_type(info); |
Chanwoo Choi | fbae30d | 2014-08-12 10:15:39 +0900 | [diff] [blame] | 407 | else |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 408 | cable_type = prev_cable_type; |
| 409 | prev_cable_type = cable_type; |
| 410 | |
| 411 | switch (cable_type) { |
| 412 | case SM5502_MUIC_ADC_OPEN_USB: |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 413 | id = EXTCON_USB; |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 414 | con_sw = DM_DP_SWITCH_USB; |
| 415 | vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 416 | break; |
| 417 | case SM5502_MUIC_ADC_OPEN_TA: |
Chanwoo Choi | 11eecf9 | 2015-10-03 14:15:13 +0900 | [diff] [blame] | 418 | id = EXTCON_CHG_USB_DCP; |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 419 | con_sw = DM_DP_SWITCH_OPEN; |
| 420 | vbus_sw = VBUSIN_SWITCH_VBUSOUT; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 421 | break; |
Nikita Travkin | e3f6032 | 2021-01-19 18:33:47 +0500 | [diff] [blame] | 422 | case SM5502_MUIC_ADC_GROUND_USB_OTG: |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 423 | case SM5502_MUIC_ADC_OPEN_USB_OTG: |
Chanwoo Choi | 2a9de9c | 2015-04-24 19:16:05 +0900 | [diff] [blame] | 424 | id = EXTCON_USB_HOST; |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 425 | con_sw = DM_DP_SWITCH_USB; |
| 426 | vbus_sw = VBUSIN_SWITCH_OPEN; |
Chanwoo Choi | e195445 | 2014-05-28 14:21:55 +0900 | [diff] [blame] | 427 | break; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 428 | default: |
| 429 | dev_dbg(info->dev, |
| 430 | "cannot handle this cable_type (0x%x)\n", cable_type); |
| 431 | return 0; |
Xu Wang | 2ddf50a | 2019-12-13 09:48:34 +0000 | [diff] [blame] | 432 | } |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 433 | |
Chanwoo Choi | a75fed2 | 2014-05-28 15:35:29 +0900 | [diff] [blame] | 434 | /* Change internal hardware path(DM_CON/DP_CON, VBUSIN) */ |
| 435 | ret = sm5502_muic_set_path(info, con_sw, vbus_sw, attached); |
| 436 | if (ret < 0) |
| 437 | return ret; |
| 438 | |
| 439 | /* Change the state of external accessory */ |
Chanwoo Choi | 8670b45 | 2016-08-16 15:55:34 +0900 | [diff] [blame] | 440 | extcon_set_state_sync(info->edev, id, attached); |
Chanwoo Choi | 8b45b6a | 2015-11-09 10:10:15 +0900 | [diff] [blame] | 441 | if (id == EXTCON_USB) |
Chanwoo Choi | 8670b45 | 2016-08-16 15:55:34 +0900 | [diff] [blame] | 442 | extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, |
Chanwoo Choi | 8b45b6a | 2015-11-09 10:10:15 +0900 | [diff] [blame] | 443 | attached); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static void sm5502_muic_irq_work(struct work_struct *work) |
| 449 | { |
| 450 | struct sm5502_muic_info *info = container_of(work, |
| 451 | struct sm5502_muic_info, irq_work); |
| 452 | int ret = 0; |
| 453 | |
| 454 | if (!info->edev) |
| 455 | return; |
| 456 | |
| 457 | mutex_lock(&info->mutex); |
| 458 | |
| 459 | /* Detect attached or detached cables */ |
| 460 | if (info->irq_attach) { |
| 461 | ret = sm5502_muic_cable_handler(info, true); |
| 462 | info->irq_attach = false; |
| 463 | } |
| 464 | if (info->irq_detach) { |
| 465 | ret = sm5502_muic_cable_handler(info, false); |
| 466 | info->irq_detach = false; |
| 467 | } |
| 468 | |
| 469 | if (ret < 0) |
| 470 | dev_err(info->dev, "failed to handle MUIC interrupt\n"); |
| 471 | |
| 472 | mutex_unlock(&info->mutex); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /* |
| 476 | * Sets irq_attach or irq_detach in sm5502_muic_info and returns 0. |
| 477 | * Returns -ESRCH if irq_type does not match registered IRQ for this dev type. |
| 478 | */ |
| 479 | static int sm5502_parse_irq(struct sm5502_muic_info *info, int irq_type) |
| 480 | { |
| 481 | switch (irq_type) { |
| 482 | case SM5502_IRQ_INT1_ATTACH: |
| 483 | info->irq_attach = true; |
| 484 | break; |
| 485 | case SM5502_IRQ_INT1_DETACH: |
| 486 | info->irq_detach = true; |
| 487 | break; |
| 488 | case SM5502_IRQ_INT1_KP: |
| 489 | case SM5502_IRQ_INT1_LKP: |
| 490 | case SM5502_IRQ_INT1_LKR: |
| 491 | case SM5502_IRQ_INT1_OVP_EVENT: |
| 492 | case SM5502_IRQ_INT1_OCP_EVENT: |
| 493 | case SM5502_IRQ_INT1_OVP_OCP_DIS: |
| 494 | case SM5502_IRQ_INT2_VBUS_DET: |
| 495 | case SM5502_IRQ_INT2_REV_ACCE: |
| 496 | case SM5502_IRQ_INT2_ADC_CHG: |
| 497 | case SM5502_IRQ_INT2_STUCK_KEY: |
| 498 | case SM5502_IRQ_INT2_STUCK_KEY_RCV: |
| 499 | case SM5502_IRQ_INT2_MHL: |
| 500 | default: |
| 501 | break; |
| 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static irqreturn_t sm5502_muic_irq_handler(int irq, void *data) |
| 508 | { |
| 509 | struct sm5502_muic_info *info = data; |
| 510 | int i, irq_type = -1, ret; |
| 511 | |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 512 | for (i = 0; i < info->type->num_muic_irqs; i++) |
| 513 | if (irq == info->type->muic_irqs[i].virq) |
| 514 | irq_type = info->type->muic_irqs[i].irq; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 515 | |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 516 | ret = info->type->parse_irq(info, irq_type); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 517 | if (ret < 0) { |
| 518 | dev_warn(info->dev, "cannot handle is interrupt:%d\n", |
| 519 | irq_type); |
| 520 | return IRQ_HANDLED; |
| 521 | } |
| 522 | schedule_work(&info->irq_work); |
| 523 | |
| 524 | return IRQ_HANDLED; |
| 525 | } |
| 526 | |
Chanwoo Choi | e195445 | 2014-05-28 14:21:55 +0900 | [diff] [blame] | 527 | static void sm5502_muic_detect_cable_wq(struct work_struct *work) |
| 528 | { |
| 529 | struct sm5502_muic_info *info = container_of(to_delayed_work(work), |
| 530 | struct sm5502_muic_info, wq_detcable); |
| 531 | int ret; |
| 532 | |
| 533 | /* Notify the state of connector cable or not */ |
| 534 | ret = sm5502_muic_cable_handler(info, true); |
| 535 | if (ret < 0) |
| 536 | dev_warn(info->dev, "failed to detect cable state\n"); |
| 537 | } |
| 538 | |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 539 | static void sm5502_init_dev_type(struct sm5502_muic_info *info) |
| 540 | { |
| 541 | unsigned int reg_data, vendor_id, version_id; |
| 542 | int i, ret; |
| 543 | |
| 544 | /* To test I2C, Print version_id and vendor_id of SM5502 */ |
| 545 | ret = regmap_read(info->regmap, SM5502_REG_DEVICE_ID, ®_data); |
| 546 | if (ret) { |
| 547 | dev_err(info->dev, |
| 548 | "failed to read DEVICE_ID register: %d\n", ret); |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | vendor_id = ((reg_data & SM5502_REG_DEVICE_ID_VENDOR_MASK) >> |
| 553 | SM5502_REG_DEVICE_ID_VENDOR_SHIFT); |
| 554 | version_id = ((reg_data & SM5502_REG_DEVICE_ID_VERSION_MASK) >> |
| 555 | SM5502_REG_DEVICE_ID_VERSION_SHIFT); |
| 556 | |
| 557 | dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", |
| 558 | version_id, vendor_id); |
| 559 | |
| 560 | /* Initiazle the register of SM5502 device to bring-up */ |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 561 | for (i = 0; i < info->type->num_reg_data; i++) { |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 562 | unsigned int val = 0; |
| 563 | |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 564 | if (!info->type->reg_data[i].invert) |
| 565 | val |= ~info->type->reg_data[i].val; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 566 | else |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 567 | val = info->type->reg_data[i].val; |
| 568 | regmap_write(info->regmap, info->type->reg_data[i].reg, val); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
Stephan Gerhold | b1b76af | 2021-05-31 15:34:34 +0200 | [diff] [blame] | 572 | static int sm5022_muic_i2c_probe(struct i2c_client *i2c) |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 573 | { |
| 574 | struct device_node *np = i2c->dev.of_node; |
| 575 | struct sm5502_muic_info *info; |
| 576 | int i, ret, irq_flags; |
| 577 | |
| 578 | if (!np) |
| 579 | return -EINVAL; |
| 580 | |
| 581 | info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); |
| 582 | if (!info) |
| 583 | return -ENOMEM; |
| 584 | i2c_set_clientdata(i2c, info); |
| 585 | |
| 586 | info->dev = &i2c->dev; |
| 587 | info->i2c = i2c; |
| 588 | info->irq = i2c->irq; |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 589 | info->type = device_get_match_data(info->dev); |
| 590 | if (!info->type) |
| 591 | return -EINVAL; |
| 592 | if (!info->type->parse_irq) { |
| 593 | dev_err(info->dev, "parse_irq missing in struct sm5502_type\n"); |
| 594 | return -EINVAL; |
| 595 | } |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 596 | |
| 597 | mutex_init(&info->mutex); |
| 598 | |
| 599 | INIT_WORK(&info->irq_work, sm5502_muic_irq_work); |
| 600 | |
| 601 | info->regmap = devm_regmap_init_i2c(i2c, &sm5502_muic_regmap_config); |
| 602 | if (IS_ERR(info->regmap)) { |
| 603 | ret = PTR_ERR(info->regmap); |
| 604 | dev_err(info->dev, "failed to allocate register map: %d\n", |
| 605 | ret); |
| 606 | return ret; |
| 607 | } |
| 608 | |
| 609 | /* Support irq domain for SM5502 MUIC device */ |
| 610 | irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED; |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 611 | ret = devm_regmap_add_irq_chip(info->dev, info->regmap, info->irq, |
| 612 | irq_flags, 0, info->type->irq_chip, |
| 613 | &info->irq_data); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 614 | if (ret != 0) { |
| 615 | dev_err(info->dev, "failed to request IRQ %d: %d\n", |
| 616 | info->irq, ret); |
| 617 | return ret; |
| 618 | } |
| 619 | |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 620 | for (i = 0; i < info->type->num_muic_irqs; i++) { |
| 621 | struct muic_irq *muic_irq = &info->type->muic_irqs[i]; |
Andrzej Hajda | 363b389 | 2015-09-24 16:00:21 +0200 | [diff] [blame] | 622 | int virq = 0; |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 623 | |
| 624 | virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq); |
| 625 | if (virq <= 0) |
| 626 | return -EINVAL; |
| 627 | muic_irq->virq = virq; |
| 628 | |
| 629 | ret = devm_request_threaded_irq(info->dev, virq, NULL, |
| 630 | sm5502_muic_irq_handler, |
Vasyl Gomonovych | 005ad18 | 2019-07-19 18:28:06 +0200 | [diff] [blame] | 631 | IRQF_NO_SUSPEND | IRQF_ONESHOT, |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 632 | muic_irq->name, info); |
| 633 | if (ret) { |
Chanwoo Choi | fbae30d | 2014-08-12 10:15:39 +0900 | [diff] [blame] | 634 | dev_err(info->dev, |
| 635 | "failed: irq request (IRQ: %d, error :%d)\n", |
| 636 | muic_irq->irq, ret); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 637 | return ret; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /* Allocate extcon device */ |
| 642 | info->edev = devm_extcon_dev_allocate(info->dev, sm5502_extcon_cable); |
| 643 | if (IS_ERR(info->edev)) { |
| 644 | dev_err(info->dev, "failed to allocate memory for extcon\n"); |
| 645 | return -ENOMEM; |
| 646 | } |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 647 | |
| 648 | /* Register extcon device */ |
| 649 | ret = devm_extcon_dev_register(info->dev, info->edev); |
| 650 | if (ret) { |
| 651 | dev_err(info->dev, "failed to register extcon device\n"); |
| 652 | return ret; |
| 653 | } |
| 654 | |
Chanwoo Choi | e195445 | 2014-05-28 14:21:55 +0900 | [diff] [blame] | 655 | /* |
| 656 | * Detect accessory after completing the initialization of platform |
| 657 | * |
| 658 | * - Use delayed workqueue to detect cable state and then |
| 659 | * notify cable state to notifiee/platform through uevent. |
| 660 | * After completing the booting of platform, the extcon provider |
| 661 | * driver should notify cable state to upper layer. |
| 662 | */ |
| 663 | INIT_DELAYED_WORK(&info->wq_detcable, sm5502_muic_detect_cable_wq); |
| 664 | queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, |
| 665 | msecs_to_jiffies(DELAY_MS_DEFAULT)); |
| 666 | |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 667 | /* Initialize SM5502 device and print vendor id and version id */ |
| 668 | sm5502_init_dev_type(info); |
| 669 | |
| 670 | return 0; |
| 671 | } |
| 672 | |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 673 | static const struct sm5502_type sm5502_data = { |
| 674 | .muic_irqs = sm5502_muic_irqs, |
| 675 | .num_muic_irqs = ARRAY_SIZE(sm5502_muic_irqs), |
| 676 | .irq_chip = &sm5502_muic_irq_chip, |
| 677 | .reg_data = sm5502_reg_data, |
| 678 | .num_reg_data = ARRAY_SIZE(sm5502_reg_data), |
| 679 | .parse_irq = sm5502_parse_irq, |
| 680 | }; |
| 681 | |
Chanwoo Choi | 34825e5 | 2015-03-07 01:41:36 +0900 | [diff] [blame] | 682 | static const struct of_device_id sm5502_dt_match[] = { |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 683 | { .compatible = "siliconmitus,sm5502-muic", .data = &sm5502_data }, |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 684 | { }, |
| 685 | }; |
Javier Martinez Canillas | ff612f9 | 2015-08-25 08:31:15 +0200 | [diff] [blame] | 686 | MODULE_DEVICE_TABLE(of, sm5502_dt_match); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 687 | |
| 688 | #ifdef CONFIG_PM_SLEEP |
| 689 | static int sm5502_muic_suspend(struct device *dev) |
| 690 | { |
Geliang Tang | d585934 | 2015-12-28 23:00:15 +0800 | [diff] [blame] | 691 | struct i2c_client *i2c = to_i2c_client(dev); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 692 | struct sm5502_muic_info *info = i2c_get_clientdata(i2c); |
| 693 | |
| 694 | enable_irq_wake(info->irq); |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | static int sm5502_muic_resume(struct device *dev) |
| 700 | { |
Geliang Tang | d585934 | 2015-12-28 23:00:15 +0800 | [diff] [blame] | 701 | struct i2c_client *i2c = to_i2c_client(dev); |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 702 | struct sm5502_muic_info *info = i2c_get_clientdata(i2c); |
| 703 | |
| 704 | disable_irq_wake(info->irq); |
| 705 | |
| 706 | return 0; |
| 707 | } |
| 708 | #endif |
| 709 | |
| 710 | static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops, |
| 711 | sm5502_muic_suspend, sm5502_muic_resume); |
| 712 | |
| 713 | static const struct i2c_device_id sm5502_i2c_id[] = { |
Stephan Gerhold | f33c056 | 2021-06-03 10:52:21 +0200 | [diff] [blame^] | 714 | { "sm5502", (kernel_ulong_t)&sm5502_data }, |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 715 | { } |
| 716 | }; |
| 717 | MODULE_DEVICE_TABLE(i2c, sm5502_i2c_id); |
| 718 | |
| 719 | static struct i2c_driver sm5502_muic_i2c_driver = { |
| 720 | .driver = { |
| 721 | .name = "sm5502", |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 722 | .pm = &sm5502_muic_pm_ops, |
| 723 | .of_match_table = sm5502_dt_match, |
| 724 | }, |
Stephan Gerhold | b1b76af | 2021-05-31 15:34:34 +0200 | [diff] [blame] | 725 | .probe_new = sm5022_muic_i2c_probe, |
Chanwoo Choi | 914b881 | 2014-05-22 14:06:33 +0900 | [diff] [blame] | 726 | .id_table = sm5502_i2c_id, |
| 727 | }; |
| 728 | |
| 729 | static int __init sm5502_muic_i2c_init(void) |
| 730 | { |
| 731 | return i2c_add_driver(&sm5502_muic_i2c_driver); |
| 732 | } |
| 733 | subsys_initcall(sm5502_muic_i2c_init); |
| 734 | |
| 735 | MODULE_DESCRIPTION("Silicon Mitus SM5502 Extcon driver"); |
| 736 | MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); |
| 737 | MODULE_LICENSE("GPL"); |