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: 3834781 Return-Path: X-Original-To: patchwork-linux-pm@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 CB7D89F2BB for ; Fri, 14 Mar 2014 19:26:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AA5F32034C for ; Fri, 14 Mar 2014 19:26:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 408B72034E for ; Fri, 14 Mar 2014 19:26:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755992AbaCNT0l (ORCPT ); Fri, 14 Mar 2014 15:26:41 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:43248 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755962AbaCNT0j (ORCPT ); Fri, 14 Mar 2014 15:26:39 -0400 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: , , CC: , , , "Rafael J. Wysocki" , Jisheng Zhang , Anson Huang , Shawn Guo , Viresh Kumar , Nishanth Menon , Dave Gerlach 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 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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__ */