From patchwork Sun Oct 29 13:48:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117417 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1529058qgn; Sun, 29 Oct 2017 06:51:33 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R27BjFY0l88nYl5xXI6UFEkl1553tL5GnYF7UH4NgwZ4QHu+J1jER5iedTCpY0MGosHUcS X-Received: by 10.99.115.7 with SMTP id o7mr5380258pgc.410.1509285093496; Sun, 29 Oct 2017 06:51:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509285093; cv=none; d=google.com; s=arc-20160816; b=Vfxifs/mdAsckoL0xZFx6z0O/qnVqrpBexckxDZAG2HU46S4Plkm0BZJcv8jMo7ekf ga26Lc/KKv46csi+C7lMdMY6LKc7P1Jzuo42SA2U45sGQ7kzVl8lN8a2rVCRemBYogqb 3n2L0mUxMm2JLyJ2BcLeSbZGkBBx0bWiPXbDhSwp9L80b0qQ+IplEbhCh9+cwN3FyCYu llKQmbVBtezwGiUnLn79MBfvw1rJLGkHaIW66wgH2TA8qAsY1+liUKVQ0zmtYBYwFKSP LzLhitV5fjZiIJEGdKyLqwSvlJlNGYVV8i3lHMXUaUs2kywGV0xHmHp6VSomSDP5RiND peiw== 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=j5pQxViqq56cTW3qY1XLNGCECbrwSO1mV9fsmXSFSq4=; b=WK6v1CWxavV7n27M5uKdWKJjTdkNP+eDv1ELfYJdXmVTazyJIrQdJkagS/vfqnNWwn C0oysxM6w72FnNrgAlsM0jBMU0qDFYPBv2pfMocJksGWaLk/NITZJgTCBdJRhWeKG34V BhNzZZFincsLFoCK1KI8+7gZg9FTWWHg1GKm4GCMbkdelun7MUJPVb10BoKTayfDG9NM ST6+AIDSwJ2vtF0LixUdCRrXOB6gYcpe9VU7e389MHcpqW7Wma4IfltKQVzc8A5cFmrz qEkU7kv8Q3stvsvPrlqxyqLPMGKgfLYU+6zPbCRH1WVIOuJ3X1VRqNREXOVome99RqQG tkUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQNwz9TB; 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 d88si8782884pfl.232.2017.10.29.06.51.33; Sun, 29 Oct 2017 06:51:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQNwz9TB; 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 S932128AbdJ2Nvb (ORCPT + 27 others); Sun, 29 Oct 2017 09:51:31 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:57176 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751525AbdJ2NtT (ORCPT ); Sun, 29 Oct 2017 09:49:19 -0400 Received: by mail-pg0-f67.google.com with SMTP id m18so9100549pgd.13 for ; Sun, 29 Oct 2017 06:49:19 -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=j5pQxViqq56cTW3qY1XLNGCECbrwSO1mV9fsmXSFSq4=; b=RQNwz9TBR+1Fm2nflFbrN3FEQSo25nS5mKSzJbjA1Tx6wMYLZq/RhcStSign4SDca3 TYnZvt6yIWdFTx36/O5vu8Hw93wHST7Te+GEFEqwh0tuCYocbBhaAPrmE+y9oWWeBnWV TCsscMTMORaU/hNZr2gLQwvoBnEBQncmU4kOs= 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=j5pQxViqq56cTW3qY1XLNGCECbrwSO1mV9fsmXSFSq4=; b=hYTFJEMKrafOGkfvp+XyEoqx8dbAwFOHqSvWbE5AAo5I+K3iMTBvqSnQUPasPFrRvv JXLGW9/vti83vonkU6+9/0fu4k4HgdF/7fSU/3ouGew0tFThzlUulLO+VonPRap39cB6 VSNizt5+vGb7SjAJtGSyNKYhy14lLSTP9+Wkzwy2i/666vtxIsfZJA7vGAT6KZoR2+nn q327GE5iQR5zUnwS3+LRh03L+FzXNRcAvT94G1bJuss7sUNKYU4vb3tM4rao5coQE1rk w9bVzAh6hHlVjtJlasS7ZiBSZjXV5LiTHZhosrYgesRebnctsvdnirMhWQRBEauaNrT0 lMwg== X-Gm-Message-State: AMCzsaVA6YGPreGGkJ5Ukui+N93vB3hgOBQ9T82y6JrZX5kz1PqymMw6 7znj/Qa/o4bS055ZdETbM5gqgQ== X-Received: by 10.84.246.9 with SMTP id k9mr4750590pll.234.1509284958682; Sun, 29 Oct 2017 06:49:18 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id k12sm22202698pgn.70.2017.10.29.06.49.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:18 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 03/12] drivers: Add boot constraints core Date: Sun, 29 Oct 2017 19:18:51 +0530 Message-Id: <2868a37e561cab91ba5495a1e14b9548c8e93c3e.1509284255.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 deferred probing. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/base/dd.c | 20 ++-- drivers/boot_constraints/Kconfig | 9 ++ drivers/boot_constraints/Makefile | 3 + drivers/boot_constraints/core.c | 199 ++++++++++++++++++++++++++++++++++++++ drivers/boot_constraints/core.h | 33 +++++++ include/linux/boot_constraint.h | 46 +++++++++ 8 files changed, 306 insertions(+), 7 deletions(-) create mode 100644 drivers/boot_constraints/Kconfig create mode 100644 drivers/boot_constraints/Makefile create mode 100644 drivers/boot_constraints/core.c create mode 100644 drivers/boot_constraints/core.h create mode 100644 include/linux/boot_constraint.h -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/Kconfig b/drivers/Kconfig index 505c676fa9c7..e595ffad2214 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -4,6 +4,8 @@ source "drivers/amba/Kconfig" source "drivers/base/Kconfig" +source "drivers/boot_constraints/Kconfig" + source "drivers/bus/Kconfig" source "drivers/connector/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index d90fdc413648..29d03466cb2a 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -72,6 +72,7 @@ obj-$(CONFIG_FB_INTEL) += video/fbdev/intelfb/ obj-$(CONFIG_PARPORT) += parport/ obj-$(CONFIG_NVM) += lightnvm/ obj-y += base/ block/ misc/ mfd/ nfc/ +obj-$(CONFIG_DEV_BOOT_CONSTRAINTS) += boot_constraints/ obj-$(CONFIG_LIBNVDIMM) += nvdimm/ obj-$(CONFIG_DAX) += dax/ obj-$(CONFIG_DMA_SHARED_BUFFER) += dma-buf/ diff --git a/drivers/base/dd.c b/drivers/base/dd.c index ad44b40fe284..4eec27fe2b2b 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 @@ -409,15 +410,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/drivers/boot_constraints/Kconfig b/drivers/boot_constraints/Kconfig new file mode 100644 index 000000000000..77831af1c6fb --- /dev/null +++ b/drivers/boot_constraints/Kconfig @@ -0,0 +1,9 @@ +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. diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile new file mode 100644 index 000000000000..0f2680177974 --- /dev/null +++ b/drivers/boot_constraints/Makefile @@ -0,0 +1,3 @@ +# Makefile for device boot constraints + +obj-y := core.o diff --git a/drivers/boot_constraints/core.c b/drivers/boot_constraints/core.c new file mode 100644 index 000000000000..366a05d6d9ba --- /dev/null +++ b/drivers/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/boot_constraints/core.h b/drivers/boot_constraints/core.h new file mode 100644 index 000000000000..7ba4ac172c09 --- /dev/null +++ b/drivers/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/include/linux/boot_constraint.h b/include/linux/boot_constraint.h new file mode 100644 index 000000000000..2b816bf74144 --- /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 Sun Oct 29 13:48:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117407 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1527455qgn; Sun, 29 Oct 2017 06:49:38 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Tw8SwdJ1OC20Quux/dRdOEqf7DIXuHMcXqx0zT3TyBS9a6BjCoyJ787QM36quUAmIsOnao X-Received: by 10.98.56.204 with SMTP id f195mr5880865pfa.188.1509284978688; Sun, 29 Oct 2017 06:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509284978; cv=none; d=google.com; s=arc-20160816; b=MiHH7xOfhGc8ZDvRsOxwpZP7dQuSfdFE53S0jpjHMaeT+ZtSzSxzzYUgISVuOIECXr /SD0iL1SeJKthLVteVKFLmEdenm9sUg4RmuEWHTWofHOA/cq0KFztzbQixw0unana8G1 VI9uETBrrzORf6et7PRgvBCkfZabGF6ye91qIeuwByyX+bKdhhdw2eVQwDXBtFNA4Adk iLA54Z9fVEST9SZqAca5E3KJKnfZznZkr+VF3B9KxQzl+nR9cPMd+GivVTuXkKRSpNbM 8zrQPree/4G2K81skuLEGbCzYKnJTJNUs+OK3e2N+B7zWaGEAoDDvZNvISEQ9S3VWiBY mM4Q== 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=sPrAiBZmbIapUxXZ3rtZTh87IahEowRiXxQY/FmhmRk=; b=yXhgXNiP7tm2ewgLs6NCjSBOQ5xC8AKEZ+Y0myT9/an9ue2MG03l//yE80QCsdx3Le 7myuQqFynN4jP3/45vbodQrZ+NtbVbynRLOvw6RT75adK82/29bfiKOngUeR70HN/7/P nvXIVCQjnY4ehhhJevKI9TxGlDoVsdpujmPAzgNeg3QuhGwtVVxjf9QbekPtxbHgXN2w HJ4uZ/gvcjePTJVtWUXiOiBrZ/VDgn15q7ouuHsAsTcehgBY6lAcbu7tFw/XdjrNKpDv I5IShuvsUoo6sfsVAOMR9eNZk6gEo0Y01SmOj0n+nfrXbAtBiOjPzopi+wIj156Kchdx a+Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TcPfx0O6; 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 j6si8653501pfh.329.2017.10.29.06.49.38; Sun, 29 Oct 2017 06:49:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TcPfx0O6; 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 S1751731AbdJ2NtZ (ORCPT + 27 others); Sun, 29 Oct 2017 09:49:25 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:52993 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbdJ2NtV (ORCPT ); Sun, 29 Oct 2017 09:49:21 -0400 Received: by mail-pf0-f194.google.com with SMTP id e64so8655326pfk.9 for ; Sun, 29 Oct 2017 06:49:21 -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=sPrAiBZmbIapUxXZ3rtZTh87IahEowRiXxQY/FmhmRk=; b=TcPfx0O6/x+V7g85A+YJCBvrP7YfLhw7qFyOnj1bJsrBfz09jFP/vuzwMMoKJBwnMo PUkxpOqxYY4jiChaaLcXAD4taacwMoFyt+Kdf1VIpFYF0VAirEIIP8w81IT6DhjunYR1 GvN+JoFirWN/qkR4aPPcOKfMzW6OjMl6mK18Q= 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=sPrAiBZmbIapUxXZ3rtZTh87IahEowRiXxQY/FmhmRk=; b=Za2ViMcFCwBUKZ+qwKEtrKNjZrH1z2w5fA7zsBF7JPtpq2gTwfFwS2O7VOKsQccoCD LhHrPiKMyM2hOswFm95+M+CYjpaU6vNZqD4Fi1mfFT0AlB8r//FL0Umaf/yOJP95tb4O L4fFjquracZ3FGW9DJFwwIVv5AtEHx99GwBI+m1uplgIpZYS4NIydnzT8+8bkuPSr1kU miHK1bjQEcLAxBrFcIUEfgd+d/R0SxSp/3Pbje2BzajDEzYPsfxP3sE55Z9/l5QuiOw0 L6EOfx8i+U/8OFPowYh8kMBN5KFz1VRF7vXXcGTUvq5wsE8CKQENSDEWWPI5RUZoz4YR x0ZQ== X-Gm-Message-State: AMCzsaXvhoBjCQ05M/rAFbgx9b9GiK+jY1arM/0a1kVqIf1TGysRLv8Z 7UqJ+eIep41zio/iFFS+8qZDMA== X-Received: by 10.84.192.37 with SMTP id b34mr4826604pld.451.1509284961335; Sun, 29 Oct 2017 06:49:21 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id 189sm20246794pge.26.2017.10.29.06.49.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:20 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 04/12] boot_constraint: Add support for supply constraints Date: Sun, 29 Oct 2017 19:18:52 +0530 Message-Id: <4e171b6a496a6f5645804d9ed9cb53b4bcbe75a0.1509284255.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the 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/boot_constraints/Makefile | 2 +- drivers/boot_constraints/core.c | 4 ++ drivers/boot_constraints/core.h | 3 ++ drivers/boot_constraints/supply.c | 98 +++++++++++++++++++++++++++++++++++++++ include/linux/boot_constraint.h | 8 +++- 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 drivers/boot_constraints/supply.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index 0f2680177974..a45616f0c3b0 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/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/boot_constraints/core.c b/drivers/boot_constraints/core.c index 366a05d6d9ba..b9c024a3bdf5 100644 --- a/drivers/boot_constraints/core.c +++ b/drivers/boot_constraints/core.c @@ -94,6 +94,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev, void (*remove)(struct constraint *constraint); switch (type) { + case DEV_BOOT_CONSTRAINT_SUPPLY: + add = constraint_supply_add; + remove = constraint_supply_remove; + break; default: return ERR_PTR(-EINVAL); } diff --git a/drivers/boot_constraints/core.h b/drivers/boot_constraints/core.h index 7ba4ac172c09..73b9d2d22a12 100644 --- a/drivers/boot_constraints/core.h +++ b/drivers/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/boot_constraints/supply.c b/drivers/boot_constraints/supply.c new file mode 100644 index 000000000000..30f816dbf12c --- /dev/null +++ b/drivers/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 2b816bf74144..fc8ec0ee82f3 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 Sun Oct 29 13:48:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117415 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1528703qgn; Sun, 29 Oct 2017 06:51:08 -0700 (PDT) X-Google-Smtp-Source: ABhQp+T1SHhwreUzOT4Ti/rggaBK4tL7VC9hA2wpjysQZFieorCbOQpt7YUShxqmtfPe82Cu9yZ5 X-Received: by 10.99.117.10 with SMTP id q10mr5066637pgc.288.1509285068152; Sun, 29 Oct 2017 06:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509285068; cv=none; d=google.com; s=arc-20160816; b=ad2w8CkmYlViRGZUi47gJhdJb7DdUsi23eNb6NYavo6iDaeeyg4cuHx/y1aPVdDvux 0u9qOB/oFPPTEl/23Skfc/67uCYlBTbt6qMgYhXR6lf5SgJmxVMxG649zG3W0PKZ3hvC iRwznuUi60lfG3M7Z8GN5Uk+N2Ov7831DiC6JH62w/wEo6VUXKr1q4/jCpkHHGNgbtPy rrwiFfaK0GVc2AUSF3GanEilHKxXfpRbXv7WPxH/1tKQuCggauItHYSslqJNeMjbq6zR G6KYmTqPgqrLgyTy2C6IoM27T1GYSl4bs6+kElV6aSVe9aAMRVyC/YMAeptKoCIYpyw8 i5Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=8dknvPdhMomhLDGww4JAVj/cpN5o9hByN7NdXXTe1dY=; b=E/2Kq/VJBx5npcfygd/fqM96UDQ1YMLuS5e5ixr8Rpv3Ghtm77amDO5Dn5PX9lO+eL rGq4D/YhSn9KaOIWuLG9WeY7m8IUAsHCfhAno9+E/6+MV5ffIUholbou2cxy5lkztHnT dL+lRs5HictcDb5nrWa1JrbZkDAWiCZCLVL/670fgFiOJdkmgCw3oX3yF8qTOV9rZiEt szhx4rd77UEyVYzo0s89hbCkJiXGyDk8IYe3MYtV1YeOWH7z4SqFsj8h8Oo8btlUld2M VDqPlDf4co9L0DJkWzaDmCeew2V6mLCZxWHPg/7VU27Z3EyRY2mpjrfpc1TGuUQeXsiU P46g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GymTc+ii; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g24si7649787pfd.403.2017.10.29.06.51.07; Sun, 29 Oct 2017 06:51:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GymTc+ii; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752006AbdJ2NvG (ORCPT + 27 others); Sun, 29 Oct 2017 09:51:06 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:43570 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751683AbdJ2NtY (ORCPT ); Sun, 29 Oct 2017 09:49:24 -0400 Received: by mail-pf0-f193.google.com with SMTP id a8so8674643pfc.0 for ; Sun, 29 Oct 2017 06:49:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=8dknvPdhMomhLDGww4JAVj/cpN5o9hByN7NdXXTe1dY=; b=GymTc+iiB7WUT2FP/077z/9brjaaGM1GuqqMXK+IDZmU1Xt5Qm4HvohAQniNiyg8Vn g8bpaKISz/S5Xj4dSqYmtIEEdO3EypbpRvd0G6cgZF+dMGPM7WfGkZQ35cwI0+ckUGwt ddYvDGE9gspW+CTnO9VYyfce//1ATpyfARlBM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=8dknvPdhMomhLDGww4JAVj/cpN5o9hByN7NdXXTe1dY=; b=eg2hXfnW806dmmRdRz4TM6Fh0xttKuMOl+ssPyuR5ju0B/e2ZakAHlzGRrHqv3OumE g5TJ+niFaB7cU38HuL62wVg93r81uGBAdL2+oPbLz0ccO3GY0nWRRkhFPnQ6RMLQbyP8 Z0RUpwQgrf4vFEwTMctgiuvVb770Qb3wWh7V16lIAOXN4VMu1WXRJeY9f8SXMAmY5BxD Q9s778fZ6PVWu5nOoadKck9K7hf5C1kTkpbqsmPT+QUNMXGq6yPDxCGAiuHGYVSkGjEQ PJbVYBg2K328RIlt2WbDu/qMA15X9HRUiIRT7ayQTITuk5OXVSdZra4HIRG901QiRx+3 jWvg== X-Gm-Message-State: AMCzsaXKJxugpHczlsA/xIRupyhFllrpNML+QNrD6BbvkES6DrI2VUMC PBvVD7JaM44Mi2ZQhDgE6kOFCQ== X-Received: by 10.84.128.72 with SMTP id 66mr4993073pla.119.1509284963816; Sun, 29 Oct 2017 06:49:23 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id n19sm22834891pfj.52.2017.10.29.06.49.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:23 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 05/12] boot_constraint: Add support for clk constraints Date: Sun, 29 Oct 2017 19:18:53 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the clk constraint type. The constraint is set by enabling the clk for the device. Once the device is probed, the clk is disabled and the constraint is removed. We may want to do clk_set_rate() from here, but lets wait for some real users that really want it. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/boot_constraints/Makefile | 2 +- drivers/boot_constraints/clk.c | 70 +++++++++++++++++++++++++++++++++++++++ drivers/boot_constraints/core.c | 4 +++ drivers/boot_constraints/core.h | 3 ++ include/linux/boot_constraint.h | 5 +++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 drivers/boot_constraints/clk.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index a45616f0c3b0..3424379fd1e4 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/boot_constraints/Makefile @@ -1,3 +1,3 @@ # Makefile for device boot constraints -obj-y := core.o supply.o +obj-y := clk.o core.o supply.o diff --git a/drivers/boot_constraints/clk.c b/drivers/boot_constraints/clk.c new file mode 100644 index 000000000000..b5b1d63c3e76 --- /dev/null +++ b/drivers/boot_constraints/clk.c @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#define pr_fmt(fmt) "Clock Boot Constraints: " fmt + +#include +#include +#include + +#include "core.h" + +struct constraint_clk { + struct dev_boot_constraint_clk_info clk_info; + struct clk *clk; +}; + +int constraint_clk_add(struct constraint *constraint, void *data) +{ + struct dev_boot_constraint_clk_info *clk_info = data; + struct constraint_clk *cclk; + struct device *dev = constraint->cdev->dev; + int ret; + + cclk = kzalloc(sizeof(*cclk), GFP_KERNEL); + if (!cclk) + return -ENOMEM; + + cclk->clk = clk_get(dev, clk_info->name); + if (IS_ERR(cclk->clk)) { + ret = PTR_ERR(cclk->clk); + if (ret != -EPROBE_DEFER) { + dev_err(dev, "clk_get() failed for %s (%d)\n", + clk_info->name, ret); + } + goto free; + } + + ret = clk_prepare_enable(cclk->clk); + if (ret) { + dev_err(dev, "clk_prepare_enable() %s failed (%d)\n", + clk_info->name, ret); + goto put_clk; + } + + cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL); + constraint->private = cclk; + + return 0; + +put_clk: + clk_put(cclk->clk); +free: + kfree(cclk); + + return ret; +} + +void constraint_clk_remove(struct constraint *constraint) +{ + struct constraint_clk *cclk = constraint->private; + + kfree_const(cclk->clk_info.name); + clk_disable_unprepare(cclk->clk); + clk_put(cclk->clk); + kfree(cclk); +} diff --git a/drivers/boot_constraints/core.c b/drivers/boot_constraints/core.c index b9c024a3bdf5..9213e56e8078 100644 --- a/drivers/boot_constraints/core.c +++ b/drivers/boot_constraints/core.c @@ -94,6 +94,10 @@ static struct constraint *constraint_allocate(struct constraint_dev *cdev, void (*remove)(struct constraint *constraint); switch (type) { + case DEV_BOOT_CONSTRAINT_CLK: + add = constraint_clk_add; + remove = constraint_clk_remove; + break; case DEV_BOOT_CONSTRAINT_SUPPLY: add = constraint_supply_add; remove = constraint_supply_remove; diff --git a/drivers/boot_constraints/core.h b/drivers/boot_constraints/core.h index 73b9d2d22a12..4f28ac2ef691 100644 --- a/drivers/boot_constraints/core.h +++ b/drivers/boot_constraints/core.h @@ -30,6 +30,9 @@ struct constraint { }; /* Forward declarations of constraint specific callbacks */ +int constraint_clk_add(struct constraint *constraint, void *data); +void constraint_clk_remove(struct constraint *constraint); + int constraint_supply_add(struct constraint *constraint, void *data); void constraint_supply_remove(struct constraint *constraint); diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index fc8ec0ee82f3..a74b261a4ee4 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -15,9 +15,14 @@ struct device; enum dev_boot_constraint_type { + DEV_BOOT_CONSTRAINT_CLK, DEV_BOOT_CONSTRAINT_SUPPLY, }; +struct dev_boot_constraint_clk_info { + const char *name; +}; + struct dev_boot_constraint_supply_info { const char *name; unsigned int u_volt_min; From patchwork Sun Oct 29 13:48:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117408 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1527459qgn; Sun, 29 Oct 2017 06:49:39 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Tp/7rHsoE/Iur22KcOHH3PmQE11qG1eO2Mlwtarhsb4H+VIg6h++M9Z3n4a/wi7ZUSrWTx X-Received: by 10.101.82.129 with SMTP id y1mr5273029pgp.137.1509284979088; Sun, 29 Oct 2017 06:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509284979; cv=none; d=google.com; s=arc-20160816; b=pPlHXRBHUJC56Pp/tGBT1s5t4UHIzngNskMKB5ngHwPxKeMuRyHHUxTsTZVmCtsc5W +hN8dN+EpgJkYTyW8muApw/QfilUdJg0oDl+FzyoTjJlvlJX5lcqMv6yblkpdI80VFDt MX0PB9sFYbr9qXuuF0dPd/6tz6tcPH1LjGzIyCQCAwSJvZaPzx3GjOEC6k2dS4snQ022 GIH9xDIE5ckL0obdbGrB3ff4kl44ihR0YK2bVSoLbM+/nntpk1B47vJT1JgnRst9yA0s OgeEmoFlM691hZFwNWrlfnkPGv/kFL6S++zu9chiZ+1LVqUVic4GKMte5hIIedDe6cqd nbPw== 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=D0ETMoWJcqfm/lXQtf6mkIrcvhuj3IBvyUBKm+r1MeE=; b=QOF8d9fgBgaOhCte4pR+ufejYE6FG+xtHyThgZ2VhALv6CXJD4Ox/OKvXm5fVsGy+a eCxrVqSJS3SQ8x9M+25dFrLi2q0k7A1WQvqP8BeHzyuPfc7XnJKdNYfmr9BNmKdSGDZT ZTMy5jZgz4e6319IA8w5i56ugPLV9bt3unVXncyKV5dflWhVaVx0foWuW6RReYL5QnRH uGCMeqKKX8jl9+pIar/OkuoXwKFaSb7HTArLnMhqmFzee1m6ZKpBYlapcH8TWPI5IA3G 6u56Mq7H5T917qLJ3Qp/c6A7Uj2nAMNX31DsXqFsatfEsHjP7XnSFpUn1qZXHGoMbWos KaFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=axZEWr3l; 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 j6si8653501pfh.329.2017.10.29.06.49.38; Sun, 29 Oct 2017 06:49:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=axZEWr3l; 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 S1751802AbdJ2Nta (ORCPT + 27 others); Sun, 29 Oct 2017 09:49:30 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:55600 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbdJ2Nt1 (ORCPT ); Sun, 29 Oct 2017 09:49:27 -0400 Received: by mail-pf0-f193.google.com with SMTP id 17so8652237pfn.12 for ; Sun, 29 Oct 2017 06:49:26 -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=D0ETMoWJcqfm/lXQtf6mkIrcvhuj3IBvyUBKm+r1MeE=; b=axZEWr3lB7/Qzy8OjJu69vP4Lrgmf0hZrHbzSX3FLMw2Fy2EVxHvLnK0zag3sc5uJy Jof4hxsoSShH1koIzH5TejLar++mfxCRitVvI1SRUAfMsxgohNvFfdqQjXUYWfAp+C9b +5BRwMaBT98d/a8vLeHRkRpSg2JdZv2kAYwMs= 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=D0ETMoWJcqfm/lXQtf6mkIrcvhuj3IBvyUBKm+r1MeE=; b=BqACeWa69vaIQ9oLAJX+v9v9CFP6ITn3W8as4cu9fVRPfyuRxp3RluV7qvxKhoZEw8 qmThWvF1vr3G9OfNY74fXJ+1gJVC9z7mfIMsgjn2DEhbo+i+vjzG8WgsE7AM60zcNNnM JF78I3b94X3gX0eblrsIrgWthkhoN6x9prgWgfDdVaZdQaiWZOSrmVFOMJvsoQYVpaqp rB73VKKsdHyfgw8Hd9I+b7veMDsVh9d+7Ny1WV10NXshFFqaFCo/rSBrPHSfEtDb9lOe KYGdhUMLfpagj3SzKhQvPMdKTjEcDH94UvlFLNalIpLRjzjjiNS7LkZRvfzlrbQUYRf2 9dUw== X-Gm-Message-State: AMCzsaXrn9+v6jKrEfkCRRaAc5F3kIygmxozyycczFz5TQDNF9W3aMLX iz+Ko11T2A1UCcSbOwM4gbgEyQ== X-Received: by 10.98.189.23 with SMTP id a23mr5949965pff.124.1509284966442; Sun, 29 Oct 2017 06:49:26 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id w5sm23161628pfw.51.2017.10.29.06.49.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:25 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 06/12] boot_constraint: Add support for PM constraints Date: Sun, 29 Oct 2017 19:18:54 +0530 Message-Id: <000268f9c5b06354333a18dbe26fc8b052231ed8.1509284255.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds the 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/boot_constraints/Makefile | 2 +- drivers/boot_constraints/core.c | 4 ++++ drivers/boot_constraints/core.h | 3 +++ drivers/boot_constraints/pm.c | 24 ++++++++++++++++++++++++ include/linux/boot_constraint.h | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 drivers/boot_constraints/pm.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index 3424379fd1e4..b7ade1a7afb5 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/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/boot_constraints/core.c b/drivers/boot_constraints/core.c index 9213e56e8078..f4d3520ddb04 100644 --- a/drivers/boot_constraints/core.c +++ b/drivers/boot_constraints/core.c @@ -98,6 +98,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/boot_constraints/core.h b/drivers/boot_constraints/core.h index 4f28ac2ef691..a051c3d7c8ab 100644 --- a/drivers/boot_constraints/core.h +++ b/drivers/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/boot_constraints/pm.c b/drivers/boot_constraints/pm.c new file mode 100644 index 000000000000..edba5eca5093 --- /dev/null +++ b/drivers/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 a74b261a4ee4..637fe9d65536 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 Sun Oct 29 13:48:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117414 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1528393qgn; Sun, 29 Oct 2017 06:50:47 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TZiFxFME+9Ln6yaFm4fjs/nmG5H2Uq1yyMAqJNVznawhqX+9kiGJno1WyFPO3Cn3btXHK3 X-Received: by 10.84.215.9 with SMTP id k9mr4797469pli.284.1509285047872; Sun, 29 Oct 2017 06:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509285047; cv=none; d=google.com; s=arc-20160816; b=FDCDNOiTpU9u/AYcTO1lyvq8VJeC8fAfUwxO2bSyXqbOFbRkb+quj9Hw9rWXh2GbLH 6Q+IomDBO+SOG74pKBi9cRdN6dKgjDgjHaSDeEy+/Hnr5dvagthd7g1te/U3aEQhXrkG gLOPkehA0+3qid7JHem7IeOCvnsLgcGisPa+4GlpD4Vc6dwxk62uh8y8bUHyzeeARxfW +g+gb4L7PwWDpy9maejNOGLD/noAfmAXa9wQuI55PWITiAfBzquN1kjIKxBfXPPL1Dff GN4i3TDFq+8pVPAR8FkjPCrChXgpnkBnTfzwNTqiiqXhuGEHmB21BxWJhdGpebAouEPh pPMA== 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=AUapgh7rcEIeG7tzA1pr/dDTN70gc45QREU9J7qYkYs=; b=YuxDPrKSI2M56O5rE7I/tHJoJNSjzLpFGahg4mYnb8VVVT+4V8xMsJWqBe5RTjoC/4 W5EO2TqUc347MEjF2kFFaG3neKYY5WaFYepUX4ojaGxeYhknQIvmx/fc4vUlTKgUgexn 64LVaiRi3f4pXGvom3NLEVe1XavpCJA5ZzLt2CuF6bta4NqL0pm0u6difyMv0/TjqQbc fR+FAEnJjmo3F7s1YKJ3OHLpatikgdQOuoKCXvuFuiW+KWRk2Ei35HG9YY4sGg+OewUo 4t1LBLSv7DOgh5xtf99+I/VzPdwe1tGQzjy7vN/sNuUivssCuIJ6kSsCsfU5CHs7AYHK D9Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LvrjYJmT; 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 j71si7942812pgc.290.2017.10.29.06.50.47; Sun, 29 Oct 2017 06:50:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LvrjYJmT; 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 S1751978AbdJ2Nup (ORCPT + 27 others); Sun, 29 Oct 2017 09:50:45 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:53016 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751744AbdJ2Nt3 (ORCPT ); Sun, 29 Oct 2017 09:49:29 -0400 Received: by mail-pf0-f193.google.com with SMTP id e64so8655481pfk.9 for ; Sun, 29 Oct 2017 06:49:29 -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=AUapgh7rcEIeG7tzA1pr/dDTN70gc45QREU9J7qYkYs=; b=LvrjYJmTN4gfrbpXJogAJlKIBZ2Gs3YF72K6fhQ/HlUJAxJYb6MGRwn0Wf3RlcqRv4 /NKZPRb9B+dWH8jSkTmSjNUDvUQ9xrLeT0WtRSFGYgBUeG0HhJBK/NCoSJkw0O9VZQdV 9qSaImRxfBpwpWTlmN8GeFR06/g72kHpp8sns= 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=AUapgh7rcEIeG7tzA1pr/dDTN70gc45QREU9J7qYkYs=; b=LkmTLZ8qzpMkDoXtmu4l8EGuwISATmcZCfAKa9lySoYhp1Cb6O4LT3JZj2V2bshZ6+ ZRqVaaj/IR27fAgt5IBBJMqeiwJNFGKyIakUmmxAp7NQN+WgcQB1qskPCtG8CzpsjdvJ SaWzft+pYYMjr47PpOQGqNDMpATJ9KHRpZqWQYvZrvseBq+neg6PPnOQ2/Dh282M7eCw ga5ZECt6CALnUWfDbtmohhCc50RqRGEwrt7cV5iDOnSaBkT1FhkuITyIXge/wX8OYavs jnApeS1ExeYq5gQD0HyPi4DBD0xgkYy2uSivVG6twWe0I3bcG5RHnOBvAp3QAc0z4hyi VfPA== X-Gm-Message-State: AMCzsaUx/EDrrO3eIQkoX/28JrS+YUR5Ls+kubESS3ko3s82D7U5ui3l BSLmiNqZG/Nj/ikQ0xFsW8+oFw== X-Received: by 10.99.160.71 with SMTP id u7mr5233932pgn.22.1509284969033; Sun, 29 Oct 2017 06:49:29 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id e6sm25752363pfg.42.2017.10.29.06.49.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:28 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 07/12] boot_constraint: Add debugfs support Date: Sun, 29 Oct 2017 19:18:55 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds 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/boot_constraints/clk.c | 3 ++ drivers/boot_constraints/core.c | 60 +++++++++++++++++++++++++++++++++++++++ drivers/boot_constraints/core.h | 6 ++++ drivers/boot_constraints/pm.c | 11 +++++-- drivers/boot_constraints/supply.c | 9 ++++++ 5 files changed, 87 insertions(+), 2 deletions(-) -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/boot_constraints/clk.c b/drivers/boot_constraints/clk.c index b5b1d63c3e76..91b7b538ef32 100644 --- a/drivers/boot_constraints/clk.c +++ b/drivers/boot_constraints/clk.c @@ -49,6 +49,8 @@ int constraint_clk_add(struct constraint *constraint, void *data) cclk->clk_info.name = kstrdup_const(clk_info->name, GFP_KERNEL); constraint->private = cclk; + constraint_add_debugfs(constraint, clk_info->name); + return 0; put_clk: @@ -63,6 +65,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/boot_constraints/core.c b/drivers/boot_constraints/core.c index f4d3520ddb04..707ffac690fc 100644 --- a/drivers/boot_constraints/core.c +++ b/drivers/boot_constraints/core.c @@ -24,6 +24,64 @@ static LIST_HEAD(constraint_devices); static DEFINE_MUTEX(constraint_devices_mutex); +/* 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); +} + +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); +} + +void constraint_remove_debugfs(struct constraint *constraint) +{ + debugfs_remove_recursive(constraint->dentry); +} + +static int __init constraint_debugfs_init(void) +{ + /* Create /sys/kernel/debug/opp directory */ + rootdir = debugfs_create_dir("boot_constraints", NULL); + + return 0; +} +core_initcall(constraint_debugfs_init); + + /* Boot constraints core */ static struct constraint_dev *constraint_device_find(struct device *dev) @@ -51,12 +109,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/boot_constraints/core.h b/drivers/boot_constraints/core.h index a051c3d7c8ab..ee84e237c66a 100644 --- a/drivers/boot_constraints/core.h +++ b/drivers/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/boot_constraints/pm.c b/drivers/boot_constraints/pm.c index edba5eca5093..d74b776cdced 100644 --- a/drivers/boot_constraints/pm.c +++ b/drivers/boot_constraints/pm.c @@ -14,11 +14,18 @@ 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; + + 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/boot_constraints/supply.c b/drivers/boot_constraints/supply.c index 30f816dbf12c..3d658410a082 100644 --- a/drivers/boot_constraints/supply.c +++ b/drivers/boot_constraints/supply.c @@ -60,6 +60,14 @@ int constraint_supply_add(struct constraint *constraint, void *data) csupply->supply.name = kstrdup_const(supply->name, GFP_KERNEL); constraint->private = csupply; + 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 +88,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 Sun Oct 29 13:48:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117409 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1527489qgn; Sun, 29 Oct 2017 06:49:41 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SFDepIngrvszt2m14krXA8H9RKF23jdAVy7jcOkkOSIg06A90ByRiC3rmtgD8u/Orx3kLW X-Received: by 10.99.127.78 with SMTP id p14mr5076523pgn.176.1509284981578; Sun, 29 Oct 2017 06:49:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509284981; cv=none; d=google.com; s=arc-20160816; b=yRXTQw6m3FOxcuvpdcQ9W1OGRESkgwKROhIKsY2y7NGO8ParAGRcwW0dbzX6JeXLp7 /t5XpAcco12y1OGsVgVOWwuS+s84XlJ/SxQVR2Q53Wr2ypl/Lj5I6sFqoXMDJjGbGwlK wqhHrCxsLVWqqdx3bxLDzgZJ9QecjPMouC7iLwgfD4cyVbUE183tTTdShYjJJpYiClqK q6GCO6PuK2GNCQEDE66snMnLVoZFicwrlT907K0s3ma+ft5xjOzVaD/9bCaPKP6VVSAF H1miOsJbte3SgsKsoCb0ksna4YpZMroeP+lplLOYp1v5f8WyYsGDwvrgEH57FgbYUJtD SK7A== 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=HRWFFgoVipB7peY01mzoJOe1W3nY5LSo0Zht3Rq225s=; b=pqXbfIK8EWmq8Kuyua2Nz5h0btbDKa6ZHTATTJybuAVnztYNd0VhVS6Cf3SJOjtqYM THSGvbAwVCLrFiZwvacFUlSgyTPSY0N9UCWNSzIPi1+cyRultbApu2LRyCgUkU5ObTv7 w7KdhEqX2wJ7HQqvAXKk64Q4cd5cbMq+cjjS/+Cwani3AtD9LaxlSfqJWvGBQsK52OZr w563LeEJ/SjmTEbyqVGqHlCVcPlFgDj8YCoKu6CpGDhRZsGxzmmW4Gv7KpX4cg5fZKRY Go/3AEKqQBqZ5zJqOQquEqtnhYULyEnOqcWNyKRGAHOTfagAecQCVvbt4RtVX4rXCBS/ MlSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M0P3+8yg; 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 j6si8653501pfh.329.2017.10.29.06.49.41; Sun, 29 Oct 2017 06:49:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M0P3+8yg; 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 S1751846AbdJ2Nti (ORCPT + 27 others); Sun, 29 Oct 2017 09:49:38 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:51122 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbdJ2Ntc (ORCPT ); Sun, 29 Oct 2017 09:49:32 -0400 Received: by mail-pg0-f66.google.com with SMTP id y5so9109842pgq.7 for ; Sun, 29 Oct 2017 06:49:32 -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=HRWFFgoVipB7peY01mzoJOe1W3nY5LSo0Zht3Rq225s=; b=M0P3+8ygjJC30N1igxngPg44LVznhTdyHzbmiF2N0+pmaBXvo8AEuAPIFfOhCrqGoA R+OJKQPufJzLYLAcrfoSaN/meQYs7U2hdP4/WIAmA42b1goMBVdHZmA9E+V9YKr1AK6E r8UoBGCOhlBXXrqwCE0+uto3SpS3VZKDGUD8A= 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=HRWFFgoVipB7peY01mzoJOe1W3nY5LSo0Zht3Rq225s=; b=oWaPamr0OJI/aGqNWOuRUehqhhQ7vTcw+ZM5ObWqIIgHJJ8QoslG+js97DB/0tCYJh ev3F7Hfnw1fRmuIVwYupv4ZbQ2Bk654EynAydFHaDXvbb4a+rC86aUxw6mYXmDo/OAl2 UL1TGddxGljL/gSNAQw7CgrzlhaIMgdBU0XygSScq8vuCAmvDpYc+Vo4Z7UZHYt5/+ay 4g+FS6J1bG2C60p+AsWuMrc5gCXuviyo4zpJ4vC3+uZZoD8wwTQkilUBXArPHPtfoHBP 4gCapGHvPS5aR3c0m6JXIR1KZEdwSL54XBac4IOeDeuBptTExy7VR8ie19gt1axWpy0f 5eJw== X-Gm-Message-State: AMCzsaXGLlwQaDj/KKYsEtJfxp8LsZjZAhzD0svNrw3bwRYZWcI2WQHQ T7MQONrRrWbSJuHa6HO0f5PvvA== X-Received: by 10.98.53.1 with SMTP id c1mr6009273pfa.248.1509284971633; Sun, 29 Oct 2017 06:49:31 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id a70sm25782019pfg.176.2017.10.29.06.49.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:31 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 08/12] boot_constraint: Manage deferrable constraints Date: Sun, 29 Oct 2017 19:18:56 +0530 Message-Id: <88c7a0a6421d267c118f501ea1e920b04649002d.1509284255.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/dd.c | 12 ++ drivers/boot_constraints/Makefile | 2 +- drivers/boot_constraints/deferrable_dev.c | 235 ++++++++++++++++++++++++++++++ include/linux/boot_constraint.h | 14 ++ 4 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 drivers/boot_constraints/deferrable_dev.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 4eec27fe2b2b..19eff5d08b9a 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -228,6 +228,18 @@ void device_unblock_probing(void) driver_deferred_probe_trigger(); } +/** + * 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 * diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index b7ade1a7afb5..a765094623a3 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/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/boot_constraints/deferrable_dev.c b/drivers/boot_constraints/deferrable_dev.c new file mode 100644 index 000000000000..04056f317aff --- /dev/null +++ b/drivers/boot_constraints/deferrable_dev.c @@ -0,0 +1,235 @@ +/* + * 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 + +#include "core.h" + +static DEFINE_IDA(pdev_index); + +void driver_enable_deferred_probe(void); + +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; +} + +static int dev_boot_constraint_add_deferrable(struct device *dev, + struct dev_boot_constraint *constraints, int count) +{ + int ret, i; + + for (i = 0; i < count; i++) { + ret = boot_constraint_add_dev(dev, &constraints[i]); + if (ret) + return ret; + } + + return 0; +} + +/* This only creates platform devices for now */ +static void add_deferrable_of_single(struct device_node *np, + struct dev_boot_constraint *constraints, + int count) +{ + struct device *dev; + int ret; + + if (!of_device_is_available(np)) + return; + + ret = of_platform_bus_create(np, NULL, NULL, NULL, false); + if (ret) + return; + + if (of_device_is_compatible(np, "arm,primecell")) { + struct amba_device *adev = of_find_amba_device_by_node(np); + + if (!adev) { + pr_err("Failed to find amba dev: %s\n", np->full_name); + return; + } + dev = &adev->dev; + } else { + struct platform_device *pdev = of_find_device_by_node(np); + + if (!pdev) { + pr_err("Failed to find pdev: %s\n", np->full_name); + return; + } + dev = &pdev->dev; + } + + ret = dev_boot_constraint_add_deferrable(dev, constraints, count); + if (ret) + dev_err(dev, "Failed to add boot constraint (%d)\n", ret); +} + +/* Not all compatible device nodes may have boot constraints */ +static bool node_has_boot_constraints(struct device_node *np, + struct dev_boot_constraint_of *oconst) +{ + int i; + + if (!oconst->dev_names) + return true; + + for (i = 0; i < oconst->dev_names_count; i++) { + if (!strcmp(oconst->dev_names[i], kbasename(np->full_name))) + return true; + } + + return false; +} + +void dev_boot_constraint_add_deferrable_of(struct dev_boot_constraint_of *oconst, + int count) +{ + struct device_node *np; + int i; + + for (i = 0; i < count; i++) { + for_each_compatible_node(np, NULL, oconst[i].compat) { + if (!node_has_boot_constraints(np, &oconst[i])) + continue; + + add_deferrable_of_single(np, oconst[i].constraints, + oconst[i].count); + } + } +} +EXPORT_SYMBOL_GPL(dev_boot_constraint_add_deferrable_of); diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index 637fe9d65536..c110b36e490f 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -35,6 +35,15 @@ struct dev_boot_constraint { void *data; }; +struct dev_boot_constraint_of { + const char *compat; + struct dev_boot_constraint *constraints; + unsigned int count; + + const char **dev_names; + unsigned int dev_names_count; +}; + struct dev_boot_constraint_info { struct dev_boot_constraint constraint; @@ -47,12 +56,17 @@ 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); +void dev_boot_constraint_add_deferrable_of(struct dev_boot_constraint_of *oconst, + 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) {} +void dev_boot_constraint_add_deferrable_of(struct dev_boot_constraint_of *oconst, + int count) +{ } #endif /* CONFIG_DEV_BOOT_CONSTRAINTS */ #endif /* _LINUX_BOOT_CONSTRAINT_H */ From patchwork Sun Oct 29 13:48:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117413 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1528148qgn; Sun, 29 Oct 2017 06:50:33 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TOwkeg1UanPTrJGCVx2gyHYYdNfdnsfdS5v9NDsxpWA2MuayRAFsnnpOseLFfGAHMTQuJb X-Received: by 10.84.231.193 with SMTP id g1mr4802684pln.407.1509285033098; Sun, 29 Oct 2017 06:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509285033; cv=none; d=google.com; s=arc-20160816; b=xUOVKU1sl76dNArS4hUnwEiIHYTZPXnnQ4AveRQ6oJtWapNoPgJUKm1nWyVUfTkK7S Pvt+zJ+MOlnQPAkVTbeGkYqwVf6wUHpIAd0MOEYiEYnnoCBWD8cBGsT7VtYz8As9WPQZ pIN11lwYvWKa9txpMrcvBaUPMt9c1aCHL0Ivc73Q3KjTHXoIxcRitXDPYuf/UZYVi/nY 5o4p9j6RtBKo3AR8pwa4vh3UhaoIdBqbxfo3+epR9fsCDxjDa/Ni1Me9TRoNTokoyOlC pBisJjZ2z7SF8rrrEahT84rDA2slJL3rV8/CXELcTEl834VHo1Lh8svh3oDL+7Klj5to 9mMQ== 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=qExC51DxMnAxdbbNF0fp4tkv43l/K8F+RIKd1+tryYE=; b=LqhrcrBc5H6s9J8JkO0uWamA222RsYWmJUW+lRJhSN9mfj/ps/VEvHJgXxHKaI9aL/ DvvL3KHFK5tMRqSX0ukmcYe2AMJi8QhROo5aad7mkoehpErUBjtJBg8jfRLBWe/qqIbO wzcZNdVcK8wg+UTobdvDBN+z5SjHzmMalKXTYMXF2H78kfPSC2IjLnpW3SuBqkqe4Urz dIruuHc0YK5uLjp67geCBxlxcOZnw7+bs+UAecx+l0RNZIWEHOOCxKOL3KIrUQK2W9p4 1WDaNMaQ1jj8fNkStJwO1rHaR36Qy/ver/QJZqiXSl+Pq9HXvYBGg/ySKOQH9v4bPrW9 s34w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fzEzTDxx; 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 102si7329781pld.614.2017.10.29.06.50.32; Sun, 29 Oct 2017 06:50:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fzEzTDxx; 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 S1751958AbdJ2Nua (ORCPT + 27 others); Sun, 29 Oct 2017 09:50:30 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:49707 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbdJ2Nte (ORCPT ); Sun, 29 Oct 2017 09:49:34 -0400 Received: by mail-pf0-f196.google.com with SMTP id i5so8667666pfe.6 for ; Sun, 29 Oct 2017 06:49:34 -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=qExC51DxMnAxdbbNF0fp4tkv43l/K8F+RIKd1+tryYE=; b=fzEzTDxxz8dUqX/V5MyeXbK+/IMVGk/gXDs777Vd9MONlXwzzP5vR9Xkj/TfYElRN4 Y91HHJEGhR+ALxzuSs1wqshG0+VnGSSo4jCZFySqRyTMIiM2lKKEInt04A2y84qdv+NJ 0d5iESSv6M4i5n+rbqbQBASBhMan5/HL3roWs= 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=qExC51DxMnAxdbbNF0fp4tkv43l/K8F+RIKd1+tryYE=; b=N5BtaipFvA5BLacBPVz/FpnI8rNoQJdA/La+2v40RDPMktWP9xNoY7Ewsa7qSBDbxB GobYvB/qV4TylxZFWjaZ2PJ0LsCsaaJIS39PKC+rDx8kPvikLMg1OOBxe8CVPr3TYZX1 1WiblEW8+PX+gXjo6ovvMB3GwGdJGvECReMTbjpsRDUnELfLyT3iCyYmS+Gsng6nXXGO iP44jQe7XzYfATWy1GvT0S+u/qI/UCAJmGtvOOOmA3cblzqcBwq1IB0vnKlpc6w+ffFF 8YbK7rei4QsIcgSxbd5abtrNsSFXsMhItOiTb1RlIG4E2agsRYqO/GU4m/Jg1S7zgGmi V9Pg== X-Gm-Message-State: AMCzsaUMW7Sm3toivxX+wsvzlhgyvPXky20OEk8cln6uD8JMVgubaFPc 4nKrjqZTy3PcBIxAQ0XjXm8BeQ== X-Received: by 10.98.10.74 with SMTP id s71mr6052933pfi.336.1509284974166; Sun, 29 Oct 2017 06:49:34 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id k76sm26332647pfb.37.2017.10.29.06.49.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:33 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 09/12] boot_constraint: Add earlycon helper Date: Sun, 29 Oct 2017 19:18:57 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Getting boot messages during initial kernel boot is a common problem, which (almost) everyone wants to solve. Considering that this would be required by multiple platforms, provide a helper to check if "earlycon" or "earlyprintk" boot arguments are passed to kernel or not. The platforms can use this helper to add serial constraints only if earlycon if required. Signed-off-by: Viresh Kumar --- drivers/boot_constraints/Makefile | 2 +- drivers/boot_constraints/serial.c | 28 ++++++++++++++++++++++++++++ include/linux/boot_constraint.h | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 drivers/boot_constraints/serial.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index a765094623a3..0d4f88bb767c 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/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 serial.o supply.o diff --git a/drivers/boot_constraints/serial.c b/drivers/boot_constraints/serial.c new file mode 100644 index 000000000000..d0d07d4aa6af --- /dev/null +++ b/drivers/boot_constraints/serial.c @@ -0,0 +1,28 @@ +/* + * This contains helpers related to serial boot constraints. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#include + +static bool earlycon_boot_constraints_enabled __initdata; + +bool __init boot_constraint_earlycon_enabled(void) +{ + return earlycon_boot_constraints_enabled; +} + +static int __init enable_earlycon_boot_constraints(char *str) +{ + earlycon_boot_constraints_enabled = true; + + return 0; +} +__setup_param("earlycon", boot_constraint_earlycon, + enable_earlycon_boot_constraints, 0); +__setup_param("earlyprintk", boot_constraint_earlyprintk, + enable_earlycon_boot_constraints, 0); diff --git a/include/linux/boot_constraint.h b/include/linux/boot_constraint.h index c110b36e490f..aeada69b87e6 100644 --- a/include/linux/boot_constraint.h +++ b/include/linux/boot_constraint.h @@ -10,6 +10,7 @@ #define _LINUX_BOOT_CONSTRAINT_H #include +#include #include struct device; @@ -58,6 +59,7 @@ int dev_boot_constraint_add(struct device *dev, void dev_boot_constraints_remove(struct device *dev); void dev_boot_constraint_add_deferrable_of(struct dev_boot_constraint_of *oconst, int count); +bool __init boot_constraint_earlycon_enabled(void); #else static inline int dev_boot_constraint_add(struct device *dev, From patchwork Sun Oct 29 13:48:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117410 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1527520qgn; Sun, 29 Oct 2017 06:49:43 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SzdYmCrXLhzVd7MQaGAV9Wgxk/vE4TPieC6ND59lhXa5Y6wBij58NBE6J8kM/K6PbMti5g X-Received: by 10.99.0.4 with SMTP id 4mr5261314pga.417.1509284983776; Sun, 29 Oct 2017 06:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509284983; cv=none; d=google.com; s=arc-20160816; b=szdBN0IJmtjojKgLQg9UEo3rOyP0LPtRFC3ApqGFNnvx7CCONJZKq4aNmKmxQY6i9f AC2v3jnyGhNDsbO6afZm5cq6d3Bf44aaxuujG2g1/Rem48QzdqnNKhIU3Ga+Hq4VIx0U xaavhpQBYeffVk+BuW81i3JYFserQopPkfKNOkmBMox6RWZkwQcxgFbnUCcI3P3VOFUK QSHIVeZZ5z7iQEeDYbcw8hsjBRm71duW4LsNo8ZEWVZ4fwmydfoy1zkgeg+1POLMkQSy CC1XeoSIONbUDrHWmF+ga1RC287MfbQKaY/mauXmAL/Cts7tRDzFGSXebcq1g6YOZDDs Hi7w== 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=/PAFDc19whP8gE8TbCtljqrLmylPN1rotB4sfti0awU=; b=rqG6x1/Cx9rmc6WRzgXGg1Gibo7dMFPRw5CovZs1kGZGuRrP5Cy/IBfIINf3JR/pEA kEj2FkBPiGqa/PfRFzmFh2+Yjy99Eu8jUQV30my42i9r64w4iDUg9YKYBSpqnrrVqRE8 8Kg7jO/ykSoiPuYNwn1X1nU+eYhsSwdmqDBajQQNhDVJRVyc6V05wyeyQB51q0MxUSjF sRq14f4AMgdjklNJ4WKV9Keol3a/g7Q6LLbOzibm1G1OQ7CNhHl2NHlGj4zb/FvyMOAl jr5napIp6O1PEepOxt+RIDfcSu3/2BFddfkpeMUhXdueMl75vj+44l1HtaNFLFGj3mhu 0iGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NMGZY8kl; 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 j6si8653501pfh.329.2017.10.29.06.49.43; Sun, 29 Oct 2017 06:49:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NMGZY8kl; 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 S1751877AbdJ2Ntl (ORCPT + 27 others); Sun, 29 Oct 2017 09:49:41 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:46121 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751830AbdJ2Nth (ORCPT ); Sun, 29 Oct 2017 09:49:37 -0400 Received: by mail-pf0-f196.google.com with SMTP id p87so8667731pfj.3 for ; Sun, 29 Oct 2017 06:49:37 -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=/PAFDc19whP8gE8TbCtljqrLmylPN1rotB4sfti0awU=; b=NMGZY8kl2QgEMGTSBJ4E/4vCWzQ/d8U5z01eLL1yGm49SJ4IcYr+Cav5pVS32T/8Yr 0DoIX1D7XEUEnSnTlUyf87DNbfgA43CiS2DWz7ydplNBMhvNgycocWlwSG1HMMAq0Uom VSfDzO3g/SyZO9C2mQvoQORY2gi1+e5rBXa9A= 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=/PAFDc19whP8gE8TbCtljqrLmylPN1rotB4sfti0awU=; b=In36jYZHrE6nVnhqx/P7j+vSCCmjK2Mgj/k2dJRinGklkz8KENEPLGimLjTr0Ury/G 6/NoO/SQ8StHbfLuve5h5gv4sbttZ+gQKJ9Q+aZIB0MpWq/BhIe44QiBDa8DoICrTyqe shsUvUiivSTjxLxfTHq4xTx6tBnzGdkL5msx4xZqJbOlQg9JgqyBXOkFcNJfXY3ERlRb e1KpieYuyRelXIlpFBprTrkZfzV3Y6GhNJi2CQxbN9ZcBiXgJN6+K60Mey1lV3OK0WT0 dXDuA4fBUxaK27iGPt6qblBx8sjgk2UOkbbYIhIzqkx+p5PuLKYe+d60gadmLFoq272O 9KyA== X-Gm-Message-State: AMCzsaWfeSm4O3gOCftUXCHEcUX+0klaLS1yoNsGt3XIo1/VhtpSkDJN rWotiHn/+pQ3VMRjZW6dEnoL1Q== X-Received: by 10.99.3.7 with SMTP id 7mr5161897pgd.295.1509284976800; Sun, 29 Oct 2017 06:49:36 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id l22sm24563957pfk.45.2017.10.29.06.49.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:36 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 10/12] boot_constraint: Add support for Hisilicon platforms Date: Sun, 29 Oct 2017 19:18:58 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds boot constraint support for Hisilicon platforms. Currently only one use case is supported: earlycon. One of the UART is enabled by the bootloader and is used for early console in the kernel. The boot constraint core handles it properly and removes constraints once the serial device is probed by its driver. This is tested on hi6220-hikey 96board. Signed-off-by: Viresh Kumar --- arch/arm64/Kconfig.platforms | 1 + drivers/boot_constraints/Makefile | 2 + drivers/boot_constraints/hikey.c | 145 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 drivers/boot_constraints/hikey.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms index 6b54ee8c1262..265df4a088ab 100644 --- a/arch/arm64/Kconfig.platforms +++ b/arch/arm64/Kconfig.platforms @@ -87,6 +87,7 @@ config ARCH_HISI select ARM_TIMER_SP804 select HISILICON_IRQ_MBIGEN if PCI select PINCTRL + select DEV_BOOT_CONSTRAINTS help This enables support for Hisilicon ARMv8 SoC family diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index 0d4f88bb767c..43c89d2458e9 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/boot_constraints/Makefile @@ -1,3 +1,5 @@ # Makefile for device boot constraints obj-y := clk.o deferrable_dev.o core.o pm.o serial.o supply.o + +obj-$(CONFIG_ARCH_HISI) += hikey.o diff --git a/drivers/boot_constraints/hikey.c b/drivers/boot_constraints/hikey.c new file mode 100644 index 000000000000..5f69f9451d93 --- /dev/null +++ b/drivers/boot_constraints/hikey.c @@ -0,0 +1,145 @@ +/* + * This takes care of Hisilicon boot time device constraints, normally set by + * the Bootloader. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#include +#include +#include +#include + +struct hikey_machine_constraints { + struct dev_boot_constraint_of *dev_constraints; + unsigned int count; +}; + +static struct dev_boot_constraint_clk_info uart_iclk_info = { + .name = "uartclk", +}; + +static struct dev_boot_constraint_clk_info uart_pclk_info = { + .name = "apb_pclk", +}; + +static struct dev_boot_constraint hikey3660_uart_constraints[] = { + { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &uart_iclk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &uart_pclk_info, + }, +}; + +static const char * const uarts_hikey3660[] = { + "serial@fff32000", /* UART 6 */ +}; + +static struct dev_boot_constraint_of hikey3660_dev_constraints[] = { + { + .compat = "arm,pl011", + .constraints = hikey3660_uart_constraints, + .count = ARRAY_SIZE(hikey3660_uart_constraints), + + .dev_names = uarts_hikey3660, + .dev_names_count = ARRAY_SIZE(uarts_hikey3660), + }, +}; + +static struct hikey_machine_constraints hikey3660_constraints = { + .dev_constraints = hikey3660_dev_constraints, + .count = ARRAY_SIZE(hikey3660_dev_constraints), +}; + +static const char * const uarts_hikey6220[] = { + "uart@f7113000", /* UART 3 */ +}; + +static struct dev_boot_constraint_of hikey6220_dev_constraints[] = { + { + .compat = "arm,pl011", + .constraints = hikey3660_uart_constraints, + .count = ARRAY_SIZE(hikey3660_uart_constraints), + + .dev_names = uarts_hikey6220, + .dev_names_count = ARRAY_SIZE(uarts_hikey6220), + }, +}; + +static struct hikey_machine_constraints hikey6220_constraints = { + .dev_constraints = hikey6220_dev_constraints, + .count = ARRAY_SIZE(hikey6220_dev_constraints), +}; + +static struct dev_boot_constraint hikey3798cv200_uart_constraints[] = { + { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &uart_pclk_info, + }, +}; + +static const char * const uarts_hikey3798cv200[] = { + "serial@8b00000", /* UART 0 */ +}; + +static struct dev_boot_constraint_of hikey3798cv200_dev_constraints[] = { + { + .compat = "arm,pl011", + .constraints = hikey3798cv200_uart_constraints, + .count = ARRAY_SIZE(hikey3798cv200_uart_constraints), + + .dev_names = uarts_hikey3798cv200, + .dev_names_count = ARRAY_SIZE(uarts_hikey3798cv200), + }, +}; + +static struct hikey_machine_constraints hikey3798cv200_constraints = { + .dev_constraints = hikey3798cv200_dev_constraints, + .count = ARRAY_SIZE(hikey3798cv200_dev_constraints), +}; + +static const struct of_device_id machines[] __initconst = { + { .compatible = "hisilicon,hi3660", .data = &hikey3660_constraints }, + { .compatible = "hisilicon,hi3798cv200", .data = &hikey3798cv200_constraints }, + { .compatible = "hisilicon,hi6220", .data = &hikey6220_constraints }, + { } +}; + +static int __init hikey_constraints_init(void) +{ + const struct hikey_machine_constraints *constraints; + const struct of_device_id *match; + struct device_node *np; + + if (!boot_constraint_earlycon_enabled()) + return 0; + + np = of_find_node_by_path("/"); + if (!np) + return -ENODEV; + + match = of_match_node(machines, np); + of_node_put(np); + + if (!match) + return 0; + + constraints = match->data; + BUG_ON(!constraints); + + dev_boot_constraint_add_deferrable_of(constraints->dev_constraints, + constraints->count); + + return 0; +} + +/* + * The amba-pl011 driver registers itself from arch_initcall level. Setup the + * serial boot constraints before that in order not to miss any boot messages. + */ +postcore_initcall_sync(hikey_constraints_init); From patchwork Sun Oct 29 13:48:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117412 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1527693qgn; Sun, 29 Oct 2017 06:49:58 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SuyK8RiEz1HraMUsdPnNx4Qrke0oImm+29wuEguEk6H5XaTb58GAd/T/eltjkqhPz7E3xS X-Received: by 10.99.7.133 with SMTP id 127mr5175893pgh.147.1509284997914; Sun, 29 Oct 2017 06:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509284997; cv=none; d=google.com; s=arc-20160816; b=Zg19Aboq4lDwiSH9aHPrL1iua1rbwyXHzi8Q/oKvWoAKO2FrqLK9pKhBCX8s1E1CDP Aoc8iG9Rh8PB+9yGuNEl6Afm8ju3vdhZUt9oOTAAc5g+m3d3q2B6QV8paomIAv6y5+st M3JMniUlXV+kcgJRhReH04pPisvsnkGf03r3qpos9Oqo6PuDmcjY+OLQv/tB7mwKRVOX o9Yjs8MjfdbyoW0AvYKMNsgY/2qMZLhCcrjeSj1TA03TwpYaINiv1UYj5bdecYf+jVAW 6jVHIPcki3EiSUcZR0Hcjq4y8fwbxaH4XoXUtvdDS8j1WcOESR915BHC/CHuVjZW9pKK WF/A== 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=NH7AjqnFOxvht+/j6IGCbejh+UmZeXfmbRXwD8Y9VqI=; b=N9cts79kU0l/diTqCgCJLxFgAe1MuKUf26WGjNWtDIurg8GohAHNOOU7J+txFB8mZT pioGPZni40YVi68kBNFesaVTcidgcIb0qfl+mdtT6AFndCVNNn/NYv67qjpZQ36z8hgP VvZN+/765hOPSlu2gTNQwKrZykG9JkAv8UUll9JJWc0rukL8LeOcXKHkQadpKbXBzbeL wTwNE7MdUXNHPSmBFQ2bY1iyJ8mw2FdCDLzNYAGSHLNCa/dt5q/PmOq28fNPK/fEXAkt mZ+jp6buf57OTqbkEeDd/tp1yAyUTm7VzbNiUWGlHJBZw/zQ8TMTcU5w0teJoJxGbYBt LpWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H47t3EYy; 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 j90si8781473pfj.47.2017.10.29.06.49.57; Sun, 29 Oct 2017 06:49:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H47t3EYy; 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 S1751934AbdJ2Nt4 (ORCPT + 27 others); Sun, 29 Oct 2017 09:49:56 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:45271 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751851AbdJ2Ntk (ORCPT ); Sun, 29 Oct 2017 09:49:40 -0400 Received: by mail-pg0-f66.google.com with SMTP id b192so9120525pga.2 for ; Sun, 29 Oct 2017 06:49:40 -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=NH7AjqnFOxvht+/j6IGCbejh+UmZeXfmbRXwD8Y9VqI=; b=H47t3EYynBj3ljlFCvz/iY24HzcGL+FL7OeCq4dFcxf0dQpziSy6kdhlprox2kLrFz 8hAz12vATzErOwu1VNcmLkwKYUmZgi0JtxcOxMNzgAsMvNTImYobe5oYQlGEEEn5mB8I mFlvOkUdVgqejM5581WCJIAnANTzmroLSzTjQ= 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=NH7AjqnFOxvht+/j6IGCbejh+UmZeXfmbRXwD8Y9VqI=; b=q5J5rrkyNsmUR5zl6hcwVihhqLU33SZebj9/X01k0KiMz7mEKxiWty52B/MYbD2HHv p4UMM8zA/TRP/26QWD50e0Y0hccXfo/8ZSTKz1M+tsd219eJcZC+wK2RI9cH4tAv5HYj w5MkA8OsCQoZ4JHMRttriNQ1VT+0lrdTcIbp5ZhpAkQ0Ml3aUYkvuEv2Sgp+J/MycVJL T44Q+XrFUhccflKg7XuUVKPaYEbPFku/7/qZm+iOvCUnix/crDpET4pexM8nuY95nZzK neIfi3QjqsTFAt8/0fG20BXwgPAwckXNZ3qYC52njcva3k3ypcnNmj/YZfNkFxLb6rFy wysw== X-Gm-Message-State: AMCzsaUyIhP1YtxiLzdHGObwKirH04F44cMsOtstrfmoLSnAMT28/mBi 8YLj+knHYIJrXejsbqFjYbkS9Q== X-Received: by 10.99.3.1 with SMTP id 1mr5274036pgd.111.1509284979451; Sun, 29 Oct 2017 06:49:39 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id r22sm23676463pfl.15.2017.10.29.06.49.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:38 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 11/12] boot_constraint: Add support for IMX platform Date: Sun, 29 Oct 2017 19:18:59 +0530 Message-Id: <154e4d17ab6b848fb3ba240d9e2349278a16442a.1509284255.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds boot constraint support for IMX platforms. Currently only one use case is supported: earlycon. Some of the UARTs are enabled by the bootloader and are used for early console in the kernel. The boot constraint core handles them properly and removes them once the serial device is probed by its driver. This gets rid of lots of hacky code in the clock drivers. Signed-off-by: Viresh Kumar --- arch/arm/mach-imx/Kconfig | 1 + drivers/boot_constraints/Makefile | 1 + drivers/boot_constraints/imx.c | 113 ++++++++++++++++++++++++++++++++++++++ drivers/clk/imx/clk-imx25.c | 12 ---- drivers/clk/imx/clk-imx27.c | 13 ----- drivers/clk/imx/clk-imx31.c | 12 ---- drivers/clk/imx/clk-imx35.c | 10 ---- drivers/clk/imx/clk-imx51-imx53.c | 16 ------ drivers/clk/imx/clk-imx6q.c | 8 --- drivers/clk/imx/clk-imx6sl.c | 8 --- drivers/clk/imx/clk-imx6sx.c | 8 --- drivers/clk/imx/clk-imx7d.c | 14 ----- drivers/clk/imx/clk.c | 38 ------------- drivers/clk/imx/clk.h | 1 - 14 files changed, 115 insertions(+), 140 deletions(-) create mode 100644 drivers/boot_constraints/imx.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index 782699e67600..9ea1fe32b280 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -4,6 +4,7 @@ menuconfig ARCH_MXC select ARCH_SUPPORTS_BIG_ENDIAN select CLKSRC_IMX_GPT select GENERIC_IRQ_CHIP + select DEV_BOOT_CONSTRAINTS select GPIOLIB select PINCTRL select PM_OPP if PM diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index 43c89d2458e9..3b5a87fcf099 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/boot_constraints/Makefile @@ -3,3 +3,4 @@ obj-y := clk.o deferrable_dev.o core.o pm.o serial.o supply.o obj-$(CONFIG_ARCH_HISI) += hikey.o +obj-$(CONFIG_ARCH_MXC) += imx.o diff --git a/drivers/boot_constraints/imx.c b/drivers/boot_constraints/imx.c new file mode 100644 index 000000000000..a402dfdea1bb --- /dev/null +++ b/drivers/boot_constraints/imx.c @@ -0,0 +1,113 @@ +/* + * This takes care of IMX boot time device constraints, normally set by the + * Bootloader. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * + * This file is released under the GPLv2. + */ + +#include +#include +#include +#include + +struct imx_machine_constraints { + struct dev_boot_constraint_of *dev_constraints; + unsigned int count; +}; + +static struct dev_boot_constraint_clk_info uart_ipg_clk_info = { + .name = "ipg", +}; + +static struct dev_boot_constraint_clk_info uart_per_clk_info = { + .name = "per", +}; + +static struct dev_boot_constraint imx_uart_constraints[] = { + { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &uart_ipg_clk_info, + }, { + .type = DEV_BOOT_CONSTRAINT_CLK, + .data = &uart_per_clk_info, + }, +}; + +static struct dev_boot_constraint_of imx_dev_constraints[] = { + { + .compat = "fsl,imx21-uart", + .constraints = imx_uart_constraints, + .count = ARRAY_SIZE(imx_uart_constraints), + }, +}; + +static struct imx_machine_constraints imx_constraints = { + .dev_constraints = imx_dev_constraints, + .count = ARRAY_SIZE(imx_dev_constraints), +}; + +/* imx7 */ +static struct dev_boot_constraint_of imx7_dev_constraints[] = { + { + .compat = "fsl,imx6q-uart", + .constraints = imx_uart_constraints, + .count = ARRAY_SIZE(imx_uart_constraints), + }, +}; + +static struct imx_machine_constraints imx7_constraints = { + .dev_constraints = imx7_dev_constraints, + .count = ARRAY_SIZE(imx7_dev_constraints), +}; + +static const struct of_device_id machines[] __initconst = { + { .compatible = "fsl,imx25", .data = &imx_constraints }, + { .compatible = "fsl,imx27", .data = &imx_constraints }, + { .compatible = "fsl,imx31", .data = &imx_constraints }, + { .compatible = "fsl,imx35", .data = &imx_constraints }, + { .compatible = "fsl,imx50", .data = &imx_constraints }, + { .compatible = "fsl,imx51", .data = &imx_constraints }, + { .compatible = "fsl,imx53", .data = &imx_constraints }, + { .compatible = "fsl,imx6dl", .data = &imx_constraints }, + { .compatible = "fsl,imx6q", .data = &imx_constraints }, + { .compatible = "fsl,imx6qp", .data = &imx_constraints }, + { .compatible = "fsl,imx6sl", .data = &imx_constraints }, + { .compatible = "fsl,imx6sx", .data = &imx_constraints }, + { .compatible = "fsl,imx6ul", .data = &imx_constraints }, + { .compatible = "fsl,imx6ull", .data = &imx_constraints }, + { .compatible = "fsl,imx7d", .data = &imx7_constraints }, + { .compatible = "fsl,imx7s", .data = &imx7_constraints }, + { } +}; + +static int __init imx_constraints_init(void) +{ + const struct imx_machine_constraints *constraints; + const struct of_device_id *match; + struct device_node *np; + + if (!boot_constraint_earlycon_enabled()) + return 0; + + np = of_find_node_by_path("/"); + if (!np) + return -ENODEV; + + match = of_match_node(machines, np); + of_node_put(np); + + if (!match) + return 0; + + constraints = match->data; + BUG_ON(!constraints); + + dev_boot_constraint_add_deferrable_of(constraints->dev_constraints, + constraints->count); + + return 0; +} +subsys_initcall(imx_constraints_init); diff --git a/drivers/clk/imx/clk-imx25.c b/drivers/clk/imx/clk-imx25.c index 23686f756b5e..4df652cd912c 100644 --- a/drivers/clk/imx/clk-imx25.c +++ b/drivers/clk/imx/clk-imx25.c @@ -86,16 +86,6 @@ enum mx25_clks { static struct clk *clk[clk_max]; -static struct clk ** const uart_clks[] __initconst = { - &clk[uart_ipg_per], - &clk[uart1_ipg], - &clk[uart2_ipg], - &clk[uart3_ipg], - &clk[uart4_ipg], - &clk[uart5_ipg], - NULL -}; - static int __init __mx25_clocks_init(void __iomem *ccm_base) { BUG_ON(!ccm_base); @@ -241,8 +231,6 @@ static int __init __mx25_clocks_init(void __iomem *ccm_base) */ clk_set_parent(clk[cko_sel], clk[ipg]); - imx_register_uart_clocks(uart_clks); - return 0; } diff --git a/drivers/clk/imx/clk-imx27.c b/drivers/clk/imx/clk-imx27.c index cf5cf75a4848..646d2075b510 100644 --- a/drivers/clk/imx/clk-imx27.c +++ b/drivers/clk/imx/clk-imx27.c @@ -47,17 +47,6 @@ static const char *ssi_sel_clks[] = { "spll_gate", "mpll", }; static struct clk *clk[IMX27_CLK_MAX]; static struct clk_onecell_data clk_data; -static struct clk ** const uart_clks[] __initconst = { - &clk[IMX27_CLK_PER1_GATE], - &clk[IMX27_CLK_UART1_IPG_GATE], - &clk[IMX27_CLK_UART2_IPG_GATE], - &clk[IMX27_CLK_UART3_IPG_GATE], - &clk[IMX27_CLK_UART4_IPG_GATE], - &clk[IMX27_CLK_UART5_IPG_GATE], - &clk[IMX27_CLK_UART6_IPG_GATE], - NULL -}; - static void __init _mx27_clocks_init(unsigned long fref) { BUG_ON(!ccm); @@ -174,8 +163,6 @@ static void __init _mx27_clocks_init(unsigned long fref) clk_prepare_enable(clk[IMX27_CLK_EMI_AHB_GATE]); - imx_register_uart_clocks(uart_clks); - imx_print_silicon_rev("i.MX27", mx27_revision()); } diff --git a/drivers/clk/imx/clk-imx31.c b/drivers/clk/imx/clk-imx31.c index cbce308aad04..d0a720b61aca 100644 --- a/drivers/clk/imx/clk-imx31.c +++ b/drivers/clk/imx/clk-imx31.c @@ -63,16 +63,6 @@ enum mx31_clks { static struct clk *clk[clk_max]; static struct clk_onecell_data clk_data; -static struct clk ** const uart_clks[] __initconst = { - &clk[ipg], - &clk[uart1_gate], - &clk[uart2_gate], - &clk[uart3_gate], - &clk[uart4_gate], - &clk[uart5_gate], - NULL -}; - static void __init _mx31_clocks_init(void __iomem *base, unsigned long fref) { clk[dummy] = imx_clk_fixed("dummy", 0); @@ -208,8 +198,6 @@ int __init mx31_clocks_init(unsigned long fref) clk_register_clkdev(clk[sdma_gate], NULL, "imx31-sdma"); clk_register_clkdev(clk[iim_gate], "iim", NULL); - - imx_register_uart_clocks(uart_clks); mxc_timer_init(MX31_GPT1_BASE_ADDR, MX31_INT_GPT, GPT_TYPE_IMX31); return 0; diff --git a/drivers/clk/imx/clk-imx35.c b/drivers/clk/imx/clk-imx35.c index 203cad6c9aab..081aacd2335b 100644 --- a/drivers/clk/imx/clk-imx35.c +++ b/drivers/clk/imx/clk-imx35.c @@ -86,14 +86,6 @@ enum mx35_clks { static struct clk *clk[clk_max]; -static struct clk ** const uart_clks[] __initconst = { - &clk[ipg], - &clk[uart1_gate], - &clk[uart2_gate], - &clk[uart3_gate], - NULL -}; - static void __init _mx35_clocks_init(void) { void __iomem *base; @@ -247,8 +239,6 @@ static void __init _mx35_clocks_init(void) */ clk_prepare_enable(clk[scc_gate]); - imx_register_uart_clocks(uart_clks); - imx_print_silicon_rev("i.MX35", mx35_revision()); } diff --git a/drivers/clk/imx/clk-imx51-imx53.c b/drivers/clk/imx/clk-imx51-imx53.c index 7bcaf270db11..2da06f8ffae1 100644 --- a/drivers/clk/imx/clk-imx51-imx53.c +++ b/drivers/clk/imx/clk-imx51-imx53.c @@ -131,20 +131,6 @@ static const char *ieee1588_sels[] = { "pll3_sw", "pll4_sw", "dummy" /* usbphy2_ static struct clk *clk[IMX5_CLK_END]; static struct clk_onecell_data clk_data; -static struct clk ** const uart_clks[] __initconst = { - &clk[IMX5_CLK_UART1_IPG_GATE], - &clk[IMX5_CLK_UART1_PER_GATE], - &clk[IMX5_CLK_UART2_IPG_GATE], - &clk[IMX5_CLK_UART2_PER_GATE], - &clk[IMX5_CLK_UART3_IPG_GATE], - &clk[IMX5_CLK_UART3_PER_GATE], - &clk[IMX5_CLK_UART4_IPG_GATE], - &clk[IMX5_CLK_UART4_PER_GATE], - &clk[IMX5_CLK_UART5_IPG_GATE], - &clk[IMX5_CLK_UART5_PER_GATE], - NULL -}; - static void __init mx5_clocks_common_init(void __iomem *ccm_base) { clk[IMX5_CLK_DUMMY] = imx_clk_fixed("dummy", 0); @@ -325,8 +311,6 @@ static void __init mx5_clocks_common_init(void __iomem *ccm_base) clk_prepare_enable(clk[IMX5_CLK_TMAX1]); clk_prepare_enable(clk[IMX5_CLK_TMAX2]); /* esdhc2, fec */ clk_prepare_enable(clk[IMX5_CLK_TMAX3]); /* esdhc1, esdhc4 */ - - imx_register_uart_clocks(uart_clks); } static void __init mx50_clocks_init(struct device_node *np) diff --git a/drivers/clk/imx/clk-imx6q.c b/drivers/clk/imx/clk-imx6q.c index c07df719b8a3..5af256a076a1 100644 --- a/drivers/clk/imx/clk-imx6q.c +++ b/drivers/clk/imx/clk-imx6q.c @@ -150,12 +150,6 @@ static inline int clk_on_imx6dl(void) return of_machine_is_compatible("fsl,imx6dl"); } -static struct clk ** const uart_clks[] __initconst = { - &clk[IMX6QDL_CLK_UART_IPG], - &clk[IMX6QDL_CLK_UART_SERIAL], - NULL -}; - static int ldb_di_sel_by_clock_id(int clock_id) { switch (clock_id) { @@ -918,7 +912,5 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node) clk_set_parent(clk[IMX6QDL_CLK_GPU2D_CORE_SEL], clk[IMX6QDL_CLK_PLL3_USB_OTG]); } - - imx_register_uart_clocks(uart_clks); } CLK_OF_DECLARE(imx6q, "fsl,imx6q-ccm", imx6q_clocks_init); diff --git a/drivers/clk/imx/clk-imx6sl.c b/drivers/clk/imx/clk-imx6sl.c index 9642cdf0fb88..97ab67783609 100644 --- a/drivers/clk/imx/clk-imx6sl.c +++ b/drivers/clk/imx/clk-imx6sl.c @@ -185,12 +185,6 @@ void imx6sl_set_wait_clk(bool enter) imx6sl_enable_pll_arm(false); } -static struct clk ** const uart_clks[] __initconst = { - &clks[IMX6SL_CLK_UART], - &clks[IMX6SL_CLK_UART_SERIAL], - NULL -}; - static void __init imx6sl_clocks_init(struct device_node *ccm_node) { struct device_node *np; @@ -447,7 +441,5 @@ static void __init imx6sl_clocks_init(struct device_node *ccm_node) clk_set_parent(clks[IMX6SL_CLK_LCDIF_AXI_SEL], clks[IMX6SL_CLK_PLL2_PFD2]); - - imx_register_uart_clocks(uart_clks); } CLK_OF_DECLARE(imx6sl, "fsl,imx6sl-ccm", imx6sl_clocks_init); diff --git a/drivers/clk/imx/clk-imx6sx.c b/drivers/clk/imx/clk-imx6sx.c index e6d389e333d7..e38dfb855ae8 100644 --- a/drivers/clk/imx/clk-imx6sx.c +++ b/drivers/clk/imx/clk-imx6sx.c @@ -137,12 +137,6 @@ static u32 share_count_ssi3; static u32 share_count_sai1; static u32 share_count_sai2; -static struct clk ** const uart_clks[] __initconst = { - &clks[IMX6SX_CLK_UART_IPG], - &clks[IMX6SX_CLK_UART_SERIAL], - NULL -}; - static void __init imx6sx_clocks_init(struct device_node *ccm_node) { struct device_node *np; @@ -566,7 +560,5 @@ static void __init imx6sx_clocks_init(struct device_node *ccm_node) clk_set_parent(clks[IMX6SX_CLK_QSPI1_SEL], clks[IMX6SX_CLK_PLL2_BUS]); clk_set_parent(clks[IMX6SX_CLK_QSPI2_SEL], clks[IMX6SX_CLK_PLL2_BUS]); - - imx_register_uart_clocks(uart_clks); } CLK_OF_DECLARE(imx6sx, "fsl,imx6sx-ccm", imx6sx_clocks_init); diff --git a/drivers/clk/imx/clk-imx7d.c b/drivers/clk/imx/clk-imx7d.c index 2305699db467..ec919758b2ae 100644 --- a/drivers/clk/imx/clk-imx7d.c +++ b/drivers/clk/imx/clk-imx7d.c @@ -392,17 +392,6 @@ static int const clks_init_on[] __initconst = { static struct clk_onecell_data clk_data; -static struct clk ** const uart_clks[] __initconst = { - &clks[IMX7D_UART1_ROOT_CLK], - &clks[IMX7D_UART2_ROOT_CLK], - &clks[IMX7D_UART3_ROOT_CLK], - &clks[IMX7D_UART4_ROOT_CLK], - &clks[IMX7D_UART5_ROOT_CLK], - &clks[IMX7D_UART6_ROOT_CLK], - &clks[IMX7D_UART7_ROOT_CLK], - NULL -}; - static void __init imx7d_clocks_init(struct device_node *ccm_node) { struct device_node *np; @@ -893,8 +882,5 @@ static void __init imx7d_clocks_init(struct device_node *ccm_node) /* set uart module clock's parent clock source that must be great then 80MHz */ clk_set_parent(clks[IMX7D_UART1_ROOT_SRC], clks[IMX7D_OSC_24M_CLK]); - - imx_register_uart_clocks(uart_clks); - } CLK_OF_DECLARE(imx7d, "fsl,imx7d-ccm", imx7d_clocks_init); diff --git a/drivers/clk/imx/clk.c b/drivers/clk/imx/clk.c index a634b1185be3..df12b5307175 100644 --- a/drivers/clk/imx/clk.c +++ b/drivers/clk/imx/clk.c @@ -73,41 +73,3 @@ void imx_cscmr1_fixup(u32 *val) *val ^= CSCMR1_FIXUP; return; } - -static int imx_keep_uart_clocks __initdata; -static struct clk ** const *imx_uart_clocks __initdata; - -static int __init imx_keep_uart_clocks_param(char *str) -{ - imx_keep_uart_clocks = 1; - - return 0; -} -__setup_param("earlycon", imx_keep_uart_earlycon, - imx_keep_uart_clocks_param, 0); -__setup_param("earlyprintk", imx_keep_uart_earlyprintk, - imx_keep_uart_clocks_param, 0); - -void __init imx_register_uart_clocks(struct clk ** const clks[]) -{ - if (imx_keep_uart_clocks) { - int i; - - imx_uart_clocks = clks; - for (i = 0; imx_uart_clocks[i]; i++) - clk_prepare_enable(*imx_uart_clocks[i]); - } -} - -static int __init imx_clk_disable_uart(void) -{ - if (imx_keep_uart_clocks && imx_uart_clocks) { - int i; - - for (i = 0; imx_uart_clocks[i]; i++) - clk_disable_unprepare(*imx_uart_clocks[i]); - } - - return 0; -} -late_initcall_sync(imx_clk_disable_uart); diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index d54f0720afba..6fda6e1d181f 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -7,7 +7,6 @@ extern spinlock_t imx_ccm_lock; void imx_check_clocks(struct clk *clks[], unsigned int count); -void imx_register_uart_clocks(struct clk ** const clks[]); extern void imx_cscmr1_fixup(u32 *val); From patchwork Sun Oct 29 13:49:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 117411 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1527615qgn; Sun, 29 Oct 2017 06:49:52 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R1vS354Wzk0UqQKNjrqtNHE0sa+1+Xy4Q22j5MdYSW1Yhp7H1o5s574Wfq2WTjanE8Avqv X-Received: by 10.98.223.15 with SMTP id u15mr5914012pfg.115.1509284992368; Sun, 29 Oct 2017 06:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509284992; cv=none; d=google.com; s=arc-20160816; b=dKrUS4WPUSQKB1tmom9c/wlOeXkwhrYJH7DOVUVrNJE5a4R5yNpbmSsksnZ8yMQm0P vbO613IK+38PhNFzmTP8oftTRwe8kcuz3a6NRy2XrapMoOi0IZffpJ2/GRaXLhNNm7pr sbc2498Nrkft+tCsym1WRcdLyS3NdvcieVIE7eerY2zrkQ+LR5RcXcyIFxqBWT8mlSdp t7+UKvs3KR2/Sy0pGcBZrZ8km1+AHCP5NRZiwxGO7nwnxe6bHaxiTv3KxB4dJyvUDEkf xdCOPHjVrCERG8QdpqDwJF4X0hLcqsPkQ13KweZhKj1JLFWBfS64p+IxavHTJ9nzf7V4 mQcQ== 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=bVJe14EBdiFFBbA8qLcbwY4uEd5vnP2Um/7UVfi0rzY=; b=rdYm+70+v9p90EnF73QcH6M+H2yNPfmvJtMBYGbkb6otLdIXRECGVDW3LXiX9+2raj Ed1n4AkrogGVkt8/ZL4V8oh6PG9NT0ZWe597a81rZhfOjTWpYWrWytrb22ki1z7ANG7Y zmccuo+WdHbzZHKxP3wcN3Omr7X/D9eF3WjwNItGyZ0ZdH4EOnLsXwXPolnUQ0tfC5Kv fJ8HkMG6ZUcFPWKyJaed/GJ1Ik9t7OYIE2iA87OWnqyCalIkw8QpKcWzzo9fTkoiGimT wJuIf8f0ZhHa/5l3u4M3KTQ4fq8/rBv8lJwzwgFL6qGqMm7p3/9npNnKv3iPfY4+JmX+ wS1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ATcfCt77; 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 u23si5839509plk.787.2017.10.29.06.49.52; Sun, 29 Oct 2017 06:49:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ATcfCt77; 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 S1751908AbdJ2Ntu (ORCPT + 27 others); Sun, 29 Oct 2017 09:49:50 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:57240 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751830AbdJ2Ntm (ORCPT ); Sun, 29 Oct 2017 09:49:42 -0400 Received: by mail-pg0-f65.google.com with SMTP id m18so9101050pgd.13 for ; Sun, 29 Oct 2017 06:49:42 -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=bVJe14EBdiFFBbA8qLcbwY4uEd5vnP2Um/7UVfi0rzY=; b=ATcfCt77CEzuX5W52njuP3+SILlYu65WgCcjigXmDt3RQ6wAfhhBUdMoDwfe2lIjwd yGZyAddFbgoFxDAGDwTNNy4vgpTUoFlT7Qj+VNsIoXyuK6bDWVv7Q/CnKSccK+cw2gJH yd+AjaN/qQaySpHqOg+t1W+LFGVETUc65uH60= 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=bVJe14EBdiFFBbA8qLcbwY4uEd5vnP2Um/7UVfi0rzY=; b=Qae5PzukVQvatWGhKJ/Oz2SKQfQmreGQH/tPJy3sDzRA+9zSPE+AplcoXXTJiR7CA0 MI3LSDug5HEDRu2uWAJX4m6Yi8FNfPmaxwyBOGoLon+fWfggh92griVTjp36DlJePapV /L+hm2kmI6WEwNADYYDhjzbpNc2hOJ3X+w/Q8W/mYLqrtjmBQgIIgcG3o3IafW0OD2ui CjuvOSciUWrg3KrwnItN4pMZ4OgDA+wL4n6zDExZ1FQlenzTcT5TzJ/Lv9eRPBHUfEvp 2twItqx/20cdwungvOGEXM63xXFqAA2jlHMjBZGW0eklXne3MC0FxCkeQP14nplECtkH CKLg== X-Gm-Message-State: AMCzsaW05nZj0+D9224oijJDu4B+4jg/CRXsrMmicmlyjQk1cGdxWu+W Ihx3el1jij+djX990+MwYlBkqg== X-Received: by 10.84.218.68 with SMTP id f4mr4763136plm.395.1509284982001; Sun, 29 Oct 2017 06:49:42 -0700 (PDT) Received: from localhost ([122.167.161.211]) by smtp.gmail.com with ESMTPSA id 81sm25482565pfh.145.2017.10.29.06.49.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 06:49:41 -0700 (PDT) From: Viresh Kumar To: Greg Kroah-Hartman Cc: Viresh Kumar , Vincent Guittot , Stephen Boyd , Rajendra Nayak , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, robdclark@gmail.com, s.hauer@pengutronix.de, l.stach@pengutronix.de, shawnguo@kernel.org, fabio.estevam@nxp.com, nm@ti.com, xuwei5@hisilicon.com, robh+dt@kernel.org Subject: [PATCH V4 12/12] boot_constraint: Add Qualcomm display controller constraints Date: Sun, 29 Oct 2017 19:19:00 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.rc1.236.g92ea95045093 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rajendra Nayak This sets boot constraints for the display controller used on Qualcomm dragonboard 410c. The display controlled is enabled by the bootloader to show a flash screen during kernel boot. The handover to kernel should be without any glitches on the screen.The resources of the display controller (like regulators) are shared with other peripherals, which may reconfigure those resources before the display driver comes up. The same problem can happen if the display driver probes first, as the constraints of the other devices (sharing same resources with display controller) may not be honored anymore by the kernel. Signed-off-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- arch/arm64/Kconfig.platforms | 1 + drivers/boot_constraints/Makefile | 1 + drivers/boot_constraints/qcom.c | 123 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 drivers/boot_constraints/qcom.c -- 2.15.0.rc1.236.g92ea95045093 diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms index 265df4a088ab..6343627cf105 100644 --- a/arch/arm64/Kconfig.platforms +++ b/arch/arm64/Kconfig.platforms @@ -134,6 +134,7 @@ config ARCH_QCOM bool "Qualcomm Platforms" select GPIOLIB select PINCTRL + select DEV_BOOT_CONSTRAINTS help This enables support for the ARMv8 based Qualcomm chipsets. diff --git a/drivers/boot_constraints/Makefile b/drivers/boot_constraints/Makefile index 3b5a87fcf099..e32751b70957 100644 --- a/drivers/boot_constraints/Makefile +++ b/drivers/boot_constraints/Makefile @@ -4,3 +4,4 @@ obj-y := clk.o deferrable_dev.o core.o pm.o serial.o supply.o obj-$(CONFIG_ARCH_HISI) += hikey.o obj-$(CONFIG_ARCH_MXC) += imx.o +obj-$(CONFIG_ARCH_QCOM) += qcom.o diff --git a/drivers/boot_constraints/qcom.c b/drivers/boot_constraints/qcom.c new file mode 100644 index 000000000000..e89357670906 --- /dev/null +++ b/drivers/boot_constraints/qcom.c @@ -0,0 +1,123 @@ +/* + * This sets up Dragonboard 410c constraints on behalf of the bootloader, which + * uses display controller to display a flash screen during system boot. + * + * Copyright (C) 2017 Linaro. + * Viresh Kumar + * Rajendra Nayak + * + * This file is released under the GPLv2. + */ + +#include +#include +#include +#include + +static struct dev_boot_constraint_clk_info iface_clk_info = { + .name = "iface_clk", +}; + +static struct dev_boot_constraint_clk_info bus_clk_info = { + .name = "bus_clk", +}; + +static struct dev_boot_constraint_clk_info core_clk_info = { + .name = "core_clk", +}; + +static struct dev_boot_constraint_clk_info vsync_clk_info = { + .name = "vsync_clk", +}; + +static struct dev_boot_constraint_clk_info esc0_clk_info = { + .name = "core_clk", +}; + +static struct dev_boot_constraint_clk_info byte_clk_info = { + .name = "byte_clk", +}; + +static struct dev_boot_constraint_clk_info pixel_clk_info = { + .name = "pixel_clk", +}; + +static struct dev_boot_constraint_supply_info vdda_info = { + .name = "vdda" +}; + +static struct dev_boot_constraint_supply_info vddio_info = { + .name = "vddio" +}; + +static struct dev_boot_constraint constraints_mdss[] = { + { + .type = DEV_BOOT_CONSTRAINT_PM, + .data = NULL, + }, +}; + +static 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, + }, +}; + +static 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 struct dev_boot_constraint_of constraints[] = { + { + .compat = "qcom,mdss", + .constraints = constraints_mdss, + .count = ARRAY_SIZE(constraints_mdss), + }, { + .compat = "qcom,mdp5", + .constraints = constraints_mdp, + .count = ARRAY_SIZE(constraints_mdp), + }, { + .compat = "qcom,mdss-dsi-ctrl", + .constraints = constraints_dsi, + .count = ARRAY_SIZE(constraints_dsi), + }, +}; + +static int __init qcom_constraints_init(void) +{ + /* Only Dragonboard 410c is supported for now */ + if (!of_machine_is_compatible("qcom,apq8016-sbc")) + return 0; + + dev_boot_constraint_add_deferrable_of(constraints, + ARRAY_SIZE(constraints)); + + return 0; +} +subsys_initcall(qcom_constraints_init);