Skip to contentSkip to conversation

usb: isp1760: extend support for isp1763

PATCH In review Rui Miguel Silva 4 participants 15 messages May 13, 2021 – Aug 20, 2021

Subsystems (4)
lore
Share & tools
lore

Rui Miguel Silva

author maintainer
#0 lore raw

v4 cover usb: isp1760: extend support for isp1763

The Arm MPS3 FPGA prototyping board [0] have an isp1763 [1] as USB controller. There is already support for the isp1760 and isp1761 in tree, this series extend the support also for the isp1763.

Move register access using regmap, remove some platform data and code, refactor the mempool, use dr_mode to align to existing bindings, then add the support for isp1763 host mode, add bindings files that did not existed and at the end add also support for peripheral mode for isp1763.

@Laurent and @Sebastian, I add both of you in the bindings files as maintainers (it is a mandatory field)since you were the ones which contributed with the initial code and peripheral code, let me know if you are ok with it. If yes I may send a follow up to add also entries in MAINTAINERS file that it is also missing.

v3 [4] -> v4:
Rob Herring (bindings):
- add device controller interrupt
- correct additionalProperties field

v2 [3] -> v3:
kernel test bot:
- add select REGMAP_MMIO

v1 [2] -> v2:

kernel test robot:
- add two patches (1/9 and 3/9) to fix dozens of pre-existing sparse warnings so that this series does not introduce new ones. No sparse warning left.
- fix duplication of regmap fields

Laurent:
- move initializers from .h to .c
- change interrupt registers setup from field to one shot register setting (did not change hcd hw mode init because I think it did not make the difference and even avoid artifact around setting twice the register)

Rob test bot:
- fix suffix at compatible string to clean up warning in bindings

Cheers,
Rui

[0]: https://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps3
[1]: https://media.digikey.com/pdf/Data%20Sheets/ST%20Ericsson%20PDFs/ISP1763A.pdf
[2]: https://lore.kernel.org/linux-devicetree/[email protected]/
[3]: https://lore.kernel.org/linux-usb/[email protected]/
[4]: https://lore.kernel.org/linux-usb/[email protected]/

Rui Miguel Silva (9):
usb: isp1760: fix strict typechecking
usb: isp1760: move to regmap for register access
usb: isp1760: use relaxed primitives
usb: isp1760: remove platform data struct and code
usb: isp1760: hcd: refactor mempool config and setup
usb: isp1760: use dr_mode binding
usb: isp1760: add support for isp1763
dt-bindings: usb: nxp,isp1760: add bindings
usb: isp1763: add peripheral mode

 .../devicetree/bindings/usb/nxp,isp1760.yaml  |   69 ++
 arch/arm/boot/dts/arm-realview-eb.dtsi        |    2 +-
 arch/arm/boot/dts/arm-realview-pb1176.dts     |    2 +-
 arch/arm/boot/dts/arm-realview-pb11mp.dts     |    2 +-
 arch/arm/boot/dts/arm-realview-pbx.dtsi       |    2 +-
 arch/arm/boot/dts/vexpress-v2m-rs1.dtsi       |    2 +-
 arch/arm/boot/dts/vexpress-v2m.dtsi           |    2 +-
 drivers/usb/isp1760/Kconfig                   |    5 +-
 drivers/usb/isp1760/isp1760-core.c            |  513 ++++++++-
 drivers/usb/isp1760/isp1760-core.h            |   44 +-
 drivers/usb/isp1760/isp1760-hcd.c             | 1021 ++++++++++++-----
 drivers/usb/isp1760/isp1760-hcd.h             |   57 +-
 drivers/usb/isp1760/isp1760-if.c              |   41 +-
 drivers/usb/isp1760/isp1760-regs.h            |  435 ++++---
 drivers/usb/isp1760/isp1760-udc.c             |  250 ++--
 drivers/usb/isp1760/isp1760-udc.h             |   13 +-
 include/linux/usb/isp1760.h                   |   19 -
 17 files changed, 1769 insertions(+), 710 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/nxp,isp1760.yaml
 delete mode 100644 include/linux/usb/isp1760.h
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH v4 1/9 usb: isp1760: fix strict typechecking

There are a lot of pre-existing typechecking warnings around the access and assign of elements of ptd structure of __dw type.

sparse: warning: invalid assignment: |=
sparse:    left side has type restricted __dw
sparse:    right side has type unsigned int

or

warning: restricted __dw degrades to integer

or

sparse: warning: incorrect type in assignment (different base types)
sparse:    expected restricted __dw [usertype] dw4
sparse:    got unsigned int [assigned] [usertype] usof

To handle this, annotate conversions along the {TO,FROM}_DW* macros and some assignments and function arguments.

This clean up completely all sparse warnings for this driver.

---
 drivers/usb/isp1760/isp1760-hcd.c | 92 ++++++++++++++++---------------
 1 file changed, 47 insertions(+), 45 deletions(-)
drivers/usb/isp1760/isp1760-hcd.c +47 -45
index 33ae656c4b68..0e0a4b01c710 100644
@@ -66,44 +66,46 @@ struct ptd {
 #define ATL_PTD_OFFSET		0x0c00
 #define PAYLOAD_OFFSET		0x1000
 
-
-/* ATL */
-/* DW0 */
-#define DW0_VALID_BIT			1
-#define FROM_DW0_VALID(x)		((x) & 0x01)
-#define TO_DW0_LENGTH(x)		(((u32) x) << 3)
-#define TO_DW0_MAXPACKET(x)		(((u32) x) << 18)
-#define TO_DW0_MULTI(x)			(((u32) x) << 29)
-#define TO_DW0_ENDPOINT(x)		(((u32)	x) << 31)
+#define TO_DW(x)	((__force __dw)x)
+#define TO_U32(x)	((__force u32)x)
+
+ /* ATL */
+ /* DW0 */
+#define DW0_VALID_BIT			TO_DW(1)
+#define FROM_DW0_VALID(x)		(TO_U32(x) & 0x01)
+#define TO_DW0_LENGTH(x)		TO_DW((((u32)x) << 3))
+#define TO_DW0_MAXPACKET(x)		TO_DW((((u32)x) << 18))
+#define TO_DW0_MULTI(x)			TO_DW((((u32)x) << 29))
+#define TO_DW0_ENDPOINT(x)		TO_DW((((u32)x) << 31))
 /* DW1 */
-#define TO_DW1_DEVICE_ADDR(x)		(((u32) x) << 3)
-#define TO_DW1_PID_TOKEN(x)		(((u32) x) << 10)
-#define DW1_TRANS_BULK			((u32) 2 << 12)
-#define DW1_TRANS_INT			((u32) 3 << 12)
-#define DW1_TRANS_SPLIT			((u32) 1 << 14)
-#define DW1_SE_USB_LOSPEED		((u32) 2 << 16)
-#define TO_DW1_PORT_NUM(x)		(((u32) x) << 18)
-#define TO_DW1_HUB_NUM(x)		(((u32) x) << 25)
+#define TO_DW1_DEVICE_ADDR(x)		TO_DW((((u32)x) << 3))
+#define TO_DW1_PID_TOKEN(x)		TO_DW((((u32)x) << 10))
+#define DW1_TRANS_BULK			TO_DW(((u32)2 << 12))
+#define DW1_TRANS_INT			TO_DW(((u32)3 << 12))
+#define DW1_TRANS_SPLIT			TO_DW(((u32)1 << 14))
+#define DW1_SE_USB_LOSPEED		TO_DW(((u32)2 << 16))
+#define TO_DW1_PORT_NUM(x)		TO_DW((((u32)x) << 18))
+#define TO_DW1_HUB_NUM(x)		TO_DW((((u32)x) << 25))
 /* DW2 */
-#define TO_DW2_DATA_START_ADDR(x)	(((u32) x) << 8)
-#define TO_DW2_RL(x)			((x) << 25)
-#define FROM_DW2_RL(x)			(((x) >> 25) & 0xf)
+#define TO_DW2_DATA_START_ADDR(x)	TO_DW((((u32)x) << 8))
+#define TO_DW2_RL(x)			TO_DW(((x) << 25))
+#define FROM_DW2_RL(x)			((TO_U32(x) >> 25) & 0xf)
 /* DW3 */
-#define FROM_DW3_NRBYTESTRANSFERRED(x)		((x) & 0x7fff)
-#define FROM_DW3_SCS_NRBYTESTRANSFERRED(x)	((x) & 0x07ff)
-#define TO_DW3_NAKCOUNT(x)		((x) << 19)
-#define FROM_DW3_NAKCOUNT(x)		(((x) >> 19) & 0xf)
-#define TO_DW3_CERR(x)			((x) << 23)
-#define FROM_DW3_CERR(x)		(((x) >> 23) & 0x3)
-#define TO_DW3_DATA_TOGGLE(x)		((x) << 25)
-#define FROM_DW3_DATA_TOGGLE(x)		(((x) >> 25) & 0x1)
-#define TO_DW3_PING(x)			((x) << 26)
-#define FROM_DW3_PING(x)		(((x) >> 26) & 0x1)
-#define DW3_ERROR_BIT			(1 << 28)
-#define DW3_BABBLE_BIT			(1 << 29)
-#define DW3_HALT_BIT			(1 << 30)
-#define DW3_ACTIVE_BIT			(1 << 31)
-#define FROM_DW3_ACTIVE(x)		(((x) >> 31) & 0x01)
+#define FROM_DW3_NRBYTESTRANSFERRED(x)		TO_U32((x) & 0x7fff)
+#define FROM_DW3_SCS_NRBYTESTRANSFERRED(x)	TO_U32((x) & 0x07ff)
+#define TO_DW3_NAKCOUNT(x)		TO_DW(((x) << 19))
+#define FROM_DW3_NAKCOUNT(x)		((TO_U32(x) >> 19) & 0xf)
+#define TO_DW3_CERR(x)			TO_DW(((x) << 23))
+#define FROM_DW3_CERR(x)		((TO_U32(x) >> 23) & 0x3)
+#define TO_DW3_DATA_TOGGLE(x)		TO_DW(((x) << 25))
+#define FROM_DW3_DATA_TOGGLE(x)		((TO_U32(x) >> 25) & 0x1)
+#define TO_DW3_PING(x)			TO_DW(((x) << 26))
+#define FROM_DW3_PING(x)		((TO_U32(x) >> 26) & 0x1)
+#define DW3_ERROR_BIT			TO_DW((1 << 28))
+#define DW3_BABBLE_BIT			TO_DW((1 << 29))
+#define DW3_HALT_BIT			TO_DW((1 << 30))
+#define DW3_ACTIVE_BIT			TO_DW((1 << 31))
+#define FROM_DW3_ACTIVE(x)		((TO_U32(x) >> 31) & 0x01)
 
 #define INT_UNDERRUN			(1 << 2)
 #define INT_BABBLE			(1 << 1)
@@ -292,12 +294,12 @@ static void ptd_write(void __iomem *base, u32 ptd_offset, u32 slot,
 								struct ptd *ptd)
 {
 	mem_writes8(base, ptd_offset + slot*sizeof(*ptd) + sizeof(ptd->dw0),
-						&ptd->dw1, 7*sizeof(ptd->dw1));
+		    (__force u32 *)&ptd->dw1, 7 * sizeof(ptd->dw1));
 	/* Make sure dw0 gets written last (after other dw's and after payload)
 	   since it contains the enable bit */
 	wmb();
-	mem_writes8(base, ptd_offset + slot*sizeof(*ptd), &ptd->dw0,
-							sizeof(ptd->dw0));
+	mem_writes8(base, ptd_offset + slot * sizeof(*ptd),
+		    (__force u32 *)&ptd->dw0, sizeof(ptd->dw0));
 }
 
 
@@ -553,7 +555,7 @@ static void create_ptd_atl(struct isp1760_qh *qh,
 	ptd->dw0 |= TO_DW0_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe));
 
 	/* DW1 */
-	ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1;
+	ptd->dw1 = TO_DW((usb_pipeendpoint(qtd->urb->pipe) >> 1));
 	ptd->dw1 |= TO_DW1_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe));
 	ptd->dw1 |= TO_DW1_PID_TOKEN(qtd->packet_type);
 
@@ -575,7 +577,7 @@ static void create_ptd_atl(struct isp1760_qh *qh,
 		/* SE bit for Split INT transfers */
 		if (usb_pipeint(qtd->urb->pipe) &&
 				(qtd->urb->dev->speed == USB_SPEED_LOW))
-			ptd->dw1 |= 2 << 16;
+			ptd->dw1 |= DW1_SE_USB_LOSPEED;
 
 		rl = 0;
 		nak = 0;
@@ -647,14 +649,14 @@ static void transform_add_int(struct isp1760_qh *qh,
 		 * that number come from? 0xff seems to work fine...
 		 */
 		/* ptd->dw5 = 0x1c; */
-		ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */
+		ptd->dw5 = TO_DW(0xff); /* Execute Complete Split on any uFrame */
 	}
 
 	period = period >> 1;/* Ensure equal or shorter period than requested */
 	period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */
 
-	ptd->dw2 |= period;
-	ptd->dw4 = usof;
+	ptd->dw2 |= TO_DW(period);
+	ptd->dw4 = TO_DW(usof);
 }
 
 static void create_ptd_int(struct isp1760_qh *qh,
@@ -977,10 +979,10 @@ static void schedule_ptds(struct usb_hcd *hcd)
 static int check_int_transfer(struct usb_hcd *hcd, struct ptd *ptd,
 								struct urb *urb)
 {
-	__dw dw4;
+	u32 dw4;
 	int i;
 
-	dw4 = ptd->dw4;
+	dw4 = TO_U32(ptd->dw4);
 	dw4 >>= 8;
 
 	/* FIXME: ISP1761 datasheet does not say what to do with these. Do we
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH v4 2/9 usb: isp1760: move to regmap for register access

In reply to Rui Miguel Silva

Rework access to registers and memory to use regmap framework. No change in current feature or way of work is intended with this change.

This will allow to reuse this driver with other IP of this family, for example isp1763, with little changes and effort.

---
 drivers/usb/isp1760/Kconfig        |   1 +
 drivers/usb/isp1760/isp1760-core.c | 239 +++++++++++++---
 drivers/usb/isp1760/isp1760-core.h |  38 ++-
 drivers/usb/isp1760/isp1760-hcd.c  | 445 +++++++++++++++--------------
 drivers/usb/isp1760/isp1760-hcd.h  |  18 +-
 drivers/usb/isp1760/isp1760-if.c   |   4 +-
 drivers/usb/isp1760/isp1760-regs.h | 338 ++++++++++------------
 drivers/usb/isp1760/isp1760-udc.c  | 227 ++++++++++-----
 drivers/usb/isp1760/isp1760-udc.h  |  10 +-
 9 files changed, 789 insertions(+), 531 deletions(-)
drivers/usb/isp1760/Kconfig +1 -0
index b1022cc490a2..d23853f601b1 100644
@@ -3,6 +3,7 @@
 config USB_ISP1760
 	tristate "NXP ISP 1760/1761 support"
 	depends on USB || USB_GADGET
+	select REGMAP_MMIO
 	help
 	  Say Y or M here if your system as an ISP1760 USB host controller
 	  or an ISP1761 USB dual-role controller.
drivers/usb/isp1760/isp1760-core.c +203 -36

315 lines not on this page · raw message

drivers/usb/isp1760/isp1760-core.h +33 -5
index d9a0a4cc467c..8fec6395f19f 100644
@@ -14,6 +14,7 @@
 #define _ISP1760_CORE_H_
 
 #include <linux/ioport.h>
+#include <linux/regmap.h>
 
 #include "isp1760-hcd.h"
 #include "isp1760-udc.h"
@@ -38,7 +39,6 @@ struct gpio_desc;
 struct isp1760_device {
 	struct device *dev;
 
-	void __iomem *regs;
 	unsigned int devflags;
 	struct gpio_desc *rst_gpio;
 
@@ -52,14 +52,42 @@ void isp1760_unregister(struct device *dev);
 
 void isp1760_set_pullup(struct isp1760_device *isp, bool enable);
 
-static inline u32 isp1760_read32(void __iomem *base, u32 reg)
+static inline u32 isp1760_field_read(struct regmap_field **fields, u32 field)
 {
-	return readl(base + reg);
+	unsigned int val;
+
+	regmap_field_read(fields[field], &val);
+
+	return val;
+}
+
+static inline void isp1760_field_write(struct regmap_field **fields, u32 field,
+				       u32 val)
+{
+	regmap_field_write(fields[field], val);
+}
+
+static inline void isp1760_field_set(struct regmap_field **fields, u32 field)
+{
+	isp1760_field_write(fields, field, 0xFFFFFFFF);
 }
 
-static inline void isp1760_write32(void __iomem *base, u32 reg, u32 val)
+static inline void isp1760_field_clear(struct regmap_field **fields, u32 field)
 {
-	writel(val, base + reg);
+	isp1760_field_write(fields, field, 0);
 }
 
+static inline u32 isp1760_reg_read(struct regmap *regs, u32 reg)
+{
+	unsigned int val;
+
+	regmap_read(regs, reg, &val);
+
+	return val;
+}
+
+static inline void isp1760_reg_write(struct regmap *regs, u32 reg, u32 val)
+{
+	regmap_write(regs, reg, val);
+}
 #endif
drivers/usb/isp1760/isp1760-hcd.c +234 -211

876 lines not on this page · raw message

drivers/usb/isp1760/isp1760-hcd.h +11 -7
index f1bb2deb1ccf..34e1899e52c4 100644
@@ -3,6 +3,9 @@
 #define _ISP1760_HCD_H_
 
 #include <linux/spinlock.h>
+#include <linux/regmap.h>
+
+#include "isp1760-regs.h"
 
 struct isp1760_qh;
 struct isp1760_qtd;
@@ -48,10 +51,13 @@ enum isp1760_queue_head_types {
 };
 
 struct isp1760_hcd {
-#ifdef CONFIG_USB_ISP1760_HCD
 	struct usb_hcd		*hcd;
 
-	u32 hcs_params;
+	void __iomem		*base;
+
+	struct regmap		*regs;
+	struct regmap_field	*fields[HC_FIELD_MAX];
+
 	spinlock_t		lock;
 	struct isp1760_slotinfo	atl_slots[32];
 	int			atl_done_map;
@@ -66,20 +72,18 @@ struct isp1760_hcd {
 	unsigned		i_thresh;
 	unsigned long		reset_done;
 	unsigned long		next_statechange;
-#endif
 };
 
 #ifdef CONFIG_USB_ISP1760_HCD
-int isp1760_hcd_register(struct isp1760_hcd *priv, void __iomem *regs,
-			 struct resource *mem, int irq, unsigned long irqflags,
-			 struct device *dev);
+int isp1760_hcd_register(struct isp1760_hcd *priv, struct resource *mem,
+			 int irq, unsigned long irqflags, struct device *dev);
 void isp1760_hcd_unregister(struct isp1760_hcd *priv);
 
 int isp1760_init_kmem_once(void);
 void isp1760_deinit_kmem_cache(void);
 #else
 static inline int isp1760_hcd_register(struct isp1760_hcd *priv,
-				       void __iomem *regs, struct resource *mem,
+				       struct resource *mem,
 				       int irq, unsigned long irqflags,
 				       struct device *dev)
 {
drivers/usb/isp1760/isp1760-if.c +2 -2
index ccd30f835888..abfba9f5ec23 100644
@@ -75,9 +75,9 @@ static int isp1761_pci_init(struct pci_dev *dev)
 		/*by default host is in 16bit mode, so
 		 * io operations at this stage must be 16 bit
 		 * */
-		writel(0xface, iobase + HC_SCRATCH_REG);
+		writel(0xface, iobase + ISP176x_HC_SCRATCH);
 		udelay(100);
-		reg_data = readl(iobase + HC_SCRATCH_REG) & 0x0000ffff;
+		reg_data = readl(iobase + ISP176x_HC_SCRATCH) & 0x0000ffff;
 		retry_count--;
 	}
 
drivers/usb/isp1760/isp1760-regs.h +151 -187

369 lines not on this page · raw message

drivers/usb/isp1760/isp1760-udc.c +148 -79

444 lines not on this page · raw message

drivers/usb/isp1760/isp1760-udc.h +6 -4
index d2df650d54e9..a49096c0ac8e 100644
@@ -17,6 +17,8 @@
 #include <linux/timer.h>
 #include <linux/usb/gadget.h>
 
+#include "isp1760-regs.h"
+
 struct isp1760_device;
 struct isp1760_udc;
 
@@ -48,7 +50,7 @@ struct isp1760_ep {
  * struct isp1760_udc - UDC state information
  * irq: IRQ number
  * irqname: IRQ name (as passed to request_irq)
- * regs: Base address of the UDC registers
+ * regs: regmap for UDC registers
  * driver: Gadget driver
  * gadget: Gadget device
  * lock: Protects driver, vbus_timer, ep, ep0_*, DC_EPINDEX register
@@ -59,12 +61,13 @@ struct isp1760_ep {
  * connected: Tracks gadget driver bus connection state
  */
 struct isp1760_udc {
-#ifdef CONFIG_USB_ISP1761_UDC
 	struct isp1760_device *isp;
 
 	int irq;
 	char *irqname;
-	void __iomem *regs;
+
+	struct regmap *regs;
+	struct regmap_field *fields[DC_FIELD_MAX];
 
 	struct usb_gadget_driver *driver;
 	struct usb_gadget gadget;
@@ -81,7 +84,6 @@ struct isp1760_udc {
 	bool connected;
 
 	unsigned int devstatus;
-#endif
 };
 
 #ifdef CONFIG_USB_ISP1761_UDC
Signature · 1 line
2.31.1
#3 lore raw

Re: [PATCH v4 2/9] usb: isp1760: move to regmap for register access

Hi Rui,

Quoted 7 lines · Rui Miguel Silva

Rework access to registers and memory to use regmap framework. No change in current feature or way of work is intended with this change.

This will allow to reuse this driver with other IP of this family, for example isp1763, with little changes and effort.

1da9e1c06873 - usb: isp1760: move to regmap for register access

Starting from this patch, our Arm TC2 platform (multi_v7_defconfig, vexpress-v2p-ca15_a7.dts) doesn't boot anymore.
We discovered this in our v5.14-rc1 based task scheduler test build.

With 1da9e1c06873^1 :

# lsusb
Bus 001 Device 001: ID 1d6b:0002 <-- NXP ISP1760 USB Host Controller
Bus 001 Device 002: ID 0471:3526
Bus 001 Device 003: ID 0781:5591
# dmesg | grep -i isp
[    4.014307] isp1760 1b000000.usb: bus width: 32, oc: digital
[    4.014442] isp1760 1b000000.usb: NXP ISP1760 USB Host Controller
[    4.014715] isp1760 1b000000.usb: new USB bus registered, assigned bus number 1
[    4.025076] isp1760 1b000000.usb: irq 32, io mem 0x1b000000
[    4.025288] isp1760 1b000000.usb: USB ISP 1761 HW rev. 1 started
[    4.055802] ISP1760 USB device initialised
[    4.257911] isp1760 1b000000.usb: port 1 high speed
[    4.325662] usb 1-1: new high-speed USB device number 2 using isp1760
[    4.475670] isp1760 1b000000.usb: port 1 high speed
[   14.320372] usb 1-1.2: new high-speed USB device number 3 using isp1760

With v5.14-rc1 :

there is no boot output at all, but I debugged it a little bit and the system seems to hang here:

[    1.847494] [<c0cac46c>] (isp1760_udc_register) from [<c0ca668c>] (isp1760_register+0x5d0/0x5f0)
[    1.847527] [<c0ca668c>] (isp1760_register) from [<c0ca6b7c>] (isp1760_plat_probe+0x150/0x1b0)
[    1.847557] [<c0ca6b7c>] (isp1760_plat_probe) from [<c0a46ef0>] (platform_probe+0x5c/0xb8)
[    1.847589] [<c0a46ef0>] (platform_probe) from [<c0a44924>] (really_probe.part.0+0x9c/0x32c)

...

    isp1760_udc_register()->isp1760_udc_init()

        ....
        /* Reset the device controller. */
        isp1760_udc_set(udc, DC_SFRESET); <-- hangs here !!!
        usleep_range(10000, 11000);
        isp1760_reg_write(udc->regs, ISP176x_DC_MODE, 0);
        usleep_range(10000, 11000);

[...]

author maintainer
#4 lore raw

Re: [PATCH v4 2/9] usb: isp1760: move to regmap for register access

Hey Dietmar,

Quoted 7 lines · Dietmar Eggemann

Hi Rui,

Quoted 4 lines · Rui Miguel Silva

Rework access to registers and memory to use regmap framework. No change in current feature or way of work is intended with this change.

Quoted 8 lines
Quoted 3 lines

This will allow to reuse this driver with other IP of this family, for example isp1763, with little changes and effort.

1da9e1c06873 - usb: isp1760: move to regmap for register access

Starting from this patch, our Arm TC2 platform (multi_v7_defconfig, vexpress-v2p-ca15_a7.dts) doesn't boot anymore.

:( sorry about that

Quoted 9 lines

We discovered this in our v5.14-rc1 based task scheduler test build.

With 1da9e1c06873^1 :

# lsusb
Bus 001 Device 001: ID 1d6b:0002 <-- NXP ISP1760 USB Host Controller
Bus 001 Device 002: ID 0471:3526
Bus 001 Device 003: ID 0781:5591
Quoted 6 lines
# dmesg | grep -i isp
[    4.014307] isp1760 1b000000.usb: bus width: 32, oc: digital
[    4.014442] isp1760 1b000000.usb: NXP ISP1760 USB Host Controller
[    4.014715] isp1760 1b000000.usb: new USB bus registered, assigned bus number 1
[    4.025076] isp1760 1b000000.usb: irq 32, io mem 0x1b000000
[    4.025288] isp1760 1b000000.usb: USB ISP 1761 HW rev. 1 started

Never managed to get my hands in a board with 1761, I will try to get one of this.

Quoted 15 lines
[    4.055802] ISP1760 USB device initialised
[    4.257911] isp1760 1b000000.usb: port 1 high speed
[    4.325662] usb 1-1: new high-speed USB device number 2 using isp1760
[    4.475670] isp1760 1b000000.usb: port 1 high speed
[   14.320372] usb 1-1.2: new high-speed USB device number 3 using isp1760

With v5.14-rc1 :

there is no boot output at all, but I debugged it a little bit and the system seems to hang here:

[    1.847494] [<c0cac46c>] (isp1760_udc_register) from [<c0ca668c>] (isp1760_register+0x5d0/0x5f0)
[    1.847527] [<c0ca668c>] (isp1760_register) from [<c0ca6b7c>] (isp1760_plat_probe+0x150/0x1b0)
[    1.847557] [<c0ca6b7c>] (isp1760_plat_probe) from [<c0a46ef0>] (platform_probe+0x5c/0xb8)
[    1.847589] [<c0a46ef0>] (platform_probe) from [<c0a44924>] (really_probe.part.0+0x9c/0x32c)
Quoted 7 lines

...

    isp1760_udc_register()->isp1760_udc_init()

        ....
        /* Reset the device controller. */
        isp1760_udc_set(udc, DC_SFRESET); <-- hangs here !!!

Thanks for the hint, I will take a better look here, to find if some register or mapping is wrongly set.

------
Cheers,
Rui

Quoted 5 lines
        usleep_range(10000, 11000);
        isp1760_reg_write(udc->regs, ISP176x_DC_MODE, 0);
        usleep_range(10000, 11000);

[...]

author maintainer
#5 lore raw

PATCH v4 3/9 usb: isp1760: use relaxed primitives

In reply to Rui Miguel Silva

Use io relaxed access memory primitives to satisfy strict type checking (__force).

This will fix some existing sparse warnings:
sparse: warning: cast to restricted __le32

---
 drivers/usb/isp1760/isp1760-hcd.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/isp1760/isp1760-hcd.c +4 -4
index 20d142140574..2cc0555e029d 100644
@@ -246,7 +246,7 @@ static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr,
 
 	if (src_offset < PAYLOAD_OFFSET) {
 		while (bytes >= 4) {
-			*dst = le32_to_cpu(__raw_readl(src));
+			*dst = readl_relaxed(src);
 			bytes -= 4;
 			src++;
 			dst++;
@@ -267,7 +267,7 @@ static void bank_reads8(void __iomem *src_base, u32 src_offset, u32 bank_addr,
 	 * allocated.
 	 */
 	if (src_offset < PAYLOAD_OFFSET)
-		val = le32_to_cpu(__raw_readl(src));
+		val = readl_relaxed(src);
 	else
 		val = __raw_readl(src);
 
@@ -301,7 +301,7 @@ static void mem_writes8(void __iomem *dst_base, u32 dst_offset,
 
 	if (dst_offset < PAYLOAD_OFFSET) {
 		while (bytes >= 4) {
-			__raw_writel(cpu_to_le32(*src), dst);
+			writel_relaxed(*src, dst);
 			bytes -= 4;
 			src++;
 			dst++;
@@ -322,7 +322,7 @@ static void mem_writes8(void __iomem *dst_base, u32 dst_offset,
 	 */
 
 	if (dst_offset < PAYLOAD_OFFSET)
-		__raw_writel(cpu_to_le32(*src), dst);
+		writel_relaxed(*src, dst);
 	else
 		__raw_writel(*src, dst);
 }
Signature · 1 line
2.31.1
author maintainer
#6 lore raw

PATCH v4 4/9 usb: isp1760: remove platform data struct and code

In reply to Rui Miguel Silva

Since the removal of the Blackfin port with:
commit 4ba66a976072 ("arch: remove blackfin port")

No one is using or referencing this header and platform data struct. Remove them.

---
 drivers/usb/isp1760/isp1760-if.c | 20 +++-----------------
 include/linux/usb/isp1760.h      | 19 -------------------
 2 files changed, 3 insertions(+), 36 deletions(-)
 delete mode 100644 include/linux/usb/isp1760.h
drivers/usb/isp1760/isp1760-if.c +3 -17
index abfba9f5ec23..fb6701608cd8 100644
@@ -16,7 +16,6 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
-#include <linux/usb/isp1760.h>
 #include <linux/usb/hcd.h>
 
 #include "isp1760-core.h"
@@ -225,22 +224,9 @@ static int isp1760_plat_probe(struct platform_device *pdev)
 
 		if (of_property_read_bool(dp, "dreq-polarity"))
 			devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
-	} else if (dev_get_platdata(&pdev->dev)) {
-		struct isp1760_platform_data *pdata =
-			dev_get_platdata(&pdev->dev);
-
-		if (pdata->is_isp1761)
-			devflags |= ISP1760_FLAG_ISP1761;
-		if (pdata->bus_width_16)
-			devflags |= ISP1760_FLAG_BUS_WIDTH_16;
-		if (pdata->port1_otg)
-			devflags |= ISP1760_FLAG_OTG_EN;
-		if (pdata->analog_oc)
-			devflags |= ISP1760_FLAG_ANALOG_OC;
-		if (pdata->dack_polarity_high)
-			devflags |= ISP1760_FLAG_DACK_POL_HIGH;
-		if (pdata->dreq_polarity_high)
-			devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
+	} else {
+		pr_err("isp1760: no platform data\n");
+		return -ENXIO;
 	}
 
 	ret = isp1760_register(mem_res, irq_res->start, irqflags, &pdev->dev,
include/linux/usb/isp1760.h deleted +0 -19
deleted file mode 100644
index b75ded28db81..000000000000
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * board initialization should put one of these into dev->platform_data
- * and place the isp1760 onto platform_bus named "isp1760-hcd".
- */
-
-#ifndef __LINUX_USB_ISP1760_H
-#define __LINUX_USB_ISP1760_H
-
-struct isp1760_platform_data {
-	unsigned is_isp1761:1;			/* Chip is ISP1761 */
-	unsigned bus_width_16:1;		/* 16/32-bit data bus width */
-	unsigned port1_otg:1;			/* Port 1 supports OTG */
-	unsigned analog_oc:1;			/* Analog overcurrent */
-	unsigned dack_polarity_high:1;		/* DACK active high */
-	unsigned dreq_polarity_high:1;		/* DREQ active high */
-};
-
-#endif /* __LINUX_USB_ISP1760_H */
Signature · 1 line
2.31.1
author maintainer
#7 lore raw

PATCH v4 5/9 usb: isp1760: hcd: refactor mempool config and setup

In reply to Rui Miguel Silva

In preparation to support other family member IP, which may have different memory layout. Drop macros and setup a configuration struct.

---
 drivers/usb/isp1760/isp1760-core.c | 21 ++++++++
 drivers/usb/isp1760/isp1760-hcd.c  | 83 ++++++++++++++++++++----------
 drivers/usb/isp1760/isp1760-hcd.h  | 37 ++++++-------
 3 files changed, 92 insertions(+), 49 deletions(-)
drivers/usb/isp1760/isp1760-core.c +21 -0
index c79ba98df9f9..35a7667e411c 100644
@@ -101,6 +101,25 @@ void isp1760_set_pullup(struct isp1760_device *isp, bool enable)
 		isp1760_field_set(udc->fields, HW_DP_PULLUP_CLEAR);
 }
 
+/*
+ * 60kb divided in:
+ * - 32 blocks @ 256  bytes
+ * - 20 blocks @ 1024 bytes
+ * -  4 blocks @ 8192 bytes
+ */
+static const struct isp1760_memory_layout isp176x_memory_conf = {
+	.blocks[0]		= 32,
+	.blocks_size[0]		= 256,
+	.blocks[1]		= 20,
+	.blocks_size[1]		= 1024,
+	.blocks[2]		= 4,
+	.blocks_size[2]		= 8192,
+
+	.ptd_num		= 32,
+	.payload_blocks		= 32 + 20 + 4,
+	.payload_area_size	= 0xf000,
+};
+
 static const struct regmap_range isp176x_hc_volatile_ranges[] = {
 	regmap_reg_range(ISP176x_HC_USBCMD, ISP176x_HC_ATL_PTD_LASTPTD),
 	regmap_reg_range(ISP176x_HC_BUFFER_STATUS, ISP176x_HC_MEMORY),
@@ -302,6 +321,8 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
 		udc->fields[i] = f;
 	}
 
+	hcd->memory_layout = &isp176x_memory_conf;
+
 	isp1760_init_core(isp);
 
 	if (IS_ENABLED(CONFIG_USB_ISP1760_HCD) && !usb_disabled()) {
drivers/usb/isp1760/isp1760-hcd.c +55 -28

162 lines not on this page · raw message

drivers/usb/isp1760/isp1760-hcd.h +16 -21
index 34e1899e52c4..9d2427ce3f1a 100644
@@ -12,24 +12,6 @@ struct isp1760_qtd;
 struct resource;
 struct usb_hcd;
 
-/*
- * 60kb divided in:
- * - 32 blocks @ 256  bytes
- * - 20 blocks @ 1024 bytes
- * -  4 blocks @ 8192 bytes
- */
-
-#define BLOCK_1_NUM 32
-#define BLOCK_2_NUM 20
-#define BLOCK_3_NUM 4
-
-#define BLOCK_1_SIZE 256
-#define BLOCK_2_SIZE 1024
-#define BLOCK_3_SIZE 8192
-#define BLOCKS (BLOCK_1_NUM + BLOCK_2_NUM + BLOCK_3_NUM)
-#define MAX_PAYLOAD_SIZE BLOCK_3_SIZE
-#define PAYLOAD_AREA_SIZE 0xf000
-
 struct isp1760_slotinfo {
 	struct isp1760_qh *qh;
 	struct isp1760_qtd *qtd;
@@ -37,6 +19,17 @@ struct isp1760_slotinfo {
 };
 
 /* chip memory management */
+#define ISP176x_BLOCK_NUM 3
+
+struct isp1760_memory_layout {
+	unsigned int blocks[ISP176x_BLOCK_NUM];
+	unsigned int blocks_size[ISP176x_BLOCK_NUM];
+
+	unsigned int ptd_num;
+	unsigned int payload_blocks;
+	unsigned int payload_area_size;
+};
+
 struct isp1760_memory_chunk {
 	unsigned int start;
 	unsigned int size;
@@ -58,12 +51,14 @@ struct isp1760_hcd {
 	struct regmap		*regs;
 	struct regmap_field	*fields[HC_FIELD_MAX];
 
+	const struct isp1760_memory_layout	*memory_layout;
+
 	spinlock_t		lock;
-	struct isp1760_slotinfo	atl_slots[32];
+	struct isp1760_slotinfo	*atl_slots;
 	int			atl_done_map;
-	struct isp1760_slotinfo	int_slots[32];
+	struct isp1760_slotinfo	*int_slots;
 	int			int_done_map;
-	struct isp1760_memory_chunk memory_pool[BLOCKS];
+	struct isp1760_memory_chunk *memory_pool;
 	struct list_head	qh_list[QH_END];
 
 	/* periodic schedule support */
Signature · 1 line
2.31.1
author maintainer
#8 lore raw

PATCH v4 6/9 usb: isp1760: use dr_mode binding

In reply to Rui Miguel Silva

There is already a binding to describe the dual role mode (dr_mode), use that instead of defining a new one (port1-otg).

Update driver code and devicetree files that use that port1-otg binding.

---
 arch/arm/boot/dts/arm-realview-eb.dtsi    | 2 +-
 arch/arm/boot/dts/arm-realview-pb1176.dts | 2 +-
 arch/arm/boot/dts/arm-realview-pb11mp.dts | 2 +-
 arch/arm/boot/dts/arm-realview-pbx.dtsi   | 2 +-
 arch/arm/boot/dts/vexpress-v2m-rs1.dtsi   | 2 +-
 arch/arm/boot/dts/vexpress-v2m.dtsi       | 2 +-
 drivers/usb/isp1760/isp1760-core.c        | 3 +--
 drivers/usb/isp1760/isp1760-core.h        | 2 +-
 drivers/usb/isp1760/isp1760-if.c          | 5 +++--
 9 files changed, 11 insertions(+), 11 deletions(-)
arch/arm/boot/dts/arm-realview-eb.dtsi +1 -1
index a534a8e444d9..04e8a27ba1eb 100644
@@ -148,7 +148,7 @@ ethernet: ethernet@4e000000 {
 	usb: usb@4f000000 {
 		compatible = "nxp,usb-isp1761";
 		reg = <0x4f000000 0x20000>;
-		port1-otg;
+		dr_mode = "peripheral";
 	};
 
 	bridge {
arch/arm/boot/dts/arm-realview-pb1176.dts +1 -1
index f925782f8560..366687fb1ee3 100644
@@ -166,7 +166,7 @@ usb@3b000000 {
 		reg = <0x3b000000 0x20000>;
 		interrupt-parent = <&intc_fpga1176>;
 		interrupts = <0 11 IRQ_TYPE_LEVEL_HIGH>;
-		port1-otg;
+		dr_mode = "peripheral";
 	};
 
 	bridge {
arch/arm/boot/dts/arm-realview-pb11mp.dts +1 -1
index 0c7dabef4a5f..228a51a38f95 100644
@@ -712,7 +712,7 @@ usb@4f000000 {
 			reg = <0x4f000000 0x20000>;
 			interrupt-parent = <&intc_tc11mp>;
 			interrupts = <0 3 IRQ_TYPE_LEVEL_HIGH>;
-			port1-otg;
+			dr_mode = "peripheral";
 		};
 	};
 };
arch/arm/boot/dts/arm-realview-pbx.dtsi +1 -1
index ac95667ed781..ccf6f756b6ed 100644
@@ -164,7 +164,7 @@ ethernet: ethernet@4e000000 {
 	usb: usb@4f000000 {
 		compatible = "nxp,usb-isp1761";
 		reg = <0x4f000000 0x20000>;
-		port1-otg;
+		dr_mode = "peripheral";
 	};
 
 	bridge {
arch/arm/boot/dts/vexpress-v2m-rs1.dtsi +1 -1
index 4f7220b11f2d..2ad9fd7c94ec 100644
@@ -144,7 +144,7 @@ usb@203000000 {
 				compatible = "nxp,usb-isp1761";
 				reg = <2 0x03000000 0x20000>;
 				interrupts = <16>;
-				port1-otg;
+				dr_mode = "peripheral";
 			};
 
 			iofpga-bus@300000000 {
arch/arm/boot/dts/vexpress-v2m.dtsi +1 -1
index 2ac41ed3a57c..ec13ceb9ed36 100644
@@ -62,7 +62,7 @@ usb@3,03000000 {
 				compatible = "nxp,usb-isp1761";
 				reg = <3 0x03000000 0x20000>;
 				interrupts = <16>;
-				port1-otg;
+				dr_mode = "peripheral";
 			};
 
 			iofpga@7,00000000 {
drivers/usb/isp1760/isp1760-core.c +1 -2
index 35a7667e411c..0aeeb12d3bfe 100644
@@ -73,10 +73,9 @@ static void isp1760_init_core(struct isp1760_device *isp)
 	 * on ISP1761.
 	 *
 	 * TODO: Really support OTG. For now we configure port 1 in device mode
-	 * when OTG is requested.
 	 */
 	if ((isp->devflags & ISP1760_FLAG_ISP1761) &&
-	    (isp->devflags & ISP1760_FLAG_OTG_EN)) {
+	    (isp->devflags & ISP1760_FLAG_PERIPHERAL_EN)) {
 		isp1760_field_set(hcd->fields, HW_DM_PULLDOWN);
 		isp1760_field_set(hcd->fields, HW_DP_PULLDOWN);
 		isp1760_field_set(hcd->fields, HW_OTG_DISABLE);
drivers/usb/isp1760/isp1760-core.h +1 -1
index 8fec6395f19f..7a6755d68d41 100644
@@ -28,7 +28,7 @@ struct gpio_desc;
  * a sane default configuration.
  */
 #define ISP1760_FLAG_BUS_WIDTH_16	0x00000002 /* 16-bit data bus width */
-#define ISP1760_FLAG_OTG_EN		0x00000004 /* Port 1 supports OTG */
+#define ISP1760_FLAG_PERIPHERAL_EN	0x00000004 /* Port 1 supports Peripheral mode*/
 #define ISP1760_FLAG_ANALOG_OC		0x00000008 /* Analog overcurrent */
 #define ISP1760_FLAG_DACK_POL_HIGH	0x00000010 /* DACK active high */
 #define ISP1760_FLAG_DREQ_POL_HIGH	0x00000020 /* DREQ active high */
drivers/usb/isp1760/isp1760-if.c +3 -2
index fb6701608cd8..cb3e4d782315 100644
@@ -17,6 +17,7 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/usb/hcd.h>
+#include <linux/usb/otg.h>
 
 #include "isp1760-core.h"
 #include "isp1760-regs.h"
@@ -213,8 +214,8 @@ static int isp1760_plat_probe(struct platform_device *pdev)
 		if (bus_width == 16)
 			devflags |= ISP1760_FLAG_BUS_WIDTH_16;
 
-		if (of_property_read_bool(dp, "port1-otg"))
-			devflags |= ISP1760_FLAG_OTG_EN;
+		if (usb_get_dr_mode(&pdev->dev) == USB_DR_MODE_PERIPHERAL)
+			devflags |= ISP1760_FLAG_PERIPHERAL_EN;
 
 		if (of_property_read_bool(dp, "analog-oc"))
 			devflags |= ISP1760_FLAG_ANALOG_OC;
Signature · 1 line
2.31.1
author maintainer
#9 lore raw

PATCH v4 7/9 usb: isp1760: add support for isp1763

In reply to Rui Miguel Silva

isp1763 have some differences from the isp1760, 8 bit address for registers and 16 bit for values, no bulk access to memory addresses, 16 PTD's instead of 32.

Following the regmap work done before add the registers, memory access and add the functions to support differences in setup sequences.

---
 drivers/usb/isp1760/Kconfig        |   4 +-
 drivers/usb/isp1760/isp1760-core.c | 301 ++++++++++++--
 drivers/usb/isp1760/isp1760-core.h |   4 +
 drivers/usb/isp1760/isp1760-hcd.c  | 627 ++++++++++++++++++++++-------
 drivers/usb/isp1760/isp1760-hcd.h  |   6 +-
 drivers/usb/isp1760/isp1760-if.c   |  12 +-
 drivers/usb/isp1760/isp1760-regs.h |  95 ++++-
 drivers/usb/isp1760/isp1760-udc.c  |   2 +
 drivers/usb/isp1760/isp1760-udc.h  |   2 +
 9 files changed, 849 insertions(+), 204 deletions(-)
drivers/usb/isp1760/Kconfig +2 -2
index d23853f601b1..2ed2b73291d1 100644
@@ -1,11 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0
 
 config USB_ISP1760
-	tristate "NXP ISP 1760/1761 support"
+	tristate "NXP ISP 1760/1761/1763 support"
 	depends on USB || USB_GADGET
 	select REGMAP_MMIO
 	help
-	  Say Y or M here if your system as an ISP1760 USB host controller
+	  Say Y or M here if your system as an ISP1760/1763 USB host controller
 	  or an ISP1761 USB dual-role controller.
 
 	  This driver does not support isochronous transfers or OTG.
drivers/usb/isp1760/isp1760-core.c +266 -35

442 lines not on this page · raw message

drivers/usb/isp1760/isp1760-core.h +4 -0
index 7a6755d68d41..91e0ee3992a7 100644
@@ -2,12 +2,14 @@
 /*
  * Driver for the NXP ISP1760 chip
  *
+ * Copyright 2021 Linaro, Rui Miguel Silva
  * Copyright 2014 Laurent Pinchart
  * Copyright 2007 Sebastian Siewior
  *
  * Contacts:
  *	Sebastian Siewior <[email protected]>
  *	Laurent Pinchart <[email protected]>
+ *	Rui Miguel Silva <[email protected]>
  */
 
 #ifndef _ISP1760_CORE_H_
@@ -35,6 +37,8 @@ struct gpio_desc;
 #define ISP1760_FLAG_ISP1761		0x00000040 /* Chip is ISP1761 */
 #define ISP1760_FLAG_INTR_POL_HIGH	0x00000080 /* Interrupt polarity active high */
 #define ISP1760_FLAG_INTR_EDGE_TRIG	0x00000100 /* Interrupt edge triggered */
+#define ISP1760_FLAG_ISP1763		0x00000200 /* Chip is ISP1763 */
+#define ISP1760_FLAG_BUS_WIDTH_8	0x00000400 /* 8-bit data bus width */
 
 struct isp1760_device {
 	struct device *dev;
drivers/usb/isp1760/isp1760-hcd.c +481 -146

1,031 lines not on this page · raw message

drivers/usb/isp1760/isp1760-hcd.h +4 -2
index 9d2427ce3f1a..ee3063a34de3 100644
@@ -19,13 +19,14 @@ struct isp1760_slotinfo {
 };
 
 /* chip memory management */
+#define ISP176x_BLOCK_MAX (32 + 20 + 4)
 #define ISP176x_BLOCK_NUM 3
 
 struct isp1760_memory_layout {
 	unsigned int blocks[ISP176x_BLOCK_NUM];
 	unsigned int blocks_size[ISP176x_BLOCK_NUM];
 
-	unsigned int ptd_num;
+	unsigned int slot_num;
 	unsigned int payload_blocks;
 	unsigned int payload_area_size;
 };
@@ -51,6 +52,7 @@ struct isp1760_hcd {
 	struct regmap		*regs;
 	struct regmap_field	*fields[HC_FIELD_MAX];
 
+	bool			is_isp1763;
 	const struct isp1760_memory_layout	*memory_layout;
 
 	spinlock_t		lock;
@@ -58,7 +60,7 @@ struct isp1760_hcd {
 	int			atl_done_map;
 	struct isp1760_slotinfo	*int_slots;
 	int			int_done_map;
-	struct isp1760_memory_chunk *memory_pool;
+	struct isp1760_memory_chunk memory_pool[ISP176x_BLOCK_MAX];
 	struct list_head	qh_list[QH_END];
 
 	/* periodic schedule support */
drivers/usb/isp1760/isp1760-if.c +11 -1
index cb3e4d782315..7cc349c0b2ad 100644
@@ -7,6 +7,7 @@
  * - PDEV (generic platform device centralized driver model)
  *
  * (c) 2007 Sebastian Siewior <[email protected]>
+ * Copyright 2021 Linaro, Rui Miguel Silva <[email protected]>
  *
  */
 
@@ -209,10 +210,18 @@ static int isp1760_plat_probe(struct platform_device *pdev)
 		if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
 			devflags |= ISP1760_FLAG_ISP1761;
 
-		/* Some systems wire up only 16 of the 32 data lines */
+		if (of_device_is_compatible(dp, "nxp,usb-isp1763"))
+			devflags |= ISP1760_FLAG_ISP1763;
+
+		/*
+		 * Some systems wire up only 8 of 16 data lines or
+		 * 16 of the 32 data lines
+		 */
 		of_property_read_u32(dp, "bus-width", &bus_width);
 		if (bus_width == 16)
 			devflags |= ISP1760_FLAG_BUS_WIDTH_16;
+		else if (bus_width == 8)
+			devflags |= ISP1760_FLAG_BUS_WIDTH_8;
 
 		if (usb_get_dr_mode(&pdev->dev) == USB_DR_MODE_PERIPHERAL)
 			devflags |= ISP1760_FLAG_PERIPHERAL_EN;
@@ -250,6 +259,7 @@ static int isp1760_plat_remove(struct platform_device *pdev)
 static const struct of_device_id isp1760_of_match[] = {
 	{ .compatible = "nxp,usb-isp1760", },
 	{ .compatible = "nxp,usb-isp1761", },
+	{ .compatible = "nxp,usb-isp1763", },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, isp1760_of_match);
drivers/usb/isp1760/isp1760-regs.h +77 -18

151 lines not on this page · raw message

drivers/usb/isp1760/isp1760-udc.c +2 -0
index 1e2ca43fb152..30efc9d32506 100644
@@ -2,10 +2,12 @@
 /*
  * Driver for the NXP ISP1761 device controller
  *
+ * Copyright 2021 Linaro, Rui Miguel Silva
  * Copyright 2014 Ideas on Board Oy
  *
  * Contacts:
  *	Laurent Pinchart <[email protected]>
+ *	Rui Miguel Silva <[email protected]>
  */
 
 #include <linux/interrupt.h>
drivers/usb/isp1760/isp1760-udc.h +2 -0
index a49096c0ac8e..f2ab5929cc9f 100644
@@ -2,10 +2,12 @@
 /*
  * Driver for the NXP ISP1761 device controller
  *
+ * Copyright 2021 Linaro, Rui Miguel Silva
  * Copyright 2014 Ideas on Board Oy
  *
  * Contacts:
  *	Laurent Pinchart <[email protected]>
+ *	Rui Miguel Silva <[email protected]>
  */
 
 #ifndef _ISP1760_UDC_H_
Signature · 1 line
2.31.1
author maintainer
#10 lore raw

PATCH v4 8/9 dt-bindings: usb: nxp,isp1760: add bindings

In reply to Rui Miguel Silva

The nxp,isp1760 driver is old in the tree, but did not had a bindings entry, since I am extend it to support isp1763 in the same family, use this to add a proper yaml bindings file.

---
 .../devicetree/bindings/usb/nxp,isp1760.yaml  | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/nxp,isp1760.yaml
Documentation/devicetree/bindings/usb/nxp,isp1760.yaml new file +69 -0
new file mode 100644
index 000000000000..a88f99adfe8e
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/usb/nxp,isp1760.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP ISP1760 family controller bindings
+
+maintainers:
+  - Sebastian Siewior <[email protected]>
+  - Laurent Pinchart <[email protected]>
+
+description: |
+  NXP ISP1760 family, which includes ISP1760/1761/1763 devicetree controller
+  bindings
+
+properties:
+  compatible:
+    enum:
+      - nxp,usb-isp1760
+      - nxp,usb-isp1761
+      - nxp,usb-isp1763
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 1
+    maxItems: 2
+    items:
+      - description: Host controller interrupt
+      - description: Device controller interrupt in isp1761
+
+  interrupt-names:
+    minItems: 1
+    maxItems: 2
+    items:
+      - const: host
+      - const: peripheral
+
+  bus-width:
+    description:
+      Number of data lines.
+    enum: [8, 16, 32]
+    default: 32
+
+  dr_mode:
+    enum:
+      - host
+      - peripheral
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    usb@40200000 {
+        compatible = "nxp,usb-isp1763";
+        reg = <0x40200000 0x100000>;
+        interrupts = <GIC_SPI 114 IRQ_TYPE_LEVEL_HIGH>;
+        bus-width = <16>;
+        dr_mode = "host";
+    };
+
+...
Signature · 1 line
2.31.1
maintainer Reviewed-by on v4 8/9
#11 lore raw

Re: [PATCH v4 8/9] dt-bindings: usb: nxp,isp1760: add bindings

Quoted 10 lines · Rui Miguel Silva

The nxp,isp1760 driver is old in the tree, but did not had a bindings entry, since I am extend it to support isp1763 in the same family, use this to add a proper yaml bindings file.

---
 .../devicetree/bindings/usb/nxp,isp1760.yaml  | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/nxp,isp1760.yaml
author maintainer
#12 lore raw

PATCH v4 9/9 usb: isp1763: add peripheral mode

In reply to Rui Miguel Silva

Besides the already host mode support add peripheral mode support for the isp1763 IP from the isp1760 family.

---
 drivers/usb/isp1760/isp1760-core.c | 25 +++++++++++------
 drivers/usb/isp1760/isp1760-regs.h | 42 ++++++++++++++++++++++++++++
 drivers/usb/isp1760/isp1760-udc.c  | 45 ++++++++++++++++++++++--------
 drivers/usb/isp1760/isp1760-udc.h  |  1 +
 4 files changed, 94 insertions(+), 19 deletions(-)
drivers/usb/isp1760/isp1760-core.c +17 -8
index 1d847f13abab..ff07e2890692 100644
@@ -83,7 +83,8 @@ static int isp1760_init_core(struct isp1760_device *isp)
 	 *
 	 * TODO: Really support OTG. For now we configure port 1 in device mode
 	 */
-	if ((isp->devflags & ISP1760_FLAG_ISP1761) &&
+	if (((isp->devflags & ISP1760_FLAG_ISP1761) ||
+	     (isp->devflags & ISP1760_FLAG_ISP1763)) &&
 	    (isp->devflags & ISP1760_FLAG_PERIPHERAL_EN)) {
 		isp1760_field_set(hcd->fields, HW_DM_PULLDOWN);
 		isp1760_field_set(hcd->fields, HW_DP_PULLDOWN);
@@ -470,13 +471,15 @@ static const struct regmap_config isp1763_dc_regmap_conf = {
 int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
 		     struct device *dev, unsigned int devflags)
 {
-	bool udc_disabled = !(devflags & ISP1760_FLAG_ISP1761);
 	const struct regmap_config *hc_regmap;
 	const struct reg_field *hc_reg_fields;
+	const struct regmap_config *dc_regmap;
+	const struct reg_field *dc_reg_fields;
 	struct isp1760_device *isp;
 	struct isp1760_hcd *hcd;
 	struct isp1760_udc *udc;
 	struct regmap_field *f;
+	bool udc_enabled;
 	int ret;
 	int i;
 
@@ -484,8 +487,11 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
 	 * If neither the HCD not the UDC is enabled return an error, as no
 	 * device would be registered.
 	 */
+	udc_enabled = ((devflags & ISP1760_FLAG_ISP1763) ||
+		       (devflags & ISP1760_FLAG_ISP1761));
+
 	if ((!IS_ENABLED(CONFIG_USB_ISP1760_HCD) || usb_disabled()) &&
-	    (!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || udc_disabled))
+	    (!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || !udc_enabled))
 		return -ENODEV;
 
 	isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL);
@@ -498,6 +504,7 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
 	udc = &isp->udc;
 
 	hcd->is_isp1763 = !!(devflags & ISP1760_FLAG_ISP1763);
+	udc->is_isp1763 = !!(devflags & ISP1760_FLAG_ISP1763);
 
 	if (!hcd->is_isp1763 && (devflags & ISP1760_FLAG_BUS_WIDTH_8)) {
 		dev_err(dev, "isp1760/61 do not support data width 8\n");
@@ -507,9 +514,13 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
 	if (hcd->is_isp1763) {
 		hc_regmap = &isp1763_hc_regmap_conf;
 		hc_reg_fields = &isp1763_hc_reg_fields[0];
+		dc_regmap = &isp1763_dc_regmap_conf;
+		dc_reg_fields = &isp1763_dc_reg_fields[0];
 	} else {
 		hc_regmap = &isp1760_hc_regmap_conf;
 		hc_reg_fields = &isp1760_hc_reg_fields[0];
+		dc_regmap = &isp1761_dc_regmap_conf;
+		dc_reg_fields = &isp1761_dc_reg_fields[0];
 	}
 
 	isp->rst_gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
@@ -532,14 +543,12 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
 		hcd->fields[i] = f;
 	}
 
-	udc->regs = devm_regmap_init_mmio(dev, hcd->base,
-					  &isp1761_dc_regmap_conf);
+	udc->regs = devm_regmap_init_mmio(dev, hcd->base, dc_regmap);
 	if (IS_ERR(udc->regs))
 		return PTR_ERR(udc->regs);
 
 	for (i = 0; i < DC_FIELD_MAX; i++) {
-		f = devm_regmap_field_alloc(dev, udc->regs,
-					    isp1761_dc_reg_fields[i]);
+		f = devm_regmap_field_alloc(dev, udc->regs, dc_reg_fields[i]);
 		if (IS_ERR(f))
 			return PTR_ERR(f);
 
@@ -562,7 +571,7 @@ int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
 			return ret;
 	}
 
-	if (IS_ENABLED(CONFIG_USB_ISP1761_UDC) && !udc_disabled) {
+	if (IS_ENABLED(CONFIG_USB_ISP1761_UDC) && udc_enabled) {
 		ret = isp1760_udc_register(isp, irq, irqflags);
 		if (ret < 0) {
 			isp1760_hcd_unregister(hcd);
drivers/usb/isp1760/isp1760-regs.h +42 -0

50 lines not on this page · raw message

drivers/usb/isp1760/isp1760-udc.c +34 -11

108 lines not on this page · raw message

drivers/usb/isp1760/isp1760-udc.h +1 -0
index f2ab5929cc9f..22044e86bc0e 100644
@@ -84,6 +84,7 @@ struct isp1760_udc {
 	u16 ep0_length;
 
 	bool connected;
+	bool is_isp1763;
 
 	unsigned int devstatus;
 };
Signature · 1 line
2.31.1
#13 lore raw
In reply to Rui Miguel Silva

Hi Rui,

I'm afraid I won't have time to review this in the near future, so feel free to get it merged without my tags.

Quoted 83 lines · Rui Miguel Silva

The Arm MPS3 FPGA prototyping board [0] have an isp1763 [1] as USB controller. There is already support for the isp1760 and isp1761 in tree, this series extend the support also for the isp1763.

Move register access using regmap, remove some platform data and code, refactor the mempool, use dr_mode to align to existing bindings, then add the support for isp1763 host mode, add bindings files that did not existed and at the end add also support for peripheral mode for isp1763.

@Laurent and @Sebastian, I add both of you in the bindings files as maintainers (it is a mandatory field)since you were the ones which contributed with the initial code and peripheral code, let me know if you are ok with it. If yes I may send a follow up to add also entries in MAINTAINERS file that it is also missing.

v3 [4] -> v4:
Rob Herring (bindings):
- add device controller interrupt
- correct additionalProperties field

v2 [3] -> v3:
kernel test bot:
- add select REGMAP_MMIO

v1 [2] -> v2:

kernel test robot:
- add two patches (1/9 and 3/9) to fix dozens of pre-existing sparse warnings so that this series does not introduce new ones. No sparse warning left.
- fix duplication of regmap fields

Laurent:
- move initializers from .h to .c
- change interrupt registers setup from field to one shot register setting (did not change hcd hw mode init because I think it did not make the difference and even avoid artifact around setting twice the register)

Rob test bot:
- fix suffix at compatible string to clean up warning in bindings

Cheers,
Rui

[0]: https://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps3
[1]: https://media.digikey.com/pdf/Data%20Sheets/ST%20Ericsson%20PDFs/ISP1763A.pdf
[2]: https://lore.kernel.org/linux-devicetree/[email protected]/
[3]: https://lore.kernel.org/linux-usb/[email protected]/
[4]: https://lore.kernel.org/linux-usb/[email protected]/

Rui Miguel Silva (9):
usb: isp1760: fix strict typechecking
usb: isp1760: move to regmap for register access
usb: isp1760: use relaxed primitives
usb: isp1760: remove platform data struct and code
usb: isp1760: hcd: refactor mempool config and setup
usb: isp1760: use dr_mode binding
usb: isp1760: add support for isp1763
dt-bindings: usb: nxp,isp1760: add bindings
usb: isp1763: add peripheral mode

 .../devicetree/bindings/usb/nxp,isp1760.yaml  |   69 ++
 arch/arm/boot/dts/arm-realview-eb.dtsi        |    2 +-
 arch/arm/boot/dts/arm-realview-pb1176.dts     |    2 +-
 arch/arm/boot/dts/arm-realview-pb11mp.dts     |    2 +-
 arch/arm/boot/dts/arm-realview-pbx.dtsi       |    2 +-
 arch/arm/boot/dts/vexpress-v2m-rs1.dtsi       |    2 +-
 arch/arm/boot/dts/vexpress-v2m.dtsi           |    2 +-
 drivers/usb/isp1760/Kconfig                   |    5 +-
 drivers/usb/isp1760/isp1760-core.c            |  513 ++++++++-
 drivers/usb/isp1760/isp1760-core.h            |   44 +-
 drivers/usb/isp1760/isp1760-hcd.c             | 1021 ++++++++++++-----
 drivers/usb/isp1760/isp1760-hcd.h             |   57 +-
 drivers/usb/isp1760/isp1760-if.c              |   41 +-
 drivers/usb/isp1760/isp1760-regs.h            |  435 ++++---
 drivers/usb/isp1760/isp1760-udc.c             |  250 ++--
 drivers/usb/isp1760/isp1760-udc.h             |   13 +-
 include/linux/usb/isp1760.h                   |   19 -
 17 files changed, 1769 insertions(+), 710 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/nxp,isp1760.yaml
 delete mode 100644 include/linux/usb/isp1760.h
Signature · 3 lines
Regards,

Laurent Pinchart
author maintainer
#14 lore raw

Hi Laurent,

Quoted 4 lines · Laurent Pinchart

Hi Rui,

I'm afraid I won't have time to review this in the near future, so feel free to get it merged without my tags.

Ok, thanks, I think Greg already put them is the usb-next, BUT I would like to ask you to take 2 min. to reply to this [0] MAINTAINERS entry.

Thanks in advance,
------
Cheers,
Rui

[0]: https://lore.kernel.org/linux-usb/[email protected]/T/#u

Quoted 90 lines · Rui Miguel Silva
Quoted 83 lines

The Arm MPS3 FPGA prototyping board [0] have an isp1763 [1] as USB controller. There is already support for the isp1760 and isp1761 in tree, this series extend the support also for the isp1763.

Move register access using regmap, remove some platform data and code, refactor the mempool, use dr_mode to align to existing bindings, then add the support for isp1763 host mode, add bindings files that did not existed and at the end add also support for peripheral mode for isp1763.

@Laurent and @Sebastian, I add both of you in the bindings files as maintainers (it is a mandatory field)since you were the ones which contributed with the initial code and peripheral code, let me know if you are ok with it. If yes I may send a follow up to add also entries in MAINTAINERS file that it is also missing.

v3 [4] -> v4:
Rob Herring (bindings):
- add device controller interrupt
- correct additionalProperties field

v2 [3] -> v3:
kernel test bot:
- add select REGMAP_MMIO

v1 [2] -> v2:

kernel test robot:
- add two patches (1/9 and 3/9) to fix dozens of pre-existing sparse warnings so that this series does not introduce new ones. No sparse warning left.
- fix duplication of regmap fields

Laurent:
- move initializers from .h to .c
- change interrupt registers setup from field to one shot register setting (did not change hcd hw mode init because I think it did not make the difference and even avoid artifact around setting twice the register)

Rob test bot:
- fix suffix at compatible string to clean up warning in bindings

Cheers,
Rui

[0]: https://developer.arm.com/tools-and-software/development-boards/fpga-prototyping-boards/mps3
[1]: https://media.digikey.com/pdf/Data%20Sheets/ST%20Ericsson%20PDFs/ISP1763A.pdf
[2]: https://lore.kernel.org/linux-devicetree/[email protected]/
[3]: https://lore.kernel.org/linux-usb/[email protected]/
[4]: https://lore.kernel.org/linux-usb/[email protected]/

Rui Miguel Silva (9):
usb: isp1760: fix strict typechecking
usb: isp1760: move to regmap for register access
usb: isp1760: use relaxed primitives
usb: isp1760: remove platform data struct and code
usb: isp1760: hcd: refactor mempool config and setup
usb: isp1760: use dr_mode binding
usb: isp1760: add support for isp1763
dt-bindings: usb: nxp,isp1760: add bindings
usb: isp1763: add peripheral mode

 .../devicetree/bindings/usb/nxp,isp1760.yaml  |   69 ++
 arch/arm/boot/dts/arm-realview-eb.dtsi        |    2 +-
 arch/arm/boot/dts/arm-realview-pb1176.dts     |    2 +-
 arch/arm/boot/dts/arm-realview-pb11mp.dts     |    2 +-
 arch/arm/boot/dts/arm-realview-pbx.dtsi       |    2 +-
 arch/arm/boot/dts/vexpress-v2m-rs1.dtsi       |    2 +-
 arch/arm/boot/dts/vexpress-v2m.dtsi           |    2 +-
 drivers/usb/isp1760/Kconfig                   |    5 +-
 drivers/usb/isp1760/isp1760-core.c            |  513 ++++++++-
 drivers/usb/isp1760/isp1760-core.h            |   44 +-
 drivers/usb/isp1760/isp1760-hcd.c             | 1021 ++++++++++++-----
 drivers/usb/isp1760/isp1760-hcd.h             |   57 +-
 drivers/usb/isp1760/isp1760-if.c              |   41 +-
 drivers/usb/isp1760/isp1760-regs.h            |  435 ++++---
 drivers/usb/isp1760/isp1760-udc.c             |  250 ++--
 drivers/usb/isp1760/isp1760-udc.h             |   13 +-
 include/linux/usb/isp1760.h                   |   19 -
 17 files changed, 1769 insertions(+), 710 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/nxp,isp1760.yaml
 delete mode 100644 include/linux/usb/isp1760.h
Signature · 3 lines
Regards,

Laurent Pinchart