Linux Audio

Check our new training course

Loading...
v6.8
  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 <linux/spinlock.h>
 13#include <linux/usb/renesas_usbhs.h>
 14#include "common.h"
 15
 16/*
 17 *	struct
 18 */
 19struct usbhs_irq_state {
 20	u16 intsts0;
 21	u16 intsts1;
 22	u16 brdysts;
 23	u16 nrdysts;
 24	u16 bempsts;
 25};
 26
 27struct usbhs_mod {
 28	char *name;
 29
 30	/*
 31	 * entry point from common.c
 32	 */
 33	int (*start)(struct usbhs_priv *priv);
 34	int (*stop)(struct usbhs_priv *priv);
 35
 36	/*
 37	 * INTSTS0
 38	 */
 39
 40	/* DVST (DVSQ) */
 41	int (*irq_dev_state)(struct usbhs_priv *priv,
 42			     struct usbhs_irq_state *irq_state);
 43
 44	/* CTRT (CTSQ) */
 45	int (*irq_ctrl_stage)(struct usbhs_priv *priv,
 46			      struct usbhs_irq_state *irq_state);
 47
 48	/* BEMP / BEMPSTS */
 49	int (*irq_empty)(struct usbhs_priv *priv,
 50			 struct usbhs_irq_state *irq_state);
 51	u16 irq_bempsts;
 52
 53	/* BRDY / BRDYSTS */
 54	int (*irq_ready)(struct usbhs_priv *priv,
 55			 struct usbhs_irq_state *irq_state);
 56	u16 irq_brdysts;
 57
 58	/*
 59	 * INTSTS1
 60	 */
 61
 62	/* ATTCHE */
 63	int (*irq_attch)(struct usbhs_priv *priv,
 64			 struct usbhs_irq_state *irq_state);
 65
 66	/* DTCHE */
 67	int (*irq_dtch)(struct usbhs_priv *priv,
 68			struct usbhs_irq_state *irq_state);
 69
 70	/* SIGN */
 71	int (*irq_sign)(struct usbhs_priv *priv,
 72			struct usbhs_irq_state *irq_state);
 73
 74	/* SACK */
 75	int (*irq_sack)(struct usbhs_priv *priv,
 76			struct usbhs_irq_state *irq_state);
 77
 78	struct usbhs_priv *priv;
 79};
 80
 81struct usbhs_mod_info {
 82	struct usbhs_mod *mod[USBHS_MAX];
 83	struct usbhs_mod *curt; /* current mod */
 84
 85	/*
 86	 * INTSTS0 :: VBINT
 87	 *
 88	 * This function will be used as autonomy mode (runtime_pwctrl == 0)
 89	 * when the platform doesn't have own get_vbus function.
 90	 *
 91	 * This callback cannot be member of "struct usbhs_mod" because it
 92	 * will be used even though host/gadget has not been selected.
 
 93	 */
 94	int (*irq_vbus)(struct usbhs_priv *priv,
 95			struct usbhs_irq_state *irq_state);
 96
 97	/*
 98	 * This function will be used on any gadget mode. To simplify the code,
 99	 * this member is in here.
100	 */
101	int (*get_vbus)(struct platform_device *pdev);
102};
103
104/*
105 *		for host/gadget module
106 */
107struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
108struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
109void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
110int usbhs_mod_is_host(struct usbhs_priv *priv);
111int usbhs_mod_change(struct usbhs_priv *priv, int id);
112int usbhs_mod_probe(struct usbhs_priv *priv);
113void usbhs_mod_remove(struct usbhs_priv *priv);
114
115void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
116void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv);
117
118/*
119 *		status functions
120 */
121int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
122int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
123
124/*
125 *		callback functions
126 */
127void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
128
129
130#define usbhs_mod_call(priv, func, param...)		\
131	({						\
132		struct usbhs_mod *mod;			\
133		mod = usbhs_mod_get_current(priv);	\
134		!mod		? -ENODEV :		\
135		!mod->func	? 0 :			\
136		 mod->func(param);			\
137	})
138
139#define usbhs_priv_to_modinfo(priv) (&priv->mod_info)
140#define usbhs_mod_info_call(priv, func, param...)	\
141({							\
142	struct usbhs_mod_info *info;			\
143	info = usbhs_priv_to_modinfo(priv);		\
144	!info->func ? 0 :				\
145	 info->func(param);				\
146})
147
148/*
149 * host / gadget control
150 */
151#if	defined(CONFIG_USB_RENESAS_USBHS_HCD) || \
152	defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE)
153extern int usbhs_mod_host_probe(struct usbhs_priv *priv);
154extern int usbhs_mod_host_remove(struct usbhs_priv *priv);
155#else
156static inline int usbhs_mod_host_probe(struct usbhs_priv *priv)
157{
158	return 0;
159}
160static inline void usbhs_mod_host_remove(struct usbhs_priv *priv)
161{
162}
163#endif
164
165#if	defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
166	defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
167extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv);
168extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv);
169#else
170static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
171{
172	return 0;
173}
174static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
175{
176}
177#endif
178
179#endif /* RENESAS_USB_MOD_H */
v4.10.11
 
  1/*
  2 * Renesas USB driver
  3 *
  4 * Copyright (C) 2011 Renesas Solutions Corp.
 
  5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6 *
  7 * This program is distributed in the hope that it will be useful,
  8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 10 * GNU General Public License for more details.
 11 *
 12 * You should have received a copy of the GNU General Public License
 13 * along with this program; if not, write to the Free Software
 14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 15 *
 16 */
 17#ifndef RENESAS_USB_MOD_H
 18#define RENESAS_USB_MOD_H
 19
 20#include <linux/spinlock.h>
 21#include <linux/usb/renesas_usbhs.h>
 22#include "common.h"
 23
 24/*
 25 *	struct
 26 */
 27struct usbhs_irq_state {
 28	u16 intsts0;
 29	u16 intsts1;
 30	u16 brdysts;
 31	u16 nrdysts;
 32	u16 bempsts;
 33};
 34
 35struct usbhs_mod {
 36	char *name;
 37
 38	/*
 39	 * entry point from common.c
 40	 */
 41	int (*start)(struct usbhs_priv *priv);
 42	int (*stop)(struct usbhs_priv *priv);
 43
 44	/*
 45	 * INTSTS0
 46	 */
 47
 48	/* DVST (DVSQ) */
 49	int (*irq_dev_state)(struct usbhs_priv *priv,
 50			     struct usbhs_irq_state *irq_state);
 51
 52	/* CTRT (CTSQ) */
 53	int (*irq_ctrl_stage)(struct usbhs_priv *priv,
 54			      struct usbhs_irq_state *irq_state);
 55
 56	/* BEMP / BEMPSTS */
 57	int (*irq_empty)(struct usbhs_priv *priv,
 58			 struct usbhs_irq_state *irq_state);
 59	u16 irq_bempsts;
 60
 61	/* BRDY / BRDYSTS */
 62	int (*irq_ready)(struct usbhs_priv *priv,
 63			 struct usbhs_irq_state *irq_state);
 64	u16 irq_brdysts;
 65
 66	/*
 67	 * INTSTS1
 68	 */
 69
 70	/* ATTCHE */
 71	int (*irq_attch)(struct usbhs_priv *priv,
 72			 struct usbhs_irq_state *irq_state);
 73
 74	/* DTCHE */
 75	int (*irq_dtch)(struct usbhs_priv *priv,
 76			struct usbhs_irq_state *irq_state);
 77
 78	/* SIGN */
 79	int (*irq_sign)(struct usbhs_priv *priv,
 80			struct usbhs_irq_state *irq_state);
 81
 82	/* SACK */
 83	int (*irq_sack)(struct usbhs_priv *priv,
 84			struct usbhs_irq_state *irq_state);
 85
 86	struct usbhs_priv *priv;
 87};
 88
 89struct usbhs_mod_info {
 90	struct usbhs_mod *mod[USBHS_MAX];
 91	struct usbhs_mod *curt; /* current mod */
 92
 93	/*
 94	 * INTSTS0 :: VBINT
 95	 *
 96	 * This function will be used as autonomy mode
 97	 * when platform cannot call notify_hotplug.
 98	 *
 99	 * This callback cannot be member of "struct usbhs_mod"
100	 * because it will be used even though
101	 * host/gadget has not been selected.
102	 */
103	int (*irq_vbus)(struct usbhs_priv *priv,
104			struct usbhs_irq_state *irq_state);
 
 
 
 
 
 
105};
106
107/*
108 *		for host/gadget module
109 */
110struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
111struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
112void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
113int usbhs_mod_is_host(struct usbhs_priv *priv);
114int usbhs_mod_change(struct usbhs_priv *priv, int id);
115int usbhs_mod_probe(struct usbhs_priv *priv);
116void usbhs_mod_remove(struct usbhs_priv *priv);
117
118void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
 
119
120/*
121 *		status functions
122 */
123int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
124int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
125
126/*
127 *		callback functions
128 */
129void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
130
131
132#define usbhs_mod_call(priv, func, param...)		\
133	({						\
134		struct usbhs_mod *mod;			\
135		mod = usbhs_mod_get_current(priv);	\
136		!mod		? -ENODEV :		\
137		!mod->func	? 0 :			\
138		 mod->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)
146extern int usbhs_mod_host_probe(struct usbhs_priv *priv);
147extern int usbhs_mod_host_remove(struct usbhs_priv *priv);
148#else
149static inline int usbhs_mod_host_probe(struct usbhs_priv *priv)
150{
151	return 0;
152}
153static inline void usbhs_mod_host_remove(struct usbhs_priv *priv)
154{
155}
156#endif
157
158#if	defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
159	defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
160extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv);
161extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv);
162#else
163static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
164{
165	return 0;
166}
167static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
168{
169}
170#endif
171
172#endif /* RENESAS_USB_MOD_H */