From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D164375AAC for ; Mon, 30 Mar 2026 16:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774886456; cv=none; b=GOw4wDye9+dePEE43lvHyg2CbUp6AqRs+PJfeVVk4AAbJXryzKv2zih6pGGSUDZRuzmBIiJXUbUSzMujH6ks3QNIIWnuWylPZVDAs9SPcpi1s1Ta4gJViFCUW5PULevrphQ/W7HnHC+2yssk+nh7it1FL4DxOsZxNVOe+Wq0wBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774886456; c=relaxed/simple; bh=LNZcLcyaESCNa/ERcf8t0QYKBjEpfVGGh7f8a07D+c4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=g6XGgoGtXyaGDbUCXA1IoKa20k7FswlVp2d7UPv6WGp72SGslk/bUvuTbMcg//qXYRxBw8CNJ8b9PWd/zNPBt/MJtf7F69fqIEOED6cXjJVKb6QHZRMzZ87yFBXiCw9zoxjwe/GylBPf1UJBwESUGhHJcrAbAfpsH1SVX/i48MA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ko8StfhW; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ko8StfhW" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-82c20b9f989so2014873b3a.0 for ; Mon, 30 Mar 2026 09:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774886453; x=1775491253; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:from:to:cc:subject:date:message-id:reply-to; bh=wpVAuzUFa0WB0ZNz5sJm2wNE73LaP5n0AkrtCatZ+9M=; b=Ko8StfhW6cWAzfH1t0mt3myOdiBJt7yIS6nrgkb5/wknBnBlhraIrgxdwbtGkGm6jb 0d/5IbArrS+nPw9/9n+umx+SwQE+MrY0Vb2hZbL/votfuDN/dbtQwHLPXp6TNRHX2DPN 03CN0Apq2ylY/BFmzdE6Nffp7k00phfeX4DqekL3oQ3aBv0WsEj/QwJBBTMlrbk+hmYo cSkOyb4ty5ijDdzhQeo9UdqLzej8JRbdcKsM9LjEIY4wWNak0eqN6etEh7kl6tcFko6z q45Ae1fStkjbPGAmxKdE3yZKp/PMssqUqREqcs63tPkkIWJNyYKnKL95EJYo1zNaga5s ipBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774886453; x=1775491253; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:sender:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wpVAuzUFa0WB0ZNz5sJm2wNE73LaP5n0AkrtCatZ+9M=; b=kUiIyEDgZlVzukTs4lwduy31rPzIk9br8ny4i1DYe4qPJR2/t2e+hy2ul0KzwLoZba Hoo49nhPb2e8nlKD3ArAGo0hSbygsOZEGr53G5P5BUuYPqatRKVFNEkz0KK3MQ4ohTCj QjTjhp2X205PA9FREmhf80E/ckREFpEbagxjp5Zft7v+SJGlWfIHoRzRS4zRUdgF1pzI Qm9RrplIEDh5y1lE7jdY41+VQu2rLJj1dzLoiJREZz0023sHJHhlaZ2WnWBp5cs8/bVr GWP/PrPLRkJfREilWJv5/+wldz0MTa8CoR+Sv5ggUPI7/7TQ6k+Zrk8a6wPhd1lBLZ1b nn1Q== X-Forwarded-Encrypted: i=1; AJvYcCVDVnADWj5JQfnGKwEWCF42QTOu0gvOG7kuqIiJFAJUhDSNktC8ffBSNkTThnTAU9Ec0RxKrMDGvZWdslY=@vger.kernel.org X-Gm-Message-State: AOJu0YyjPxW4bvhU4vfzJD0e5kERXyNxmnWTug3aWL2plWMsI0WTyb8y QpJ1FgtdxTSV1oZ8nHJyFm6r2XnEulL/sq25och6ci26fIKMXs3uy1tu X-Gm-Gg: ATEYQzy6NNonQ1AFAdNFobu7Tgeu5gnJt4a0qcVV7w7ygEr5dj5c/NIlwM5yzg4yGfL pjiUUq4lg+c0CTYE6RmDCNZ3nU/zieW77+kjOCQOi8Ylfu4GGuvL8B9UgaEQmgFGDBMGp/8WJPP o8SEe1d3SQ+VM20D+zqS/c5lJxkWz0Lmp4Vj7xQvnSqo3sssLKGsPgHizmTKSm2a3QBrn5ViOCJ TasUsChs990ssUhJAZf8FAW68lJtjijcmV3GD/1TKiTWT6WdLTbyz2jNGMlyIjLHhPyfYxCCfaj LhJY8/I/a4tEBAiKDKoVcbwhRW0sW2UOrzaZJh2FzYVZDo7A6kAbhVyM6hDM6uoWCETw4eWjH46 HxA+bIOzF2m5ZEPZx2gLcF0bqrAJB71p+ZjGwC9Qztrm57fPPFah/LBkcEQzUjCop+3QJCZbesD Y6phvJFp0s/YMy98IaKJRM1xE1ME7KkTzauw06vNa/xV5RpJ+shhMZJRw5MlMbBBqe9ZrQD5J0 X-Received: by 2002:a05:6a20:e290:b0:398:71b6:33aa with SMTP id adf61e73a8af0-39c87bc0f52mr13801393637.64.1774886453083; Mon, 30 Mar 2026 09:00:53 -0700 (PDT) Received: from ?IPV6:2600:1700:e321:62f0:da43:aeff:fecc:bfd5? ([2600:1700:e321:62f0:da43:aeff:fecc:bfd5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c76916cf861sm7325614a12.12.2026.03.30.09.00.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Mar 2026 09:00:52 -0700 (PDT) Sender: Guenter Roeck Message-ID: Date: Mon, 30 Mar 2026 09:00:49 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 2/2] hwmon: add support for MCP998X To: Victor.Duicu@microchip.com Cc: corbet@lwn.net, linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, linux-kernel@vger.kernel.org, krzk+dt@kernel.org, linux-doc@vger.kernel.org, conor+dt@kernel.org, Marius.Cristea@microchip.com References: <20260217-add-mcp9982-hwmon-v10-0-5e0aaae6f289@microchip.com> <20260217-add-mcp9982-hwmon-v10-2-5e0aaae6f289@microchip.com> <2d3955f5b906018fd7670ed5b8d37eaffa0ec207.camel@microchip.com> Content-Language: en-US From: Guenter Roeck Autocrypt: addr=linux@roeck-us.net; keydata= xsFNBE6H1WcBEACu6jIcw5kZ5dGeJ7E7B2uweQR/4FGxH10/H1O1+ApmcQ9i87XdZQiB9cpN RYHA7RCEK2dh6dDccykQk3bC90xXMPg+O3R+C/SkwcnUak1UZaeK/SwQbq/t0tkMzYDRxfJ7 nyFiKxUehbNF3r9qlJgPqONwX5vJy4/GvDHdddSCxV41P/ejsZ8PykxyJs98UWhF54tGRWFl 7i1xvaDB9lN5WTLRKSO7wICuLiSz5WZHXMkyF4d+/O5ll7yz/o/JxK5vO/sduYDIlFTvBZDh gzaEtNf5tQjsjG4io8E0Yq0ViobLkS2RTNZT8ICq/Jmvl0SpbHRvYwa2DhNsK0YjHFQBB0FX Idh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Vf0miwIFYy j/UEfAFNW+tbtKPNn3xZTLs3quQN7GdYLh+J0XxITpBZaFOpwEKV+VS36pSLnNl0T5wm0E/y scPJ0OVY7ly5Vm1nnoH4licaU5Y1nSkFR/j2douI5P7Cj687WuNMC6CcFd6j72kRfxklOqXw zvy+2NEcXyziiLXp84130yxAKXfluax9sZhhrhKT6VrD45S6N3HxJpXQ/RY/EX35neH2/F7B RgSloce2+zWfpELyS1qRkCUTt1tlGV2p+y2BPfXzrHn2vxvbhEn1QpQ6t+85FKN8YEhJEygJ F0WaMvQMNrk9UAUziVcUkLU52NS9SXqpVg8vgrO0JKx97IXFPcNh0DWsSj/0Y8HO/RDkGXYn FDMj7fZSPKyPQPmEHg+W/KzxSSfdgWIHF2QaQ0b2q1wOSec4Rti52ohmNSY+KNIW/zODhugJ np3900V20aS7eD9K8GTU0TGC1pyz6IVJwIE= In-Reply-To: <2d3955f5b906018fd7670ed5b8d37eaffa0ec207.camel@microchip.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 3/30/26 05:01, Victor.Duicu@microchip.com wrote: > Hi Guenter, > > ... > >>> +     } >>> + >>> +     switch (type) { >>> +     case hwmon_temp: >>> +             switch (attr) { >>> +             case hwmon_temp_input: >>> +                     /* Block reading from addresses 0x00->0x09 is >>> not allowed. */ >>> +                     ret = regmap_read(priv->regmap, >>> MCP9982_HIGH_BYTE_ADDR(channel), ®_high); >>> +                     if (ret) >>> +                             return ret; >>> + >>> +                     ret = regmap_read(priv->regmap, >>> MCP9982_HIGH_BYTE_ADDR(channel) + 1, >>> +                                       ®_low); >>> +                     if (ret) >>> +                             return ret; >> >> Reading the 11-bit temperature value involves two separate 8-bit >> register reads. >> If the chip updates the temperature between these two reads, the >> resulting value >> may be torn. While some chips latch the low byte upon reading the >> high byte, >> the driver does not explicitly rely on or document this behavior, and >> it's safer >> to use regmap_bulk_read if supported, or at least ensure the correct >> order and >> atomicity if possible. >> >> Note: Maybe the low temperature is latched, but there is no >> indication in the >> datasheet that this would be the case. Even if it is, the code above >> is >> inefficient. > > The low temperature register is latched. In the documentation at > page 32 it is described that when reading the high byte register, > the value from the low byte register is copied into a 'shadow' > register. In this way it is guaranteed that when we read the low byte, > it will correspond to the high byte. > > Regarding the bulk read, the chip has a number of design quirks and > because of that different commands are supported only on some > particular memory regions. > > According to the documentation page 26, the only areas of memory that > support SMBus block read are 80h->89h(temperature memory block) and > 90h->97h(status memory block). In order to block read the temperatures, > the area of memory targeted has to be the temperature memory block. In > this context the read operation uses SMBus protocol and the first value > returned will be the number of addresses that can be read (in our > particular case a max value of 10 bytes). > > In v8 of the driver > https://lore.kernel.org/all/20251120071248.3767-1-victor.duicu@microchip.com/ > , > the temperature values were read with regmap_bulk_read(). In that > version, regmap_bulk_read() was also used to read the temperature > limits, without returning count (this is an undocumented feature of the > chip and because of that we could assume is not supported). > In order to avoid this behaviour and avoid mixing the SMBus and I2C > protocols all block readings were removed. > > In the hopes of bypassing a long chain of replies, I tested the > behaviour of the chip with different read instructions. > Regmap_bulk_read() when applied to the temperature memory block > (80h->89h) returns count and the high and low bytes. When it is applied > to the 00h->09h memory, it uses I2C. It returns one temperature byte, > but all other bytes are returned as 0xFF. The chip behaves as if > it is at the last register location in the temperature block while the > host continues to ACK.(behaviour described at page 26). > If we set use_single_read in regmap_config and apply regmap_bulk_read() > to the 00h->09h register area the high and low temperature bytes are > read successfully without count. > > Regmap_multi_reg_read() reads a number of registers one by one. When > applied to the 00h->09h area, I2C is used and it returns only the high > and low temperature bytes. When applied to the temperature memory block > (80h->89h), because it is not a bulk function, returns the count till > the end of the temperature memory block (aka SMBus count). > > I2c_smbus_read_block_data() when applied to the temperature block (80h- > 89h) returns the count, the driver replies with an NACK and the > communication is stopped. In our case, the board we are using to test > the driver has an AT91 adapter and supports > I2C_FUNC_SMBUS_READ_BLOCK_DATA. It seems that the I2C driver for AT91 > does not modify the buff length of the message, leaving it 1. > > I2c_smbus_read_i2c_block_data() when applied to the temperature block > (80h-89h) returns count and the temperature values. > > If you are of the opinion that block reading the temperatures is worth > introducing (even in case we need to skip count) then I can add it, but > we should come to an agreement on which function to use. > Please let me know your thoughts. > It is your chip, so I'll let you decide. Please include all the above as comments into the code. Thanks, Guenter