Yoshihiro Shimoda | de18757 | 2016-01-07 18:18:13 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Renesas USB driver R-Car Gen. 3 initialization and power control |
| 3 | * |
| 4 | * Copyright (C) 2016 Renesas Electronics Corporation |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
Yoshihiro Shimoda | b760323 | 2016-10-20 13:19:19 +0900 | [diff] [blame] | 12 | #include <linux/delay.h> |
Yoshihiro Shimoda | de18757 | 2016-01-07 18:18:13 +0900 | [diff] [blame] | 13 | #include <linux/io.h> |
| 14 | #include "common.h" |
| 15 | #include "rcar3.h" |
| 16 | |
| 17 | #define LPSTS 0x102 |
| 18 | #define UGCTRL2 0x184 /* 32-bit register */ |
| 19 | |
| 20 | /* Low Power Status register (LPSTS) */ |
| 21 | #define LPSTS_SUSPM 0x4000 |
| 22 | |
| 23 | /* USB General control register 2 (UGCTRL2), bit[31:6] should be 0 */ |
| 24 | #define UGCTRL2_RESERVED_3 0x00000001 /* bit[3:0] should be B'0001 */ |
| 25 | #define UGCTRL2_USB0SEL_OTG 0x00000030 |
| 26 | |
Ben Dooks | 107a4b5 | 2016-06-21 18:52:54 +0100 | [diff] [blame] | 27 | static void usbhs_write32(struct usbhs_priv *priv, u32 reg, u32 data) |
Yoshihiro Shimoda | de18757 | 2016-01-07 18:18:13 +0900 | [diff] [blame] | 28 | { |
| 29 | iowrite32(data, priv->base + reg); |
| 30 | } |
| 31 | |
| 32 | static int usbhs_rcar3_power_ctrl(struct platform_device *pdev, |
| 33 | void __iomem *base, int enable) |
| 34 | { |
| 35 | struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev); |
| 36 | |
| 37 | usbhs_write32(priv, UGCTRL2, UGCTRL2_RESERVED_3 | UGCTRL2_USB0SEL_OTG); |
| 38 | |
Yoshihiro Shimoda | b760323 | 2016-10-20 13:19:19 +0900 | [diff] [blame] | 39 | if (enable) { |
Yoshihiro Shimoda | de18757 | 2016-01-07 18:18:13 +0900 | [diff] [blame] | 40 | usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM); |
Yoshihiro Shimoda | b760323 | 2016-10-20 13:19:19 +0900 | [diff] [blame] | 41 | /* The controller on R-Car Gen3 needs to wait up to 45 usec */ |
| 42 | udelay(45); |
| 43 | } else { |
Yoshihiro Shimoda | de18757 | 2016-01-07 18:18:13 +0900 | [diff] [blame] | 44 | usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0); |
Yoshihiro Shimoda | b760323 | 2016-10-20 13:19:19 +0900 | [diff] [blame] | 45 | } |
Yoshihiro Shimoda | de18757 | 2016-01-07 18:18:13 +0900 | [diff] [blame] | 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int usbhs_rcar3_get_id(struct platform_device *pdev) |
| 51 | { |
| 52 | return USBHS_GADGET; |
| 53 | } |
| 54 | |
| 55 | const struct renesas_usbhs_platform_callback usbhs_rcar3_ops = { |
| 56 | .power_ctrl = usbhs_rcar3_power_ctrl, |
| 57 | .get_id = usbhs_rcar3_get_id, |
| 58 | }; |