Received: by 10.223.176.5 with SMTP id f5csp235194wra; Mon, 5 Feb 2018 20:51:27 -0800 (PST) X-Google-Smtp-Source: AH8x225hqfyOrlvhQCWyhFEQuJ5SsNqQw3821L1UfAoIjPM5YFHMwMJY7FQws1MZcE6fLvX2b+dE X-Received: by 10.99.140.18 with SMTP id m18mr994286pgd.320.1517892687685; Mon, 05 Feb 2018 20:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517892687; cv=none; d=google.com; s=arc-20160816; b=Kiy9X82nXP37hK/M/hvqN/RUmNwwvKG6jil2YrZlXRyjyzuhOQRxNfBwW/5zPKXiuY gZvzPA67DZSkpM59Le2Gkq1It62deiLUHkAVVDlDI7lResN4Xd5EUItEfq0dPtw4jgR8 hwTGKl35ymjShKDnvbDnUrH/Ib0l7i4sgFUzI3As4E1FWTUj7bCzURVhrjPYnUMYCaqN 8Vtl4iTDNFsB81ljHQp681YemA0eBect6K+Xo07p6z11unVqFoQ3kDf6NO1KCi0be6t9 uuTknT/V+drca58ssY25Cnw6RlpLm4eGGU1IrXIDjGpCJ6D+XmuTZZiL11O7uhYhZM4s twig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=21kJDAVamVAqlAwZDQV/7h1wXRy7HBTaDb2Xz4brdgs=; b=SsDaaMw4yepx6d+eDZaBwwZWj9HpsDVAdWq/Kv8QzRQP96wkiLD3pZjmMG03z+rJQx DjpbnITBY5N9tH0aW0VsrPWGWz44pg4lqnJ0dL5GJyfd2JRN+aeDwxQkyG0lJFmCSa1r KUtdWOOWYRFmKuZnDwmPQrY0+SelF+Md8/Q6Fuk/ZmIpUI/nHvTehl6oDJrfVClDA2hU AiNw8fHZ04/xK/1czJtEl4rtSr8er9fTn1sRfeEA2EdQqIbi/WX2bRUqqN+d+yQ0aasK HLxXyv8E6o643Y0V/SVmktytCaW0RqRhe8vdLjfBxu5+UgLFeSVQhWF6J9U5CQ2G2ROA amZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8si4471137pgn.769.2018.02.05.20.51.13; Mon, 05 Feb 2018 20:51:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752294AbeBFEua (ORCPT + 99 others); Mon, 5 Feb 2018 23:50:30 -0500 Received: from hermes.aosc.io ([199.195.250.187]:50232 "EHLO hermes.aosc.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752315AbeBFEuY (ORCPT ); Mon, 5 Feb 2018 23:50:24 -0500 Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id 5C87557021; Tue, 6 Feb 2018 04:50:20 +0000 (UTC) From: Icenowy Zheng To: Liam Girdwood , Rob Herring , Maxime Ripard , Chen-Yu Tsai Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@googlegroups.com, Ondrej Jirman , Icenowy Zheng Subject: [PATCH v2 02/10] regulator: add support for SY8106A regulator Date: Tue, 6 Feb 2018 12:48:57 +0800 Message-Id: <20180206044905.30508-3-icenowy@aosc.io> In-Reply-To: <20180206044905.30508-1-icenowy@aosc.io> References: <20180206044905.30508-1-icenowy@aosc.io> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ondrej Jirman SY8106A is an I2C attached single output regulator made by Silergy Corp, which is used on several Allwinner H3/H5 SBCs to control the power supply of the ARM cores. Add a driver for it. Signed-off-by: Ondrej Jirman [Icenowy: Change commit message, remove enable/disable code, add default ramp_delay, add comment for go bit] Signed-off-by: Icenowy Zheng --- Changes in v2: - Dropped the enable/disable code. - Added default ramp_delay value. - Added comment for the "go bit". drivers/regulator/Kconfig | 8 +- drivers/regulator/Makefile | 2 +- drivers/regulator/sy8106a-regulator.c | 168 ++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 drivers/regulator/sy8106a-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index b27417ca188a..70227230bca2 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -792,6 +792,13 @@ config REGULATOR_STW481X_VMMC This driver supports the internal VMMC regulator in the STw481x PMIC chips. +config REGULATOR_SY8106A + tristate "Silergy SY8106A regulator" + depends on I2C && (OF || COMPILE_TEST) + select REGMAP_I2C + help + This driver supports SY8106A single output regulator. + config REGULATOR_TPS51632 tristate "TI TPS51632 Power Regulator" depends on I2C @@ -966,4 +973,3 @@ config REGULATOR_WM8994 WM8994 CODEC. endif - diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 19fea09ba10a..7564664c64df 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -99,6 +99,7 @@ obj-$(CONFIG_REGULATOR_SC2731) += sc2731-regulator.o obj-$(CONFIG_REGULATOR_SKY81452) += sky81452-regulator.o obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o +obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o obj-$(CONFIG_REGULATOR_TI_ABB) += ti-abb-regulator.o obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o @@ -124,5 +125,4 @@ obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o - ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG diff --git a/drivers/regulator/sy8106a-regulator.c b/drivers/regulator/sy8106a-regulator.c new file mode 100644 index 000000000000..c5643c33e1e5 --- /dev/null +++ b/drivers/regulator/sy8106a-regulator.c @@ -0,0 +1,168 @@ +/* + * sy8106a-regulator.c - Regulator device driver for SY8106A + * + * Copyright (C) 2016 Ondřej Jirman + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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 + * Library General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include + +#define SY8106A_REG_VOUT1_SEL 0x01 +#define SY8106A_REG_VOUT_COM 0x02 +#define SY8106A_REG_VOUT1_SEL_MASK 0x7f +#define SY8106A_DISABLE_REG BIT(0) +/* + * The I2C controlled voltage will only work when this bit is set; otherwise + * it will behave like a fixed regulator. + */ +#define SY8106A_GO_BIT BIT(7) + +struct sy8106a { + struct regulator_dev *rdev; + struct regmap *regmap; +}; + +static const struct regmap_config sy8106a_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static int sy8106a_set_voltage_sel(struct regulator_dev *rdev, unsigned int sel) +{ + /* We use our set_voltage_sel in order to avoid unnecessary I2C + * chatter, because the regulator_get_voltage_sel_regmap using + * apply_bit would perform 4 unnecessary transfers instead of one, + * increasing the chance of error. + */ + return regmap_write(rdev->regmap, rdev->desc->vsel_reg, + sel | SY8106A_GO_BIT); +} + +static const struct regulator_ops sy8106a_ops = { + .set_voltage_sel = sy8106a_set_voltage_sel, + .set_voltage_time_sel = regulator_set_voltage_time_sel, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .list_voltage = regulator_list_voltage_linear, + /* Enabling/disabling the regulator is not yet implemented */ +}; + +/* Default limits measured in millivolts and milliamps */ +#define SY8106A_MIN_MV 680 +#define SY8106A_MAX_MV 1950 +#define SY8106A_STEP_MV 10 + +static const struct regulator_desc sy8106a_reg = { + .name = "SY8106A", + .id = 0, + .ops = &sy8106a_ops, + .type = REGULATOR_VOLTAGE, + .n_voltages = ((SY8106A_MAX_MV - SY8106A_MIN_MV) / SY8106A_STEP_MV) + 1, + .min_uV = (SY8106A_MIN_MV * 1000), + .uV_step = (SY8106A_STEP_MV * 1000), + .vsel_reg = SY8106A_REG_VOUT1_SEL, + .vsel_mask = SY8106A_REG_VOUT1_SEL_MASK, + /* + * This ramp_delay is a conservative default value which works on + * H3/H5 boards VDD-CPUX situations. + */ + .ramp_delay = 200, + .owner = THIS_MODULE, +}; + +/* + * I2C driver interface functions + */ +static int sy8106a_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct sy8106a *chip; + struct device *dev = &i2c->dev; + struct regulator_dev *rdev = NULL; + struct regulator_config config = { }; + unsigned int selector; + int error; + + chip = devm_kzalloc(&i2c->dev, sizeof(struct sy8106a), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->regmap = devm_regmap_init_i2c(i2c, &sy8106a_regmap_config); + if (IS_ERR(chip->regmap)) { + error = PTR_ERR(chip->regmap); + dev_err(&i2c->dev, "Failed to allocate register map: %d\n", + error); + return error; + } + + config.dev = &i2c->dev; + config.regmap = chip->regmap; + config.driver_data = chip; + + config.of_node = dev->of_node; + config.init_data = of_get_regulator_init_data(dev, dev->of_node, + &sy8106a_reg); + + if (!config.init_data) + return -ENOMEM; + + /* Probe regulator */ + error = regmap_read(chip->regmap, SY8106A_REG_VOUT1_SEL, &selector); + if (error) { + dev_err(&i2c->dev, "Failed to read voltage at probe time: %d\n", error); + return error; + } + + rdev = devm_regulator_register(&i2c->dev, &sy8106a_reg, &config); + if (IS_ERR(rdev)) { + error = PTR_ERR(rdev); + dev_err(&i2c->dev, "Failed to register SY8106A regulator: %d\n", error); + return error; + } + + chip->rdev = rdev; + + i2c_set_clientdata(i2c, chip); + + return 0; +} + +static const struct of_device_id sy8106a_i2c_of_match[] = { + { .compatible = "silergy,sy8106a" }, + { }, +}; +MODULE_DEVICE_TABLE(of, sy8106a_i2c_of_match); + +static const struct i2c_device_id sy8106a_i2c_id[] = { + { "sy8106a", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(i2c, sy8106a_i2c_id); + +static struct i2c_driver sy8106a_regulator_driver = { + .driver = { + .name = "sy8106a", + .of_match_table = of_match_ptr(sy8106a_i2c_of_match), + }, + .probe = sy8106a_i2c_probe, + .id_table = sy8106a_i2c_id, +}; + +module_i2c_driver(sy8106a_regulator_driver); + +MODULE_AUTHOR("Ondřej Jirman "); +MODULE_DESCRIPTION("Regulator device driver for Silergy SY8106A"); +MODULE_LICENSE("GPL"); -- 2.15.1