blob: 53924f8e840c9e8f095a94d54f20ebae15fb0e91 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-1.0+
Kuninori Morimotof1407d52011-04-04 13:44:59 +09002/*
3 * Renesas USB
4 *
5 * Copyright (C) 2011 Renesas Solutions Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 */
18#ifndef RENESAS_USB_H
19#define RENESAS_USB_H
Yoshihiro Shimodaf16323f2017-12-13 15:46:58 +090020#include <linux/notifier.h>
Kuninori Morimotof1407d52011-04-04 13:44:59 +090021#include <linux/platform_device.h>
22#include <linux/usb/ch9.h>
23
24/*
25 * module type
26 *
27 * it will be return value from get_id
28 */
29enum {
30 USBHS_HOST = 0,
31 USBHS_GADGET,
32 USBHS_MAX,
33};
34
35/*
36 * callback functions table for driver
37 *
38 * These functions are called from platform for driver.
39 * Callback function's pointer will be set before
40 * renesas_usbhs_platform_callback :: hardware_init was called
41 */
42struct renesas_usbhs_driver_callback {
43 int (*notify_hotplug)(struct platform_device *pdev);
44};
45
46/*
47 * callback functions for platform
48 *
49 * These functions are called from driver for platform
50 */
51struct renesas_usbhs_platform_callback {
52
53 /*
54 * option:
55 *
56 * Hardware init function for platform.
57 * it is called when driver was probed.
58 */
59 int (*hardware_init)(struct platform_device *pdev);
60
61 /*
62 * option:
63 *
64 * Hardware exit function for platform.
65 * it is called when driver was removed
66 */
Kuninori Morimoto225da3e2013-03-31 18:34:43 -070067 int (*hardware_exit)(struct platform_device *pdev);
Kuninori Morimotof1407d52011-04-04 13:44:59 +090068
69 /*
70 * option:
71 *
Kuninori Morimotof1ee56a2011-10-23 19:57:10 -070072 * for board specific clock control
73 */
Kuninori Morimoto225da3e2013-03-31 18:34:43 -070074 int (*power_ctrl)(struct platform_device *pdev,
Kuninori Morimotof1ee56a2011-10-23 19:57:10 -070075 void __iomem *base, int enable);
76
77 /*
78 * option:
79 *
Kuninori Morimotof1407d52011-04-04 13:44:59 +090080 * Phy reset for platform
81 */
Kuninori Morimoto225da3e2013-03-31 18:34:43 -070082 int (*phy_reset)(struct platform_device *pdev);
Kuninori Morimotof1407d52011-04-04 13:44:59 +090083
84 /*
85 * get USB ID function
86 * - USBHS_HOST
87 * - USBHS_GADGET
88 */
89 int (*get_id)(struct platform_device *pdev);
90
91 /*
92 * get VBUS status function.
93 */
94 int (*get_vbus)(struct platform_device *pdev);
Kuninori Morimoto258485d2011-10-10 22:01:40 -070095
96 /*
97 * option:
98 *
99 * VBUS control is needed for Host
100 */
101 int (*set_vbus)(struct platform_device *pdev, int enable);
Yoshihiro Shimodaf16323f2017-12-13 15:46:58 +0900102
103 /*
104 * option:
105 * extcon notifier to set host/peripheral mode.
106 */
107 int (*notifier)(struct notifier_block *nb, unsigned long event,
108 void *data);
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900109};
110
111/*
112 * parameters for renesas usbhs
113 *
114 * some register needs USB chip specific parameters.
115 * This struct show it to driver
116 */
Yoshihiro Shimoda51f141a2015-11-18 14:34:09 +0900117
118struct renesas_usbhs_driver_pipe_config {
119 u8 type; /* USB_ENDPOINT_XFER_xxx */
120 u16 bufsize;
121 u8 bufnum;
122 bool double_buf;
123};
124#define RENESAS_USBHS_PIPE(_type, _size, _num, _double_buf) { \
125 .type = (_type), \
126 .bufsize = (_size), \
127 .bufnum = (_num), \
128 .double_buf = (_double_buf), \
129 }
130
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900131struct renesas_usbhs_driver_param {
132 /*
133 * pipe settings
134 */
Yoshihiro Shimoda51f141a2015-11-18 14:34:09 +0900135 struct renesas_usbhs_driver_pipe_config *pipe_configs;
136 int pipe_size; /* pipe_configs array size */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900137
138 /*
139 * option:
140 *
141 * for BUSWAIT :: BWAIT
Kuninori Morimoto11935de2011-10-10 22:01:28 -0700142 * see
143 * renesas_usbhs/common.c :: usbhsc_set_buswait()
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900144 * */
145 int buswait_bwait;
Kuninori Morimotobc573812011-04-28 16:41:14 +0900146
147 /*
148 * option:
149 *
150 * delay time from notify_hotplug callback
151 */
Kuninori Morimotoa49a88f2011-10-23 19:57:02 -0700152 int detection_delay; /* msec */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900153
154 /*
155 * option:
156 *
157 * dma id for dmaengine
Kuninori Morimoto45277152012-05-28 23:31:39 -0700158 * The data transfer direction on D0FIFO/D1FIFO should be
159 * fixed for keeping consistency.
160 * So, the platform id settings will be..
161 * .d0_tx_id = xx_TX,
162 * .d1_rx_id = xx_RX,
163 * or
164 * .d1_tx_id = xx_TX,
165 * .d0_rx_id = xx_RX,
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900166 */
167 int d0_tx_id;
168 int d0_rx_id;
169 int d1_tx_id;
170 int d1_rx_id;
Yoshihiro Shimodad3cf6a42014-11-10 20:02:47 +0900171 int d2_tx_id;
172 int d2_rx_id;
173 int d3_tx_id;
174 int d3_rx_id;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900175
176 /*
177 * option:
178 *
179 * pio <--> dma border.
180 */
181 int pio_dma_border; /* default is 64byte */
Kuninori Morimotof427eb62011-10-10 22:06:12 -0700182
Yoshihiro Shimoda9ae7ce02015-09-29 18:21:18 +0900183 uintptr_t type;
Ulrich Hecht8ecef002014-07-10 09:53:59 +0200184 u32 enable_gpio;
185
Kuninori Morimotof427eb62011-10-10 22:06:12 -0700186 /*
187 * option:
188 */
189 u32 has_otg:1; /* for controlling PWEN/EXTLP */
Shimoda, Yoshihiro5ea43992012-01-05 15:37:22 +0900190 u32 has_sudmac:1; /* for SUDMAC */
Yoshihiro Shimodaab330cf2015-03-12 15:35:20 +0900191 u32 has_usb_dmac:1; /* for USB-DMAC */
192#define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900193};
194
Yoshihiro Shimoda0f386722017-10-03 20:09:14 +0900195#define USBHS_TYPE_RCAR_GEN2 1
196#define USBHS_TYPE_RCAR_GEN3 2
197#define USBHS_TYPE_RCAR_GEN3_WITH_PLL 3
Chris Brandtaec29272018-01-08 07:30:53 -0500198#define USBHS_TYPE_RZA1 4
Ulrich Hecht8ecef002014-07-10 09:53:59 +0200199
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900200/*
201 * option:
202 *
203 * platform information for renesas_usbhs driver.
204 */
205struct renesas_usbhs_platform_info {
206 /*
207 * option:
208 *
209 * platform set these functions before
210 * call platform_add_devices if needed
211 */
212 struct renesas_usbhs_platform_callback platform_callback;
213
214 /*
215 * driver set these callback functions pointer.
216 * platform can use it on callback functions
217 */
218 struct renesas_usbhs_driver_callback driver_callback;
219
220 /*
221 * option:
222 *
223 * driver use these param for some register
224 */
225 struct renesas_usbhs_driver_param driver_param;
226};
227
228/*
229 * macro for platform
230 */
231#define renesas_usbhs_get_info(pdev)\
232 ((struct renesas_usbhs_platform_info *)(pdev)->dev.platform_data)
233
234#define renesas_usbhs_call_notify_hotplug(pdev) \
235 ({ \
236 struct renesas_usbhs_driver_callback *dc; \
237 dc = &(renesas_usbhs_get_info(pdev)->driver_callback); \
Kuninori Morimotoaf32fe52011-04-21 14:10:16 +0900238 if (dc && dc->notify_hotplug) \
Kuninori Morimotof1407d52011-04-04 13:44:59 +0900239 dc->notify_hotplug(pdev); \
240 })
241#endif /* RENESAS_USB_H */