Received: by 10.223.164.221 with SMTP id h29csp3323173wrb; Mon, 30 Oct 2017 20:04:55 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R0bf456xOYRvBTX8alxdskuSAnxYHg8m7XPGtl6Vr/PU/fn3GO2Afr8fjaIx3his0BcgHr X-Received: by 10.99.4.129 with SMTP id 123mr512301pge.20.1509419095661; Mon, 30 Oct 2017 20:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509419095; cv=none; d=google.com; s=arc-20160816; b=Sb4RQdev6WElUMni9guqzZ3ZzHdo9T729yOnQ+OoBOnRATS0PPVWrGxpO7GZKjiOhm 8hDwVfTdGcdR1XjQyjuPynK3Wiru6H1Hfcr5QOAn/RJ8lIyL7ZB9QKhcZy1HY9LOTDV2 nPIccHvCdy5coLTT55XesQwu97/RFK+R2eGiqfg3JgJvqoEuzZtSUgft+8C7E74ufQPG hdF6DvLyCsx7h2qX0UMfVa+i2ykCMJFra8PNVCNhlwAei64gN0kMueqIc6+T2IUBPpAS Mh1Ue99EYY1GsZS82GDygS896AMoYxaSoSd/0RfvTfXN6ZfweV/6FIGmvcu0xVpTeu0d Wu0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=08dSE4vfMTz8yL/I6hDOgZVEZHi6FFNmUlpqzP0hFPs=; b=D4VU/SoneV9rGAGJuNxcmox/ufnzEXHTHmB24cMdlXrhic/4LCMPCIzll/yG8/vOxf NRXzUPW4HQ83sfuPGq20KBHA2zy5vw6rw/XoILINI8neuDs1sKb8sF6oGfldZPvfhrNC PseNDW2wkcGHBgc3Dj8Bd1GdfpbWyuh4pHvK2PgyLdaNcN+QU76u9Bvd6wnDhq6C9VQ7 h+tchPUS3wXaDG5Lr3P7gwiGg39QNZjyn24Br6TdGizd0eZltdLeC75xcQalZHUA5qsB cezzqbs1xZXvDM0j6rnEPn3N0EVrtwkHpQoX/WtiCICO8wqs9xSNRFRFFaTXNWKATL30 ZPWQ== 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 b29si417751pfh.302.2017.10.30.20.04.42; Mon, 30 Oct 2017 20:04:55 -0700 (PDT) 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 S1752064AbdJaDD0 (ORCPT + 99 others); Mon, 30 Oct 2017 23:03:26 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:47237 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751399AbdJaDDY (ORCPT ); Mon, 30 Oct 2017 23:03:24 -0400 Received: by mail-pf0-f195.google.com with SMTP id z11so12641647pfk.4; Mon, 30 Oct 2017 20:03:24 -0700 (PDT) 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; bh=08dSE4vfMTz8yL/I6hDOgZVEZHi6FFNmUlpqzP0hFPs=; b=dbHppvkktUPgmV/CltPvJBSVtiLzwdxPM8f9+uVNvsVd1PEWM3P8I2QsDNNNoxf444 NVQcOFvorUXUNBhMUfCeaQf5gIgU/wy6HRYFN/0ANvuuKfPwewhdKH/7KN+4LLJGB2gl iDWHkJF70pGSN0QrUfgP98SUFjSNPTNMzHNIz9f+a3VXHEpMpYmxxuOz02/zivZGpJx9 fyrnS0CZM05Z+bTuMmlgu1tZU2HlTB0B3PLzpnLPnRRqZLRz9pY4uwtXtEg1Aqz2l98u gsFSdr1lH0S5IFgB4Bu/ZEI96ikeYCEpBKuROeCdsd5MVywzt1BRbPdIoDbx52hQkGEX 9Lcw== X-Gm-Message-State: AMCzsaUuoKQ8UPxHBj+jXLHX41nJS+p3kWo25xmhkEL5cO40HkOehYQe HOop3K5CU7nerNpSdbP7reRkRw== X-Received: by 10.98.16.211 with SMTP id 80mr509278pfq.72.1509419004089; Mon, 30 Oct 2017 20:03:24 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id g207sm460042pfb.101.2017.10.30.20.03.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Oct 2017 20:03:22 -0700 (PDT) From: Lin Huang To: dmitry.torokhov@gmail.com, jikos@kernel.org, robh@kernel.org Cc: benjamin.tissoires@redhat.com, jani.nikula@intel.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, briannorris@chromium.org, devicetree@vger.kernel.org, Lin Huang Subject: [PATCH v2 1/2] HID: i2c-hid: add reset gpio property Date: Tue, 31 Oct 2017 11:03:15 +0800 Message-Id: <1509418996-25348-1-git-send-email-hl@rock-chips.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org some i2c hid devices have reset gpio, need to control it in the driver. Signed-off-by: Lin Huang --- Changes in v2: - Add 10us in usleep_range() upper range - reuse post_power_delay_ms as deassert reset delay - delete deassert_reset_us property drivers/hid/i2c-hid/i2c-hid.c | 61 +++++++++++++++++++++++++++-------- include/linux/platform_data/i2c-hid.h | 3 ++ 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 9145c21..9f06135 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -793,6 +794,35 @@ struct hid_ll_driver i2c_hid_ll_driver = { }; EXPORT_SYMBOL_GPL(i2c_hid_ll_driver); +static int i2c_hid_hw_power_on(struct i2c_hid *ihid) +{ + int ret; + + ret = regulator_enable(ihid->pdata.supply); + if (ret < 0) + return ret; + + gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 1); + if (ihid->pdata.assert_reset_us) + usleep_range(ihid->pdata.assert_reset_us, + ihid->pdata.assert_reset_us + 10); + + gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 0); + + /* use for power supply delay or reset deassert delay */ + if (ihid->pdata.post_power_delay_ms) + msleep(ihid->pdata.post_power_delay_ms); + + return ret; +} + +static int i2c_hid_hw_power_off(struct i2c_hid *ihid) +{ + gpiod_set_value_cansleep(ihid->pdata.reset_gpio, 1); + + return regulator_disable(ihid->pdata.supply); +} + static int i2c_hid_init_irq(struct i2c_client *client) { struct i2c_hid *ihid = i2c_get_clientdata(client); @@ -934,6 +964,9 @@ static int i2c_hid_of_probe(struct i2c_client *client, if (!ret) pdata->post_power_delay_ms = val; + of_property_read_u32(dev->of_node, "assert-reset-us", + &pdata->assert_reset_us); + return 0; } @@ -1002,14 +1035,16 @@ static int i2c_hid_probe(struct i2c_client *client, goto err; } - ret = regulator_enable(ihid->pdata.supply); + ihid->pdata.reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(ihid->pdata.reset_gpio)) + goto err; + + ret = i2c_hid_hw_power_on(ihid); if (ret < 0) { - dev_err(&client->dev, "Failed to enable regulator: %d\n", - ret); + dev_err(&client->dev, "Failed to power on: %d\n", ret); goto err; } - if (ihid->pdata.post_power_delay_ms) - msleep(ihid->pdata.post_power_delay_ms); i2c_set_clientdata(client, ihid); @@ -1086,7 +1121,7 @@ static int i2c_hid_probe(struct i2c_client *client, pm_runtime_disable(&client->dev); err_regulator: - regulator_disable(ihid->pdata.supply); + i2c_hid_hw_power_off(ihid); err: i2c_hid_free_buffers(ihid); @@ -1112,8 +1147,7 @@ static int i2c_hid_remove(struct i2c_client *client) if (ihid->bufsize) i2c_hid_free_buffers(ihid); - regulator_disable(ihid->pdata.supply); - + i2c_hid_hw_power_off(ihid); kfree(ihid); return 0; @@ -1165,9 +1199,10 @@ static int i2c_hid_suspend(struct device *dev) hid_warn(hid, "Failed to enable irq wake: %d\n", wake_status); } else { - ret = regulator_disable(ihid->pdata.supply); + ret = i2c_hid_hw_power_off(ihid); if (ret < 0) - hid_warn(hid, "Failed to disable supply: %d\n", ret); + hid_warn(hid, "Failed to disable hw power: %d\n", + ret); } return 0; @@ -1182,11 +1217,9 @@ static int i2c_hid_resume(struct device *dev) int wake_status; if (!device_may_wakeup(&client->dev)) { - ret = regulator_enable(ihid->pdata.supply); + ret = i2c_hid_hw_power_on(ihid); if (ret < 0) - hid_warn(hid, "Failed to enable supply: %d\n", ret); - if (ihid->pdata.post_power_delay_ms) - msleep(ihid->pdata.post_power_delay_ms); + hid_warn(hid, "Failed to enable hw power: %d\n", ret); } else if (ihid->irq_wake_enabled) { wake_status = disable_irq_wake(client->irq); if (!wake_status) diff --git a/include/linux/platform_data/i2c-hid.h b/include/linux/platform_data/i2c-hid.h index 1fb0882..40f1840 100644 --- a/include/linux/platform_data/i2c-hid.h +++ b/include/linux/platform_data/i2c-hid.h @@ -14,6 +14,7 @@ #include +struct gpio_desc; struct regulator; /** @@ -37,6 +38,8 @@ struct i2c_hid_platform_data { u16 hid_descriptor_address; struct regulator *supply; int post_power_delay_ms; + struct gpio_desc *reset_gpio; + int assert_reset_us; }; #endif /* __LINUX_I2C_HID_H */ -- 2.7.4 From 1583451114086163836@xxx Tue Nov 07 23:17:38 +0000 2017 X-GM-THRID: 1581787714485790213 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread