diff options
Diffstat (limited to 'drivers/mfd/tc6387xb.c')
-rw-r--r-- | drivers/mfd/tc6387xb.c | 119 |
1 files changed, 88 insertions, 31 deletions
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c index 3280ab33f88a..5c7f04343d5c 100644 --- a/drivers/mfd/tc6387xb.c +++ b/drivers/mfd/tc6387xb.c | |||
@@ -22,28 +22,52 @@ enum { | |||
22 | TC6387XB_CELL_MMC, | 22 | TC6387XB_CELL_MMC, |
23 | }; | 23 | }; |
24 | 24 | ||
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 | |||
25 | #ifdef CONFIG_PM | 46 | #ifdef CONFIG_PM |
26 | static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state) | 47 | static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state) |
27 | { | 48 | { |
28 | struct clk *clk32k = platform_get_drvdata(dev); | 49 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
29 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; | 50 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; |
30 | 51 | ||
31 | if (pdata && pdata->suspend) | 52 | if (pdata && pdata->suspend) |
32 | pdata->suspend(dev); | 53 | pdata->suspend(dev); |
33 | clk_disable(clk32k); | 54 | clk_disable(tc6387xb->clk32k); |
34 | 55 | ||
35 | return 0; | 56 | return 0; |
36 | } | 57 | } |
37 | 58 | ||
38 | static int tc6387xb_resume(struct platform_device *dev) | 59 | static int tc6387xb_resume(struct platform_device *dev) |
39 | { | 60 | { |
40 | struct clk *clk32k = platform_get_drvdata(dev); | 61 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
41 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; | 62 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; |
42 | 63 | ||
43 | clk_enable(clk32k); | 64 | clk_enable(tc6387xb->clk32k); |
44 | if (pdata && pdata->resume) | 65 | if (pdata && pdata->resume) |
45 | pdata->resume(dev); | 66 | pdata->resume(dev); |
46 | 67 | ||
68 | tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0, | ||
69 | tc6387xb_mmc_resources[0].start & 0xfffe); | ||
70 | |||
47 | return 0; | 71 | return 0; |
48 | } | 72 | } |
49 | #else | 73 | #else |
@@ -53,12 +77,32 @@ static int tc6387xb_resume(struct platform_device *dev) | |||
53 | 77 | ||
54 | /*--------------------------------------------------------------------------*/ | 78 | /*--------------------------------------------------------------------------*/ |
55 | 79 | ||
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 | |||
56 | static int tc6387xb_mmc_enable(struct platform_device *mmc) | 97 | static int tc6387xb_mmc_enable(struct platform_device *mmc) |
57 | { | 98 | { |
58 | struct platform_device *dev = to_platform_device(mmc->dev.parent); | 99 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
59 | struct clk *clk32k = platform_get_drvdata(dev); | 100 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
60 | 101 | ||
61 | clk_enable(clk32k); | 102 | clk_enable(tc6387xb->clk32k); |
103 | |||
104 | tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0, | ||
105 | tc6387xb_mmc_resources[0].start & 0xfffe); | ||
62 | 106 | ||
63 | return 0; | 107 | return 0; |
64 | } | 108 | } |
@@ -66,36 +110,20 @@ static int tc6387xb_mmc_enable(struct platform_device *mmc) | |||
66 | static int tc6387xb_mmc_disable(struct platform_device *mmc) | 110 | static int tc6387xb_mmc_disable(struct platform_device *mmc) |
67 | { | 111 | { |
68 | struct platform_device *dev = to_platform_device(mmc->dev.parent); | 112 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
69 | struct clk *clk32k = platform_get_drvdata(dev); | 113 | struct tc6387xb *tc6387xb = platform_get_drvdata(dev); |
70 | 114 | ||
71 | clk_disable(clk32k); | 115 | clk_disable(tc6387xb->clk32k); |
72 | 116 | ||
73 | return 0; | 117 | return 0; |
74 | } | 118 | } |
75 | 119 | ||
76 | /*--------------------------------------------------------------------------*/ | ||
77 | |||
78 | static struct tmio_mmc_data tc6387xb_mmc_data = { | 120 | static struct tmio_mmc_data tc6387xb_mmc_data = { |
79 | .hclk = 24000000, | 121 | .hclk = 24000000, |
122 | .set_pwr = tc6387xb_mmc_pwr, | ||
123 | .set_clk_div = tc6387xb_mmc_clk_div, | ||
80 | }; | 124 | }; |
81 | 125 | ||
82 | static struct resource tc6387xb_mmc_resources[] = { | 126 | /*--------------------------------------------------------------------------*/ |
83 | { | ||
84 | .start = 0x800, | ||
85 | .end = 0x9ff, | ||
86 | .flags = IORESOURCE_MEM, | ||
87 | }, | ||
88 | { | ||
89 | .start = 0x200, | ||
90 | .end = 0x2ff, | ||
91 | .flags = IORESOURCE_MEM, | ||
92 | }, | ||
93 | { | ||
94 | .start = 0, | ||
95 | .end = 0, | ||
96 | .flags = IORESOURCE_IRQ, | ||
97 | }, | ||
98 | }; | ||
99 | 127 | ||
100 | static struct mfd_cell tc6387xb_cells[] = { | 128 | static struct mfd_cell tc6387xb_cells[] = { |
101 | [TC6387XB_CELL_MMC] = { | 129 | [TC6387XB_CELL_MMC] = { |
@@ -111,8 +139,9 @@ static struct mfd_cell tc6387xb_cells[] = { | |||
111 | static int tc6387xb_probe(struct platform_device *dev) | 139 | static int tc6387xb_probe(struct platform_device *dev) |
112 | { | 140 | { |
113 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; | 141 | struct tc6387xb_platform_data *pdata = dev->dev.platform_data; |
114 | struct resource *iomem; | 142 | struct resource *iomem, *rscr; |
115 | struct clk *clk32k; | 143 | struct clk *clk32k; |
144 | struct tc6387xb *tc6387xb; | ||
116 | int irq, ret; | 145 | int irq, ret; |
117 | 146 | ||
118 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); | 147 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
@@ -120,18 +149,40 @@ static int tc6387xb_probe(struct platform_device *dev) | |||
120 | return -EINVAL; | 149 | return -EINVAL; |
121 | } | 150 | } |
122 | 151 | ||
152 | tc6387xb = kzalloc(sizeof *tc6387xb, GFP_KERNEL); | ||
153 | if (!tc6387xb) | ||
154 | return -ENOMEM; | ||
155 | |||
123 | ret = platform_get_irq(dev, 0); | 156 | ret = platform_get_irq(dev, 0); |
124 | if (ret >= 0) | 157 | if (ret >= 0) |
125 | irq = ret; | 158 | irq = ret; |
126 | else | 159 | else |
127 | goto err_resource; | 160 | goto err_no_irq; |
128 | 161 | ||
129 | clk32k = clk_get(&dev->dev, "CLK_CK32K"); | 162 | clk32k = clk_get(&dev->dev, "CLK_CK32K"); |
130 | if (IS_ERR(clk32k)) { | 163 | if (IS_ERR(clk32k)) { |
131 | ret = PTR_ERR(clk32k); | 164 | ret = PTR_ERR(clk32k); |
165 | goto err_no_clk; | ||
166 | } | ||
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) | ||
132 | goto err_resource; | 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; | ||
133 | } | 182 | } |
134 | platform_set_drvdata(dev, clk32k); | 183 | |
184 | tc6387xb->clk32k = clk32k; | ||
185 | platform_set_drvdata(dev, tc6387xb); | ||
135 | 186 | ||
136 | if (pdata && pdata->enable) | 187 | if (pdata && pdata->enable) |
137 | pdata->enable(dev); | 188 | pdata->enable(dev); |
@@ -149,8 +200,13 @@ static int tc6387xb_probe(struct platform_device *dev) | |||
149 | if (!ret) | 200 | if (!ret) |
150 | return 0; | 201 | return 0; |
151 | 202 | ||
152 | clk_put(clk32k); | 203 | err_ioremap: |
204 | release_resource(&tc6387xb->rscr); | ||
153 | err_resource: | 205 | err_resource: |
206 | clk_put(clk32k); | ||
207 | err_no_clk: | ||
208 | err_no_irq: | ||
209 | kfree(tc6387xb); | ||
154 | return ret; | 210 | return ret; |
155 | } | 211 | } |
156 | 212 | ||
@@ -195,3 +251,4 @@ MODULE_DESCRIPTION("Toshiba TC6387XB core driver"); | |||
195 | MODULE_LICENSE("GPL v2"); | 251 | MODULE_LICENSE("GPL v2"); |
196 | MODULE_AUTHOR("Ian Molton"); | 252 | MODULE_AUTHOR("Ian Molton"); |
197 | MODULE_ALIAS("platform:tc6387xb"); | 253 | MODULE_ALIAS("platform:tc6387xb"); |
254 | |||