From patchwork Wed Oct 29 13:13:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 5187771 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 514779F387 for ; Wed, 29 Oct 2014 13:14:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD3F12022A for ; Wed, 29 Oct 2014 13:13:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4050720260 for ; Wed, 29 Oct 2014 13:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932875AbaJ2NNz (ORCPT ); Wed, 29 Oct 2014 09:13:55 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:24174 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932746AbaJ2NNx (ORCPT ); Wed, 29 Oct 2014 09:13:53 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NE700L4KJJXTX00@mailout1.w1.samsung.com>; Wed, 29 Oct 2014 13:16:45 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-eb-5450e80e821d Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id BF.90.04619.E08E0545; Wed, 29 Oct 2014 13:13:50 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NE70089XJEZ5DA0@eusync3.samsung.com>; Wed, 29 Oct 2014 13:13:50 +0000 (GMT) From: Marek Szyprowski To: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Kukjin Kim , Tobias Jakobi , Daniel Drake , Dmitry Eremin-Solenikov , David Woodhouse , Sebastian Reichel Subject: [PATCH 1/2] power: reset: add driver for Hardkernel's Odroid boards Date: Wed, 29 Oct 2014 14:13:28 +0100 Message-id: <1414588409-8065-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEJMWRmVeSWpSXmKPExsVy+t/xq7p8LwJCDG7st7SY9OQ9s8X8I+dY LR7Nf8xsMXHlZGaL3gVX2Sw+9x5htJhxfh+TRdfPn2wWa4/cZbc4vbvEgctj0fcsj52z7rJ7 LN60n81j8wotj02rOtk8+rasYvT4vEkugD2KyyYlNSezLLVI3y6BK2PemjfsBScMKt6+uM/U wHhTo4uRk0NCwETix5nzTBC2mMSFe+vZuhi5OIQEljJKnNt7ixEkISTQxyTx45IDiM0mYCjR 9baLDcQWEYiVmLj1B5jNLDCPSeLgjnwQW1jAR+L6u2/MIDaLgKrEo4dvgOZwcPAKuEv8WO8N sUtO4v/LFUwTGLkXMDKsYhRNLU0uKE5KzzXUK07MLS7NS9dLzs/dxAgJpy87GBcfszrEKMDB qMTD67AxIESINbGsuDL3EKMEB7OSCO+7vUAh3pTEyqrUovz4otKc1OJDjEwcnFINjAsOWsXz SgtvnfWvsW/tA+Yq2dB38u3WU0ScFvQd835VHHP8i0qY0G19l9bHrmG6TB7eVy5c9fWaMlP1 lyGXR3nL3atR0zSCbizfejRCvU9Jgc1/085/P9K61uSeVYtLT+pV4y57skXuxvbIp2UHl157 6ZN2IUjSxER/7uNS6Zq/y13rZgZNVmIpzkg01GIuKk4EAC3B/H4FAgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a driver implementing correct reboot and poweroff procedures for Exynos4412-based Hardkernel's Odroid X/X2/U2/U3/U3+ boards. Signed-off-by: Marek Szyprowski --- .../bindings/power/reset/odroid-reset.txt | 18 ++++ drivers/power/reset/Kconfig | 6 ++ drivers/power/reset/Makefile | 1 + drivers/power/reset/odroid-reboot.c | 119 +++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/reset/odroid-reset.txt create mode 100644 drivers/power/reset/odroid-reboot.c diff --git a/Documentation/devicetree/bindings/power/reset/odroid-reset.txt b/Documentation/devicetree/bindings/power/reset/odroid-reset.txt new file mode 100644 index 000000000000..86471a463518 --- /dev/null +++ b/Documentation/devicetree/bindings/power/reset/odroid-reset.txt @@ -0,0 +1,18 @@ +* Device tree bindings for Hardkernel's Exynos4412 based Odroid boards + +This node is intended to allow proper system reboot and power off of +Odroid X/X2/U2/U3/U3+ boards with eMMC storage. Without this node, board +hangs during standard reset procedure. + +Required properties: +- compatible: hardkernel,odroid-reboot +- samsung,pmureg-phandle: phandle to Exynos PMU node +- reset-gpios: phandle and gpio-specifier to the GPIO pin + connected to the eMMC_nDET + +Example: +odroid_reboot { + compatible = "hardkernel,odroid-reboot"; + samsung,pmureg-phandle = <&pmu_system_controller>; + reset-gpio = <&gpk1 2 0>; +}; diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index f65ff49bb275..f02b13d5344f 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -84,6 +84,12 @@ config POWER_RESET_LTC2952 This driver supports an external powerdown trigger and board power down via the LTC2952. Bindings are made in the device tree. +config POWER_RESET_ODROID + bool "Hardkernel's Exynos4412 based Odroid reboot driver" + depends on POWER_RESET && ARCH_EXYNOS + help + Power off and restart support for Odroid boards. + config POWER_RESET_QNAP bool "QNAP power-off driver" depends on OF_GPIO && PLAT_ORION diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 76ce1c59469b..178ee86eb813 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o +obj-$(CONFIG_POWER_RESET_ODROID) += odroid-reboot.o obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o obj-$(CONFIG_POWER_RESET_SUN6I) += sun6i-reboot.o diff --git a/drivers/power/reset/odroid-reboot.c b/drivers/power/reset/odroid-reboot.c new file mode 100644 index 000000000000..823e93539220 --- /dev/null +++ b/drivers/power/reset/odroid-reboot.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * 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 + +#define PS_HOLD_CONTROL 0x330C + +struct odroid_reboot_data { + struct device *dev; + int power_gpio; + struct regmap *reg_pmu; + void (*reboot_func)(enum reboot_mode mode, const char *cmd); +}; + +static struct odroid_reboot_data *reboot_data; + +static void odroid_reboot(enum reboot_mode mode, const char *cmd) +{ + local_irq_disable(); + + gpio_set_value(reboot_data->power_gpio, 0); + mdelay(150); + gpio_set_value(reboot_data->power_gpio, 1); + + reboot_data->reboot_func(mode, cmd); + + pr_emerg("%s: waiting for reboot\n", __func__); + while (1) + ; +} + +static void odroid_power_off(void) +{ + regmap_update_bits(reboot_data->reg_pmu, PS_HOLD_CONTROL, 0xffffffff, 0x5200); + while (1) { + pr_emerg("%s: should not reach here!\n", __func__); + msleep(1000); + } +} + +static struct odroid_reboot_data *odroid_reboot_parse_dt(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct odroid_reboot_data *data; + + data = devm_kzalloc(dev, sizeof(struct odroid_reboot_data), GFP_KERNEL); + if (!data) + return NULL; + + data->power_gpio = of_get_named_gpio(np, "reset-gpios", 0); + if (!gpio_is_valid(data->power_gpio)) { + dev_err(dev, "invalid reset gpio pin\n"); + return NULL; + } + devm_gpio_request(dev, data->power_gpio, "reset"); + + data->reg_pmu = syscon_regmap_lookup_by_phandle(np, + "samsung,pmureg-phandle"); + if (IS_ERR(data->reg_pmu)) { + dev_err(dev, "failed to map PMU registers\n"); + return NULL; + } + + return data; +} + +static int odroid_reboot_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + + if (pdev->dev.of_node) + reboot_data = odroid_reboot_parse_dt(dev); + + if (!reboot_data) + return -EINVAL; + + reboot_data->dev = &pdev->dev; + reboot_data->reboot_func = arm_pm_restart; + + /* grab reboot arm specific hook */ + arm_pm_restart = odroid_reboot; + + /* register power off function */ + pm_power_off = odroid_power_off; + + return 0; +} + +static struct of_device_id odroid_reboot_of_match[] = { + { .compatible = "hardkernel,odroid-reboot", }, + { }, +}; + +static struct platform_driver odroid_reboot_driver = { + .probe = odroid_reboot_probe, + .driver = { + .name = "odroid-reboot", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(odroid_reboot_of_match), + } +}; +module_platform_driver(odroid_reboot_driver);