162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __SDHCI_PCI_H
362306a36Sopenharmony_ci#define __SDHCI_PCI_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci * PCI device IDs, sub IDs
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_SDS0		0x8420
1062306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_SDS1		0x8421
1162306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_FUJIN2		0x8520
1262306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_SEABIRD0	0x8620
1362306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_SEABIRD1	0x8621
1462306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_GG8_9860	0x9860
1562306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_GG8_9861	0x9861
1662306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_GG8_9862	0x9862
1762306a36Sopenharmony_ci#define PCI_DEVICE_ID_O2_GG8_9863	0x9863
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_PCH_SDIO0	0x8809
2062306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_PCH_SDIO1	0x880a
2162306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BYT_EMMC	0x0f14
2262306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BYT_SDIO	0x0f15
2362306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BYT_SD	0x0f16
2462306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BYT_EMMC2	0x0f50
2562306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BSW_EMMC	0x2294
2662306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BSW_SDIO	0x2295
2762306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BSW_SD	0x2296
2862306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_MRFLD_MMC	0x1190
2962306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CLV_SDIO0	0x08f9
3062306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CLV_SDIO1	0x08fa
3162306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CLV_SDIO2	0x08fb
3262306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CLV_EMMC0	0x08e5
3362306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CLV_EMMC1	0x08e6
3462306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_QRK_SD	0x08A7
3562306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_SPT_EMMC	0x9d2b
3662306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_SPT_SDIO	0x9d2c
3762306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_SPT_SD	0x9d2d
3862306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_DNV_EMMC	0x19db
3962306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CDF_EMMC	0x18db
4062306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BXT_SD	0x0aca
4162306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BXT_EMMC	0x0acc
4262306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BXT_SDIO	0x0ad0
4362306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BXTM_SD	0x1aca
4462306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BXTM_EMMC	0x1acc
4562306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_BXTM_SDIO	0x1ad0
4662306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_APL_SD	0x5aca
4762306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_APL_EMMC	0x5acc
4862306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_APL_SDIO	0x5ad0
4962306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_GLK_SD	0x31ca
5062306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_GLK_EMMC	0x31cc
5162306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_GLK_SDIO	0x31d0
5262306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CNP_EMMC	0x9dc4
5362306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CNP_SD	0x9df5
5462306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CNPH_SD	0xa375
5562306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_ICP_EMMC	0x34c4
5662306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_ICP_SD	0x34f8
5762306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_EHL_EMMC	0x4b47
5862306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_EHL_SD	0x4b48
5962306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CML_EMMC	0x02c4
6062306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CML_SD	0x02f5
6162306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_CMLH_SD	0x06f5
6262306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_JSL_EMMC	0x4dc4
6362306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_JSL_SD	0x4df8
6462306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_LKF_EMMC	0x98c4
6562306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_LKF_SD	0x98f8
6662306a36Sopenharmony_ci#define PCI_DEVICE_ID_INTEL_ADL_EMMC	0x54c4
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define PCI_DEVICE_ID_SYSKONNECT_8000	0x8000
6962306a36Sopenharmony_ci#define PCI_DEVICE_ID_VIA_95D0		0x95d0
7062306a36Sopenharmony_ci#define PCI_DEVICE_ID_REALTEK_5250	0x5250
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_NI_7884	0x7884
7362306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_NI_78E3	0x78e3
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define PCI_VENDOR_ID_ARASAN		0x16e6
7662306a36Sopenharmony_ci#define PCI_DEVICE_ID_ARASAN_PHY_EMMC	0x0670
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define PCI_DEVICE_ID_SYNOPSYS_DWC_MSHC 0xc202
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define PCI_DEVICE_ID_GLI_9755		0x9755
8162306a36Sopenharmony_ci#define PCI_DEVICE_ID_GLI_9750		0x9750
8262306a36Sopenharmony_ci#define PCI_DEVICE_ID_GLI_9763E		0xe763
8362306a36Sopenharmony_ci#define PCI_DEVICE_ID_GLI_9767		0x9767
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/*
8662306a36Sopenharmony_ci * PCI device class and mask
8762306a36Sopenharmony_ci */
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define SYSTEM_SDHCI			(PCI_CLASS_SYSTEM_SDHCI << 8)
9062306a36Sopenharmony_ci#define PCI_CLASS_MASK			0xFFFF00
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/*
9362306a36Sopenharmony_ci * Macros for PCI device-description
9462306a36Sopenharmony_ci */
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define _PCI_VEND(vend) PCI_VENDOR_ID_##vend
9762306a36Sopenharmony_ci#define _PCI_DEV(vend, dev) PCI_DEVICE_ID_##vend##_##dev
9862306a36Sopenharmony_ci#define _PCI_SUBDEV(subvend, subdev) PCI_SUBDEVICE_ID_##subvend##_##subdev
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci#define SDHCI_PCI_DEVICE(vend, dev, cfg) { \
10162306a36Sopenharmony_ci	.vendor = _PCI_VEND(vend), .device = _PCI_DEV(vend, dev), \
10262306a36Sopenharmony_ci	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
10362306a36Sopenharmony_ci	.driver_data = (kernel_ulong_t)&(sdhci_##cfg) \
10462306a36Sopenharmony_ci}
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci#define SDHCI_PCI_SUBDEVICE(vend, dev, subvend, subdev, cfg) { \
10762306a36Sopenharmony_ci	.vendor = _PCI_VEND(vend), .device = _PCI_DEV(vend, dev), \
10862306a36Sopenharmony_ci	.subvendor = _PCI_VEND(subvend), \
10962306a36Sopenharmony_ci	.subdevice = _PCI_SUBDEV(subvend, subdev), \
11062306a36Sopenharmony_ci	.driver_data = (kernel_ulong_t)&(sdhci_##cfg) \
11162306a36Sopenharmony_ci}
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci#define SDHCI_PCI_DEVICE_CLASS(vend, cl, cl_msk, cfg) { \
11462306a36Sopenharmony_ci	.vendor = _PCI_VEND(vend), .device = PCI_ANY_ID, \
11562306a36Sopenharmony_ci	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, \
11662306a36Sopenharmony_ci	.class = (cl), .class_mask = (cl_msk), \
11762306a36Sopenharmony_ci	.driver_data = (kernel_ulong_t)&(sdhci_##cfg) \
11862306a36Sopenharmony_ci}
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci/*
12162306a36Sopenharmony_ci * PCI registers
12262306a36Sopenharmony_ci */
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#define PCI_SDHCI_IFPIO			0x00
12562306a36Sopenharmony_ci#define PCI_SDHCI_IFDMA			0x01
12662306a36Sopenharmony_ci#define PCI_SDHCI_IFVENDOR		0x02
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci#define PCI_SLOT_INFO			0x40	/* 8 bits */
12962306a36Sopenharmony_ci#define  PCI_SLOT_INFO_SLOTS(x)		((x >> 4) & 7)
13062306a36Sopenharmony_ci#define  PCI_SLOT_INFO_FIRST_BAR_MASK	0x07
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#define MAX_SLOTS			8
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_cistruct sdhci_pci_chip;
13562306a36Sopenharmony_cistruct sdhci_pci_slot;
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistruct sdhci_pci_fixes {
13862306a36Sopenharmony_ci	unsigned int		quirks;
13962306a36Sopenharmony_ci	unsigned int		quirks2;
14062306a36Sopenharmony_ci	bool			allow_runtime_pm;
14162306a36Sopenharmony_ci	bool			own_cd_for_runtime_pm;
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci	int			(*probe) (struct sdhci_pci_chip *);
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci	int			(*probe_slot) (struct sdhci_pci_slot *);
14662306a36Sopenharmony_ci	int			(*add_host) (struct sdhci_pci_slot *);
14762306a36Sopenharmony_ci	void			(*remove_slot) (struct sdhci_pci_slot *, int);
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
15062306a36Sopenharmony_ci	int			(*suspend) (struct sdhci_pci_chip *);
15162306a36Sopenharmony_ci	int			(*resume) (struct sdhci_pci_chip *);
15262306a36Sopenharmony_ci#endif
15362306a36Sopenharmony_ci#ifdef CONFIG_PM
15462306a36Sopenharmony_ci	int			(*runtime_suspend) (struct sdhci_pci_chip *);
15562306a36Sopenharmony_ci	int			(*runtime_resume) (struct sdhci_pci_chip *);
15662306a36Sopenharmony_ci#endif
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci	const struct sdhci_ops	*ops;
15962306a36Sopenharmony_ci	size_t			priv_size;
16062306a36Sopenharmony_ci};
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_cistruct sdhci_pci_slot {
16362306a36Sopenharmony_ci	struct sdhci_pci_chip	*chip;
16462306a36Sopenharmony_ci	struct sdhci_host	*host;
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci	int			cd_idx;
16762306a36Sopenharmony_ci	bool			cd_override_level;
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci	void (*hw_reset)(struct sdhci_host *host);
17062306a36Sopenharmony_ci	unsigned long		private[] ____cacheline_aligned;
17162306a36Sopenharmony_ci};
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_cistruct sdhci_pci_chip {
17462306a36Sopenharmony_ci	struct pci_dev		*pdev;
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci	unsigned int		quirks;
17762306a36Sopenharmony_ci	unsigned int		quirks2;
17862306a36Sopenharmony_ci	bool			allow_runtime_pm;
17962306a36Sopenharmony_ci	bool			pm_retune;
18062306a36Sopenharmony_ci	bool			rpm_retune;
18162306a36Sopenharmony_ci	const struct sdhci_pci_fixes *fixes;
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci	int			num_slots;	/* Slots on controller */
18462306a36Sopenharmony_ci	struct sdhci_pci_slot	*slots[MAX_SLOTS]; /* Pointers to host slots */
18562306a36Sopenharmony_ci};
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_cistatic inline void *sdhci_pci_priv(struct sdhci_pci_slot *slot)
18862306a36Sopenharmony_ci{
18962306a36Sopenharmony_ci	return (void *)slot->private;
19062306a36Sopenharmony_ci}
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#ifdef CONFIG_PM_SLEEP
19362306a36Sopenharmony_ciint sdhci_pci_resume_host(struct sdhci_pci_chip *chip);
19462306a36Sopenharmony_ci#endif
19562306a36Sopenharmony_ciint sdhci_pci_enable_dma(struct sdhci_host *host);
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ciextern const struct sdhci_pci_fixes sdhci_arasan;
19862306a36Sopenharmony_ciextern const struct sdhci_pci_fixes sdhci_snps;
19962306a36Sopenharmony_ciextern const struct sdhci_pci_fixes sdhci_o2;
20062306a36Sopenharmony_ciextern const struct sdhci_pci_fixes sdhci_gl9750;
20162306a36Sopenharmony_ciextern const struct sdhci_pci_fixes sdhci_gl9755;
20262306a36Sopenharmony_ciextern const struct sdhci_pci_fixes sdhci_gl9763e;
20362306a36Sopenharmony_ciextern const struct sdhci_pci_fixes sdhci_gl9767;
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci#endif /* __SDHCI_PCI_H */
206