Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1455404rdb; Sun, 7 Jan 2024 22:18:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGL77s0csZaT8ta80fdtbCBbcHyYTwS4gxyNlcVD+qsw5VVkvn0XauFYcQQ6qiopz3rSbF5 X-Received: by 2002:a17:906:3855:b0:a28:b79a:37a0 with SMTP id w21-20020a170906385500b00a28b79a37a0mr722271ejc.222.1704694731759; Sun, 07 Jan 2024 22:18:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704694731; cv=none; d=google.com; s=arc-20160816; b=J9dvPvRWa42sxEf8P6ZM98s2/DdTvgBpndghp4hgAV4SPxP0cwpeq13Nq6yJR/vLC6 uBwuFhd+phriAFJ1OEQPEJGEsZBBtX7IdDe18OXe0YzVk/cvua/IZWgJ46c4xYV1IP2+ 33d4+ZClMgRh0x6AV3zM1yOzEDrla8H5LADuWrGrzJr9BEHcrPG1RPG3HN1VrjIHYEHY 0vYF9YjEXEQ4tH0BSnib8SH9DpZmYakkjT4YfBMDD1bWNC2LOqfCQgH1Kzvwn07/U9eu lOYCM5szBlDaxssCFprwZoqK345SdlXY4yLF9o9Mu32oidKG5yEhqV5R8qLaCJnMgBuj ygWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id; bh=JxKWZ0iFvolfQySmIZiVviFxg2q/+Ns/Cenq1wSZJho=; fh=xA9MWCFUeaVcPGAttInVKz22Gy07njVHf2xaG+oahkI=; b=f/oqcq4NBOR/Zyy/oTz3l6XZjmX+Y27waxcnf07keCycr+CDmm1eCahCcsCJzcb7S5 nk8RDSGsiFp1g/zd0Tg6uiBu5KTf6VrQ+pqh6zK/4w0+7o7m9ZQ8eZvCKue6DqyNNHLg SuDDp9gBMEdlUeVcFBsnEObTxSEeGuQLHmSw6kFDLPJn/E22FmqCeWsQ9X3jcNs2ypyl vTK6zmfbOj7JN4GcJhQE/6SXkRtWNqxC+/UXrVi57j1FAo8/+MMwlJGxO/7USOpYwgwb UnlhosIcYejFhu+Pp6JoYO4srLa+BK6OaQIYrg90/1SpSbRerHVH3zWAZHMJx1pC0heN 0srw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19095-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t22-20020a170906609600b00a28c1b1e239si2839209ejj.880.2024.01.07.22.18.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 22:18:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19095-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19095-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 598CA1F216D7 for ; Mon, 8 Jan 2024 06:18:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB2667497; Mon, 8 Jan 2024 06:18:40 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 A018079C2; Mon, 8 Jan 2024 06:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a28d61ba65eso141977066b.3; Sun, 07 Jan 2024 22:18:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704694717; x=1705299517; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JxKWZ0iFvolfQySmIZiVviFxg2q/+Ns/Cenq1wSZJho=; b=gdxQB2+Q9VoolFW97n58rOvf38dqBjg6aKqWFWSS517gmtfbDvacYCLLqcjgT1a9J6 R4jOeUCh4CZVeFTU7Ve8wWnAytzv6Xy1yVCaSoTYdAOFX8MxkzFtMLVK+Yxw9oVDzuNF Q54f6w4JqwjAp2mhFFPde8nlYM/jdQpBO3gDKmpe+J1tPFI6MpJGnOo4mu2WLyCs2SVJ SHdoy6o6YVoI0r2wKro+onQzjxLYG+QNCspHA/qblf5/VbC4bXyjrkku0d3N5K4HnQV/ F+w0GmH2w7nrCKiZJA8MN5J7lR+5k6eWDFRuEvLMtjnwvjWhe2sWviLkpwAJUw2mCYIS 49fg== X-Gm-Message-State: AOJu0YySFNvM1QFFAetVw/LG/MYCK0LlnQsy6cyvHCoRoPFV9GROsBaB xQE9123Qmfs3CgF8Lffdal4= X-Received: by 2002:a17:906:4f:b0:a28:aa08:200b with SMTP id 15-20020a170906004f00b00a28aa08200bmr744741ejg.140.1704694712800; Sun, 07 Jan 2024 22:18:32 -0800 (PST) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:59? ([2a0b:e7c0:0:107::aaaa:59]) by smtp.gmail.com with ESMTPSA id d11-20020a170906640b00b00a26f1f36708sm3624821ejm.78.2024.01.07.22.18.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 07 Jan 2024 22:18:32 -0800 (PST) Message-ID: <5ff1d706-9f06-4eb6-bc86-75f933e54118@kernel.org> Date: Mon, 8 Jan 2024 07:18:31 +0100 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 v4 3/3] w1: add UART w1 bus driver Content-Language: en-US To: cj.winklhofer@gmail.com, Krzysztof Kozlowski , Rob Herring , Conor Dooley , Rob Herring , Greg Kroah-Hartman , Krzysztof Kozlowski , Jonathan Corbet Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-doc@vger.kernel.org References: <20240106-w1-uart-v4-0-7fe1378a8b3e@gmail.com> <20240106-w1-uart-v4-3-7fe1378a8b3e@gmail.com> From: Jiri Slaby Autocrypt: addr=jirislaby@kernel.org; keydata= xsFNBE6S54YBEACzzjLwDUbU5elY4GTg/NdotjA0jyyJtYI86wdKraekbNE0bC4zV+ryvH4j rrcDwGs6tFVrAHvdHeIdI07s1iIx5R/ndcHwt4fvI8CL5PzPmn5J+h0WERR5rFprRh6axhOk rSD5CwQl19fm4AJCS6A9GJtOoiLpWn2/IbogPc71jQVrupZYYx51rAaHZ0D2KYK/uhfc6neJ i0WqPlbtIlIrpvWxckucNu6ZwXjFY0f3qIRg3Vqh5QxPkojGsq9tXVFVLEkSVz6FoqCHrUTx wr+aw6qqQVgvT/McQtsI0S66uIkQjzPUrgAEtWUv76rM4ekqL9stHyvTGw0Fj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PHgAwW35rpnq4f/EYTykbk1sa13Tav6btJ+4QOgbcezWI wZ5w/JVfEJW9JXp3BFAVzRQ5nVrrLDAJZ8Y5ioWcm99JtSIIxXxt9FJaGc1Bgsi5K/+dyTKL wLMJgiBzbVx8G+fCJJ9YtlNOPWhbKPlrQ8+AY52Aagi9WNhe6XfJdh5g6ptiOILm330mkR4g W6nEgZVyIyTq3ekOuruftWL99qpP5zi+eNrMmLRQx9iecDNgFr342R9bTDlb1TLuRb+/tJ98 f/bIWIr0cqQmqQ33FgRhrG1+Xml6UXyJ2jExmlO8JljuOGeXYh6ZkIEyzqzffzBLXZCujlYQ DFXpyMNVJ2ZwPmX2mWEoYuaBU0JN7wM+/zWgOf2zRwhEuD3A2cO2PxoiIfyUEfB9SSmffaK/ S4xXoB6wvGENZ85Hg37C7WDNdaAt6Xh2uQIly5grkgvWppkNy4ZHxE+jeNsU7tg= In-Reply-To: <20240106-w1-uart-v4-3-7fe1378a8b3e@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 06. 01. 24, 17:02, Christoph Winklhofer via B4 Relay wrote: > From: Christoph Winklhofer > > Add a UART 1-Wire bus driver. The driver utilizes the UART interface via > the Serial Device Bus to create the 1-Wire timing patterns. The driver > was tested on a "Raspberry Pi 3B" with a DS18B20 and on a "Variscite > DART-6UL" with a DS18S20 temperature sensor. > > The 1-Wire timing pattern and the corresponding UART baud-rate with the > interpretation of the transferred bytes are described in the document: > > Link: https://www.analog.com/en/technical-articles/using-a-uart-to-implement-a-1wire-bus-master.html > > In short, the UART peripheral must support full-duplex and operate in > open-drain mode. The timing patterns are generated by a specific > combination of baud-rate and transmitted byte, which corresponds to a > 1-Wire read bit, write bit or reset. ... > --- /dev/null > +++ b/drivers/w1/masters/w1-uart.c > @@ -0,0 +1,398 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * w1-uart - UART 1-Wire bus driver > + * > + * Uses the UART interface (via Serial Device Bus) to create the 1-Wire > + * timing patterns. Implements the following 1-Wire master interface: > + * > + * - reset_bus: requests baud-rate 9600 > + * > + * - touch_bit: requests baud-rate 115200 > + * > + * Author: Christoph Winklhofer > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define W1_UART_TIMEOUT msecs_to_jiffies(500) > + > +/* > + * struct w1_uart_config - configuration for 1-Wire operation > + * > + * @baudrate: baud-rate returned from serdev > + * @delay_us: delay to complete a 1-Wire cycle (in us) > + * @tx_byte: byte to generate 1-Wire timing pattern > + */ > +struct w1_uart_config { > + unsigned int baudrate; > + unsigned int delay_us; > + unsigned char tx_byte; If it is a "byte", it should be u8. > +}; > + > +struct w1_uart_device { > + struct serdev_device *serdev; > + struct w1_bus_master bus; > + > + struct w1_uart_config cfg_reset; > + struct w1_uart_config cfg_touch_0; > + struct w1_uart_config cfg_touch_1; > + > + struct completion rx_byte_received; > + unsigned char rx_byte; The same here. > + int rx_err; > + > + struct mutex mutex; > +}; > + > +/* > + * struct w1_uart_limits - limits for 1-Wire operations > + * > + * @baudrate: Requested baud-rate to create 1-Wire timing pattern > + * @bit_min_us: minimum time for a bit (in us) > + * @bit_max_us: maximum time for a bit (in us) > + * @sample_us: timespan to sample 1-Wire response > + * @cycle_us: duration of the 1-Wire cycle > + */ > +struct w1_uart_limits { > + unsigned int baudrate; > + unsigned int bit_min_us; > + unsigned int bit_max_us; > + unsigned int sample_us; > + unsigned int cycle_us; > +}; > + > +static inline unsigned int baud_to_bit_ns(unsigned int baud) > +{ > + return 1000000000 / baud; NSEC_PER_SEC > +} > + > +static inline unsigned int to_ns(unsigned int us) > +{ > + return us * 1000; NSEC_PER_USEC > +} > + > +/* > + * Set baud-rate, delay and tx-byte to create a 1-Wire pulse and adapt > + * the tx-byte according to the actual baud-rate. > + * > + * Reject when: > + * - time for a bit outside min/max range > + * - a 1-Wire response is not detectable for sent byte > + */ > +static int w1_uart_set_config(struct serdev_device *serdev, > + const struct w1_uart_limits *limits, > + struct w1_uart_config *w1cfg) > +{ > + unsigned int bits_low; > + unsigned int bit_ns; > + unsigned int low_ns; > + > + w1cfg->baudrate = serdev_device_set_baudrate(serdev, limits->baudrate); > + if (w1cfg->baudrate == 0) > + return -EINVAL; > + > + /* Compute in nanoseconds for accuracy */ > + bit_ns = baud_to_bit_ns(w1cfg->baudrate); > + bits_low = to_ns(limits->bit_min_us) / bit_ns; > + /* start bit is always low */ > + low_ns = bit_ns * (bits_low + 1); > + > + if (low_ns < to_ns(limits->bit_min_us)) > + return -EINVAL; > + > + if (low_ns > to_ns(limits->bit_max_us)) > + return -EINVAL; > + > + /* 1-Wire response detectable for sent byte */ > + if (limits->sample_us > 0 && > + bit_ns * 8 < low_ns + to_ns(limits->sample_us)) BITS_PER_BYTE > + return -EINVAL; > + > + /* delay to complete 1-Wire cycle, include start and stop-bit */ > + w1cfg->delay_us = 0; > + if (bit_ns * 10 < to_ns(limits->cycle_us)) What is this 10? Dub it. > + w1cfg->delay_us = > + (to_ns(limits->cycle_us) - bit_ns * 10) / 1000; And this 10? The end: / NSEC_PER_USEC > + > + /* byte to create 1-Wire pulse */ > + w1cfg->tx_byte = 0xff << bits_low; > + > + return 0; > +} ... > +static int w1_uart_serdev_tx_rx(struct w1_uart_device *w1dev, > + const struct w1_uart_config *w1cfg, > + unsigned char *rx_byte) u8 * > +{ ... > +} > + > +static int w1_uart_serdev_receive_buf(struct serdev_device *serdev, > + const unsigned char *buf, size_t count) serdev already uses u8 * here. You are basing on the top of some old tree. regards, -- js suse labs