1f1407d5cSKuninori Morimoto /* 2f1407d5cSKuninori Morimoto * Renesas USB driver 3f1407d5cSKuninori Morimoto * 4f1407d5cSKuninori Morimoto * Copyright (C) 2011 Renesas Solutions Corp. 5f1407d5cSKuninori Morimoto * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 6f1407d5cSKuninori Morimoto * 7f1407d5cSKuninori Morimoto * This program is distributed in the hope that it will be useful, 8f1407d5cSKuninori Morimoto * but WITHOUT ANY WARRANTY; without even the implied warranty of 9f1407d5cSKuninori Morimoto * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10f1407d5cSKuninori Morimoto * GNU General Public License for more details. 11f1407d5cSKuninori Morimoto * 12f1407d5cSKuninori Morimoto * You should have received a copy of the GNU General Public License 13f1407d5cSKuninori Morimoto * along with this program; if not, write to the Free Software 14f1407d5cSKuninori Morimoto * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15f1407d5cSKuninori Morimoto * 16f1407d5cSKuninori Morimoto */ 17148e1134SThierry Reding #include <linux/err.h> 188ecef00fSUlrich Hecht #include <linux/gpio.h> 19f1407d5cSKuninori Morimoto #include <linux/io.h> 20f1407d5cSKuninori Morimoto #include <linux/module.h> 21*b854100eSYoshihiro Shimoda #include <linux/of_device.h> 22*b854100eSYoshihiro Shimoda #include <linux/of_gpio.h> 23f1407d5cSKuninori Morimoto #include <linux/pm_runtime.h> 24f1407d5cSKuninori Morimoto #include <linux/slab.h> 25f1407d5cSKuninori Morimoto #include <linux/sysfs.h> 26cc502bb7SPaul Bolle #include "common.h" 278ecef00fSUlrich Hecht #include "rcar2.h" 28f1407d5cSKuninori Morimoto 29233f519dSKuninori Morimoto /* 30233f519dSKuninori Morimoto * image of renesas_usbhs 31233f519dSKuninori Morimoto * 32233f519dSKuninori Morimoto * ex) gadget case 33233f519dSKuninori Morimoto 34233f519dSKuninori Morimoto * mod.c 35233f519dSKuninori Morimoto * mod_gadget.c 36233f519dSKuninori Morimoto * mod_host.c pipe.c fifo.c 37233f519dSKuninori Morimoto * 38233f519dSKuninori Morimoto * +-------+ +-----------+ 39233f519dSKuninori Morimoto * | pipe0 |------>| fifo pio | 40233f519dSKuninori Morimoto * +------------+ +-------+ +-----------+ 41233f519dSKuninori Morimoto * | mod_gadget |=====> | pipe1 |--+ 42233f519dSKuninori Morimoto * +------------+ +-------+ | +-----------+ 43233f519dSKuninori Morimoto * | pipe2 | | +-| fifo dma0 | 44233f519dSKuninori Morimoto * +------------+ +-------+ | | +-----------+ 45233f519dSKuninori Morimoto * | mod_host | | pipe3 |<-|--+ 46233f519dSKuninori Morimoto * +------------+ +-------+ | +-----------+ 47233f519dSKuninori Morimoto * | .... | +--->| fifo dma1 | 48233f519dSKuninori Morimoto * | .... | +-----------+ 49233f519dSKuninori Morimoto */ 50233f519dSKuninori Morimoto 51233f519dSKuninori Morimoto 52b002ff6eSKuninori Morimoto #define USBHSF_RUNTIME_PWCTRL (1 << 0) 53b002ff6eSKuninori Morimoto 54b002ff6eSKuninori Morimoto /* status */ 55b002ff6eSKuninori Morimoto #define usbhsc_flags_init(p) do {(p)->flags = 0; } while (0) 56b002ff6eSKuninori Morimoto #define usbhsc_flags_set(p, b) ((p)->flags |= (b)) 57b002ff6eSKuninori Morimoto #define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b)) 58b002ff6eSKuninori Morimoto #define usbhsc_flags_has(p, b) ((p)->flags & (b)) 59b002ff6eSKuninori Morimoto 60f1407d5cSKuninori Morimoto /* 61f1407d5cSKuninori Morimoto * platform call back 62f1407d5cSKuninori Morimoto * 63f1407d5cSKuninori Morimoto * renesas usb support platform callback function. 64f1407d5cSKuninori Morimoto * Below macro call it. 65f1407d5cSKuninori Morimoto * if platform doesn't have callback, it return 0 (no error) 66f1407d5cSKuninori Morimoto */ 67f1407d5cSKuninori Morimoto #define usbhs_platform_call(priv, func, args...)\ 68f1407d5cSKuninori Morimoto (!(priv) ? -ENODEV : \ 6948298206SKuninori Morimoto !((priv)->pfunc.func) ? 0 : \ 7048298206SKuninori Morimoto (priv)->pfunc.func(args)) 71f1407d5cSKuninori Morimoto 72f1407d5cSKuninori Morimoto /* 73f1407d5cSKuninori Morimoto * common functions 74f1407d5cSKuninori Morimoto */ 75f1407d5cSKuninori Morimoto u16 usbhs_read(struct usbhs_priv *priv, u32 reg) 76f1407d5cSKuninori Morimoto { 77f1407d5cSKuninori Morimoto return ioread16(priv->base + reg); 78f1407d5cSKuninori Morimoto } 79f1407d5cSKuninori Morimoto 80f1407d5cSKuninori Morimoto void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data) 81f1407d5cSKuninori Morimoto { 82f1407d5cSKuninori Morimoto iowrite16(data, priv->base + reg); 83f1407d5cSKuninori Morimoto } 84f1407d5cSKuninori Morimoto 85f1407d5cSKuninori Morimoto void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data) 86f1407d5cSKuninori Morimoto { 87f1407d5cSKuninori Morimoto u16 val = usbhs_read(priv, reg); 88f1407d5cSKuninori Morimoto 89f1407d5cSKuninori Morimoto val &= ~mask; 90f1407d5cSKuninori Morimoto val |= data & mask; 91f1407d5cSKuninori Morimoto 92f1407d5cSKuninori Morimoto usbhs_write(priv, reg, val); 93f1407d5cSKuninori Morimoto } 94f1407d5cSKuninori Morimoto 95206dcc2cSKuninori Morimoto struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev) 96206dcc2cSKuninori Morimoto { 97206dcc2cSKuninori Morimoto return dev_get_drvdata(&pdev->dev); 98206dcc2cSKuninori Morimoto } 99206dcc2cSKuninori Morimoto 100f1407d5cSKuninori Morimoto /* 101f1407d5cSKuninori Morimoto * syscfg functions 102f1407d5cSKuninori Morimoto */ 10376190152SKuninori Morimoto static void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable) 104f1407d5cSKuninori Morimoto { 105f1407d5cSKuninori Morimoto usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0); 106f1407d5cSKuninori Morimoto } 107f1407d5cSKuninori Morimoto 108f1407d5cSKuninori Morimoto void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable) 109f1407d5cSKuninori Morimoto { 1103244a7b4SKuninori Morimoto u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; 1113244a7b4SKuninori Morimoto u16 val = DCFM | DRPD | HSE | USBE; 112f427eb64SKuninori Morimoto int has_otg = usbhs_get_dparam(priv, has_otg); 113f427eb64SKuninori Morimoto 114f427eb64SKuninori Morimoto if (has_otg) 115f427eb64SKuninori Morimoto usbhs_bset(priv, DVSTCTR, (EXTLP | PWEN), (EXTLP | PWEN)); 116f1407d5cSKuninori Morimoto 117f1407d5cSKuninori Morimoto /* 118f1407d5cSKuninori Morimoto * if enable 119f1407d5cSKuninori Morimoto * 120f1407d5cSKuninori Morimoto * - select Host mode 121f1407d5cSKuninori Morimoto * - D+ Line/D- Line Pull-down 122f1407d5cSKuninori Morimoto */ 123f1407d5cSKuninori Morimoto usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); 124f1407d5cSKuninori Morimoto } 125f1407d5cSKuninori Morimoto 126f1407d5cSKuninori Morimoto void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable) 127f1407d5cSKuninori Morimoto { 1283244a7b4SKuninori Morimoto u16 mask = DCFM | DRPD | DPRPU | HSE | USBE; 1293244a7b4SKuninori Morimoto u16 val = DPRPU | HSE | USBE; 130f1407d5cSKuninori Morimoto 131f1407d5cSKuninori Morimoto /* 132f1407d5cSKuninori Morimoto * if enable 133f1407d5cSKuninori Morimoto * 134f1407d5cSKuninori Morimoto * - select Function mode 135f1407d5cSKuninori Morimoto * - D+ Line Pull-up 136f1407d5cSKuninori Morimoto */ 137f1407d5cSKuninori Morimoto usbhs_bset(priv, SYSCFG, mask, enable ? val : 0); 138f1407d5cSKuninori Morimoto } 139f1407d5cSKuninori Morimoto 1404cd2f599Skuninori.morimoto.gx@renesas.com void usbhs_sys_function_pullup(struct usbhs_priv *priv, int enable) 1414cd2f599Skuninori.morimoto.gx@renesas.com { 1424cd2f599Skuninori.morimoto.gx@renesas.com usbhs_bset(priv, SYSCFG, DPRPU, enable ? DPRPU : 0); 1434cd2f599Skuninori.morimoto.gx@renesas.com } 1444cd2f599Skuninori.morimoto.gx@renesas.com 145dfbb7f4fSKuninori Morimoto void usbhs_sys_set_test_mode(struct usbhs_priv *priv, u16 mode) 146dfbb7f4fSKuninori Morimoto { 147dfbb7f4fSKuninori Morimoto usbhs_write(priv, TESTMODE, mode); 148dfbb7f4fSKuninori Morimoto } 149dfbb7f4fSKuninori Morimoto 150f1407d5cSKuninori Morimoto /* 151f1407d5cSKuninori Morimoto * frame functions 152f1407d5cSKuninori Morimoto */ 153f1407d5cSKuninori Morimoto int usbhs_frame_get_num(struct usbhs_priv *priv) 154f1407d5cSKuninori Morimoto { 155f1407d5cSKuninori Morimoto return usbhs_read(priv, FRMNUM) & FRNM_MASK; 156f1407d5cSKuninori Morimoto } 157f1407d5cSKuninori Morimoto 158f1407d5cSKuninori Morimoto /* 159ef8bedb9SKuninori Morimoto * usb request functions 160ef8bedb9SKuninori Morimoto */ 161ef8bedb9SKuninori Morimoto void usbhs_usbreq_get_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req) 162ef8bedb9SKuninori Morimoto { 163ef8bedb9SKuninori Morimoto u16 val; 164ef8bedb9SKuninori Morimoto 165ef8bedb9SKuninori Morimoto val = usbhs_read(priv, USBREQ); 166ef8bedb9SKuninori Morimoto req->bRequest = (val >> 8) & 0xFF; 167ef8bedb9SKuninori Morimoto req->bRequestType = (val >> 0) & 0xFF; 168ef8bedb9SKuninori Morimoto 169ef8bedb9SKuninori Morimoto req->wValue = usbhs_read(priv, USBVAL); 170ef8bedb9SKuninori Morimoto req->wIndex = usbhs_read(priv, USBINDX); 171ef8bedb9SKuninori Morimoto req->wLength = usbhs_read(priv, USBLENG); 172ef8bedb9SKuninori Morimoto } 173ef8bedb9SKuninori Morimoto 174ef8bedb9SKuninori Morimoto void usbhs_usbreq_set_val(struct usbhs_priv *priv, struct usb_ctrlrequest *req) 175ef8bedb9SKuninori Morimoto { 176ef8bedb9SKuninori Morimoto usbhs_write(priv, USBREQ, (req->bRequest << 8) | req->bRequestType); 177ef8bedb9SKuninori Morimoto usbhs_write(priv, USBVAL, req->wValue); 178ef8bedb9SKuninori Morimoto usbhs_write(priv, USBINDX, req->wIndex); 179ef8bedb9SKuninori Morimoto usbhs_write(priv, USBLENG, req->wLength); 180ef8bedb9SKuninori Morimoto 181ef8bedb9SKuninori Morimoto usbhs_bset(priv, DCPCTR, SUREQ, SUREQ); 182ef8bedb9SKuninori Morimoto } 183ef8bedb9SKuninori Morimoto 184ef8bedb9SKuninori Morimoto /* 185258485d9SKuninori Morimoto * bus/vbus functions 186258485d9SKuninori Morimoto */ 187258485d9SKuninori Morimoto void usbhs_bus_send_sof_enable(struct usbhs_priv *priv) 188258485d9SKuninori Morimoto { 189a9be4a45SKuninori Morimoto u16 status = usbhs_read(priv, DVSTCTR) & (USBRST | UACT); 190a9be4a45SKuninori Morimoto 191a9be4a45SKuninori Morimoto if (status != USBRST) { 192a9be4a45SKuninori Morimoto struct device *dev = usbhs_priv_to_dev(priv); 193a9be4a45SKuninori Morimoto dev_err(dev, "usbhs should be reset\n"); 194a9be4a45SKuninori Morimoto } 195a9be4a45SKuninori Morimoto 196258485d9SKuninori Morimoto usbhs_bset(priv, DVSTCTR, (USBRST | UACT), UACT); 197258485d9SKuninori Morimoto } 198258485d9SKuninori Morimoto 199258485d9SKuninori Morimoto void usbhs_bus_send_reset(struct usbhs_priv *priv) 200258485d9SKuninori Morimoto { 201258485d9SKuninori Morimoto usbhs_bset(priv, DVSTCTR, (USBRST | UACT), USBRST); 202258485d9SKuninori Morimoto } 203258485d9SKuninori Morimoto 20475587f52SKuninori Morimoto int usbhs_bus_get_speed(struct usbhs_priv *priv) 20575587f52SKuninori Morimoto { 20675587f52SKuninori Morimoto u16 dvstctr = usbhs_read(priv, DVSTCTR); 20775587f52SKuninori Morimoto 20875587f52SKuninori Morimoto switch (RHST & dvstctr) { 20975587f52SKuninori Morimoto case RHST_LOW_SPEED: 21075587f52SKuninori Morimoto return USB_SPEED_LOW; 21175587f52SKuninori Morimoto case RHST_FULL_SPEED: 21275587f52SKuninori Morimoto return USB_SPEED_FULL; 21375587f52SKuninori Morimoto case RHST_HIGH_SPEED: 21475587f52SKuninori Morimoto return USB_SPEED_HIGH; 21575587f52SKuninori Morimoto } 21675587f52SKuninori Morimoto 21775587f52SKuninori Morimoto return USB_SPEED_UNKNOWN; 21875587f52SKuninori Morimoto } 21975587f52SKuninori Morimoto 220258485d9SKuninori Morimoto int usbhs_vbus_ctrl(struct usbhs_priv *priv, int enable) 221258485d9SKuninori Morimoto { 222258485d9SKuninori Morimoto struct platform_device *pdev = usbhs_priv_to_pdev(priv); 223258485d9SKuninori Morimoto 224258485d9SKuninori Morimoto return usbhs_platform_call(priv, set_vbus, pdev, enable); 225258485d9SKuninori Morimoto } 226258485d9SKuninori Morimoto 227258485d9SKuninori Morimoto static void usbhsc_bus_init(struct usbhs_priv *priv) 228258485d9SKuninori Morimoto { 229258485d9SKuninori Morimoto usbhs_write(priv, DVSTCTR, 0); 230258485d9SKuninori Morimoto 231258485d9SKuninori Morimoto usbhs_vbus_ctrl(priv, 0); 232258485d9SKuninori Morimoto } 233258485d9SKuninori Morimoto 234258485d9SKuninori Morimoto /* 235eb05191fSKuninori Morimoto * device configuration 236eb05191fSKuninori Morimoto */ 2373dd49268SKuninori Morimoto int usbhs_set_device_config(struct usbhs_priv *priv, int devnum, 238eb05191fSKuninori Morimoto u16 upphub, u16 hubport, u16 speed) 239eb05191fSKuninori Morimoto { 240eb05191fSKuninori Morimoto struct device *dev = usbhs_priv_to_dev(priv); 241eb05191fSKuninori Morimoto u16 usbspd = 0; 242eb05191fSKuninori Morimoto u32 reg = DEVADD0 + (2 * devnum); 243eb05191fSKuninori Morimoto 244eb05191fSKuninori Morimoto if (devnum > 10) { 245eb05191fSKuninori Morimoto dev_err(dev, "cannot set speed to unknown device %d\n", devnum); 246eb05191fSKuninori Morimoto return -EIO; 247eb05191fSKuninori Morimoto } 248eb05191fSKuninori Morimoto 249eb05191fSKuninori Morimoto if (upphub > 0xA) { 250eb05191fSKuninori Morimoto dev_err(dev, "unsupported hub number %d\n", upphub); 251eb05191fSKuninori Morimoto return -EIO; 252eb05191fSKuninori Morimoto } 253eb05191fSKuninori Morimoto 254eb05191fSKuninori Morimoto switch (speed) { 255eb05191fSKuninori Morimoto case USB_SPEED_LOW: 256eb05191fSKuninori Morimoto usbspd = USBSPD_SPEED_LOW; 257eb05191fSKuninori Morimoto break; 258eb05191fSKuninori Morimoto case USB_SPEED_FULL: 259eb05191fSKuninori Morimoto usbspd = USBSPD_SPEED_FULL; 260eb05191fSKuninori Morimoto break; 261eb05191fSKuninori Morimoto case USB_SPEED_HIGH: 262eb05191fSKuninori Morimoto usbspd = USBSPD_SPEED_HIGH; 263eb05191fSKuninori Morimoto break; 264eb05191fSKuninori Morimoto default: 265eb05191fSKuninori Morimoto dev_err(dev, "unsupported speed %d\n", speed); 266eb05191fSKuninori Morimoto return -EIO; 267eb05191fSKuninori Morimoto } 268eb05191fSKuninori Morimoto 269eb05191fSKuninori Morimoto usbhs_write(priv, reg, UPPHUB(upphub) | 270eb05191fSKuninori Morimoto HUBPORT(hubport)| 271eb05191fSKuninori Morimoto USBSPD(usbspd)); 272eb05191fSKuninori Morimoto 273eb05191fSKuninori Morimoto return 0; 274eb05191fSKuninori Morimoto } 275eb05191fSKuninori Morimoto 276eb05191fSKuninori Morimoto /* 277f1407d5cSKuninori Morimoto * local functions 278f1407d5cSKuninori Morimoto */ 27911935de5SKuninori Morimoto static void usbhsc_set_buswait(struct usbhs_priv *priv) 280f1407d5cSKuninori Morimoto { 281f1407d5cSKuninori Morimoto int wait = usbhs_get_dparam(priv, buswait_bwait); 282f1407d5cSKuninori Morimoto 283f1407d5cSKuninori Morimoto /* set bus wait if platform have */ 284f1407d5cSKuninori Morimoto if (wait) 285f1407d5cSKuninori Morimoto usbhs_bset(priv, BUSWAIT, 0x000F, wait); 286f1407d5cSKuninori Morimoto } 287f1407d5cSKuninori Morimoto 288f1407d5cSKuninori Morimoto /* 289f1407d5cSKuninori Morimoto * platform default param 290f1407d5cSKuninori Morimoto */ 2918ecef00fSUlrich Hecht 2928ecef00fSUlrich Hecht /* commonly used on old SH-Mobile SoCs */ 293f1407d5cSKuninori Morimoto static u32 usbhsc_default_pipe_type[] = { 294f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_CONTROL, 295f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_ISOC, 296f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_ISOC, 297f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_BULK, 298f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_BULK, 299f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_BULK, 300f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_INT, 301f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_INT, 302f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_INT, 303f1407d5cSKuninori Morimoto USB_ENDPOINT_XFER_INT, 304f1407d5cSKuninori Morimoto }; 305f1407d5cSKuninori Morimoto 3068ecef00fSUlrich Hecht /* commonly used on newer SH-Mobile and R-Car SoCs */ 3078ecef00fSUlrich Hecht static u32 usbhsc_new_pipe_type[] = { 3088ecef00fSUlrich Hecht USB_ENDPOINT_XFER_CONTROL, 3098ecef00fSUlrich Hecht USB_ENDPOINT_XFER_ISOC, 3108ecef00fSUlrich Hecht USB_ENDPOINT_XFER_ISOC, 3118ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3128ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3138ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3148ecef00fSUlrich Hecht USB_ENDPOINT_XFER_INT, 3158ecef00fSUlrich Hecht USB_ENDPOINT_XFER_INT, 3168ecef00fSUlrich Hecht USB_ENDPOINT_XFER_INT, 3178ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3188ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3198ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3208ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3218ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3228ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3238ecef00fSUlrich Hecht USB_ENDPOINT_XFER_BULK, 3248ecef00fSUlrich Hecht }; 3258ecef00fSUlrich Hecht 326f1407d5cSKuninori Morimoto /* 3276e267da8SKuninori Morimoto * power control 3286e267da8SKuninori Morimoto */ 3296e267da8SKuninori Morimoto static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable) 3306e267da8SKuninori Morimoto { 331f1ee56a0SKuninori Morimoto struct platform_device *pdev = usbhs_priv_to_pdev(priv); 3326e267da8SKuninori Morimoto struct device *dev = usbhs_priv_to_dev(priv); 3336e267da8SKuninori Morimoto 3346e267da8SKuninori Morimoto if (enable) { 3356e267da8SKuninori Morimoto /* enable PM */ 3366e267da8SKuninori Morimoto pm_runtime_get_sync(dev); 3376e267da8SKuninori Morimoto 338f1ee56a0SKuninori Morimoto /* enable platform power */ 339f1ee56a0SKuninori Morimoto usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); 340f1ee56a0SKuninori Morimoto 3416e267da8SKuninori Morimoto /* USB on */ 3426e267da8SKuninori Morimoto usbhs_sys_clock_ctrl(priv, enable); 3436e267da8SKuninori Morimoto } else { 3446e267da8SKuninori Morimoto /* USB off */ 3456e267da8SKuninori Morimoto usbhs_sys_clock_ctrl(priv, enable); 3466e267da8SKuninori Morimoto 347f1ee56a0SKuninori Morimoto /* disable platform power */ 348f1ee56a0SKuninori Morimoto usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable); 349f1ee56a0SKuninori Morimoto 3506e267da8SKuninori Morimoto /* disable PM */ 3516e267da8SKuninori Morimoto pm_runtime_put_sync(dev); 3526e267da8SKuninori Morimoto } 3536e267da8SKuninori Morimoto } 3546e267da8SKuninori Morimoto 3556e267da8SKuninori Morimoto /* 356ca8a282aSKuninori Morimoto * hotplug 357f1407d5cSKuninori Morimoto */ 358ca8a282aSKuninori Morimoto static void usbhsc_hotplug(struct usbhs_priv *priv) 359f1407d5cSKuninori Morimoto { 360f1407d5cSKuninori Morimoto struct platform_device *pdev = usbhs_priv_to_pdev(priv); 361f1407d5cSKuninori Morimoto struct usbhs_mod *mod = usbhs_mod_get_current(priv); 362f1407d5cSKuninori Morimoto int id; 363f1407d5cSKuninori Morimoto int enable; 364f1407d5cSKuninori Morimoto int ret; 365f1407d5cSKuninori Morimoto 366f1407d5cSKuninori Morimoto /* 367f1407d5cSKuninori Morimoto * get vbus status from platform 368f1407d5cSKuninori Morimoto */ 369f1407d5cSKuninori Morimoto enable = usbhs_platform_call(priv, get_vbus, pdev); 370f1407d5cSKuninori Morimoto 371f1407d5cSKuninori Morimoto /* 372f1407d5cSKuninori Morimoto * get id from platform 373f1407d5cSKuninori Morimoto */ 374f1407d5cSKuninori Morimoto id = usbhs_platform_call(priv, get_id, pdev); 375f1407d5cSKuninori Morimoto 376f1407d5cSKuninori Morimoto if (enable && !mod) { 377f1407d5cSKuninori Morimoto ret = usbhs_mod_change(priv, id); 378f1407d5cSKuninori Morimoto if (ret < 0) 379f1407d5cSKuninori Morimoto return; 380f1407d5cSKuninori Morimoto 381f1407d5cSKuninori Morimoto dev_dbg(&pdev->dev, "%s enable\n", __func__); 382f1407d5cSKuninori Morimoto 3836e267da8SKuninori Morimoto /* power on */ 384b002ff6eSKuninori Morimoto if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 3856e267da8SKuninori Morimoto usbhsc_power_ctrl(priv, enable); 386f1407d5cSKuninori Morimoto 387258485d9SKuninori Morimoto /* bus init */ 388258485d9SKuninori Morimoto usbhsc_set_buswait(priv); 389258485d9SKuninori Morimoto usbhsc_bus_init(priv); 390258485d9SKuninori Morimoto 391f1407d5cSKuninori Morimoto /* module start */ 392f1407d5cSKuninori Morimoto usbhs_mod_call(priv, start, priv); 393f1407d5cSKuninori Morimoto 394f1407d5cSKuninori Morimoto } else if (!enable && mod) { 395f1407d5cSKuninori Morimoto dev_dbg(&pdev->dev, "%s disable\n", __func__); 396f1407d5cSKuninori Morimoto 397f1407d5cSKuninori Morimoto /* module stop */ 398f1407d5cSKuninori Morimoto usbhs_mod_call(priv, stop, priv); 399f1407d5cSKuninori Morimoto 400258485d9SKuninori Morimoto /* bus init */ 401258485d9SKuninori Morimoto usbhsc_bus_init(priv); 402258485d9SKuninori Morimoto 4036e267da8SKuninori Morimoto /* power off */ 404b002ff6eSKuninori Morimoto if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 4056e267da8SKuninori Morimoto usbhsc_power_ctrl(priv, enable); 406f1407d5cSKuninori Morimoto 407f1407d5cSKuninori Morimoto usbhs_mod_change(priv, -1); 408f1407d5cSKuninori Morimoto 409f1407d5cSKuninori Morimoto /* reset phy for next connection */ 410f1407d5cSKuninori Morimoto usbhs_platform_call(priv, phy_reset, pdev); 411f1407d5cSKuninori Morimoto } 412f1407d5cSKuninori Morimoto } 413f1407d5cSKuninori Morimoto 414ca8a282aSKuninori Morimoto /* 415ca8a282aSKuninori Morimoto * notify hotplug 416ca8a282aSKuninori Morimoto */ 417ca8a282aSKuninori Morimoto static void usbhsc_notify_hotplug(struct work_struct *work) 418ca8a282aSKuninori Morimoto { 419ca8a282aSKuninori Morimoto struct usbhs_priv *priv = container_of(work, 420ca8a282aSKuninori Morimoto struct usbhs_priv, 421ca8a282aSKuninori Morimoto notify_hotplug_work.work); 422ca8a282aSKuninori Morimoto usbhsc_hotplug(priv); 423ca8a282aSKuninori Morimoto } 424ca8a282aSKuninori Morimoto 425b4fcea2aSKuninori Morimoto static int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev) 426f1407d5cSKuninori Morimoto { 427206dcc2cSKuninori Morimoto struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 428bc57381eSKuninori Morimoto int delay = usbhs_get_dparam(priv, detection_delay); 429f1407d5cSKuninori Morimoto 430f1407d5cSKuninori Morimoto /* 431f1407d5cSKuninori Morimoto * This functions will be called in interrupt. 432f1407d5cSKuninori Morimoto * To make sure safety context, 433f1407d5cSKuninori Morimoto * use workqueue for usbhs_notify_hotplug 434f1407d5cSKuninori Morimoto */ 435a49a88f1SKuninori Morimoto schedule_delayed_work(&priv->notify_hotplug_work, 436a49a88f1SKuninori Morimoto msecs_to_jiffies(delay)); 437f1407d5cSKuninori Morimoto return 0; 438f1407d5cSKuninori Morimoto } 439f1407d5cSKuninori Morimoto 440f1407d5cSKuninori Morimoto /* 441f1407d5cSKuninori Morimoto * platform functions 442f1407d5cSKuninori Morimoto */ 443*b854100eSYoshihiro Shimoda static const struct of_device_id usbhs_of_match[] = { 444*b854100eSYoshihiro Shimoda { 445*b854100eSYoshihiro Shimoda .compatible = "renesas,usbhs-r8a7790", 446*b854100eSYoshihiro Shimoda .data = (void *)USBHS_TYPE_R8A7790, 447*b854100eSYoshihiro Shimoda }, 448*b854100eSYoshihiro Shimoda { 449*b854100eSYoshihiro Shimoda .compatible = "renesas,usbhs-r8a7791", 450*b854100eSYoshihiro Shimoda .data = (void *)USBHS_TYPE_R8A7791, 451*b854100eSYoshihiro Shimoda }, 452*b854100eSYoshihiro Shimoda { }, 453*b854100eSYoshihiro Shimoda }; 454*b854100eSYoshihiro Shimoda MODULE_DEVICE_TABLE(of, usbhs_of_match); 455*b854100eSYoshihiro Shimoda 456*b854100eSYoshihiro Shimoda static struct renesas_usbhs_platform_info *usbhs_parse_dt(struct device *dev) 457*b854100eSYoshihiro Shimoda { 458*b854100eSYoshihiro Shimoda struct renesas_usbhs_platform_info *info; 459*b854100eSYoshihiro Shimoda struct renesas_usbhs_driver_param *dparam; 460*b854100eSYoshihiro Shimoda const struct of_device_id *of_id = of_match_device(usbhs_of_match, dev); 461*b854100eSYoshihiro Shimoda u32 tmp; 462*b854100eSYoshihiro Shimoda int gpio; 463*b854100eSYoshihiro Shimoda 464*b854100eSYoshihiro Shimoda info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); 465*b854100eSYoshihiro Shimoda if (!info) 466*b854100eSYoshihiro Shimoda return NULL; 467*b854100eSYoshihiro Shimoda 468*b854100eSYoshihiro Shimoda dparam = &info->driver_param; 469*b854100eSYoshihiro Shimoda dparam->type = of_id ? (u32)of_id->data : 0; 470*b854100eSYoshihiro Shimoda if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp)) 471*b854100eSYoshihiro Shimoda dparam->buswait_bwait = tmp; 472*b854100eSYoshihiro Shimoda gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0, 473*b854100eSYoshihiro Shimoda NULL); 474*b854100eSYoshihiro Shimoda if (gpio > 0) 475*b854100eSYoshihiro Shimoda dparam->enable_gpio = gpio; 476*b854100eSYoshihiro Shimoda 477*b854100eSYoshihiro Shimoda return info; 478*b854100eSYoshihiro Shimoda } 479*b854100eSYoshihiro Shimoda 480b7a8d17dSKuninori Morimoto static int usbhs_probe(struct platform_device *pdev) 481f1407d5cSKuninori Morimoto { 482ace0a5f9SJingoo Han struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev); 483f1407d5cSKuninori Morimoto struct renesas_usbhs_driver_callback *dfunc; 484f1407d5cSKuninori Morimoto struct usbhs_priv *priv; 48553069af3SShimoda, Yoshihiro struct resource *res, *irq_res; 486f1407d5cSKuninori Morimoto int ret; 487f1407d5cSKuninori Morimoto 488*b854100eSYoshihiro Shimoda /* check device node */ 489*b854100eSYoshihiro Shimoda if (pdev->dev.of_node) 490*b854100eSYoshihiro Shimoda info = pdev->dev.platform_data = usbhs_parse_dt(&pdev->dev); 491*b854100eSYoshihiro Shimoda 492f1407d5cSKuninori Morimoto /* check platform information */ 4938ecef00fSUlrich Hecht if (!info) { 494f1407d5cSKuninori Morimoto dev_err(&pdev->dev, "no platform information\n"); 495f1407d5cSKuninori Morimoto return -EINVAL; 496f1407d5cSKuninori Morimoto } 497f1407d5cSKuninori Morimoto 498f1407d5cSKuninori Morimoto /* platform data */ 499f1407d5cSKuninori Morimoto res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 50053069af3SShimoda, Yoshihiro irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 50153069af3SShimoda, Yoshihiro if (!res || !irq_res) { 502f1407d5cSKuninori Morimoto dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n"); 503f1407d5cSKuninori Morimoto return -ENODEV; 504f1407d5cSKuninori Morimoto } 505f1407d5cSKuninori Morimoto 506f1407d5cSKuninori Morimoto /* usb private data */ 50758efc77cSKuninori Morimoto priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 508f1407d5cSKuninori Morimoto if (!priv) { 509f1407d5cSKuninori Morimoto dev_err(&pdev->dev, "Could not allocate priv\n"); 510f1407d5cSKuninori Morimoto return -ENOMEM; 511f1407d5cSKuninori Morimoto } 512f1407d5cSKuninori Morimoto 513148e1134SThierry Reding priv->base = devm_ioremap_resource(&pdev->dev, res); 514148e1134SThierry Reding if (IS_ERR(priv->base)) 515148e1134SThierry Reding return PTR_ERR(priv->base); 516f1407d5cSKuninori Morimoto 517f1407d5cSKuninori Morimoto /* 518f1407d5cSKuninori Morimoto * care platform info 519f1407d5cSKuninori Morimoto */ 5208ecef00fSUlrich Hecht 52148298206SKuninori Morimoto memcpy(&priv->dparam, 52248298206SKuninori Morimoto &info->driver_param, 52348298206SKuninori Morimoto sizeof(struct renesas_usbhs_driver_param)); 524f1407d5cSKuninori Morimoto 5258ecef00fSUlrich Hecht switch (priv->dparam.type) { 5268ecef00fSUlrich Hecht case USBHS_TYPE_R8A7790: 5278ecef00fSUlrich Hecht case USBHS_TYPE_R8A7791: 5288ecef00fSUlrich Hecht priv->pfunc = usbhs_rcar2_ops; 5298ecef00fSUlrich Hecht if (!priv->dparam.pipe_type) { 5308ecef00fSUlrich Hecht priv->dparam.pipe_type = usbhsc_new_pipe_type; 5318ecef00fSUlrich Hecht priv->dparam.pipe_size = 5328ecef00fSUlrich Hecht ARRAY_SIZE(usbhsc_new_pipe_type); 5338ecef00fSUlrich Hecht } 5348ecef00fSUlrich Hecht break; 5358ecef00fSUlrich Hecht default: 5368ecef00fSUlrich Hecht if (!info->platform_callback.get_id) { 5378ecef00fSUlrich Hecht dev_err(&pdev->dev, "no platform callbacks"); 5388ecef00fSUlrich Hecht return -EINVAL; 5398ecef00fSUlrich Hecht } 5408ecef00fSUlrich Hecht memcpy(&priv->pfunc, 5418ecef00fSUlrich Hecht &info->platform_callback, 5428ecef00fSUlrich Hecht sizeof(struct renesas_usbhs_platform_callback)); 5438ecef00fSUlrich Hecht break; 5448ecef00fSUlrich Hecht } 5458ecef00fSUlrich Hecht 546f1407d5cSKuninori Morimoto /* set driver callback functions for platform */ 547f1407d5cSKuninori Morimoto dfunc = &info->driver_callback; 548f1407d5cSKuninori Morimoto dfunc->notify_hotplug = usbhsc_drvcllbck_notify_hotplug; 549f1407d5cSKuninori Morimoto 550f1407d5cSKuninori Morimoto /* set default param if platform doesn't have */ 55148298206SKuninori Morimoto if (!priv->dparam.pipe_type) { 55248298206SKuninori Morimoto priv->dparam.pipe_type = usbhsc_default_pipe_type; 55348298206SKuninori Morimoto priv->dparam.pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type); 554f1407d5cSKuninori Morimoto } 55548298206SKuninori Morimoto if (!priv->dparam.pio_dma_border) 55648298206SKuninori Morimoto priv->dparam.pio_dma_border = 64; /* 64byte */ 557f1407d5cSKuninori Morimoto 558b002ff6eSKuninori Morimoto /* FIXME */ 559b002ff6eSKuninori Morimoto /* runtime power control ? */ 56048298206SKuninori Morimoto if (priv->pfunc.get_vbus) 561b002ff6eSKuninori Morimoto usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL); 562b002ff6eSKuninori Morimoto 563f1407d5cSKuninori Morimoto /* 564f1407d5cSKuninori Morimoto * priv settings 565f1407d5cSKuninori Morimoto */ 56653069af3SShimoda, Yoshihiro priv->irq = irq_res->start; 56753069af3SShimoda, Yoshihiro if (irq_res->flags & IORESOURCE_IRQ_SHAREABLE) 56853069af3SShimoda, Yoshihiro priv->irqflags = IRQF_SHARED; 569f1407d5cSKuninori Morimoto priv->pdev = pdev; 570bc57381eSKuninori Morimoto INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug); 571f1407d5cSKuninori Morimoto spin_lock_init(usbhs_priv_to_lock(priv)); 572f1407d5cSKuninori Morimoto 573f1407d5cSKuninori Morimoto /* call pipe and module init */ 574f1407d5cSKuninori Morimoto ret = usbhs_pipe_probe(priv); 575f1407d5cSKuninori Morimoto if (ret < 0) 57658efc77cSKuninori Morimoto return ret; 577f1407d5cSKuninori Morimoto 578d3af90a5SKuninori Morimoto ret = usbhs_fifo_probe(priv); 579f1407d5cSKuninori Morimoto if (ret < 0) 58097f93227SKuninori Morimoto goto probe_end_pipe_exit; 581f1407d5cSKuninori Morimoto 582d3af90a5SKuninori Morimoto ret = usbhs_mod_probe(priv); 583d3af90a5SKuninori Morimoto if (ret < 0) 584d3af90a5SKuninori Morimoto goto probe_end_fifo_exit; 585d3af90a5SKuninori Morimoto 586f1407d5cSKuninori Morimoto /* dev_set_drvdata should be called after usbhs_mod_init */ 587c9a0552eSLibo Chen platform_set_drvdata(pdev, priv); 588f1407d5cSKuninori Morimoto 589f1407d5cSKuninori Morimoto /* 590f1407d5cSKuninori Morimoto * deviece reset here because 591f1407d5cSKuninori Morimoto * USB device might be used in boot loader. 592f1407d5cSKuninori Morimoto */ 593f1407d5cSKuninori Morimoto usbhs_sys_clock_ctrl(priv, 0); 594f1407d5cSKuninori Morimoto 5958ecef00fSUlrich Hecht /* check GPIO determining if USB function should be enabled */ 5968ecef00fSUlrich Hecht if (priv->dparam.enable_gpio) { 5978ecef00fSUlrich Hecht gpio_request_one(priv->dparam.enable_gpio, GPIOF_IN, NULL); 5988ecef00fSUlrich Hecht ret = !gpio_get_value(priv->dparam.enable_gpio); 5998ecef00fSUlrich Hecht gpio_free(priv->dparam.enable_gpio); 6008ecef00fSUlrich Hecht if (ret) { 6018ecef00fSUlrich Hecht dev_warn(&pdev->dev, 6028ecef00fSUlrich Hecht "USB function not selected (GPIO %d)\n", 6038ecef00fSUlrich Hecht priv->dparam.enable_gpio); 6048ecef00fSUlrich Hecht ret = -ENOTSUPP; 6058ecef00fSUlrich Hecht goto probe_end_mod_exit; 6068ecef00fSUlrich Hecht } 6078ecef00fSUlrich Hecht } 6088ecef00fSUlrich Hecht 609f1407d5cSKuninori Morimoto /* 610f1407d5cSKuninori Morimoto * platform call 611f1407d5cSKuninori Morimoto * 612f1407d5cSKuninori Morimoto * USB phy setup might depend on CPU/Board. 613f1407d5cSKuninori Morimoto * If platform has its callback functions, 614f1407d5cSKuninori Morimoto * call it here. 615f1407d5cSKuninori Morimoto */ 616f1407d5cSKuninori Morimoto ret = usbhs_platform_call(priv, hardware_init, pdev); 617f1407d5cSKuninori Morimoto if (ret < 0) { 618f1407d5cSKuninori Morimoto dev_err(&pdev->dev, "platform prove failed.\n"); 61997f93227SKuninori Morimoto goto probe_end_mod_exit; 620f1407d5cSKuninori Morimoto } 621f1407d5cSKuninori Morimoto 622f1407d5cSKuninori Morimoto /* reset phy for connection */ 623f1407d5cSKuninori Morimoto usbhs_platform_call(priv, phy_reset, pdev); 624f1407d5cSKuninori Morimoto 625b002ff6eSKuninori Morimoto /* power control */ 626b002ff6eSKuninori Morimoto pm_runtime_enable(&pdev->dev); 627b002ff6eSKuninori Morimoto if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) { 628b002ff6eSKuninori Morimoto usbhsc_power_ctrl(priv, 1); 629b002ff6eSKuninori Morimoto usbhs_mod_autonomy_mode(priv); 630b002ff6eSKuninori Morimoto } 631b002ff6eSKuninori Morimoto 632f1407d5cSKuninori Morimoto /* 633f1407d5cSKuninori Morimoto * manual call notify_hotplug for cold plug 634f1407d5cSKuninori Morimoto */ 635f1407d5cSKuninori Morimoto ret = usbhsc_drvcllbck_notify_hotplug(pdev); 636f1407d5cSKuninori Morimoto if (ret < 0) 637f1407d5cSKuninori Morimoto goto probe_end_call_remove; 638f1407d5cSKuninori Morimoto 639f1407d5cSKuninori Morimoto dev_info(&pdev->dev, "probed\n"); 640f1407d5cSKuninori Morimoto 641f1407d5cSKuninori Morimoto return ret; 642f1407d5cSKuninori Morimoto 643f1407d5cSKuninori Morimoto probe_end_call_remove: 644f1407d5cSKuninori Morimoto usbhs_platform_call(priv, hardware_exit, pdev); 645f1407d5cSKuninori Morimoto probe_end_mod_exit: 646f1407d5cSKuninori Morimoto usbhs_mod_remove(priv); 647d3af90a5SKuninori Morimoto probe_end_fifo_exit: 648d3af90a5SKuninori Morimoto usbhs_fifo_remove(priv); 64997f93227SKuninori Morimoto probe_end_pipe_exit: 65097f93227SKuninori Morimoto usbhs_pipe_remove(priv); 651f1407d5cSKuninori Morimoto 652f1407d5cSKuninori Morimoto dev_info(&pdev->dev, "probe failed\n"); 653f1407d5cSKuninori Morimoto 654f1407d5cSKuninori Morimoto return ret; 655f1407d5cSKuninori Morimoto } 656f1407d5cSKuninori Morimoto 657fb4e98abSBill Pemberton static int usbhs_remove(struct platform_device *pdev) 658f1407d5cSKuninori Morimoto { 659206dcc2cSKuninori Morimoto struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); 660ace0a5f9SJingoo Han struct renesas_usbhs_platform_info *info = dev_get_platdata(&pdev->dev); 661af32fe51SKuninori Morimoto struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback; 662f1407d5cSKuninori Morimoto 663f1407d5cSKuninori Morimoto dev_dbg(&pdev->dev, "usb remove\n"); 664f1407d5cSKuninori Morimoto 665af32fe51SKuninori Morimoto dfunc->notify_hotplug = NULL; 666af32fe51SKuninori Morimoto 667b002ff6eSKuninori Morimoto /* power off */ 668b002ff6eSKuninori Morimoto if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 669b002ff6eSKuninori Morimoto usbhsc_power_ctrl(priv, 0); 670f1407d5cSKuninori Morimoto 671b002ff6eSKuninori Morimoto pm_runtime_disable(&pdev->dev); 672f1407d5cSKuninori Morimoto 673f1407d5cSKuninori Morimoto usbhs_platform_call(priv, hardware_exit, pdev); 674f1407d5cSKuninori Morimoto usbhs_mod_remove(priv); 675d3af90a5SKuninori Morimoto usbhs_fifo_remove(priv); 67697f93227SKuninori Morimoto usbhs_pipe_remove(priv); 677f1407d5cSKuninori Morimoto 678f1407d5cSKuninori Morimoto return 0; 679f1407d5cSKuninori Morimoto } 680f1407d5cSKuninori Morimoto 681ca8a282aSKuninori Morimoto static int usbhsc_suspend(struct device *dev) 682ca8a282aSKuninori Morimoto { 683ca8a282aSKuninori Morimoto struct usbhs_priv *priv = dev_get_drvdata(dev); 684ca8a282aSKuninori Morimoto struct usbhs_mod *mod = usbhs_mod_get_current(priv); 685ca8a282aSKuninori Morimoto 686ca8a282aSKuninori Morimoto if (mod) { 687ca8a282aSKuninori Morimoto usbhs_mod_call(priv, stop, priv); 688ca8a282aSKuninori Morimoto usbhs_mod_change(priv, -1); 689ca8a282aSKuninori Morimoto } 690ca8a282aSKuninori Morimoto 691ca8a282aSKuninori Morimoto if (mod || !usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 692ca8a282aSKuninori Morimoto usbhsc_power_ctrl(priv, 0); 693ca8a282aSKuninori Morimoto 694ca8a282aSKuninori Morimoto return 0; 695ca8a282aSKuninori Morimoto } 696ca8a282aSKuninori Morimoto 697ca8a282aSKuninori Morimoto static int usbhsc_resume(struct device *dev) 698ca8a282aSKuninori Morimoto { 699ca8a282aSKuninori Morimoto struct usbhs_priv *priv = dev_get_drvdata(dev); 700ca8a282aSKuninori Morimoto struct platform_device *pdev = usbhs_priv_to_pdev(priv); 701ca8a282aSKuninori Morimoto 702ca8a282aSKuninori Morimoto if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) 703ca8a282aSKuninori Morimoto usbhsc_power_ctrl(priv, 1); 704ca8a282aSKuninori Morimoto 7055b50d3b5SKuninori Morimoto usbhs_platform_call(priv, phy_reset, pdev); 7065b50d3b5SKuninori Morimoto 7075b50d3b5SKuninori Morimoto usbhsc_drvcllbck_notify_hotplug(pdev); 708ca8a282aSKuninori Morimoto 709ca8a282aSKuninori Morimoto return 0; 710ca8a282aSKuninori Morimoto } 711ca8a282aSKuninori Morimoto 712ca8a282aSKuninori Morimoto static int usbhsc_runtime_nop(struct device *dev) 713ca8a282aSKuninori Morimoto { 714ca8a282aSKuninori Morimoto /* Runtime PM callback shared between ->runtime_suspend() 715ca8a282aSKuninori Morimoto * and ->runtime_resume(). Simply returns success. 716ca8a282aSKuninori Morimoto * 717ca8a282aSKuninori Morimoto * This driver re-initializes all registers after 718ca8a282aSKuninori Morimoto * pm_runtime_get_sync() anyway so there is no need 719ca8a282aSKuninori Morimoto * to save and restore registers here. 720ca8a282aSKuninori Morimoto */ 721ca8a282aSKuninori Morimoto return 0; 722ca8a282aSKuninori Morimoto } 723ca8a282aSKuninori Morimoto 724ca8a282aSKuninori Morimoto static const struct dev_pm_ops usbhsc_pm_ops = { 725ca8a282aSKuninori Morimoto .suspend = usbhsc_suspend, 726ca8a282aSKuninori Morimoto .resume = usbhsc_resume, 727ca8a282aSKuninori Morimoto .runtime_suspend = usbhsc_runtime_nop, 728ca8a282aSKuninori Morimoto .runtime_resume = usbhsc_runtime_nop, 729ca8a282aSKuninori Morimoto }; 730ca8a282aSKuninori Morimoto 731f1407d5cSKuninori Morimoto static struct platform_driver renesas_usbhs_driver = { 732f1407d5cSKuninori Morimoto .driver = { 733f1407d5cSKuninori Morimoto .name = "renesas_usbhs", 734ca8a282aSKuninori Morimoto .pm = &usbhsc_pm_ops, 735*b854100eSYoshihiro Shimoda .of_match_table = of_match_ptr(usbhs_of_match), 736f1407d5cSKuninori Morimoto }, 737f1407d5cSKuninori Morimoto .probe = usbhs_probe, 7387690417dSBill Pemberton .remove = usbhs_remove, 739f1407d5cSKuninori Morimoto }; 740f1407d5cSKuninori Morimoto 741cc27c96cSAxel Lin module_platform_driver(renesas_usbhs_driver); 742f1407d5cSKuninori Morimoto 743f1407d5cSKuninori Morimoto MODULE_LICENSE("GPL"); 744f1407d5cSKuninori Morimoto MODULE_DESCRIPTION("Renesas USB driver"); 745f1407d5cSKuninori Morimoto MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); 746