From nobody Thu Dec 18 19:43:31 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 AA3C5C77B61 for ; Mon, 1 May 2023 17:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232574AbjEARSL (ORCPT ); Mon, 1 May 2023 13:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231467AbjEARSF (ORCPT ); Mon, 1 May 2023 13:18:05 -0400 Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46DD81727; Mon, 1 May 2023 10:17:27 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id E46321285; Mon, 1 May 2023 19:01:43 +0200 (CEST) Authentication-Results: ext-mx-out002.mykolab.com (amavisd-new); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:date:subject:subject:from:from :received:received:received; s=dkim20160331; t=1682960501; x= 1684774902; bh=xTUiam1mNVkvBIOCFygEjOsaIx+Hp4y9WTKziIxXGUc=; b=m yEJZQ7ojeN7+Viyk+MZVj/6XgzMi9jxP7nDfirgh5lG8lIqRj/NnbQdRrWRj6hqf DRqRzjwazIQHU2RbU174pynb2qnZr+Vx2jB5HJE3Ln/ozJOqFtQDA268VAU/7pgW 5EezQAZ5TvDyC+jGJVyjt1k5PXelW9eLkrr7zI9h/2OT583hOm/QHRiHFYOf1t3O 4n6RzDqqGz+AdYcaQUTi4eOAixyXZ7iL2yFwPVn5OxiBJ0ZnzhrjvuFhNIBFE9iq UsTWQCJAHf4z/38f+m8nTAKmCXecbg6K9Z81zRa+evPV+2rXBGckC7bE7PeEYOnf QOBML6e3ueH9Xrv1P1a+ajo3+hV4xtdEWosZWB5ZyjHXWBfdVvXP/eI3a6WOl/kT b1b4/27Zc9ZXxdNYPtVYkPVMj1xKzZ/0Ym5YRqG+f88+JbhdlXeGBQAAJmmISvfe QpKOQvXxWkoH5YfBYfqgX5+4jnwrILUlKx2jBVCS9eFeSMbsdNPebOzINXlg/V4F 5mR9SSscTVcRTyy3Ao1C0IzzzPSltYhGXEkmr4Xk45OVZXsHoY/gVZIY/e+NuDDd FqRk0RTmoV/k6FWI/E23RVo+nvtrgFb83ThQaqAhO0sHIO61l3v8N2rqOfURwEFw E5a7yTNiEU4H+t+kaN4AYRtiN9frDeDv8bARl/Dk4E= X-Virus-Scanned: amavisd-new at mykolab.com Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out002.mykolab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IPjw4Y3ilWCT; Mon, 1 May 2023 19:01:41 +0200 (CEST) Received: from int-mx002.mykolab.com (unknown [10.9.13.2]) by mx.kolabnow.com (Postfix) with ESMTPS id 12A28E4A; Mon, 1 May 2023 19:01:40 +0200 (CEST) Received: from ext-subm001.mykolab.com (unknown [10.9.6.1]) by int-mx002.mykolab.com (Postfix) with ESMTPS id 7DCE175AF; Mon, 1 May 2023 19:01:40 +0200 (CEST) From: alison@she-devel.com To: johan@kernel.org Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alison@she-devel.com, achaiken@aurora.tech Subject: [PATCH 1/2] gnss: ubx: customize serial device open to set U-Blox Zed-F9P baud Date: Mon, 1 May 2023 10:01:23 -0700 Message-Id: <20230501170124.1218603-2-alison@she-devel.com> In-Reply-To: <20230501170124.1218603-1-alison@she-devel.com> References: <20230501170124.1218603-1-alison@she-devel.com> MIME-Version: 1.0 Organization: Aurora Innovation 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: Alison Chaiken Add support for setting the baud rate of U-Blox Zed-F9P GNSS devices. Provide functions that support writing of arbitrary configuration messages to the device plus one that specifically configures the baud rate. Override the default gnss_serial_open() with a new method that writes the configuration message to the GNSS if the devicetree declares it to be a Zed F9P and requests a non-default baud. Add a boolean flag to the ubx_data private data of the GNSS driver in order to track whether the configuration message has already been written. Set the Zed F9P to its default port speed if the devicetree does not specify a value. Signed-off-by: Alison Chaiken Reported-by: kernel test robot --- drivers/gnss/ubx.c | 195 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c index c951be202ca2..1d59a11f5360 100644 --- a/drivers/gnss/ubx.c +++ b/drivers/gnss/ubx.c @@ -9,18 +9,201 @@ #include #include #include +#include #include #include +#include +#include #include #include =20 #include "serial.h" =20 +/* Total configuration message length =3D PREAMBLE_LEN + MESSAGE_CLASS_LEN= + + * MESSAGE_LENGTH_LEN + payload length + CHECKSUM_LEN + */ +const int32_t PREAMBLE_LEN =3D 2; +const int32_t MESSAGE_CLASS_LEN =3D 2; +const int32_t MESSAGE_LENGTH_LEN =3D 2; +const int32_t CHECKSUM_LEN =3D 2; +const size_t FIRST_CONFIG_REGISTER_BYTE =3D 10U; +const size_t FIRST_VALUE_BYTE =3D 14U; +const size_t FIRST_CHECKSUM_BYTE =3D 18U; +const size_t CFG_MSG_TOTAL_LEN =3D 20U; + +uint8_t ZED_F9P_CFG_VALSET_MSG[] =3D { + 0xB5, 0x62, /* 0-1 preamble */ + 0x06, 0x8A, /* 2-3 CFG_VALSET command */ + 0x0C, 0x00, /* 4-5 payload length =3D 12 for one key-value pair */ + 0x00, /* 6 U-Blox API version */ + 0x01, /* 7 Write to RAM */ + 0x00, 0x00, /* 8-9 Reserved */ + 0x00, 0x00, 0x00, 0x00, /* 10-13 Placeholder for configuration register */ + 0x00, 0x00, 0x00, 0x00, /* 14-17 Placeholder for baud value */ + 0x00, 0x00 /* 18-19 Placeholder for checksum */ +}; + +const speed_t ZED_F9P_MIN_BAUD =3D 9600; +const speed_t ZED_F9P_DEFAULT_BAUD =3D 38400; +const speed_t ZED_F9P_MAX_BAUD =3D 921600; +const uint32_t ZED_F9P_BAUD_CONFIG_REGISTER =3D 0x40520001; + struct ubx_data { struct regulator *v_bckp; struct regulator *vcc; + unsigned long is_configured; +}; + +union message_length { + uint16_t ml; + uint8_t bytes[2]; +}; + +union int_to_bytes { + uint32_t int_val; + uint8_t bytes[4]; }; =20 +/* Payload length is contained in bytes 0-2 after message class and ID. + * While the checksum includes the Message class and ID plus message leng= th, the + * payload does not. + */ +static uint16_t get_payload_length(const uint8_t msg[]) +{ + union message_length hs_msg_len; + + hs_msg_len.bytes[0] =3D msg[PREAMBLE_LEN + MESSAGE_CLASS_LEN]; + hs_msg_len.bytes[1] =3D msg[PREAMBLE_LEN + MESSAGE_CLASS_LEN + 1U]; + return hs_msg_len.ml; +} + +static int32_t get_msg_total_len(const uint8_t msg[]) +{ + const size_t payload_len =3D get_payload_length(msg); + + return PREAMBLE_LEN + MESSAGE_CLASS_LEN + MESSAGE_LENGTH_LEN + payload_len + + CHECKSUM_LEN; +} + +/* The checksum is calculated on message class, message ID, message length= and + * payload. + */ +static void calc_ubx_checksum(const uint8_t msg[], uint8_t checksum[], + const uint16_t total_len) +{ + uint8_t CK_A =3D 0; + uint8_t CK_B =3D 0; + int i; + + for (i =3D PREAMBLE_LEN; i < (total_len - CHECKSUM_LEN); i++) { + CK_A +=3D msg[i]; + CK_B +=3D CK_A; + } + checksum[0] =3D CK_A; + checksum[1] =3D CK_B; +} + +static uint32_t check_baud(speed_t speed, const struct device *dev) +{ + if ((speed < ZED_F9P_MIN_BAUD) || (speed > ZED_F9P_MAX_BAUD)) { + dev_warn(dev, "Baud rate specification %d out of range\n", speed); + speed =3D ZED_F9P_DEFAULT_BAUD; + } + return speed; +} + +static int prepare_zedf9p_config_msg(const speed_t speed, + const struct device *dev, const size_t msg_register) +{ + union int_to_bytes cfg_val, cfg_register; + int i =3D 0; + uint8_t checksum[2]; + const size_t total_len =3D get_msg_total_len(ZED_F9P_CFG_VALSET_MSG); + + if (total_len !=3D CFG_MSG_TOTAL_LEN) + goto bad_msg; + + cfg_val.int_val =3D check_baud(speed, dev); + cfg_register.int_val =3D msg_register; + for (i =3D 0; i < 4; i++) { + ZED_F9P_CFG_VALSET_MSG[FIRST_VALUE_BYTE + i] =3D cfg_val.bytes[i]; + ZED_F9P_CFG_VALSET_MSG[FIRST_CONFIG_REGISTER_BYTE + i] =3D cfg_register.= bytes[i]; + } + calc_ubx_checksum(ZED_F9P_CFG_VALSET_MSG, checksum, total_len); + ZED_F9P_CFG_VALSET_MSG[FIRST_CHECKSUM_BYTE] =3D checksum[0]; + ZED_F9P_CFG_VALSET_MSG[FIRST_CHECKSUM_BYTE + 1U] =3D checksum[1]; + return 0; + + bad_msg: + dev_err(dev, "Malformed UBX-CFG-VALSET message\n"); + return -EINVAL; +} + +/* Configure the Zed F9P baud rate via the UBX-CFG-VALSET message. */ +static int set_zedf9p_baud(struct gnss_device *gdev, + struct serdev_device *serdev, const speed_t speed) +{ + size_t count =3D 0U; + int ret; + + if (speed =3D=3D ZED_F9P_DEFAULT_BAUD) + return 0; + + ret =3D prepare_zedf9p_config_msg(speed, &gdev->dev, ZED_F9P_BAUD_CONFIG_= REGISTER); + if (ret) + return ret; + /* Initially set the UART to the default speed to match the GNSS' power-o= n value. */ + serdev_device_set_baudrate(serdev, ZED_F9P_DEFAULT_BAUD); + /* Now set the new baud rate. */ + count =3D gdev->ops->write_raw(gdev, ZED_F9P_CFG_VALSET_MSG, CFG_MSG_TOTA= L_LEN); + if (count !=3D CFG_MSG_TOTAL_LEN) + return count; + + return 0; +} + +static int ubx_serial_open(struct gnss_device *gdev) +{ + struct gnss_serial *gserial =3D gnss_get_drvdata(gdev); + struct serdev_device *serdev =3D gserial->serdev; + struct ubx_data *data =3D gnss_serial_get_drvdata(gserial); + struct device_node *np; + int ret; + + ret =3D serdev_device_open(serdev); + if (ret) + return ret; + + serdev_device_set_flow_control(serdev, false); + + np =3D serdev->dev.of_node; + if ((of_device_is_compatible(np, "u-blox,zed-f9p")) && (!data->is_configu= red)) { + /* 4800 is the default value set by gnss_serial_parse_dt() */ + if (gserial->speed =3D=3D 4800) { + /* Fall back instead to Zed F9P default */ + gserial->speed =3D ZED_F9P_DEFAULT_BAUD; + } else { + ret =3D set_zedf9p_baud(gdev, serdev, gserial->speed); + if (ret) + return ret; + } + data->is_configured =3D 1; + } + serdev_device_set_baudrate(serdev, gserial->speed); + + ret =3D pm_runtime_get_sync(&serdev->dev); + if (ret < 0) { + pm_runtime_put_noidle(&serdev->dev); + goto err_close; + } + return 0; + +err_close: + serdev_device_close(serdev); + + return ret; +} + static int ubx_set_active(struct gnss_serial *gserial) { struct ubx_data *data =3D gnss_serial_get_drvdata(gserial); @@ -67,6 +250,7 @@ static int ubx_probe(struct serdev_device *serdev) { struct gnss_serial *gserial; struct ubx_data *data; + struct gnss_operations *ubx_gnss_ops; int ret; =20 gserial =3D gnss_serial_allocate(serdev, sizeof(*data)); @@ -74,12 +258,22 @@ static int ubx_probe(struct serdev_device *serdev) ret =3D PTR_ERR(gserial); return ret; } + ubx_gnss_ops =3D kzalloc(sizeof(struct gnss_operations), GFP_KERNEL); + if (IS_ERR(ubx_gnss_ops)) { + ret =3D PTR_ERR(ubx_gnss_ops); + return ret; + } =20 gserial->ops =3D &ubx_gserial_ops; =20 gserial->gdev->type =3D GNSS_TYPE_UBX; + ubx_gnss_ops->open =3D &ubx_serial_open; + ubx_gnss_ops->close =3D gserial->gdev->ops->close; + ubx_gnss_ops->write_raw =3D gserial->gdev->ops->write_raw; + gserial->gdev->ops =3D ubx_gnss_ops; =20 data =3D gnss_serial_get_drvdata(gserial); + data->is_configured =3D 0; =20 data->vcc =3D devm_regulator_get(&serdev->dev, "vcc"); if (IS_ERR(data->vcc)) { @@ -133,6 +327,7 @@ static const struct of_device_id ubx_of_match[] =3D { { .compatible =3D "u-blox,neo-6m" }, { .compatible =3D "u-blox,neo-8" }, { .compatible =3D "u-blox,neo-m8" }, + { .compatible =3D "u-blox,zed-f9p" }, {}, }; MODULE_DEVICE_TABLE(of, ubx_of_match); --=20 2.39.2 From nobody Thu Dec 18 19:43:31 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 B38BFC77B7C for ; Mon, 1 May 2023 17:17:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232199AbjEARR0 (ORCPT ); Mon, 1 May 2023 13:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232240AbjEARRR (ORCPT ); Mon, 1 May 2023 13:17:17 -0400 X-Greylist: delayed 499 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 01 May 2023 10:16:49 PDT Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.153]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 556C81727; Mon, 1 May 2023 10:16:49 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id 6265F4112C; Mon, 1 May 2023 19:01:47 +0200 (CEST) Authentication-Results: ext-mx-out003.mykolab.com (amavisd-new); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:date:subject:subject:from:from :received:received:received; s=dkim20160331; t=1682960507; x= 1684774908; bh=IeHcnYGT8x5oIMpt7vaj6WJo5TzDUMMrc5PAh+gHWeM=; b=g H8zMfSm/g4Vp9Qa85RFMbzfPxPx+R4NV1on17YilXuQiiQGfqIZWkSKNUwKO+YqT FhpFxfkmicdbWvzkkc7EUAowwYPOTtbnh5NMX7YPklUJy5JLsDj+qDrk/VO9YYlz S3M48OR3lJs4lDuG4PlXRDKVAnuFRFmifwnJzsGPyU381hjf6RXoL+4VqMS3+il+ fmJV7WM3pQMOZH1BiDXP6nuajOcueifbiNCYsbyblpzS73MQvPhhokN+af58u/4b AvT5a3AMfadV5pEw/8qdlqaUDF/zpWXxarnTXAnZGpYZej7Hk5OCJYCMuxpRBRT8 LGfJzNnDqZAEdxFD9LSbobpZYIhHSS0pQ2sihUJjZDN9oCvI36Tib8+npyyIylmV nuyUSHaew2SUkO9hoa9DUqTd0OqO6pI+sOBRuBRgUl5sEMIEA3qrTNbc9Skfk6SY dVEoEuiSjR/wTBenIYv/REfOuzR2mHRuXdgjs7sObLFGhH6PD+5XiqbxRhoLJVBG un1a/hb3x8rdEjp083QxjTtUT1iMa6wPRdxBvtcRVCypZWXJgqKxIe4LS7ET0xOb DFr7txNwKsi9w+lOOHBIQr2w20oVabKK/aQ+x4FY2x1XXbDoZMZ8aryCT4u8PPv/ dMSn8Ac10dD+peI+gU99uBTRJwWH+ognZdcZiVnW28= X-Virus-Scanned: amavisd-new at mykolab.com Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out003.mykolab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id td_WHPxP5L4p; Mon, 1 May 2023 19:01:47 +0200 (CEST) Received: from int-mx002.mykolab.com (unknown [10.9.13.2]) by mx.kolabnow.com (Postfix) with ESMTPS id C531F41869; Mon, 1 May 2023 19:01:46 +0200 (CEST) Received: from ext-subm001.mykolab.com (unknown [10.9.6.1]) by int-mx002.mykolab.com (Postfix) with ESMTPS id 68A3875AD; Mon, 1 May 2023 19:01:46 +0200 (CEST) From: alison@she-devel.com To: johan@kernel.org Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, alison@she-devel.com, achaiken@aurora.tech Subject: [PATCH 2/2] dt-bindings: gnss: Add U-Blox Zed-F9 Date: Mon, 1 May 2023 10:01:24 -0700 Message-Id: <20230501170124.1218603-3-alison@she-devel.com> In-Reply-To: <20230501170124.1218603-1-alison@she-devel.com> References: <20230501170124.1218603-1-alison@she-devel.com> MIME-Version: 1.0 Organization: Aurora Innovation 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: Alison Chaiken Add support for the U-Blox Zed-F9P GNSS device. Signed-off-by: Alison Chaiken Acked-by: Rob Herring Reported-by: kernel test robot --- Documentation/devicetree/bindings/gnss/u-blox,neo-6m.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/gnss/u-blox,neo-6m.yaml b/Do= cumentation/devicetree/bindings/gnss/u-blox,neo-6m.yaml index 4835a280b3bf..86b65d4d9266 100644 --- a/Documentation/devicetree/bindings/gnss/u-blox,neo-6m.yaml +++ b/Documentation/devicetree/bindings/gnss/u-blox,neo-6m.yaml @@ -21,6 +21,7 @@ properties: - u-blox,neo-6m - u-blox,neo-8 - u-blox,neo-m8 + - u-blox,zed-f9p =20 reg: description: > --=20 2.39.2