Vitaliy Vasylskyy | d8e5fc8 | 2024-09-09 01:06:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-1.0+ */ |
| 2 | /* |
| 3 | * Renesas USB driver |
| 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_MOD_H |
| 10 | #define RENESAS_USB_MOD_H |
| 11 | |
| 12 | #include "common.h" |
| 13 | |
| 14 | /* |
| 15 | * struct |
| 16 | */ |
| 17 | struct usbhs_irq_state { |
| 18 | u16 intsts0; |
| 19 | u16 intsts1; |
| 20 | u16 brdysts; |
| 21 | u16 nrdysts; |
| 22 | u16 bempsts; |
| 23 | }; |
| 24 | |
| 25 | struct usbhs_mod { |
| 26 | char *name; |
| 27 | |
| 28 | /* |
| 29 | * entry point from common.c |
| 30 | */ |
| 31 | int (*start)(struct usbhs_priv *priv); |
| 32 | int (*stop)(struct usbhs_priv *priv); |
| 33 | |
| 34 | /* |
| 35 | * INTSTS0 |
| 36 | */ |
| 37 | |
| 38 | /* DVST (DVSQ) */ |
| 39 | int (*irq_dev_state)(struct usbhs_priv *priv, |
| 40 | struct usbhs_irq_state *irq_state); |
| 41 | |
| 42 | /* CTRT (CTSQ) */ |
| 43 | int (*irq_ctrl_stage)(struct usbhs_priv *priv, |
| 44 | struct usbhs_irq_state *irq_state); |
| 45 | |
| 46 | /* BEMP / BEMPSTS */ |
| 47 | int (*irq_empty)(struct usbhs_priv *priv, |
| 48 | struct usbhs_irq_state *irq_state); |
| 49 | u16 irq_bempsts; |
| 50 | |
| 51 | /* BRDY / BRDYSTS */ |
| 52 | int (*irq_ready)(struct usbhs_priv *priv, |
| 53 | struct usbhs_irq_state *irq_state); |
| 54 | u16 irq_brdysts; |
| 55 | |
| 56 | /* |
| 57 | * INTSTS1 |
| 58 | */ |
| 59 | |
| 60 | /* ATTCHE */ |
| 61 | int (*irq_attch)(struct usbhs_priv *priv, |
| 62 | struct usbhs_irq_state *irq_state); |
| 63 | |
| 64 | /* DTCHE */ |
| 65 | int (*irq_dtch)(struct usbhs_priv *priv, |
| 66 | struct usbhs_irq_state *irq_state); |
| 67 | |
| 68 | /* SIGN */ |
| 69 | int (*irq_sign)(struct usbhs_priv *priv, |
| 70 | struct usbhs_irq_state *irq_state); |
| 71 | |
| 72 | /* SACK */ |
| 73 | int (*irq_sack)(struct usbhs_priv *priv, |
| 74 | struct usbhs_irq_state *irq_state); |
| 75 | |
| 76 | struct usbhs_priv *priv; |
| 77 | }; |
| 78 | |
| 79 | struct usbhs_mod_info { |
| 80 | struct usbhs_mod *mod[USBHS_MAX]; |
| 81 | struct usbhs_mod *curt; /* current mod */ |
| 82 | |
| 83 | /* |
| 84 | * INTSTS0 :: VBINT |
| 85 | * |
| 86 | * This function will be used as autonomy mode (runtime_pwctrl == 0) |
| 87 | * when the platform doesn't have own get_vbus function. |
| 88 | * |
| 89 | * This callback cannot be member of "struct usbhs_mod" because it |
| 90 | * will be used even though host/gadget has not been selected. |
| 91 | */ |
| 92 | int (*irq_vbus)(struct usbhs_priv *priv, |
| 93 | struct usbhs_irq_state *irq_state); |
| 94 | }; |
| 95 | |
| 96 | /* |
| 97 | * for host/gadget module |
| 98 | */ |
| 99 | struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id); |
| 100 | struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv); |
| 101 | void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id); |
| 102 | int usbhs_mod_is_host(struct usbhs_priv *priv); |
| 103 | int usbhs_mod_change(struct usbhs_priv *priv, int id); |
| 104 | int usbhs_mod_probe(struct usbhs_priv *priv); |
| 105 | void usbhs_mod_remove(struct usbhs_priv *priv); |
| 106 | |
| 107 | void usbhs_mod_autonomy_mode(struct usbhs_priv *priv); |
| 108 | void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv); |
| 109 | |
| 110 | /* |
| 111 | * status functions |
| 112 | */ |
| 113 | int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state); |
| 114 | int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state); |
| 115 | |
| 116 | /* |
| 117 | * callback functions |
| 118 | */ |
| 119 | void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod); |
| 120 | |
| 121 | irqreturn_t usbhs_interrupt(int irq, void *data); |
| 122 | |
| 123 | #define usbhs_mod_call(priv, func, param...) \ |
| 124 | ({ \ |
| 125 | struct usbhs_mod *mod; \ |
| 126 | mod = usbhs_mod_get_current(priv); \ |
| 127 | !mod ? -ENODEV : \ |
| 128 | !mod->func ? 0 : \ |
| 129 | mod->func(param); \ |
| 130 | }) |
| 131 | |
| 132 | #define usbhs_priv_to_modinfo(priv) (&priv->mod_info) |
| 133 | #define usbhs_mod_info_call(priv, func, param...) \ |
| 134 | ({ \ |
| 135 | struct usbhs_mod_info *info; \ |
| 136 | info = usbhs_priv_to_modinfo(priv); \ |
| 137 | !info->func ? 0 : \ |
| 138 | info->func(param); \ |
| 139 | }) |
| 140 | |
| 141 | /* |
| 142 | * host / gadget control |
| 143 | */ |
| 144 | #if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \ |
| 145 | defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE) |
| 146 | extern int usbhs_mod_host_probe(struct usbhs_priv *priv); |
| 147 | extern int usbhs_mod_host_remove(struct usbhs_priv *priv); |
| 148 | #else |
| 149 | static inline int usbhs_mod_host_probe(struct usbhs_priv *priv) |
| 150 | { |
| 151 | return 0; |
| 152 | } |
| 153 | static inline void usbhs_mod_host_remove(struct usbhs_priv *priv) |
| 154 | { |
| 155 | } |
| 156 | #endif |
| 157 | |
| 158 | extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv); |
| 159 | extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv); |
| 160 | |
| 161 | #endif /* RENESAS_USB_MOD_H */ |