From patchwork Tue Aug 1 09:23:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109120 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1267031qge; Tue, 1 Aug 2017 02:28:58 -0700 (PDT) X-Received: by 10.84.131.163 with SMTP id d32mr20009391pld.16.1501579738343; Tue, 01 Aug 2017 02:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579738; cv=none; d=google.com; s=arc-20160816; b=q80rTQ5AeUnfChNlBaoumqYs15yAWodDPQ93UB9pOCGYZyOYaHuBiCb7Kdm6+EXxL6 ayPa21rQ3fQIm3oiyib06ea7qSuLkzxRGzmoWJ4+DiaKgH5Ht058QyzPDBOs/JX6iVxE hebRqwj4rzvwH7QascY8q9SDgEhboK3KEKlO7uDnEiCcQrPeZyepYtsDrulmmgKtLoVv a2LHE4nf1gKafO6quWB2oIUwAYr58AK99L7dceXKcysICZM5qfv9gwYcbGD1UktV9J2m irOvbDCl8N8dPT0gcCpXUm0gyHS5V2ANU0XrSBFppu4C1qReHgt/dt8IVS/1XAV29h0j waWA== 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=Bn3eKKtJ+ja/c3q4C2aIQGvbuWmnJRzIILYqL7H80c0=; b=kj1+WBacuYRjwfa37b4EJwO7HJ/YKR5+/rS7Pw7467UHNcGbHXleqRBZX1W73KTSrr M53cJheK4uFbd/7nzuxNJi/VyXAs4/u4Uhq8puwrjzSC/DsH5lbyk3ZQssI09W247/4s LIN2+eiIl90ToQPLd3PG3N2VCk0ae2C6GczNuvUGuJ1NMWynK8TtpUyxr45tXVdf7Lm5 uig2oJPOmQxI0FOx12JflYkZWSFVqR/87cMPESlymPncb21KGGrrcsF/ksm9QgrzIU2s AR1iB06B6i/TYfzPUsHXaP3l86OXdF3UNQB7nuVtdraNQ3QDy10UIwgEv9ElEqcl+hHj 0nBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=Pmb0q9x5; 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 32si16891423plb.992.2017.08.01.02.28.58; Tue, 01 Aug 2017 02:28:58 -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=Pmb0q9x5; 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 S1751802AbdHAJ2z (ORCPT + 26 others); Tue, 1 Aug 2017 05:28:55 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:33888 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751623AbdHAJ2v (ORCPT ); Tue, 1 Aug 2017 05:28:51 -0400 Received: by mail-pf0-f180.google.com with SMTP id o86so2173084pfj.1 for ; Tue, 01 Aug 2017 02:28:51 -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=Bn3eKKtJ+ja/c3q4C2aIQGvbuWmnJRzIILYqL7H80c0=; b=Pmb0q9x5zhskMUQ35sCoWgfKENytco8QiJvnudPFoxKdUcntFxzvFkFArtVOXI4zd2 sUYO26FskUN4x1CyuJY4dtxZu/7kQBLfgIoYMf0mEuUXNHWgf398ot9IFuFApB/O/sCX HFY9cmp/J6TU7k3qa3m0M4ksdIEGsbJdHEguU= 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=Bn3eKKtJ+ja/c3q4C2aIQGvbuWmnJRzIILYqL7H80c0=; b=Gxzfwub9JLnd45gi5efEOvpFbO5yXfGr9R9P0bZ/q3WEzgPuzpSgwj7/FkRu/RpmGK Er9CVUI5/T355sjs21uTNkLFAL4Idw1HJhlBmaFvblxQYaxD4fEs7zTUpULNcie9WB1l rak5wSAp5Slc3z3QAUwOfI4jG4lzlbp10o1wcL6qyV4rU1z5uEwLZ3wE1UmTqlAZQ03Y gBirDFWi6bQmPBpDJN6G4yICwSoTNs6YCtyCg53KZHTRN6KgpMjwNHaRfEMzUZTqLv14 ssby5hq364rkEG+4+DhXtSAWT+RaoVsc7rYW9dIps+OszbD/3+3crmX6VMn2qQYwMcfO cQWA== X-Gm-Message-State: AIVw112gYhbX4EzIuGA6ex6mahtGxLBMHbQvBaru+JGb5+jNdXDNKPp3 /OOToc7U6kKfqM0v X-Received: by 10.84.236.4 with SMTP id q4mr20204023plk.423.1501579730788; Tue, 01 Aug 2017 02:28:50 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id p126sm48021509pfp.28.2017.08.01.02.28.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:28:49 -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 1/8] drivers: Add boot constraints core Date: Tue, 1 Aug 2017 14:53:42 +0530 Message-Id: <1a844e27ee7e0b22acf8ea582bf4e8d35f54c84a.1501578037.git.viresh.kumar@linaro.org> 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 Some devices are powered ON by the bootloader before the bootloader handovers control to Linux. It maybe important for those devices to keep working until the time a Linux device driver probes the device and reconfigure its resources. A typical example of that can be the LCD controller, which is used by the bootloaders to show image(s) while the platform is booting into Linux. The LCD controller can be using some resources, like clk, regulators, PM domain, etc, that are shared between several devices. These shared resources should be configured to satisfy need of all the users. If another device's (X) driver gets probed before the LCD controller driver in this case, then it may end up reconfiguring these resources to ranges satisfying the current users (only device X) and that can make the LCD screen unstable. This patch introduces the concept of boot-constraints, which will be set by the bootloaders and the kernel will satisfy them until the time driver for such a device is probed (successfully or unsuccessfully). The list of boot constraint types is empty for now, and will be incrementally updated by later patches. Only two routines are exposed by the boot constraints core for now: - dev_boot_constraint_add(): This shall be called by parts of the kernel (before the device is probed) to set the constraints. - dev_boot_constraints_remove(): This is called only by the driver core after a device is probed successfully or unsuccessfully. Special handling is done here for deffered probing. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/base/Kconfig | 10 ++ drivers/base/Makefile | 1 + drivers/base/boot_constraints/Makefile | 3 + drivers/base/boot_constraints/core.c | 199 +++++++++++++++++++++++++++++++++ drivers/base/boot_constraints/core.h | 33 ++++++ drivers/base/dd.c | 20 ++-- include/linux/boot_constraint.h | 46 ++++++++ 7 files changed, 305 insertions(+), 7 deletions(-) create mode 100644 drivers/base/boot_constraints/Makefile create mode 100644 drivers/base/boot_constraints/core.c create mode 100644 drivers/base/boot_constraints/core.h create mode 100644 include/linux/boot_constraint.h -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index f046d21de57d..2333db2a33b7 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -347,4 +347,14 @@ config GENERIC_ARCH_TOPOLOGY appropriate scaling, sysfs interface for changing capacity values at runtime. +config DEV_BOOT_CONSTRAINTS + bool "Boot constraints for devices" + help + This enables boot constraints detection for devices. These constraints + are (normally) set by the Bootloader and must be satisfied by the + kernel until the relevant device driver is probed. Once the driver is + probed, the constraint is dropped. + + If unsure, say N. + endmenu diff --git a/drivers/base/Makefile b/drivers/base/Makefile index 397e5c344e6a..8c37ca07114b 100644 --- a/drivers/base/Makefile +++ b/drivers/base/Makefile @@ -5,6 +5,7 @@ obj-y := component.o core.o bus.o dd.o syscore.o \ cpu.o firmware.o init.o map.o devres.o \ attribute_container.o transport_class.o \ topology.o container.o property.o cacheinfo.o +obj-$(CONFIG_DEV_BOOT_CONSTRAINTS) += boot_constraints/ obj-$(CONFIG_DEVTMPFS) += devtmpfs.o obj-$(CONFIG_DMA_CMA) += dma-contiguous.o obj-y += power/ diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile new file mode 100644 index 000000000000..0f2680177974 --- /dev/null +++ b/drivers/base/boot_constraints/Makefile @@ -0,0 +1,3 @@ +# Makefile for device boot constraints + +obj-y := core.o diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c new file mode 100644 index 000000000000..366a05d6d9ba --- /dev/null +++ b/drivers/base/boot_constraints/core.c @@ -0,0 +1,199 @@ +/* + * This takes care of boot time device constraints, normally set by the + * Bootloader. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#define pr_fmt(fmt) "Boot Constraints: " fmt + +#include +#include +#include +#include + +#include "core.h" + +#define for_each_constraint(_constraint, _temp, _cdev) \ + list_for_each_entry_safe(_constraint, _temp, &_cdev->constraints, node) + +/* Global list of all constraint devices currently registered */ +static LIST_HEAD(constraint_devices); +static DEFINE_MUTEX(constraint_devices_mutex); + +/* Boot constraints core */ + +static struct constraint_dev *constraint_device_find(struct device *dev) +{ + struct constraint_dev *cdev; + + list_for_each_entry(cdev, &constraint_devices, node) { + if (cdev->dev == dev) + return cdev; + } + + return NULL; +} + +static struct constraint_dev *constraint_device_allocate(struct device *dev) +{ + struct constraint_dev *cdev; + + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); + if (!cdev) + return ERR_PTR(-ENOMEM); + + cdev->dev = dev; + INIT_LIST_HEAD(&cdev->node); + INIT_LIST_HEAD(&cdev->constraints); + + list_add(&cdev->node, &constraint_devices); + + return cdev; +} + +static void constraint_device_free(struct constraint_dev *cdev) +{ + list_del(&cdev->node); + kfree(cdev); +} + +static struct constraint_dev *constraint_device_get(struct device *dev) +{ + struct constraint_dev *cdev; + + cdev = constraint_device_find(dev); + if (cdev) + return cdev; + + cdev = constraint_device_allocate(dev); + if (IS_ERR(cdev)) { + dev_err(dev, "Failed to add constraint dev (%ld)\n", + PTR_ERR(cdev)); + } + + return cdev; +} + +static void constraint_device_put(struct constraint_dev *cdev) +{ + if (!list_empty(&cdev->constraints)) + return; + + constraint_device_free(cdev); +} + +static struct constraint *constraint_allocate(struct constraint_dev *cdev, + enum dev_boot_constraint_type type) +{ + struct constraint *constraint; + int (*add)(struct constraint *constraint, void *data); + void (*remove)(struct constraint *constraint); + + switch (type) { + default: + return ERR_PTR(-EINVAL); + } + + constraint = kzalloc(sizeof(*constraint), GFP_KERNEL); + if (!constraint) + return ERR_PTR(-ENOMEM); + + constraint->cdev = cdev; + constraint->type = type; + constraint->add = add; + constraint->remove = remove; + INIT_LIST_HEAD(&constraint->node); + + list_add(&constraint->node, &cdev->constraints); + + return constraint; +} + +static void constraint_free(struct constraint *constraint) +{ + list_del(&constraint->node); + kfree(constraint); +} + +int dev_boot_constraint_add(struct device *dev, + struct dev_boot_constraint_info *info) +{ + struct constraint_dev *cdev; + struct constraint *constraint; + int ret; + + mutex_lock(&constraint_devices_mutex); + + /* Find or add the cdev type first */ + cdev = constraint_device_get(dev); + if (IS_ERR(cdev)) { + ret = PTR_ERR(cdev); + goto unlock; + } + + constraint = constraint_allocate(cdev, info->constraint.type); + if (IS_ERR(constraint)) { + dev_err(dev, "Failed to add constraint type: %d (%ld)\n", + info->constraint.type, PTR_ERR(constraint)); + ret = PTR_ERR(constraint); + goto put_cdev; + } + + constraint->free_resources = info->free_resources; + constraint->free_resources_data = info->free_resources_data; + + /* Set constraint */ + ret = constraint->add(constraint, info->constraint.data); + if (ret) + goto free_constraint; + + dev_dbg(dev, "Added boot constraint-type (%d)\n", + info->constraint.type); + + mutex_unlock(&constraint_devices_mutex); + + return 0; + +free_constraint: + constraint_free(constraint); +put_cdev: + constraint_device_put(cdev); +unlock: + mutex_unlock(&constraint_devices_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_boot_constraint_add); + +static void constraint_remove(struct constraint *constraint) +{ + constraint->remove(constraint); + + if (constraint->free_resources) + constraint->free_resources(constraint->free_resources_data); + + constraint_free(constraint); +} + +void dev_boot_constraints_remove(struct device *dev) +{ + struct constraint_dev *cdev; + struct constraint *constraint, *temp; + + mutex_lock(&constraint_devices_mutex); + + cdev = constraint_device_find(dev); + if (!cdev) + goto unlock; + + for_each_constraint(constraint, temp, cdev) + constraint_remove(constraint); + + constraint_device_put(cdev); +unlock: + mutex_unlock(&constraint_devices_mutex); +} diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h new file mode 100644 index 000000000000..7ba4ac172c09 --- /dev/null +++ b/drivers/base/boot_constraints/core.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ +#ifndef _CORE_H +#define _CORE_H + +#include +#include +#include + +struct constraint_dev { + struct device *dev; + struct list_head node; + struct list_head constraints; +}; + +struct constraint { + struct constraint_dev *cdev; + struct list_head node; + enum dev_boot_constraint_type type; + void (*free_resources)(void *data); + void *free_resources_data; + + int (*add)(struct constraint *constraint, void *data); + void (*remove)(struct constraint *constraint); + void *private; +}; + +/* Forward declarations of constraint specific callbacks */ +#endif /* _CORE_H */ diff --git a/drivers/base/dd.c b/drivers/base/dd.c index c17fefc77345..2262a4a4c0e4 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -17,6 +17,7 @@ * This file is released under the GPLv2 */ +#include #include #include #include @@ -383,15 +384,20 @@ static int really_probe(struct device *dev, struct device_driver *drv) */ devices_kset_move_last(dev); - if (dev->bus->probe) { + if (dev->bus->probe) ret = dev->bus->probe(dev); - if (ret) - goto probe_failed; - } else if (drv->probe) { + else if (drv->probe) ret = drv->probe(dev); - if (ret) - goto probe_failed; - } + + /* + * Remove boot constraints for both successful and unsuccessful probe(), + * except for the case where EPROBE_DEFER is returned by probe(). + */ + if (ret != -EPROBE_DEFER) + dev_boot_constraints_remove(dev); + + if (ret) + goto probe_failed; if (test_remove) { test_remove = false; diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h new file mode 100644 index 000000000000..ae34fee547c5 --- /dev/null +++ b/include/linux/boot_constraint.h @@ -0,0 +1,46 @@ +/* + * Boot constraints header. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2 + */ +#ifndef _LINUX_BOOT_CONSTRAINT_H +#define _LINUX_BOOT_CONSTRAINT_H + +#include +#include + +struct device; + +enum dev_boot_constraint_type { + DEV_BOOT_CONSTRAINT_NONE, +}; + +struct dev_boot_constraint { + enum dev_boot_constraint_type type; + void *data; +}; + +struct dev_boot_constraint_info { + struct dev_boot_constraint constraint; + + /* This will be called just before the constraint is removed */ + void (*free_resources)(void *data); + void *free_resources_data; +}; + +#ifdef CONFIG_DEV_BOOT_CONSTRAINTS +int dev_boot_constraint_add(struct device *dev, + struct dev_boot_constraint_info *info); +void dev_boot_constraints_remove(struct device *dev); +#else +static inline +int dev_boot_constraint_add(struct device *dev, + struct dev_boot_constraint_info *info); +{ return -EINVAL; } +static inline void dev_boot_constraints_remove(struct device *dev) {} +#endif /* CONFIG_DEV_BOOT_CONSTRAINTS */ + +#endif /* _LINUX_BOOT_CONSTRAINT_H */ From patchwork Tue Aug 1 09:23:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109131 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1268489qge; Tue, 1 Aug 2017 02:30:32 -0700 (PDT) X-Received: by 10.98.34.201 with SMTP id p70mr18504980pfj.330.1501579832126; Tue, 01 Aug 2017 02:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579832; cv=none; d=google.com; s=arc-20160816; b=rwn71OXyLfVxacf+LaHkCZn6UH2WIEWXscLShdlEScRgmKiHX09lHaJhEn5VBG6XwM 8wrClM/lsaFD7VK5jwCFDB5J0VnJgHjG2mzgOfi9nNiNAXKI/1jZRKMT6f+vwfmcOQjV MUXcFam3o4PiLzM/r8H1WbFeEEznQ1Nsi0dOaKJTzsl2QXSB+EfnBJSTO3jedbwI2Lie Y/W/kFkID75n1VpAtQbalID3UbxApNJ0VquRyeqfWQ+ihCRRux30fTHThD8ZPcUx1G1j ofTmo7ts211D13Nds7Td8d3qbaeP/ElAGB4udlHUAtu9om9SRHqW+QfJtiMcLI+ZujBd ZIMw== 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=aH8FdonCLl0m8Z3J7tViAvmmWIkQ8wHx84A/SUHjLg8=; b=s+OPxf1CNO/zf/ZqOIbqR6Jf4+WoYApwYxO5tOVYRh8MCSXBsO/+2Kwc0TodUAwgRx ACVaGb/J2QabIPxmfK+o6hOCzfXo7yROqx68oLCdHnxxQsUq7u+TjKuH0t0RNy26Af55 K6wZzuxGzZkb2o530PUvaWlINhbdiDNWWTJZngxYjq56kOVAT+hfOtBxB/6jOI9f//ok 2JkY9eis9RZPqtO9a0pyqsbck2Qxaciv1+svlqjmpYR//0ntC4bdbeYpC6rqGhugfVmx 8Hs3aFFXrXpQ0Ij6juyBdLc78kh+S0UCcK1z6EmTdwskivDxKi6GeNWqFa+n4mNrapIk K00A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=XoWlccBu; 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 j10si17567484pfc.13.2017.08.01.02.30.31; Tue, 01 Aug 2017 02:30:32 -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=XoWlccBu; 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 S1751993AbdHAJa3 (ORCPT + 26 others); Tue, 1 Aug 2017 05:30:29 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:33550 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751680AbdHAJ2y (ORCPT ); Tue, 1 Aug 2017 05:28:54 -0400 Received: by mail-pf0-f172.google.com with SMTP id d67so5614447pfc.0 for ; Tue, 01 Aug 2017 02:28:54 -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=aH8FdonCLl0m8Z3J7tViAvmmWIkQ8wHx84A/SUHjLg8=; b=XoWlccBufOT5MRayOPCO5bsLalMaVjorNtK88xC4l8vAMHcpGUUgB8xE05ZX9EU6NP esq9SmD/AFq7+lgncMcgswdkCfFgO+61IJKR2xyLNixJmD66yFr+oZSEUUeKhAJTOc5Q 3eVlpkKuRhm7RFWLPPGoqQTxqfYKBpXnh5gA8= 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=aH8FdonCLl0m8Z3J7tViAvmmWIkQ8wHx84A/SUHjLg8=; b=fmKnIEEluiFlgc3wTfyojoQpb8+ZYjx/rQUDWNcFoJUcfserofRN8fCm6sApB8p6BS vcEQXlQYm+myvWGQ6qw2XskyKLMFWyYzHBI1nvtsanB+Y5Xjb1+K08LrnG5OPUlino/C iLN7l8OPyUegfxGI2eocodKi0DPk/GR/5ikBpUBnTWCKirCFdYvhD2V6ll5J25V+hAj8 2nUjbCn6TyxwmbtUw28du5PtRE7gYiI5GWSPHFddZMeA18eSdvOLvVxFiXFbVmfCPm+a wyBsNf8/vpjogetS8LNjCzdg6YEZuFXV8FRFkLLUGy8tjuAXOnvKEP/0R9LJRnTf2oV4 Gu6Q== X-Gm-Message-State: AIVw111879eamNguDRRle3Isbvord++5E7gTXdKVhM7BLnh7Snt6V56g 7EJYhvICSdWetVRv X-Received: by 10.98.215.21 with SMTP id b21mr3205762pfh.120.1501579733947; Tue, 01 Aug 2017 02:28:53 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id a87sm8569597pfg.18.2017.08.01.02.28.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:28:53 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman , Jonathan Corbet 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, linux-doc@vger.kernel.org Subject: [PATCH V3 2/8] drivers: boot_constraint: Add boot_constraints_disable kernel parameter Date: Tue, 1 Aug 2017 14:53:43 +0530 Message-Id: <4bec0c3e58f76e06e5305c5ddbab859e2a87935e.1501578037.git.viresh.kumar@linaro.org> 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 Users must be given an option to discard any constraints set by bootloaders. For example, consider that a constraint is set for the LCD controller's supply and the LCD driver isn't loaded by the kernel. If the user doesn't need to use the LCD device, then he shouldn't be forced to honour the constraint. We can also think about finer control of such constraints with help of some sysfs files, but a kernel parameter is fine to begin with. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- Documentation/admin-guide/kernel-parameters.txt | 3 +++ drivers/base/boot_constraints/core.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) -- 2.13.0.71.gd7076ec9c9cb diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index d9c171ce4190..0706d1b6004d 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -426,6 +426,9 @@ embedded devices based on command line input. See Documentation/block/cmdline-partition.txt + boot_constraints_disable + Do not set any boot constraints for devices. + boot_delay= Milliseconds to delay each printk during boot. Values larger than 10 seconds (10000) are changed to no delay (0). diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c index 366a05d6d9ba..e0c33b2b216f 100644 --- a/drivers/base/boot_constraints/core.c +++ b/drivers/base/boot_constraints/core.c @@ -24,6 +24,17 @@ static LIST_HEAD(constraint_devices); static DEFINE_MUTEX(constraint_devices_mutex); +static bool boot_constraints_disabled; + +static int __init constraints_disable(char *str) +{ + boot_constraints_disabled = true; + pr_debug("disabled\n"); + + return 0; +} +early_param("boot_constraints_disable", constraints_disable); + /* Boot constraints core */ static struct constraint_dev *constraint_device_find(struct device *dev) @@ -126,6 +137,9 @@ int dev_boot_constraint_add(struct device *dev, struct constraint *constraint; int ret; + if (boot_constraints_disabled) + return -ENODEV; + mutex_lock(&constraint_devices_mutex); /* Find or add the cdev type first */ @@ -184,6 +198,9 @@ void dev_boot_constraints_remove(struct device *dev) struct constraint_dev *cdev; struct constraint *constraint, *temp; + if (boot_constraints_disabled) + return; + mutex_lock(&constraint_devices_mutex); cdev = constraint_device_find(dev); From patchwork Tue Aug 1 09:23:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109121 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1267107qge; Tue, 1 Aug 2017 02:29:04 -0700 (PDT) X-Received: by 10.84.174.3 with SMTP id q3mr20907203plb.289.1501579744844; Tue, 01 Aug 2017 02:29:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579744; cv=none; d=google.com; s=arc-20160816; b=lCzGhsz5bw7d0V/DocKfnJK1SVaT6FjdAD/vxsn855s/ttsLnBdpPEfIxOMsYGvz2Z uUbsmdS0m/eWGq4tmCatN76b6u+QNnDKO/NgWQf0/FDYMEScEIdvymfg3/sICSWUD6Oy mhts867fGRZQGssvxEgTeTD4AmLnbgIRoE8akEkWPDLUpBoUsgnRQErwzm10n5QhquWX fetBKM7Bp8bQDsXmqs5+6zycyqIrOit5jBFdBW1Iv4a1YbI3iqbBvOJoxCai7xRbeDTa kGe+uT3juMmHbGWvLNM/JqUnQX/4Sl3T8/0vDpbgLj0aXLZj6jd8TC/NopN6NJh/xK7e 2epg== 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=eRIiqaooxX0dycstPkKuTrk/FPgZsmSWzTlHoeYia6I=; b=pXUxYDJ16vSqtQkJWSOJKvmyb5bg50fpzWVjSQg801jfQEh9P1RhPhKnyzsuAO34yu +CPQ9CYZTkvjQ79M0hseKVNOsOAtjou2DjQeixXJR4H1EF2pCsKi/g7h3bGXvgcc0i4i 2aeJGUgGO6mf+3R1FmJUkWjgaI2cBVRnS/ABK/SD3Xx4mv9bmhq+/VQddYGT/8EYtoSF ynb0ZLExJpuk2DI4cJp20fCAF4hvP+sWZbsW60aFqhNKEmbq42M831eix3PH+iNrF7Qs D6BvqwYhQLfp16KBJU97EZ6ne4DKUEpy29frw+Dj5kktYOp0aPjEMehck52fZY3NzVMJ jB4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=YPKkkZlu; 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 s132si17915082pgs.645.2017.08.01.02.29.04; Tue, 01 Aug 2017 02:29:04 -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=YPKkkZlu; 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 S1751833AbdHAJ3C (ORCPT + 26 others); Tue, 1 Aug 2017 05:29:02 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:35124 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbdHAJ25 (ORCPT ); Tue, 1 Aug 2017 05:28:57 -0400 Received: by mail-pf0-f175.google.com with SMTP id t86so5525365pfe.2 for ; Tue, 01 Aug 2017 02:28:57 -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=eRIiqaooxX0dycstPkKuTrk/FPgZsmSWzTlHoeYia6I=; b=YPKkkZlubtl7mmyywj+UYemg7c5p/VDw+ve3m9ns4Xs9CZX0vu/gG4S0pqZhqX0T8f A9DzkU1iX4TZVj686XU+4/HQ0dBZ+qdO4TrbfpnYrcnclqomxN2vsC5PQ1CZ8K/wkt3x KZNejaLsk5BbEKSJSYNZe14GsjCLm6pKm6reM= 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=eRIiqaooxX0dycstPkKuTrk/FPgZsmSWzTlHoeYia6I=; b=NxQmJuefxkDJ5G7K/GyaczKybYoHoM/osXCGqfWf4p8lP5eZKoVnGLCCYfkUzDuFf0 CHxxA9fTGLFGrCE3qJexrmZN74ZPhVrUrIckZvUu6tyxPKx+aMtL2WLS+ppTn0Ey7tvN BK4SUlMx7hMKudWr+W7xpDzahrCGCpC9uMRJPMqrpDSIwVP2kzRSsJ/zUoTOHp3RJXGK 58TCql25rZBwpgMXbIyX0wNh2IZ6zkF/S7frRgt+UynzmRvga03/M6jEDNPgZd593BGx hbqOhpj50rIcyaZPwwji1TPso3+6QPi6H2l289twIS9yDJjA5oCkzC7YIetegii97Wyz QEYQ== X-Gm-Message-State: AIVw110Gi5eA09vWquENftqRztJp398f+OLUkK93lISLE2ll44cKZCu7 XkfMg+JP6ymvQlDw X-Received: by 10.84.224.207 with SMTP id k15mr20375047pln.108.1501579737106; Tue, 01 Aug 2017 02:28:57 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id r25sm3714324pgu.7.2017.08.01.02.28.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:28:56 -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 3/8] drivers: boot_constraint: Add support for supply constraints Date: Tue, 1 Aug 2017 14:53:44 +0530 Message-Id: <0ba4891f8e7152438e6ad66b096e960646b39ad8.1501578037.git.viresh.kumar@linaro.org> 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 first constraint type: power-supply. The constraint is set by enabling the regulator and setting a voltage range (if required) for the respective regulator device, which will be honored by the regulator core even if more users turn up. Once the device is probed, the regulator is released and the constraint is removed. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/base/boot_constraints/Makefile | 2 +- drivers/base/boot_constraints/core.c | 4 ++ drivers/base/boot_constraints/core.h | 3 ++ drivers/base/boot_constraints/supply.c | 98 ++++++++++++++++++++++++++++++++++ include/linux/boot_constraint.h | 8 ++- 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 drivers/base/boot_constraints/supply.c -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile index 0f2680177974..a45616f0c3b0 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 +obj-y := core.o supply.o diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c index e0c33b2b216f..06b618a85c0a 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_SUPPLY: + add = constraint_supply_add; + remove = constraint_supply_remove; + break; default: return ERR_PTR(-EINVAL); } diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h index 7ba4ac172c09..73b9d2d22a12 100644 --- a/drivers/base/boot_constraints/core.h +++ b/drivers/base/boot_constraints/core.h @@ -30,4 +30,7 @@ struct constraint { }; /* Forward declarations of constraint specific callbacks */ +int constraint_supply_add(struct constraint *constraint, void *data); +void constraint_supply_remove(struct constraint *constraint); + #endif /* _CORE_H */ diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c new file mode 100644 index 000000000000..30f816dbf12c --- /dev/null +++ b/drivers/base/boot_constraints/supply.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#define pr_fmt(fmt) "Supply Boot Constraints: " fmt + +#include +#include +#include + +#include "core.h" + +struct constraint_supply { + struct dev_boot_constraint_supply_info supply; + struct regulator *reg; +}; + +int constraint_supply_add(struct constraint *constraint, void *data) +{ + struct dev_boot_constraint_supply_info *supply = data; + struct constraint_supply *csupply; + struct device *dev = constraint->cdev->dev; + int ret; + + csupply = kzalloc(sizeof(*csupply), GFP_KERNEL); + if (!csupply) + return -ENOMEM; + + csupply->reg = regulator_get(dev, supply->name); + if (IS_ERR(csupply->reg)) { + ret = PTR_ERR(csupply->reg); + if (ret != -EPROBE_DEFER) { + dev_err(dev, "regulator_get() failed for %s (%d)\n", + supply->name, ret); + } + goto free; + } + + if (supply->u_volt_min != 0 && supply->u_volt_max != 0) { + ret = regulator_set_voltage(csupply->reg, supply->u_volt_min, + supply->u_volt_max); + if (ret) { + dev_err(dev, "regulator_set_voltage %s failed (%d)\n", + supply->name, ret); + goto free_regulator; + } + } + + ret = regulator_enable(csupply->reg); + if (ret) { + dev_err(dev, "regulator_enable %s failed (%d)\n", + supply->name, ret); + goto remove_voltage; + } + + memcpy(&csupply->supply, supply, sizeof(*supply)); + csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL); + constraint->private = csupply; + + return 0; + +remove_voltage: + if (supply->u_volt_min != 0 && supply->u_volt_max != 0) + regulator_set_voltage(csupply->reg, 0, INT_MAX); +free_regulator: + regulator_put(csupply->reg); +free: + kfree(csupply); + + return ret; +} + +void constraint_supply_remove(struct constraint *constraint) +{ + struct constraint_supply *csupply = constraint->private; + struct dev_boot_constraint_supply_info *supply = &csupply->supply; + struct device *dev = constraint->cdev->dev; + int ret; + + kfree_const(supply->name); + + ret = regulator_disable(csupply->reg); + if (ret) + dev_err(dev, "regulator_disable failed (%d)\n", ret); + + if (supply->u_volt_min != 0 && supply->u_volt_max != 0) { + ret = regulator_set_voltage(csupply->reg, 0, INT_MAX); + if (ret) + dev_err(dev, "regulator_set_voltage failed (%d)\n", + ret); + } + + regulator_put(csupply->reg); + kfree(csupply); +} diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index ae34fee547c5..d19b8ec2f10d 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -15,7 +15,13 @@ struct device; enum dev_boot_constraint_type { - DEV_BOOT_CONSTRAINT_NONE, + DEV_BOOT_CONSTRAINT_SUPPLY, +}; + +struct dev_boot_constraint_supply_info { + const char *name; + unsigned int u_volt_min; + unsigned int u_volt_max; }; struct dev_boot_constraint { 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; From patchwork Tue Aug 1 09:23:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109123 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1267248qge; Tue, 1 Aug 2017 02:29:14 -0700 (PDT) X-Received: by 10.84.137.169 with SMTP id 38mr20047525pln.331.1501579754484; Tue, 01 Aug 2017 02:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579754; cv=none; d=google.com; s=arc-20160816; b=tQVmo0wqwFPjSOaf5YeQtppXOEaT4Q14QsgkFngbNJmBWkORw9NVovdtPpKlW9Y61Q H4i3xPZhYdfDc4rPMwBC4CvgvYOrtiGf8fJnjIPLgLpwaYL8qzpXJybqaU7V4Af1gMP0 9oP/w8fs/SmVWmZ0QVS09f0eeVdMBQtS77ZoF2c1xakk9Oi5tQIifaSQ4UXB4fADNd0x Er2/VtSpOMPErcNgsbe1akr2gKkbPdIssqDHkCPbdkjZe3ySJ50kCuwg/6nspJB8Zqqj fYuaOpiXJYtKCt+0LKBZ5iRQz2PTEqcFJgrRwfFKkmKvff6qn68aiRCHRPMOIxpFBlDD GvHg== 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=Mqqdzezdl5DkbZhvHySyzv7MgeW/7FaWvioq1S2dX80=; b=dos1o4wvpgUHLjQyxVKbkZyrBtRBiXJpg25hERMhhBOWk+N8Wfc7LNPFcmEXv8wubx EZ0Off6eALJBL19aH/Y9UbbIn8r4MrO0KF0cBj7bVkJNG5l/vlDpq/MkcF/NDX5mjIcs qN36U9+wYvo9uNulHGqEnW8cQ7/m4hd/HpU7VqDSrGZzI3s7x5V51FmKZR7NAXa8mW/k /R0k3mQwLa1R8YI+2HXSWMUuXUwicGR/UyQqpL5ZG2WFftxW138Qf3iMzFp1Enwk1Jsg 3i0zRCvYiswM3lhK8uJ7vdO8515tAxlU+gwq2FhDSN0eSxC7e/6PXRuJnYVAp2zP8MW5 WN7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=kDcKwmcZ; 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 m23si17071326plk.953.2017.08.01.02.29.13; Tue, 01 Aug 2017 02:29:14 -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=kDcKwmcZ; 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 S1751923AbdHAJ3K (ORCPT + 26 others); Tue, 1 Aug 2017 05:29:10 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:37315 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbdHAJ3D (ORCPT ); Tue, 1 Aug 2017 05:29:03 -0400 Received: by mail-pg0-f49.google.com with SMTP id y129so5688995pgy.4 for ; Tue, 01 Aug 2017 02:29:03 -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=Mqqdzezdl5DkbZhvHySyzv7MgeW/7FaWvioq1S2dX80=; b=kDcKwmcZMyACBTHZ+ebar8USfVgf3XFAGZVBFgxTHPPqGG6t0O4TJbeqf6lTaJozIw X0DcRJxzbos9Nwj632jhIMaLbxq887oHOLw7h6Px8IcMR01eYW/+xU9alB6fZkpW5zRE ouWC0UpB7iSlQeFJrnifonVgJzvoCqhuIlb/4= 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=Mqqdzezdl5DkbZhvHySyzv7MgeW/7FaWvioq1S2dX80=; b=e04TD141CnWrtDiIKIt2XmLNGjVBFj5CoFX4dsH9zvGe/0GdGuGWmU65dSMLMxp0ay J/Frpumcw21E9xzBv2X0n/2sGCnBSfUOSCN12sDxPgxI82XA/lTozg3amAdZG/BrxR68 YBgQm+37sU7jg5iXdh20cu5Tf3RJ2peP5AgOUkpdBbXyNc2Zhi4rrxc7W9LAEYDuTwQG vKZdQ2bs15Zfg8TFnigryL+otszRenFdcFkwXZfKdJJf97MtbC9QxoAct0Rz/yGfWa9a fLw6F2muxYw3owxsp08JWuT0JYvUzXyVyUhbNK6wHXoHHLW4Z1OXmAE77dJuY0AiyV4t HpeQ== X-Gm-Message-State: AIVw1117E39ZzxZ7aW40IahnmPjjlIjRQGWRIfufLVBlLHlEe3tBUFKH 6yHe9kRtvoQcca2B X-Received: by 10.98.40.7 with SMTP id o7mr18261631pfo.124.1501579743419; Tue, 01 Aug 2017 02:29:03 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id e198sm13107539pfh.36.2017.08.01.02.29.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:29:02 -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 5/8] drivers: boot_constraint: Add support for PM constraints Date: Tue, 1 Aug 2017 14:53:46 +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 PM constraint type. The constraint is set by attaching the power domain for the device, which will also enable the power domain. This guarantees that the power domain doesn't get shut down while being used. We don't need to detach the power domain to remove the constraint as the domain is attached only once, from here or before driver probe. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/base/boot_constraints/Makefile | 2 +- drivers/base/boot_constraints/core.c | 4 ++++ drivers/base/boot_constraints/core.h | 3 +++ drivers/base/boot_constraints/pm.c | 24 ++++++++++++++++++++++++ include/linux/boot_constraint.h | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 drivers/base/boot_constraints/pm.c -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile index 3424379fd1e4..b7ade1a7afb5 100644 --- a/drivers/base/boot_constraints/Makefile +++ b/drivers/base/boot_constraints/Makefile @@ -1,3 +1,3 @@ # Makefile for device boot constraints -obj-y := clk.o core.o supply.o +obj-y := clk.o core.o pm.o supply.o diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c index 88568ed1bfad..06267f0c88d4 100644 --- a/drivers/base/boot_constraints/core.c +++ b/drivers/base/boot_constraints/core.c @@ -109,6 +109,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev, add = constraint_clk_add; remove = constraint_clk_remove; break; + case DEV_BOOT_CONSTRAINT_PM: + add = constraint_pm_add; + remove = constraint_pm_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 4f28ac2ef691..a051c3d7c8ab 100644 --- a/drivers/base/boot_constraints/core.h +++ b/drivers/base/boot_constraints/core.h @@ -33,6 +33,9 @@ struct constraint { int constraint_clk_add(struct constraint *constraint, void *data); void constraint_clk_remove(struct constraint *constraint); +int constraint_pm_add(struct constraint *constraint, void *data); +void constraint_pm_remove(struct constraint *constraint); + int constraint_supply_add(struct constraint *constraint, void *data); void constraint_supply_remove(struct constraint *constraint); diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c new file mode 100644 index 000000000000..edba5eca5093 --- /dev/null +++ b/drivers/base/boot_constraints/pm.c @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#define pr_fmt(fmt) "PM Boot Constraints: " fmt + +#include + +#include "core.h" + +int constraint_pm_add(struct constraint *constraint, void *data) +{ + struct device *dev = constraint->cdev->dev; + + return dev_pm_domain_attach(dev, true); +} + +void constraint_pm_remove(struct constraint *constraint) +{ + /* Nothing to do for now */ +} diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index a2696002e6e1..edc9abe7913a 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -16,6 +16,7 @@ struct device; enum dev_boot_constraint_type { DEV_BOOT_CONSTRAINT_CLK, + DEV_BOOT_CONSTRAINT_PM, DEV_BOOT_CONSTRAINT_SUPPLY, }; From patchwork Tue Aug 1 09:23:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109122 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1267194qge; Tue, 1 Aug 2017 02:29:11 -0700 (PDT) X-Received: by 10.84.241.71 with SMTP id u7mr20432369plm.196.1501579751291; Tue, 01 Aug 2017 02:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579751; cv=none; d=google.com; s=arc-20160816; b=tLMiX3X19UWPju4MIkRf3nWhI4llH/Kq7QEWvvaScHX5NftIxRkHk0Xpmbls355jgH mNx1TZvBJA5BFfA8goP+mQchmdN5b8qyIipnkQmFX+mNMSZ60NYvFGE+00tR7wCjU1B4 OAMcm0ApUWs7GZOUlaI7COzm/DJLX+GZT6f3tWezRisqcRp/rBj9c5/FgkZwrQ37uXWA a8m128b+bSugGvNMHa9wiia7oFvVr2kS/taiPzJj38zET1FTG1HxhxBzD4tiodfVGU/x vKPyTXhhn/gpIPHEonaNaF2+q5Xlj6uphFNPMLFpvfhTvMH5vEKo1LOIax4GPV0/0IKv kfqg== 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=6md5ryAp8WswVU2AZXWaVyYJxaC31qCON4ECwcj98no=; b=AWIxW0n0Jy6uZ40DznvCDdt/k5fYbM0ubphOXhHUuwkHqab7tW7iYVPmYIqqXp4j8P sZzw9h7W21Nvik2nDuClaXhjDkW09UItdJHK3GuhO5va+UJEJKyt0Nct2jUY1gNOYiLR H8ImsWhn/Wdax0StRLnCzwzsHZ5Fm5ybpmUt4jbEvzlq9SCCJibw1FLIa+IvTCwVBCS+ uHnEnJ89eIM7N8nqC5YhcOg7hgPruMLBJKYF5lU6Jq7sGySaAHvrbV7QTjD+GqV0RPh+ aHuAUCJLGD2yRr5amsOLw9Mzyexd6NWQz6oRtmELPXsClPMibSptWGyiKNkPXSFW/J45 naFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=UoFE4NjJ; 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 s132si17915082pgs.645.2017.08.01.02.29.10; Tue, 01 Aug 2017 02:29: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=UoFE4NjJ; 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 S1751883AbdHAJ3J (ORCPT + 26 others); Tue, 1 Aug 2017 05:29:09 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:34375 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751834AbdHAJ3H (ORCPT ); Tue, 1 Aug 2017 05:29:07 -0400 Received: by mail-pg0-f43.google.com with SMTP id u185so5716471pgb.1 for ; Tue, 01 Aug 2017 02:29:07 -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=6md5ryAp8WswVU2AZXWaVyYJxaC31qCON4ECwcj98no=; b=UoFE4NjJd+YYv1AztZBRzVRMQQR+g2Hv0llc0sqLmfYh1cmqhU/h+dz5u5C3g0G1Ju RFtMr6qXzsTfhZ9egOWpODVoEzD+uH0DII5lcXbQKKgQERXpY4BOjjWGIa83CuhSRgV5 Qtd0XT2HHgBWkoIRkeQ7aG88/0olBLiaO4T6I= 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=6md5ryAp8WswVU2AZXWaVyYJxaC31qCON4ECwcj98no=; b=qkmEg3NwLTGvpSx2gxJf47NEHienp9Bql4Zu5tgCfZ5d/PYdHovUIcuT9+4l2WrO+4 2wVZQEE/VyrEmSPJVk3hqGMNoin1VNCd1llfRsRdQ1b6z1kR34DqzpAoNXvAiDHdlGcq LjwxGXXWCAoFzt1RHjHbQ11CQ6TDj9NGsVWdybus0uZoNKYzI6moa1buQfNEpe3PWvL7 rbQcntZHG9cUVupamGfeySWJblkAQ/ZdRk3pu2PU2HGnBBMCucNqzoNxPwPprwJu65Iz tTerbnj2PADnfxXM0dx5PPvGOSKtMvYComn65wn6Jl3GXrAlcsVcGNpDJ5ncEjfgJQd1 lZYg== X-Gm-Message-State: AIVw110zv4PZXSYwR6X/gsNLePttOCLiZKm5f7VpAbQQxztcIRNXzqRf 7YOWoc6BtrPK2YdH X-Received: by 10.84.179.165 with SMTP id b34mr20655560plc.455.1501579746772; Tue, 01 Aug 2017 02:29:06 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id z12sm55395702pgs.88.2017.08.01.02.29.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:29:06 -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 6/8] drivers: boot_constraint: Add debugfs support Date: Tue, 1 Aug 2017 14:53:47 +0530 Message-Id: <7a42cfb49a580a07c2045207fe7f1a3cb2096ce3.1501578037.git.viresh.kumar@linaro.org> 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: clk-ciu pm-domain supply-vmmc supply-vmmcaux /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/clk-ciu: /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/pm-domain: /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmc: u_volt_max u_volt_min /sys/kernel/debug/boot_constraints/f723d000.dwmmc0/supply-vmmcaux: u_volt_max u_volt_min Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/base/boot_constraints/clk.c | 4 ++ drivers/base/boot_constraints/core.c | 72 ++++++++++++++++++++++++++++++++++ drivers/base/boot_constraints/core.h | 6 +++ drivers/base/boot_constraints/pm.c | 12 +++++- drivers/base/boot_constraints/supply.c | 10 +++++ 5 files changed, 102 insertions(+), 2 deletions(-) -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraints/clk.c b/drivers/base/boot_constraints/clk.c index b5b1d63c3e76..bdbfcbc2944d 100644 --- a/drivers/base/boot_constraints/clk.c +++ b/drivers/base/boot_constraints/clk.c @@ -49,6 +49,9 @@ int constraint_clk_add(struct constraint *constraint, void *data) cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL); constraint->private = cclk; + /* Debugfs */ + constraint_add_debugfs(constraint, clk_info->name); + return 0; put_clk: @@ -63,6 +66,7 @@ void constraint_clk_remove(struct constraint *constraint) { struct constraint_clk *cclk = constraint->private; + constraint_remove_debugfs(constraint); kfree_const(cclk->clk_info.name); clk_disable_unprepare(cclk->clk); clk_put(cclk->clk); diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c index 06267f0c88d4..c0e3a85ff85a 100644 --- a/drivers/base/boot_constraints/core.c +++ b/drivers/base/boot_constraints/core.c @@ -35,6 +35,76 @@ 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); +} + +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 DEV_BOOT_CONSTRAINT_CLK: + prefix = "clk"; + break; + case DEV_BOOT_CONSTRAINT_PM: + prefix = "pm"; + break; + case DEV_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); +} + +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) @@ -62,12 +132,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); } diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h index a051c3d7c8ab..ee84e237c66a 100644 --- a/drivers/base/boot_constraints/core.h +++ b/drivers/base/boot_constraints/core.h @@ -8,6 +8,7 @@ #define _CORE_H #include +#include #include #include @@ -15,6 +16,7 @@ struct constraint_dev { struct device *dev; struct list_head node; struct list_head constraints; + struct dentry *dentry; }; struct constraint { @@ -23,12 +25,16 @@ struct constraint { enum dev_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); void *private; }; +void constraint_add_debugfs(struct constraint *constraint, const char *suffix); +void constraint_remove_debugfs(struct constraint *constraint); + /* Forward declarations of constraint specific callbacks */ int constraint_clk_add(struct constraint *constraint, void *data); void constraint_clk_remove(struct constraint *constraint); diff --git a/drivers/base/boot_constraints/pm.c b/drivers/base/boot_constraints/pm.c index edba5eca5093..95910d0dc457 100644 --- a/drivers/base/boot_constraints/pm.c +++ b/drivers/base/boot_constraints/pm.c @@ -14,11 +14,19 @@ int constraint_pm_add(struct constraint *constraint, void *data) { struct device *dev = constraint->cdev->dev; + int ret; - return dev_pm_domain_attach(dev, true); + ret = dev_pm_domain_attach(dev, true); + if (ret) + return ret; + + /* Debugfs */ + constraint_add_debugfs(constraint, "domain"); + + return 0; } void constraint_pm_remove(struct constraint *constraint) { - /* Nothing to do for now */ + constraint_remove_debugfs(constraint); } diff --git a/drivers/base/boot_constraints/supply.c b/drivers/base/boot_constraints/supply.c index 30f816dbf12c..b206f500b2bc 100644 --- a/drivers/base/boot_constraints/supply.c +++ b/drivers/base/boot_constraints/supply.c @@ -60,6 +60,15 @@ 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: @@ -80,6 +89,7 @@ void constraint_supply_remove(struct constraint *constraint) struct device *dev = constraint->cdev->dev; int ret; + constraint_remove_debugfs(constraint); kfree_const(supply->name); ret = regulator_disable(csupply->reg); From patchwork Tue Aug 1 09:23:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109125 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1267327qge; Tue, 1 Aug 2017 02:29:18 -0700 (PDT) X-Received: by 10.98.252.23 with SMTP id e23mr18616060pfh.277.1501579758578; Tue, 01 Aug 2017 02:29:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579758; cv=none; d=google.com; s=arc-20160816; b=XilFyP5KJbBK2q1VFttAMS5+WLTyPQNUd5YFSLvl+xvm537UJHrXdqfYcqeYUrCn9f lk52gfRSfOUFyM8by1nAjHdSzUnhZF9fb6aFvIor+07aEanOb8LkEQVCu37lWHdu+fim okkEipAs3/RMNWRMYRQGJsbwEBTKGfrfjXDlcUAIKZc4WKWlGtTSdD25zi/Uc8rY0M+m lOewTWUXlmdkPuWyOVVewatWZ1VB6hWSic2KdEGfRUtKh979sLMunMrzQlsZcOPRQozu v7CXNMYVEFMogNEg7aSc9P9ykATfO6su6hsXsy+VwWMtypPBa3A2bg1IzJFFXEEwfiPE 0ckg== 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=X3NxMmF0TAnr17DvQAQ3pYgH0rtWaQ06KjoMdYLurRQ=; b=O7O2+XcMrp3DavpNlN84N5S1m1KWVfANQHnXdgLugqlA/HRNL2N439pYGprDrHl78x AcpysIy3A0v2mfe8E0iIRsv51yDa60vbft/HWLuCOJEVHCNlfQqtAITxbvOV2TkLrXMx 8BhEVw2Mq1j8B0EEbh/9HgPWI3GbqAe1d0o9omFGF6rPTipFIBpA5oEXbVgzeYw7I9H4 E/EAZGHbKvsfWo+FzYhdXrX5E009pbWaJke73PxR6ezXRxjjw0kaUHL6fGNiCVIyB2uV UZcxQYRxOoZVnxEOON48uIeulk9L69Tpi+346x5lIqPs4abAGFPGLwB8GyuREzNssLMl dqHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=d7ZpyqAu; 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 m23si17071326plk.953.2017.08.01.02.29.18; Tue, 01 Aug 2017 02:29:18 -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=d7ZpyqAu; 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 S1751944AbdHAJ3P (ORCPT + 26 others); Tue, 1 Aug 2017 05:29:15 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:35902 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbdHAJ3K (ORCPT ); Tue, 1 Aug 2017 05:29:10 -0400 Received: by mail-pf0-f176.google.com with SMTP id z129so5529951pfb.3 for ; Tue, 01 Aug 2017 02:29:10 -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=X3NxMmF0TAnr17DvQAQ3pYgH0rtWaQ06KjoMdYLurRQ=; b=d7ZpyqAurY/DJ5X+exA6qKhiVZf16bX7a2sF++s59ETMwQ42nd+gj7tQtRiya3Fnwq /5LDUMVhWYQt9QnWSKlHZog7n82UXR8188PzsS+IhYnl9glf+N/Skr6g27JwUci2cxVy tBj3Pp+GQiwkDjEr3pviqSAeuVoJgKV3IzaxA= 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=X3NxMmF0TAnr17DvQAQ3pYgH0rtWaQ06KjoMdYLurRQ=; b=C6gTmbHw4EP3nlydNRoq07nPrkXEJVVxO73lXe38fC/M9b+TK/QtI+KLGw4ThbT6+R tpAT1x4bJ6/aIsaHfp1N53R/gSZ/mZ0kkPvAGwLREODw5sqaaySroAQMxLxOvxnqAkxU AjhacwM6CLYbzJfkjVWK3LmjSUqYIKlYA3aoBEa0rOQHWWundbPzYUB04BinnHHN1Mrk oIbr5h+IbUB+ozk2Etd1zIhnFfNdzTWlqdXDiEQpQ3w2jjZEc9ZmzTkmqBxnzxkAvCCF G5QstoBN+AwqLP9YzRBhe0fOFP6OBN+fi78UxRyJGR89PvINZveUzoEjUxw4vFEZTSQC UhLA== X-Gm-Message-State: AIVw111724vQtSc11uerhweo09C2aejYd8T1/3TkMz+qxFmoMQfvLs3a YAvLLRMEPEX9UOSq X-Received: by 10.84.168.131 with SMTP id f3mr20079288plb.220.1501579750109; Tue, 01 Aug 2017 02:29:10 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id b4sm51097210pgc.9.2017.08.01.02.29.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:29:09 -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 7/8] drivers: boot_constraint: Manage deferrable constraints Date: Tue, 1 Aug 2017 14:53:48 +0530 Message-Id: <79e1a28ab90d0bb88c47c6179f57542e9d197443.1501578037.git.viresh.kumar@linaro.org> 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 It is possible that some of the resources aren't available at the time constraints are getting set and the boot constraints core will return -EPROBE_DEFER for them. In order to retry adding the constraints at a later point of time (after the resource is added and before any of its users come up), this patch proposes two things: - Each constraint is represented by a virtual platform device, so that it is re-probed again until the time all the dependencies aren't met. The platform device is removed along with the constraint, with help of the free_resources() callback. - Enable early defer probing support by calling driver_enable_deferred_probe(), so that the core retries probing deferred devices every time any device is bound to a driver. This makes sure that the constraint is set before any of the users of the resources come up. This is tested on ARM64 Hikey board where probe was deferred for a device. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/base/base.h | 1 + drivers/base/boot_constraints/Makefile | 2 +- drivers/base/boot_constraints/core.c | 2 +- drivers/base/boot_constraints/core.h | 2 + drivers/base/boot_constraints/deferrable_dev.c | 192 +++++++++++++++++++++++++ drivers/base/dd.c | 12 ++ include/linux/boot_constraint.h | 10 ++ 7 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 drivers/base/boot_constraints/deferrable_dev.c -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/base.h b/drivers/base/base.h index 539432a14b5c..9c117f0dc44c 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -131,6 +131,7 @@ extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); extern void device_block_probing(void); extern void device_unblock_probing(void); +extern void driver_enable_deferred_probe(void); /* /sys/devices directory */ extern struct kset *devices_kset; diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile index b7ade1a7afb5..a765094623a3 100644 --- a/drivers/base/boot_constraints/Makefile +++ b/drivers/base/boot_constraints/Makefile @@ -1,3 +1,3 @@ # Makefile for device boot constraints -obj-y := clk.o core.o pm.o supply.o +obj-y := clk.o deferrable_dev.o core.o pm.o supply.o diff --git a/drivers/base/boot_constraints/core.c b/drivers/base/boot_constraints/core.c index c0e3a85ff85a..8e2f9b8fe80f 100644 --- a/drivers/base/boot_constraints/core.c +++ b/drivers/base/boot_constraints/core.c @@ -24,7 +24,7 @@ static LIST_HEAD(constraint_devices); static DEFINE_MUTEX(constraint_devices_mutex); -static bool boot_constraints_disabled; +bool boot_constraints_disabled; static int __init constraints_disable(char *str) { diff --git a/drivers/base/boot_constraints/core.h b/drivers/base/boot_constraints/core.h index ee84e237c66a..41354f7206bf 100644 --- a/drivers/base/boot_constraints/core.h +++ b/drivers/base/boot_constraints/core.h @@ -32,6 +32,8 @@ struct constraint { void *private; }; +extern bool boot_constraints_disabled; + void constraint_add_debugfs(struct constraint *constraint, const char *suffix); void constraint_remove_debugfs(struct constraint *constraint); diff --git a/drivers/base/boot_constraints/deferrable_dev.c b/drivers/base/boot_constraints/deferrable_dev.c new file mode 100644 index 000000000000..5169882f2af1 --- /dev/null +++ b/drivers/base/boot_constraints/deferrable_dev.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#define pr_fmt(fmt) "Boot Constraints: " fmt + +#include +#include +#include +#include +#include +#include + +#include "../base.h" +#include "core.h" + +static DEFINE_IDA(pdev_index); + +struct boot_constraint_pdata { + struct device *dev; + struct dev_boot_constraint constraint; + int probe_failed; + int index; +}; + +static void boot_constraint_remove(void *data) +{ + struct platform_device *pdev = data; + struct boot_constraint_pdata *pdata = dev_get_platdata(&pdev->dev); + + ida_simple_remove(&pdev_index, pdata->index); + kfree(pdata->constraint.data); + platform_device_unregister(pdev); +} + +/* + * A platform device is added for each and every constraint, to handle + * -EPROBE_DEFER properly. + */ +static int boot_constraint_probe(struct platform_device *pdev) +{ + struct boot_constraint_pdata *pdata = dev_get_platdata(&pdev->dev); + struct dev_boot_constraint_info info; + int ret; + + if (WARN_ON(!pdata)) + return -EINVAL; + + info.constraint = pdata->constraint; + info.free_resources = boot_constraint_remove; + info.free_resources_data = pdev; + + ret = dev_boot_constraint_add(pdata->dev, &info); + if (ret) { + if (ret == -EPROBE_DEFER) + driver_enable_deferred_probe(); + else + pdata->probe_failed = ret; + } + + return ret; +} + +static struct platform_driver boot_constraint_driver = { + .driver = { + .name = "boot-constraints-dev", + }, + .probe = boot_constraint_probe, +}; + +static int __init boot_constraint_init(void) +{ + return platform_driver_register(&boot_constraint_driver); +} +core_initcall(boot_constraint_init); + +static int _boot_constraint_add_dev(struct device *dev, + struct dev_boot_constraint *constraint) +{ + struct boot_constraint_pdata pdata = { + .dev = dev, + .constraint.type = constraint->type, + }; + struct platform_device *pdev; + struct boot_constraint_pdata *pdev_pdata; + int size, ret; + + switch (constraint->type) { + case DEV_BOOT_CONSTRAINT_CLK: + size = sizeof(struct dev_boot_constraint_clk_info); + break; + case DEV_BOOT_CONSTRAINT_PM: + size = 0; + break; + case DEV_BOOT_CONSTRAINT_SUPPLY: + size = sizeof(struct dev_boot_constraint_supply_info); + break; + default: + dev_err(dev, "%s: Constraint type (%d) not supported\n", + __func__, constraint->type); + return -EINVAL; + } + + /* Will be freed from boot_constraint_remove() */ + pdata.constraint.data = kmemdup(constraint->data, size, GFP_KERNEL); + if (!pdata.constraint.data) + return -ENOMEM; + + ret = ida_simple_get(&pdev_index, 0, 256, GFP_KERNEL); + if (ret < 0) { + dev_err(dev, "failed to allocate index (%d)\n", ret); + goto free; + } + + pdata.index = ret; + + pdev = platform_device_register_data(NULL, "boot-constraints-dev", ret, + &pdata, sizeof(pdata)); + if (IS_ERR(pdev)) { + dev_err(dev, "%s: Failed to create pdev (%ld)\n", __func__, + PTR_ERR(pdev)); + ret = PTR_ERR(pdev); + goto ida_remove; + } + + /* Release resources if probe has failed */ + pdev_pdata = dev_get_platdata(&pdev->dev); + if (pdev_pdata->probe_failed) { + ret = pdev_pdata->probe_failed; + goto remove_pdev; + } + + return 0; + +remove_pdev: + platform_device_unregister(pdev); +ida_remove: + ida_simple_remove(&pdev_index, pdata.index); +free: + kfree(pdata.constraint.data); + + return ret; +} + +int dev_boot_constraint_add_deferrable(struct device *dev, + struct dev_boot_constraint *constraints, int count) +{ + int ret, i; + + if (boot_constraints_disabled) + return -ENODEV; + + for (i = 0; i < count; i++) { + ret = _boot_constraint_add_dev(dev, &constraints[i]); + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(dev_boot_constraint_add_deferrable); + +/* This only creates platform devices for now */ +int dev_boot_constraint_add_of_deferrable(const char *compatible, + struct dev_boot_constraint *constraints, int count) +{ + struct platform_device *pdev; + struct device_node *np; + + if (boot_constraints_disabled) + return -ENODEV; + + np = of_find_compatible_node(NULL, NULL, compatible); + if (!np) + return -ENODEV; + + pdev = of_find_device_by_node(np); + if (!pdev) + pdev = of_platform_device_create(np, NULL, NULL); + + of_node_put(np); + + if (!pdev) + return -ENODEV; + + return dev_boot_constraint_add_deferrable(&pdev->dev, constraints, + count); +} +EXPORT_SYMBOL_GPL(dev_boot_constraint_add_of_deferrable); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 2262a4a4c0e4..62a8a22f8b04 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -204,6 +204,18 @@ void device_unblock_probing(void) } /** + * driver_enable_deferred_probe() - Enable probing of deferred devices + * + * We don't want to get in the way when the bulk of drivers are getting probed + * and so deferred probe is disabled in the beginning. Enable it now because we + * need it. + */ +void driver_enable_deferred_probe(void) +{ + driver_deferred_probe_enable = true; +} + +/** * deferred_probe_initcall() - Enable probing of deferred devices * * We don't want to get in the way when the bulk of drivers are getting probed. diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index edc9abe7913a..f66c2f6d14dc 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -47,12 +47,22 @@ struct dev_boot_constraint_info { int dev_boot_constraint_add(struct device *dev, struct dev_boot_constraint_info *info); void dev_boot_constraints_remove(struct device *dev); +int dev_boot_constraint_add_deferrable(struct device *dev, + struct dev_boot_constraint *constraints, int count); +int dev_boot_constraint_add_of_deferrable(const char *compatible, + struct dev_boot_constraint *constraints, int count); #else static inline int dev_boot_constraint_add(struct device *dev, struct dev_boot_constraint_info *info); { return -EINVAL; } static inline void dev_boot_constraints_remove(struct device *dev) {} +static inline int dev_boot_constraint_add_deferrable(struct device *dev, + struct dev_boot_constraint *constraints, int count) +{ return -EINVAL; } +static inline int dev_boot_constraint_add_of_deferrable(const char *compatible, + struct dev_boot_constraint *constraints, int count) +{ return -EINVAL; } #endif /* CONFIG_DEV_BOOT_CONSTRAINTS */ #endif /* _LINUX_BOOT_CONSTRAINT_H */ From patchwork Tue Aug 1 09:23:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 109128 Delivered-To: patch@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1267537qge; Tue, 1 Aug 2017 02:29:34 -0700 (PDT) X-Received: by 10.84.237.8 with SMTP id s8mr16065735plk.403.1501579774324; Tue, 01 Aug 2017 02:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501579774; cv=none; d=google.com; s=arc-20160816; b=fj4yK72SwgjGqsdeWJfpzklIhEL3ryI3c9kS0ZZRo7zicpXRB0CZdjYNCPiv4FpejT 1STPeAXNXJ+lMqQZcXcIJqsNbybnuwH/RTinlaelSOJhJmMf6339ADTpOclbVC4n/mtp 8z6JFkIdU6W6a/XWTAHQ/k0din4Z1rH7LDSHjDXFYDhDJL772HjxdY2dWQtbhpIH1Px/ fX1UHYVKEQ/fUwi2xulMwOnfEw0ChHaD/yEaVbsInkgeXe2NENumoHTWfD7jeOauLo9e Qi5vCKx9NLO+MAu36GMlVI4Lr+IKsDeWY2tFgA9stbnZMjAbsCXAx4UC6GtAJhPY0a5w ptLA== 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=shxbM+ccNBl6QL2YjiLs+xH/6Z0DkTwy+gGjIg8ilR8=; b=Ixq46iWzqzj/Rm157l6AT2feM450dC3ncWJlqyH3qPRL1O8ltDLrr4O9koHBIaiTTB LrDwvRqqz4LDgTE40mqI9ZwqNLSbQ6+iC0HN6b6zXs9adLY5eTM5j9DCrtGxUZwu2Glq k2dHpViBtfUkWLgnzGFTDf+lOXcZvxIOEMmSAqa4G93Jxr7kev8nDYwFRf6PjiYs7gvu kiuQLs6Gwd79HkiNlfBqTlITaOILzky0hH1AcRbGBOerAN9wtgc8lB2Kg7iOCbmEM5Ah WIDS4Qeu8DdP/gGeGNkuBipnCIYKUYXM0Qd5zSK7Th6EQZ9UC4PsGvuUgP45RxHvQd/4 3hXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=CT2/PqMy; 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.29.34; Tue, 01 Aug 2017 02:29:34 -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=CT2/PqMy; 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 S1751657AbdHAJ3c (ORCPT + 26 others); Tue, 1 Aug 2017 05:29:32 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:33962 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751924AbdHAJ3N (ORCPT ); Tue, 1 Aug 2017 05:29:13 -0400 Received: by mail-pf0-f176.google.com with SMTP id o86so2176480pfj.1 for ; Tue, 01 Aug 2017 02:29:13 -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=shxbM+ccNBl6QL2YjiLs+xH/6Z0DkTwy+gGjIg8ilR8=; b=CT2/PqMy18Mg8dy7IDkNQNYOdgJx4ZdRypJ8BLAvBzo/7GSFO9WwG6GXdLLRmwB1Ng 576DfHp8Mqt/P26nzjl2A5Ec0P2theO3atdws6zY74cLK4IRe6kqDJThRo1eKbAZzam7 OvUcJZ/9fpiGtZ5XPU7nCHPMGEI/yV8jWmTac= 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=shxbM+ccNBl6QL2YjiLs+xH/6Z0DkTwy+gGjIg8ilR8=; b=U+9xxZCqM1aKHB81wUEHyuQO5NM/IIO/0wgvtnY35eyzptRdNGthugaz6PcYU+WbsY qCdR0lI1bpsMKsqJ85cw+6+vFX+JK73qBmj6wYf5hm4lNE2NmP7feOwVq/WoazC703eR Ldr2nPHXcyVMitHZyQehDwXO6pzr0CoO7LG3V9QHKEqxJRVg6ner6WnlKqhmJEozubpj ty3mTp40xmlBZ9uB5eXX1daE07LdS64DUJK7/BnPQxyDxAOogejRjwh1ExecpbfzzDBs rag/ruLFa5IiULEez6aJuXV3iqluWEfZLVxEHUn5mfUTAjWkR0SOfNHJocVuKIql6N5q k9yg== X-Gm-Message-State: AIVw111BNTQNiOCTIARMT8xF5SHvTNkC0dhdbKG+qVUHDxhpBAeNU6wJ Y3z+ohbOdf6f2rbJQBEQ/g== X-Received: by 10.99.120.193 with SMTP id t184mr18277435pgc.35.1501579753130; Tue, 01 Aug 2017 02:29:13 -0700 (PDT) Received: from localhost ([122.172.27.66]) by smtp.gmail.com with ESMTPSA id j29sm64985874pfj.68.2017.08.01.02.29.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 02:29:12 -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 8/8] drivers: boot_constraint: Add Qualcomm display controller constraints Date: Tue, 1 Aug 2017 14:53:49 +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 From: Rajendra Nayak NOT TO BE MERGED This sets boot constraints for the display controller used on Qualcomm dragonboard 410c. Not-signed-off-by: Rajendra Nayak Not-signed-off-by: Viresh Kumar --- drivers/base/boot_constraints/Makefile | 2 +- drivers/base/boot_constraints/qcom-display.c | 107 +++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 drivers/base/boot_constraints/qcom-display.c -- 2.13.0.71.gd7076ec9c9cb diff --git a/drivers/base/boot_constraints/Makefile b/drivers/base/boot_constraints/Makefile index a765094623a3..b0bdf67ebbbf 100644 --- a/drivers/base/boot_constraints/Makefile +++ b/drivers/base/boot_constraints/Makefile @@ -1,3 +1,3 @@ # Makefile for device boot constraints -obj-y := clk.o deferrable_dev.o core.o pm.o supply.o +obj-y := clk.o deferrable_dev.o core.o pm.o supply.o qcom-display.o diff --git a/drivers/base/boot_constraints/qcom-display.c b/drivers/base/boot_constraints/qcom-display.c new file mode 100644 index 000000000000..29f930ac692b --- /dev/null +++ b/drivers/base/boot_constraints/qcom-display.c @@ -0,0 +1,107 @@ +/* + * Sets up constraints on behalf of the bootloader, which uses display + * controller to display a flash screen during system boot. + */ + +#include +#include +#include + +struct dev_boot_constraint_clk_info iface_clk_info = { + .name = "iface_clk", +}; + +struct dev_boot_constraint_clk_info bus_clk_info = { + .name = "bus_clk", +}; + +struct dev_boot_constraint_clk_info core_clk_info = { + .name = "core_clk", +}; + +struct dev_boot_constraint_clk_info vsync_clk_info = { + .name = "vsync_clk", +}; + +struct dev_boot_constraint_clk_info esc0_clk_info = { + .name = "core_clk", +}; + +struct dev_boot_constraint_clk_info byte_clk_info = { + .name = "byte_clk", +}; + +struct dev_boot_constraint_clk_info pixel_clk_info = { + .name = "pixel_clk", +}; + +struct dev_boot_constraint_supply_info vdda_info = { + .name = "vdda" +}; + +struct dev_boot_constraint_supply_info vddio_info = { + .name = "vddio" +}; + +struct dev_boot_constraint constraints_mdss[] = { + { + .type = DEV_BOOT_CONSTRAINT_PM, + .data = NULL, + }, +}; + +struct dev_boot_constraint constraints_mdp[] = { + { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &iface_clk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &bus_clk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &core_clk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &vsync_clk_info, + }, +}; + +struct dev_boot_constraint constraints_dsi[] = { + { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &esc0_clk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &byte_clk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &pixel_clk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_SUPPLY, + .data = &vdda_info, + + }, { + .type = DEV_BOOT_CONSTRAINT_SUPPLY, + .data = &vddio_info, + }, +}; + +static int __init qcom_constraints_init(void) +{ + int ret; + + ret = dev_boot_constraint_add_of_deferrable("qcom,mdss", + constraints_mdss, ARRAY_SIZE(constraints_mdss)); + if (ret) + return ret; + + ret = dev_boot_constraint_add_of_deferrable("qcom,mdp5", + constraints_mdp, ARRAY_SIZE(constraints_mdp)); + if (ret) + return ret; + + ret = dev_boot_constraint_add_of_deferrable("qcom,mdss-dsi-ctrl", + constraints_dsi, ARRAY_SIZE(constraints_dsi)); + return ret; +} +subsys_initcall(qcom_constraints_init);