| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2014-2017 Broadcom |
|---|
| 3 | | - * |
|---|
| 4 | | - * This software is licensed under the terms of the GNU General Public |
|---|
| 5 | | - * License version 2, as published by the Free Software Foundation, and |
|---|
| 6 | | - * may be copied, distributed, and modified under those terms. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | | - * GNU General Public License for more details. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | |
|---|
| 14 | 6 | #ifndef _USB_BRCM_COMMON_INIT_H |
|---|
| 15 | 7 | #define _USB_BRCM_COMMON_INIT_H |
|---|
| 8 | + |
|---|
| 9 | +#include <linux/regmap.h> |
|---|
| 16 | 10 | |
|---|
| 17 | 11 | #define USB_CTLR_MODE_HOST 0 |
|---|
| 18 | 12 | #define USB_CTLR_MODE_DEVICE 1 |
|---|
| 19 | 13 | #define USB_CTLR_MODE_DRD 2 |
|---|
| 20 | 14 | #define USB_CTLR_MODE_TYPEC_PD 3 |
|---|
| 21 | 15 | |
|---|
| 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 |
|---|
| 24 | +}; |
|---|
| 25 | + |
|---|
| 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) |
|---|
| 36 | + |
|---|
| 22 | 37 | struct brcm_usb_init_params; |
|---|
| 23 | 38 | |
|---|
| 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); |
|---|
| 49 | +}; |
|---|
| 50 | + |
|---|
| 24 | 51 | struct brcm_usb_init_params { |
|---|
| 25 | | - void __iomem *ctrl_regs; |
|---|
| 26 | | - void __iomem *xhci_ec_regs; |
|---|
| 52 | + void __iomem *regs[BRCM_REGS_MAX]; |
|---|
| 27 | 53 | int ioc; |
|---|
| 28 | 54 | int ipp; |
|---|
| 29 | 55 | int mode; |
|---|
| .. | .. |
|---|
| 32 | 58 | int selected_family; |
|---|
| 33 | 59 | const char *family_name; |
|---|
| 34 | 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; |
|---|
| 35 | 65 | }; |
|---|
| 36 | 66 | |
|---|
| 37 | | -void brcm_usb_set_family_map(struct brcm_usb_init_params *params); |
|---|
| 38 | | -int brcm_usb_init_get_dual_select(struct brcm_usb_init_params *params); |
|---|
| 39 | | -void brcm_usb_init_set_dual_select(struct brcm_usb_init_params *params, |
|---|
| 40 | | - int mode); |
|---|
| 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); |
|---|
| 41 | 70 | |
|---|
| 42 | | -void brcm_usb_init_ipp(struct brcm_usb_init_params *ini); |
|---|
| 43 | | -void brcm_usb_init_common(struct brcm_usb_init_params *ini); |
|---|
| 44 | | -void brcm_usb_init_eohci(struct brcm_usb_init_params *ini); |
|---|
| 45 | | -void brcm_usb_init_xhci(struct brcm_usb_init_params *ini); |
|---|
| 46 | | -void brcm_usb_uninit_common(struct brcm_usb_init_params *ini); |
|---|
| 47 | | -void brcm_usb_uninit_eohci(struct brcm_usb_init_params *ini); |
|---|
| 48 | | -void brcm_usb_uninit_xhci(struct brcm_usb_init_params *ini); |
|---|
| 71 | +static inline u32 brcm_usb_readl(void __iomem *addr) |
|---|
| 72 | +{ |
|---|
| 73 | + /* |
|---|
| 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). |
|---|
| 77 | + * |
|---|
| 78 | + * Other architectures (e.g., ARM) either do not support big endian, or |
|---|
| 79 | + * else leave I/O in little endian mode. |
|---|
| 80 | + */ |
|---|
| 81 | + if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) |
|---|
| 82 | + return __raw_readl(addr); |
|---|
| 83 | + else |
|---|
| 84 | + return readl_relaxed(addr); |
|---|
| 85 | +} |
|---|
| 86 | + |
|---|
| 87 | +static inline void brcm_usb_writel(u32 val, void __iomem *addr) |
|---|
| 88 | +{ |
|---|
| 89 | + /* See brcmnand_readl() comments */ |
|---|
| 90 | + if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) |
|---|
| 91 | + __raw_writel(val, addr); |
|---|
| 92 | + else |
|---|
| 93 | + writel_relaxed(val, addr); |
|---|
| 94 | +} |
|---|
| 95 | + |
|---|
| 96 | +static inline void brcm_usb_ctrl_unset(void __iomem *reg, u32 mask) |
|---|
| 97 | +{ |
|---|
| 98 | + brcm_usb_writel(brcm_usb_readl(reg) & ~(mask), reg); |
|---|
| 99 | +}; |
|---|
| 100 | + |
|---|
| 101 | +static inline void brcm_usb_ctrl_set(void __iomem *reg, u32 mask) |
|---|
| 102 | +{ |
|---|
| 103 | + brcm_usb_writel(brcm_usb_readl(reg) | (mask), reg); |
|---|
| 104 | +}; |
|---|
| 105 | + |
|---|
| 106 | +static inline void brcm_usb_init_ipp(struct brcm_usb_init_params *ini) |
|---|
| 107 | +{ |
|---|
| 108 | + if (ini->ops->init_ipp) |
|---|
| 109 | + ini->ops->init_ipp(ini); |
|---|
| 110 | +} |
|---|
| 111 | + |
|---|
| 112 | +static inline void brcm_usb_init_common(struct brcm_usb_init_params *ini) |
|---|
| 113 | +{ |
|---|
| 114 | + if (ini->ops->init_common) |
|---|
| 115 | + ini->ops->init_common(ini); |
|---|
| 116 | +} |
|---|
| 117 | + |
|---|
| 118 | +static inline void brcm_usb_init_eohci(struct brcm_usb_init_params *ini) |
|---|
| 119 | +{ |
|---|
| 120 | + if (ini->ops->init_eohci) |
|---|
| 121 | + ini->ops->init_eohci(ini); |
|---|
| 122 | +} |
|---|
| 123 | + |
|---|
| 124 | +static inline void brcm_usb_init_xhci(struct brcm_usb_init_params *ini) |
|---|
| 125 | +{ |
|---|
| 126 | + if (ini->ops->init_xhci) |
|---|
| 127 | + ini->ops->init_xhci(ini); |
|---|
| 128 | +} |
|---|
| 129 | + |
|---|
| 130 | +static inline void brcm_usb_uninit_common(struct brcm_usb_init_params *ini) |
|---|
| 131 | +{ |
|---|
| 132 | + if (ini->ops->uninit_common) |
|---|
| 133 | + ini->ops->uninit_common(ini); |
|---|
| 134 | +} |
|---|
| 135 | + |
|---|
| 136 | +static inline void brcm_usb_uninit_eohci(struct brcm_usb_init_params *ini) |
|---|
| 137 | +{ |
|---|
| 138 | + if (ini->ops->uninit_eohci) |
|---|
| 139 | + ini->ops->uninit_eohci(ini); |
|---|
| 140 | +} |
|---|
| 141 | + |
|---|
| 142 | +static inline void brcm_usb_uninit_xhci(struct brcm_usb_init_params *ini) |
|---|
| 143 | +{ |
|---|
| 144 | + if (ini->ops->uninit_xhci) |
|---|
| 145 | + ini->ops->uninit_xhci(ini); |
|---|
| 146 | +} |
|---|
| 147 | + |
|---|
| 148 | +static inline int brcm_usb_get_dual_select(struct brcm_usb_init_params *ini) |
|---|
| 149 | +{ |
|---|
| 150 | + if (ini->ops->get_dual_select) |
|---|
| 151 | + return ini->ops->get_dual_select(ini); |
|---|
| 152 | + return 0; |
|---|
| 153 | +} |
|---|
| 154 | + |
|---|
| 155 | +static inline void brcm_usb_set_dual_select(struct brcm_usb_init_params *ini, |
|---|
| 156 | + int mode) |
|---|
| 157 | +{ |
|---|
| 158 | + if (ini->ops->set_dual_select) |
|---|
| 159 | + ini->ops->set_dual_select(ini, mode); |
|---|
| 160 | +} |
|---|
| 49 | 161 | |
|---|
| 50 | 162 | #endif /* _USB_BRCM_COMMON_INIT_H */ |
|---|