xref: /openbmc/linux/drivers/usb/renesas_usbhs/common.c (revision b002ff6e268b6024d6927a1ce330a14ca162b6ab)
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  */
17f1407d5cSKuninori Morimoto #include <linux/io.h>
18f1407d5cSKuninori Morimoto #include <linux/module.h>
19f1407d5cSKuninori Morimoto #include <linux/pm_runtime.h>
20f1407d5cSKuninori Morimoto #include <linux/slab.h>
21f1407d5cSKuninori Morimoto #include <linux/sysfs.h>
22f1407d5cSKuninori Morimoto #include "./common.h"
23f1407d5cSKuninori Morimoto 
24*b002ff6eSKuninori Morimoto #define USBHSF_RUNTIME_PWCTRL	(1 << 0)
25*b002ff6eSKuninori Morimoto 
26*b002ff6eSKuninori Morimoto /* status */
27*b002ff6eSKuninori Morimoto #define usbhsc_flags_init(p)   do {(p)->flags = 0; } while (0)
28*b002ff6eSKuninori Morimoto #define usbhsc_flags_set(p, b) ((p)->flags |=  (b))
29*b002ff6eSKuninori Morimoto #define usbhsc_flags_clr(p, b) ((p)->flags &= ~(b))
30*b002ff6eSKuninori Morimoto #define usbhsc_flags_has(p, b) ((p)->flags &   (b))
31*b002ff6eSKuninori Morimoto 
32f1407d5cSKuninori Morimoto /*
33f1407d5cSKuninori Morimoto  * platform call back
34f1407d5cSKuninori Morimoto  *
35f1407d5cSKuninori Morimoto  * renesas usb support platform callback function.
36f1407d5cSKuninori Morimoto  * Below macro call it.
37f1407d5cSKuninori Morimoto  * if platform doesn't have callback, it return 0 (no error)
38f1407d5cSKuninori Morimoto  */
39f1407d5cSKuninori Morimoto #define usbhs_platform_call(priv, func, args...)\
40f1407d5cSKuninori Morimoto 	(!(priv) ? -ENODEV :			\
41f1407d5cSKuninori Morimoto 	 !((priv)->pfunc->func) ? 0 :		\
42f1407d5cSKuninori Morimoto 	 (priv)->pfunc->func(args))
43f1407d5cSKuninori Morimoto 
44f1407d5cSKuninori Morimoto /*
45f1407d5cSKuninori Morimoto  *		common functions
46f1407d5cSKuninori Morimoto  */
47f1407d5cSKuninori Morimoto u16 usbhs_read(struct usbhs_priv *priv, u32 reg)
48f1407d5cSKuninori Morimoto {
49f1407d5cSKuninori Morimoto 	return ioread16(priv->base + reg);
50f1407d5cSKuninori Morimoto }
51f1407d5cSKuninori Morimoto 
52f1407d5cSKuninori Morimoto void usbhs_write(struct usbhs_priv *priv, u32 reg, u16 data)
53f1407d5cSKuninori Morimoto {
54f1407d5cSKuninori Morimoto 	iowrite16(data, priv->base + reg);
55f1407d5cSKuninori Morimoto }
56f1407d5cSKuninori Morimoto 
57f1407d5cSKuninori Morimoto void usbhs_bset(struct usbhs_priv *priv, u32 reg, u16 mask, u16 data)
58f1407d5cSKuninori Morimoto {
59f1407d5cSKuninori Morimoto 	u16 val = usbhs_read(priv, reg);
60f1407d5cSKuninori Morimoto 
61f1407d5cSKuninori Morimoto 	val &= ~mask;
62f1407d5cSKuninori Morimoto 	val |= data & mask;
63f1407d5cSKuninori Morimoto 
64f1407d5cSKuninori Morimoto 	usbhs_write(priv, reg, val);
65f1407d5cSKuninori Morimoto }
66f1407d5cSKuninori Morimoto 
67206dcc2cSKuninori Morimoto struct usbhs_priv *usbhs_pdev_to_priv(struct platform_device *pdev)
68206dcc2cSKuninori Morimoto {
69206dcc2cSKuninori Morimoto 	return dev_get_drvdata(&pdev->dev);
70206dcc2cSKuninori Morimoto }
71206dcc2cSKuninori Morimoto 
72f1407d5cSKuninori Morimoto /*
73f1407d5cSKuninori Morimoto  *		syscfg functions
74f1407d5cSKuninori Morimoto  */
75f1407d5cSKuninori Morimoto void usbhs_sys_clock_ctrl(struct usbhs_priv *priv, int enable)
76f1407d5cSKuninori Morimoto {
77f1407d5cSKuninori Morimoto 	usbhs_bset(priv, SYSCFG, SCKE, enable ? SCKE : 0);
78f1407d5cSKuninori Morimoto }
79f1407d5cSKuninori Morimoto 
80f1407d5cSKuninori Morimoto void usbhs_sys_hispeed_ctrl(struct usbhs_priv *priv, int enable)
81f1407d5cSKuninori Morimoto {
82f1407d5cSKuninori Morimoto 	usbhs_bset(priv, SYSCFG, HSE, enable ? HSE : 0);
83f1407d5cSKuninori Morimoto }
84f1407d5cSKuninori Morimoto 
85f1407d5cSKuninori Morimoto void usbhs_sys_usb_ctrl(struct usbhs_priv *priv, int enable)
86f1407d5cSKuninori Morimoto {
87f1407d5cSKuninori Morimoto 	usbhs_bset(priv, SYSCFG, USBE, enable ? USBE : 0);
88f1407d5cSKuninori Morimoto }
89f1407d5cSKuninori Morimoto 
90f1407d5cSKuninori Morimoto void usbhs_sys_host_ctrl(struct usbhs_priv *priv, int enable)
91f1407d5cSKuninori Morimoto {
92f1407d5cSKuninori Morimoto 	u16 mask = DCFM | DRPD | DPRPU;
93f1407d5cSKuninori Morimoto 	u16 val  = DCFM | DRPD;
94f1407d5cSKuninori Morimoto 
95f1407d5cSKuninori Morimoto 	/*
96f1407d5cSKuninori Morimoto 	 * if enable
97f1407d5cSKuninori Morimoto 	 *
98f1407d5cSKuninori Morimoto 	 * - select Host mode
99f1407d5cSKuninori Morimoto 	 * - D+ Line/D- Line Pull-down
100f1407d5cSKuninori Morimoto 	 */
101f1407d5cSKuninori Morimoto 	usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
102f1407d5cSKuninori Morimoto }
103f1407d5cSKuninori Morimoto 
104f1407d5cSKuninori Morimoto void usbhs_sys_function_ctrl(struct usbhs_priv *priv, int enable)
105f1407d5cSKuninori Morimoto {
106f1407d5cSKuninori Morimoto 	u16 mask = DCFM | DRPD | DPRPU;
107f1407d5cSKuninori Morimoto 	u16 val  = DPRPU;
108f1407d5cSKuninori Morimoto 
109f1407d5cSKuninori Morimoto 	/*
110f1407d5cSKuninori Morimoto 	 * if enable
111f1407d5cSKuninori Morimoto 	 *
112f1407d5cSKuninori Morimoto 	 * - select Function mode
113f1407d5cSKuninori Morimoto 	 * - D+ Line Pull-up
114f1407d5cSKuninori Morimoto 	 */
115f1407d5cSKuninori Morimoto 	usbhs_bset(priv, SYSCFG, mask, enable ? val : 0);
116f1407d5cSKuninori Morimoto }
117f1407d5cSKuninori Morimoto 
118f1407d5cSKuninori Morimoto /*
119f1407d5cSKuninori Morimoto  *		frame functions
120f1407d5cSKuninori Morimoto  */
121f1407d5cSKuninori Morimoto int usbhs_frame_get_num(struct usbhs_priv *priv)
122f1407d5cSKuninori Morimoto {
123f1407d5cSKuninori Morimoto 	return usbhs_read(priv, FRMNUM) & FRNM_MASK;
124f1407d5cSKuninori Morimoto }
125f1407d5cSKuninori Morimoto 
126f1407d5cSKuninori Morimoto /*
127f1407d5cSKuninori Morimoto  *		local functions
128f1407d5cSKuninori Morimoto  */
129f1407d5cSKuninori Morimoto static void usbhsc_bus_ctrl(struct usbhs_priv *priv, int enable)
130f1407d5cSKuninori Morimoto {
131f1407d5cSKuninori Morimoto 	int wait = usbhs_get_dparam(priv, buswait_bwait);
132f1407d5cSKuninori Morimoto 	u16 data = 0;
133f1407d5cSKuninori Morimoto 
134f1407d5cSKuninori Morimoto 	if (enable) {
135f1407d5cSKuninori Morimoto 		/* set bus wait if platform have */
136f1407d5cSKuninori Morimoto 		if (wait)
137f1407d5cSKuninori Morimoto 			usbhs_bset(priv, BUSWAIT, 0x000F, wait);
138f1407d5cSKuninori Morimoto 	}
139f1407d5cSKuninori Morimoto 	usbhs_write(priv, DVSTCTR, data);
140f1407d5cSKuninori Morimoto }
141f1407d5cSKuninori Morimoto 
142f1407d5cSKuninori Morimoto /*
143f1407d5cSKuninori Morimoto  *		platform default param
144f1407d5cSKuninori Morimoto  */
145f1407d5cSKuninori Morimoto static u32 usbhsc_default_pipe_type[] = {
146f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_CONTROL,
147f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_ISOC,
148f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_ISOC,
149f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_BULK,
150f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_BULK,
151f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_BULK,
152f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_INT,
153f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_INT,
154f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_INT,
155f1407d5cSKuninori Morimoto 		USB_ENDPOINT_XFER_INT,
156f1407d5cSKuninori Morimoto };
157f1407d5cSKuninori Morimoto 
158f1407d5cSKuninori Morimoto /*
1596e267da8SKuninori Morimoto  *		power control
1606e267da8SKuninori Morimoto  */
1616e267da8SKuninori Morimoto static void usbhsc_power_ctrl(struct usbhs_priv *priv, int enable)
1626e267da8SKuninori Morimoto {
1636e267da8SKuninori Morimoto 	struct device *dev = usbhs_priv_to_dev(priv);
1646e267da8SKuninori Morimoto 
1656e267da8SKuninori Morimoto 	if (enable) {
1666e267da8SKuninori Morimoto 		/* enable PM */
1676e267da8SKuninori Morimoto 		pm_runtime_get_sync(dev);
1686e267da8SKuninori Morimoto 
1696e267da8SKuninori Morimoto 		/* USB on */
1706e267da8SKuninori Morimoto 		usbhs_sys_clock_ctrl(priv, enable);
1716e267da8SKuninori Morimoto 		usbhsc_bus_ctrl(priv, enable);
1726e267da8SKuninori Morimoto 	} else {
1736e267da8SKuninori Morimoto 		/* USB off */
1746e267da8SKuninori Morimoto 		usbhsc_bus_ctrl(priv, enable);
1756e267da8SKuninori Morimoto 		usbhs_sys_clock_ctrl(priv, enable);
1766e267da8SKuninori Morimoto 
1776e267da8SKuninori Morimoto 		/* disable PM */
1786e267da8SKuninori Morimoto 		pm_runtime_put_sync(dev);
1796e267da8SKuninori Morimoto 	}
1806e267da8SKuninori Morimoto }
1816e267da8SKuninori Morimoto 
1826e267da8SKuninori Morimoto /*
1836e267da8SKuninori Morimoto  *		notify hotplug
184f1407d5cSKuninori Morimoto  */
185f1407d5cSKuninori Morimoto static void usbhsc_notify_hotplug(struct work_struct *work)
186f1407d5cSKuninori Morimoto {
187f1407d5cSKuninori Morimoto 	struct usbhs_priv *priv = container_of(work,
188f1407d5cSKuninori Morimoto 					       struct usbhs_priv,
189bc57381eSKuninori Morimoto 					       notify_hotplug_work.work);
190f1407d5cSKuninori Morimoto 	struct platform_device *pdev = usbhs_priv_to_pdev(priv);
191f1407d5cSKuninori Morimoto 	struct usbhs_mod *mod = usbhs_mod_get_current(priv);
192f1407d5cSKuninori Morimoto 	int id;
193f1407d5cSKuninori Morimoto 	int enable;
194f1407d5cSKuninori Morimoto 	int ret;
195f1407d5cSKuninori Morimoto 
196f1407d5cSKuninori Morimoto 	/*
197f1407d5cSKuninori Morimoto 	 * get vbus status from platform
198f1407d5cSKuninori Morimoto 	 */
199f1407d5cSKuninori Morimoto 	enable = usbhs_platform_call(priv, get_vbus, pdev);
200f1407d5cSKuninori Morimoto 
201f1407d5cSKuninori Morimoto 	/*
202f1407d5cSKuninori Morimoto 	 * get id from platform
203f1407d5cSKuninori Morimoto 	 */
204f1407d5cSKuninori Morimoto 	id = usbhs_platform_call(priv, get_id, pdev);
205f1407d5cSKuninori Morimoto 
206f1407d5cSKuninori Morimoto 	if (enable && !mod) {
207f1407d5cSKuninori Morimoto 		ret = usbhs_mod_change(priv, id);
208f1407d5cSKuninori Morimoto 		if (ret < 0)
209f1407d5cSKuninori Morimoto 			return;
210f1407d5cSKuninori Morimoto 
211f1407d5cSKuninori Morimoto 		dev_dbg(&pdev->dev, "%s enable\n", __func__);
212f1407d5cSKuninori Morimoto 
2136e267da8SKuninori Morimoto 		/* power on */
214*b002ff6eSKuninori Morimoto 		if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
2156e267da8SKuninori Morimoto 			usbhsc_power_ctrl(priv, enable);
216f1407d5cSKuninori Morimoto 
217f1407d5cSKuninori Morimoto 		/* module start */
218f1407d5cSKuninori Morimoto 		usbhs_mod_call(priv, start, priv);
219f1407d5cSKuninori Morimoto 
220f1407d5cSKuninori Morimoto 	} else if (!enable && mod) {
221f1407d5cSKuninori Morimoto 		dev_dbg(&pdev->dev, "%s disable\n", __func__);
222f1407d5cSKuninori Morimoto 
223f1407d5cSKuninori Morimoto 		/* module stop */
224f1407d5cSKuninori Morimoto 		usbhs_mod_call(priv, stop, priv);
225f1407d5cSKuninori Morimoto 
2266e267da8SKuninori Morimoto 		/* power off */
227*b002ff6eSKuninori Morimoto 		if (usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
2286e267da8SKuninori Morimoto 			usbhsc_power_ctrl(priv, enable);
229f1407d5cSKuninori Morimoto 
230f1407d5cSKuninori Morimoto 		usbhs_mod_change(priv, -1);
231f1407d5cSKuninori Morimoto 
232f1407d5cSKuninori Morimoto 		/* reset phy for next connection */
233f1407d5cSKuninori Morimoto 		usbhs_platform_call(priv, phy_reset, pdev);
234f1407d5cSKuninori Morimoto 	}
235f1407d5cSKuninori Morimoto }
236f1407d5cSKuninori Morimoto 
237bc57381eSKuninori Morimoto int usbhsc_drvcllbck_notify_hotplug(struct platform_device *pdev)
238f1407d5cSKuninori Morimoto {
239206dcc2cSKuninori Morimoto 	struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
240bc57381eSKuninori Morimoto 	int delay = usbhs_get_dparam(priv, detection_delay);
241f1407d5cSKuninori Morimoto 
242f1407d5cSKuninori Morimoto 	/*
243f1407d5cSKuninori Morimoto 	 * This functions will be called in interrupt.
244f1407d5cSKuninori Morimoto 	 * To make sure safety context,
245f1407d5cSKuninori Morimoto 	 * use workqueue for usbhs_notify_hotplug
246f1407d5cSKuninori Morimoto 	 */
247bc57381eSKuninori Morimoto 	schedule_delayed_work(&priv->notify_hotplug_work, delay);
248f1407d5cSKuninori Morimoto 	return 0;
249f1407d5cSKuninori Morimoto }
250f1407d5cSKuninori Morimoto 
251f1407d5cSKuninori Morimoto /*
252f1407d5cSKuninori Morimoto  *		platform functions
253f1407d5cSKuninori Morimoto  */
254f1407d5cSKuninori Morimoto static int __devinit usbhs_probe(struct platform_device *pdev)
255f1407d5cSKuninori Morimoto {
256f1407d5cSKuninori Morimoto 	struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
257f1407d5cSKuninori Morimoto 	struct renesas_usbhs_driver_callback *dfunc;
258f1407d5cSKuninori Morimoto 	struct usbhs_priv *priv;
259f1407d5cSKuninori Morimoto 	struct resource *res;
260f1407d5cSKuninori Morimoto 	unsigned int irq;
261f1407d5cSKuninori Morimoto 	int ret;
262f1407d5cSKuninori Morimoto 
263f1407d5cSKuninori Morimoto 	/* check platform information */
264f1407d5cSKuninori Morimoto 	if (!info ||
265*b002ff6eSKuninori Morimoto 	    !info->platform_callback.get_id) {
266f1407d5cSKuninori Morimoto 		dev_err(&pdev->dev, "no platform information\n");
267f1407d5cSKuninori Morimoto 		return -EINVAL;
268f1407d5cSKuninori Morimoto 	}
269f1407d5cSKuninori Morimoto 
270f1407d5cSKuninori Morimoto 	/* platform data */
271f1407d5cSKuninori Morimoto 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
272f1407d5cSKuninori Morimoto 	irq = platform_get_irq(pdev, 0);
273f1407d5cSKuninori Morimoto 	if (!res || (int)irq <= 0) {
274f1407d5cSKuninori Morimoto 		dev_err(&pdev->dev, "Not enough Renesas USB platform resources.\n");
275f1407d5cSKuninori Morimoto 		return -ENODEV;
276f1407d5cSKuninori Morimoto 	}
277f1407d5cSKuninori Morimoto 
278f1407d5cSKuninori Morimoto 	/* usb private data */
279f1407d5cSKuninori Morimoto 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
280f1407d5cSKuninori Morimoto 	if (!priv) {
281f1407d5cSKuninori Morimoto 		dev_err(&pdev->dev, "Could not allocate priv\n");
282f1407d5cSKuninori Morimoto 		return -ENOMEM;
283f1407d5cSKuninori Morimoto 	}
284f1407d5cSKuninori Morimoto 
285f1407d5cSKuninori Morimoto 	priv->base = ioremap_nocache(res->start, resource_size(res));
286f1407d5cSKuninori Morimoto 	if (!priv->base) {
287f1407d5cSKuninori Morimoto 		dev_err(&pdev->dev, "ioremap error.\n");
288f1407d5cSKuninori Morimoto 		ret = -ENOMEM;
289f1407d5cSKuninori Morimoto 		goto probe_end_kfree;
290f1407d5cSKuninori Morimoto 	}
291f1407d5cSKuninori Morimoto 
292f1407d5cSKuninori Morimoto 	/*
293f1407d5cSKuninori Morimoto 	 * care platform info
294f1407d5cSKuninori Morimoto 	 */
295f1407d5cSKuninori Morimoto 	priv->pfunc	= &info->platform_callback;
296f1407d5cSKuninori Morimoto 	priv->dparam	= &info->driver_param;
297f1407d5cSKuninori Morimoto 
298f1407d5cSKuninori Morimoto 	/* set driver callback functions for platform */
299f1407d5cSKuninori Morimoto 	dfunc			= &info->driver_callback;
300f1407d5cSKuninori Morimoto 	dfunc->notify_hotplug	= usbhsc_drvcllbck_notify_hotplug;
301f1407d5cSKuninori Morimoto 
302f1407d5cSKuninori Morimoto 	/* set default param if platform doesn't have */
303f1407d5cSKuninori Morimoto 	if (!priv->dparam->pipe_type) {
304f1407d5cSKuninori Morimoto 		priv->dparam->pipe_type = usbhsc_default_pipe_type;
305f1407d5cSKuninori Morimoto 		priv->dparam->pipe_size = ARRAY_SIZE(usbhsc_default_pipe_type);
306f1407d5cSKuninori Morimoto 	}
307f1407d5cSKuninori Morimoto 
308*b002ff6eSKuninori Morimoto 	/* FIXME */
309*b002ff6eSKuninori Morimoto 	/* runtime power control ? */
310*b002ff6eSKuninori Morimoto 	if (priv->pfunc->get_vbus)
311*b002ff6eSKuninori Morimoto 		usbhsc_flags_set(priv, USBHSF_RUNTIME_PWCTRL);
312*b002ff6eSKuninori Morimoto 
313f1407d5cSKuninori Morimoto 	/*
314f1407d5cSKuninori Morimoto 	 * priv settings
315f1407d5cSKuninori Morimoto 	 */
316f1407d5cSKuninori Morimoto 	priv->irq	= irq;
317f1407d5cSKuninori Morimoto 	priv->pdev	= pdev;
318bc57381eSKuninori Morimoto 	INIT_DELAYED_WORK(&priv->notify_hotplug_work, usbhsc_notify_hotplug);
319f1407d5cSKuninori Morimoto 	spin_lock_init(usbhs_priv_to_lock(priv));
320f1407d5cSKuninori Morimoto 
321f1407d5cSKuninori Morimoto 	/* call pipe and module init */
322f1407d5cSKuninori Morimoto 	ret = usbhs_pipe_probe(priv);
323f1407d5cSKuninori Morimoto 	if (ret < 0)
324f1407d5cSKuninori Morimoto 		goto probe_end_mod_exit;
325f1407d5cSKuninori Morimoto 
326f1407d5cSKuninori Morimoto 	ret = usbhs_mod_probe(priv);
327f1407d5cSKuninori Morimoto 	if (ret < 0)
328f1407d5cSKuninori Morimoto 		goto probe_end_iounmap;
329f1407d5cSKuninori Morimoto 
330f1407d5cSKuninori Morimoto 	/* dev_set_drvdata should be called after usbhs_mod_init */
331f1407d5cSKuninori Morimoto 	dev_set_drvdata(&pdev->dev, priv);
332f1407d5cSKuninori Morimoto 
333f1407d5cSKuninori Morimoto 	/*
334f1407d5cSKuninori Morimoto 	 * deviece reset here because
335f1407d5cSKuninori Morimoto 	 * USB device might be used in boot loader.
336f1407d5cSKuninori Morimoto 	 */
337f1407d5cSKuninori Morimoto 	usbhs_sys_clock_ctrl(priv, 0);
338f1407d5cSKuninori Morimoto 
339f1407d5cSKuninori Morimoto 	/*
340f1407d5cSKuninori Morimoto 	 * platform call
341f1407d5cSKuninori Morimoto 	 *
342f1407d5cSKuninori Morimoto 	 * USB phy setup might depend on CPU/Board.
343f1407d5cSKuninori Morimoto 	 * If platform has its callback functions,
344f1407d5cSKuninori Morimoto 	 * call it here.
345f1407d5cSKuninori Morimoto 	 */
346f1407d5cSKuninori Morimoto 	ret = usbhs_platform_call(priv, hardware_init, pdev);
347f1407d5cSKuninori Morimoto 	if (ret < 0) {
348f1407d5cSKuninori Morimoto 		dev_err(&pdev->dev, "platform prove failed.\n");
349f1407d5cSKuninori Morimoto 		goto probe_end_pipe_exit;
350f1407d5cSKuninori Morimoto 	}
351f1407d5cSKuninori Morimoto 
352f1407d5cSKuninori Morimoto 	/* reset phy for connection */
353f1407d5cSKuninori Morimoto 	usbhs_platform_call(priv, phy_reset, pdev);
354f1407d5cSKuninori Morimoto 
355*b002ff6eSKuninori Morimoto 	/* power control */
356*b002ff6eSKuninori Morimoto 	pm_runtime_enable(&pdev->dev);
357*b002ff6eSKuninori Morimoto 	if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL)) {
358*b002ff6eSKuninori Morimoto 		usbhsc_power_ctrl(priv, 1);
359*b002ff6eSKuninori Morimoto 		usbhs_mod_autonomy_mode(priv);
360*b002ff6eSKuninori Morimoto 	}
361*b002ff6eSKuninori Morimoto 
362f1407d5cSKuninori Morimoto 	/*
363f1407d5cSKuninori Morimoto 	 * manual call notify_hotplug for cold plug
364f1407d5cSKuninori Morimoto 	 */
365f1407d5cSKuninori Morimoto 	ret = usbhsc_drvcllbck_notify_hotplug(pdev);
366f1407d5cSKuninori Morimoto 	if (ret < 0)
367f1407d5cSKuninori Morimoto 		goto probe_end_call_remove;
368f1407d5cSKuninori Morimoto 
369f1407d5cSKuninori Morimoto 	dev_info(&pdev->dev, "probed\n");
370f1407d5cSKuninori Morimoto 
371f1407d5cSKuninori Morimoto 	return ret;
372f1407d5cSKuninori Morimoto 
373f1407d5cSKuninori Morimoto probe_end_call_remove:
374f1407d5cSKuninori Morimoto 	usbhs_platform_call(priv, hardware_exit, pdev);
375f1407d5cSKuninori Morimoto probe_end_pipe_exit:
376f1407d5cSKuninori Morimoto 	usbhs_pipe_remove(priv);
377f1407d5cSKuninori Morimoto probe_end_mod_exit:
378f1407d5cSKuninori Morimoto 	usbhs_mod_remove(priv);
379f1407d5cSKuninori Morimoto probe_end_iounmap:
380f1407d5cSKuninori Morimoto 	iounmap(priv->base);
381f1407d5cSKuninori Morimoto probe_end_kfree:
382f1407d5cSKuninori Morimoto 	kfree(priv);
383f1407d5cSKuninori Morimoto 
384f1407d5cSKuninori Morimoto 	dev_info(&pdev->dev, "probe failed\n");
385f1407d5cSKuninori Morimoto 
386f1407d5cSKuninori Morimoto 	return ret;
387f1407d5cSKuninori Morimoto }
388f1407d5cSKuninori Morimoto 
389f1407d5cSKuninori Morimoto static int __devexit usbhs_remove(struct platform_device *pdev)
390f1407d5cSKuninori Morimoto {
391206dcc2cSKuninori Morimoto 	struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
392af32fe51SKuninori Morimoto 	struct renesas_usbhs_platform_info *info = pdev->dev.platform_data;
393af32fe51SKuninori Morimoto 	struct renesas_usbhs_driver_callback *dfunc = &info->driver_callback;
394f1407d5cSKuninori Morimoto 
395f1407d5cSKuninori Morimoto 	dev_dbg(&pdev->dev, "usb remove\n");
396f1407d5cSKuninori Morimoto 
397af32fe51SKuninori Morimoto 	dfunc->notify_hotplug = NULL;
398af32fe51SKuninori Morimoto 
399*b002ff6eSKuninori Morimoto 	/* power off */
400*b002ff6eSKuninori Morimoto 	if (!usbhsc_flags_has(priv, USBHSF_RUNTIME_PWCTRL))
401*b002ff6eSKuninori Morimoto 		usbhsc_power_ctrl(priv, 0);
402f1407d5cSKuninori Morimoto 
403*b002ff6eSKuninori Morimoto 	pm_runtime_disable(&pdev->dev);
404f1407d5cSKuninori Morimoto 
405f1407d5cSKuninori Morimoto 	usbhs_platform_call(priv, hardware_exit, pdev);
406f1407d5cSKuninori Morimoto 	usbhs_pipe_remove(priv);
407f1407d5cSKuninori Morimoto 	usbhs_mod_remove(priv);
408f1407d5cSKuninori Morimoto 	iounmap(priv->base);
409f1407d5cSKuninori Morimoto 	kfree(priv);
410f1407d5cSKuninori Morimoto 
411f1407d5cSKuninori Morimoto 	return 0;
412f1407d5cSKuninori Morimoto }
413f1407d5cSKuninori Morimoto 
414f1407d5cSKuninori Morimoto static struct platform_driver renesas_usbhs_driver = {
415f1407d5cSKuninori Morimoto 	.driver		= {
416f1407d5cSKuninori Morimoto 		.name	= "renesas_usbhs",
417f1407d5cSKuninori Morimoto 	},
418f1407d5cSKuninori Morimoto 	.probe		= usbhs_probe,
419f1407d5cSKuninori Morimoto 	.remove		= __devexit_p(usbhs_remove),
420f1407d5cSKuninori Morimoto };
421f1407d5cSKuninori Morimoto 
422f1407d5cSKuninori Morimoto static int __init usbhs_init(void)
423f1407d5cSKuninori Morimoto {
424f1407d5cSKuninori Morimoto 	return platform_driver_register(&renesas_usbhs_driver);
425f1407d5cSKuninori Morimoto }
426f1407d5cSKuninori Morimoto 
427f1407d5cSKuninori Morimoto static void __exit usbhs_exit(void)
428f1407d5cSKuninori Morimoto {
429f1407d5cSKuninori Morimoto 	platform_driver_unregister(&renesas_usbhs_driver);
430f1407d5cSKuninori Morimoto }
431f1407d5cSKuninori Morimoto 
432f1407d5cSKuninori Morimoto module_init(usbhs_init);
433f1407d5cSKuninori Morimoto module_exit(usbhs_exit);
434f1407d5cSKuninori Morimoto 
435f1407d5cSKuninori Morimoto MODULE_LICENSE("GPL");
436f1407d5cSKuninori Morimoto MODULE_DESCRIPTION("Renesas USB driver");
437f1407d5cSKuninori Morimoto MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
438