From patchwork Mon Aug 22 18:22:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Cousson X-Patchwork-Id: 1086112 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7MIMglH005437 for ; Mon, 22 Aug 2011 18:23:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752730Ab1HVSXy (ORCPT ); Mon, 22 Aug 2011 14:23:54 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:38244 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752463Ab1HVSXw (ORCPT ); Mon, 22 Aug 2011 14:23:52 -0400 Received: from dlep36.itg.ti.com ([157.170.170.91]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id p7MINnuT007947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 22 Aug 2011 13:23:49 -0500 Received: from dlep26.itg.ti.com (smtp-le.itg.ti.com [157.170.170.27]) by dlep36.itg.ti.com (8.13.8/8.13.8) with ESMTP id p7MINnNv012781; Mon, 22 Aug 2011 13:23:49 -0500 (CDT) Received: from dlee73.ent.ti.com (localhost [127.0.0.1]) by dlep26.itg.ti.com (8.13.8/8.13.8) with ESMTP id p7MINkqE002115; Mon, 22 Aug 2011 13:23:49 -0500 (CDT) Received: from dlelxv22.itg.ti.com (172.17.1.197) by DLEE73.ent.ti.com (157.170.170.88) with Microsoft SMTP Server id 8.3.106.1; Mon, 22 Aug 2011 13:22:37 -0500 Received: from localhost.localdomain (lncpu04.tif.ti.com [137.167.102.15]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id p7MIMVuf016901; Mon, 22 Aug 2011 13:22:36 -0500 From: Benoit Cousson To: CC: , , , , Benoit Cousson Subject: [RFC PATCH 3/3] OMAP: omap_device: Add a method to build an omap_device from a DT node Date: Mon, 22 Aug 2011 20:22:23 +0200 Message-ID: <1314037343-19783-4-git-send-email-b-cousson@ti.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1314037343-19783-1-git-send-email-b-cousson@ti.com> References: <1314037343-19783-1-git-send-email-b-cousson@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 22 Aug 2011 18:23:55 +0000 (UTC) Add a notifier called during device_add phase. If a of_node is present, retrieve the hwmod entry in order to populate propely the omap_device structure. For the moment the resource from the device-tree are overloaded. DT does not support named resource yet, and thus, most driver will not work without that information. Signed-off-by: Benoit Cousson Cc: Kevin Hilman --- arch/arm/plat-omap/omap_device.c | 102 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 102 insertions(+), 0 deletions(-) diff --git a/arch/arm/plat-omap/omap_device.c b/arch/arm/plat-omap/omap_device.c index 70361f8..0ae9e7f 100644 --- a/arch/arm/plat-omap/omap_device.c +++ b/arch/arm/plat-omap/omap_device.c @@ -85,6 +85,8 @@ #include #include #include +#include +#include #include #include @@ -94,6 +96,8 @@ #define USE_WAKEUP_LAT 0 #define IGNORE_WAKEUP_LAT 1 +#define MAX_HWMOD_NAME_SIZE 32 + static int omap_device_register(struct platform_device *pdev); static int omap_early_device_register(struct platform_device *pdev); static struct omap_device *omap_device_alloc(struct platform_device *pdev, @@ -354,6 +358,100 @@ static int _dt_get_property(const char *prop, int len, int index, char *output, return -ENODEV; } +static struct dev_pm_domain omap_device_pm_domain; + +/** + * omap_device_build_from_dt - build an omap_device with multiple hwmods + * @pdev_name: name of the platform_device driver to use + * @pdev_id: this platform_device's connection ID + * @oh: ptr to the single omap_hwmod that backs this omap_device + * @pdata: platform_data ptr to associate with the platform_device + * @pdata_len: amount of memory pointed to by @pdata + * @pm_lats: pointer to a omap_device_pm_latency array for this device + * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats + * @is_early_device: should the device be registered as an early device or not + * + * Function for building an omap_device already registered from device-tree + * + * Returns 0 or PTR_ERR() on error. + */ +static int omap_device_build_from_dt(struct platform_device *pdev) +{ + struct omap_hwmod **hwmods; + struct omap_device *od; + struct omap_hwmod *oh; + char oh_name[MAX_HWMOD_NAME_SIZE]; + const char *prop; + int oh_cnt, i, prop_len; + int ret = 0; + + prop = of_get_property(pdev->dev.of_node, "hwmods", &prop_len); + oh_cnt = _dt_count_property_string(prop, prop_len); + if (!oh_cnt || IS_ERR_VALUE(oh_cnt)) { + dev_warn(&pdev->dev, "No 'hwmods' to build omap_device\n"); + return -ENODEV; + } + + hwmods = kzalloc(sizeof(struct omap_hwmod *) * oh_cnt, GFP_KERNEL); + if (!hwmods) { + ret = -ENOMEM; + goto odbfd_exit; + } + + for (i = 0; i < oh_cnt; i++) { + _dt_get_property(prop, prop_len, i, oh_name, + MAX_HWMOD_NAME_SIZE); + + oh = omap_hwmod_lookup(oh_name); + if (!oh) { + dev_err(&pdev->dev, "Cannot lookup hwmod '%s'\n", + oh_name); + ret = -EINVAL; + goto odbfd_exit1; + } + hwmods[i] = oh; + } + + od = omap_device_alloc(pdev, hwmods, oh_cnt, NULL, 0); + if (!od) { + dev_err(&pdev->dev, "Cannot allocate omap_device for :%s\n", + oh_name); + ret = PTR_ERR(od); + goto odbfd_exit1; + } + + if (of_get_property(pdev->dev.of_node, "no_idle_on_suspend", NULL)) + omap_device_disable_idle_on_suspend(pdev); + + pdev->dev.pm_domain = &omap_device_pm_domain; + +odbfd_exit1: + kfree(hwmods); +odbfd_exit: + return ret; +} + +static int _omap_device_notifier_call(struct notifier_block *nb, + unsigned long event, void *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + + switch (event) { + case BUS_NOTIFY_ADD_DEVICE: + if (pdev->dev.of_node) { + dev_dbg(&pdev->dev, "add_device with DT bindings\n"); + omap_device_build_from_dt(pdev); + } + break; + + case BUS_NOTIFY_DEL_DEVICE: + dev_dbg(&pdev->dev, "del_device\n"); + break; + } + + return NOTIFY_DONE; +} + /* Public functions for use by core code */ @@ -1064,8 +1162,12 @@ struct device omap_device_parent = { .parent = &platform_bus, }; +static struct notifier_block platform_nb; + static int __init omap_device_init(void) { + platform_nb.notifier_call = _omap_device_notifier_call; + bus_register_notifier(&platform_bus_type, &platform_nb); return device_register(&omap_device_parent); } core_initcall(omap_device_init);