Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3555394pxj; Tue, 15 Jun 2021 03:38:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIXLOOOFA8jWV5C1xv9AvrMbRKxNNomsGll9f0KTdTBsritvRjK+B2Lp2cDtIZLrThhDAG X-Received: by 2002:a50:fe8d:: with SMTP id d13mr6231252edt.14.1623753506391; Tue, 15 Jun 2021 03:38:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623753506; cv=none; d=google.com; s=arc-20160816; b=cs8hr1v86oIMUTc2b3jqjshAbOFX+FCrTEjFmO9ts2cSRxPBn9ZKBP1+dTdxZlc4u0 6HgyCuMRXYm3FuisGaroS4BlxdzPGr5YDgr5PgxmOvj5IV0pOpTi/mrAkJkH7G8eMBko tQljP7pBo+KmAbY+2T25FcVMpSfBGY5tvIwkDwUQ7rB9E0d11hgsZf6FEmIGccme6yfV D64yl+hCCNvZHvI4IHsQen4KJ7dtvk4Rt6xN/jaA+2yRaA3ApRIIK4urC0YIUttwk607 D601fuvs9Wqwc3wh97Y+ftCIEHgPw1YtbNGPFbyJGlgDT7co4zx3yIOyl7cWIuRvISZs vzLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=yKGaVzsaPWa0kOpHRXY5NUqTSi5jxQ0vLAr+VFLu1Xs=; b=OeJajuPJmF85oqFUdWmF5jC3ya/2WCX+dM2Z7FzkFZwOJPdAnKc0FcRI10M7UCVyKN pXeba0kzd7C+VYGEtJbdyxKBuJ+cQisNvZvXdZdoiJus+xbdiv5hZzqW3I+ygj7K/+nd 1vI83lyKfNZ4ihGyO9cI8ls0DnPKMjZU7s0w/5lq7o7o9YOjJpIaDIqAsReWpLwin2lD d8j78qUzRGswDaddqms7lvuF26WoQfJrhAKFhyyJgWN0tlqCJrAUCFXV+999r6XHA/Ux Lcx9tap0XKV8oFLx3j4L5LVcKai2cHN78nAVh6eTdq5l2wwSegbzPTTKfQwswHAuTB3f mPBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alistair23.me header.s=fm1 header.b=CLsuttwY; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=PxWy89yh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w11si13806824ejq.499.2021.06.15.03.38.02; Tue, 15 Jun 2021 03:38:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alistair23.me header.s=fm1 header.b=CLsuttwY; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=PxWy89yh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231772AbhFOKgi (ORCPT + 99 others); Tue, 15 Jun 2021 06:36:38 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:55675 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbhFOKgf (ORCPT ); Tue, 15 Jun 2021 06:36:35 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 44A685C0116; Tue, 15 Jun 2021 06:34:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 15 Jun 2021 06:34:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alistair23.me; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=yKGaVzsaPWa0k OpHRXY5NUqTSi5jxQ0vLAr+VFLu1Xs=; b=CLsuttwYXhXPU9MQxTdB1AHrXCv3L DG+/QygRo0hhVhLFcF7OfLGv/YDsoIjqB2i82YLH0pTkNYri3oJuxD0lPYMtsRey hSAvhSj4I9JIuSw7i/VZfhGpvlDnoLYzg3cZscRaeT85+UX26NgR9avg9YLABtwS bzQAfnBE2G/mKNV6uVFRaNNxhHPO3nK3M62XMMm3hd7DmQtqxNMpcUcc8aqHrUrA YaX1SarL3dFlg2I+/UqXWeaeoDCeu7AnrzrKxpkDNh7BLbglth6GVl0u69wNu9yu h34d0hchsu8SF853Zjk7mE0Ya/b6hTUHwzjds2sL3v9JKsCSHa1/kFLtA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=yKGaVzsaPWa0kOpHRXY5NUqTSi5jxQ0vLAr+VFLu1Xs=; b=PxWy89yh iixT/JRhovJzWYHb0+czdk6PtbVwAWJycN/Z5mZHy2H7nnv9uTdzIpFxyUocwhik DkxYdwDNmV2HBDxGs5t73lkWCi6TL17as6GkYTKXm98Z9YQxrGHWapCCqLcRA5la /thBMGpD64Y6ytnfY2DZaHI2zzqUas/CcTxI/KnERbqu93Hhl2IkKcox44xoeTtn yxAAQGmo5nDkOK+h24o2RQOp9ZsD8aR3889xO2c3hp1D/gIKgDH6Pj3mto13feKN YxwLB1qv4UNPFj0+x2X2HHcEKdPNFSGEgTRknVPCFln/UiO6WgTXguIBkWGU+c1f yzPEggaY54KQXA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedvjedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheptehlihhsthgrihhrucfhrhgrnhgtihhsuceorghlihhsthgr ihhrsegrlhhishhtrghirhdvfedrmhgvqeenucggtffrrghtthgvrhhnpeehffejteette ekfffhvdeghfegvedvvdeujeehheefveefudefgeeitdehueejleenucffohhmrghinhep rhgvmhgrrhhkrggslhgvrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomheprghlihhsthgrihhrsegrlhhishhtrghirhdvfedrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Jun 2021 06:34:26 -0400 (EDT) From: Alistair Francis To: lee.jones@linaro.org, robh+dt@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, linux-imx@nxp.com, kernel@pengutronix.de Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alistair23@gmail.com, Alistair Francis Subject: [PATCH v6 3/5] regulator: sy7636a: Initial commit Date: Tue, 15 Jun 2021 20:33:58 +1000 Message-Id: <20210615103400.946-3-alistair@alistair23.me> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210615103400.946-1-alistair@alistair23.me> References: <20210615103400.946-1-alistair@alistair23.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Initial support for the Silergy SY7636A-regulator Power Management chip. Signed-off-by: Alistair Francis --- drivers/regulator/Kconfig | 6 ++ drivers/regulator/Makefile | 1 + drivers/regulator/sy7636a-regulator.c | 127 ++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 drivers/regulator/sy7636a-regulator.c diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 3e7a38525cb3..ebb968e8b2b0 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -1150,6 +1150,12 @@ config REGULATOR_STW481X_VMMC This driver supports the internal VMMC regulator in the STw481x PMIC chips. +config REGULATOR_SY7636A + tristate "Silergy SY7636A voltage regulator" + depends on MFD_SY7636A + help + This driver supports Silergy SY3686A voltage regulator. + config REGULATOR_SY8106A tristate "Silergy SY8106A regulator" depends on I2C && (OF || COMPILE_TEST) diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 580b015296ea..b17c24d93f3b 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -136,6 +136,7 @@ obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o +obj-$(CONFIG_REGULATOR_SY7636A) += sy7636a-regulator.o obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o obj-$(CONFIG_REGULATOR_SY8824X) += sy8824x.o obj-$(CONFIG_REGULATOR_SY8827N) += sy8827n.o diff --git a/drivers/regulator/sy7636a-regulator.c b/drivers/regulator/sy7636a-regulator.c new file mode 100644 index 000000000000..c384c2b6ac46 --- /dev/null +++ b/drivers/regulator/sy7636a-regulator.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: GPL-2.0+ +// +// Functions to access SY3686A power management chip voltages +// +// Copyright (C) 2019 reMarkable AS - http://www.remarkable.com/ +// +// Authors: Lars Ivar Miljeteig +// Alistair Francis + +#include +#include +#include +#include +#include + +#define SY7636A_POLL_ENABLED_TIME 500 + +static int sy7636a_get_vcom_voltage_op(struct regulator_dev *rdev) +{ + int ret; + unsigned int val, val_h; + + ret = regmap_read(rdev->regmap, SY7636A_REG_VCOM_ADJUST_CTRL_L, &val); + if (ret) + return ret; + + ret = regmap_read(rdev->regmap, SY7636A_REG_VCOM_ADJUST_CTRL_H, &val_h); + if (ret) + return ret; + + val |= (val_h << VCOM_ADJUST_CTRL_SHIFT); + + return (val & VCOM_ADJUST_CTRL_MASK) * VCOM_ADJUST_CTRL_SCAL; +} + +static int sy7636a_get_status(struct regulator_dev *rdev) +{ + struct sy7636a *sy7636a = dev_get_drvdata(rdev->dev.parent); + int ret = 0; + + ret = gpiod_get_value_cansleep(sy7636a->pgood_gpio); + if (ret < 0) + dev_err(&rdev->dev, "Failed to read pgood gpio: %d\n", ret); + + return ret; +} + +static const struct regulator_ops sy7636a_vcom_volt_ops = { + .get_voltage = sy7636a_get_vcom_voltage_op, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .get_status = sy7636a_get_status, +}; + +struct regulator_desc desc = { + .name = "vcom", + .id = 0, + .ops = &sy7636a_vcom_volt_ops, + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .enable_reg = SY7636A_REG_OPERATION_MODE_CRL, + .enable_mask = SY7636A_OPERATION_MODE_CRL_ONOFF, + .poll_enabled_time = SY7636A_POLL_ENABLED_TIME, + .regulators_node = of_match_ptr("regulators"), + .of_match = of_match_ptr("vcom"), +}; + +static int sy7636a_regulator_probe(struct platform_device *pdev) +{ + struct sy7636a *sy7636a = dev_get_drvdata(pdev->dev.parent); + struct regulator_config config = { }; + struct regulator_dev *rdev; + struct gpio_desc *gdp; + int ret; + + if (!sy7636a) + return -EPROBE_DEFER; + + platform_set_drvdata(pdev, sy7636a); + + gdp = devm_gpiod_get(sy7636a->dev, "epd-pwr-good", GPIOD_IN); + if (IS_ERR(gdp)) { + dev_err(sy7636a->dev, "Power good GPIO fault %ld\n", PTR_ERR(gdp)); + return PTR_ERR(gdp); + } + + sy7636a->pgood_gpio = gdp; + + ret = regmap_write(sy7636a->regmap, SY7636A_REG_POWER_ON_DELAY_TIME, 0x0); + if (ret) { + dev_err(sy7636a->dev, "Failed to initialize regulator: %d\n", ret); + return ret; + } + + config.dev = &pdev->dev; + config.dev->of_node = sy7636a->dev->of_node; + config.driver_data = sy7636a; + config.regmap = sy7636a->regmap; + + rdev = devm_regulator_register(&pdev->dev, &desc, &config); + if (IS_ERR(rdev)) { + dev_err(sy7636a->dev, "Failed to register %s regulator\n", + pdev->name); + return PTR_ERR(rdev); + } + + return 0; +} + +static const struct platform_device_id sy7636a_regulator_id_table[] = { + { "sy7636a-regulator", }, +}; +MODULE_DEVICE_TABLE(platform, sy7636a_regulator_id_table); + +static struct platform_driver sy7636a_regulator_driver = { + .driver = { + .name = "sy7636a-regulator", + }, + .probe = sy7636a_regulator_probe, + .id_table = sy7636a_regulator_id_table, +}; +module_platform_driver(sy7636a_regulator_driver); + +MODULE_AUTHOR("Lars Ivar Miljeteig "); +MODULE_DESCRIPTION("SY7636A voltage regulator driver"); +MODULE_LICENSE("GPL v2"); -- 2.31.1