Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-1.0+ |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 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 |
Yoshihiro Shimoda | f16323f | 2017-12-13 15:46:58 +0900 | [diff] [blame] | 20 | #include <linux/notifier.h> |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 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 | */ |
Kuninori Morimoto | 225da3e | 2013-03-31 18:34:43 -0700 | [diff] [blame] | 67 | int (*hardware_exit)(struct platform_device *pdev); |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * option: |
| 71 | * |
Kuninori Morimoto | f1ee56a | 2011-10-23 19:57:10 -0700 | [diff] [blame] | 72 | * for board specific clock control |
| 73 | */ |
Kuninori Morimoto | 225da3e | 2013-03-31 18:34:43 -0700 | [diff] [blame] | 74 | int (*power_ctrl)(struct platform_device *pdev, |
Kuninori Morimoto | f1ee56a | 2011-10-23 19:57:10 -0700 | [diff] [blame] | 75 | void __iomem *base, int enable); |
| 76 | |
| 77 | /* |
| 78 | * option: |
| 79 | * |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 80 | * Phy reset for platform |
| 81 | */ |
Kuninori Morimoto | 225da3e | 2013-03-31 18:34:43 -0700 | [diff] [blame] | 82 | int (*phy_reset)(struct platform_device *pdev); |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 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); |
Kuninori Morimoto | 258485d | 2011-10-10 22:01:40 -0700 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * option: |
| 98 | * |
| 99 | * VBUS control is needed for Host |
| 100 | */ |
| 101 | int (*set_vbus)(struct platform_device *pdev, int enable); |
Yoshihiro Shimoda | f16323f | 2017-12-13 15:46:58 +0900 | [diff] [blame] | 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); |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 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 | */ |
Yoshihiro Shimoda | 51f141a | 2015-11-18 14:34:09 +0900 | [diff] [blame] | 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 | |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 131 | struct renesas_usbhs_driver_param { |
| 132 | /* |
| 133 | * pipe settings |
| 134 | */ |
Yoshihiro Shimoda | 51f141a | 2015-11-18 14:34:09 +0900 | [diff] [blame] | 135 | struct renesas_usbhs_driver_pipe_config *pipe_configs; |
| 136 | int pipe_size; /* pipe_configs array size */ |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * option: |
| 140 | * |
| 141 | * for BUSWAIT :: BWAIT |
Kuninori Morimoto | 11935de | 2011-10-10 22:01:28 -0700 | [diff] [blame] | 142 | * see |
| 143 | * renesas_usbhs/common.c :: usbhsc_set_buswait() |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 144 | * */ |
| 145 | int buswait_bwait; |
Kuninori Morimoto | bc57381 | 2011-04-28 16:41:14 +0900 | [diff] [blame] | 146 | |
| 147 | /* |
| 148 | * option: |
| 149 | * |
| 150 | * delay time from notify_hotplug callback |
| 151 | */ |
Kuninori Morimoto | a49a88f | 2011-10-23 19:57:02 -0700 | [diff] [blame] | 152 | int detection_delay; /* msec */ |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * option: |
| 156 | * |
| 157 | * dma id for dmaengine |
Kuninori Morimoto | 4527715 | 2012-05-28 23:31:39 -0700 | [diff] [blame] | 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, |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 166 | */ |
| 167 | int d0_tx_id; |
| 168 | int d0_rx_id; |
| 169 | int d1_tx_id; |
| 170 | int d1_rx_id; |
Yoshihiro Shimoda | d3cf6a4 | 2014-11-10 20:02:47 +0900 | [diff] [blame] | 171 | int d2_tx_id; |
| 172 | int d2_rx_id; |
| 173 | int d3_tx_id; |
| 174 | int d3_rx_id; |
Kuninori Morimoto | e73a989 | 2011-06-06 14:19:03 +0900 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * option: |
| 178 | * |
| 179 | * pio <--> dma border. |
| 180 | */ |
| 181 | int pio_dma_border; /* default is 64byte */ |
Kuninori Morimoto | f427eb6 | 2011-10-10 22:06:12 -0700 | [diff] [blame] | 182 | |
Yoshihiro Shimoda | 9ae7ce0 | 2015-09-29 18:21:18 +0900 | [diff] [blame] | 183 | uintptr_t type; |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 184 | u32 enable_gpio; |
| 185 | |
Kuninori Morimoto | f427eb6 | 2011-10-10 22:06:12 -0700 | [diff] [blame] | 186 | /* |
| 187 | * option: |
| 188 | */ |
| 189 | u32 has_otg:1; /* for controlling PWEN/EXTLP */ |
Shimoda, Yoshihiro | 5ea4399 | 2012-01-05 15:37:22 +0900 | [diff] [blame] | 190 | u32 has_sudmac:1; /* for SUDMAC */ |
Yoshihiro Shimoda | ab330cf | 2015-03-12 15:35:20 +0900 | [diff] [blame] | 191 | u32 has_usb_dmac:1; /* for USB-DMAC */ |
| 192 | #define USBHS_USB_DMAC_XFER_SIZE 32 /* hardcode the xfer size */ |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 193 | }; |
| 194 | |
Yoshihiro Shimoda | 0f38672 | 2017-10-03 20:09:14 +0900 | [diff] [blame] | 195 | #define USBHS_TYPE_RCAR_GEN2 1 |
| 196 | #define USBHS_TYPE_RCAR_GEN3 2 |
| 197 | #define USBHS_TYPE_RCAR_GEN3_WITH_PLL 3 |
Chris Brandt | aec2927 | 2018-01-08 07:30:53 -0500 | [diff] [blame] | 198 | #define USBHS_TYPE_RZA1 4 |
Ulrich Hecht | 8ecef00 | 2014-07-10 09:53:59 +0200 | [diff] [blame] | 199 | |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 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); \ |
Kuninori Morimoto | af32fe5 | 2011-04-21 14:10:16 +0900 | [diff] [blame] | 238 | if (dc && dc->notify_hotplug) \ |
Kuninori Morimoto | f1407d5 | 2011-04-04 13:44:59 +0900 | [diff] [blame] | 239 | dc->notify_hotplug(pdev); \ |
| 240 | }) |
| 241 | #endif /* RENESAS_USB_H */ |