Received: by 10.213.65.68 with SMTP id h4csp1611218imn; Thu, 29 Mar 2018 07:51:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Jy0+kSLyCWmBIVjtCgnzBcagkSXbB3MvQEHBCOWlGu9slRKzrhuTxsOofJ+qPJVU85DXr X-Received: by 2002:a17:902:aa46:: with SMTP id c6-v6mr3111462plr.154.1522335102186; Thu, 29 Mar 2018 07:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522335102; cv=none; d=google.com; s=arc-20160816; b=CzbxCvDN0hJbNXE59THu/RCOZ8xsHevkADGq7/9rkbpREwmNLsW1JW3uvM9jxmXY/q 4sEgtESYTXZY7kGEkvnEvwkUAO8JrYAs3LJGdQwOjxT6TE/YAttjLZmpj+309aRXD33W HnBtXYTciAXUPAzJex5cs9AllCB+qwsyOMRqa6zFmitAwyL56MsEQkBNl+3/hqGqpv9I 5TpTlo8qZkJf+Aqtcc9FLw+Uk1Ok/Fe+sLj5cpX0D20YknS2DvoBUdXMWpdzIk4grZJl 3c8MHOLzNw5oKQqE8NPxrfocWAZOW6OInEgPaqXkEPXi8ycAkmZcUCLZjFbM0wfktoPO zRbA== 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:arc-authentication-results; bh=rujGLKzJNHDzwDuXtFiv/EirN/H++y9A/Tdo2X6Q7aA=; b=qCcUpqErxspNnnrrDasdRnYIHJF1xpY7Afzqp3zQ5PFB+xrbF66553yuxK4NIqnFPj NTXdpak8tFLOBuqAOKoA/MATShDuH+c7gDA1dy0rcWxgPuVbs8NZlYn3znrTv9O/sh1+ BzTD7K06bSzh2d8DJoQ/03UMRLG3Q7CF8+OosZbaAeihl7pwT0LXw5A6dthlbMTVvyA5 LL78q5o28TOvAfaP/nr2Rn9leGPfU0kvuXwPV+X7B/iWjr6I9dcwSM9Sk/imHot9+lkh I1G/tlud16pufG8Yj0TQGA+xbaMbg2nl11RBg2vDc+BewFrzbe5hawiZSBFU+PIOsFG9 zdDg== 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 b92-v6si6146316plb.514.2018.03.29.07.51.28; Thu, 29 Mar 2018 07:51:42 -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 S1751981AbeC2OuO (ORCPT + 99 others); Thu, 29 Mar 2018 10:50:14 -0400 Received: from mail.x-arc.de ([217.6.246.34]:56454 "EHLO root.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750979AbeC2OuC (ORCPT ); Thu, 29 Mar 2018 10:50:02 -0400 Received: from idefix.phytec.de (idefix.phytec.de [172.16.0.10]) by root.phytec.de (Postfix) with ESMTP id 3C9A9A0050E; Thu, 29 Mar 2018 16:50:13 +0200 (CEST) Received: from augenblix.phytec.de ([172.16.0.56]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2018032916500049-172209 ; Thu, 29 Mar 2018 16:50:00 +0200 From: Daniel Schultz To: lee.jones@linaro.org Cc: zyw@rock-chips.com, zhangqing@rock-chips.com, xsf@rock-chips.com, tony.xie@rock-chips.com, w.egorov@phytec.de, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/2] mfd: rk808: Add restart functionality Date: Thu, 29 Mar 2018 16:50:00 +0200 Message-Id: <1522335000-23057-2-git-send-email-d.schultz@phytec.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522335000-23057-1-git-send-email-d.schultz@phytec.de> References: <1522335000-23057-1-git-send-email-d.schultz@phytec.de> X-MIMETrack: Itemize by SMTP Server on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 29.03.2018 16:50:00, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 29.03.2018 16:50:00, Serialize complete at 29.03.2018 16:50:00 X-TNEFEvaluated: 1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When using Rockchip SoCs with rk805/808/818 PMICs, restarts are realized by setting the reset registers in the "Clock and Reset Unit". Now, the driver can trigger a restart in the PMIC. Like the shutdown function, the restart is bound to an independent "rockchip,system-reset-controller" devicetree property can easily enabled by adding this. Signed-off-by: Daniel Schultz --- Changes: v2: Re-submit with recipients from Rockchip. v3: - Added devicetree property to enable the PMIC reset seperate from "rockchip,system-power-controller". - Dropped the first patch of this serie. v4: Splitted refactoring and the new reset feature. v5: - drivers/mfd/rk808.c | 58 ++++++++++++++++++++++++++++++++++++++++++----- include/linux/mfd/rk808.h | 1 + 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c index 1cb1b3a..7f5c3d7 100644 --- a/drivers/mfd/rk808.c +++ b/drivers/mfd/rk808.c @@ -27,6 +27,7 @@ #include #include #include +#include struct rk808_reg_data { int addr; @@ -392,16 +393,49 @@ static void rk805_device_shutdown(void) { rk808_update_bits(RK805_DEV_CTRL_REG, DEV_OFF); } +static int rk805_restart_notify(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + rk808_update_bits(RK805_DEV_CTRL_REG, DEV_OFF_RST); + return NOTIFY_DONE; +} static void rk808_device_shutdown(void) { rk808_update_bits(RK808_DEVCTRL_REG, DEV_OFF_RST); } +static int rk808_restart_notify(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + rk808_update_bits(RK808_DEVCTRL_REG, DEV_OFF); + return NOTIFY_DONE; +} static void rk818_device_shutdown(void) { rk808_update_bits(RK818_DEVCTRL_REG, DEV_OFF); } +static int rk818_restart_notify(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + rk808_update_bits(RK818_DEVCTRL_REG, DEV_OFF_RST); + return NOTIFY_DONE; +} + +static struct notifier_block rk805_restart_handler = { + .notifier_call = rk805_restart_notify, + .priority = 196, +}; + +static struct notifier_block rk808_restart_handler = { + .notifier_call = rk808_restart_notify, + .priority = 196, +}; + +static struct notifier_block rk818_restart_handler = { + .notifier_call = rk818_restart_notify, + .priority = 196, +}; static const struct of_device_id rk808_of_match[] = { { .compatible = "rockchip,rk805" }, @@ -421,7 +455,7 @@ static int rk808_probe(struct i2c_client *client, void (*pm_pwroff_fn)(void); int nr_pre_init_regs; int nr_cells; - int pm_off = 0, msb, lsb; + int pm_off = 0, pm_rst_off = 0, msb, lsb; int ret; int i; @@ -456,6 +490,7 @@ static int rk808_probe(struct i2c_client *client, cells = rk805s; nr_cells = ARRAY_SIZE(rk805s); pm_pwroff_fn = rk805_device_shutdown; + rk808->nb = &rk805_restart_handler; break; case RK808_ID: rk808->regmap_cfg = &rk808_regmap_config; @@ -465,6 +500,7 @@ static int rk808_probe(struct i2c_client *client, cells = rk808s; nr_cells = ARRAY_SIZE(rk808s); pm_pwroff_fn = rk808_device_shutdown; + rk808->nb = &rk808_restart_handler; break; case RK818_ID: rk808->regmap_cfg = &rk818_regmap_config; @@ -474,6 +510,7 @@ static int rk808_probe(struct i2c_client *client, cells = rk818s; nr_cells = ARRAY_SIZE(rk818s); pm_pwroff_fn = rk818_device_shutdown; + rk808->nb = &rk818_restart_handler; break; default: dev_err(&client->dev, "Unsupported RK8XX ID %lu\n", @@ -524,13 +561,20 @@ static int rk808_probe(struct i2c_client *client, goto err_irq; } - pm_off = of_property_read_bool(np, - "rockchip,system-power-controller"); - if (pm_off && !pm_power_off) { - rk808_i2c_client = client; + rk808_i2c_client = client; + + pm_off = of_property_read_bool(np, "rockchip,system-power-controller"); + if (pm_off && !pm_power_off) pm_power_off = pm_pwroff_fn; - } + pm_rst_off = of_property_read_bool(np, + "rockchip,system-reset-controller"); + if (pm_rst_off && rk808->nb) { + ret = register_restart_handler(rk808->nb); + if (ret) + dev_err(&client->dev, + "cannot register restart handler, %d\n", ret); + } return 0; err_irq: @@ -544,6 +588,8 @@ static int rk808_remove(struct i2c_client *client) regmap_del_irq_chip(client->irq, rk808->irq_data); pm_power_off = NULL; + if (rk808->nb) + unregister_restart_handler(rk808->nb); return 0; } diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h index d315659..6f8583b 100644 --- a/include/linux/mfd/rk808.h +++ b/include/linux/mfd/rk808.h @@ -453,5 +453,6 @@ struct rk808 { long variant; const struct regmap_config *regmap_cfg; const struct regmap_irq_chip *regmap_irq_chip; + struct notifier_block *nb; }; #endif /* __LINUX_REGULATOR_RK808_H */ -- 2.7.4