Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1188516imm; Wed, 10 Oct 2018 10:25:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV610PvuSHSOsKbgnaofGrFgQtMr0P6gpR9OiYymkS+dfSQBzinF5oK3fAc39bdFTnmPPQmXl X-Received: by 2002:a62:6414:: with SMTP id y20-v6mr35668705pfb.213.1539192333630; Wed, 10 Oct 2018 10:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539192333; cv=none; d=google.com; s=arc-20160816; b=RzrIFwDy+O0eDXRgIdUkFzI5GvQh4BGDlseHw/qEIX2OrSXpw1hKz6Eq101nol/gXg JDGaKN3/6xAMmuoieX93t8JmdJclBSjaOGndodsFgBiF35+gse4ed+Py8WdtuVQZRkfZ rvatauaKM+49W8o7SbIoQhC1COiOTDwzIYlof6oVdr+xgDAkPMrp2q0VlaLjVG7flWPy m0siiHy1r4tnmGDGmWl9IUkg8BjnPj5kEPX3odDJ8xn5y8DUHUQKD/0SeBr2M7wO81vb psqhISkun9leyqfeSYHSFYG5ybhUmiR25u33RkD8vxpFDpJz3fNzCAAc1ZjfCiTO4gi9 VSow== 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=ODo0Gn1HORZVGe7aft/Uydw6t4Ytk6QAHDGBYwLl40U=; b=O1V+YFCcONePYtx5lS0/m8ZbGZgfa81ZjwKqmwSjioSEFXrtp03lNyrl7rcQc9LfX9 cbD52VevpFzydndzHD0/k0X4Q35Ce39mreORG0gxxh7szxM7NSmwhtBfq0T+wVlCyxpd KKvXChm6/BOefw0aCiqPx6/lVr/hs9HamqQNw5Afh9etabLGd6cc7CH1XOAKIIMtSXkf WHQbAklRGpySyuJ/ttCKSeW0TdsA11UmIyOfFHlRa+uPJn4tO8oWUrjMyDNnw5e97fwi kHEJ6+2FWV1nUh5RNJDolXJKw8SxedFjnAjVQTsTo3NCSafgIEg6sJpWFklTlMdXOYxD y2VQ== 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 l14-v6si21038742pfo.118.2018.10.10.10.25.18; Wed, 10 Oct 2018 10:25:33 -0700 (PDT) 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 S1727562AbeJKAqy (ORCPT + 99 others); Wed, 10 Oct 2018 20:46:54 -0400 Received: from shell.v3.sk ([90.176.6.54]:54611 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726670AbeJKAqw (ORCPT ); Wed, 10 Oct 2018 20:46:52 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id A9578BCFB6; Wed, 10 Oct 2018 19:23:41 +0200 (CEST) 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 3KVRyiptfyQB; Wed, 10 Oct 2018 19:23:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id E449DBCFC5; Wed, 10 Oct 2018 19:23:12 +0200 (CEST) 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 VdAFkFThlbpw; Wed, 10 Oct 2018 19:23:08 +0200 (CEST) Received: from belphegor.lan (ip-89-102-31-34.net.upcbroadband.cz [89.102.31.34]) by zimbra.v3.sk (Postfix) with ESMTPSA id 0B9C5BCFB6; Wed, 10 Oct 2018 19:23:07 +0200 (CEST) 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 09/15] Platform: OLPC: add a regulator for the DCON Date: Wed, 10 Oct 2018 19:22:54 +0200 Message-Id: <20181010172300.317643-10-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010172300.317643-1-lkundrak@v3.sk> References: <20181010172300.317643-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 --- drivers/platform/olpc/Kconfig | 1 + drivers/platform/olpc/olpc-ec.c | 65 +++++++++++++++++++++++++++++++++ 2 files changed, 66 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 b9d9a9897dd5..8f82922631a9 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; @@ -347,9 +352,60 @@ 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 =3D=3D 0) + ec->dcon_enabled =3D state; + + return ret; +} + +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, 1); +} + +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, 0); +} + +static int dcon_regulator_is_enabled(struct regulator_dev *rdev) +{ + struct olpc_ec_priv *ec =3D rdev_get_drvdata(rdev); + + return ec->dcon_enabled; +} + +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) @@ -378,6 +434,15 @@ 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, &conf= ig); + 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.0