From patchwork Wed Aug 3 23:05:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 73233 Delivered-To: patches@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1099035qga; Wed, 3 Aug 2016 16:05:35 -0700 (PDT) X-Received: by 10.67.7.9 with SMTP id cy9mr115113688pad.155.1470265533018; Wed, 03 Aug 2016 16:05:33 -0700 (PDT) Return-Path: Received: from mail-pf0-x22a.google.com (mail-pf0-x22a.google.com. [2607:f8b0:400e:c00::22a]) by mx.google.com with ESMTPS id p29si11049940pfj.147.2016.08.03.16.05.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Aug 2016 16:05:33 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22a as permitted sender) client-ip=2607:f8b0:400e:c00::22a; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22a as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x22a.google.com with SMTP id h186so81428635pfg.3 for ; Wed, 03 Aug 2016 16:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zFSgXMfSDzQrCu3UebMdgWEJIiNkwUhyhMcdafy8Kqg=; b=LfqVZEAKbZxHY+rqVeViCXukJZX1VFSD9EMqYIjUgOUez99F4uR4civuCyLvZryV29 d46GMNvpzJCw+t9+GL5kBlZR5tk1dIz+MgGQ3hztSAu0Ix3ZNXowBE+ncflXGP525Mur kdG418qeTdAfFMlpWOn3c1Oy7RYjOVOL36nH4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zFSgXMfSDzQrCu3UebMdgWEJIiNkwUhyhMcdafy8Kqg=; b=FOGArWt7hXaYL6Bo0p2wQ0XjZV++b4a6Uw2tQw/WBZd0tsaFsG1u8dXsNNWv724Ey0 WNfeXOjj0HHYrmRdax2lwWibnK/3WmgHS9jvZW1yrj9usGPVTnMIkQH17FoOxDHw7RMj uMu6NWX1bKqhOhIZr7wYP4ijzWcZDUKlJQekVRiIO2UO7DyMcoKIb9PtyW1NjyoIdgNI UiSogLKmBAzXdNxBDykNvMTc0m+tYTYSJ+vCFTXGf848QW8g2Ouvezo2KoglgLwBO+eK IbfYfDW15JoOYNdQM2mtpWmq0JT1szgJoDGI2kIvHRLtZwM5r2fhwbZg8YdUJWDEF4Mq pg2w== X-Gm-Message-State: AEkoouuZzE4hq0hliQGnRnOameemxf/unEqodN0zAkFIF8QdgPR0d+q8Fem3UVtQxY86jSmuceY= X-Received: by 10.98.48.65 with SMTP id w62mr120064498pfw.18.1470265532753; Wed, 03 Aug 2016 16:05:32 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id m24sm15050482pfi.34.2016.08.03.16.05.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Aug 2016 16:05:32 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Andy Yan , Rob Herring , Arnd Bergmann , Thierry Reding , =?UTF-8?q?Heiko=20St=C3=BCbner?= , Caesar Wang , Kees Cook , Guodong Xu , Haojian Zhuang , Vishal Bhoj , Bjorn Andersson , devicetree@vger.kernel.org, Android Kernel Team Subject: [RFC][PATCH 3/4] power: reset: Add sram-reboot-mode driver Date: Wed, 3 Aug 2016 16:05:22 -0700 Message-Id: <1470265523-27557-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470265523-27557-1-git-send-email-john.stultz@linaro.org> References: <1470265523-27557-1-git-send-email-john.stultz@linaro.org> MIME-Version: 1.0 Add sram-reboot-mode driver, which enables reboot modes to be specified from sram subnodes. Cc: Andy Yan Cc: Rob Herring Cc: Arnd Bergmann Cc: Thierry Reding Cc: Heiko Stübner Cc: Caesar Wang Cc: Kees Cook Cc: Guodong Xu Cc: Haojian Zhuang Cc: Vishal Bhoj Cc: Bjorn Andersson Cc: devicetree@vger.kernel.org Cc: Android Kernel Team Signed-off-by: John Stultz --- drivers/power/reset/Kconfig | 10 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/sram-reboot-mode.c | 95 ++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 drivers/power/reset/sram-reboot-mode.c -- 1.9.1 diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index 3bfac53..af553ed 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -208,5 +208,15 @@ config SYSCON_REBOOT_MODE register, then the bootloader can read it to take different action according to the mode. +config SRAM_REBOOT_MODE + bool "Generic SRAM reboot mode driver" + select REBOOT_MODE + select SRAM + help + Say y here will enable reboot mode driver. This will + get reboot mode arguments and store it in an SRAM + address, then the bootloader can read it to take different + action according to the mode. + endif diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 1be307c..14f23ad 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -24,3 +24,4 @@ obj-$(CONFIG_POWER_RESET_RMOBILE) += rmobile-reset.o obj-$(CONFIG_POWER_RESET_ZX) += zx-reboot.o obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o +obj-$(CONFIG_SRAM_REBOOT_MODE) += sram-reboot-mode.o diff --git a/drivers/power/reset/sram-reboot-mode.c b/drivers/power/reset/sram-reboot-mode.c new file mode 100644 index 0000000..8945dac --- /dev/null +++ b/drivers/power/reset/sram-reboot-mode.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2016, Linaro Limited + * Based on syscon-reboot-mode.c + * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "reboot-mode.h" + + + +struct sram_reboot_mode { + struct reboot_mode_driver reboot; + void __iomem *reboot_reason_val_addr; +}; + +static int sram_reboot_mode_write(struct reboot_mode_driver *reboot, + unsigned int magic) +{ + struct sram_reboot_mode *sram_rbm; + + sram_rbm = container_of(reboot, struct sram_reboot_mode, reboot); + + writel(magic, sram_rbm->reboot_reason_val_addr); + return 0; +} + +static int sram_reboot_mode_probe(struct platform_device *pdev) +{ + struct sram_reboot_mode *sram_rbm; + struct resource *res; + int ret; + + sram_rbm = devm_kzalloc(&pdev->dev, sizeof(*sram_rbm), GFP_KERNEL); + if (!sram_rbm) + return -ENOMEM; + + sram_rbm->reboot.dev = &pdev->dev; + sram_rbm->reboot.write = sram_reboot_mode_write; + + dev_set_drvdata(&pdev->dev, sram_rbm); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return PTR_ERR(res); + + sram_rbm->reboot_reason_val_addr = devm_ioremap(&pdev->dev, res->start, + resource_size(res)); + if (IS_ERR(sram_rbm->reboot_reason_val_addr)) + return PTR_ERR(sram_rbm->reboot_reason_val_addr); + + ret = reboot_mode_register(&sram_rbm->reboot); + if (ret) + dev_err(&pdev->dev, "can't register reboot mode\n"); + + return ret; +} + +static int sram_reboot_mode_remove(struct platform_device *pdev) +{ + struct sram_reboot_mode *sram_rbm = dev_get_drvdata(&pdev->dev); + + return reboot_mode_unregister(&sram_rbm->reboot); +} + +static const struct of_device_id sram_reboot_mode_of_match[] = { + { .compatible = "sram-reboot-mode" }, + {} +}; + +static struct platform_driver sram_reboot_mode_driver = { + .probe = sram_reboot_mode_probe, + .remove = sram_reboot_mode_remove, + .driver = { + .name = "sram-reboot-mode", + .of_match_table = sram_reboot_mode_of_match, + }, +}; +module_platform_driver(sram_reboot_mode_driver); + +MODULE_AUTHOR("John Stultz "); +MODULE_DESCRIPTION("SRAM reboot mode driver"); +MODULE_LICENSE("GPL v2");