mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-24 02:37:15 +07:00
8da76f71fe
Intel EHL UFS host controller advertises auto-hibernate capability but it
does not work correctly. Add a quirk for that.
[mkp: checkpatch fix]
Link: https://lore.kernel.org/r/20200810141024.28859-1-adrian.hunter@intel.com
Fixes: 8c09d75276
("scsi: ufshdc-pci: Add Intel PCI IDs for EHL")
Acked-by: Stanley Chu <stanley.chu@mediatek.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
217 lines
5.1 KiB
C
217 lines
5.1 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Universal Flash Storage Host controller PCI glue driver
|
|
*
|
|
* This code is based on drivers/scsi/ufs/ufshcd-pci.c
|
|
* Copyright (C) 2011-2013 Samsung India Software Operations
|
|
*
|
|
* Authors:
|
|
* Santosh Yaraganavi <santosh.sy@samsung.com>
|
|
* Vinayak Holikatti <h.vinayak@samsung.com>
|
|
*/
|
|
|
|
#include "ufshcd.h"
|
|
#include <linux/pci.h>
|
|
#include <linux/pm_runtime.h>
|
|
|
|
static int ufs_intel_disable_lcc(struct ufs_hba *hba)
|
|
{
|
|
u32 attr = UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE);
|
|
u32 lcc_enable = 0;
|
|
|
|
ufshcd_dme_get(hba, attr, &lcc_enable);
|
|
if (lcc_enable)
|
|
ufshcd_disable_host_tx_lcc(hba);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ufs_intel_link_startup_notify(struct ufs_hba *hba,
|
|
enum ufs_notify_change_status status)
|
|
{
|
|
int err = 0;
|
|
|
|
switch (status) {
|
|
case PRE_CHANGE:
|
|
err = ufs_intel_disable_lcc(hba);
|
|
break;
|
|
case POST_CHANGE:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static int ufs_intel_ehl_init(struct ufs_hba *hba)
|
|
{
|
|
hba->quirks |= UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8;
|
|
return 0;
|
|
}
|
|
|
|
static struct ufs_hba_variant_ops ufs_intel_cnl_hba_vops = {
|
|
.name = "intel-pci",
|
|
.link_startup_notify = ufs_intel_link_startup_notify,
|
|
};
|
|
|
|
static struct ufs_hba_variant_ops ufs_intel_ehl_hba_vops = {
|
|
.name = "intel-pci",
|
|
.init = ufs_intel_ehl_init,
|
|
.link_startup_notify = ufs_intel_link_startup_notify,
|
|
};
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
/**
|
|
* ufshcd_pci_suspend - suspend power management function
|
|
* @dev: pointer to PCI device handle
|
|
*
|
|
* Returns 0 if successful
|
|
* Returns non-zero otherwise
|
|
*/
|
|
static int ufshcd_pci_suspend(struct device *dev)
|
|
{
|
|
return ufshcd_system_suspend(dev_get_drvdata(dev));
|
|
}
|
|
|
|
/**
|
|
* ufshcd_pci_resume - resume power management function
|
|
* @dev: pointer to PCI device handle
|
|
*
|
|
* Returns 0 if successful
|
|
* Returns non-zero otherwise
|
|
*/
|
|
static int ufshcd_pci_resume(struct device *dev)
|
|
{
|
|
return ufshcd_system_resume(dev_get_drvdata(dev));
|
|
}
|
|
#endif /* !CONFIG_PM_SLEEP */
|
|
|
|
#ifdef CONFIG_PM
|
|
static int ufshcd_pci_runtime_suspend(struct device *dev)
|
|
{
|
|
return ufshcd_runtime_suspend(dev_get_drvdata(dev));
|
|
}
|
|
static int ufshcd_pci_runtime_resume(struct device *dev)
|
|
{
|
|
return ufshcd_runtime_resume(dev_get_drvdata(dev));
|
|
}
|
|
static int ufshcd_pci_runtime_idle(struct device *dev)
|
|
{
|
|
return ufshcd_runtime_idle(dev_get_drvdata(dev));
|
|
}
|
|
#endif /* !CONFIG_PM */
|
|
|
|
/**
|
|
* ufshcd_pci_shutdown - main function to put the controller in reset state
|
|
* @pdev: pointer to PCI device handle
|
|
*/
|
|
static void ufshcd_pci_shutdown(struct pci_dev *pdev)
|
|
{
|
|
ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
|
|
}
|
|
|
|
/**
|
|
* ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space
|
|
* data structure memory
|
|
* @pdev: pointer to PCI handle
|
|
*/
|
|
static void ufshcd_pci_remove(struct pci_dev *pdev)
|
|
{
|
|
struct ufs_hba *hba = pci_get_drvdata(pdev);
|
|
|
|
pm_runtime_forbid(&pdev->dev);
|
|
pm_runtime_get_noresume(&pdev->dev);
|
|
ufshcd_remove(hba);
|
|
ufshcd_dealloc_host(hba);
|
|
}
|
|
|
|
/**
|
|
* ufshcd_pci_probe - probe routine of the driver
|
|
* @pdev: pointer to PCI device handle
|
|
* @id: PCI device id
|
|
*
|
|
* Returns 0 on success, non-zero value on failure
|
|
*/
|
|
static int
|
|
ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
|
|
{
|
|
struct ufs_hba *hba;
|
|
void __iomem *mmio_base;
|
|
int err;
|
|
|
|
err = pcim_enable_device(pdev);
|
|
if (err) {
|
|
dev_err(&pdev->dev, "pcim_enable_device failed\n");
|
|
return err;
|
|
}
|
|
|
|
pci_set_master(pdev);
|
|
|
|
err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
|
|
if (err < 0) {
|
|
dev_err(&pdev->dev, "request and iomap failed\n");
|
|
return err;
|
|
}
|
|
|
|
mmio_base = pcim_iomap_table(pdev)[0];
|
|
|
|
err = ufshcd_alloc_host(&pdev->dev, &hba);
|
|
if (err) {
|
|
dev_err(&pdev->dev, "Allocation failed\n");
|
|
return err;
|
|
}
|
|
|
|
hba->vops = (struct ufs_hba_variant_ops *)id->driver_data;
|
|
|
|
err = ufshcd_init(hba, mmio_base, pdev->irq);
|
|
if (err) {
|
|
dev_err(&pdev->dev, "Initialization failed\n");
|
|
ufshcd_dealloc_host(hba);
|
|
return err;
|
|
}
|
|
|
|
pci_set_drvdata(pdev, hba);
|
|
pm_runtime_put_noidle(&pdev->dev);
|
|
pm_runtime_allow(&pdev->dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct dev_pm_ops ufshcd_pci_pm_ops = {
|
|
SET_SYSTEM_SLEEP_PM_OPS(ufshcd_pci_suspend,
|
|
ufshcd_pci_resume)
|
|
SET_RUNTIME_PM_OPS(ufshcd_pci_runtime_suspend,
|
|
ufshcd_pci_runtime_resume,
|
|
ufshcd_pci_runtime_idle)
|
|
};
|
|
|
|
static const struct pci_device_id ufshcd_pci_tbl[] = {
|
|
{ PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
|
|
{ PCI_VDEVICE(INTEL, 0x9DFA), (kernel_ulong_t)&ufs_intel_cnl_hba_vops },
|
|
{ PCI_VDEVICE(INTEL, 0x4B41), (kernel_ulong_t)&ufs_intel_ehl_hba_vops },
|
|
{ PCI_VDEVICE(INTEL, 0x4B43), (kernel_ulong_t)&ufs_intel_ehl_hba_vops },
|
|
{ } /* terminate list */
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
|
|
|
|
static struct pci_driver ufshcd_pci_driver = {
|
|
.name = UFSHCD,
|
|
.id_table = ufshcd_pci_tbl,
|
|
.probe = ufshcd_pci_probe,
|
|
.remove = ufshcd_pci_remove,
|
|
.shutdown = ufshcd_pci_shutdown,
|
|
.driver = {
|
|
.pm = &ufshcd_pci_pm_ops
|
|
},
|
|
};
|
|
|
|
module_pci_driver(ufshcd_pci_driver);
|
|
|
|
MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
|
|
MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
|
|
MODULE_DESCRIPTION("UFS host controller PCI glue driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_VERSION(UFSHCD_DRIVER_VERSION);
|