Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2205613imu; Thu, 10 Jan 2019 10:01:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN4SwoWNurmtHj/DYrWVG1pJINMBmuBguPIsj9YAVlpP3Qiu5fAKmiOR1zMHgukPtTseV7lh X-Received: by 2002:a62:3541:: with SMTP id c62mr11063561pfa.19.1547143264480; Thu, 10 Jan 2019 10:01:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547143264; cv=none; d=google.com; s=arc-20160816; b=FqvFH/MuNBWnj6q7EEF0vx+V/XNMixdSb5zlednO3rgvHfme18cIWDKbwA0Pk74Lnx w+K36cOYnh4Dz0KPVGSz+DDH4GaUccTqQ0PChdOZI5v5xIs9UL/7lDnxizsoZp4R8QTJ ROOu0CH466rHgWVsrLb/Fe6Cl8SkfiBwUtkxbiK/QG3mZ+c7CBeM5Pd2a98fzfxlKom2 77mgrRbvwZrOt3I6gHW71cSUx7hh+aSfrA8e4P2Y6aUG4aVA8rGs5ce5WxIyAI3Ufhmj nT/oxGWQsVkbgiCVRegkcJxokJn0bO7M8WCRy7djJjgaSiSAXEfrpbJVby6x4RW7I7Sg q1FQ== 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=eKWkZjiE6JVKgByV0oYdW/2RAQIpV634L48H+wUDv4w=; b=CpXGQMnPhnUuGeaFo0xbzzmJEYjs8pcIvbK+uwZyfmovCse+4EcPRi0A+VmYS8v+/2 F+tWC5owrItbhyE02Pnbzcpej/QvJLctDL3DsCFpvBOsdNu3JUPyIMlwobMJ+RGUab2S ImwoZlGK+mrjzHVSK9jCxEnynDCml7P9mKKzO0Ja1d5ScB8eK3QBgi34IsgHMZQy5cSd YfFhyOgujRHkGgHtNxMW67+j1jst4iyXF4vpD3Ak/4L9KT+JGwVQJ39C8Qcdv10grIwJ EQQtlmL72tQMO3rDFJe6jty4OEDVJuYO3h69ndLlLOhMVCYGA2vZqwMhyKbwQroGfHNq 8fMA== 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 d13si22533946pgh.196.2019.01.10.10.00.49; Thu, 10 Jan 2019 10:01:04 -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 S1730900AbfAJR7b (ORCPT + 99 others); Thu, 10 Jan 2019 12:59:31 -0500 Received: from shell.v3.sk ([90.176.6.54]:58594 "EHLO shell.v3.sk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730809AbfAJR7W (ORCPT ); Thu, 10 Jan 2019 12:59:22 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id CCD9C1002F3; Thu, 10 Jan 2019 18:59:18 +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 GuJ5w0lho0Ks; Thu, 10 Jan 2019 18:59:06 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 994CD1002F9; Thu, 10 Jan 2019 18:59:00 +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 0ZLcfJBxow8y; Thu, 10 Jan 2019 18:58:56 +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 233091002FA; Thu, 10 Jan 2019 18:58:55 +0100 (CET) From: Lubomir Rintel To: Andy Shevchenko , Darren Hart Cc: Rob Herring , Russell King , Mark Rutland , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lubomir Rintel Subject: [PATCH v5 07/10] Platform: OLPC: Add a regulator for the DCON Date: Thu, 10 Jan 2019 18:58:42 +0100 Message-Id: <20190110175845.1203986-8-lkundrak@v3.sk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190110175845.1203986-1-lkundrak@v3.sk> References: <20190110175845.1203986-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 559f843199d7..858ac1d2290a 100644 --- a/drivers/platform/olpc/Kconfig +++ b/drivers/platform/olpc/Kconfig @@ -1,4 +1,5 @@ config OLPC_EC + select REGULATOR bool =20 config OLPC_XO175_EC diff --git a/drivers/platform/olpc/olpc-ec.c b/drivers/platform/olpc/olpc= -ec.c index a91f78245f5e..8566bcf2938d 100644 --- a/drivers/platform/olpc/olpc-ec.c +++ b/drivers/platform/olpc/olpc-ec.c @@ -16,6 +16,7 @@ #include #include #include +#include #include =20 struct ec_cmd_desc { @@ -36,6 +37,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; @@ -346,9 +351,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) @@ -376,6 +433,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.20.1