Re: [PATCH 2/2] extcon: max88743: Add support for SmartDock accessory

2017-10-18 Thread Chanwoo Choi
Hi Marek,

Also, this patch need to fix the patch subject as following:
- max88743 -> max77843

If you fix the subject, feel free to add my acked-tag.
Acked-by: Chanwoo Choi 

After finishing the review from MFD maintainer, I'll merge them.

Regards,
Chanwoo Choi

On 2017년 10월 18일 18:28, Marek Szyprowski wrote:
> SmartDock uses ADC_RESERVED_ACC_3 (0x10) ADC ID type and provides following
> features:
> 1. USB host with embedded USB hub (2-4 ports) for mice, keyboard, etc,
> 2. MHL for video output,
> 3. charging.
> 
> Tested with Unitek Y-2165 MHL+OTG Hub Smart Phone Dock.
> 
> Signed-off-by: Marek Szyprowski 
> ---
>  drivers/extcon/extcon-max77843.c | 77 
> +---
>  include/linux/mfd/max77843-private.h |  2 +
>  2 files changed, 65 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-max77843.c 
> b/drivers/extcon/extcon-max77843.c
> index 217c743405f8..cc28d2622ae7 100644
> --- a/drivers/extcon/extcon-max77843.c
> +++ b/drivers/extcon/extcon-max77843.c
> @@ -80,7 +80,7 @@ enum max77843_muic_accessory_type {
>   MAX77843_MUIC_ADC_REMOTE_S12_BUTTON,
>   MAX77843_MUIC_ADC_RESERVED_ACC_1,
>   MAX77843_MUIC_ADC_RESERVED_ACC_2,
> - MAX77843_MUIC_ADC_RESERVED_ACC_3,
> + MAX77843_MUIC_ADC_RESERVED_ACC_3, /* SmartDock */
>   MAX77843_MUIC_ADC_RESERVED_ACC_4,
>   MAX77843_MUIC_ADC_RESERVED_ACC_5,
>   MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2,
> @@ -119,6 +119,7 @@ enum max77843_muic_charger_type {
>   MAX77843_MUIC_CHG_SPECIAL_BIAS,
>   MAX77843_MUIC_CHG_RESERVED,
>   MAX77843_MUIC_CHG_GND,
> + MAX77843_MUIC_CHG_DOCK,
>  };
>  
>  static const unsigned int max77843_extcon_cable[] = {
> @@ -130,6 +131,7 @@ static const unsigned int max77843_extcon_cable[] = {
>   EXTCON_CHG_USB_FAST,
>   EXTCON_CHG_USB_SLOW,
>   EXTCON_DISP_MHL,
> + EXTCON_DOCK,
>   EXTCON_JIG,
>   EXTCON_NONE,
>  };
> @@ -200,7 +202,7 @@ static const struct regmap_irq_chip 
> max77843_muic_irq_chip = {
>  };
>  
>  static int max77843_muic_set_path(struct max77843_muic_info *info,
> - u8 val, bool attached)
> + u8 val, bool attached, bool nobccomp)
>  {
>   struct max77693_dev *max77843 = info->max77843;
>   int ret = 0;
> @@ -210,10 +212,16 @@ static int max77843_muic_set_path(struct 
> max77843_muic_info *info,
>   ctrl1 = val;
>   else
>   ctrl1 = MAX77843_MUIC_CONTROL1_SW_OPEN;
> + if (nobccomp) {
> + /* Disable BC1.2 protocol and force manual switch control */
> + ctrl1 |= MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK;
> + }
>  
>   ret = regmap_update_bits(max77843->regmap_muic,
>   MAX77843_MUIC_REG_CONTROL1,
> - MAX77843_MUIC_CONTROL1_COM_SW, ctrl1);
> + MAX77843_MUIC_CONTROL1_COM_SW |
> + MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK,
> + ctrl1);
>   if (ret < 0) {
>   dev_err(info->dev, "Cannot switch MUIC port\n");
>   return ret;
> @@ -303,6 +311,19 @@ static int max77843_muic_get_cable_type(struct 
> max77843_muic_info *info,
>   break;
>   }
>  
> + if (adc == MAX77843_MUIC_ADC_RESERVED_ACC_3) { /* SmartDock */
> + if (chg_type == MAX77843_MUIC_CHG_NONE) {
> + *attached = false;
> + cable_type = info->prev_chg_type;
> + info->prev_chg_type = MAX77843_MUIC_CHG_NONE;
> + } else {
> + *attached = true;
> + cable_type = MAX77843_MUIC_CHG_DOCK;
> + info->prev_chg_type = MAX77843_MUIC_CHG_DOCK;
> + }
> + break;
> + }
> +
>   if (chg_type == MAX77843_MUIC_CHG_NONE) {
>   *attached = false;
>   cable_type = info->prev_chg_type;
> @@ -365,7 +386,7 @@ static int max77843_muic_adc_gnd_handler(struct 
> max77843_muic_info *info)
>   case MAX77843_MUIC_GND_USB_HOST_VB:
>   ret = max77843_muic_set_path(info,
>MAX77843_MUIC_CONTROL1_SW_USB,
> -  attached);
> +  attached, false);
>   if (ret < 0)
>   return ret;
>  
> @@ -376,7 +397,7 @@ static int max77843_muic_adc_gnd_handler(struct 
> max77843_muic_info *info)
>   case MAX77843_MUIC_GND_MHL:
>   ret = max77843_muic_set_path(info,
>MAX77843_MUIC_CONTROL1_SW_OPEN,
> -  attached);
> +  attached, false);
>   if (ret < 0)
>   return ret;

Re: [PATCH 2/2] extcon: max88743: Add support for SmartDock accessory

2017-10-18 Thread Chanwoo Choi
Hi Marek,

Also, this patch need to fix the patch subject as following:
- max88743 -> max77843

If you fix the subject, feel free to add my acked-tag.
Acked-by: Chanwoo Choi 

After finishing the review from MFD maintainer, I'll merge them.

Regards,
Chanwoo Choi

On 2017년 10월 18일 18:28, Marek Szyprowski wrote:
> SmartDock uses ADC_RESERVED_ACC_3 (0x10) ADC ID type and provides following
> features:
> 1. USB host with embedded USB hub (2-4 ports) for mice, keyboard, etc,
> 2. MHL for video output,
> 3. charging.
> 
> Tested with Unitek Y-2165 MHL+OTG Hub Smart Phone Dock.
> 
> Signed-off-by: Marek Szyprowski 
> ---
>  drivers/extcon/extcon-max77843.c | 77 
> +---
>  include/linux/mfd/max77843-private.h |  2 +
>  2 files changed, 65 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-max77843.c 
> b/drivers/extcon/extcon-max77843.c
> index 217c743405f8..cc28d2622ae7 100644
> --- a/drivers/extcon/extcon-max77843.c
> +++ b/drivers/extcon/extcon-max77843.c
> @@ -80,7 +80,7 @@ enum max77843_muic_accessory_type {
>   MAX77843_MUIC_ADC_REMOTE_S12_BUTTON,
>   MAX77843_MUIC_ADC_RESERVED_ACC_1,
>   MAX77843_MUIC_ADC_RESERVED_ACC_2,
> - MAX77843_MUIC_ADC_RESERVED_ACC_3,
> + MAX77843_MUIC_ADC_RESERVED_ACC_3, /* SmartDock */
>   MAX77843_MUIC_ADC_RESERVED_ACC_4,
>   MAX77843_MUIC_ADC_RESERVED_ACC_5,
>   MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2,
> @@ -119,6 +119,7 @@ enum max77843_muic_charger_type {
>   MAX77843_MUIC_CHG_SPECIAL_BIAS,
>   MAX77843_MUIC_CHG_RESERVED,
>   MAX77843_MUIC_CHG_GND,
> + MAX77843_MUIC_CHG_DOCK,
>  };
>  
>  static const unsigned int max77843_extcon_cable[] = {
> @@ -130,6 +131,7 @@ static const unsigned int max77843_extcon_cable[] = {
>   EXTCON_CHG_USB_FAST,
>   EXTCON_CHG_USB_SLOW,
>   EXTCON_DISP_MHL,
> + EXTCON_DOCK,
>   EXTCON_JIG,
>   EXTCON_NONE,
>  };
> @@ -200,7 +202,7 @@ static const struct regmap_irq_chip 
> max77843_muic_irq_chip = {
>  };
>  
>  static int max77843_muic_set_path(struct max77843_muic_info *info,
> - u8 val, bool attached)
> + u8 val, bool attached, bool nobccomp)
>  {
>   struct max77693_dev *max77843 = info->max77843;
>   int ret = 0;
> @@ -210,10 +212,16 @@ static int max77843_muic_set_path(struct 
> max77843_muic_info *info,
>   ctrl1 = val;
>   else
>   ctrl1 = MAX77843_MUIC_CONTROL1_SW_OPEN;
> + if (nobccomp) {
> + /* Disable BC1.2 protocol and force manual switch control */
> + ctrl1 |= MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK;
> + }
>  
>   ret = regmap_update_bits(max77843->regmap_muic,
>   MAX77843_MUIC_REG_CONTROL1,
> - MAX77843_MUIC_CONTROL1_COM_SW, ctrl1);
> + MAX77843_MUIC_CONTROL1_COM_SW |
> + MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK,
> + ctrl1);
>   if (ret < 0) {
>   dev_err(info->dev, "Cannot switch MUIC port\n");
>   return ret;
> @@ -303,6 +311,19 @@ static int max77843_muic_get_cable_type(struct 
> max77843_muic_info *info,
>   break;
>   }
>  
> + if (adc == MAX77843_MUIC_ADC_RESERVED_ACC_3) { /* SmartDock */
> + if (chg_type == MAX77843_MUIC_CHG_NONE) {
> + *attached = false;
> + cable_type = info->prev_chg_type;
> + info->prev_chg_type = MAX77843_MUIC_CHG_NONE;
> + } else {
> + *attached = true;
> + cable_type = MAX77843_MUIC_CHG_DOCK;
> + info->prev_chg_type = MAX77843_MUIC_CHG_DOCK;
> + }
> + break;
> + }
> +
>   if (chg_type == MAX77843_MUIC_CHG_NONE) {
>   *attached = false;
>   cable_type = info->prev_chg_type;
> @@ -365,7 +386,7 @@ static int max77843_muic_adc_gnd_handler(struct 
> max77843_muic_info *info)
>   case MAX77843_MUIC_GND_USB_HOST_VB:
>   ret = max77843_muic_set_path(info,
>MAX77843_MUIC_CONTROL1_SW_USB,
> -  attached);
> +  attached, false);
>   if (ret < 0)
>   return ret;
>  
> @@ -376,7 +397,7 @@ static int max77843_muic_adc_gnd_handler(struct 
> max77843_muic_info *info)
>   case MAX77843_MUIC_GND_MHL:
>   ret = max77843_muic_set_path(info,
>MAX77843_MUIC_CONTROL1_SW_OPEN,
> -  attached);
> +  attached, false);
>   if (ret < 0)
>   return ret;
>  
> @@ -412,7 +433,7 @@ static int 

[PATCH 2/2] extcon: max88743: Add support for SmartDock accessory

2017-10-18 Thread Marek Szyprowski
SmartDock uses ADC_RESERVED_ACC_3 (0x10) ADC ID type and provides following
features:
1. USB host with embedded USB hub (2-4 ports) for mice, keyboard, etc,
2. MHL for video output,
3. charging.

Tested with Unitek Y-2165 MHL+OTG Hub Smart Phone Dock.

Signed-off-by: Marek Szyprowski 
---
 drivers/extcon/extcon-max77843.c | 77 +---
 include/linux/mfd/max77843-private.h |  2 +
 2 files changed, 65 insertions(+), 14 deletions(-)

diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c
index 217c743405f8..cc28d2622ae7 100644
--- a/drivers/extcon/extcon-max77843.c
+++ b/drivers/extcon/extcon-max77843.c
@@ -80,7 +80,7 @@ enum max77843_muic_accessory_type {
MAX77843_MUIC_ADC_REMOTE_S12_BUTTON,
MAX77843_MUIC_ADC_RESERVED_ACC_1,
MAX77843_MUIC_ADC_RESERVED_ACC_2,
-   MAX77843_MUIC_ADC_RESERVED_ACC_3,
+   MAX77843_MUIC_ADC_RESERVED_ACC_3, /* SmartDock */
MAX77843_MUIC_ADC_RESERVED_ACC_4,
MAX77843_MUIC_ADC_RESERVED_ACC_5,
MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2,
@@ -119,6 +119,7 @@ enum max77843_muic_charger_type {
MAX77843_MUIC_CHG_SPECIAL_BIAS,
MAX77843_MUIC_CHG_RESERVED,
MAX77843_MUIC_CHG_GND,
+   MAX77843_MUIC_CHG_DOCK,
 };
 
 static const unsigned int max77843_extcon_cable[] = {
@@ -130,6 +131,7 @@ static const unsigned int max77843_extcon_cable[] = {
EXTCON_CHG_USB_FAST,
EXTCON_CHG_USB_SLOW,
EXTCON_DISP_MHL,
+   EXTCON_DOCK,
EXTCON_JIG,
EXTCON_NONE,
 };
@@ -200,7 +202,7 @@ static const struct regmap_irq_chip max77843_muic_irq_chip 
= {
 };
 
 static int max77843_muic_set_path(struct max77843_muic_info *info,
-   u8 val, bool attached)
+   u8 val, bool attached, bool nobccomp)
 {
struct max77693_dev *max77843 = info->max77843;
int ret = 0;
@@ -210,10 +212,16 @@ static int max77843_muic_set_path(struct 
max77843_muic_info *info,
ctrl1 = val;
else
ctrl1 = MAX77843_MUIC_CONTROL1_SW_OPEN;
+   if (nobccomp) {
+   /* Disable BC1.2 protocol and force manual switch control */
+   ctrl1 |= MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK;
+   }
 
ret = regmap_update_bits(max77843->regmap_muic,
MAX77843_MUIC_REG_CONTROL1,
-   MAX77843_MUIC_CONTROL1_COM_SW, ctrl1);
+   MAX77843_MUIC_CONTROL1_COM_SW |
+   MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK,
+   ctrl1);
if (ret < 0) {
dev_err(info->dev, "Cannot switch MUIC port\n");
return ret;
@@ -303,6 +311,19 @@ static int max77843_muic_get_cable_type(struct 
max77843_muic_info *info,
break;
}
 
+   if (adc == MAX77843_MUIC_ADC_RESERVED_ACC_3) { /* SmartDock */
+   if (chg_type == MAX77843_MUIC_CHG_NONE) {
+   *attached = false;
+   cable_type = info->prev_chg_type;
+   info->prev_chg_type = MAX77843_MUIC_CHG_NONE;
+   } else {
+   *attached = true;
+   cable_type = MAX77843_MUIC_CHG_DOCK;
+   info->prev_chg_type = MAX77843_MUIC_CHG_DOCK;
+   }
+   break;
+   }
+
if (chg_type == MAX77843_MUIC_CHG_NONE) {
*attached = false;
cable_type = info->prev_chg_type;
@@ -365,7 +386,7 @@ static int max77843_muic_adc_gnd_handler(struct 
max77843_muic_info *info)
case MAX77843_MUIC_GND_USB_HOST_VB:
ret = max77843_muic_set_path(info,
 MAX77843_MUIC_CONTROL1_SW_USB,
-attached);
+attached, false);
if (ret < 0)
return ret;
 
@@ -376,7 +397,7 @@ static int max77843_muic_adc_gnd_handler(struct 
max77843_muic_info *info)
case MAX77843_MUIC_GND_MHL:
ret = max77843_muic_set_path(info,
 MAX77843_MUIC_CONTROL1_SW_OPEN,
-attached);
+attached, false);
if (ret < 0)
return ret;
 
@@ -412,7 +433,7 @@ static int max77843_muic_jig_handler(struct 
max77843_muic_info *info,
return -EINVAL;
}
 
-   ret = max77843_muic_set_path(info, path, attached);
+   ret = max77843_muic_set_path(info, path, attached, false);
if (ret < 0)
return ret;
 
@@ -421,6 +442,26 @@ static int max77843_muic_jig_handler(struct 
max77843_muic_info *info,
return 0;
 }
 

[PATCH 2/2] extcon: max88743: Add support for SmartDock accessory

2017-10-18 Thread Marek Szyprowski
SmartDock uses ADC_RESERVED_ACC_3 (0x10) ADC ID type and provides following
features:
1. USB host with embedded USB hub (2-4 ports) for mice, keyboard, etc,
2. MHL for video output,
3. charging.

Tested with Unitek Y-2165 MHL+OTG Hub Smart Phone Dock.

Signed-off-by: Marek Szyprowski 
---
 drivers/extcon/extcon-max77843.c | 77 +---
 include/linux/mfd/max77843-private.h |  2 +
 2 files changed, 65 insertions(+), 14 deletions(-)

diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c
index 217c743405f8..cc28d2622ae7 100644
--- a/drivers/extcon/extcon-max77843.c
+++ b/drivers/extcon/extcon-max77843.c
@@ -80,7 +80,7 @@ enum max77843_muic_accessory_type {
MAX77843_MUIC_ADC_REMOTE_S12_BUTTON,
MAX77843_MUIC_ADC_RESERVED_ACC_1,
MAX77843_MUIC_ADC_RESERVED_ACC_2,
-   MAX77843_MUIC_ADC_RESERVED_ACC_3,
+   MAX77843_MUIC_ADC_RESERVED_ACC_3, /* SmartDock */
MAX77843_MUIC_ADC_RESERVED_ACC_4,
MAX77843_MUIC_ADC_RESERVED_ACC_5,
MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2,
@@ -119,6 +119,7 @@ enum max77843_muic_charger_type {
MAX77843_MUIC_CHG_SPECIAL_BIAS,
MAX77843_MUIC_CHG_RESERVED,
MAX77843_MUIC_CHG_GND,
+   MAX77843_MUIC_CHG_DOCK,
 };
 
 static const unsigned int max77843_extcon_cable[] = {
@@ -130,6 +131,7 @@ static const unsigned int max77843_extcon_cable[] = {
EXTCON_CHG_USB_FAST,
EXTCON_CHG_USB_SLOW,
EXTCON_DISP_MHL,
+   EXTCON_DOCK,
EXTCON_JIG,
EXTCON_NONE,
 };
@@ -200,7 +202,7 @@ static const struct regmap_irq_chip max77843_muic_irq_chip 
= {
 };
 
 static int max77843_muic_set_path(struct max77843_muic_info *info,
-   u8 val, bool attached)
+   u8 val, bool attached, bool nobccomp)
 {
struct max77693_dev *max77843 = info->max77843;
int ret = 0;
@@ -210,10 +212,16 @@ static int max77843_muic_set_path(struct 
max77843_muic_info *info,
ctrl1 = val;
else
ctrl1 = MAX77843_MUIC_CONTROL1_SW_OPEN;
+   if (nobccomp) {
+   /* Disable BC1.2 protocol and force manual switch control */
+   ctrl1 |= MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK;
+   }
 
ret = regmap_update_bits(max77843->regmap_muic,
MAX77843_MUIC_REG_CONTROL1,
-   MAX77843_MUIC_CONTROL1_COM_SW, ctrl1);
+   MAX77843_MUIC_CONTROL1_COM_SW |
+   MAX77843_MUIC_CONTROL1_NOBCCOMP_MASK,
+   ctrl1);
if (ret < 0) {
dev_err(info->dev, "Cannot switch MUIC port\n");
return ret;
@@ -303,6 +311,19 @@ static int max77843_muic_get_cable_type(struct 
max77843_muic_info *info,
break;
}
 
+   if (adc == MAX77843_MUIC_ADC_RESERVED_ACC_3) { /* SmartDock */
+   if (chg_type == MAX77843_MUIC_CHG_NONE) {
+   *attached = false;
+   cable_type = info->prev_chg_type;
+   info->prev_chg_type = MAX77843_MUIC_CHG_NONE;
+   } else {
+   *attached = true;
+   cable_type = MAX77843_MUIC_CHG_DOCK;
+   info->prev_chg_type = MAX77843_MUIC_CHG_DOCK;
+   }
+   break;
+   }
+
if (chg_type == MAX77843_MUIC_CHG_NONE) {
*attached = false;
cable_type = info->prev_chg_type;
@@ -365,7 +386,7 @@ static int max77843_muic_adc_gnd_handler(struct 
max77843_muic_info *info)
case MAX77843_MUIC_GND_USB_HOST_VB:
ret = max77843_muic_set_path(info,
 MAX77843_MUIC_CONTROL1_SW_USB,
-attached);
+attached, false);
if (ret < 0)
return ret;
 
@@ -376,7 +397,7 @@ static int max77843_muic_adc_gnd_handler(struct 
max77843_muic_info *info)
case MAX77843_MUIC_GND_MHL:
ret = max77843_muic_set_path(info,
 MAX77843_MUIC_CONTROL1_SW_OPEN,
-attached);
+attached, false);
if (ret < 0)
return ret;
 
@@ -412,7 +433,7 @@ static int max77843_muic_jig_handler(struct 
max77843_muic_info *info,
return -EINVAL;
}
 
-   ret = max77843_muic_set_path(info, path, attached);
+   ret = max77843_muic_set_path(info, path, attached, false);
if (ret < 0)
return ret;
 
@@ -421,6 +442,26 @@ static int max77843_muic_jig_handler(struct 
max77843_muic_info *info,
return 0;
 }
 
+static int