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; 339c1587d9SRui Miguel Silva u32 otg_ctrl; 347ef077a8SLaurent Pinchart 357ef077a8SLaurent Pinchart /* Low-level chip reset */ 367ef077a8SLaurent Pinchart if (isp->rst_gpio) { 377ef077a8SLaurent Pinchart gpiod_set_value_cansleep(isp->rst_gpio, 1); 380f029008SJia-Ju Bai msleep(50); 397ef077a8SLaurent Pinchart gpiod_set_value_cansleep(isp->rst_gpio, 0); 407ef077a8SLaurent Pinchart } 417ef077a8SLaurent Pinchart 427ef077a8SLaurent Pinchart /* 437ef077a8SLaurent Pinchart * Reset the host controller, including the CPU interface 447ef077a8SLaurent Pinchart * configuration. 457ef077a8SLaurent Pinchart */ 461da9e1c0SRui Miguel Silva isp1760_field_set(hcd->fields, SW_RESET_RESET_ALL); 477ef077a8SLaurent Pinchart msleep(100); 487ef077a8SLaurent Pinchart 497ef077a8SLaurent Pinchart /* Setup HW Mode Control: This assumes a level active-low interrupt */ 5060d789f3SRui Miguel Silva if ((isp->devflags & ISP1760_FLAG_ANALOG_OC) && hcd->is_isp1763) { 5160d789f3SRui Miguel Silva dev_err(isp->dev, "isp1763 analog overcurrent not available\n"); 5260d789f3SRui Miguel Silva return -EINVAL; 5360d789f3SRui Miguel Silva } 5460d789f3SRui Miguel Silva 557ef077a8SLaurent Pinchart if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_16) 561da9e1c0SRui Miguel Silva isp1760_field_clear(hcd->fields, HW_DATA_BUS_WIDTH); 5760d789f3SRui Miguel Silva if (isp->devflags & ISP1760_FLAG_BUS_WIDTH_8) 5860d789f3SRui Miguel Silva isp1760_field_set(hcd->fields, HW_DATA_BUS_WIDTH); 597ef077a8SLaurent Pinchart if (isp->devflags & ISP1760_FLAG_ANALOG_OC) 601da9e1c0SRui Miguel Silva isp1760_field_set(hcd->fields, HW_ANA_DIGI_OC); 617ef077a8SLaurent Pinchart if (isp->devflags & ISP1760_FLAG_DACK_POL_HIGH) 621da9e1c0SRui Miguel Silva isp1760_field_set(hcd->fields, HW_DACK_POL_HIGH); 637ef077a8SLaurent Pinchart if (isp->devflags & ISP1760_FLAG_DREQ_POL_HIGH) 641da9e1c0SRui Miguel Silva isp1760_field_set(hcd->fields, HW_DREQ_POL_HIGH); 657ef077a8SLaurent Pinchart if (isp->devflags & ISP1760_FLAG_INTR_POL_HIGH) 661da9e1c0SRui Miguel Silva isp1760_field_set(hcd->fields, HW_INTR_HIGH_ACT); 677ef077a8SLaurent Pinchart if (isp->devflags & ISP1760_FLAG_INTR_EDGE_TRIG) 681da9e1c0SRui Miguel Silva isp1760_field_set(hcd->fields, HW_INTR_EDGE_TRIG); 697ef077a8SLaurent Pinchart 707ef077a8SLaurent Pinchart /* 717ef077a8SLaurent Pinchart * The ISP1761 has a dedicated DC IRQ line but supports sharing the HC 727ef077a8SLaurent Pinchart * IRQ line for both the host and device controllers. Hardcode IRQ 737ef077a8SLaurent Pinchart * sharing for now and disable the DC interrupts globally to avoid 747ef077a8SLaurent Pinchart * spurious interrupts during HCD registration. 757ef077a8SLaurent Pinchart */ 767ef077a8SLaurent Pinchart if (isp->devflags & ISP1760_FLAG_ISP1761) { 771da9e1c0SRui Miguel Silva isp1760_reg_write(udc->regs, ISP176x_DC_MODE, 0); 781da9e1c0SRui Miguel Silva isp1760_field_set(hcd->fields, HW_COMN_IRQ); 797ef077a8SLaurent Pinchart } 807ef077a8SLaurent Pinchart 817ef077a8SLaurent Pinchart /* 827ef077a8SLaurent Pinchart * PORT 1 Control register of the ISP1760 is the OTG control register 837ef077a8SLaurent Pinchart * on ISP1761. 847ef077a8SLaurent Pinchart * 857ef077a8SLaurent Pinchart * TODO: Really support OTG. For now we configure port 1 in device mode 867ef077a8SLaurent Pinchart */ 879c1587d9SRui Miguel Silva if (isp->devflags & ISP1760_FLAG_ISP1761) { 889c1587d9SRui Miguel Silva if (isp->devflags & ISP1760_FLAG_PERIPHERAL_EN) { 899c1587d9SRui Miguel Silva otg_ctrl = (ISP176x_HW_DM_PULLDOWN_CLEAR | 909c1587d9SRui Miguel Silva ISP176x_HW_DP_PULLDOWN_CLEAR | 919c1587d9SRui Miguel Silva ISP176x_HW_OTG_DISABLE); 921da9e1c0SRui Miguel Silva } else { 939c1587d9SRui Miguel Silva otg_ctrl = (ISP176x_HW_SW_SEL_HC_DC_CLEAR | 949c1587d9SRui Miguel Silva ISP176x_HW_VBUS_DRV | 959c1587d9SRui Miguel Silva ISP176x_HW_SEL_CP_EXT); 969c1587d9SRui Miguel Silva } 979c1587d9SRui Miguel Silva isp1760_reg_write(hcd->regs, ISP176x_HC_OTG_CTRL, otg_ctrl); 981da9e1c0SRui Miguel Silva } 997ef077a8SLaurent Pinchart 10060d789f3SRui Miguel Silva dev_info(isp->dev, "%s bus width: %u, oc: %s\n", 10160d789f3SRui Miguel Silva hcd->is_isp1763 ? "isp1763" : "isp1760", 10260d789f3SRui Miguel Silva isp->devflags & ISP1760_FLAG_BUS_WIDTH_8 ? 8 : 1037ef077a8SLaurent Pinchart isp->devflags & ISP1760_FLAG_BUS_WIDTH_16 ? 16 : 32, 10460d789f3SRui Miguel Silva hcd->is_isp1763 ? "not available" : 1057ef077a8SLaurent Pinchart isp->devflags & ISP1760_FLAG_ANALOG_OC ? "analog" : "digital"); 10660d789f3SRui Miguel Silva 10760d789f3SRui Miguel Silva return 0; 1087ef077a8SLaurent Pinchart } 1097ef077a8SLaurent Pinchart 1107ef077a8SLaurent Pinchart void isp1760_set_pullup(struct isp1760_device *isp, bool enable) 1117ef077a8SLaurent Pinchart { 1121da9e1c0SRui Miguel Silva struct isp1760_udc *udc = &isp->udc; 1131da9e1c0SRui Miguel Silva 1141da9e1c0SRui Miguel Silva if (enable) 1151da9e1c0SRui Miguel Silva isp1760_field_set(udc->fields, HW_DP_PULLUP); 1161da9e1c0SRui Miguel Silva else 1171da9e1c0SRui Miguel Silva isp1760_field_set(udc->fields, HW_DP_PULLUP_CLEAR); 1187ef077a8SLaurent Pinchart } 1197ef077a8SLaurent Pinchart 120a74f639cSRui Miguel Silva /* 12160d789f3SRui Miguel Silva * ISP1760/61: 12260d789f3SRui Miguel Silva * 123a74f639cSRui Miguel Silva * 60kb divided in: 124a74f639cSRui Miguel Silva * - 32 blocks @ 256 bytes 125a74f639cSRui Miguel Silva * - 20 blocks @ 1024 bytes 126a74f639cSRui Miguel Silva * - 4 blocks @ 8192 bytes 127a74f639cSRui Miguel Silva */ 128a74f639cSRui Miguel Silva static const struct isp1760_memory_layout isp176x_memory_conf = { 129a74f639cSRui Miguel Silva .blocks[0] = 32, 130a74f639cSRui Miguel Silva .blocks_size[0] = 256, 131a74f639cSRui Miguel Silva .blocks[1] = 20, 132a74f639cSRui Miguel Silva .blocks_size[1] = 1024, 133a74f639cSRui Miguel Silva .blocks[2] = 4, 134a74f639cSRui Miguel Silva .blocks_size[2] = 8192, 135a74f639cSRui Miguel Silva 13660d789f3SRui Miguel Silva .slot_num = 32, 137a74f639cSRui Miguel Silva .payload_blocks = 32 + 20 + 4, 138a74f639cSRui Miguel Silva .payload_area_size = 0xf000, 139a74f639cSRui Miguel Silva }; 140a74f639cSRui Miguel Silva 14160d789f3SRui Miguel Silva /* 14260d789f3SRui Miguel Silva * ISP1763: 14360d789f3SRui Miguel Silva * 14460d789f3SRui Miguel Silva * 20kb divided in: 14560d789f3SRui Miguel Silva * - 8 blocks @ 256 bytes 14660d789f3SRui Miguel Silva * - 2 blocks @ 1024 bytes 14760d789f3SRui Miguel Silva * - 4 blocks @ 4096 bytes 14860d789f3SRui Miguel Silva */ 14960d789f3SRui Miguel Silva static const struct isp1760_memory_layout isp1763_memory_conf = { 15060d789f3SRui Miguel Silva .blocks[0] = 8, 15160d789f3SRui Miguel Silva .blocks_size[0] = 256, 15260d789f3SRui Miguel Silva .blocks[1] = 2, 15360d789f3SRui Miguel Silva .blocks_size[1] = 1024, 15460d789f3SRui Miguel Silva .blocks[2] = 4, 15560d789f3SRui Miguel Silva .blocks_size[2] = 4096, 15660d789f3SRui Miguel Silva 15760d789f3SRui Miguel Silva .slot_num = 16, 15860d789f3SRui Miguel Silva .payload_blocks = 8 + 2 + 4, 15960d789f3SRui Miguel Silva .payload_area_size = 0x5000, 16060d789f3SRui Miguel Silva }; 16160d789f3SRui Miguel Silva 1621da9e1c0SRui Miguel Silva static const struct regmap_range isp176x_hc_volatile_ranges[] = { 1631da9e1c0SRui Miguel Silva regmap_reg_range(ISP176x_HC_USBCMD, ISP176x_HC_ATL_PTD_LASTPTD), 1641da9e1c0SRui Miguel Silva regmap_reg_range(ISP176x_HC_BUFFER_STATUS, ISP176x_HC_MEMORY), 16560d789f3SRui Miguel Silva regmap_reg_range(ISP176x_HC_INTERRUPT, ISP176x_HC_OTG_CTRL_CLEAR), 1661da9e1c0SRui Miguel Silva }; 1671da9e1c0SRui Miguel Silva 1681da9e1c0SRui Miguel Silva static const struct regmap_access_table isp176x_hc_volatile_table = { 1691da9e1c0SRui Miguel Silva .yes_ranges = isp176x_hc_volatile_ranges, 1701da9e1c0SRui Miguel Silva .n_yes_ranges = ARRAY_SIZE(isp176x_hc_volatile_ranges), 1711da9e1c0SRui Miguel Silva }; 1721da9e1c0SRui Miguel Silva 17360d789f3SRui Miguel Silva static const struct regmap_config isp1760_hc_regmap_conf = { 1741da9e1c0SRui Miguel Silva .name = "isp1760-hc", 1751da9e1c0SRui Miguel Silva .reg_bits = 16, 1761da9e1c0SRui Miguel Silva .reg_stride = 4, 1771da9e1c0SRui Miguel Silva .val_bits = 32, 1781da9e1c0SRui Miguel Silva .fast_io = true, 17960d789f3SRui Miguel Silva .max_register = ISP176x_HC_OTG_CTRL_CLEAR, 1801da9e1c0SRui Miguel Silva .volatile_table = &isp176x_hc_volatile_table, 1811da9e1c0SRui Miguel Silva }; 1821da9e1c0SRui Miguel Silva 1831da9e1c0SRui Miguel Silva static const struct reg_field isp1760_hc_reg_fields[] = { 1841da9e1c0SRui Miguel Silva [HCS_PPC] = REG_FIELD(ISP176x_HC_HCSPARAMS, 4, 4), 1851da9e1c0SRui Miguel Silva [HCS_N_PORTS] = REG_FIELD(ISP176x_HC_HCSPARAMS, 0, 3), 1861da9e1c0SRui Miguel Silva [HCC_ISOC_CACHE] = REG_FIELD(ISP176x_HC_HCCPARAMS, 7, 7), 1871da9e1c0SRui Miguel Silva [HCC_ISOC_THRES] = REG_FIELD(ISP176x_HC_HCCPARAMS, 4, 6), 1881da9e1c0SRui Miguel Silva [CMD_LRESET] = REG_FIELD(ISP176x_HC_USBCMD, 7, 7), 1891da9e1c0SRui Miguel Silva [CMD_RESET] = REG_FIELD(ISP176x_HC_USBCMD, 1, 1), 1901da9e1c0SRui Miguel Silva [CMD_RUN] = REG_FIELD(ISP176x_HC_USBCMD, 0, 0), 1911da9e1c0SRui Miguel Silva [STS_PCD] = REG_FIELD(ISP176x_HC_USBSTS, 2, 2), 1921da9e1c0SRui Miguel Silva [HC_FRINDEX] = REG_FIELD(ISP176x_HC_FRINDEX, 0, 13), 1931da9e1c0SRui Miguel Silva [FLAG_CF] = REG_FIELD(ISP176x_HC_CONFIGFLAG, 0, 0), 19460d789f3SRui Miguel Silva [HC_ISO_PTD_DONEMAP] = REG_FIELD(ISP176x_HC_ISO_PTD_DONEMAP, 0, 31), 19560d789f3SRui Miguel Silva [HC_ISO_PTD_SKIPMAP] = REG_FIELD(ISP176x_HC_ISO_PTD_SKIPMAP, 0, 31), 19660d789f3SRui Miguel Silva [HC_ISO_PTD_LASTPTD] = REG_FIELD(ISP176x_HC_ISO_PTD_LASTPTD, 0, 31), 19760d789f3SRui Miguel Silva [HC_INT_PTD_DONEMAP] = REG_FIELD(ISP176x_HC_INT_PTD_DONEMAP, 0, 31), 19860d789f3SRui Miguel Silva [HC_INT_PTD_SKIPMAP] = REG_FIELD(ISP176x_HC_INT_PTD_SKIPMAP, 0, 31), 19960d789f3SRui Miguel Silva [HC_INT_PTD_LASTPTD] = REG_FIELD(ISP176x_HC_INT_PTD_LASTPTD, 0, 31), 20060d789f3SRui Miguel Silva [HC_ATL_PTD_DONEMAP] = REG_FIELD(ISP176x_HC_ATL_PTD_DONEMAP, 0, 31), 20160d789f3SRui Miguel Silva [HC_ATL_PTD_SKIPMAP] = REG_FIELD(ISP176x_HC_ATL_PTD_SKIPMAP, 0, 31), 20260d789f3SRui Miguel Silva [HC_ATL_PTD_LASTPTD] = REG_FIELD(ISP176x_HC_ATL_PTD_LASTPTD, 0, 31), 2031da9e1c0SRui Miguel Silva [PORT_OWNER] = REG_FIELD(ISP176x_HC_PORTSC1, 13, 13), 2041da9e1c0SRui Miguel Silva [PORT_POWER] = REG_FIELD(ISP176x_HC_PORTSC1, 12, 12), 2051da9e1c0SRui Miguel Silva [PORT_LSTATUS] = REG_FIELD(ISP176x_HC_PORTSC1, 10, 11), 2061da9e1c0SRui Miguel Silva [PORT_RESET] = REG_FIELD(ISP176x_HC_PORTSC1, 8, 8), 2071da9e1c0SRui Miguel Silva [PORT_SUSPEND] = REG_FIELD(ISP176x_HC_PORTSC1, 7, 7), 2081da9e1c0SRui Miguel Silva [PORT_RESUME] = REG_FIELD(ISP176x_HC_PORTSC1, 6, 6), 2091da9e1c0SRui Miguel Silva [PORT_PE] = REG_FIELD(ISP176x_HC_PORTSC1, 2, 2), 2101da9e1c0SRui Miguel Silva [PORT_CSC] = REG_FIELD(ISP176x_HC_PORTSC1, 1, 1), 2111da9e1c0SRui Miguel Silva [PORT_CONNECT] = REG_FIELD(ISP176x_HC_PORTSC1, 0, 0), 2121da9e1c0SRui Miguel Silva [ALL_ATX_RESET] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 31, 31), 2131da9e1c0SRui Miguel Silva [HW_ANA_DIGI_OC] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 15, 15), 2141da9e1c0SRui Miguel Silva [HW_COMN_IRQ] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 10, 10), 2151da9e1c0SRui Miguel Silva [HW_DATA_BUS_WIDTH] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 8, 8), 2161da9e1c0SRui Miguel Silva [HW_DACK_POL_HIGH] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 6, 6), 2171da9e1c0SRui Miguel Silva [HW_DREQ_POL_HIGH] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 5, 5), 2181da9e1c0SRui Miguel Silva [HW_INTR_HIGH_ACT] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 2, 2), 2191da9e1c0SRui Miguel Silva [HW_INTR_EDGE_TRIG] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 1, 1), 2201da9e1c0SRui Miguel Silva [HW_GLOBAL_INTR_EN] = REG_FIELD(ISP176x_HC_HW_MODE_CTRL, 0, 0), 22160d789f3SRui Miguel Silva [HC_CHIP_REV] = REG_FIELD(ISP176x_HC_CHIP_ID, 16, 31), 22260d789f3SRui Miguel Silva [HC_CHIP_ID_HIGH] = REG_FIELD(ISP176x_HC_CHIP_ID, 8, 15), 22360d789f3SRui Miguel Silva [HC_CHIP_ID_LOW] = REG_FIELD(ISP176x_HC_CHIP_ID, 0, 7), 22460d789f3SRui Miguel Silva [HC_SCRATCH] = REG_FIELD(ISP176x_HC_SCRATCH, 0, 31), 2251da9e1c0SRui Miguel Silva [SW_RESET_RESET_ALL] = REG_FIELD(ISP176x_HC_RESET, 0, 0), 22660d789f3SRui Miguel Silva [ISO_BUF_FILL] = REG_FIELD(ISP176x_HC_BUFFER_STATUS, 2, 2), 2271da9e1c0SRui Miguel Silva [INT_BUF_FILL] = REG_FIELD(ISP176x_HC_BUFFER_STATUS, 1, 1), 2281da9e1c0SRui Miguel Silva [ATL_BUF_FILL] = REG_FIELD(ISP176x_HC_BUFFER_STATUS, 0, 0), 2291da9e1c0SRui Miguel Silva [MEM_BANK_SEL] = REG_FIELD(ISP176x_HC_MEMORY, 16, 17), 2301da9e1c0SRui Miguel Silva [MEM_START_ADDR] = REG_FIELD(ISP176x_HC_MEMORY, 0, 15), 23160d789f3SRui Miguel Silva [HC_INTERRUPT] = REG_FIELD(ISP176x_HC_INTERRUPT, 0, 9), 23260d789f3SRui Miguel Silva [HC_ATL_IRQ_ENABLE] = REG_FIELD(ISP176x_HC_INTERRUPT_ENABLE, 8, 8), 23360d789f3SRui Miguel Silva [HC_INT_IRQ_ENABLE] = REG_FIELD(ISP176x_HC_INTERRUPT_ENABLE, 7, 7), 23460d789f3SRui Miguel Silva [HC_ISO_IRQ_MASK_OR] = REG_FIELD(ISP176x_HC_ISO_IRQ_MASK_OR, 0, 31), 23560d789f3SRui Miguel Silva [HC_INT_IRQ_MASK_OR] = REG_FIELD(ISP176x_HC_INT_IRQ_MASK_OR, 0, 31), 23660d789f3SRui Miguel Silva [HC_ATL_IRQ_MASK_OR] = REG_FIELD(ISP176x_HC_ATL_IRQ_MASK_OR, 0, 31), 23760d789f3SRui Miguel Silva [HC_ISO_IRQ_MASK_AND] = REG_FIELD(ISP176x_HC_ISO_IRQ_MASK_AND, 0, 31), 23860d789f3SRui Miguel Silva [HC_INT_IRQ_MASK_AND] = REG_FIELD(ISP176x_HC_INT_IRQ_MASK_AND, 0, 31), 23960d789f3SRui Miguel Silva [HC_ATL_IRQ_MASK_AND] = REG_FIELD(ISP176x_HC_ATL_IRQ_MASK_AND, 0, 31), 2409c1587d9SRui Miguel Silva [HW_OTG_DISABLE_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 26, 26), 2419c1587d9SRui Miguel Silva [HW_SW_SEL_HC_DC_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 23, 23), 2429c1587d9SRui Miguel Silva [HW_VBUS_DRV_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 20, 20), 2439c1587d9SRui Miguel Silva [HW_SEL_CP_EXT_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 19, 19), 2449c1587d9SRui Miguel Silva [HW_DM_PULLDOWN_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 18, 18), 2459c1587d9SRui Miguel Silva [HW_DP_PULLDOWN_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 17, 17), 2469c1587d9SRui Miguel Silva [HW_DP_PULLUP_CLEAR] = REG_FIELD(ISP176x_HC_OTG_CTRL, 16, 16), 2479c1587d9SRui Miguel Silva [HW_OTG_DISABLE] = REG_FIELD(ISP176x_HC_OTG_CTRL, 10, 10), 2489c1587d9SRui Miguel Silva [HW_SW_SEL_HC_DC] = REG_FIELD(ISP176x_HC_OTG_CTRL, 7, 7), 2499c1587d9SRui Miguel Silva [HW_VBUS_DRV] = REG_FIELD(ISP176x_HC_OTG_CTRL, 4, 4), 2509c1587d9SRui Miguel Silva [HW_SEL_CP_EXT] = REG_FIELD(ISP176x_HC_OTG_CTRL, 3, 3), 2519c1587d9SRui Miguel Silva [HW_DM_PULLDOWN] = REG_FIELD(ISP176x_HC_OTG_CTRL, 2, 2), 2529c1587d9SRui Miguel Silva [HW_DP_PULLDOWN] = REG_FIELD(ISP176x_HC_OTG_CTRL, 1, 1), 2539c1587d9SRui Miguel Silva [HW_DP_PULLUP] = REG_FIELD(ISP176x_HC_OTG_CTRL, 0, 0), 254*26ae2c94SLinus Walleij /* Make sure the array is sized properly during compilation */ 255*26ae2c94SLinus Walleij [HC_FIELD_MAX] = {}, 25660d789f3SRui Miguel Silva }; 25760d789f3SRui Miguel Silva 25860d789f3SRui Miguel Silva static const struct reg_field isp1763_hc_reg_fields[] = { 25960d789f3SRui Miguel Silva [CMD_LRESET] = REG_FIELD(ISP1763_HC_USBCMD, 7, 7), 26060d789f3SRui Miguel Silva [CMD_RESET] = REG_FIELD(ISP1763_HC_USBCMD, 1, 1), 26160d789f3SRui Miguel Silva [CMD_RUN] = REG_FIELD(ISP1763_HC_USBCMD, 0, 0), 26260d789f3SRui Miguel Silva [STS_PCD] = REG_FIELD(ISP1763_HC_USBSTS, 2, 2), 26360d789f3SRui Miguel Silva [HC_FRINDEX] = REG_FIELD(ISP1763_HC_FRINDEX, 0, 13), 26460d789f3SRui Miguel Silva [FLAG_CF] = REG_FIELD(ISP1763_HC_CONFIGFLAG, 0, 0), 26560d789f3SRui Miguel Silva [HC_ISO_PTD_DONEMAP] = REG_FIELD(ISP1763_HC_ISO_PTD_DONEMAP, 0, 15), 26660d789f3SRui Miguel Silva [HC_ISO_PTD_SKIPMAP] = REG_FIELD(ISP1763_HC_ISO_PTD_SKIPMAP, 0, 15), 26760d789f3SRui Miguel Silva [HC_ISO_PTD_LASTPTD] = REG_FIELD(ISP1763_HC_ISO_PTD_LASTPTD, 0, 15), 26860d789f3SRui Miguel Silva [HC_INT_PTD_DONEMAP] = REG_FIELD(ISP1763_HC_INT_PTD_DONEMAP, 0, 15), 26960d789f3SRui Miguel Silva [HC_INT_PTD_SKIPMAP] = REG_FIELD(ISP1763_HC_INT_PTD_SKIPMAP, 0, 15), 27060d789f3SRui Miguel Silva [HC_INT_PTD_LASTPTD] = REG_FIELD(ISP1763_HC_INT_PTD_LASTPTD, 0, 15), 27160d789f3SRui Miguel Silva [HC_ATL_PTD_DONEMAP] = REG_FIELD(ISP1763_HC_ATL_PTD_DONEMAP, 0, 15), 27260d789f3SRui Miguel Silva [HC_ATL_PTD_SKIPMAP] = REG_FIELD(ISP1763_HC_ATL_PTD_SKIPMAP, 0, 15), 27360d789f3SRui Miguel Silva [HC_ATL_PTD_LASTPTD] = REG_FIELD(ISP1763_HC_ATL_PTD_LASTPTD, 0, 15), 27460d789f3SRui Miguel Silva [PORT_OWNER] = REG_FIELD(ISP1763_HC_PORTSC1, 13, 13), 27560d789f3SRui Miguel Silva [PORT_POWER] = REG_FIELD(ISP1763_HC_PORTSC1, 12, 12), 27660d789f3SRui Miguel Silva [PORT_LSTATUS] = REG_FIELD(ISP1763_HC_PORTSC1, 10, 11), 27760d789f3SRui Miguel Silva [PORT_RESET] = REG_FIELD(ISP1763_HC_PORTSC1, 8, 8), 27860d789f3SRui Miguel Silva [PORT_SUSPEND] = REG_FIELD(ISP1763_HC_PORTSC1, 7, 7), 27960d789f3SRui Miguel Silva [PORT_RESUME] = REG_FIELD(ISP1763_HC_PORTSC1, 6, 6), 28060d789f3SRui Miguel Silva [PORT_PE] = REG_FIELD(ISP1763_HC_PORTSC1, 2, 2), 28160d789f3SRui Miguel Silva [PORT_CSC] = REG_FIELD(ISP1763_HC_PORTSC1, 1, 1), 28260d789f3SRui Miguel Silva [PORT_CONNECT] = REG_FIELD(ISP1763_HC_PORTSC1, 0, 0), 28360d789f3SRui Miguel Silva [HW_DATA_BUS_WIDTH] = REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 4, 4), 28460d789f3SRui Miguel Silva [HW_DACK_POL_HIGH] = REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 6, 6), 28560d789f3SRui Miguel Silva [HW_DREQ_POL_HIGH] = REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 5, 5), 28660d789f3SRui Miguel Silva [HW_INTF_LOCK] = REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 3, 3), 28760d789f3SRui Miguel Silva [HW_INTR_HIGH_ACT] = REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 2, 2), 28860d789f3SRui Miguel Silva [HW_INTR_EDGE_TRIG] = REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 1, 1), 28960d789f3SRui Miguel Silva [HW_GLOBAL_INTR_EN] = REG_FIELD(ISP1763_HC_HW_MODE_CTRL, 0, 0), 29060d789f3SRui Miguel Silva [SW_RESET_RESET_ATX] = REG_FIELD(ISP1763_HC_RESET, 3, 3), 29160d789f3SRui Miguel Silva [SW_RESET_RESET_ALL] = REG_FIELD(ISP1763_HC_RESET, 0, 0), 29260d789f3SRui Miguel Silva [HC_CHIP_ID_HIGH] = REG_FIELD(ISP1763_HC_CHIP_ID, 0, 15), 29360d789f3SRui Miguel Silva [HC_CHIP_ID_LOW] = REG_FIELD(ISP1763_HC_CHIP_REV, 8, 15), 29460d789f3SRui Miguel Silva [HC_CHIP_REV] = REG_FIELD(ISP1763_HC_CHIP_REV, 0, 7), 29560d789f3SRui Miguel Silva [HC_SCRATCH] = REG_FIELD(ISP1763_HC_SCRATCH, 0, 15), 29660d789f3SRui Miguel Silva [ISO_BUF_FILL] = REG_FIELD(ISP1763_HC_BUFFER_STATUS, 2, 2), 29760d789f3SRui Miguel Silva [INT_BUF_FILL] = REG_FIELD(ISP1763_HC_BUFFER_STATUS, 1, 1), 29860d789f3SRui Miguel Silva [ATL_BUF_FILL] = REG_FIELD(ISP1763_HC_BUFFER_STATUS, 0, 0), 29960d789f3SRui Miguel Silva [MEM_START_ADDR] = REG_FIELD(ISP1763_HC_MEMORY, 0, 15), 30060d789f3SRui Miguel Silva [HC_DATA] = REG_FIELD(ISP1763_HC_DATA, 0, 15), 30160d789f3SRui Miguel Silva [HC_INTERRUPT] = REG_FIELD(ISP1763_HC_INTERRUPT, 0, 10), 30260d789f3SRui Miguel Silva [HC_ATL_IRQ_ENABLE] = REG_FIELD(ISP1763_HC_INTERRUPT_ENABLE, 8, 8), 30360d789f3SRui Miguel Silva [HC_INT_IRQ_ENABLE] = REG_FIELD(ISP1763_HC_INTERRUPT_ENABLE, 7, 7), 30460d789f3SRui Miguel Silva [HC_ISO_IRQ_MASK_OR] = REG_FIELD(ISP1763_HC_ISO_IRQ_MASK_OR, 0, 15), 30560d789f3SRui Miguel Silva [HC_INT_IRQ_MASK_OR] = REG_FIELD(ISP1763_HC_INT_IRQ_MASK_OR, 0, 15), 30660d789f3SRui Miguel Silva [HC_ATL_IRQ_MASK_OR] = REG_FIELD(ISP1763_HC_ATL_IRQ_MASK_OR, 0, 15), 30760d789f3SRui Miguel Silva [HC_ISO_IRQ_MASK_AND] = REG_FIELD(ISP1763_HC_ISO_IRQ_MASK_AND, 0, 15), 30860d789f3SRui Miguel Silva [HC_INT_IRQ_MASK_AND] = REG_FIELD(ISP1763_HC_INT_IRQ_MASK_AND, 0, 15), 30960d789f3SRui Miguel Silva [HC_ATL_IRQ_MASK_AND] = REG_FIELD(ISP1763_HC_ATL_IRQ_MASK_AND, 0, 15), 31060d789f3SRui Miguel Silva [HW_HC_2_DIS] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 15, 15), 31160d789f3SRui Miguel Silva [HW_OTG_DISABLE] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 10, 10), 31260d789f3SRui Miguel Silva [HW_SW_SEL_HC_DC] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 7, 7), 31360d789f3SRui Miguel Silva [HW_VBUS_DRV] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 4, 4), 31460d789f3SRui Miguel Silva [HW_SEL_CP_EXT] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 3, 3), 31560d789f3SRui Miguel Silva [HW_DM_PULLDOWN] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 2, 2), 31660d789f3SRui Miguel Silva [HW_DP_PULLDOWN] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 1, 1), 31760d789f3SRui Miguel Silva [HW_DP_PULLUP] = REG_FIELD(ISP1763_HC_OTG_CTRL_SET, 0, 0), 31860d789f3SRui Miguel Silva [HW_HC_2_DIS_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 15, 15), 31960d789f3SRui Miguel Silva [HW_OTG_DISABLE_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 10, 10), 32060d789f3SRui Miguel Silva [HW_SW_SEL_HC_DC_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 7, 7), 32160d789f3SRui Miguel Silva [HW_VBUS_DRV_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 4, 4), 32260d789f3SRui Miguel Silva [HW_SEL_CP_EXT_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 3, 3), 32360d789f3SRui Miguel Silva [HW_DM_PULLDOWN_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 2, 2), 32460d789f3SRui Miguel Silva [HW_DP_PULLDOWN_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 1, 1), 32560d789f3SRui Miguel Silva [HW_DP_PULLUP_CLEAR] = REG_FIELD(ISP1763_HC_OTG_CTRL_CLEAR, 0, 0), 326*26ae2c94SLinus Walleij /* Make sure the array is sized properly during compilation */ 327*26ae2c94SLinus Walleij [HC_FIELD_MAX] = {}, 32860d789f3SRui Miguel Silva }; 32960d789f3SRui Miguel Silva 33060d789f3SRui Miguel Silva static const struct regmap_range isp1763_hc_volatile_ranges[] = { 33160d789f3SRui Miguel Silva regmap_reg_range(ISP1763_HC_USBCMD, ISP1763_HC_ATL_PTD_LASTPTD), 33260d789f3SRui Miguel Silva regmap_reg_range(ISP1763_HC_BUFFER_STATUS, ISP1763_HC_DATA), 33360d789f3SRui Miguel Silva regmap_reg_range(ISP1763_HC_INTERRUPT, ISP1763_HC_OTG_CTRL_CLEAR), 33460d789f3SRui Miguel Silva }; 33560d789f3SRui Miguel Silva 33660d789f3SRui Miguel Silva static const struct regmap_access_table isp1763_hc_volatile_table = { 33760d789f3SRui Miguel Silva .yes_ranges = isp1763_hc_volatile_ranges, 33860d789f3SRui Miguel Silva .n_yes_ranges = ARRAY_SIZE(isp1763_hc_volatile_ranges), 33960d789f3SRui Miguel Silva }; 34060d789f3SRui Miguel Silva 34160d789f3SRui Miguel Silva static const struct regmap_config isp1763_hc_regmap_conf = { 34260d789f3SRui Miguel Silva .name = "isp1763-hc", 34360d789f3SRui Miguel Silva .reg_bits = 8, 34460d789f3SRui Miguel Silva .reg_stride = 2, 34560d789f3SRui Miguel Silva .val_bits = 16, 34660d789f3SRui Miguel Silva .fast_io = true, 34760d789f3SRui Miguel Silva .max_register = ISP1763_HC_OTG_CTRL_CLEAR, 34860d789f3SRui Miguel Silva .volatile_table = &isp1763_hc_volatile_table, 3491da9e1c0SRui Miguel Silva }; 3501da9e1c0SRui Miguel Silva 3511da9e1c0SRui Miguel Silva static const struct regmap_range isp176x_dc_volatile_ranges[] = { 3521da9e1c0SRui Miguel Silva regmap_reg_range(ISP176x_DC_EPMAXPKTSZ, ISP176x_DC_EPTYPE), 3531da9e1c0SRui Miguel Silva regmap_reg_range(ISP176x_DC_BUFLEN, ISP176x_DC_EPINDEX), 3541da9e1c0SRui Miguel Silva }; 3551da9e1c0SRui Miguel Silva 3561da9e1c0SRui Miguel Silva static const struct regmap_access_table isp176x_dc_volatile_table = { 3571da9e1c0SRui Miguel Silva .yes_ranges = isp176x_dc_volatile_ranges, 3581da9e1c0SRui Miguel Silva .n_yes_ranges = ARRAY_SIZE(isp176x_dc_volatile_ranges), 3591da9e1c0SRui Miguel Silva }; 3601da9e1c0SRui Miguel Silva 36160d789f3SRui Miguel Silva static const struct regmap_config isp1761_dc_regmap_conf = { 3621da9e1c0SRui Miguel Silva .name = "isp1761-dc", 3631da9e1c0SRui Miguel Silva .reg_bits = 16, 3641da9e1c0SRui Miguel Silva .reg_stride = 4, 3651da9e1c0SRui Miguel Silva .val_bits = 32, 3661da9e1c0SRui Miguel Silva .fast_io = true, 36760d789f3SRui Miguel Silva .max_register = ISP176x_DC_TESTMODE, 3681da9e1c0SRui Miguel Silva .volatile_table = &isp176x_dc_volatile_table, 3691da9e1c0SRui Miguel Silva }; 3701da9e1c0SRui Miguel Silva 3711da9e1c0SRui Miguel Silva static const struct reg_field isp1761_dc_reg_fields[] = { 3721da9e1c0SRui Miguel Silva [DC_DEVEN] = REG_FIELD(ISP176x_DC_ADDRESS, 7, 7), 3731da9e1c0SRui Miguel Silva [DC_DEVADDR] = REG_FIELD(ISP176x_DC_ADDRESS, 0, 6), 3741da9e1c0SRui Miguel Silva [DC_VBUSSTAT] = REG_FIELD(ISP176x_DC_MODE, 8, 8), 3751da9e1c0SRui Miguel Silva [DC_SFRESET] = REG_FIELD(ISP176x_DC_MODE, 4, 4), 3761da9e1c0SRui Miguel Silva [DC_GLINTENA] = REG_FIELD(ISP176x_DC_MODE, 3, 3), 3771da9e1c0SRui Miguel Silva [DC_CDBGMOD_ACK] = REG_FIELD(ISP176x_DC_INTCONF, 6, 6), 3781da9e1c0SRui Miguel Silva [DC_DDBGMODIN_ACK] = REG_FIELD(ISP176x_DC_INTCONF, 4, 4), 3791da9e1c0SRui Miguel Silva [DC_DDBGMODOUT_ACK] = REG_FIELD(ISP176x_DC_INTCONF, 2, 2), 3801da9e1c0SRui Miguel Silva [DC_INTPOL] = REG_FIELD(ISP176x_DC_INTCONF, 0, 0), 3811da9e1c0SRui Miguel Silva [DC_IEPRXTX_7] = REG_FIELD(ISP176x_DC_INTENABLE, 25, 25), 3821da9e1c0SRui Miguel Silva [DC_IEPRXTX_6] = REG_FIELD(ISP176x_DC_INTENABLE, 23, 23), 3831da9e1c0SRui Miguel Silva [DC_IEPRXTX_5] = REG_FIELD(ISP176x_DC_INTENABLE, 21, 21), 3841da9e1c0SRui Miguel Silva [DC_IEPRXTX_4] = REG_FIELD(ISP176x_DC_INTENABLE, 19, 19), 3851da9e1c0SRui Miguel Silva [DC_IEPRXTX_3] = REG_FIELD(ISP176x_DC_INTENABLE, 17, 17), 3861da9e1c0SRui Miguel Silva [DC_IEPRXTX_2] = REG_FIELD(ISP176x_DC_INTENABLE, 15, 15), 3871da9e1c0SRui Miguel Silva [DC_IEPRXTX_1] = REG_FIELD(ISP176x_DC_INTENABLE, 13, 13), 3881da9e1c0SRui Miguel Silva [DC_IEPRXTX_0] = REG_FIELD(ISP176x_DC_INTENABLE, 11, 11), 3891da9e1c0SRui Miguel Silva [DC_IEP0SETUP] = REG_FIELD(ISP176x_DC_INTENABLE, 8, 8), 3901da9e1c0SRui Miguel Silva [DC_IEVBUS] = REG_FIELD(ISP176x_DC_INTENABLE, 7, 7), 3911da9e1c0SRui Miguel Silva [DC_IEHS_STA] = REG_FIELD(ISP176x_DC_INTENABLE, 5, 5), 3921da9e1c0SRui Miguel Silva [DC_IERESM] = REG_FIELD(ISP176x_DC_INTENABLE, 4, 4), 3931da9e1c0SRui Miguel Silva [DC_IESUSP] = REG_FIELD(ISP176x_DC_INTENABLE, 3, 3), 3941da9e1c0SRui Miguel Silva [DC_IEBRST] = REG_FIELD(ISP176x_DC_INTENABLE, 0, 0), 3951da9e1c0SRui Miguel Silva [DC_EP0SETUP] = REG_FIELD(ISP176x_DC_EPINDEX, 5, 5), 3961da9e1c0SRui Miguel Silva [DC_ENDPIDX] = REG_FIELD(ISP176x_DC_EPINDEX, 1, 4), 3971da9e1c0SRui Miguel Silva [DC_EPDIR] = REG_FIELD(ISP176x_DC_EPINDEX, 0, 0), 3981da9e1c0SRui Miguel Silva [DC_CLBUF] = REG_FIELD(ISP176x_DC_CTRLFUNC, 4, 4), 3991da9e1c0SRui Miguel Silva [DC_VENDP] = REG_FIELD(ISP176x_DC_CTRLFUNC, 3, 3), 4001da9e1c0SRui Miguel Silva [DC_DSEN] = REG_FIELD(ISP176x_DC_CTRLFUNC, 2, 2), 4011da9e1c0SRui Miguel Silva [DC_STATUS] = REG_FIELD(ISP176x_DC_CTRLFUNC, 1, 1), 4021da9e1c0SRui Miguel Silva [DC_STALL] = REG_FIELD(ISP176x_DC_CTRLFUNC, 0, 0), 4031da9e1c0SRui Miguel Silva [DC_BUFLEN] = REG_FIELD(ISP176x_DC_BUFLEN, 0, 15), 4041da9e1c0SRui Miguel Silva [DC_FFOSZ] = REG_FIELD(ISP176x_DC_EPMAXPKTSZ, 0, 10), 4051da9e1c0SRui Miguel Silva [DC_EPENABLE] = REG_FIELD(ISP176x_DC_EPTYPE, 3, 3), 4061da9e1c0SRui Miguel Silva [DC_ENDPTYP] = REG_FIELD(ISP176x_DC_EPTYPE, 0, 1), 4071da9e1c0SRui Miguel Silva [DC_UFRAMENUM] = REG_FIELD(ISP176x_DC_FRAMENUM, 11, 13), 4081da9e1c0SRui Miguel Silva [DC_FRAMENUM] = REG_FIELD(ISP176x_DC_FRAMENUM, 0, 10), 40960d789f3SRui Miguel Silva [DC_CHIP_ID_HIGH] = REG_FIELD(ISP176x_DC_CHIPID, 16, 31), 41060d789f3SRui Miguel Silva [DC_CHIP_ID_LOW] = REG_FIELD(ISP176x_DC_CHIPID, 0, 15), 41160d789f3SRui Miguel Silva [DC_SCRATCH] = REG_FIELD(ISP176x_DC_SCRATCH, 0, 15), 412*26ae2c94SLinus Walleij /* Make sure the array is sized properly during compilation */ 413*26ae2c94SLinus Walleij [DC_FIELD_MAX] = {}, 41460d789f3SRui Miguel Silva }; 41560d789f3SRui Miguel Silva 41660d789f3SRui Miguel Silva static const struct regmap_range isp1763_dc_volatile_ranges[] = { 41760d789f3SRui Miguel Silva regmap_reg_range(ISP1763_DC_EPMAXPKTSZ, ISP1763_DC_EPTYPE), 41860d789f3SRui Miguel Silva regmap_reg_range(ISP1763_DC_BUFLEN, ISP1763_DC_EPINDEX), 41960d789f3SRui Miguel Silva }; 42060d789f3SRui Miguel Silva 42160d789f3SRui Miguel Silva static const struct regmap_access_table isp1763_dc_volatile_table = { 42260d789f3SRui Miguel Silva .yes_ranges = isp1763_dc_volatile_ranges, 42360d789f3SRui Miguel Silva .n_yes_ranges = ARRAY_SIZE(isp1763_dc_volatile_ranges), 42460d789f3SRui Miguel Silva }; 42560d789f3SRui Miguel Silva 42660d789f3SRui Miguel Silva static const struct reg_field isp1763_dc_reg_fields[] = { 42760d789f3SRui Miguel Silva [DC_DEVEN] = REG_FIELD(ISP1763_DC_ADDRESS, 7, 7), 42860d789f3SRui Miguel Silva [DC_DEVADDR] = REG_FIELD(ISP1763_DC_ADDRESS, 0, 6), 42960d789f3SRui Miguel Silva [DC_VBUSSTAT] = REG_FIELD(ISP1763_DC_MODE, 8, 8), 43060d789f3SRui Miguel Silva [DC_SFRESET] = REG_FIELD(ISP1763_DC_MODE, 4, 4), 43160d789f3SRui Miguel Silva [DC_GLINTENA] = REG_FIELD(ISP1763_DC_MODE, 3, 3), 43260d789f3SRui Miguel Silva [DC_CDBGMOD_ACK] = REG_FIELD(ISP1763_DC_INTCONF, 6, 6), 43360d789f3SRui Miguel Silva [DC_DDBGMODIN_ACK] = REG_FIELD(ISP1763_DC_INTCONF, 4, 4), 43460d789f3SRui Miguel Silva [DC_DDBGMODOUT_ACK] = REG_FIELD(ISP1763_DC_INTCONF, 2, 2), 43560d789f3SRui Miguel Silva [DC_INTPOL] = REG_FIELD(ISP1763_DC_INTCONF, 0, 0), 43660d789f3SRui Miguel Silva [DC_IEPRXTX_7] = REG_FIELD(ISP1763_DC_INTENABLE, 25, 25), 43760d789f3SRui Miguel Silva [DC_IEPRXTX_6] = REG_FIELD(ISP1763_DC_INTENABLE, 23, 23), 43860d789f3SRui Miguel Silva [DC_IEPRXTX_5] = REG_FIELD(ISP1763_DC_INTENABLE, 21, 21), 43960d789f3SRui Miguel Silva [DC_IEPRXTX_4] = REG_FIELD(ISP1763_DC_INTENABLE, 19, 19), 44060d789f3SRui Miguel Silva [DC_IEPRXTX_3] = REG_FIELD(ISP1763_DC_INTENABLE, 17, 17), 44160d789f3SRui Miguel Silva [DC_IEPRXTX_2] = REG_FIELD(ISP1763_DC_INTENABLE, 15, 15), 44260d789f3SRui Miguel Silva [DC_IEPRXTX_1] = REG_FIELD(ISP1763_DC_INTENABLE, 13, 13), 44360d789f3SRui Miguel Silva [DC_IEPRXTX_0] = REG_FIELD(ISP1763_DC_INTENABLE, 11, 11), 44460d789f3SRui Miguel Silva [DC_IEP0SETUP] = REG_FIELD(ISP1763_DC_INTENABLE, 8, 8), 44560d789f3SRui Miguel Silva [DC_IEVBUS] = REG_FIELD(ISP1763_DC_INTENABLE, 7, 7), 44660d789f3SRui Miguel Silva [DC_IEHS_STA] = REG_FIELD(ISP1763_DC_INTENABLE, 5, 5), 44760d789f3SRui Miguel Silva [DC_IERESM] = REG_FIELD(ISP1763_DC_INTENABLE, 4, 4), 44860d789f3SRui Miguel Silva [DC_IESUSP] = REG_FIELD(ISP1763_DC_INTENABLE, 3, 3), 44960d789f3SRui Miguel Silva [DC_IEBRST] = REG_FIELD(ISP1763_DC_INTENABLE, 0, 0), 45060d789f3SRui Miguel Silva [DC_EP0SETUP] = REG_FIELD(ISP1763_DC_EPINDEX, 5, 5), 45160d789f3SRui Miguel Silva [DC_ENDPIDX] = REG_FIELD(ISP1763_DC_EPINDEX, 1, 4), 45260d789f3SRui Miguel Silva [DC_EPDIR] = REG_FIELD(ISP1763_DC_EPINDEX, 0, 0), 45360d789f3SRui Miguel Silva [DC_CLBUF] = REG_FIELD(ISP1763_DC_CTRLFUNC, 4, 4), 45460d789f3SRui Miguel Silva [DC_VENDP] = REG_FIELD(ISP1763_DC_CTRLFUNC, 3, 3), 45560d789f3SRui Miguel Silva [DC_DSEN] = REG_FIELD(ISP1763_DC_CTRLFUNC, 2, 2), 45660d789f3SRui Miguel Silva [DC_STATUS] = REG_FIELD(ISP1763_DC_CTRLFUNC, 1, 1), 45760d789f3SRui Miguel Silva [DC_STALL] = REG_FIELD(ISP1763_DC_CTRLFUNC, 0, 0), 45860d789f3SRui Miguel Silva [DC_BUFLEN] = REG_FIELD(ISP1763_DC_BUFLEN, 0, 15), 45960d789f3SRui Miguel Silva [DC_FFOSZ] = REG_FIELD(ISP1763_DC_EPMAXPKTSZ, 0, 10), 46060d789f3SRui Miguel Silva [DC_EPENABLE] = REG_FIELD(ISP1763_DC_EPTYPE, 3, 3), 46160d789f3SRui Miguel Silva [DC_ENDPTYP] = REG_FIELD(ISP1763_DC_EPTYPE, 0, 1), 46260d789f3SRui Miguel Silva [DC_UFRAMENUM] = REG_FIELD(ISP1763_DC_FRAMENUM, 11, 13), 46360d789f3SRui Miguel Silva [DC_FRAMENUM] = REG_FIELD(ISP1763_DC_FRAMENUM, 0, 10), 46460d789f3SRui Miguel Silva [DC_CHIP_ID_HIGH] = REG_FIELD(ISP1763_DC_CHIPID_HIGH, 0, 15), 46560d789f3SRui Miguel Silva [DC_CHIP_ID_LOW] = REG_FIELD(ISP1763_DC_CHIPID_LOW, 0, 15), 46660d789f3SRui Miguel Silva [DC_SCRATCH] = REG_FIELD(ISP1763_DC_SCRATCH, 0, 15), 467*26ae2c94SLinus Walleij /* Make sure the array is sized properly during compilation */ 468*26ae2c94SLinus Walleij [DC_FIELD_MAX] = {}, 46960d789f3SRui Miguel Silva }; 47060d789f3SRui Miguel Silva 47160d789f3SRui Miguel Silva static const struct regmap_config isp1763_dc_regmap_conf = { 47260d789f3SRui Miguel Silva .name = "isp1763-dc", 47360d789f3SRui Miguel Silva .reg_bits = 8, 47460d789f3SRui Miguel Silva .reg_stride = 2, 47560d789f3SRui Miguel Silva .val_bits = 16, 47660d789f3SRui Miguel Silva .fast_io = true, 47760d789f3SRui Miguel Silva .max_register = ISP1763_DC_TESTMODE, 47860d789f3SRui Miguel Silva .volatile_table = &isp1763_dc_volatile_table, 4791da9e1c0SRui Miguel Silva }; 4801da9e1c0SRui Miguel Silva 4817ef077a8SLaurent Pinchart int isp1760_register(struct resource *mem, int irq, unsigned long irqflags, 4827ef077a8SLaurent Pinchart struct device *dev, unsigned int devflags) 4837ef077a8SLaurent Pinchart { 48460d789f3SRui Miguel Silva const struct regmap_config *hc_regmap; 48560d789f3SRui Miguel Silva const struct reg_field *hc_reg_fields; 486d369c918SRui Miguel Silva const struct regmap_config *dc_regmap; 487d369c918SRui Miguel Silva const struct reg_field *dc_reg_fields; 4887ef077a8SLaurent Pinchart struct isp1760_device *isp; 4891da9e1c0SRui Miguel Silva struct isp1760_hcd *hcd; 4901da9e1c0SRui Miguel Silva struct isp1760_udc *udc; 4911da9e1c0SRui Miguel Silva struct regmap_field *f; 492d369c918SRui Miguel Silva bool udc_enabled; 4937ef077a8SLaurent Pinchart int ret; 4941da9e1c0SRui Miguel Silva int i; 4957ef077a8SLaurent Pinchart 496d21daf1eSLaurent Pinchart /* 497d21daf1eSLaurent Pinchart * If neither the HCD not the UDC is enabled return an error, as no 498d21daf1eSLaurent Pinchart * device would be registered. 499d21daf1eSLaurent Pinchart */ 500d369c918SRui Miguel Silva udc_enabled = ((devflags & ISP1760_FLAG_ISP1763) || 501d369c918SRui Miguel Silva (devflags & ISP1760_FLAG_ISP1761)); 502d369c918SRui Miguel Silva 503d21daf1eSLaurent Pinchart if ((!IS_ENABLED(CONFIG_USB_ISP1760_HCD) || usb_disabled()) && 504de940244SRui Miguel Silva (!udc_enabled || !IS_ENABLED(CONFIG_USB_ISP1761_UDC))) 5057ef077a8SLaurent Pinchart return -ENODEV; 5067ef077a8SLaurent Pinchart 5077ef077a8SLaurent Pinchart isp = devm_kzalloc(dev, sizeof(*isp), GFP_KERNEL); 5087ef077a8SLaurent Pinchart if (!isp) 5097ef077a8SLaurent Pinchart return -ENOMEM; 5107ef077a8SLaurent Pinchart 5117ef077a8SLaurent Pinchart isp->dev = dev; 5127ef077a8SLaurent Pinchart isp->devflags = devflags; 5131da9e1c0SRui Miguel Silva hcd = &isp->hcd; 5141da9e1c0SRui Miguel Silva udc = &isp->udc; 5151da9e1c0SRui Miguel Silva 51660d789f3SRui Miguel Silva hcd->is_isp1763 = !!(devflags & ISP1760_FLAG_ISP1763); 517d369c918SRui Miguel Silva udc->is_isp1763 = !!(devflags & ISP1760_FLAG_ISP1763); 51860d789f3SRui Miguel Silva 51960d789f3SRui Miguel Silva if (!hcd->is_isp1763 && (devflags & ISP1760_FLAG_BUS_WIDTH_8)) { 52060d789f3SRui Miguel Silva dev_err(dev, "isp1760/61 do not support data width 8\n"); 52160d789f3SRui Miguel Silva return -EINVAL; 52260d789f3SRui Miguel Silva } 52360d789f3SRui Miguel Silva 52460d789f3SRui Miguel Silva if (hcd->is_isp1763) { 52560d789f3SRui Miguel Silva hc_regmap = &isp1763_hc_regmap_conf; 52660d789f3SRui Miguel Silva hc_reg_fields = &isp1763_hc_reg_fields[0]; 527d369c918SRui Miguel Silva dc_regmap = &isp1763_dc_regmap_conf; 528d369c918SRui Miguel Silva dc_reg_fields = &isp1763_dc_reg_fields[0]; 52960d789f3SRui Miguel Silva } else { 53060d789f3SRui Miguel Silva hc_regmap = &isp1760_hc_regmap_conf; 53160d789f3SRui Miguel Silva hc_reg_fields = &isp1760_hc_reg_fields[0]; 532d369c918SRui Miguel Silva dc_regmap = &isp1761_dc_regmap_conf; 533d369c918SRui Miguel Silva dc_reg_fields = &isp1761_dc_reg_fields[0]; 5341da9e1c0SRui Miguel Silva } 5357ef077a8SLaurent Pinchart 5367ef077a8SLaurent Pinchart isp->rst_gpio = devm_gpiod_get_optional(dev, NULL, GPIOD_OUT_HIGH); 5377ef077a8SLaurent Pinchart if (IS_ERR(isp->rst_gpio)) 5387ef077a8SLaurent Pinchart return PTR_ERR(isp->rst_gpio); 5397ef077a8SLaurent Pinchart 5401da9e1c0SRui Miguel Silva hcd->base = devm_ioremap_resource(dev, mem); 5411da9e1c0SRui Miguel Silva if (IS_ERR(hcd->base)) 5421da9e1c0SRui Miguel Silva return PTR_ERR(hcd->base); 5431da9e1c0SRui Miguel Silva 54460d789f3SRui Miguel Silva hcd->regs = devm_regmap_init_mmio(dev, hcd->base, hc_regmap); 5451da9e1c0SRui Miguel Silva if (IS_ERR(hcd->regs)) 5461da9e1c0SRui Miguel Silva return PTR_ERR(hcd->regs); 5471da9e1c0SRui Miguel Silva 5481da9e1c0SRui Miguel Silva for (i = 0; i < HC_FIELD_MAX; i++) { 54960d789f3SRui Miguel Silva f = devm_regmap_field_alloc(dev, hcd->regs, hc_reg_fields[i]); 5501da9e1c0SRui Miguel Silva if (IS_ERR(f)) 5511da9e1c0SRui Miguel Silva return PTR_ERR(f); 5521da9e1c0SRui Miguel Silva 5531da9e1c0SRui Miguel Silva hcd->fields[i] = f; 5541da9e1c0SRui Miguel Silva } 5551da9e1c0SRui Miguel Silva 556d369c918SRui Miguel Silva udc->regs = devm_regmap_init_mmio(dev, hcd->base, dc_regmap); 5571da9e1c0SRui Miguel Silva if (IS_ERR(udc->regs)) 5581da9e1c0SRui Miguel Silva return PTR_ERR(udc->regs); 5591da9e1c0SRui Miguel Silva 5601da9e1c0SRui Miguel Silva for (i = 0; i < DC_FIELD_MAX; i++) { 561d369c918SRui Miguel Silva f = devm_regmap_field_alloc(dev, udc->regs, dc_reg_fields[i]); 5621da9e1c0SRui Miguel Silva if (IS_ERR(f)) 5631da9e1c0SRui Miguel Silva return PTR_ERR(f); 5641da9e1c0SRui Miguel Silva 5651da9e1c0SRui Miguel Silva udc->fields[i] = f; 5661da9e1c0SRui Miguel Silva } 5677ef077a8SLaurent Pinchart 56860d789f3SRui Miguel Silva if (hcd->is_isp1763) 56960d789f3SRui Miguel Silva hcd->memory_layout = &isp1763_memory_conf; 57060d789f3SRui Miguel Silva else 571a74f639cSRui Miguel Silva hcd->memory_layout = &isp176x_memory_conf; 572a74f639cSRui Miguel Silva 57360d789f3SRui Miguel Silva ret = isp1760_init_core(isp); 57460d789f3SRui Miguel Silva if (ret < 0) 57560d789f3SRui Miguel Silva return ret; 5767ef077a8SLaurent Pinchart 577d21daf1eSLaurent Pinchart if (IS_ENABLED(CONFIG_USB_ISP1760_HCD) && !usb_disabled()) { 5781da9e1c0SRui Miguel Silva ret = isp1760_hcd_register(hcd, mem, irq, 5797ef077a8SLaurent Pinchart irqflags | IRQF_SHARED, dev); 5807ef077a8SLaurent Pinchart if (ret < 0) 5817ef077a8SLaurent Pinchart return ret; 582d21daf1eSLaurent Pinchart } 5837ef077a8SLaurent Pinchart 584de940244SRui Miguel Silva if (udc_enabled && IS_ENABLED(CONFIG_USB_ISP1761_UDC)) { 58580b4a0f8SValentin Rothberg ret = isp1760_udc_register(isp, irq, irqflags); 5867ef077a8SLaurent Pinchart if (ret < 0) { 5871da9e1c0SRui Miguel Silva isp1760_hcd_unregister(hcd); 5887ef077a8SLaurent Pinchart return ret; 5897ef077a8SLaurent Pinchart } 5907ef077a8SLaurent Pinchart } 5917ef077a8SLaurent Pinchart 5927ef077a8SLaurent Pinchart dev_set_drvdata(dev, isp); 5937ef077a8SLaurent Pinchart 5947ef077a8SLaurent Pinchart return 0; 5957ef077a8SLaurent Pinchart } 5967ef077a8SLaurent Pinchart 5977ef077a8SLaurent Pinchart void isp1760_unregister(struct device *dev) 5987ef077a8SLaurent Pinchart { 5997ef077a8SLaurent Pinchart struct isp1760_device *isp = dev_get_drvdata(dev); 6007ef077a8SLaurent Pinchart 6017ef077a8SLaurent Pinchart isp1760_udc_unregister(isp); 6027ef077a8SLaurent Pinchart isp1760_hcd_unregister(&isp->hcd); 6037ef077a8SLaurent Pinchart } 6047ef077a8SLaurent Pinchart 6057ef077a8SLaurent Pinchart MODULE_DESCRIPTION("Driver for the ISP1760 USB-controller from NXP"); 6067ef077a8SLaurent Pinchart MODULE_AUTHOR("Sebastian Siewior <bigeasy@linuxtronix.de>"); 6077ef077a8SLaurent Pinchart MODULE_LICENSE("GPL v2"); 608