Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp672541imu; Fri, 16 Nov 2018 08:27:27 -0800 (PST) X-Google-Smtp-Source: AJdET5dMxDqTbAxiratRNJez86gn0tp6SXmU4kEpwa4TXut/8n2WUcRQzbzJxr1onBKgtTcmgFrG X-Received: by 2002:a65:65c9:: with SMTP id y9mr10787074pgv.438.1542385647926; Fri, 16 Nov 2018 08:27:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542385647; cv=none; d=google.com; s=arc-20160816; b=AQkTOjFRaYZpNh1HuVzehPjXG1NFl4yWTfM9zKMXbn7PhgBA+aydS8QoVMnwQZv1ER MLFQHlmTwC9iQLkwvge8w8d0mOgiq+QaxJuCg9l+adKs2diTijb64ollf6/iWliREE7Z C0rYQhsk1d3paFoAN7F9FexQhMXZghNzPwwcHnj31e9HXoKEq/BNM0d2wNMG5lXEmWT1 Et2gGXfdRRGTW9FRYCAGBuzBgoVKYJzLfre3yIW53clkNejZWekRdJsTnMfUqlJNDeoo yOi3POOrbQPInRnMPA728pxT4pkESBUpZziTWYi40lQRydkBcyLa5oFfVw0+x7w6fKX/ dEfw== 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; bh=M03wOl6J2+wgFUOp0R8YM225e8reLsZqbmYbBsqfrvc=; b=K8tDYvpjgEIApO4tC1xN3swH7c5sRAcFUE9I6hu/nev6Yh3kZlvEY3FtLYw1D4v2pt zlNEbSG6fzCYYgAognUkPRnna8Lpb9XWh6IjpZ78aPRBGnoEPCsE+zEC7Y5cw9yhQa8J YGZbUi4OUQAQsedCou+gJDod1hHr3V4LLKG8FsC+9ll+frwMyg7UbYHLAONiBdug6VE0 FyoHFHN21hCRXVuGKAnjrG/6zznAIGwoTy/X8n/ipTIJvhDnoKo2wqoPUe4evERVtdRQ VzioL2QhNrmR2v5lDVu81NrnDKW1BmTV8Ka62UvfCSEFV3FIgj13/+Z916ToojX6WBbb /XFg== 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 t5si12827731pgm.79.2018.11.16.08.27.13; Fri, 16 Nov 2018 08:27: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 S2390295AbeKQCiN (ORCPT + 99 others); Fri, 16 Nov 2018 21:38:13 -0500 Received: from shell.v3.sk ([90.176.6.54]:57111 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390040AbeKQCiM (ORCPT ); Fri, 16 Nov 2018 21:38:12 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 3160C52C13; Fri, 16 Nov 2018 17:25:07 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id OWW3vXZg0E_7; Fri, 16 Nov 2018 17:24:41 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id A772252C54; Fri, 16 Nov 2018 17:24:25 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id LjF0DCxKA09F; Fri, 16 Nov 2018 17:24:23 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id D56E952DBB; Fri, 16 Nov 2018 17:24:17 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven , Darren Hart , Andy Shevchenko Cc: Greg Kroah-Hartman , James Cameron , Sebastian Reichel , Rob Herring , Mark Rutland , Eric Miao , Haojian Zhuang , Daniel Mack , Robert Jarzmik , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, platform-driver-x86@vger.kernel.org, devel@driverdev.osuosl.org, linux-pm@vger.kernel.org, Lubomir Rintel Subject: [PATCH v2 10/17] Platform: OLPC: add a regulator for the DCON Date: Fri, 16 Nov 2018 17:23:56 +0100 Message-Id: <20181116162403.49854-11-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181116162403.49854-1-lkundrak@v3.sk> References: <20181116162403.49854-1-lkundrak@v3.sk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All OLPC ECs are able to turn the power to the DCON on an off. Use the regulator framework to expose the functionality. Signed-off-by: Lubomir Rintel --- Changes since v1: - Use idiomatic form of return on error - Avoid mixing bool and int drivers/platform/olpc/Kconfig | 1 + drivers/platform/olpc/olpc-ec.c | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/drivers/platform/olpc/Kconfig b/drivers/platform/olpc/Kconfi= g index 7c643d24ad0f..c5a872fb286f 100644 --- a/drivers/platform/olpc/Kconfig +++ b/drivers/platform/olpc/Kconfig @@ -6,6 +6,7 @@ config OLPC select OF select OF_PROMTREE if X86 select IRQ_DOMAIN + select REGULATOR help Add support for detecting the unique features of the OLPC XO hardware. diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc= -ec.c index 2b80174b8f4b..f725ab2a2db9 100644 --- a/drivers/platform/olpc/olpc-ec.c +++ b/drivers/platform/olpc/olpc-ec.c @@ -14,6 +14,7 @@ #include #include #include +#include #include =20 struct ec_cmd_desc { @@ -34,6 +35,10 @@ struct olpc_ec_priv { struct work_struct worker; struct mutex cmd_lock; =20 + /* DCON regulator */ + struct regulator_dev *dcon_rdev; + bool dcon_enabled; + /* Pending EC commands */ struct list_head cmd_q; spinlock_t cmd_q_lock; @@ -344,9 +349,61 @@ static struct dentry *olpc_ec_setup_debugfs(void) =20 #endif /* CONFIG_DEBUG_FS */ =20 +static int olpc_ec_set_dcon_power(struct olpc_ec_priv *ec, bool state) +{ + unsigned char ec_byte =3D state; + int ret; + + if (ec->dcon_enabled =3D=3D state) + return 0; + + ret =3D olpc_ec_cmd(EC_DCON_POWER_MODE, &ec_byte, 1, NULL, 0); + if (ret) + return ret; + + ec->dcon_enabled =3D state; + return 0; +} + +static int dcon_regulator_enable(struct regulator_dev *rdev) +{ + struct olpc_ec_priv *ec =3D rdev_get_drvdata(rdev); + + return olpc_ec_set_dcon_power(ec, true); +} + +static int dcon_regulator_disable(struct regulator_dev *rdev) +{ + struct olpc_ec_priv *ec =3D rdev_get_drvdata(rdev); + + return olpc_ec_set_dcon_power(ec, false); +} + +static int dcon_regulator_is_enabled(struct regulator_dev *rdev) +{ + struct olpc_ec_priv *ec =3D rdev_get_drvdata(rdev); + + return ec->dcon_enabled ? 1 : 0; +} + +static struct regulator_ops dcon_regulator_ops =3D { + .enable =3D dcon_regulator_enable, + .disable =3D dcon_regulator_disable, + .is_enabled =3D dcon_regulator_is_enabled, +}; + +static const struct regulator_desc dcon_desc =3D { + .name =3D "dcon", + .id =3D 0, + .ops =3D &dcon_regulator_ops, + .type =3D REGULATOR_VOLTAGE, + .owner =3D THIS_MODULE, +}; + static int olpc_ec_probe(struct platform_device *pdev) { struct olpc_ec_priv *ec; + struct regulator_config config =3D { }; int err; =20 if (!ec_driver) @@ -374,6 +431,16 @@ static int olpc_ec_probe(struct platform_device *pde= v) return err; } =20 + config.dev =3D pdev->dev.parent; + config.driver_data =3D ec; + ec->dcon_enabled =3D true; + ec->dcon_rdev =3D devm_regulator_register(&pdev->dev, &dcon_desc, + &config); + if (IS_ERR(ec->dcon_rdev)) { + dev_err(&pdev->dev, "failed to register DCON regulator\n"); + return PTR_ERR(ec->dcon_rdev); + } + ec->dbgfs_dir =3D olpc_ec_setup_debugfs(); =20 return err; --=20 2.19.1