1 // SPDX-License-Identifier: GPL-1.0+
5 * Copyright (C) 2011 Renesas Solutions Corp.
6 * Copyright (C) 2019 Renesas Electronics Corporation
7 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
9 #ifndef RENESAS_USB_MOD_H
10 #define RENESAS_USB_MOD_H
12 #include <linux/spinlock.h>
13 #include <linux/usb/renesas_usbhs.h>
19 struct usbhs_irq_state
{
31 * entry point from common.c
33 int (*start
)(struct usbhs_priv
*priv
);
34 int (*stop
)(struct usbhs_priv
*priv
);
41 int (*irq_dev_state
)(struct usbhs_priv
*priv
,
42 struct usbhs_irq_state
*irq_state
);
45 int (*irq_ctrl_stage
)(struct usbhs_priv
*priv
,
46 struct usbhs_irq_state
*irq_state
);
49 int (*irq_empty
)(struct usbhs_priv
*priv
,
50 struct usbhs_irq_state
*irq_state
);
54 int (*irq_ready
)(struct usbhs_priv
*priv
,
55 struct usbhs_irq_state
*irq_state
);
63 int (*irq_attch
)(struct usbhs_priv
*priv
,
64 struct usbhs_irq_state
*irq_state
);
67 int (*irq_dtch
)(struct usbhs_priv
*priv
,
68 struct usbhs_irq_state
*irq_state
);
71 int (*irq_sign
)(struct usbhs_priv
*priv
,
72 struct usbhs_irq_state
*irq_state
);
75 int (*irq_sack
)(struct usbhs_priv
*priv
,
76 struct usbhs_irq_state
*irq_state
);
78 struct usbhs_priv
*priv
;
81 struct usbhs_mod_info
{
82 struct usbhs_mod
*mod
[USBHS_MAX
];
83 struct usbhs_mod
*curt
; /* current mod */
88 * This function will be used as autonomy mode (runtime_pwctrl == 0)
89 * when the platform doesn't have own get_vbus function.
91 * This callback cannot be member of "struct usbhs_mod" because it
92 * will be used even though host/gadget has not been selected.
94 int (*irq_vbus
)(struct usbhs_priv
*priv
,
95 struct usbhs_irq_state
*irq_state
);
98 * This function will be used on any gadget mode. To simplify the code,
99 * this member is in here.
101 int (*get_vbus
)(struct platform_device
*pdev
);
105 * for host/gadget module
107 struct usbhs_mod
*usbhs_mod_get(struct usbhs_priv
*priv
, int id
);
108 struct usbhs_mod
*usbhs_mod_get_current(struct usbhs_priv
*priv
);
109 void usbhs_mod_register(struct usbhs_priv
*priv
, struct usbhs_mod
*usb
, int id
);
110 int usbhs_mod_is_host(struct usbhs_priv
*priv
);
111 int usbhs_mod_change(struct usbhs_priv
*priv
, int id
);
112 int usbhs_mod_probe(struct usbhs_priv
*priv
);
113 void usbhs_mod_remove(struct usbhs_priv
*priv
);
115 void usbhs_mod_autonomy_mode(struct usbhs_priv
*priv
);
116 void usbhs_mod_non_autonomy_mode(struct usbhs_priv
*priv
);
121 int usbhs_status_get_device_state(struct usbhs_irq_state
*irq_state
);
122 int usbhs_status_get_ctrl_stage(struct usbhs_irq_state
*irq_state
);
127 void usbhs_irq_callback_update(struct usbhs_priv
*priv
, struct usbhs_mod
*mod
);
130 #define usbhs_mod_call(priv, func, param...) \
132 struct usbhs_mod *mod; \
133 mod = usbhs_mod_get_current(priv); \
139 #define usbhs_priv_to_modinfo(priv) (&priv->mod_info)
140 #define usbhs_mod_info_call(priv, func, param...) \
142 struct usbhs_mod_info *info; \
143 info = usbhs_priv_to_modinfo(priv); \
149 * host / gadget control
151 #if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \
152 defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE)
153 extern int usbhs_mod_host_probe(struct usbhs_priv
*priv
);
154 extern int usbhs_mod_host_remove(struct usbhs_priv
*priv
);
156 static inline int usbhs_mod_host_probe(struct usbhs_priv
*priv
)
160 static inline void usbhs_mod_host_remove(struct usbhs_priv
*priv
)
165 #if defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
166 defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
167 extern int usbhs_mod_gadget_probe(struct usbhs_priv
*priv
);
168 extern void usbhs_mod_gadget_remove(struct usbhs_priv
*priv
);
170 static inline int usbhs_mod_gadget_probe(struct usbhs_priv
*priv
)
174 static inline void usbhs_mod_gadget_remove(struct usbhs_priv
*priv
)
179 #endif /* RENESAS_USB_MOD_H */