Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp343872imn; Thu, 28 Jul 2022 02:20:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tGOnLujMXxw7rikDVnFmBNXyPxGPLAaZNfi+v4/7LQtWfIs/thCjZo/HveMHjVzwldkhCr X-Received: by 2002:a05:6402:4390:b0:43b:e9d9:f9e4 with SMTP id o16-20020a056402439000b0043be9d9f9e4mr21442896edc.361.1659000041225; Thu, 28 Jul 2022 02:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659000041; cv=none; d=google.com; s=arc-20160816; b=oordvb/vgHPmYcyru1BFsUFFfSJ+oRqayEC2rMGvLqid0XRQoRfTG0OjmmtUWMwfG7 uXfS7IRAyZxrU7ITOR/ffwqGnuiP4JIE5kVVs66ybq/ExlZEQ1wvInTg6hpmwAedostY Kq89TPWoUDqy9TkCFaefm6mei6RRG848JUirWP7HY3WBGSUNxm2kkw9m99WIwtLqBHdH ynRj1JA71jCgORoAYNZGmLXovYjS/JK7K/NYDYklRSr96tZs5sohXqXU30wVNc3TIE34 Erl54KcC5iQfN7wY23kR/mee9nCEwLs7O2c64mx1ImFiWex1QClOIyyIzyqJEi7RUAIY HvQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=aGsV1lS1+Os98QUPUuUUU6QXrDGuwm2rUWp9UObtIUI=; b=iWHTR9PAzv+IVVCq88vuTlmZ41V4hUmMWLf/gquG7+fOCC1b8PptHCO96ec6NpG/qb 7XIL3tBYcJhwp7I4CWhFbc9RqSlJeRKpf3Wgqu8YKimeqOTosGBPoQMDR9I7MmKW6Ev1 G7Pd3qk4E3F4UMGP4mj5SGpDbYtnmjee7uu1COkJ9tG12245yKBaaxlUpSHBaVVQgkAL CN/jRWlDnDHwRY/me3O5Q/MJEXjUVCibFEi57hE+NJzg6yaQhWpvPtwtveNy+D7hqKl6 xWxIJvg9Aj5YP5IJI1CarZ70Njwtz1BpoEJ1YGXADF4RLqz4s7fv3w+HFkwre98/W0Hb 34nA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h25-20020a170906719900b00722f8c55e6csi230380ejk.817.2022.07.28.02.20.15; Thu, 28 Jul 2022 02:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235355AbiG1JCq (ORCPT + 99 others); Thu, 28 Jul 2022 05:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235350AbiG1JCo (ORCPT ); Thu, 28 Jul 2022 05:02:44 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CE7B6566C for ; Thu, 28 Jul 2022 02:02:43 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oGzPc-0004ja-6B; Thu, 28 Jul 2022 11:02:32 +0200 Received: from pengutronix.de (unknown [IPv6:2a01:4f8:1c1c:29e9:22:41ff:fe00:1400]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id C4EBBBCB24; Thu, 28 Jul 2022 09:02:29 +0000 (UTC) Date: Thu, 28 Jul 2022 11:02:28 +0200 From: Marc Kleine-Budde To: Dario Binacchi Cc: Max Staudt , linux-kernel@vger.kernel.org, linux-can@vger.kernel.org, Oliver Hartkopp , michael@amarulasolutions.com, Amarula patchwork , Jeroen Hofstee , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wolfgang Grandegger , netdev@vger.kernel.org Subject: Re: [RFC PATCH v3 8/9] can: slcan: add support to set bit time register (btr) Message-ID: <20220728090228.nckgpmfe7rpnfcyr@pengutronix.de> References: <20220726210217.3368497-1-dario.binacchi@amarulasolutions.com> <20220726210217.3368497-9-dario.binacchi@amarulasolutions.com> <20220727113054.ffcckzlcipcxer2c@pengutronix.de> <20220727192839.707a3453.max@enpas.org> <20220727182414.3mysdeam7mtnqyfx@pengutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="5tukwidie4thhway" Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --5tukwidie4thhway Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 28.07.2022 09:36:21, Dario Binacchi wrote: > > Most of the other CAN drivers write the BTR values into the register of > > the hardware. How are these BTR values transported into the driver? > > > > There are 2 ways: > > > > 1) - user space configures a bitrate > > - the kernel calculates with the "struct can_bittiming_const" [1] gi= ven > > by driver and the CAN clock rate the low level timing parameters. > > > > [1] https://elixir.bootlin.com/linux/v5.18/source/include/uapi/lin= ux/can/netlink.h#L47 > > > > 2) - user space configures low level bit timing parameter > > (Sample point in one-tenth of a percent, Time quanta (TQ) in > > nanoseconds, Propagation segment in TQs, Phase buffer segment 1 in > > TQs, Phase buffer segment 2 in TQs, Synchronisation jump width in > > TQs) > > - the kernel calculates the Bit-rate prescaler from the given TQ and > > CAN clock rate > > > > Both ways result in a fully calculated "struct can_bittiming" [2]. The > > driver translates this into the hardware specific BTR values and writes > > the into the registers. > > > > If you know the CAN clock and the bit timing const parameters of the > > slcan's BTR register you can make use of the automatic BTR calculation, > > too. Maybe the framework needs some tweaking if the driver supports both > > fixed CAN bit rate _and_ "struct can_bittiming_const". >=20 > Does it make sense to use the device tree The driver doesn't support DT and DT only works for static serial interfaces. > to provide the driver with those > parameters required for the automatic calculation of the BTR (clock rate, > struct can_bittiming_const, ...) that depend on the connected > controller? The device tree usually says it's a CAN controller compatible to X and the following clock(s) are connected. The driver for CAN controller X knows the bit timing const. Some USB CAN drivers query the bit timing const from the USB device. > In this way the solution should be generic and therefore scalable. I > think we should also add some properties to map the calculated BTR > value on the physical register of the controller. The driver knows how to map the "struct can_bittiming" to the BTR register values of the hardware. What does the serial protocol say to the BTR values? Are these standard SJA1000 layout with 8 MHz CAN clock or are those adapter specific? > Or, use the device tree to extend the bittates supported by the controller > to the fixed ones (struct can_priv::bitrate_const)? The serial protocol defines fixed bit rates, no need to describe them in the DT: | 0 10 Kbit/s | 1 20 Kbit/s | 2 50 Kbit/s | 3 100 Kbit/s | 4 125 Kbit/s | 5 250 Kbit/s | 6 500 Kbit/s | 7 800 Kbit/s | 8 1000 Kbit/s Are there more bit rates? regards, Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | --5tukwidie4thhway Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEBsvAIBsPu6mG7thcrX5LkNig010FAmLiUKEACgkQrX5LkNig 0117QggAjrRUz25+oJjtGLVN5SEFPDVNMFeaVARhoxHZX/v7IfAyQpAT/HjiT/Sx 5YyBaN98+KS86zMu5qjHrdlhjqbIH+uOYdN/y42hEhiRXGkOSnC2l8cKuuYowOgO U9QfZrOIFv4pfstQ+yRRSNG30wGUezJtISk1U+TkYaxwFcihU1SIMm9p1hhofjQJ iIPc41SbKRzgTtzyAjBS0d2Ti6gXKv4k7vCVfjgEM5ai/jRcIvlqf5xvEmhxfP2I tqabd4hSh8rDZe1I9eaNrpOslOVx1bWW6Vycycoq8oN1QcNkng1BHvF/xFctmfoN MKZ/u90EzFCwX/H2Ndc/dsrm2RnN6g== =+ALT -----END PGP SIGNATURE----- --5tukwidie4thhway--