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 | |
| 26 | #ifdef CONFIG_PM |
| 27 | static int tmio_mmc_suspend(struct platform_device *dev, pm_message_t state) |
| 28 | { |
Andres Salomon | 944dc03 | 2011-03-01 12:32:20 -0800 | [diff] [blame] | 29 | const struct mfd_cell *cell = mfd_get_cell(dev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 30 | int ret; |
| 31 | |
Guennadi Liakhovetski | e6ee718 | 2011-05-05 16:13:12 +0000 | [diff] [blame] | 32 | ret = tmio_mmc_host_suspend(&dev->dev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 33 | |
| 34 | /* Tell MFD core it can disable us now.*/ |
| 35 | if (!ret && cell->disable) |
| 36 | cell->disable(dev); |
| 37 | |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | static int tmio_mmc_resume(struct platform_device *dev) |
| 42 | { |
Andres Salomon | 944dc03 | 2011-03-01 12:32:20 -0800 | [diff] [blame] | 43 | const struct mfd_cell *cell = mfd_get_cell(dev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 44 | int ret = 0; |
| 45 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 46 | /* Tell the MFD core we are ready to be enabled */ |
Guennadi Liakhovetski | e6ee718 | 2011-05-05 16:13:12 +0000 | [diff] [blame] | 47 | if (cell->resume) |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 48 | ret = cell->resume(dev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 49 | |
Guennadi Liakhovetski | e6ee718 | 2011-05-05 16:13:12 +0000 | [diff] [blame] | 50 | if (!ret) |
| 51 | ret = tmio_mmc_host_resume(&dev->dev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 52 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 53 | return ret; |
| 54 | } |
| 55 | #else |
| 56 | #define tmio_mmc_suspend NULL |
| 57 | #define tmio_mmc_resume NULL |
| 58 | #endif |
| 59 | |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 60 | static int __devinit tmio_mmc_probe(struct platform_device *pdev) |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 61 | { |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 62 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 63 | struct tmio_mmc_data *pdata; |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 64 | struct tmio_mmc_host *host; |
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 | |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 87 | ret = tmio_mmc_host_probe(&host, pdev, pdata); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 88 | if (ret) |
Magnus Damm | 7ee422d | 2010-02-17 16:38:23 +0900 | [diff] [blame] | 89 | goto cell_disable; |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 90 | |
Yong Zhang | d9618e9 | 2011-09-22 16:59:04 +0800 | [diff] [blame] | 91 | ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING, |
| 92 | dev_name(&pdev->dev), host); |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 93 | if (ret) |
| 94 | goto host_remove; |
| 95 | |
Guennadi Liakhovetski | 311f3ac | 2010-05-19 18:34:22 +0000 | [diff] [blame] | 96 | 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] | 97 | (unsigned long)host->ctl, irq); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 98 | |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 99 | return 0; |
| 100 | |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 101 | host_remove: |
| 102 | tmio_mmc_host_remove(host); |
Magnus Damm | 7ee422d | 2010-02-17 16:38:23 +0900 | [diff] [blame] | 103 | cell_disable: |
| 104 | if (cell->disable) |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 105 | cell->disable(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 106 | out: |
| 107 | return ret; |
| 108 | } |
| 109 | |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 110 | static int __devexit tmio_mmc_remove(struct platform_device *pdev) |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 111 | { |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 112 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
| 113 | struct mmc_host *mmc = platform_get_drvdata(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 114 | |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 115 | platform_set_drvdata(pdev, NULL); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 116 | |
| 117 | if (mmc) { |
Magnus Damm | 8e7bfdb | 2011-05-06 11:02:33 +0000 | [diff] [blame] | 118 | struct tmio_mmc_host *host = mmc_priv(mmc); |
| 119 | free_irq(platform_get_irq(pdev, 0), host); |
| 120 | tmio_mmc_host_remove(host); |
Magnus Damm | 7ee422d | 2010-02-17 16:38:23 +0900 | [diff] [blame] | 121 | if (cell->disable) |
Guennadi Liakhovetski | b614749 | 2011-03-23 12:42:44 +0100 | [diff] [blame] | 122 | cell->disable(pdev); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /* ------------------- device registration ----------------------- */ |
| 129 | |
| 130 | static struct platform_driver tmio_mmc_driver = { |
| 131 | .driver = { |
| 132 | .name = "tmio-mmc", |
| 133 | .owner = THIS_MODULE, |
| 134 | }, |
| 135 | .probe = tmio_mmc_probe, |
| 136 | .remove = __devexit_p(tmio_mmc_remove), |
| 137 | .suspend = tmio_mmc_suspend, |
| 138 | .resume = tmio_mmc_resume, |
| 139 | }; |
| 140 | |
Axel Lin | d1f81a6 | 2011-11-26 12:55:43 +0800 | [diff] [blame] | 141 | module_platform_driver(tmio_mmc_driver); |
Ian Molton | 4a48998 | 2008-07-15 16:02:21 +0100 | [diff] [blame] | 142 | |
| 143 | MODULE_DESCRIPTION("Toshiba TMIO SD/MMC driver"); |
| 144 | MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); |
| 145 | MODULE_LICENSE("GPL v2"); |
| 146 | MODULE_ALIAS("platform:tmio-mmc"); |