From patchwork Tue Jul 21 18:08:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11676359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A31A6C1 for ; Tue, 21 Jul 2020 18:09:30 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 62D9322482; Tue, 21 Jul 2020 18:09:30 +0000 (UTC) Delivered-To: soc@kernel.org Received: from kozik-lap.mshome.net (unknown [194.230.155.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 57038207DD; Tue, 21 Jul 2020 18:09:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595354970; bh=6ykphDOzUx35ph/lg7nXBoYUdEcNLoB+38x9UyKILiE=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qg3J7Gyu76Q2t5j98+aw+evjiBTz8l2UrZ327TjL5BpFrQzVs8ZINuCPAqbWVWtba rU0I7DEs3R9Fr86mdg70OID2SYuULEeoYfpflLf6xhDGp2zJQMoATDXVepMCWChMFj 9/rocHAp7V/w6iyGw5Zhh9WXT+poFEiy235nizo0= From: Krzysztof Kozlowski List-Id: To: Olof Johansson , Arnd Bergmann , arm@kernel.org, soc@kernel.org Cc: Krzysztof Kozlowski , Kukjin Kim , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [GIT PULL 1/4] ARM: dts: samsung: DTS for v5.9 Date: Tue, 21 Jul 2020 20:08:57 +0200 Message-Id: <20200721180900.13844-2-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200721180900.13844-1-krzk@kernel.org> References: <20200721180900.13844-1-krzk@kernel.org> The following changes since commit b3a9e3b9622ae10064826dccb4f7a52bd88c7407: Linux 5.8-rc1 (2020-06-14 12:45:04 -0700) are available in the Git repository at: https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux.git tags/samsung-dt-5.9 for you to fetch changes up to f37b5d3aef8db06390cb7ef25585b39f89c1dedf: ARM: dts: exynos: Replace HTTP links with HTTPS ones (2020-07-20 16:43:28 +0200) ---------------------------------------------------------------- Samsung DTS ARM changes for v5.9 1. Enable Bluetooth on Artik5 (Exynos3250). 2. Enable accelerometer on Aries boards (Samsung Galaxy S family, S5Pv210); multiple fixes. 3. Fix highest frequencies on Exynos5800. 4. Fix rare USB instability on Odroid XU3 family (Exynos5422). 5. Minor DTS fixes and adjustments with dtschema. ---------------------------------------------------------------- Alexander A. Klimov (1): ARM: dts: exynos: Replace HTTP links with HTTPS ones Anand Moon (1): ARM: dts: exynos: Align L2 cache-controller nodename with dtschema Jonathan Bakker (5): ARM: dts: s5pv210: Add interrupt-controller property to gph3 ARM: dts: s5pv210: Correct fuelgauge definition on Aries ARM: dts: s5pv210: Add support for GP2A light sensor on Aries ARM: dts: s5pv210: Add BMA023 accelerometer support to Aries ARM: dts: s5pv210: Correct BCM4329 bluetooth node Krzysztof Kozlowski (5): ARM: dts: exynos: Fix missing empty reg/ranges property regulators on Trats ARM: dts: exynos: Remove DMA controller bus node name to fix dtschema warnings ARM: dts: exynos: Define fixed regulators in root node for consistency in Origen ARM: dts: exynos: Define fixed regulators in root node for consistency in Arndale ARM: dts: exynos: Define fixed regulators in root node for consistency in SMDK5420 Marek Szyprowski (3): ARM: dts: exynos: Extend all Exynos5800 A15's OPPs with max voltage data ARM: dts: exynos: Enable Bluetooth support for Artik5 board ARM: dts: exynos: Disable frequency scaling for FSYS bus on Odroid XU3 family arch/arm/boot/dts/exynos3250-artik5.dtsi | 41 ++++++++ arch/arm/boot/dts/exynos3250.dtsi | 47 ++++----- arch/arm/boot/dts/exynos4.dtsi | 70 ++++++------- arch/arm/boot/dts/exynos4210-trats.dts | 98 +++++++++--------- arch/arm/boot/dts/exynos4210-universal_c210.dts | 28 ++--- arch/arm/boot/dts/exynos4210.dtsi | 2 +- arch/arm/boot/dts/exynos4412-origen.dts | 21 ++-- arch/arm/boot/dts/exynos4412.dtsi | 2 +- arch/arm/boot/dts/exynos5250-arndale.dts | 86 +++++++--------- arch/arm/boot/dts/exynos5250.dtsi | 92 ++++++++--------- arch/arm/boot/dts/exynos5410-pinctrl.dtsi | 2 +- arch/arm/boot/dts/exynos5410.dtsi | 46 ++++----- arch/arm/boot/dts/exynos5420-smdk5420.dts | 53 ++++------ arch/arm/boot/dts/exynos5420.dtsi | 130 +++++++++++------------- arch/arm/boot/dts/exynos5422-odroid-core.dtsi | 6 -- arch/arm/boot/dts/exynos5800.dtsi | 6 +- arch/arm/boot/dts/s5pv210-aries.dtsi | 90 ++++++++++++++-- arch/arm/boot/dts/s5pv210-fascinate4g.dts | 17 ++++ arch/arm/boot/dts/s5pv210-pinctrl.dtsi | 2 + 19 files changed, 445 insertions(+), 394 deletions(-) From patchwork Tue Jul 21 18:08:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11676361 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E95FC13B6 for ; Tue, 21 Jul 2020 18:09:32 +0000 (UTC) Received: by mail.kernel.org (Postfix) id E1D09207BB; Tue, 21 Jul 2020 18:09:32 +0000 (UTC) Delivered-To: soc@kernel.org Received: from kozik-lap.mshome.net (unknown [194.230.155.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D8D6A2073A; Tue, 21 Jul 2020 18:09:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595354972; bh=5hWIRPC8NaNw54pXsuIkIhsbEDdZaif8PHZBuYokxq4=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=YnzXZcbsbBdKyuSR8HKAVAZCEtn1J8AXVSOw+15RB+mThn/FiR+yIxSvOirGX4Jah p5E3NSPvDbAZMUGZyy4++8piConaNW4Lq9qagyzQQBTaASRp09mhJzHmZ/b1aYOuYp ahGDZdsWwC4NhKv3I2QVmRZU3NyfLn3PD6rfp8Cs= From: Krzysztof Kozlowski List-Id: To: Olof Johansson , Arnd Bergmann , arm@kernel.org, soc@kernel.org Cc: Krzysztof Kozlowski , Kukjin Kim , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [GIT PULL 2/4] arm64: dts: samsung: DTS for v5.9 Date: Tue, 21 Jul 2020 20:08:58 +0200 Message-Id: <20200721180900.13844-3-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200721180900.13844-1-krzk@kernel.org> References: <20200721180900.13844-1-krzk@kernel.org> The following changes since commit b3a9e3b9622ae10064826dccb4f7a52bd88c7407: Linux 5.8-rc1 (2020-06-14 12:45:04 -0700) are available in the Git repository at: https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux.git tags/samsung-dt64-5.9 for you to fetch changes up to 229134cc51d739bc99264ee14b7a783d479ce205: arm64: dts: exynos: Add unit address to soc node and move thermal zones on Exynos7 (2020-07-07 08:45:47 +0200) ---------------------------------------------------------------- Samsung DTS ARM64 changes for v5.9 1. Enable UFS (Universal Flash Storage) on Exynos7 Espresso board. 2. Fix silent hang after boot off Exynos7 Espresso board. 3. Minor DTS fixes and adjustments with dtschema. ---------------------------------------------------------------- Alim Akhtar (3): arm64: dts: exynos: Add UFS node to Exynos7 arm64: dts: exynos: Fix silent hang after boot on Espresso arm64: dts: exynos: Keep LDO12 always-on on Espresso Krzysztof Kozlowski (5): arm64: dts: exynos: Describe PWM interrupts on Exynos7 arm64: dts: exynos: Remove generic arm,armv8-pmuv3 compatible arm64: dts: exynos: Remove DMA controller bus node name to fix dtschema warnings arm64: dts: exynos: Add unit address to soc node on Exynos5433 arm64: dts: exynos: Add unit address to soc node and move thermal zones on Exynos7 arch/arm64/boot/dts/exynos/exynos5433.dtsi | 53 +++++------ arch/arm64/boot/dts/exynos/exynos7-espresso.dts | 6 ++ arch/arm64/boot/dts/exynos/exynos7.dtsi | 111 ++++++++++++++++-------- 3 files changed, 103 insertions(+), 67 deletions(-) From patchwork Tue Jul 21 18:08:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11676363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B7146C1 for ; Tue, 21 Jul 2020 18:09:35 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 730802073A; Tue, 21 Jul 2020 18:09:35 +0000 (UTC) Delivered-To: soc@kernel.org Received: from kozik-lap.mshome.net (unknown [194.230.155.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6A8FE206F5; Tue, 21 Jul 2020 18:09:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595354975; bh=hdCbrWB0meLrxiZ1+k6LHItZpF5C4AX7Nip10hChMcE=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=BDq9cPWZeWClxxQmMU6+Jk/7ng9vSbA/ogaHdH2tcz8kVt6Sw6nLxPljaNJXOIYvK 61+6W30pakbf36XLkv38oiijm+rx18UMkAjDIrGUoAcfUYOywLbF6rLJUkkM4a5vSw 0Ml4HLqX9dDNGBwTQFsFP8Twe+omgLTX6Dh1egsk= From: Krzysztof Kozlowski List-Id: To: Olof Johansson , Arnd Bergmann , arm@kernel.org, soc@kernel.org Cc: Krzysztof Kozlowski , Kukjin Kim , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [GIT PULL 3/4] ARM: samsung: mach/soc for v5.9 Date: Tue, 21 Jul 2020 20:08:59 +0200 Message-Id: <20200721180900.13844-4-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200721180900.13844-1-krzk@kernel.org> References: <20200721180900.13844-1-krzk@kernel.org> The following changes since commit b3a9e3b9622ae10064826dccb4f7a52bd88c7407: Linux 5.8-rc1 (2020-06-14 12:45:04 -0700) are available in the Git repository at: https://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux.git tags/samsung-soc-5.9 for you to fetch changes up to 3ecdf2a5d262df01bc100472cb909580d0fdce69: ARM: s3c24xx: Replace HTTP links with HTTPS ones (2020-07-20 16:42:28 +0200) ---------------------------------------------------------------- Samsung mach/soc changes for v5.9 1. Restore big.LITTLE cpuidle support on Exynos542x boards. 2. Cleanups and minor fixes. ---------------------------------------------------------------- Alexander A. Klimov (1): ARM: s3c24xx: Replace HTTP links with HTTPS ones Guillaume Tucker (1): ARM: exynos: clear L310_AUX_CTRL_FULL_LINE_ZERO in default l2c_aux_val Linus Walleij (1): ARM: s3c24xx: leds: Convert to use GPIO descriptors Marek Szyprowski (1): ARM: exynos: MCPM: Restore big.LITTLE cpuidle support arch/arm/mach-exynos/exynos.c | 2 +- arch/arm/mach-exynos/mcpm-exynos.c | 10 +++-- arch/arm/mach-s3c24xx/Kconfig | 2 +- arch/arm/mach-s3c24xx/common-smdk.c | 67 ++++++++++++++++++++---------- arch/arm/mach-s3c24xx/mach-h1940.c | 2 +- arch/arm/mach-s3c24xx/mach-mini2440.c | 65 ++++++++++++++++++++++++----- arch/arm/mach-s3c24xx/mach-n30.c | 56 +++++++++++++++++++++---- arch/arm/mach-s3c24xx/mach-qt2410.c | 12 +++++- arch/arm/mach-s3c24xx/mach-rx3715.c | 2 +- arch/arm/mach-s3c24xx/mach-vr1000.c | 38 +++++++++++++++-- drivers/leds/leds-s3c24xx.c | 36 ++++------------ include/linux/platform_data/leds-s3c24xx.h | 6 --- 12 files changed, 212 insertions(+), 86 deletions(-) From patchwork Tue Jul 21 18:09:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 11676365 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 475A46C1 for ; Tue, 21 Jul 2020 18:09:38 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 3F34E207BB; Tue, 21 Jul 2020 18:09:38 +0000 (UTC) Delivered-To: soc@kernel.org Received: from kozik-lap.mshome.net (unknown [194.230.155.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 08DFE20792; Tue, 21 Jul 2020 18:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595354978; bh=Oy52OkSXnTEWPGTA6z9Up0N94Bpg5ST8vemgrSA/COU=; h=From:List-Id:To:Cc:Subject:Date:In-Reply-To:References:From; b=oMX98E2xLLPOR9o10i88CNFGrjR/Mb089WygThJyxb3Ea8A4DVf60KVEdiJeMeGVf LMXhJ4k1+JEkXNQQBUQdamAylXCH/nkp8+doGEWpnFpPLpI1saBU+SkWDoYO86Ltc2 tmkrBl0rlQ+ZzjUsfJgX6N+bygJBAm8Z84o4TT6s= From: Krzysztof Kozlowski List-Id: To: Olof Johansson , Arnd Bergmann , arm@kernel.org, soc@kernel.org Cc: Marek Szyprowski , Kukjin Kim , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski Subject: [PATCH 4/4] soc: samsung: exynos-regulator-coupler: Add simple voltage coupler for Exynos5800 Date: Tue, 21 Jul 2020 20:09:00 +0200 Message-Id: <20200721180900.13844-5-krzk@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200721180900.13844-1-krzk@kernel.org> References: <20200721180900.13844-1-krzk@kernel.org> From: Marek Szyprowski Add a simple custom voltage regulator coupler for Exynos5800 SoCs, which require coupling between "vdd_arm" and "vdd_int" regulators. This coupler ensures that the voltage values don't go below the bootloader-selected operation point during the boot process until the clients set their constraints. It is achieved by assuming minimal voltage value equal to the current value if no constraints are set. This also ensures proper voltage balancing if any of the client driver is missing. The balancing code comes from the regulator/core.c with the additional logic for handling regulators without client constraints applied added. Signed-off-by: Marek Szyprowski Reviewed-by: Dmitry Osipenko Signed-off-by: Krzysztof Kozlowski --- arch/arm/mach-exynos/Kconfig | 1 + drivers/soc/samsung/Kconfig | 3 + drivers/soc/samsung/Makefile | 1 + .../soc/samsung/exynos-regulator-coupler.c | 221 ++++++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 drivers/soc/samsung/exynos-regulator-coupler.c diff --git a/arch/arm/mach-exynos/Kconfig b/arch/arm/mach-exynos/Kconfig index 76838255b5fa..f185cd3d4c62 100644 --- a/arch/arm/mach-exynos/Kconfig +++ b/arch/arm/mach-exynos/Kconfig @@ -118,6 +118,7 @@ config SOC_EXYNOS5800 bool "Samsung EXYNOS5800" default y depends on SOC_EXYNOS5420 + select EXYNOS_REGULATOR_COUPLER config EXYNOS_MCPM bool diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig index c7a2003687c7..264185664594 100644 --- a/drivers/soc/samsung/Kconfig +++ b/drivers/soc/samsung/Kconfig @@ -37,4 +37,7 @@ config EXYNOS_PM_DOMAINS bool "Exynos PM domains" if COMPILE_TEST depends on PM_GENERIC_DOMAINS || COMPILE_TEST +config EXYNOS_REGULATOR_COUPLER + bool "Exynos SoC Regulator Coupler" if COMPILE_TEST + depends on ARCH_EXYNOS || COMPILE_TEST endif diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile index edd1d6ea064d..ecc3a32f6406 100644 --- a/drivers/soc/samsung/Makefile +++ b/drivers/soc/samsung/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_EXYNOS_PMU) += exynos-pmu.o obj-$(CONFIG_EXYNOS_PMU_ARM_DRIVERS) += exynos3250-pmu.o exynos4-pmu.o \ exynos5250-pmu.o exynos5420-pmu.o obj-$(CONFIG_EXYNOS_PM_DOMAINS) += pm_domains.o +obj-$(CONFIG_EXYNOS_REGULATOR_COUPLER) += exynos-regulator-coupler.o diff --git a/drivers/soc/samsung/exynos-regulator-coupler.c b/drivers/soc/samsung/exynos-regulator-coupler.c new file mode 100644 index 000000000000..61a156b44a48 --- /dev/null +++ b/drivers/soc/samsung/exynos-regulator-coupler.c @@ -0,0 +1,221 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * Author: Marek Szyprowski + * + * Simplified generic voltage coupler from regulator core.c + * The main difference is that it keeps current regulator voltage + * if consumers didn't apply their constraints yet. + */ + +#include +#include +#include +#include +#include +#include + +static int regulator_get_optimal_voltage(struct regulator_dev *rdev, + int *current_uV, + int *min_uV, int *max_uV, + suspend_state_t state) +{ + struct coupling_desc *c_desc = &rdev->coupling_desc; + struct regulator_dev **c_rdevs = c_desc->coupled_rdevs; + struct regulation_constraints *constraints = rdev->constraints; + int desired_min_uV = 0, desired_max_uV = INT_MAX; + int max_current_uV = 0, min_current_uV = INT_MAX; + int highest_min_uV = 0, target_uV, possible_uV; + int i, ret, max_spread, n_coupled = c_desc->n_coupled; + bool done; + + *current_uV = -1; + + /* Find highest min desired voltage */ + for (i = 0; i < n_coupled; i++) { + int tmp_min = 0; + int tmp_max = INT_MAX; + + lockdep_assert_held_once(&c_rdevs[i]->mutex.base); + + ret = regulator_check_consumers(c_rdevs[i], + &tmp_min, + &tmp_max, state); + if (ret < 0) + return ret; + + if (tmp_min == 0) { + ret = regulator_get_voltage_rdev(c_rdevs[i]); + if (ret < 0) + return ret; + tmp_min = ret; + } + + /* apply constraints */ + ret = regulator_check_voltage(c_rdevs[i], &tmp_min, &tmp_max); + if (ret < 0) + return ret; + + highest_min_uV = max(highest_min_uV, tmp_min); + + if (i == 0) { + desired_min_uV = tmp_min; + desired_max_uV = tmp_max; + } + } + + max_spread = constraints->max_spread[0]; + + /* + * Let target_uV be equal to the desired one if possible. + * If not, set it to minimum voltage, allowed by other coupled + * regulators. + */ + target_uV = max(desired_min_uV, highest_min_uV - max_spread); + + /* + * Find min and max voltages, which currently aren't violating + * max_spread. + */ + for (i = 1; i < n_coupled; i++) { + int tmp_act; + + tmp_act = regulator_get_voltage_rdev(c_rdevs[i]); + if (tmp_act < 0) + return tmp_act; + + min_current_uV = min(tmp_act, min_current_uV); + max_current_uV = max(tmp_act, max_current_uV); + } + + /* + * Correct target voltage, so as it currently isn't + * violating max_spread + */ + possible_uV = max(target_uV, max_current_uV - max_spread); + possible_uV = min(possible_uV, min_current_uV + max_spread); + + if (possible_uV > desired_max_uV) + return -EINVAL; + + done = (possible_uV == target_uV); + desired_min_uV = possible_uV; + + /* Set current_uV if wasn't done earlier in the code and if necessary */ + if (*current_uV == -1) { + ret = regulator_get_voltage_rdev(rdev); + if (ret < 0) + return ret; + *current_uV = ret; + } + + *min_uV = desired_min_uV; + *max_uV = desired_max_uV; + + return done; +} + +static int exynos_coupler_balance_voltage(struct regulator_coupler *coupler, + struct regulator_dev *rdev, + suspend_state_t state) +{ + struct regulator_dev **c_rdevs; + struct regulator_dev *best_rdev; + struct coupling_desc *c_desc = &rdev->coupling_desc; + int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev; + unsigned int delta, best_delta; + unsigned long c_rdev_done = 0; + bool best_c_rdev_done; + + c_rdevs = c_desc->coupled_rdevs; + n_coupled = c_desc->n_coupled; + + /* + * Find the best possible voltage change on each loop. Leave the loop + * if there isn't any possible change. + */ + do { + best_c_rdev_done = false; + best_delta = 0; + best_min_uV = 0; + best_max_uV = 0; + best_c_rdev = 0; + best_rdev = NULL; + + /* + * Find highest difference between optimal voltage + * and current voltage. + */ + for (i = 0; i < n_coupled; i++) { + /* + * optimal_uV is the best voltage that can be set for + * i-th regulator at the moment without violating + * max_spread constraint in order to balance + * the coupled voltages. + */ + int optimal_uV = 0, optimal_max_uV = 0, current_uV = 0; + + if (test_bit(i, &c_rdev_done)) + continue; + + ret = regulator_get_optimal_voltage(c_rdevs[i], + ¤t_uV, + &optimal_uV, + &optimal_max_uV, + state); + if (ret < 0) + goto out; + + delta = abs(optimal_uV - current_uV); + + if (delta && best_delta <= delta) { + best_c_rdev_done = ret; + best_delta = delta; + best_rdev = c_rdevs[i]; + best_min_uV = optimal_uV; + best_max_uV = optimal_max_uV; + best_c_rdev = i; + } + } + + /* Nothing to change, return successfully */ + if (!best_rdev) { + ret = 0; + goto out; + } + + ret = regulator_set_voltage_rdev(best_rdev, best_min_uV, + best_max_uV, state); + + if (ret < 0) + goto out; + + if (best_c_rdev_done) + set_bit(best_c_rdev, &c_rdev_done); + + } while (n_coupled > 1); + +out: + return ret; +} + +static int exynos_coupler_attach(struct regulator_coupler *coupler, + struct regulator_dev *rdev) +{ + return 0; +} + +static struct regulator_coupler exynos_coupler = { + .attach_regulator = exynos_coupler_attach, + .balance_voltage = exynos_coupler_balance_voltage, +}; + +static int __init exynos_coupler_init(void) +{ + if (!of_machine_is_compatible("samsung,exynos5800")) + return 0; + + return regulator_coupler_register(&exynos_coupler); +} +arch_initcall(exynos_coupler_init);