Skip to contentSkip to conversation

max3421: add devicetree support

PATCH Superseded Jules Maselbas 4 participants 18 messages Sep 15, 2017 – Nov 1, 2017 10 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover max3421: add devicetree support

Hi,

This patchset adds devicetree support to the max3421 driver. Thoses modification are based on a previous (unapplied) patch series by Alexander Amelkin [1].

Since I am not a kernel expert I would a like to have your feedbacks on:
1. Under which condition pdata must be freed (in max3421_probe) ?
2. If it neccessary to free platform_data in max3421_remove function ?

Thank you,

[1]: [https://lkml.org/lkml/2017/5/26/285]

---

Jules Maselbas (2):
usb: max3421: Add devicetree support
dt-bindings: max3421: Add bindings documentation

 .../devicetree/bindings/usb/maxim,max3421.txt      | 24 ++++++
 drivers/usb/host/max3421-hcd.c                     | 87 +++++++++++++++++++++-
 2 files changed, 110 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt
Signature · 6 lines
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): cover.1505492941.git.jules.maselbas-l+/[email protected]

#2 lore raw

PATCH 1/2 usb: max3421: Add devicetree support

Adds support for devicetree to the max3421 driver.

---
 drivers/usb/host/max3421-hcd.c | 87 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 86 insertions(+), 1 deletion(-)
drivers/usb/host/max3421-hcd.c +86 -1
index 0ece9a9341e5..928a5aabee02 100644
@@ -60,6 +60,7 @@
 #include <linux/spi/spi.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
+#include <linux/of.h>
 
 #include <linux/platform_data/max3421-hcd.h>
 
@@ -85,6 +86,8 @@
 			  USB_PORT_STAT_C_OVERCURRENT | \
 			  USB_PORT_STAT_C_RESET) << 16)
 
+#define MAX3421_GPOUT_COUNT	8
+
 enum max3421_rh_state {
 	MAX3421_RH_RESET,
 	MAX3421_RH_SUSPENDED,
@@ -1672,7 +1675,7 @@ max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value)
 	u8 mask, idx;
 
 	--pin_number;
-	if (pin_number > 7)
+	if (pin_number >= MAX3421_GPOUT_COUNT)
 		return;
 
 	mask = 1u << (pin_number % 4);
@@ -1699,6 +1702,10 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,
 	spin_lock_irqsave(&max3421_hcd->lock, flags);
 
 	pdata = spi->dev.platform_data;
+	if (!pdata) {
+		dev_err(&spi->dev, "Device platform data is missing\n");
+		return -EFAULT;
+	}
 
 	switch (type_req) {
 	case ClearHubFeature:
@@ -1831,11 +1838,35 @@ static const struct hc_driver max3421_hcd_desc = {
 	.bus_resume =		max3421_bus_resume,
 };
 
+static int
+max3421_of_vbus_en_pin(struct device *dev, struct max3421_hcd_platform_data *pdata)
+{
+	int retval;
+	uint32_t value[2];
+
+	if (!pdata)
+		return -EINVAL;
+
+	retval = of_property_read_u32_array(dev->of_node, "maxim,vbus-en-pin", value, 2);
+	if (retval) {
+		dev_err(dev, "device tree node property 'maxim,vbus-en-pin' is missing\n");
+		return retval;
+	}
+	dev_info(dev, "property 'maxim,vbus-en-pin' value is <%d %d>\n", value[0], value[1]);
+
+	pdata->vbus_gpout = value[0];
+	pdata->vbus_active_level = value[1];
+
+	return 0;
+}
+
 static int
 max3421_probe(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
 	struct max3421_hcd *max3421_hcd;
 	struct usb_hcd *hcd = NULL;
+	struct max3421_hcd_platform_data *pdata = NULL;
 	int retval = -ENOMEM;
 
 	if (spi_setup(spi) < 0) {
@@ -1843,6 +1874,42 @@ max3421_probe(struct spi_device *spi)
 		return -EFAULT;
 	}
 
+	if (!spi->irq) {
+		dev_err(dev, "Failed to get SPI IRQ");
+		return -EFAULT;
+	}
+
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+		pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL);
+		if (!pdata) {
+			dev_err(&spi->dev, "failed to allocate memory for private data\n");
+			retval = -ENOMEM;
+			goto error;
+		}
+		retval = max3421_of_vbus_en_pin(dev, pdata);
+		if (retval)
+			goto error;
+
+		spi->dev.platform_data = pdata;
+	}
+
+	pdata = spi->dev.platform_data;
+	if (!pdata) {
+		dev_err(&spi->dev, "driver configuration data is not provided\n");
+		retval = -EFAULT;
+		goto error;
+	}
+	if (pdata->vbus_active_level > 1) {
+		dev_err(&spi->dev, "vbus active level value %d is out of range (0/1)\n", pdata->vbus_active_level);
+		retval = -EINVAL;
+		goto error;
+	}
+	if (pdata->vbus_gpout < 1 || pdata->vbus_gpout > MAX3421_GPOUT_COUNT) {
+		dev_err(&spi->dev, "vbus gpout value %d is out of range (1..8)\n", pdata->vbus_gpout);
+		retval = -EINVAL;
+		goto error;
+	}
+
 	hcd = usb_create_hcd(&max3421_hcd_desc, &spi->dev,
 			     dev_name(&spi->dev));
 	if (!hcd) {
@@ -1885,6 +1952,11 @@ max3421_probe(struct spi_device *spi)
 	return 0;
 
 error:
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) {
+		devm_kfree(&spi->dev, pdata);
+		spi->dev.platform_data = NULL;
+	}
+
 	if (hcd) {
 		kfree(max3421_hcd->tx);
 		kfree(max3421_hcd->rx);
@@ -1923,17 +1995,30 @@ max3421_remove(struct spi_device *spi)
 
 	spin_unlock_irqrestore(&max3421_hcd->lock, flags);
 
+	if (IS_ENABLED(CONFIG_OF) && spi->dev.platform_data) {
+		dev_dbg(&spi->dev, "Freeing platform data structure\n");
+		devm_kfree(&spi->dev, spi->dev.platform_data);
+		spi->dev.platform_data = NULL;
+	}
+
 	free_irq(spi->irq, hcd);
 
 	usb_put_hcd(hcd);
 	return 0;
 }
 
+static const struct of_device_id max3421_of_match_table[] = {
+	{ .compatible = "maxim,max3421", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, max3421_of_match_table);
+
 static struct spi_driver max3421_driver = {
 	.probe		= max3421_probe,
 	.remove		= max3421_remove,
 	.driver		= {
 		.name	= "max3421-hcd",
+		.of_match_table = of_match_ptr(max3421_of_match_table),
 	},
 };
 
Signature · 6 lines
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH 2/2 dt-bindings: max3421: Add bindings documentation

In reply to a message not in the archive

Adds bindings documentation for the max3421 driver.

---
 .../devicetree/bindings/usb/maxim,max3421.txt      | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt
Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +24 -0
new file mode 100644
index 000000000000..7536c3ab3e5a
@@ -0,0 +1,24 @@
+Maxim Integrated SPI-based USB 2.0 host controller MAX3421E
+
+Required properties:
+ - compatible: "maxim,max3421"
+ - spi-max-frequency: maximum frequency for this device must not exceed 26 MHz.
+ - reg: chip select number to which this device is connected.
+ - maxim,vbus-en-pin: <GPOUTx ACTIVE_LEVEL>
+   GPOUTx is the number (1-8) of the GPOUT pin of MAX3421E to drive Vbus.
+   ACTIVE_LEVEL is 0 or 1.
+ - interrupt-parent: the phandle of the associated interrupt controller.
+ - interrupts: the interuption line description for the interrupt controller.
+   The driver configures MAX3421E for active low level triggered interrupts,
+   configure your interrupt line accordingly.
+
+Example:
+
+	usb@0 {
+		compatible = "maxim,max3421";
+		reg = <0>;
+		maxim,vbus-en-pin = <3 1>;
+		spi-max-frequency = <26000000>;
+		interrupt-parent = <&PIC>;
+		interrupts = <42>;
+	};
Signature · 6 lines
2.14.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): a69d2c5fc640fa0f4c9e9edb45da98fae39cfbac.1505492941.git.jules.maselbas-l+/[email protected]

Acked-by
#5 lore raw

Re: [PATCH 2/2] dt-bindings: max3421: Add bindings documentation

Quoted 7 lines · Jules Maselbas

Adds bindings documentation for the max3421 driver.

---
 .../devicetree/bindings/usb/maxim,max3421.txt      | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

v2 cover max3421: add devicetree support

In reply to a message not in the archive

Hi,

This patchset adds devicetree support to the max3421 driver. Theses modification are based on a previous (unapplied) patch series by Alexander Amelkin [1].

Changes since v2:
* The platform_data is no longer freed in max3421_remove() as it is allocated with devm_kzalloc.
* Removed the dev_err print if devm_kzalloc fail.
* Removed a test for platform_data null pointer in max3421_hub_control() as the driver probe will fail if no platform_data is found.

Thank you.

[1]: [https://lkml.org/lkml/2017/5/26/285]

---

Jules Maselbas (2):
usb: max3421: Add devicetree support
dt-bindings: max3421: Add bindings documentation

 .../devicetree/bindings/usb/maxim,max3421.txt      | 24 +++++++
 drivers/usb/host/max3421-hcd.c                     | 75 +++++++++++++++++++++-
 2 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt
Signature · 6 lines
2.14.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): cover.1508108927.git.jules.maselbas-l+/[email protected]

#8 lore raw

PATCH v2 1/2 usb: max3421: Add devicetree support

Adds support for devicetree to the max3421 driver.

---
 drivers/usb/host/max3421-hcd.c | 75 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)
drivers/usb/host/max3421-hcd.c +74 -1
index 0ece9a9341e5..d77b3f27c6e7 100644
@@ -60,6 +60,7 @@
 #include <linux/spi/spi.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
+#include <linux/of.h>
 
 #include <linux/platform_data/max3421-hcd.h>
 
@@ -85,6 +86,8 @@
 			  USB_PORT_STAT_C_OVERCURRENT | \
 			  USB_PORT_STAT_C_RESET) << 16)
 
+#define MAX3421_GPOUT_COUNT	8
+
 enum max3421_rh_state {
 	MAX3421_RH_RESET,
 	MAX3421_RH_SUSPENDED,
@@ -1672,7 +1675,7 @@ max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value)
 	u8 mask, idx;
 
 	--pin_number;
-	if (pin_number > 7)
+	if (pin_number >= MAX3421_GPOUT_COUNT)
 		return;
 
 	mask = 1u << (pin_number % 4);
@@ -1831,11 +1834,35 @@ static const struct hc_driver max3421_hcd_desc = {
 	.bus_resume =		max3421_bus_resume,
 };
 
+static int
+max3421_of_vbus_en_pin(struct device *dev, struct max3421_hcd_platform_data *pdata)
+{
+	int retval;
+	uint32_t value[2];
+
+	if (!pdata)
+		return -EINVAL;
+
+	retval = of_property_read_u32_array(dev->of_node, "maxim,vbus-en-pin", value, 2);
+	if (retval) {
+		dev_err(dev, "device tree node property 'maxim,vbus-en-pin' is missing\n");
+		return retval;
+	}
+	dev_info(dev, "property 'maxim,vbus-en-pin' value is <%d %d>\n", value[0], value[1]);
+
+	pdata->vbus_gpout = value[0];
+	pdata->vbus_active_level = value[1];
+
+	return 0;
+}
+
 static int
 max3421_probe(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
 	struct max3421_hcd *max3421_hcd;
 	struct usb_hcd *hcd = NULL;
+	struct max3421_hcd_platform_data *pdata = NULL;
 	int retval = -ENOMEM;
 
 	if (spi_setup(spi) < 0) {
@@ -1843,6 +1870,40 @@ max3421_probe(struct spi_device *spi)
 		return -EFAULT;
 	}
 
+	if (!spi->irq) {
+		dev_err(dev, "Failed to get SPI IRQ");
+		return -EFAULT;
+	}
+
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+		pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+		if (!pdata) {
+			retval = -ENOMEM;
+			goto error;
+		}
+		retval = max3421_of_vbus_en_pin(dev, pdata);
+		if (retval)
+			goto error;
+		spi->dev.platform_data = pdata;
+	}
+
+	pdata = dev->platform_data;
+	if (!pdata) {
+		dev_err(dev, "driver configuration data is not provided\n");
+		retval = -EFAULT;
+		goto error;
+	}
+	if (pdata->vbus_active_level > 1) {
+		dev_err(dev, "vbus active level value %d is out of range (0/1)\n", pdata->vbus_active_level);
+		retval = -EINVAL;
+		goto error;
+	}
+	if (pdata->vbus_gpout < 1 || pdata->vbus_gpout > MAX3421_GPOUT_COUNT) {
+		dev_err(dev, "vbus gpout value %d is out of range (1..8)\n", pdata->vbus_gpout);
+		retval = -EINVAL;
+		goto error;
+	}
+
 	hcd = usb_create_hcd(&max3421_hcd_desc, &spi->dev,
 			     dev_name(&spi->dev));
 	if (!hcd) {
@@ -1885,6 +1946,11 @@ max3421_probe(struct spi_device *spi)
 	return 0;
 
 error:
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) {
+		devm_kfree(&spi->dev, pdata);
+		spi->dev.platform_data = NULL;
+	}
+
 	if (hcd) {
 		kfree(max3421_hcd->tx);
 		kfree(max3421_hcd->rx);
@@ -1929,11 +1995,18 @@ max3421_remove(struct spi_device *spi)
 	return 0;
 }
 
+static const struct of_device_id max3421_of_match_table[] = {
+	{ .compatible = "maxim,max3421", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, max3421_of_match_table);
+
 static struct spi_driver max3421_driver = {
 	.probe		= max3421_probe,
 	.remove		= max3421_remove,
 	.driver		= {
 		.name	= "max3421-hcd",
+		.of_match_table = of_match_ptr(max3421_of_match_table),
 	},
 };
 
Signature · 6 lines
2.14.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

PATCH v2 2/2 dt-bindings: max3421: Add bindings documentation

In reply to a message not in the archive

Adds bindings documentation for the max3421 driver.

---
 .../devicetree/bindings/usb/maxim,max3421.txt      | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt
Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +24 -0
new file mode 100644
index 000000000000..7536c3ab3e5a
@@ -0,0 +1,24 @@
+Maxim Integrated SPI-based USB 2.0 host controller MAX3421E
+
+Required properties:
+ - compatible: "maxim,max3421"
+ - spi-max-frequency: maximum frequency for this device must not exceed 26 MHz.
+ - reg: chip select number to which this device is connected.
+ - maxim,vbus-en-pin: <GPOUTx ACTIVE_LEVEL>
+   GPOUTx is the number (1-8) of the GPOUT pin of MAX3421E to drive Vbus.
+   ACTIVE_LEVEL is 0 or 1.
+ - interrupt-parent: the phandle of the associated interrupt controller.
+ - interrupts: the interuption line description for the interrupt controller.
+   The driver configures MAX3421E for active low level triggered interrupts,
+   configure your interrupt line accordingly.
+
+Example:
+
+	usb@0 {
+		compatible = "maxim,max3421";
+		reg = <0>;
+		maxim,vbus-en-pin = <3 1>;
+		spi-max-frequency = <26000000>;
+		interrupt-parent = <&PIC>;
+		interrupts = <42>;
+	};
Signature · 6 lines
2.14.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 832170edafa26b7b2bed76afe170f1c9c4f7b9ae.1508108927.git.jules.maselbas-l+/[email protected]

#11 lore raw

Re: [PATCH v2 2/2] dt-bindings: max3421: Add bindings documentation

Hello!

Quoted 14 lines · Jules Maselbas

Adds bindings documentation for the max3421 driver.

---
  .../devicetree/bindings/usb/maxim,max3421.txt      | 24 ++++++++++++++++++++++
  1 file changed, 24 insertions(+)

create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt

Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +0 -0
new file mode 100644
index 000000000000..7536c3ab3e5a

Documentation/devicetree/bindings/usb/maxim,max3421.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +10 -0
@@ -0,0 +1,24 @@
+Maxim Integrated SPI-based USB 2.0 host controller MAX3421E
+
+Required properties:
+ - compatible: "maxim,max3421"
+ - spi-max-frequency: maximum frequency for this device must not exceed 26 MHz.
+ - reg: chip select number to which this device is connected.
+ - maxim,vbus-en-pin: <GPOUTx ACTIVE_LEVEL>
+   GPOUTx is the number (1-8) of the GPOUT pin of MAX3421E to drive Vbus.
+   ACTIVE_LEVEL is 0 or 1.
+ - interrupt-parent: the phandle of the associated interrupt controller.

This is never a required prob, it may be inherited from the parent nodes.

Documentation/devicetree/bindings/usb/maxim,max3421.txt line 11

Quoted 1 line
Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +1 -0
+ - interrupts: the interuption line description for the interrupt controller.

Interrupt.

[...]

MBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): a064c008-2268-26ef-edee-47bda38b117b-M4DtvfQ/[email protected]

#13 lore raw

Re: [PATCH v2 2/2] dt-bindings: max3421: Add bindings documentation

Quoted 20 lines · Sergei Shtylyov
Quoted 20 lines

Adds bindings documentation for the max3421 driver.

---
  .../devicetree/bindings/usb/maxim,max3421.txt      | 24 
++++++++++++++++++++++
  1 file changed, 24 insertions(+)

create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt

Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +5 -0
new file mode 100644
index 000000000000..7536c3ab3e5a
@@ -0,0 +1,24 @@
+Maxim Integrated SPI-based USB 2.0 host controller MAX3421E
+
+Required properties:
+ - compatible: "maxim,max3421"
+ - spi-max-frequency: maximum frequency for this device must not exceed 26 
Quoted 8 lines

Documentation/devicetree/bindings/usb/maxim,max3421.txt line 10

Quoted 6 lines

MHz.
+ - reg: chip select number to which this device is connected.
+ - maxim,vbus-en-pin: <GPOUTx ACTIVE_LEVEL>

Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +3 -0
+   GPOUTx is the number (1-8) of the GPOUT pin of MAX3421E to drive Vbus.
+   ACTIVE_LEVEL is 0 or 1.
+ - interrupt-parent: the phandle of the associated interrupt controller.

This is never a required prob, it may be inherited from the parent nodes.

Prop, sorry. :-)

[...]

MBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 6a3f35f1-dae9-063d-963e-812a7341f612-M4DtvfQ/[email protected]

#15 lore raw

Re: [PATCH v2 2/2] dt-bindings: max3421: Add bindings documentation

Thanks Sergei,

Is it better if the documentation say:
"
Optional property:
- interrupt-parent: the phandle of the associated interrupt controller.
"
or should I also add that "it may be inherited from the parent nodes."?

Jules Maselbas.

----- Mail original -----
De: "Sergei Shtylyov" <sergei.shtylyov-M4DtvfQ/[email protected]>
À: "Jules Maselbas" <jules.maselbas-l+/[email protected]>, [email protected]
Cc: "julia lawall" <[email protected]>, [email protected], "mark rutland" <[email protected]>, [email protected], [email protected] Envoyé: Lundi 16 Octobre 2017 22:21:53
Objet: Re: [PATCH v2 2/2] dt-bindings: max3421: Add bindings documentation

Quoted 21 lines · Sergei Shtylyov
Quoted 21 lines

Adds bindings documentation for the max3421 driver.

---
  .../devicetree/bindings/usb/maxim,max3421.txt      | 24 
++++++++++++++++++++++
  1 file changed, 24 insertions(+)

create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt

Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +5 -0
new file mode 100644
index 000000000000..7536c3ab3e5a
@@ -0,0 +1,24 @@
+Maxim Integrated SPI-based USB 2.0 host controller MAX3421E
+
+Required properties:
+ - compatible: "maxim,max3421"
+ - spi-max-frequency: maximum frequency for this device must not exceed 26 
Quoted 8 lines

Documentation/devicetree/bindings/usb/maxim,max3421.txt line 10

Quoted 6 lines

MHz.
+ - reg: chip select number to which this device is connected.
+ - maxim,vbus-en-pin: <GPOUTx ACTIVE_LEVEL>

Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +3 -0
+   GPOUTx is the number (1-8) of the GPOUT pin of MAX3421E to drive Vbus.
+   ACTIVE_LEVEL is 0 or 1.
+ - interrupt-parent: the phandle of the associated interrupt controller.

This is never a required prob, it may be inherited from the parent nodes.

Prop, sorry. :-)

[...]

MBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1452233455.381184.1508188958452.JavaMail.zimbra-l+/[email protected]

#17 lore raw

Re: [PATCH v2 2/2] dt-bindings: max3421: Add bindings documentation

Quoted 7 lines · Jules Maselbas

Thanks Sergei,

Is it better if the documentation say:
"
Optional property:
- interrupt-parent: the phandle of the associated interrupt controller.
"

That should be enough.

Quoted 3 lines

or should I also add that "it may be inherited from the parent nodes."?

Jules Maselbas.

MBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw

Re: [PATCH v2 2/2] dt-bindings: max3421: Add bindings documentation

In reply to a message not in the archive
Quoted 7 lines · Jules Maselbas

Adds bindings documentation for the max3421 driver.

---
 .../devicetree/bindings/usb/maxim,max3421.txt      | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt

Please add acks when posting new versions.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#19 lore raw

v3 cover max3421: add devicetree support

In reply to a message not in the archive

Hi,

This patchset adds devicetree support to the max3421 driver. Theses modification are based on a previous (unapplied) patch series by Alexander Amelkin [1].

Changes in v3:
* Documentation modification, interrupt-parent is optional.

Changes in v2:
* The platform_data is no longer freed in max3421_remove() as it is allocated with devm_kzalloc.
* Removed the dev_err print if devm_kzalloc fail.
* Removed a test for platform_data null pointer in max3421_hub_control() as the driver probe will fail if no platform_data is found.

Thank you.

[1]: [https://lkml.org/lkml/2017/5/26/285]

---

Jules Maselbas (2):
usb: max3421: Add devicetree support
dt-bindings: max3421: Add bindings documentation

 .../devicetree/bindings/usb/maxim,max3421.txt      | 25 ++++++++
 drivers/usb/host/max3421-hcd.c                     | 75 +++++++++++++++++++++-
 2 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt
Signature · 6 lines
2.14.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): cover.1508798984.git.jules.maselbas-l+/[email protected]

#21 lore raw

PATCH v3 1/2 usb: max3421: Add devicetree support

Adds support for devicetree to the max3421 driver.

---
 drivers/usb/host/max3421-hcd.c | 75 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)
drivers/usb/host/max3421-hcd.c +74 -1
index 0ece9a9341e5..d77b3f27c6e7 100644
@@ -60,6 +60,7 @@
 #include <linux/spi/spi.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
+#include <linux/of.h>
 
 #include <linux/platform_data/max3421-hcd.h>
 
@@ -85,6 +86,8 @@
 			  USB_PORT_STAT_C_OVERCURRENT | \
 			  USB_PORT_STAT_C_RESET) << 16)
 
+#define MAX3421_GPOUT_COUNT	8
+
 enum max3421_rh_state {
 	MAX3421_RH_RESET,
 	MAX3421_RH_SUSPENDED,
@@ -1672,7 +1675,7 @@ max3421_gpout_set_value(struct usb_hcd *hcd, u8 pin_number, u8 value)
 	u8 mask, idx;
 
 	--pin_number;
-	if (pin_number > 7)
+	if (pin_number >= MAX3421_GPOUT_COUNT)
 		return;
 
 	mask = 1u << (pin_number % 4);
@@ -1831,11 +1834,35 @@ static const struct hc_driver max3421_hcd_desc = {
 	.bus_resume =		max3421_bus_resume,
 };
 
+static int
+max3421_of_vbus_en_pin(struct device *dev, struct max3421_hcd_platform_data *pdata)
+{
+	int retval;
+	uint32_t value[2];
+
+	if (!pdata)
+		return -EINVAL;
+
+	retval = of_property_read_u32_array(dev->of_node, "maxim,vbus-en-pin", value, 2);
+	if (retval) {
+		dev_err(dev, "device tree node property 'maxim,vbus-en-pin' is missing\n");
+		return retval;
+	}
+	dev_info(dev, "property 'maxim,vbus-en-pin' value is <%d %d>\n", value[0], value[1]);
+
+	pdata->vbus_gpout = value[0];
+	pdata->vbus_active_level = value[1];
+
+	return 0;
+}
+
 static int
 max3421_probe(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
 	struct max3421_hcd *max3421_hcd;
 	struct usb_hcd *hcd = NULL;
+	struct max3421_hcd_platform_data *pdata = NULL;
 	int retval = -ENOMEM;
 
 	if (spi_setup(spi) < 0) {
@@ -1843,6 +1870,40 @@ max3421_probe(struct spi_device *spi)
 		return -EFAULT;
 	}
 
+	if (!spi->irq) {
+		dev_err(dev, "Failed to get SPI IRQ");
+		return -EFAULT;
+	}
+
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+		pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+		if (!pdata) {
+			retval = -ENOMEM;
+			goto error;
+		}
+		retval = max3421_of_vbus_en_pin(dev, pdata);
+		if (retval)
+			goto error;
+		spi->dev.platform_data = pdata;
+	}
+
+	pdata = dev->platform_data;
+	if (!pdata) {
+		dev_err(dev, "driver configuration data is not provided\n");
+		retval = -EFAULT;
+		goto error;
+	}
+	if (pdata->vbus_active_level > 1) {
+		dev_err(dev, "vbus active level value %d is out of range (0/1)\n", pdata->vbus_active_level);
+		retval = -EINVAL;
+		goto error;
+	}
+	if (pdata->vbus_gpout < 1 || pdata->vbus_gpout > MAX3421_GPOUT_COUNT) {
+		dev_err(dev, "vbus gpout value %d is out of range (1..8)\n", pdata->vbus_gpout);
+		retval = -EINVAL;
+		goto error;
+	}
+
 	hcd = usb_create_hcd(&max3421_hcd_desc, &spi->dev,
 			     dev_name(&spi->dev));
 	if (!hcd) {
@@ -1885,6 +1946,11 @@ max3421_probe(struct spi_device *spi)
 	return 0;
 
 error:
+	if (IS_ENABLED(CONFIG_OF) && dev->of_node && pdata) {
+		devm_kfree(&spi->dev, pdata);
+		spi->dev.platform_data = NULL;
+	}
+
 	if (hcd) {
 		kfree(max3421_hcd->tx);
 		kfree(max3421_hcd->rx);
@@ -1929,11 +1995,18 @@ max3421_remove(struct spi_device *spi)
 	return 0;
 }
 
+static const struct of_device_id max3421_of_match_table[] = {
+	{ .compatible = "maxim,max3421", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, max3421_of_match_table);
+
 static struct spi_driver max3421_driver = {
 	.probe		= max3421_probe,
 	.remove		= max3421_remove,
 	.driver		= {
 		.name	= "max3421-hcd",
+		.of_match_table = of_match_ptr(max3421_of_match_table),
 	},
 };
 
Signature · 6 lines
2.14.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#22 lore raw

PATCH v3 2/2 dt-bindings: max3421: Add bindings documentation

In reply to a message not in the archive

Adds bindings documentation for the max3421 driver.

---
 .../devicetree/bindings/usb/maxim,max3421.txt      | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/maxim,max3421.txt
Documentation/devicetree/bindings/usb/maxim,max3421.txt new file +25 -0
new file mode 100644
index 000000000000..5c699e52ce3f
@@ -0,0 +1,25 @@
+Maxim Integrated SPI-based USB 2.0 host controller MAX3421E
+
+Required properties:
+ - compatible: Should be "maxim,max3421"
+ - spi-max-frequency: maximum frequency for this device must not exceed 26 MHz.
+ - reg: chip select number to which this device is connected.
+ - maxim,vbus-en-pin: <GPOUTx ACTIVE_LEVEL>
+   GPOUTx is the number (1-8) of the GPOUT pin of MAX3421E to drive Vbus.
+   ACTIVE_LEVEL is 0 or 1.
+ - interrupts: the interrupt line description for the interrupt controller.
+   The driver configures MAX3421E for active low level triggered interrupts,
+   configure your interrupt line accordingly.
+
+Optional property:
+ - interrupt-parent: the phandle to the associated interrupt controller.
+
+Example:
+	usb@0 {
+		compatible = "maxim,max3421";
+		reg = <0>;
+		maxim,vbus-en-pin = <3 1>;
+		spi-max-frequency = <26000000>;
+		interrupt-parent = <&PIC>;
+		interrupts = <42>;
+	};
Signature · 6 lines
2.14.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#23 lore raw
In reply to a message not in the archive
Quoted 5 lines · Jules Maselbas

Hi,

This patchset adds devicetree support to the max3421 driver. Theses modification are based on a previous (unapplied) patch series by Alexander Amelkin [1].

I've already applied this series, right? If there were any changes from the older patch that I applied, can you send a fix-up patch?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#25 lore raw

Yes,

The first version of this patch series was already applied (on usb-next).
I made new versions because I forgot that there are no rebase. So this is why I sent new patch.

The newest (v3) version has been split in two patch and also applied (on usb-testing).
9b796ffcd16dfaf820ecc6a9dc287e6d758a556e dt-bindings: usb: max3421: Interrupt-parent is optional 892f6ebc53ac1a12a26c21eb26d18064461a7007 usb: host: max3421-hcd: Remove pdata test in max3421_hub_control()

I am not sure, are theses patch fix-up?

Thanks,
Jules.

Quoted 10 lines · ----- Le 1 Nov 17, à 17:12, gregkh gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@publ…
Quoted 5 lines · Jules Maselbas

Hi,

This patchset adds devicetree support to the max3421 driver. Theses modification are based on a previous (unapplied) patch series by Alexander Amelkin [1].

I've already applied this series, right? If there were any changes from the older patch that I applied, can you send a fix-up patch?

Quoted 7 lines

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 2145557244.443021.1509555056126.JavaMail.zimbra-l+/[email protected]

#27 lore raw
Quoted 10 lines · Jules Maselbas

Yes,

The first version of this patch series was already applied (on usb-next).
I made new versions because I forgot that there are no rebase. So this is why I sent new patch.

The newest (v3) version has been split in two patch and also applied (on usb-testing).
9b796ffcd16dfaf820ecc6a9dc287e6d758a556e dt-bindings: usb: max3421: Interrupt-parent is optional 892f6ebc53ac1a12a26c21eb26d18064461a7007 usb: host: max3421-hcd: Remove pdata test in max3421_hub_control()

I am not sure, are theses patch fix-up?

If you are happy with all of the patches I've now taken, all is good :)

If not, please send me what needs to be applied.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html