Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp168060ybl; Tue, 7 Jan 2020 04:13:01 -0800 (PST) X-Google-Smtp-Source: APXvYqxTjsWNr3c2kA/YaDMuq92eUVMMcydo8SZx9XBRe2IhmE201ssWY0niqWSirPff+O/XRL5X X-Received: by 2002:a9d:7b4e:: with SMTP id f14mr123644091oto.355.1578399181487; Tue, 07 Jan 2020 04:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578399181; cv=none; d=google.com; s=arc-20160816; b=brAQH2drxMzrAK1UG5mdNCjyM6G0cqSsSV63Vsm46b2XQlnxx5q/VGed9XTI+zHtTr PsHuItD13yXOa91a7gHRnWFGp/KVy/TC2JO8TsBcBcw/akSNEonsScZa69obRyp2nMdv OdvNatRRwRsfJgvfj5hzN0uLS4muDKtzuvzlbWOtv8lw+cUbSFceKs82V9cx9aHm7QfC +C0RuBunEvrkGq3Ni/ULbufpCNvilRbPQ74d/Uw7tTMy6l4egTZlEW5D4Hzs4FReaSbi VikNySZCs4v02Fk5GBOFwS/MXT4gAU9s/z0cmVyIIyqfHKB6gTUkv0ec3YLVf/yvVjCV 5mdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=IyyrdIDQlwVJClfzGwNhR8Zly4pMsd9+TJ5wRCXLDtM=; b=vksKGqSSSb7RztbnfIHDPm+CUvjX869UoQ3F9I18b8+Hyy9EdztnMd26iU+0Fd30MI 1umXAKeDEIh8V7Dn8AjvIuAyPUQbq0rt+4/khYy0+dtfMXwaTwns0oV9Raqx5yiYIj7D b0tMA/ajHyDEhK21f+/s7qgj7ulVKzZnuobPCKXWgaokBWPNQV+d6hO5TeoXr1NUUoFz JhyRjIj2v1PDBXZC9C7rX4LOo8oDGu0TgLhJb0Hv7KAnZRDoFAnfp91/w5nDRh7Xp1XW OyS0DDgjVPYjxMdyi9p67XJ4iqaUZqoAH8f9YmQecVFnhf1SyZPfJwCJDl3sO9zGTCR3 Ymbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intenta.de header.s=dkim1 header.b=izslhIGq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intenta.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si35208673otr.293.2020.01.07.04.12.49; Tue, 07 Jan 2020 04:13:01 -0800 (PST) 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; dkim=pass header.i=@intenta.de header.s=dkim1 header.b=izslhIGq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intenta.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbgAGMME (ORCPT + 99 others); Tue, 7 Jan 2020 07:12:04 -0500 Received: from mail.intenta.de ([178.249.25.132]:31287 "EHLO mail.intenta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726937AbgAGMME (ORCPT ); Tue, 7 Jan 2020 07:12:04 -0500 X-Greylist: delayed 355 seconds by postgrey-1.27 at vger.kernel.org; Tue, 07 Jan 2020 07:12:03 EST DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=intenta.de; s=dkim1; h=Content-Type:MIME-Version:Message-ID:Subject:CC:To:From:Date; bh=IyyrdIDQlwVJClfzGwNhR8Zly4pMsd9+TJ5wRCXLDtM=; b=izslhIGqY/ast6R96SpD0DtDi5NakZBPyOMQtkFRXaL8JaF7UgbEZy7oKKbW/EQ7ANu+IwvaLUpj/6TrSd9wFzro5hOZZ+snHV4dUAuTfkXuPxcz4IybuRoM9JNwl2DmIefAHQrBLVSxQ5rBCzz56QFqeghi8vXvEoQ3dGdaM3RgSvhnNuTo97YymO8zRoC3NltdFmkbIngEyCt60ShTuofJcT1zb7swvgAirCFzA0Lkn/ev74jVvkx9j4mCW5p8gA6B+KEsI8S42tKWTKh58R77B6NLmF+JUc7Aibzr+7oBDB6qX9jsZ929cs+pG70QQdLRSojTe4vN55C6JDeT/g==; Date: Tue, 7 Jan 2020 13:06:03 +0100 From: Helmut Grohne To: Support Opensource , Lee Jones CC: Subject: [PATCH 1/2] mfd: da9062: enable being a system-power-controller Message-ID: <20200107120559.GA700@laureti-dev> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-ClientProxiedBy: ICSMA002.intenta.de (10.10.16.48) To ICSMA002.intenta.de (10.10.16.48) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DA9062 can be the device used to power the CPU. In that case, it can be used to power off the system. In the CONTROL_A register, the M_*_EN bits must be zero for the corresponding *_EN bits to have an effect. We zero them all to turn off the system. Signed-off-by: Helmut Grohne --- drivers/mfd/da9062-core.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) This patch includes the functionality into the da9062-core driver. If that is not the preferred way to integrate it, it can be added as a mfd_cell instead. In that case, I can move the functionality to a new drivers/power/reset/da9062-poweroff.c. As far as I can see, doing so implies that we can no longer use the standard system-power-controller property though and must use a new compatible property dlg,da9062-poweroff. Please let me know your preference. diff --git a/drivers/mfd/da9062-core.c b/drivers/mfd/da9062-core.c index e69626867c26..a2b5dfee677f 100644 --- a/drivers/mfd/da9062-core.c +++ b/drivers/mfd/da9062-core.c @@ -572,6 +572,23 @@ static const struct of_device_id da9062_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, da9062_dt_ids); +/* Hold client since pm_power_off is global. */ +static struct i2c_client *da9062_i2c_client; + +static void da9062_power_off(void) +{ + struct da9062 *chip = i2c_get_clientdata(da9062_i2c_client); + const unsigned int mask = DA9062AA_SYSTEM_EN_MASK | + DA9062AA_POWER_EN_MASK | DA9062AA_POWER1_EN_MASK | + DA9062AA_M_SYSTEM_EN_MASK | DA9062AA_M_POWER_EN_MASK | + DA9062AA_M_POWER1_EN_MASK; + int ret = regmap_update_bits(chip->regmap, DA9062AA_CONTROL_A, mask, 0); + + if (ret < 0) + dev_err(&da9062_i2c_client->dev, + "DA9062AA_CONTROL_A update failed, %d\n", ret); +} + static int da9062_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -661,6 +678,15 @@ static int da9062_i2c_probe(struct i2c_client *i2c, return ret; } + if (of_device_is_system_power_controller(i2c->dev.of_node)) { + if (!pm_power_off) { + da9062_i2c_client = i2c; + pm_power_off = da9062_power_off; + } else { + dev_warn(&i2c->dev, "Poweroff callback already assigned\n"); + } + } + return ret; } @@ -668,6 +694,11 @@ static int da9062_i2c_remove(struct i2c_client *i2c) { struct da9062 *chip = i2c_get_clientdata(i2c); + if (pm_power_off == da9062_power_off) + pm_power_off = NULL; + if (da9062_i2c_client) + da9062_i2c_client = NULL; + mfd_remove_devices(chip->dev); regmap_del_irq_chip(i2c->irq, chip->regmap_irq); -- 2.20.1