diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index dc867f368b68..e0ec781e5d0a 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -124,13 +124,17 @@ #define CIO3PLL_DTC_VREG_ADJUST GENMASK(16, 14) #define ACIOPHY_CFG0 0x08 +#define ACIOPHY_CFG0_COMMON_BIG BIT(0) // alyssa #define ACIOPHY_CFG0_COMMON_BIG_OV BIT(1) +#define ACIOPHY_CFG0_COMMON_SMALL BIT(2) // alyssa #define ACIOPHY_CFG0_COMMON_SMALL_OV BIT(3) +#define ACIOPHY_CFG0_COMMON_CLAMP BIT(4) // alyssa #define ACIOPHY_CFG0_COMMON_CLAMP_OV BIT(5) #define ACIOPHY_CFG0_RX_SMALL_OV GENMASK(9, 8) #define ACIOPHY_CFG0_RX_BIG_OV GENMASK(13, 12) #define ACIOPHY_CFG0_RX_CLAMP_OV GENMASK(17, 16) +/* LANE_MODE/CROSSBAR seem to be mirrored at both 048/0x4c and 0x60/0x64 */ #define ACIOPHY_CROSSBAR 0x4c #define ACIOPHY_CROSSBAR_PROTOCOL GENMASK(4, 0) #define ACIOPHY_CROSSBAR_PROTOCOL_USB4 0x0 @@ -217,6 +221,29 @@ enum atcphy_lane_mode { #define ACIOPHY_DP_PCLK_STAT 0x7044 #define ACIOPHY_AUSPLL_LOCK BIT(3) +/* t8122 ACIOPHY BIST registers */ + +#define ACIOPHY_BIST_BASE 0x17000 + +#define ACIOPHY_BIST_BLK_BIST_CFG1 (ACIOPHY_BIST_BASE + 0x0) +#define ACIOPHY_BIST_BLK_BIST_CFG1_BIST_CLOCK_EN BIT(0) +#define ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN BIT(2) + +#define ACIOPHY_BIST_BLK_BIST_CFG2 (ACIOPHY_BIST_BASE + 0x4) +#define ACIOPHY_BIST_BLK_BIST_CFG2_USBPHY_MAC_LN0_PHY_STATUS_RE BIT(2) + +#define ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2 (ACIOPHY_BIST_BASE + 0x80) +#define ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2_USBPHY_MAC_LN0_PHY_STATUS2 BIT(2) +#define ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2_USBPHY_MAC_LN0_PHY_STATUS BIT(6) + +#define ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1 (ACIOPHY_BIST_BASE + 0x88) +#define ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PIPE_RESET_N_OV_VAL BIT(20) +#define ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PWR_DOWN_OV_VAL GENMASK(26, 25) + +#define ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2 (ACIOPHY_BIST_BASE + 0x8c) +#define ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2_MAC_USBPHY_LN0_RESET_N_OV BIT(5) +#define ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2_MAC_USBPHY_LN0_PWR_DOWN_OV BIT(9) + #define LN0_AUSPMA_RX_TOP 0x9000 #define LN0_AUSPMA_RX_EQ 0xA000 #define LN0_AUSPMA_RX_SHM 0xB000 @@ -477,7 +504,7 @@ enum atcphy_lane_mode { #define USB2PHY_SIG_VBUSDET_FORCE_EN BIT(1) #define USB2PHY_SIG_VBUSVLDEXT_FORCE_VAL BIT(2) #define USB2PHY_SIG_VBUSVLDEXT_FORCE_EN BIT(3) -#define USB2PHY_SIG_HOST (7 << 12) +#define USB2PHY_SIG_HOST (7 << 12) /* from lsb->msb: DPPULLDOWN_FORCE_VAL | DMPULLDOWN_FORCE_VAL | DPDMPULLDOWN_FORCE_EN */ #define USB2PHY_MISCTUNE 0x1c #define USB2PHY_MISCTUNE_APBCLK_GATE_OFF BIT(29) @@ -556,6 +583,24 @@ struct atcphy_mode_configuration { bool set_swap; }; +enum atcphy_type { + ATCPHY_T8103, + ATCPHY_T8122 +}; + +/* Per-compatible data */ +struct atcphy_data { + enum atcphy_type type; +}; + +static const struct atcphy_data t8103_data = { + .type = ATCPHY_T8103 +}; + +static const struct atcphy_data t8122_data = { + .type = ATCPHY_T8122 +}; + /** * struct apple_atcphy - Apple Type-C PHY device struct * @np: Device node pointer @@ -566,6 +611,7 @@ struct atcphy_mode_configuration { * @tunables.lane_usb3: USB3 lane-specific tunables * @tunables.lane_dp: DisplayPort lane-specific tunables * @tunables.lane_usb4: USB4 lane-specific tunables + * @data.type: Compatible type * @mode: Current PHY operating mode * @swap_lanes: True if lanes must be swapped due to cable orientation * @dp_link_rate: DisplayPort link rate @@ -601,6 +647,8 @@ struct apple_atcphy { struct apple_tunable *lane_usb4[2]; } tunables; + const struct atcphy_data *data; + enum atcphy_mode mode; bool swap_lanes; int dp_link_rate; @@ -895,12 +943,15 @@ static void atcphy_apply_tunables(struct apple_atcphy *atcphy, enum atcphy_mode case APPLE_ATCPHY_MODE_USB3: case APPLE_ATCPHY_MODE_USB3_DP: apple_tunable_apply(atcphy->regs.core, atcphy->tunables.lane_usb3[lane0]); - apple_tunable_apply(atcphy->regs.core, atcphy->tunables.lane_dp[lane1]); + if (atcphy->data->type == ATCPHY_T8103) + apple_tunable_apply(atcphy->regs.core, atcphy->tunables.lane_dp[lane1]); break; case APPLE_ATCPHY_MODE_DP: - apple_tunable_apply(atcphy->regs.core, atcphy->tunables.lane_dp[lane0]); - apple_tunable_apply(atcphy->regs.core, atcphy->tunables.lane_dp[lane1]); + if (atcphy->data->type == ATCPHY_T8103) { + apple_tunable_apply(atcphy->regs.core, atcphy->tunables.lane_dp[lane0]); + apple_tunable_apply(atcphy->regs.core, atcphy->tunables.lane_dp[lane1]); + } break; /* @@ -927,6 +978,7 @@ static int atcphy_pipehandler_lock(struct apple_atcphy *atcphy) if (readl(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ) & PIPEHANDLER_LOCK_EN) { dev_warn(atcphy->dev, "Pipehandler already locked\n"); + WARN_ON(1); return 0; } @@ -937,6 +989,7 @@ static int atcphy_pipehandler_lock(struct apple_atcphy *atcphy) if (ret) { clear32(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ, 1); dev_warn(atcphy->dev, "Pipehandler lock not acked.\n"); + WARN_ON(1); } return ret; @@ -975,6 +1028,14 @@ static int atcphy_pipehandler_check(struct apple_atcphy *atcphy) return 0; } +#if 0 +// FIXME fill this in +static int atcphy_configure_pipehandler_usb3_t8122_start(struct apple_atcphy *atcphy, bool host) +{ + /* BIST dance for t8122 */ +} +#endif + static int atcphy_configure_pipehandler_usb3(struct apple_atcphy *atcphy, bool host) { int ret; @@ -1004,43 +1065,111 @@ static int atcphy_configure_pipehandler_usb3(struct apple_atcphy *atcphy, bool h } /* BIST dance */ - core_set32(atcphy, ACIOPHY_TOP_BIST_PHY_CFG0, - ACIOPHY_TOP_BIST_PHY_CFG0_LN0_RESET_N); - core_set32(atcphy, ACIOPHY_TOP_BIST_OV_CFG, ACIOPHY_TOP_BIST_OV_CFG_LN0_RESET_N_OV); - ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_TOP_PHY_STAT, reg, - !(reg & ACIOPHY_TOP_PHY_STAT_LN0_UNK23), 10, 10000); - if (ret) - dev_warn(atcphy->dev, - "Timed out waiting for ACIOPHY_TOP_PHY_STAT_LN0_UNK23\n"); - - core_set32(atcphy, ACIOPHY_TOP_BIST_READ_CTRL, - ACIOPHY_TOP_BIST_READ_CTRL_LN0_PHY_STATUS_RE); - core_clear32(atcphy, ACIOPHY_TOP_BIST_READ_CTRL, - ACIOPHY_TOP_BIST_READ_CTRL_LN0_PHY_STATUS_RE); - - core_mask32(atcphy, ACIOPHY_TOP_BIST_PHY_CFG1, - ACIOPHY_TOP_BIST_PHY_CFG1_LN0_PWR_DOWN, - FIELD_PREP(ACIOPHY_TOP_BIST_PHY_CFG1_LN0_PWR_DOWN, 3)); - - core_set32(atcphy, ACIOPHY_TOP_BIST_OV_CFG, - ACIOPHY_TOP_BIST_OV_CFG_LN0_PWR_DOWN_OV); - core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, - ACIOPHY_TOP_BIST_CIOPHY_CFG1_CLK_EN); - core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, - ACIOPHY_TOP_BIST_CIOPHY_CFG1_BIST_EN); - writel(0, atcphy->regs.core + ACIOPHY_TOP_BIST_CIOPHY_CFG1); - - ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_TOP_PHY_STAT, reg, - (reg & ACIOPHY_TOP_PHY_STAT_LN0_UNK0), 10, 10000); - if (ret) - dev_warn(atcphy->dev, - "timed out waiting for ACIOPHY_TOP_PHY_STAT_LN0_UNK0\n"); - - ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_TOP_PHY_STAT, reg, - !(reg & ACIOPHY_TOP_PHY_STAT_LN0_UNK23), 10, 10000); - if (ret) - dev_warn(atcphy->dev, - "timed out waiting for ACIOPHY_TOP_PHY_STAT_LN0_UNK23\n"); + if (atcphy->data->type == ATCPHY_T8122) { + // enable the pipe BIST + core_set32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_CLOCK_EN); + + // enable pipe reset override and set power down override to 2 + core_mask32(atcphy, ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1, + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PIPE_RESET_N_OV_VAL | + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PWR_DOWN_OV_VAL, + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PIPE_RESET_N_OV_VAL | + FIELD_PREP(ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PWR_DOWN_OV_VAL, 2)); + core_set32(atcphy, ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2, + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2_MAC_USBPHY_LN0_RESET_N_OV | + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2_MAC_USBPHY_LN0_PWR_DOWN_OV); + + // BIST USB toggle + core_set32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN); + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_BIST_BLK_BIST_CFG1, reg, + (reg & ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN), 10, 10000); + if (ret) + dev_warn(atcphy->dev, "Timed out waiting for BIST_USB_EN\n"); + core_clear32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN); + + u32 val = readl(atcphy->regs.core + ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2); + printk("USBPHY_MAC_STATUS2 is 0x%x", val); + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2, reg, + (reg & ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2_USBPHY_MAC_LN0_PHY_STATUS2), 10, 10000); + if (ret) + dev_warn(atcphy->dev, "Timed out waiting for LN0_PHY_STATUS2\n"); + + core_set32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG2, + ACIOPHY_BIST_BLK_BIST_CFG2_USBPHY_MAC_LN0_PHY_STATUS_RE); + core_clear32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG2, + ACIOPHY_BIST_BLK_BIST_CFG2_USBPHY_MAC_LN0_PHY_STATUS_RE); + + // set power down override to 3 + core_mask32(atcphy, ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1, + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PWR_DOWN_OV_VAL, + FIELD_PREP(ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV1_MAC_USBPHY_LN0_PWR_DOWN_OV_VAL, 3)); + core_set32(atcphy, ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2, + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2_MAC_USBPHY_LN0_PWR_DOWN_OV); + + // BIST USB toggle + core_set32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN); + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_BIST_BLK_BIST_CFG1, reg, + (reg & ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN), 10, 10000); + if (ret) + dev_warn(atcphy->dev, "Timed out waiting for BIST_USB_EN\n"); + core_clear32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN); + + val = readl(atcphy->regs.core + ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2); + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2, reg, + (reg & ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2_USBPHY_MAC_LN0_PHY_STATUS), 10, 10000); + if (ret) + dev_warn(atcphy->dev, "Timed out waiting for LN0_PHY_STATUS\n"); + val = readl(atcphy->regs.core + ACIOPHY_BIST_BLK_USBPHY_MAC_STATUS2); + printk("USBPHY_MAC_STATUS2 is finally 0x%x", val); + + core_set32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG2, + ACIOPHY_BIST_BLK_BIST_CFG2_USBPHY_MAC_LN0_PHY_STATUS_RE); + core_clear32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG2, + ACIOPHY_BIST_BLK_BIST_CFG2_USBPHY_MAC_LN0_PHY_STATUS_RE); + } else { // ATCPHY_T8103 + core_set32(atcphy, ACIOPHY_TOP_BIST_PHY_CFG0, + ACIOPHY_TOP_BIST_PHY_CFG0_LN0_RESET_N); + core_set32(atcphy, ACIOPHY_TOP_BIST_OV_CFG, ACIOPHY_TOP_BIST_OV_CFG_LN0_RESET_N_OV); + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_TOP_PHY_STAT, reg, + !(reg & ACIOPHY_TOP_PHY_STAT_LN0_UNK23), 10, 10000); + if (ret) + dev_warn(atcphy->dev, + "Timed out waiting for ACIOPHY_TOP_PHY_STAT_LN0_UNK23\n"); + + core_set32(atcphy, ACIOPHY_TOP_BIST_READ_CTRL, + ACIOPHY_TOP_BIST_READ_CTRL_LN0_PHY_STATUS_RE); + core_clear32(atcphy, ACIOPHY_TOP_BIST_READ_CTRL, + ACIOPHY_TOP_BIST_READ_CTRL_LN0_PHY_STATUS_RE); + + core_mask32(atcphy, ACIOPHY_TOP_BIST_PHY_CFG1, + ACIOPHY_TOP_BIST_PHY_CFG1_LN0_PWR_DOWN, + FIELD_PREP(ACIOPHY_TOP_BIST_PHY_CFG1_LN0_PWR_DOWN, 3)); + + core_set32(atcphy, ACIOPHY_TOP_BIST_OV_CFG, + ACIOPHY_TOP_BIST_OV_CFG_LN0_PWR_DOWN_OV); + core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, + ACIOPHY_TOP_BIST_CIOPHY_CFG1_CLK_EN); + core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, + ACIOPHY_TOP_BIST_CIOPHY_CFG1_BIST_EN); + writel(0, atcphy->regs.core + ACIOPHY_TOP_BIST_CIOPHY_CFG1); + + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_TOP_PHY_STAT, reg, + (reg & ACIOPHY_TOP_PHY_STAT_LN0_UNK0), 10, 10000); + if (ret) + dev_warn(atcphy->dev, + "timed out waiting for ACIOPHY_TOP_PHY_STAT_LN0_UNK0\n"); + + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_TOP_PHY_STAT, reg, + !(reg & ACIOPHY_TOP_PHY_STAT_LN0_UNK23), 10, 10000); + if (ret) + dev_warn(atcphy->dev, + "timed out waiting for ACIOPHY_TOP_PHY_STAT_LN0_UNK23\n"); + } /* Clear reset for non-selected USB3 PHY (?) */ mask32(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE, @@ -1048,12 +1177,33 @@ static int atcphy_configure_pipehandler_usb3(struct apple_atcphy *atcphy, bool h clear32(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE, PIPEHANDLER_NATIVE_RESET); - /* More BIST stuff (?) */ - writel(0, atcphy->regs.core + ACIOPHY_TOP_BIST_OV_CFG); - core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, - ACIOPHY_TOP_BIST_CIOPHY_CFG1_CLK_EN); - core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, - ACIOPHY_TOP_BIST_CIOPHY_CFG1_BIST_EN); + if (atcphy->data->type == ATCPHY_T8122) { + // disable the overrides + core_clear32(atcphy, ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2, + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2_MAC_USBPHY_LN0_RESET_N_OV | + ACIOPHY_BIST_BLK_MAC_USBPHY_CFG_OV2_MAC_USBPHY_LN0_PWR_DOWN_OV); + + // BIST USB toggle + core_set32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN); + ret = readl_poll_timeout(atcphy->regs.core + ACIOPHY_BIST_BLK_BIST_CFG1, reg, + (reg & ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN), 10, 10000); + if (ret) + dev_warn(atcphy->dev, "Timed out waiting for BIST_USB_EN\n"); + core_clear32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_USB_EN); + + // disable the pipe BIST, we're done! + core_clear32(atcphy, ACIOPHY_BIST_BLK_BIST_CFG1, + ACIOPHY_BIST_BLK_BIST_CFG1_BIST_CLOCK_EN); + } else { // ATCPHY_T8103 + /* More BIST stuff (?) */ + writel(0, atcphy->regs.core + ACIOPHY_TOP_BIST_OV_CFG); + core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, + ACIOPHY_TOP_BIST_CIOPHY_CFG1_CLK_EN); + core_set32(atcphy, ACIOPHY_TOP_BIST_CIOPHY_CFG1, + ACIOPHY_TOP_BIST_CIOPHY_CFG1_BIST_EN); + } } /* Configure PIPE mux to USB3 PHY */ @@ -1215,6 +1365,9 @@ static void atcphy_configure_lanes(struct apple_atcphy *atcphy, enum atcphy_mode static void atcphy_enable_dp_aux(struct apple_atcphy *atcphy) { + if (atcphy->data->type != ATCPHY_T8103) + return; + core_set32(atcphy, ACIOPHY_LANE_DP_CFG_BLK_TX_DP_CTRL0, DPTXPHY_PMA_LANE_RESET_N); core_set32(atcphy, ACIOPHY_LANE_DP_CFG_BLK_TX_DP_CTRL0, DPTXPHY_PMA_LANE_RESET_N_OV); @@ -1267,13 +1420,15 @@ static void atcphy_enable_dp_aux(struct apple_atcphy *atcphy) static void atcphy_disable_dp_aux(struct apple_atcphy *atcphy) { - set32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_AUX_PWN_DOWN); - set32(atcphy->regs.lpdptx + LPDPTX_AUX_CFG_BLK_AUX_CTRL, LPDPTX_BLK_AUX_CTRL_PWRDN); - set32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_AUX_CLAMP_EN); - clear32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_SLEEP_B_SML_IN); - udelay(10); - clear32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_SLEEP_B_BIG_IN); - udelay(10); + if (atcphy->data->type == ATCPHY_T8103) { + set32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_AUX_PWN_DOWN); + set32(atcphy->regs.lpdptx + LPDPTX_AUX_CFG_BLK_AUX_CTRL, LPDPTX_BLK_AUX_CTRL_PWRDN); + set32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_AUX_CLAMP_EN); + clear32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_SLEEP_B_SML_IN); + udelay(10); + clear32(atcphy->regs.lpdptx + LPDPTX_AUX_CONTROL, LPDPTX_SLEEP_B_BIG_IN); + udelay(10); + } core_clear32(atcphy, ACIOPHY_LANE_DP_CFG_BLK_TX_DP_CTRL0, DPTXPHY_PMA_LANE_RESET_N); core_clear32(atcphy, ACIOPHY_LANE_DP_CFG_BLK_TX_DP_CTRL0, DPRX_PCLK_ENABLE); @@ -1644,24 +1799,27 @@ static int atcphy_power_off(struct apple_atcphy *atcphy) /* Enable all reset lines */ core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_PHY_RESET_N); - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_CLAMP_EN); + if (atcphy->data->type == ATCPHY_T8103) + core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_CLAMP_EN); core_clear32(atcphy, ATCPHY_MISC, ATCPHY_MISC_RESET_N | ATCPHY_MISC_LANE_SWAP); core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_APB_RESET_N); - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_BIG); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, - !(reg & ATCPHY_POWER_SLEEP_BIG), 10, 1000); - if (ret) { - dev_err(atcphy->dev, "Failed to sleep atcphy \"big\"\n"); - return ret; - } + if (atcphy->data->type == ATCPHY_T8103) { + core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_BIG); + ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + !(reg & ATCPHY_POWER_SLEEP_BIG), 10, 1000); + if (ret) { + dev_err(atcphy->dev, "Failed to sleep atcphy \"big\"\n"); + return ret; + } - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_SMALL); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, - !(reg & ATCPHY_POWER_SLEEP_SMALL), 10, 1000); - if (ret) { - dev_err(atcphy->dev, "Failed to sleep atcphy \"small\"\n"); - return ret; + core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_SMALL); + ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + !(reg & ATCPHY_POWER_SLEEP_SMALL), 10, 1000); + if (ret) { + dev_err(atcphy->dev, "Failed to sleep atcphy \"small\"\n"); + return ret; + } } return 0; @@ -1683,13 +1841,26 @@ static void atcphy_usb2_power_on(struct apple_atcphy *atcphy) udelay(10); clear32(atcphy->regs.usb2phy + USB2PHY_CTL, USB2PHY_CTL_PORT_RESET); udelay(10); + + if (atcphy->data->type == ATCPHY_T8122) { +#define AUSBC_CORE_EVT_BLK_C0_USB2_CTL 0x0 +#define AUSBC_CORE_EVT_BLK_C0_USB2_CTL_LOAD_CNT BIT(0) /* perhaps bits 0-2 */ +#define AUSBC_CORE_EVT_BLK_C0_USB2_CTL_EVT_EN BIT(3) + // FIXME t8122: added step + set32(atcphy->regs.core + AUSBC_CORE_EVT_BLK_C0_USB2_CTL, AUSBC_CORE_EVT_BLK_C0_USB2_CTL_LOAD_CNT | AUSBC_CORE_EVT_BLK_C0_USB2_CTL_EVT_EN); + } set32(atcphy->regs.usb2phy + USB2PHY_CTL, USB2PHY_CTL_APB_RESET_N); udelay(10); clear32(atcphy->regs.usb2phy + USB2PHY_MISCTUNE, USB2PHY_MISCTUNE_APBCLK_GATE_OFF); clear32(atcphy->regs.usb2phy + USB2PHY_MISCTUNE, USB2PHY_MISCTUNE_REFCLK_GATE_OFF); /* Enable the PHY */ +#if 1 + // FIXME t8122: added step (probably not needed since _probably_ it is implicitly cleared?) + mask32(atcphy->regs.usb2phy + USB2PHY_USBCTL, USB2PHY_USBCTL_RUN | USB2PHY_USBCTL_ISOLATION, USB2PHY_USBCTL_RUN); +#else writel(USB2PHY_USBCTL_RUN, atcphy->regs.usb2phy + USB2PHY_USBCTL); +#endif } static int atcphy_power_on(struct apple_atcphy *atcphy) @@ -1741,43 +1912,59 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) atcphy_apply_tunables(atcphy, mode); - core_set32(atcphy, AUSPLL_FSM_CTRL, 0x1fe000); - core_set32(atcphy, AUSPLL_APB_CMD_OVERRIDE, AUSPLL_APB_CMD_OVERRIDE_UNK28); - - set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_SMALL_OV); - udelay(10); - set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_BIG_OV); - udelay(10); - set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_CLAMP_OV); - udelay(10); + if (atcphy->data->type == ATCPHY_T8122) { + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_SMALL); + udelay(10); + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_SMALL_OV); + udelay(10); + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_BIG); + udelay(10); + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_BIG_OV); + udelay(10); + clear32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_CLAMP); + udelay(10); + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_CLAMP_OV); + udelay(10); + } else { // ATCPHY_T8103 + core_set32(atcphy, AUSPLL_FSM_CTRL, 0x1fe000); + core_set32(atcphy, AUSPLL_APB_CMD_OVERRIDE, AUSPLL_APB_CMD_OVERRIDE_UNK28); - mask32(atcphy->regs.core + ACIOPHY_SLEEP_CTRL, ACIOPHY_SLEEP_CTRL_TX_SMALL_OV, - FIELD_PREP(ACIOPHY_SLEEP_CTRL_TX_SMALL_OV, 3)); - udelay(10); - mask32(atcphy->regs.core + ACIOPHY_SLEEP_CTRL, ACIOPHY_SLEEP_CTRL_TX_BIG_OV, - FIELD_PREP(ACIOPHY_SLEEP_CTRL_TX_BIG_OV, 3)); - udelay(10); - mask32(atcphy->regs.core + ACIOPHY_SLEEP_CTRL, ACIOPHY_SLEEP_CTRL_TX_CLAMP_OV, - FIELD_PREP(ACIOPHY_SLEEP_CTRL_TX_CLAMP_OV, 3)); - udelay(10); + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_SMALL_OV); + udelay(10); + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_BIG_OV); + udelay(10); + set32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_COMMON_CLAMP_OV); + udelay(10); - mask32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_RX_BIG_OV, - FIELD_PREP(ACIOPHY_CFG0_RX_BIG_OV, 3)); - udelay(10); - mask32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_RX_SMALL_OV, - FIELD_PREP(ACIOPHY_CFG0_RX_SMALL_OV, 3)); - udelay(10); - mask32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_RX_CLAMP_OV, - FIELD_PREP(ACIOPHY_CFG0_RX_CLAMP_OV, 3)); - udelay(10); + mask32(atcphy->regs.core + ACIOPHY_SLEEP_CTRL, ACIOPHY_SLEEP_CTRL_TX_SMALL_OV, + FIELD_PREP(ACIOPHY_SLEEP_CTRL_TX_SMALL_OV, 3)); + udelay(10); + mask32(atcphy->regs.core + ACIOPHY_SLEEP_CTRL, ACIOPHY_SLEEP_CTRL_TX_BIG_OV, + FIELD_PREP(ACIOPHY_SLEEP_CTRL_TX_BIG_OV, 3)); + udelay(10); + mask32(atcphy->regs.core + ACIOPHY_SLEEP_CTRL, ACIOPHY_SLEEP_CTRL_TX_CLAMP_OV, + FIELD_PREP(ACIOPHY_SLEEP_CTRL_TX_CLAMP_OV, 3)); + udelay(10); + mask32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_RX_BIG_OV, + FIELD_PREP(ACIOPHY_CFG0_RX_BIG_OV, 3)); + udelay(10); + mask32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_RX_SMALL_OV, + FIELD_PREP(ACIOPHY_CFG0_RX_SMALL_OV, 3)); + udelay(10); + mask32(atcphy->regs.core + ACIOPHY_CFG0, ACIOPHY_CFG0_RX_CLAMP_OV, + FIELD_PREP(ACIOPHY_CFG0_RX_CLAMP_OV, 3)); + udelay(10); + } /* Setup AUX channel if DP altmode is requested */ if (atcphy_modes[mode].enable_dp_aux) atcphy_enable_dp_aux(atcphy); /* Enable clocks and configure lanes */ - core_set32(atcphy, CIO3PLL_CLK_CTRL, CIO3PLL_CLK_PCLK_EN); - core_set32(atcphy, CIO3PLL_CLK_CTRL, CIO3PLL_CLK_REFCLK_EN); + if (atcphy->data->type == ATCPHY_T8103) { + core_set32(atcphy, CIO3PLL_CLK_CTRL, CIO3PLL_CLK_PCLK_EN); + core_set32(atcphy, CIO3PLL_CLK_CTRL, CIO3PLL_CLK_REFCLK_EN); + } atcphy_configure_lanes(atcphy, mode); /* Take the USB3 PHY out of reset */ @@ -2163,19 +2350,22 @@ static int atcphy_load_tunables(struct apple_atcphy *atcphy) const char *dt_name; struct apple_tunable **tunable; struct resource *res; + int t8103_only; } tunables[] = { - { "apple,tunable-axi2af", &atcphy->tunables.axi2af, atcphy->res.axi2af }, - { "apple,tunable-common-a", &atcphy->tunables.common[0], atcphy->res.core }, - { "apple,tunable-common-b", &atcphy->tunables.common[1], atcphy->res.core }, - { "apple,tunable-lane0-usb", &atcphy->tunables.lane_usb3[0], atcphy->res.core }, - { "apple,tunable-lane1-usb", &atcphy->tunables.lane_usb3[1], atcphy->res.core }, - { "apple,tunable-lane0-cio", &atcphy->tunables.lane_usb4[0], atcphy->res.core }, - { "apple,tunable-lane1-cio", &atcphy->tunables.lane_usb4[1], atcphy->res.core }, - { "apple,tunable-lane0-dp", &atcphy->tunables.lane_dp[0], atcphy->res.core }, - { "apple,tunable-lane1-dp", &atcphy->tunables.lane_dp[1], atcphy->res.core }, + { "apple,tunable-axi2af", &atcphy->tunables.axi2af, atcphy->res.axi2af, 0 }, + { "apple,tunable-common-a", &atcphy->tunables.common[0], atcphy->res.core, 0 }, + { "apple,tunable-common-b", &atcphy->tunables.common[1], atcphy->res.core, 0 }, + { "apple,tunable-lane0-usb", &atcphy->tunables.lane_usb3[0], atcphy->res.core, 0 }, + { "apple,tunable-lane1-usb", &atcphy->tunables.lane_usb3[1], atcphy->res.core, 0 }, + { "apple,tunable-lane0-cio", &atcphy->tunables.lane_usb4[0], atcphy->res.core, 0 }, + { "apple,tunable-lane1-cio", &atcphy->tunables.lane_usb4[1], atcphy->res.core, 0 }, + { "apple,tunable-lane0-dp", &atcphy->tunables.lane_dp[0], atcphy->res.core, 1 }, + { "apple,tunable-lane1-dp", &atcphy->tunables.lane_dp[1], atcphy->res.core, 1 }, }; for (int i = 0; i < ARRAY_SIZE(tunables); i++) { + if (tunables[i].t8103_only && atcphy->data->type != ATCPHY_T8103) + continue; *tunables[i].tunable = devm_apple_tunable_parse( atcphy->dev, atcphy->np, tunables[i].dt_name, tunables[i].res); if (IS_ERR(*tunables[i].tunable)) { @@ -2247,12 +2437,21 @@ static int atcphy_probe_finalize(struct apple_atcphy *atcphy) return 0; } +static const struct of_device_id atcphy_match[] = { + { .compatible = "apple,t8103-atcphy", &t8103_data }, + { .compatible = "apple,t8122-atcphy", &t8122_data }, + {}, +}; +MODULE_DEVICE_TABLE(of, atcphy_match); + static int atcphy_probe(struct platform_device *pdev) { struct apple_atcphy *atcphy; struct device *dev = &pdev->dev; + const struct of_device_id *match; int ret; + printk("atcphy_probe: go\n"); atcphy = devm_kzalloc(&pdev->dev, sizeof(*atcphy), GFP_KERNEL); if (!atcphy) return -ENOMEM; @@ -2262,9 +2461,16 @@ static int atcphy_probe(struct platform_device *pdev) mutex_init(&atcphy->lock); platform_set_drvdata(pdev, atcphy); + match = of_match_device(atcphy_match, dev); + if (!match) + return -EINVAL; + atcphy->data = match->data; + + printk("atcphy_probe: try map\n"); ret = atcphy_map_resources(pdev, atcphy); if (ret) return ret; + printk("atcphy_probe: try tunables\n"); ret = atcphy_load_tunables(atcphy); if (ret) return ret; @@ -2272,15 +2478,10 @@ static int atcphy_probe(struct platform_device *pdev) atcphy->mode = APPLE_ATCPHY_MODE_OFF; atcphy->pipehandler_up = false; + printk("atcphy_probe: finalize\n"); return atcphy_probe_finalize(atcphy); } -static const struct of_device_id atcphy_match[] = { - { .compatible = "apple,t8103-atcphy" }, - {}, -}; -MODULE_DEVICE_TABLE(of, atcphy_match); - static struct platform_driver atcphy_driver = { .driver = { .name = "phy-apple-atc",