User Tools

Site Tools


devm_ioremap_resource

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
devm_ioremap_resource [2018/07/30 16:38]
rpjday [Broadcom Cygnus]
devm_ioremap_resource [2018/07/31 10:54]
rpjday [platform_get_resource()]
Line 1: Line 1:
 ===== Overview ===== ===== Overview =====
  
-Explain ''​devm_ioremap_resource()'',​ with examples. Add some links.+Explain ''​devm_ioremap_resource()'',​ with examples ​particularly related to memory regions. Add some links.
  
-===== Let's talk about resources ===== +===== struct resource ​=====
- +
-==== struct resource ====+
  
 From ''​include/​linux/​ioport.h'',​ a device can have a number of resources of different types: From ''​include/​linux/​ioport.h'',​ a device can have a number of resources of different types:
Line 24: Line 22:
 </​code>​ </​code>​
  
- +In particular, one resource ​type is a memory range (''​flags''​ of ''​IORESOURCE_MEM''​):​
-A small sample of resource ​types from that same file (''​IORESOURCE_MEM'' ​is the one representing physical memory that many drivers are interested in):+
  
 <​code>​ <​code>​
Line 40: Line 37:
 </​code>​ </​code>​
  
-==== struct platform_device ====+Here's a single example from ''​arch/​arm/​mach-davinci/​dm355.c'',​ defining an array of resources:
  
-From ''​include/​linux/​platform_device.h'':​+<​code>​ 
 +static struct resource edma_resources[] = { 
 +        { 
 +                .name   = "​edma3_cc",​ 
 +                .start ​ = 0x01c00000,​ 
 +                .end    = 0x01c00000 + SZ_64K - 1, 
 +                .flags ​ = IORESOURCE_MEM,​ 
 +        }, 
 +        { 
 +                .name   = "​edma3_tc0",​ 
 +                .start ​ = 0x01c10000,​ 
 +                .end    = 0x01c10000 + SZ_1K - 1, 
 +                .flags ​ = IORESOURCE_MEM,​ 
 +        }, 
 +        { 
 +                .name   = "​edma3_tc1",​ 
 +                .start ​ = 0x01c10400,​ 
 +                .end    = 0x01c10400 + SZ_1K - 1, 
 +                .flags ​ = IORESOURCE_MEM,​ 
 +        }, 
 +        ... snip ... 
 +</​code>​ 
 +===== struct platform_device ===== 
 + 
 +From ''​include/​linux/​platform_device.h''​, showing how a ''​platform_device''​ can represent any number of resources:
  
 <​code>​ <​code>​
Line 72: Line 93:
 ===== platform_get_resource() ===== ===== platform_get_resource() =====
  
-From ''​drivers/​base/​platform.c'',​ given a platform device ​and a resource type, return that resource type or ''​NULL'':​+From ''​drivers/​base/​platform.c'',​ given a ''​struct platform_device *dev'' ​and a resource type, return that (numbered) ​resource type or ''​NULL'':​
  
 <​code>​ <​code>​
Line 201: Line 222:
 </​code>​ </​code>​
  
 +Also:
 +
 +<​code>​
 +regs = platform_get_resource_byname(pdev,​ IORESOURCE_MEM,​ "​amac_base"​);​
 +if (!regs) {
 +        dev_err(&​pdev->​dev,​ "​Unable to obtain base resource\n"​);​
 +        return -EINVAL;
 +}
 +
 +bgmac->​plat.base = devm_ioremap_resource(&​pdev->​dev,​ regs);
 +if (IS_ERR(bgmac->​plat.base))
 +        return PTR_ERR(bgmac->​plat.base);​
 +
 +regs = platform_get_resource_byname(pdev,​ IORESOURCE_MEM,​ "​idm_base"​);​
 +if (regs) {
 +        bgmac->​plat.idm_base = devm_ioremap_resource(&​pdev->​dev,​ regs);
 +        if (IS_ERR(bgmac->​plat.idm_base))
 +                return PTR_ERR(bgmac->​plat.idm_base);​
 +        bgmac->​feature_flags &= ~BGMAC_FEAT_IDM_MASK;​
 +}
 +</​code>​
devm_ioremap_resource.txt · Last modified: 2018/07/31 11:59 by rpjday