Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp153718imn; Wed, 27 Jul 2022 18:26:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ts1fJ1gzhOnfSNcjenLw5U4Glt5Zkz+MucUfVphQAeos0w8PoS6J2J/L7YbOoiSOv4sWn4 X-Received: by 2002:a17:907:28c9:b0:72b:6912:5453 with SMTP id en9-20020a17090728c900b0072b69125453mr18834749ejc.419.1658971562259; Wed, 27 Jul 2022 18:26:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658971562; cv=none; d=google.com; s=arc-20160816; b=n6nu4w4O9hrrtmX+2qhRPj7XEr674lXlPieHLnNWmw3Ob7a7irwXfXn7E9bE8EM9vR adRMuBLT3Qqq+rQkQvH3sqLlDmu4ixhKEjop/y5bP0eNvpRFgK2hSH2lIinz8wN5Ml7a /GWI6lYY+Hn2KBAu2r4vHL4Kacu18tU+wSRwuvqYgyWnWTKP1ixIXX/a/jCHQYY+PeG3 QZorS2jnWHnnBaPrfqJb9uHTKCb6RWj1PNqLJvGltKAVxkXRJEqoqlaWBAT+23GM2zIo RkxQZAvdA6CskVrhSaOO25mrr49t33qQGia+WkzBPEx6XVM3kJevM1J5LxpEKirwNY6S m7Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X9+m39qpfDk/Jz5JojeONM6iXLnZUrRI7Za8g7a2MjA=; b=zU+78o0uMiMevcPTxUJ4THmGdOhBCiHO0FBk9AWN9eKTeoeGY4SA60N2Ml60GRZSRR cENI65HZIXi8WteVb4l1rVHKsV4Qtos6bMI9qtfKRC3dK/8P4JkamwQkWVsx3F226vF5 QaSo0n4MnS5cKNzg+FC7OBQwpD7FUOkPTsIC9TbOmI7J1F3tylPHCKqqTyU5CJyzQ7Ru stgiYQDZnTSwwy5CwMfG0uXB6kUW0AkAsVfCNmKCkWtNhrCS5IHNTd6Q4RJgQirHMcbA aE42mFRaP259kkGCsZ1ogY7h1KqUarTDpg5d7+V0qYEhGFDtx4JYlLsg+QnAuhBX6JFV /5zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YnUAKpUw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn21-20020a1709070d1500b007123c7ecf90si21997213ejc.476.2022.07.27.18.25.37; Wed, 27 Jul 2022 18:26:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YnUAKpUw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237279AbiG1BMH (ORCPT + 99 others); Wed, 27 Jul 2022 21:12:07 -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-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.31.1