Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Toshiba TC6387XB support |
| 3 | * Copyright (c) 2005 Ian Molton |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This file contains TC6387XB base support. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/platform_device.h> |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 15 | #include <linux/clk.h> |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 16 | #include <linux/err.h> |
| 17 | #include <linux/mfd/core.h> |
| 18 | #include <linux/mfd/tmio.h> |
| 19 | #include <linux/mfd/tc6387xb.h> |
| 20 | |
Ian Molton | d2432a6 | 2008-08-04 18:58:18 +0200 | [diff] [blame] | 21 | enum { |
| 22 | TC6387XB_CELL_MMC, |
| 23 | }; |
| 24 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 25 | struct tc6387xb { |
| 26 | void __iomem *scr; |
| 27 | struct clk *clk32k; |
| 28 | struct resource rscr; |
| 29 | }; |
| 30 | |
| 31 | static struct resource tc6387xb_mmc_resources[] = { |
| 32 | { |
| 33 | .start = 0x800, |
| 34 | .end = 0x9ff, |
| 35 | .flags = IORESOURCE_MEM, |
| 36 | }, |
| 37 | { |
| 38 | .start = 0, |
| 39 | .end = 0, |
| 40 | .flags = IORESOURCE_IRQ, |
| 41 | }, |
| 42 | }; |
| 43 | |
| 44 | /*--------------------------------------------------------------------------*/ |
| 45 | |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 46 | #ifdef CONFIG_PM |
| 47 | static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state) |
| 48 | { |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 49 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 50 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 51 | |
| 52 | if (pdata && pdata->suspend) |
| 53 | pdata->suspend(dev); |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 54 | clk_disable(tc6387xb->clk32k); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int tc6387xb_resume(struct platform_device *dev) |
| 60 | { |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 61 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 62 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 63 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 64 | clk_enable(tc6387xb->clk32k); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 65 | if (pdata && pdata->resume) |
| 66 | pdata->resume(dev); |
| 67 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 68 | tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0, |
| 69 | tc6387xb_mmc_resources[0].start & 0xfffe); |
| 70 | |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | #else |
| 74 | #define tc6387xb_suspend NULL |
| 75 | #define tc6387xb_resume NULL |
| 76 | #endif |
| 77 | |
| 78 | /*--------------------------------------------------------------------------*/ |
| 79 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 80 | static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state) |
| 81 | { |
| 82 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
| 83 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
| 84 | |
| 85 | tmio_core_mmc_pwr(tc6387xb->scr + 0x200, 0, state); |
| 86 | } |
| 87 | |
| 88 | static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state) |
| 89 | { |
| 90 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
| 91 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
| 92 | |
| 93 | tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, 0, state); |
| 94 | } |
| 95 | |
| 96 | |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 97 | static int tc6387xb_mmc_enable(struct platform_device *mmc) |
| 98 | { |
| 99 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 100 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 101 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 102 | clk_enable(tc6387xb->clk32k); |
| 103 | |
| 104 | tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0, |
| 105 | tc6387xb_mmc_resources[0].start & 0xfffe); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static int tc6387xb_mmc_disable(struct platform_device *mmc) |
| 111 | { |
| 112 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 113 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 114 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 115 | clk_disable(tc6387xb->clk32k); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
Samuel Ortiz | 4d3792e | 2009-06-15 15:43:31 +0200 | [diff] [blame] | 120 | static struct tmio_mmc_data tc6387xb_mmc_data = { |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 121 | .hclk = 24000000, |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 122 | .set_pwr = tc6387xb_mmc_pwr, |
| 123 | .set_clk_div = tc6387xb_mmc_clk_div, |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 124 | }; |
| 125 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 126 | /*--------------------------------------------------------------------------*/ |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 127 | |
| 128 | static struct mfd_cell tc6387xb_cells[] = { |
Ian Molton | d2432a6 | 2008-08-04 18:58:18 +0200 | [diff] [blame] | 129 | [TC6387XB_CELL_MMC] = { |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 130 | .name = "tmio-mmc", |
| 131 | .enable = tc6387xb_mmc_enable, |
| 132 | .disable = tc6387xb_mmc_disable, |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 133 | .driver_data = &tc6387xb_mmc_data, |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 134 | .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources), |
| 135 | .resources = tc6387xb_mmc_resources, |
| 136 | }, |
| 137 | }; |
| 138 | |
| 139 | static int tc6387xb_probe(struct platform_device *dev) |
| 140 | { |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 141 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 142 | struct resource *iomem, *rscr; |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 143 | struct clk *clk32k; |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 144 | struct tc6387xb *tc6387xb; |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 145 | int irq, ret; |
| 146 | |
| 147 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 148 | if (!iomem) { |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 149 | return -EINVAL; |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 152 | tc6387xb = kzalloc(sizeof *tc6387xb, GFP_KERNEL); |
| 153 | if (!tc6387xb) |
| 154 | return -ENOMEM; |
| 155 | |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 156 | ret = platform_get_irq(dev, 0); |
| 157 | if (ret >= 0) |
| 158 | irq = ret; |
| 159 | else |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 160 | goto err_no_irq; |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 161 | |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 162 | clk32k = clk_get(&dev->dev, "CLK_CK32K"); |
| 163 | if (IS_ERR(clk32k)) { |
| 164 | ret = PTR_ERR(clk32k); |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 165 | goto err_no_clk; |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 166 | } |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 167 | |
| 168 | rscr = &tc6387xb->rscr; |
| 169 | rscr->name = "tc6387xb-core"; |
| 170 | rscr->start = iomem->start; |
| 171 | rscr->end = iomem->start + 0xff; |
| 172 | rscr->flags = IORESOURCE_MEM; |
| 173 | |
| 174 | ret = request_resource(iomem, rscr); |
| 175 | if (ret) |
| 176 | goto err_resource; |
| 177 | |
| 178 | tc6387xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1); |
| 179 | if (!tc6387xb->scr) { |
| 180 | ret = -ENOMEM; |
| 181 | goto err_ioremap; |
| 182 | } |
| 183 | |
| 184 | tc6387xb->clk32k = clk32k; |
| 185 | platform_set_drvdata(dev, tc6387xb); |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 186 | |
| 187 | if (pdata && pdata->enable) |
| 188 | pdata->enable(dev); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 189 | |
| 190 | printk(KERN_INFO "Toshiba tc6387xb initialised\n"); |
| 191 | |
Ian Molton | d2432a6 | 2008-08-04 18:58:18 +0200 | [diff] [blame] | 192 | tc6387xb_cells[TC6387XB_CELL_MMC].platform_data = |
| 193 | &tc6387xb_cells[TC6387XB_CELL_MMC]; |
| 194 | tc6387xb_cells[TC6387XB_CELL_MMC].data_size = |
| 195 | sizeof(tc6387xb_cells[TC6387XB_CELL_MMC]); |
| 196 | |
Samuel Ortiz | 56bf2bd | 2008-08-01 00:16:13 +0200 | [diff] [blame] | 197 | ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells, |
| 198 | ARRAY_SIZE(tc6387xb_cells), iomem, irq); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 199 | |
| 200 | if (!ret) |
| 201 | return 0; |
| 202 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 203 | err_ioremap: |
| 204 | release_resource(&tc6387xb->rscr); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 205 | err_resource: |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 206 | clk_put(clk32k); |
| 207 | err_no_clk: |
| 208 | err_no_irq: |
| 209 | kfree(tc6387xb); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 210 | return ret; |
| 211 | } |
| 212 | |
| 213 | static int tc6387xb_remove(struct platform_device *dev) |
| 214 | { |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 215 | struct clk *clk32k = platform_get_drvdata(dev); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 216 | |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 217 | mfd_remove_devices(&dev->dev); |
| 218 | clk_disable(clk32k); |
| 219 | clk_put(clk32k); |
| 220 | platform_set_drvdata(dev, NULL); |
Ian Molton | cbdfb42 | 2008-07-15 15:12:52 +0100 | [diff] [blame] | 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | static struct platform_driver tc6387xb_platform_driver = { |
| 227 | .driver = { |
| 228 | .name = "tc6387xb", |
| 229 | }, |
| 230 | .probe = tc6387xb_probe, |
| 231 | .remove = tc6387xb_remove, |
| 232 | .suspend = tc6387xb_suspend, |
| 233 | .resume = tc6387xb_resume, |
| 234 | }; |
| 235 | |
| 236 | |
| 237 | static int __init tc6387xb_init(void) |
| 238 | { |
| 239 | return platform_driver_register(&tc6387xb_platform_driver); |
| 240 | } |
| 241 | |
| 242 | static void __exit tc6387xb_exit(void) |
| 243 | { |
| 244 | platform_driver_unregister(&tc6387xb_platform_driver); |
| 245 | } |
| 246 | |
| 247 | module_init(tc6387xb_init); |
| 248 | module_exit(tc6387xb_exit); |
| 249 | |
| 250 | MODULE_DESCRIPTION("Toshiba TC6387XB core driver"); |
| 251 | MODULE_LICENSE("GPL v2"); |
| 252 | MODULE_AUTHOR("Ian Molton"); |
| 253 | MODULE_ALIAS("platform:tc6387xb"); |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 254 | |