diff options
Diffstat (limited to 'drivers/gpio/gpio-pl061.c')
-rw-r--r-- | drivers/gpio/gpio-pl061.c | 66 |
1 files changed, 23 insertions, 43 deletions
diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c index b4b5da4fd2cc..c1720de18a4f 100644 --- a/drivers/gpio/gpio-pl061.c +++ b/drivers/gpio/gpio-pl061.c | |||
@@ -48,12 +48,7 @@ struct pl061_context_save_regs { | |||
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | struct pl061_gpio { | 50 | struct pl061_gpio { |
51 | /* Each of the two spinlocks protects a different set of hardware | 51 | spinlock_t lock; |
52 | * regiters and data structurs. This decouples the code of the IRQ from | ||
53 | * the GPIO code. This also makes the case of a GPIO routine call from | ||
54 | * the IRQ code simpler. | ||
55 | */ | ||
56 | spinlock_t lock; /* GPIO registers */ | ||
57 | 52 | ||
58 | void __iomem *base; | 53 | void __iomem *base; |
59 | int irq_base; | 54 | int irq_base; |
@@ -216,39 +211,34 @@ static void __init pl061_init_gc(struct pl061_gpio *chip, int irq_base) | |||
216 | IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); | 211 | IRQ_GC_INIT_NESTED_LOCK, IRQ_NOREQUEST, 0); |
217 | } | 212 | } |
218 | 213 | ||
219 | static int pl061_probe(struct amba_device *dev, const struct amba_id *id) | 214 | static int pl061_probe(struct amba_device *adev, const struct amba_id *id) |
220 | { | 215 | { |
221 | struct pl061_platform_data *pdata; | 216 | struct device *dev = &adev->dev; |
217 | struct pl061_platform_data *pdata = dev->platform_data; | ||
222 | struct pl061_gpio *chip; | 218 | struct pl061_gpio *chip; |
223 | int ret, irq, i; | 219 | int ret, irq, i; |
224 | 220 | ||
225 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 221 | chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); |
226 | if (chip == NULL) | 222 | if (chip == NULL) |
227 | return -ENOMEM; | 223 | return -ENOMEM; |
228 | 224 | ||
229 | pdata = dev->dev.platform_data; | ||
230 | if (pdata) { | 225 | if (pdata) { |
231 | chip->gc.base = pdata->gpio_base; | 226 | chip->gc.base = pdata->gpio_base; |
232 | chip->irq_base = pdata->irq_base; | 227 | chip->irq_base = pdata->irq_base; |
233 | } else if (dev->dev.of_node) { | 228 | } else if (adev->dev.of_node) { |
234 | chip->gc.base = -1; | 229 | chip->gc.base = -1; |
235 | chip->irq_base = 0; | 230 | chip->irq_base = 0; |
236 | } else { | 231 | } else |
237 | ret = -ENODEV; | 232 | return -ENODEV; |
238 | goto free_mem; | ||
239 | } | ||
240 | 233 | ||
241 | if (!request_mem_region(dev->res.start, | 234 | if (!devm_request_mem_region(dev, adev->res.start, |
242 | resource_size(&dev->res), "pl061")) { | 235 | resource_size(&adev->res), "pl061")) |
243 | ret = -EBUSY; | 236 | return -EBUSY; |
244 | goto free_mem; | ||
245 | } | ||
246 | 237 | ||
247 | chip->base = ioremap(dev->res.start, resource_size(&dev->res)); | 238 | chip->base = devm_ioremap(dev, adev->res.start, |
248 | if (chip->base == NULL) { | 239 | resource_size(&adev->res)); |
249 | ret = -ENOMEM; | 240 | if (chip->base == NULL) |
250 | goto release_region; | 241 | return -ENOMEM; |
251 | } | ||
252 | 242 | ||
253 | spin_lock_init(&chip->lock); | 243 | spin_lock_init(&chip->lock); |
254 | 244 | ||
@@ -258,13 +248,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id) | |||
258 | chip->gc.set = pl061_set_value; | 248 | chip->gc.set = pl061_set_value; |
259 | chip->gc.to_irq = pl061_to_irq; | 249 | chip->gc.to_irq = pl061_to_irq; |
260 | chip->gc.ngpio = PL061_GPIO_NR; | 250 | chip->gc.ngpio = PL061_GPIO_NR; |
261 | chip->gc.label = dev_name(&dev->dev); | 251 | chip->gc.label = dev_name(dev); |
262 | chip->gc.dev = &dev->dev; | 252 | chip->gc.dev = dev; |
263 | chip->gc.owner = THIS_MODULE; | 253 | chip->gc.owner = THIS_MODULE; |
264 | 254 | ||
265 | ret = gpiochip_add(&chip->gc); | 255 | ret = gpiochip_add(&chip->gc); |
266 | if (ret) | 256 | if (ret) |
267 | goto iounmap; | 257 | return ret; |
268 | 258 | ||
269 | /* | 259 | /* |
270 | * irq_chip support | 260 | * irq_chip support |
@@ -276,11 +266,10 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id) | |||
276 | pl061_init_gc(chip, chip->irq_base); | 266 | pl061_init_gc(chip, chip->irq_base); |
277 | 267 | ||
278 | writeb(0, chip->base + GPIOIE); /* disable irqs */ | 268 | writeb(0, chip->base + GPIOIE); /* disable irqs */ |
279 | irq = dev->irq[0]; | 269 | irq = adev->irq[0]; |
280 | if (irq < 0) { | 270 | if (irq < 0) |
281 | ret = -ENODEV; | 271 | return -ENODEV; |
282 | goto iounmap; | 272 | |
283 | } | ||
284 | irq_set_chained_handler(irq, pl061_irq_handler); | 273 | irq_set_chained_handler(irq, pl061_irq_handler); |
285 | irq_set_handler_data(irq, chip); | 274 | irq_set_handler_data(irq, chip); |
286 | 275 | ||
@@ -294,18 +283,9 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id) | |||
294 | } | 283 | } |
295 | } | 284 | } |
296 | 285 | ||
297 | amba_set_drvdata(dev, chip); | 286 | amba_set_drvdata(adev, chip); |
298 | 287 | ||
299 | return 0; | 288 | return 0; |
300 | |||
301 | iounmap: | ||
302 | iounmap(chip->base); | ||
303 | release_region: | ||
304 | release_mem_region(dev->res.start, resource_size(&dev->res)); | ||
305 | free_mem: | ||
306 | kfree(chip); | ||
307 | |||
308 | return ret; | ||
309 | } | 289 | } |
310 | 290 | ||
311 | #ifdef CONFIG_PM | 291 | #ifdef CONFIG_PM |