linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3] extcon: palmas: Option to disable ID/VBUS detection based on platform
@ 2013-07-10  9:29 Laxman Dewangan
  2013-07-11  2:42 ` Chanwoo Choi
  0 siblings, 1 reply; 4+ messages in thread
From: Laxman Dewangan @ 2013-07-10  9:29 UTC (permalink / raw)
  To: cw00.choi, myungjoo.ham
  Cc: devicetree-discuss, rob, linux-doc, linux-kernel, kishon, gg,
	Laxman Dewangan

Based on system design, platform needs to detect the VBUS or ID or
both. Provide option to select this through platform data to
disable part of cable detection through palmas-usb.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Acked-by: Graeme Gregory <gg@slimlogic.co.uk>
---
No changes from V1.

Change from V2:
- Remove the changes on platform strcuture.
- Move the palma_usb allocation before DT parsing.
- remove the mem allocation of pdata as it is not used.

Note:
- This was the 4th patch of the series. ALready 3 pacthes are applied and
  hence sending this 4th patch only. This has the fix suggested by Chanwoo.

 .../devicetree/bindings/extcon/extcon-palmas.txt   |    2 +
 drivers/extcon/extcon-palmas.c                     |   87 ++++++++++++--------
 include/linux/mfd/palmas.h                         |    3 +
 3 files changed, 58 insertions(+), 34 deletions(-)

diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
index f110e75..7dab6a8 100644
--- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
+++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
@@ -6,6 +6,8 @@ Required Properties:
 
 Optional Properties:
  - ti,wakeup : To enable the wakeup comparator in probe
+ - ti,enable-id-detection: Perform ID detection.
+ - ti,enable-vbus-detection: Perform VBUS detection.
 
 palmas-usb {
        compatible = "ti,twl6035-usb", "ti,palmas-usb";
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 5440f7c..5c218d2 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -122,11 +122,14 @@ static void palmas_enable_irq(struct palmas_usb *palmas_usb)
 		PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
 		PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 
-	palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb);
+	if (palmas_usb->enable_vbus_detection)
+		palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb);
 
 	/* cold plug for host mode needs this delay */
-	msleep(30);
-	palmas_id_irq_handler(palmas_usb->id_irq, palmas_usb);
+	if (palmas_usb->enable_id_detection) {
+		msleep(30);
+		palmas_id_irq_handler(palmas_usb->id_irq, palmas_usb);
+	}
 }
 
 static int palmas_usb_probe(struct platform_device *pdev)
@@ -137,20 +140,26 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	struct palmas_usb *palmas_usb;
 	int status;
 
-	if (node && !pdata) {
-		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
-
-		if (!pdata)
-			return -ENOMEM;
+	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
+	if (!palmas_usb)
+		return -ENOMEM;
 
-		pdata->wakeup = of_property_read_bool(node, "ti,wakeup");
+	if (node && !pdata) {
+		palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup");
+		palmas_usb->enable_id_detection = of_property_read_bool(node,
+						"ti,enable-id-detection");
+		palmas_usb->enable_vbus_detection = of_property_read_bool(node,
+						"ti,enable-vbus-detection");
+	} else if (pdata) {
+		palmas_usb->wakeup = pdata->wakeup;
+		palmas_usb->enable_id_detection = true;
+		palmas_usb->enable_vbus_detection = true;
 	} else if (!pdata) {
-		return -EINVAL;
+		palmas_usb->wakeup = true;
+		palmas_usb->enable_id_detection = true;
+		palmas_usb->enable_vbus_detection = true;
 	}
 
-	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
-	if (!palmas_usb)
-		return -ENOMEM;
 
 	palmas->usb = palmas_usb;
 	palmas_usb->palmas = palmas;
@@ -166,7 +175,7 @@ static int palmas_usb_probe(struct platform_device *pdev)
 	palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data,
 						PALMAS_VBUS_IRQ);
 
-	palmas_usb_wakeup(palmas, pdata->wakeup);
+	palmas_usb_wakeup(palmas, palmas_usb->wakeup);
 
 	platform_set_drvdata(pdev, palmas_usb);
 
@@ -180,26 +189,32 @@ static int palmas_usb_probe(struct platform_device *pdev)
 		return status;
 	}
 
-	status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq,
-			NULL, palmas_id_irq_handler,
-			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
-			IRQF_ONESHOT | IRQF_EARLY_RESUME,
-			"palmas_usb_id", palmas_usb);
-	if (status < 0) {
-		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
+	if (palmas_usb->enable_id_detection) {
+		status = devm_request_threaded_irq(palmas_usb->dev,
+				palmas_usb->id_irq,
+				NULL, palmas_id_irq_handler,
+				IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
+				IRQF_ONESHOT | IRQF_EARLY_RESUME,
+				"palmas_usb_id", palmas_usb);
+		if (status < 0) {
+			dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->id_irq, status);
-		goto fail_extcon;
+			goto fail_extcon;
+		}
 	}
 
-	status = devm_request_threaded_irq(palmas_usb->dev,
-			palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler,
-			IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
-			IRQF_ONESHOT | IRQF_EARLY_RESUME,
-			"palmas_usb_vbus", palmas_usb);
-	if (status < 0) {
-		dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
+	if (palmas_usb->enable_vbus_detection) {
+		status = devm_request_threaded_irq(palmas_usb->dev,
+				palmas_usb->vbus_irq, NULL,
+				palmas_vbus_irq_handler,
+				IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING |
+				IRQF_ONESHOT | IRQF_EARLY_RESUME,
+				"palmas_usb_vbus", palmas_usb);
+		if (status < 0) {
+			dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->vbus_irq, status);
-		goto fail_extcon;
+			goto fail_extcon;
+		}
 	}
 
 	palmas_enable_irq(palmas_usb);
@@ -227,8 +242,10 @@ static int palmas_usb_suspend(struct device *dev)
 	struct palmas_usb *palmas_usb = dev_get_drvdata(dev);
 
 	if (device_may_wakeup(dev)) {
-		enable_irq_wake(palmas_usb->vbus_irq);
-		enable_irq_wake(palmas_usb->id_irq);
+		if (palmas_usb->enable_vbus_detection)
+			enable_irq_wake(palmas_usb->vbus_irq);
+		if (palmas_usb->enable_id_detection)
+			enable_irq_wake(palmas_usb->id_irq);
 	}
 	return 0;
 }
@@ -238,8 +255,10 @@ static int palmas_usb_resume(struct device *dev)
 	struct palmas_usb *palmas_usb = dev_get_drvdata(dev);
 
 	if (device_may_wakeup(dev)) {
-		disable_irq_wake(palmas_usb->vbus_irq);
-		disable_irq_wake(palmas_usb->id_irq);
+		if (palmas_usb->enable_vbus_detection)
+			disable_irq_wake(palmas_usb->vbus_irq);
+		if (palmas_usb->enable_id_detection)
+			disable_irq_wake(palmas_usb->id_irq);
 	}
 	return 0;
 };
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index 03c22ca..cfc678c 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -377,6 +377,9 @@ struct palmas_usb {
 	int vbus_irq;
 
 	enum palmas_usb_state linkstat;
+	int wakeup;
+	bool enable_vbus_detection;
+	bool enable_id_detection;
 };
 
 #define comparator_to_palmas(x) container_of((x), struct palmas_usb, comparator)
-- 
1.7.1.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] extcon: palmas: Option to disable ID/VBUS detection based on platform
  2013-07-10  9:29 [PATCH V3] extcon: palmas: Option to disable ID/VBUS detection based on platform Laxman Dewangan
@ 2013-07-11  2:42 ` Chanwoo Choi
  2013-07-11  3:08   ` Laxman Dewangan
  0 siblings, 1 reply; 4+ messages in thread
From: Chanwoo Choi @ 2013-07-11  2:42 UTC (permalink / raw)
  To: Laxman Dewangan
  Cc: myungjoo.ham, devicetree-discuss, rob, linux-doc, linux-kernel,
	kishon, gg

Hi Laxman,

>  static int palmas_usb_probe(struct platform_device *pdev)
> @@ -137,20 +140,26 @@ static int palmas_usb_probe(struct platform_device *pdev)
>  	struct palmas_usb *palmas_usb;
>  	int status;
>  
> -	if (node && !pdata) {
> -		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
> -
> -		if (!pdata)
> -			return -ENOMEM;
> +	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
> +	if (!palmas_usb)
> +		return -ENOMEM;
>  
> -		pdata->wakeup = of_property_read_bool(node, "ti,wakeup");
> +	if (node && !pdata) {
> +		palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup");
> +		palmas_usb->enable_id_detection = of_property_read_bool(node,
> +						"ti,enable-id-detection");
> +		palmas_usb->enable_vbus_detection = of_property_read_bool(node,
> +						"ti,enable-vbus-detection");
> +	} else if (pdata) {
> +		palmas_usb->wakeup = pdata->wakeup;
> +		palmas_usb->enable_id_detection = true;
> +		palmas_usb->enable_vbus_detection = true;
>  	} else if (!pdata) {
> -		return -EINVAL;
> +		palmas_usb->wakeup = true;
> +		palmas_usb->enable_id_detection = true;
> +		palmas_usb->enable_vbus_detection = true;
>  	}

I think we could modify it as following patch to remove duplicate line.
If you agree about below modification, I will apply your patch with following patch.

index 5c218d2..56909cc 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -150,16 +150,14 @@ static int palmas_usb_probe(struct platform_device *pdev)
                                                "ti,enable-id-detection");
                palmas_usb->enable_vbus_detection = of_property_read_bool(node,
                                                "ti,enable-vbus-detection");
-       } else if (pdata) {
-               palmas_usb->wakeup = pdata->wakeup;
-               palmas_usb->enable_id_detection = true;
-               palmas_usb->enable_vbus_detection = true;
-       } else if (!pdata) {
+       } else {
                palmas_usb->wakeup = true;
                palmas_usb->enable_id_detection = true;
                palmas_usb->enable_vbus_detection = true;
-       }
 
+               if (pdata)
+                       palmas_usb->wakeup = pdata->wakeup;
+       }
 
        palmas->usb = palmas_usb;
        palmas_usb->palmas = palmas;


Thanks,
Chanwoo Choi



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] extcon: palmas: Option to disable ID/VBUS detection based on platform
  2013-07-11  2:42 ` Chanwoo Choi
@ 2013-07-11  3:08   ` Laxman Dewangan
  2013-07-11  4:30     ` Chanwoo Choi
  0 siblings, 1 reply; 4+ messages in thread
From: Laxman Dewangan @ 2013-07-11  3:08 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: myungjoo.ham, devicetree-discuss, rob, linux-doc, linux-kernel,
	kishon, gg

On Thursday 11 July 2013 08:12 AM, Chanwoo Choi wrote:
> Hi Laxman,
>
>>   static int palmas_usb_probe(struct platform_device *pdev)
>> @@ -137,20 +140,26 @@ static int palmas_usb_probe(struct platform_device *pdev)
>>   	struct palmas_usb *palmas_usb;
>>   	int status;
>>   
>> -	if (node && !pdata) {
>> -		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
>> -
>> -		if (!pdata)
>> -			return -ENOMEM;
>> +	palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
>> +	if (!palmas_usb)
>> +		return -ENOMEM;
>>   
>> -		pdata->wakeup = of_property_read_bool(node, "ti,wakeup");
>> +	if (node && !pdata) {
>> +		palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup");
>> +		palmas_usb->enable_id_detection = of_property_read_bool(node,
>> +						"ti,enable-id-detection");
>> +		palmas_usb->enable_vbus_detection = of_property_read_bool(node,
>> +						"ti,enable-vbus-detection");
>> +	} else if (pdata) {
>> +		palmas_usb->wakeup = pdata->wakeup;
>> +		palmas_usb->enable_id_detection = true;
>> +		palmas_usb->enable_vbus_detection = true;
>>   	} else if (!pdata) {
>> -		return -EINVAL;
>> +		palmas_usb->wakeup = true;
>> +		palmas_usb->enable_id_detection = true;
>> +		palmas_usb->enable_vbus_detection = true;
>>   	}
> I think we could modify it as following patch to remove duplicate line.
> If you agree about below modification, I will apply your patch with following patch.
>
I am fine with this and this looks simple and straight.

I have seen some patches/discussion from TI to remove the platform data 
support at all and hence removing from here in future will be very simple.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V3] extcon: palmas: Option to disable ID/VBUS detection based on platform
  2013-07-11  3:08   ` Laxman Dewangan
@ 2013-07-11  4:30     ` Chanwoo Choi
  0 siblings, 0 replies; 4+ messages in thread
From: Chanwoo Choi @ 2013-07-11  4:30 UTC (permalink / raw)
  To: Laxman Dewangan
  Cc: myungjoo.ham, devicetree-discuss, rob, linux-doc, linux-kernel,
	kishon, gg

On 07/11/2013 12:08 PM, Laxman Dewangan wrote:
> On Thursday 11 July 2013 08:12 AM, Chanwoo Choi wrote:
>> Hi Laxman,
>>
>>>   static int palmas_usb_probe(struct platform_device *pdev)
>>> @@ -137,20 +140,26 @@ static int palmas_usb_probe(struct platform_device *pdev)
>>>       struct palmas_usb *palmas_usb;
>>>       int status;
>>>   -    if (node && !pdata) {
>>> -        pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
>>> -
>>> -        if (!pdata)
>>> -            return -ENOMEM;
>>> +    palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL);
>>> +    if (!palmas_usb)
>>> +        return -ENOMEM;
>>>   -        pdata->wakeup = of_property_read_bool(node, "ti,wakeup");
>>> +    if (node && !pdata) {
>>> +        palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup");
>>> +        palmas_usb->enable_id_detection = of_property_read_bool(node,
>>> +                        "ti,enable-id-detection");
>>> +        palmas_usb->enable_vbus_detection = of_property_read_bool(node,
>>> +                        "ti,enable-vbus-detection");
>>> +    } else if (pdata) {
>>> +        palmas_usb->wakeup = pdata->wakeup;
>>> +        palmas_usb->enable_id_detection = true;
>>> +        palmas_usb->enable_vbus_detection = true;
>>>       } else if (!pdata) {
>>> -        return -EINVAL;
>>> +        palmas_usb->wakeup = true;
>>> +        palmas_usb->enable_id_detection = true;
>>> +        palmas_usb->enable_vbus_detection = true;
>>>       }
>> I think we could modify it as following patch to remove duplicate line.
>> If you agree about below modification, I will apply your patch with following patch.
>>
> I am fine with this and this looks simple and straight.
> 
> I have seen some patches/discussion from TI to remove the platform data support at all and hence removing from here in future will be very simple.
> 

This patch is applied on extcon-linus branch.

Thanks,
Chanwoo Choi


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-11  4:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-10  9:29 [PATCH V3] extcon: palmas: Option to disable ID/VBUS detection based on platform Laxman Dewangan
2013-07-11  2:42 ` Chanwoo Choi
2013-07-11  3:08   ` Laxman Dewangan
2013-07-11  4:30     ` Chanwoo Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).