Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 1 | /* |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 2 | * linux/drivers/mmc/host/tmio_mmc.c |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 3 | * |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 4 | * Copyright (C) 2007 Ian Molton |
| 5 | * Copyright (C) 2004 Ian Molton |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * Driver for the MMC / SD / SDIO cell found in: |
| 12 | * |
Philipp Zabel | e6f2c7a | 2009-06-04 20:12:37 +0200 | [diff] [blame] | 13 | * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3 |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 14 | */ |
Guennadi Liakhovetski | e0bc6ff | 2010-11-23 17:24:11 +0100 | [diff] [blame] | 15 | |
Guennadi Liakhovetski | e0bc6ff | 2010-11-23 17:24:11 +0100 | [diff] [blame] | 16 | #include <linux/device.h> |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 17 | #include <linux/mfd/core.h> |
| 18 | #include <linux/mfd/tmio.h> |
Guennadi Liakhovetski | e0bc6ff | 2010-11-23 17:24:11 +0100 | [diff] [blame] | 19 | #include <linux/mmc/host.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/pagemap.h> |
| 22 | #include <linux/scatterlist.h> |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 23 | |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 24 | #include "tmio_mmc.h" |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 25 | |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 26 | #ifdef CONFIG_PM_SLEEP |
| 27 | static int tmio_mmc_suspend(struct device *dev) |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 28 | { |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 29 | struct platform_device *pdev = to_platform_device(dev); |
| 30 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 31 | int ret; |
| 32 | |
Ulf Hansson | 70a15e1 | 2014-08-25 12:28:20 +0200 | [diff] [blame] | 33 | ret = pm_runtime_force_suspend(dev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 34 | |
| 35 | /* Tell MFD core it can disable us now.*/ |
| 36 | if (!ret && cell->disable) |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 37 | cell->disable(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 38 | |
| 39 | return ret; |
| 40 | } |
| 41 | |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 42 | static int tmio_mmc_resume(struct device *dev) |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 43 | { |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 44 | struct platform_device *pdev = to_platform_device(dev); |
| 45 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 46 | int ret = 0; |
| 47 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 48 | /* Tell the MFD core we are ready to be enabled */ |
Guennadi Liakhovetski | e6ee718 | 2011-05-05 16:13:12 +0000 | [diff] [blame] | 49 | if (cell->resume) |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 50 | ret = cell->resume(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 51 | |
Guennadi Liakhovetski | e6ee718 | 2011-05-05 16:13:12 +0000 | [diff] [blame] | 52 | if (!ret) |
Ulf Hansson | 70a15e1 | 2014-08-25 12:28:20 +0200 | [diff] [blame] | 53 | ret = pm_runtime_force_resume(dev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 54 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 55 | return ret; |
| 56 | } |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 57 | #endif |
| 58 | |
Bill Pemberton | c3be1ef | 2012-11-19 13:23:06 -0500 | [diff] [blame] | 59 | static int tmio_mmc_probe(struct platform_device *pdev) |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 60 | { |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 61 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 62 | struct tmio_mmc_data *pdata; |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 63 | struct tmio_mmc_host *host; |
Kuninori Morimoto | 3b159a6 | 2013-11-20 00:30:55 -0800 | [diff] [blame] | 64 | struct resource *res; |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 65 | int ret = -EINVAL, irq; |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 66 | |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 67 | if (pdev->num_resources != 2) |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 68 | goto out; |
| 69 | |
Samuel Ortiz | ec71974 | 2011-04-06 11:38:14 +0200 | [diff] [blame] | 70 | pdata = pdev->dev.platform_data; |
Philipp Zabel | d6c9b5e | 2009-06-04 20:12:34 +0200 | [diff] [blame] | 71 | if (!pdata || !pdata->hclk) |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 72 | goto out; |
Philipp Zabel | d6c9b5e | 2009-06-04 20:12:34 +0200 | [diff] [blame] | 73 | |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 74 | irq = platform_get_irq(pdev, 0); |
| 75 | if (irq < 0) { |
| 76 | ret = irq; |
| 77 | goto out; |
| 78 | } |
| 79 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 80 | /* Tell the MFD core we are ready to be enabled */ |
| 81 | if (cell->enable) { |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 82 | ret = cell->enable(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 83 | if (ret) |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 84 | goto out; |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Kuninori Morimoto | 3b159a6 | 2013-11-20 00:30:55 -0800 | [diff] [blame] | 87 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Ian Molton | 25db67e | 2015-04-27 00:01:06 +0100 | [diff] [blame] | 88 | if (!res) { |
| 89 | ret = -EINVAL; |
| 90 | goto cell_disable; |
| 91 | } |
Kuninori Morimoto | 3b159a6 | 2013-11-20 00:30:55 -0800 | [diff] [blame] | 92 | |
Kuninori Morimoto | 5d60e50 | 2013-11-20 00:31:06 -0800 | [diff] [blame] | 93 | pdata->flags |= TMIO_MMC_HAVE_HIGH_REG; |
Kuninori Morimoto | 3b159a6 | 2013-11-20 00:30:55 -0800 | [diff] [blame] | 94 | |
Kuninori Morimoto | 94b110a | 2015-01-13 04:57:22 +0000 | [diff] [blame] | 95 | host = tmio_mmc_host_alloc(pdev); |
| 96 | if (!host) |
Magnus Damm | 7ee422d | 2010-02-17 16:38:23 +0900 | [diff] [blame] | 97 | goto cell_disable; |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 98 | |
Kuninori Morimoto | 7445bf9 | 2015-01-13 04:58:20 +0000 | [diff] [blame] | 99 | /* SD control register space size is 0x200, 0x400 for bus_shift=1 */ |
| 100 | host->bus_shift = resource_size(res) >> 10; |
| 101 | |
Kuninori Morimoto | 94b110a | 2015-01-13 04:57:22 +0000 | [diff] [blame] | 102 | ret = tmio_mmc_host_probe(host, pdata); |
| 103 | if (ret) |
| 104 | goto host_free; |
| 105 | |
Ian Molton | de501af | 2015-04-27 00:01:36 +0100 | [diff] [blame] | 106 | ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, |
| 107 | IRQF_TRIGGER_FALLING, |
Yong Zhang | d9618e9 | 2011-09-22 16:59:04 +0800 | [diff] [blame] | 108 | dev_name(&pdev->dev), host); |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 109 | if (ret) |
| 110 | goto host_remove; |
| 111 | |
Guennadi Liakhovetski | 311f3ac | 2010-05-19 18:34:22 +0000 | [diff] [blame] | 112 | pr_info("%s at 0x%08lx irq %d\n", mmc_hostname(host->mmc), |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 113 | (unsigned long)host->ctl, irq); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 114 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 115 | return 0; |
| 116 | |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 117 | host_remove: |
| 118 | tmio_mmc_host_remove(host); |
Kuninori Morimoto | 94b110a | 2015-01-13 04:57:22 +0000 | [diff] [blame] | 119 | host_free: |
| 120 | tmio_mmc_host_free(host); |
Magnus Damm | 7ee422d | 2010-02-17 16:38:23 +0900 | [diff] [blame] | 121 | cell_disable: |
| 122 | if (cell->disable) |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 123 | cell->disable(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 124 | out: |
| 125 | return ret; |
| 126 | } |
| 127 | |
Bill Pemberton | 6e0ee71 | 2012-11-19 13:26:03 -0500 | [diff] [blame] | 128 | static int tmio_mmc_remove(struct platform_device *pdev) |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 129 | { |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 130 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
| 131 | struct mmc_host *mmc = platform_get_drvdata(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 132 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 133 | if (mmc) { |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 134 | struct tmio_mmc_host *host = mmc_priv(mmc); |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 135 | tmio_mmc_host_remove(host); |
Magnus Damm | 7ee422d | 2010-02-17 16:38:23 +0900 | [diff] [blame] | 136 | if (cell->disable) |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 137 | cell->disable(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /* ------------------- device registration ----------------------- */ |
| 144 | |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 145 | static const struct dev_pm_ops tmio_mmc_dev_pm_ops = { |
| 146 | SET_SYSTEM_SLEEP_PM_OPS(tmio_mmc_suspend, tmio_mmc_resume) |
Rafael J. Wysocki | 6ed23b8 | 2014-12-04 00:34:11 +0100 | [diff] [blame] | 147 | SET_RUNTIME_PM_OPS(tmio_mmc_host_runtime_suspend, |
Ulf Hansson | 78f76df | 2014-08-25 12:12:02 +0200 | [diff] [blame] | 148 | tmio_mmc_host_runtime_resume, |
| 149 | NULL) |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 150 | }; |
| 151 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 152 | static struct platform_driver tmio_mmc_driver = { |
| 153 | .driver = { |
| 154 | .name = "tmio-mmc", |
Ulf Hansson | c896448 | 2013-10-23 14:57:50 +0200 | [diff] [blame] | 155 | .pm = &tmio_mmc_dev_pm_ops, |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 156 | }, |
| 157 | .probe = tmio_mmc_probe, |
Bill Pemberton | 0433c14 | 2012-11-19 13:20:26 -0500 | [diff] [blame] | 158 | .remove = tmio_mmc_remove, |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
Axel Lin | d1f81a6 | 2011-11-26 12:55:43 +0800 | [diff] [blame] | 161 | module_platform_driver(tmio_mmc_driver); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 162 | |
| 163 | MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver"); |
| 164 | MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); |
| 165 | MODULE_LICENSE("GPL v2"); |
| 166 | MODULE_ALIAS("platform:tmio-mmc"); |