linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops
@ 2016-08-16 16:04 Tal Shorer
  2016-08-16 16:04 ` [PATCH v3 1/8] usb: ulpi: move setting of ulpi->dev parent up in ulpi_register() Tal Shorer
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

struct ulpi_ops is defined as follows:

struct ulpi_ops {
        struct device *dev;
        int (*read)(struct ulpi_ops *ops, u8 addr);
        int (*write)(struct ulpi_ops *ops, u8 addr, u8 val);
};

Upon calling ulpi_register_interface(), the struct device argument is
put inside the struct ulpi_ops argument's dev field. Later, when
calling the actual read()/write() operations, the struct ulpi_ops is
passed to them and they use the stored device to access whatever
private data they need.

This means that if one wishes to reuse the same oprations for multiple
interfaces (e.g if we have multiple instances of the same controller),
any but the last interface registered will not operate properly (and
the one that does work will be at the mercy of the others to not mess
it up).

I understand that barely any driver uses this bus right now, but I
suppose it's there to be used at some point. We might as well fix the
design here before we hit this bug.

This series fixes this by passing the given struct device directly to
the operation functions via ulpi->dev.parent in ulpi_read() and
ulpi_write(). It also changes the operations struct to be constant
since now nobody has a reason to modify it.

Changes from v1:
 * Split the actual api change into multiple patch as per Felipe Balbi's
   suggestion. The series now first adds the new api, then migrates
   everything to use and only then removes the old api.

Changes from v2:
 * Merge patches 2 and 3 (now patch 2)
 * Merge patches 5 and 6 (now patch 4)
 * Remove comment documenting the removed dev field in struct ulpi_ops

Tal Shorer (8):
  usb: ulpi: move setting of ulpi->dev parent up in ulpi_register()
  usb: ulpi: add new api functions, {read|write}_dev()
  usb: dwc3: ulpi: use new api
  usb: ulpi: remove calls to old api callbacks
  usb: ulpi: rename operations {read|write}_dev to simply {read|write}
  usb: ulpi: remove "dev" field from struct ulpi_ops
  usb: ulpi: make ops struct constant
  usb: dwc3: ulpi: make dwc3_ulpi_ops constant

 drivers/usb/common/ulpi.c      | 11 ++++++-----
 drivers/usb/dwc3/ulpi.c        | 10 +++++-----
 include/linux/ulpi/driver.h    |  2 +-
 include/linux/ulpi/interface.h |  9 ++++-----
 4 files changed, 16 insertions(+), 16 deletions(-)

--
2.7.4

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

* [PATCH v3 1/8] usb: ulpi: move setting of ulpi->dev parent up in ulpi_register()
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:11   ` Heikki Krogerus
  2016-08-16 16:04 ` [PATCH v3 2/8] usb: ulpi: add new api functions, {read|write}_dev() Tal Shorer
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

Once ulpi operations use the parent device directly, this will be
needed during the operations used in ulpi_register() itself, so set
the parent field before calling any ulpi operations.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/common/ulpi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index e04a34e..c6ce92b 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -157,6 +157,8 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)
 {
 	int ret;
 
+	ulpi->dev.parent = dev; /* needed early for ops */
+
 	/* Test the interface */
 	ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa);
 	if (ret < 0)
@@ -175,7 +177,6 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)
 	ulpi->id.product = ulpi_read(ulpi, ULPI_PRODUCT_ID_LOW);
 	ulpi->id.product |= ulpi_read(ulpi, ULPI_PRODUCT_ID_HIGH) << 8;
 
-	ulpi->dev.parent = dev;
 	ulpi->dev.bus = &ulpi_bus;
 	ulpi->dev.type = &ulpi_dev_type;
 	dev_set_name(&ulpi->dev, "%s.ulpi", dev_name(dev));
-- 
2.7.4

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

* [PATCH v3 2/8] usb: ulpi: add new api functions, {read|write}_dev()
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
  2016-08-16 16:04 ` [PATCH v3 1/8] usb: ulpi: move setting of ulpi->dev parent up in ulpi_register() Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:11   ` Heikki Krogerus
  2016-08-16 16:04 ` [PATCH v3 3/8] usb: dwc3: ulpi: use new api Tal Shorer
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

Add these two new api callbacks to struct ulpi_ops. These are different
than read, write in that they pass the parent device directly instead
of via the ops argument.
They are intended to replace the old api functions.

If the new api callbacks are missing, revert to calling the old ones
as before.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/common/ulpi.c      | 8 ++++++--
 include/linux/ulpi/interface.h | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index c6ce92b..15e4a14 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -21,13 +21,17 @@
 
 int ulpi_read(struct ulpi *ulpi, u8 addr)
 {
-	return ulpi->ops->read(ulpi->ops, addr);
+	if (!ulpi->ops->read_dev)
+		return ulpi->ops->read(ulpi->ops, addr);
+	return ulpi->ops->read_dev(ulpi->dev.parent, addr);
 }
 EXPORT_SYMBOL_GPL(ulpi_read);
 
 int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val)
 {
-	return ulpi->ops->write(ulpi->ops, addr, val);
+	if (!ulpi->ops->write_dev)
+		return ulpi->ops->write(ulpi->ops, addr, val);
+	return ulpi->ops->write_dev(ulpi->dev.parent, addr, val);
 }
 EXPORT_SYMBOL_GPL(ulpi_write);
 
diff --git a/include/linux/ulpi/interface.h b/include/linux/ulpi/interface.h
index 4de8ab4..d8189d0 100644
--- a/include/linux/ulpi/interface.h
+++ b/include/linux/ulpi/interface.h
@@ -15,6 +15,8 @@ struct ulpi_ops {
 	struct device *dev;
 	int (*read)(struct ulpi_ops *ops, u8 addr);
 	int (*write)(struct ulpi_ops *ops, u8 addr, u8 val);
+	int (*read_dev)(struct device *dev, u8 addr);
+	int (*write_dev)(struct device *dev, u8 addr, u8 val);
 };
 
 struct ulpi *ulpi_register_interface(struct device *, struct ulpi_ops *);
-- 
2.7.4

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

* [PATCH v3 3/8] usb: dwc3: ulpi: use new api
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
  2016-08-16 16:04 ` [PATCH v3 1/8] usb: ulpi: move setting of ulpi->dev parent up in ulpi_register() Tal Shorer
  2016-08-16 16:04 ` [PATCH v3 2/8] usb: ulpi: add new api functions, {read|write}_dev() Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:14   ` Heikki Krogerus
  2016-08-16 16:04 ` [PATCH v3 4/8] usb: ulpi: remove calls to old api callbacks Tal Shorer
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

The old read, write callbacks in struct ulpi_ops have been deprecated
in favor of new callbacks that pass the parent device directly.
Replace the used callbacks in dwc3's ulpi component with the new api.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/dwc3/ulpi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc3/ulpi.c b/drivers/usb/dwc3/ulpi.c
index ec004c6..94eeb7a 100644
--- a/drivers/usb/dwc3/ulpi.c
+++ b/drivers/usb/dwc3/ulpi.c
@@ -35,9 +35,9 @@ static int dwc3_ulpi_busyloop(struct dwc3 *dwc)
 	return -ETIMEDOUT;
 }
 
-static int dwc3_ulpi_read(struct ulpi_ops *ops, u8 addr)
+static int dwc3_ulpi_read(struct device *dev, u8 addr)
 {
-	struct dwc3 *dwc = dev_get_drvdata(ops->dev);
+	struct dwc3 *dwc = dev_get_drvdata(dev);
 	u32 reg;
 	int ret;
 
@@ -53,9 +53,9 @@ static int dwc3_ulpi_read(struct ulpi_ops *ops, u8 addr)
 	return DWC3_GUSB2PHYACC_DATA(reg);
 }
 
-static int dwc3_ulpi_write(struct ulpi_ops *ops, u8 addr, u8 val)
+static int dwc3_ulpi_write(struct device *dev, u8 addr, u8 val)
 {
-	struct dwc3 *dwc = dev_get_drvdata(ops->dev);
+	struct dwc3 *dwc = dev_get_drvdata(dev);
 	u32 reg;
 
 	reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr);
@@ -66,8 +66,8 @@ static int dwc3_ulpi_write(struct ulpi_ops *ops, u8 addr, u8 val)
 }
 
 static struct ulpi_ops dwc3_ulpi_ops = {
-	.read = dwc3_ulpi_read,
-	.write = dwc3_ulpi_write,
+	.read_dev = dwc3_ulpi_read,
+	.write_dev = dwc3_ulpi_write,
 };
 
 int dwc3_ulpi_init(struct dwc3 *dwc)
-- 
2.7.4

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

* [PATCH v3 4/8] usb: ulpi: remove calls to old api callbacks
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
                   ` (2 preceding siblings ...)
  2016-08-16 16:04 ` [PATCH v3 3/8] usb: dwc3: ulpi: use new api Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:14   ` Heikki Krogerus
  2016-08-16 16:04 ` [PATCH v3 5/8] usb: ulpi: rename operations {read|write}_dev to simply {read|write} Tal Shorer
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

Now that all users use the new api callbacks, remove the old api
callbacks and force new interface drivers to use the new api.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/common/ulpi.c      | 4 ----
 include/linux/ulpi/interface.h | 2 --
 2 files changed, 6 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index 15e4a14..d682cf2 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -21,16 +21,12 @@
 
 int ulpi_read(struct ulpi *ulpi, u8 addr)
 {
-	if (!ulpi->ops->read_dev)
-		return ulpi->ops->read(ulpi->ops, addr);
 	return ulpi->ops->read_dev(ulpi->dev.parent, addr);
 }
 EXPORT_SYMBOL_GPL(ulpi_read);
 
 int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val)
 {
-	if (!ulpi->ops->write_dev)
-		return ulpi->ops->write(ulpi->ops, addr, val);
 	return ulpi->ops->write_dev(ulpi->dev.parent, addr, val);
 }
 EXPORT_SYMBOL_GPL(ulpi_write);
diff --git a/include/linux/ulpi/interface.h b/include/linux/ulpi/interface.h
index d8189d0..71f3c99 100644
--- a/include/linux/ulpi/interface.h
+++ b/include/linux/ulpi/interface.h
@@ -13,8 +13,6 @@ struct ulpi;
  */
 struct ulpi_ops {
 	struct device *dev;
-	int (*read)(struct ulpi_ops *ops, u8 addr);
-	int (*write)(struct ulpi_ops *ops, u8 addr, u8 val);
 	int (*read_dev)(struct device *dev, u8 addr);
 	int (*write_dev)(struct device *dev, u8 addr, u8 val);
 };
-- 
2.7.4

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

* [PATCH v3 5/8] usb: ulpi: rename operations {read|write}_dev to simply {read|write}
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
                   ` (3 preceding siblings ...)
  2016-08-16 16:04 ` [PATCH v3 4/8] usb: ulpi: remove calls to old api callbacks Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:15   ` Heikki Krogerus
  2016-08-16 16:04 ` [PATCH v3 6/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

With the removal of the old {read|write} operations, we can now safely
rename the new api operations {read|write}_dev to use the shorter and
clearer names {read|write}, respectively.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/common/ulpi.c      | 4 ++--
 drivers/usb/dwc3/ulpi.c        | 4 ++--
 include/linux/ulpi/interface.h | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index d682cf2..da17a74 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -21,13 +21,13 @@
 
 int ulpi_read(struct ulpi *ulpi, u8 addr)
 {
-	return ulpi->ops->read_dev(ulpi->dev.parent, addr);
+	return ulpi->ops->read(ulpi->dev.parent, addr);
 }
 EXPORT_SYMBOL_GPL(ulpi_read);
 
 int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val)
 {
-	return ulpi->ops->write_dev(ulpi->dev.parent, addr, val);
+	return ulpi->ops->write(ulpi->dev.parent, addr, val);
 }
 EXPORT_SYMBOL_GPL(ulpi_write);
 
diff --git a/drivers/usb/dwc3/ulpi.c b/drivers/usb/dwc3/ulpi.c
index 94eeb7a..51ac939 100644
--- a/drivers/usb/dwc3/ulpi.c
+++ b/drivers/usb/dwc3/ulpi.c
@@ -66,8 +66,8 @@ static int dwc3_ulpi_write(struct device *dev, u8 addr, u8 val)
 }
 
 static struct ulpi_ops dwc3_ulpi_ops = {
-	.read_dev = dwc3_ulpi_read,
-	.write_dev = dwc3_ulpi_write,
+	.read = dwc3_ulpi_read,
+	.write = dwc3_ulpi_write,
 };
 
 int dwc3_ulpi_init(struct dwc3 *dwc)
diff --git a/include/linux/ulpi/interface.h b/include/linux/ulpi/interface.h
index 71f3c99..ac3cd80 100644
--- a/include/linux/ulpi/interface.h
+++ b/include/linux/ulpi/interface.h
@@ -13,8 +13,8 @@ struct ulpi;
  */
 struct ulpi_ops {
 	struct device *dev;
-	int (*read_dev)(struct device *dev, u8 addr);
-	int (*write_dev)(struct device *dev, u8 addr, u8 val);
+	int (*read)(struct device *dev, u8 addr);
+	int (*write)(struct device *dev, u8 addr, u8 val);
 };
 
 struct ulpi *ulpi_register_interface(struct device *, struct ulpi_ops *);
-- 
2.7.4

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

* [PATCH v3 6/8] usb: ulpi: remove "dev" field from struct ulpi_ops
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
                   ` (4 preceding siblings ...)
  2016-08-16 16:04 ` [PATCH v3 5/8] usb: ulpi: rename operations {read|write}_dev to simply {read|write} Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:15   ` Heikki Krogerus
  2016-08-16 16:04 ` [PATCH v3 7/8] usb: ulpi: make ops struct constant Tal Shorer
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

Operations now use ulpi->dev.parent directly instead of via the
ulpi_ops struct, making this field unused. Remove it.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/common/ulpi.c      | 1 -
 include/linux/ulpi/interface.h | 3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index da17a74..d005c15 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -213,7 +213,6 @@ struct ulpi *ulpi_register_interface(struct device *dev, struct ulpi_ops *ops)
 		return ERR_PTR(-ENOMEM);
 
 	ulpi->ops = ops;
-	ops->dev = dev;
 
 	ret = ulpi_register(dev, ulpi);
 	if (ret) {
diff --git a/include/linux/ulpi/interface.h b/include/linux/ulpi/interface.h
index ac3cd80..cdedac8 100644
--- a/include/linux/ulpi/interface.h
+++ b/include/linux/ulpi/interface.h
@@ -4,15 +4,14 @@
 #include <linux/types.h>
 
 struct ulpi;
+struct device;
 
 /**
  * struct ulpi_ops - ULPI register access
- * @dev: the interface provider
  * @read: read operation for ULPI register access
  * @write: write operation for ULPI register access
  */
 struct ulpi_ops {
-	struct device *dev;
 	int (*read)(struct device *dev, u8 addr);
 	int (*write)(struct device *dev, u8 addr, u8 val);
 };
-- 
2.7.4

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

* [PATCH v3 7/8] usb: ulpi: make ops struct constant
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
                   ` (5 preceding siblings ...)
  2016-08-16 16:04 ` [PATCH v3 6/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:16   ` Heikki Krogerus
  2016-08-16 16:04 ` [PATCH v3 8/8] usb: dwc3: ulpi: make dwc3_ulpi_ops constant Tal Shorer
  2016-08-29  7:58 ` [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Felipe Balbi
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

None of the core ulpi functions perform any changes to the operations
struct, and logically as a struct that contains function pointers
there's no reason it shouldn't be constant.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/common/ulpi.c      | 3 ++-
 include/linux/ulpi/driver.h    | 2 +-
 include/linux/ulpi/interface.h | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index d005c15..8b31770 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -203,7 +203,8 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi)
  * Allocates and registers a ULPI device and an interface for it. Called from
  * the USB controller that provides the ULPI interface.
  */
-struct ulpi *ulpi_register_interface(struct device *dev, struct ulpi_ops *ops)
+struct ulpi *ulpi_register_interface(struct device *dev,
+				     const struct ulpi_ops *ops)
 {
 	struct ulpi *ulpi;
 	int ret;
diff --git a/include/linux/ulpi/driver.h b/include/linux/ulpi/driver.h
index 80b36ca..a7af21a 100644
--- a/include/linux/ulpi/driver.h
+++ b/include/linux/ulpi/driver.h
@@ -15,7 +15,7 @@ struct ulpi_ops;
  */
 struct ulpi {
 	struct ulpi_device_id id;
-	struct ulpi_ops *ops;
+	const struct ulpi_ops *ops;
 	struct device dev;
 };
 
diff --git a/include/linux/ulpi/interface.h b/include/linux/ulpi/interface.h
index cdedac8..a2011a9 100644
--- a/include/linux/ulpi/interface.h
+++ b/include/linux/ulpi/interface.h
@@ -16,7 +16,7 @@ struct ulpi_ops {
 	int (*write)(struct device *dev, u8 addr, u8 val);
 };
 
-struct ulpi *ulpi_register_interface(struct device *, struct ulpi_ops *);
+struct ulpi *ulpi_register_interface(struct device *, const struct ulpi_ops *);
 void ulpi_unregister_interface(struct ulpi *);
 
 #endif /* __LINUX_ULPI_INTERFACE_H */
-- 
2.7.4

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

* [PATCH v3 8/8] usb: dwc3: ulpi: make dwc3_ulpi_ops constant
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
                   ` (6 preceding siblings ...)
  2016-08-16 16:04 ` [PATCH v3 7/8] usb: ulpi: make ops struct constant Tal Shorer
@ 2016-08-16 16:04 ` Tal Shorer
  2016-08-17 11:17   ` Heikki Krogerus
  2016-08-29  7:58 ` [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Felipe Balbi
  8 siblings, 1 reply; 19+ messages in thread
From: Tal Shorer @ 2016-08-16 16:04 UTC (permalink / raw)
  To: gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, balbi, Tal Shorer

ulpi_register_interface() accepts a const struct ulpi_ops and dwc3
doesn't perform any changes to this struct at runtime, so there's no
reason it shouldn't be constant.

Signed-off-by: Tal Shorer <tal.shorer@gmail.com>
---
 drivers/usb/dwc3/ulpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/ulpi.c b/drivers/usb/dwc3/ulpi.c
index 51ac939..bd86f84 100644
--- a/drivers/usb/dwc3/ulpi.c
+++ b/drivers/usb/dwc3/ulpi.c
@@ -65,7 +65,7 @@ static int dwc3_ulpi_write(struct device *dev, u8 addr, u8 val)
 	return dwc3_ulpi_busyloop(dwc);
 }
 
-static struct ulpi_ops dwc3_ulpi_ops = {
+static const struct ulpi_ops dwc3_ulpi_ops = {
 	.read = dwc3_ulpi_read,
 	.write = dwc3_ulpi_write,
 };
-- 
2.7.4

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

* Re: [PATCH v3 1/8] usb: ulpi: move setting of ulpi->dev parent up in ulpi_register()
  2016-08-16 16:04 ` [PATCH v3 1/8] usb: ulpi: move setting of ulpi->dev parent up in ulpi_register() Tal Shorer
@ 2016-08-17 11:11   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:11 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:46PM +0300, Tal Shorer wrote:
> Once ulpi operations use the parent device directly, this will be
> needed during the operations used in ulpi_register() itself, so set
> the parent field before calling any ulpi operations.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 2/8] usb: ulpi: add new api functions, {read|write}_dev()
  2016-08-16 16:04 ` [PATCH v3 2/8] usb: ulpi: add new api functions, {read|write}_dev() Tal Shorer
@ 2016-08-17 11:11   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:11 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:47PM +0300, Tal Shorer wrote:
> Add these two new api callbacks to struct ulpi_ops. These are different
> than read, write in that they pass the parent device directly instead
> of via the ops argument.
> They are intended to replace the old api functions.
> 
> If the new api callbacks are missing, revert to calling the old ones
> as before.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 3/8] usb: dwc3: ulpi: use new api
  2016-08-16 16:04 ` [PATCH v3 3/8] usb: dwc3: ulpi: use new api Tal Shorer
@ 2016-08-17 11:14   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:14 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:48PM +0300, Tal Shorer wrote:
> The old read, write callbacks in struct ulpi_ops have been deprecated
> in favor of new callbacks that pass the parent device directly.
> Replace the used callbacks in dwc3's ulpi component with the new api.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 4/8] usb: ulpi: remove calls to old api callbacks
  2016-08-16 16:04 ` [PATCH v3 4/8] usb: ulpi: remove calls to old api callbacks Tal Shorer
@ 2016-08-17 11:14   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:14 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:49PM +0300, Tal Shorer wrote:
> Now that all users use the new api callbacks, remove the old api
> callbacks and force new interface drivers to use the new api.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 5/8] usb: ulpi: rename operations {read|write}_dev to simply {read|write}
  2016-08-16 16:04 ` [PATCH v3 5/8] usb: ulpi: rename operations {read|write}_dev to simply {read|write} Tal Shorer
@ 2016-08-17 11:15   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:15 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:50PM +0300, Tal Shorer wrote:
> With the removal of the old {read|write} operations, we can now safely
> rename the new api operations {read|write}_dev to use the shorter and
> clearer names {read|write}, respectively.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 6/8] usb: ulpi: remove "dev" field from struct ulpi_ops
  2016-08-16 16:04 ` [PATCH v3 6/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
@ 2016-08-17 11:15   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:15 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:51PM +0300, Tal Shorer wrote:
> Operations now use ulpi->dev.parent directly instead of via the
> ulpi_ops struct, making this field unused. Remove it.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 7/8] usb: ulpi: make ops struct constant
  2016-08-16 16:04 ` [PATCH v3 7/8] usb: ulpi: make ops struct constant Tal Shorer
@ 2016-08-17 11:16   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:16 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:52PM +0300, Tal Shorer wrote:
> None of the core ulpi functions perform any changes to the operations
> struct, and logically as a struct that contains function pointers
> there's no reason it shouldn't be constant.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 8/8] usb: dwc3: ulpi: make dwc3_ulpi_ops constant
  2016-08-16 16:04 ` [PATCH v3 8/8] usb: dwc3: ulpi: make dwc3_ulpi_ops constant Tal Shorer
@ 2016-08-17 11:17   ` Heikki Krogerus
  0 siblings, 0 replies; 19+ messages in thread
From: Heikki Krogerus @ 2016-08-17 11:17 UTC (permalink / raw)
  To: Tal Shorer; +Cc: gregkh, linux-usb, linux-kernel, balbi

On Tue, Aug 16, 2016 at 07:04:53PM +0300, Tal Shorer wrote:
> ulpi_register_interface() accepts a const struct ulpi_ops and dwc3
> doesn't perform any changes to this struct at runtime, so there's no
> reason it shouldn't be constant.
> 
> Signed-off-by: Tal Shorer <tal.shorer@gmail.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

Thanks,

-- 
heikki

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

* Re: [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops
  2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
                   ` (7 preceding siblings ...)
  2016-08-16 16:04 ` [PATCH v3 8/8] usb: dwc3: ulpi: make dwc3_ulpi_ops constant Tal Shorer
@ 2016-08-29  7:58 ` Felipe Balbi
  2016-08-29 11:15   ` Greg KH
  8 siblings, 1 reply; 19+ messages in thread
From: Felipe Balbi @ 2016-08-29  7:58 UTC (permalink / raw)
  To: Tal Shorer, gregkh, linux-usb, heikki.krogerus; +Cc: linux-kernel, Tal Shorer

[-- Attachment #1: Type: text/plain, Size: 2423 bytes --]


Hi folks,

Tal Shorer <tal.shorer@gmail.com> writes:
> struct ulpi_ops is defined as follows:
>
> struct ulpi_ops {
>         struct device *dev;
>         int (*read)(struct ulpi_ops *ops, u8 addr);
>         int (*write)(struct ulpi_ops *ops, u8 addr, u8 val);
> };
>
> Upon calling ulpi_register_interface(), the struct device argument is
> put inside the struct ulpi_ops argument's dev field. Later, when
> calling the actual read()/write() operations, the struct ulpi_ops is
> passed to them and they use the stored device to access whatever
> private data they need.
>
> This means that if one wishes to reuse the same oprations for multiple
> interfaces (e.g if we have multiple instances of the same controller),
> any but the last interface registered will not operate properly (and
> the one that does work will be at the mercy of the others to not mess
> it up).
>
> I understand that barely any driver uses this bus right now, but I
> suppose it's there to be used at some point. We might as well fix the
> design here before we hit this bug.
>
> This series fixes this by passing the given struct device directly to
> the operation functions via ulpi->dev.parent in ulpi_read() and
> ulpi_write(). It also changes the operations struct to be constant
> since now nobody has a reason to modify it.
>
> Changes from v1:
>  * Split the actual api change into multiple patch as per Felipe Balbi's
>    suggestion. The series now first adds the new api, then migrates
>    everything to use and only then removes the old api.
>
> Changes from v2:
>  * Merge patches 2 and 3 (now patch 2)
>  * Merge patches 5 and 6 (now patch 4)
>  * Remove comment documenting the removed dev field in struct ulpi_ops
>
> Tal Shorer (8):
>   usb: ulpi: move setting of ulpi->dev parent up in ulpi_register()
>   usb: ulpi: add new api functions, {read|write}_dev()
>   usb: dwc3: ulpi: use new api
>   usb: ulpi: remove calls to old api callbacks
>   usb: ulpi: rename operations {read|write}_dev to simply {read|write}
>   usb: ulpi: remove "dev" field from struct ulpi_ops
>   usb: ulpi: make ops struct constant
>   usb: dwc3: ulpi: make dwc3_ulpi_ops constant

I have no idea how to apply these :-) Many of the patches touch dwc3,
but some touch common ulpi. Greg, is it okay if I take the entire series
and send it to you during my for-next pull request?

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]

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

* Re: [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops
  2016-08-29  7:58 ` [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Felipe Balbi
@ 2016-08-29 11:15   ` Greg KH
  0 siblings, 0 replies; 19+ messages in thread
From: Greg KH @ 2016-08-29 11:15 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Tal Shorer, linux-usb, heikki.krogerus, linux-kernel

On Mon, Aug 29, 2016 at 10:58:25AM +0300, Felipe Balbi wrote:
> 
> Hi folks,
> 
> Tal Shorer <tal.shorer@gmail.com> writes:
> > struct ulpi_ops is defined as follows:
> >
> > struct ulpi_ops {
> >         struct device *dev;
> >         int (*read)(struct ulpi_ops *ops, u8 addr);
> >         int (*write)(struct ulpi_ops *ops, u8 addr, u8 val);
> > };
> >
> > Upon calling ulpi_register_interface(), the struct device argument is
> > put inside the struct ulpi_ops argument's dev field. Later, when
> > calling the actual read()/write() operations, the struct ulpi_ops is
> > passed to them and they use the stored device to access whatever
> > private data they need.
> >
> > This means that if one wishes to reuse the same oprations for multiple
> > interfaces (e.g if we have multiple instances of the same controller),
> > any but the last interface registered will not operate properly (and
> > the one that does work will be at the mercy of the others to not mess
> > it up).
> >
> > I understand that barely any driver uses this bus right now, but I
> > suppose it's there to be used at some point. We might as well fix the
> > design here before we hit this bug.
> >
> > This series fixes this by passing the given struct device directly to
> > the operation functions via ulpi->dev.parent in ulpi_read() and
> > ulpi_write(). It also changes the operations struct to be constant
> > since now nobody has a reason to modify it.
> >
> > Changes from v1:
> >  * Split the actual api change into multiple patch as per Felipe Balbi's
> >    suggestion. The series now first adds the new api, then migrates
> >    everything to use and only then removes the old api.
> >
> > Changes from v2:
> >  * Merge patches 2 and 3 (now patch 2)
> >  * Merge patches 5 and 6 (now patch 4)
> >  * Remove comment documenting the removed dev field in struct ulpi_ops
> >
> > Tal Shorer (8):
> >   usb: ulpi: move setting of ulpi->dev parent up in ulpi_register()
> >   usb: ulpi: add new api functions, {read|write}_dev()
> >   usb: dwc3: ulpi: use new api
> >   usb: ulpi: remove calls to old api callbacks
> >   usb: ulpi: rename operations {read|write}_dev to simply {read|write}
> >   usb: ulpi: remove "dev" field from struct ulpi_ops
> >   usb: ulpi: make ops struct constant
> >   usb: dwc3: ulpi: make dwc3_ulpi_ops constant
> 
> I have no idea how to apply these :-) Many of the patches touch dwc3,
> but some touch common ulpi. Greg, is it okay if I take the entire series
> and send it to you during my for-next pull request?

Sure, that works for me.

greg k-h

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

end of thread, other threads:[~2016-08-29 11:14 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-16 16:04 [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
2016-08-16 16:04 ` [PATCH v3 1/8] usb: ulpi: move setting of ulpi->dev parent up in ulpi_register() Tal Shorer
2016-08-17 11:11   ` Heikki Krogerus
2016-08-16 16:04 ` [PATCH v3 2/8] usb: ulpi: add new api functions, {read|write}_dev() Tal Shorer
2016-08-17 11:11   ` Heikki Krogerus
2016-08-16 16:04 ` [PATCH v3 3/8] usb: dwc3: ulpi: use new api Tal Shorer
2016-08-17 11:14   ` Heikki Krogerus
2016-08-16 16:04 ` [PATCH v3 4/8] usb: ulpi: remove calls to old api callbacks Tal Shorer
2016-08-17 11:14   ` Heikki Krogerus
2016-08-16 16:04 ` [PATCH v3 5/8] usb: ulpi: rename operations {read|write}_dev to simply {read|write} Tal Shorer
2016-08-17 11:15   ` Heikki Krogerus
2016-08-16 16:04 ` [PATCH v3 6/8] usb: ulpi: remove "dev" field from struct ulpi_ops Tal Shorer
2016-08-17 11:15   ` Heikki Krogerus
2016-08-16 16:04 ` [PATCH v3 7/8] usb: ulpi: make ops struct constant Tal Shorer
2016-08-17 11:16   ` Heikki Krogerus
2016-08-16 16:04 ` [PATCH v3 8/8] usb: dwc3: ulpi: make dwc3_ulpi_ops constant Tal Shorer
2016-08-17 11:17   ` Heikki Krogerus
2016-08-29  7:58 ` [PATCH v3 0/8] usb: ulpi: remove "dev" field from struct ulpi_ops Felipe Balbi
2016-08-29 11:15   ` Greg KH

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).