ufshcd-pci.c 5.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*
 * 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>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * See the COPYING file in the top-level directory or visit
 * <http://www.gnu.org/licenses/gpl-2.0.html>
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * This program is provided "AS IS" and "WITH ALL FAULTS" and
 * without warranty of any kind. You are solely responsible for
 * determining the appropriateness of using and distributing
 * the program and assume all risks associated with your exercise
 * of rights with respect to the program, including but not limited
 * to infringement of third party rights, the risks and costs of
 * program errors, damage to or loss of data, programs or equipment,
 * and unavailability or interruption of operations. Under no
 * circumstances will the contributor of this Program be liable for
 * any damages of any kind arising from your use or distribution of
 * this program.
 */

#include "ufshcd.h"
#include <linux/pci.h>
38
#include <linux/pm_runtime.h>
39

A
Adrian Hunter 已提交
40
#ifdef CONFIG_PM_SLEEP
41 42 43 44 45
/**
 * ufshcd_pci_suspend - suspend power management function
 * @pdev: pointer to PCI device handle
 * @state: power state
 *
46 47
 * Returns 0 if successful
 * Returns non-zero otherwise
48
 */
49
static int ufshcd_pci_suspend(struct device *dev)
50
{
51
	return ufshcd_system_suspend(dev_get_drvdata(dev));
52 53 54 55 56 57
}

/**
 * ufshcd_pci_resume - resume power management function
 * @pdev: pointer to PCI device handle
 *
58 59
 * Returns 0 if successful
 * Returns non-zero otherwise
60
 */
61
static int ufshcd_pci_resume(struct device *dev)
62
{
63
	return ufshcd_system_resume(dev_get_drvdata(dev));
64
}
A
Adrian Hunter 已提交
65
#endif /* !CONFIG_PM_SLEEP */
66

A
Adrian Hunter 已提交
67
#ifdef CONFIG_PM
68 69
static int ufshcd_pci_runtime_suspend(struct device *dev)
{
70
	return ufshcd_runtime_suspend(dev_get_drvdata(dev));
71 72 73
}
static int ufshcd_pci_runtime_resume(struct device *dev)
{
74
	return ufshcd_runtime_resume(dev_get_drvdata(dev));
75 76 77
}
static int ufshcd_pci_runtime_idle(struct device *dev)
{
78
	return ufshcd_runtime_idle(dev_get_drvdata(dev));
79
}
A
Adrian Hunter 已提交
80
#endif /* !CONFIG_PM */
81

82 83 84 85 86 87
/**
 * 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)
{
88
	ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
89 90 91 92 93 94 95 96 97 98 99
}

/**
 * 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);

100 101
	pm_runtime_forbid(&pdev->dev);
	pm_runtime_get_noresume(&pdev->dev);
102
	ufshcd_remove(hba);
103
	ufshcd_dealloc_host(hba);
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
}

/**
 * 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;

120
	err = pcim_enable_device(pdev);
121
	if (err) {
122 123
		dev_err(&pdev->dev, "pcim_enable_device failed\n");
		return err;
124 125 126 127
	}

	pci_set_master(pdev);

128
	err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
129
	if (err < 0) {
130 131
		dev_err(&pdev->dev, "request and iomap failed\n");
		return err;
132 133
	}

134
	mmio_base = pcim_iomap_table(pdev)[0];
135

136 137 138 139 140 141 142
	err = ufshcd_alloc_host(&pdev->dev, &hba);
	if (err) {
		dev_err(&pdev->dev, "Allocation failed\n");
		return err;
	}

	err = ufshcd_init(hba, mmio_base, pdev->irq);
143 144
	if (err) {
		dev_err(&pdev->dev, "Initialization failed\n");
145
		ufshcd_dealloc_host(hba);
146
		return err;
147 148 149
	}

	pci_set_drvdata(pdev, hba);
150 151
	pm_runtime_put_noidle(&pdev->dev);
	pm_runtime_allow(&pdev->dev);
152 153 154 155

	return 0;
}

156
static const struct dev_pm_ops ufshcd_pci_pm_ops = {
A
Adrian Hunter 已提交
157 158 159 160 161
	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)
162 163
};

164
static const struct pci_device_id ufshcd_pci_tbl[] = {
165 166 167 168 169 170 171 172 173 174 175 176
	{ PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
	{ }	/* 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,
177 178 179
	.driver = {
		.pm = &ufshcd_pci_pm_ops
	},
180 181 182 183 184 185 186 187 188
};

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);