From patchwork Thu Jul 28 00:34:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Potin Lai X-Patchwork-Id: 12930910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED10AC19F29 for ; Thu, 28 Jul 2022 01:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236865AbiG1BMD (ORCPT ); Wed, 27 Jul 2022 21:12:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234593AbiG1BMB (ORCPT ); Wed, 27 Jul 2022 21:12:01 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C2418B0F; Wed, 27 Jul 2022 18:12:01 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id o20-20020a17090aac1400b001f2da729979so3898623pjq.0; Wed, 27 Jul 2022 18:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lmQYtc1hSA2dj1fab7+3HzZDSuHervzNbSwsZTrDXjc=; b=dckY4rctkINyLcgKXr8vtXi/D9PEwpKwVFnjKS+yi0m8irntIaAIsIqSJtG+i2rbaV gKuUQlApE+I5ikOmJPKSyzqO55S7UbPOo2wrNzNtjXFVSQL3fQt7I0dZZGLXuxAA7p+n 89yp41grVcp1cTEUIXfBsaBOz0YN9EzUn4ZJY4n+f7iJYCY0eXxW+N5pyw2ynpoXlMou B5gUYVurPhEhJHmONI3/V3r3NXrPrBeGsQ8D9N5H+u3LA3OZWXOIYz6u6hJMIc6ClnjT 8puqcqLYVLtu2zmDOLRHc7/HSeo0N35Ut0wZ37crE+IgR0CVlXrMD5Owccp7G+qx/95x Ko2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lmQYtc1hSA2dj1fab7+3HzZDSuHervzNbSwsZTrDXjc=; b=O8Dr3lY/uTKyjU8ITlyYUvxXBFRi1AkD9Qugb7n+f5kw7XkXu6Ks6T1I+Ym9l0m6c3 5c2F4UN8OmKmIBQtrIAnxLDbVoJo6MDujcgTciL3S0wVg7lIoG2gq+dcmttvKGEI8GXE oX7jet1YcbnSVd8M4zVuI+a6tKB6AiVzG4o81dRgguDVu42R2cze83T/mr+H3fbnbQOU 4xXe1Pwed1D2W/yTmrT590niC7Xy2w+RLMKwEX9e19+Xwra+pOrZ/dVGsTKdsNTw9DGu cb/ENpkcinzQg2rpjdZrP2orduR/Cv51cndXpAfPWPzF51CODRNzU1wJE2hDxZkCtRSU fFcg== X-Gm-Message-State: AJIora/O8tMIIK7c6MV6GUO0OFZubrMbaN6NQ9sHkGLlsg9+S8SFFLpL xN0qpZAGewhedOoNxo2SJ2Cqo5vegeBkpw== X-Google-Smtp-Source: AGRyM1sufE+nIab1k+JQR+33NqLDTGV8v4ashdniEEDLhYDXDAHeZRxxhwhpgftNKnmSfq6eSjmZgw== X-Received: by 2002:a17:902:e84e:b0:16c:773:9daf with SMTP id t14-20020a170902e84e00b0016c07739dafmr24075745plg.43.1658970720570; Wed, 27 Jul 2022 18:12:00 -0700 (PDT) Received: from localhost.localdomain (125-228-123-29.hinet-ip.hinet.net. [125.228.123.29]) by smtp.gmail.com with ESMTPSA id x194-20020a6286cb000000b0052ad49292f0sm14526215pfd.48.2022.07.27.18.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jul 2022 18:12:00 -0700 (PDT) From: Potin Lai To: Andy Shevchenko , Jonathan Cameron , Lars-Peter Clausen Cc: Patrick Williams , Potin Lai , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Potin Lai Subject: [PATCH v4 1/2] iio: humidity: hdc100x: switch to probe_new callback Date: Thu, 28 Jul 2022 00:34:16 +0000 Message-Id: <20220728003417.3083353-2-potin.lai.pt@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220728003417.3083353-1-potin.lai.pt@gmail.com> References: <20220728003417.3083353-1-potin.lai.pt@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Switch to probe_new callback due to probe is deprecated soon. Signed-off-by: Potin Lai Reviewed-by: Andy Shevchenko --- drivers/iio/humidity/hdc100x.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c index 9e0fce917ce4c..0d514818635cb 100644 --- a/drivers/iio/humidity/hdc100x.c +++ b/drivers/iio/humidity/hdc100x.c @@ -351,8 +351,7 @@ static const struct iio_info hdc100x_info = { .attrs = &hdc100x_attribute_group, }; -static int hdc100x_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int hdc100x_probe(struct i2c_client *client) { struct iio_dev *indio_dev; struct hdc100x_data *data; @@ -422,7 +421,7 @@ static struct i2c_driver hdc100x_driver = { .name = "hdc100x", .of_match_table = hdc100x_dt_ids, }, - .probe = hdc100x_probe, + .probe_new = hdc100x_probe, .id_table = hdc100x_id, }; module_i2c_driver(hdc100x_driver); From patchwork Thu Jul 28 00:34:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Potin Lai X-Patchwork-Id: 12930911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDD2EC04A68 for ; Thu, 28 Jul 2022 01:12:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237094AbiG1BME (ORCPT ); Wed, 27 Jul 2022 21:12:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbiG1BME (ORCPT ); Wed, 27 Jul 2022 21:12:04 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57BDB3134F; Wed, 27 Jul 2022 18:12:03 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d3so483007pls.4; Wed, 27 Jul 2022 18:12:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X9+m39qpfDk/Jz5JojeONM6iXLnZUrRI7Za8g7a2MjA=; b=YnUAKpUwr6Z0hgClMKu/z6gzuLd2HBzBV74KpUUfhItEXPghvWt2bQV0US4N6hYI3I 5exC2Hf0DXL7jPYWOWE/4oF+cKcfdLF7zIcmqJrZsEJV3l14mXKMQrEoydw/RBipfmjD yypu1wbl0DelATYZCqWMGZ5buPDS4AThMF9OQomt4AbF3M8ald5jUgiJfi6MtPvtkv37 msE4qVe2oGcm94ygJfi/SXKxPbQNNNVrT52INPVXGD0G3VcN3yWEvrpil1/hX0LBlg5j MrfnGOjaUvrli4KhYSLoO9nBQc5SACnB/odrJ1wGjeCydL7o/d+T1U1FlUicGliIQcFN hzAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X9+m39qpfDk/Jz5JojeONM6iXLnZUrRI7Za8g7a2MjA=; b=sYsZCzZTB4juBTDmWrH5bWlYLdGFgJ43MMyTP1uMH1wivggpmfqBbOxR2FEi9prRST 0e+gbEPvh4LDR7veNOqqdBrQW6+lNHB7zt61g9XWDT9LPhZENFEPLaduEgtp0JrO+Csm gIUokFyqXfJIFTf4LmLrvoNJgKJKnwmgiavU48jzbTveQEFcWYlTGiz/hLkPSOIcf+Px mZhFpzfsOMbF3PUYxXGOHZax+pptcUN26gKIrabZXV1l/idAx3YXXj88rYj9ARjM4qKP dOqnzBV+PA/J9dmN6rSwRGjNzV6KYPAOLMMao7g66K2107WXnKVbZHkSju9WTI7ZpWmr Wkjg== X-Gm-Message-State: AJIora82irl9LVIToS6tL4wioonzSIYnRm3VZwQB0S8yxM5T5zqAJ0Ff Sead+N7osYMUKuVUTXYmC8n0RQrHXvI2QQ== X-Google-Smtp-Source: AGRyM1uyHj9EthnZvg5Fhnn4IYVAr8XGvk8wF6m1uPtl9tyYnlhwKWAyK0jM9dD3AcisXkE275UHBw== X-Received: by 2002:a17:902:6bcc:b0:16d:17db:3374 with SMTP id m12-20020a1709026bcc00b0016d17db3374mr24798082plt.101.1658970722825; Wed, 27 Jul 2022 18:12:02 -0700 (PDT) Received: from localhost.localdomain (125-228-123-29.hinet-ip.hinet.net. [125.228.123.29]) by smtp.gmail.com with ESMTPSA id x194-20020a6286cb000000b0052ad49292f0sm14526215pfd.48.2022.07.27.18.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jul 2022 18:12:02 -0700 (PDT) From: Potin Lai To: Andy Shevchenko , Jonathan Cameron , Lars-Peter Clausen Cc: Patrick Williams , Potin Lai , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Potin Lai Subject: [PATCH v4 2/2] iio: humidity: hdc100x: add manufacturer and device ID check Date: Thu, 28 Jul 2022 00:34:17 +0000 Message-Id: <20220728003417.3083353-3-potin.lai.pt@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220728003417.3083353-1-potin.lai.pt@gmail.com> References: <20220728003417.3083353-1-potin.lai.pt@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add manufacturer and device ID checking during probe, and skip the checking if chip model not supported. Supported: - HDC1000 - HDC1010 - HDC1050 - HDC1080 Not supported: - HDC1008 Signed-off-by: Potin Lai --- drivers/iio/humidity/hdc100x.c | 69 ++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c index 0d514818635cb..be1244577921d 100644 --- a/drivers/iio/humidity/hdc100x.c +++ b/drivers/iio/humidity/hdc100x.c @@ -34,7 +34,25 @@ #define HDC100X_REG_CONFIG_ACQ_MODE BIT(12) #define HDC100X_REG_CONFIG_HEATER_EN BIT(13) +#define HDC100X_REG_MFR_ID 0xFE +#define HDC100X_REG_DEV_ID 0xFF + +#define HDC100X_MFR_ID 0x5449 + +struct hdc100x_chip_data { + bool support_mfr_check; +}; + +static const struct hdc100x_chip_data hdc100x_chip_data = { + .support_mfr_check = true, +}; + +static const struct hdc100x_chip_data hdc1008_chip_data = { + .support_mfr_check = false, +}; + struct hdc100x_data { + const struct hdc100x_chip_data *chip_data; struct i2c_client *client; struct mutex lock; u16 config; @@ -351,8 +369,32 @@ static const struct iio_info hdc100x_info = { .attrs = &hdc100x_attribute_group, }; +static int hdc100x_read_mfr_id(struct i2c_client *client) +{ + return i2c_smbus_read_word_swapped(client, HDC100X_REG_MFR_ID); +} + +static int hdc100x_read_dev_id(struct i2c_client *client) +{ + return i2c_smbus_read_word_swapped(client, HDC100X_REG_DEV_ID); +} + +static bool is_valid_hdc100x(struct i2c_client *client) +{ + int mfr_id, dev_id; + + mfr_id = hdc100x_read_mfr_id(client); + dev_id = hdc100x_read_dev_id(client); + if (mfr_id == HDC100X_MFR_ID && + (dev_id == 0x1000 || dev_id == 0x1050)) + return true; + + return false; +} + static int hdc100x_probe(struct i2c_client *client) { + const struct hdc100x_chip_data *chip_data; struct iio_dev *indio_dev; struct hdc100x_data *data; int ret; @@ -361,6 +403,10 @@ static int hdc100x_probe(struct i2c_client *client) I2C_FUNC_SMBUS_BYTE | I2C_FUNC_I2C)) return -EOPNOTSUPP; + chip_data = device_get_match_data(&client->dev); + if (chip_data->support_mfr_check && !is_valid_hdc100x(client)) + return -EINVAL; + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; @@ -368,6 +414,7 @@ static int hdc100x_probe(struct i2c_client *client) data = iio_priv(indio_dev); i2c_set_clientdata(client, indio_dev); data->client = client; + data->chip_data = chip_data; mutex_init(&data->lock); indio_dev->name = dev_name(&client->dev); @@ -396,22 +443,22 @@ static int hdc100x_probe(struct i2c_client *client) } static const struct i2c_device_id hdc100x_id[] = { - { "hdc100x", 0 }, - { "hdc1000", 0 }, - { "hdc1008", 0 }, - { "hdc1010", 0 }, - { "hdc1050", 0 }, - { "hdc1080", 0 }, + { "hdc100X", (kernel_ulong_t)&hdc100x_chip_data }, + { "hdc1000", (kernel_ulong_t)&hdc100x_chip_data }, + { "hdc1008", (kernel_ulong_t)&hdc1008_chip_data }, + { "hdc1010", (kernel_ulong_t)&hdc100x_chip_data }, + { "hdc1050", (kernel_ulong_t)&hdc100x_chip_data }, + { "hdc1080", (kernel_ulong_t)&hdc100x_chip_data }, { } }; MODULE_DEVICE_TABLE(i2c, hdc100x_id); static const struct of_device_id hdc100x_dt_ids[] = { - { .compatible = "ti,hdc1000" }, - { .compatible = "ti,hdc1008" }, - { .compatible = "ti,hdc1010" }, - { .compatible = "ti,hdc1050" }, - { .compatible = "ti,hdc1080" }, + { .compatible = "ti,hdc1000", .data = &hdc100x_chip_data }, + { .compatible = "ti,hdc1008", .data = &hdc1008_chip_data }, + { .compatible = "ti,hdc1010", .data = &hdc100x_chip_data }, + { .compatible = "ti,hdc1050", .data = &hdc100x_chip_data }, + { .compatible = "ti,hdc1080", .data = &hdc100x_chip_data }, { } }; MODULE_DEVICE_TABLE(of, hdc100x_dt_ids);