162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause-Clear */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
462306a36Sopenharmony_ci * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef ATH12K_PCI_H
762306a36Sopenharmony_ci#define ATH12K_PCI_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/mhi.h>
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "core.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#define PCIE_SOC_GLOBAL_RESET			0x3008
1462306a36Sopenharmony_ci#define PCIE_SOC_GLOBAL_RESET_V			1
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#define WLAON_WARM_SW_ENTRY			0x1f80504
1762306a36Sopenharmony_ci#define WLAON_SOC_RESET_CAUSE_REG		0x01f8060c
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define PCIE_Q6_COOKIE_ADDR			0x01f80500
2062306a36Sopenharmony_ci#define PCIE_Q6_COOKIE_DATA			0xc0000000
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/* register to wake the UMAC from power collapse */
2362306a36Sopenharmony_ci#define PCIE_SCRATCH_0_SOC_PCIE_REG		0x4040
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* register used for handshake mechanism to validate UMAC is awake */
2662306a36Sopenharmony_ci#define PCIE_SOC_WAKE_PCIE_LOCAL_REG		0x3004
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define PCIE_PCIE_PARF_LTSSM			0x1e081b0
2962306a36Sopenharmony_ci#define PARM_LTSSM_VALUE			0x111
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define GCC_GCC_PCIE_HOT_RST			0x1e38338
3262306a36Sopenharmony_ci#define GCC_GCC_PCIE_HOT_RST_VAL		0x10
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define PCIE_PCIE_INT_ALL_CLEAR			0x1e08228
3562306a36Sopenharmony_ci#define PCIE_SMLH_REQ_RST_LINK_DOWN		0x2
3662306a36Sopenharmony_ci#define PCIE_INT_CLEAR_ALL			0xffffffff
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define PCIE_QSERDES_COM_SYSCLK_EN_SEL_REG(ab) \
3962306a36Sopenharmony_ci	((ab)->hw_params->regs->pcie_qserdes_sysclk_en_sel)
4062306a36Sopenharmony_ci#define PCIE_QSERDES_COM_SYSCLK_EN_SEL_VAL	0x10
4162306a36Sopenharmony_ci#define PCIE_QSERDES_COM_SYSCLK_EN_SEL_MSK	0xffffffff
4262306a36Sopenharmony_ci#define PCIE_PCS_OSC_DTCT_CONFIG1_REG(ab) \
4362306a36Sopenharmony_ci	((ab)->hw_params->regs->pcie_pcs_osc_dtct_config_base)
4462306a36Sopenharmony_ci#define PCIE_PCS_OSC_DTCT_CONFIG1_VAL		0x02
4562306a36Sopenharmony_ci#define PCIE_PCS_OSC_DTCT_CONFIG2_REG(ab) \
4662306a36Sopenharmony_ci	((ab)->hw_params->regs->pcie_pcs_osc_dtct_config_base + 0x4)
4762306a36Sopenharmony_ci#define PCIE_PCS_OSC_DTCT_CONFIG2_VAL		0x52
4862306a36Sopenharmony_ci#define PCIE_PCS_OSC_DTCT_CONFIG4_REG(ab) \
4962306a36Sopenharmony_ci	((ab)->hw_params->regs->pcie_pcs_osc_dtct_config_base + 0xc)
5062306a36Sopenharmony_ci#define PCIE_PCS_OSC_DTCT_CONFIG4_VAL		0xff
5162306a36Sopenharmony_ci#define PCIE_PCS_OSC_DTCT_CONFIG_MSK		0x000000ff
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#define WLAON_QFPROM_PWR_CTRL_REG		0x01f8031c
5462306a36Sopenharmony_ci#define QFPROM_PWR_CTRL_VDD4BLOW_MASK		0x4
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define PCI_BAR_WINDOW0_BASE	0x1E00000
5762306a36Sopenharmony_ci#define PCI_BAR_WINDOW0_END	0x1E7FFFC
5862306a36Sopenharmony_ci#define PCI_SOC_RANGE_MASK	0x3FFF
5962306a36Sopenharmony_ci#define PCI_SOC_PCI_REG_BASE	0x1E04000
6062306a36Sopenharmony_ci#define PCI_SOC_PCI_REG_END	0x1E07FFC
6162306a36Sopenharmony_ci#define PCI_PARF_BASE		0x1E08000
6262306a36Sopenharmony_ci#define PCI_PARF_END		0x1E0BFFC
6362306a36Sopenharmony_ci#define PCI_MHIREGLEN_REG	0x1E0E100
6462306a36Sopenharmony_ci#define PCI_MHI_REGION_END	0x1E0EFFC
6562306a36Sopenharmony_ci#define QRTR_PCI_DOMAIN_NR_MASK		GENMASK(7, 4)
6662306a36Sopenharmony_ci#define QRTR_PCI_BUS_NUMBER_MASK	GENMASK(3, 0)
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define ATH12K_PCI_SOC_HW_VERSION_1	1
6962306a36Sopenharmony_ci#define ATH12K_PCI_SOC_HW_VERSION_2	2
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_cistruct ath12k_msi_user {
7262306a36Sopenharmony_ci	const char *name;
7362306a36Sopenharmony_ci	int num_vectors;
7462306a36Sopenharmony_ci	u32 base_vector;
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistruct ath12k_msi_config {
7862306a36Sopenharmony_ci	int total_vectors;
7962306a36Sopenharmony_ci	int total_users;
8062306a36Sopenharmony_ci	const struct ath12k_msi_user *users;
8162306a36Sopenharmony_ci};
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_cienum ath12k_pci_flags {
8462306a36Sopenharmony_ci	ATH12K_PCI_FLAG_INIT_DONE,
8562306a36Sopenharmony_ci	ATH12K_PCI_FLAG_IS_MSI_64,
8662306a36Sopenharmony_ci	ATH12K_PCI_ASPM_RESTORE,
8762306a36Sopenharmony_ci};
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistruct ath12k_pci_ops {
9062306a36Sopenharmony_ci	int (*wakeup)(struct ath12k_base *ab);
9162306a36Sopenharmony_ci	void (*release)(struct ath12k_base *ab);
9262306a36Sopenharmony_ci};
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_cistruct ath12k_pci {
9562306a36Sopenharmony_ci	struct pci_dev *pdev;
9662306a36Sopenharmony_ci	struct ath12k_base *ab;
9762306a36Sopenharmony_ci	u16 dev_id;
9862306a36Sopenharmony_ci	char amss_path[100];
9962306a36Sopenharmony_ci	u32 msi_ep_base_data;
10062306a36Sopenharmony_ci	struct mhi_controller *mhi_ctrl;
10162306a36Sopenharmony_ci	const struct ath12k_msi_config *msi_config;
10262306a36Sopenharmony_ci	unsigned long mhi_state;
10362306a36Sopenharmony_ci	u32 register_window;
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	/* protects register_window above */
10662306a36Sopenharmony_ci	spinlock_t window_lock;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	/* enum ath12k_pci_flags */
10962306a36Sopenharmony_ci	unsigned long flags;
11062306a36Sopenharmony_ci	u16 link_ctl;
11162306a36Sopenharmony_ci	const struct ath12k_pci_ops *pci_ops;
11262306a36Sopenharmony_ci};
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_cistatic inline struct ath12k_pci *ath12k_pci_priv(struct ath12k_base *ab)
11562306a36Sopenharmony_ci{
11662306a36Sopenharmony_ci	return (struct ath12k_pci *)ab->drv_priv;
11762306a36Sopenharmony_ci}
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ciint ath12k_pci_get_user_msi_assignment(struct ath12k_base *ab, char *user_name,
12062306a36Sopenharmony_ci				       int *num_vectors, u32 *user_base_data,
12162306a36Sopenharmony_ci				       u32 *base_vector);
12262306a36Sopenharmony_ciint ath12k_pci_get_msi_irq(struct device *dev, unsigned int vector);
12362306a36Sopenharmony_civoid ath12k_pci_write32(struct ath12k_base *ab, u32 offset, u32 value);
12462306a36Sopenharmony_ciu32 ath12k_pci_read32(struct ath12k_base *ab, u32 offset);
12562306a36Sopenharmony_ciint ath12k_pci_map_service_to_pipe(struct ath12k_base *ab, u16 service_id,
12662306a36Sopenharmony_ci				   u8 *ul_pipe, u8 *dl_pipe);
12762306a36Sopenharmony_civoid ath12k_pci_get_msi_address(struct ath12k_base *ab, u32 *msi_addr_lo,
12862306a36Sopenharmony_ci				u32 *msi_addr_hi);
12962306a36Sopenharmony_civoid ath12k_pci_get_ce_msi_idx(struct ath12k_base *ab, u32 ce_id,
13062306a36Sopenharmony_ci			       u32 *msi_idx);
13162306a36Sopenharmony_civoid ath12k_pci_hif_ce_irq_enable(struct ath12k_base *ab);
13262306a36Sopenharmony_civoid ath12k_pci_hif_ce_irq_disable(struct ath12k_base *ab);
13362306a36Sopenharmony_civoid ath12k_pci_ext_irq_enable(struct ath12k_base *ab);
13462306a36Sopenharmony_civoid ath12k_pci_ext_irq_disable(struct ath12k_base *ab);
13562306a36Sopenharmony_ciint ath12k_pci_hif_suspend(struct ath12k_base *ab);
13662306a36Sopenharmony_ciint ath12k_pci_hif_resume(struct ath12k_base *ab);
13762306a36Sopenharmony_civoid ath12k_pci_stop(struct ath12k_base *ab);
13862306a36Sopenharmony_ciint ath12k_pci_start(struct ath12k_base *ab);
13962306a36Sopenharmony_ciint ath12k_pci_power_up(struct ath12k_base *ab);
14062306a36Sopenharmony_civoid ath12k_pci_power_down(struct ath12k_base *ab);
14162306a36Sopenharmony_ci#endif /* ATH12K_PCI_H */
142