Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-1.0+ */
0002 /*
0003  * Renesas USB driver
0004  *
0005  * Copyright (C) 2011 Renesas Solutions Corp.
0006  * Copyright (C) 2019 Renesas Electronics Corporation
0007  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
0008  */
0009 #ifndef RENESAS_USB_MOD_H
0010 #define RENESAS_USB_MOD_H
0011 
0012 #include <linux/spinlock.h>
0013 #include <linux/usb/renesas_usbhs.h>
0014 #include "common.h"
0015 
0016 /*
0017  *  struct
0018  */
0019 struct usbhs_irq_state {
0020     u16 intsts0;
0021     u16 intsts1;
0022     u16 brdysts;
0023     u16 nrdysts;
0024     u16 bempsts;
0025 };
0026 
0027 struct usbhs_mod {
0028     char *name;
0029 
0030     /*
0031      * entry point from common.c
0032      */
0033     int (*start)(struct usbhs_priv *priv);
0034     int (*stop)(struct usbhs_priv *priv);
0035 
0036     /*
0037      * INTSTS0
0038      */
0039 
0040     /* DVST (DVSQ) */
0041     int (*irq_dev_state)(struct usbhs_priv *priv,
0042                  struct usbhs_irq_state *irq_state);
0043 
0044     /* CTRT (CTSQ) */
0045     int (*irq_ctrl_stage)(struct usbhs_priv *priv,
0046                   struct usbhs_irq_state *irq_state);
0047 
0048     /* BEMP / BEMPSTS */
0049     int (*irq_empty)(struct usbhs_priv *priv,
0050              struct usbhs_irq_state *irq_state);
0051     u16 irq_bempsts;
0052 
0053     /* BRDY / BRDYSTS */
0054     int (*irq_ready)(struct usbhs_priv *priv,
0055              struct usbhs_irq_state *irq_state);
0056     u16 irq_brdysts;
0057 
0058     /*
0059      * INTSTS1
0060      */
0061 
0062     /* ATTCHE */
0063     int (*irq_attch)(struct usbhs_priv *priv,
0064              struct usbhs_irq_state *irq_state);
0065 
0066     /* DTCHE */
0067     int (*irq_dtch)(struct usbhs_priv *priv,
0068             struct usbhs_irq_state *irq_state);
0069 
0070     /* SIGN */
0071     int (*irq_sign)(struct usbhs_priv *priv,
0072             struct usbhs_irq_state *irq_state);
0073 
0074     /* SACK */
0075     int (*irq_sack)(struct usbhs_priv *priv,
0076             struct usbhs_irq_state *irq_state);
0077 
0078     struct usbhs_priv *priv;
0079 };
0080 
0081 struct usbhs_mod_info {
0082     struct usbhs_mod *mod[USBHS_MAX];
0083     struct usbhs_mod *curt; /* current mod */
0084 
0085     /*
0086      * INTSTS0 :: VBINT
0087      *
0088      * This function will be used as autonomy mode (runtime_pwctrl == 0)
0089      * when the platform doesn't have own get_vbus function.
0090      *
0091      * This callback cannot be member of "struct usbhs_mod" because it
0092      * will be used even though host/gadget has not been selected.
0093      */
0094     int (*irq_vbus)(struct usbhs_priv *priv,
0095             struct usbhs_irq_state *irq_state);
0096 
0097     /*
0098      * This function will be used on any gadget mode. To simplify the code,
0099      * this member is in here.
0100      */
0101     int (*get_vbus)(struct platform_device *pdev);
0102 };
0103 
0104 /*
0105  *      for host/gadget module
0106  */
0107 struct usbhs_mod *usbhs_mod_get(struct usbhs_priv *priv, int id);
0108 struct usbhs_mod *usbhs_mod_get_current(struct usbhs_priv *priv);
0109 void usbhs_mod_register(struct usbhs_priv *priv, struct usbhs_mod *usb, int id);
0110 int usbhs_mod_is_host(struct usbhs_priv *priv);
0111 int usbhs_mod_change(struct usbhs_priv *priv, int id);
0112 int usbhs_mod_probe(struct usbhs_priv *priv);
0113 void usbhs_mod_remove(struct usbhs_priv *priv);
0114 
0115 void usbhs_mod_autonomy_mode(struct usbhs_priv *priv);
0116 void usbhs_mod_non_autonomy_mode(struct usbhs_priv *priv);
0117 
0118 /*
0119  *      status functions
0120  */
0121 int usbhs_status_get_device_state(struct usbhs_irq_state *irq_state);
0122 int usbhs_status_get_ctrl_stage(struct usbhs_irq_state *irq_state);
0123 
0124 /*
0125  *      callback functions
0126  */
0127 void usbhs_irq_callback_update(struct usbhs_priv *priv, struct usbhs_mod *mod);
0128 
0129 
0130 #define usbhs_mod_call(priv, func, param...)        \
0131     ({                      \
0132         struct usbhs_mod *mod;          \
0133         mod = usbhs_mod_get_current(priv);  \
0134         !mod        ? -ENODEV :     \
0135         !mod->func  ? 0 :           \
0136          mod->func(param);          \
0137     })
0138 
0139 #define usbhs_priv_to_modinfo(priv) (&priv->mod_info)
0140 #define usbhs_mod_info_call(priv, func, param...)   \
0141 ({                          \
0142     struct usbhs_mod_info *info;            \
0143     info = usbhs_priv_to_modinfo(priv);     \
0144     !info->func ? 0 :               \
0145      info->func(param);             \
0146 })
0147 
0148 /*
0149  * host / gadget control
0150  */
0151 #if defined(CONFIG_USB_RENESAS_USBHS_HCD) || \
0152     defined(CONFIG_USB_RENESAS_USBHS_HCD_MODULE)
0153 extern int usbhs_mod_host_probe(struct usbhs_priv *priv);
0154 extern int usbhs_mod_host_remove(struct usbhs_priv *priv);
0155 #else
0156 static inline int usbhs_mod_host_probe(struct usbhs_priv *priv)
0157 {
0158     return 0;
0159 }
0160 static inline void usbhs_mod_host_remove(struct usbhs_priv *priv)
0161 {
0162 }
0163 #endif
0164 
0165 #if defined(CONFIG_USB_RENESAS_USBHS_UDC) || \
0166     defined(CONFIG_USB_RENESAS_USBHS_UDC_MODULE)
0167 extern int usbhs_mod_gadget_probe(struct usbhs_priv *priv);
0168 extern void usbhs_mod_gadget_remove(struct usbhs_priv *priv);
0169 #else
0170 static inline int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
0171 {
0172     return 0;
0173 }
0174 static inline void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
0175 {
0176 }
0177 #endif
0178 
0179 #endif /* RENESAS_USB_MOD_H */