summaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-max77693.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/extcon/extcon-max77693.c')
-rw-r--r--drivers/extcon/extcon-max77693.c94
1 files changed, 40 insertions, 54 deletions
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index f4f3b3d53928..35b9e118b2fb 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -24,6 +24,7 @@
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/mfd/max77693.h> 26#include <linux/mfd/max77693.h>
27#include <linux/mfd/max77693-common.h>
27#include <linux/mfd/max77693-private.h> 28#include <linux/mfd/max77693-private.h>
28#include <linux/extcon.h> 29#include <linux/extcon.h>
29#include <linux/regmap.h> 30#include <linux/regmap.h>
@@ -42,7 +43,7 @@ static struct max77693_reg_data default_init_data[] = {
42 { 43 {
43 /* STATUS2 - [3]ChgDetRun */ 44 /* STATUS2 - [3]ChgDetRun */
44 .addr = MAX77693_MUIC_REG_STATUS2, 45 .addr = MAX77693_MUIC_REG_STATUS2,
45 .data = STATUS2_CHGDETRUN_MASK, 46 .data = MAX77693_STATUS2_CHGDETRUN_MASK,
46 }, { 47 }, {
47 /* INTMASK1 - Unmask [3]ADC1KM,[0]ADCM */ 48 /* INTMASK1 - Unmask [3]ADC1KM,[0]ADCM */
48 .addr = MAX77693_MUIC_REG_INTMASK1, 49 .addr = MAX77693_MUIC_REG_INTMASK1,
@@ -235,7 +236,7 @@ static int max77693_muic_set_debounce_time(struct max77693_muic_info *info,
235 */ 236 */
236 ret = regmap_write(info->max77693->regmap_muic, 237 ret = regmap_write(info->max77693->regmap_muic,
237 MAX77693_MUIC_REG_CTRL3, 238 MAX77693_MUIC_REG_CTRL3,
238 time << CONTROL3_ADCDBSET_SHIFT); 239 time << MAX77693_CONTROL3_ADCDBSET_SHIFT);
239 if (ret) { 240 if (ret) {
240 dev_err(info->dev, "failed to set ADC debounce time\n"); 241 dev_err(info->dev, "failed to set ADC debounce time\n");
241 return ret; 242 return ret;
@@ -268,7 +269,7 @@ static int max77693_muic_set_path(struct max77693_muic_info *info,
268 if (attached) 269 if (attached)
269 ctrl1 = val; 270 ctrl1 = val;
270 else 271 else
271 ctrl1 = CONTROL1_SW_OPEN; 272 ctrl1 = MAX77693_CONTROL1_SW_OPEN;
272 273
273 ret = regmap_update_bits(info->max77693->regmap_muic, 274 ret = regmap_update_bits(info->max77693->regmap_muic,
274 MAX77693_MUIC_REG_CTRL1, COMP_SW_MASK, ctrl1); 275 MAX77693_MUIC_REG_CTRL1, COMP_SW_MASK, ctrl1);
@@ -278,13 +279,14 @@ static int max77693_muic_set_path(struct max77693_muic_info *info,
278 } 279 }
279 280
280 if (attached) 281 if (attached)
281 ctrl2 |= CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */ 282 ctrl2 |= MAX77693_CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
282 else 283 else
283 ctrl2 |= CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */ 284 ctrl2 |= MAX77693_CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
284 285
285 ret = regmap_update_bits(info->max77693->regmap_muic, 286 ret = regmap_update_bits(info->max77693->regmap_muic,
286 MAX77693_MUIC_REG_CTRL2, 287 MAX77693_MUIC_REG_CTRL2,
287 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK, ctrl2); 288 MAX77693_CONTROL2_LOWPWR_MASK | MAX77693_CONTROL2_CPEN_MASK,
289 ctrl2);
288 if (ret < 0) { 290 if (ret < 0) {
289 dev_err(info->dev, "failed to update MUIC register\n"); 291 dev_err(info->dev, "failed to update MUIC register\n");
290 return ret; 292 return ret;
@@ -326,8 +328,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info,
326 * Read ADC value to check cable type and decide cable state 328 * Read ADC value to check cable type and decide cable state
327 * according to cable type 329 * according to cable type
328 */ 330 */
329 adc = info->status[0] & STATUS1_ADC_MASK; 331 adc = info->status[0] & MAX77693_STATUS1_ADC_MASK;
330 adc >>= STATUS1_ADC_SHIFT; 332 adc >>= MAX77693_STATUS1_ADC_SHIFT;
331 333
332 /* 334 /*
333 * Check current cable state/cable type and store cable type 335 * Check current cable state/cable type and store cable type
@@ -350,8 +352,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info,
350 * Read ADC value to check cable type and decide cable state 352 * Read ADC value to check cable type and decide cable state
351 * according to cable type 353 * according to cable type
352 */ 354 */
353 adc = info->status[0] & STATUS1_ADC_MASK; 355 adc = info->status[0] & MAX77693_STATUS1_ADC_MASK;
354 adc >>= STATUS1_ADC_SHIFT; 356 adc >>= MAX77693_STATUS1_ADC_SHIFT;
355 357
356 /* 358 /*
357 * Check current cable state/cable type and store cable type 359 * Check current cable state/cable type and store cable type
@@ -366,13 +368,13 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info,
366 } else { 368 } else {
367 *attached = true; 369 *attached = true;
368 370
369 adclow = info->status[0] & STATUS1_ADCLOW_MASK; 371 adclow = info->status[0] & MAX77693_STATUS1_ADCLOW_MASK;
370 adclow >>= STATUS1_ADCLOW_SHIFT; 372 adclow >>= MAX77693_STATUS1_ADCLOW_SHIFT;
371 adc1k = info->status[0] & STATUS1_ADC1K_MASK; 373 adc1k = info->status[0] & MAX77693_STATUS1_ADC1K_MASK;
372 adc1k >>= STATUS1_ADC1K_SHIFT; 374 adc1k >>= MAX77693_STATUS1_ADC1K_SHIFT;
373 375
374 vbvolt = info->status[1] & STATUS2_VBVOLT_MASK; 376 vbvolt = info->status[1] & MAX77693_STATUS2_VBVOLT_MASK;
375 vbvolt >>= STATUS2_VBVOLT_SHIFT; 377 vbvolt >>= MAX77693_STATUS2_VBVOLT_SHIFT;
376 378
377 /** 379 /**
378 * [0x1|VBVolt|ADCLow|ADC1K] 380 * [0x1|VBVolt|ADCLow|ADC1K]
@@ -397,8 +399,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info,
397 * Read charger type to check cable type and decide cable state 399 * Read charger type to check cable type and decide cable state
398 * according to type of charger cable. 400 * according to type of charger cable.
399 */ 401 */
400 chg_type = info->status[1] & STATUS2_CHGTYP_MASK; 402 chg_type = info->status[1] & MAX77693_STATUS2_CHGTYP_MASK;
401 chg_type >>= STATUS2_CHGTYP_SHIFT; 403 chg_type >>= MAX77693_STATUS2_CHGTYP_SHIFT;
402 404
403 if (chg_type == MAX77693_CHARGER_TYPE_NONE) { 405 if (chg_type == MAX77693_CHARGER_TYPE_NONE) {
404 *attached = false; 406 *attached = false;
@@ -422,10 +424,10 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info,
422 * Read ADC value to check cable type and decide cable state 424 * Read ADC value to check cable type and decide cable state
423 * according to cable type 425 * according to cable type
424 */ 426 */
425 adc = info->status[0] & STATUS1_ADC_MASK; 427 adc = info->status[0] & MAX77693_STATUS1_ADC_MASK;
426 adc >>= STATUS1_ADC_SHIFT; 428 adc >>= MAX77693_STATUS1_ADC_SHIFT;
427 chg_type = info->status[1] & STATUS2_CHGTYP_MASK; 429 chg_type = info->status[1] & MAX77693_STATUS2_CHGTYP_MASK;
428 chg_type >>= STATUS2_CHGTYP_SHIFT; 430 chg_type >>= MAX77693_STATUS2_CHGTYP_SHIFT;
429 431
430 if (adc == MAX77693_MUIC_ADC_OPEN 432 if (adc == MAX77693_MUIC_ADC_OPEN
431 && chg_type == MAX77693_CHARGER_TYPE_NONE) 433 && chg_type == MAX77693_CHARGER_TYPE_NONE)
@@ -437,8 +439,8 @@ static int max77693_muic_get_cable_type(struct max77693_muic_info *info,
437 * Read vbvolt field, if vbvolt is 1, 439 * Read vbvolt field, if vbvolt is 1,
438 * this cable is used for charging. 440 * this cable is used for charging.
439 */ 441 */
440 vbvolt = info->status[1] & STATUS2_VBVOLT_MASK; 442 vbvolt = info->status[1] & MAX77693_STATUS2_VBVOLT_MASK;
441 vbvolt >>= STATUS2_VBVOLT_SHIFT; 443 vbvolt >>= MAX77693_STATUS2_VBVOLT_SHIFT;
442 444
443 cable_type = vbvolt; 445 cable_type = vbvolt;
444 break; 446 break;
@@ -520,7 +522,8 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
520 } 522 }
521 523
522 /* Dock-Car/Desk/Audio, PATH:AUDIO */ 524 /* Dock-Car/Desk/Audio, PATH:AUDIO */
523 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); 525 ret = max77693_muic_set_path(info, MAX77693_CONTROL1_SW_AUDIO,
526 attached);
524 if (ret < 0) 527 if (ret < 0)
525 return ret; 528 return ret;
526 extcon_set_cable_state_(info->edev, dock_id, attached); 529 extcon_set_cable_state_(info->edev, dock_id, attached);
@@ -585,14 +588,16 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info)
585 case MAX77693_MUIC_GND_USB_HOST: 588 case MAX77693_MUIC_GND_USB_HOST:
586 case MAX77693_MUIC_GND_USB_HOST_VB: 589 case MAX77693_MUIC_GND_USB_HOST_VB:
587 /* USB_HOST, PATH: AP_USB */ 590 /* USB_HOST, PATH: AP_USB */
588 ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached); 591 ret = max77693_muic_set_path(info, MAX77693_CONTROL1_SW_USB,
592 attached);
589 if (ret < 0) 593 if (ret < 0)
590 return ret; 594 return ret;
591 extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); 595 extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
592 break; 596 break;
593 case MAX77693_MUIC_GND_AV_CABLE_LOAD: 597 case MAX77693_MUIC_GND_AV_CABLE_LOAD:
594 /* Audio Video Cable with load, PATH:AUDIO */ 598 /* Audio Video Cable with load, PATH:AUDIO */
595 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); 599 ret = max77693_muic_set_path(info, MAX77693_CONTROL1_SW_AUDIO,
600 attached);
596 if (ret < 0) 601 if (ret < 0)
597 return ret; 602 return ret;
598 extcon_set_cable_state_(info->edev, EXTCON_USB, attached); 603 extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
@@ -615,7 +620,7 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info,
615 int cable_type, bool attached) 620 int cable_type, bool attached)
616{ 621{
617 int ret = 0; 622 int ret = 0;
618 u8 path = CONTROL1_SW_OPEN; 623 u8 path = MAX77693_CONTROL1_SW_OPEN;
619 624
620 dev_info(info->dev, 625 dev_info(info->dev,
621 "external connector is %s (adc:0x%02x)\n", 626 "external connector is %s (adc:0x%02x)\n",
@@ -625,12 +630,12 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info,
625 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */ 630 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */
626 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */ 631 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */
627 /* PATH:AP_USB */ 632 /* PATH:AP_USB */
628 path = CONTROL1_SW_USB; 633 path = MAX77693_CONTROL1_SW_USB;
629 break; 634 break;
630 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */ 635 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */
631 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* ADC_JIG_UART_ON */ 636 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* ADC_JIG_UART_ON */
632 /* PATH:AP_UART */ 637 /* PATH:AP_UART */
633 path = CONTROL1_SW_UART; 638 path = MAX77693_CONTROL1_SW_UART;
634 break; 639 break;
635 default: 640 default:
636 dev_err(info->dev, "failed to detect %s jig cable\n", 641 dev_err(info->dev, "failed to detect %s jig cable\n",
@@ -1077,7 +1082,7 @@ static int max77693_muic_probe(struct platform_device *pdev)
1077 dev_dbg(&pdev->dev, "allocate register map\n"); 1082 dev_dbg(&pdev->dev, "allocate register map\n");
1078 } else { 1083 } else {
1079 info->max77693->regmap_muic = devm_regmap_init_i2c( 1084 info->max77693->regmap_muic = devm_regmap_init_i2c(
1080 info->max77693->muic, 1085 info->max77693->i2c_muic,
1081 &max77693_muic_regmap_config); 1086 &max77693_muic_regmap_config);
1082 if (IS_ERR(info->max77693->regmap_muic)) { 1087 if (IS_ERR(info->max77693->regmap_muic)) {
1083 ret = PTR_ERR(info->max77693->regmap_muic); 1088 ret = PTR_ERR(info->max77693->regmap_muic);
@@ -1164,28 +1169,9 @@ static int max77693_muic_probe(struct platform_device *pdev)
1164 } 1169 }
1165 1170
1166 for (i = 0; i < num_init_data; i++) { 1171 for (i = 0; i < num_init_data; i++) {
1167 enum max77693_irq_source irq_src
1168 = MAX77693_IRQ_GROUP_NR;
1169
1170 regmap_write(info->max77693->regmap_muic, 1172 regmap_write(info->max77693->regmap_muic,
1171 init_data[i].addr, 1173 init_data[i].addr,
1172 init_data[i].data); 1174 init_data[i].data);
1173
1174 switch (init_data[i].addr) {
1175 case MAX77693_MUIC_REG_INTMASK1:
1176 irq_src = MUIC_INT1;
1177 break;
1178 case MAX77693_MUIC_REG_INTMASK2:
1179 irq_src = MUIC_INT2;
1180 break;
1181 case MAX77693_MUIC_REG_INTMASK3:
1182 irq_src = MUIC_INT3;
1183 break;
1184 }
1185
1186 if (irq_src < MAX77693_IRQ_GROUP_NR)
1187 info->max77693->irq_masks_cur[irq_src]
1188 = init_data[i].data;
1189 } 1175 }
1190 1176
1191 if (pdata && pdata->muic_data) { 1177 if (pdata && pdata->muic_data) {
@@ -1199,12 +1185,12 @@ static int max77693_muic_probe(struct platform_device *pdev)
1199 if (muic_pdata->path_uart) 1185 if (muic_pdata->path_uart)
1200 info->path_uart = muic_pdata->path_uart; 1186 info->path_uart = muic_pdata->path_uart;
1201 else 1187 else
1202 info->path_uart = CONTROL1_SW_UART; 1188 info->path_uart = MAX77693_CONTROL1_SW_UART;
1203 1189
1204 if (muic_pdata->path_usb) 1190 if (muic_pdata->path_usb)
1205 info->path_usb = muic_pdata->path_usb; 1191 info->path_usb = muic_pdata->path_usb;
1206 else 1192 else
1207 info->path_usb = CONTROL1_SW_USB; 1193 info->path_usb = MAX77693_CONTROL1_SW_USB;
1208 1194
1209 /* 1195 /*
1210 * Default delay time for detecting cable state 1196 * Default delay time for detecting cable state
@@ -1216,8 +1202,8 @@ static int max77693_muic_probe(struct platform_device *pdev)
1216 else 1202 else
1217 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT); 1203 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
1218 } else { 1204 } else {
1219 info->path_usb = CONTROL1_SW_USB; 1205 info->path_usb = MAX77693_CONTROL1_SW_USB;
1220 info->path_uart = CONTROL1_SW_UART; 1206 info->path_uart = MAX77693_CONTROL1_SW_UART;
1221 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT); 1207 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
1222 } 1208 }
1223 1209