From patchwork Mon Mar 8 04:36:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 12121411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DCF4C433E6 for ; Mon, 8 Mar 2021 04:38:29 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9319664FE4 for ; Mon, 8 Mar 2021 04:38:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9319664FE4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/JrEU/xd+Xc7dR3C61EDbLBI8BLu8A2VlNhszTCCVvE=; b=j59qIcKyQbKP+MvHpbYKH9Znf 4rPlxljCXSx0DS49tkzEStV8oPXtgS2HCs8E3rFB2Y2qJFweqR3C3Nz3NBNP1GrE6BGDludjNHfWK icbpb4dxkcpeh6pmi0idYuMMN5yl4oLiZnTrzwcbAMGcKFnkwUBGNLYzUlIo+eEzgyhO94985nLqO 9W6DoJpsq7XnTbL6buXHCcyjLi17UaDNMLqA7eF5zcBUfUbT7qVXaf5b6u7CX+lGr78zSY4Fm0y/G KuP666DclvIDUbtD7aTw+fCH9ERzVWF5cI+lMe0Y1ks/JAE5jfgFZOrd1qEdOi+XyvqzbWQicrX/f JwlBGcilQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lJ7dA-00F7Im-CY; Mon, 08 Mar 2021 04:36:33 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lJ7cv-00F7E7-CX for linux-arm-kernel@lists.infradead.org; Mon, 08 Mar 2021 04:36:19 +0000 Received: by mail-pj1-x102f.google.com with SMTP id ga23-20020a17090b0397b02900c0b81bbcd4so2270923pjb.0 for ; Sun, 07 Mar 2021 20:36:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FHYldnLHVjUCtTPUMHFVsgGiL0sQpC3TJ8ogHG6aen8=; b=kf5mR4d+LR5JbmXKw7GBAbezQrJuBbdr23XLj7F4h0q19tZUWG1P3AbEmDtzUGrnZZ QIPpIARW/MuIw3pbo79B7vjypi5C1e/tuJuU40TMB7Z3pesGzJWkJjAohZ2KJdLH+7eK x5rimKui7iYlNXUZegTL0pvXUDliEdJbc8fIw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FHYldnLHVjUCtTPUMHFVsgGiL0sQpC3TJ8ogHG6aen8=; b=U4IR80pT5RiRisg0hEMMVx+B2B7jTgSYFwEThK5IEcgBsnivygONVS/PAVY7/90ImV JeaB5SEQ2Xmgi8Ct4WftvaGRVS3DoQdrERXjuxsoFj0GuJ6jMZITK5WLDQMw9tqIN15q gCpHRudu+ZQr34csl/p2rbZ24xnbFKYvYtBp27f970p5IJrtX1t/l2VYUKbIWlcMsowv +zKLZfmWUN2khYCrH8pAfanjp0H0LundaPx7p9HCAC4FOMiju+DSr6ig+UHsFOlWsBjy cDAW/23gwlyqcbrsOdIdZN3maD4GmGZBpagwaehBX/WoDs93NrPRHI1cZAKUMUsg7m4y 2VLw== X-Gm-Message-State: AOAM53014xXf02NGGrYTkpvSUNZkflViyDKnddL3STdS2ikxlHxc2BG/ wxMCP4D1PGMPnBsV+gX68O/1iA== X-Google-Smtp-Source: ABdhPJxfM03eVHY5cSuqb4Q3jnfIMSUxwGHkcMGr83Img4syS9OwBsVqxPVXEldm7tF596anODr1XA== X-Received: by 2002:a17:90a:d590:: with SMTP id v16mr22232876pju.118.1615178176205; Sun, 07 Mar 2021 20:36:16 -0800 (PST) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:5da1:da1b:5bcf:2d46]) by smtp.gmail.com with ESMTPSA id q2sm8191562pfu.215.2021.03.07.20.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Mar 2021 20:36:15 -0800 (PST) From: Hsin-Yi Wang To: Wolfram Sang , Bartosz Golaszewski , linux-i2c@vger.kernel.org Cc: Matthias Brugger , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Bibby Hsieh , Marek Szyprowski Subject: [PATCH v16 1/2] dt-binding: i2c: add bus-supply property Date: Mon, 8 Mar 2021 12:36:06 +0800 Message-Id: <20210308043607.957156-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210308043607.957156-1-hsinyi@chromium.org> References: <20210308043607.957156-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210308_043617_561799_DF45D271 X-CRM114-Status: GOOD ( 12.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bibby Hsieh In some platforms, they disable the power-supply of i2c due to power consumption reduction. This patch add bus-supply property. Signed-off-by: Bibby Hsieh Acked-by: Rob Herring Signed-off-by: Hsin-Yi Wang --- Documentation/devicetree/bindings/i2c/i2c.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/i2c/i2c.txt b/Documentation/devicetree/bindings/i2c/i2c.txt index df41f72afc87..88972bd62ce1 100644 --- a/Documentation/devicetree/bindings/i2c/i2c.txt +++ b/Documentation/devicetree/bindings/i2c/i2c.txt @@ -130,6 +130,9 @@ wants to support one of the below features, it should adapt these bindings. - wakeup-source device can be used as a wakeup source. +- bus-supply + phandle to the regulator that provides power to SCL/SDA. + Binding may contain optional "interrupts" property, describing interrupts used by the device. I2C core will assign "irq" interrupt (or the very first interrupt if not using interrupt names) as primary interrupt for the slave. From patchwork Mon Mar 8 04:36:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 12121415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74084C433E6 for ; Mon, 8 Mar 2021 04:38:31 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A1426514A for ; Mon, 8 Mar 2021 04:38:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A1426514A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+3YuMfrrCkZpQJri05yquQ0/32RQ/drRrGlUUbu8JIo=; b=PtPq567LDVlzPDJktXKp2N/va cxF8z0+MTTXKDT8xy54korrjz3YFIzxb2OjmYdN9W0Z89ZD0hT8UeBZBbkBWjiOatB+nWx0Ovbl9K BzfF4BF/Rq2nq5SYmf3C5prthtdi4Ohc8e+yzR0jZGRZUDkCr+1TziSdIK9nzG/TI7UZKO+jFdhmx Yjw6pNdgEp2US1BAJi32oVbp4gNCnlnp+wnoPVSs3BQDQQ4N3JJW7LTQZYk7OXHz+8ThqniuxD0Tq k+K1tI3kN9jrj7vfdh/d0sJTiz83xxyoRvNaqxPCIL9IaGC96bZOIIi4n8JQ8pVVpvhVNLNC1JlwT UYuxz7iMw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lJ7dQ-00F7QH-GO; Mon, 08 Mar 2021 04:36:48 +0000 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lJ7cy-00F7Eu-GE for linux-arm-kernel@lists.infradead.org; Mon, 08 Mar 2021 04:36:24 +0000 Received: by mail-pg1-x535.google.com with SMTP id h4so5626964pgf.13 for ; Sun, 07 Mar 2021 20:36:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zCUYo1BkJJoqTymCi6hMvf2QLrcDwpw0+n4l7ZEpGN4=; b=T4nNWfeEEpfK2XSkki4jbWraVBbxktuRTS2HhXQoYGtkzL34pFQHtqzEHkw+0KMCvW IC6Es0tS2VVoolWQLYrOCRxyEd8JnsTdt/8jJd6LWWobrBPilU6YjAZTwAkWNF9VjRS7 Vc3mhkTOhGGB4yIYCv7eDSY+hCy8bpNX/joSg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zCUYo1BkJJoqTymCi6hMvf2QLrcDwpw0+n4l7ZEpGN4=; b=fEDe9LNN6TaqfbKhN5C/3jpp1kNgjCklgX/1jn2qyjtvRVVnSzf6aEteZLQrgLQ1k8 EzK1QO/hgArwaFriTj2D7LsN1lueC40gAb/ZWjdADqKxL1LMOry7sGVWSZFVeM7uL0Vx k1PLvD6cr9QRH0UdXAgYZsaXEptaFSz/m4gQ9un+uEDH8EO+316WXBkCh4xKsVgdMK9D X1fzZdeyqugbdo73AAeBCgwmGvEjTWjAt1vtnrhQgeIqcTHWn0mI9fN3UEeLMguaOb9g /DK326yMCIeadkEYMaymbptP/VXFcFfjJjiR8NwfYRcW6AZD5p38UU0kkrTSeyh4UZlv hwOg== X-Gm-Message-State: AOAM532KTXECpOtqbZWCAJCwiYBUPaT47rMeeWjcGTu8OkP0F/1MNgu6 g+p/C2cORz0KxVmgCb641mSH+g== X-Google-Smtp-Source: ABdhPJz6orCjYR3o+ZywlBEuIT4SmHbby45FSbzAS27Gny6Lq5/Vvs7jh8ldq2xhkJ4Ot5U/vCCqXQ== X-Received: by 2002:aa7:92c7:0:b029:1ee:75b2:2dab with SMTP id k7-20020aa792c70000b02901ee75b22dabmr20048195pfa.61.1615178178182; Sun, 07 Mar 2021 20:36:18 -0800 (PST) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:5da1:da1b:5bcf:2d46]) by smtp.gmail.com with ESMTPSA id q2sm8191562pfu.215.2021.03.07.20.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Mar 2021 20:36:17 -0800 (PST) From: Hsin-Yi Wang To: Wolfram Sang , Bartosz Golaszewski , linux-i2c@vger.kernel.org Cc: Matthias Brugger , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Bibby Hsieh , Marek Szyprowski Subject: [PATCH v16 2/2] i2c: core: support bus regulator controlling in adapter Date: Mon, 8 Mar 2021 12:36:07 +0800 Message-Id: <20210308043607.957156-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210308043607.957156-1-hsinyi@chromium.org> References: <20210308043607.957156-1-hsinyi@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210308_043620_727272_30593D0F X-CRM114-Status: GOOD ( 19.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bibby Hsieh Although in the most platforms, the bus power of i2c are alway on, some platforms disable the i2c bus power in order to meet low power request. We get and enable bulk regulator in i2c adapter device. Signed-off-by: Bibby Hsieh Signed-off-by: Marek Szyprowski Signed-off-by: Hsin-Yi Wang --- drivers/i2c/i2c-core-base.c | 93 +++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 2 + 2 files changed, 95 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 63ebf722a424..667f4a4de7cc 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -439,12 +439,14 @@ static int i2c_smbus_host_notify_to_irq(const struct i2c_client *client) static int i2c_device_probe(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); + struct i2c_adapter *adap; struct i2c_driver *driver; int status; if (!client) return 0; + adap = client->adapter; client->irq = client->init_irq; if (!client->irq) { @@ -510,6 +512,12 @@ static int i2c_device_probe(struct device *dev) dev_dbg(dev, "probe\n"); + status = regulator_enable(adap->bus_regulator); + if (status < 0) { + dev_err(&adap->dev, "Failed to enable power regulator\n"); + goto err_clear_wakeup_irq; + } + status = of_clk_set_defaults(dev->of_node, false); if (status < 0) goto err_clear_wakeup_irq; @@ -550,8 +558,10 @@ static int i2c_device_probe(struct device *dev) static int i2c_device_remove(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); + struct i2c_adapter *adap; struct i2c_driver *driver; + adap = client->adapter; driver = to_i2c_driver(dev->driver); if (driver->remove) { int status; @@ -564,6 +574,8 @@ static int i2c_device_remove(struct device *dev) } dev_pm_domain_detach(&client->dev, true); + if (!pm_runtime_status_suspended(&client->dev)) + regulator_disable(adap->bus_regulator); dev_pm_clear_wake_irq(&client->dev); device_init_wakeup(&client->dev, false); @@ -576,6 +588,80 @@ static int i2c_device_remove(struct device *dev) return 0; } +#ifdef CONFIG_PM_SLEEP +static int i2c_resume_early(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + int err; + + if (!client) + return 0; + + if (!pm_runtime_status_suspended(&client->dev)) { + err = regulator_enable(client->adapter->bus_regulator); + if (err) + return err; + } + + return pm_generic_resume_early(&client->dev); +} + +static int i2c_suspend_late(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + int err; + + if (!client) + return 0; + + err = pm_generic_suspend_late(&client->dev); + if (err) + return err; + + if (!pm_runtime_status_suspended(&client->dev)) + return regulator_disable(client->adapter->bus_regulator); + + return 0; +} +#endif + +#ifdef CONFIG_PM +static int i2c_runtime_resume(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + int err; + + if (!client) + return 0; + + err = regulator_enable(client->adapter->bus_regulator); + if (err) + return err; + + return pm_generic_runtime_resume(&client->dev); +} + +static int i2c_runtime_suspend(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + int err; + + if (!client) + return 0; + + err = pm_generic_runtime_suspend(&client->dev); + if (err) + return err; + + return regulator_disable(client->adapter->bus_regulator); +} +#endif + +static const struct dev_pm_ops i2c_device_pm = { + SET_LATE_SYSTEM_SLEEP_PM_OPS(i2c_suspend_late, i2c_resume_early) + SET_RUNTIME_PM_OPS(i2c_runtime_suspend, i2c_runtime_resume, NULL) +}; + static void i2c_device_shutdown(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); @@ -633,6 +719,7 @@ struct bus_type i2c_bus_type = { .probe = i2c_device_probe, .remove = i2c_device_remove, .shutdown = i2c_device_shutdown, + .pm = &i2c_device_pm, }; EXPORT_SYMBOL_GPL(i2c_bus_type); @@ -1446,6 +1533,12 @@ static int i2c_register_adapter(struct i2c_adapter *adap) if (res) goto out_reg; + adap->bus_regulator = devm_regulator_get(&adap->dev, "bus"); + if (IS_ERR(adap->bus_regulator)) { + res = PTR_ERR(adap->bus_regulator); + goto out_reg; + } + pm_runtime_no_callbacks(&adap->dev); pm_suspend_ignore_children(&adap->dev, true); pm_runtime_enable(&adap->dev); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 56622658b215..ec87758d9f40 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -15,6 +15,7 @@ #include /* for struct device */ #include /* for completion */ #include +#include #include #include /* for Host Notify IRQ */ #include /* for struct device_node */ @@ -721,6 +722,7 @@ struct i2c_adapter { const struct i2c_adapter_quirks *quirks; struct irq_domain *host_notify_domain; + struct regulator *bus_regulator; }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)