Commit 0133370f93eae5ed3c0f16d9da2b7add7dda6076

Authored by Kishon Vijay Abraham I
Committed by Tony Lindgren
1 parent 3d70f8c617

drivers: bus: ocp2scp: add pdata support

ocp2scp was not having pdata support which makes *musb* fail for non-dt
boot in OMAP platform. The pdata will have information about the devices
that is connected to ocp2scp. ocp2scp driver will now make use of this
information to create the devices that is attached to ocp2scp.

This is needed to fix MUSB regression caused by commit c9e4412a
(arm: omap: phy: remove unused functions from omap-phy-internal.c)

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>
[tony@atomide.com: updated comments for regression info]
Signed-off-by: Tony Lindgren <tony@atomide.com>

Showing 2 changed files with 96 additions and 3 deletions Side-by-side Diff

drivers/bus/omap-ocp2scp.c
... ... @@ -22,7 +22,27 @@
22 22 #include <linux/pm_runtime.h>
23 23 #include <linux/of.h>
24 24 #include <linux/of_platform.h>
  25 +#include <linux/platform_data/omap_ocp2scp.h>
25 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 + */
  34 +static 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 +
26 46 static int ocp2scp_remove_devices(struct device *dev, void *c)
27 47 {
28 48 struct platform_device *pdev = to_platform_device(dev);
29 49  
30 50  
31 51  
32 52  
... ... @@ -34,19 +54,61 @@
34 54  
35 55 static int __devinit omap_ocp2scp_probe(struct platform_device *pdev)
36 56 {
37   - int ret;
38   - struct device_node *np = pdev->dev.of_node;
  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;
39 63  
40 64 if (np) {
41 65 ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
42 66 if (ret) {
43   - dev_err(&pdev->dev, "failed to add resources for ocp2scp child\n");
  67 + dev_err(&pdev->dev,
  68 + "failed to add resources for ocp2scp child\n");
44 69 goto err0;
45 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, res_cnt);
  86 + if (ret) {
  87 + dev_err(&pdev->dev,
  88 + "failed to add resources for ocp2scp child\n");
  89 + goto err1;
  90 + }
  91 +
  92 + pdev_child->dev.parent = &pdev->dev;
  93 +
  94 + ret = platform_device_add(pdev_child);
  95 + if (ret) {
  96 + dev_err(&pdev->dev,
  97 + "failed to register ocp2scp child device\n");
  98 + goto err1;
  99 + }
  100 + }
  101 + } else {
  102 + dev_err(&pdev->dev, "OCP2SCP initialized without plat data\n");
  103 + return -EINVAL;
46 104 }
  105 +
47 106 pm_runtime_enable(&pdev->dev);
48 107  
49 108 return 0;
  109 +
  110 +err1:
  111 + platform_device_put(pdev_child);
50 112  
51 113 err0:
52 114 device_for_each_child(&pdev->dev, NULL, ocp2scp_remove_devices);
include/linux/platform_data/omap_ocp2scp.h
  1 +/*
  2 + * omap_ocp2scp.h -- ocp2scp header file
  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 +#ifndef __DRIVERS_OMAP_OCP2SCP_H
  20 +#define __DRIVERS_OMAP_OCP2SCP_H
  21 +
  22 +struct omap_ocp2scp_dev {
  23 + const char *drv_name;
  24 + struct resource *res;
  25 +};
  26 +
  27 +struct omap_ocp2scp_platform_data {
  28 + int dev_cnt;
  29 + struct omap_ocp2scp_dev **devices;
  30 +};
  31 +#endif /* __DRIVERS_OMAP_OCP2SCP_H */