From patchwork Thu Jan 16 02:56:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bibby Hsieh X-Patchwork-Id: 205650 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, 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 CFCFCC47409 for ; Thu, 16 Jan 2020 02:56:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F4C72465A for ; Thu, 16 Jan 2020 02:56:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="oRAd9PJN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729476AbgAPC4p (ORCPT ); Wed, 15 Jan 2020 21:56:45 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:22993 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729057AbgAPC4o (ORCPT ); Wed, 15 Jan 2020 21:56:44 -0500 X-UUID: caf87e9e076b4a4e92e206d6a5b6c2c0-20200116 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=l3wpXk/uhyCXKXXtWKjWF1p9bNTWnEdUHRhkP+uqsEM=; b=oRAd9PJNDWPZ+Bt7oHyrdILizsirn8o0jSP+HO6gWsVWqilulzOg6s+Qk3wuohKXWugLhlpe/63g7Uq3rBanXG2ufnP4Ipbk543KPoixNljJoarPG+W23CLQ4n4R4IVXmfwqDWJEeMzoz7TL0+FFDAxi4M4vOrgfc9VMTknLcmE=; X-UUID: caf87e9e076b4a4e92e206d6a5b6c2c0-20200116 Received: from mtkcas09.mediatek.inc [(172.21.101.178)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1369943095; Thu, 16 Jan 2020 10:56:39 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 16 Jan 2020 10:56:01 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 16 Jan 2020 10:57:26 +0800 From: Bibby Hsieh To: Wolfram Sang , Bartosz Golaszewski , CC: , , , , , , Bibby Hsieh Subject: [PATCH v10 1/4] dt-binding: eeprom: at24: add vcc-supply property Date: Thu, 16 Jan 2020 10:56:34 +0800 Message-ID: <20200116025637.3524-2-bibby.hsieh@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200116025637.3524-1-bibby.hsieh@mediatek.com> References: <20200116025637.3524-1-bibby.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In some platforms, they disable the power-supply of eeprom due to power consumption reduction. This patch add vcc-supply property. Signed-off-by: Bibby Hsieh Reviewed-by: Rob Herring --- Documentation/devicetree/bindings/eeprom/at24.yaml | 4 ++++ 1 file changed, 4 insertions(+) -- 2.18.0 diff --git a/Documentation/devicetree/bindings/eeprom/at24.yaml b/Documentation/devicetree/bindings/eeprom/at24.yaml index e8778560d966..c04a3b8a6eba 100644 --- a/Documentation/devicetree/bindings/eeprom/at24.yaml +++ b/Documentation/devicetree/bindings/eeprom/at24.yaml @@ -167,6 +167,10 @@ properties: minimum: 1 maximum: 8 + vcc-supply: + description: + phandle of the regulator that provides the supply voltage. + required: - compatible - reg From patchwork Thu Jan 16 02:56:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bibby Hsieh X-Patchwork-Id: 205651 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, 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 AD615C32771 for ; Thu, 16 Jan 2020 02:56:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78F5F2467E for ; Thu, 16 Jan 2020 02:56:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="ovFVlxwC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729066AbgAPC4m (ORCPT ); Wed, 15 Jan 2020 21:56:42 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:56859 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728901AbgAPC4m (ORCPT ); Wed, 15 Jan 2020 21:56:42 -0500 X-UUID: 126ce06ae2334d8bbdb17346fed09442-20200116 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=LtjPNUgsXNGW2XU98MsD/otonEB6WtDiyz4/NVSxDTI=; b=ovFVlxwCPFkO0/32sCWG1QgOn0QOHvis/UneWiTsXtQP+AJjQOCCGEacv6t36LY4ge7RdjWHjUuiqWIR1nPfmvasr9SsKA+6WsIKkmAKchBaEEV3C6bYvJCtBG1QGRBpGd+rPvpsAAoCpRBfQkXK9AI6miDL6GfFPx3HbexHCK4=; X-UUID: 126ce06ae2334d8bbdb17346fed09442-20200116 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 705813892; Thu, 16 Jan 2020 10:56:39 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 16 Jan 2020 10:56:02 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 16 Jan 2020 10:57:26 +0800 From: Bibby Hsieh To: Wolfram Sang , Bartosz Golaszewski , CC: , , , , , , Bibby Hsieh Subject: [PATCH v10 3/4] misc: eeprom: at24: support pm_runtime control Date: Thu, 16 Jan 2020 10:56:36 +0800 Message-ID: <20200116025637.3524-4-bibby.hsieh@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200116025637.3524-1-bibby.hsieh@mediatek.com> References: <20200116025637.3524-1-bibby.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Although in the most platforms, the power of eeprom are alway on, some platforms disable the eeprom power in order to meet low power request. This patch add the pm_runtime ops to control power to support all platforms. Signed-off-by: Bibby Hsieh --- drivers/misc/eeprom/at24.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) -- 2.18.0 diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 0681d5fdd538..2fe1b5e0e034 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -22,6 +22,7 @@ #include #include #include +#include #include /* Address pointer is 16 bit. */ @@ -91,6 +92,7 @@ struct at24_data { struct gpio_desc *wp_gpio; + struct regulator *vcc_reg; /* * Some chips tie up multiple I2C addresses; dummy devices reserve * them for us, and we'll use them with SMBus calls. @@ -662,6 +664,10 @@ static int at24_probe(struct i2c_client *client) at24->client[0].client = client; at24->client[0].regmap = regmap; + at24->vcc_reg = devm_regulator_get(dev, "vcc"); + if (IS_ERR(at24->vcc_reg)) + return PTR_ERR(at24->vcc_reg); + at24->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_HIGH); if (IS_ERR(at24->wp_gpio)) return PTR_ERR(at24->wp_gpio); @@ -701,6 +707,12 @@ static int at24_probe(struct i2c_client *client) i2c_set_clientdata(client, at24); + err = regulator_enable(at24->vcc_reg); + if (err) { + dev_err(dev, "Failed to enable vcc regulator\n"); + return err; + } + /* enable runtime pm */ pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -713,6 +725,7 @@ static int at24_probe(struct i2c_client *client) pm_runtime_idle(dev); if (err) { pm_runtime_disable(dev); + regulator_disable(at24->vcc_reg); return -ENODEV; } @@ -728,15 +741,42 @@ static int at24_probe(struct i2c_client *client) static int at24_remove(struct i2c_client *client) { + struct at24_data *at24 = i2c_get_clientdata(client); + pm_runtime_disable(&client->dev); + if (!pm_runtime_status_suspended(&client->dev)) + regulator_disable(at24->vcc_reg); pm_runtime_set_suspended(&client->dev); return 0; } +static int __maybe_unused at24_suspend(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct at24_data *at24 = i2c_get_clientdata(client); + + return regulator_disable(at24->vcc_reg); +} + +static int __maybe_unused at24_resume(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct at24_data *at24 = i2c_get_clientdata(client); + + return regulator_enable(at24->vcc_reg); +} + +static const struct dev_pm_ops at24_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(at24_suspend, at24_resume, NULL) +}; + static struct i2c_driver at24_driver = { .driver = { .name = "at24", + .pm = &at24_pm_ops, .of_match_table = at24_of_match, .acpi_match_table = ACPI_PTR(at24_acpi_ids), }, From patchwork Thu Jan 16 02:56:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bibby Hsieh X-Patchwork-Id: 205649 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, 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 C7BA3C32771 for ; Thu, 16 Jan 2020 02:56:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 969362467C for ; Thu, 16 Jan 2020 02:56:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="skbTP87n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729025AbgAPC4r (ORCPT ); Wed, 15 Jan 2020 21:56:47 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:22993 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729274AbgAPC4q (ORCPT ); Wed, 15 Jan 2020 21:56:46 -0500 X-UUID: 00945ec16c45493482df239c5d5cddd1-20200116 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=Dndcsd5tlSGVB1znTJcds0eLsHRPvv+LCRBkyUFsTwQ=; b=skbTP87na6SzTlHNKVXSZBrC5uD/KbiRDmXP+vP3yScVD6FSQpC7J4JRkHIG26LYHEkNJiqbp1fAz0fadKsPqr6pGqUByQqoLl2IAZo80FcvafEsAWJeb3avswUzSDOwxs0ugpaYhv0rq3EI44gYdfqhoD4cTvqBKrbggnluzTM=; X-UUID: 00945ec16c45493482df239c5d5cddd1-20200116 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 2125257112; Thu, 16 Jan 2020 10:56:40 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 16 Jan 2020 10:56:11 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 16 Jan 2020 10:57:26 +0800 From: Bibby Hsieh To: Wolfram Sang , Bartosz Golaszewski , CC: , , , , , , Bibby Hsieh Subject: [PATCH v10 4/4] i2c: core: support bus regulator controlling in adapter Date: Thu, 16 Jan 2020 10:56:37 +0800 Message-ID: <20200116025637.3524-5-bibby.hsieh@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200116025637.3524-1-bibby.hsieh@mediatek.com> References: <20200116025637.3524-1-bibby.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 --- drivers/i2c/i2c-core-base.c | 81 +++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 3 ++ 2 files changed, 84 insertions(+) -- 2.18.0 diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 9333c865d4a9..9b9e96b094ca 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -306,6 +306,7 @@ 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 = client->adapter; struct i2c_driver *driver; int status; @@ -371,6 +372,12 @@ static int i2c_device_probe(struct device *dev) dev_dbg(dev, "probe\n"); + status = regulator_enable(adap->bus_reg); + 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; @@ -407,6 +414,7 @@ static int i2c_device_probe(struct device *dev) static int i2c_device_remove(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); + struct i2c_adapter *adap = client->adapter; struct i2c_driver *driver; int status = 0; @@ -420,6 +428,8 @@ static int i2c_device_remove(struct device *dev) } dev_pm_domain_detach(&client->dev, true); + if (!pm_runtime_status_suspended(&adap->dev)) + regulator_disable(adap->bus_reg); dev_pm_clear_wake_irq(&client->dev); device_init_wakeup(&client->dev, false); @@ -431,6 +441,71 @@ static int i2c_device_remove(struct device *dev) return status; } +#ifdef CONFIG_PM_SLEEP +static int i2c_resume(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + struct i2c_adapter *adap = client->adapter; + int err; + + if (pm_runtime_status_suspended(&adap->dev)) { + err = regulator_enable(adap->bus_reg); + if (err) + return err; + } + + return pm_generic_resume(dev); +} + +static int i2c_suspend(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + struct i2c_adapter *adap = client->adapter; + int err; + + if (!pm_runtime_status_suspended(&adap->dev)) { + err = regulator_disable(adap->bus_reg); + if (err) + return err; + } + + return pm_generic_suspend(dev); +} +#endif + +#ifdef CONFIG_PM +static int i2c_runtime_resume(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + struct i2c_adapter *adap = client->adapter; + int err; + + err = regulator_enable(adap->bus_reg); + if (err) + return err; + + return pm_generic_runtime_resume(dev); +} + +static int i2c_runtime_suspend(struct device *dev) +{ + struct i2c_client *client = i2c_verify_client(dev); + struct i2c_adapter *adap = client->adapter; + int err; + + err = pm_generic_runtime_suspend(dev); + if (err) + return err; + + return regulator_disable(adap->bus_reg); +} +#endif + +static const struct dev_pm_ops i2c_device_pm = { + SET_SYSTEM_SLEEP_PM_OPS(i2c_suspend, i2c_resume) + 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); @@ -488,6 +563,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); @@ -1351,6 +1427,11 @@ static int i2c_register_adapter(struct i2c_adapter *adap) goto out_reg; dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); + adap->bus_reg = devm_regulator_get(&adap->dev, "bus"); + if (IS_ERR(adap->bus_reg)) { + res = PTR_ERR(adap->bus_reg); + goto out_reg; + } pm_runtime_no_callbacks(&adap->dev); pm_suspend_ignore_children(&adap->dev, true); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index d2f786706657..833b81a680da 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 */ @@ -330,6 +331,7 @@ struct i2c_client { int init_irq; /* irq set at initialization */ int irq; /* irq issued by device */ struct list_head detected; + #if IS_ENABLED(CONFIG_I2C_SLAVE) i2c_slave_cb_t slave_cb; /* callback for slave mode */ #endif @@ -723,6 +725,7 @@ struct i2c_adapter { const struct i2c_adapter_quirks *quirks; struct irq_domain *host_notify_domain; + struct regulator *bus_reg; }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)