GNU Linux-libre 6.9.1-gnu
[releases.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  * Copyright (C) 2019 Renesas Electronics Corporation
7  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8  */
9 #ifndef RENESAS_USB_H
10 #define RENESAS_USB_H
11 #include <linux/notifier.h>
12 #include <linux/platform_device.h>
13 #include <linux/usb/ch9.h>
14
15 /*
16  * module type
17  *
18  * it will be return value from get_id
19  */
20 enum {
21         USBHS_HOST = 0,
22         USBHS_GADGET,
23         USBHS_MAX,
24 };
25
26 /*
27  * callback functions for platform
28  *
29  * These functions are called from driver for platform
30  */
31 struct renesas_usbhs_platform_callback {
32
33         /*
34          * option:
35          *
36          * Hardware init function for platform.
37          * it is called when driver was probed.
38          */
39         int (*hardware_init)(struct platform_device *pdev);
40
41         /*
42          * option:
43          *
44          * Hardware exit function for platform.
45          * it is called when driver was removed
46          */
47         int (*hardware_exit)(struct platform_device *pdev);
48
49         /*
50          * option:
51          *
52          * for board specific clock control
53          */
54         int (*power_ctrl)(struct platform_device *pdev,
55                            void __iomem *base, int enable);
56
57         /*
58          * option:
59          *
60          * Phy reset for platform
61          */
62         int (*phy_reset)(struct platform_device *pdev);
63
64         /*
65          * get USB ID function
66          *  - USBHS_HOST
67          *  - USBHS_GADGET
68          */
69         int (*get_id)(struct platform_device *pdev);
70
71         /*
72          * get VBUS status function.
73          */
74         int (*get_vbus)(struct platform_device *pdev);
75
76         /*
77          * option:
78          *
79          * VBUS control is needed for Host
80          */
81         int (*set_vbus)(struct platform_device *pdev, int enable);
82
83         /*
84          * option:
85          * extcon notifier to set host/peripheral mode.
86          */
87         int (*notifier)(struct notifier_block *nb, unsigned long event,
88                         void *data);
89 };
90
91 /*
92  * parameters for renesas usbhs
93  *
94  * some register needs USB chip specific parameters.
95  * This struct show it to driver
96  */
97
98 struct renesas_usbhs_driver_pipe_config {
99         u8 type;        /* USB_ENDPOINT_XFER_xxx */
100         u16 bufsize;
101         u8 bufnum;
102         bool double_buf;
103 };
104 #define RENESAS_USBHS_PIPE(_type, _size, _num, _double_buf)     {       \
105                         .type = (_type),                \
106                         .bufsize = (_size),             \
107                         .bufnum = (_num),               \
108                         .double_buf = (_double_buf),    \
109         }
110
111 struct renesas_usbhs_driver_param {
112         /*
113          * pipe settings
114          */
115         struct renesas_usbhs_driver_pipe_config *pipe_configs;
116         int pipe_size; /* pipe_configs array size */
117
118         /*
119          * option:
120          *
121          * for BUSWAIT :: BWAIT
122          * see
123          *      renesas_usbhs/common.c :: usbhsc_set_buswait()
124          * */
125         int buswait_bwait;
126
127         /*
128          * option:
129          *
130          * delay time from notify_hotplug callback
131          */
132         int detection_delay; /* msec */
133
134         /*
135          * option:
136          *
137          * dma id for dmaengine
138          * The data transfer direction on D0FIFO/D1FIFO should be
139          * fixed for keeping consistency.
140          * So, the platform id settings will be..
141          *      .d0_tx_id = xx_TX,
142          *      .d1_rx_id = xx_RX,
143          * or
144          *      .d1_tx_id = xx_TX,
145          *      .d0_rx_id = xx_RX,
146          */
147         int d0_tx_id;
148         int d0_rx_id;
149         int d1_tx_id;
150         int d1_rx_id;
151         int d2_tx_id;
152         int d2_rx_id;
153         int d3_tx_id;
154         int d3_rx_id;
155
156         /*
157          * option:
158          *
159          * pio <--> dma border.
160          */
161         int pio_dma_border; /* default is 64byte */
162
163         /*
164          * option:
165          */
166         u32 has_usb_dmac:1; /* for USB-DMAC */
167         u32 runtime_pwctrl:1;
168         u32 has_cnen:1;
169         u32 cfifo_byte_addr:1; /* CFIFO is byte addressable */
170 #define USBHS_USB_DMAC_XFER_SIZE        32      /* hardcode the xfer size */
171         u32 multi_clks:1;
172         u32 has_new_pipe_configs:1;
173 };
174
175 /*
176  * option:
177  *
178  * platform information for renesas_usbhs driver.
179  */
180 struct renesas_usbhs_platform_info {
181         /*
182          * option:
183          *
184          * platform set these functions before
185          * call platform_add_devices if needed
186          */
187         struct renesas_usbhs_platform_callback  platform_callback;
188
189         /*
190          * option:
191          *
192          * driver use these param for some register
193          */
194         struct renesas_usbhs_driver_param       driver_param;
195 };
196
197 /*
198  * macro for platform
199  */
200 #define renesas_usbhs_get_info(pdev)\
201         ((struct renesas_usbhs_platform_info *)(pdev)->dev.platform_data)
202 #endif /* RENESAS_USB_H */