From patchwork Tue Aug 1 09:23:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109130 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1268134qge; Tue, 1 Aug 2017 02:30:11 -0700 (PDT) X-Received: by 10.99.119.139 with SMTP id s133mr18030172pgc.256.1501579811239; Tue, 01 Aug 2017 02:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579811; cv=none; d=google.com; s=arc-20160816; b=lQPHHPsXhl5ymk0X5t7qiYqCujFg5VwGhsr/fAnN+k/+tFSqymJDniJzZ3hdCQ4LNG ETaHHAySRXR+axf9ejYvJ9gJzfxTB4fyYMnZOjcYGrRCPJPti5YO3LCGCXjLD1Z5qQH2 NQcruUbEBcV8GFZedRpH2DjM4NvVfv0Lo4/mgJkSrils/AeBLnjGSZpj25Ob9U9H9/nu IzdNtPa67WVgYeIS+Ua7+qKxInrEOEB9+Ma1Bu54wXA74dMoKeTuMHxj/IZM2/S3Stot QnSDowF+A3tN85Fl6+wdjCa4xC5c8LD8RxTs1jZuCcvmSOwCGbyt5qc2nfePquhm3579 L8Xg== 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=qf4Pp5ijbq1ESnyFRa0/290auhjWPx+ZOW2jU5UmNAs=; b=QwoMADQFpdwQF6j69qLdl1D1qAPYd6qH3L9Wxzz+oPgRN0k7crO/r1Hizu1xyvOmUE Gjf1leUu6DjqFEWcUUOXcHc7de95V+tMs6uZG6/UZyRx4m1FJbV/kVDPFuEG0RM9BpPJ KVCKpptq++QReJ52ZAB4/oMuKXd0X9cJvuh6IRecK0EpFuZPoMFk09IaLuz8WdJvPd9F gel2Kk7ihuowM+kZOaCMzyMls8YMsZdkr5GrRkv/nDsizpoLRiJa1jwbqWBaY0hwU/8o GwGwokFcnh+MX0rwWYXUR40Ppo6GgaZ9ufOH+FHwL1tsjJmVIwy/gyr7Fkk6XeHhLhIf 6c8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=hmU3q8BM; 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 b10si13320510pgn.43.2017.08.01.02.30.10; Tue, 01 Aug 2017 02:30:11 -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=hmU3q8BM; 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 S1751974AbdHAJaI (ORCPT + 26 others); Tue, 1 Aug 2017 05:30:08 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:33921 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751623AbdHAJ3A (ORCPT ); Tue, 1 Aug 2017 05:29:00 -0400 Received: by mail-pf0-f181.google.com with SMTP id o86so2174525pfj.1 for ; Tue, 01 Aug 2017 02:29:00 -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=qf4Pp5ijbq1ESnyFRa0/290auhjWPx+ZOW2jU5UmNAs=; b=hmU3q8BMnUu+t7QQQcQEfHvVQ5fft0Rzd+wwGP4w68tlUoDeNnhhHKdjnMr4yxfYR7 ytlNJxZlPkUCYCcC/vAUDcTNhoRbvGeOuLpIzMXTuf/u3pqAJ6xD51mCL9jeZWXOhIRy AzN4gikf9095p4zT+si0nYXGgmGqr50pYpgKI= 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=qf4Pp5ijbq1ESnyFRa0/290auhjWPx+ZOW2jU5UmNAs=; b=G3OtVqpKPG7vx71ZVqUxrViAnDhmcHGahRnNLOfrtxgFwGs2IJBE5fdDJTpLHHM0NP nwO1p+RMZ3jgaJliOpOF2Xy2hi4qcaw8+gymYq9pNBMNq4wwFbDaR00GIMUDgBWkoDAj ywwylcieL/3LJJFIwQGiOzxrP1pc9ltXTKTtkLrvASQEV+q2m2zuetQYwtBTQQk7OozC gFLrOezAh8+wl+qupgexfaDXRL4HPAgjeMBnXl22CTVB3aQ0CGAOWUR5BR7kJtKRYzlA JNSqetri7Cy/VPMOo+tZFjxRSTt9mZP2nIuIAjMgS+OcTwIklRixlvCUfaOSk4rvqxPZ +fow== X-Gm-Message-State: AIVw112ccn+a7VTpqA1vhBT9p7hhCtxHSQk+eXJ3Gecthj1swPeIPdGe X6EU3GtXuB9ViRnm X-Received: by 10.84.228.200 with SMTP id y8mr20525131pli.102.1501579740172; Tue, 01 Aug 2017 02:29:00 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id e5sm60869248pfd.41.2017.08.01.02.28.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:28:59 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Mark Brown , Stephen Boyd , Rajendra Nayak , Shiraz Hashim , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com Subject: [PATCH V3 4/8] drivers: boot_constraint: Add support for clk constraints Date: Tue, 1 Aug 2017 14:53:45 +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 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/base/boot_constraints/Makefile | 2 +- drivers/base/boot_constraints/clk.c | 70 ++++++++++++++++++++++++++++++++++ drivers/base/boot_constraints/core.c | 4 ++ drivers/base/boot_constraints/core.h | 3 ++ include/linux/boot_constraint.h | 5 +++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 drivers/base/boot_constraints/clk.c -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile index a45616f0c3b0..3424379fd1e4 100644 --- a/drivers/base/boot_constraints/Makefile +++ b/drivers/base/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/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c new file mode 100644 index 000000000000..b5b1d63c3e76 --- /dev/null +++ b/drivers/base/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/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c index 06b618a85c0a..88568ed1bfad 100644 --- a/drivers/base/boot_constraints/core.c +++ b/drivers/base/boot_constraints/core.c @@ -105,6 +105,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/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h index 73b9d2d22a12..4f28ac2ef691 100644 --- a/drivers/base/boot_constraints/core.h +++ b/drivers/base/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 d19b8ec2f10d..a2696002e6e1 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;