From patchwork Mon Sep 20 15:48:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 1530237 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=sSq1+du3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4HCqBV1skCz9sW5 for ; Tue, 21 Sep 2021 02:04:34 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 83C2882A15; Mon, 20 Sep 2021 18:04:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.b="sSq1+du3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5272980EC5; Mon, 20 Sep 2021 17:48:22 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EB7F3807FE for ; Mon, 20 Sep 2021 17:48:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=alexandre.ghiti@canonical.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 4AFE63F320 for ; Mon, 20 Sep 2021 15:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632152895; bh=ZPtpeu0AW5lxeRcMKrpCnQ0flfak9heaEk2zq0whYS0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=sSq1+du3fSKQW9F7UH0UzIRmB+yGTo33NBLrfNVilie1pbwrij8aBDQTsbdZn5x+U N5FWluDO2VIw4gQ19mWywdJAolXWfbFVtjOJr9HwPvPKhqigqCiTXyd+eIpVMBJ+mm nP0TuUjGuY880Ig/pvd2pD1v2O7MD/CbGfBDOs/nQNuV1YjjQBx8tO6Kpmh8EcdrMN Z3n0v5NOOy/h9XBBYFmMAQLqo49aD+SoMy0ZRGvAysExAMK1ycN71e+wadTKakk0ae Uqr5/x7vuzh39DVIsEQJV8tcaH1DYn6K0M0VocXYBmKrR0rCghJNonzRuBrSYxZbSm YC36deJ1TCcAQ== Received: by mail-wr1-f69.google.com with SMTP id r7-20020a5d6947000000b0015e0f68a63bso6498805wrw.22 for ; Mon, 20 Sep 2021 08:48:15 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=ZPtpeu0AW5lxeRcMKrpCnQ0flfak9heaEk2zq0whYS0=; b=U6b+GWGbgedugMe4pUgMRkoROFzJOkhqUD7xi7B/HwfwGkHKl4q0MPSWstpiu+FCYC ZkXhuAChJsUzTszQyQlMjttoNZnmPMcEPzvELXPHz0LUUJ7gYGig660fYxrv9GoSwFBJ zUEqfFE2zQOgs7//+voQfYpkMpmbvUbWaagL4nRBnE4M5Qd8570cjz137u2VqopvUGHt hGik934wMjATqUxjBVStlodLXPc7nEn8xEYWYjpwwpWtvuz8O8JDqYfo7x6A4qCtW+aj YooGXLMiLME9/EGXRavRAxcq4SvqJ1YRjFlAZd8OV1Yj+Gu0b9agbVP7UoilFS7eckDb hinA== X-Gm-Message-State: AOAM5300SeRejOkJC0Jb2y2Hi80sUbKaxZAeUh/P86eoZCQQKvYEVnzp SRZawwggAilNLFTKNaVWxUKvmdJ59/lYAAObKzNuQvnpOdAHtH7p4oo/l0G8IzAxNkZM6XywTnX gN6p+r84MPLvqyEXpGJAXswY4sCFySGQ= X-Received: by 2002:a7b:c405:: with SMTP id k5mr25002396wmi.24.1632152894931; Mon, 20 Sep 2021 08:48:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSc6JSXhpDWVXUu1tOkFew8KSeXDeCg0r6XvoDBd1eCEFTuQTZRI6BDjZVgohUbreoD3TrCA== X-Received: by 2002:a7b:c405:: with SMTP id k5mr25002377wmi.24.1632152894731; Mon, 20 Sep 2021 08:48:14 -0700 (PDT) Received: from localhost.localdomain (lfbn-lyo-1-470-249.w2-7.abo.wanadoo.fr. [2.7.60.249]) by smtp.gmail.com with ESMTPSA id h8sm19197939wmb.35.2021.09.20.08.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Sep 2021 08:48:14 -0700 (PDT) From: Alexandre Ghiti To: Paul Walmsley , Pragnesh Patel , Green Wan , Jaehoon Chung , Heinrich Schuchardt , u-boot@lists.denx.de Cc: Alexandre Ghiti Subject: [PATCH] drivers: pmic: Add sysreset driver to da9063 pmic device Date: Mon, 20 Sep 2021 17:48:09 +0200 Message-Id: <20210920154809.1695453-1-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 20 Sep 2021 18:04:26 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This pmic device is present on the SiFive Unmatched board and this new driver adds the possibility to reset it. Signed-off-by: Alexandre Ghiti --- configs/sifive_unmatched_defconfig | 2 ++ drivers/power/pmic/da9063.c | 49 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/configs/sifive_unmatched_defconfig b/configs/sifive_unmatched_defconfig index 978818b688..9ab058be39 100644 --- a/configs/sifive_unmatched_defconfig +++ b/configs/sifive_unmatched_defconfig @@ -43,3 +43,5 @@ CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_PCI=y CONFIG_BOARD_EARLY_INIT_F=y +CONFIG_DM_PMIC=y +CONFIG_DM_PMIC_DA9063=y diff --git a/drivers/power/pmic/da9063.c b/drivers/power/pmic/da9063.c index 25101d18f7..b04879d9c5 100644 --- a/drivers/power/pmic/da9063.c +++ b/drivers/power/pmic/da9063.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +88,7 @@ static int da9063_bind(struct udevice *dev) { ofnode regulators_node; int children; + int ret; regulators_node = dev_read_subnode(dev, "regulators"); if (!ofnode_valid(regulators_node)) { @@ -101,6 +103,14 @@ static int da9063_bind(struct udevice *dev) if (!children) debug("%s: %s - no child found\n", __func__, dev->name); + if (CONFIG_IS_ENABLED(SYSRESET)) { + ret = device_bind_driver(dev, "da9063-sysreset", + "da9063-sysreset", NULL); + if (ret) + debug("%s: %s - failed to bind sysreset driver\n", + __func__, dev->name); + } + /* Always return success for this device */ return 0; } @@ -129,3 +139,42 @@ U_BOOT_DRIVER(pmic_da9063) = { .probe = da9063_probe, .ops = &da9063_ops, }; + +#ifdef CONFIG_SYSRESET +#include + +static int da9063_sysreset_request(struct udevice *dev, enum sysreset_t type) +{ + struct udevice *pmic_dev = dev->parent; + uint ret; + + if (type != SYSRESET_WARM && type != SYSRESET_COLD) + return -EPROTONOSUPPORT; + + ret = pmic_reg_write(pmic_dev, DA9063_REG_PAGE_CON, 0x00); + if (ret < 0) + return ret; + + /* Sets the WAKE_UP bit */ + ret = pmic_reg_write(pmic_dev, DA9063_REG_CONTROL_F, 0x04); + if (ret < 0) + return ret; + + /* Powerdown! */ + ret = pmic_reg_write(pmic_dev, DA9063_REG_CONTROL_A, 0x68); + if (ret < 0) + return ret; + + return -EINPROGRESS; +} + +static struct sysreset_ops da9063_sysreset_ops = { + .request = da9063_sysreset_request, +}; + +U_BOOT_DRIVER(da9063_sysreset) = { + .name = "da9063-sysreset", + .id = UCLASS_SYSRESET, + .ops = &da9063_sysreset_ops, +}; +#endif