vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console
[linux/fpc-iii.git] / drivers / mmc / host / tmio_mmc.c
blob43a2ea5cff24f335c481b7ad8c6f5abff1712d36
1 /*
2 * Driver for the MMC / SD / SDIO cell found in:
4 * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
6 * Copyright (C) 2017 Renesas Electronics Corporation
7 * Copyright (C) 2017 Horms Solutions, Simon Horman
8 * Copyright (C) 2007 Ian Molton
9 * Copyright (C) 2004 Ian Molton
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/device.h>
17 #include <linux/mfd/core.h>
18 #include <linux/mfd/tmio.h>
19 #include <linux/mmc/host.h>
20 #include <linux/module.h>
21 #include <linux/pagemap.h>
22 #include <linux/scatterlist.h>
24 #include "tmio_mmc.h"
26 #ifdef CONFIG_PM_SLEEP
27 static int tmio_mmc_suspend(struct device *dev)
29 struct platform_device *pdev = to_platform_device(dev);
30 const struct mfd_cell *cell = mfd_get_cell(pdev);
31 int ret;
33 ret = pm_runtime_force_suspend(dev);
35 /* Tell MFD core it can disable us now.*/
36 if (!ret && cell->disable)
37 cell->disable(pdev);
39 return ret;
42 static int tmio_mmc_resume(struct device *dev)
44 struct platform_device *pdev = to_platform_device(dev);
45 const struct mfd_cell *cell = mfd_get_cell(pdev);
46 int ret = 0;
48 /* Tell the MFD core we are ready to be enabled */
49 if (cell->resume)
50 ret = cell->resume(pdev);
52 if (!ret)
53 ret = pm_runtime_force_resume(dev);
55 return ret;
57 #endif
59 static int tmio_mmc_probe(struct platform_device *pdev)
61 const struct mfd_cell *cell = mfd_get_cell(pdev);
62 struct tmio_mmc_data *pdata;
63 struct tmio_mmc_host *host;
64 struct resource *res;
65 int ret = -EINVAL, irq;
67 if (pdev->num_resources != 2)
68 goto out;
70 pdata = pdev->dev.platform_data;
71 if (!pdata || !pdata->hclk)
72 goto out;
74 irq = platform_get_irq(pdev, 0);
75 if (irq < 0) {
76 ret = irq;
77 goto out;
80 /* Tell the MFD core we are ready to be enabled */
81 if (cell->enable) {
82 ret = cell->enable(pdev);
83 if (ret)
84 goto out;
87 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
88 if (!res) {
89 ret = -EINVAL;
90 goto cell_disable;
93 pdata->flags |= TMIO_MMC_HAVE_HIGH_REG;
95 host = tmio_mmc_host_alloc(pdev, pdata);
96 if (IS_ERR(host)) {
97 ret = PTR_ERR(host);
98 goto cell_disable;
101 /* SD control register space size is 0x200, 0x400 for bus_shift=1 */
102 host->bus_shift = resource_size(res) >> 10;
104 host->mmc->f_max = pdata->hclk;
105 host->mmc->f_min = pdata->hclk / 512;
107 ret = tmio_mmc_host_probe(host);
108 if (ret)
109 goto host_free;
111 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq,
112 IRQF_TRIGGER_FALLING,
113 dev_name(&pdev->dev), host);
114 if (ret)
115 goto host_remove;
117 pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc),
118 (unsigned long)host->ctl, irq);
120 return 0;
122 host_remove:
123 tmio_mmc_host_remove(host);
124 host_free:
125 tmio_mmc_host_free(host);
126 cell_disable:
127 if (cell->disable)
128 cell->disable(pdev);
129 out:
130 return ret;
133 static int tmio_mmc_remove(struct platform_device *pdev)
135 const struct mfd_cell *cell = mfd_get_cell(pdev);
136 struct tmio_mmc_host *host = platform_get_drvdata(pdev);
138 tmio_mmc_host_remove(host);
139 if (cell->disable)
140 cell->disable(pdev);
142 return 0;
145 /* ------------------- device registration ----------------------- */
147 static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
148 SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume)
149 SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend,
150 tmio_mmc_host_runtime_resume, NULL)
153 static struct platform_driver tmio_mmc_driver = {
154 .driver = {
155 .name = "tmio-mmc",
156 .pm = &tmio_mmc_dev_pm_ops,
158 .probe = tmio_mmc_probe,
159 .remove = tmio_mmc_remove,
162 module_platform_driver(tmio_mmc_driver);
164 MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver");
165 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
166 MODULE_LICENSE("GPL v2");
167 MODULE_ALIAS("platform:tmio-mmc");