xref: /linux/include/linux/usb/renesas_usbhs.h (revision be709d48329a500621d2a05835283150ae137b45)
1 // SPDX-License-Identifier: GPL-1.0+
2 /*
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
20 #include <linux/notifier.h>
21 #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  */
29 enum {
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  */
42 struct 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  */
51 struct 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 	 */
67 	int (*hardware_exit)(struct platform_device *pdev);
68 
69 	/*
70 	 * option:
71 	 *
72 	 * for board specific clock control
73 	 */
74 	int (*power_ctrl)(struct platform_device *pdev,
75 			   void __iomem *base, int enable);
76 
77 	/*
78 	 * option:
79 	 *
80 	 * Phy reset for platform
81 	 */
82 	int (*phy_reset)(struct platform_device *pdev);
83 
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);
95 
96 	/*
97 	 * option:
98 	 *
99 	 * VBUS control is needed for Host
100 	 */
101 	int (*set_vbus)(struct platform_device *pdev, int enable);
102 
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);
109 };
110 
111 /*
112  * parameters for renesas usbhs
113  *
114  * some register needs USB chip specific parameters.
115  * This struct show it to driver
116  */
117 
118 struct 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 
131 struct renesas_usbhs_driver_param {
132 	/*
133 	 * pipe settings
134 	 */
135 	struct renesas_usbhs_driver_pipe_config *pipe_configs;
136 	int pipe_size; /* pipe_configs array size */
137 
138 	/*
139 	 * option:
140 	 *
141 	 * for BUSWAIT :: BWAIT
142 	 * see
143 	 *	renesas_usbhs/common.c :: usbhsc_set_buswait()
144 	 * */
145 	int buswait_bwait;
146 
147 	/*
148 	 * option:
149 	 *
150 	 * delay time from notify_hotplug callback
151 	 */
152 	int detection_delay; /* msec */
153 
154 	/*
155 	 * option:
156 	 *
157 	 * dma id for dmaengine
158 	 * 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,
166 	 */
167 	int d0_tx_id;
168 	int d0_rx_id;
169 	int d1_tx_id;
170 	int d1_rx_id;
171 	int d2_tx_id;
172 	int d2_rx_id;
173 	int d3_tx_id;
174 	int d3_rx_id;
175 
176 	/*
177 	 * option:
178 	 *
179 	 * pio <--> dma border.
180 	 */
181 	int pio_dma_border; /* default is 64byte */
182 
183 	uintptr_t type;
184 	u32 enable_gpio;
185 
186 	/*
187 	 * option:
188 	 */
189 	u32 has_otg:1; /* for controlling PWEN/EXTLP */
190 	u32 has_sudmac:1; /* for SUDMAC */
191 	u32 has_usb_dmac:1; /* for USB-DMAC */
192 #define USBHS_USB_DMAC_XFER_SIZE	32	/* hardcode the xfer size */
193 };
194 
195 #define USBHS_TYPE_RCAR_GEN2		1
196 #define USBHS_TYPE_RCAR_GEN3		2
197 #define USBHS_TYPE_RCAR_GEN3_WITH_PLL	3
198 #define USBHS_TYPE_RZA1			4
199 
200 /*
201  * option:
202  *
203  * platform information for renesas_usbhs driver.
204  */
205 struct 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);	\
238 		if (dc && dc->notify_hotplug)				\
239 			dc->notify_hotplug(pdev);			\
240 	})
241 #endif /* RENESAS_USB_H */
242