Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2620368pxb; Tue, 21 Sep 2021 04:08:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvjU93WE+eR3TbwIZg7IwAu2FZqB0QJsT7sKZ8//8bRx+QO8mc6aXYRE1h+9N+bj56+5FN X-Received: by 2002:aa7:c80a:: with SMTP id a10mr34487957edt.174.1632222492716; Tue, 21 Sep 2021 04:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632222492; cv=none; d=google.com; s=arc-20160816; b=EdQrY7tOIYNjXdqBkWNf4z2Y4S3laUcit3UY9021GWm9m8vn+GdYuHbEExvw0ZiCNX jVourCnhQjkBBtcLeU0vsMmNUJG/FQKKBjQH/7i90nEPdzbxucv03ImcW540e0GRt8yG tXqW66ThOeMKHg9FFnA2EN/2EWDKPMDR4oNQz2ezqOIowwawedm3wKvzZqI/A8FzoTFw C2A15t9ujlZB1Bib1pd9R7UgSqYyHSSwOIlm+3np5BaHZam0OQrrJY1Q9gewv+sAI8mq SeonIeDQY9S2u8sAo1PxmMluF/E1jsp3y5jnb/h/956GTZ42IVxsueVzBzmRna2h/voa 70QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:to:subject; bh=vWyHaTmZXP9bnNInvoS1bKjfkYHVYoqlZmYd6EJYyo8=; b=JagzHx5i8oPc1HIldqIvwAh3V/IRx0TjN9bV7nPWo4Iv/8qwGC+/96dkeF8cgwCQRL m55eB/IsflzKUL1j5r5R+QMxK0gqr8N5R8CGOML0eexavkObq0UHsmabIjAhXdQLS92o ujqN8bHL9AfsMnxrfDI3myaEIn6jzI3EurR7dVzXWfB1HUPVOaXpdZElOi053ht6lXKI LNBJIvT4HAhAlxCUVZ3+F3j5SAuNVtgWut4lYd3UAagOCO5S31VaZ0PL6B/49VY37Yrd HGENEhEgQCwoO6Sw6ojjLiGG1bLx31kvX5GnhAdlrhzxntBWDQ02CiXW9V3U4c2GIr80 /fGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r23si3428777edq.233.2021.09.21.04.07.47; Tue, 21 Sep 2021 04:08:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=codethink.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbhIULGI (ORCPT + 99 others); Tue, 21 Sep 2021 07:06:08 -0400 Received: from imap3.hz.codethink.co.uk ([176.9.8.87]:49320 "EHLO imap3.hz.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232220AbhIULGH (ORCPT ); Tue, 21 Sep 2021 07:06:07 -0400 X-Greylist: delayed 2369 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Sep 2021 07:06:07 EDT Received: from [167.98.27.226] (helo=[10.35.5.170]) by imap3.hz.codethink.co.uk with esmtpsa (Exim 4.92 #3 (Debian)) id 1mScxX-0002QA-8i; Tue, 21 Sep 2021 11:25:07 +0100 Subject: Re: [PATCH] drivers: mfd: da9063: Add restart notifier implementation To: Alexandre Ghiti , Support Opensource , Lee Jones , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20210921053356.1705833-1-alexandre.ghiti@canonical.com> From: Ben Dooks Organization: Codethink Limited. Message-ID: <28072b8e-2c32-e67d-19d3-026913c0bc7f@codethink.co.uk> Date: Tue, 21 Sep 2021 11:25:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20210921053356.1705833-1-alexandre.ghiti@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/09/2021 06:33, Alexandre Ghiti wrote: > The SiFive Unmatched board uses the da9063 PMIC for reset: add a restart > notifier that will execute a small i2c sequence allowing to reset the > board. > > The original implementation comes from Marcus Comstedt and Anders Montonen > (https://forums.sifive.com/t/reboot-command/4721/28). > > Signed-off-by: Alexandre Ghiti I've got a couple of comments here, mainly is this the right place and has anyone other than you tested. I tried something similar on my Unmatched and it just turned the board off. > --- > drivers/mfd/da9063-core.c | 25 +++++++++++++++++++++++++ > include/linux/mfd/da9063/core.h | 3 +++ > 2 files changed, 28 insertions(+) > > diff --git a/drivers/mfd/da9063-core.c b/drivers/mfd/da9063-core.c > index df407c3afce3..c87b8d611f20 100644 > --- a/drivers/mfd/da9063-core.c > +++ b/drivers/mfd/da9063-core.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -158,6 +159,18 @@ static int da9063_clear_fault_log(struct da9063 *da9063) > return ret; > } > > +static int da9063_restart_notify(struct notifier_block *this, > + unsigned long mode, void *cmd) > +{ > + struct da9063 *da9063 = container_of(this, struct da9063, restart_handler); > + > + regmap_write(da9063->regmap, DA9063_REG_PAGE_CON, 0x00); > + regmap_write(da9063->regmap, DA9063_REG_CONTROL_F, 0x04); > + regmap_write(da9063->regmap, DA9063_REG_CONTROL_A, 0x68); > + > + return NOTIFY_DONE; > +} > + Firstly, do you also need to force the AUTOBOOT (bit 3, CONTROL_C) to ensure the PMIC does restart. > int da9063_device_init(struct da9063 *da9063, unsigned int irq) > { > int ret; > @@ -197,6 +210,18 @@ int da9063_device_init(struct da9063 *da9063, unsigned int irq) > } > } > > + da9063->restart_handler.notifier_call = da9063_restart_notify; > + da9063->restart_handler.priority = 128; > + ret = register_restart_handler(&da9063->restart_handler); > + if (ret) { > + dev_err(da9063->dev, "Failed to register restart handler\n"); > + return ret; > + } > + > + devm_add_action(da9063->dev, > + (void (*)(void *))unregister_restart_handler, > + &da9063->restart_handler); there's devm_register_reboot_notifier() > + > return ret; > } > > diff --git a/include/linux/mfd/da9063/core.h b/include/linux/mfd/da9063/core.h > index fa7a43f02f27..1b20c498e340 100644 > --- a/include/linux/mfd/da9063/core.h > +++ b/include/linux/mfd/da9063/core.h > @@ -85,6 +85,9 @@ struct da9063 { > int chip_irq; > unsigned int irq_base; > struct regmap_irq_chip_data *regmap_irq; > + > + /* Restart */ > + struct notifier_block restart_handler; > }; > > int da9063_device_init(struct da9063 *da9063, unsigned int irq); Note, the watchdog driver for the DA9063 also has a restart method although it also does not set the AUTOBOOT bit either. The best thing is to enable the watchdog driver, the SiFive release does not have either the core DA9063 or the watchdog driver for it enabled. -- Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html