Skip to content

Commit 241e2ce

Browse files
pawellcdnsgregkh
authored andcommitted
usb: cdnsp: Fix issue with resuming from L1
In very rare cases after resuming controller from L1 to L0 it reads registers before the clock UTMI have been enabled and as the result driver reads incorrect value. Most of registers are in APB domain clock but some of them (e.g. PORTSC) are in UTMI domain clock. After entering to L1 state the UTMI clock can be disabled. When controller transition from L1 to L0 the port status change event is reported and in interrupt runtime function driver reads PORTSC. During this read operation controller synchronize UTMI and APB domain but UTMI clock is still disabled and in result it reads 0xFFFFFFFF value. To fix this issue driver increases APB timeout value. The issue is platform specific and if the default value of APB timeout is not sufficient then this time should be set Individually for each platform. Fixes: 3d82904 ("usb: cdnsp: cdns3 Add main part of Cadence USBSSP DRD Driver") Cc: stable <stable@kernel.org> Signed-off-by: Pawel Laszczak <pawell@cadence.com> Acked-by: Peter Chen <peter.chen@kernel.org> Link: https://lore.kernel.org/r/PH7PR07MB953846C57973E4DB134CAA71DDBF2@PH7PR07MB9538.namprd07.prod.outlook.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 59820fd commit 241e2ce

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

drivers/usb/cdns3/cdnsp-gadget.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ static void cdnsp_clear_port_change_bit(struct cdnsp_device *pdev,
139139
(portsc & PORT_CHANGE_BITS), port_regs);
140140
}
141141

142+
static void cdnsp_set_apb_timeout_value(struct cdnsp_device *pdev)
143+
{
144+
struct cdns *cdns = dev_get_drvdata(pdev->dev);
145+
__le32 __iomem *reg;
146+
void __iomem *base;
147+
u32 offset = 0;
148+
u32 val;
149+
150+
if (!cdns->override_apb_timeout)
151+
return;
152+
153+
base = &pdev->cap_regs->hc_capbase;
154+
offset = cdnsp_find_next_ext_cap(base, offset, D_XEC_PRE_REGS_CAP);
155+
reg = base + offset + REG_CHICKEN_BITS_3_OFFSET;
156+
157+
val = le32_to_cpu(readl(reg));
158+
val = CHICKEN_APB_TIMEOUT_SET(val, cdns->override_apb_timeout);
159+
writel(cpu_to_le32(val), reg);
160+
}
161+
142162
static void cdnsp_set_chicken_bits_2(struct cdnsp_device *pdev, u32 bit)
143163
{
144164
__le32 __iomem *reg;
@@ -1798,6 +1818,15 @@ static int cdnsp_gen_setup(struct cdnsp_device *pdev)
17981818
pdev->hci_version = HC_VERSION(pdev->hcc_params);
17991819
pdev->hcc_params = readl(&pdev->cap_regs->hcc_params);
18001820

1821+
/*
1822+
* Override the APB timeout value to give the controller more time for
1823+
* enabling UTMI clock and synchronizing APB and UTMI clock domains.
1824+
* This fix is platform specific and is required to fixes issue with
1825+
* reading incorrect value from PORTSC register after resuming
1826+
* from L1 state.
1827+
*/
1828+
cdnsp_set_apb_timeout_value(pdev);
1829+
18011830
cdnsp_get_rev_cap(pdev);
18021831

18031832
/* Make sure the Device Controller is halted. */

drivers/usb/cdns3/cdnsp-gadget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ struct cdnsp_rev_cap {
520520
#define REG_CHICKEN_BITS_2_OFFSET 0x48
521521
#define CHICKEN_XDMA_2_TP_CACHE_DIS BIT(28)
522522

523+
#define REG_CHICKEN_BITS_3_OFFSET 0x4C
524+
#define CHICKEN_APB_TIMEOUT_SET(p, val) (((p) & ~GENMASK(21, 0)) | (val))
525+
523526
/* XBUF Extended Capability ID. */
524527
#define XBUF_CAP_ID 0xCB
525528
#define XBUF_RX_TAG_MASK_0_OFFSET 0x1C

drivers/usb/cdns3/cdnsp-pci.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#define PCI_DRIVER_NAME "cdns-pci-usbssp"
2929
#define PLAT_DRIVER_NAME "cdns-usbssp"
3030

31+
#define CHICKEN_APB_TIMEOUT_VALUE 0x1C20
32+
3133
static struct pci_dev *cdnsp_get_second_fun(struct pci_dev *pdev)
3234
{
3335
/*
@@ -139,6 +141,14 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
139141
cdnsp->otg_irq = pdev->irq;
140142
}
141143

144+
/*
145+
* Cadence PCI based platform require some longer timeout for APB
146+
* to fixes domain clock synchronization issue after resuming
147+
* controller from L1 state.
148+
*/
149+
cdnsp->override_apb_timeout = CHICKEN_APB_TIMEOUT_VALUE;
150+
pci_set_drvdata(pdev, cdnsp);
151+
142152
if (pci_is_enabled(func)) {
143153
cdnsp->dev = dev;
144154
cdnsp->gadget_init = cdnsp_gadget_init;
@@ -148,8 +158,6 @@ static int cdnsp_pci_probe(struct pci_dev *pdev,
148158
goto free_cdnsp;
149159
}
150160

151-
pci_set_drvdata(pdev, cdnsp);
152-
153161
device_wakeup_enable(&pdev->dev);
154162
if (pci_dev_run_wake(pdev))
155163
pm_runtime_put_noidle(&pdev->dev);

drivers/usb/cdns3/core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct cdns3_platform_data {
7979
* @pdata: platform data from glue layer
8080
* @lock: spinlock structure
8181
* @xhci_plat_data: xhci private data structure pointer
82+
* @override_apb_timeout: hold value of APB timeout. For value 0 the default
83+
* value in CHICKEN_BITS_3 will be preserved.
8284
* @gadget_init: pointer to gadget initialization function
8385
*/
8486
struct cdns {
@@ -117,6 +119,7 @@ struct cdns {
117119
struct cdns3_platform_data *pdata;
118120
spinlock_t lock;
119121
struct xhci_plat_priv *xhci_plat_data;
122+
u32 override_apb_timeout;
120123

121124
int (*gadget_init)(struct cdns *cdns);
122125
};

0 commit comments

Comments
 (0)