From patchwork Fri Oct 14 02:02:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaogang Cui X-Patchwork-Id: 9376029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E164E60839 for ; Fri, 14 Oct 2016 02:16:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C860C29F3C for ; Fri, 14 Oct 2016 02:16:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB81F29F54; Fri, 14 Oct 2016 02:16:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BB4629F3C for ; Fri, 14 Oct 2016 02:16:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756057AbcJNCQl (ORCPT ); Thu, 13 Oct 2016 22:16:41 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:39206 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752376AbcJNCQj (ORCPT ); Thu, 13 Oct 2016 22:16:39 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 313356183D; Fri, 14 Oct 2016 02:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1476410850; bh=Afc/akVLsJfok0qazrKlhHh+padKbjU1gt9AJBlHzVc=; h=From:To:Cc:Subject:Date:From; b=PaCUXVDHkqk9JzjsKTw6weV2bDqyK33y5yXjXzGQQgxZRoKOYD65/lK7mQtqqBJDY KwgM297ttTqoqCvh9cnaDoDDggSvbj225ORrD67Pw4bSjgIH1r2V7hJWxwWV6OgZnT HimM+nCbVS1W55nSDJABpkVxBnWlvkosieNJFwbY= Received: from XIAOGANG02.ap.qualcomm.com (unknown [180.166.53.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: xiaogang@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 930DA61739; Fri, 14 Oct 2016 02:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1476410848; bh=Afc/akVLsJfok0qazrKlhHh+padKbjU1gt9AJBlHzVc=; h=From:To:Cc:Subject:Date:From; b=j9crfePJnGez+iKdGXAanXYS4VJxvfvtnJawBGnoaEHDZ7u0BMPd6RtKlw0XI5waC ZClsgs3HBIXqoOAETnQbrnqpInWfB9w/a1tEzQ0TpiDFk01CXT7xkQOQ0TnQsoH9WL k08vwLf/H+Txuvnqd+E/++xQOu0Qj+h4CPvm6NGE= DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org 930DA61739 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=xiaogang@codeaurora.org From: Xiaogang Cui To: andy.gross@linaro.org Cc: Xiaogang Cui , Sebastian Reichel , Dmitry Eremin-Solenikov , David Woodhouse , Rob Herring , Mark Rutland , Krzysztof Kozlowski , Andy Yan , John Stultz , Alexandre Belloni , Nicolas Ferre , Chris Brand , Richard Weinberger , Moritz Fischer , Florian Fainelli , linux-pm@vger.kernel.org (open list:POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS), devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/2] power: reset: Add qcom reboot mode driver Date: Fri, 14 Oct 2016 10:02:27 +0800 Message-Id: <1476410823-8912-1-git-send-email-xiaogang@codeaurora.org> X-Mailer: git-send-email 2.7.2.windows.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a initial version so it's very similar with syscon reboot mode driver. We will add more functionalities in the further after dependency is ready. Signed-off-by: Xiaogang Cui --- .../bindings/power_supply/qcom-reboot-mode.txt | 23 +++++ drivers/power/reset/Kconfig | 10 ++ drivers/power/reset/Makefile | 1 + drivers/power/reset/qcom-reboot-mode.c | 109 +++++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 Documentation/devicetree/bindings/power_supply/qcom-reboot-mode.txt create mode 100644 drivers/power/reset/qcom-reboot-mode.c diff --git a/Documentation/devicetree/bindings/power_supply/qcom-reboot-mode.txt b/Documentation/devicetree/bindings/power_supply/qcom-reboot-mode.txt new file mode 100644 index 0000000..8b33592 --- /dev/null +++ b/Documentation/devicetree/bindings/power_supply/qcom-reboot-mode.txt @@ -0,0 +1,23 @@ +Qualcomm Reboot Mode Driver + +Qualcomm reboot mode driver based on reboot mode framework to update +SPMI specific bits. + +Required Properties: +-compatible: "qcom,reboot-mode" +-offset: offset of the SPMI reboot mode register + +Optional Properties: +-mask: mask of reboot mode +-mode-xxx: magic of reboot mode + +Example: + qcom,reboot-mode@88f { + compatible = "qcom,reboot-mode"; + offset = <0x88f>; + mode-normal = <0x00>; + mode-recovery = <0x04>; + mode-bootloader = <0x08>; + mode-rtc = <0x0C>; + }; + diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index c74c3f6..bdcf6d3f 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 QCOM_REBOOT_MODE + tristate "Qualcomm reboot mode driver" + depends on MFD_SPMI_PMIC + select REBOOT_MODE + help + Say y here will enable Qualcomm reboot mode driver. This will + get reboot mode arguments and store it in SPMI PMIC register, + 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..06e010f 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_QCOM_REBOOT_MODE) += qcom-reboot-mode.o diff --git a/drivers/power/reset/qcom-reboot-mode.c b/drivers/power/reset/qcom-reboot-mode.c new file mode 100644 index 0000000..37bb635 --- /dev/null +++ b/drivers/power/reset/qcom-reboot-mode.c @@ -0,0 +1,109 @@ +/* Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "reboot-mode.h" + +struct qcom_reboot_mode { + struct regmap *map; + struct reboot_mode_driver reboot; + u32 offset; + u32 mask; +}; + +static int qcom_reboot_mode_write(struct reboot_mode_driver *reboot, + unsigned int magic) +{ + struct qcom_reboot_mode *qrm; + int ret; + + qrm = container_of(reboot, struct qcom_reboot_mode, reboot); + + /* update reboot magic */ + ret = regmap_update_bits(qrm->map, qrm->offset, qrm->mask, magic); + if (ret < 0) { + dev_err(reboot->dev, "Failed to update reboot mode bits\n"); + return ret; + } + + return 0; +} + +static int qcom_reboot_mode_probe(struct platform_device *pdev) +{ + struct qcom_reboot_mode *qrm; + struct device *dev = &pdev->dev; + int ret; + + qrm = devm_kzalloc(&pdev->dev, sizeof(*qrm), GFP_KERNEL); + if (!qrm) + return -ENOMEM; + + qrm->reboot.dev = dev; + qrm->reboot.write = qcom_reboot_mode_write; + qrm->mask = 0xffffffff; + + qrm->map = dev_get_regmap(dev->parent, NULL); + if (IS_ERR_OR_NULL(qrm->map)) + return -EINVAL; + + if (of_property_read_u32(dev->of_node, "offset", &qrm->offset)) + return -EINVAL; + + of_property_read_u32(dev->of_node, "mask", &qrm->mask); + + ret = reboot_mode_register(&qrm->reboot); + if (ret) + dev_err(dev, "Failed to register reboot mode\n"); + + dev_set_drvdata(dev, qrm); + return ret; +} + +static int qcom_reboot_mode_remove(struct platform_device *pdev) +{ + struct qcom_reboot_mode *qrm; + + qrm = dev_get_drvdata(&pdev->dev); + return reboot_mode_unregister(&qrm->reboot); +} + +static const struct of_device_id of_qcom_reboot_mode_match[] = { + { .compatible = "qcom,reboot-mode" }, + {} +}; +MODULE_DEVICE_TABLE(of, of_qcom_reboot_mode_match); + +static struct platform_driver qcom_reboot_mode_driver = { + .probe = qcom_reboot_mode_probe, + .remove = qcom_reboot_mode_remove, + .driver = { + .name = "qcom-reboot-mode", + .of_match_table = of_match_ptr(of_qcom_reboot_mode_match), + }, +}; + +static int __init qcom_reboot_mode_init(void) +{ + return platform_driver_register(&qcom_reboot_mode_driver); +} +device_initcall(qcom_reboot_mode_init); + +MODULE_DESCRIPTION("QCOM Reboot Mode Driver"); +MODULE_LICENSE("GPL v2");