From patchwork Fri Mar 14 19:25:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Gerlach X-Patchwork-Id: 3835261 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A7D639F1CD for ; Fri, 14 Mar 2014 20:20:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 80CB4202A7 for ; Fri, 14 Mar 2014 20:20:20 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C4DB202A1 for ; Fri, 14 Mar 2014 20:20:19 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOXmF-0002mV-Ie; Fri, 14 Mar 2014 19:28:21 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOXlW-0006zU-9x; Fri, 14 Mar 2014 19:27:34 +0000 Received: from bear.ext.ti.com ([192.94.94.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WOXkH-0006od-Tk for linux-arm-kernel@lists.infradead.org; Fri, 14 Mar 2014 19:26:30 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s2EJPsw5023183; Fri, 14 Mar 2014 14:25:54 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2EJPs0P023102; Fri, 14 Mar 2014 14:25:54 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Fri, 14 Mar 2014 14:25:54 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s2EJPrpC015877; Fri, 14 Mar 2014 14:25:53 -0500 Received: from localhost (lta0274052.am.dhcp.ti.com [128.247.71.78]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id s2EJPrt18974; Fri, 14 Mar 2014 14:25:53 -0500 (CDT) From: Dave Gerlach To: , , Subject: [RFC 1/9] opp-modifier: Introduce OPP Modifier Framework Date: Fri, 14 Mar 2014 14:25:27 -0500 Message-ID: <1394825135-60110-2-git-send-email-d-gerlach@ti.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1394825135-60110-1-git-send-email-d-gerlach@ti.com> References: <1394825135-60110-1-git-send-email-d-gerlach@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140314_152618_282866_A81C4766 X-CRM114-Status: GOOD ( 18.14 ) X-Spam-Score: -6.9 (------) Cc: Jisheng Zhang , devicetree@vger.kernel.org, Nishanth Menon , Dave Gerlach , Viresh Kumar , Anson Huang , "Rafael J. Wysocki" , cpufreq@vger.kernel.org, kernel@pengutronix.de, Shawn Guo X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce framework to allow an OPP modifier driver to selectively determine which possible OPPs for an SoC are available based on register values found in SoC through a common API. Three functions are exported, a register and unregister function for the opp modifier drivers to notify the API of their existence, and opp_modify_dev_table which looks up the appropriate driver and DT information to use for a device and then uses enable/disable to change which previously loaded OPPs are available on the device. Signed-off-by: Dave Gerlach --- drivers/power/Makefile | 2 + drivers/power/opp/Makefile | 1 + drivers/power/opp/core.c | 126 +++++++++++++++++++++++++++++++++++++++++++ include/linux/opp-modifier.h | 35 ++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 drivers/power/opp/Makefile create mode 100644 drivers/power/opp/core.c create mode 100644 include/linux/opp-modifier.h diff --git a/drivers/power/Makefile b/drivers/power/Makefile index ee54a3e..ed379cf 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -58,3 +58,5 @@ obj-$(CONFIG_POWER_AVS) += avs/ obj-$(CONFIG_CHARGER_SMB347) += smb347-charger.o obj-$(CONFIG_CHARGER_TPS65090) += tps65090-charger.o obj-$(CONFIG_POWER_RESET) += reset/ + +obj-y += opp/ diff --git a/drivers/power/opp/Makefile b/drivers/power/opp/Makefile new file mode 100644 index 0000000..820eb10 --- /dev/null +++ b/drivers/power/opp/Makefile @@ -0,0 +1 @@ +obj-y += core.o diff --git a/drivers/power/opp/core.c b/drivers/power/opp/core.c new file mode 100644 index 0000000..403013b --- /dev/null +++ b/drivers/power/opp/core.c @@ -0,0 +1,126 @@ +/* + * OPP Modifier framework + * + * Copyright (C) 2013 Texas Instruments Inc. + * Dave Gerlach + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_MUTEX(opp_modifier_list_mutex); +static LIST_HEAD(opp_modifier_list); + +static int opp_modify_dev_opp_table(struct opp_modifier_dev *opp_dev, + struct device *dev) +{ + if (opp_dev->ops->modify) + return opp_dev->ops->modify(dev); + + return -EINVAL; +} + +static struct opp_modifier_dev *opp_modifier_get(struct device *dev) +{ + struct opp_modifier_dev *o, *opp_dev; + struct device_node *np; + + if (!dev) + return ERR_PTR(-EINVAL); + + np = of_parse_phandle(dev->of_node, "platform-opp-modifier", 0); + + if (!np) + return ERR_PTR(-ENOSYS); + + opp_dev = NULL; + + mutex_lock(&opp_modifier_list_mutex); + + list_for_each_entry(o, &opp_modifier_list, list) { + if (of_get_parent(np) == o->of_node) { + opp_dev = o; + break; + } + } + + if (!opp_dev) { + mutex_unlock(&opp_modifier_list_mutex); + return ERR_PTR(-EINVAL); + } + + of_node_put(np); + + try_module_get(opp_dev->owner); + mutex_unlock(&opp_modifier_list_mutex); + + return opp_dev; +} + +static void opp_modifier_put(struct opp_modifier_dev *opp_dev) +{ + if (IS_ERR(opp_dev)) + return; + + module_put(opp_dev->owner); +} + +int opp_modifier_register(struct opp_modifier_dev *opp_dev) +{ + mutex_lock(&opp_modifier_list_mutex); + list_add(&opp_dev->list, &opp_modifier_list); + mutex_unlock(&opp_modifier_list_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(opp_modifier_register); + +void opp_modifier_unregister(struct opp_modifier_dev *opp_dev) +{ + mutex_lock(&opp_modifier_list_mutex); + list_del(&opp_dev->list); + mutex_unlock(&opp_modifier_list_mutex); +} +EXPORT_SYMBOL_GPL(opp_modifier_unregister); + +int opp_modify_dev_table(struct device *dev) +{ + struct opp_modifier_dev *opp_dev; + int ret; + + opp_dev = opp_modifier_get(dev); + + /* + * It is a valid case for a device to not implement + * an OPP modifier table so return 0 if not present + */ + + if (IS_ERR(opp_dev) && PTR_ERR(opp_dev) == -ENOSYS) { + dev_dbg(dev, "No platform-opp-modifier entry present\n"); + return 0; + } else if (IS_ERR(opp_dev)) { + return PTR_ERR(opp_dev); + } + + ret = opp_modify_dev_opp_table(opp_dev, dev); + + opp_modifier_put(opp_dev); + + return ret; +} +EXPORT_SYMBOL_GPL(opp_modify_dev_table); diff --git a/include/linux/opp-modifier.h b/include/linux/opp-modifier.h new file mode 100644 index 0000000..8d50851 --- /dev/null +++ b/include/linux/opp-modifier.h @@ -0,0 +1,35 @@ +/* + * TI OPP Modifier Core API + * + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/ + * Dave Gerlach + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __LINUX_OPP_MODIFIER_H__ +#define __LINUX_OPP_MODIFIER_H__ + +struct opp_modifier_dev { + struct opp_modifier_ops *ops; + struct module *owner; + struct list_head list; + struct device_node *of_node; +}; + +struct opp_modifier_ops { + int (*modify)(struct device *dev); +}; + +int opp_modifier_register(struct opp_modifier_dev *opp_dev); +void opp_modifier_unregister(struct opp_modifier_dev *opp_dev); +int opp_modify_dev_table(struct device *dev); + +#endif /* __LINUX_OPP_MODIFIER_H__ */