19c92ab61SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
249859e55SAl Cooper /*
349859e55SAl Cooper * Copyright (C) 2014-2017 Broadcom
449859e55SAl Cooper */
549859e55SAl Cooper
649859e55SAl Cooper #ifndef _USB_BRCM_COMMON_INIT_H
749859e55SAl Cooper #define _USB_BRCM_COMMON_INIT_H
849859e55SAl Cooper
99d5f51dcSAl Cooper #include <linux/regmap.h>
109d5f51dcSAl Cooper
1149859e55SAl Cooper #define USB_CTLR_MODE_HOST 0
1249859e55SAl Cooper #define USB_CTLR_MODE_DEVICE 1
1349859e55SAl Cooper #define USB_CTLR_MODE_DRD 2
1449859e55SAl Cooper #define USB_CTLR_MODE_TYPEC_PD 3
1549859e55SAl Cooper
169d5f51dcSAl Cooper enum brcmusb_reg_sel {
179d5f51dcSAl Cooper BRCM_REGS_CTRL = 0,
189d5f51dcSAl Cooper BRCM_REGS_XHCI_EC,
199d5f51dcSAl Cooper BRCM_REGS_XHCI_GBL,
209d5f51dcSAl Cooper BRCM_REGS_USB_PHY,
219d5f51dcSAl Cooper BRCM_REGS_USB_MDIO,
22bed63b63SAl Cooper BRCM_REGS_BDC_EC,
239d5f51dcSAl Cooper BRCM_REGS_MAX
249d5f51dcSAl Cooper };
2549859e55SAl Cooper
2694583a41SAl Cooper #define USB_CTRL_REG(base, reg) ((void __iomem *)base + USB_CTRL_##reg)
2794583a41SAl Cooper #define USB_XHCI_EC_REG(base, reg) ((void __iomem *)base + USB_XHCI_EC_##reg)
2894583a41SAl Cooper #define USB_CTRL_MASK(reg, field) \
2994583a41SAl Cooper USB_CTRL_##reg##_##field##_MASK
3094583a41SAl Cooper #define USB_CTRL_SET(base, reg, field) \
3194583a41SAl Cooper brcm_usb_ctrl_set(USB_CTRL_REG(base, reg), \
3294583a41SAl Cooper USB_CTRL_##reg##_##field##_MASK)
3394583a41SAl Cooper #define USB_CTRL_UNSET(base, reg, field) \
3494583a41SAl Cooper brcm_usb_ctrl_unset(USB_CTRL_REG(base, reg), \
3594583a41SAl Cooper USB_CTRL_##reg##_##field##_MASK)
3694583a41SAl Cooper
37*5095d045SJustin Chen #define USB_XHCI_GBL_REG(base, reg) ((void __iomem *)base + USB_XHCI_GBL_##reg)
38*5095d045SJustin Chen #define USB_XHCI_GBL_SET(base, reg, field) \
39*5095d045SJustin Chen brcm_usb_ctrl_set(USB_XHCI_GBL_REG(base, reg), \
40*5095d045SJustin Chen USB_XHCI_GBL_##reg##_##field##_MASK)
41*5095d045SJustin Chen #define USB_XHCI_GBL_UNSET(base, reg, field) \
42*5095d045SJustin Chen brcm_usb_ctrl_unset(USB_XHCI_GBL_REG(base, reg), \
43*5095d045SJustin Chen USB_XHCI_GBL_##reg##_##field##_MASK)
44*5095d045SJustin Chen
4594583a41SAl Cooper struct brcm_usb_init_params;
4694583a41SAl Cooper
4794583a41SAl Cooper struct brcm_usb_init_ops {
4894583a41SAl Cooper void (*init_ipp)(struct brcm_usb_init_params *params);
4994583a41SAl Cooper void (*init_common)(struct brcm_usb_init_params *params);
5094583a41SAl Cooper void (*init_eohci)(struct brcm_usb_init_params *params);
5194583a41SAl Cooper void (*init_xhci)(struct brcm_usb_init_params *params);
5294583a41SAl Cooper void (*uninit_common)(struct brcm_usb_init_params *params);
5394583a41SAl Cooper void (*uninit_eohci)(struct brcm_usb_init_params *params);
5494583a41SAl Cooper void (*uninit_xhci)(struct brcm_usb_init_params *params);
5594583a41SAl Cooper int (*get_dual_select)(struct brcm_usb_init_params *params);
5632fb07f3SJustin Chen void (*set_dual_select)(struct brcm_usb_init_params *params);
5794583a41SAl Cooper };
5894583a41SAl Cooper
5949859e55SAl Cooper struct brcm_usb_init_params {
609d5f51dcSAl Cooper void __iomem *regs[BRCM_REGS_MAX];
6149859e55SAl Cooper int ioc;
6249859e55SAl Cooper int ipp;
6332fb07f3SJustin Chen int supported_port_modes;
6432fb07f3SJustin Chen int port_mode;
6549859e55SAl Cooper u32 family_id;
6649859e55SAl Cooper u32 product_id;
6749859e55SAl Cooper int selected_family;
6849859e55SAl Cooper const char *family_name;
6949859e55SAl Cooper const u32 *usb_reg_bits_map;
7094583a41SAl Cooper const struct brcm_usb_init_ops *ops;
719d5f51dcSAl Cooper struct regmap *syscon_piarbctl;
72b0c0b66cSAl Cooper bool wake_enabled;
7349859e55SAl Cooper };
7449859e55SAl Cooper
7532942d33SRafał Miłecki void brcm_usb_dvr_init_4908(struct brcm_usb_init_params *params);
7694583a41SAl Cooper void brcm_usb_dvr_init_7445(struct brcm_usb_init_params *params);
774e5b9c9aSAl Cooper void brcm_usb_dvr_init_7216(struct brcm_usb_init_params *params);
789d5f51dcSAl Cooper void brcm_usb_dvr_init_7211b0(struct brcm_usb_init_params *params);
7949859e55SAl Cooper
brcm_usb_readl(void __iomem * addr)8094583a41SAl Cooper static inline u32 brcm_usb_readl(void __iomem *addr)
8194583a41SAl Cooper {
8294583a41SAl Cooper /*
8394583a41SAl Cooper * MIPS endianness is configured by boot strap, which also reverses all
8494583a41SAl Cooper * bus endianness (i.e., big-endian CPU + big endian bus ==> native
8594583a41SAl Cooper * endian I/O).
8694583a41SAl Cooper *
8794583a41SAl Cooper * Other architectures (e.g., ARM) either do not support big endian, or
8894583a41SAl Cooper * else leave I/O in little endian mode.
8994583a41SAl Cooper */
907c2fc792SChen Li if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
9194583a41SAl Cooper return __raw_readl(addr);
9294583a41SAl Cooper else
9394583a41SAl Cooper return readl_relaxed(addr);
9494583a41SAl Cooper }
9594583a41SAl Cooper
brcm_usb_writel(u32 val,void __iomem * addr)9694583a41SAl Cooper static inline void brcm_usb_writel(u32 val, void __iomem *addr)
9794583a41SAl Cooper {
9894583a41SAl Cooper /* See brcmnand_readl() comments */
997c2fc792SChen Li if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
10094583a41SAl Cooper __raw_writel(val, addr);
10194583a41SAl Cooper else
10294583a41SAl Cooper writel_relaxed(val, addr);
10394583a41SAl Cooper }
10494583a41SAl Cooper
brcm_usb_ctrl_unset(void __iomem * reg,u32 mask)10594583a41SAl Cooper static inline void brcm_usb_ctrl_unset(void __iomem *reg, u32 mask)
10694583a41SAl Cooper {
10794583a41SAl Cooper brcm_usb_writel(brcm_usb_readl(reg) & ~(mask), reg);
10894583a41SAl Cooper };
10994583a41SAl Cooper
brcm_usb_ctrl_set(void __iomem * reg,u32 mask)11094583a41SAl Cooper static inline void brcm_usb_ctrl_set(void __iomem *reg, u32 mask)
11194583a41SAl Cooper {
11294583a41SAl Cooper brcm_usb_writel(brcm_usb_readl(reg) | (mask), reg);
11394583a41SAl Cooper };
11494583a41SAl Cooper
brcm_usb_init_ipp(struct brcm_usb_init_params * ini)11594583a41SAl Cooper static inline void brcm_usb_init_ipp(struct brcm_usb_init_params *ini)
11694583a41SAl Cooper {
11794583a41SAl Cooper if (ini->ops->init_ipp)
11894583a41SAl Cooper ini->ops->init_ipp(ini);
11994583a41SAl Cooper }
12094583a41SAl Cooper
brcm_usb_init_common(struct brcm_usb_init_params * ini)12194583a41SAl Cooper static inline void brcm_usb_init_common(struct brcm_usb_init_params *ini)
12294583a41SAl Cooper {
12394583a41SAl Cooper if (ini->ops->init_common)
12494583a41SAl Cooper ini->ops->init_common(ini);
12594583a41SAl Cooper }
12694583a41SAl Cooper
brcm_usb_init_eohci(struct brcm_usb_init_params * ini)12794583a41SAl Cooper static inline void brcm_usb_init_eohci(struct brcm_usb_init_params *ini)
12894583a41SAl Cooper {
12994583a41SAl Cooper if (ini->ops->init_eohci)
13094583a41SAl Cooper ini->ops->init_eohci(ini);
13194583a41SAl Cooper }
13294583a41SAl Cooper
brcm_usb_init_xhci(struct brcm_usb_init_params * ini)13394583a41SAl Cooper static inline void brcm_usb_init_xhci(struct brcm_usb_init_params *ini)
13494583a41SAl Cooper {
13594583a41SAl Cooper if (ini->ops->init_xhci)
13694583a41SAl Cooper ini->ops->init_xhci(ini);
13794583a41SAl Cooper }
13894583a41SAl Cooper
brcm_usb_uninit_common(struct brcm_usb_init_params * ini)13994583a41SAl Cooper static inline void brcm_usb_uninit_common(struct brcm_usb_init_params *ini)
14094583a41SAl Cooper {
14194583a41SAl Cooper if (ini->ops->uninit_common)
14294583a41SAl Cooper ini->ops->uninit_common(ini);
14394583a41SAl Cooper }
14494583a41SAl Cooper
brcm_usb_uninit_eohci(struct brcm_usb_init_params * ini)14594583a41SAl Cooper static inline void brcm_usb_uninit_eohci(struct brcm_usb_init_params *ini)
14694583a41SAl Cooper {
14794583a41SAl Cooper if (ini->ops->uninit_eohci)
14894583a41SAl Cooper ini->ops->uninit_eohci(ini);
14994583a41SAl Cooper }
15094583a41SAl Cooper
brcm_usb_uninit_xhci(struct brcm_usb_init_params * ini)15194583a41SAl Cooper static inline void brcm_usb_uninit_xhci(struct brcm_usb_init_params *ini)
15294583a41SAl Cooper {
15394583a41SAl Cooper if (ini->ops->uninit_xhci)
15494583a41SAl Cooper ini->ops->uninit_xhci(ini);
15594583a41SAl Cooper }
15694583a41SAl Cooper
brcm_usb_get_dual_select(struct brcm_usb_init_params * ini)15794583a41SAl Cooper static inline int brcm_usb_get_dual_select(struct brcm_usb_init_params *ini)
15894583a41SAl Cooper {
15994583a41SAl Cooper if (ini->ops->get_dual_select)
16094583a41SAl Cooper return ini->ops->get_dual_select(ini);
16194583a41SAl Cooper return 0;
16294583a41SAl Cooper }
16394583a41SAl Cooper
brcm_usb_set_dual_select(struct brcm_usb_init_params * ini)16432fb07f3SJustin Chen static inline void brcm_usb_set_dual_select(struct brcm_usb_init_params *ini)
16594583a41SAl Cooper {
16694583a41SAl Cooper if (ini->ops->set_dual_select)
16732fb07f3SJustin Chen ini->ops->set_dual_select(ini);
16894583a41SAl Cooper }
16949859e55SAl Cooper
17049859e55SAl Cooper #endif /* _USB_BRCM_COMMON_INIT_H */
171