From patchwork Wed Jul 12 06:34:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 107444 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp432803qge; Tue, 11 Jul 2017 23:35:29 -0700 (PDT) X-Received: by 10.99.117.94 with SMTP id f30mr2293339pgn.197.1499841329005; Tue, 11 Jul 2017 23:35:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499841328; cv=none; d=google.com; s=arc-20160816; b=zey76jNyBLQ98wW46q0++d3n0xRjEEAQlycqP39TBRR8/7vqnuxIafotdIycLFSw9Q x4SCVm8odfRfzZuj60Q3Urd+kezFvKHvv9v4ZG2dqBRfFIHLvgIw/JLGuw3HUvqeMYns JCN8DPEp/akoS4mbhJ4lsAy2U5i4Xuc5gqK6Wo7p34ycXDTTyB1AT8H8J0PM7xn13DoS 5cYJkxN0w4L++ITgKUlZMtarZMlBSQ8DdskQvQu8bu5ENEoz4wLQw4jSHhMFbXMBIaMk YgFSfKqxTL1fM9gtVvViC+RNOwVRjBxlAZs05YoJwQve3Dq/W7RH0oHLSPCelYb4GdE8 xFEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=0Blu/aTAvn5OqHYZR7PoOCnkMR5Y1/Y/TlE5/ep+TC8=; b=dXTwSO8dfbNSi/kkbISdIJPW2Pt0kvlAnFMvUBAYDYGQNtvbhIwELBRZCtDpA2we8+ aTULq7eYkucc/NxgVB/ET1/tJzRj/MtZCnaeshMjv52sc2hFG0HqtMh6qKHtYvL4SpU6 hV1u+7+O18G0qlCprpt8w9YrYl6vQeM7SNvusMFv5TP070yd5pp/WeQvUiSt91Xdrmq0 Wy4rH7z+bgHPaZHwp0ufjlnSPi8nlf1GmXyOcowcZrQjWLXGvFkj1e3T6Xqnxy/5OvxQ X4xrH5IlClDW9uVfO4brOUZGaSptjqH6uNd9pJu8ACM3Phf/kGo+CA+buKWGP+ZaPeYh cs8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=ELsRujEb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j1si1272640pld.16.2017.07.11.23.35.28; Tue, 11 Jul 2017 23:35:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=ELsRujEb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756698AbdGLGfF (ORCPT + 25 others); Wed, 12 Jul 2017 02:35:05 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:32879 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756632AbdGLGe5 (ORCPT ); Wed, 12 Jul 2017 02:34:57 -0400 Received: by mail-pg0-f49.google.com with SMTP id k14so8072824pgr.0 for ; Tue, 11 Jul 2017 23:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=0Blu/aTAvn5OqHYZR7PoOCnkMR5Y1/Y/TlE5/ep+TC8=; b=ELsRujEbxUTuCdeTZc4IxhixFHN81pG92Nj00Th6OWA+U/A9bjHD+gpuLbgwiDKzWR TrmtRNKesVFz0oynnqxgOiX03uhGPXhawNXrmyBGofAvtQsRfC5NT4JPalBN2Bo9HNuY Xv2/ZwAQp3CcXBWJedy/edz4yfUmF9N+yxfCg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=0Blu/aTAvn5OqHYZR7PoOCnkMR5Y1/Y/TlE5/ep+TC8=; b=DYyuZ38dbLi0DV6RB2aajcEqm1qHbtdicxNft29Lxy6V6PUFYOHEzHAJw3TMAjNFug ytPBmcCLyXe23DT3XMyrtYbhT73AIvf/+IZKNa8orlOSJ3yDnyCc37cUAKNeG9k4kOBF 4gPUErNwLEQq0vj/s5ISA2p/vww6UNGlMGXoTW5a4U/DgkjVAQzZQJs+qD/4MAUND6iO WJZIUMCKIWqRKHJhwdou2A/Wkr+IIs1ZwbLNjRWCpdZzqg8hyQPG3tDSgSrgbDwHA0Vb 0akz/XuwRqvJnVNeYVCRLOoOwWCWILpdy8oaQr3e2UyidZ4KSSclcWqK6hQJLTTNVCgT bRaw== X-Gm-Message-State: AIVw112n0I1iT/cY4HdemdESkbbtakFxclpDvR1sN08nZRNl6rJf7836 atGq3x8A76kCb4+N X-Received: by 10.99.60.28 with SMTP id j28mr2270194pga.18.1499841296308; Tue, 11 Jul 2017 23:34:56 -0700 (PDT) Received: from localhost ([122.167.138.108]) by smtp.gmail.com with ESMTPSA id q67sm2580908pfi.81.2017.07.11.23.34.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jul 2017 23:34:55 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Rob Herring , Mark Brown , Stephen Boyd , Rajendra Nayak , Shiraz Hashim , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RFC v2 4/6] drivers: boot_constraint: Add debugfs support Date: Wed, 12 Jul 2017 12:04:34 +0530 Message-Id: X-Mailer: git-send-email 2.13.0.71.gd7076ec9c9cb In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds debugfs support for boot constraints. This is how it looks for a "vmmc-supply" constraint for the MMC device. $ ls -R /sys/kernel/debug/boot_constraints/ /sys/kernel/debug/boot_constraints/: f723d000.dwmmc0 /sys/kernel/debug/boot_constraints/f723d000.dwmmc0: supply-vmmc /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc: u_volt_max u_volt_min Signed-off-by: Viresh Kumar --- drivers/base/boot_constraint.c | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraint.c b/drivers/base/boot_constraint.c index d372ddfe1264..4e3b5e1aec7c 100644 --- a/drivers/base/boot_constraint.c +++ b/drivers/base/boot_constraint.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) "Boot Constraints: " fmt #include +#include #include #include #include @@ -24,6 +25,7 @@ struct constraint { enum boot_constraint_type type; void (*free_resources)(void *data); void *free_resources_data; + struct dentry *dentry; int (*add)(struct constraint *constraint, void *data); void (*remove)(struct constraint *constraint); @@ -34,6 +36,7 @@ struct constraint_dev { struct device *dev; struct list_head node; struct list_head constraints; + struct dentry *dentry; }; #define for_each_constraint(_constraint, _temp, _cdev) \ @@ -59,6 +62,71 @@ static int __init constraints_disable(char *str) early_param("boot_constraints_disable", constraints_disable); +/* Debugfs */ + +static struct dentry *rootdir; + +static void constraint_device_add_debugfs(struct constraint_dev *cdev) +{ + struct device *dev = cdev->dev; + + cdev->dentry = debugfs_create_dir(dev_name(dev), rootdir); + if (!cdev->dentry) + dev_err(dev, "Failed to create constraint dev debugfs dir\n"); +} + +static void constraint_device_remove_debugfs(struct constraint_dev *cdev) +{ + debugfs_remove_recursive(cdev->dentry); +} + +static void constraint_add_debugfs(struct constraint *constraint, + const char *suffix) +{ + struct device *dev = constraint->cdev->dev; + const char *prefix; + char name[NAME_MAX]; + + switch (constraint->type) { + case BOOT_CONSTRAINT_SUPPLY: + prefix = "supply"; + break; + default: + dev_err(dev, "%s: Constraint type (%d) not supported\n", + __func__, constraint->type); + return; + } + + snprintf(name, NAME_MAX, "%s-%s", prefix, suffix); + + constraint->dentry = debugfs_create_dir(name, constraint->cdev->dentry); + if (!constraint->dentry) + dev_err(dev, "Failed to create constraint (%s) debugfs dir\n", + name); +} + +static void constraint_remove_debugfs(struct constraint *constraint) +{ + debugfs_remove_recursive(constraint->dentry); +} + +static int __init constraint_debugfs_init(void) +{ + if (boot_constraints_disabled) + return -ENODEV; + + /* Create /sys/kernel/debug/opp directory */ + rootdir = debugfs_create_dir("boot_constraints", NULL); + if (!rootdir) { + pr_err("Failed to create root directory\n"); + return -ENOMEM; + } + + return 0; +} +core_initcall(constraint_debugfs_init); + + /* Boot constraints core */ static struct constraint_dev *constraint_device_find(struct device *dev) @@ -86,12 +154,14 @@ static struct constraint_dev *constraint_device_allocate(struct device *dev) INIT_LIST_HEAD(&cdev->constraints); list_add(&cdev->node, &constraint_devices); + constraint_device_add_debugfs(cdev); return cdev; } static void constraint_device_free(struct constraint_dev *cdev) { + constraint_device_remove_debugfs(cdev); list_del(&cdev->node); kfree(cdev); } @@ -292,6 +362,15 @@ static int constraint_supply_add(struct constraint *constraint, void *data) csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL); constraint->private = csupply; + /* Debugfs */ + constraint_add_debugfs(constraint, supply->name); + + debugfs_create_u32("u_volt_min", 0444, constraint->dentry, + &csupply->supply.u_volt_min); + + debugfs_create_u32("u_volt_max", 0444, constraint->dentry, + &csupply->supply.u_volt_max); + return 0; remove_voltage: @@ -319,6 +398,7 @@ static void constraint_supply_remove(struct constraint *constraint) dev_err(dev, "regulator_set_voltage failed (%d)\n", ret); regulator_put(csupply->reg); + constraint_remove_debugfs(constraint); kfree_const(csupply->supply.name); kfree(csupply); }