aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/htc-pasic3.c
diff options
context:
space:
mode:
authorPhilipp Zabel <philipp.zabel@gmail.com>2009-02-17 04:06:45 -0500
committerSamuel Ortiz <samuel@sortiz.org>2009-04-04 18:32:21 -0400
commit0254a8f496f9c939d4068613ace4ffd0d9e6ece2 (patch)
tree0807d9ef298a4022bd76a072806ca008598d3497 /drivers/mfd/htc-pasic3.c
parenta23a175795cdb202619ac176129b2f0c2a5c9456 (diff)
mfd: convert PASIC3 to use MFD core
This patch makes htc-pasic3 register the DS1WM and LED cell drivers through the MFD core infrastructure instead of allocating the platform devices manually. It also calculates the bus_shift parameter from the memory resource size. Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com> Signed-off-by: Samuel Ortiz <sameo@openedhand.com>
Diffstat (limited to 'drivers/mfd/htc-pasic3.c')
-rw-r--r--drivers/mfd/htc-pasic3.c159
1 files changed, 61 insertions, 98 deletions
diff --git a/drivers/mfd/htc-pasic3.c b/drivers/mfd/htc-pasic3.c
index 91b294dcc133..92b683790ad8 100644
--- a/drivers/mfd/htc-pasic3.c
+++ b/drivers/mfd/htc-pasic3.c
@@ -12,18 +12,17 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14 14
15#include <linux/ds1wm.h>
16#include <linux/gpio.h> 15#include <linux/gpio.h>
17#include <linux/io.h> 16#include <linux/io.h>
18#include <linux/irq.h> 17#include <linux/irq.h>
19#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/mfd/core.h>
20#include <linux/mfd/ds1wm.h>
20#include <linux/mfd/htc-pasic3.h> 21#include <linux/mfd/htc-pasic3.h>
21 22
22struct pasic3_data { 23struct pasic3_data {
23 void __iomem *mapping; 24 void __iomem *mapping;
24 unsigned int bus_shift; 25 unsigned int bus_shift;
25 struct platform_device *ds1wm_pdev;
26 struct platform_device *led_pdev;
27}; 26};
28 27
29#define REG_ADDR 5 28#define REG_ADDR 5
@@ -65,46 +64,15 @@ EXPORT_SYMBOL(pasic3_read_register); /* for leds-pasic3 */
65 * LEDs 64 * LEDs
66 */ 65 */
67 66
68static int led_device_add(struct device *pasic3_dev, 67static struct mfd_cell led_cell __initdata = {
69 const struct pasic3_leds_machinfo *pdata) 68 .name = "leds-pasic3",
70{ 69};
71 struct pasic3_data *asic = pasic3_dev->driver_data;
72 struct platform_device *pdev;
73 int ret;
74
75 pdev = platform_device_alloc("pasic3-led", -1);
76 if (!pdev) {
77 dev_dbg(pasic3_dev, "failed to allocate LED platform device\n");
78 return -ENOMEM;
79 }
80
81 ret = platform_device_add_data(pdev, pdata,
82 sizeof(struct pasic3_leds_machinfo));
83 if (ret < 0) {
84 dev_dbg(pasic3_dev, "failed to add LED platform data\n");
85 goto exit_pdev_put;
86 }
87
88 pdev->dev.parent = pasic3_dev;
89 ret = platform_device_add(pdev);
90 if (ret < 0) {
91 dev_dbg(pasic3_dev, "failed to add LED platform device\n");
92 goto exit_pdev_put;
93 }
94
95 asic->led_pdev = pdev;
96 return 0;
97
98exit_pdev_put:
99 platform_device_put(pdev);
100 return ret;
101}
102 70
103/* 71/*
104 * DS1WM 72 * DS1WM
105 */ 73 */
106 74
107static void ds1wm_enable(struct platform_device *pdev) 75static int ds1wm_enable(struct platform_device *pdev)
108{ 76{
109 struct device *dev = pdev->dev.parent; 77 struct device *dev = pdev->dev.parent;
110 int c; 78 int c;
@@ -113,9 +81,10 @@ static void ds1wm_enable(struct platform_device *pdev)
113 pasic3_write_register(dev, 0x28, c & 0x7f); 81 pasic3_write_register(dev, 0x28, c & 0x7f);
114 82
115 dev_dbg(dev, "DS1WM OWM_EN low (active) %02x\n", c & 0x7f); 83 dev_dbg(dev, "DS1WM OWM_EN low (active) %02x\n", c & 0x7f);
84 return 0;
116} 85}
117 86
118static void ds1wm_disable(struct platform_device *pdev) 87static int ds1wm_disable(struct platform_device *pdev)
119{ 88{
120 struct device *dev = pdev->dev.parent; 89 struct device *dev = pdev->dev.parent;
121 int c; 90 int c;
@@ -124,56 +93,33 @@ static void ds1wm_disable(struct platform_device *pdev)
124 pasic3_write_register(dev, 0x28, c | 0x80); 93 pasic3_write_register(dev, 0x28, c | 0x80);
125 94
126 dev_dbg(dev, "DS1WM OWM_EN high (inactive) %02x\n", c | 0x80); 95 dev_dbg(dev, "DS1WM OWM_EN high (inactive) %02x\n", c | 0x80);
96 return 0;
127} 97}
128 98
129static struct ds1wm_platform_data ds1wm_pdata = { 99static struct ds1wm_driver_data ds1wm_pdata = {
130 .bus_shift = 2, 100 .active_high = 0,
131 .enable = ds1wm_enable,
132 .disable = ds1wm_disable,
133}; 101};
134 102
135static int ds1wm_device_add(struct platform_device *pasic3_pdev, int bus_shift) 103static struct resource ds1wm_resources[] __initdata = {
136{ 104 [0] = {
137 struct device *pasic3_dev = &pasic3_pdev->dev; 105 .start = 0,
138 struct pasic3_data *asic = pasic3_dev->driver_data; 106 .flags = IORESOURCE_MEM,
139 struct platform_device *pdev; 107 },
140 int ret; 108 [1] = {
141 109 .start = 0,
142 pdev = platform_device_alloc("ds1wm", -1); 110 .end = 0,
143 if (!pdev) { 111 .flags = IORESOURCE_IRQ,
144 dev_dbg(pasic3_dev, "failed to allocate DS1WM platform device\n"); 112 },
145 return -ENOMEM; 113};
146 }
147
148 ret = platform_device_add_resources(pdev, pasic3_pdev->resource,
149 pasic3_pdev->num_resources);
150 if (ret < 0) {
151 dev_dbg(pasic3_dev, "failed to add DS1WM resources\n");
152 goto exit_pdev_put;
153 }
154
155 ds1wm_pdata.bus_shift = asic->bus_shift;
156 ret = platform_device_add_data(pdev, &ds1wm_pdata,
157 sizeof(struct ds1wm_platform_data));
158 if (ret < 0) {
159 dev_dbg(pasic3_dev, "failed to add DS1WM platform data\n");
160 goto exit_pdev_put;
161 }
162
163 pdev->dev.parent = pasic3_dev;
164 ret = platform_device_add(pdev);
165 if (ret < 0) {
166 dev_dbg(pasic3_dev, "failed to add DS1WM platform device\n");
167 goto exit_pdev_put;
168 }
169
170 asic->ds1wm_pdev = pdev;
171 return 0;
172 114
173exit_pdev_put: 115static struct mfd_cell ds1wm_cell __initdata = {
174 platform_device_put(pdev); 116 .name = "ds1wm",
175 return ret; 117 .enable = ds1wm_enable,
176} 118 .disable = ds1wm_disable,
119 .driver_data = &ds1wm_pdata,
120 .num_resources = 2,
121 .resources = ds1wm_resources,
122};
177 123
178static int __init pasic3_probe(struct platform_device *pdev) 124static int __init pasic3_probe(struct platform_device *pdev)
179{ 125{
@@ -182,12 +128,27 @@ static int __init pasic3_probe(struct platform_device *pdev)
182 struct pasic3_data *asic; 128 struct pasic3_data *asic;
183 struct resource *r; 129 struct resource *r;
184 int ret; 130 int ret;
131 int irq = 0;
132
133 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
134 if (r) {
135 ds1wm_resources[1].flags = IORESOURCE_IRQ | (r->flags &
136 (IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE));
137 irq = r->start;
138 }
139
140 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
141 if (r) {
142 ds1wm_resources[1].flags = IORESOURCE_IRQ | (r->flags &
143 (IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE));
144 irq = r->start;
145 }
185 146
186 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 147 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
187 if (!r) 148 if (!r)
188 return -ENXIO; 149 return -ENXIO;
189 150
190 if (!request_mem_region(r->start, r->end - r->start + 1, "pasic3")) 151 if (!request_mem_region(r->start, resource_size(r), "pasic3"))
191 return -EBUSY; 152 return -EBUSY;
192 153
193 asic = kzalloc(sizeof(struct pasic3_data), GFP_KERNEL); 154 asic = kzalloc(sizeof(struct pasic3_data), GFP_KERNEL);
@@ -196,24 +157,29 @@ static int __init pasic3_probe(struct platform_device *pdev)
196 157
197 platform_set_drvdata(pdev, asic); 158 platform_set_drvdata(pdev, asic);
198 159
199 if (pdata && pdata->bus_shift) 160 asic->mapping = ioremap(r->start, resource_size(r));
200 asic->bus_shift = pdata->bus_shift;
201 else
202 asic->bus_shift = 2;
203
204 asic->mapping = ioremap(r->start, r->end - r->start + 1);
205 if (!asic->mapping) { 161 if (!asic->mapping) {
206 dev_err(dev, "couldn't ioremap PASIC3\n"); 162 dev_err(dev, "couldn't ioremap PASIC3\n");
207 kfree(asic); 163 kfree(asic);
208 return -ENOMEM; 164 return -ENOMEM;
209 } 165 }
210 166
211 ret = ds1wm_device_add(pdev, asic->bus_shift); 167 /* calculate bus shift from mem resource */
168 asic->bus_shift = (resource_size(r) - 5) >> 3;
169
170 /* the first 5 PASIC3 registers control the DS1WM */
171 ds1wm_resources[0].end = (5 << asic->bus_shift) - 1;
172 ds1wm_cell.platform_data = &ds1wm_cell;
173 ds1wm_cell.data_size = sizeof(ds1wm_cell);
174 ret = mfd_add_devices(&pdev->dev, pdev->id, &ds1wm_cell, 1, r, irq);
212 if (ret < 0) 175 if (ret < 0)
213 dev_warn(dev, "failed to register DS1WM\n"); 176 dev_warn(dev, "failed to register DS1WM\n");
214 177
215 if (pdata->led_pdata) { 178 if (pdata->led_pdata) {
216 ret = led_device_add(dev, pdata->led_pdata); 179 led_cell.driver_data = pdata->led_pdata;
180 led_cell.platform_data = &led_cell;
181 led_cell.data_size = sizeof(ds1wm_cell);
182 ret = mfd_add_devices(&pdev->dev, pdev->id, &led_cell, 1, r, 0);
217 if (ret < 0) 183 if (ret < 0)
218 dev_warn(dev, "failed to register LED device\n"); 184 dev_warn(dev, "failed to register LED device\n");
219 } 185 }
@@ -226,14 +192,11 @@ static int pasic3_remove(struct platform_device *pdev)
226 struct pasic3_data *asic = platform_get_drvdata(pdev); 192 struct pasic3_data *asic = platform_get_drvdata(pdev);
227 struct resource *r; 193 struct resource *r;
228 194
229 if (asic->led_pdev) 195 mfd_remove_devices(&pdev->dev);
230 platform_device_unregister(asic->led_pdev);
231 if (asic->ds1wm_pdev)
232 platform_device_unregister(asic->ds1wm_pdev);
233 196
234 iounmap(asic->mapping); 197 iounmap(asic->mapping);
235 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 198 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
236 release_mem_region(r->start, r->end - r->start + 1); 199 release_mem_region(r->start, resource_size(r));
237 kfree(asic); 200 kfree(asic);
238 return 0; 201 return 0;
239} 202}