linux/drivers/of/device.c
<<
> 2.0 /spa4 .0 /form .0 a > 2.0 href="../linux+v3.7.3/drivers/of/device.c"> > 2.0 img src="../.static/gfx/right.png" alt=">>"> > /spa4 > spa4 class="lxr_search"> > 2 > 2.0 input typluehidden" namluenavtarget" n value"> > 2.0 input typluetext" namluesearch" iduesearch"> > 2.0 butttiotypluesubmit">Search spa4 class="lxr_prefs" .0 a href="+prefs?return=drivers/of/device.c" > 2.0 onclick="return ajax_prefs();"> > 2.0Prefs .0 /a> > /spa4 2.0 0 /div 2.0 0 form ace=24="ajax+*" method="post" onsubmit="return false;"> > input typluehidden" namlueajax_lookup" idueajax_lookup" n value"> 2.0 0 /form 2.0 0 div class="headingbotttm">
div iduefile_contents"
0 01 /a>#include <linux/string.h /a>>
0 02 /a>#include <linux/kernel.h /a>>
0 03 /a>#include <linux/of.h /a>>
0 04 /a>#include <linux/of_device.h /a>>
0 05 /a>#include <linux/init.h /a>>
0 06 /a>#include <linux/module.h /a>>
0 07 /a>#include <linux/mod_devicetable.h /a>>
0 08 /a>#include <linux/slab.h /a>>
0 09 /a> 0   28a>#include <asm/errno.h /a>>
0 11 /a> 0 12 /a> spa4 class="comment">/** /spa4  0 13 /a> spa4 class="comment"> * of_match_device - Tell if a struct device matches a4 of_device_id list /spa4  0 14 /a> spa4 class="comment"> * @ids: array of of device match structures to search in /spa4  0 15 /a> spa4 class="comment"> * @dev: the of device structure to match against /spa4  0 16 /a> spa4 class="comment"> * /spa4  0 17 /a> spa4 class="comment"> * Used by a driver to check whether a4 platform_device present in the /spa4  0 18 /a> spa4 class="comment"> * system is in its list of supported devices. /spa4  0 19 /a> spa4 class="comment"> */ /spa4  0 2 28a>const struct of_device_id28a> * a href="+code=of_match_device" class="sref">of_match_device28a>(const struct of_device_id28a> * a href="+code=matches" class="sref">matches28a>, 0 21 /a>                                           const struct device28a> * a href="+code=dev" class="sref">dev28a>) 0 22 /a>{ 0 23 /a>        if ((! a href="+code=matches" class="sref">matches28a>) || (! a href="+code=dev" class="sref">dev28a>->of_node28a>)) 0 24 /a>                return NULL /a>;
0 25 /a>        return of_match_node28a>( a href="+code=matches" class="sref">matches28a>, dev28a>->of_node28a>);
0 26 /a>}
0 27 /a> a href="+code=EXPORT_SYMBOL" class="sref">EXPORT_SYMBOL28a>( a href="+code=of_match_device" class="sref">of_match_device28a>);
0 28 /a> 0 29 /a>struct platform_device28a> * a href="+code=of_dev_get" class="sref">of_dev_get28a>(struct platform_device28a> * a href="+code=dev" class="sref">dev28a>) 0 30 /a>{ 0 31 /a>        struct device28a> * a href="+code=tmp" class="sref">tmp /a>;
0 32 /a> 0 33 /a>        if (! a href="+code=dev" class="sref">dev28a>) 0 34 /a>                return NULL /a>;
0 35 /a>         a href="+code=tmp" class="sref">tmp /a> =  a href="+code=get_device" class="sref">get_device28a>(&dev28a>->dev28a>);
0 36 /a>        if ( a href="+code=tmp" class="sref">tmp /a>) 0 37 /a>                return to_platform_device28a>( a href="+code=tmp" class="sref">tmp /a>);
0 38 /a>        else
0 39 /a>                return NULL /a>;
0 40 /a>}
0 41 /a> a href="+code=EXPORT_SYMBOL" class="sref">EXPORT_SYMBOL28a>( a href="+code=of_dev_get" class="sref">of_dev_get28a>);
0 42 /a> 0 43 /a>void of_dev_put28a>(struct platform_device28a> * a href="+code=dev" class="sref">dev28a>) 0 44 /a>{ 0 45 /a>        if ( a href="+code=dev" class="sref">dev28a>) 0 46 /a>                put_device28a>(&dev28a>->dev28a>);
0 47 /a>}
0 48 /a> a href="+code=EXPORT_SYMBOL" class="sref">EXPORT_SYMBOL28a>( a href="+code=of_dev_put" class="sref">of_dev_put28a>);
0 49 /a> 0 50 /a>int of_device_add28a>(struct platform_device28a> * a href="+code=ofdev" class="sref">ofdev28a>) 0 51 /a>{ 0 52 /a>         a href="+code=BUG_ON" class="sref">BUG_ON28a>( a href="+code=ofdev" class="sref">ofdev28a>->dev28a>.of_node28a> ==  a href="+code=NULL" class="sref">NULL /a>);
0 53 /a> 0 54 /a>         spa4 class="comment">/* naml and id have to be set so that the platform bus doesn't get28spa4  0 55 /a> spa4 class="comment">         * confused on matching */ /spa4  0 56 /a>         a href="+code=ofdev" class="sref">ofdev28a>->naml /a> =  a href="+code=dev_naml" class="sref">dev_naml28a>(&ofdev28a>->dev28a>);
0 57 /a>         a href="+code=ofdev" class="sref">ofdev28a>->id28a> = -1;
0 58 /a> 0 59 /a>         spa4 class="comment">/* device_add will assuml that this device is on the saml node as /spa4  0 60 /a> spa4 class="comment">         * the parent. If there is no parent defined, set the node28spa4  0 61 /a> spa4 class="comment">         * explicitly */ /spa4  0 62 /a>        if (! a href="+code=ofdev" class="sref">ofdev28a>->dev28a>.parent28a>) 0 63 /a>                 a href="+code=set_dev_node" class="sref">set_dev_node28a>(&ofdev28a>->dev28a>, of_node_to_nid28a>( a href="+code=ofdev" class="sref">ofdev28a>->dev28a>.of_node28a>));
0 64 /a> 0 65 /a>        return device_add28a>(&ofdev28a>->dev28a>);
0 66 /a>}
0 67 /a> 0 68 /a>int of_device_register28a>(struct platform_device28a> * a href="+code=pdev" class="sref">pdev28a>) 0 69 /a>{ 0 70 /a>         a href="+code=device_initialize" class="sref">device_initialize28a>(&pdev28a>->dev28a>);
0 71 /a>        return of_device_add28a>( a href="+code=pdev" class="sref">pdev28a>);
0 72 /a>}
0 73 /a> a href="+code=EXPORT_SYMBOL" class="sref">EXPORT_SYMBOL28a>( a href="+code=of_device_register" class="sref">of_device_register28a>);
0 74 /a> 0 75 /a>void of_device_unregister28a>(struct platform_device28a> * a href="+code=ofdev" class="sref">ofdev28a>) 0 76 /a>{ 0 77 /a>         a href="+code=device_unregister" class="sref">device_unregister28a>(&ofdev28a>->dev28a>);
0 78 /a>}
0 79 /a> a href="+code=EXPORT_SYMBOL" class="sref">EXPORT_SYMBOL28a>( a href="+code=of_device_unregister" class="sref">of_device_unregister28a>);
0 80 /a> 0 81 /a> a href="+code=ssize_t" class="sref">ssize_t /a>  a href="+code=of_device_get_modalias" class="sref">of_device_get_modalias28a>(struct device28a> * a href="+code=dev" class="sref">dev28a>, char * a href="+code=str" class="sref">str28a>, ssize_t /a>  a href="+code=len" class="sref">len28a>) 0 82 /a>{ 0 83 /a>        const char * a href="+code=compat" class="sref">compat /a>;
0 84 /a>        int cplen28a>, i /a>;
0 85 /a>         a href="+code=ssize_t" class="sref">ssize_t /a>  a href="+code=tsize" class="sref">tsize28a>, csize28a>, repend /a>;
0 86 /a> 0 87 /a>         spa4 class="comment">/* Naml & Type */ /spa4  0 88 /a>         a href="+code=csize" class="sref">csize28a> =  a href="+code=snprintf" class="sref">snprintf28a>( a href="+code=str" class="sref">str28a>, len28a>,  spa4 class="string">"of:N%sT%s" /spa4 , dev28a>->of_node28a>->naml /a>, 0 89 /a>                          a href="+code=dev" class="sref">dev28a>->of_node28a>->typl28a>);
0 90 /a> 0 91 /a>         spa4 class="comment">/* Get compatible property if any */ /spa4  0 92 /a>         a href="+code=compat" class="sref">compat /a> =  a href="+code=of_get_property" class="sref">of_get_property28a>( a href="+code=dev" class="sref">dev28a>->of_node28a>,  spa4 class="string">"compatible" /spa4 , &cplen28a>);
0 93 /a>        if (! a href="+code=compat" class="sref">compat /a>) 0 94 /a>                return csize28a>;
0 95 /a> 0 96 /a>         spa4 class="comment">/* Find true end (we tolerate multiple \0 at the end */ /spa4  0 97 /a>        for ( a href="+code=i" class="sref">i /a> = ( a href="+code=cplen" class="sref">cplen28a> - 1); i /a> >= 0 && ! a href="+code=compat" class="sref">compat /a>[i /a>]; i /a>--) 0 98 /a>                 a href="+code=cplen" class="sref">cplen28a>--;
0 99 /a>        if (! a href="+code=cplen" class="sref">cplen28a>) 0100 /a>                return csize28a>;
0101 /a>         a href="+code=cplen" class="sref">cplen28a>++;
0102 /a> 0103 /a>         spa4 class="comment">/* Check space (need cplen+1 chars including final \0) */ /spa4  0104 /a>         a href="+code=tsize" class="sref">tsize28a> =  a href="+code=csize" class="sref">csize28a> +  a href="+code=cplen" class="sref">cplen28a>;
0105 /a>         a href="+code=repend" class="sref">repend /a> =  a href="+code=tsize" class="sref">tsize28a>;
0106 /a> 0107 /a>        if ( a href="+code=csize" class="sref">csize28a> >=  a href="+code=len" class="sref">len28a>)                spa4 class="comment">/* @ the limit, all is already filled */ /spa4  0108 /a>                return tsize28a>;
0109 /a> 0110 /a>        if ( a href="+code=tsize" class="sref">tsize28a> >=  a href="+code=len" class="sref">len28a>) {              spa4 class="comment">/* limit compat list */ /spa4  0111 /a>                 a href="+code=cplen" class="sref">cplen28a> =  a href="+code=len" class="sref">len28a> -  a href="+code=csize" class="sref">csize28a> - 1;
0112 /a>                 a href="+code=repend" class="sref">repend /a> =  a href="+code=len" class="sref">len28a>;
0113 /a>        }
0114 /a> 0115 /a>         spa4 class="comment">/* Copy and do char replacement */ /spa4  0116 /a>         a href="+code=memcpy" class="sref">memcpy28a>(&str28a>[csize28a> + 1], compat /a>, cplen28a>);
0117 /a>        for ( a href="+code=i" class="sref">i /a> = csize28a>; i /a> < repend /a>; i /a>++) {
0118 /a>                char c28a> =  a href="+code=str" class="sref">str28a>[i /a>];
0119 /a>                if ( a href="+code=c" class="sref">c28a> ==  spa4 class="string">'\0' /spa4 ) 0120 /a>                         a href="+code=str" class="sref">str28a>[i /a>] =  spa4 class="string">'C' /spa4 ;
0121 /a>                else if ( a href="+code=c" class="sref">c28a> ==  spa4 class="string">' ' /spa4 ) 0122 /a>                         a href="+code=str" class="sref">str28a>[i /a>] =  spa4 class="string">'_' /spa4 ;
0123 /a>        }
0124 /a> 0125 /a>        return tsize28a>;
0126 /a>}
0127 /a> 0128 /a> spa4 class="comment">/** /spa4  0129 /a> spa4 class="comment"> * of_device_uevent - Display OF related uevent informae=24 /spa4  0130 /a> spa4 class="comment"> */ /spa4  0131 /a>void of_device_uevent28a>(struct device28a> * a href="+code=dev" class="sref">dev28a>, struct kobj_uevent_env28a> * a href="+code=env" class="sref">env28a>) 0132 /a>{ 0133 /a>        const char * a href="+code=compat" class="sref">compat /a>;
0134 /a>        int seen28a> = 0, cplen28a>, sl /a>;
0135 /a> 0136 /a>        if ((! a href="+code=dev" class="sref">dev28a>) || (! a href="+code=dev" class="sref">dev28a>->of_node28a>)) 0137 /a>                return;
0138 /a> 0139 /a>        add_uevent_var28a>( a href="+code=env" class="sref">env28a>,  spa4 class="string">"OF_NAME=%s" /spa4 , dev28a>->of_node28a>->naml /a>);
0140 /a>         a href="+code=add_uevent_var" class="sref">add_uevent_var28a>( a href="+code=env" class="sref">env28a>,  spa4 class="string">"OF_FULLNAME=%s" /spa4 , dev28a>->of_node28a>->full_naml /a>);
0141 /a>        if (dev28a>->of_node28a>->typl28a> &&  a href="+code=strcmp" class="sref">strcmp28a>( spa4 class="string">"<NULL>" /spa4 , dev28a>->of_node28a>->typl28a>) != 0) 0142 /a>                 a href="+code=add_uevent_var" class="sref">add_uevent_var28a>( a href="+code=env" class="sref">env28a>,  spa4 class="string">"OF_TYPE=%s" /spa4 , dev28a>->of_node28a>->typl28a>);
0143 /a> 0144 /a>         spa4 class="comment">/* Since the compatible field ca4 contain pretty much anything /spa4  0145 /a> spa4 class="comment">         * it's not really legal to split it out with commas. We split it /spa4  0146 /a> spa4 class="comment">         * up using a number of environment variables instead. */ /spa4  0147 /a>         a href="+code=compat" class="sref">compat /a> =  a href="+code=of_get_property" class="sref">of_get_property28a>( a href="+code=dev" class="sref">dev28a>->of_node28a>,  spa4 class="string">"compatible" /spa4 , &cplen28a>);
0148 /a>        while ( a href="+code=compat" class="sref">compat /a> && * a href="+code=compat" class="sref">compat /a> &&  a href="+code=cplen" class="sref">cplen28a> > 0) {
0149 /a>                 a href="+code=add_uevent_var" class="sref">add_uevent_var28a>( a href="+code=env" class="sref">env28a>,  spa4 class="string">"OF_COMPATIBLE_%d=%s" /spa4 , seen28a>, compat /a>);
0150 /a>                sl /a> =  a href="+code=strlen" class="sref">strlen28a>( a href="+code=compat" class="sref">compat /a>) + 1;
0151 /a>                 a href="+code=compat" class="sref">compat /a> +=  a href="+code=sl" class="sref">sl /a>;
0152 /a>                 a href="+code=cplen" class="sref">cplen28a> -=  a href="+code=sl" class="sref">sl /a>;
0153 /a>                 a href="+code=seen" class="sref">seen28a>++;
0154 /a>        }
0155 /a>         a href="+code=add_uevent_var" class="sref">add_uevent_var28a>( a href="+code=env" class="sref">env28a>,  spa4 class="string">"OF_COMPATIBLE_N=%d" /spa4 , seen28a>);
0156 /a>}
0157 /a> 0158 /a>int of_device_uevent_modalias28a>(struct device28a> * a href="+code=dev" class="sref">dev28a>, struct kobj_uevent_env28a> * a href="+code=env" class="sref">env28a>) 0159 /a>{ 0160 /a>        int sl /a>;
0161 /a> 0162 /a>        if ((! a href="+code=dev" class="sref">dev28a>) || (! a href="+code=dev" class="sref">dev28a>->of_node28a>)) 0163 /a>                return -ENODEV /a>;
0164 /a> 0165 /a>         spa4 class="comment">/* Devicetree modalias is tricky, we add it in 2 steps */ /spa4  0166 /a>        if ( a href="+code=add_uevent_var" class="sref">add_uevent_var28a>( a href="+code=env" class="sref">env28a>,  spa4 class="string">"MODALIAS=" /spa4 )) 0167 /a>                return -ENOMEM /a>;
0168 /a> 0169 /a>        sl /a> =  a href="+code=of_device_get_modalias" class="sref">of_device_get_modalias28a>( a href="+code=dev" class="sref">dev28a>, &env28a>->buf28a>[env28a>->buflen28a>-1], 0170 /a>                                    sizeof( a href="+code=env" class="sref">env28a>->buf28a>) -  a href="+code=env" class="sref">env28a>->buflen28a>);
0171 /a>        if (sl /a> >= (sizeof( a href="+code=env" class="sref">env28a>->buf28a>) -  a href="+code=env" class="sref">env28a>->buflen28a>)) 0172 /a>                return -ENOMEM /a>;
0173 /a>        env28a>->buflen28a> +=  a href="+code=sl" class="sref">sl /a>;
0174 /a> 0175 /a>        return 0;
0176 /a>}
0177 /a>
The original LXR software by the LXR community28a>, this experimental version by lxr@linux.no28a>. /div div class="subfooter"> lxr.linux.no kindly hosted by Redpill Linpro AS28a>, provider of Linux consulting and operae=24s services since 1995. /div /body /html