blob: 8df55fc3aad675fbafac0c2b561f01ef97700a72 [file] [log] [blame]
Emil Medveb41e5ff2008-05-03 06:34:04 +10001/*
2 * Copyright (C) 2008 Freescale Semiconductor, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */
9
10#include <linux/device.h> /* devres_*(), devm_ioremap_release() */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/gfp.h>
Anton Blanchard40f1ce72011-05-08 21:43:47 +000012#include <linux/io.h> /* ioremap_prot() */
Paul Gortmaker4b16f8e2011-07-22 18:24:23 -040013#include <linux/export.h> /* EXPORT_SYMBOL() */
Emil Medveb41e5ff2008-05-03 06:34:04 +100014
15/**
Anton Blanchard40f1ce72011-05-08 21:43:47 +000016 * devm_ioremap_prot - Managed ioremap_prot()
Emil Medveb41e5ff2008-05-03 06:34:04 +100017 * @dev: Generic device to remap IO address for
18 * @offset: BUS offset to map
19 * @size: Size of map
20 * @flags: Page flags
21 *
22 * Managed ioremap_prot(). Map is automatically unmapped on driver
23 * detach.
24 */
25void __iomem *devm_ioremap_prot(struct device *dev, resource_size_t offset,
26 size_t size, unsigned long flags)
27{
28 void __iomem **ptr, *addr;
29
30 ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
31 if (!ptr)
32 return NULL;
33
Anton Blanchard40f1ce72011-05-08 21:43:47 +000034 addr = ioremap_prot(offset, size, flags);
Emil Medveb41e5ff2008-05-03 06:34:04 +100035 if (addr) {
36 *ptr = addr;
37 devres_add(dev, ptr);
38 } else
39 devres_free(ptr);
40
41 return addr;
42}
43EXPORT_SYMBOL(devm_ioremap_prot);