From patchwork Mon Aug 30 10:09:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12464839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 553BAC432BE for ; Mon, 30 Aug 2021 10:12:03 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1A64F6108E for ; Mon, 30 Aug 2021 10:12:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1A64F6108E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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: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:In-Reply-To:References: List-Owner; bh=mGrVhaJO1pl0F0rQsbzKiSK19AGgWPyQQKP6N7O3zaI=; b=AEB+spHCMHQwQo Z0KIY8OWN9JdcqXswXxQn+6wfNnJHGivKk+N5xGIWtdpQ+fGvGr6cdS8KdEISwRX+0aQo+BiP1WLs O0wPnuE2ZLAQrMtRWt2IK9qkkO3c556QXzutrfvMFAfwQ6SUgz32sTN35zeH36yr0IS+MXmd1f2Tk H0T8A5j3ZByyWUXjX9Kc9onM3e/Ta/5fS6fIa5aWxOd8+F0ezgMqm9SJF6ny0x/qTeGmPhNPF/pjc kQ4ZAIhcUnHH8vP9YuEmF54FRlKaxUsR6YJa5wOUVWhI6JGpGKfb5jVC9cv5qqN7Hhg3BYVw1cYWp QTJnRYfI7Dk8Vjmb3eVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mKeEZ-00Gy9u-Sr; Mon, 30 Aug 2021 10:09:44 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mKeET-00Gy8y-5H for linux-arm-kernel@lists.infradead.org; Mon, 30 Aug 2021 10:09:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1630318176; x=1661854176; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=SoTCnikdgf21XcZdMwzYaqI+NZ+PtkhKdXux8qvsieo=; b=xtEjmDchE6iY4qAfopY7tdOCsM5hMjuX7yBOFB0oQ2KemXncJ1sVQvm1 Nxb6eOjHtTFuxPwZOCsgP+u6/52aqQyeHjnozvfYRJC4atK6jitEqaa6l fJslVWwA8dEnFsImjmPNbwdtdEpGKXHlKMhE1qEzNvaAB2Og3Pq5f0BEb gL8215V3fipGwh6nQhwoMgnNSRlVale7nCwGSU5yaRY09GChKjlFM+d3z mcA8K2EC8ANKaV7qnEncKDWVwIOljlzhBrwzb5fiQeogYAd0Qa9QmCMmd YJZuG0SlzADowLCyD2EhH6H6XFa/vvo6xEL0XtgwcwsDos/IFGmz0M1/G w==; IronPort-SDR: 4T4vwwYIncsecFxlp5h/c8QbNX4IxLSceq5/odL52lcreFdly7Vjax5UO79sXnoqjOakbH4QC+ RmEIZqpwFBqlYw3A1YB8jfOKYSQPcXI7QjlHrw7vHa8zUbSKnJar5HD+f+BSiXtM0/dm8v5bDt C1OBPwlPCinNJO+iyr9226wmFxjCiJ19xElp+znInps3mVhy4fmQsno7BSC4leMoZvQy5y2+CY ltzam7hoKa5+r4qY9N4nvJUDnTffzFAlFyN5bpHBY5DdRpQIqIzBUwsgrr1GM8OS1z+sxyjT6g miDDPT+XhnRnF7OwfT3XgXlX X-IronPort-AV: E=Sophos;i="5.84,363,1620716400"; d="scan'208";a="127552924" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 Aug 2021 03:09:35 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Mon, 30 Aug 2021 03:09:35 -0700 Received: from rob-dk-mpu01.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Mon, 30 Aug 2021 03:09:34 -0700 From: Claudiu Beznea To: , , , CC: , , Claudiu Beznea Subject: [PATCH] ARM: at91: pm: switch backup area to vbat in backup mode Date: Mon, 30 Aug 2021 13:09:27 +0300 Message-ID: <20210830100927.22711-1-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210830_030937_310561_AB8D4474 X-CRM114-Status: GOOD ( 18.23 ) 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 Backup area is now switched to VDDIN33 at boot (with the help of bootloader). When switching to backup mode we need to switch backup area to VBAT as all the other power sources are cut off. The resuming from backup mode is done with the help of bootloader, so there is no need to do something particular in Linux to restore backup area power source. Signed-off-by: Claudiu Beznea Acked-by: Nicolas Ferre --- Hi Nicolas, This applies clean on top of patch with title "ARM: at91: pm: do not panic if ram controllers are not enabled" Thank you, Claudiu Beznea arch/arm/mach-at91/pm.c | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c index d92afca64b49..8711d6824c1f 100644 --- a/arch/arm/mach-at91/pm.c +++ b/arch/arm/mach-at91/pm.c @@ -47,12 +47,26 @@ struct at91_pm_bu { unsigned long ddr_phy_calibration[BACKUP_DDR_PHY_CALIBRATION]; }; +/* + * struct at91_pm_sfrbu_offsets: registers mapping for SFRBU + * @pswbu: power switch BU control registers + */ +struct at91_pm_sfrbu_regs { + struct { + u32 key; + u32 ctrl; + u32 state; + u32 softsw; + } pswbu; +}; + /** * struct at91_soc_pm - AT91 SoC power management data structure * @config_shdwc_ws: wakeup sources configuration function for SHDWC * @config_pmc_ws: wakeup srouces configuration function for PMC * @ws_ids: wakup sources of_device_id array * @data: PM data to be used on last phase of suspend + * @sfrbu_regs: SFRBU registers mapping * @bu: backup unit mapped data (for backup mode) * @memcs: memory chip select */ @@ -62,6 +76,7 @@ struct at91_soc_pm { const struct of_device_id *ws_ids; struct at91_pm_bu *bu; struct at91_pm_data data; + struct at91_pm_sfrbu_regs sfrbu_regs; void *memcs; }; @@ -356,9 +371,36 @@ static int at91_suspend_finish(unsigned long val) return 0; } +static void at91_pm_switch_ba_to_vbat(void) +{ + unsigned int offset = offsetof(struct at91_pm_sfrbu_regs, pswbu); + unsigned int val; + + /* Just for safety. */ + if (!soc_pm.data.sfrbu) + return; + + val = readl(soc_pm.data.sfrbu + offset); + + /* Already on VBAT. */ + if (!(val & soc_pm.sfrbu_regs.pswbu.state)) + return; + + val &= ~soc_pm.sfrbu_regs.pswbu.softsw; + val |= soc_pm.sfrbu_regs.pswbu.key | soc_pm.sfrbu_regs.pswbu.ctrl; + writel(val, soc_pm.data.sfrbu + offset); + + /* Wait for update. */ + val = readl(soc_pm.data.sfrbu + offset); + while (val & soc_pm.sfrbu_regs.pswbu.state) + val = readl(soc_pm.data.sfrbu + offset); +} + static void at91_pm_suspend(suspend_state_t state) { if (soc_pm.data.mode == AT91_PM_BACKUP) { + at91_pm_switch_ba_to_vbat(); + cpu_suspend(0, at91_suspend_finish); /* The SRAM is lost between suspend cycles */ @@ -1155,6 +1197,11 @@ void __init sama5d2_pm_init(void) soc_pm.ws_ids = sama5d2_ws_ids; soc_pm.config_shdwc_ws = at91_sama5d2_config_shdwc_ws; soc_pm.config_pmc_ws = at91_sama5d2_config_pmc_ws; + + soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8); + soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0); + soc_pm.sfrbu_regs.pswbu.softsw = BIT(1); + soc_pm.sfrbu_regs.pswbu.state = BIT(3); } void __init sama7_pm_init(void) @@ -1185,6 +1232,11 @@ void __init sama7_pm_init(void) soc_pm.ws_ids = sama7g5_ws_ids; soc_pm.config_pmc_ws = at91_sam9x60_config_pmc_ws; + + soc_pm.sfrbu_regs.pswbu.key = (0x4BD20C << 8); + soc_pm.sfrbu_regs.pswbu.ctrl = BIT(0); + soc_pm.sfrbu_regs.pswbu.softsw = BIT(1); + soc_pm.sfrbu_regs.pswbu.state = BIT(2); } static int __init at91_pm_modes_select(char *str)