linux/drivers/bus/omap-ocp2scp.c
<<
>>
Prefs
   1/*
   2 * omap-ocp2scp.c - transform ocp interface protocol to scp protocol
   3 *
   4 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License as published by
   7 * the Free Software Foundation; either version 2 of the License, or
   8 * (at your option) any later version.
   9 *
  10 * Author: Kishon Vijay Abraham I <kishon@ti.com>
  11 *
  12 * This program is distributed in the hope that it will be useful,
  13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 * GNU General Public License for more details.
  16 *
  17 */
  18
  19#include <linux/module.h>
  20#include <linux/platform_device.h>
  21#include <linux/err.h>
  22#include <linux/pm_runtime.h>
  23#include <linux/of.h>
  24#include <linux/of_platform.h>
  25#include <linux/platform_data/omap_ocp2scp.h>
  26
  27/**
  28 * _count_resources - count for the number of resources
  29 * @res: struct resource *
  30 *
  31 * Count and return the number of resources populated for the device that is
  32 * connected to ocp2scp.
  33 */
  34static unsigned _count_resources(struct resource *res)
  35{
  36        int cnt = 0;
  37
  38        while (res->start != res->end) {
  39                cnt++;
  40                res++;
  41        }
  42
  43        return cnt;
  44}
  45
  46static int ocp2scp_remove_devices(struct device *dev, void *c)
  47{
  48        struct platform_device *pdev = to_platform_device(dev);
  49
  50        platform_device_unregister(pdev);
  51
  52        return 0;
  53}
  54
  55static int __devinit omap_ocp2scp_probe(struct platform_device *pdev)
  56{
  57        int ret;
  58        unsigned res_cnt, i;
  59        struct device_node *np = pdev->dev.of_node;
  60        struct platform_device *pdev_child;
  61        struct omap_ocp2scp_platform_data *pdata = pdev->dev.platform_data;
  62        struct omap_ocp2scp_dev *dev;
  63
  64        if (np) {
  65                ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
  66                if (ret) {
  67                        dev_err(&pdev->dev,
  68                            "failed to add resources for ocp2scp child\n");
  69                        goto err0;
  70                }
  71        } else if (pdata) {
  72                for (i = 0, dev = *pdata->devices; i < pdata->dev_cnt; i++,
  73                    dev++) {
  74                        res_cnt = _count_resources(dev->res);
  75
  76                        pdev_child = platform_device_alloc(dev->drv_name,
  77                            PLATFORM_DEVID_AUTO);
  78                        if (!pdev_child) {
  79                                dev_err(&pdev->dev,
  80                                  "failed to allocate mem for ocp2scp child\n");
  81                                goto err0;
  82                        }
  83
  84                        ret = platform_device_add_resources(pdev_child,
  85                            dev->res,   43        return                         ret) {
                            dev_err(&pdev->dev,
   78<8a>                            "failed to add resources for ocp2scp child\n");
                                err0;
                           a href="drivers/bus/omap-ocp2scp.c#L83"9id="L81"9class="line" name="L81"9  81<9a>
                        }
pdev_child,
dev.     =mp;pdev->dev);
a href="drivers/bus/omap-ocp2scp.c#L82"9id="L83"9class="line" name="L83"9  83<9a>
                        ret = platform_device_add_re>(pdev_child,
<                           (ret) {
                        dev_err(&pdev->dev,
                            "failed to addister);
9  78<9a>                            err0;
   79<9a>                           a href="drivers/bus/omap-ocp2scp.c#L83"10id="L10" cclass="line" name="L10">   80>  >                }
01 80> a>        } else if a href="drivers/bus/omap-ocp2scp.c#L67"10id="L12" 0class="line" name="L12">02 80> a>                   href="+code=ret" cr" class="sref">dev_err(&pdev->dev,
"faiOCP2SCP t);
03 80> a>                   urn 0;
-href="+code=devEINVAclass="sref">NULEINVAc>;
04 80> a>           a href="drivers/bus/omap-ocp2scp.c#L71"10id="L15" 0class="line" name="L15">05 80> a>
06 80> a>           href="+code=pdevuntime.h<_enablclass="sref">platuntime.h<_enablc>(&pdev->dev,
<07 80> a>
08 80> a>           urn 0;
09 80> a>
>  101/a>err0;
<: href="drivers/bus/omap-ocp2scp.c#L50"1 id="L11" cclass="line" name="L11"> 1 80>11>           href="+code=pdevform_device_addpu16.2" name="L43"tform_device_addpu1>(pdev_child,
<>  1211a>
>  131/a>err0;
<: href="drivers/bus/omap-ocp2scp.c#L50"1 id="L14"  class="line" name="L14">>  14114>           href="+code=pdeice_addm_d_eachild" class="sref">pdeice_addm_d_eachild" c>(&pdev->dev,
NULL, ocp2scp_remove_devices(st>  1511a>
>  16116>           urn 0;
href="+code=ret" class="sref">ret) {a href="drivers/bus/omap-ocp2scp.c#L69"1 id="L17"  class="line" name="L17">>  171/a>>  181/a>
>  191/a>#intic int __deviniex c>    href="+code=NUL2_ocp2scp_devove_delass="sref">ocp2_ocp2scp_devove_de>(&amuct platform_device *pdev)
  201/a>#ina href="drivers/bus/omap-ocp2scp.c#L67"1 id="L21"1 class="line" name="L21"1>  21121>           href="+code=pdevuntime.h<_disablclass="sref">platuntime.h<_disablc>(&pdev->dev,
<   12122>           href="+code=pdeice_addm_d_eachild" class="sref">pdeice_addm_d_eachild" c>(&pdev->dev,
NULL, ocp2scp_remove_devices(st  2312a>
  24124>           urn 0;
  251/a>#ina href="drivers/bus/omap-ocp2scp.c#L71"1 id="L26"1 class="line" name="L26"1>  261/a>
  271/a>ocpCONFIG_OF>
  281/a>pdepfvice_addic>    href="+code=NUL2_ocp2scp_devid_tablclass="sref">pla2_ocp2scp_devid_tablc>   [] = a href="drivers/bus/omap-ocp2scp.c#L67"1 id="L29"1 class="line" name="L29"1>  2912a>           {  href="+code=placompc iblclass="sref">placompc iblc> = "faiti,p-ocp2scp.c#ot;);
 }a href="drivers/bus/omap-ocp2scp.c#L80"1 id="L30"1 class="line" name="L30"1>  3013 >           {a href="drivers/bus/omap-ocp2scp.c#L71"1 id="L31"1 class="line" name="L31"1>  311/a>  321/a>plaMODULEVID_ACE_TABLE>(pdepf>, pla2_ocp2scp_devid_tablc>     331/a>  3413a>
  3513a>static intuct platform_deviers/b>    href="+code=NUL2_ocp2scp_deviers/blass="sref">pla2_ocp2scp_deviers/b> =   361/a>        int href="+code=plate" class="sref">omabe(st          a href="+code=of_p_ocp2scp_probe" class="sref">omap_ocp2scp_probe(sta href="drivers/bus/omap-ocp2scp.c#L80"1 id="L27"1 class="line" name="L37"1>  37137>        int href="+code=plaove_delass="sref">ocpove_de>(&a         a href="+code=of_eviniex c_class="sref">np(ocp2_ocp2scp_devove_de>(&a)a href="drivers/bus/omap-ocp2scp.c#L80"1 id="L18"  class="line" name="L38"1>  381/a>        whi href="+code=plaiers/blass="sref">plaiers/b> = <        a a href="drivers/bus/omap-ocp2scp.c#L67"1 id="L29"1 class="line" name="L39"1>  391/a>                drve,
<   a hn class="string">"faip-ocp2scp.c#ot;);
a href="drivers/bus/omap-ocp2scp.c#L80"1 id="L40"1 class="line" name="L40"1>  401/a>                pla2wn/b>     =mhref="+code=of_THIS_MODULElass="sref">plaTHIS_MODULE>(sta href="drivers/bus/omap-ocp2scp.c#L80"1 id="L41"1 class="line" name="L41"1>  4114a>                    href="+code=of_nodmatchitablclass="sref">pla2odmatchitablc> = pla2odmatchiptb>(pla2_ocp2scp_devid_tablc>     42142>           }a href="drivers/bus/omap-ocp2scp.c#L80"1 id="L43"1 class="line" name="L43"1>  431/a>   }a href="drivers/bus/omap-ocp2scp.c#L53"1 id="L44"1 class="line" name="L44"1>  4414a>
  451/a>
plaule.h<_tform_deviers/b>(pla2_ocp2scp_deviers/b> =   4614a>
  471/a>{
plaMODULEVALIAS>("faitform_de: p-ocp2scp.c#ot;);
  481/a>   aref="+code=plaMODULEVAUTHORlass="sref">plaMODULEVAUTHOR>("faias Instruments Incorp.ot;);
  491/a>
plaMODULEVIDSCRIPTION>("faiOMAP OCP2SCP vers/bot;);
  5015a>plaMODULEVLACENSE>("faiGPL v2ot;);
  511/a>

   

iv>