Merge tag 'drm-for-v4.15-part2-fixes' of git://people.freedesktop.org/~airlied/linux
[linux-2.6-microblaze.git] / include / linux / usb / renesas_usbhs.h
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/platform_device.h>
21 #include <linux/usb/ch9.h>
22
23 /*
24  * module type
25  *
26  * it will be return value from get_id
27  */
28 enum {
29         USBHS_HOST = 0,
30         USBHS_GADGET,
31         USBHS_MAX,
32 };
33
34 /*
35  * callback functions table for driver
36  *
37  * These functions are called from platform for driver.
38  * Callback function's pointer will be set before
39  * renesas_usbhs_platform_callback :: hardware_init was called
40  */
41 struct renesas_usbhs_driver_callback {
42         int (*notify_hotplug)(struct platform_device *pdev);
43 };
44
45 /*
46  * callback functions for platform
47  *
48  * These functions are called from driver for platform
49  */
50 struct renesas_usbhs_platform_callback {
51
52         /*
53          * option:
54          *
55          * Hardware init function for platform.
56          * it is called when driver was probed.
57          */
58         int (*hardware_init)(struct platform_device *pdev);
59
60         /*
61          * option:
62          *
63          * Hardware exit function for platform.
64          * it is called when driver was removed
65          */
66         int (*hardware_exit)(struct platform_device *pdev);
67
68         /*
69          * option:
70          *
71          * for board specific clock control
72          */
73         int (*power_ctrl)(struct platform_device *pdev,
74                            void __iomem *base, int enable);
75
76         /*
77          * option:
78          *
79          * Phy reset for platform
80          */
81         int (*phy_reset)(struct platform_device *pdev);
82
83         /*
84          * get USB ID function
85          *  - USBHS_HOST
86          *  - USBHS_GADGET
87          */
88         int (*get_id)(struct platform_device *pdev);
89
90         /*
91          * get VBUS status function.
92          */
93         int (*get_vbus)(struct platform_device *pdev);
94
95         /*
96          * option:
97          *
98          * VBUS control is needed for Host
99          */
100         int (*set_vbus)(struct platform_device *pdev, int enable);
101 };
102
103 /*
104  * parameters for renesas usbhs
105  *
106  * some register needs USB chip specific parameters.
107  * This struct show it to driver
108  */
109
110 struct renesas_usbhs_driver_pipe_config {
111         u8 type;        /* USB_ENDPOINT_XFER_xxx */
112         u16 bufsize;
113         u8 bufnum;
114         bool double_buf;
115 };
116 #define RENESAS_USBHS_PIPE(_type, _size, _num, _double_buf)     {       \
117                         .type = (_type),                \
118                         .bufsize = (_size),             \
119                         .bufnum = (_num),               \
120                         .double_buf = (_double_buf),    \
121         }
122
123 struct renesas_usbhs_driver_param {
124         /*
125          * pipe settings
126          */
127         struct renesas_usbhs_driver_pipe_config *pipe_configs;
128         int pipe_size; /* pipe_configs array size */
129
130         /*
131          * option:
132          *
133          * for BUSWAIT :: BWAIT
134          * see
135          *      renesas_usbhs/common.c :: usbhsc_set_buswait()
136          * */
137         int buswait_bwait;
138
139         /*
140          * option:
141          *
142          * delay time from notify_hotplug callback
143          */
144         int detection_delay; /* msec */
145
146         /*
147          * option:
148          *
149          * dma id for dmaengine
150          * The data transfer direction on D0FIFO/D1FIFO should be
151          * fixed for keeping consistency.
152          * So, the platform id settings will be..
153          *      .d0_tx_id = xx_TX,
154          *      .d1_rx_id = xx_RX,
155          * or
156          *      .d1_tx_id = xx_TX,
157          *      .d0_rx_id = xx_RX,
158          */
159         int d0_tx_id;
160         int d0_rx_id;
161         int d1_tx_id;
162         int d1_rx_id;
163         int d2_tx_id;
164         int d2_rx_id;
165         int d3_tx_id;
166         int d3_rx_id;
167
168         /*
169          * option:
170          *
171          * pio <--> dma border.
172          */
173         int pio_dma_border; /* default is 64byte */
174
175         uintptr_t type;
176         u32 enable_gpio;
177
178         /*
179          * option:
180          */
181         u32 has_otg:1; /* for controlling PWEN/EXTLP */
182         u32 has_sudmac:1; /* for SUDMAC */
183         u32 has_usb_dmac:1; /* for USB-DMAC */
184 #define USBHS_USB_DMAC_XFER_SIZE        32      /* hardcode the xfer size */
185 };
186
187 #define USBHS_TYPE_RCAR_GEN2            1
188 #define USBHS_TYPE_RCAR_GEN3            2
189 #define USBHS_TYPE_RCAR_GEN3_WITH_PLL   3
190
191 /*
192  * option:
193  *
194  * platform information for renesas_usbhs driver.
195  */
196 struct renesas_usbhs_platform_info {
197         /*
198          * option:
199          *
200          * platform set these functions before
201          * call platform_add_devices if needed
202          */
203         struct renesas_usbhs_platform_callback  platform_callback;
204
205         /*
206          * driver set these callback functions pointer.
207          * platform can use it on callback functions
208          */
209         struct renesas_usbhs_driver_callback    driver_callback;
210
211         /*
212          * option:
213          *
214          * driver use these param for some register
215          */
216         struct renesas_usbhs_driver_param       driver_param;
217 };
218
219 /*
220  * macro for platform
221  */
222 #define renesas_usbhs_get_info(pdev)\
223         ((struct renesas_usbhs_platform_info *)(pdev)->dev.platform_data)
224
225 #define renesas_usbhs_call_notify_hotplug(pdev)                         \
226         ({                                                              \
227                 struct renesas_usbhs_driver_callback *dc;               \
228                 dc = &(renesas_usbhs_get_info(pdev)->driver_callback);  \
229                 if (dc && dc->notify_hotplug)                           \
230                         dc->notify_hotplug(pdev);                       \
231         })
232 #endif /* RENESAS_USB_H */