From patchwork Fri Dec 7 14:28:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Chmiel?= X-Patchwork-Id: 10718315 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 89E711731 for ; Fri, 7 Dec 2018 14:29:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76F922DD44 for ; Fri, 7 Dec 2018 14:29:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62F832E294; Fri, 7 Dec 2018 14:29:38 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFF612DD44 for ; Fri, 7 Dec 2018 14:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+kIarU8sjMQQTkVCis/tV9jZRdcDOHCEHN+PjlFHvog=; b=HMBDYv3p76hT+N r/dK+2XqTTDLK7WxyWc9hUGQ8zWz0pAWSK8fPiWDNp59ROTJstuFyH8/gOjLpyjNPbMfiJsfyalZa fYNyph5qqpsPLR+YDU/HgmoKdpGxs0JK0WFTSlFWOpFRE2GvhQE9PwlqpioLVb12ysDEPrLwpkNMl 5QelBSj3nTTxRzr9kOHKpoNwtjIVkJjMsJis09TuKBU3nBImmtZHaDPlrjqhNiYX1G3gt6+fokzIx Ixp8HrdfEtCbi18IEGHbrTvEasbMJqY28RsCJCAC7KUg7Skv3QKZvN+URWEdCjyO8Vh28wuiFYbBa 3peuqFh+pu0F85aG1ibw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gVH8C-0007hy-IV; Fri, 07 Dec 2018 14:29:28 +0000 Received: from mail-lf1-x142.google.com ([2a00:1450:4864:20::142]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gVH7z-0007Vg-28 for linux-arm-kernel@lists.infradead.org; Fri, 07 Dec 2018 14:29:16 +0000 Received: by mail-lf1-x142.google.com with SMTP id u18so3150248lff.10 for ; Fri, 07 Dec 2018 06:29:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S+OENI6YtzSczLSuymPnFLAriTDDg6DPhxH59mLlxng=; b=Wx9N47JXA0kxNsiHKrumv040W7czuEfj/tQSCfblQxXVckW73b2Z5wN2DcD7Ig9y63 0JwoRZDcFjcV3E+42WvSntm3HZnYAzYsMMJyoCe1oy9ALzbJraLdfH75MohITf8jcXZm +4EGkgFxEOedNHjlSM033SO1Dw+tVZrTdONNCchri5jahpXrn4ZHNs1cjA6txoCVyKFk PENspGs45go8eoOtO1zQFKVZKk6Zucc9YeYtmqgtzp8VN6nKVjGkKrIuwBRHKyt0P5rN NJcIWpu8tJn45jmpe1YL8ggeJGbHF5HfvLwjvKWKLgTKRMzyV1hawSpRtDcHS9xr8f4X 3kJg== 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=S+OENI6YtzSczLSuymPnFLAriTDDg6DPhxH59mLlxng=; b=Cs2miu6S5e3pnIoqtvQnYh1MqPF/ATKDlousct2I9IZItlflO2YkdgmjDZK92+QlHk 1/tUpBdqeg79+8xwRpvKpY3glG6nX3t1lDXNEFI5SbJSx0FwDdMcf9iX/2EGAVtL62i0 gVbtKySCktiRnvQjkzRZWQEgzAaeuWBxAeZsGw3si0hhpTHvrviKwA61zoOqZogH9y0s DsJuWeyd7XjMdWd4HKW3MP+CB0DNGy8er7ohlbnBlpQh6Lu37cE+4/LhSx5pcw7wQIyJ I7K8nssJFcqqALeSSyKH0KdEo5ZtHjw5LYsS56PN09YhFTkSvLMe2NdBks2vn/PU21/+ 4dig== X-Gm-Message-State: AA+aEWbWAJ6p2ea9n8wOH6w2qgKxWmeqFvFrHptIU6JBRqGzopdh0Znm 0J/R2y/MvJCSZyXtH1ikeqmurr/mgao= X-Google-Smtp-Source: AFSGD/Xel2TAfxU/X85KmS2yoOaa1eMH70+7GtbBT3zSR22gSbGsDe46di7TQVf6SYoJPVUlKA0YMw== X-Received: by 2002:a19:280f:: with SMTP id o15mr1461603lfo.0.1544192943060; Fri, 07 Dec 2018 06:29:03 -0800 (PST) Received: from localhost.localdomain ([2a02:a315:5445:5300:74d5:51ba:2673:f3f4]) by smtp.googlemail.com with ESMTPSA id v64sm630504lfa.48.2018.12.07.06.29.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Dec 2018 06:29:02 -0800 (PST) From: =?utf-8?q?Pawe=C5=82_Chmiel?= To: nick@shmanahar.org Subject: [PATCH v4 1/3] Input: atmel_mxt_ts: Add support for optional regulators Date: Fri, 7 Dec 2018 15:28:55 +0100 Message-Id: <20181207142857.15818-2-pawel.mikolaj.chmiel@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181207142857.15818-1-pawel.mikolaj.chmiel@gmail.com> References: <20181207142857.15818-1-pawel.mikolaj.chmiel@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181207_062915_107341_59B3E393 X-CRM114-Status: GOOD ( 19.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, alexandre.belloni@bootlin.com, dmitry.torokhov@gmail.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-input@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?q?Pawe=C5=82_Chmiel?= Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds optional regulators, which can be used to power up touchscreen. After enabling regulators, we need to wait 150msec. This value is taken from official driver. It was tested on Samsung Galaxy i9000 (based on Samsung S5PV210 SOC). Signed-off-by: Paweł Chmiel --- Changes from v3: - Fix checkpatch issues - Drop sentence punctuation from subject of one of patches Changes from v2: - Move code enabling regulators into separate method, to make code more readable. Changes from v1: - Enable regulators only if reset_gpio is present. - Switch from devm_regulator_get_optional to devm_regulator_get --- drivers/input/touchscreen/atmel_mxt_ts.c | 65 +++++++++++++++++++++--- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d3aacd534e9c..1dc8ad0da5af 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -194,10 +195,10 @@ enum t100_type { /* Delay times */ #define MXT_BACKUP_TIME 50 /* msec */ -#define MXT_RESET_GPIO_TIME 20 /* msec */ #define MXT_RESET_INVALID_CHG 100 /* msec */ #define MXT_RESET_TIME 200 /* msec */ #define MXT_RESET_TIMEOUT 3000 /* msec */ +#define MXT_REGULATOR_DELAY 150 /* msec */ #define MXT_CRC_TIMEOUT 1000 /* msec */ #define MXT_FW_RESET_TIME 3000 /* msec */ #define MXT_FW_CHG_TIMEOUT 300 /* msec */ @@ -323,6 +324,8 @@ struct mxt_data { struct t7_config t7_cfg; struct mxt_dbg dbg; struct gpio_desc *reset_gpio; + struct regulator *vdd_reg; + struct regulator *avdd_reg; /* Cached parameters from object table */ u16 T5_address; @@ -3038,6 +3041,38 @@ static const struct dmi_system_id chromebook_T9_suspend_dmi[] = { { } }; +static int mxt_regulator_enable(struct mxt_data *data) +{ + int error; + + if (data->reset_gpio) { + error = regulator_enable(data->vdd_reg); + if (error) { + dev_err(&data->client->dev, + "Failed to enable vdd regulator: %d\n", error); + return error; + } + + error = regulator_enable(data->avdd_reg); + if (error) { + dev_err(&data->client->dev, + "Failed to enable avdd regulator: %d\n", error); + return error; + } + + /* + * According to maXTouch power sequencing specification, + * RESET line must be kept low until some time + * after regulators come up to voltage + */ + msleep(MXT_REGULATOR_DELAY); + gpiod_set_value(data->reset_gpio, 1); + msleep(MXT_RESET_INVALID_CHG); + } + + return 0; +} + static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct mxt_data *data; @@ -3098,6 +3133,22 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } + data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); + if (IS_ERR(data->vdd_reg)) { + error = PTR_ERR(data->vdd_reg); + dev_err(&client->dev, "Failed to get vdd regulator: %d\n", + error); + return error; + } + + data->avdd_reg = devm_regulator_get(&client->dev, "avdd"); + if (IS_ERR(data->avdd_reg)) { + error = PTR_ERR(data->avdd_reg); + dev_err(&client->dev, "Failed to get avdd regulator: %d\n", + error); + return error; + } + error = devm_request_threaded_irq(&client->dev, client->irq, NULL, mxt_interrupt, IRQF_ONESHOT, client->name, data); @@ -3108,11 +3159,9 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) disable_irq(client->irq); - if (data->reset_gpio) { - msleep(MXT_RESET_GPIO_TIME); - gpiod_set_value(data->reset_gpio, 1); - msleep(MXT_RESET_INVALID_CHG); - } + error = mxt_regulator_enable(data); + if (error) + return error; error = mxt_initialize(data); if (error) @@ -3138,6 +3187,10 @@ static int mxt_remove(struct i2c_client *client) struct mxt_data *data = i2c_get_clientdata(client); disable_irq(data->irq); + if (data->reset_gpio) { + regulator_disable(data->avdd_reg); + regulator_disable(data->vdd_reg); + } sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); mxt_free_input_device(data); mxt_free_object_table(data);