Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp594307ybm; Mon, 20 May 2019 23:37:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwY+vub9q7WHmz0MUIMHlQrvwUn9V79Gm7PKGFtKrvZHtuJlSuRgoT2tD4zLM5AhgBAbENO X-Received: by 2002:a65:42c3:: with SMTP id l3mr56065166pgp.372.1558420648955; Mon, 20 May 2019 23:37:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558420648; cv=none; d=google.com; s=arc-20160816; b=nxIwrwLKkXUAIpXRXRL2JkTXkYNrWwfnSia/W2Ktf18CiTx0u2CTPuWZ6zXsTSef+F KvhVcAd/fvjsCO4d7d1zQZ/2tjBAJI7OHvFw4djsll+AimaTOxkOPCiTJuRENqmXB5vU wiIiKqOkhJdtbiU2D/PCHO2taZNL14Ml5671TcInhgr1QMveZ36hPJSm479iECRIRYdk GyqoXqd2RhN8/7aYDYlzr2Q5KCt8ZtRHhexLMNR0SSgBnt8LdkCYr3qrMC6a5GlVgxf3 WHwHO31Imoi9uCgJkQ5KJCdUfyjjrkdjpbL97up5MG7DtoNV+p2305lxEI0EBIPAlFil LBWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=r9OrPlnBItmzT5Lh5NQuG7COb7Ei9/WlTEsyn6IFVA4=; b=RY/oK36agBnFgzoK59Qu2sS5iVUMydKWfjVSdqzrdrkUYZ599t+2tMBrLK6jhPibmW oX2UGbDQqEYdsJC5kCiEcGp+042MW4bOfQxlYMmWldW0+3sS9gqrOQZ/4cTvbRc74PmW y5NFZ8uUwZGWhhkAv/bP9Votsvx9m3PGeb8U/+OxPfPwRWp+j/ELrZobS8ry9b/xVV2V aWsJvRuDykJhc0LGnQO3r/7kHNeEVj4A2ZfJZjhYXEwgxRkdqj1tIo5iGpCRUivLI+nR I6idZhMZHGmoCl2OAvZ0RC4OgpE1MpLDBSG+n852b9o7m73eKshIxtyDpqKD9Mg08BAY NL0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si18688565pgc.267.2019.05.20.23.37.14; Mon, 20 May 2019 23:37:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728010AbfEUGfj (ORCPT + 99 others); Tue, 21 May 2019 02:35:39 -0400 Received: from olimex.com ([184.105.72.32]:33921 "EHLO olimex.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725835AbfEUGfi (ORCPT ); Tue, 21 May 2019 02:35:38 -0400 Received: from localhost.localdomain ([94.155.250.134]) by olimex.com with ESMTPSA (ECDHE-RSA-AES128-GCM-SHA256:TLSv1.2:Kx=ECDH:Au=RSA:Enc=AESGCM(128):Mac=AEAD) (SMTP-AUTH username stefan@olimex.com, mechanism PLAIN) for ; Mon, 20 May 2019 23:25:34 -0700 From: Stefan Mavrodiev To: Heiko Stuebner , Lee Jones , linux-kernel@vger.kernel.org Cc: Stefan Mavrodiev Subject: [PATCH v2 2/2] mfd: rk808: Prepare rk805 for poweroff Date: Tue, 21 May 2019 09:24:49 +0300 Message-Id: <20190521062449.29410-3-stefan@olimex.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190521062449.29410-1-stefan@olimex.com> References: <20190521062449.29410-1-stefan@olimex.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org RK805 has SLEEP signal, which can put the device into SLEEP or OFF mode. The default is SLEEP mode. However, when the kernel performs power-off (actually the ATF) the device will not go fully off and this will result in higher power consumption and inability to wake the device with RTC alarm. The solution is to enable pm_power_off_prepare function, which will configure SLEEP pin for OFF function. Signed-off-by: Stefan Mavrodiev --- Changes for v2: - Move pm_pwroff_prep_fn to header - Check pm_power_off_prepare before make it NULL drivers/mfd/rk808.c | 29 +++++++++++++++++++++++++++++ include/linux/mfd/rk808.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c index c0b179792bbf..fb6cdf900899 100644 --- a/drivers/mfd/rk808.c +++ b/drivers/mfd/rk808.c @@ -387,6 +387,24 @@ static void rk805_device_shutdown(void) dev_err(&rk808_i2c_client->dev, "power off error!\n"); } +static void rk805_device_shutdown_prepare(void) +{ + int ret; + struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client); + + if (!rk808) { + dev_warn(&rk808_i2c_client->dev, + "have no rk805, so do nothing here\n"); + return; + } + + ret = regmap_update_bits(rk808->regmap, + RK805_GPIO_IO_POL_REG, + SLP_SD_MSK, SHUTDOWN_FUN); + if (ret) + dev_err(&rk808_i2c_client->dev, "power off error!\n"); +} + static void rk808_device_shutdown(void) { int ret; @@ -475,6 +493,7 @@ static int rk808_probe(struct i2c_client *client, cells = rk805s; nr_cells = ARRAY_SIZE(rk805s); rk808->pm_pwroff_fn = rk805_device_shutdown; + rk808->pm_pwroff_prep_fn = rk805_device_shutdown_prepare; break; case RK808_ID: rk808->regmap_cfg = &rk808_regmap_config; @@ -550,6 +569,12 @@ static int rk808_probe(struct i2c_client *client, pm_power_off = rk808->pm_pwroff_fn; } + if (pm_off && !pm_power_off_prepare) { + if (!rk808_i2c_client) + rk808_i2c_client = client; + pm_power_off_prepare = rk808->pm_pwroff_prep_fn; + } + return 0; err_irq: @@ -566,6 +591,10 @@ static int rk808_remove(struct i2c_client *client) if (rk808->pm_pwroff_fn && pm_power_off == rk808->pm_pwroff_fn) pm_power_off = NULL; + if (rk808->pm_pwroff_prep_fn && + pm_power_off_prepare == rk808->pm_pwroff_prep_fn) + pm_power_off_prepare = NULL; + return 0; } diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h index 8b5d68a7bb9c..ec928173e507 100644 --- a/include/linux/mfd/rk808.h +++ b/include/linux/mfd/rk808.h @@ -454,5 +454,6 @@ struct rk808 { const struct regmap_config *regmap_cfg; const struct regmap_irq_chip *regmap_irq_chip; void (*pm_pwroff_fn)(void); + void (*pm_pwroff_prep_fn)(void); }; #endif /* __LINUX_REGULATOR_RK808_H */ -- 2.17.1