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