From patchwork Sun Oct 29 13:48:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117415 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1528703qgn; Sun, 29 Oct 2017 06:51:08 -0700 (PDT) X-Google-Smtp-Source: ABhQp+T1SHhwreUzOT4Ti/rggaBK4tL7VC9hA2wpjysQZFieorCbOQpt7YUShxqmtfPe82Cu9yZ5 X-Received: by 10.99.117.10 with SMTP id q10mr5066637pgc.288.1509285068152; Sun, 29 Oct 2017 06:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509285068; cv=none; d=google.com; s=arc-20160816; b=ad2w8CkmYlViRGZUi47gJhdJb7DdUsi23eNb6NYavo6iDaeeyg4cuHx/y1aPVdDvux 0u9qOB/oFPPTEl/23Skfc/67uCYlBTbt6qMgYhXR6lf5SgJmxVMxG649zG3W0PKZ3hvC iRwznuUi60lfG3M7Z8GN5Uk+N2Ov7831DiC6JH62w/wEo6VUXKr1q4/jCpkHHGNgbtPy rrwiFfaK0GVc2AUSF3GanEilHKxXfpRbXv7WPxH/1tKQuCggauItHYSslqJNeMjbq6zR G6KYmTqPgqrLgyTy2C6IoM27T1GYSl4bs6+kElV6aSVe9aAMRVyC/YMAeptKoCIYpyw8 i5Jg== 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=8dknvPdhMomhLDGww4JAVj/cpN5o9hByN7NdXXTe1dY=; b=E/2Kq/VJBx5npcfygd/fqM96UDQ1YMLuS5e5ixr8Rpv3Ghtm77amDO5Dn5PX9lO+eL rGq4D/YhSn9KaOIWuLG9WeY7m8IUAsHCfhAno9+E/6+MV5ffIUholbou2cxy5lkztHnT dL+lRs5HictcDb5nrWa1JrbZkDAWiCZCLVL/670fgFiOJdkmgCw3oX3yF8qTOV9rZiEt szhx4rd77UEyVYzo0s89hbCkJiXGyDk8IYe3MYtV1YeOWH7z4SqFsj8h8Oo8btlUld2M VDqPlDf4co9L0DJkWzaDmCeew2V6mLCZxWHPg/7VU27Z3EyRY2mpjrfpc1TGuUQeXsiU P46g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GymTc+ii; 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 g24si7649787pfd.403.2017.10.29.06.51.07; Sun, 29 Oct 2017 06:51:08 -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.s=google header.b=GymTc+ii; 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 S1752006AbdJ2NvG (ORCPT + 27 others); Sun, 29 Oct 2017 09:51:06 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:43570 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751683AbdJ2NtY (ORCPT ); Sun, 29 Oct 2017 09:49:24 -0400 Received: by mail-pf0-f193.google.com with SMTP id a8so8674643pfc.0 for ; Sun, 29 Oct 2017 06:49:24 -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=8dknvPdhMomhLDGww4JAVj/cpN5o9hByN7NdXXTe1dY=; b=GymTc+iiB7WUT2FP/077z/9brjaaGM1GuqqMXK+IDZmU1Xt5Qm4HvohAQniNiyg8Vn g8bpaKISz/S5Xj4dSqYmtIEEdO3EypbpRvd0G6cgZF+dMGPM7WfGkZQ35cwI0+ckUGwt ddYvDGE9gspW+CTnO9VYyfce//1ATpyfARlBM= 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=8dknvPdhMomhLDGww4JAVj/cpN5o9hByN7NdXXTe1dY=; b=eg2hXfnW806dmmRdRz4TM6Fh0xttKuMOl+ssPyuR5ju0B/e2ZakAHlzGRrHqv3OumE g5TJ+niFaB7cU38HuL62wVg93r81uGBAdL2+oPbLz0ccO3GY0nWRRkhFPnQ6RMLQbyP8 Z0RUpwQgrf4vFEwTMctgiuvVb770Qb3wWh7V16lIAOXN4VMu1WXRJeY9f8SXMAmY5BxD Q9s778fZ6PVWu5nOoadKck9K7hf5C1kTkpbqsmPT+QUNMXGq6yPDxCGAiuHGYVSkGjEQ PJbVYBg2K328RIlt2WbDu/qMA15X9HRUiIRT7ayQTITuk5OXVSdZra4HIRG901QiRx+3 jWvg== X-Gm-Message-State: AMCzsaXKJxugpHczlsA/xIRupyhFllrpNML+QNrD6BbvkES6DrI2VUMC PBvVD7JaM44Mi2ZQhDgE6kOFCQ== X-Received: by 10.84.128.72 with SMTP id 66mr4993073pla.119.1509284963816; Sun, 29 Oct 2017 06:49:23 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id n19sm22834891pfj.52.2017.10.29.06.49.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:23 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 05/12] boot_constraint: Add support for clk constraints Date: Sun, 29 Oct 2017 19:18:53 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 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 the clk constraint type. The constraint is set by enabling the clk for the device. Once the device is probed, the clk is disabled and the constraint is removed. We may want to do clk_set_rate() from here, but lets wait for some real users that really want it. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/boot_constraints/Makefile | 2 +- drivers/boot_constraints/clk.c | 70 +++++++++++++++++++++++++++++++++++++++ drivers/boot_constraints/core.c | 4 +++ drivers/boot_constraints/core.h | 3 ++ include/linux/boot_constraint.h | 5 +++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 drivers/boot_constraints/clk.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index a45616f0c3b0..3424379fd1e4 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/boot_constraints/Makefile @@ -1,3 +1,3 @@ # Makefile for device boot constraints -obj-y := core.o supply.o +obj-y := clk.o core.o supply.o diff --git a/drivers/boot_constraints/clk.c b/drivers/boot_constraints/clk.c new file mode 100644 index 000000000000..b5b1d63c3e76 --- /dev/null +++ b/drivers/boot_constraints/clk.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#define pr_fmt(fmt) "Clock Boot Constraints: " fmt + +#include +#include +#include + +#include "core.h" + +struct constraint_clk { + struct dev_boot_constraint_clk_info clk_info; + struct clk *clk; +}; + +int constraint_clk_add(struct constraint *constraint, void *data) +{ + struct dev_boot_constraint_clk_info *clk_info = data; + struct constraint_clk *cclk; + struct device *dev = constraint->cdev->dev; + int ret; + + cclk = kzalloc(sizeof(*cclk), GFP_KERNEL); + if (!cclk) + return -ENOMEM; + + cclk->clk = clk_get(dev, clk_info->name); + if (IS_ERR(cclk->clk)) { + ret = PTR_ERR(cclk->clk); + if (ret != -EPROBE_DEFER) { + dev_err(dev, "clk_get() failed for %s (%d)\n", + clk_info->name, ret); + } + goto free; + } + + ret = clk_prepare_enable(cclk->clk); + if (ret) { + dev_err(dev, "clk_prepare_enable() %s failed (%d)\n", + clk_info->name, ret); + goto put_clk; + } + + cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL); + constraint->private = cclk; + + return 0; + +put_clk: + clk_put(cclk->clk); +free: + kfree(cclk); + + return ret; +} + +void constraint_clk_remove(struct constraint *constraint) +{ + struct constraint_clk *cclk = constraint->private; + + kfree_const(cclk->clk_info.name); + clk_disable_unprepare(cclk->clk); + clk_put(cclk->clk); + kfree(cclk); +} diff --git a/drivers/boot_constraints/core.c b/drivers/boot_constraints/core.c index b9c024a3bdf5..9213e56e8078 100644 --- a/drivers/boot_constraints/core.c +++ b/drivers/boot_constraints/core.c @@ -94,6 +94,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev, void (*remove)(struct constraint *constraint); switch (type) { + case DEV_BOOT_CONSTRAINT_CLK: + add = constraint_clk_add; + remove = constraint_clk_remove; + break; case DEV_BOOT_CONSTRAINT_SUPPLY: add = constraint_supply_add; remove = constraint_supply_remove; diff --git a/drivers/boot_constraints/core.h b/drivers/boot_constraints/core.h index 73b9d2d22a12..4f28ac2ef691 100644 --- a/drivers/boot_constraints/core.h +++ b/drivers/boot_constraints/core.h @@ -30,6 +30,9 @@ struct constraint { }; /* Forward declarations of constraint specific callbacks */ +int constraint_clk_add(struct constraint *constraint, void *data); +void constraint_clk_remove(struct constraint *constraint); + int constraint_supply_add(struct constraint *constraint, void *data); void constraint_supply_remove(struct constraint *constraint); diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index fc8ec0ee82f3..a74b261a4ee4 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -15,9 +15,14 @@ struct device; enum dev_boot_constraint_type { + DEV_BOOT_CONSTRAINT_CLK, DEV_BOOT_CONSTRAINT_SUPPLY, }; +struct dev_boot_constraint_clk_info { + const char *name; +}; + struct dev_boot_constraint_supply_info { const char *name; unsigned int u_volt_min;