From nobody Fri Dec 19 06:38:55 2025 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 957603D540 for ; Mon, 18 Dec 2023 15:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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="XEYbUYxv" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-40c824b199fso22137475e9.1 for ; Mon, 18 Dec 2023 07:02:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702911758; x=1703516558; 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=+efQ3dctr+OQvRMNDnm0Ymjvj7E044tU07+IdHrC1Vg=; b=XEYbUYxvbju3ckGQE4dBlJkl+6ytK2yfaK4n0xMEujgQ1DBwBsFI2BTy7LFDQT0taJ N5Wigl5ERAnoJgZp/oL18efianMmQPtDHrhXqwmT6DoWl3EqlH5u5uuOvVRGHNh2Ow++ by2MzA1nZbzLCX6Kn8bWQq0xUccCWLJgfXHZca6nKV854vdnKz32baFr13lTzcCYLN0y yOWc7s+7muBbmOLQOQb8o3hIKUgfpO5cdNFSooPJHgBFqbUbLE4xeC+J9EE5mr1A+4Lb FUxocyI24mdnuIxu4QeTBr9t2JE6wNpUaITJuc/o/mzlfzDvSEe4qSruvgZGuYKefvF8 C3Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702911758; x=1703516558; 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=+efQ3dctr+OQvRMNDnm0Ymjvj7E044tU07+IdHrC1Vg=; b=XYJPWJNsnn1cEC8Icg7WZWs4ElSAG8SGkrwcM2FgyrKyAsfDbsQ/19uzZ7iU3kHW8C 6bz9G3FYVjmIuK8dM1S1Ycp0H7p4xWLi8CAvQXG1KfzE5rND/o0gavfIbtsOsnFkUeos PEYHHD+Kz9NHbuMm/psoiZr4XaLicwtW+k41IwQO+O5qs9oH8ZlDu4gHoSiIPM9T4v6i pOlriXtPx6g5MPJ5zi/xL8+Fi28BNwy5uJqQhszc/QR8yQwWSm+MjFilKAIufg9OJMHf idZpdkmxCl3TfLvvtALbnmaG/QDeHlHIa8nrry0bB3dByqSxMWyP2ysJhQCuWuHadGbu 4yFg== X-Gm-Message-State: AOJu0YxRss4tQgtFdKnBFAu2B8G2qMTlzoMsJvh27l76TzN1wn2I0V5Y d7KZwK6F1Bc69BAIjX3cRoE= X-Google-Smtp-Source: AGHT+IGhwY9c63jbk9DRsD/cZJ6ympUCuQWmMb+3muWlT5XIQ895agc+N+dmWB/jdm+AEqGn/Mdmrw== X-Received: by 2002:a05:600c:1705:b0:40c:315e:9ec3 with SMTP id c5-20020a05600c170500b0040c315e9ec3mr8126152wmn.65.1702911757799; Mon, 18 Dec 2023 07:02:37 -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 v18-20020a05600c445200b0040a3f9862e3sm3741814wmn.1.2023.12.18.07.02.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:02:37 -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 v4 1/5] w1: ds2490: support block sizes larger than 128 bytes in ds_read_block Date: Mon, 18 Dec 2023 10:02:26 -0500 Message-Id: <20231218150230.1992448-2-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218150230.1992448-1-marc.ferland@sonatest.com> References: <20231218150230.1992448-1-marc.ferland@sonatest.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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_ arise 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 block in smaller 128 bytes chunks 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. 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..4b285d4944aa 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_chunk(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_chunk(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 Fri Dec 19 06:38:55 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 730EC3D579 for ; Mon, 18 Dec 2023 15:02:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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="jmRprAEn" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-40c2bb872e2so36677795e9.3 for ; Mon, 18 Dec 2023 07:02:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702911759; x=1703516559; 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=xSPmstIzw2V0xdaeu3UEvx0O97+IGAfial7Fk0oauN4=; b=jmRprAEnIzZ1lfm3mzVNU8fr2ItU28yKLMDyGpFqueV3eu7A5XC0lKbIEFgXTXmnW9 R8z39BD8GmBhdL3nGKQ4gDgsT9IM/MrKnOSDQGG4LReoV/0rnEp3aBx3CxoHP3N0Xmyr c5WlTNO33Ctsjea8t/f5DMqzHnEE6hESPEbIC4AZeK5QCdX2L0cUVSdj4KkdDV/RG16x m8K3TK+naIwxTBk3ON9fNBqGRPvqezJbkidqBKFpvmN6WYnsbaZavmNEt10gW7iybOeu c0OX5ougQu50yz6l+OhGWWQhisuzam9cdnyxhluFZS3J1OTTEgAir7WzTrvO84jOpEoK jMMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702911759; x=1703516559; 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=xSPmstIzw2V0xdaeu3UEvx0O97+IGAfial7Fk0oauN4=; b=gKPlzCjiZgRbYCZtmrXGyaNPjbwtw2EETS66YicDNx1qdxUMMhlPvg55etMUPOdgGx EvMuRW6ukotL2crtVbgOccfTmNbXcwKqt1KQh8nZsVidUGEZwCHhf0BAFqSFK+Gt78b/ 6/E1RvwT1IB1bDpXOgAMpBHZPbIdA8razoiuYDrnaQeg2Zi6FA0lIhkAUq6EH5PQTlEu 0ATvHv+VPgAOvHs6KKukdaY+zgmDhCKyTWt4LMiipWbKpSoa3Upm528OkZzWhFNxcChg qinLKgmTxwUliy5nPIxNIKSPzAFY+SJYD2DLEX81kwUbBQmT7in//Wvs505jOCb+y8Tz LCOA== X-Gm-Message-State: AOJu0YwBnU8U/73bYf21CQ3UeTC4a5Kmfu8b942z27qRB5J7XdthSAjA cn/xZiKzfcvW7k5ISBuz3Qk= X-Google-Smtp-Source: AGHT+IGXxSUtvYbNnBnFFcaXLM9umBTEYXvSB0O9Kf2YTnQppX1mwL/dYFwMMXHhWFNIfBijr0S4hw== X-Received: by 2002:a05:600c:3657:b0:40c:35b3:b797 with SMTP id y23-20020a05600c365700b0040c35b3b797mr4222408wmq.35.1702911759414; Mon, 18 Dec 2023 07:02:39 -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 v18-20020a05600c445200b0040a3f9862e3sm3741814wmn.1.2023.12.18.07.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:02:39 -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 v4 2/5] w1: ds2433: remove unused definitions Date: Mon, 18 Dec 2023 10:02:27 -0500 Message-Id: <20231218150230.1992448-3-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218150230.1992448-1-marc.ferland@sonatest.com> References: <20231218150230.1992448-1-marc.ferland@sonatest.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Marc Ferland Both W1_F23_TIME and W1_PAGE_COUNT are unused, get rid of them. Signed-off-by: Marc Ferland --- drivers/w1/slaves/w1_ds2433.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index 9f21fd98f799..cd99eceac1ae 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -25,13 +25,10 @@ #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 =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 Fri Dec 19 06:38:55 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 2E0763A1C7 for ; Mon, 18 Dec 2023 15:02:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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="aR8fL4Ro" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40b5155e154so39641275e9.3 for ; Mon, 18 Dec 2023 07:02:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702911761; x=1703516561; 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=fXPVw6iwVGyN3Gn7MPY6LEH6gfBHetBScHY6a0NPK7w=; b=aR8fL4Ron/YfTb9YjPyDHXNSK3O07L/ib6VvT0kSekiBO0DQYuLffFRUmUwvZatj7b DeASzwkhWnPfKIHLifgCtst9IZBsV4IjfHDYepHCLsxM/tOVB3715B5ZktwIfVd3D/1A tV0r4NXm4wpNiaQPiDpEZrp1yZXDGKQJcVSA/FHlhbPxdOxFYc1trYDYHDR93S5QhZap mPRW7FdYxmsWcQQAhwez4mzM9GwJ/hsvhzVbuTvpCdcMNX31FSODpSHXQXjnhUB5SWpt KnEdmOqoT12n3XWuWdgRuyr4qpAl4CIxK0yMPpR6X9Rzj0gUj56k2Q1No+TlU7wXdgRM XnXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702911761; x=1703516561; 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=fXPVw6iwVGyN3Gn7MPY6LEH6gfBHetBScHY6a0NPK7w=; b=gOot24cw7TKlz2WxjUTUxcXsyfHmojt1gQtCr3R2rotpv0GdKfGKFrjOa1GBZsxNHZ si7c5P1AlJ3jNL6ckFFEymqWkT7VivwRZFOh4LQwx7NtV1T/Umxz8UJ+OCAPjTGBxJrw CYOt1QMQ8A5KcSsVd0X50nTBiLKs15LEaJQAsXocebW1esobd/MT1LkkDtbepEGiHcBf OiS+IoSnxExznL1+17sQB2BwmnScBW6SGKDKOCA5bplNg8VdY7BsI/IZBxtKHOz2Cz8J euE9x6aVvOWzcab1ihosSQbIyR5vUt74zrXX7YeAHE9UiAxnSxYA0lRoUhyJ82Lzgtfg Fwdg== X-Gm-Message-State: AOJu0YxIuJmo/mHi5yVC/fVAIxWcqzqT32z0GcCqaQVEGzL+F48NPxP2 C6ryFex6kzwxDkLhTsCZ1uY= X-Google-Smtp-Source: AGHT+IGMPeCEQBlfHJb5loIZmePmhyT0WmOdCnYvBn0gAfd+mBUvQtQQ4QxKeyJtnFNIBZA7AQIE/Q== X-Received: by 2002:a05:600c:3108:b0:40c:6c81:7ae2 with SMTP id g8-20020a05600c310800b0040c6c817ae2mr2688049wmo.182.1702911761385; Mon, 18 Dec 2023 07:02:41 -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 v18-20020a05600c445200b0040a3f9862e3sm3741814wmn.1.2023.12.18.07.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:02:40 -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 v4 3/5] w1: ds2433: introduce a configuration structure Date: Mon, 18 Dec 2023 10:02:28 -0500 Message-Id: <20231218150230.1992448-4-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218150230.1992448-1-marc.ferland@sonatest.com> References: <20231218150230.1992448-1-marc.ferland@sonatest.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 cd99eceac1ae..0c67082c8bb7 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -34,9 +34,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 /* @@ -95,7 +110,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 @@ -150,9 +165,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; @@ -188,8 +201,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); @@ -206,7 +219,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 @@ -268,24 +281,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) { -#ifdef CONFIG_W1_SLAVE_DS2433_CRC - kfree(sl->family_data); + struct w1_f23_data *data =3D sl->family_data; sl->family_data =3D NULL; -#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ +#ifdef CONFIG_W1_SLAVE_DS2433_CRC + kfree(data->memory); +#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ + kfree(data); } =20 static const struct w1_family_ops w1_f23_fops =3D { --=20 2.34.1 From nobody Fri Dec 19 06:38:55 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 62BB53A1B6 for ; Mon, 18 Dec 2023 15:02:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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="QLjMgq6d" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40c3f68b69aso30912415e9.1 for ; Mon, 18 Dec 2023 07:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702911763; x=1703516563; 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=BrCVp+ELjwJFeIl59KTx3k6nG/02EPd4vli/rhAAYEw=; b=QLjMgq6d2QN1t42qGqOLCqKoHlAJQkG+wGXI+UjcDJYj5UsyjMZ/fj0/ysQYaNZLBl 3q2YJVZi5zLW4vKjcaF4LVkzJ4ZKRQ4pkun3H+Bst1YiNBO76Zga4lObFIHhoYwNzjkf eBRH2yAvyyyopaFtzVxp15O6JhWdT2Av9pVv/YY0TNBHn9SRzWDgBfWmTTz6+Nv2S/JB hAYU5eh4tFJhwPhnHBU3Jb/Z1csj/rqCHa7dmIpMSJUFQlvHAiFk2LeE3yIGeVSG4Ucz C6pGDf10zMHKirsf1tutcoDaC9oGd2EAyAV/yU3y4rrCYS1HpXvqIyW3hHDNUgZ3LUcP RMdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702911763; x=1703516563; 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=BrCVp+ELjwJFeIl59KTx3k6nG/02EPd4vli/rhAAYEw=; b=f5imWl3p2wQdP2Z0v91b9TnOb86K7Df6zET/wgk4qOfZejYtf038svIufKouH6IEpM 5AAOBxZ6MiQIm+u9C72rA+L/w5CwsMXFKssnLnBMYoDLyEmnRJRCHiZGpnJVrzjyyPP+ L2WJb/BNx95KqGJ5SBI2Pk342UwwaiYwMTJxrXK7o7NKrHY1iBGZn3WCOKLHK7VH8UJi bEvuzAtCvwS+1fjLlsdPjZPG6mhGPMgrKeUyrFucGgo5+5WLzflZxqNshtfRRawUcE2c whuDd/wT5dsF5yU0YNir27bCV5ca5L+weK1gWC88W/TKOjHQWRNwRXLDtCACQ8wxw7Ir N8MA== X-Gm-Message-State: AOJu0YwiS7l8vmEvq5NAoGA4UHzYSizTaw5wN7/Nx4K4t1VgoiREXAmx amse+SzF7DUdviWJe+T6XJU= X-Google-Smtp-Source: AGHT+IGGbogZ7zmzL/bKQ+igdQnGqOoc75JZqE8v9myvMF4xn2ErGZdbpxnRb641+sEFvTZPEEwJSQ== X-Received: by 2002:a05:600c:5129:b0:40b:5e1b:549f with SMTP id o41-20020a05600c512900b0040b5e1b549fmr10100545wms.43.1702911763544; Mon, 18 Dec 2023 07:02:43 -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 v18-20020a05600c445200b0040a3f9862e3sm3741814wmn.1.2023.12.18.07.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:02:42 -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 v4 4/5] w1: ds2433: use the kernel bitmap implementation Date: Mon, 18 Dec 2023 10:02:29 -0500 Message-Id: <20231218150230.1992448-5-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218150230.1992448-1-marc.ferland@sonatest.com> References: <20231218150230.1992448-1-marc.ferland@sonatest.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. On the ds28ec20 though, the number of pages increases to 80 which will not fit on a single u32. As a solution, I replaced the u32 variable with a standard bitmap and set the number of bits to 32 which is the same size we had before. Signed-off-by: Marc Ferland --- drivers/w1/slaves/w1_ds2433.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index 0c67082c8bb7..87df76094e03 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -28,6 +28,7 @@ #define W1_PAGE_SIZE 32 #define W1_PAGE_BITS 5 #define W1_PAGE_MASK 0x1F +#define W1_VALIDCRC_MAX 32 =20 #define W1_F23_READ_EEPROM 0xF0 #define W1_F23_WRITE_SCRATCH 0x0F @@ -48,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; + DECLARE_BITMAP(validcrc, W1_VALIDCRC_MAX); #endif const struct ds2433_config *cfg; }; @@ -76,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 @@ -92,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; } @@ -207,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; } @@ -290,11 +291,17 @@ static int w1_f23_add_slave(struct w1_slave *sl) data->cfg =3D &config_f23; =20 #ifdef CONFIG_W1_SLAVE_DS2433_CRC + if (data->cfg->page_count > W1_VALIDCRC_MAX) { + dev_err(&sl->dev, "page count too big for crc bitmap\n"); + kfree(data); + return -EINVAL; + } data->memory =3D kzalloc(data->cfg->eeprom_size, GFP_KERNEL); if (!data->memory) { kfree(data); return -ENOMEM; } + bitmap_zero(data->validcrc, data->cfg->page_count); #endif /* CONFIG_W1_SLAVE_DS2433_CRC */ sl->family_data =3D data; =20 --=20 2.34.1 From nobody Fri Dec 19 06:38:55 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 10348498B0 for ; Mon, 18 Dec 2023 15:02:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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="nUX9HRDN" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40c517d0de5so35191055e9.0 for ; Mon, 18 Dec 2023 07:02:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702911765; x=1703516565; 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=33UEvlku9H80YwKyiOsjOU9cNtiOuGAX65EK76JzhzM=; b=nUX9HRDNC/3fp33+1mshnbb4eDi3fe9MLN9wOEQco1vVKTR/1lgnUXbhge1TnfOHNg 5/G3hQOms0ANPgIf6qR8S/qqTGKwfI3JeGrTWKeQyR5Ytpky49BP7yXNHoM94EkdSo6J /14HvqYJsMwb1dk7lhhxfcJpLXuy4BdZLKshSHwHG4jLX7eafoEygOeVaBNdmGL9hJ2Y hvAvvBRDn1dvgosaZ4S0yEEmYOismJloVCVUu5DXybwkFxe52AWlJ/pj8AL/R2GvE1FX ZvAFVGG8XqlBEBpUHS2K0NTv8V3XOiFvfoHGQ7QYj9sSfQWdRw88iPFftyhWUJSn33+Z rLXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702911765; x=1703516565; 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=33UEvlku9H80YwKyiOsjOU9cNtiOuGAX65EK76JzhzM=; b=nqSvkgkGbPMFRSUNdY859muA/YPgO4l5WhW6g0L+F0vDBbf78AOhp1iZZGs77x3hlt KD/ZKadSZdJfWRdjt8dkqZNaL1fcyLlcKs2PUK89xAGOL35freEnDbF2D3Dz79eHD//X Bf2kH2p9XnBTljZM7u+uwl9vsrx9JgQ0O/rXnskP3PJ/nqHe5Et6sZ/EIvSnziRwnSeX CxJ+TFlK2Uuo2mnxntbTYbbQtgui9r3n5porvvhslGSl85bcahx+yCC26cz1l+2x6tiH 9rz/m29xclpn3vYViVaeQvcy3P62oHeBiFvi48kcNTA4o5oZstBBrXVD5aPyWgFi3PPw Izaw== X-Gm-Message-State: AOJu0YyKjguxCNtHdmQ9GXOSVi4mRGDlyZZX4JvdWYXRre6fdrIqcBfF y5rwXHTH6LCKObFzriWxyoI= X-Google-Smtp-Source: AGHT+IHvqUdDTCHPB7hdV+W1rN1hRWZFwqikQa4382Q3MvwIVnL5ZsP7JXqQkQmtzcdeG/qk3V2dDQ== X-Received: by 2002:a7b:cbc7:0:b0:402:e68f:8896 with SMTP id n7-20020a7bcbc7000000b00402e68f8896mr8834738wmi.0.1702911765199; Mon, 18 Dec 2023 07:02:45 -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 v18-20020a05600c445200b0040a3f9862e3sm3741814wmn.1.2023.12.18.07.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:02:44 -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 v4 5/5] w1: ds2433: add support for ds28ec20 eeprom Date: Mon, 18 Dec 2023 10:02:30 -0500 Message-Id: <20231218150230.1992448-6-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231218150230.1992448-1-marc.ferland@sonatest.com> References: <20231218150230.1992448-1-marc.ferland@sonatest.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 | 101 +++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 9 deletions(-) diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index 87df76094e03..250b7f7ec429 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,12 +24,15 @@ #include =20 #define W1_EEPROM_DS2433 0x23 +#define W1_EEPROM_DS28EC20 0x43 + +#define W1_EEPROM_DS2433_SIZE 512 +#define W1_EEPROM_DS28EC20_SIZE 2560 =20 -#define W1_EEPROM_SIZE 512 #define W1_PAGE_SIZE 32 #define W1_PAGE_BITS 5 #define W1_PAGE_MASK 0x1F -#define W1_VALIDCRC_MAX 32 +#define W1_VALIDCRC_MAX 96 =20 #define W1_F23_READ_EEPROM 0xF0 #define W1_F23_WRITE_SCRATCH 0x0F @@ -42,11 +46,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 +274,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 +302,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 +324,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 if (data->cfg->page_count > W1_VALIDCRC_MAX) { @@ -324,13 +367,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