162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * Copyright (c) 2021, MediaTek Inc. 462306a36Sopenharmony_ci * Copyright (c) 2021-2022, Intel Corporation. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Authors: 762306a36Sopenharmony_ci * Haijun Liu <haijun.liu@mediatek.com> 862306a36Sopenharmony_ci * Ricardo Martinez <ricardo.martinez@linux.intel.com> 962306a36Sopenharmony_ci * Sreehari Kancharla <sreehari.kancharla@intel.com> 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * Contributors: 1262306a36Sopenharmony_ci * Amir Hanania <amir.hanania@intel.com> 1362306a36Sopenharmony_ci * Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com> 1462306a36Sopenharmony_ci * Moises Veleta <moises.veleta@intel.com> 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#ifndef __T7XX_PCI_H__ 1862306a36Sopenharmony_ci#define __T7XX_PCI_H__ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#include <linux/completion.h> 2162306a36Sopenharmony_ci#include <linux/irqreturn.h> 2262306a36Sopenharmony_ci#include <linux/mutex.h> 2362306a36Sopenharmony_ci#include <linux/pci.h> 2462306a36Sopenharmony_ci#include <linux/spinlock.h> 2562306a36Sopenharmony_ci#include <linux/types.h> 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#include "t7xx_reg.h" 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* struct t7xx_addr_base - holds base addresses 3062306a36Sopenharmony_ci * @pcie_mac_ireg_base: PCIe MAC register base 3162306a36Sopenharmony_ci * @pcie_ext_reg_base: used to calculate base addresses for CLDMA, DPMA and MHCCIF registers 3262306a36Sopenharmony_ci * @pcie_dev_reg_trsl_addr: used to calculate the register base address 3362306a36Sopenharmony_ci * @infracfg_ao_base: base address used in CLDMA reset operations 3462306a36Sopenharmony_ci * @mhccif_rc_base: host view of MHCCIF rc base addr 3562306a36Sopenharmony_ci */ 3662306a36Sopenharmony_cistruct t7xx_addr_base { 3762306a36Sopenharmony_ci void __iomem *pcie_mac_ireg_base; 3862306a36Sopenharmony_ci void __iomem *pcie_ext_reg_base; 3962306a36Sopenharmony_ci u32 pcie_dev_reg_trsl_addr; 4062306a36Sopenharmony_ci void __iomem *infracfg_ao_base; 4162306a36Sopenharmony_ci void __iomem *mhccif_rc_base; 4262306a36Sopenharmony_ci}; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_citypedef irqreturn_t (*t7xx_intr_callback)(int irq, void *param); 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/* struct t7xx_pci_dev - MTK device context structure 4762306a36Sopenharmony_ci * @intr_handler: array of handler function for request_threaded_irq 4862306a36Sopenharmony_ci * @intr_thread: array of thread_fn for request_threaded_irq 4962306a36Sopenharmony_ci * @callback_param: array of cookie passed back to interrupt functions 5062306a36Sopenharmony_ci * @pdev: PCI device 5162306a36Sopenharmony_ci * @base_addr: memory base addresses of HW components 5262306a36Sopenharmony_ci * @md: modem interface 5362306a36Sopenharmony_ci * @ccmni_ctlb: context structure used to control the network data path 5462306a36Sopenharmony_ci * @rgu_pci_irq_en: RGU callback ISR registered and active 5562306a36Sopenharmony_ci * @md_pm_entities: list of pm entities 5662306a36Sopenharmony_ci * @md_pm_entity_mtx: protects md_pm_entities list 5762306a36Sopenharmony_ci * @pm_sr_ack: ack from the device when went to sleep or woke up 5862306a36Sopenharmony_ci * @md_pm_state: state for resume/suspend 5962306a36Sopenharmony_ci * @md_pm_lock: protects PCIe sleep lock 6062306a36Sopenharmony_ci * @sleep_disable_count: PCIe L1.2 lock counter 6162306a36Sopenharmony_ci * @sleep_lock_acquire: indicates that sleep has been disabled 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_cistruct t7xx_pci_dev { 6462306a36Sopenharmony_ci t7xx_intr_callback intr_handler[EXT_INT_NUM]; 6562306a36Sopenharmony_ci t7xx_intr_callback intr_thread[EXT_INT_NUM]; 6662306a36Sopenharmony_ci void *callback_param[EXT_INT_NUM]; 6762306a36Sopenharmony_ci struct pci_dev *pdev; 6862306a36Sopenharmony_ci struct t7xx_addr_base base_addr; 6962306a36Sopenharmony_ci struct t7xx_modem *md; 7062306a36Sopenharmony_ci struct t7xx_ccmni_ctrl *ccmni_ctlb; 7162306a36Sopenharmony_ci bool rgu_pci_irq_en; 7262306a36Sopenharmony_ci struct completion init_done; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci /* Low Power Items */ 7562306a36Sopenharmony_ci struct list_head md_pm_entities; 7662306a36Sopenharmony_ci struct mutex md_pm_entity_mtx; /* Protects MD PM entities list */ 7762306a36Sopenharmony_ci struct completion pm_sr_ack; 7862306a36Sopenharmony_ci atomic_t md_pm_state; 7962306a36Sopenharmony_ci spinlock_t md_pm_lock; /* Protects PCI resource lock */ 8062306a36Sopenharmony_ci unsigned int sleep_disable_count; 8162306a36Sopenharmony_ci struct completion sleep_lock_acquire; 8262306a36Sopenharmony_ci#ifdef CONFIG_WWAN_DEBUGFS 8362306a36Sopenharmony_ci struct dentry *debugfs_dir; 8462306a36Sopenharmony_ci#endif 8562306a36Sopenharmony_ci}; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_cienum t7xx_pm_id { 8862306a36Sopenharmony_ci PM_ENTITY_ID_CTRL1, 8962306a36Sopenharmony_ci PM_ENTITY_ID_CTRL2, 9062306a36Sopenharmony_ci PM_ENTITY_ID_DATA, 9162306a36Sopenharmony_ci PM_ENTITY_ID_INVALID 9262306a36Sopenharmony_ci}; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* struct md_pm_entity - device power management entity 9562306a36Sopenharmony_ci * @entity: list of PM Entities 9662306a36Sopenharmony_ci * @suspend: callback invoked before sending D3 request to device 9762306a36Sopenharmony_ci * @suspend_late: callback invoked after getting D3 ACK from device 9862306a36Sopenharmony_ci * @resume_early: callback invoked before sending the resume request to device 9962306a36Sopenharmony_ci * @resume: callback invoked after getting resume ACK from device 10062306a36Sopenharmony_ci * @id: unique PM entity identifier 10162306a36Sopenharmony_ci * @entity_param: parameter passed to the registered callbacks 10262306a36Sopenharmony_ci * 10362306a36Sopenharmony_ci * This structure is used to indicate PM operations required by internal 10462306a36Sopenharmony_ci * HW modules such as CLDMA and DPMA. 10562306a36Sopenharmony_ci */ 10662306a36Sopenharmony_cistruct md_pm_entity { 10762306a36Sopenharmony_ci struct list_head entity; 10862306a36Sopenharmony_ci int (*suspend)(struct t7xx_pci_dev *t7xx_dev, void *entity_param); 10962306a36Sopenharmony_ci void (*suspend_late)(struct t7xx_pci_dev *t7xx_dev, void *entity_param); 11062306a36Sopenharmony_ci void (*resume_early)(struct t7xx_pci_dev *t7xx_dev, void *entity_param); 11162306a36Sopenharmony_ci int (*resume)(struct t7xx_pci_dev *t7xx_dev, void *entity_param); 11262306a36Sopenharmony_ci enum t7xx_pm_id id; 11362306a36Sopenharmony_ci void *entity_param; 11462306a36Sopenharmony_ci}; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_civoid t7xx_pci_disable_sleep(struct t7xx_pci_dev *t7xx_dev); 11762306a36Sopenharmony_civoid t7xx_pci_enable_sleep(struct t7xx_pci_dev *t7xx_dev); 11862306a36Sopenharmony_ciint t7xx_pci_sleep_disable_complete(struct t7xx_pci_dev *t7xx_dev); 11962306a36Sopenharmony_ciint t7xx_pci_pm_entity_register(struct t7xx_pci_dev *t7xx_dev, struct md_pm_entity *pm_entity); 12062306a36Sopenharmony_ciint t7xx_pci_pm_entity_unregister(struct t7xx_pci_dev *t7xx_dev, struct md_pm_entity *pm_entity); 12162306a36Sopenharmony_civoid t7xx_pci_pm_init_late(struct t7xx_pci_dev *t7xx_dev); 12262306a36Sopenharmony_civoid t7xx_pci_pm_exp_detected(struct t7xx_pci_dev *t7xx_dev); 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#endif /* __T7XX_PCI_H__ */ 125