From 850b307789dca8dfff6d7cad57ba2ffbfbb5f6ed Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Wed, 20 Mar 2024 14:30:47 +0000 Subject: usb: dwc3-generic: implement Qualcomm wrapper The Qualcomm specific dwc3 wrapper isn't hugely complicated, implemented the missing initialisation for host and gadget mode. Reviewed-by: Mattijs Korpershoek Reviewed-by: Marek Vasut Reviewed-by: Neil Armstrong Signed-off-by: Caleb Connolly Link: https://lore.kernel.org/r/20240320-b4-qcom-usb-v4-1-41be480172e1@linaro.org Signed-off-by: Mattijs Korpershoek --- drivers/usb/dwc3/dwc3-generic.c | 81 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index a379a0002e..7a00529a2a 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -425,6 +425,77 @@ struct dwc3_glue_ops ti_ops = { .glue_configure = dwc3_ti_glue_configure, }; +/* USB QSCRATCH Hardware registers */ +#define QSCRATCH_GENERAL_CFG 0x08 +#define PIPE_UTMI_CLK_SEL BIT(0) +#define PIPE3_PHYSTATUS_SW BIT(3) +#define PIPE_UTMI_CLK_DIS BIT(8) + +#define QSCRATCH_HS_PHY_CTRL 0x10 +#define UTMI_OTG_VBUS_VALID BIT(20) +#define SW_SESSVLD_SEL BIT(28) + +#define QSCRATCH_SS_PHY_CTRL 0x30 +#define LANE0_PWR_PRESENT BIT(24) + +#define PWR_EVNT_IRQ_STAT_REG 0x58 +#define PWR_EVNT_LPM_IN_L2_MASK BIT(4) +#define PWR_EVNT_LPM_OUT_L2_MASK BIT(5) + +#define SDM845_QSCRATCH_BASE_OFFSET 0xf8800 +#define SDM845_QSCRATCH_SIZE 0x400 +#define SDM845_DWC3_CORE_SIZE 0xcd00 + +static void dwc3_qcom_vbus_override_enable(void __iomem *qscratch_base, bool enable) +{ + if (enable) { + setbits_le32(qscratch_base + QSCRATCH_SS_PHY_CTRL, + LANE0_PWR_PRESENT); + setbits_le32(qscratch_base + QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + } else { + clrbits_le32(qscratch_base + QSCRATCH_SS_PHY_CTRL, + LANE0_PWR_PRESENT); + clrbits_le32(qscratch_base + QSCRATCH_HS_PHY_CTRL, + UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); + } +} + +/* For controllers running without superspeed PHYs */ +static void dwc3_qcom_select_utmi_clk(void __iomem *qscratch_base) +{ + /* Configure dwc3 to use UTMI clock as PIPE clock not present */ + setbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_DIS); + + setbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW); + + clrbits_le32(qscratch_base + QSCRATCH_GENERAL_CFG, + PIPE_UTMI_CLK_DIS); +} + +static void dwc3_qcom_glue_configure(struct udevice *dev, int index, + enum usb_dr_mode mode) +{ + struct dwc3_glue_data *glue = dev_get_plat(dev); + void __iomem *qscratch_base = map_physmem(glue->regs, 0x400, MAP_NOCACHE); + if (IS_ERR_OR_NULL(qscratch_base)) { + log_err("%s: Invalid qscratch base address\n", dev->name); + return; + } + + if (dev_read_bool(dev, "qcom,select-utmi-as-pipe-clk")) + dwc3_qcom_select_utmi_clk(qscratch_base); + + if (mode != USB_DR_MODE_HOST) + dwc3_qcom_vbus_override_enable(qscratch_base, true); +} + +struct dwc3_glue_ops qcom_ops = { + .glue_configure = dwc3_qcom_glue_configure, +}; + static int dwc3_rk_glue_get_ctrl_dev(struct udevice *dev, ofnode *node) { *node = dev_ofnode(dev); @@ -512,6 +583,14 @@ static int dwc3_glue_reset_init(struct udevice *dev, else if (ret) return ret; + if (device_is_compatible(dev, "qcom,dwc3")) { + reset_assert_bulk(&glue->resets); + /* We should wait at least 6 sleep clock cycles, that's + * (6 / 32764) * 1000000 ~= 200us. But some platforms + * have slower sleep clocks so we'll play it safe. + */ + udelay(500); + } ret = reset_deassert_bulk(&glue->resets); if (ret) { reset_release_bulk(&glue->resets); @@ -629,7 +708,7 @@ static const struct udevice_id dwc3_glue_ids[] = { { .compatible = "rockchip,rk3399-dwc3" }, { .compatible = "rockchip,rk3568-dwc3", .data = (ulong)&rk_ops }, { .compatible = "rockchip,rk3588-dwc3", .data = (ulong)&rk_ops }, - { .compatible = "qcom,dwc3" }, + { .compatible = "qcom,dwc3", .data = (ulong)&qcom_ops }, { .compatible = "fsl,imx8mp-dwc3", .data = (ulong)&imx8mp_ops }, { .compatible = "fsl,imx8mq-dwc3" }, { .compatible = "intel,tangier-dwc3" }, -- cgit v1.2.3 From 341a172ef7867e3bfa90d6951997e5e2f168e188 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Wed, 20 Mar 2024 14:30:49 +0000 Subject: usb: gadget: CDC ACM: call usb_gadget_initialize To actually use the gadget the peripheral driver must be probed and we must call g_dnl_clear_detach(). Otherwise acm_stdio_start() will always fail to find a UDC on DT platforms. Reviewed-by: Mattijs Korpershoek Reviewed-by: Neil Armstrong Signed-off-by: Caleb Connolly Link: https://lore.kernel.org/r/20240320-b4-qcom-usb-v4-3-41be480172e1@linaro.org Signed-off-by: Mattijs Korpershoek --- drivers/usb/gadget/f_acm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c index de42e0189e..ba216128ab 100644 --- a/drivers/usb/gadget/f_acm.c +++ b/drivers/usb/gadget/f_acm.c @@ -623,12 +623,21 @@ static void acm_stdio_puts(struct stdio_dev *dev, const char *str) static int acm_stdio_start(struct stdio_dev *dev) { + struct udevice *udc; int ret; if (dev->priv) { /* function already exist */ return 0; } + ret = udc_device_get_by_index(0, &udc); + if (ret) { + pr_err("USB init failed: %d\n", ret); + return ret; + } + + g_dnl_clear_detach(); + ret = g_dnl_register("usb_serial_acm"); if (ret) return ret; -- cgit v1.2.3 From 304fa0aa445384e5e681a54abf413850591cec10 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Wed, 20 Mar 2024 14:30:50 +0000 Subject: usb: gadget: UMS: support multiple sector sizes UFS storage often uses a 4096-byte sector size, add support for dynamic sector sizes based loosely on the Linux implementation. Support for dynamic sector sizes changes the types used in some divisions, resulting in the compiler attempting to use libgcc helpers (__aeabi_ldivmod). Replace these divisions with calls to lldiv() to handle this correctly. Reviewed-by: Mattijs Korpershoek Reviewed-by: Neil Armstrong Signed-off-by: Caleb Connolly Link: https://lore.kernel.org/r/20240320-b4-qcom-usb-v4-4-41be480172e1@linaro.org [mkorpershoek: squashed the lldiv() fix from caleb] Signed-off-by: Mattijs Korpershoek --- cmd/usb_mass_storage.c | 4 -- drivers/usb/gadget/f_mass_storage.c | 102 ++++++++++++++++++++---------------- drivers/usb/gadget/storage_common.c | 12 +++-- include/usb_mass_storage.h | 1 - 4 files changed, 66 insertions(+), 53 deletions(-) diff --git a/cmd/usb_mass_storage.c b/cmd/usb_mass_storage.c index a8ddeb4946..751701fe73 100644 --- a/cmd/usb_mass_storage.c +++ b/cmd/usb_mass_storage.c @@ -88,10 +88,6 @@ static int ums_init(const char *devtype, const char *devnums_part_str) if (!strchr(devnum_part_str, ':')) partnum = 0; - /* f_mass_storage.c assumes SECTOR_SIZE sectors */ - if (block_dev->blksz != SECTOR_SIZE) - goto cleanup; - ums_new = realloc(ums, (ums_count + 1) * sizeof(*ums)); if (!ums_new) goto cleanup; diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index c725aed3f6..ef90c7ec7f 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -240,6 +240,7 @@ /* #define DUMP_MSGS */ #include +#include #include #include #include @@ -724,12 +725,13 @@ static int do_read(struct fsg_common *common) curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; return -EINVAL; } - file_offset = ((loff_t) lba) << 9; + file_offset = ((loff_t)lba) << curlun->blkbits; /* Carry out the file reads */ amount_left = common->data_size_from_cmnd; - if (unlikely(amount_left == 0)) + if (unlikely(amount_left == 0)) { return -EIO; /* No default reply */ + } for (;;) { @@ -768,13 +770,13 @@ static int do_read(struct fsg_common *common) /* Perform the read */ rc = ums[common->lun].read_sector(&ums[common->lun], - file_offset / SECTOR_SIZE, - amount / SECTOR_SIZE, + lldiv(file_offset, curlun->blksize), + lldiv(amount, curlun->blksize), (char __user *)bh->buf); if (!rc) return -EIO; - nread = rc * SECTOR_SIZE; + nread = rc * curlun->blksize; VLDBG(curlun, "file read %u @ %llu -> %d\n", amount, (unsigned long long) file_offset, @@ -787,7 +789,7 @@ static int do_read(struct fsg_common *common) } else if (nread < amount) { LDBG(curlun, "partial file read: %d/%u\n", (int) nread, amount); - nread -= (nread & 511); /* Round down to a block */ + nread -= (nread & (curlun->blksize - 1)); /* Round down to a block */ } file_offset += nread; amount_left -= nread; @@ -861,7 +863,7 @@ static int do_write(struct fsg_common *common) /* Carry out the file writes */ get_some_more = 1; - file_offset = usb_offset = ((loff_t) lba) << 9; + file_offset = usb_offset = ((loff_t)lba) << curlun->blkbits; amount_left_to_req = common->data_size_from_cmnd; amount_left_to_write = common->data_size_from_cmnd; @@ -893,7 +895,7 @@ static int do_write(struct fsg_common *common) curlun->info_valid = 1; continue; } - amount -= (amount & 511); + amount -= (amount & (curlun->blksize - 1)); if (amount == 0) { /* Why were we were asked to transfer a @@ -942,12 +944,12 @@ static int do_write(struct fsg_common *common) /* Perform the write */ rc = ums[common->lun].write_sector(&ums[common->lun], - file_offset / SECTOR_SIZE, - amount / SECTOR_SIZE, + lldiv(file_offset, curlun->blksize), + lldiv(amount, curlun->blksize), (char __user *)bh->buf); if (!rc) return -EIO; - nwritten = rc * SECTOR_SIZE; + nwritten = rc * curlun->blksize; VLDBG(curlun, "file write %u @ %llu -> %d\n", amount, (unsigned long long) file_offset, @@ -960,7 +962,7 @@ static int do_write(struct fsg_common *common) } else if (nwritten < amount) { LDBG(curlun, "partial file write: %d/%u\n", (int) nwritten, amount); - nwritten -= (nwritten & 511); + nwritten -= (nwritten & (curlun->blksize - 1)); /* Round down to a block */ } file_offset += nwritten; @@ -1034,8 +1036,8 @@ static int do_verify(struct fsg_common *common) return -EIO; /* No default reply */ /* Prepare to carry out the file verify */ - amount_left = verification_length << 9; - file_offset = ((loff_t) lba) << 9; + amount_left = verification_length << curlun->blkbits; + file_offset = ((loff_t) lba) << curlun->blkbits; /* Write out all the dirty buffers before invalidating them */ @@ -1058,12 +1060,12 @@ static int do_verify(struct fsg_common *common) /* Perform the read */ rc = ums[common->lun].read_sector(&ums[common->lun], - file_offset / SECTOR_SIZE, - amount / SECTOR_SIZE, + lldiv(file_offset, curlun->blksize), + lldiv(amount, curlun->blksize), (char __user *)bh->buf); if (!rc) return -EIO; - nread = rc * SECTOR_SIZE; + nread = rc * curlun->blksize; VLDBG(curlun, "file read %u @ %llu -> %d\n", amount, (unsigned long long) file_offset, @@ -1075,7 +1077,7 @@ static int do_verify(struct fsg_common *common) } else if (nread < amount) { LDBG(curlun, "partial file verify: %d/%u\n", (int) nread, amount); - nread -= (nread & 511); /* Round down to a sector */ + nread -= (nread & (curlun->blksize - 1)); /* Round down to a sector */ } if (nread == 0) { curlun->sense_data = SS_UNRECOVERED_READ_ERROR; @@ -1183,7 +1185,7 @@ static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh) put_unaligned_be32(curlun->num_sectors - 1, &buf[0]); /* Max logical block */ - put_unaligned_be32(512, &buf[4]); /* Block length */ + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */ return 8; } @@ -1370,7 +1372,7 @@ static int do_read_format_capacities(struct fsg_common *common, put_unaligned_be32(curlun->num_sectors, &buf[0]); /* Number of blocks */ - put_unaligned_be32(512, &buf[4]); /* Block length */ + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */ buf[4] = 0x02; /* Current capacity */ return 12; } @@ -1781,6 +1783,16 @@ static int check_command(struct fsg_common *common, int cmnd_size, return 0; } +/* wrapper of check_command for data size in blocks handling */ +static int check_command_size_in_blocks(struct fsg_common *common, + int cmnd_size, enum data_direction data_dir, + unsigned int mask, int needs_medium, const char *name) +{ + common->data_size_from_cmnd <<= common->luns[common->lun].blkbits; + return check_command(common, cmnd_size, data_dir, + mask, needs_medium, name); +} + static int do_scsi_command(struct fsg_common *common) { @@ -1865,30 +1877,30 @@ static int do_scsi_command(struct fsg_common *common) case SC_READ_6: i = common->cmnd[4]; - common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; - reply = check_command(common, 6, DATA_DIR_TO_HOST, - (7<<1) | (1<<4), 1, - "READ(6)"); + common->data_size_from_cmnd = (i == 0 ? 256 : i); + reply = check_command_size_in_blocks(common, 6, DATA_DIR_TO_HOST, + (7<<1) | (1<<4), 1, + "READ(6)"); if (reply == 0) reply = do_read(common); break; case SC_READ_10: common->data_size_from_cmnd = - get_unaligned_be16(&common->cmnd[7]) << 9; - reply = check_command(common, 10, DATA_DIR_TO_HOST, - (1<<1) | (0xf<<2) | (3<<7), 1, - "READ(10)"); + get_unaligned_be16(&common->cmnd[7]); + reply = check_command_size_in_blocks(common, 10, DATA_DIR_TO_HOST, + (1<<1) | (0xf<<2) | (3<<7), 1, + "READ(10)"); if (reply == 0) reply = do_read(common); break; case SC_READ_12: common->data_size_from_cmnd = - get_unaligned_be32(&common->cmnd[6]) << 9; - reply = check_command(common, 12, DATA_DIR_TO_HOST, - (1<<1) | (0xf<<2) | (0xf<<6), 1, - "READ(12)"); + get_unaligned_be32(&common->cmnd[6]); + reply = check_command_size_in_blocks(common, 12, DATA_DIR_TO_HOST, + (1<<1) | (0xf<<2) | (0xf<<6), 1, + "READ(12)"); if (reply == 0) reply = do_read(common); break; @@ -1983,30 +1995,30 @@ static int do_scsi_command(struct fsg_common *common) case SC_WRITE_6: i = common->cmnd[4]; - common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9; - reply = check_command(common, 6, DATA_DIR_FROM_HOST, - (7<<1) | (1<<4), 1, - "WRITE(6)"); + common->data_size_from_cmnd = (i == 0 ? 256 : i); + reply = check_command_size_in_blocks(common, 6, DATA_DIR_FROM_HOST, + (7<<1) | (1<<4), 1, + "WRITE(6)"); if (reply == 0) reply = do_write(common); break; case SC_WRITE_10: common->data_size_from_cmnd = - get_unaligned_be16(&common->cmnd[7]) << 9; - reply = check_command(common, 10, DATA_DIR_FROM_HOST, - (1<<1) | (0xf<<2) | (3<<7), 1, - "WRITE(10)"); + get_unaligned_be16(&common->cmnd[7]); + reply = check_command_size_in_blocks(common, 10, DATA_DIR_FROM_HOST, + (1<<1) | (0xf<<2) | (3<<7), 1, + "WRITE(10)"); if (reply == 0) reply = do_write(common); break; case SC_WRITE_12: common->data_size_from_cmnd = - get_unaligned_be32(&common->cmnd[6]) << 9; - reply = check_command(common, 12, DATA_DIR_FROM_HOST, - (1<<1) | (0xf<<2) | (0xf<<6), 1, - "WRITE(12)"); + get_unaligned_be32(&common->cmnd[6]); + reply = check_command_size_in_blocks(common, 12, DATA_DIR_FROM_HOST, + (1<<1) | (0xf<<2) | (0xf<<6), 1, + "WRITE(12)"); if (reply == 0) reply = do_write(common); break; @@ -2497,7 +2509,7 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common, for (i = 0; i < nluns; i++) { common->luns[i].removable = 1; - rc = fsg_lun_open(&common->luns[i], ums[i].num_sectors, ""); + rc = fsg_lun_open(&common->luns[i], ums[i].num_sectors, ums->block_dev.blksz, ""); if (rc) goto error_luns; } diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index 5674e8fe49..97dc6b6f72 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -269,6 +269,7 @@ struct device_attribute { int i; }; #define ETOOSMALL 525 #include +#include #include #include @@ -290,6 +291,8 @@ struct fsg_lun { u32 sense_data; u32 sense_data_info; u32 unit_attention_data; + unsigned int blkbits; + unsigned int blksize; /* logical block size of bound block device */ struct device dev; }; @@ -566,7 +569,7 @@ static struct usb_gadget_strings fsg_stringtab = { */ static int fsg_lun_open(struct fsg_lun *curlun, unsigned int num_sectors, - const char *filename) + unsigned int sector_size, const char *filename) { int ro; @@ -574,9 +577,12 @@ static int fsg_lun_open(struct fsg_lun *curlun, unsigned int num_sectors, ro = curlun->initially_ro; curlun->ro = ro; - curlun->file_length = num_sectors << 9; + curlun->file_length = num_sectors * sector_size; curlun->num_sectors = num_sectors; - debug("open backing file: %s\n", filename); + curlun->blksize = sector_size; + curlun->blkbits = order_base_2(sector_size >> 9) + 9; + debug("blksize: %u\n", sector_size); + debug("open backing file: '%s'\n", filename); return 0; } diff --git a/include/usb_mass_storage.h b/include/usb_mass_storage.h index 83ab93b530..6d83d93cad 100644 --- a/include/usb_mass_storage.h +++ b/include/usb_mass_storage.h @@ -7,7 +7,6 @@ #ifndef __USB_MASS_STORAGE_H__ #define __USB_MASS_STORAGE_H__ -#define SECTOR_SIZE 0x200 #include #include -- cgit v1.2.3 From 42839c0fdf7893200d214200a1bd539fb4fbdf65 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Wed, 20 Mar 2024 14:30:51 +0000 Subject: iommu: qcom-smmu: fix debugging The priv struct was wrong in dump_boot_mappings(). Causing errors when compiling with -DDEBUG. Fix this. Reviewed-by: Mattijs Korpershoek Reviewed-by: Neil Armstrong Signed-off-by: Caleb Connolly Link: https://lore.kernel.org/r/20240320-b4-qcom-usb-v4-5-41be480172e1@linaro.org Signed-off-by: Mattijs Korpershoek --- drivers/iommu/qcom-hyp-smmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/qcom-hyp-smmu.c b/drivers/iommu/qcom-hyp-smmu.c index 8e5cdb5815..f2b39de56f 100644 --- a/drivers/iommu/qcom-hyp-smmu.c +++ b/drivers/iommu/qcom-hyp-smmu.c @@ -319,7 +319,7 @@ static int qcom_smmu_connect(struct udevice *dev) } #ifdef DEBUG -static inline void dump_boot_mappings(struct arm_smmu_priv *priv) +static inline void dump_boot_mappings(struct qcom_smmu_priv *priv) { u32 val; int i; -- cgit v1.2.3 From 4d158980897085a5b0255ab910208d8afc8522dc Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 17 Mar 2024 05:42:52 +0100 Subject: usb: udc: dwc3: Fold board dm_usb_gadget_handle_interrupts() into DWC3 gadget The dm_usb_gadget_handle_interrupts() has no place in board code. Move this into DWC3 driver. The OMAP implementation is special, add new weak dwc3_uboot_interrupt_status() function to decide whether DWC3 interrupt handling should be called, and override it in OMAP DWC3 code, to repair the special OMAP interrupt handling code until OMAP gets switched over to DM UDC proper. Signed-off-by: Marek Vasut Reviewed-by: Caleb Connolly Reviewed-by: Mattijs Korpershoek Tested-by: Mattijs Korpershoek # vim3 Tested-by: Caleb Connolly # qcom sdm845 Link: https://lore.kernel.org/r/20240317044357.547037-1-marek.vasut+renesas@mailbox.org Signed-off-by: Mattijs Korpershoek --- board/purism/librem5/spl.c | 6 ------ board/samsung/common/exynos5-dt.c | 6 ------ board/st/stih410-b2260/board.c | 6 ------ board/ti/am43xx/board.c | 11 ----------- drivers/usb/dwc3/core.c | 25 +++++++++++++++++++++---- drivers/usb/dwc3/dwc3-omap.c | 4 ++-- include/dwc3-omap-uboot.h | 1 - include/dwc3-uboot.h | 1 + 8 files changed, 24 insertions(+), 36 deletions(-) diff --git a/board/purism/librem5/spl.c b/board/purism/librem5/spl.c index 581f092966..9aadc55330 100644 --- a/board/purism/librem5/spl.c +++ b/board/purism/librem5/spl.c @@ -418,12 +418,6 @@ out: return rv; } -int dm_usb_gadget_handle_interrupts(struct udevice *dev) -{ - dwc3_uboot_handle_interrupt(dev); - return 0; -} - static void dwc3_nxp_usb_phy_init(struct dwc3_device *dwc3) { u32 RegData; diff --git a/board/samsung/common/exynos5-dt.c b/board/samsung/common/exynos5-dt.c index 95cf6d2acc..b3e87c9375 100644 --- a/board/samsung/common/exynos5-dt.c +++ b/board/samsung/common/exynos5-dt.c @@ -122,12 +122,6 @@ static struct dwc3_device dwc3_device_data = { .index = 0, }; -int dm_usb_gadget_handle_interrupts(struct udevice *dev) -{ - dwc3_uboot_handle_interrupt(dev); - return 0; -} - int board_usb_init(int index, enum usb_init_type init) { struct exynos_usb3_phy *phy = (struct exynos_usb3_phy *) diff --git a/board/st/stih410-b2260/board.c b/board/st/stih410-b2260/board.c index e21cbc270e..82817571ae 100644 --- a/board/st/stih410-b2260/board.c +++ b/board/st/stih410-b2260/board.c @@ -50,12 +50,6 @@ static struct dwc3_device dwc3_device_data = { .index = 0, }; -int dm_usb_gadget_handle_interrupts(struct udevice *dev) -{ - dwc3_uboot_handle_interrupt(dev); - return 0; -} - int board_usb_init(int index, enum usb_init_type init) { int node; diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c index ea0d0b9208..a4679a2e29 100644 --- a/board/ti/am43xx/board.c +++ b/board/ti/am43xx/board.c @@ -759,17 +759,6 @@ static struct ti_usb_phy_device usb_phy2_device = { .usb2_phy_power = (void *)USB2_PHY2_POWER, .index = 1, }; - -int dm_usb_gadget_handle_interrupts(struct udevice *dev) -{ - u32 status; - - status = dwc3_omap_uboot_interrupt_status(dev); - if (status) - dwc3_uboot_handle_interrupt(dev); - - return 0; -} #endif /* CONFIG_USB_DWC3 */ #if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 4b4fcd8a22..09737be9a9 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -983,6 +983,11 @@ void dwc3_uboot_exit(int index) } } +MODULE_ALIAS("platform:dwc3"); +MODULE_AUTHOR("Felipe Balbi "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); + /** * dwc3_uboot_handle_interrupt - handle dwc3 core interrupt * @dev: device of this controller @@ -1004,10 +1009,22 @@ void dwc3_uboot_handle_interrupt(struct udevice *dev) } } -MODULE_ALIAS("platform:dwc3"); -MODULE_AUTHOR("Felipe Balbi "); -MODULE_LICENSE("GPL v2"); -MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); +#if !CONFIG_IS_ENABLED(DM_USB_GADGET) +__weak int dwc3_uboot_interrupt_status(struct udevice *dev) +{ + return 1; +} + +int dm_usb_gadget_handle_interrupts(struct udevice *dev) +{ + if (!dwc3_uboot_interrupt_status(dev)) + return 0; + + dwc3_uboot_handle_interrupt(dev); + + return 0; +} +#endif #if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB) int dwc3_setup_phy(struct udevice *dev, struct phy_bulk *phys) diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index 4fadb4a3e2..53c4d4826b 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c @@ -428,7 +428,7 @@ void dwc3_omap_uboot_exit(int index) } /** - * dwc3_omap_uboot_interrupt_status - check the status of interrupt + * dwc3_uboot_interrupt_status - check the status of interrupt * @dev: device of this controller * * Checks the status of interrupts and returns true if an interrupt @@ -436,7 +436,7 @@ void dwc3_omap_uboot_exit(int index) * * Generally called from board file. */ -int dwc3_omap_uboot_interrupt_status(struct udevice *dev) +int dwc3_uboot_interrupt_status(struct udevice *dev) { struct dwc3_omap *omap = NULL; diff --git a/include/dwc3-omap-uboot.h b/include/dwc3-omap-uboot.h index ed92bfc5a9..f220705ef7 100644 --- a/include/dwc3-omap-uboot.h +++ b/include/dwc3-omap-uboot.h @@ -27,5 +27,4 @@ struct dwc3_omap_device { int dwc3_omap_uboot_init(struct dwc3_omap_device *dev); void dwc3_omap_uboot_exit(int index); -int dwc3_omap_uboot_interrupt_status(struct udevice *dev); #endif /* __DWC3_OMAP_UBOOT_H_ */ diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h index 35cfbb93b2..5f13f5bcf4 100644 --- a/include/dwc3-uboot.h +++ b/include/dwc3-uboot.h @@ -44,6 +44,7 @@ struct dwc3_device { int dwc3_uboot_init(struct dwc3_device *dev); void dwc3_uboot_exit(int index); +int dwc3_uboot_interrupt_status(struct udevice *dev); void dwc3_uboot_handle_interrupt(struct udevice *dev); struct phy; -- cgit v1.2.3 From 12ac51cdb788b9f8e50cbc4fa3681102882ade33 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 17 Mar 2024 05:42:53 +0100 Subject: usb: udc: dwc3: Fold dwc3_uboot_handle_interrupt into dm_usb_gadget_handle_interrupts The only call site of dwc3_uboot_handle_interrupt() is the dm_usb_gadget_handle_interrupts(), fold the former into the later. This makes dwc3_uboot_handle_interrupt() unavailable to be called from board code as well. Signed-off-by: Marek Vasut Reviewed-by: Mattijs Korpershoek Tested-by: Mattijs Korpershoek # vim3 Link: https://lore.kernel.org/r/20240317044357.547037-2-marek.vasut+renesas@mailbox.org Signed-off-by: Mattijs Korpershoek --- drivers/usb/dwc3/core.c | 27 +++++++++++---------------- include/dwc3-uboot.h | 1 - 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 09737be9a9..96e850b717 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -988,18 +988,27 @@ MODULE_AUTHOR("Felipe Balbi "); MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); +#if !CONFIG_IS_ENABLED(DM_USB_GADGET) +__weak int dwc3_uboot_interrupt_status(struct udevice *dev) +{ + return 1; +} + /** - * dwc3_uboot_handle_interrupt - handle dwc3 core interrupt + * dm_usb_gadget_handle_interrupts - handle dwc3 core interrupt * @dev: device of this controller * * Invokes dwc3 gadget interrupts. * * Generally called from board file. */ -void dwc3_uboot_handle_interrupt(struct udevice *dev) +int dm_usb_gadget_handle_interrupts(struct udevice *dev) { struct dwc3 *dwc = NULL; + if (!dwc3_uboot_interrupt_status(dev)) + return 0; + list_for_each_entry(dwc, &dwc3_list, list) { if (dwc->dev != dev) continue; @@ -1007,20 +1016,6 @@ void dwc3_uboot_handle_interrupt(struct udevice *dev) dwc3_gadget_uboot_handle_interrupt(dwc); break; } -} - -#if !CONFIG_IS_ENABLED(DM_USB_GADGET) -__weak int dwc3_uboot_interrupt_status(struct udevice *dev) -{ - return 1; -} - -int dm_usb_gadget_handle_interrupts(struct udevice *dev) -{ - if (!dwc3_uboot_interrupt_status(dev)) - return 0; - - dwc3_uboot_handle_interrupt(dev); return 0; } diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h index 5f13f5bcf4..3689d60ae7 100644 --- a/include/dwc3-uboot.h +++ b/include/dwc3-uboot.h @@ -45,7 +45,6 @@ struct dwc3_device { int dwc3_uboot_init(struct dwc3_device *dev); void dwc3_uboot_exit(int index); int dwc3_uboot_interrupt_status(struct udevice *dev); -void dwc3_uboot_handle_interrupt(struct udevice *dev); struct phy; #if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB) -- cgit v1.2.3