treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / phy / broadcom / phy-brcm-usb-init.h
blob899b9eb43fad69fabba135c37f857cef8a275953
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2014-2017 Broadcom
4 */
6 #ifndef _USB_BRCM_COMMON_INIT_H
7 #define _USB_BRCM_COMMON_INIT_H
9 #include <linux/regmap.h>
11 #define USB_CTLR_MODE_HOST 0
12 #define USB_CTLR_MODE_DEVICE 1
13 #define USB_CTLR_MODE_DRD 2
14 #define USB_CTLR_MODE_TYPEC_PD 3
16 enum brcmusb_reg_sel {
17 BRCM_REGS_CTRL = 0,
18 BRCM_REGS_XHCI_EC,
19 BRCM_REGS_XHCI_GBL,
20 BRCM_REGS_USB_PHY,
21 BRCM_REGS_USB_MDIO,
22 BRCM_REGS_BDC_EC,
23 BRCM_REGS_MAX
26 #define USB_CTRL_REG(base, reg) ((void __iomem *)base + USB_CTRL_##reg)
27 #define USB_XHCI_EC_REG(base, reg) ((void __iomem *)base + USB_XHCI_EC_##reg)
28 #define USB_CTRL_MASK(reg, field) \
29 USB_CTRL_##reg##_##field##_MASK
30 #define USB_CTRL_SET(base, reg, field) \
31 brcm_usb_ctrl_set(USB_CTRL_REG(base, reg), \
32 USB_CTRL_##reg##_##field##_MASK)
33 #define USB_CTRL_UNSET(base, reg, field) \
34 brcm_usb_ctrl_unset(USB_CTRL_REG(base, reg), \
35 USB_CTRL_##reg##_##field##_MASK)
37 struct brcm_usb_init_params;
39 struct brcm_usb_init_ops {
40 void (*init_ipp)(struct brcm_usb_init_params *params);
41 void (*init_common)(struct brcm_usb_init_params *params);
42 void (*init_eohci)(struct brcm_usb_init_params *params);
43 void (*init_xhci)(struct brcm_usb_init_params *params);
44 void (*uninit_common)(struct brcm_usb_init_params *params);
45 void (*uninit_eohci)(struct brcm_usb_init_params *params);
46 void (*uninit_xhci)(struct brcm_usb_init_params *params);
47 int (*get_dual_select)(struct brcm_usb_init_params *params);
48 void (*set_dual_select)(struct brcm_usb_init_params *params, int mode);
51 struct brcm_usb_init_params {
52 void __iomem *regs[BRCM_REGS_MAX];
53 int ioc;
54 int ipp;
55 int mode;
56 u32 family_id;
57 u32 product_id;
58 int selected_family;
59 const char *family_name;
60 const u32 *usb_reg_bits_map;
61 const struct brcm_usb_init_ops *ops;
62 struct regmap *syscon_piarbctl;
63 bool wake_enabled;
64 bool suspend_with_clocks;
67 void brcm_usb_dvr_init_7445(struct brcm_usb_init_params *params);
68 void brcm_usb_dvr_init_7216(struct brcm_usb_init_params *params);
69 void brcm_usb_dvr_init_7211b0(struct brcm_usb_init_params *params);
71 static inline u32 brcm_usb_readl(void __iomem *addr)
74 * MIPS endianness is configured by boot strap, which also reverses all
75 * bus endianness (i.e., big-endian CPU + big endian bus ==> native
76 * endian I/O).
78 * Other architectures (e.g., ARM) either do not support big endian, or
79 * else leave I/O in little endian mode.
81 if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
82 return __raw_readl(addr);
83 else
84 return readl_relaxed(addr);
87 static inline void brcm_usb_writel(u32 val, void __iomem *addr)
89 /* See brcmnand_readl() comments */
90 if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
91 __raw_writel(val, addr);
92 else
93 writel_relaxed(val, addr);
96 static inline void brcm_usb_ctrl_unset(void __iomem *reg, u32 mask)
98 brcm_usb_writel(brcm_usb_readl(reg) & ~(mask), reg);
101 static inline void brcm_usb_ctrl_set(void __iomem *reg, u32 mask)
103 brcm_usb_writel(brcm_usb_readl(reg) | (mask), reg);
106 static inline void brcm_usb_init_ipp(struct brcm_usb_init_params *ini)
108 if (ini->ops->init_ipp)
109 ini->ops->init_ipp(ini);
112 static inline void brcm_usb_init_common(struct brcm_usb_init_params *ini)
114 if (ini->ops->init_common)
115 ini->ops->init_common(ini);
118 static inline void brcm_usb_init_eohci(struct brcm_usb_init_params *ini)
120 if (ini->ops->init_eohci)
121 ini->ops->init_eohci(ini);
124 static inline void brcm_usb_init_xhci(struct brcm_usb_init_params *ini)
126 if (ini->ops->init_xhci)
127 ini->ops->init_xhci(ini);
130 static inline void brcm_usb_uninit_common(struct brcm_usb_init_params *ini)
132 if (ini->ops->uninit_common)
133 ini->ops->uninit_common(ini);
136 static inline void brcm_usb_uninit_eohci(struct brcm_usb_init_params *ini)
138 if (ini->ops->uninit_eohci)
139 ini->ops->uninit_eohci(ini);
142 static inline void brcm_usb_uninit_xhci(struct brcm_usb_init_params *ini)
144 if (ini->ops->uninit_xhci)
145 ini->ops->uninit_xhci(ini);
148 static inline int brcm_usb_get_dual_select(struct brcm_usb_init_params *ini)
150 if (ini->ops->get_dual_select)
151 return ini->ops->get_dual_select(ini);
152 return 0;
155 static inline void brcm_usb_set_dual_select(struct brcm_usb_init_params *ini,
156 int mode)
158 if (ini->ops->set_dual_select)
159 ini->ops->set_dual_select(ini, mode);
162 #endif /* _USB_BRCM_COMMON_INIT_H */