xref: /linux/drivers/usb/isp1760/isp1760-core.c (revision d369c9187c1897ce5339716354ce47b2c2f67352)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
27ef077a8SLaurent Pinchart /*
37ef077a8SLaurent Pinchart  * Driver for the NXP ISP1760 chip
47ef077a8SLaurent Pinchart  *
560d789f3SRui 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>
1260d789f3SRui 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 
2960d789f3SRui 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 */
4960d789f3SRui Miguel Silva 	if ((isp->devflags & ISP1760_FLAG_ANALOG_OC) && hcd->is_isp1763) {
5060d789f3SRui Miguel Silva 		dev_err(isp->dev, "isp1763 analog overcurrent not available\n");
5160d789f3SRui Miguel Silva 		return -EINVAL;
5260d789f3SRui Miguel Silva 	}
5360d789f3SRui Miguel Silva 
547ef077a8SLaurent Pinchart 	if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_16)
551da9e1c0SRui Miguel Silva 		isp1760_field_clear(hcd->fields, HW_DATA_BUS_WIDTH);
5660d789f3SRui Miguel Silva 	if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_8)
5760d789f3SRui 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 	 */
86*d369c918SRui Miguel Silva 	if (((isp->devflags & ISP1760_FLAG_ISP1761) ||
87*d369c918SRui Miguel Silva 	     (isp->devflags & ISP1760_FLAG_ISP1763)) &&
883eb96e04SRui Miguel Silva 	    (isp->devflags & ISP1760_FLAG_PERIPHERAL_EN)) {
891da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_DM_PULLDOWN);
901da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_DP_PULLDOWN);
911da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_OTG_DISABLE);
921da9e1c0SRui Miguel Silva 	} else {
931da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_SW_SEL_HC_DC);
941da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_VBUS_DRV);
951da9e1c0SRui Miguel Silva 		isp1760_field_set(hcd->fields, HW_SEL_CP_EXT);
961da9e1c0SRui Miguel Silva 	}
977ef077a8SLaurent Pinchart 
9860d789f3SRui Miguel Silva 	dev_info(isp->dev, "%s bus width: %u, oc: %s\n",
9960d789f3SRui Miguel Silva 		 hcd->is_isp1763 ? "isp1763" : "isp1760",
10060d789f3SRui Miguel Silva 		 isp->devflags & ISP1760_FLAG_BUS_WIDTH_8 ? 8 :
1017ef077a8SLaurent Pinchart 		 isp->devflags & ISP1760_FLAG_BUS_WIDTH_16 ? 16 : 32,
10260d789f3SRui Miguel Silva 		 hcd->is_isp1763 ? "not available" :
1037ef077a8SLaurent Pinchart 		 isp->devflags & ISP1760_FLAG_ANALOG_OC ? "analog" : "digital");
10460d789f3SRui Miguel Silva 
10560d789f3SRui Miguel Silva 	return 0;
1067ef077a8SLaurent Pinchart }
1077ef077a8SLaurent Pinchart 
1087ef077a8SLaurent Pinchart void isp1760_set_pullup(struct isp1760_device *isp, bool enable)
1097ef077a8SLaurent Pinchart {
1101da9e1c0SRui Miguel Silva 	struct isp1760_udc *udc = &isp->udc;
1111da9e1c0SRui Miguel Silva 
1121da9e1c0SRui Miguel Silva 	if (enable)
1131da9e1c0SRui Miguel Silva 		isp1760_field_set(udc->fields, HW_DP_PULLUP);
1141da9e1c0SRui Miguel Silva 	else
1151da9e1c0SRui Miguel Silva 		isp1760_field_set(udc->fields, HW_DP_PULLUP_CLEAR);
1167ef077a8SLaurent Pinchart }
1177ef077a8SLaurent Pinchart 
118a74f639cSRui Miguel Silva /*
11960d789f3SRui Miguel Silva  * ISP1760/61:
12060d789f3SRui Miguel Silva  *
121a74f639cSRui Miguel Silva  * 60kb divided in:
122a74f639cSRui Miguel Silva  * - 32 blocks @ 256  bytes
123a74f639cSRui Miguel Silva  * - 20 blocks @ 1024 bytes
124a74f639cSRui Miguel Silva  * -  4 blocks @ 8192 bytes
125a74f639cSRui Miguel Silva  */
126a74f639cSRui Miguel Silva static const struct isp1760_memory_layout isp176x_memory_conf = {
127a74f639cSRui Miguel Silva 	.blocks[0]		= 32,
128a74f639cSRui Miguel Silva 	.blocks_size[0]		= 256,
129a74f639cSRui Miguel Silva 	.blocks[1]		= 20,
130a74f639cSRui Miguel Silva 	.blocks_size[1]		= 1024,
131a74f639cSRui Miguel Silva 	.blocks[2]		= 4,
132a74f639cSRui Miguel Silva 	.blocks_size[2]		= 8192,
133a74f639cSRui Miguel Silva 
13460d789f3SRui Miguel Silva 	.slot_num		= 32,
135a74f639cSRui Miguel Silva 	.payload_blocks		= 32 + 20 + 4,
136a74f639cSRui Miguel Silva 	.payload_area_size	= 0xf000,
137a74f639cSRui Miguel Silva };
138a74f639cSRui Miguel Silva 
13960d789f3SRui Miguel Silva /*
14060d789f3SRui Miguel Silva  * ISP1763:
14160d789f3SRui Miguel Silva  *
14260d789f3SRui Miguel Silva  * 20kb divided in:
14360d789f3SRui Miguel Silva  * - 8 blocks @ 256  bytes
14460d789f3SRui Miguel Silva  * - 2 blocks @ 1024 bytes
14560d789f3SRui Miguel Silva  * - 4 blocks @ 4096 bytes
14660d789f3SRui Miguel Silva  */
14760d789f3SRui Miguel Silva static const struct isp1760_memory_layout isp1763_memory_conf = {
14860d789f3SRui Miguel Silva 	.blocks[0]		= 8,
14960d789f3SRui Miguel Silva 	.blocks_size[0]		= 256,
15060d789f3SRui Miguel Silva 	.blocks[1]		= 2,
15160d789f3SRui Miguel Silva 	.blocks_size[1]		= 1024,
15260d789f3SRui Miguel Silva 	.blocks[2]		= 4,
15360d789f3SRui Miguel Silva 	.blocks_size[2]		= 4096,
15460d789f3SRui Miguel Silva 
15560d789f3SRui Miguel Silva 	.slot_num		= 16,
15660d789f3SRui Miguel Silva 	.payload_blocks		= 8 + 2 + 4,
15760d789f3SRui Miguel Silva 	.payload_area_size	= 0x5000,
15860d789f3SRui Miguel Silva };
15960d789f3SRui Miguel Silva 
1601da9e1c0SRui Miguel Silva static const struct regmap_range isp176x_hc_volatile_ranges[] = {
1611da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_HC_USBCMD, ISP176x_HC_ATL_PTD_LASTPTD),
1621da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_HC_BUFFER_STATUS, ISP176x_HC_MEMORY),
16360d789f3SRui Miguel Silva 	regmap_reg_range(ISP176x_HC_INTERRUPT, ISP176x_HC_OTG_CTRL_CLEAR),
1641da9e1c0SRui Miguel Silva };
1651da9e1c0SRui Miguel Silva 
1661da9e1c0SRui Miguel Silva static const struct regmap_access_table isp176x_hc_volatile_table = {
1671da9e1c0SRui Miguel Silva 	.yes_ranges	= isp176x_hc_volatile_ranges,
1681da9e1c0SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp176x_hc_volatile_ranges),
1691da9e1c0SRui Miguel Silva };
1701da9e1c0SRui Miguel Silva 
17160d789f3SRui Miguel Silva static const struct regmap_config isp1760_hc_regmap_conf = {
1721da9e1c0SRui Miguel Silva 	.name = "isp1760-hc",
1731da9e1c0SRui Miguel Silva 	.reg_bits = 16,
1741da9e1c0SRui Miguel Silva 	.reg_stride = 4,
1751da9e1c0SRui Miguel Silva 	.val_bits = 32,
1761da9e1c0SRui Miguel Silva 	.fast_io = true,
17760d789f3SRui Miguel Silva 	.max_register = ISP176x_HC_OTG_CTRL_CLEAR,
1781da9e1c0SRui Miguel Silva 	.volatile_table = &isp176x_hc_volatile_table,
1791da9e1c0SRui Miguel Silva };
1801da9e1c0SRui Miguel Silva 
1811da9e1c0SRui Miguel Silva static const struct reg_field isp1760_hc_reg_fields[] = {
1821da9e1c0SRui Miguel Silva 	[HCS_PPC]		= REG_FIELD(ISP176x_HC_HCSPARAMS, 4, 4),
1831da9e1c0SRui Miguel Silva 	[HCS_N_PORTS]		= REG_FIELD(ISP176x_HC_HCSPARAMS, 0, 3),
1841da9e1c0SRui Miguel Silva 	[HCC_ISOC_CACHE]	= REG_FIELD(ISP176x_HC_HCCPARAMS, 7, 7),
1851da9e1c0SRui Miguel Silva 	[HCC_ISOC_THRES]	= REG_FIELD(ISP176x_HC_HCCPARAMS, 4, 6),
1861da9e1c0SRui Miguel Silva 	[CMD_LRESET]		= REG_FIELD(ISP176x_HC_USBCMD, 7, 7),
1871da9e1c0SRui Miguel Silva 	[CMD_RESET]		= REG_FIELD(ISP176x_HC_USBCMD, 1, 1),
1881da9e1c0SRui Miguel Silva 	[CMD_RUN]		= REG_FIELD(ISP176x_HC_USBCMD, 0, 0),
1891da9e1c0SRui Miguel Silva 	[STS_PCD]		= REG_FIELD(ISP176x_HC_USBSTS, 2, 2),
1901da9e1c0SRui Miguel Silva 	[HC_FRINDEX]		= REG_FIELD(ISP176x_HC_FRINDEX, 0, 13),
1911da9e1c0SRui Miguel Silva 	[FLAG_CF]		= REG_FIELD(ISP176x_HC_CONFIGFLAG, 0, 0),
19260d789f3SRui Miguel Silva 	[HC_ISO_PTD_DONEMAP]	= REG_FIELD(ISP176x_HC_ISO_PTD_DONEMAP, 0, 31),
19360d789f3SRui Miguel Silva 	[HC_ISO_PTD_SKIPMAP]	= REG_FIELD(ISP176x_HC_ISO_PTD_SKIPMAP, 0, 31),
19460d789f3SRui Miguel Silva 	[HC_ISO_PTD_LASTPTD]	= REG_FIELD(ISP176x_HC_ISO_PTD_LASTPTD, 0, 31),
19560d789f3SRui Miguel Silva 	[HC_INT_PTD_DONEMAP]	= REG_FIELD(ISP176x_HC_INT_PTD_DONEMAP, 0, 31),
19660d789f3SRui Miguel Silva 	[HC_INT_PTD_SKIPMAP]	= REG_FIELD(ISP176x_HC_INT_PTD_SKIPMAP, 0, 31),
19760d789f3SRui Miguel Silva 	[HC_INT_PTD_LASTPTD]	= REG_FIELD(ISP176x_HC_INT_PTD_LASTPTD, 0, 31),
19860d789f3SRui Miguel Silva 	[HC_ATL_PTD_DONEMAP]	= REG_FIELD(ISP176x_HC_ATL_PTD_DONEMAP, 0, 31),
19960d789f3SRui Miguel Silva 	[HC_ATL_PTD_SKIPMAP]	= REG_FIELD(ISP176x_HC_ATL_PTD_SKIPMAP, 0, 31),
20060d789f3SRui Miguel Silva 	[HC_ATL_PTD_LASTPTD]	= REG_FIELD(ISP176x_HC_ATL_PTD_LASTPTD, 0, 31),
2011da9e1c0SRui Miguel Silva 	[PORT_OWNER]		= REG_FIELD(ISP176x_HC_PORTSC1, 13, 13),
2021da9e1c0SRui Miguel Silva 	[PORT_POWER]		= REG_FIELD(ISP176x_HC_PORTSC1, 12, 12),
2031da9e1c0SRui Miguel Silva 	[PORT_LSTATUS]		= REG_FIELD(ISP176x_HC_PORTSC1, 10, 11),
2041da9e1c0SRui Miguel Silva 	[PORT_RESET]		= REG_FIELD(ISP176x_HC_PORTSC1, 8, 8),
2051da9e1c0SRui Miguel Silva 	[PORT_SUSPEND]		= REG_FIELD(ISP176x_HC_PORTSC1, 7, 7),
2061da9e1c0SRui Miguel Silva 	[PORT_RESUME]		= REG_FIELD(ISP176x_HC_PORTSC1, 6, 6),
2071da9e1c0SRui Miguel Silva 	[PORT_PE]		= REG_FIELD(ISP176x_HC_PORTSC1, 2, 2),
2081da9e1c0SRui Miguel Silva 	[PORT_CSC]		= REG_FIELD(ISP176x_HC_PORTSC1, 1, 1),
2091da9e1c0SRui Miguel Silva 	[PORT_CONNECT]		= REG_FIELD(ISP176x_HC_PORTSC1, 0, 0),
2101da9e1c0SRui Miguel Silva 	[ALL_ATX_RESET]		= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 31, 31),
2111da9e1c0SRui Miguel Silva 	[HW_ANA_DIGI_OC]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 15, 15),
2121da9e1c0SRui Miguel Silva 	[HW_COMN_IRQ]		= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 10, 10),
2131da9e1c0SRui Miguel Silva 	[HW_DATA_BUS_WIDTH]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 8, 8),
2141da9e1c0SRui Miguel Silva 	[HW_DACK_POL_HIGH]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 6, 6),
2151da9e1c0SRui Miguel Silva 	[HW_DREQ_POL_HIGH]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 5, 5),
2161da9e1c0SRui Miguel Silva 	[HW_INTR_HIGH_ACT]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 2, 2),
2171da9e1c0SRui Miguel Silva 	[HW_INTR_EDGE_TRIG]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 1, 1),
2181da9e1c0SRui Miguel Silva 	[HW_GLOBAL_INTR_EN]	= REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 0, 0),
21960d789f3SRui Miguel Silva 	[HC_CHIP_REV]		= REG_FIELD(ISP176x_HC_CHIP_ID, 16, 31),
22060d789f3SRui Miguel Silva 	[HC_CHIP_ID_HIGH]	= REG_FIELD(ISP176x_HC_CHIP_ID, 8, 15),
22160d789f3SRui Miguel Silva 	[HC_CHIP_ID_LOW]	= REG_FIELD(ISP176x_HC_CHIP_ID, 0, 7),
22260d789f3SRui Miguel Silva 	[HC_SCRATCH]		= REG_FIELD(ISP176x_HC_SCRATCH, 0, 31),
2231da9e1c0SRui Miguel Silva 	[SW_RESET_RESET_ALL]	= REG_FIELD(ISP176x_HC_RESET, 0, 0),
22460d789f3SRui Miguel Silva 	[ISO_BUF_FILL]		= REG_FIELD(ISP176x_HC_BUFFER_STATUS, 2, 2),
2251da9e1c0SRui Miguel Silva 	[INT_BUF_FILL]		= REG_FIELD(ISP176x_HC_BUFFER_STATUS, 1, 1),
2261da9e1c0SRui Miguel Silva 	[ATL_BUF_FILL]		= REG_FIELD(ISP176x_HC_BUFFER_STATUS, 0, 0),
2271da9e1c0SRui Miguel Silva 	[MEM_BANK_SEL]		= REG_FIELD(ISP176x_HC_MEMORY, 16, 17),
2281da9e1c0SRui Miguel Silva 	[MEM_START_ADDR]	= REG_FIELD(ISP176x_HC_MEMORY, 0, 15),
22960d789f3SRui Miguel Silva 	[HC_INTERRUPT]		= REG_FIELD(ISP176x_HC_INTERRUPT, 0, 9),
23060d789f3SRui Miguel Silva 	[HC_ATL_IRQ_ENABLE]	= REG_FIELD(ISP176x_HC_INTERRUPT_ENABLE, 8, 8),
23160d789f3SRui Miguel Silva 	[HC_INT_IRQ_ENABLE]	= REG_FIELD(ISP176x_HC_INTERRUPT_ENABLE, 7, 7),
23260d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_OR]	= REG_FIELD(ISP176x_HC_ISO_IRQ_MASK_OR, 0, 31),
23360d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_OR]	= REG_FIELD(ISP176x_HC_INT_IRQ_MASK_OR, 0, 31),
23460d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_OR]	= REG_FIELD(ISP176x_HC_ATL_IRQ_MASK_OR, 0, 31),
23560d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_AND]	= REG_FIELD(ISP176x_HC_ISO_IRQ_MASK_AND, 0, 31),
23660d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_AND]	= REG_FIELD(ISP176x_HC_INT_IRQ_MASK_AND, 0, 31),
23760d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_AND]	= REG_FIELD(ISP176x_HC_ATL_IRQ_MASK_AND, 0, 31),
23860d789f3SRui Miguel Silva 	[HW_OTG_DISABLE]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 10, 10),
23960d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 7, 7),
24060d789f3SRui Miguel Silva 	[HW_VBUS_DRV]		= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 4, 4),
24160d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT]		= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 3, 3),
24260d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 2, 2),
24360d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN]	= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 1, 1),
24460d789f3SRui Miguel Silva 	[HW_DP_PULLUP]		= REG_FIELD(ISP176x_HC_OTG_CTRL_SET, 0, 0),
24560d789f3SRui Miguel Silva 	[HW_OTG_DISABLE_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 10, 10),
24660d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 7, 7),
24760d789f3SRui Miguel Silva 	[HW_VBUS_DRV_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 4, 4),
24860d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 3, 3),
24960d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 2, 2),
25060d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 1, 1),
25160d789f3SRui Miguel Silva 	[HW_DP_PULLUP_CLEAR]	= REG_FIELD(ISP176x_HC_OTG_CTRL_CLEAR, 0, 0),
25260d789f3SRui Miguel Silva };
25360d789f3SRui Miguel Silva 
25460d789f3SRui Miguel Silva static const struct reg_field isp1763_hc_reg_fields[] = {
25560d789f3SRui Miguel Silva 	[CMD_LRESET]		= REG_FIELD(ISP1763_HC_USBCMD, 7, 7),
25660d789f3SRui Miguel Silva 	[CMD_RESET]		= REG_FIELD(ISP1763_HC_USBCMD, 1, 1),
25760d789f3SRui Miguel Silva 	[CMD_RUN]		= REG_FIELD(ISP1763_HC_USBCMD, 0, 0),
25860d789f3SRui Miguel Silva 	[STS_PCD]		= REG_FIELD(ISP1763_HC_USBSTS, 2, 2),
25960d789f3SRui Miguel Silva 	[HC_FRINDEX]		= REG_FIELD(ISP1763_HC_FRINDEX, 0, 13),
26060d789f3SRui Miguel Silva 	[FLAG_CF]		= REG_FIELD(ISP1763_HC_CONFIGFLAG, 0, 0),
26160d789f3SRui Miguel Silva 	[HC_ISO_PTD_DONEMAP]	= REG_FIELD(ISP1763_HC_ISO_PTD_DONEMAP, 0, 15),
26260d789f3SRui Miguel Silva 	[HC_ISO_PTD_SKIPMAP]	= REG_FIELD(ISP1763_HC_ISO_PTD_SKIPMAP, 0, 15),
26360d789f3SRui Miguel Silva 	[HC_ISO_PTD_LASTPTD]	= REG_FIELD(ISP1763_HC_ISO_PTD_LASTPTD, 0, 15),
26460d789f3SRui Miguel Silva 	[HC_INT_PTD_DONEMAP]	= REG_FIELD(ISP1763_HC_INT_PTD_DONEMAP, 0, 15),
26560d789f3SRui Miguel Silva 	[HC_INT_PTD_SKIPMAP]	= REG_FIELD(ISP1763_HC_INT_PTD_SKIPMAP, 0, 15),
26660d789f3SRui Miguel Silva 	[HC_INT_PTD_LASTPTD]	= REG_FIELD(ISP1763_HC_INT_PTD_LASTPTD, 0, 15),
26760d789f3SRui Miguel Silva 	[HC_ATL_PTD_DONEMAP]	= REG_FIELD(ISP1763_HC_ATL_PTD_DONEMAP, 0, 15),
26860d789f3SRui Miguel Silva 	[HC_ATL_PTD_SKIPMAP]	= REG_FIELD(ISP1763_HC_ATL_PTD_SKIPMAP, 0, 15),
26960d789f3SRui Miguel Silva 	[HC_ATL_PTD_LASTPTD]	= REG_FIELD(ISP1763_HC_ATL_PTD_LASTPTD, 0, 15),
27060d789f3SRui Miguel Silva 	[PORT_OWNER]		= REG_FIELD(ISP1763_HC_PORTSC1, 13, 13),
27160d789f3SRui Miguel Silva 	[PORT_POWER]		= REG_FIELD(ISP1763_HC_PORTSC1, 12, 12),
27260d789f3SRui Miguel Silva 	[PORT_LSTATUS]		= REG_FIELD(ISP1763_HC_PORTSC1, 10, 11),
27360d789f3SRui Miguel Silva 	[PORT_RESET]		= REG_FIELD(ISP1763_HC_PORTSC1, 8, 8),
27460d789f3SRui Miguel Silva 	[PORT_SUSPEND]		= REG_FIELD(ISP1763_HC_PORTSC1, 7, 7),
27560d789f3SRui Miguel Silva 	[PORT_RESUME]		= REG_FIELD(ISP1763_HC_PORTSC1, 6, 6),
27660d789f3SRui Miguel Silva 	[PORT_PE]		= REG_FIELD(ISP1763_HC_PORTSC1, 2, 2),
27760d789f3SRui Miguel Silva 	[PORT_CSC]		= REG_FIELD(ISP1763_HC_PORTSC1, 1, 1),
27860d789f3SRui Miguel Silva 	[PORT_CONNECT]		= REG_FIELD(ISP1763_HC_PORTSC1, 0, 0),
27960d789f3SRui Miguel Silva 	[HW_DATA_BUS_WIDTH]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 4, 4),
28060d789f3SRui Miguel Silva 	[HW_DACK_POL_HIGH]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 6, 6),
28160d789f3SRui Miguel Silva 	[HW_DREQ_POL_HIGH]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 5, 5),
28260d789f3SRui Miguel Silva 	[HW_INTF_LOCK]		= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 3, 3),
28360d789f3SRui Miguel Silva 	[HW_INTR_HIGH_ACT]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 2, 2),
28460d789f3SRui Miguel Silva 	[HW_INTR_EDGE_TRIG]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 1, 1),
28560d789f3SRui Miguel Silva 	[HW_GLOBAL_INTR_EN]	= REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 0, 0),
28660d789f3SRui Miguel Silva 	[SW_RESET_RESET_ATX]	= REG_FIELD(ISP1763_HC_RESET, 3, 3),
28760d789f3SRui Miguel Silva 	[SW_RESET_RESET_ALL]	= REG_FIELD(ISP1763_HC_RESET, 0, 0),
28860d789f3SRui Miguel Silva 	[HC_CHIP_ID_HIGH]	= REG_FIELD(ISP1763_HC_CHIP_ID, 0, 15),
28960d789f3SRui Miguel Silva 	[HC_CHIP_ID_LOW]	= REG_FIELD(ISP1763_HC_CHIP_REV, 8, 15),
29060d789f3SRui Miguel Silva 	[HC_CHIP_REV]		= REG_FIELD(ISP1763_HC_CHIP_REV, 0, 7),
29160d789f3SRui Miguel Silva 	[HC_SCRATCH]		= REG_FIELD(ISP1763_HC_SCRATCH, 0, 15),
29260d789f3SRui Miguel Silva 	[ISO_BUF_FILL]		= REG_FIELD(ISP1763_HC_BUFFER_STATUS, 2, 2),
29360d789f3SRui Miguel Silva 	[INT_BUF_FILL]		= REG_FIELD(ISP1763_HC_BUFFER_STATUS, 1, 1),
29460d789f3SRui Miguel Silva 	[ATL_BUF_FILL]		= REG_FIELD(ISP1763_HC_BUFFER_STATUS, 0, 0),
29560d789f3SRui Miguel Silva 	[MEM_START_ADDR]	= REG_FIELD(ISP1763_HC_MEMORY, 0, 15),
29660d789f3SRui Miguel Silva 	[HC_DATA]		= REG_FIELD(ISP1763_HC_DATA, 0, 15),
29760d789f3SRui Miguel Silva 	[HC_INTERRUPT]		= REG_FIELD(ISP1763_HC_INTERRUPT, 0, 10),
29860d789f3SRui Miguel Silva 	[HC_ATL_IRQ_ENABLE]	= REG_FIELD(ISP1763_HC_INTERRUPT_ENABLE, 8, 8),
29960d789f3SRui Miguel Silva 	[HC_INT_IRQ_ENABLE]	= REG_FIELD(ISP1763_HC_INTERRUPT_ENABLE, 7, 7),
30060d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_OR]	= REG_FIELD(ISP1763_HC_ISO_IRQ_MASK_OR, 0, 15),
30160d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_OR]	= REG_FIELD(ISP1763_HC_INT_IRQ_MASK_OR, 0, 15),
30260d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_OR]	= REG_FIELD(ISP1763_HC_ATL_IRQ_MASK_OR, 0, 15),
30360d789f3SRui Miguel Silva 	[HC_ISO_IRQ_MASK_AND]	= REG_FIELD(ISP1763_HC_ISO_IRQ_MASK_AND, 0, 15),
30460d789f3SRui Miguel Silva 	[HC_INT_IRQ_MASK_AND]	= REG_FIELD(ISP1763_HC_INT_IRQ_MASK_AND, 0, 15),
30560d789f3SRui Miguel Silva 	[HC_ATL_IRQ_MASK_AND]	= REG_FIELD(ISP1763_HC_ATL_IRQ_MASK_AND, 0, 15),
30660d789f3SRui Miguel Silva 	[HW_HC_2_DIS]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 15, 15),
30760d789f3SRui Miguel Silva 	[HW_OTG_DISABLE]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 10, 10),
30860d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 7, 7),
30960d789f3SRui Miguel Silva 	[HW_VBUS_DRV]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 4, 4),
31060d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 3, 3),
31160d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 2, 2),
31260d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN]	= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 1, 1),
31360d789f3SRui Miguel Silva 	[HW_DP_PULLUP]		= REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 0, 0),
31460d789f3SRui Miguel Silva 	[HW_HC_2_DIS_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 15, 15),
31560d789f3SRui Miguel Silva 	[HW_OTG_DISABLE_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 10, 10),
31660d789f3SRui Miguel Silva 	[HW_SW_SEL_HC_DC_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 7, 7),
31760d789f3SRui Miguel Silva 	[HW_VBUS_DRV_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 4, 4),
31860d789f3SRui Miguel Silva 	[HW_SEL_CP_EXT_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 3, 3),
31960d789f3SRui Miguel Silva 	[HW_DM_PULLDOWN_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 2, 2),
32060d789f3SRui Miguel Silva 	[HW_DP_PULLDOWN_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 1, 1),
32160d789f3SRui Miguel Silva 	[HW_DP_PULLUP_CLEAR]	= REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 0, 0),
32260d789f3SRui Miguel Silva };
32360d789f3SRui Miguel Silva 
32460d789f3SRui Miguel Silva static const struct regmap_range isp1763_hc_volatile_ranges[] = {
32560d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_HC_USBCMD, ISP1763_HC_ATL_PTD_LASTPTD),
32660d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_HC_BUFFER_STATUS, ISP1763_HC_DATA),
32760d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_HC_INTERRUPT, ISP1763_HC_OTG_CTRL_CLEAR),
32860d789f3SRui Miguel Silva };
32960d789f3SRui Miguel Silva 
33060d789f3SRui Miguel Silva static const struct regmap_access_table isp1763_hc_volatile_table = {
33160d789f3SRui Miguel Silva 	.yes_ranges	= isp1763_hc_volatile_ranges,
33260d789f3SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp1763_hc_volatile_ranges),
33360d789f3SRui Miguel Silva };
33460d789f3SRui Miguel Silva 
33560d789f3SRui Miguel Silva static const struct regmap_config isp1763_hc_regmap_conf = {
33660d789f3SRui Miguel Silva 	.name = "isp1763-hc",
33760d789f3SRui Miguel Silva 	.reg_bits = 8,
33860d789f3SRui Miguel Silva 	.reg_stride = 2,
33960d789f3SRui Miguel Silva 	.val_bits = 16,
34060d789f3SRui Miguel Silva 	.fast_io = true,
34160d789f3SRui Miguel Silva 	.max_register = ISP1763_HC_OTG_CTRL_CLEAR,
34260d789f3SRui Miguel Silva 	.volatile_table = &isp1763_hc_volatile_table,
3431da9e1c0SRui Miguel Silva };
3441da9e1c0SRui Miguel Silva 
3451da9e1c0SRui Miguel Silva static const struct regmap_range isp176x_dc_volatile_ranges[] = {
3461da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_DC_EPMAXPKTSZ, ISP176x_DC_EPTYPE),
3471da9e1c0SRui Miguel Silva 	regmap_reg_range(ISP176x_DC_BUFLEN, ISP176x_DC_EPINDEX),
3481da9e1c0SRui Miguel Silva };
3491da9e1c0SRui Miguel Silva 
3501da9e1c0SRui Miguel Silva static const struct regmap_access_table isp176x_dc_volatile_table = {
3511da9e1c0SRui Miguel Silva 	.yes_ranges	= isp176x_dc_volatile_ranges,
3521da9e1c0SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp176x_dc_volatile_ranges),
3531da9e1c0SRui Miguel Silva };
3541da9e1c0SRui Miguel Silva 
35560d789f3SRui Miguel Silva static const struct regmap_config isp1761_dc_regmap_conf = {
3561da9e1c0SRui Miguel Silva 	.name = "isp1761-dc",
3571da9e1c0SRui Miguel Silva 	.reg_bits = 16,
3581da9e1c0SRui Miguel Silva 	.reg_stride = 4,
3591da9e1c0SRui Miguel Silva 	.val_bits = 32,
3601da9e1c0SRui Miguel Silva 	.fast_io = true,
36160d789f3SRui Miguel Silva 	.max_register = ISP176x_DC_TESTMODE,
3621da9e1c0SRui Miguel Silva 	.volatile_table = &isp176x_dc_volatile_table,
3631da9e1c0SRui Miguel Silva };
3641da9e1c0SRui Miguel Silva 
3651da9e1c0SRui Miguel Silva static const struct reg_field isp1761_dc_reg_fields[] = {
3661da9e1c0SRui Miguel Silva 	[DC_DEVEN]		= REG_FIELD(ISP176x_DC_ADDRESS, 7, 7),
3671da9e1c0SRui Miguel Silva 	[DC_DEVADDR]		= REG_FIELD(ISP176x_DC_ADDRESS, 0, 6),
3681da9e1c0SRui Miguel Silva 	[DC_VBUSSTAT]		= REG_FIELD(ISP176x_DC_MODE, 8, 8),
3691da9e1c0SRui Miguel Silva 	[DC_SFRESET]		= REG_FIELD(ISP176x_DC_MODE, 4, 4),
3701da9e1c0SRui Miguel Silva 	[DC_GLINTENA]		= REG_FIELD(ISP176x_DC_MODE, 3, 3),
3711da9e1c0SRui Miguel Silva 	[DC_CDBGMOD_ACK]	= REG_FIELD(ISP176x_DC_INTCONF, 6, 6),
3721da9e1c0SRui Miguel Silva 	[DC_DDBGMODIN_ACK]	= REG_FIELD(ISP176x_DC_INTCONF, 4, 4),
3731da9e1c0SRui Miguel Silva 	[DC_DDBGMODOUT_ACK]	= REG_FIELD(ISP176x_DC_INTCONF, 2, 2),
3741da9e1c0SRui Miguel Silva 	[DC_INTPOL]		= REG_FIELD(ISP176x_DC_INTCONF, 0, 0),
3751da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_7]		= REG_FIELD(ISP176x_DC_INTENABLE, 25, 25),
3761da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_6]		= REG_FIELD(ISP176x_DC_INTENABLE, 23, 23),
3771da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_5]		= REG_FIELD(ISP176x_DC_INTENABLE, 21, 21),
3781da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_4]		= REG_FIELD(ISP176x_DC_INTENABLE, 19, 19),
3791da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_3]		= REG_FIELD(ISP176x_DC_INTENABLE, 17, 17),
3801da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_2]		= REG_FIELD(ISP176x_DC_INTENABLE, 15, 15),
3811da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_1]		= REG_FIELD(ISP176x_DC_INTENABLE, 13, 13),
3821da9e1c0SRui Miguel Silva 	[DC_IEPRXTX_0]		= REG_FIELD(ISP176x_DC_INTENABLE, 11, 11),
3831da9e1c0SRui Miguel Silva 	[DC_IEP0SETUP]		= REG_FIELD(ISP176x_DC_INTENABLE, 8, 8),
3841da9e1c0SRui Miguel Silva 	[DC_IEVBUS]		= REG_FIELD(ISP176x_DC_INTENABLE, 7, 7),
3851da9e1c0SRui Miguel Silva 	[DC_IEHS_STA]		= REG_FIELD(ISP176x_DC_INTENABLE, 5, 5),
3861da9e1c0SRui Miguel Silva 	[DC_IERESM]		= REG_FIELD(ISP176x_DC_INTENABLE, 4, 4),
3871da9e1c0SRui Miguel Silva 	[DC_IESUSP]		= REG_FIELD(ISP176x_DC_INTENABLE, 3, 3),
3881da9e1c0SRui Miguel Silva 	[DC_IEBRST]		= REG_FIELD(ISP176x_DC_INTENABLE, 0, 0),
3891da9e1c0SRui Miguel Silva 	[DC_EP0SETUP]		= REG_FIELD(ISP176x_DC_EPINDEX, 5, 5),
3901da9e1c0SRui Miguel Silva 	[DC_ENDPIDX]		= REG_FIELD(ISP176x_DC_EPINDEX, 1, 4),
3911da9e1c0SRui Miguel Silva 	[DC_EPDIR]		= REG_FIELD(ISP176x_DC_EPINDEX, 0, 0),
3921da9e1c0SRui Miguel Silva 	[DC_CLBUF]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 4, 4),
3931da9e1c0SRui Miguel Silva 	[DC_VENDP]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 3, 3),
3941da9e1c0SRui Miguel Silva 	[DC_DSEN]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 2, 2),
3951da9e1c0SRui Miguel Silva 	[DC_STATUS]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 1, 1),
3961da9e1c0SRui Miguel Silva 	[DC_STALL]		= REG_FIELD(ISP176x_DC_CTRLFUNC, 0, 0),
3971da9e1c0SRui Miguel Silva 	[DC_BUFLEN]		= REG_FIELD(ISP176x_DC_BUFLEN, 0, 15),
3981da9e1c0SRui Miguel Silva 	[DC_FFOSZ]		= REG_FIELD(ISP176x_DC_EPMAXPKTSZ, 0, 10),
3991da9e1c0SRui Miguel Silva 	[DC_EPENABLE]		= REG_FIELD(ISP176x_DC_EPTYPE, 3, 3),
4001da9e1c0SRui Miguel Silva 	[DC_ENDPTYP]		= REG_FIELD(ISP176x_DC_EPTYPE, 0, 1),
4011da9e1c0SRui Miguel Silva 	[DC_UFRAMENUM]		= REG_FIELD(ISP176x_DC_FRAMENUM, 11, 13),
4021da9e1c0SRui Miguel Silva 	[DC_FRAMENUM]		= REG_FIELD(ISP176x_DC_FRAMENUM, 0, 10),
40360d789f3SRui Miguel Silva 	[DC_CHIP_ID_HIGH]	= REG_FIELD(ISP176x_DC_CHIPID, 16, 31),
40460d789f3SRui Miguel Silva 	[DC_CHIP_ID_LOW]	= REG_FIELD(ISP176x_DC_CHIPID, 0, 15),
40560d789f3SRui Miguel Silva 	[DC_SCRATCH]		= REG_FIELD(ISP176x_DC_SCRATCH, 0, 15),
40660d789f3SRui Miguel Silva };
40760d789f3SRui Miguel Silva 
40860d789f3SRui Miguel Silva static const struct regmap_range isp1763_dc_volatile_ranges[] = {
40960d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_DC_EPMAXPKTSZ, ISP1763_DC_EPTYPE),
41060d789f3SRui Miguel Silva 	regmap_reg_range(ISP1763_DC_BUFLEN, ISP1763_DC_EPINDEX),
41160d789f3SRui Miguel Silva };
41260d789f3SRui Miguel Silva 
41360d789f3SRui Miguel Silva static const struct regmap_access_table isp1763_dc_volatile_table = {
41460d789f3SRui Miguel Silva 	.yes_ranges	= isp1763_dc_volatile_ranges,
41560d789f3SRui Miguel Silva 	.n_yes_ranges	= ARRAY_SIZE(isp1763_dc_volatile_ranges),
41660d789f3SRui Miguel Silva };
41760d789f3SRui Miguel Silva 
41860d789f3SRui Miguel Silva static const struct reg_field isp1763_dc_reg_fields[] = {
41960d789f3SRui Miguel Silva 	[DC_DEVEN]		= REG_FIELD(ISP1763_DC_ADDRESS, 7, 7),
42060d789f3SRui Miguel Silva 	[DC_DEVADDR]		= REG_FIELD(ISP1763_DC_ADDRESS, 0, 6),
42160d789f3SRui Miguel Silva 	[DC_VBUSSTAT]		= REG_FIELD(ISP1763_DC_MODE, 8, 8),
42260d789f3SRui Miguel Silva 	[DC_SFRESET]		= REG_FIELD(ISP1763_DC_MODE, 4, 4),
42360d789f3SRui Miguel Silva 	[DC_GLINTENA]		= REG_FIELD(ISP1763_DC_MODE, 3, 3),
42460d789f3SRui Miguel Silva 	[DC_CDBGMOD_ACK]	= REG_FIELD(ISP1763_DC_INTCONF, 6, 6),
42560d789f3SRui Miguel Silva 	[DC_DDBGMODIN_ACK]	= REG_FIELD(ISP1763_DC_INTCONF, 4, 4),
42660d789f3SRui Miguel Silva 	[DC_DDBGMODOUT_ACK]	= REG_FIELD(ISP1763_DC_INTCONF, 2, 2),
42760d789f3SRui Miguel Silva 	[DC_INTPOL]		= REG_FIELD(ISP1763_DC_INTCONF, 0, 0),
42860d789f3SRui Miguel Silva 	[DC_IEPRXTX_7]		= REG_FIELD(ISP1763_DC_INTENABLE, 25, 25),
42960d789f3SRui Miguel Silva 	[DC_IEPRXTX_6]		= REG_FIELD(ISP1763_DC_INTENABLE, 23, 23),
43060d789f3SRui Miguel Silva 	[DC_IEPRXTX_5]		= REG_FIELD(ISP1763_DC_INTENABLE, 21, 21),
43160d789f3SRui Miguel Silva 	[DC_IEPRXTX_4]		= REG_FIELD(ISP1763_DC_INTENABLE, 19, 19),
43260d789f3SRui Miguel Silva 	[DC_IEPRXTX_3]		= REG_FIELD(ISP1763_DC_INTENABLE, 17, 17),
43360d789f3SRui Miguel Silva 	[DC_IEPRXTX_2]		= REG_FIELD(ISP1763_DC_INTENABLE, 15, 15),
43460d789f3SRui Miguel Silva 	[DC_IEPRXTX_1]		= REG_FIELD(ISP1763_DC_INTENABLE, 13, 13),
43560d789f3SRui Miguel Silva 	[DC_IEPRXTX_0]		= REG_FIELD(ISP1763_DC_INTENABLE, 11, 11),
43660d789f3SRui Miguel Silva 	[DC_IEP0SETUP]		= REG_FIELD(ISP1763_DC_INTENABLE, 8, 8),
43760d789f3SRui Miguel Silva 	[DC_IEVBUS]		= REG_FIELD(ISP1763_DC_INTENABLE, 7, 7),
43860d789f3SRui Miguel Silva 	[DC_IEHS_STA]		= REG_FIELD(ISP1763_DC_INTENABLE, 5, 5),
43960d789f3SRui Miguel Silva 	[DC_IERESM]		= REG_FIELD(ISP1763_DC_INTENABLE, 4, 4),
44060d789f3SRui Miguel Silva 	[DC_IESUSP]		= REG_FIELD(ISP1763_DC_INTENABLE, 3, 3),
44160d789f3SRui Miguel Silva 	[DC_IEBRST]		= REG_FIELD(ISP1763_DC_INTENABLE, 0, 0),
44260d789f3SRui Miguel Silva 	[DC_EP0SETUP]		= REG_FIELD(ISP1763_DC_EPINDEX, 5, 5),
44360d789f3SRui Miguel Silva 	[DC_ENDPIDX]		= REG_FIELD(ISP1763_DC_EPINDEX, 1, 4),
44460d789f3SRui Miguel Silva 	[DC_EPDIR]		= REG_FIELD(ISP1763_DC_EPINDEX, 0, 0),
44560d789f3SRui Miguel Silva 	[DC_CLBUF]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 4, 4),
44660d789f3SRui Miguel Silva 	[DC_VENDP]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 3, 3),
44760d789f3SRui Miguel Silva 	[DC_DSEN]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 2, 2),
44860d789f3SRui Miguel Silva 	[DC_STATUS]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 1, 1),
44960d789f3SRui Miguel Silva 	[DC_STALL]		= REG_FIELD(ISP1763_DC_CTRLFUNC, 0, 0),
45060d789f3SRui Miguel Silva 	[DC_BUFLEN]		= REG_FIELD(ISP1763_DC_BUFLEN, 0, 15),
45160d789f3SRui Miguel Silva 	[DC_FFOSZ]		= REG_FIELD(ISP1763_DC_EPMAXPKTSZ, 0, 10),
45260d789f3SRui Miguel Silva 	[DC_EPENABLE]		= REG_FIELD(ISP1763_DC_EPTYPE, 3, 3),
45360d789f3SRui Miguel Silva 	[DC_ENDPTYP]		= REG_FIELD(ISP1763_DC_EPTYPE, 0, 1),
45460d789f3SRui Miguel Silva 	[DC_UFRAMENUM]		= REG_FIELD(ISP1763_DC_FRAMENUM, 11, 13),
45560d789f3SRui Miguel Silva 	[DC_FRAMENUM]		= REG_FIELD(ISP1763_DC_FRAMENUM, 0, 10),
45660d789f3SRui Miguel Silva 	[DC_CHIP_ID_HIGH]	= REG_FIELD(ISP1763_DC_CHIPID_HIGH, 0, 15),
45760d789f3SRui Miguel Silva 	[DC_CHIP_ID_LOW]	= REG_FIELD(ISP1763_DC_CHIPID_LOW, 0, 15),
45860d789f3SRui Miguel Silva 	[DC_SCRATCH]		= REG_FIELD(ISP1763_DC_SCRATCH, 0, 15),
45960d789f3SRui Miguel Silva };
46060d789f3SRui Miguel Silva 
46160d789f3SRui Miguel Silva static const struct regmap_config isp1763_dc_regmap_conf = {
46260d789f3SRui Miguel Silva 	.name = "isp1763-dc",
46360d789f3SRui Miguel Silva 	.reg_bits = 8,
46460d789f3SRui Miguel Silva 	.reg_stride = 2,
46560d789f3SRui Miguel Silva 	.val_bits = 16,
46660d789f3SRui Miguel Silva 	.fast_io = true,
46760d789f3SRui Miguel Silva 	.max_register = ISP1763_DC_TESTMODE,
46860d789f3SRui Miguel Silva 	.volatile_table = &isp1763_dc_volatile_table,
4691da9e1c0SRui Miguel Silva };
4701da9e1c0SRui Miguel Silva 
4717ef077a8SLaurent Pinchart int isp1760_register(struct resource *mem, int irq, unsigned long irqflags,
4727ef077a8SLaurent Pinchart 		     struct device *dev, unsigned int devflags)
4737ef077a8SLaurent Pinchart {
47460d789f3SRui Miguel Silva 	const struct regmap_config *hc_regmap;
47560d789f3SRui Miguel Silva 	const struct reg_field *hc_reg_fields;
476*d369c918SRui Miguel Silva 	const struct regmap_config *dc_regmap;
477*d369c918SRui Miguel Silva 	const struct reg_field *dc_reg_fields;
4787ef077a8SLaurent Pinchart 	struct isp1760_device *isp;
4791da9e1c0SRui Miguel Silva 	struct isp1760_hcd *hcd;
4801da9e1c0SRui Miguel Silva 	struct isp1760_udc *udc;
4811da9e1c0SRui Miguel Silva 	struct regmap_field *f;
482*d369c918SRui Miguel Silva 	bool udc_enabled;
4837ef077a8SLaurent Pinchart 	int ret;
4841da9e1c0SRui Miguel Silva 	int i;
4857ef077a8SLaurent Pinchart 
486d21daf1eSLaurent Pinchart 	/*
487d21daf1eSLaurent Pinchart 	 * If neither the HCD not the UDC is enabled return an error, as no
488d21daf1eSLaurent Pinchart 	 * device would be registered.
489d21daf1eSLaurent Pinchart 	 */
490*d369c918SRui Miguel Silva 	udc_enabled = ((devflags & ISP1760_FLAG_ISP1763) ||
491*d369c918SRui Miguel Silva 		       (devflags & ISP1760_FLAG_ISP1761));
492*d369c918SRui Miguel Silva 
493d21daf1eSLaurent Pinchart 	if ((!IS_ENABLED(CONFIG_USB_ISP1760_HCD) || usb_disabled()) &&
494*d369c918SRui Miguel Silva 	    (!IS_ENABLED(CONFIG_USB_ISP1761_UDC) || !udc_enabled))
4957ef077a8SLaurent Pinchart 		return -ENODEV;
4967ef077a8SLaurent Pinchart 
4977ef077a8SLaurent Pinchart 	isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL);
4987ef077a8SLaurent Pinchart 	if (!isp)
4997ef077a8SLaurent Pinchart 		return -ENOMEM;
5007ef077a8SLaurent Pinchart 
5017ef077a8SLaurent Pinchart 	isp->dev = dev;
5027ef077a8SLaurent Pinchart 	isp->devflags = devflags;
5031da9e1c0SRui Miguel Silva 	hcd = &isp->hcd;
5041da9e1c0SRui Miguel Silva 	udc = &isp->udc;
5051da9e1c0SRui Miguel Silva 
50660d789f3SRui Miguel Silva 	hcd->is_isp1763 = !!(devflags & ISP1760_FLAG_ISP1763);
507*d369c918SRui Miguel Silva 	udc->is_isp1763 = !!(devflags & ISP1760_FLAG_ISP1763);
50860d789f3SRui Miguel Silva 
50960d789f3SRui Miguel Silva 	if (!hcd->is_isp1763 && (devflags & ISP1760_FLAG_BUS_WIDTH_8)) {
51060d789f3SRui Miguel Silva 		dev_err(dev, "isp1760/61 do not support data width 8\n");
51160d789f3SRui Miguel Silva 		return -EINVAL;
51260d789f3SRui Miguel Silva 	}
51360d789f3SRui Miguel Silva 
51460d789f3SRui Miguel Silva 	if (hcd->is_isp1763) {
51560d789f3SRui Miguel Silva 		hc_regmap = &isp1763_hc_regmap_conf;
51660d789f3SRui Miguel Silva 		hc_reg_fields = &isp1763_hc_reg_fields[0];
517*d369c918SRui Miguel Silva 		dc_regmap = &isp1763_dc_regmap_conf;
518*d369c918SRui Miguel Silva 		dc_reg_fields = &isp1763_dc_reg_fields[0];
51960d789f3SRui Miguel Silva 	} else {
52060d789f3SRui Miguel Silva 		hc_regmap = &isp1760_hc_regmap_conf;
52160d789f3SRui Miguel Silva 		hc_reg_fields = &isp1760_hc_reg_fields[0];
522*d369c918SRui Miguel Silva 		dc_regmap = &isp1761_dc_regmap_conf;
523*d369c918SRui Miguel Silva 		dc_reg_fields = &isp1761_dc_reg_fields[0];
5241da9e1c0SRui Miguel Silva 	}
5257ef077a8SLaurent Pinchart 
5267ef077a8SLaurent Pinchart 	isp->rst_gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH);
5277ef077a8SLaurent Pinchart 	if (IS_ERR(isp->rst_gpio))
5287ef077a8SLaurent Pinchart 		return PTR_ERR(isp->rst_gpio);
5297ef077a8SLaurent Pinchart 
5301da9e1c0SRui Miguel Silva 	hcd->base = devm_ioremap_resource(dev, mem);
5311da9e1c0SRui Miguel Silva 	if (IS_ERR(hcd->base))
5321da9e1c0SRui Miguel Silva 		return PTR_ERR(hcd->base);
5331da9e1c0SRui Miguel Silva 
53460d789f3SRui Miguel Silva 	hcd->regs = devm_regmap_init_mmio(dev, hcd->base, hc_regmap);
5351da9e1c0SRui Miguel Silva 	if (IS_ERR(hcd->regs))
5361da9e1c0SRui Miguel Silva 		return PTR_ERR(hcd->regs);
5371da9e1c0SRui Miguel Silva 
5381da9e1c0SRui Miguel Silva 	for (i = 0; i < HC_FIELD_MAX; i++) {
53960d789f3SRui Miguel Silva 		f = devm_regmap_field_alloc(dev, hcd->regs, hc_reg_fields[i]);
5401da9e1c0SRui Miguel Silva 		if (IS_ERR(f))
5411da9e1c0SRui Miguel Silva 			return PTR_ERR(f);
5421da9e1c0SRui Miguel Silva 
5431da9e1c0SRui Miguel Silva 		hcd->fields[i] = f;
5441da9e1c0SRui Miguel Silva 	}
5451da9e1c0SRui Miguel Silva 
546*d369c918SRui Miguel Silva 	udc->regs = devm_regmap_init_mmio(dev, hcd->base, dc_regmap);
5471da9e1c0SRui Miguel Silva 	if (IS_ERR(udc->regs))
5481da9e1c0SRui Miguel Silva 		return PTR_ERR(udc->regs);
5491da9e1c0SRui Miguel Silva 
5501da9e1c0SRui Miguel Silva 	for (i = 0; i < DC_FIELD_MAX; i++) {
551*d369c918SRui Miguel Silva 		f = devm_regmap_field_alloc(dev, udc->regs, dc_reg_fields[i]);
5521da9e1c0SRui Miguel Silva 		if (IS_ERR(f))
5531da9e1c0SRui Miguel Silva 			return PTR_ERR(f);
5541da9e1c0SRui Miguel Silva 
5551da9e1c0SRui Miguel Silva 		udc->fields[i] = f;
5561da9e1c0SRui Miguel Silva 	}
5577ef077a8SLaurent Pinchart 
55860d789f3SRui Miguel Silva 	if (hcd->is_isp1763)
55960d789f3SRui Miguel Silva 		hcd->memory_layout = &isp1763_memory_conf;
56060d789f3SRui Miguel Silva 	else
561a74f639cSRui Miguel Silva 		hcd->memory_layout = &isp176x_memory_conf;
562a74f639cSRui Miguel Silva 
56360d789f3SRui Miguel Silva 	ret = isp1760_init_core(isp);
56460d789f3SRui Miguel Silva 	if (ret < 0)
56560d789f3SRui Miguel Silva 		return ret;
5667ef077a8SLaurent Pinchart 
567d21daf1eSLaurent Pinchart 	if (IS_ENABLED(CONFIG_USB_ISP1760_HCD) && !usb_disabled()) {
5681da9e1c0SRui Miguel Silva 		ret = isp1760_hcd_register(hcd, mem, irq,
5697ef077a8SLaurent Pinchart 					   irqflags | IRQF_SHARED, dev);
5707ef077a8SLaurent Pinchart 		if (ret < 0)
5717ef077a8SLaurent Pinchart 			return ret;
572d21daf1eSLaurent Pinchart 	}
5737ef077a8SLaurent Pinchart 
574*d369c918SRui Miguel Silva 	if (IS_ENABLED(CONFIG_USB_ISP1761_UDC) && udc_enabled) {
57580b4a0f8SValentin Rothberg 		ret = isp1760_udc_register(isp, irq, irqflags);
5767ef077a8SLaurent Pinchart 		if (ret < 0) {
5771da9e1c0SRui Miguel Silva 			isp1760_hcd_unregister(hcd);
5787ef077a8SLaurent Pinchart 			return ret;
5797ef077a8SLaurent Pinchart 		}
5807ef077a8SLaurent Pinchart 	}
5817ef077a8SLaurent Pinchart 
5827ef077a8SLaurent Pinchart 	dev_set_drvdata(dev, isp);
5837ef077a8SLaurent Pinchart 
5847ef077a8SLaurent Pinchart 	return 0;
5857ef077a8SLaurent Pinchart }
5867ef077a8SLaurent Pinchart 
5877ef077a8SLaurent Pinchart void isp1760_unregister(struct device *dev)
5887ef077a8SLaurent Pinchart {
5897ef077a8SLaurent Pinchart 	struct isp1760_device *isp = dev_get_drvdata(dev);
5907ef077a8SLaurent Pinchart 
5917ef077a8SLaurent Pinchart 	isp1760_udc_unregister(isp);
5927ef077a8SLaurent Pinchart 	isp1760_hcd_unregister(&isp->hcd);
5937ef077a8SLaurent Pinchart }
5947ef077a8SLaurent Pinchart 
5957ef077a8SLaurent Pinchart MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP");
5967ef077a8SLaurent Pinchart MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>");
5977ef077a8SLaurent Pinchart MODULE_LICENSE("GPL v2");
598