xref: /linux/drivers/usb/isp1760/isp1760-core.c (revision 60d789f3bfbb7428e6ba2949de70a6db8e12e8fa)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
27ef077a8SLaurent Pinchart /*
37ef077a8SLaurent Pinchart  * Driver for the NXP ISP1760 chip
47ef077a8SLaurent Pinchart  *
5*60d789f3SRui Miguel Silva  * Copyright 2021 Linaro, Rui Miguel Silva
67ef077a8SLaurent Pinchart  * Copyright 2014 Laurent Pinchart
77ef077a8SLaurent Pinchart  * Copyright 2007 Sebastian Siewior
87ef077a8SLaurent Pinchart  *
97ef077a8SLaurent Pinchart  * Contacts:
107ef077a8SLaurent Pinchart  *	Sebastian Siewior <bigeasy@linutronix.de>
117ef077a8SLaurent Pinchart  *	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
12*60d789f3SRui Miguel Silva  *	Rui Miguel Silva <rui.silva@linaro.org>
137ef077a8SLaurent Pinchart  */
147ef077a8SLaurent Pinchart 
157ef077a8SLaurent Pinchart #include <linux/delay.h>
167ef077a8SLaurent Pinchart #include <linux/gpio/consumer.h>
177ef077a8SLaurent Pinchart #include <linux/io.h>
187ef077a8SLaurent Pinchart #include <linux/kernel.h>
197ef077a8SLaurent Pinchart #include <linux/module.h>
201da9e1c0SRui Miguel Silva #include <linux/regmap.h>
217ef077a8SLaurent Pinchart #include <linux/slab.h>
227ef077a8SLaurent Pinchart #include <linux/usb.h>
237ef077a8SLaurent Pinchart 
247ef077a8SLaurent Pinchart #include "isp1760-core.h"
257ef077a8SLaurent Pinchart #include "isp1760-hcd.h"
267ef077a8SLaurent Pinchart #include "isp1760-regs.h"
277ef077a8SLaurent Pinchart #include "isp1760-udc.h"
287ef077a8SLaurent Pinchart 
29*60d789f3SRui Miguel Silva static int isp1760_init_core(struct isp1760_device *isp)
307ef077a8SLaurent Pinchart {
311da9e1c0SRui Miguel Silva 	struct isp1760_hcd *hcd = &isp->hcd;
321da9e1c0SRui Miguel Silva 	struct isp1760_udc *udc = &isp->udc;
337ef077a8SLaurent Pinchart 
347ef077a8SLaurent Pinchart 	/* Low-level chip reset */
357ef077a8SLaurent Pinchart 	if (isp->rst_gpio) {
367ef077a8SLaurent Pinchart 		gpiod_set_value_cansleep(isp->rst_gpio, 1);
370f029008SJia-Ju Bai 		msleep(50);
387ef077a8SLaurent Pinchart 		gpiod_set_value_cansleep(isp->rst_gpio, 0);
397ef077a8SLaurent Pinchart 	}
407ef077a8SLaurent Pinchart 
417ef077a8SLaurent Pinchart 	/*
427ef077a8SLaurent Pinchart 	 * Reset the host controller, including the CPU interface
437ef077a8SLaurent Pinchart 	 * configuration.
447ef077a8SLaurent Pinchart 	 */
451da9e1c0SRui Miguel Silva 	isp1760_field_set(hcd->fields, SW_RESET_RESET_ALL);
467ef077a8SLaurent Pinchart 	msleep(100);
477ef077a8SLaurent Pinchart 
487ef077a8SLaurent Pinchart 	/* Setup HW Mode Control: This assumes a level active-low interrupt */
49*60d789f3SRui Miguel Silva 	if ((isp->devflags & ISP1760_FLAG_ANALOG_OC) && hcd->is_isp1763) {
50*60d789f3SRui Miguel Silva 		dev_err(isp->dev, "isp1763 analog overcurrent not available\n");
51*60d789f3SRui Miguel Silva 		return -EINVAL;
52*60d789f3SRui Miguel Silva 	}
53*60d789f3SRui Miguel Silva 
547ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_16)
551da9e1c0SRui Miguel Silva 		isp1760_field_clear(hcd->fields, HW_DATA_BUS_WIDTH);
56*60d789f3SRui Miguel Silva 	if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_8)
57*60d789f3SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_DATA_BUS_WIDTH);
587ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_ANALOG_OC)
591da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_ANA_DIGI_OC);
607ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_DACK_POL_HIGH)
611da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_DACK_POL_HIGH);
627ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_DREQ_POL_HIGH)
631da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_DREQ_POL_HIGH);
647ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_INTR_POL_HIGH)
651da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_INTR_HIGH_ACT);
667ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_INTR_EDGE_TRIG)
671da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_INTR_EDGE_TRIG);
687ef077a8SLaurent Pinchart 
697ef077a8SLaurent Pinchart 	/*
707ef077a8SLaurent Pinchart 	 * The ISP1761 has a dedicated DC IRQ line but supports sharing the HC
717ef077a8SLaurent Pinchart 	 * IRQ line for both the host and device controllers. Hardcode IRQ
727ef077a8SLaurent Pinchart 	 * sharing for now and disable the DC interrupts globally to avoid
737ef077a8SLaurent Pinchart 	 * spurious interrupts during HCD registration.
747ef077a8SLaurent Pinchart 	 */
757ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_ISP1761) {
761da9e1c0SRui Miguel Silva 		isp1760_reg_write(udc->regs, ISP176x_DC_MODE, 0);
771da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_COMN_IRQ);
787ef077a8SLaurent Pinchart 	}
797ef077a8SLaurent Pinchart 
807ef077a8SLaurent Pinchart 	/*
817ef077a8SLaurent Pinchart 	 * PORT 1 Control register of the ISP1760 is the OTG control register
827ef077a8SLaurent Pinchart 	 * on ISP1761.
837ef077a8SLaurent Pinchart 	 *
847ef077a8SLaurent Pinchart 	 * TODO: Really support OTG. For now we configure port 1 in device mode
857ef077a8SLaurent Pinchart 	 */
867ef077a8SLaurent Pinchart 	if ((isp->devflags & ISP1760_FLAG_ISP1761) &&
873eb96e04SRui Miguel Silva 	    (isp->devflags & ISP1760_FLAG_PERIPHERAL_EN)) {
881da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_DM_PULLDOWN);
891da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_DP_PULLDOWN);
901da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_OTG_DISABLE);
911da9e1c0SRui Miguel Silva 	} else {
921da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_SW_SEL_HC_DC);
931da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_VBUS_DRV);
941da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_SEL_CP_EXT);
951da9e1c0SRui Miguel Silva 	}
967ef077a8SLaurent Pinchart 
97*60d789f3SRui Miguel Silva 	dev_info(isp->dev, "%s bus width: %u, oc: %s\n",
98*60d789f3SRui Miguel Silva 		 hcd->is_isp1763 ? "isp1763" : "isp1760",
99*60d789f3SRui Miguel Silva 		 isp->devflags & ISP1760_FLAG_BUS_WIDTH_8 ? 8 :
1007ef077a8SLaurent Pinchart 		 isp->devflags & ISP1760_FLAG_BUS_WIDTH_16 ? 16 : 32,
101*60d789f3SRui Miguel Silva 		 hcd->is_isp1763 ? "not available" :
1027ef077a8SLaurent Pinchart 		 isp->devflags & ISP1760_FLAG_ANALOG_OC ? "analog" : "digital");
103*60d789f3SRui Miguel Silva 
104*60d789f3SRui Miguel Silva 	return 0;
1057ef077a8SLaurent Pinchart }
1067ef077a8SLaurent Pinchart 
1077ef077a8SLaurent Pinchart void isp1760_set_pullup(struct isp1760_device *isp, bool enable)
1087ef077a8SLaurent Pinchart {
1091da9e1c0SRui Miguel Silva 	struct isp1760_udc *udc = &isp->udc;
1101da9e1c0SRui Miguel Silva 
1111da9e1c0SRui Miguel Silva 	if (enable)
1121da9e1c0SRui Miguel Silva 		isp1760_field_set(udc->fields, HW_DP_PULLUP);
1131da9e1c0SRui Miguel Silva 	else
1141da9e1c0SRui Miguel Silva 		isp1760_field_set(udc->fields, HW_DP_PULLUP_CLEAR);
1157ef077a8SLaurent Pinchart }
1167ef077a8SLaurent Pinchart 
117a74f639cSRui Miguel Silva /*
118*60d789f3SRui Miguel Silva  * ISP1760/61:
119*60d789f3SRui Miguel Silva  *
120a74f639cSRui Miguel Silva  * 60kb divided in:
121a74f639cSRui Miguel Silva  * - 32 blocks @ 256  bytes
122a74f639cSRui Miguel Silva  * - 20 blocks @ 1024 bytes
123a74f639cSRui Miguel Silva  * -  4 blocks @ 8192 bytes
124a74f639cSRui Miguel Silva  */
125a74f639cSRui Miguel Silva static const struct isp1760_memory_layout isp176x_memory_conf = {
126a74f639cSRui Miguel Silva 	.blocks[0]		= 32,
127a74f639cSRui Miguel Silva 	.blocks_size[0]		= 256,
128a74f639cSRui Miguel Silva 	.blocks[1]		= 20,
129a74f639cSRui Miguel Silva 	.blocks_size[1]		= 1024,
130a74f639cSRui Miguel Silva 	.blocks[2]		= 4,
131a74f639cSRui Miguel Silva 	.blocks_size[2]		= 8192,
132a74f639cSRui Miguel Silva 
133*60d789f3SRui Miguel Silva 	.slot_num		= 32,
134a74f639cSRui Miguel Silva 	.payload_blocks		= 32 + 20 + 4,
135a74f639cSRui Miguel Silva 	.payload_area_size	= 0xf000,
136a74f639cSRui Miguel Silva };
137a74f639cSRui Miguel Silva 
138*60d789f3SRui Miguel Silva /*
139*60d789f3SRui Miguel Silva  * ISP1763:
140*60d789f3SRui Miguel Silva  *
141*60d789f3SRui Miguel Silva  * 20kb divided in:
142*60d789f3SRui Miguel Silva  * - 8 blocks @ 256  bytes
143*60d789f3SRui Miguel Silva  * - 2 blocks @ 1024 bytes
144*60d789f3SRui Miguel Silva  * - 4 blocks @ 4096 bytes
145*60d789f3SRui Miguel Silva  */
146*60d789f3SRui Miguel Silva static const struct isp1760_memory_layout isp1763_memory_conf = {
147*60d789f3SRui Miguel Silva 	.blocks[0]		= 8,
148*60d789f3SRui Miguel Silva 	.blocks_size[0]		= 256,
149*60d789f3SRui Miguel Silva 	.blocks[1]		= 2,
150*60d789f3SRui Miguel Silva 	.blocks_size[1]		= 1024,
151*60d789f3SRui Miguel Silva 	.blocks[2]		= 4,
152*60d789f3SRui Miguel Silva 	.blocks_size[2]		= 4096,
153*60d789f3SRui Miguel Silva 
154*60d789f3SRui Miguel Silva 	.slot_num		= 16,
155*60d789f3SRui Miguel Silva 	.payload_blocks		= 8 + 2 + 4,
156*60d789f3SRui Miguel Silva 	.payload_area_size	= 0x5000,
157*60d789f3SRui Miguel Silva };
158*60d789f3SRui Miguel Silva 
1591da9e1c0SRui Miguel Silva static const struct regmap_range isp176x_hc_volatile_ranges[] = {
1601da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_HC_USBCMD, ISP176x_HC_ATL_PTD_LASTPTD),
1611da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_HC_BUFFER_STATUS, ISP176x_HC_MEMORY),
162*60d789f3SRui Miguel Silva 	regmap_reg_range(ISP176x_HC_INTERRUPT, ISP176x_HC_OTG_CTRL_CLEAR),
1631da9e1c0SRui Miguel Silva };
1641da9e1c0SRui Miguel Silva 
1651da9e1c0SRui Miguel Silva static const struct regmap_access_table isp176x_hc_volatile_table = {
1661da9e1c0SRui Miguel Silva 	.yes_ranges	= isp176x_hc_volatile_ranges,
1671da9e1c0SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp176x_hc_volatile_ranges),
1681da9e1c0SRui Miguel Silva };
1691da9e1c0SRui Miguel Silva 
170*60d789f3SRui Miguel Silva static const struct regmap_config isp1760_hc_regmap_conf = {
1711da9e1c0SRui Miguel Silva 	.name = "isp1760-hc",
1721da9e1c0SRui Miguel Silva 	.reg_bits = 16,
1731da9e1c0SRui Miguel Silva 	.reg_stride = 4,
1741da9e1c0SRui Miguel Silva 	.val_bits = 32,
1751da9e1c0SRui Miguel Silva 	.fast_io = true,
176*60d789f3SRui Miguel Silva 	.max_register = ISP176x_HC_OTG_CTRL_CLEAR,
1771da9e1c0SRui Miguel Silva 	.volatile_table = &isp176x_hc_volatile_table,
1781da9e1c0SRui Miguel Silva };
1791da9e1c0SRui Miguel Silva 
1801da9e1c0SRui Miguel Silva static const struct reg_field isp1760_hc_reg_fields[] = {
1811da9e1c0SRui Miguel Silva 	[HCS_PPC]		= REG_FIELD(ISP176x_HC_HCSPARAMS, 4, 4),
1821da9e1c0SRui Miguel Silva 	[HCS_N_PORTS]		= REG_FIELD(ISP176x_HC_HCSPARAMS, 0, 3),
1831da9e1c0SRui Miguel Silva 	[HCC_ISOC_CACHE]	= REG_FIELD(ISP176x_HC_HCCPARAMS, 7, 7),
1841da9e1c0SRui Miguel Silva 	[HCC_ISOC_THRES]	= REG_FIELD(ISP176x_HC_HCCPARAMS, 4, 6),
1851da9e1c0SRui Miguel Silva 	[CMD_LRESET]		= REG_FIELD(ISP176x_HC_USBCMD, 7, 7),
1861da9e1c0SRui Miguel Silva 	[CMD_RESET]		= REG_FIELD(ISP176x_HC_USBCMD, 1, 1),
1871da9e1c0SRui Miguel Silva 	[CMD_RUN]		= REG_FIELD(ISP176x_HC_USBCMD, 0, 0),
1881da9e1c0SRui Miguel Silva 	[STS_PCD]		= REG_FIELD(ISP176x_HC_USBSTS, 2, 2),
1891da9e1c0SRui Miguel Silva 	[HC_FRINDEX]		= REG_FIELD(ISP176x_HC_FRINDEX, 0, 13),
1901da9e1c0SRui Miguel Silva 	[FLAG_CF]		= REG_FIELD(ISP176x_HC_CONFIGFLAG, 0, 0),
191*60d789f3SRui Miguel Silva 	[HC_ISO_PTD_DONEMAP]	= REG_FIELD(ISP176x_HC_ISO_PTD_DONEMAP, 0, 31),
192*60d789f3SRui Miguel Silva 	[HC_ISO_PTD_SKIPMAP]	= REG_FIELD(ISP176x_HC_ISO_PTD_SKIPMAP, 0, 31),
193*60d789f3SRui Miguel Silva 	[HC_ISO_PTD_LASTPTD]	= REG_FIELD(ISP176x_HC_ISO_PTD_LASTPTD, 0, 31),
194*60d789f3SRui Miguel Silva 	[HC_INT_PTD_DONEMAP]	= REG_FIELD(ISP176x_HC_INT_PTD_DONEMAP, 0, 31),
195*60d789f3SRui Miguel Silva 	[HC_INT_PTD_SKIPMAP]	= REG_FIELD(ISP176x_HC_INT_PTD_SKIPMAP, 0, 31),
196*60d789f3SRui Miguel Silva 	[HC_INT_PTD_LASTPTD]	= REG_FIELD(ISP176x_HC_INT_PTD_LASTPTD, 0, 31),
197*60d789f3SRui Miguel Silva 	[HC_ATL_PTD_DONEMAP]	= REG_FIELD(ISP176x_HC_ATL_PTD_DONEMAP, 0, 31),
198*60d789f3SRui Miguel Silva 	[HC_ATL_PTD_SKIPMAP]	= REG_FIELD(ISP176x_HC_ATL_PTD_SKIPMAP, 0, 31),
199*60d789f3SRui Miguel Silva 	[HC_ATL_PTD_LASTPTD]	= REG_FIELD(ISP176x_HC_ATL_PTD_LASTPTD, 0, 31),
2001da9e1c0SRui Miguel Silva 	[PORT_OWNER]		= REG_FIELD(ISP176x_HC_PORTSC1, 13, 13),
2011da9e1c0SRui Miguel Silva 	[PORT_POWER]		= REG_FIELD(ISP176x_HC_PORTSC1, 12, 12),
2021da9e1c0SRui Miguel Silva 	[PORT_LSTATUS]		= REG_FIELD(ISP176x_HC_PORTSC1, 10, 11),
2031da9e1c0SRui Miguel Silva 	[PORT_RESET]		= REG_FIELD(ISP176x_HC_PORTSC1, 8, 8),
2041da9e1c0SRui Miguel Silva 	[PORT_SUSPEND]		= REG_FIELD(ISP176x_HC_PORTSC1, 7, 7),
2051da9e1c0SRui Miguel Silva 	[PORT_RESUME]		= REG_FIELD(ISP176x_HC_PORTSC1, 6, 6),
2061da9e1c0SRui Miguel Silva 	[PORT_PE]		= REG_FIELD(ISP176x_HC_PORTSC1, 2, 2),
2071da9e1c0SRui Miguel Silva 	[PORT_CSC]		= REG_FIELD(ISP176x_HC_PORTSC1, 1, 1),
2081da9e1c0SRui Miguel Silva 	[PORT_CONNECT]		= REG_FIELD(ISP176x_HC_PORTSC1, 0, 0),
2091da9e1c0SRui Miguel Silva 	[ALL_ATX_RESET]		= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 31, 31),
2101da9e1c0SRui Miguel Silva 	[HW_ANA_DIGI_OC]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 15, 15),
2111da9e1c0SRui Miguel Silva 	[HW_COMN_IRQ]		= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 10, 10),
2121da9e1c0SRui Miguel Silva 	[HW_DATA_BUS_WIDTH]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 8, 8),
2131da9e1c0SRui Miguel Silva 	[HW_DACK_POL_HIGH]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 6, 6),
2141da9e1c0SRui Miguel Silva 	[HW_DREQ_POL_HIGH]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 5, 5),
2151da9e1c0SRui Miguel Silva 	[HW_INTR_HIGH_ACT]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 2, 2),
2161da9e1c0SRui Miguel Silva 	[HW_INTR_EDGE_TRIG]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 1, 1),
2171da9e1c0SRui Miguel Silva 	[HW_GLOBAL_INTR_EN]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 0, 0),
218*60d789f3SRui Miguel Silva 	[HC_CHIP_REV]		= REG_FIELD(ISP176x_HC_CHIP_ID, 16, 31),
219*60d789f3SRui Miguel Silva 	[HC_CHIP_ID_HIGH]	= REG_FIELD(ISP176x_HC_CHIP_ID, 8, 15),
220*60d789f3SRui Miguel Silva 	[HC_CHIP_ID_LOW]	= REG_FIELD(ISP176x_HC_CHIP_ID, 0, 7),
221*60d789f3SRui Miguel Silva 	[HC_SCRATCH]		= REG_FIELD(ISP176x_HC_SCRATCH, 0, 31),
2221da9e1c0SRui Miguel Silva 	[SW_RESET_RESET_ALL]	= REG_FIELD(ISP176x_HC_RESET, 0, 0),
223*60d789f3SRui Miguel Silva 	[ISO_BUF_FILL]		= REG_FIELD(ISP176x_HC_BUFFER_STATUS, 2, 2),
2241da9e1c0SRui Miguel Silva 	[INT_BUF_FILL]		= REG_FIELD(ISP176x_HC_BUFFER_STATUS, 1, 1),
2251da9e1c0SRui Miguel Silva 	[ATL_BUF_FILL]		= REG_FIELD(ISP176x_HC_BUFFER_STATUS, 0, 0),
2261da9e1c0SRui Miguel Silva 	[MEM_BANK_SEL]		= REG_FIELD(ISP176x_HC_MEMORY, 16, 17),
2271da9e1c0SRui Miguel Silva 	[MEM_START_ADDR]	= REG_FIELD(ISP176x_HC_MEMORY, 0, 15),
228*60d789f3SRui Miguel Silva 	[HC_INTERRUPT]		= REG_FIELD(ISP176x_HC_INTERRUPT, 0, 9),
229*60d789f3SRui Miguel Silva 	[HC_ATL_IRQ_ENABLE]	= REG_FIELD(ISP176x_HC_INTERRUPT_ENABLE, 8, 8),
230*60d789f3SRui Miguel Silva 	[HC_INT_IRQ_ENABLE]	= REG_FIELD(ISP176x_HC_INTERRUPT_ENABLE, 7, 7),
231*60d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_OR]	= REG_FIELD(ISP176x_HC_ISO_IRQ_MASK_OR, 0, 31),
232*60d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_OR]	= REG_FIELD(ISP176x_HC_INT_IRQ_MASK_OR, 0, 31),
233*60d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_OR]	= REG_FIELD(ISP176x_HC_ATL_IRQ_MASK_OR, 0, 31),
234*60d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_AND]	= REG_FIELD(ISP176x_HC_ISO_IRQ_MASK_AND, 0, 31),
235*60d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_AND]	= REG_FIELD(ISP176x_HC_INT_IRQ_MASK_AND, 0, 31),
236*60d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_AND]	= REG_FIELD(ISP176x_HC_ATL_IRQ_MASK_AND, 0, 31),
237*60d789f3SRui Miguel Silva 	[HW_OTG_DISABLE]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 10, 10),
238*60d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 7, 7),
239*60d789f3SRui Miguel Silva 	[HW_VBUS_DRV]		= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 4, 4),
240*60d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT]		= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 3, 3),
241*60d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 2, 2),
242*60d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 1, 1),
243*60d789f3SRui Miguel Silva 	[HW_DP_PULLUP]		= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 0, 0),
244*60d789f3SRui Miguel Silva 	[HW_OTG_DISABLE_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 10, 10),
245*60d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 7, 7),
246*60d789f3SRui Miguel Silva 	[HW_VBUS_DRV_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 4, 4),
247*60d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 3, 3),
248*60d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 2, 2),
249*60d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 1, 1),
250*60d789f3SRui Miguel Silva 	[HW_DP_PULLUP_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 0, 0),
251*60d789f3SRui Miguel Silva };
252*60d789f3SRui Miguel Silva 
253*60d789f3SRui Miguel Silva static const struct reg_field isp1763_hc_reg_fields[] = {
254*60d789f3SRui Miguel Silva 	[CMD_LRESET]		= REG_FIELD(ISP1763_HC_USBCMD, 7, 7),
255*60d789f3SRui Miguel Silva 	[CMD_RESET]		= REG_FIELD(ISP1763_HC_USBCMD, 1, 1),
256*60d789f3SRui Miguel Silva 	[CMD_RUN]		= REG_FIELD(ISP1763_HC_USBCMD, 0, 0),
257*60d789f3SRui Miguel Silva 	[STS_PCD]		= REG_FIELD(ISP1763_HC_USBSTS, 2, 2),
258*60d789f3SRui Miguel Silva 	[HC_FRINDEX]		= REG_FIELD(ISP1763_HC_FRINDEX, 0, 13),
259*60d789f3SRui Miguel Silva 	[FLAG_CF]		= REG_FIELD(ISP1763_HC_CONFIGFLAG, 0, 0),
260*60d789f3SRui Miguel Silva 	[HC_ISO_PTD_DONEMAP]	= REG_FIELD(ISP1763_HC_ISO_PTD_DONEMAP, 0, 15),
261*60d789f3SRui Miguel Silva 	[HC_ISO_PTD_SKIPMAP]	= REG_FIELD(ISP1763_HC_ISO_PTD_SKIPMAP, 0, 15),
262*60d789f3SRui Miguel Silva 	[HC_ISO_PTD_LASTPTD]	= REG_FIELD(ISP1763_HC_ISO_PTD_LASTPTD, 0, 15),
263*60d789f3SRui Miguel Silva 	[HC_INT_PTD_DONEMAP]	= REG_FIELD(ISP1763_HC_INT_PTD_DONEMAP, 0, 15),
264*60d789f3SRui Miguel Silva 	[HC_INT_PTD_SKIPMAP]	= REG_FIELD(ISP1763_HC_INT_PTD_SKIPMAP, 0, 15),
265*60d789f3SRui Miguel Silva 	[HC_INT_PTD_LASTPTD]	= REG_FIELD(ISP1763_HC_INT_PTD_LASTPTD, 0, 15),
266*60d789f3SRui Miguel Silva 	[HC_ATL_PTD_DONEMAP]	= REG_FIELD(ISP1763_HC_ATL_PTD_DONEMAP, 0, 15),
267*60d789f3SRui Miguel Silva 	[HC_ATL_PTD_SKIPMAP]	= REG_FIELD(ISP1763_HC_ATL_PTD_SKIPMAP, 0, 15),
268*60d789f3SRui Miguel Silva 	[HC_ATL_PTD_LASTPTD]	= REG_FIELD(ISP1763_HC_ATL_PTD_LASTPTD, 0, 15),
269*60d789f3SRui Miguel Silva 	[PORT_OWNER]		= REG_FIELD(ISP1763_HC_PORTSC1, 13, 13),
270*60d789f3SRui Miguel Silva 	[PORT_POWER]		= REG_FIELD(ISP1763_HC_PORTSC1, 12, 12),
271*60d789f3SRui Miguel Silva 	[PORT_LSTATUS]		= REG_FIELD(ISP1763_HC_PORTSC1, 10, 11),
272*60d789f3SRui Miguel Silva 	[PORT_RESET]		= REG_FIELD(ISP1763_HC_PORTSC1, 8, 8),
273*60d789f3SRui Miguel Silva 	[PORT_SUSPEND]		= REG_FIELD(ISP1763_HC_PORTSC1, 7, 7),
274*60d789f3SRui Miguel Silva 	[PORT_RESUME]		= REG_FIELD(ISP1763_HC_PORTSC1, 6, 6),
275*60d789f3SRui Miguel Silva 	[PORT_PE]		= REG_FIELD(ISP1763_HC_PORTSC1, 2, 2),
276*60d789f3SRui Miguel Silva 	[PORT_CSC]		= REG_FIELD(ISP1763_HC_PORTSC1, 1, 1),
277*60d789f3SRui Miguel Silva 	[PORT_CONNECT]		= REG_FIELD(ISP1763_HC_PORTSC1, 0, 0),
278*60d789f3SRui Miguel Silva 	[HW_DATA_BUS_WIDTH]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 4, 4),
279*60d789f3SRui Miguel Silva 	[HW_DACK_POL_HIGH]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 6, 6),
280*60d789f3SRui Miguel Silva 	[HW_DREQ_POL_HIGH]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 5, 5),
281*60d789f3SRui Miguel Silva 	[HW_INTF_LOCK]		= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 3, 3),
282*60d789f3SRui Miguel Silva 	[HW_INTR_HIGH_ACT]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 2, 2),
283*60d789f3SRui Miguel Silva 	[HW_INTR_EDGE_TRIG]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 1, 1),
284*60d789f3SRui Miguel Silva 	[HW_GLOBAL_INTR_EN]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 0, 0),
285*60d789f3SRui Miguel Silva 	[SW_RESET_RESET_ATX]	= REG_FIELD(ISP1763_HC_RESET, 3, 3),
286*60d789f3SRui Miguel Silva 	[SW_RESET_RESET_ALL]	= REG_FIELD(ISP1763_HC_RESET, 0, 0),
287*60d789f3SRui Miguel Silva 	[HC_CHIP_ID_HIGH]	= REG_FIELD(ISP1763_HC_CHIP_ID, 0, 15),
288*60d789f3SRui Miguel Silva 	[HC_CHIP_ID_LOW]	= REG_FIELD(ISP1763_HC_CHIP_REV, 8, 15),
289*60d789f3SRui Miguel Silva 	[HC_CHIP_REV]		= REG_FIELD(ISP1763_HC_CHIP_REV, 0, 7),
290*60d789f3SRui Miguel Silva 	[HC_SCRATCH]		= REG_FIELD(ISP1763_HC_SCRATCH, 0, 15),
291*60d789f3SRui Miguel Silva 	[ISO_BUF_FILL]		= REG_FIELD(ISP1763_HC_BUFFER_STATUS, 2, 2),
292*60d789f3SRui Miguel Silva 	[INT_BUF_FILL]		= REG_FIELD(ISP1763_HC_BUFFER_STATUS, 1, 1),
293*60d789f3SRui Miguel Silva 	[ATL_BUF_FILL]		= REG_FIELD(ISP1763_HC_BUFFER_STATUS, 0, 0),
294*60d789f3SRui Miguel Silva 	[MEM_START_ADDR]	= REG_FIELD(ISP1763_HC_MEMORY, 0, 15),
295*60d789f3SRui Miguel Silva 	[HC_DATA]		= REG_FIELD(ISP1763_HC_DATA, 0, 15),
296*60d789f3SRui Miguel Silva 	[HC_INTERRUPT]		= REG_FIELD(ISP1763_HC_INTERRUPT, 0, 10),
297*60d789f3SRui Miguel Silva 	[HC_ATL_IRQ_ENABLE]	= REG_FIELD(ISP1763_HC_INTERRUPT_ENABLE, 8, 8),
298*60d789f3SRui Miguel Silva 	[HC_INT_IRQ_ENABLE]	= REG_FIELD(ISP1763_HC_INTERRUPT_ENABLE, 7, 7),
299*60d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_OR]	= REG_FIELD(ISP1763_HC_ISO_IRQ_MASK_OR, 0, 15),
300*60d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_OR]	= REG_FIELD(ISP1763_HC_INT_IRQ_MASK_OR, 0, 15),
301*60d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_OR]	= REG_FIELD(ISP1763_HC_ATL_IRQ_MASK_OR, 0, 15),
302*60d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_AND]	= REG_FIELD(ISP1763_HC_ISO_IRQ_MASK_AND, 0, 15),
303*60d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_AND]	= REG_FIELD(ISP1763_HC_INT_IRQ_MASK_AND, 0, 15),
304*60d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_AND]	= REG_FIELD(ISP1763_HC_ATL_IRQ_MASK_AND, 0, 15),
305*60d789f3SRui Miguel Silva 	[HW_HC_2_DIS]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 15, 15),
306*60d789f3SRui Miguel Silva 	[HW_OTG_DISABLE]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 10, 10),
307*60d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 7, 7),
308*60d789f3SRui Miguel Silva 	[HW_VBUS_DRV]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 4, 4),
309*60d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 3, 3),
310*60d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 2, 2),
311*60d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 1, 1),
312*60d789f3SRui Miguel Silva 	[HW_DP_PULLUP]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 0, 0),
313*60d789f3SRui Miguel Silva 	[HW_HC_2_DIS_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 15, 15),
314*60d789f3SRui Miguel Silva 	[HW_OTG_DISABLE_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 10, 10),
315*60d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 7, 7),
316*60d789f3SRui Miguel Silva 	[HW_VBUS_DRV_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 4, 4),
317*60d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 3, 3),
318*60d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 2, 2),
319*60d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 1, 1),
320*60d789f3SRui Miguel Silva 	[HW_DP_PULLUP_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 0, 0),
321*60d789f3SRui Miguel Silva };
322*60d789f3SRui Miguel Silva 
323*60d789f3SRui Miguel Silva static const struct regmap_range isp1763_hc_volatile_ranges[] = {
324*60d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_HC_USBCMD, ISP1763_HC_ATL_PTD_LASTPTD),
325*60d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_HC_BUFFER_STATUS, ISP1763_HC_DATA),
326*60d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_HC_INTERRUPT, ISP1763_HC_OTG_CTRL_CLEAR),
327*60d789f3SRui Miguel Silva };
328*60d789f3SRui Miguel Silva 
329*60d789f3SRui Miguel Silva static const struct regmap_access_table isp1763_hc_volatile_table = {
330*60d789f3SRui Miguel Silva 	.yes_ranges	= isp1763_hc_volatile_ranges,
331*60d789f3SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp1763_hc_volatile_ranges),
332*60d789f3SRui Miguel Silva };
333*60d789f3SRui Miguel Silva 
334*60d789f3SRui Miguel Silva static const struct regmap_config isp1763_hc_regmap_conf = {
335*60d789f3SRui Miguel Silva 	.name = "isp1763-hc",
336*60d789f3SRui Miguel Silva 	.reg_bits = 8,
337*60d789f3SRui Miguel Silva 	.reg_stride = 2,
338*60d789f3SRui Miguel Silva 	.val_bits = 16,
339*60d789f3SRui Miguel Silva 	.fast_io = true,
340*60d789f3SRui Miguel Silva 	.max_register = ISP1763_HC_OTG_CTRL_CLEAR,
341*60d789f3SRui Miguel Silva 	.volatile_table = &isp1763_hc_volatile_table,
3421da9e1c0SRui Miguel Silva };
3431da9e1c0SRui Miguel Silva 
3441da9e1c0SRui Miguel Silva static const struct regmap_range isp176x_dc_volatile_ranges[] = {
3451da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_DC_EPMAXPKTSZ, ISP176x_DC_EPTYPE),
3461da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_DC_BUFLEN, ISP176x_DC_EPINDEX),
3471da9e1c0SRui Miguel Silva };
3481da9e1c0SRui Miguel Silva 
3491da9e1c0SRui Miguel Silva static const struct regmap_access_table isp176x_dc_volatile_table = {
3501da9e1c0SRui Miguel Silva 	.yes_ranges	= isp176x_dc_volatile_ranges,
3511da9e1c0SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp176x_dc_volatile_ranges),
3521da9e1c0SRui Miguel Silva };
3531da9e1c0SRui Miguel Silva 
354*60d789f3SRui Miguel Silva static const struct regmap_config isp1761_dc_regmap_conf = {
3551da9e1c0SRui Miguel Silva 	.name = "isp1761-dc",
3561da9e1c0SRui Miguel Silva 	.reg_bits = 16,
3571da9e1c0SRui Miguel Silva 	.reg_stride = 4,
3581da9e1c0SRui Miguel Silva 	.val_bits = 32,
3591da9e1c0SRui Miguel Silva 	.fast_io = true,
360*60d789f3SRui Miguel Silva 	.max_register = ISP176x_DC_TESTMODE,
3611da9e1c0SRui Miguel Silva 	.volatile_table = &isp176x_dc_volatile_table,
3621da9e1c0SRui Miguel Silva };
3631da9e1c0SRui Miguel Silva 
3641da9e1c0SRui Miguel Silva static const struct reg_field isp1761_dc_reg_fields[] = {
3651da9e1c0SRui Miguel Silva 	[DC_DEVEN]		= REG_FIELD(ISP176x_DC_ADDRESS, 7, 7),
3661da9e1c0SRui Miguel Silva 	[DC_DEVADDR]		= REG_FIELD(ISP176x_DC_ADDRESS, 0, 6),
3671da9e1c0SRui Miguel Silva 	[DC_VBUSSTAT]		= REG_FIELD(ISP176x_DC_MODE, 8, 8),
3681da9e1c0SRui Miguel Silva 	[DC_SFRESET]		= REG_FIELD(ISP176x_DC_MODE, 4, 4),
3691da9e1c0SRui Miguel Silva 	[DC_GLINTENA]		= REG_FIELD(ISP176x_DC_MODE, 3, 3),
3701da9e1c0SRui Miguel Silva 	[DC_CDBGMOD_ACK]	= REG_FIELD(ISP176x_DC_INTCONF, 6, 6),
3711da9e1c0SRui Miguel Silva 	[DC_DDBGMODIN_ACK]	= REG_FIELD(ISP176x_DC_INTCONF, 4, 4),
3721da9e1c0SRui Miguel Silva 	[DC_DDBGMODOUT_ACK]	= REG_FIELD(ISP176x_DC_INTCONF, 2, 2),
3731da9e1c0SRui Miguel Silva 	[DC_INTPOL]		= REG_FIELD(ISP176x_DC_INTCONF, 0, 0),
3741da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_7]		= REG_FIELD(ISP176x_DC_INTENABLE, 25, 25),
3751da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_6]		= REG_FIELD(ISP176x_DC_INTENABLE, 23, 23),
3761da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_5]		= REG_FIELD(ISP176x_DC_INTENABLE, 21, 21),
3771da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_4]		= REG_FIELD(ISP176x_DC_INTENABLE, 19, 19),
3781da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_3]		= REG_FIELD(ISP176x_DC_INTENABLE, 17, 17),
3791da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_2]		= REG_FIELD(ISP176x_DC_INTENABLE, 15, 15),
3801da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_1]		= REG_FIELD(ISP176x_DC_INTENABLE, 13, 13),
3811da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_0]		= REG_FIELD(ISP176x_DC_INTENABLE, 11, 11),
3821da9e1c0SRui Miguel Silva 	[DC_IEP0SETUP]		= REG_FIELD(ISP176x_DC_INTENABLE, 8, 8),
3831da9e1c0SRui Miguel Silva 	[DC_IEVBUS]		= REG_FIELD(ISP176x_DC_INTENABLE, 7, 7),
3841da9e1c0SRui Miguel Silva 	[DC_IEHS_STA]		= REG_FIELD(ISP176x_DC_INTENABLE, 5, 5),
3851da9e1c0SRui Miguel Silva 	[DC_IERESM]		= REG_FIELD(ISP176x_DC_INTENABLE, 4, 4),
3861da9e1c0SRui Miguel Silva 	[DC_IESUSP]		= REG_FIELD(ISP176x_DC_INTENABLE, 3, 3),
3871da9e1c0SRui Miguel Silva 	[DC_IEBRST]		= REG_FIELD(ISP176x_DC_INTENABLE, 0, 0),
3881da9e1c0SRui Miguel Silva 	[DC_EP0SETUP]		= REG_FIELD(ISP176x_DC_EPINDEX, 5, 5),
3891da9e1c0SRui Miguel Silva 	[DC_ENDPIDX]		= REG_FIELD(ISP176x_DC_EPINDEX, 1, 4),
3901da9e1c0SRui Miguel Silva 	[DC_EPDIR]		= REG_FIELD(ISP176x_DC_EPINDEX, 0, 0),
3911da9e1c0SRui Miguel Silva 	[DC_CLBUF]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 4, 4),
3921da9e1c0SRui Miguel Silva 	[DC_VENDP]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 3, 3),
3931da9e1c0SRui Miguel Silva 	[DC_DSEN]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 2, 2),
3941da9e1c0SRui Miguel Silva 	[DC_STATUS]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 1, 1),
3951da9e1c0SRui Miguel Silva 	[DC_STALL]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 0, 0),
3961da9e1c0SRui Miguel Silva 	[DC_BUFLEN]		= REG_FIELD(ISP176x_DC_BUFLEN, 0, 15),
3971da9e1c0SRui Miguel Silva 	[DC_FFOSZ]		= REG_FIELD(ISP176x_DC_EPMAXPKTSZ, 0, 10),
3981da9e1c0SRui Miguel Silva 	[DC_EPENABLE]		= REG_FIELD(ISP176x_DC_EPTYPE, 3, 3),
3991da9e1c0SRui Miguel Silva 	[DC_ENDPTYP]		= REG_FIELD(ISP176x_DC_EPTYPE, 0, 1),
4001da9e1c0SRui Miguel Silva 	[DC_UFRAMENUM]		= REG_FIELD(ISP176x_DC_FRAMENUM, 11, 13),
4011da9e1c0SRui Miguel Silva 	[DC_FRAMENUM]		= REG_FIELD(ISP176x_DC_FRAMENUM, 0, 10),
402*60d789f3SRui Miguel Silva 	[DC_CHIP_ID_HIGH]	= REG_FIELD(ISP176x_DC_CHIPID, 16, 31),
403*60d789f3SRui Miguel Silva 	[DC_CHIP_ID_LOW]	= REG_FIELD(ISP176x_DC_CHIPID, 0, 15),
404*60d789f3SRui Miguel Silva 	[DC_SCRATCH]		= REG_FIELD(ISP176x_DC_SCRATCH, 0, 15),
405*60d789f3SRui Miguel Silva };
406*60d789f3SRui Miguel Silva 
407*60d789f3SRui Miguel Silva static const struct regmap_range isp1763_dc_volatile_ranges[] = {
408*60d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_DC_EPMAXPKTSZ, ISP1763_DC_EPTYPE),
409*60d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_DC_BUFLEN, ISP1763_DC_EPINDEX),
410*60d789f3SRui Miguel Silva };
411*60d789f3SRui Miguel Silva 
412*60d789f3SRui Miguel Silva static const struct regmap_access_table isp1763_dc_volatile_table = {
413*60d789f3SRui Miguel Silva 	.yes_ranges	= isp1763_dc_volatile_ranges,
414*60d789f3SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp1763_dc_volatile_ranges),
415*60d789f3SRui Miguel Silva };
416*60d789f3SRui Miguel Silva 
417*60d789f3SRui Miguel Silva static const struct reg_field isp1763_dc_reg_fields[] = {
418*60d789f3SRui Miguel Silva 	[DC_DEVEN]		= REG_FIELD(ISP1763_DC_ADDRESS, 7, 7),
419*60d789f3SRui Miguel Silva 	[DC_DEVADDR]		= REG_FIELD(ISP1763_DC_ADDRESS, 0, 6),
420*60d789f3SRui Miguel Silva 	[DC_VBUSSTAT]		= REG_FIELD(ISP1763_DC_MODE, 8, 8),
421*60d789f3SRui Miguel Silva 	[DC_SFRESET]		= REG_FIELD(ISP1763_DC_MODE, 4, 4),
422*60d789f3SRui Miguel Silva 	[DC_GLINTENA]		= REG_FIELD(ISP1763_DC_MODE, 3, 3),
423*60d789f3SRui Miguel Silva 	[DC_CDBGMOD_ACK]	= REG_FIELD(ISP1763_DC_INTCONF, 6, 6),
424*60d789f3SRui Miguel Silva 	[DC_DDBGMODIN_ACK]	= REG_FIELD(ISP1763_DC_INTCONF, 4, 4),
425*60d789f3SRui Miguel Silva 	[DC_DDBGMODOUT_ACK]	= REG_FIELD(ISP1763_DC_INTCONF, 2, 2),
426*60d789f3SRui Miguel Silva 	[DC_INTPOL]		= REG_FIELD(ISP1763_DC_INTCONF, 0, 0),
427*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_7]		= REG_FIELD(ISP1763_DC_INTENABLE, 25, 25),
428*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_6]		= REG_FIELD(ISP1763_DC_INTENABLE, 23, 23),
429*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_5]		= REG_FIELD(ISP1763_DC_INTENABLE, 21, 21),
430*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_4]		= REG_FIELD(ISP1763_DC_INTENABLE, 19, 19),
431*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_3]		= REG_FIELD(ISP1763_DC_INTENABLE, 17, 17),
432*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_2]		= REG_FIELD(ISP1763_DC_INTENABLE, 15, 15),
433*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_1]		= REG_FIELD(ISP1763_DC_INTENABLE, 13, 13),
434*60d789f3SRui Miguel Silva 	[DC_IEPRXTX_0]		= REG_FIELD(ISP1763_DC_INTENABLE, 11, 11),
435*60d789f3SRui Miguel Silva 	[DC_IEP0SETUP]		= REG_FIELD(ISP1763_DC_INTENABLE, 8, 8),
436*60d789f3SRui Miguel Silva 	[DC_IEVBUS]		= REG_FIELD(ISP1763_DC_INTENABLE, 7, 7),
437*60d789f3SRui Miguel Silva 	[DC_IEHS_STA]		= REG_FIELD(ISP1763_DC_INTENABLE, 5, 5),
438*60d789f3SRui Miguel Silva 	[DC_IERESM]		= REG_FIELD(ISP1763_DC_INTENABLE, 4, 4),
439*60d789f3SRui Miguel Silva 	[DC_IESUSP]		= REG_FIELD(ISP1763_DC_INTENABLE, 3, 3),
440*60d789f3SRui Miguel Silva 	[DC_IEBRST]		= REG_FIELD(ISP1763_DC_INTENABLE, 0, 0),
441*60d789f3SRui Miguel Silva 	[DC_EP0SETUP]		= REG_FIELD(ISP1763_DC_EPINDEX, 5, 5),
442*60d789f3SRui Miguel Silva 	[DC_ENDPIDX]		= REG_FIELD(ISP1763_DC_EPINDEX, 1, 4),
443*60d789f3SRui Miguel Silva 	[DC_EPDIR]		= REG_FIELD(ISP1763_DC_EPINDEX, 0, 0),
444*60d789f3SRui Miguel Silva 	[DC_CLBUF]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 4, 4),
445*60d789f3SRui Miguel Silva 	[DC_VENDP]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 3, 3),
446*60d789f3SRui Miguel Silva 	[DC_DSEN]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 2, 2),
447*60d789f3SRui Miguel Silva 	[DC_STATUS]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 1, 1),
448*60d789f3SRui Miguel Silva 	[DC_STALL]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 0, 0),
449*60d789f3SRui Miguel Silva 	[DC_BUFLEN]		= REG_FIELD(ISP1763_DC_BUFLEN, 0, 15),
450*60d789f3SRui Miguel Silva 	[DC_FFOSZ]		= REG_FIELD(ISP1763_DC_EPMAXPKTSZ, 0, 10),
451*60d789f3SRui Miguel Silva 	[DC_EPENABLE]		= REG_FIELD(ISP1763_DC_EPTYPE, 3, 3),
452*60d789f3SRui Miguel Silva 	[DC_ENDPTYP]		= REG_FIELD(ISP1763_DC_EPTYPE, 0, 1),
453*60d789f3SRui Miguel Silva 	[DC_UFRAMENUM]		= REG_FIELD(ISP1763_DC_FRAMENUM, 11, 13),
454*60d789f3SRui Miguel Silva 	[DC_FRAMENUM]		= REG_FIELD(ISP1763_DC_FRAMENUM, 0, 10),
455*60d789f3SRui Miguel Silva 	[DC_CHIP_ID_HIGH]	= REG_FIELD(ISP1763_DC_CHIPID_HIGH, 0, 15),
456*60d789f3SRui Miguel Silva 	[DC_CHIP_ID_LOW]	= REG_FIELD(ISP1763_DC_CHIPID_LOW, 0, 15),
457*60d789f3SRui Miguel Silva 	[DC_SCRATCH]		= REG_FIELD(ISP1763_DC_SCRATCH, 0, 15),
458*60d789f3SRui Miguel Silva };
459*60d789f3SRui Miguel Silva 
460*60d789f3SRui Miguel Silva static const struct regmap_config isp1763_dc_regmap_conf = {
461*60d789f3SRui Miguel Silva 	.name = "isp1763-dc",
462*60d789f3SRui Miguel Silva 	.reg_bits = 8,
463*60d789f3SRui Miguel Silva 	.reg_stride = 2,
464*60d789f3SRui Miguel Silva 	.val_bits = 16,
465*60d789f3SRui Miguel Silva 	.fast_io = true,
466*60d789f3SRui Miguel Silva 	.max_register = ISP1763_DC_TESTMODE,
467*60d789f3SRui Miguel Silva 	.volatile_table = &isp1763_dc_volatile_table,
4681da9e1c0SRui Miguel Silva };
4691da9e1c0SRui Miguel Silva 
4707ef077a8SLaurent Pinchart int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
4717ef077a8SLaurent Pinchart 		     struct device *dev, unsigned int devflags)
4727ef077a8SLaurent Pinchart {
473*60d789f3SRui Miguel Silva 	bool udc_disabled = !(devflags & ISP1760_FLAG_ISP1761);
474*60d789f3SRui Miguel Silva 	const struct regmap_config *hc_regmap;
475*60d789f3SRui Miguel Silva 	const struct reg_field *hc_reg_fields;
4767ef077a8SLaurent Pinchart 	struct isp1760_device *isp;
4771da9e1c0SRui Miguel Silva 	struct isp1760_hcd *hcd;
4781da9e1c0SRui Miguel Silva 	struct isp1760_udc *udc;
4791da9e1c0SRui Miguel Silva 	struct regmap_field *f;
4807ef077a8SLaurent Pinchart 	int ret;
4811da9e1c0SRui Miguel Silva 	int i;
4827ef077a8SLaurent Pinchart 
483d21daf1eSLaurent Pinchart 	/*
484d21daf1eSLaurent Pinchart 	 * If neither the HCD not the UDC is enabled return an error, as no
485d21daf1eSLaurent Pinchart 	 * device would be registered.
486d21daf1eSLaurent Pinchart 	 */
487d21daf1eSLaurent Pinchart 	if ((!IS_ENABLED(CONFIG_USB_ISP1760_HCD) || usb_disabled()) &&
488d21daf1eSLaurent Pinchart 	    (!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || udc_disabled))
4897ef077a8SLaurent Pinchart 		return -ENODEV;
4907ef077a8SLaurent Pinchart 
4917ef077a8SLaurent Pinchart 	isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL);
4927ef077a8SLaurent Pinchart 	if (!isp)
4937ef077a8SLaurent Pinchart 		return -ENOMEM;
4947ef077a8SLaurent Pinchart 
4957ef077a8SLaurent Pinchart 	isp->dev = dev;
4967ef077a8SLaurent Pinchart 	isp->devflags = devflags;
4971da9e1c0SRui Miguel Silva 	hcd = &isp->hcd;
4981da9e1c0SRui Miguel Silva 	udc = &isp->udc;
4991da9e1c0SRui Miguel Silva 
500*60d789f3SRui Miguel Silva 	hcd->is_isp1763 = !!(devflags & ISP1760_FLAG_ISP1763);
501*60d789f3SRui Miguel Silva 
502*60d789f3SRui Miguel Silva 	if (!hcd->is_isp1763 && (devflags & ISP1760_FLAG_BUS_WIDTH_8)) {
503*60d789f3SRui Miguel Silva 		dev_err(dev, "isp1760/61 do not support data width 8\n");
504*60d789f3SRui Miguel Silva 		return -EINVAL;
505*60d789f3SRui Miguel Silva 	}
506*60d789f3SRui Miguel Silva 
507*60d789f3SRui Miguel Silva 	if (hcd->is_isp1763) {
508*60d789f3SRui Miguel Silva 		hc_regmap = &isp1763_hc_regmap_conf;
509*60d789f3SRui Miguel Silva 		hc_reg_fields = &isp1763_hc_reg_fields[0];
510*60d789f3SRui Miguel Silva 	} else {
511*60d789f3SRui Miguel Silva 		hc_regmap = &isp1760_hc_regmap_conf;
512*60d789f3SRui Miguel Silva 		hc_reg_fields = &isp1760_hc_reg_fields[0];
5131da9e1c0SRui Miguel Silva 	}
5147ef077a8SLaurent Pinchart 
5157ef077a8SLaurent Pinchart 	isp->rst_gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
5167ef077a8SLaurent Pinchart 	if (IS_ERR(isp->rst_gpio))
5177ef077a8SLaurent Pinchart 		return PTR_ERR(isp->rst_gpio);
5187ef077a8SLaurent Pinchart 
5191da9e1c0SRui Miguel Silva 	hcd->base = devm_ioremap_resource(dev, mem);
5201da9e1c0SRui Miguel Silva 	if (IS_ERR(hcd->base))
5211da9e1c0SRui Miguel Silva 		return PTR_ERR(hcd->base);
5221da9e1c0SRui Miguel Silva 
523*60d789f3SRui Miguel Silva 	hcd->regs = devm_regmap_init_mmio(dev, hcd->base, hc_regmap);
5241da9e1c0SRui Miguel Silva 	if (IS_ERR(hcd->regs))
5251da9e1c0SRui Miguel Silva 		return PTR_ERR(hcd->regs);
5261da9e1c0SRui Miguel Silva 
5271da9e1c0SRui Miguel Silva 	for (i = 0; i < HC_FIELD_MAX; i++) {
528*60d789f3SRui Miguel Silva 		f = devm_regmap_field_alloc(dev, hcd->regs, hc_reg_fields[i]);
5291da9e1c0SRui Miguel Silva 		if (IS_ERR(f))
5301da9e1c0SRui Miguel Silva 			return PTR_ERR(f);
5311da9e1c0SRui Miguel Silva 
5321da9e1c0SRui Miguel Silva 		hcd->fields[i] = f;
5331da9e1c0SRui Miguel Silva 	}
5341da9e1c0SRui Miguel Silva 
535*60d789f3SRui Miguel Silva 	udc->regs = devm_regmap_init_mmio(dev, hcd->base,
536*60d789f3SRui Miguel Silva 					  &isp1761_dc_regmap_conf);
5371da9e1c0SRui Miguel Silva 	if (IS_ERR(udc->regs))
5381da9e1c0SRui Miguel Silva 		return PTR_ERR(udc->regs);
5391da9e1c0SRui Miguel Silva 
5401da9e1c0SRui Miguel Silva 	for (i = 0; i < DC_FIELD_MAX; i++) {
5411da9e1c0SRui Miguel Silva 		f = devm_regmap_field_alloc(dev, udc->regs,
5421da9e1c0SRui Miguel Silva 					    isp1761_dc_reg_fields[i]);
5431da9e1c0SRui Miguel Silva 		if (IS_ERR(f))
5441da9e1c0SRui Miguel Silva 			return PTR_ERR(f);
5451da9e1c0SRui Miguel Silva 
5461da9e1c0SRui Miguel Silva 		udc->fields[i] = f;
5471da9e1c0SRui Miguel Silva 	}
5487ef077a8SLaurent Pinchart 
549*60d789f3SRui Miguel Silva 	if (hcd->is_isp1763)
550*60d789f3SRui Miguel Silva 		hcd->memory_layout = &isp1763_memory_conf;
551*60d789f3SRui Miguel Silva 	else
552a74f639cSRui Miguel Silva 		hcd->memory_layout = &isp176x_memory_conf;
553a74f639cSRui Miguel Silva 
554*60d789f3SRui Miguel Silva 	ret = isp1760_init_core(isp);
555*60d789f3SRui Miguel Silva 	if (ret < 0)
556*60d789f3SRui Miguel Silva 		return ret;
5577ef077a8SLaurent Pinchart 
558d21daf1eSLaurent Pinchart 	if (IS_ENABLED(CONFIG_USB_ISP1760_HCD) && !usb_disabled()) {
5591da9e1c0SRui Miguel Silva 		ret = isp1760_hcd_register(hcd, mem, irq,
5607ef077a8SLaurent Pinchart 					   irqflags | IRQF_SHARED, dev);
5617ef077a8SLaurent Pinchart 		if (ret < 0)
5627ef077a8SLaurent Pinchart 			return ret;
563d21daf1eSLaurent Pinchart 	}
5647ef077a8SLaurent Pinchart 
565d21daf1eSLaurent Pinchart 	if (IS_ENABLED(CONFIG_USB_ISP1761_UDC) && !udc_disabled) {
56680b4a0f8SValentin Rothberg 		ret = isp1760_udc_register(isp, irq, irqflags);
5677ef077a8SLaurent Pinchart 		if (ret < 0) {
5681da9e1c0SRui Miguel Silva 			isp1760_hcd_unregister(hcd);
5697ef077a8SLaurent Pinchart 			return ret;
5707ef077a8SLaurent Pinchart 		}
5717ef077a8SLaurent Pinchart 	}
5727ef077a8SLaurent Pinchart 
5737ef077a8SLaurent Pinchart 	dev_set_drvdata(dev, isp);
5747ef077a8SLaurent Pinchart 
5757ef077a8SLaurent Pinchart 	return 0;
5767ef077a8SLaurent Pinchart }
5777ef077a8SLaurent Pinchart 
5787ef077a8SLaurent Pinchart void isp1760_unregister(struct device *dev)
5797ef077a8SLaurent Pinchart {
5807ef077a8SLaurent Pinchart 	struct isp1760_device *isp = dev_get_drvdata(dev);
5817ef077a8SLaurent Pinchart 
5827ef077a8SLaurent Pinchart 	isp1760_udc_unregister(isp);
5837ef077a8SLaurent Pinchart 	isp1760_hcd_unregister(&isp->hcd);
5847ef077a8SLaurent Pinchart }
5857ef077a8SLaurent Pinchart 
5867ef077a8SLaurent Pinchart MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
5877ef077a8SLaurent Pinchart MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>");
5887ef077a8SLaurent Pinchart MODULE_LICENSE("GPL v2");
589