linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose
@ 2021-12-28 17:01 ` Hans de Goede
  2021-12-28 17:01   ` [PATCH 2/4] extcon: int3496: Request non-exclusive access to the ID GPIO Hans de Goede
                     ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Hans de Goede @ 2021-12-28 17:01 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi; +Cc: Hans de Goede, Stephan Gerhold, linux-kernel

On all devices which I have with an INT3496 ACPI device,
there is only an ID pin defined.

Change the log-messages about not being able to get GPIOs for
"VBUS EN" and "USB MUX" to use dev_dbg().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/extcon/extcon-intel-int3496.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c
index fb527c23639e..df6ab4ef46f5 100644
--- a/drivers/extcon/extcon-intel-int3496.c
+++ b/drivers/extcon/extcon-intel-int3496.c
@@ -121,11 +121,11 @@ static int int3496_probe(struct platform_device *pdev)
 
 	data->gpio_vbus_en = devm_gpiod_get(dev, "vbus", GPIOD_ASIS);
 	if (IS_ERR(data->gpio_vbus_en))
-		dev_info(dev, "can't request VBUS EN GPIO\n");
+		dev_dbg(dev, "can't request VBUS EN GPIO\n");
 
 	data->gpio_usb_mux = devm_gpiod_get(dev, "mux", GPIOD_ASIS);
 	if (IS_ERR(data->gpio_usb_mux))
-		dev_info(dev, "can't request USB MUX GPIO\n");
+		dev_dbg(dev, "can't request USB MUX GPIO\n");
 
 	/* register extcon device */
 	data->edev = devm_extcon_dev_allocate(dev, int3496_cable);
-- 
2.33.1


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

* [PATCH 2/4] extcon: int3496: Request non-exclusive access to the ID GPIO
  2021-12-28 17:01 ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose Hans de Goede
@ 2021-12-28 17:01   ` Hans de Goede
  2021-12-28 17:01   ` [PATCH 3/4] extcon: int3496: Add support for binding to plain platform devices Hans de Goede
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2021-12-28 17:01 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi; +Cc: Hans de Goede, Stephan Gerhold, linux-kernel

Some DSDTs are buggy and do a read from the ID pin during the ACPI
initialization, causing the pin to be marked as owned by:
"ACPI:OpRegion" and causing gpiod_get() to fail with -EBUSY.

Pass the GPIOD_FLAGS_BIT_NONEXCLUSIVE flag to the gpiod_get() call
to work around this.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/extcon/extcon-intel-int3496.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c
index df6ab4ef46f5..20605574020c 100644
--- a/drivers/extcon/extcon-intel-int3496.c
+++ b/drivers/extcon/extcon-intel-int3496.c
@@ -106,7 +106,8 @@ static int int3496_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	data->gpio_usb_id = devm_gpiod_get(dev, "id", GPIOD_IN);
+	data->gpio_usb_id =
+		devm_gpiod_get(dev, "id", GPIOD_IN | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
 	if (IS_ERR(data->gpio_usb_id)) {
 		ret = PTR_ERR(data->gpio_usb_id);
 		dev_err(dev, "can't request USB ID GPIO: %d\n", ret);
-- 
2.33.1


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

* [PATCH 3/4] extcon: int3496: Add support for binding to plain platform devices
  2021-12-28 17:01 ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose Hans de Goede
  2021-12-28 17:01   ` [PATCH 2/4] extcon: int3496: Request non-exclusive access to the ID GPIO Hans de Goede
@ 2021-12-28 17:01   ` Hans de Goede
  2021-12-28 17:01   ` [PATCH 4/4] extcon: int3496: Add support for controlling Vbus through a regulator Hans de Goede
  2022-02-16  1:27   ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose Chanwoo Choi
  3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2021-12-28 17:01 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi; +Cc: Hans de Goede, Stephan Gerhold, linux-kernel

On some X86 Android tablets the DSTD lack the INT3496 ACPI device,
while also not handling micro USB port ID pin events inside the DSDT
(instead the forked factory image kernel has things hardcoded).

The new drivers/platform/x86/x86-android-tablets.c module manually
instantiates an intel-int3496 device for these tablets.

Add support to the extcon-intel-int3496 driver to bind to devices
without an ACPI companion and export a normal platform_device
modalias for automatic module loading.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/extcon/extcon-intel-int3496.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c
index 20605574020c..0830076d8c05 100644
--- a/drivers/extcon/extcon-intel-int3496.c
+++ b/drivers/extcon/extcon-intel-int3496.c
@@ -91,10 +91,12 @@ static int int3496_probe(struct platform_device *pdev)
 	struct int3496_data *data;
 	int ret;
 
-	ret = devm_acpi_dev_add_driver_gpios(dev, acpi_int3496_default_gpios);
-	if (ret) {
-		dev_err(dev, "can't add GPIO ACPI mapping\n");
-		return ret;
+	if (has_acpi_companion(dev)) {
+		ret = devm_acpi_dev_add_driver_gpios(dev, acpi_int3496_default_gpios);
+		if (ret) {
+			dev_err(dev, "can't add GPIO ACPI mapping\n");
+			return ret;
+		}
 	}
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
@@ -165,12 +167,19 @@ static const struct acpi_device_id int3496_acpi_match[] = {
 };
 MODULE_DEVICE_TABLE(acpi, int3496_acpi_match);
 
+static const struct platform_device_id int3496_ids[] = {
+	{ .name = "intel-int3496" },
+	{},
+};
+MODULE_DEVICE_TABLE(platform, int3496_ids);
+
 static struct platform_driver int3496_driver = {
 	.driver = {
 		.name = "intel-int3496",
 		.acpi_match_table = int3496_acpi_match,
 	},
 	.probe = int3496_probe,
+	.id_table = int3496_ids,
 };
 
 module_platform_driver(int3496_driver);
-- 
2.33.1


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

* [PATCH 4/4] extcon: int3496: Add support for controlling Vbus through a regulator
  2021-12-28 17:01 ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose Hans de Goede
  2021-12-28 17:01   ` [PATCH 2/4] extcon: int3496: Request non-exclusive access to the ID GPIO Hans de Goede
  2021-12-28 17:01   ` [PATCH 3/4] extcon: int3496: Add support for binding to plain platform devices Hans de Goede
@ 2021-12-28 17:01   ` Hans de Goede
  2022-02-16  1:27   ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose Chanwoo Choi
  3 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2021-12-28 17:01 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi; +Cc: Hans de Goede, Stephan Gerhold, linux-kernel

On some boards the 5V vboost-regulator for powering devices connected to
the micro USB connector is not controlled through a GPIO. This happens
for example when the 5V vboost-regulator is integrated into the charger IC
and controlled over I2C.

Add support for controlling the 5V vboost-regulator through the regulator
framework for such boards.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/extcon/extcon-intel-int3496.c | 30 ++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c
index 0830076d8c05..ded1a85a5549 100644
--- a/drivers/extcon/extcon-intel-int3496.c
+++ b/drivers/extcon/extcon-intel-int3496.c
@@ -17,6 +17,7 @@
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
 
 #define INT3496_GPIO_USB_ID	0
 #define INT3496_GPIO_VBUS_EN	1
@@ -30,7 +31,9 @@ struct int3496_data {
 	struct gpio_desc *gpio_usb_id;
 	struct gpio_desc *gpio_vbus_en;
 	struct gpio_desc *gpio_usb_mux;
+	struct regulator *vbus_boost;
 	int usb_id_irq;
+	bool vbus_boost_enabled;
 };
 
 static const unsigned int int3496_cable[] = {
@@ -53,6 +56,27 @@ static const struct acpi_gpio_mapping acpi_int3496_default_gpios[] = {
 	{ },
 };
 
+static void int3496_set_vbus_boost(struct int3496_data *data, bool enable)
+{
+	int ret;
+
+	if (IS_ERR_OR_NULL(data->vbus_boost))
+		return;
+
+	if (data->vbus_boost_enabled == enable)
+		return;
+
+	if (enable)
+		ret = regulator_enable(data->vbus_boost);
+	else
+		ret = regulator_disable(data->vbus_boost);
+
+	if (ret == 0)
+		data->vbus_boost_enabled = enable;
+	else
+		dev_err(data->dev, "Error updating Vbus boost regulator: %d\n", ret);
+}
+
 static void int3496_do_usb_id(struct work_struct *work)
 {
 	struct int3496_data *data =
@@ -71,6 +95,8 @@ static void int3496_do_usb_id(struct work_struct *work)
 
 	if (!IS_ERR(data->gpio_vbus_en))
 		gpiod_direction_output(data->gpio_vbus_en, !id);
+	else
+		int3496_set_vbus_boost(data, !id);
 
 	extcon_set_state_sync(data->edev, EXTCON_USB_HOST, !id);
 }
@@ -123,8 +149,10 @@ static int int3496_probe(struct platform_device *pdev)
 	}
 
 	data->gpio_vbus_en = devm_gpiod_get(dev, "vbus", GPIOD_ASIS);
-	if (IS_ERR(data->gpio_vbus_en))
+	if (IS_ERR(data->gpio_vbus_en)) {
 		dev_dbg(dev, "can't request VBUS EN GPIO\n");
+		data->vbus_boost = devm_regulator_get_optional(dev, "vbus");
+	}
 
 	data->gpio_usb_mux = devm_gpiod_get(dev, "mux", GPIOD_ASIS);
 	if (IS_ERR(data->gpio_usb_mux))
-- 
2.33.1


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

* Re: [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose
  2021-12-28 17:01 ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose Hans de Goede
                     ` (2 preceding siblings ...)
  2021-12-28 17:01   ` [PATCH 4/4] extcon: int3496: Add support for controlling Vbus through a regulator Hans de Goede
@ 2022-02-16  1:27   ` Chanwoo Choi
  3 siblings, 0 replies; 5+ messages in thread
From: Chanwoo Choi @ 2022-02-16  1:27 UTC (permalink / raw)
  To: Hans de Goede, MyungJoo Ham; +Cc: Stephan Gerhold, linux-kernel

On 12/29/21 2:01 AM, Hans de Goede wrote:
> On all devices which I have with an INT3496 ACPI device,
> there is only an ID pin defined.
> 
> Change the log-messages about not being able to get GPIOs for
> "VBUS EN" and "USB MUX" to use dev_dbg().
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/extcon/extcon-intel-int3496.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-intel-int3496.c
> index fb527c23639e..df6ab4ef46f5 100644
> --- a/drivers/extcon/extcon-intel-int3496.c
> +++ b/drivers/extcon/extcon-intel-int3496.c
> @@ -121,11 +121,11 @@ static int int3496_probe(struct platform_device *pdev)
>  
>  	data->gpio_vbus_en = devm_gpiod_get(dev, "vbus", GPIOD_ASIS);
>  	if (IS_ERR(data->gpio_vbus_en))
> -		dev_info(dev, "can't request VBUS EN GPIO\n");
> +		dev_dbg(dev, "can't request VBUS EN GPIO\n");
>  
>  	data->gpio_usb_mux = devm_gpiod_get(dev, "mux", GPIOD_ASIS);
>  	if (IS_ERR(data->gpio_usb_mux))
> -		dev_info(dev, "can't request USB MUX GPIO\n");
> +		dev_dbg(dev, "can't request USB MUX GPIO\n");
>  
>  	/* register extcon device */
>  	data->edev = devm_extcon_dev_allocate(dev, int3496_cable);
> 

Applied them (patch1-4). Thanks.

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

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

end of thread, other threads:[~2022-02-16  1:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20211228170156epcas1p2a0dea22755f2336b01c6e06b289d9583@epcas1p2.samsung.com>
2021-12-28 17:01 ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose Hans de Goede
2021-12-28 17:01   ` [PATCH 2/4] extcon: int3496: Request non-exclusive access to the ID GPIO Hans de Goede
2021-12-28 17:01   ` [PATCH 3/4] extcon: int3496: Add support for binding to plain platform devices Hans de Goede
2021-12-28 17:01   ` [PATCH 4/4] extcon: int3496: Add support for controlling Vbus through a regulator Hans de Goede
2022-02-16  1:27   ` [PATCH 1/4] extcon: int3496: Make the driver a bit less verbose 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).