xref: /openbmc/linux/drivers/phy/broadcom/phy-brcm-usb-init.h (revision 4e5b9c9a73b32d28759225a40d30848393a8f1fd)
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 
949859e55SAl Cooper #define USB_CTLR_MODE_HOST 0
1049859e55SAl Cooper #define USB_CTLR_MODE_DEVICE 1
1149859e55SAl Cooper #define USB_CTLR_MODE_DRD 2
1249859e55SAl Cooper #define USB_CTLR_MODE_TYPEC_PD 3
1349859e55SAl Cooper 
1449859e55SAl Cooper struct  brcm_usb_init_params;
1549859e55SAl Cooper 
1694583a41SAl Cooper #define USB_CTRL_REG(base, reg)	((void __iomem *)base + USB_CTRL_##reg)
1794583a41SAl Cooper #define USB_XHCI_EC_REG(base, reg) ((void __iomem *)base + USB_XHCI_EC_##reg)
1894583a41SAl Cooper #define USB_CTRL_MASK(reg, field) \
1994583a41SAl Cooper 	USB_CTRL_##reg##_##field##_MASK
2094583a41SAl Cooper #define USB_CTRL_SET(base, reg, field)	\
2194583a41SAl Cooper 	brcm_usb_ctrl_set(USB_CTRL_REG(base, reg),	\
2294583a41SAl Cooper 			  USB_CTRL_##reg##_##field##_MASK)
2394583a41SAl Cooper #define USB_CTRL_UNSET(base, reg, field)	\
2494583a41SAl Cooper 	brcm_usb_ctrl_unset(USB_CTRL_REG(base, reg),		\
2594583a41SAl Cooper 			    USB_CTRL_##reg##_##field##_MASK)
2694583a41SAl Cooper 
2794583a41SAl Cooper struct  brcm_usb_init_params;
2894583a41SAl Cooper 
2994583a41SAl Cooper struct brcm_usb_init_ops {
3094583a41SAl Cooper 	void (*init_ipp)(struct brcm_usb_init_params *params);
3194583a41SAl Cooper 	void (*init_common)(struct brcm_usb_init_params *params);
3294583a41SAl Cooper 	void (*init_eohci)(struct brcm_usb_init_params *params);
3394583a41SAl Cooper 	void (*init_xhci)(struct brcm_usb_init_params *params);
3494583a41SAl Cooper 	void (*uninit_common)(struct brcm_usb_init_params *params);
3594583a41SAl Cooper 	void (*uninit_eohci)(struct brcm_usb_init_params *params);
3694583a41SAl Cooper 	void (*uninit_xhci)(struct brcm_usb_init_params *params);
3794583a41SAl Cooper 	int  (*get_dual_select)(struct brcm_usb_init_params *params);
3894583a41SAl Cooper 	void (*set_dual_select)(struct brcm_usb_init_params *params, int mode);
3994583a41SAl Cooper 	void (*wake_enable)(struct brcm_usb_init_params *params,
4094583a41SAl Cooper 			    int enable);
4194583a41SAl Cooper };
4294583a41SAl Cooper 
4349859e55SAl Cooper struct  brcm_usb_init_params {
4449859e55SAl Cooper 	void __iomem *ctrl_regs;
4549859e55SAl Cooper 	void __iomem *xhci_ec_regs;
46*4e5b9c9aSAl Cooper 	void __iomem *xhci_gbl_regs;
4749859e55SAl Cooper 	int ioc;
4849859e55SAl Cooper 	int ipp;
4949859e55SAl Cooper 	int mode;
5049859e55SAl Cooper 	u32 family_id;
5149859e55SAl Cooper 	u32 product_id;
5249859e55SAl Cooper 	int selected_family;
5349859e55SAl Cooper 	const char *family_name;
5449859e55SAl Cooper 	const u32 *usb_reg_bits_map;
5594583a41SAl Cooper 	const struct brcm_usb_init_ops *ops;
5649859e55SAl Cooper };
5749859e55SAl Cooper 
5894583a41SAl Cooper void brcm_usb_dvr_init_7445(struct brcm_usb_init_params *params);
59*4e5b9c9aSAl Cooper void brcm_usb_dvr_init_7216(struct brcm_usb_init_params *params);
6049859e55SAl Cooper 
6194583a41SAl Cooper static inline u32 brcm_usb_readl(void __iomem *addr)
6294583a41SAl Cooper {
6394583a41SAl Cooper 	/*
6494583a41SAl Cooper 	 * MIPS endianness is configured by boot strap, which also reverses all
6594583a41SAl Cooper 	 * bus endianness (i.e., big-endian CPU + big endian bus ==> native
6694583a41SAl Cooper 	 * endian I/O).
6794583a41SAl Cooper 	 *
6894583a41SAl Cooper 	 * Other architectures (e.g., ARM) either do not support big endian, or
6994583a41SAl Cooper 	 * else leave I/O in little endian mode.
7094583a41SAl Cooper 	 */
7194583a41SAl Cooper 	if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
7294583a41SAl Cooper 		return __raw_readl(addr);
7394583a41SAl Cooper 	else
7494583a41SAl Cooper 		return readl_relaxed(addr);
7594583a41SAl Cooper }
7694583a41SAl Cooper 
7794583a41SAl Cooper static inline void brcm_usb_writel(u32 val, void __iomem *addr)
7894583a41SAl Cooper {
7994583a41SAl Cooper 	/* See brcmnand_readl() comments */
8094583a41SAl Cooper 	if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
8194583a41SAl Cooper 		__raw_writel(val, addr);
8294583a41SAl Cooper 	else
8394583a41SAl Cooper 		writel_relaxed(val, addr);
8494583a41SAl Cooper }
8594583a41SAl Cooper 
8694583a41SAl Cooper static inline void brcm_usb_ctrl_unset(void __iomem *reg, u32 mask)
8794583a41SAl Cooper {
8894583a41SAl Cooper 	brcm_usb_writel(brcm_usb_readl(reg) & ~(mask), reg);
8994583a41SAl Cooper };
9094583a41SAl Cooper 
9194583a41SAl Cooper static inline void brcm_usb_ctrl_set(void __iomem *reg, u32 mask)
9294583a41SAl Cooper {
9394583a41SAl Cooper 	brcm_usb_writel(brcm_usb_readl(reg) | (mask), reg);
9494583a41SAl Cooper };
9594583a41SAl Cooper 
9694583a41SAl Cooper static inline void brcm_usb_init_ipp(struct brcm_usb_init_params *ini)
9794583a41SAl Cooper {
9894583a41SAl Cooper 	if (ini->ops->init_ipp)
9994583a41SAl Cooper 		ini->ops->init_ipp(ini);
10094583a41SAl Cooper }
10194583a41SAl Cooper 
10294583a41SAl Cooper static inline void brcm_usb_init_common(struct brcm_usb_init_params *ini)
10394583a41SAl Cooper {
10494583a41SAl Cooper 	if (ini->ops->init_common)
10594583a41SAl Cooper 		ini->ops->init_common(ini);
10694583a41SAl Cooper }
10794583a41SAl Cooper 
10894583a41SAl Cooper static inline void brcm_usb_init_eohci(struct brcm_usb_init_params *ini)
10994583a41SAl Cooper {
11094583a41SAl Cooper 	if (ini->ops->init_eohci)
11194583a41SAl Cooper 		ini->ops->init_eohci(ini);
11294583a41SAl Cooper }
11394583a41SAl Cooper 
11494583a41SAl Cooper static inline void brcm_usb_init_xhci(struct brcm_usb_init_params *ini)
11594583a41SAl Cooper {
11694583a41SAl Cooper 	if (ini->ops->init_xhci)
11794583a41SAl Cooper 		ini->ops->init_xhci(ini);
11894583a41SAl Cooper }
11994583a41SAl Cooper 
12094583a41SAl Cooper static inline void brcm_usb_uninit_common(struct brcm_usb_init_params *ini)
12194583a41SAl Cooper {
12294583a41SAl Cooper 	if (ini->ops->uninit_common)
12394583a41SAl Cooper 		ini->ops->uninit_common(ini);
12494583a41SAl Cooper }
12594583a41SAl Cooper 
12694583a41SAl Cooper static inline void brcm_usb_uninit_eohci(struct brcm_usb_init_params *ini)
12794583a41SAl Cooper {
12894583a41SAl Cooper 	if (ini->ops->uninit_eohci)
12994583a41SAl Cooper 		ini->ops->uninit_eohci(ini);
13094583a41SAl Cooper }
13194583a41SAl Cooper 
13294583a41SAl Cooper static inline void brcm_usb_uninit_xhci(struct brcm_usb_init_params *ini)
13394583a41SAl Cooper {
13494583a41SAl Cooper 	if (ini->ops->uninit_xhci)
13594583a41SAl Cooper 		ini->ops->uninit_xhci(ini);
13694583a41SAl Cooper }
13794583a41SAl Cooper 
13894583a41SAl Cooper static inline void brcm_usb_wake_enable(struct brcm_usb_init_params *ini,
13994583a41SAl Cooper 	int enable)
14094583a41SAl Cooper {
14194583a41SAl Cooper 	if (ini->ops->wake_enable)
14294583a41SAl Cooper 		ini->ops->wake_enable(ini, enable);
14394583a41SAl Cooper }
14494583a41SAl Cooper 
14594583a41SAl Cooper static inline int brcm_usb_get_dual_select(struct brcm_usb_init_params *ini)
14694583a41SAl Cooper {
14794583a41SAl Cooper 	if (ini->ops->get_dual_select)
14894583a41SAl Cooper 		return ini->ops->get_dual_select(ini);
14994583a41SAl Cooper 	return 0;
15094583a41SAl Cooper }
15194583a41SAl Cooper 
15294583a41SAl Cooper static inline void brcm_usb_set_dual_select(struct brcm_usb_init_params *ini,
15394583a41SAl Cooper 	int mode)
15494583a41SAl Cooper {
15594583a41SAl Cooper 	if (ini->ops->set_dual_select)
15694583a41SAl Cooper 		ini->ops->set_dual_select(ini, mode);
15794583a41SAl Cooper }
15849859e55SAl Cooper 
15949859e55SAl Cooper #endif /* _USB_BRCM_COMMON_INIT_H */
160