summaryrefslogtreecommitdiffstats
path: root/drivers/extcon/extcon-max77843.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/extcon/extcon-max77843.c')
-rw-r--r--drivers/extcon/extcon-max77843.c66
1 files changed, 41 insertions, 25 deletions
diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c
index cc5e7bca38c8..fdd928542c19 100644
--- a/drivers/extcon/extcon-max77843.c
+++ b/drivers/extcon/extcon-max77843.c
@@ -15,6 +15,7 @@
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/mfd/max77693-common.h>
18#include <linux/mfd/max77843-private.h> 19#include <linux/mfd/max77843-private.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
@@ -32,7 +33,7 @@ enum max77843_muic_status {
32 33
33struct max77843_muic_info { 34struct max77843_muic_info {
34 struct device *dev; 35 struct device *dev;
35 struct max77843 *max77843; 36 struct max77693_dev *max77843;
36 struct extcon_dev *edev; 37 struct extcon_dev *edev;
37 38
38 struct mutex mutex; 39 struct mutex mutex;
@@ -198,18 +199,18 @@ static const struct regmap_irq_chip max77843_muic_irq_chip = {
198static int max77843_muic_set_path(struct max77843_muic_info *info, 199static int max77843_muic_set_path(struct max77843_muic_info *info,
199 u8 val, bool attached) 200 u8 val, bool attached)
200{ 201{
201 struct max77843 *max77843 = info->max77843; 202 struct max77693_dev *max77843 = info->max77843;
202 int ret = 0; 203 int ret = 0;
203 unsigned int ctrl1, ctrl2; 204 unsigned int ctrl1, ctrl2;
204 205
205 if (attached) 206 if (attached)
206 ctrl1 = val; 207 ctrl1 = val;
207 else 208 else
208 ctrl1 = CONTROL1_SW_OPEN; 209 ctrl1 = MAX77843_MUIC_CONTROL1_SW_OPEN;
209 210
210 ret = regmap_update_bits(max77843->regmap_muic, 211 ret = regmap_update_bits(max77843->regmap_muic,
211 MAX77843_MUIC_REG_CONTROL1, 212 MAX77843_MUIC_REG_CONTROL1,
212 CONTROL1_COM_SW, ctrl1); 213 MAX77843_MUIC_CONTROL1_COM_SW, ctrl1);
213 if (ret < 0) { 214 if (ret < 0) {
214 dev_err(info->dev, "Cannot switch MUIC port\n"); 215 dev_err(info->dev, "Cannot switch MUIC port\n");
215 return ret; 216 return ret;
@@ -243,7 +244,7 @@ static int max77843_muic_get_cable_type(struct max77843_muic_info *info,
243 244
244 adc = info->status[MAX77843_MUIC_STATUS1] & 245 adc = info->status[MAX77843_MUIC_STATUS1] &
245 MAX77843_MUIC_STATUS1_ADC_MASK; 246 MAX77843_MUIC_STATUS1_ADC_MASK;
246 adc >>= STATUS1_ADC_SHIFT; 247 adc >>= MAX77843_MUIC_STATUS1_ADC_SHIFT;
247 248
248 switch (group) { 249 switch (group) {
249 case MAX77843_CABLE_GROUP_ADC: 250 case MAX77843_CABLE_GROUP_ADC:
@@ -309,7 +310,7 @@ static int max77843_muic_get_cable_type(struct max77843_muic_info *info,
309 /* Get VBVolt register bit */ 310 /* Get VBVolt register bit */
310 gnd_type |= (info->status[MAX77843_MUIC_STATUS2] & 311 gnd_type |= (info->status[MAX77843_MUIC_STATUS2] &
311 MAX77843_MUIC_STATUS2_VBVOLT_MASK); 312 MAX77843_MUIC_STATUS2_VBVOLT_MASK);
312 gnd_type >>= STATUS2_VBVOLT_SHIFT; 313 gnd_type >>= MAX77843_MUIC_STATUS2_VBVOLT_SHIFT;
313 314
314 /* Offset of GND cable */ 315 /* Offset of GND cable */
315 gnd_type |= MAX77843_MUIC_GND_USB_HOST; 316 gnd_type |= MAX77843_MUIC_GND_USB_HOST;
@@ -338,7 +339,9 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
338 switch (gnd_cable_type) { 339 switch (gnd_cable_type) {
339 case MAX77843_MUIC_GND_USB_HOST: 340 case MAX77843_MUIC_GND_USB_HOST:
340 case MAX77843_MUIC_GND_USB_HOST_VB: 341 case MAX77843_MUIC_GND_USB_HOST_VB:
341 ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); 342 ret = max77843_muic_set_path(info,
343 MAX77843_MUIC_CONTROL1_SW_USB,
344 attached);
342 if (ret < 0) 345 if (ret < 0)
343 return ret; 346 return ret;
344 347
@@ -346,7 +349,9 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
346 break; 349 break;
347 case MAX77843_MUIC_GND_MHL_VB: 350 case MAX77843_MUIC_GND_MHL_VB:
348 case MAX77843_MUIC_GND_MHL: 351 case MAX77843_MUIC_GND_MHL:
349 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 352 ret = max77843_muic_set_path(info,
353 MAX77843_MUIC_CONTROL1_SW_OPEN,
354 attached);
350 if (ret < 0) 355 if (ret < 0)
351 return ret; 356 return ret;
352 357
@@ -365,7 +370,7 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info,
365 int cable_type, bool attached) 370 int cable_type, bool attached)
366{ 371{
367 int ret; 372 int ret;
368 u8 path = CONTROL1_SW_OPEN; 373 u8 path = MAX77843_MUIC_CONTROL1_SW_OPEN;
369 374
370 dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", 375 dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n",
371 attached ? "attached" : "detached", cable_type); 376 attached ? "attached" : "detached", cable_type);
@@ -373,10 +378,10 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info,
373 switch (cable_type) { 378 switch (cable_type) {
374 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: 379 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF:
375 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: 380 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON:
376 path = CONTROL1_SW_USB; 381 path = MAX77843_MUIC_CONTROL1_SW_USB;
377 break; 382 break;
378 case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: 383 case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF:
379 path = CONTROL1_SW_UART; 384 path = MAX77843_MUIC_CONTROL1_SW_UART;
380 break; 385 break;
381 default: 386 default:
382 return -EINVAL; 387 return -EINVAL;
@@ -474,14 +479,18 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
474 479
475 switch (chg_type) { 480 switch (chg_type) {
476 case MAX77843_MUIC_CHG_USB: 481 case MAX77843_MUIC_CHG_USB:
477 ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); 482 ret = max77843_muic_set_path(info,
483 MAX77843_MUIC_CONTROL1_SW_USB,
484 attached);
478 if (ret < 0) 485 if (ret < 0)
479 return ret; 486 return ret;
480 487
481 extcon_set_cable_state_(info->edev, EXTCON_USB, attached); 488 extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
482 break; 489 break;
483 case MAX77843_MUIC_CHG_DOWNSTREAM: 490 case MAX77843_MUIC_CHG_DOWNSTREAM:
484 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 491 ret = max77843_muic_set_path(info,
492 MAX77843_MUIC_CONTROL1_SW_OPEN,
493 attached);
485 if (ret < 0) 494 if (ret < 0)
486 return ret; 495 return ret;
487 496
@@ -489,14 +498,18 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
489 attached); 498 attached);
490 break; 499 break;
491 case MAX77843_MUIC_CHG_DEDICATED: 500 case MAX77843_MUIC_CHG_DEDICATED:
492 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 501 ret = max77843_muic_set_path(info,
502 MAX77843_MUIC_CONTROL1_SW_OPEN,
503 attached);
493 if (ret < 0) 504 if (ret < 0)
494 return ret; 505 return ret;
495 506
496 extcon_set_cable_state_(info->edev, EXTCON_TA, attached); 507 extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
497 break; 508 break;
498 case MAX77843_MUIC_CHG_SPECIAL_500MA: 509 case MAX77843_MUIC_CHG_SPECIAL_500MA:
499 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 510 ret = max77843_muic_set_path(info,
511 MAX77843_MUIC_CONTROL1_SW_OPEN,
512 attached);
500 if (ret < 0) 513 if (ret < 0)
501 return ret; 514 return ret;
502 515
@@ -504,7 +517,9 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
504 attached); 517 attached);
505 break; 518 break;
506 case MAX77843_MUIC_CHG_SPECIAL_1A: 519 case MAX77843_MUIC_CHG_SPECIAL_1A:
507 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 520 ret = max77843_muic_set_path(info,
521 MAX77843_MUIC_CONTROL1_SW_OPEN,
522 attached);
508 if (ret < 0) 523 if (ret < 0)
509 return ret; 524 return ret;
510 525
@@ -528,7 +543,8 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
528 "failed to detect %s accessory (chg_type:0x%x)\n", 543 "failed to detect %s accessory (chg_type:0x%x)\n",
529 attached ? "attached" : "detached", chg_type); 544 attached ? "attached" : "detached", chg_type);
530 545
531 max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 546 max77843_muic_set_path(info, MAX77843_MUIC_CONTROL1_SW_OPEN,
547 attached);
532 return -EINVAL; 548 return -EINVAL;
533 } 549 }
534 550
@@ -539,7 +555,7 @@ static void max77843_muic_irq_work(struct work_struct *work)
539{ 555{
540 struct max77843_muic_info *info = container_of(work, 556 struct max77843_muic_info *info = container_of(work,
541 struct max77843_muic_info, irq_work); 557 struct max77843_muic_info, irq_work);
542 struct max77843 *max77843 = info->max77843; 558 struct max77693_dev *max77843 = info->max77843;
543 int ret = 0; 559 int ret = 0;
544 560
545 mutex_lock(&info->mutex); 561 mutex_lock(&info->mutex);
@@ -615,7 +631,7 @@ static void max77843_muic_detect_cable_wq(struct work_struct *work)
615{ 631{
616 struct max77843_muic_info *info = container_of(to_delayed_work(work), 632 struct max77843_muic_info *info = container_of(to_delayed_work(work),
617 struct max77843_muic_info, wq_detcable); 633 struct max77843_muic_info, wq_detcable);
618 struct max77843 *max77843 = info->max77843; 634 struct max77693_dev *max77843 = info->max77843;
619 int chg_type, adc, ret; 635 int chg_type, adc, ret;
620 bool attached; 636 bool attached;
621 637
@@ -656,7 +672,7 @@ err_cable_wq:
656static int max77843_muic_set_debounce_time(struct max77843_muic_info *info, 672static int max77843_muic_set_debounce_time(struct max77843_muic_info *info,
657 enum max77843_muic_adc_debounce_time time) 673 enum max77843_muic_adc_debounce_time time)
658{ 674{
659 struct max77843 *max77843 = info->max77843; 675 struct max77693_dev *max77843 = info->max77843;
660 int ret; 676 int ret;
661 677
662 switch (time) { 678 switch (time) {
@@ -667,7 +683,7 @@ static int max77843_muic_set_debounce_time(struct max77843_muic_info *info,
667 ret = regmap_update_bits(max77843->regmap_muic, 683 ret = regmap_update_bits(max77843->regmap_muic,
668 MAX77843_MUIC_REG_CONTROL4, 684 MAX77843_MUIC_REG_CONTROL4,
669 MAX77843_MUIC_CONTROL4_ADCDBSET_MASK, 685 MAX77843_MUIC_CONTROL4_ADCDBSET_MASK,
670 time << CONTROL4_ADCDBSET_SHIFT); 686 time << MAX77843_MUIC_CONTROL4_ADCDBSET_SHIFT);
671 if (ret < 0) { 687 if (ret < 0) {
672 dev_err(info->dev, "Cannot write MUIC regmap\n"); 688 dev_err(info->dev, "Cannot write MUIC regmap\n");
673 return ret; 689 return ret;
@@ -681,7 +697,7 @@ static int max77843_muic_set_debounce_time(struct max77843_muic_info *info,
681 return 0; 697 return 0;
682} 698}
683 699
684static int max77843_init_muic_regmap(struct max77843 *max77843) 700static int max77843_init_muic_regmap(struct max77693_dev *max77843)
685{ 701{
686 int ret; 702 int ret;
687 703
@@ -720,7 +736,7 @@ err_muic_i2c:
720 736
721static int max77843_muic_probe(struct platform_device *pdev) 737static int max77843_muic_probe(struct platform_device *pdev)
722{ 738{
723 struct max77843 *max77843 = dev_get_drvdata(pdev->dev.parent); 739 struct max77693_dev *max77843 = dev_get_drvdata(pdev->dev.parent);
724 struct max77843_muic_info *info; 740 struct max77843_muic_info *info;
725 unsigned int id; 741 unsigned int id;
726 int i, ret; 742 int i, ret;
@@ -768,7 +784,7 @@ static int max77843_muic_probe(struct platform_device *pdev)
768 max77843_muic_set_debounce_time(info, MAX77843_DEBOUNCE_TIME_25MS); 784 max77843_muic_set_debounce_time(info, MAX77843_DEBOUNCE_TIME_25MS);
769 785
770 /* Set initial path for UART */ 786 /* Set initial path for UART */
771 max77843_muic_set_path(info, CONTROL1_SW_UART, true); 787 max77843_muic_set_path(info, MAX77843_MUIC_CONTROL1_SW_UART, true);
772 788
773 /* Check revision number of MUIC device */ 789 /* Check revision number of MUIC device */
774 ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id); 790 ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id);
@@ -830,7 +846,7 @@ err_muic_irq:
830static int max77843_muic_remove(struct platform_device *pdev) 846static int max77843_muic_remove(struct platform_device *pdev)
831{ 847{
832 struct max77843_muic_info *info = platform_get_drvdata(pdev); 848 struct max77843_muic_info *info = platform_get_drvdata(pdev);
833 struct max77843 *max77843 = info->max77843; 849 struct max77693_dev *max77843 = info->max77843;
834 850
835 cancel_work_sync(&info->irq_work); 851 cancel_work_sync(&info->irq_work);
836 regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); 852 regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic);