From nobody Tue Dec 16 16:38:53 2025 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 78BA1C4167B for ; Thu, 30 Nov 2023 13:53:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345745AbjK3NxQ (ORCPT ); Thu, 30 Nov 2023 08:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345662AbjK3NxO (ORCPT ); Thu, 30 Nov 2023 08:53:14 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3CEB9 for ; Thu, 30 Nov 2023 05:53:20 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40a4848c6e1so7540225e9.1 for ; Thu, 30 Nov 2023 05:53:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701352399; x=1701957199; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OilnCkUOcXAx+nYBX9A7TYy/ZEalaKAFOMCP+QsH9zE=; b=GTITvgjN4LDCMopYJkwVD/Tg1BIxAWkU68BsVfPGQnF/FSFuu8CXR2jpwN9U2eY5VA 64sRhgxwdH6uf9YDIlgKUtatyuZSr+x8gYNDSFjNOKfM0y8ZfYgAi8as2fJ+LZ/JXzZc KH++21Y3+bEtPgnIXtu9NXH0pMvv9t3IxPJZHdBG3MW4EcTL5Bj+ovHustLGlodYOJoZ TU51dLItPWZ7xBjpj7GYlpxb8o3/Ks4rrE9QKxuc5KXyybiDSujpwt45KlxpdTjoG0r1 DOEX3Sj9V9nhcb4JuIwc70dEv6KV32uqY/iyIs5euoGHPDn22iy7H/lY4m0wWW92Wz73 Z8ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352399; x=1701957199; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OilnCkUOcXAx+nYBX9A7TYy/ZEalaKAFOMCP+QsH9zE=; b=MIckQxi0Ei90iQhZZ2UZmbOWPO/xfeeKTtJLb74mUErQObWU1DRsJ7cvUaO8zf1vCF W84BMfTixtPt0tdeENH7BIH7RbYK1ZWT6ky6dD8/z4c0lOeiyERTv263b6b9krRQdjm3 XWgbdz+9j/tNndaQfOO4MiJSvBeLyGX3CGf7lnnSL79pomXCXh25Vg/GL0qryG5hLuow +M9N8Qj83ikimVFftF/p6MhCq9wL4KzyYk9EBGkDESxeyRg29YqQEXLbxNxXnoMRhJTF s6it9TbaFUuQo27TZZZYHLn3KPBxnw4yxHzaJ6yrT3mvSo/KJpopsC+hgqUkrlFubIWo rgaQ== X-Gm-Message-State: AOJu0YwqYA1mfqJLtlMTik6JDdZS0Hwhgakc2cLNVcUIDa22Cq/TabBy 5VncVLquAQoaquIRGmTaM9o= X-Google-Smtp-Source: AGHT+IFu0FNKnf3vLpzLeG/rXcQe5ML2H7tXtk1blfUEbndjqZp6qn1VEoBghNW3QOPF6y6GIdkqMQ== X-Received: by 2002:a05:600c:3549:b0:40b:386a:f827 with SMTP id i9-20020a05600c354900b0040b386af827mr16750904wmq.24.1701352399057; Thu, 30 Nov 2023 05:53:19 -0800 (PST) Received: from mfe-desktop.Sonatest.net (ipagstaticip-d73c7528-4de5-0861-800b-03d8b15e3869.sdsl.bell.ca. [174.94.156.236]) by smtp.googlemail.com with ESMTPSA id d9-20020a05600c34c900b0040b2c195523sm5864573wmq.31.2023.11.30.05.53.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:53:17 -0800 (PST) From: marc.ferland@gmail.com X-Google-Original-From: marc.ferland@sonatest.com To: krzysztof.kozlowski@linaro.org Cc: gregkh@linuxfoundation.org, marc.ferland@sonatest.com, jeff.dagenais@gmail.com, rdunlap@infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/5] w1: ds2490: support block sizes larger than 128 bytes in ds_read_block Date: Thu, 30 Nov 2023 08:52:28 -0500 Message-Id: <20231130135232.191320-2-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130135232.191320-1-marc.ferland@sonatest.com> References: <20231130135232.191320-1-marc.ferland@sonatest.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Ferland The current ds_read_block function only supports block sizes up to 128 bytes, which is the depth of the 'data out' fifo on the ds2490. Reading larger blocks will fail with a: -110 (ETIMEDOUT) from usb_control_msg(). Example: $ dd if=3D/sys/bus/w1/devices/43-000000478756/eeprom bs=3D256 count=3D1 yields to the following message from the kernel: usb 5-1: Failed to write 1-wire data to ep0x2: err=3D-110. I discovered this issue while implementing support for the ds28ec20 eeprom in the w1-2433 driver. This driver accepts reading blocks of sizes up to the size of the entire memory (2560 bytes in the case of the ds28ec20). Note that this issue _does not_ arises when the kernel is configured with CONFIG_W1_SLAVE_DS2433_CRC enabled since in this mode the driver reads one 32 byte block at a time (a single memory page). Also, from the ds2490 datasheet (2995.pdf, page 22, BLOCK I/O command): For a block write sequence the EP2 FIFO must be pre-filled with data before command execution. Additionally, for block sizes greater then the FIFO size, the FIFO content status must be monitored by host SW so that additional data can be sent to the FIFO when necessary. A similar EP3 FIFO content monitoring requirement exists for block read sequences. During a block read the number of bytes loaded into the EP3 FIFO must be monitored so that the data can be read before the FIFO overflows. Breaking the buffer in 128 bytes blocks and simply calling the original code sequence has solved the issue for me. Tested with a DS1490F usb<->one-wire adapter and both the DS28EC20 and DS2433 eeprom memories. Note: The v1 of this patch changed both the ds_read_block and ds_write_block functions, but since I don't have any way to test the 'write' part with writes bigger than a page size (maximum accepted by my eeprom), I preferred not to make any assumptions and I just removed that part. Signed-off-by: Marc Ferland --- drivers/w1/masters/ds2490.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c index 5f5b97e24700..b6e244992c15 100644 --- a/drivers/w1/masters/ds2490.c +++ b/drivers/w1/masters/ds2490.c @@ -98,6 +98,8 @@ #define ST_EPOF 0x80 /* Status transfer size, 16 bytes status, 16 byte result flags */ #define ST_SIZE 0x20 +/* 1-wire data i/o fifo size, 128 bytes */ +#define FIFO_SIZE 0x80 =20 /* Result Register flags */ #define RR_DETECT 0xA5 /* New device detected */ @@ -614,14 +616,11 @@ static int ds_read_byte(struct ds_device *dev, u8 *by= te) return 0; } =20 -static int ds_read_block(struct ds_device *dev, u8 *buf, int len) +static int __read_block(struct ds_device *dev, u8 *buf, int len) { struct ds_status st; int err; =20 - if (len > 64*1024) - return -E2BIG; - memset(buf, 0xFF, len); =20 err =3D ds_send_data(dev, buf, len); @@ -640,6 +639,24 @@ static int ds_read_block(struct ds_device *dev, u8 *bu= f, int len) return err; } =20 +static int ds_read_block(struct ds_device *dev, u8 *buf, int len) +{ + int err, to_read, rem =3D len; + + if (len > 64*1024) + return -E2BIG; + + do { + to_read =3D rem <=3D FIFO_SIZE ? rem : FIFO_SIZE; + err =3D __read_block(dev, &buf[len - rem], to_read); + if (err < 0) + return err; + rem -=3D to_read; + } while (rem); + + return err; +} + static int ds_write_block(struct ds_device *dev, u8 *buf, int len) { int err; --=20 2.34.1 From nobody Tue Dec 16 16:38:53 2025 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 DF6C8C4167B for ; Thu, 30 Nov 2023 13:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345758AbjK3NxT (ORCPT ); Thu, 30 Nov 2023 08:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345740AbjK3NxQ (ORCPT ); Thu, 30 Nov 2023 08:53:16 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14A88B9 for ; Thu, 30 Nov 2023 05:53:23 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40b4c2ef584so7805105e9.3 for ; Thu, 30 Nov 2023 05:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701352401; x=1701957201; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vh8fgHf4VbVXQAtoSfn0NqPkk1fZpC4zX2ISfWKVIQM=; b=mob7rgADKfDtN0ODT3laUMpF4w4GUiLz1OCtmp3MwKY3jnf2cjoOUpLofzLekHjqB4 XuGe9Q7GG7r5P25CqYXO0ndlZCL+glg6bgRHO3uTgNg+nwZhJVAObHRqu+uqpdAPTheH 2+qK/OtwF3D7YSoctt9RP9q0LnvVemB7zLyYcXF/1UzHqrad4rDRQKan+sBNYunS7+jP bv/t1WPHlVWsVWE942w1GclmdqNPFkV+BikC9/9B0ARIMWnM1B/P8Sd1UXVKsoT268oF 6E5UJrLVwK4DG9s1rtRnq5qtS9u69rnsWj5azZSphJllzZ7aKSL54qbLXuAxlR1L/So1 Nlaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352401; x=1701957201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vh8fgHf4VbVXQAtoSfn0NqPkk1fZpC4zX2ISfWKVIQM=; b=D41rPj1uYxi9OZDqc9YzhMeVoPPFQ/t9Ktgoc6pkDDyAaaQGQnav2owQr2VjueaGbJ HSDR2lNeovARhac3cYf5kdIAfyRJm8JpleLQeaW6b4m01PZG+HxnlJvfNR74e17bUtbu zgAO2hz3NcjT8CugXwhNoVZRQDPq23TVgF1blpfJs4ERymLSpT7F4ZEdDlYxwznjQYzT DDv/Ze94cTn2YTD5pcQ5NTSDGbFU5xT26DDgtpdIKnm1/0swfCtHphTjvZVhMOes/36p a8PodA6eDfJt6M5nzgITtqp8/ng65pVlUWFOtyacR5OlT5vtG1lioNXK3AjMrhheYcrm Rqsg== X-Gm-Message-State: AOJu0YzWzj4IOlCKvlwzgSibG/mepYDoypdgG1b0CKlwgKxS725poLYL WYTzA8uqeMmtu2KIWjHLiOk= X-Google-Smtp-Source: AGHT+IGaLv3RI8lqocNNF3eRfSnx3JhFXi80PR7IlvFYnJnh7qLCynxVjit8YcDIqMZPMeNu80uXlA== X-Received: by 2002:a05:600c:3b23:b0:405:4a78:a892 with SMTP id m35-20020a05600c3b2300b004054a78a892mr13782875wms.9.1701352401362; Thu, 30 Nov 2023 05:53:21 -0800 (PST) Received: from mfe-desktop.Sonatest.net (ipagstaticip-d73c7528-4de5-0861-800b-03d8b15e3869.sdsl.bell.ca. [174.94.156.236]) by smtp.googlemail.com with ESMTPSA id d9-20020a05600c34c900b0040b2c195523sm5864573wmq.31.2023.11.30.05.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:53:20 -0800 (PST) From: marc.ferland@gmail.com X-Google-Original-From: marc.ferland@sonatest.com To: krzysztof.kozlowski@linaro.org Cc: gregkh@linuxfoundation.org, marc.ferland@sonatest.com, jeff.dagenais@gmail.com, rdunlap@infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/5] w1: ds2433: remove unused definition Date: Thu, 30 Nov 2023 08:52:29 -0500 Message-Id: <20231130135232.191320-3-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130135232.191320-1-marc.ferland@sonatest.com> References: <20231130135232.191320-1-marc.ferland@sonatest.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Ferland W1_F23_TIME isn't used anywhere, get rid of it. Signed-off-by: Marc Ferland --- drivers/w1/slaves/w1_ds2433.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index 9f21fd98f799..e18523ef8c45 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -30,8 +30,6 @@ #define W1_PAGE_BITS 5 #define W1_PAGE_MASK 0x1F =20 -#define W1_F23_TIME 300 - #define W1_F23_READ_EEPROM 0xF0 #define W1_F23_WRITE_SCRATCH 0x0F #define W1_F23_READ_SCRATCH 0xAA --=20 2.34.1 From nobody Tue Dec 16 16:38:53 2025 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 DA0DFC4167B for ; Thu, 30 Nov 2023 13:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345753AbjK3Nx2 (ORCPT ); Thu, 30 Nov 2023 08:53:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345763AbjK3NxT (ORCPT ); Thu, 30 Nov 2023 08:53:19 -0500 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 424B5131 for ; Thu, 30 Nov 2023 05:53:25 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c9b7bd6fffso12883061fa.3 for ; Thu, 30 Nov 2023 05:53:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701352403; x=1701957203; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4jPqJAoT2VW6Xw934SGmT3qvNdjOvu6oesgMdO97hOc=; b=fR4yRsQH+0RNWmgsbNqceOzRcHKgWn651xSoWrXSzSUlzQrup9x4bictNZS0TE+rg+ gNeYeF8DgG+1iM7yGzvZlEfXz34g7mYdd2+oOyoLbtMuTn/NdHppW4GOrC4VmBofSGeR N2w2RNWgZzX0OKX77TwUjRs4CeGyHRxHx859wixeTZBnfMi/flPGEBbNSii1BVCG5seV F1mdg586tVhgmsIpoHUrQIj+jEDzsisNS4S9PY+yhX7sNfcuuptB4I36Tk2irIrbXev5 IfnUtJAZW0zvuMmWGuR0kOkRqFVJKk0SUs3REFtcA6eLNjTt6J1Hwbsa5WsPiPexnjfJ Cwtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352403; x=1701957203; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4jPqJAoT2VW6Xw934SGmT3qvNdjOvu6oesgMdO97hOc=; b=gSCJQDREh/078+zGpauG7xf95xntNgo1FpdOjvCANGOWUTPW8McBC0zreZ3OgcUUiO pT/SA8x8pmFcGB19X2KfjNpxMBoWkeKSJBESKg6EldRj8fXQfGCKHEGiq3IQ+yjEHtRc X/x/H4QfKh7DIkNEzUCosAM8PA6tGZscCoELazCkxcoVI/OyEiqfKCF5V2tM57R//dkf W9T47tCf3E5KnmmwjCirQMPBtqCBYkYacitCtmNUi2mrzYa9FeEttGnZToL/M4pgkLGm i++Q3An5YJLcd4StBuUC0Bf//1s04O5nxWnsf4zJY870nIEvdn67TgdL0AGTEviLW9Aq 3/aw== X-Gm-Message-State: AOJu0YxFl0MjF7uVfswE4BRVdR9UJ5bMod5DW73rQ5Z20Nu7Q95l427G mdFvzEDvPCXX9QgWsmzbYuw5EOTtbSA= X-Google-Smtp-Source: AGHT+IFHJMPYlI4DbmvVzORiPCFKkiL2/5v3CEPx6XVvrJGU9q7SeNHZpJ8tfPOHpEntXbcwjx3B1Q== X-Received: by 2002:a2e:8049:0:b0:2c9:b84a:1482 with SMTP id p9-20020a2e8049000000b002c9b84a1482mr5073867ljg.17.1701352403467; Thu, 30 Nov 2023 05:53:23 -0800 (PST) Received: from mfe-desktop.Sonatest.net (ipagstaticip-d73c7528-4de5-0861-800b-03d8b15e3869.sdsl.bell.ca. [174.94.156.236]) by smtp.googlemail.com with ESMTPSA id d9-20020a05600c34c900b0040b2c195523sm5864573wmq.31.2023.11.30.05.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:53:22 -0800 (PST) From: marc.ferland@gmail.com X-Google-Original-From: marc.ferland@sonatest.com To: krzysztof.kozlowski@linaro.org Cc: gregkh@linuxfoundation.org, marc.ferland@sonatest.com, jeff.dagenais@gmail.com, rdunlap@infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/5] w1: ds2433: introduce a configuration structure Date: Thu, 30 Nov 2023 08:52:30 -0500 Message-Id: <20231130135232.191320-4-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130135232.191320-1-marc.ferland@sonatest.com> References: <20231130135232.191320-1-marc.ferland@sonatest.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Ferland Add a ds2433_config structure for parameters that are different between the ds2433 and the ds28ec20. The goal is to reuse the same code for both chips. A pointer to this config structure is added to w1_f23_data and the CONFIG_W1_SLAVE_DS2433_CRC ifdefs are adjusted since now both driver configurations (with or without crc support) will make use of w1_f23_data. Also, the 'memory' buffer is now dynamically allocated based on the size specififed in the config structure to help support memories of different sizes. Signed-off-by: Marc Ferland --- drivers/w1/slaves/w1_ds2433.c | 47 ++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index e18523ef8c45..7d4d9fc1a9c4 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -25,7 +25,7 @@ #define W1_EEPROM_DS2433 0x23 =20 #define W1_EEPROM_SIZE 512 -#define W1_PAGE_COUNT 16 + #define W1_PAGE_SIZE 32 #define W1_PAGE_BITS 5 #define W1_PAGE_MASK 0x1F @@ -35,9 +35,24 @@ #define W1_F23_READ_SCRATCH 0xAA #define W1_F23_COPY_SCRATCH 0x55 =20 +struct ds2433_config { + size_t eeprom_size; /* eeprom size in bytes */ + unsigned int page_count; /* number of 256 bits pages */ + unsigned int tprog; /* time in ms for page programming */ +}; + +static const struct ds2433_config config_f23 =3D { + .eeprom_size =3D W1_EEPROM_SIZE, + .page_count =3D 16, + .tprog =3D 5, +}; + struct w1_f23_data { - u8 memory[W1_EEPROM_SIZE]; +#ifdef CONFIG_W1_SLAVE_DS2433_CRC + u8 *memory; u32 validcrc; +#endif + const struct ds2433_config *cfg; }; =20 /* @@ -96,7 +111,7 @@ static ssize_t eeprom_read(struct file *filp, struct kob= ject *kobj, u8 wrbuf[3]; #endif =20 - count =3D w1_f23_fix_count(off, count, W1_EEPROM_SIZE); + count =3D w1_f23_fix_count(off, count, bin_attr->size); if (!count) return 0; =20 @@ -151,9 +166,7 @@ static ssize_t eeprom_read(struct file *filp, struct ko= bject *kobj, */ static int w1_f23_write(struct w1_slave *sl, int addr, int len, const u8 *= data) { -#ifdef CONFIG_W1_SLAVE_DS2433_CRC struct w1_f23_data *f23 =3D sl->family_data; -#endif u8 wrbuf[4]; u8 rdbuf[W1_PAGE_SIZE + 3]; u8 es =3D (addr + len - 1) & 0x1f; @@ -189,8 +202,8 @@ static int w1_f23_write(struct w1_slave *sl, int addr, = int len, const u8 *data) wrbuf[3] =3D es; w1_write_block(sl->master, wrbuf, 4); =20 - /* Sleep for 5 ms to wait for the write to complete */ - msleep(5); + /* Sleep for tprog ms to wait for the write to complete */ + msleep(f23->cfg->tprog); =20 /* Reset the bus to wake up the EEPROM (this may not be needed) */ w1_reset_bus(sl->master); @@ -207,7 +220,7 @@ static ssize_t eeprom_write(struct file *filp, struct k= object *kobj, struct w1_slave *sl =3D kobj_to_w1_slave(kobj); int addr, len, idx; =20 - count =3D w1_f23_fix_count(off, count, W1_EEPROM_SIZE); + count =3D w1_f23_fix_count(off, count, bin_attr->size); if (!count) return 0; =20 @@ -269,24 +282,34 @@ static const struct attribute_group *w1_f23_groups[] = =3D { =20 static int w1_f23_add_slave(struct w1_slave *sl) { -#ifdef CONFIG_W1_SLAVE_DS2433_CRC struct w1_f23_data *data; =20 data =3D kzalloc(sizeof(struct w1_f23_data), GFP_KERNEL); if (!data) return -ENOMEM; + + data->cfg =3D &config_f23; + +#ifdef CONFIG_W1_SLAVE_DS2433_CRC + data->memory =3D kzalloc(data->cfg->eeprom_size, GFP_KERNEL); + if (!data->memory) { + kfree(data); + return -ENOMEM; + } +#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ sl->family_data =3D data; =20 -#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ return 0; } =20 static void w1_f23_remove_slave(struct w1_slave *sl) { + struct w1_f23_data *data =3D sl->family_data; #ifdef CONFIG_W1_SLAVE_DS2433_CRC - kfree(sl->family_data); + kfree(data->memory); +#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ + kfree(data); sl->family_data =3D NULL; -#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ } =20 static const struct w1_family_ops w1_f23_fops =3D { --=20 2.34.1 From nobody Tue Dec 16 16:38:53 2025 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 5E8D0C4167B for ; Thu, 30 Nov 2023 13:53:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345775AbjK3Nxa (ORCPT ); Thu, 30 Nov 2023 08:53:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345780AbjK3NxZ (ORCPT ); Thu, 30 Nov 2023 08:53:25 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 046001703 for ; Thu, 30 Nov 2023 05:53:27 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40b397793aaso5762325e9.0 for ; Thu, 30 Nov 2023 05:53:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701352406; x=1701957206; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=22flK2ZnV7fxAF7GRABs1AemQfTsdiwJ7rqNojXeu70=; b=gMVgEfkY6l0yb7xIu0M0gmhXBB/T2+WWFM+X6vD2s4tqLalDaQ24rguUznMktGNO2W vXlrWk+1YM2j71jExi3n99brPLCYCdbaumlwUFpWBDw1pZ98lmCGKYozeRKUF8i835xI DNmuSs4467Qf4Uuc/NPUnyEKQK5A1TK2rMr0E+52CVBOW/FsF+4J24PY1dvjubgA81aw TqaC2+oUhuvfRg9sXtzEtTALfScCm+AveJ0vJYHX/+s6jBnphx5EmX2tNAqvCFQEB3Nj 3n01aiCWTqo9VbV3up0/SF5W4ek8Fukch+6NagHt6mjgqnm3GZ/yUHjDEwwv1g45MP/o HmrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352406; x=1701957206; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=22flK2ZnV7fxAF7GRABs1AemQfTsdiwJ7rqNojXeu70=; b=pTVueQM7DasHRsFRAlqh84Lu1umTRA7nZWbtPYYTZJlrLUFu/3ZBpzXs8aqUUEiolD URNejbL+F4WoWB2x8NA+9MpIFZaVH8kHjrFLLRP6iL4Yr54zomneyxFgUTA4QAXssBS7 /aJGkU435Y2lNk6fIrUEq5Php4VhRM6RP/uAkpqaUPrzNPE1aT5gMoynd3v2ih5EP7CT NvG3A501XfzdkSFh1GF8HaHbU9hYtEKfrCLSXKqQKCRCY+/1XM9p4R/CTr9gPUBImYhp Mx+y/sf7lGZwwRX3x2nUfqMpb2P0wueBbYlv2IyAwj8xMgLy9kviwQW0xFMYoe37K1Di wMLw== X-Gm-Message-State: AOJu0Yx5fSGjal+fkcTKMsNFHctQnCfW3SIU+c/S3VBBPMmi0x1Pwli+ lZJ13PSyf4olKcLhv/qiIXFVXZYTOXc= X-Google-Smtp-Source: AGHT+IEozFY2cjarBpixSbdrCz1+V45vzXIl2TTDK9dmJ8tARXuOGHBo9vg/tr1EwBkPUdM21wnhlA== X-Received: by 2002:a05:600c:4507:b0:406:44fc:65c9 with SMTP id t7-20020a05600c450700b0040644fc65c9mr19258107wmo.8.1701352406158; Thu, 30 Nov 2023 05:53:26 -0800 (PST) Received: from mfe-desktop.Sonatest.net (ipagstaticip-d73c7528-4de5-0861-800b-03d8b15e3869.sdsl.bell.ca. [174.94.156.236]) by smtp.googlemail.com with ESMTPSA id d9-20020a05600c34c900b0040b2c195523sm5864573wmq.31.2023.11.30.05.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:53:24 -0800 (PST) From: marc.ferland@gmail.com X-Google-Original-From: marc.ferland@sonatest.com To: krzysztof.kozlowski@linaro.org Cc: gregkh@linuxfoundation.org, marc.ferland@sonatest.com, jeff.dagenais@gmail.com, rdunlap@infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/5] w1: ds2433: use the kernel bitmap implementation Date: Thu, 30 Nov 2023 08:52:31 -0500 Message-Id: <20231130135232.191320-5-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130135232.191320-1-marc.ferland@sonatest.com> References: <20231130135232.191320-1-marc.ferland@sonatest.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Ferland The ds2433 driver uses the 'validcrc' variable to mark out which pages have been successfully (crc is valid) retrieved from the eeprom and placed in the internal 'memory' buffer (see CONFIG_W1_SLAVE_DS2433_CRC). The current implementation assumes that the number of pages will never go beyond 32 pages (bit field is a u32). This is fine for the ds2433 since it only has 16 pages. Use a dynamically allocated bitmap so that we can support eeproms with more than 32 pages which is the case for the ds28ec20 (80 pages). As an added bonus, the code also gets easier on the eye. Signed-off-by: Marc Ferland --- drivers/w1/slaves/w1_ds2433.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index 7d4d9fc1a9c4..63ed03191137 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -49,8 +49,8 @@ static const struct ds2433_config config_f23 =3D { =20 struct w1_f23_data { #ifdef CONFIG_W1_SLAVE_DS2433_CRC - u8 *memory; - u32 validcrc; + u8 *memory; + unsigned long *validcrc; #endif const struct ds2433_config *cfg; }; @@ -77,11 +77,11 @@ static int w1_f23_refresh_block(struct w1_slave *sl, st= ruct w1_f23_data *data, u8 wrbuf[3]; int off =3D block * W1_PAGE_SIZE; =20 - if (data->validcrc & (1 << block)) + if (test_bit(block, data->validcrc)) return 0; =20 if (w1_reset_select_slave(sl)) { - data->validcrc =3D 0; + bitmap_zero(data->validcrc, data->cfg->page_count); return -EIO; } =20 @@ -93,7 +93,7 @@ static int w1_f23_refresh_block(struct w1_slave *sl, stru= ct w1_f23_data *data, =20 /* cache the block if the CRC is valid */ if (crc16(CRC16_INIT, &data->memory[off], W1_PAGE_SIZE) =3D=3D CRC16_VALI= D) - data->validcrc |=3D (1 << block); + set_bit(block, data->validcrc); =20 return 0; } @@ -208,7 +208,7 @@ static int w1_f23_write(struct w1_slave *sl, int addr, = int len, const u8 *data) /* Reset the bus to wake up the EEPROM (this may not be needed) */ w1_reset_bus(sl->master); #ifdef CONFIG_W1_SLAVE_DS2433_CRC - f23->validcrc &=3D ~(1 << (addr >> W1_PAGE_BITS)); + clear_bit(addr >> W1_PAGE_BITS, f23->validcrc); #endif return 0; } @@ -296,6 +296,13 @@ static int w1_f23_add_slave(struct w1_slave *sl) kfree(data); return -ENOMEM; } + data->validcrc =3D bitmap_zalloc(data->cfg->page_count, + GFP_KERNEL); + if (!data->validcrc) { + kfree(data->memory); + kfree(data); + return -ENOMEM; + } #endif /* CONFIG_W1_SLAVE_DS2433_CRC */ sl->family_data =3D data; =20 @@ -307,6 +314,7 @@ static void w1_f23_remove_slave(struct w1_slave *sl) struct w1_f23_data *data =3D sl->family_data; #ifdef CONFIG_W1_SLAVE_DS2433_CRC kfree(data->memory); + bitmap_free(data->validcrc); #endif /* CONFIG_W1_SLAVE_DS2433_CRC */ kfree(data); sl->family_data =3D NULL; --=20 2.34.1 From nobody Tue Dec 16 16:38:53 2025 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 F13C5C4167B for ; Thu, 30 Nov 2023 13:53:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345839AbjK3Nxd (ORCPT ); Thu, 30 Nov 2023 08:53:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345816AbjK3Nx1 (ORCPT ); Thu, 30 Nov 2023 08:53:27 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D87DF1721 for ; Thu, 30 Nov 2023 05:53:29 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40b538d5c4eso6385585e9.1 for ; Thu, 30 Nov 2023 05:53:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701352408; x=1701957208; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DzCWC63D/h6//8PScKXUzeHvcD/O+lCbOIGXiWj5l+M=; b=KMTO3pi/b/IiDz3TJrwtXnNDm7R0rKwtykFzmt9e0Ytev3aWm4+TfGrE2YT9xBkHF4 N3V+bcB+cL79Ij1QPyzYz+FuVpbqv8dfWI+SliglkZzNxGyLHH6f5/XsUsr5UzMtZHaH 1QC/JnzofLAXuEJ/oX23jdTXPlLPDwfrZnh/7TPPcCoCxav+4cadXYvPJtO/+w+oIWpQ Q/hrqE0UCKPt6H+uQS/drZVqYIVNJGvz/+uuv4fB/J09D+W7yLoPeCjkdSI+051mIrat EDp3gREN84+J0dPPW5i22jf06T9Q201P63UfxfNXbJOmFaHjumWkQKOxKeqWDIqrPnzQ nssw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701352408; x=1701957208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DzCWC63D/h6//8PScKXUzeHvcD/O+lCbOIGXiWj5l+M=; b=ZAPzRH89NTfKZgTp3QYz5lTMwZIEk+8va10gxnS4eo4nhKUDGa6uo3kuz0NhuQFpGp N6xGH1CQo5T0OuFt4NLwUogRRwhx0mOcOqBv0HNtrydbPB/x0Xt9mKjw7uB+LCVo4VM/ bXPMZSMeyZtUlB83POWur2k3uMIRRRjkZI+LAGoe9CJhQdtrf8/0EliAlI2GyYejMQD6 ceVb6YiMA1oGQ7vOoaTVKcqfzCIxn+5Ne9SRPpTDBNUr/9ho8cKEIrXItRg2fxwH+6/F oxWsOTPXQAlScgGV21B0KbnYuvXf8WzciUO7Jw34w5e2g3ERSRsold1qIoEDPkVE7NJi h3xQ== X-Gm-Message-State: AOJu0YynwXpQ3dwRU0UHUt2u3xdjSGCTZo8uKFaf/ZfSWF62tO+7paji eA0V7mobeh4NfPVNhma9W6g= X-Google-Smtp-Source: AGHT+IHYH9TjvVOmWJEP50X6tBWWe7CxNLCAH5qNmNYlkH3UoQqRyvgFURnID8D6d6ZPcLHrkOpTrQ== X-Received: by 2002:a05:600c:296:b0:40b:47dc:9b9d with SMTP id 22-20020a05600c029600b0040b47dc9b9dmr7381246wmk.40.1701352408235; Thu, 30 Nov 2023 05:53:28 -0800 (PST) Received: from mfe-desktop.Sonatest.net (ipagstaticip-d73c7528-4de5-0861-800b-03d8b15e3869.sdsl.bell.ca. [174.94.156.236]) by smtp.googlemail.com with ESMTPSA id d9-20020a05600c34c900b0040b2c195523sm5864573wmq.31.2023.11.30.05.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:53:27 -0800 (PST) From: marc.ferland@gmail.com X-Google-Original-From: marc.ferland@sonatest.com To: krzysztof.kozlowski@linaro.org Cc: gregkh@linuxfoundation.org, marc.ferland@sonatest.com, jeff.dagenais@gmail.com, rdunlap@infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/5] w1: ds2433: add support for ds28ec20 eeprom Date: Thu, 30 Nov 2023 08:52:32 -0500 Message-Id: <20231130135232.191320-6-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130135232.191320-1-marc.ferland@sonatest.com> References: <20231130135232.191320-1-marc.ferland@sonatest.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Ferland The ds28ec20 eeprom is (almost) backward compatible with the ds2433. The only differences are: - the eeprom size is now 2560 bytes instead of 512; - the number of pages is now 80 (same page size as the ds2433: 256 bits); - the programming time has increased from 5ms to 10ms; This patch adds support for the ds28ec20 to the ds2433 driver. From the datasheet: The DS28EC20 provides a high degree of backward compatibility with the DS2433. Besides the different family codes, the only protocol change that is required on an existing DS2433 implementation is a lengthening of the programming duration (tPROG) from 5ms to 10ms. dmesg now returns: w1_master_driver w1_bus_master1: Attaching one wire slave 43.0000004787= 56 crc e0 instead of: w1_master_driver w1_bus_master1: Attaching one wire slave 43.0000004787= 56 crc e0 w1_master_driver w1_bus_master1: Family 43 for 43.000000478756.e0 is no= t registered. Test script writing/reading random data (CONFIG_W1_SLAVE_DS2433_CRC is not set): #!/bin/sh EEPROM=3D/sys/bus/w1/devices/43-000000478756/eeprom BINFILE1=3D/home/root/file1.bin BINFILE2=3D/home/root/file2.bin for BS in 1 2 3 4 8 16 32 64 128 256 512 1024 2560; do dd if=3D/dev/random of=3D${BINFILE1} bs=3D${BS} count=3D1 status=3D= none dd if=3D${BINFILE1} of=3D${EEPROM} status=3Dnone dd if=3D${EEPROM} of=3D${BINFILE2} bs=3D${BS} count=3D1 status=3Dno= ne if ! cmp --silent ${BINFILE1} ${BINFILE2}; then echo file1 hexdump ${BINFILE1} echo file2 hexdump ${BINFILE2} echo FAIL exit 1 fi echo "${BS} OK!" done Results: # ./test.sh 1 OK! 2 OK! 3 OK! 4 OK! 8 OK! 16 OK! 32 OK! 64 OK! 128 OK! 256 OK! 512 OK! 1024 OK! 2560 OK! Tests with CONFIG_W1_SLAVE_DS2433_CRC=3Dy: $ cat /proc/config.gz | gunzip | grep CONFIG_W1_SLAVE_DS2433 CONFIG_W1_SLAVE_DS2433=3Dm CONFIG_W1_SLAVE_DS2433_CRC=3Dy # create a 32 bytes block with a crc, i.e.: 00000000 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 |123456789:= ;<=3D>?@| 00000010 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e ba 63 |ABCDEFGHIJ= KLMN.c| # fill all 80 blocks $ dd if=3Dtest.bin of=3D/sys/bus/w1/devices/43-000000478756/eeprom bs= =3D32 count=3D80 # read back all blocks, i.e.: $ hexdump -C /sys/bus/w1/devices/43-000000478756/eeprom 00000000 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 |123456789:= ;<=3D>?@| 00000010 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e ba 63 |ABCDEFGHIJ= KLMN.c| 00000020 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 |123456789:= ;<=3D>?@| 00000030 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e ba 63 |ABCDEFGHIJ= KLMN.c| ... 000009e0 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 |123456789:= ;<=3D>?@| 000009f0 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e ba 63 |ABCDEFGHIJ= KLMN.c| 00000a00 Note: both memories (ds2433 and ds28ec20) have been tested with the new driver. Signed-off-by: Marc Ferland Co-developed-by: Jean-Francois Dagenais Signed-off-by: Jean-Francois Dagenais --- drivers/w1/slaves/w1_ds2433.c | 98 ++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 8 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index 63ed03191137..ab1491a7854a 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * w1_ds2433.c - w1 family 23 (DS2433) driver + * w1_ds2433.c - w1 family 23 (DS2433) & 43 (DS28EC20) eeprom driver * * Copyright (c) 2005 Ben Gardner + * Copyright (c) 2023 Marc Ferland */ =20 #include @@ -23,8 +24,10 @@ #include =20 #define W1_EEPROM_DS2433 0x23 +#define W1_EEPROM_DS28EC20 0x43 =20 -#define W1_EEPROM_SIZE 512 +#define W1_EEPROM_DS2433_SIZE 512 +#define W1_EEPROM_DS28EC20_SIZE 2560 =20 #define W1_PAGE_SIZE 32 #define W1_PAGE_BITS 5 @@ -42,11 +45,17 @@ struct ds2433_config { }; =20 static const struct ds2433_config config_f23 =3D { - .eeprom_size =3D W1_EEPROM_SIZE, + .eeprom_size =3D W1_EEPROM_DS2433_SIZE, .page_count =3D 16, .tprog =3D 5, }; =20 +static const struct ds2433_config config_f43 =3D { + .eeprom_size =3D W1_EEPROM_DS28EC20_SIZE, + .page_count =3D 80, + .tprog =3D 10, +}; + struct w1_f23_data { #ifdef CONFIG_W1_SLAVE_DS2433_CRC u8 *memory; @@ -264,10 +273,22 @@ static ssize_t eeprom_write(struct file *filp, struct= kobject *kobj, return count; } =20 -static BIN_ATTR_RW(eeprom, W1_EEPROM_SIZE); +static struct bin_attribute bin_attr_f23_eeprom =3D { + .attr =3D { .name =3D "eeprom", .mode =3D 0644 }, + .read =3D eeprom_read, + .write =3D eeprom_write, + .size =3D W1_EEPROM_DS2433_SIZE, +}; + +static struct bin_attribute bin_attr_f43_eeprom =3D { + .attr =3D { .name =3D "eeprom", .mode =3D 0644 }, + .read =3D eeprom_read, + .write =3D eeprom_write, + .size =3D W1_EEPROM_DS28EC20_SIZE, +}; =20 static struct bin_attribute *w1_f23_bin_attributes[] =3D { - &bin_attr_eeprom, + &bin_attr_f23_eeprom, NULL, }; =20 @@ -280,6 +301,20 @@ static const struct attribute_group *w1_f23_groups[] = =3D { NULL, }; =20 +static struct bin_attribute *w1_f43_bin_attributes[] =3D { + &bin_attr_f43_eeprom, + NULL, +}; + +static const struct attribute_group w1_f43_group =3D { + .bin_attrs =3D w1_f43_bin_attributes, +}; + +static const struct attribute_group *w1_f43_groups[] =3D { + &w1_f43_group, + NULL, +}; + static int w1_f23_add_slave(struct w1_slave *sl) { struct w1_f23_data *data; @@ -288,7 +323,14 @@ static int w1_f23_add_slave(struct w1_slave *sl) if (!data) return -ENOMEM; =20 - data->cfg =3D &config_f23; + switch (sl->family->fid) { + case W1_EEPROM_DS2433: + data->cfg =3D &config_f23; + break; + case W1_EEPROM_DS28EC20: + data->cfg =3D &config_f43; + break; + } =20 #ifdef CONFIG_W1_SLAVE_DS2433_CRC data->memory =3D kzalloc(data->cfg->eeprom_size, GFP_KERNEL); @@ -326,13 +368,53 @@ static const struct w1_family_ops w1_f23_fops =3D { .groups =3D w1_f23_groups, }; =20 +static const struct w1_family_ops w1_f43_fops =3D { + .add_slave =3D w1_f23_add_slave, + .remove_slave =3D w1_f23_remove_slave, + .groups =3D w1_f43_groups, +}; + static struct w1_family w1_family_23 =3D { .fid =3D W1_EEPROM_DS2433, .fops =3D &w1_f23_fops, }; -module_w1_family(w1_family_23); + +static struct w1_family w1_family_43 =3D { + .fid =3D W1_EEPROM_DS28EC20, + .fops =3D &w1_f43_fops, +}; + +static int __init w1_ds2433_init(void) +{ + int err; + + err =3D w1_register_family(&w1_family_23); + if (err) + return err; + + err =3D w1_register_family(&w1_family_43); + if (err) + goto err_43; + + return 0; + +err_43: + w1_unregister_family(&w1_family_23); + return err; +} + +static void __exit w1_ds2433_exit(void) +{ + w1_unregister_family(&w1_family_23); + w1_unregister_family(&w1_family_43); +} + +module_init(w1_ds2433_init); +module_exit(w1_ds2433_exit); =20 MODULE_AUTHOR("Ben Gardner "); -MODULE_DESCRIPTION("w1 family 23 driver for DS2433, 4kb EEPROM"); +MODULE_AUTHOR("Marc Ferland "); +MODULE_DESCRIPTION("w1 family 23/43 driver for DS2433 (4kb) and DS28EC20 (= 20kb)"); MODULE_LICENSE("GPL"); MODULE_ALIAS("w1-family-" __stringify(W1_EEPROM_DS2433)); +MODULE_ALIAS("w1-family-" __stringify(W1_EEPROM_DS28EC20)); --=20 2.34.1