static int usbhs_rza1_hardware_init(struct platform_device *pdev) { struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); struct device_node *usb_x1_clk, *extal_clk; u32 freq_usb = 0, freq_extal = 0; /* Input Clock Selection (NOTE: ch0 controls both ch0 and ch1) */ usb_x1_clk = of_find_node_by_name(NULL, "usb_x1"); extal_clk = of_find_node_by_name(NULL, "extal"); of_property_read_u32(usb_x1_clk, "clock-frequency", &freq_usb); of_property_read_u32(extal_clk, "clock-frequency", &freq_extal); if (freq_usb == 0) { if (freq_extal == 12000000) { /* Select 12MHz XTAL */ usbhs_bset(priv, SYSCFG, UCKSEL, UCKSEL); } else { dev_err(usbhs_priv_to_dev(priv), "A 48MHz USB clock or 12MHz main clock is required.\n"); return -EIO; } } /* Enable USB PLL (NOTE: ch0 controls both ch0 and ch1) */ usbhs_bset(priv, SYSCFG, UPLLE, UPLLE); udelay(1000); usbhs_bset(priv, SUSPMODE, SUSPM, SUSPM); return 0; }
/* * DCPCTR/PIPEnCTR functions */ static void usbhsp_pipectrl_set(struct usbhs_pipe *pipe, u16 mask, u16 val) { struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); int offset = usbhsp_addr_offset(pipe); if (usbhs_pipe_is_dcp(pipe)) usbhs_bset(priv, DCPCTR, mask, val); else usbhs_bset(priv, PIPEnCTR + offset, mask, val); }
/* * DCP/PIPE functions */ static void __usbhsp_pipe_xxx_set(struct usbhs_pipe *pipe, u16 dcp_reg, u16 pipe_reg, u16 mask, u16 val) { struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); if (usbhs_pipe_is_dcp(pipe)) usbhs_bset(priv, dcp_reg, mask, val); else usbhs_bset(priv, pipe_reg, mask, val); }
static int usbhs_rcar3_power_ctrl(struct platform_device *pdev, void __iomem *base, int enable) { struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); usbhs_write32(priv, UGCTRL2, UGCTRL2_RESERVED_3 | UGCTRL2_USB0SEL_OTG); if (enable) usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM); else usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0); return 0; }
/* * FIFO ctrl */ static void usbhsf_send_terminator(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo) { struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); usbhs_bset(priv, fifo->ctr, BVAL, BVAL); }
/* * local functions */ static void usbhsc_set_buswait(struct usbhs_priv *priv) { int wait = usbhs_get_dparam(priv, buswait_bwait); /* set bus wait if platform have */ if (wait) usbhs_bset(priv, BUSWAIT, 0x000F, wait); }
void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable) { u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; u16 val = DCFM | DRPD | HSE | USBE; int has_otg = usbhs_get_dparam(priv, has_otg); if (has_otg) usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN)); /* * if enable * * - select Host mode * - D+ Line/D- Line Pull-down */ usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); }
void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req) { usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType); usbhs_write(priv, USBVAL, req->wValue); usbhs_write(priv, USBINDX, req->wIndex); usbhs_write(priv, USBLENG, req->wLength); usbhs_bset(priv, DCPCTR, SUREQ, SUREQ); }
/* * bus/vbus functions */ void usbhs_bus_send_sof_enable(struct usbhs_priv *priv) { u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT); if (status != USBRST) { struct device *dev = usbhs_priv_to_dev(priv); dev_err(dev, "usbhs should be reset\n"); } usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT); }
/* * local functions */ static void usbhsc_bus_ctrl(struct usbhs_priv *priv, int enable) { int wait = usbhs_get_dparam(priv, buswait_bwait); u16 data = 0; if (enable) { /* set bus wait if platform have */ if (wait) usbhs_bset(priv, BUSWAIT, 0x000F, wait); } usbhs_write(priv, DVSTCTR, data); }
void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable) { u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; u16 val = DPRPU | HSE | USBE; /* * if enable * * - select Function mode * - D+ Line Pull-up */ usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); }
void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable) { u16 mask = DCFM | DRPD | DPRPU; u16 val = DCFM | DRPD; /* * if enable * * - select Host mode * - D+ Line/D- Line Pull-down */ usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); }
void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable) { u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; u16 val = HSE | USBE; /* * if enable * * - select Function mode * - D+ Line Pull-up is disabled * When D+ Line Pull-up is enabled, * calling usbhs_sys_function_pullup(,1) */ usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); }
void usbhs_bus_send_reset(struct usbhs_priv *priv) { usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST); }
void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable) { usbhs_bset(priv, SYSCFG, DPRPU, enable ? DPRPU : 0); }
/* * syscfg functions */ static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable) { usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0); }
void usbhs_sys_hispeed_ctrl(struct usbhs_priv *priv, int enable) { usbhs_bset(priv, SYSCFG, HSE, enable ? HSE : 0); }
void usbhs_sys_usb_ctrl(struct usbhs_priv *priv, int enable) { usbhs_bset(priv, SYSCFG, USBE, enable ? USBE : 0); }