Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1288906ybf; Thu, 27 Feb 2020 08:11:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzLniZ53Qb90ddqBEYU419SNexHGGB0TLhKcxjAXTUGcctL3x+1iSvL7Kuo3UJEDYOVu7Hd X-Received: by 2002:aca:d483:: with SMTP id l125mr3920197oig.124.1582819886047; Thu, 27 Feb 2020 08:11:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582819886; cv=none; d=google.com; s=arc-20160816; b=keoq+Hl4rdGSbQaDCJrnzD3w02dIHcI9ECk2E4rhfH4Ke1iscuwHgQk3EmncX6tzCU iY3+MF58Q7AZ1GhWBMUTSR9/xnzfYOFtkgz6aa8ni6syrmVw2AI63X1pz9R6IubD4eUS KUrsla2v2x7qSf03OgdzgFW2xrIDleW0nD2UZIovbqc4zaiUvjEDj2FY+7pmH9oku08Q CZowEZfbQQd+RLIfoJlJSqVvGnzFSzEPaKKXL30zZx9quH+LZkMKEgTBgSRfHi3u1m5A Xvu74pHEwPLG94quEH4f0LncUixEvLtpiUgNUg//3OQKCL/hC1e1FY2p6QZnQK5AWE6x pQKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=0iDpNGq6IRp8gcDFfkwBhK68bKjQJBn92umR+xGbvCg=; b=Qti7htp+Hj0KkhXT2GKyZ9CRh1pZApEr5ZG/VSsi7/L0dEW35z/S5+R+u381GBDGSp +jWk9PNie/drRkT5C/0/4wzHjz7gEKbgTA5QrUmhrZpcMIUbA0Vh1wRn0tTpdqQaozn+ xSW7rpN2ePzknOzmQdyaj8JSxmBU6rZ1YU5yh+ZPE+vHGhwZaUSYd0QKxkF5im9kp/15 ouigoJU0tHa4yb91JJTgMJkJdMzFRInoVbXDg9lsPgVcSsR5S5FpWFt9uno1K1QSKznC kecgsjVAdMd1A/FiWlqjdHEqp1dKU83n03UB6H0jjUqKW3fpqd2U97uFR6X4iO+VJEq7 ZfvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aosc.io header.s=dkim header.b=Co6bzQ6F; 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 t192si76452oif.75.2020.02.27.08.11.14; Thu, 27 Feb 2020 08:11:26 -0800 (PST) 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; dkim=pass header.i=@aosc.io header.s=dkim header.b=Co6bzQ6F; 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 S1729983AbgB0QJR (ORCPT + 99 others); Thu, 27 Feb 2020 11:09:17 -0500 Received: from hermes.aosc.io ([199.195.250.187]:54889 "EHLO hermes.aosc.io" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729134AbgB0QJR (ORCPT ); Thu, 27 Feb 2020 11:09:17 -0500 Received: from localhost (localhost [127.0.0.1]) (Authenticated sender: icenowy@aosc.io) by hermes.aosc.io (Postfix) with ESMTPSA id AFE494B2ED; Thu, 27 Feb 2020 16:09:10 +0000 (UTC) From: Icenowy Zheng To: Dmitry Torokhov , Rob Herring , Bastien Nocera , Ondrej Jirman Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Icenowy Zheng Subject: [PATCH v2 2/3] Input: goodix - use string-based chip ID Date: Fri, 28 Feb 2020 00:08:01 +0800 Message-Id: <20200227160802.7043-3-icenowy@aosc.io> In-Reply-To: <20200227160802.7043-1-icenowy@aosc.io> References: <20200227160802.7043-1-icenowy@aosc.io> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aosc.io; s=dkim; t=1582819756; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=0iDpNGq6IRp8gcDFfkwBhK68bKjQJBn92umR+xGbvCg=; b=Co6bzQ6FiD5JH6Gd/UbVp/L8hASBcHWNrb5syERRx6Hf/ssVEyGUmM/KA5CR1QdvdQC/we CbCWsxfC3Cz0NgfW+G5jlezSM3Zkk94MzFk7ZAQyXRMW/ZVT+3tbTHeXdNOqVB/PKDLYBi hXHP2+oE2sei26oD67VLUnOP6WD9uTo= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For Goodix GT917S chip, the chip ID string is "917S", which contains not only numbers now. Use string-based chip ID in the driver to support this chip and further chips with alphanumber ID. Signed-off-by: Icenowy Zheng --- Changes in v2: - Used a table to save ID and chip data info. - Use strscpy(). drivers/input/touchscreen/goodix.c | 61 +++++++++++++++++------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index 0403102e807e..dde85b894ca4 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -37,6 +37,11 @@ struct goodix_chip_data { int (*check_config)(struct goodix_ts_data *, const struct firmware *); }; +struct goodix_chip_id { + const char *id; + const struct goodix_chip_data *data; +}; + struct goodix_ts_data { struct i2c_client *client; struct input_dev *input_dev; @@ -48,7 +53,7 @@ struct goodix_ts_data { struct regulator *vddio; struct gpio_desc *gpiod_int; struct gpio_desc *gpiod_rst; - u16 id; + char id[5]; u16 version; const char *cfg_name; struct completion firmware_loading_complete; @@ -115,6 +120,22 @@ static const struct goodix_chip_data gt9x_chip_data = { .check_config = goodix_check_cfg_8, }; +static const struct goodix_chip_id goodix_chip_ids[] = { + { .id = "1151", .data = >1x_chip_data }, + { .id = "5663", .data = >1x_chip_data }, + { .id = "5688", .data = >1x_chip_data }, + + { .id = "911", .data = >911_chip_data }, + { .id = "9271", .data = >911_chip_data }, + { .id = "9110", .data = >911_chip_data }, + { .id = "927", .data = >911_chip_data }, + { .id = "928", .data = >911_chip_data }, + + { .id = "912", .data = >967_chip_data }, + { .id = "967", .data = >967_chip_data }, + { } +}; + static const unsigned long goodix_irq_flags[] = { IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, @@ -235,28 +256,16 @@ static int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value) return goodix_i2c_write(client, reg, &value, sizeof(value)); } -static const struct goodix_chip_data *goodix_get_chip_data(u16 id) +static const struct goodix_chip_data *goodix_get_chip_data(const char *id) { - switch (id) { - case 1151: - case 5663: - case 5688: - return >1x_chip_data; - - case 911: - case 9271: - case 9110: - case 927: - case 928: - return >911_chip_data; - - case 912: - case 967: - return >967_chip_data; - - default: - return >9x_chip_data; + unsigned int i; + + for (i = 0; goodix_chip_ids[i].id; i++) { + if (!strcmp(goodix_chip_ids[i].id, id)) + return goodix_chip_ids[i].data; } + + return >9x_chip_data; } static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) @@ -673,12 +682,11 @@ static int goodix_read_version(struct goodix_ts_data *ts) memcpy(id_str, buf, 4); id_str[4] = 0; - if (kstrtou16(id_str, 10, &ts->id)) - ts->id = 0x1001; + strscpy(ts->id, id_str, 5); ts->version = get_unaligned_le16(&buf[4]); - dev_info(&ts->client->dev, "ID %d, version: %04x\n", ts->id, + dev_info(&ts->client->dev, "ID %s, version: %04x\n", ts->id, ts->version); return 0; @@ -736,7 +744,8 @@ static int goodix_configure_dev(struct goodix_ts_data *ts) ts->input_dev->phys = "input/ts"; ts->input_dev->id.bustype = BUS_I2C; ts->input_dev->id.vendor = 0x0416; - ts->input_dev->id.product = ts->id; + if (kstrtou16(ts->id, 10, &ts->input_dev->id.product)) + ts->input_dev->id.product = 0x1001; ts->input_dev->id.version = ts->version; /* Capacitive Windows/Home button on some devices */ @@ -915,7 +924,7 @@ static int goodix_ts_probe(struct i2c_client *client, if (ts->gpiod_int && ts->gpiod_rst) { /* update device config */ ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL, - "goodix_%d_cfg.bin", ts->id); + "goodix_%s_cfg.bin", ts->id); if (!ts->cfg_name) return -ENOMEM; -- 2.24.1