From patchwork Mon Feb 4 11:53:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14461 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id CE89523F96 for ; Mon, 4 Feb 2013 11:56:12 +0000 (UTC) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by fiordland.canonical.com (Postfix) with ESMTP id 6B248A1877A for ; Mon, 4 Feb 2013 11:56:12 +0000 (UTC) Received: by mail-ve0-f171.google.com with SMTP id b10so4567302vea.16 for ; Mon, 04 Feb 2013 03:56:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=VUfaZP3CnLMkFUUO1iD3lKRDtVAhZvzf660CNatqMUE=; b=ISpKoYF13OYXQxtloned12/wdZBBt8PG6klvqBrx3IlahBWpPge2cE1nYonieGXPW7 k3ZCr/FlUdGF6SVCtOFfF6IiChxAEAfe4472mMO0tDf+PqlSkFh82r19MSix9XAcNOg0 zYEGKJfkIgcC7RptKifuh2cFLx4EM1VxKuI7fZCVCk6pTs6ChuNs4omM3+V4GUqinKOq Z+YaxiNamrahLxreX8u8BkE+oAgA9st14zVVKyjslxg9u/5Ma5JGfc/izoaP4Fu7M5qb nBFrb7Cwqe3m62hQeEnVUxEKmX+sKMFnq30LamCEvNXWTdDdPoCN7x8Gjf6BPjzylEzM fR8g== X-Received: by 10.52.27.50 with SMTP id q18mr19331001vdg.20.1359978971930; Mon, 04 Feb 2013 03:56:11 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.252.8 with SMTP id zo8csp83033vec; Mon, 4 Feb 2013 03:56:11 -0800 (PST) X-Received: by 10.194.158.100 with SMTP id wt4mr34595667wjb.37.1359978970890; Mon, 04 Feb 2013 03:56:10 -0800 (PST) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by mx.google.com with ESMTPS id xv9si5709263wjb.227.2013.02.04.03.56.10 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Feb 2013 03:56:10 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.181 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.181; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.181 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f181.google.com with SMTP id hm6so1500895wib.14 for ; Mon, 04 Feb 2013 03:56:10 -0800 (PST) X-Received: by 10.194.76.165 with SMTP id l5mr34481374wjw.14.1359978970516; Mon, 04 Feb 2013 03:56:10 -0800 (PST) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPS id j9sm12937128wia.5.2013.02.04.03.56.08 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Feb 2013 03:56:09 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org, broonie@opensource.wolfsonmicro.com Cc: Lee Jones Subject: [PATCH 12/73] regulator: core: Show consumers that hold a regulator in Sysfs Date: Mon, 4 Feb 2013 11:53:27 +0000 Message-Id: <1359978868-28736-13-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359978868-28736-1-git-send-email-lee.jones@linaro.org> References: <1359978868-28736-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQlP1kuSl8MwfSc4/xRN1cgprOYrQoVZxRxtzRjbcFpLMuYLx9iinJVrHZyl0kLVXqhY/UUb To locate the consumers that currently hold a regulator we're creating a new sysfs entry. The consumers are published in /sys/class/regulator/regulator.<#>/use Signed-off-by: Lee Jones --- drivers/regulator/core.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2785843..81212c7 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -85,6 +85,7 @@ struct regulator { struct device_attribute dev_attr; struct regulator_dev *rdev; struct dentry *debugfs; + int use; }; static int _regulator_is_enabled(struct regulator_dev *rdev); @@ -614,6 +615,33 @@ static ssize_t regulator_bypass_show(struct device *dev, static DEVICE_ATTR(bypass, 0444, regulator_bypass_show, NULL); +static ssize_t regulator_use_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct regulator_dev *rdev = dev_get_drvdata(dev); + struct regulator *reg; + size_t size = 0; + + if (rdev->use_count == 0) + return sprintf(buf, "no users\n"); + + list_for_each_entry(reg, &rdev->consumer_list, list) { + if (!reg->use) + continue; + + if (reg->dev != NULL) + size += sprintf((buf + size), "%s (%d) ", + dev_name(reg->dev), reg->use); + else + size += sprintf((buf + size), "unknown (%d) ", + reg->use); + } + size += sprintf((buf + size), "\n"); + + return size; +} +static DEVICE_ATTR(use, 0444, regulator_use_show, NULL); + /* * These are the only attributes are present for all regulators. * Other attributes are a function of regulator functionality. @@ -1564,6 +1592,8 @@ int regulator_enable(struct regulator *regulator) if (ret != 0 && rdev->supply) regulator_disable(rdev->supply); + else + regulator->use++; return ret; } @@ -1656,6 +1686,9 @@ int regulator_disable(struct regulator *regulator) if (ret == 0 && rdev->supply) regulator_disable(rdev->supply); + if (ret == 0) + regulator->use--; + return ret; } EXPORT_SYMBOL_GPL(regulator_disable); @@ -3190,6 +3223,10 @@ static int add_regulator_attributes(struct regulator_dev *rdev) struct regulator_ops *ops = rdev->desc->ops; int status = 0; + status = device_create_file(dev, &dev_attr_use); + if (status < 0) + return status; + /* some attributes need specific methods to be displayed */ if ((ops->get_voltage && ops->get_voltage(rdev) >= 0) || (ops->get_voltage_sel && ops->get_voltage_sel(rdev) >= 0) ||