From patchwork Mon Jul 16 21:32:16 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Wysocki X-Patchwork-Id: 1202391 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 76CF93FC33 for ; Mon, 16 Jul 2012 21:31:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754227Ab2GPVaz (ORCPT ); Mon, 16 Jul 2012 17:30:55 -0400 Received: from ogre.sisk.pl ([193.178.161.156]:43072 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753482Ab2GPV2m (ORCPT ); Mon, 16 Jul 2012 17:28:42 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by ogre.sisk.pl (Postfix) with ESMTP id B35A51D8258; Mon, 16 Jul 2012 23:25:35 +0200 (CEST) Received: from ogre.sisk.pl ([127.0.0.1]) by localhost (ogre.sisk.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 04510-02; Mon, 16 Jul 2012 23:24:52 +0200 (CEST) Received: from ferrari.rjw.lan (62-121-64-87.home.aster.pl [62.121.64.87]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ogre.sisk.pl (Postfix) with ESMTP id 5D1C91D84B8; Mon, 16 Jul 2012 23:24:30 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM list Subject: [RFC][PATCH 14/14] ARM: shmobile: Add support for storing PM domain information in DTs Date: Mon, 16 Jul 2012 23:32:16 +0200 User-Agent: KMail/1.13.6 (Linux/3.5.0-rc5+; KDE/4.6.0; x86_64; ; ) Cc: Mark Brown , LKML , Matthew Garrett , Magnus Damm , Arnd Bergmann , Grant Likely , "Linux-sh list" References: <201207032302.17805.rjw@sisk.pl> <201207052217.48086.rjw@sisk.pl> <201207162315.49073.rjw@sisk.pl> In-Reply-To: <201207162315.49073.rjw@sisk.pl> MIME-Version: 1.0 Message-Id: <201207162332.16328.rjw@sisk.pl> X-Virus-Scanned: amavisd-new at ogre.sisk.pl using MkS_Vir for Linux Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org From: Rafael J. Wysocki Allow the common power management support code for Renesas SoCs to read the names of the power domains that platform devices belong to from a device tree describing the platform. The name of the power domain is stored within the given device's DT node as a case-sensitive string attribute of the name "renesas,pmdomain". The values of those attributes are read by the platform code throuch a platform bus type notifier which is executed right after adding the device to the device hierarchy and are then used for adding devices to the given PM domains with the help of pm_genpd_name_add_device(). Signed-off-by: Rafael J. Wysocki --- arch/arm/mach-shmobile/pm-rmobile.c | 92 ++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 9 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux/arch/arm/mach-shmobile/pm-rmobile.c =================================================================== --- linux.orig/arch/arm/mach-shmobile/pm-rmobile.c +++ linux/arch/arm/mach-shmobile/pm-rmobile.c @@ -3,6 +3,7 @@ * * Copyright (C) 2012 Renesas Solutions Corp. * Copyright (C) 2012 Kuninori Morimoto + * Copyright (C) 2012 Rafael J. Wysocki * * based on pm-sh7372.c * Copyright (C) 2011 Magnus Damm @@ -13,7 +14,9 @@ */ #include #include +#include #include +#include #include #include #include @@ -149,21 +152,92 @@ static void rmobile_init_pm_domain(struc __rmobile_pd_power_up(rmobile_pd, false); } -void rmobile_init_domains(struct rmobile_pm_domain domains[], int num) -{ - int j; - - for (j = 0; j < num; j++) - rmobile_init_pm_domain(&domains[j]); -} - void rmobile_add_device_to_domain(const char *domain_name, struct platform_device *pdev) { struct device *dev = &pdev->dev; + int ret; - pm_genpd_name_add_device(domain_name, dev); + do + ret = pm_genpd_name_add_device(domain_name, dev); + while (ret == -EAGAIN); if (pm_clk_no_clocks(dev)) pm_clk_add(dev, NULL); } + +#ifdef CONFIG_USE_OF + +static void rmobile_read_domain_from_dt(struct device *dev) +{ + const char *domain_name; + int ret; + + ret = of_property_read_string(dev->of_node, "renesas,pmdomain", + &domain_name); + if (!ret) + rmobile_add_device_to_domain(domain_name, + to_platform_device(dev)); +} + +static void rmobile_remove_from_domain(struct device *dev) +{ + struct generic_pm_domain *genpd = dev_to_genpd(dev); + int ret; + + /* + * The check below takes care of the situations in which the device's + * pm_domain pointer contains a valid address, but that is not an + * address of a generic PM domain object. + */ + if (pm_genpd_present(genpd)) { + do + ret = pm_genpd_remove_device(genpd, dev); + while (ret == -EAGAIN); + } +} + +static int rmobile_pm_notifier_call(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct device *dev = data; + + switch (event) { + case BUS_NOTIFY_ADD_DEVICE: + if (dev->of_node) + rmobile_read_domain_from_dt(dev); + + break; + + case BUS_NOTIFY_DEL_DEVICE: + rmobile_remove_from_domain(dev); + + break; + } + return NOTIFY_DONE; +} + +static struct notifier_block platform_nb = { + .notifier_call = rmobile_pm_notifier_call, +}; + +static void rmobile_add_bus_notifier_for_domains(void) +{ + bus_register_notifier(&platform_bus_type, &platform_nb); +} + +#else + +static inline void rmobile_add_bus_notifier_for_domains(void) {} + +#endif /* CONFIG_USE_OF */ + +void rmobile_init_domains(struct rmobile_pm_domain domains[], int num) +{ + int j; + + for (j = 0; j < num; j++) + rmobile_init_pm_domain(&domains[j]); + + rmobile_add_bus_notifier_for_domains(); +} #endif /* CONFIG_PM */