From patchwork Sun Feb 17 09:14:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 10816907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DA63139A for ; Sun, 17 Feb 2019 09:15:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DEFE287B3 for ; Sun, 17 Feb 2019 09:15:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7274529738; Sun, 17 Feb 2019 09:15:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62D8A287B3 for ; Sun, 17 Feb 2019 09:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727057AbfBQJPP (ORCPT ); Sun, 17 Feb 2019 04:15:15 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:41304 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726921AbfBQJO4 (ORCPT ); Sun, 17 Feb 2019 04:14:56 -0500 Received: by mail-pg1-f193.google.com with SMTP id m1so6957960pgq.8 for ; Sun, 17 Feb 2019 01:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MaBbem7EOSDQZkBwVKyj6IqtqFXAHgbLHZFaAWD/vYo=; b=gozDVM2k3uvO0y910fROCg6L+V9pCNwENWT7ssgaB160Mk8hnaeQMLQkNSat4gr0z7 Flx6C1R1Gdmf1JUBxrFoePo2qIIjrU1XiblFpbwvGygyHf1Qkl02D1ZM2UzkOUY6Xx/C H6eM9Xs/2zCv4XYj9UUSKSOKuoTU2AJNAzdgk= 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=MaBbem7EOSDQZkBwVKyj6IqtqFXAHgbLHZFaAWD/vYo=; b=SJbIMr/+Z5hzoxhdM3qfG3Q82SPzMT+8YzLM73fE2n0YWn/xCrCei20tp2hDP10peB 4nzEt3I8WbTWw69Koezk98N8nQexP+Wgp0cKUQUaiNde44vwLDcBvvP0T1cxam2v6Yhz sntM9bJ6bfuH5XjFl9Z547ndQ1ly9X1j6MFo2UE04gOJmtmQQYdpFrTxq7AvUhpjrALF P4wKfSynnXrWqH2nNp7T+kR5TUEiS5Gzhc5ROYXCK8iqiRykbU5/MAEUU8ujhCZXdDm/ on0XRJ0a48/i0S/Ffdme0o0bom4SBy07eDsAxBgJJbePvsQNS+aBmDT3YULZCoFP5T8o T0Dw== X-Gm-Message-State: AHQUAuYH77ldQXn79K3X9URhHc0Pr9miCBLv79xQhwIqkEKWCeXuXbFN AnjmC0vBmXNt5wsraQU8MxBk4Q== X-Google-Smtp-Source: AHgI3Ib+MJilqFAW+bHbGfaSFOgT7JpxVSPX1Wvu7wQrD3mnJjmWTCyaS87aL1YKirwkNPhc4DXIbg== X-Received: by 2002:a62:f51d:: with SMTP id n29mr11314658pfh.21.1550394894955; Sun, 17 Feb 2019 01:14:54 -0800 (PST) Received: from localhost.localdomain ([115.97.184.151]) by smtp.gmail.com with ESMTPSA id v15sm5565924pfa.75.2019.02.17.01.14.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Feb 2019 01:14:54 -0800 (PST) From: Jagan Teki To: Dmitry Torokhov , Bastien Nocera , Rob Herring Cc: Henrik Rydberg , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Mark Rutland , linux-amarula@amarulasolutions.com, Michael Trimarchi , Jagan Teki Subject: [PATCH v5 2/4] Input: goodix - Add regulators support Date: Sun, 17 Feb 2019 14:44:34 +0530 Message-Id: <20190217091436.3702-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190217091436.3702-1-jagan@amarulasolutions.com> References: <20190217091436.3702-1-jagan@amarulasolutions.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Goodix CTP controllers support analog, digital and gpio regulator supplies on relevant controller pin configurations. Support them via regulator bulk calls. Signed-off-by: Jagan Teki --- drivers/input/touchscreen/goodix.c | 58 ++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index f2d9c2c41885..294456a53fe0 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,15 @@ struct goodix_chip_data { int (*check_config)(struct goodix_ts_data *, const struct firmware *); }; +static const char * const goodix_supply_names[] = { + "AVDD28", + "AVDD22", + "DVDD12", + "VDDIO", +}; + +#define GOODIX_NUM_SUPPLIES ARRAY_SIZE(goodix_supply_names) + struct goodix_ts_data { struct i2c_client *client; struct input_dev *input_dev; @@ -47,6 +57,7 @@ struct goodix_ts_data { struct touchscreen_properties prop; unsigned int max_touch_num; unsigned int int_trigger_type; + struct regulator_bulk_data supplies[GOODIX_NUM_SUPPLIES]; struct gpio_desc *gpiod_int; struct gpio_desc *gpiod_rst; u16 id; @@ -761,11 +772,18 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx) complete_all(&ts->firmware_loading_complete); } +static void goodix_disable_regulator(void *arg) +{ + struct goodix_ts_data *ts = arg; + + regulator_bulk_disable(GOODIX_NUM_SUPPLIES, ts->supplies); +} + static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct goodix_ts_data *ts; - int error; + int error, i; dev_dbg(&client->dev, "I2C Address: 0x%02x\n", client->addr); @@ -786,25 +804,49 @@ static int goodix_ts_probe(struct i2c_client *client, if (error) return error; + for (i = 0; i < GOODIX_NUM_SUPPLIES; i++) + ts->supplies[i].supply = goodix_supply_names[i]; + + error = devm_regulator_bulk_get(&client->dev, GOODIX_NUM_SUPPLIES, + ts->supplies); + if (error) { + dev_err(&client->dev, "Failed to get regulators (ret=%d)\n", + error); + return error; + } + + error = devm_add_action_or_reset(&client->dev, + goodix_disable_regulator, ts); + if (error) + return error; + + /* power the controller */ + error = regulator_bulk_enable(GOODIX_NUM_SUPPLIES, ts->supplies); + if (error) { + dev_err(&client->dev, "Failed to enable regulators (ret=%d)\n", + error); + return error; + } + if (ts->gpiod_int && ts->gpiod_rst) { /* reset the controller */ error = goodix_reset(ts); if (error) { dev_err(&client->dev, "Controller reset failed.\n"); - return error; + goto error; } } error = goodix_i2c_test(client); if (error) { dev_err(&client->dev, "I2C communication failure: %d\n", error); - return error; + goto error; } error = goodix_read_version(ts); if (error) { dev_err(&client->dev, "Read version failed.\n"); - return error; + goto error; } ts->chip = goodix_get_chip_data(ts->id); @@ -823,17 +865,21 @@ static int goodix_ts_probe(struct i2c_client *client, dev_err(&client->dev, "Failed to invoke firmware loader: %d\n", error); - return error; + goto error; } return 0; } else { error = goodix_configure_dev(ts); if (error) - return error; + goto error; } return 0; + +error: + regulator_bulk_disable(GOODIX_NUM_SUPPLIES, ts->supplies); + return error; } static int goodix_ts_remove(struct i2c_client *client)