From patchwork Fri Feb 16 20:32:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13560659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F805C48BF3 for ; Fri, 16 Feb 2024 20:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JclWowoz8TNdaAfsEVyXerk4DiGWZCaE2h+hOIstoX8=; b=sWeJLLDIrNsnQR DZOLtfttzZ4NvYSUtyjvlzBBISA5yD3IqDjQnsFh5xyOaU0sLHuX+7CvUDbWBhUqez5tzp+I4kkj1 kg12mf55SF1WV2tO12Ccb7yI3h2/AmiDZZT4TrerlO5vWHdlwRYCy7IXk7bVnJuSB2+vSmeQMqH2a MdL8ZRH+DukKFbnAUvlpw++OwM9RzpRdlse4jvWs6/VeavSRSCrkJFn+UO7y88HAhlLYvT1sP1tBE XapVqtzK3rlO0J0h50mwAJ8b9Dpc9pGxdSnW/D2pMktxjku/an6+RAgV61FAAUPmlCPRTdnAmYna0 CKGCIA/Ve3F+62tRStnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb4vB-00000003ekS-0Gww; Fri, 16 Feb 2024 20:34:57 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb4ts-00000003dq3-00Lc for linux-arm-kernel@lists.infradead.org; Fri, 16 Feb 2024 20:33:41 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2d204e102a9so31383581fa.0 for ; Fri, 16 Feb 2024 12:33:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1708115613; x=1708720413; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iiAgZXD5R5oyKE5kvpTu1Xl8SVVb50mDoXKZHDVMF3g=; b=FJakvS5oMMN9et6XexaExEoBiqoxglL8AShxb8VKMfv9Xt/n8hOMK9IzU6y8eUmH+3 iwrrHzqwX/GCfbB33n327rAGNxDZTYEAVG7fWcbYfKjjOvUmMebqWtrNpVycu3m4jVT2 rNZjaCFLJlyHDJMmx0H3G1tXv9h/PQjYIX15JgQQY/QaxkufWgjNaLiJ7NTLhaaEMt5b z8zdPpapysvhBbZ6s/xp1AYpw5FvlU7lHP2b9PN+ADiXei7d8YfLCgLZZYvNGr+UHLge YypMWCvqup2YrmQwplq8YsL8L9qrETLND/ceB0A8y3lFp8Kw73u9fRvGf1mwilcYlD0c aWVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708115613; x=1708720413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iiAgZXD5R5oyKE5kvpTu1Xl8SVVb50mDoXKZHDVMF3g=; b=acB3hj7vIwy51f1+bjeNLv6+AM4ZpHiHHscQmbgaATBlaAsLj6vGklLOPgeVUeQcSt OIZ8kQEcvj7IDB8bnbdBIWwGs9YoYcPm3Gu0OkZchr4OU4RuvEwh7lpscFtlzix4/BxW eMdMX6nQeedc4TqY7CznDouguSD8b6aiMSvZl8EN8vGjdqU9O4SKVEqaiaRA9gojD1eH BCJ0O+F62YeW3bsqKWt8MeJZjx9bfqQZC2i062EC9979POaM7mS+FGbsCB3Kh73EpkQ2 zcMgLWOK3IwRxVSOfyvnuH+tAmVRMHOZvHZ8R/uO/opDzR4efMOWRAfyvSQrl4OwEDPv f2VA== X-Forwarded-Encrypted: i=1; AJvYcCUnMc02FIhIRgEss2VcPmvb4F9IgpsSw1hy0k1tjt9rhY6cLOGXWEAP4cEe4rcW+tm7/2tlRbW3moiA04ZIKCkck20MJbXi9RcB+hotB5JpdH/vpG0= X-Gm-Message-State: AOJu0Yz5/p/Nfnq3IM3N2Eb3IpMvo/j+RGD00OfXsUccRlWJjFEMQ899 7s1O8cFdGPRA3baSojTU9iEyTsV2EkDywXCFZdYsSsK/erEbb+IvEMF4c6Br+z0= X-Google-Smtp-Source: AGHT+IEuflH9wQzsx8TrMcwmwhz38pYeg7QRtUYyjKydmIUvwvFOOto2iAhoyBREDsH8Oy9snBTz1A== X-Received: by 2002:a2e:b8c6:0:b0:2d1:1dae:c562 with SMTP id s6-20020a2eb8c6000000b002d11daec562mr4928843ljp.6.1708115613459; Fri, 16 Feb 2024 12:33:33 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:7758:12d:16:5f19]) by smtp.gmail.com with ESMTPSA id m5-20020a05600c4f4500b0041253d0acd6sm1420528wmq.47.2024.02.16.12.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 12:33:33 -0800 (PST) From: Bartosz Golaszewski To: Marcel Holtmann , Luiz Augusto von Dentz , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kalle Valo , Bjorn Andersson , Konrad Dybcio , Liam Girdwood , Mark Brown , Catalin Marinas , Will Deacon , Bjorn Helgaas , Bartosz Golaszewski , Saravana Kannan , Geert Uytterhoeven , Arnd Bergmann , Neil Armstrong , Marek Szyprowski , Alex Elder , Srini Kandagatla , Greg Kroah-Hartman , Abel Vesa , Manivannan Sadhasivam , Lukas Wunner , Dmitry Baryshkov Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 14/18] PCI/pwrctl: add a power control driver for WCN7850 Date: Fri, 16 Feb 2024 21:32:11 +0100 Message-Id: <20240216203215.40870-15-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240216203215.40870-1-brgl@bgdev.pl> References: <20240216203215.40870-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_123336_484651_8957131D X-CRM114-Status: GOOD ( 26.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Add a PCI power control driver that's capable of correctly powering up the ath12k module on WCN7850 using the PCI pwrctl functionality. Signed-off-by: Bartosz Golaszewski --- drivers/pci/pwrctl/Kconfig | 8 + drivers/pci/pwrctl/Makefile | 2 + drivers/pci/pwrctl/pci-pwrctl-wcn7850.c | 202 ++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 drivers/pci/pwrctl/pci-pwrctl-wcn7850.c diff --git a/drivers/pci/pwrctl/Kconfig b/drivers/pci/pwrctl/Kconfig index 96195395af69..b91170ebfb49 100644 --- a/drivers/pci/pwrctl/Kconfig +++ b/drivers/pci/pwrctl/Kconfig @@ -5,4 +5,12 @@ menu "PCI Power control drivers" config PCI_PWRCTL tristate +config PCI_PWRCTL_WCN7850 + tristate "PCI Power Control driver for WCN7850" + select PCI_PWRCTL + default m if (ATH12K && ARCH_QCOM) + help + Enable support for the PCI power control driver for the ath12k + module of the WCN7850 WLAN/BT chip. + endmenu diff --git a/drivers/pci/pwrctl/Makefile b/drivers/pci/pwrctl/Makefile index 52ae0640ef7b..de20c3af1b78 100644 --- a/drivers/pci/pwrctl/Makefile +++ b/drivers/pci/pwrctl/Makefile @@ -2,3 +2,5 @@ obj-$(CONFIG_PCI_PWRCTL) += pci-pwrctl-core.o pci-pwrctl-core-y := core.o + +obj-$(CONFIG_PCI_PWRCTL_WCN7850) += pci-pwrctl-wcn7850.o diff --git a/drivers/pci/pwrctl/pci-pwrctl-wcn7850.c b/drivers/pci/pwrctl/pci-pwrctl-wcn7850.c new file mode 100644 index 000000000000..e2b2c53bff29 --- /dev/null +++ b/drivers/pci/pwrctl/pci-pwrctl-wcn7850.c @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct pci_pwrctl_wcn7850_vreg { + const char *name; + unsigned int load_uA; +}; + +struct pci_pwrctl_wcn7850_pdata { + struct pci_pwrctl_wcn7850_vreg *vregs; + size_t num_vregs; + unsigned int delay_msec; +}; + +struct pci_pwrctl_wcn7850_ctx { + struct pci_pwrctl pwrctl; + const struct pci_pwrctl_wcn7850_pdata *pdata; + struct regulator_bulk_data *regs; + struct gpio_desc *en_gpio; + struct clk *clk; +}; + +static struct pci_pwrctl_wcn7850_vreg pci_pwrctl_wcn7850_vregs[] = { + { + .name = "vdd", + .load_uA = 16000, + }, + { + .name = "vddio", + .load_uA = 5000, + }, + { + .name = "vddio1p2", + .load_uA = 16000, + }, + { + .name = "vddaon", + .load_uA = 26000, + }, + { + .name = "vdddig", + .load_uA = 126000, + }, + { + .name = "vddrfa1p2", + .load_uA = 257000, + }, + { + .name = "vddrfa1p8", + .load_uA = 302000, + }, +}; + +static struct pci_pwrctl_wcn7850_pdata pci_pwrctl_wcn7850_of_data = { + .vregs = pci_pwrctl_wcn7850_vregs, + .num_vregs = ARRAY_SIZE(pci_pwrctl_wcn7850_vregs), + .delay_msec = 50, +}; + +static int pci_pwrctl_wcn7850_power_on(struct pci_pwrctl_wcn7850_ctx *ctx) +{ + int ret; + + ret = regulator_bulk_enable(ctx->pdata->num_vregs, ctx->regs); + if (ret) + return ret; + + ret = clk_prepare_enable(ctx->clk); + if (ret) + return ret; + + gpiod_set_value_cansleep(ctx->en_gpio, 1); + + if (ctx->pdata->delay_msec) + msleep(ctx->pdata->delay_msec); + + return 0; +} + +static int pci_pwrctl_wcn7850_power_off(struct pci_pwrctl_wcn7850_ctx *ctx) +{ + gpiod_set_value_cansleep(ctx->en_gpio, 0); + clk_disable_unprepare(ctx->clk); + + return regulator_bulk_disable(ctx->pdata->num_vregs, ctx->regs); +} + +static void devm_pci_pwrctl_wcn7850_power_off(void *data) +{ + struct pci_pwrctl_wcn7850_ctx *ctx = data; + + pci_pwrctl_wcn7850_power_off(ctx); +} + +static int pci_pwrctl_wcn7850_probe(struct platform_device *pdev) +{ + struct pci_pwrctl_wcn7850_ctx *ctx; + struct device *dev = &pdev->dev; + int ret, i; + + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->pdata = of_device_get_match_data(dev); + if (!ctx->pdata) + return dev_err_probe(dev, -ENODEV, + "Failed to obtain platform data\n"); + + if (ctx->pdata->vregs) { + ctx->regs = devm_kcalloc(dev, ctx->pdata->num_vregs, + sizeof(*ctx->regs), GFP_KERNEL); + if (!ctx->regs) + return -ENOMEM; + + for (i = 0; i < ctx->pdata->num_vregs; i++) + ctx->regs[i].supply = ctx->pdata->vregs[i].name; + + ret = devm_regulator_bulk_get(dev, ctx->pdata->num_vregs, + ctx->regs); + if (ret < 0) + return dev_err_probe(dev, ret, + "Failed to get all regulators\n"); + + for (i = 0; i < ctx->pdata->num_vregs; i++) { + if (!ctx->pdata->vregs[1].load_uA) + continue; + + ret = regulator_set_load(ctx->regs[i].consumer, + ctx->pdata->vregs[i].load_uA); + if (ret) + return dev_err_probe(dev, ret, + "Failed to set vreg load\n"); + } + } + + ctx->clk = devm_clk_get_optional(dev, NULL); + if (IS_ERR(ctx->clk)) + return dev_err_probe(dev, PTR_ERR(ctx->clk), + "Failed to get clock\n"); + + ctx->en_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW); + if (IS_ERR(ctx->en_gpio)) + return dev_err_probe(dev, PTR_ERR(ctx->en_gpio), + "Failed to get enable the GPIO\n"); + + ret = pci_pwrctl_wcn7850_power_on(ctx); + if (ret) + return dev_err_probe(dev, ret, + "Failed to power on the device\n"); + + ret = devm_add_action_or_reset(dev, devm_pci_pwrctl_wcn7850_power_off, + ctx); + if (ret) + return ret; + + ctx->pwrctl.dev = dev; + + ret = devm_pci_pwrctl_device_set_ready(dev, &ctx->pwrctl); + if (ret) + return dev_err_probe(dev, ret, + "Failed to register the pwrctl wrapper\n"); + + return 0; +} + +static const struct of_device_id pci_pwrctl_wcn7850_of_match[] = { + { + .compatible = "pci17cb,1107", + .data = &pci_pwrctl_wcn7850_of_data, + }, + { } +}; +MODULE_DEVICE_TABLE(of, pci_pwrctl_wcn7850_of_match); + +static struct platform_driver pci_pwrctl_wcn7850_driver = { + .driver = { + .name = "pci-pwrctl-wcn7850", + .of_match_table = pci_pwrctl_wcn7850_of_match, + }, + .probe = pci_pwrctl_wcn7850_probe, +}; +module_platform_driver(pci_pwrctl_wcn7850_driver); + +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_DESCRIPTION("PCI Power Sequencing module for WCN7850"); +MODULE_LICENSE("GPL");