*/
#include <common.h>
+#include <clk.h>
#include <dm.h>
#include <dm/device.h>
#include <generic-phy.h>
#include <phy-sun4i-usb.h>
+#include <reset.h>
#include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/clock.h>
enum sun4i_usb_phy_type type;
u32 disc_thresh;
u8 phyctl_offset;
+ bool dedicated_clocks;
bool enable_pmu_unk1;
bool phy0_dual_route;
};
const char *gpio_vbus;
const char *gpio_vbus_det;
const char *gpio_id_det;
- int rst_mask;
} phy_info[] = {
{
.gpio_vbus = CONFIG_USB0_VBUS_PIN,
.gpio_vbus_det = CONFIG_USB0_VBUS_DET,
.gpio_id_det = CONFIG_USB0_ID_DET,
- .rst_mask = (CCM_USB_CTRL_PHY0_RST | CCM_USB_CTRL_PHY0_CLK),
},
{
.gpio_vbus = CONFIG_USB1_VBUS_PIN,
.gpio_vbus_det = NULL,
.gpio_id_det = NULL,
- .rst_mask = (CCM_USB_CTRL_PHY1_RST | CCM_USB_CTRL_PHY1_CLK),
},
{
.gpio_vbus = CONFIG_USB2_VBUS_PIN,
.gpio_vbus_det = NULL,
.gpio_id_det = NULL,
-#ifdef CONFIG_MACH_SUN8I_A83T
- .rst_mask = (CCM_USB_CTRL_HSIC_RST | CCM_USB_CTRL_HSIC_CLK |
- CCM_USB_CTRL_12M_CLK),
-#else
- .rst_mask = (CCM_USB_CTRL_PHY2_RST | CCM_USB_CTRL_PHY2_CLK),
-#endif
},
{
.gpio_vbus = CONFIG_USB3_VBUS_PIN,
int gpio_vbus;
int gpio_vbus_det;
int gpio_id_det;
- int rst_mask;
+ struct clk clocks;
+ struct reset_ctl resets;
int id;
};
struct sun4i_usb_phy_data {
void __iomem *base;
- struct sunxi_ccm_reg *ccm;
const struct sun4i_usb_phy_cfg *cfg;
struct sun4i_usb_phy_plat *usb_phy;
};
struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
u32 val;
+ int ret;
- setbits_le32(&data->ccm->usb_clk_cfg, usb_phy->rst_mask);
+ ret = clk_enable(&usb_phy->clocks);
+ if (ret) {
+ dev_err(dev, "failed to enable usb_%ldphy clock\n", phy->id);
+ return ret;
+ }
+
+ ret = reset_deassert(&usb_phy->resets);
+ if (ret) {
+ dev_err(dev, "failed to deassert usb_%ldreset reset\n", phy->id);
+ return ret;
+ }
if (data->cfg->type == sun8i_a83t_phy) {
if (phy->id == 0) {
{
struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev);
struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id];
+ int ret;
if (phy->id == 0) {
if (data->cfg->type == sun8i_a83t_phy) {
sun4i_usb_phy_passby(phy, false);
- clrbits_le32(&data->ccm->usb_clk_cfg, usb_phy->rst_mask);
+ ret = clk_disable(&usb_phy->clocks);
+ if (ret) {
+ dev_err(dev, "failed to disable usb_%ldphy clock\n", phy->id);
+ return ret;
+ }
+
+ ret = reset_assert(&usb_phy->resets);
+ if (ret) {
+ dev_err(dev, "failed to assert usb_%ldreset reset\n", phy->id);
+ return ret;
+ }
return 0;
}
if (IS_ERR(data->base))
return PTR_ERR(data->base);
- data->ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
- if (IS_ERR(data->ccm))
- return PTR_ERR(data->ccm);
-
data->usb_phy = plat;
for (i = 0; i < data->cfg->num_phys; i++) {
struct sun4i_usb_phy_plat *phy = &plat[i];
sunxi_gpio_set_pull(phy->gpio_id_det, SUNXI_GPIO_PULL_UP);
}
+ if (data->cfg->dedicated_clocks)
+ snprintf(name, sizeof(name), "usb%d_phy", i);
+ else
+ strlcpy(name, "usb_phy", sizeof(name));
+
+ ret = clk_get_by_name(dev, name, &phy->clocks);
+ if (ret) {
+ dev_err(dev, "failed to get usb%d_phy clock phandle\n", i);
+ return ret;
+ }
+
+ snprintf(name, sizeof(name), "usb%d_reset", i);
+ ret = reset_get_by_name(dev, name, &phy->resets);
+ if (ret) {
+ dev_err(dev, "failed to get usb%d_reset reset phandle\n", i);
+ return ret;
+ }
+
if (i || data->cfg->phy0_dual_route) {
snprintf(name, sizeof(name), "pmu%d", i);
phy->pmu = (void __iomem *)devfdt_get_addr_name(dev, name);
}
phy->id = i;
- phy->rst_mask = info->rst_mask;
- if ((data->cfg->type == sun8i_h3_phy) && (phy->id == 3))
- phy->rst_mask = (BIT(3) | BIT(11));
};
debug("Allwinner Sun4I USB PHY driver loaded\n");
.type = sun4i_a10_phy,
.disc_thresh = 3,
.phyctl_offset = REG_PHYCTL_A10,
+ .dedicated_clocks = false,
.enable_pmu_unk1 = false,
};
.type = sun4i_a10_phy,
.disc_thresh = 2,
.phyctl_offset = REG_PHYCTL_A10,
+ .dedicated_clocks = false,
.enable_pmu_unk1 = false,
};
.type = sun6i_a31_phy,
.disc_thresh = 3,
.phyctl_offset = REG_PHYCTL_A10,
+ .dedicated_clocks = true,
.enable_pmu_unk1 = false,
};
.type = sun4i_a10_phy,
.disc_thresh = 2,
.phyctl_offset = REG_PHYCTL_A10,
+ .dedicated_clocks = false,
.enable_pmu_unk1 = false,
};
.type = sun4i_a10_phy,
.disc_thresh = 3,
.phyctl_offset = REG_PHYCTL_A10,
+ .dedicated_clocks = true,
.enable_pmu_unk1 = false,
};
.type = sun8i_a33_phy,
.disc_thresh = 3,
.phyctl_offset = REG_PHYCTL_A33,
+ .dedicated_clocks = true,
.enable_pmu_unk1 = false,
};
.num_phys = 3,
.type = sun8i_a83t_phy,
.phyctl_offset = REG_PHYCTL_A33,
+ .dedicated_clocks = true,
};
static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
.type = sun8i_h3_phy,
.disc_thresh = 3,
.phyctl_offset = REG_PHYCTL_A33,
+ .dedicated_clocks = true,
.enable_pmu_unk1 = true,
.phy0_dual_route = true,
};
.type = sun8i_v3s_phy,
.disc_thresh = 3,
.phyctl_offset = REG_PHYCTL_A33,
+ .dedicated_clocks = true,
.enable_pmu_unk1 = true,
.phy0_dual_route = true,
};
.type = sun50i_a64_phy,
.disc_thresh = 3,
.phyctl_offset = REG_PHYCTL_A33,
+ .dedicated_clocks = true,
.enable_pmu_unk1 = true,
.phy0_dual_route = true,
};