From patchwork Wed Oct 6 03:53:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 515271 Delivered-To: patch@linaro.org Received: by 2002:ac0:890a:0:0:0:0:0 with SMTP id 10csp154936imy; Tue, 5 Oct 2021 20:54:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDJaIWP1oM23eFfiDQb/brfxuUnzSgEGnUO8/fCDLDYcUo4rq/+Q1+/uRtquLYOvJUvrwB X-Received: by 2002:a17:906:2f15:: with SMTP id v21mr29080888eji.444.1633492457554; Tue, 05 Oct 2021 20:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633492457; cv=none; d=google.com; s=arc-20160816; b=Sq/RhgVFaZv/YQrtcuDPTbpzbv4k8En9im2ZEzaqjdBKr8zIXynYRprGfZ0zI9QB5a 6KglBW4IttP4kePtrVKfqLd9cbRSp/2tpgLPODDmn8kYFZ737XBOKzgenz71thf3m0fv heVarCB4cNbrHW0GJ+vYahUXytQDFhLbL5Auv29o5gCDgy8Znz48Zb0h6S2bGxvC2z0g P46M5D7b22/Ac3TAPPUEwdoJN5CV1xXIdk8aQR4WpR8sLVxKLaZuamuOrm2nviJl8W/J E4wlZcH0xcTeb14f2p0hPolAXrVSnLpEu7kb0HnK4W7wnQJ63w9HQx3oN/MWkuqFANuF 98CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0QbCWpC0YUHd4oM8ALhGkUXV2GRwREBEvhvGaNVxQyo=; b=y0l6yzaELu6BGgZPZz/z/8QOhNQudnh+/vS8TEJTslVxrmuNwOhu8xuPmsvPYYVAYc xONPYshVh+s1iM7eFy6aEXpk+nFosYl6wpdyudlEaqlslU+bVJsEsI9IZGO2/xQKfNPk dVOglwj9Muz6ORdE2/wGCjqi3qWH4hTbW/dnUQZxVL9ey8fPXzqytQK9tLAmrzb/FdhC QzhGlfDl7aPR8mbSpkg/wscq4zkuEEwyT24M1KKFJ/KT4uwTgDNwqUq7t/T0q8TPsg/e c6NKYbcGc6lrPz4sn914vvfCDGG07xlvWVvpYJ1pOxi/idrS9R3rvlXNCIlCCWOAMQEr +X7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=he2kT439; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-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. [23.128.96.18]) by mx.google.com with ESMTP id df20si451688edb.555.2021.10.05.20.54.17; Tue, 05 Oct 2021 20:54:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=he2kT439; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-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 S230363AbhJFD4G (ORCPT + 3 others); Tue, 5 Oct 2021 23:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231985AbhJFD4F (ORCPT ); Tue, 5 Oct 2021 23:56:05 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7FB3C06174E for ; Tue, 5 Oct 2021 20:54:13 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id x27so4495659lfa.9 for ; Tue, 05 Oct 2021 20:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0QbCWpC0YUHd4oM8ALhGkUXV2GRwREBEvhvGaNVxQyo=; b=he2kT439AhNtxiuqDLrNaZpNYt38+4H16zAkk/pYeKvytO6jQI9YrfDulq+/ku2ae6 QcjskLIWgJBzMoIQi0R91D2cctBB27lEMBdcuYBNl1HRLoyuq5WQRO/M8fZI0e/eaEWd sINOv6L6kKh0sh5q3Gj4F1V2jcH1vNu7KSKbOJFm7UG2hdj6vvWkvE73ie0jGA+nIM0Y t6Z1V4bddNVkkWhw8u7pOiI2jhSPajejhaCgdcxmdmpZkHfz35vCMKx36LYu5awMpEY2 nVj9Hb4/4m9nCEHG9DRzBH3FEma/IlB2fgdRMh3xMWOJE1+ti3mLeKUTppV80/OiPgZ5 eS1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0QbCWpC0YUHd4oM8ALhGkUXV2GRwREBEvhvGaNVxQyo=; b=iOEMsX7NBqEQeZiTKzyHz6xfnM0jk9jZn0MolGt10FJqmula4PDzTCDRGwlPbED2Vi K9W9qtEpyviw9Pcoaebh8UougCDDpB2XVQ7MqQvQG6N9lNdUnEbUTBLf0RxKGQHnOWDG HLyTHcTXn/s0M2/XY75c+cE1oC/4HZ550GifOyzOJ6f8qV1q8oJSSONYpd4FR2mFl2zt UVtZ8SgTz0wNuTK2mO3NQ4DRdPFEvXK/c6w/PXQpzOd8KqdACokY/ujaOgwChpjxe39+ pyuS+Eb1fzTajWVjqysiG8+THm0N8+XB3wNgAWznPdoak0rUytF7ZFBei9FKoxhZvE+h qygg== X-Gm-Message-State: AOAM531Os9qXpbssvlcvJWs7Q9tQqKX5EdNNgsceXu5hHaZSF7fW6BMp GNMBsYtQruLKE76SmwIHtxKy0A== X-Received: by 2002:a2e:550:: with SMTP id 77mr27560874ljf.478.1633492452244; Tue, 05 Oct 2021 20:54:12 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id s4sm2142967lfd.103.2021.10.05.20.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 20:54:11 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , Ulf Hansson , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Kalle Valo , "David S. Miller" , Jakub Kicinski , Stanimir Varbanov Cc: linux-arm-msm@vger.kernel.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v1 01/15] dt-bindings: add pwrseq device tree bindings Date: Wed, 6 Oct 2021 06:53:53 +0300 Message-Id: <20211006035407.1147909-2-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006035407.1147909-1-dmitry.baryshkov@linaro.org> References: <20211006035407.1147909-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Add device tree bindings for the new power sequencer subsystem. Consumers would reference pwrseq nodes using "foo-pwrseq" properties. Providers would use '#pwrseq-cells' property to declare the amount of cells in the pwrseq specifier. Signed-off-by: Dmitry Baryshkov --- .../bindings/power/pwrseq/pwrseq.yaml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/pwrseq/pwrseq.yaml -- 2.33.0 diff --git a/Documentation/devicetree/bindings/power/pwrseq/pwrseq.yaml b/Documentation/devicetree/bindings/power/pwrseq/pwrseq.yaml new file mode 100644 index 000000000000..4a8f6c0218bf --- /dev/null +++ b/Documentation/devicetree/bindings/power/pwrseq/pwrseq.yaml @@ -0,0 +1,32 @@ +# SPDX-License-Identifier: GPL-2.0 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/pwrseq/pwrseq.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Power Sequencer devices + +maintainers: + - Dmitry Baryshkov + +properties: + "#powerseq-cells": + description: + Number of cells in a pwrseq specifier. + +patternProperties: + ".*-pwrseq$": + description: Power sequencer supply phandle(s) for this node + +additionalProperties: true + +examples: + - | + qca_pwrseq: qca-pwrseq { + #pwrseq-cells = <1>; + }; + + bluetooth { + bt-pwrseq = <&qca_pwrseq 1>; + }; +... From patchwork Wed Oct 6 03:53:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 515272 Delivered-To: patch@linaro.org Received: by 2002:ac0:890a:0:0:0:0:0 with SMTP id 10csp154966imy; Tue, 5 Oct 2021 20:54:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiaiFcHGqi51J4jn97xJsqoaYtlCBSsTySHuzQVLEB8CC/lvXinSz27iz33molLpuUvn4G X-Received: by 2002:a17:906:7ac5:: with SMTP id k5mr29442233ejo.386.1633492461149; Tue, 05 Oct 2021 20:54:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633492461; cv=none; d=google.com; s=arc-20160816; b=svpFALVN9IMLyJEU9dZbzcVldGNMuDC8xjjovVYRDTmPke36KC5Ah8DbE8Y+OaQlPD UUocZ9pJ6C5fL2zm5lG70veNBV1g5nA9J2tdWfy+wyS03s0DtGOLfKS4F83Kpd4JmyTe 6TSLvvwp1iAVMWG5Rss4NU8j4c0gaI1cNaogC81IilPinbpPKfj+Nv7ecjonQYopmouo /YkgYAWfLDgly8MMvyC/wtd2mhgXS/t58QPZIe7nbAk5pZ9gxPo+xLUZRXRIrFUvsrmV OKGPdq9LgeqiexliE42xx83mdZDkSpHaIgq7PUdu9fYYF0GdrE5clp2wqGMvN4XGFg4S yjzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=00n7CaYRtB/oPVPJyhNLQU99dusIfQvK/8kpoba23hk=; b=Uq7LmzSNmdvsqgvXtbbN8NdYZBtqggDh0REZskTEuHZJLvY1VzQaxVjSaIhjJh4FYf 6CSz1ltfey5Bqsypz70KNS11T4IQ90G4Su2f2LXrrXLZzG5jmbFC8a8ZDhosM7DN027R KPcu1a2XHxvXXz1gzEtnDd+0lAINZYk1F1Ua6FhLpO0DogUfxQ+7btz1wQDS/Vc/ySMC /Xt4uViKMnDUhZIDIeVhAEL4imlDJLhPX3Pa8kU9W8Em3LbrNwjwOpMEThNwB0G4JGWk YPHM+fTlXd16sO8DEu28ac6RqrDtiKtKc1vUWvIfYioe3CgMqjo0mptmbC2E6mNZ3fLV 39/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zX40LljG; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-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. [23.128.96.18]) by mx.google.com with ESMTP id eb13si4889864edb.395.2021.10.05.20.54.20; Tue, 05 Oct 2021 20:54:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zX40LljG; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-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 S237335AbhJFD4J (ORCPT + 3 others); Tue, 5 Oct 2021 23:56:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237278AbhJFD4G (ORCPT ); Tue, 5 Oct 2021 23:56:06 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E50C061753 for ; Tue, 5 Oct 2021 20:54:14 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id m3so4627822lfu.2 for ; Tue, 05 Oct 2021 20:54:14 -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 :mime-version:content-transfer-encoding; bh=00n7CaYRtB/oPVPJyhNLQU99dusIfQvK/8kpoba23hk=; b=zX40LljGN0ujw8Ut02so9lFStCBV0UifqUNXL0ScIn+t056lOtA+NXl2HUma6WEbyT iHzvQr0fA86NTJ4WX5zvV5ZnwjUSwpP/AwO/AwfBrPb1A8whPKrmDYhypIwS4dCm5FoD bmfAAvbSh4JeEKf64NBq1URR/KeBWwDXLtCFaQynpl06NivcC6ju2RPI7kY1Ob5KKcVz bXnsCjZCPmcAj2ljhIDXY54cOk34otVfOdrOChtE0ZWY/q5NJ/7iIwEdU9+ZHTzTOkmu qwOnrOaBCTqAqiCzzhD7u6T0KPw3Q0+yWQ4cJRx0JymQl+BaZAaA7vUcHz3TvNhFsiX3 uNMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=00n7CaYRtB/oPVPJyhNLQU99dusIfQvK/8kpoba23hk=; b=mMR7UcpeeTKuH2aWyzSbsU5ybngLzvUznXeCtySYioBSlV5LE8QnQRBGSLA2Y5mqn/ T9RP2ZMrzcTWTreMLGSjXm3+dkexr5Ksh8zcPOp1hzaSM6SnAMp9TV58efdNWCIWR9uQ BHzDW5GUQJJQJ9bg0cUjm3iHBs3ZdU9Fe0AzPqj06tpKp1gzg1RPaugj489KQX7QGB/1 lDCXIixFuUUFE7UI6pZub6qugC0wn3KcV7B3K+vSSkTybRIXNoQEKShAH6h7sdfbwd7Z t0gkHyUsyY2WKWFta1uNCgRwPS2CIYi5IxsLbzHF9FecE3M9GzwBTLwebCemsgcSKtY8 HEAQ== X-Gm-Message-State: AOAM531R4w7fWyb3z9rOkitw4Iu+DGr31YpUdbCJqgaTZ2b0wfKxnHcx Afxd2MLhZ1PqNOHpugorc6+F7w== X-Received: by 2002:a05:6512:2614:: with SMTP id bt20mr7043195lfb.506.1633492453152; Tue, 05 Oct 2021 20:54:13 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id s4sm2142967lfd.103.2021.10.05.20.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 20:54:12 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , Ulf Hansson , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Kalle Valo , "David S. Miller" , Jakub Kicinski , Stanimir Varbanov Cc: linux-arm-msm@vger.kernel.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v1 02/15] power: add power sequencer subsystem Date: Wed, 6 Oct 2021 06:53:54 +0300 Message-Id: <20211006035407.1147909-3-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006035407.1147909-1-dmitry.baryshkov@linaro.org> References: <20211006035407.1147909-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Basing on MMC's pwrseq support code, add separate power sequencer subsystem. It will be used by other drivers to handle device power up requirements. Signed-off-by: Dmitry Baryshkov --- Documentation/driver-api/index.rst | 1 + Documentation/driver-api/pwrseq.rst | 77 +++++ drivers/power/Kconfig | 1 + drivers/power/Makefile | 1 + drivers/power/pwrseq/Kconfig | 14 + drivers/power/pwrseq/Makefile | 6 + drivers/power/pwrseq/core.c | 448 ++++++++++++++++++++++++++++ include/linux/pwrseq/consumer.h | 82 +++++ include/linux/pwrseq/driver.h | 160 ++++++++++ 9 files changed, 790 insertions(+) create mode 100644 Documentation/driver-api/pwrseq.rst create mode 100644 drivers/power/pwrseq/Kconfig create mode 100644 drivers/power/pwrseq/Makefile create mode 100644 drivers/power/pwrseq/core.c create mode 100644 include/linux/pwrseq/consumer.h create mode 100644 include/linux/pwrseq/driver.h -- 2.33.0 diff --git a/Documentation/driver-api/index.rst b/Documentation/driver-api/index.rst index c57c609ad2eb..15f51c08db1f 100644 --- a/Documentation/driver-api/index.rst +++ b/Documentation/driver-api/index.rst @@ -94,6 +94,7 @@ available subsections can be seen below. ptp phy/index pwm + pwrseq pldmfw/index rfkill serial/index diff --git a/Documentation/driver-api/pwrseq.rst b/Documentation/driver-api/pwrseq.rst new file mode 100644 index 000000000000..df7cfce0f792 --- /dev/null +++ b/Documentation/driver-api/pwrseq.rst @@ -0,0 +1,77 @@ +.. Copyright 2021 Linaro Ltd. + +.. This documentation is free software; you can redistribute +.. it and/or modify it under the terms of the GNU General Public +.. License version 2 as published by the Free Software Foundation. + +==================== +Power Sequencing API +==================== + +:Author: Dmitry Baryshkov +:Author: Ulf Hansson (original MMC pwrseq) + +Introduction +============ + +This framework is designed to provide a standard kernel interface to +handle power sequencing requirements for different devices. + +The intention is to provide a generic way to handle power sequencing of complex +devices sitting on a variety of busses. First implementation comes from MMC +SDIO/eMMC code, not generified to support other kinds of devices. + +Glossary +-------- + +The pwrseq API uses a number of terms which may not be familiar: + +Power sequencer + + Electronic device (or part of it) that supplies power to other devices. + Unlike regulators (which typically handle single voltage), power sequencer + handles several voltage inputs. Also it does not provide an exact voltage + output. Instead it makes sure that the consumers (see below) are powered on + when required. + +Consumer + + Electronic device which consumes power provided by a power sequencer. + +Consumer driver interface +========================= + +This offers a similar API to the kernel clock or regulator framework. Consumer +drivers use `get <#API-pwrseq-get>`__ and +`put <#API-pwrseq-put>`__ operations to acquire and release +power sequencers. Functions are provided to `power on +<#API-pwrseq-full-power-on>`__ and `power off <#API-pwrseq-power-off>`__ the +power sequencer. + +A stub version of this API is provided when the power sequencer framework is +not in use in order to minimise the need to use ifdefs. + +Power sequencer driver interface +================================ + +Drivers for power sequencers register the sequencer within the pwrseq +core, providing operations structures to the core. + +API reference +============= + +Due to limitations of the kernel documentation framework and the +existing layout of the source code the entire regulator API is +documented here. + +.. kernel-doc:: include/linux/pwrseq/consumer.h + :internal: + +.. kernel-doc:: include/linux/pwrseq/driver.h + :internal: + +.. kernel-doc:: include/linux/pwrseq/fallback.h + :internal: + +.. kernel-doc:: drivers/power/pwrseq/core.c + :export: diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 696bf77a7042..c87cd2240a74 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only +source "drivers/power/pwrseq/Kconfig" source "drivers/power/reset/Kconfig" source "drivers/power/supply/Kconfig" diff --git a/drivers/power/Makefile b/drivers/power/Makefile index effbf0377f32..1dbce454a8c4 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_POWER_RESET) += reset/ obj-$(CONFIG_POWER_SUPPLY) += supply/ +obj-$(CONFIG_PWRSEQ) += pwrseq/ diff --git a/drivers/power/pwrseq/Kconfig b/drivers/power/pwrseq/Kconfig new file mode 100644 index 000000000000..dab8f4d860fe --- /dev/null +++ b/drivers/power/pwrseq/Kconfig @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +menuconfig PWRSEQ + bool "Power Sequencer drivers" + help + Provides support for special power sequencing drivers. Power + sequencer is an entity providing abstraced power on/power off/reset + operations for the connected devices. Possible usages include MMC + SDIO devices, some complex WiFi/BT chips, controlled USB hubs, etc. + + Say Y here to enable support for such devices. + +if PWRSEQ + +endif diff --git a/drivers/power/pwrseq/Makefile b/drivers/power/pwrseq/Makefile new file mode 100644 index 000000000000..108429ff6445 --- /dev/null +++ b/drivers/power/pwrseq/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for power sequencer drivers. +# + +obj-$(CONFIG_PWRSEQ) += core.o diff --git a/drivers/power/pwrseq/core.c b/drivers/power/pwrseq/core.c new file mode 100644 index 000000000000..d29b4b97b95c --- /dev/null +++ b/drivers/power/pwrseq/core.c @@ -0,0 +1,448 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021 (c) Linaro Ltd. + * Author: Dmitry Baryshkov + * + * Based on phy-core.c: + * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define to_pwrseq(a) (container_of((a), struct pwrseq, dev)) + +static DEFINE_IDA(pwrseq_ida); +static DEFINE_MUTEX(pwrseq_provider_mutex); +static LIST_HEAD(pwrseq_provider_list); + +/** + * struct pwrseq_provider - a + */ +struct pwrseq_provider { + struct device *dev; + struct module *owner; + struct list_head list; + void *data; + struct pwrseq * (*of_xlate)(void *data, struct of_phandle_args *args); +}; + +/** + * pwrseq_put() - release the pwrseq + * @pwrseq: the pwrseq returned by pwrseq_get() + * + * Releases a refcount on the pwrseq instance received from pwrseq_get(). + */ +void pwrseq_put(struct pwrseq *pwrseq) +{ + module_put(pwrseq->owner); + put_device(&pwrseq->dev); +} +EXPORT_SYMBOL_GPL(pwrseq_put); + +static struct pwrseq_provider *of_pwrseq_provider_lookup(struct device_node *node) +{ + struct pwrseq_provider *pwrseq_provider; + + list_for_each_entry(pwrseq_provider, &pwrseq_provider_list, list) { + if (pwrseq_provider->dev->of_node == node) + return pwrseq_provider; + } + + return ERR_PTR(-EPROBE_DEFER); +} + +static struct pwrseq *_of_pwrseq_get(struct device *dev, const char *id) +{ + struct pwrseq_provider *pwrseq_provider; + struct pwrseq *pwrseq; + struct of_phandle_args args; + char prop_name[64]; /* 64 is max size of property name */ + int ret; + + snprintf(prop_name, sizeof(prop_name), "%s-pwrseq", id); + ret = of_parse_phandle_with_args(dev->of_node, prop_name, "#pwrseq-cells", 0, &args); + if (ret == -ENOENT) + return NULL; + else if (ret < 0) + return ERR_PTR(ret); + + mutex_lock(&pwrseq_provider_mutex); + pwrseq_provider = of_pwrseq_provider_lookup(args.np); + if (IS_ERR(pwrseq_provider) || !try_module_get(pwrseq_provider->owner)) { + pwrseq = ERR_PTR(-EPROBE_DEFER); + goto out_unlock; + } + + if (!of_device_is_available(args.np)) { + dev_warn(pwrseq_provider->dev, "Requested pwrseq is disabled\n"); + pwrseq = ERR_PTR(-ENODEV); + goto out_put_module; + } + + pwrseq = pwrseq_provider->of_xlate(pwrseq_provider->data, &args); + +out_put_module: + module_put(pwrseq_provider->owner); + +out_unlock: + mutex_unlock(&pwrseq_provider_mutex); + of_node_put(args.np); + + return pwrseq; +} + +/** + * pwrseq_get() - lookup and obtain a reference to a pwrseq + * @dev: device for which to get the pwrseq + * @id: name of the pwrseq from device's point of view + * + * Returns the pwrseq instance, after getting a refcount to it; or + * NULL if there is no such pwrseq. The caller is responsible for + * calling pwrseq_put() to release that count. + */ +struct pwrseq * pwrseq_get(struct device *dev, const char *id) +{ + struct pwrseq *pwrseq; + + pwrseq = _of_pwrseq_get(dev, id); + if (IS_ERR_OR_NULL(pwrseq)) + return pwrseq; + + if (!try_module_get(pwrseq->owner)) + return ERR_PTR(-EPROBE_DEFER); + + get_device(&pwrseq->dev); + + return pwrseq; +} +EXPORT_SYMBOL_GPL(pwrseq_get); + +static void devm_pwrseq_release(struct device *dev, void *res) +{ + struct pwrseq *pwrseq = *(struct pwrseq **)res; + + pwrseq_put(pwrseq); +} + +/** + * devm_pwrseq_get() - lookup and obtain a reference to a pwrseq + * @dev: device for which to get the pwrseq + * @id: name of the pwrseq from device's point of view + * + * Devres-managed variant of pwrseq_get(). + * Returns the pwrseq instance, after getting a refcount to it; or + * NULL if there is no such pwrseq. Gets the pwrseq using pwrseq_get(), and + * associates it with the a device using devres. On driver detach, returned + * pwrseq is automatically put using pwrseq_put(), removing the need to call it + * manually. + */ +struct pwrseq * devm_pwrseq_get(struct device *dev, const char *id) +{ + struct pwrseq **ptr, *pwrseq; + + ptr = devres_alloc(devm_pwrseq_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + pwrseq = pwrseq_get(dev, id); + if (!IS_ERR_OR_NULL(pwrseq)) { + *ptr = pwrseq; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return pwrseq; +} +EXPORT_SYMBOL_GPL(devm_pwrseq_get); + +/** + * pwrseq_pre_power_on() - perform pre-power on actions + * @pwrseq: pwrseq instance + * + * Perform pre-powering on actions, like pulling reset pin. This function + * should be called before device is being powered on. Typical usage would + * include MMC cards, where pwrseq subsystem is combined with the MMC power + * controls. + * In most cases there is no need to call it directly, use + * @pwrseq_full_power_on() instead. + */ +int pwrseq_pre_power_on(struct pwrseq *pwrseq) +{ + if (pwrseq && pwrseq->ops->pre_power_on) + return pwrseq->ops->pre_power_on(pwrseq); + + return 0; +} +EXPORT_SYMBOL_GPL(pwrseq_pre_power_on); + +/** + * pwrseq_power_on() - power on the device + * @pwrseq: pwrseq instance + * + * Power on the device and perform post-power on actions, like pulling reset + * or enable pin. In most cases there is no need to call it directly, use + * @pwrseq_full_power_on() instead. + */ +int pwrseq_power_on(struct pwrseq *pwrseq) +{ + if (pwrseq && pwrseq->ops->power_on) + return pwrseq->ops->power_on(pwrseq); + + return 0; +} +EXPORT_SYMBOL_GPL(pwrseq_power_on); + +/** + * pwrseq_power_off() - power off the device + * @pwrseq: pwrseq instance + * + * Power off the device clearly. + */ +void pwrseq_power_off(struct pwrseq *pwrseq) +{ + if (pwrseq && pwrseq->ops->power_off) + pwrseq->ops->power_off(pwrseq); +} +EXPORT_SYMBOL_GPL(pwrseq_power_off); + +/** + * pwrseq_reset() - reset powered device + * @pwrseq: pwrseq instance + * + * Reset the device controlled by the power sequencer. + */ +void pwrseq_reset(struct pwrseq *pwrseq) +{ + if (pwrseq && pwrseq->ops->reset) + pwrseq->ops->reset(pwrseq); +} +EXPORT_SYMBOL_GPL(pwrseq_reset); + +static void pwrseq_dev_release(struct device *dev) +{ + struct pwrseq *pwrseq = to_pwrseq(dev); + + ida_free(&pwrseq_ida, pwrseq->id); + of_node_put(dev->of_node); + kfree(pwrseq); +} + +static struct class pwrseq_class = { + .name = "pwrseq", + .dev_release = pwrseq_dev_release, +}; + +/** + * __pwrseq_create() - internal helper for pwrseq_create + * @dev: parent device + * @owner: the module providing callbacks. + * @ops: pwrseq device callbacks + * + * This is an internal helper for pwrseq_create which should not be called + * directly. + * + * Return: created instance or the wrapped error code. + */ +struct pwrseq *__pwrseq_create(struct device *dev, struct module *owner, const struct pwrseq_ops *ops) +{ + struct pwrseq *pwrseq; + int ret; + + if (WARN_ON(!dev)) + return ERR_PTR(-EINVAL); + + pwrseq = kzalloc(sizeof(*pwrseq), GFP_KERNEL); + if (!pwrseq) + return ERR_PTR(-ENOMEM); + + ret = ida_alloc(&pwrseq_ida, GFP_KERNEL); + if (ret < 0) + goto free_pwrseq; + + pwrseq->id = ret; + + device_initialize(&pwrseq->dev); + + pwrseq->dev.class = &pwrseq_class; + pwrseq->dev.parent = dev; + pwrseq->dev.of_node = of_node_get(dev->of_node); + pwrseq->ops = ops; + pwrseq->owner = owner; + + ret = dev_set_name(&pwrseq->dev, "pwrseq-%s.%u", dev_name(dev), pwrseq->id); + if (ret) + goto put_dev; + + ret = device_add(&pwrseq->dev); + if (ret) + goto put_dev; + + return pwrseq; + +put_dev: + /* will call pwrseq_dev_release() to free resources */ + put_device(&pwrseq->dev); + + return ERR_PTR(ret); + +free_pwrseq: + kfree(pwrseq); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(__pwrseq_create); + +void pwrseq_destroy(struct pwrseq *pwrseq) +{ + device_unregister(&pwrseq->dev); +} +EXPORT_SYMBOL_GPL(pwrseq_destroy); + +static void devm_pwrseq_destroy(struct device *dev, void *res) +{ + struct pwrseq *pwrseq = *(struct pwrseq **)res; + + pwrseq_destroy(pwrseq); +} + +/** + * __devm_pwrseq_create() - devres-managed version of __pwrseq_create + * @dev: parent device + * @owner: the module providing callbacks. + * @ops: pwrseq device callbacks + * + * This is the devres-managed version of __pwrseq_create(). It is an internal + * helper which should not be called directly. + * + * Return: created instance or the wrapped error code. + */ +struct pwrseq *__devm_pwrseq_create(struct device *dev, struct module *owner, const struct pwrseq_ops *ops) +{ + struct pwrseq **ptr, *pwrseq; + + ptr = devres_alloc(devm_pwrseq_destroy, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + pwrseq = __pwrseq_create(dev, owner, ops); + if (!IS_ERR(pwrseq)) { + *ptr = pwrseq; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return pwrseq; +} +EXPORT_SYMBOL_GPL(__devm_pwrseq_create); + +/** + * __of_pwrseq_provider_register - internal version of of_pwrseq_provider_register + * @dev: handling device + * @owner: the module providing callbacks. + * @xlate: xlate function returning pwrseq instance corresponding to OF args + * @data: provider-specific data to be passed to xlate function + * + * This is an internal helper of of_pwrseq_provider_register, it should not be + * called directly. + */ +struct pwrseq_provider *__of_pwrseq_provider_register(struct device *dev, + struct module *owner, + struct pwrseq * (*of_xlate)(void *data, + struct of_phandle_args *args), + void *data) +{ + struct pwrseq_provider *pwrseq_provider; + + pwrseq_provider = kzalloc(sizeof(*pwrseq_provider), GFP_KERNEL); + if (!pwrseq_provider) + return ERR_PTR(-ENOMEM); + + if (!fwnode_property_present(dev->fwnode, "#pwrseq-cells")) + dev_warn(dev, "no #pwrseq-cells property found, please add the property to the provider\n"); + + pwrseq_provider->dev = dev; + pwrseq_provider->owner = owner; + pwrseq_provider->of_xlate = of_xlate; + pwrseq_provider->data = data; + + mutex_lock(&pwrseq_provider_mutex); + list_add_tail(&pwrseq_provider->list, &pwrseq_provider_list); + mutex_unlock(&pwrseq_provider_mutex); + + return pwrseq_provider; +} +EXPORT_SYMBOL_GPL(__of_pwrseq_provider_register); + +/** + * of_pwrseq_provider_unregister() - unregister pwrseq provider + * @pwrseq_provider: pwrseq provider to unregister + * + * Unregister pwrseq provider previously registered by of_pwrseq_provider_register(). + */ +void of_pwrseq_provider_unregister(struct pwrseq_provider *pwrseq_provider) +{ + if (IS_ERR(pwrseq_provider)) + return; + + mutex_lock(&pwrseq_provider_mutex); + list_del(&pwrseq_provider->list); + kfree(pwrseq_provider); + mutex_unlock(&pwrseq_provider_mutex); +} +EXPORT_SYMBOL_GPL(of_pwrseq_provider_unregister); + +static void devm_pwrseq_provider_unregister(struct device *dev, void *res) +{ + struct pwrseq_provider *pwrseq_provider = *(struct pwrseq_provider **)res; + + of_pwrseq_provider_unregister(pwrseq_provider); +} + +/** + * __devm_of_pwrseq_provider_register - internal version of devm_of_pwrseq_provider_register + * @dev: handling device + * @owner: the module providing callbacks. + * @xlate: xlate function returning pwrseq instance corresponding to OF args + * @data: provider-specific data to be passed to xlate function + * + * This is an internal helper of devm_of_pwrseq_provider_register, it should + * not be called directly. + */ +struct pwrseq_provider *__devm_of_pwrseq_provider_register(struct device *dev, + struct module *owner, + struct pwrseq * (*of_xlate)(void *data, + struct of_phandle_args *args), + void *data) +{ + struct pwrseq_provider **ptr, *pwrseq_provider; + + ptr = devres_alloc(devm_pwrseq_provider_unregister, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + pwrseq_provider = __of_pwrseq_provider_register(dev, owner, of_xlate, data); + if (!IS_ERR(pwrseq_provider)) { + *ptr = pwrseq_provider; + devres_add(dev, ptr); + } else { + devres_free(ptr); + } + + return pwrseq_provider; +} +EXPORT_SYMBOL_GPL(__devm_of_pwrseq_provider_register); + +static int __init pwrseq_core_init(void) +{ + return class_register(&pwrseq_class); +} +device_initcall(pwrseq_core_init); diff --git a/include/linux/pwrseq/consumer.h b/include/linux/pwrseq/consumer.h new file mode 100644 index 000000000000..7c8efefd3184 --- /dev/null +++ b/include/linux/pwrseq/consumer.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Linaro Ltd. + */ + +#ifndef __LINUX_PWRSEQ_CONSUMER_H__ +#define __LINUX_PWRSEQ_CONSUMER_H__ + +struct pwrseq; +struct device; + +#if defined(CONFIG_PWRSEQ) + +struct pwrseq *__must_check pwrseq_get(struct device *dev, const char *id); +struct pwrseq *__must_check devm_pwrseq_get(struct device *dev, const char *id); + +void pwrseq_put(struct pwrseq *pwrseq); + +int pwrseq_pre_power_on(struct pwrseq *pwrseq); +int pwrseq_power_on(struct pwrseq *pwrseq); +void pwrseq_power_off(struct pwrseq *pwrseq); +void pwrseq_reset(struct pwrseq *pwrseq); + +#else + +static inline struct pwrseq *__must_check +pwrseq_get(struct device *dev, const char *id) +{ + return NULL; +} + +static inline struct pwrseq *__must_check +devm_pwrseq_get(struct device *dev, const char *id) +{ + return NULL; +} + +static inline void pwrseq_put(struct pwrseq *pwrseq) +{ +} + +static inline int pwrseq_pre_power_on(struct pwrseq *pwrseq) +{ + return -ENOSYS; +} + +static inline int pwrseq_power_on(struct pwrseq *pwrseq) +{ + return -ENOSYS; +} + +static inline void pwrseq_power_off(struct pwrseq *pwrseq) +{ +} + +static inline void pwrseq_reset(struct pwrseq *pwrseq) +{ +} + +#endif + +/** + * pwrseq_full_power_on() - Perform full power on of the sequencer + * @pwrseq: the power sequencer to power on + * + * Perform full power on of the sequencer, including pre power on and + * power on steps. + * + * Return: 0 upon no error; -error upon error. + */ +static inline int pwrseq_full_power_on(struct pwrseq *pwrseq) +{ + int ret; + + ret = pwrseq_pre_power_on(pwrseq); + if (ret) + return ret; + + return pwrseq_power_on(pwrseq); +} + +#endif /* __LINUX_PWRSEQ_CONSUMER_H__ */ diff --git a/include/linux/pwrseq/driver.h b/include/linux/pwrseq/driver.h new file mode 100644 index 000000000000..bdb8a25a8504 --- /dev/null +++ b/include/linux/pwrseq/driver.h @@ -0,0 +1,160 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2021 Linaro Ltd. + */ + +#ifndef __LINUX_PWRSEQ_DRIVER_H__ +#define __LINUX_PWRSEQ_DRIVER_H__ + +#include + +struct pwrseq; + +/** + * struct pwrseq_ops - power sequencer operations. + * + * @pre_power_on: Perform pre powering operations (like ensuring that the + * device will be held in the reset) + * @power_on: Power on the sequencer, making sure that the consumer + * devices can be operated + * @power_off: Power off the sequencer, removing power from the comsumer + * device (if possible) + * @reset: Reset the consumer device + */ +struct pwrseq_ops { + int (*pre_power_on)(struct pwrseq *pwrseq); + int (*power_on)(struct pwrseq *pwrseq); + void (*power_off)(struct pwrseq *pwrseq); + void (*reset)(struct pwrseq *pwrseq); +}; + +struct module; + +/** + * struct pwrseq - private pwrseq data + * + * Power sequencer device, one for each power sequencer. + * + * This should *not* be used directly by anything except the pwrseq core. + */ +struct pwrseq { + struct device dev; + const struct pwrseq_ops *ops; + unsigned int id; + struct module *owner; +}; + +struct pwrseq *__pwrseq_create(struct device *dev, struct module *owner, const struct pwrseq_ops *ops); +struct pwrseq *__devm_pwrseq_create(struct device *dev, struct module *owner, const struct pwrseq_ops *ops); + +/** + * pwrseq_create() - create pwrseq instance + * @dev: parent device + * @ops: pwrseq device callbacks + * + * Create new pwrseq instance parenting with @dev using provided @ops set of + * callbacks. Create instance should be destroyed using @pwrseq_destroy(). + * + * Return: created instance or the wrapped error code. + */ +#define pwrseq_create(dev, ops, data) __pwrseq_create((dev), THIS_MODULE, (ops)) + +/** + * devm_pwrseq_create() - devres-managed version of pwrseq_create + * @dev: parent device + * @ops: pwrseq device callbacks + * + * This is the devres-managed version of pwrseq_create(). It creates new + * pwrseq instance parenting with @dev using provided @ops set of + * callbacks. Returned object is destroyed automatically, one must not call + * pwrseq_destroy(). + * + * Return: created instance or the wrapped error code. + */ +#define devm_pwrseq_create(dev, ops, data) __devm_pwrseq_create((dev), THIS_MODULE, (ops)) + +void pwrseq_destroy(struct pwrseq *pwrseq); + +/** + * pwrseq_set_data() - get drv-specific data for the pwrseq + * @pwrseq: the pwrseq to get driver data for + * @data: the data to set + * + * Sets the driver-specific data for the provided powrseq instance. + */ +static inline void pwrseq_set_drvdata(struct pwrseq *pwrseq, void *data) +{ + dev_set_drvdata(&pwrseq->dev, data); +} + +/** + * pwrseq_get_data() - get drv-specific data for the pwrseq + * @pwrseq: the pwrseq to get driver data for + * + * Returns driver-specific data for the provided powrseq instance. + */ +static inline void *pwrseq_get_drvdata(struct pwrseq *pwrseq) +{ + return dev_get_drvdata(&pwrseq->dev); +} + +/** + * of_pwrseq_provider_register() - register OF pwrseq provider + * @dev: handling device + * @xlate: xlate function returning pwrseq instance corresponding to OF args + * @data: provider-specific data to be passed to xlate function + * + * This macros registers OF-specific pwrseq provider. Pwrseq core will call + * specified @xlate function to retrieve pwrseq instance corresponding to + * device tree arguments. Returned pwrseq provider should be unregistered using + * of_pwrseq_provider_unregister(). + */ +#define of_pwrseq_provider_register(dev, xlate, data) \ + __of_pwrseq_provider_register((dev), THIS_MODULE, (xlate), (data)) + +/** + * devm_of_pwrseq_provider_register() - devres-managed version of of_pwrseq_provider_register + * @dev: handling device + * @xlate: xlate function returning pwrseq instance corresponding to OF args + * @data: provider-specific data to be passed to xlate function + * + * This is a devres-managed version of of_pwrseq_provider_register(). + * This macros registers OF-specific pwrseq provider. Pwrseq core will call + * specified @xlate function to retrieve pwrseq instance corresponding to + * device tree arguments. Returned pwrseq provider is automatically + * unregistered, without the need to call of_pwrseq_provider_unregister(). + */ +#define devm_of_pwrseq_provider_register(dev, xlate, data) \ + __devm_of_pwrseq_provider_register((dev), THIS_MODULE, (xlate), (data)) + +struct of_phandle_args; + +struct pwrseq_provider *__of_pwrseq_provider_register(struct device *dev, + struct module *owner, + struct pwrseq * (*of_xlate)(void *data, + struct of_phandle_args *args), + void *data); +struct pwrseq_provider *__devm_of_pwrseq_provider_register(struct device *dev, + struct module *owner, + struct pwrseq * (*of_xlate)(void *data, + struct of_phandle_args *args), + void *data); +void of_pwrseq_provider_unregister(struct pwrseq_provider *pwrseq_provider); + +/** + * of_pwrseq_xlate_single() - returns the pwrseq instance from pwrseq provider + * @data: the pwrseq provider data + * @args: of_phandle_args (not used here) + * + * Intended to be used by pwrseq provider for the common case where + * #pwrseq-cells is 0. For other cases where #pwrseq-cells is greater than '0', + * the pwrseq provider should provide a custom of_xlate function that reads the + * *args* and returns the appropriate pwrseq. + */ +static inline struct pwrseq *of_pwrseq_xlate_single(void *data, + struct of_phandle_args *args) +{ + return data; +} + +#endif /* __LINUX_PWRSEQ_DRIVER_H__ */ From patchwork Wed Oct 6 03:53:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 515280 Delivered-To: patch@linaro.org Received: by 2002:ac0:890a:0:0:0:0:0 with SMTP id 10csp155379imy; Tue, 5 Oct 2021 20:55:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRu1e7jhReoeY71XePqYrraFP4wNhQBlSUgRHJlegoIgbwkwh6uHhTcG2lT0A9k9yHRGSj X-Received: by 2002:a17:906:1706:: with SMTP id c6mr30575765eje.343.1633492519828; Tue, 05 Oct 2021 20:55:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633492519; cv=none; d=google.com; s=arc-20160816; b=EMG4hD0lDpj/hSrgKgS7+ekUCjAp8mV87MRZ4BMcJNz9/E1fHYZVPdEzpLOfxSVIw0 dn8029aszIzWc5wtrQDSvltM2urIhkDLVHACGWsoZbAHZdPK9s2vD9jt0hylaiegKWCf kpQTnHks8J+HCsi+EU/1Xln3tn9HVjnCSqHUF1Qdy7a4K8p66fUxxjCfq0l7JIcTu6Y/ ru0BKRa6PM+AW5xrWwmjm6JsPnRycfWcrmSo625KYa/0o+6Cka9oa2wmXmQzIk0+An5R b/48afILJJpnN9ENyul9Nga33OH6XTQ1M5Jgi30XjN9veppY+7SPKwzFaDP4Ms7N6QBC DJ7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rbD+BS0NcNaczpvYu66j0XoKIa1SV+z+K/gWdXPxBUk=; b=AfWWDP5vILfcIhYt8nLNRi8+SD0sx5Ovbnb16QtcfD6csDE4YreYiL1gDuh2UQr1/Z YaoRkoHyLXqD3lijhd4MumgQMKd2fHliHpz9gccCIWTODrwtP7idBgmuqyXIiYrno4TF lIhs/fegI4CU21h1JbjK6dd0HMeqWontQdTY1BjgUeWdS4EeRNCcsfCA/jJnL2k2nkWB GalT1PIPT+RtY4rjDWmd+dSkHHVONH42VHFfctfyIxvW4N2yU9K83INPr0nsBub5lQBn YSNMhS/BK+jHqIoIIsQ4QpltgmJY4BzlGLP//AxgTIrCZLwIH6kSHSxd/A7PqAA6Q/3E 7hVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KykwizkL; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-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. [23.128.96.18]) by mx.google.com with ESMTP id h15si22884315ejj.98.2021.10.05.20.55.19; Tue, 05 Oct 2021 20:55:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KykwizkL; spf=pass (google.com: domain of linux-mmc-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-mmc-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 S237817AbhJFD5H (ORCPT + 3 others); Tue, 5 Oct 2021 23:57:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237300AbhJFD4H (ORCPT ); Tue, 5 Oct 2021 23:56:07 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6833C061768 for ; Tue, 5 Oct 2021 20:54:15 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id r19so4458775lfe.10 for ; Tue, 05 Oct 2021 20:54:15 -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 :mime-version:content-transfer-encoding; bh=rbD+BS0NcNaczpvYu66j0XoKIa1SV+z+K/gWdXPxBUk=; b=KykwizkLmvDe9V3ztSXHrMUbEtG+5O9apjwceX15mSAxfOGddjZBn9DvzqFQm8al+v EAnxZ4OCvL47ljwDebZl06eRDP+igYzAFrsJJ+opFdIsw1yb/jto3oBjuKWhwchmzFZk mzy0kAh+LD6tz+hN8sGOY125bt6SsnhGXQMAcV3SbFx/KPE+6HAg9GcKn4rXy+OHW9a9 EJqd/8q7d+PsNvrrx65/+T9ur6agPadWkmCQTbQ3U/B/stGNNXhj/8ogUfAi8CGTLy7Q Pzj9M/b0zsb5GzGml+qQ1rPPUbEVQyDD+9ZVBLd8fsMeGmeWr/I8emBgFrsG/NavD70P tDlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rbD+BS0NcNaczpvYu66j0XoKIa1SV+z+K/gWdXPxBUk=; b=NDTdw8Ma7SzDLxiECFWREpofw+238z6wz98Yy1XWtL28ZqHONqkGlg1t+npvkC7qMx 2ncwnOivh/JN1QqiKs3/wGQw6s5HIGFLgVUVg8xouy0RI5r1/Qnyz4moQC3Xpc1ju0KX 1g9KDiuTocAZ1Xbztiupk5snlbTPPfWZVpKqM5El8KYOypg8pcpCry4JVAONdlj5vzX/ Dv95Y6F0+uW74/eyCpjfhc2orY3ntGDGN1WcWfLYccuNiNUSAlGm9AUVkpmdNxPpJmdE 8beQVlgpuMw7F62Ucqjcx27eTvBliZXMZwDfpRy+4BYw9r8Wdh792TrCVDXERXndMNOU 1RaQ== X-Gm-Message-State: AOAM531dzh+F2ZslRsBGGyvb7gt+SUGFC81jFTPrIPGIy71GlbAMOwGd 7nHdL6QGgRHBiK+9Vb2zZ51SuQ== X-Received: by 2002:a05:6512:ea2:: with SMTP id bi34mr6935938lfb.638.1633492453860; Tue, 05 Oct 2021 20:54:13 -0700 (PDT) Received: from eriador.lan ([37.153.55.125]) by smtp.gmail.com with ESMTPSA id s4sm2142967lfd.103.2021.10.05.20.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 20:54:13 -0700 (PDT) From: Dmitry Baryshkov To: Andy Gross , Bjorn Andersson , Ulf Hansson , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Kalle Valo , "David S. Miller" , Jakub Kicinski , Stanimir Varbanov Cc: linux-arm-msm@vger.kernel.org, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v1 03/15] pwrseq: port MMC's pwrseq drivers to new pwrseq subsystem Date: Wed, 6 Oct 2021 06:53:55 +0300 Message-Id: <20211006035407.1147909-4-dmitry.baryshkov@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211006035407.1147909-1-dmitry.baryshkov@linaro.org> References: <20211006035407.1147909-1-dmitry.baryshkov@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Port MMC's all pwrseq drivers to new pwrseq subsystem. Signed-off-by: Dmitry Baryshkov --- .../pwrseq}/mmc-pwrseq-emmc.yaml | 6 +- .../pwrseq}/mmc-pwrseq-sd8787.yaml | 6 +- .../pwrseq}/mmc-pwrseq-simple.yaml | 6 +- drivers/mmc/core/Kconfig | 32 ---- drivers/mmc/core/Makefile | 3 - drivers/mmc/core/pwrseq_emmc.c | 120 ------------- drivers/mmc/core/pwrseq_sd8787.c | 117 ------------- drivers/mmc/core/pwrseq_simple.c | 164 ------------------ drivers/power/pwrseq/Kconfig | 32 ++++ drivers/power/pwrseq/Makefile | 4 + drivers/power/pwrseq/pwrseq_emmc.c | 121 +++++++++++++ drivers/power/pwrseq/pwrseq_sd8787.c | 108 ++++++++++++ drivers/power/pwrseq/pwrseq_simple.c | 162 +++++++++++++++++ include/linux/pwrseq/driver.h | 4 +- 14 files changed, 444 insertions(+), 441 deletions(-) rename Documentation/devicetree/bindings/{mmc => power/pwrseq}/mmc-pwrseq-emmc.yaml (91%) rename Documentation/devicetree/bindings/{mmc => power/pwrseq}/mmc-pwrseq-sd8787.yaml (86%) rename Documentation/devicetree/bindings/{mmc => power/pwrseq}/mmc-pwrseq-simple.yaml (92%) delete mode 100644 drivers/mmc/core/pwrseq_emmc.c delete mode 100644 drivers/mmc/core/pwrseq_sd8787.c delete mode 100644 drivers/mmc/core/pwrseq_simple.c create mode 100644 drivers/power/pwrseq/pwrseq_emmc.c create mode 100644 drivers/power/pwrseq/pwrseq_sd8787.c create mode 100644 drivers/power/pwrseq/pwrseq_simple.c -- 2.33.0 diff --git a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-emmc.yaml b/Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-emmc.yaml similarity index 91% rename from Documentation/devicetree/bindings/mmc/mmc-pwrseq-emmc.yaml rename to Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-emmc.yaml index 1fc7e620f328..a5e14e4a19b3 100644 --- a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-emmc.yaml +++ b/Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-emmc.yaml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 %YAML 1.2 --- -$id: http://devicetree.org/schemas/mmc/mmc-pwrseq-emmc.yaml# +$id: http://devicetree.org/schemas/power/pwrseq/mmc-pwrseq-emmc.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# title: Simple eMMC hardware reset provider binding @@ -32,6 +32,9 @@ properties: reset procedure as described in Jedec 4.4 specification, the gpio line should be defined as GPIO_ACTIVE_LOW. + "#pwrseq-cells": + const: 0 + required: - compatible - reset-gpios @@ -43,6 +46,7 @@ examples: #include sdhci0_pwrseq { compatible = "mmc-pwrseq-emmc"; + #pwrseq-cells = <0>; reset-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>; }; ... diff --git a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-sd8787.yaml b/Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-sd8787.yaml similarity index 86% rename from Documentation/devicetree/bindings/mmc/mmc-pwrseq-sd8787.yaml rename to Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-sd8787.yaml index 9e2396751030..7876be05573d 100644 --- a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-sd8787.yaml +++ b/Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-sd8787.yaml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 %YAML 1.2 --- -$id: http://devicetree.org/schemas/mmc/mmc-pwrseq-sd8787.yaml# +$id: http://devicetree.org/schemas/power/pwrseq/mmc-pwrseq-sd8787.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# title: Marvell SD8787 power sequence provider binding @@ -25,6 +25,9 @@ properties: description: contains a reset GPIO specifier with the default active state + "#pwrseq-cells": + const: 0 + required: - compatible - powerdown-gpios @@ -37,6 +40,7 @@ examples: #include wifi_pwrseq: wifi_pwrseq { compatible = "mmc-pwrseq-sd8787"; + #pwrseq-cells = <0>; powerdown-gpios = <&twl_gpio 0 GPIO_ACTIVE_LOW>; reset-gpios = <&twl_gpio 1 GPIO_ACTIVE_LOW>; }; diff --git a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.yaml b/Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-simple.yaml similarity index 92% rename from Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.yaml rename to Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-simple.yaml index 226fb191913d..3eff40fd347e 100644 --- a/Documentation/devicetree/bindings/mmc/mmc-pwrseq-simple.yaml +++ b/Documentation/devicetree/bindings/power/pwrseq/mmc-pwrseq-simple.yaml @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 %YAML 1.2 --- -$id: http://devicetree.org/schemas/mmc/mmc-pwrseq-simple.yaml# +$id: http://devicetree.org/schemas/power/pwrseq/mmc-pwrseq-simple.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# title: Simple MMC power sequence provider binding @@ -47,6 +47,9 @@ properties: Delay in us after asserting the reset-gpios (if any) during power off of the card. + "#pwrseq-cells": + const: 0 + required: - compatible @@ -57,6 +60,7 @@ examples: #include sdhci0_pwrseq { compatible = "mmc-pwrseq-simple"; + #pwrseq-cells = <0>; reset-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>; clocks = <&clk_32768_ck>; clock-names = "ext_clock"; diff --git a/drivers/mmc/core/Kconfig b/drivers/mmc/core/Kconfig index 6f25c34e4fec..cf7df64ce009 100644 --- a/drivers/mmc/core/Kconfig +++ b/drivers/mmc/core/Kconfig @@ -2,38 +2,6 @@ # # MMC core configuration # -config PWRSEQ_EMMC - tristate "HW reset support for eMMC" - default y - depends on OF - help - This selects Hardware reset support aka pwrseq-emmc for eMMC - devices. By default this option is set to y. - - This driver can also be built as a module. If so, the module - will be called pwrseq_emmc. - -config PWRSEQ_SD8787 - tristate "HW reset support for SD8787 BT + Wifi module" - depends on OF && (MWIFIEX || BT_MRVL_SDIO || LIBERTAS_SDIO || WILC1000_SDIO) - help - This selects hardware reset support for the SD8787 BT + Wifi - module. By default this option is set to n. - - This driver can also be built as a module. If so, the module - will be called pwrseq_sd8787. - -config PWRSEQ_SIMPLE - tristate "Simple HW reset support for MMC" - default y - depends on OF - help - This selects simple hardware reset support aka pwrseq-simple for MMC - devices. By default this option is set to y. - - This driver can also be built as a module. If so, the module - will be called pwrseq_simple. - config MMC_BLOCK tristate "MMC block device driver" depends on BLOCK diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile index 6a907736cd7a..322eb69bd00e 100644 --- a/drivers/mmc/core/Makefile +++ b/drivers/mmc/core/Makefile @@ -10,9 +10,6 @@ mmc_core-y := core.o bus.o host.o \ sdio_cis.o sdio_io.o sdio_irq.o \ slot-gpio.o regulator.o mmc_core-$(CONFIG_OF) += pwrseq.o -obj-$(CONFIG_PWRSEQ_SIMPLE) += pwrseq_simple.o -obj-$(CONFIG_PWRSEQ_SD8787) += pwrseq_sd8787.o -obj-$(CONFIG_PWRSEQ_EMMC) += pwrseq_emmc.o mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o obj-$(CONFIG_MMC_BLOCK) += mmc_block.o mmc_block-objs := block.o queue.o diff --git a/drivers/mmc/core/pwrseq_emmc.c b/drivers/mmc/core/pwrseq_emmc.c deleted file mode 100644 index f6dde9edd7a3..000000000000 --- a/drivers/mmc/core/pwrseq_emmc.c +++ /dev/null @@ -1,120 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2015, Samsung Electronics Co., Ltd. - * - * Author: Marek Szyprowski - * - * Simple eMMC hardware reset provider - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "pwrseq.h" - -struct mmc_pwrseq_emmc { - struct mmc_pwrseq pwrseq; - struct notifier_block reset_nb; - struct gpio_desc *reset_gpio; -}; - -#define to_pwrseq_emmc(p) container_of(p, struct mmc_pwrseq_emmc, pwrseq) - -static void mmc_pwrseq_emmc_reset(struct mmc_host *host) -{ - struct mmc_pwrseq_emmc *pwrseq = to_pwrseq_emmc(host->pwrseq); - - gpiod_set_value_cansleep(pwrseq->reset_gpio, 1); - udelay(1); - gpiod_set_value_cansleep(pwrseq->reset_gpio, 0); - udelay(200); -} - -static int mmc_pwrseq_emmc_reset_nb(struct notifier_block *this, - unsigned long mode, void *cmd) -{ - struct mmc_pwrseq_emmc *pwrseq = container_of(this, - struct mmc_pwrseq_emmc, reset_nb); - gpiod_set_value(pwrseq->reset_gpio, 1); - udelay(1); - gpiod_set_value(pwrseq->reset_gpio, 0); - udelay(200); - - return NOTIFY_DONE; -} - -static const struct mmc_pwrseq_ops mmc_pwrseq_emmc_ops = { - .reset = mmc_pwrseq_emmc_reset, -}; - -static int mmc_pwrseq_emmc_probe(struct platform_device *pdev) -{ - struct mmc_pwrseq_emmc *pwrseq; - struct device *dev = &pdev->dev; - - pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); - if (!pwrseq) - return -ENOMEM; - - pwrseq->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); - if (IS_ERR(pwrseq->reset_gpio)) - return PTR_ERR(pwrseq->reset_gpio); - - if (!gpiod_cansleep(pwrseq->reset_gpio)) { - /* - * register reset handler to ensure emmc reset also from - * emergency_reboot(), priority 255 is the highest priority - * so it will be executed before any system reboot handler. - */ - pwrseq->reset_nb.notifier_call = mmc_pwrseq_emmc_reset_nb; - pwrseq->reset_nb.priority = 255; - register_restart_handler(&pwrseq->reset_nb); - } else { - dev_notice(dev, "EMMC reset pin tied to a sleepy GPIO driver; reset on emergency-reboot disabled\n"); - } - - pwrseq->pwrseq.ops = &mmc_pwrseq_emmc_ops; - pwrseq->pwrseq.dev = dev; - pwrseq->pwrseq.owner = THIS_MODULE; - platform_set_drvdata(pdev, pwrseq); - - return mmc_pwrseq_register(&pwrseq->pwrseq); -} - -static int mmc_pwrseq_emmc_remove(struct platform_device *pdev) -{ - struct mmc_pwrseq_emmc *pwrseq = platform_get_drvdata(pdev); - - unregister_restart_handler(&pwrseq->reset_nb); - mmc_pwrseq_unregister(&pwrseq->pwrseq); - - return 0; -} - -static const struct of_device_id mmc_pwrseq_emmc_of_match[] = { - { .compatible = "mmc-pwrseq-emmc",}, - {/* sentinel */}, -}; - -MODULE_DEVICE_TABLE(of, mmc_pwrseq_emmc_of_match); - -static struct platform_driver mmc_pwrseq_emmc_driver = { - .probe = mmc_pwrseq_emmc_probe, - .remove = mmc_pwrseq_emmc_remove, - .driver = { - .name = "pwrseq_emmc", - .of_match_table = mmc_pwrseq_emmc_of_match, - }, -}; - -module_platform_driver(mmc_pwrseq_emmc_driver); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/mmc/core/pwrseq_sd8787.c b/drivers/mmc/core/pwrseq_sd8787.c deleted file mode 100644 index 2e120ad83020..000000000000 --- a/drivers/mmc/core/pwrseq_sd8787.c +++ /dev/null @@ -1,117 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * pwrseq_sd8787.c - power sequence support for Marvell SD8787 BT + Wifi chip - * - * Copyright (C) 2016 Matt Ranostay - * - * Based on the original work pwrseq_simple.c - * Copyright (C) 2014 Linaro Ltd - * Author: Ulf Hansson - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "pwrseq.h" - -struct mmc_pwrseq_sd8787 { - struct mmc_pwrseq pwrseq; - struct gpio_desc *reset_gpio; - struct gpio_desc *pwrdn_gpio; - u32 reset_pwrdwn_delay_ms; -}; - -#define to_pwrseq_sd8787(p) container_of(p, struct mmc_pwrseq_sd8787, pwrseq) - -static void mmc_pwrseq_sd8787_pre_power_on(struct mmc_host *host) -{ - struct mmc_pwrseq_sd8787 *pwrseq = to_pwrseq_sd8787(host->pwrseq); - - gpiod_set_value_cansleep(pwrseq->reset_gpio, 1); - - msleep(pwrseq->reset_pwrdwn_delay_ms); - gpiod_set_value_cansleep(pwrseq->pwrdn_gpio, 1); -} - -static void mmc_pwrseq_sd8787_power_off(struct mmc_host *host) -{ - struct mmc_pwrseq_sd8787 *pwrseq = to_pwrseq_sd8787(host->pwrseq); - - gpiod_set_value_cansleep(pwrseq->pwrdn_gpio, 0); - gpiod_set_value_cansleep(pwrseq->reset_gpio, 0); -} - -static const struct mmc_pwrseq_ops mmc_pwrseq_sd8787_ops = { - .pre_power_on = mmc_pwrseq_sd8787_pre_power_on, - .power_off = mmc_pwrseq_sd8787_power_off, -}; - -static const u32 sd8787_delay_ms = 300; -static const u32 wilc1000_delay_ms = 5; - -static const struct of_device_id mmc_pwrseq_sd8787_of_match[] = { - { .compatible = "mmc-pwrseq-sd8787", .data = &sd8787_delay_ms }, - { .compatible = "mmc-pwrseq-wilc1000", .data = &wilc1000_delay_ms }, - {/* sentinel */}, -}; -MODULE_DEVICE_TABLE(of, mmc_pwrseq_sd8787_of_match); - -static int mmc_pwrseq_sd8787_probe(struct platform_device *pdev) -{ - struct mmc_pwrseq_sd8787 *pwrseq; - struct device *dev = &pdev->dev; - const struct of_device_id *match; - - pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); - if (!pwrseq) - return -ENOMEM; - - match = of_match_node(mmc_pwrseq_sd8787_of_match, pdev->dev.of_node); - pwrseq->reset_pwrdwn_delay_ms = *(u32 *)match->data; - - pwrseq->pwrdn_gpio = devm_gpiod_get(dev, "powerdown", GPIOD_OUT_LOW); - if (IS_ERR(pwrseq->pwrdn_gpio)) - return PTR_ERR(pwrseq->pwrdn_gpio); - - pwrseq->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); - if (IS_ERR(pwrseq->reset_gpio)) - return PTR_ERR(pwrseq->reset_gpio); - - pwrseq->pwrseq.dev = dev; - pwrseq->pwrseq.ops = &mmc_pwrseq_sd8787_ops; - pwrseq->pwrseq.owner = THIS_MODULE; - platform_set_drvdata(pdev, pwrseq); - - return mmc_pwrseq_register(&pwrseq->pwrseq); -} - -static int mmc_pwrseq_sd8787_remove(struct platform_device *pdev) -{ - struct mmc_pwrseq_sd8787 *pwrseq = platform_get_drvdata(pdev); - - mmc_pwrseq_unregister(&pwrseq->pwrseq); - - return 0; -} - -static struct platform_driver mmc_pwrseq_sd8787_driver = { - .probe = mmc_pwrseq_sd8787_probe, - .remove = mmc_pwrseq_sd8787_remove, - .driver = { - .name = "pwrseq_sd8787", - .of_match_table = mmc_pwrseq_sd8787_of_match, - }, -}; - -module_platform_driver(mmc_pwrseq_sd8787_driver); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c deleted file mode 100644 index ea4d3670560e..000000000000 --- a/drivers/mmc/core/pwrseq_simple.c +++ /dev/null @@ -1,164 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2014 Linaro Ltd - * - * Author: Ulf Hansson - * - * Simple MMC power sequence management - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "pwrseq.h" - -struct mmc_pwrseq_simple { - struct mmc_pwrseq pwrseq; - bool clk_enabled; - u32 post_power_on_delay_ms; - u32 power_off_delay_us; - struct clk *ext_clk; - struct gpio_descs *reset_gpios; -}; - -#define to_pwrseq_simple(p) container_of(p, struct mmc_pwrseq_simple, pwrseq) - -static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq, - int value) -{ - struct gpio_descs *reset_gpios = pwrseq->reset_gpios; - - if (!IS_ERR(reset_gpios)) { - unsigned long *values; - int nvalues = reset_gpios->ndescs; - - values = bitmap_alloc(nvalues, GFP_KERNEL); - if (!values) - return; - - if (value) - bitmap_fill(values, nvalues); - else - bitmap_zero(values, nvalues); - - gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc, - reset_gpios->info, values); - - kfree(values); - } -} - -static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host) -{ - struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq); - - if (!IS_ERR(pwrseq->ext_clk) && !pwrseq->clk_enabled) { - clk_prepare_enable(pwrseq->ext_clk); - pwrseq->clk_enabled = true; - } - - mmc_pwrseq_simple_set_gpios_value(pwrseq, 1); -} - -static void mmc_pwrseq_simple_post_power_on(struct mmc_host *host) -{ - struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq); - - mmc_pwrseq_simple_set_gpios_value(pwrseq, 0); - - if (pwrseq->post_power_on_delay_ms) - msleep(pwrseq->post_power_on_delay_ms); -} - -static void mmc_pwrseq_simple_power_off(struct mmc_host *host) -{ - struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq); - - mmc_pwrseq_simple_set_gpios_value(pwrseq, 1); - - if (pwrseq->power_off_delay_us) - usleep_range(pwrseq->power_off_delay_us, - 2 * pwrseq->power_off_delay_us); - - if (!IS_ERR(pwrseq->ext_clk) && pwrseq->clk_enabled) { - clk_disable_unprepare(pwrseq->ext_clk); - pwrseq->clk_enabled = false; - } -} - -static const struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = { - .pre_power_on = mmc_pwrseq_simple_pre_power_on, - .post_power_on = mmc_pwrseq_simple_post_power_on, - .power_off = mmc_pwrseq_simple_power_off, -}; - -static const struct of_device_id mmc_pwrseq_simple_of_match[] = { - { .compatible = "mmc-pwrseq-simple",}, - {/* sentinel */}, -}; -MODULE_DEVICE_TABLE(of, mmc_pwrseq_simple_of_match); - -static int mmc_pwrseq_simple_probe(struct platform_device *pdev) -{ - struct mmc_pwrseq_simple *pwrseq; - struct device *dev = &pdev->dev; - - pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); - if (!pwrseq) - return -ENOMEM; - - pwrseq->ext_clk = devm_clk_get(dev, "ext_clock"); - if (IS_ERR(pwrseq->ext_clk) && PTR_ERR(pwrseq->ext_clk) != -ENOENT) - return PTR_ERR(pwrseq->ext_clk); - - pwrseq->reset_gpios = devm_gpiod_get_array(dev, "reset", - GPIOD_OUT_HIGH); - if (IS_ERR(pwrseq->reset_gpios) && - PTR_ERR(pwrseq->reset_gpios) != -ENOENT && - PTR_ERR(pwrseq->reset_gpios) != -ENOSYS) { - return PTR_ERR(pwrseq->reset_gpios); - } - - device_property_read_u32(dev, "post-power-on-delay-ms", - &pwrseq->post_power_on_delay_ms); - device_property_read_u32(dev, "power-off-delay-us", - &pwrseq->power_off_delay_us); - - pwrseq->pwrseq.dev = dev; - pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops; - pwrseq->pwrseq.owner = THIS_MODULE; - platform_set_drvdata(pdev, pwrseq); - - return mmc_pwrseq_register(&pwrseq->pwrseq); -} - -static int mmc_pwrseq_simple_remove(struct platform_device *pdev) -{ - struct mmc_pwrseq_simple *pwrseq = platform_get_drvdata(pdev); - - mmc_pwrseq_unregister(&pwrseq->pwrseq); - - return 0; -} - -static struct platform_driver mmc_pwrseq_simple_driver = { - .probe = mmc_pwrseq_simple_probe, - .remove = mmc_pwrseq_simple_remove, - .driver = { - .name = "pwrseq_simple", - .of_match_table = mmc_pwrseq_simple_of_match, - }, -}; - -module_platform_driver(mmc_pwrseq_simple_driver); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/power/pwrseq/Kconfig b/drivers/power/pwrseq/Kconfig index dab8f4d860fe..1985f13d9193 100644 --- a/drivers/power/pwrseq/Kconfig +++ b/drivers/power/pwrseq/Kconfig @@ -11,4 +11,36 @@ menuconfig PWRSEQ if PWRSEQ +config PWRSEQ_EMMC + tristate "HW reset support for eMMC" + default y + depends on OF + help + This selects Hardware reset support aka pwrseq-emmc for eMMC + devices. By default this option is set to y. + + This driver can also be built as a module. If so, the module + will be called pwrseq_emmc. + +config PWRSEQ_SD8787 + tristate "HW reset support for SD8787 BT + Wifi module" + depends on OF + help + This selects hardware reset support for the SD8787 BT + Wifi + module. By default this option is set to n. + + This driver can also be built as a module. If so, the module + will be called pwrseq_sd8787. + +config PWRSEQ_SIMPLE + tristate "Simple HW reset support" + default y + depends on OF + help + This selects simple hardware reset support aka pwrseq-simple. + By default this option is set to y. + + This driver can also be built as a module. If so, the module + will be called pwrseq_simple. + endif diff --git a/drivers/power/pwrseq/Makefile b/drivers/power/pwrseq/Makefile index 108429ff6445..6f359d228843 100644 --- a/drivers/power/pwrseq/Makefile +++ b/drivers/power/pwrseq/Makefile @@ -4,3 +4,7 @@ # obj-$(CONFIG_PWRSEQ) += core.o + +obj-$(CONFIG_PWRSEQ_EMMC) += pwrseq_emmc.o +obj-$(CONFIG_PWRSEQ_SD8787) += pwrseq_sd8787.o +obj-$(CONFIG_PWRSEQ_SIMPLE) += pwrseq_simple.o diff --git a/drivers/power/pwrseq/pwrseq_emmc.c b/drivers/power/pwrseq/pwrseq_emmc.c new file mode 100644 index 000000000000..954bbb44979d --- /dev/null +++ b/drivers/power/pwrseq/pwrseq_emmc.c @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2015, Samsung Electronics Co., Ltd. + * + * Author: Marek Szyprowski + * + * Simple eMMC hardware reset provider + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct pwrseq_emmc { + struct notifier_block reset_nb; + struct gpio_desc *reset_gpio; +}; + +static void pwrseq_ereset(struct pwrseq *pwrseq) +{ + struct pwrseq_emmc *pwrseq_emmc = pwrseq_get_drvdata(pwrseq); + + gpiod_set_value_cansleep(pwrseq_emmc->reset_gpio, 1); + udelay(1); + gpiod_set_value_cansleep(pwrseq_emmc->reset_gpio, 0); + udelay(200); +} + +static int pwrseq_ereset_nb(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + struct pwrseq_emmc *pwrseq_emmc = container_of(this, + struct pwrseq_emmc, reset_nb); + gpiod_set_value(pwrseq_emmc->reset_gpio, 1); + udelay(1); + gpiod_set_value(pwrseq_emmc->reset_gpio, 0); + udelay(200); + + return NOTIFY_DONE; +} + +static const struct pwrseq_ops pwrseq_eops = { + .reset = pwrseq_ereset, +}; + +static int pwrseq_eprobe(struct platform_device *pdev) +{ + struct pwrseq_emmc *pwrseq_emmc; + struct pwrseq *pwrseq; + struct pwrseq_provider *provider; + struct device *dev = &pdev->dev; + + pwrseq_emmc = devm_kzalloc(dev, sizeof(*pwrseq_emmc), GFP_KERNEL); + if (!pwrseq_emmc) + return -ENOMEM; + + pwrseq_emmc->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(pwrseq_emmc->reset_gpio)) + return PTR_ERR(pwrseq_emmc->reset_gpio); + + if (!gpiod_cansleep(pwrseq_emmc->reset_gpio)) { + /* + * register reset handler to ensure emmc reset also from + * emergency_reboot(), priority 255 is the highest priority + * so it will be executed before any system reboot handler. + */ + pwrseq_emmc->reset_nb.notifier_call = pwrseq_ereset_nb; + pwrseq_emmc->reset_nb.priority = 255; + register_restart_handler(&pwrseq_emmc->reset_nb); + } else { + dev_notice(dev, "EMMC reset pin tied to a sleepy GPIO driver; reset on emergency-reboot disabled\n"); + } + + platform_set_drvdata(pdev, pwrseq_emmc); + + pwrseq = devm_pwrseq_create(dev, &pwrseq_eops); + if (IS_ERR(pwrseq)) + return PTR_ERR(pwrseq); + + pwrseq_set_drvdata(pwrseq, pwrseq_emmc); + + provider = devm_of_pwrseq_provider_register(dev, of_pwrseq_xlate_single, pwrseq); + + return PTR_ERR_OR_ZERO(provider); +} + +static int pwrseq_eremove(struct platform_device *pdev) +{ + struct pwrseq_emmc *pwrseq_emmc = platform_get_drvdata(pdev); + + unregister_restart_handler(&pwrseq_emmc->reset_nb); + + return 0; +} + +static const struct of_device_id pwrseq_eof_match[] = { + { .compatible = "mmc-pwrseq-emmc",}, + {/* sentinel */}, +}; + +MODULE_DEVICE_TABLE(of, pwrseq_eof_match); + +static struct platform_driver pwrseq_edriver = { + .probe = pwrseq_eprobe, + .remove = pwrseq_eremove, + .driver = { + .name = "pwrseq_emmc", + .of_match_table = pwrseq_eof_match, + }, +}; + +module_platform_driver(pwrseq_edriver); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/power/pwrseq/pwrseq_sd8787.c b/drivers/power/pwrseq/pwrseq_sd8787.c new file mode 100644 index 000000000000..aeb80327f40d --- /dev/null +++ b/drivers/power/pwrseq/pwrseq_sd8787.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * pwrseq_sd8787.c - power sequence support for Marvell SD8787 BT + Wifi chip + * + * Copyright (C) 2016 Matt Ranostay + * + * Based on the original work pwrseq_sd8787.c + * Copyright (C) 2014 Linaro Ltd + * Author: Ulf Hansson + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +struct pwrseq_sd8787 { + struct gpio_desc *reset_gpio; + struct gpio_desc *pwrdn_gpio; + u32 reset_pwrdwn_delay_ms; +}; + +static int pwrseq_sd8787_pre_power_on(struct pwrseq *pwrseq) +{ + struct pwrseq_sd8787 *pwrseq_sd8787 = pwrseq_get_drvdata(pwrseq); + + gpiod_set_value_cansleep(pwrseq_sd8787->reset_gpio, 1); + + msleep(pwrseq_sd8787->reset_pwrdwn_delay_ms); + gpiod_set_value_cansleep(pwrseq_sd8787->pwrdn_gpio, 1); + + return 0; +} + +static void pwrseq_sd8787_power_off(struct pwrseq *pwrseq) +{ + struct pwrseq_sd8787 *pwrseq_sd8787 = pwrseq_get_drvdata(pwrseq); + + gpiod_set_value_cansleep(pwrseq_sd8787->pwrdn_gpio, 0); + gpiod_set_value_cansleep(pwrseq_sd8787->reset_gpio, 0); +} + +static const struct pwrseq_ops pwrseq_sd8787_ops = { + .pre_power_on = pwrseq_sd8787_pre_power_on, + .power_off = pwrseq_sd8787_power_off, +}; + +static const u32 sd8787_delay_ms = 300; +static const u32 wilc1000_delay_ms = 5; + +static const struct of_device_id pwrseq_sd8787_of_match[] = { + { .compatible = "mmc-pwrseq-sd8787", .data = &sd8787_delay_ms }, + { .compatible = "mmc-pwrseq-wilc1000", .data = &wilc1000_delay_ms }, + {/* sentinel */}, +}; +MODULE_DEVICE_TABLE(of, pwrseq_sd8787_of_match); + +static int pwrseq_sd8787_probe(struct platform_device *pdev) +{ + struct pwrseq_sd8787 *pwrseq_sd8787; + struct pwrseq *pwrseq; + struct pwrseq_provider *provider; + struct device *dev = &pdev->dev; + + pwrseq_sd8787 = devm_kzalloc(dev, sizeof(*pwrseq_sd8787), GFP_KERNEL); + if (!pwrseq_sd8787) + return -ENOMEM; + + pwrseq_sd8787->reset_pwrdwn_delay_ms = *(u32 *)of_device_get_match_data(dev); + + pwrseq_sd8787->pwrdn_gpio = devm_gpiod_get(dev, "powerdown", GPIOD_OUT_LOW); + if (IS_ERR(pwrseq_sd8787->pwrdn_gpio)) + return PTR_ERR(pwrseq_sd8787->pwrdn_gpio); + + pwrseq_sd8787->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(pwrseq_sd8787->reset_gpio)) + return PTR_ERR(pwrseq_sd8787->reset_gpio); + + pwrseq = devm_pwrseq_create(dev, &pwrseq_sd8787_ops); + if (IS_ERR(pwrseq)) + return PTR_ERR(pwrseq); + + pwrseq_set_drvdata(pwrseq, pwrseq_sd8787); + + provider = devm_of_pwrseq_provider_register(dev, of_pwrseq_xlate_single, pwrseq); + + return PTR_ERR_OR_ZERO(provider); +} + +static struct platform_driver pwrseq_sd8787_driver = { + .probe = pwrseq_sd8787_probe, + .driver = { + .name = "pwrseq_sd8787", + .of_match_table = pwrseq_sd8787_of_match, + }, +}; + +module_platform_driver(pwrseq_sd8787_driver); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/power/pwrseq/pwrseq_simple.c b/drivers/power/pwrseq/pwrseq_simple.c new file mode 100644 index 000000000000..4889fd5a11e0 --- /dev/null +++ b/drivers/power/pwrseq/pwrseq_simple.c @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2014 Linaro Ltd + * + * Author: Ulf Hansson + * + * Simple MMC power sequence management + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct pwrseq_simple { + bool clk_enabled; + u32 post_power_on_delay_ms; + u32 power_off_delay_us; + struct clk *ext_clk; + struct gpio_descs *reset_gpios; +}; + +static int pwrseq_simple_set_gpios_value(struct pwrseq_simple *pwrseq_simple, + int value) +{ + struct gpio_descs *reset_gpios = pwrseq_simple->reset_gpios; + unsigned long *values; + int nvalues; + int ret; + + if (IS_ERR(reset_gpios)) + return PTR_ERR(reset_gpios); + + nvalues = reset_gpios->ndescs; + + values = bitmap_alloc(nvalues, GFP_KERNEL); + if (!values) + return -ENOMEM; + + if (value) + bitmap_fill(values, nvalues); + else + bitmap_zero(values, nvalues); + + ret = gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc, + reset_gpios->info, values); + kfree(values); + + return ret; +} + +static int pwrseq_simple_pre_power_on(struct pwrseq *pwrseq) +{ + struct pwrseq_simple *pwrseq_simple = pwrseq_get_drvdata(pwrseq); + + if (!IS_ERR(pwrseq_simple->ext_clk) && !pwrseq_simple->clk_enabled) { + clk_prepare_enable(pwrseq_simple->ext_clk); + pwrseq_simple->clk_enabled = true; + } + + return pwrseq_simple_set_gpios_value(pwrseq_simple, 1); +} + +static int pwrseq_simple_power_on(struct pwrseq *pwrseq) +{ + struct pwrseq_simple *pwrseq_simple = pwrseq_get_drvdata(pwrseq); + int ret; + + ret = pwrseq_simple_set_gpios_value(pwrseq_simple, 0); + if (ret) + return ret; + + if (pwrseq_simple->post_power_on_delay_ms) + msleep(pwrseq_simple->post_power_on_delay_ms); + + return 0; +} + +static void pwrseq_simple_power_off(struct pwrseq *pwrseq) +{ + struct pwrseq_simple *pwrseq_simple = pwrseq_get_drvdata(pwrseq); + + pwrseq_simple_set_gpios_value(pwrseq_simple, 1); + + if (pwrseq_simple->power_off_delay_us) + usleep_range(pwrseq_simple->power_off_delay_us, + 2 * pwrseq_simple->power_off_delay_us); + + if (!IS_ERR(pwrseq_simple->ext_clk) && pwrseq_simple->clk_enabled) { + clk_disable_unprepare(pwrseq_simple->ext_clk); + pwrseq_simple->clk_enabled = false; + } +} + +static const struct pwrseq_ops pwrseq_simple_ops = { + .pre_power_on = pwrseq_simple_pre_power_on, + .power_on = pwrseq_simple_power_on, + .power_off = pwrseq_simple_power_off, +}; + +static const struct of_device_id pwrseq_simple_of_match[] = { + { .compatible = "mmc-pwrseq-simple",}, /* MMC-specific compatible */ + {/* sentinel */}, +}; +MODULE_DEVICE_TABLE(of, pwrseq_simple_of_match); + +static int pwrseq_simple_probe(struct platform_device *pdev) +{ + struct pwrseq_simple *pwrseq_simple; + struct pwrseq *pwrseq; + struct pwrseq_provider *provider; + struct device *dev = &pdev->dev; + + pwrseq_simple = devm_kzalloc(dev, sizeof(*pwrseq_simple), GFP_KERNEL); + if (!pwrseq_simple) + return -ENOMEM; + + pwrseq_simple->ext_clk = devm_clk_get(dev, "ext_clock"); + if (IS_ERR(pwrseq_simple->ext_clk) && PTR_ERR(pwrseq_simple->ext_clk) != -ENOENT) + return PTR_ERR(pwrseq_simple->ext_clk); + + pwrseq_simple->reset_gpios = devm_gpiod_get_array(dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(pwrseq_simple->reset_gpios) && + PTR_ERR(pwrseq_simple->reset_gpios) != -ENOENT && + PTR_ERR(pwrseq_simple->reset_gpios) != -ENOSYS) { + return PTR_ERR(pwrseq_simple->reset_gpios); + } + + device_property_read_u32(dev, "post-power-on-delay-ms", + &pwrseq_simple->post_power_on_delay_ms); + device_property_read_u32(dev, "power-off-delay-us", + &pwrseq_simple->power_off_delay_us); + + pwrseq = devm_pwrseq_create(dev, &pwrseq_simple_ops); + if (IS_ERR(pwrseq)) + return PTR_ERR(pwrseq); + + pwrseq_set_drvdata(pwrseq, pwrseq_simple); + + provider = devm_of_pwrseq_provider_register(dev, of_pwrseq_xlate_single, pwrseq); + + return PTR_ERR_OR_ZERO(provider); +} + +static struct platform_driver pwrseq_simple_driver = { + .probe = pwrseq_simple_probe, + .driver = { + .name = "pwrseq_simple", + .of_match_table = pwrseq_simple_of_match, + }, +}; + +module_platform_driver(pwrseq_simple_driver); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/pwrseq/driver.h b/include/linux/pwrseq/driver.h index bdb8a25a8504..0ca1d0311ab6 100644 --- a/include/linux/pwrseq/driver.h +++ b/include/linux/pwrseq/driver.h @@ -57,7 +57,7 @@ struct pwrseq *__devm_pwrseq_create(struct device *dev, struct module *owner, co * * Return: created instance or the wrapped error code. */ -#define pwrseq_create(dev, ops, data) __pwrseq_create((dev), THIS_MODULE, (ops)) +#define pwrseq_create(dev, ops) __pwrseq_create((dev), THIS_MODULE, (ops)) /** * devm_pwrseq_create() - devres-managed version of pwrseq_create @@ -71,7 +71,7 @@ struct pwrseq *__devm_pwrseq_create(struct device *dev, struct module *owner, co * * Return: created instance or the wrapped error code. */ -#define devm_pwrseq_create(dev, ops, data) __devm_pwrseq_create((dev), THIS_MODULE, (ops)) +#define devm_pwrseq_create(dev, ops) __devm_pwrseq_create((dev), THIS_MODULE, (ops)) void pwrseq_destroy(struct pwrseq *pwrseq);