From patchwork Wed Dec 19 15:56:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ben Whitten X-Patchwork-Id: 10737537 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE28814DE for ; Wed, 19 Dec 2018 15:56:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA1DE2B48D for ; Wed, 19 Dec 2018 15:56:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A09D2B554; Wed, 19 Dec 2018 15:56:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EDB012B48D for ; Wed, 19 Dec 2018 15:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tV0ydjFXY+08IeuvU6JIFD66bBL6DB93tOX0YHn9Ek4=; b=N73p3WV+CKq3a8 dp3FogbwsNxrQpRZ7YDd1sy36YkEyZ4EYhNcS/95voAIVCDIe8hqF1vpljrG2mkQLngS8vE3JkdMD d5yEVhyohKpgD62+xfiUEoEoYUZOiphfpT2aT1pZ2rbKAdvqR/3FxXk+EmBb/oRVQevGRroTRzVOa ymRxBz1hoNpLjXqyVzk8SsUUlTLJhPGceVwqAOF7Iaik4txdnbIi8wCBFWP/cB9N4bkkUb6L+JTS4 WrFa5drXEjDJKq9SQUptl8QH5MRMg1vyX9sQxU8+8hLrRO5bYzKUGZhp/4XAo5sEEYlDmEJTRgoDU oo7Xesjl7yOWdQF/9kiQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeDP-0005f3-KI; Wed, 19 Dec 2018 15:56:55 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeD8-0005Ng-Lb; Wed, 19 Dec 2018 15:56:40 +0000 Received: by mail-wr1-x441.google.com with SMTP id c14so20065056wrr.0; Wed, 19 Dec 2018 07:56:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i25TBhQL7o6CHJnnqUQpts9IplaeJoYk7okEUv8SLCY=; b=cd/5I+wvqr4dRJG8VPC/swkl7I15HMcU7aC7EHf51CGe6xhnShdzhGUCp7d3vxDjJK AEpnk8ff7bElUFzsO0z4sQhWHCcxdWUnC/DwfWqkx1ZvP3/Sx5SRVi0oqNUXg7+8Ffae 3itgb8oOqv3qAPSUU0U4BG5lun+hwaITnhTx4OxHlGwBUxO11bEnbDTgGj5kq/O6PJZg 389Ljn8JTCWhQ+mOpyj7IJoESv5ZBeqIDGcAB6+yfsGHjuKl49yXx8OObnWolzI3XjAm l0sr9W4NHhG6WUSCoWLaASjblV2zMMcSaNNxhw4LejCYJEOIsPyc8Z+5euEfD2ivs4CM d8tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=i25TBhQL7o6CHJnnqUQpts9IplaeJoYk7okEUv8SLCY=; b=ZxbNxGKhiZ3YSn5pGarhAeU+5HiKpsm2BigC+VveIDEwHP3jdM811+FuIhhM86Tw4j Pmi/lF0UnGyQFJkq3yZmW1y+cRdCHsPjYElpyM9lkL9SsG/1HHQHA+Y7nAJrm9Ii0q+m vdzG7Ro6CO/ggn6cWF8l5kMogYSGq4RLImbwxYNrsJd0qk8V3FmLU9E/GaAPlSUFwMgU RZtmcrh2ZFQ5Z9+mDewxj7x7ZPftyA8hqp9W9+DgBx0O2gP8Z6ReL5Q4lr40aSrxIEUn ZxQTZEnCpDm56ymFg0BtC7BJNfycJE4scDt4FzP7XVwCsy3octVoLPtropK4XB4RR587 gfuA== X-Gm-Message-State: AA+aEWZxeY10Oiu6NKmIxlehq8W4C7KrePspxjvjCJLP8qjYg7DtTd1e YH6IttfFIvXqA5eW+Hy7294= X-Google-Smtp-Source: AFSGD/XJldM8wQzQKmgztzLgvYW6XD6F6f9rBcFdXRm/4FebNLhJ0nN7qoNCfqSk2sluqmiPwI2/mQ== X-Received: by 2002:a5d:5409:: with SMTP id g9mr19569977wrv.88.1545234986687; Wed, 19 Dec 2018 07:56:26 -0800 (PST) Received: from Sarah.corp.lairdtech.com ([109.174.151.67]) by smtp.gmail.com with ESMTPSA id c9sm6836099wmh.27.2018.12.19.07.56.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 07:56:25 -0800 (PST) From: Ben Whitten X-Google-Original-From: Ben Whitten To: starnight@g.ncu.edu.tw, jiri@resnulli.us, afaerber@suse.de Subject: [PATCH RFC lora-next 1/4] net: lora: sx125x sx1301: correct style warnings Date: Wed, 19 Dec 2018 15:56:13 +0000 Message-Id: <20181219155616.9547-2-ben.whitten@lairdtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181219155616.9547-1-ben.whitten@lairdtech.com> References: <20181219155616.9547-1-ben.whitten@lairdtech.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181219_075638_703770_E0A1F502 X-CRM114-Status: GOOD ( 15.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Whitten , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-lpwan@lists.infradead.org, "David S. Miller" , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Checkpatch highlights some style issues which need to be addressed. Signed-off-by: Ben Whitten --- drivers/net/lora/sx125x.c | 20 +++++++++------ drivers/net/lora/sx1301.c | 52 ++++++++++++++++++++++----------------- drivers/net/lora/sx1301.h | 7 +++--- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/drivers/net/lora/sx125x.c b/drivers/net/lora/sx125x.c index b7ca782b9386..1a941f663c52 100644 --- a/drivers/net/lora/sx125x.c +++ b/drivers/net/lora/sx125x.c @@ -49,7 +49,7 @@ struct sx125x_priv { struct device *dev; struct regmap *regmap; - struct regmap_field *regmap_fields[ARRAY_SIZE(sx125x_regmap_fields)]; + struct regmap_field *regmap_fields[ARRAY_SIZE(sx125x_regmap_fields)]; }; #define to_clkout(_hw) container_of(_hw, struct sx125x_priv, clkout_hw) @@ -67,13 +67,13 @@ static struct regmap_config __maybe_unused sx125x_regmap_config = { }; static int sx125x_field_write(struct sx125x_priv *priv, - enum sx125x_fields field_id, u8 val) + enum sx125x_fields field_id, u8 val) { return regmap_field_write(priv->regmap_fields[field_id], val); } static int sx125x_field_read(struct sx125x_priv *priv, - enum sx125x_fields field_id, unsigned int *val) + enum sx125x_fields field_id, unsigned int *val) { return regmap_field_read(priv->regmap_fields[field_id], val); } @@ -149,8 +149,12 @@ static int sx125x_register_clock_provider(struct sx125x_priv *priv) init.num_parents = 1; priv->clkout_hw.init = &init; - of_property_read_string_index(dev->of_node, "clock-output-names", 0, - &init.name); + ret = of_property_read_string_index(dev->of_node, "clock-output-names", + 0, &init.name); + if (ret) { + dev_err(dev, "unable to find output name\n"); + return ret; + } priv->clkout = devm_clk_register(dev, &priv->clkout_hw); if (IS_ERR(priv->clkout)) { @@ -158,7 +162,7 @@ static int sx125x_register_clock_provider(struct sx125x_priv *priv) return PTR_ERR(priv->clkout); } ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, - &priv->clkout_hw); + &priv->clkout_hw); return ret; } @@ -180,8 +184,8 @@ static int __maybe_unused sx125x_regmap_probe(struct device *dev, struct regmap const struct reg_field *reg_fields = sx125x_regmap_fields; priv->regmap_fields[i] = devm_regmap_field_alloc(dev, - priv->regmap, - reg_fields[i]); + priv->regmap, + reg_fields[i]); if (IS_ERR(priv->regmap_fields[i])) { ret = PTR_ERR(priv->regmap_fields[i]); dev_err(dev, "Cannot allocate regmap field: %d\n", ret); diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c index 23cbddc364e5..e75df93b96d8 100644 --- a/drivers/net/lora/sx1301.c +++ b/drivers/net/lora/sx1301.c @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-2.0-or-later -/* - * Semtech SX1301 LoRa concentrator +/* Semtech SX1301 LoRa concentrator * * Copyright (c) 2018 Andreas Färber * Copyright (c) 2018 Ben Whitten @@ -55,12 +54,13 @@ static struct regmap_config sx1301_regmap_config = { }; static int sx1301_field_write(struct sx1301_priv *priv, - enum sx1301_fields field_id, u8 val) + enum sx1301_fields field_id, u8 val) { return regmap_field_write(priv->regmap_fields[field_id], val); } -static int sx1301_agc_ram_read(struct sx1301_priv *priv, u8 addr, unsigned int *val) +static int sx1301_agc_ram_read(struct sx1301_priv *priv, u8 addr, + unsigned int *val) { int ret; @@ -79,7 +79,8 @@ static int sx1301_agc_ram_read(struct sx1301_priv *priv, u8 addr, unsigned int * return 0; } -static int sx1301_arb_ram_read(struct sx1301_priv *priv, u8 addr, unsigned int *val) +static int sx1301_arb_ram_read(struct sx1301_priv *priv, u8 addr, + unsigned int *val) { int ret; @@ -98,7 +99,8 @@ static int sx1301_arb_ram_read(struct sx1301_priv *priv, u8 addr, unsigned int * return 0; } -static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct firmware *fw) +static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, + const struct firmware *fw) { u8 *buf; enum sx1301_fields rst, select_mux; @@ -165,7 +167,8 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, const struct } if (memcmp(fw->data, buf, fw->size)) { - dev_err(priv->dev, "MCU prom data read does not match data written\n"); + dev_err(priv->dev, + "MCU prom data read does not match data written\n"); kfree(buf); return -ENXIO; } @@ -228,11 +231,12 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv) return ret; } - dev_info(priv->dev, "AGC calibration firmware version %u\n", (unsigned)val); + dev_info(priv->dev, "AGC calibration firmware version %u\n", val); if (val != SX1301_MCU_AGC_CAL_FW_VERSION) { - dev_err(priv->dev, "unexpected firmware version, expecting %u\n", - SX1301_MCU_AGC_CAL_FW_VERSION); + dev_err(priv->dev, + "unexpected firmware version, expecting %u\n", + SX1301_MCU_AGC_CAL_FW_VERSION); return -ENXIO; } @@ -257,7 +261,7 @@ static int sx1301_agc_calibrate(struct sx1301_priv *priv) return ret; } - dev_info(priv->dev, "AGC status: %02x\n", (unsigned)val); + dev_info(priv->dev, "AGC status: %02x\n", val); if ((val & (BIT(7) | BIT(0))) != (BIT(7) | BIT(0))) { dev_err(priv->dev, "AGC calibration failed\n"); return -ENXIO; @@ -328,11 +332,12 @@ static int sx1301_load_all_firmware(struct sx1301_priv *priv) return ret; } - dev_info(priv->dev, "AGC firmware version %u\n", (unsigned)val); + dev_info(priv->dev, "AGC firmware version %u\n", val); if (val != SX1301_MCU_AGC_FW_VERSION) { - dev_err(priv->dev, "unexpected firmware version, expecting %u\n", - SX1301_MCU_AGC_FW_VERSION); + dev_err(priv->dev, + "unexpected firmware version, expecting %u\n", + SX1301_MCU_AGC_FW_VERSION); return -ENXIO; } @@ -342,18 +347,20 @@ static int sx1301_load_all_firmware(struct sx1301_priv *priv) return ret; } - dev_info(priv->dev, "ARB firmware version %u\n", (unsigned)val); + dev_info(priv->dev, "ARB firmware version %u\n", val); if (val != SX1301_MCU_ARB_FW_VERSION) { - dev_err(priv->dev, "unexpected firmware version, expecting %u\n", - SX1301_MCU_ARB_FW_VERSION); + dev_err(priv->dev, + "unexpected firmware version, expecting %u\n", + SX1301_MCU_ARB_FW_VERSION); return -ENXIO; } return 0; } -static netdev_tx_t sx130x_loradev_start_xmit(struct sk_buff *skb, struct net_device *netdev) +static netdev_tx_t sx130x_loradev_start_xmit(struct sk_buff *skb, + struct net_device *netdev) { if (skb->protocol != htons(ETH_P_LORA)) { kfree_skb(skb); @@ -489,11 +496,12 @@ static int sx1301_probe(struct spi_device *spi) const struct reg_field *reg_fields = sx1301_regmap_fields; priv->regmap_fields[i] = devm_regmap_field_alloc(&spi->dev, - priv->regmap, - reg_fields[i]); + priv->regmap, + reg_fields[i]); if (IS_ERR(priv->regmap_fields[i])) { ret = PTR_ERR(priv->regmap_fields[i]); - dev_err(&spi->dev, "Cannot allocate regmap field: %d\n", ret); + dev_err(&spi->dev, + "Cannot allocate regmap field: %d\n", ret); return ret; } } @@ -553,7 +561,7 @@ static int sx1301_probe(struct spi_device *spi) return ret; } - msleep(5); + usleep_range(5000, 6000); ret = sx1301_field_write(priv, F_RADIO_RST, 0); if (ret) { diff --git a/drivers/net/lora/sx1301.h b/drivers/net/lora/sx1301.h index a1a2e388207e..dd2b7da94fcc 100644 --- a/drivers/net/lora/sx1301.h +++ b/drivers/net/lora/sx1301.h @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -/* - * Semtech SX1301 LoRa concentrator +/* Semtech SX1301 LoRa concentrator * * Copyright (c) 2018 Ben Whitten * Copyright (c) 2018 Andreas Färber @@ -34,7 +33,7 @@ #define SX1301_VIRT_BASE 0x100 #define SX1301_PAGE_LEN 0x80 -#define SX1301_PAGE_BASE(n) (SX1301_VIRT_BASE + (SX1301_PAGE_LEN * n)) +#define SX1301_PAGE_BASE(n) (SX1301_VIRT_BASE + (SX1301_PAGE_LEN * (n))) /* Page 0 */ #define SX1301_CHRS (SX1301_PAGE_BASE(0) + 0x23) @@ -112,7 +111,7 @@ struct sx1301_priv { struct clk *clk32m; struct gpio_desc *rst_gpio; struct regmap *regmap; - struct regmap_field *regmap_fields[ARRAY_SIZE(sx1301_regmap_fields)]; + struct regmap_field *regmap_fields[ARRAY_SIZE(sx1301_regmap_fields)]; }; int __init sx130x_radio_init(void); From patchwork Wed Dec 19 15:56:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Whitten X-Patchwork-Id: 10737539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE37713B5 for ; Wed, 19 Dec 2018 15:57:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C726E2B434 for ; Wed, 19 Dec 2018 15:57:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7DED2B48D; Wed, 19 Dec 2018 15:57:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 096792B434 for ; Wed, 19 Dec 2018 15:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Az7jggHIKlspATeHi1aG+jdmc6+jHn8iv320r3+rWlw=; b=JaO1xo3x6RWhMtn58g1UqbzjK4 CakxD1IMMrPSo/LjuWdXtMm3wm2SjFpvVTXQ+bc+/If+r+JxNYbrTWfdIoUgn4aaazXIXNXQNUEqe U7sopGrV7fdGi3NGyh53xlURcUERR9BOaK3g6t9HSttziobTPv8L1WGafKv410JYE/vn1+ckECkK9 1Wk1I4UqTlnqUKMva0RiE+IPM/aOmgGrJKwNn4OKJ2D3TFUdfWb7hErHLFM5THvnolzNVuPEdp6eD 7rCvMjODETs+N93hgcXYeIjUdvUWxzJw4WdMwvaXBhgA2Zl/VN+D4Oc1+zq/7IYEJhM31lIoy+3DC I5TylElg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeDd-0005rJ-8n; Wed, 19 Dec 2018 15:57:09 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeD9-0005Nj-TM; Wed, 19 Dec 2018 15:56:41 +0000 Received: by mail-wm1-x343.google.com with SMTP id r24so9856396wmh.0; Wed, 19 Dec 2018 07:56:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=vIMy8SmxnypKM4KjCpJRLf3oGe6ywU5lLEfE6JwZlBc=; b=NbxHH+Xm7V1QSsyhxEB1bZcoE4jO9rnk0VFdCA2QUnRBp02yvDbZk1rjBO3HqEzy8b 47yb6MgO71DCiyjWPcmfDK/C8yxb1nXUyxu9Gez+RX9L4ZF2AWvZqO5KtjauMzed+rtV j+nIytfcJxnyGQRDRdh9zGTcIceoi8+VBnivp638QwkwtmoJZvKYdGo/XGOIgVwJuSFO gp8QttOVJYQijTfT4KzuTKUmW8xuFQi6JoQWBucUT/ZiuJTvmFSkMunP4v1kFYenhwPs rDXTbcPIhZAYUmH0z2TCFxqoZOJXuBlzMItRYOD0NYawLBycq8KHnz1/mSrHRMzG9LwV zOwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=vIMy8SmxnypKM4KjCpJRLf3oGe6ywU5lLEfE6JwZlBc=; b=ErVtiu0jlRuJ5emSLTlzhi3vEWhaGMTHjWNQ+ktHnS+OkyYfxYsw1VjgImNJuZ0JgT 2b5HT0iLegfTvFMhFdili8EHiORL5mGTG1UdAbCIRxAIn2Z+ZWe80x3OnwGLQVyCnpBS OXm+NVdPRApSP8q5JPTZPohv9UIFV8gH5+YN5LkYYPP0dBBfUi8S8kTD3+8VLqp0MHXW qllrcKk6fNHR6zddqh/CjJAZ0Jw69BVTbR018ay0/XNwhGUXQ8BR7mZkKwRKwoBp8wk7 ymWXaLCSdlM0c0n5AS6zkWsaYYk2XjywXrrH5wOU487S1kSjArt74MdLwJAW4r/U1t/X epYA== X-Gm-Message-State: AA+aEWYm6IXwlhRzm8Pwfp7faO/f2iA5M4uTVGRrIE1kuhDvVkHrV71d rAuZoPzb+Z/GcHs1OgDHrR0= X-Google-Smtp-Source: AFSGD/U6gV73ESm8MAGXew/owddgAXUJniFZuKbNkMY4kjqx0/jASl6pv/XqGXyX2PUIYU1MF70j5Q== X-Received: by 2002:a7b:ce84:: with SMTP id q4mr8086373wmj.105.1545234988002; Wed, 19 Dec 2018 07:56:28 -0800 (PST) Received: from Sarah.corp.lairdtech.com ([109.174.151.67]) by smtp.gmail.com with ESMTPSA id c9sm6836099wmh.27.2018.12.19.07.56.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 07:56:27 -0800 (PST) From: Ben Whitten X-Google-Original-From: Ben Whitten To: starnight@g.ncu.edu.tw, jiri@resnulli.us, afaerber@suse.de Subject: [PATCH RFC lora-next 2/4] net: lora: sx1301: add minimal to get AGC working prior to tx work Date: Wed, 19 Dec 2018 15:56:14 +0000 Message-Id: <20181219155616.9547-3-ben.whitten@lairdtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181219155616.9547-1-ben.whitten@lairdtech.com> References: <20181219155616.9547-1-ben.whitten@lairdtech.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181219_075639_947277_E7EADA3D X-CRM114-Status: GOOD ( 20.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Whitten , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-lpwan@lists.infradead.org, "David S. Miller" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP As part of initialisation when opening the lora device after loading the AGC firmware we need to satisfy its startup procedure which involves a few steps; Loading a 16 entry lookup table. For this I have hard coded the laird ETSI certified table for use on the RG186-M2 (EU) cards, this will need investigation on how other devices load calibration data. Selecting the correct channel to transmit on. Currently always 0 for the reference design. Then ending the AGC init procedure and seeing that it has come up. Signed-off-by: Ben Whitten --- drivers/net/lora/sx1301.c | 254 +++++++++++++++++++++++++++++++++++++- drivers/net/lora/sx1301.h | 16 +++ 2 files changed, 268 insertions(+), 2 deletions(-) diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c index e75df93b96d8..0c7b6d0b31af 100644 --- a/drivers/net/lora/sx1301.c +++ b/drivers/net/lora/sx1301.c @@ -24,6 +24,121 @@ #include "sx1301.h" +static struct sx1301_tx_gain_lut tx_gain_lut[] = { + { + .dig_gain = 0, + .pa_gain = 0, + .dac_gain = 3, + .mix_gain = 8, + .rf_power = -3, + }, + { + .dig_gain = 0, + .pa_gain = 0, + .dac_gain = 3, + .mix_gain = 9, + .rf_power = 0, + }, + { + .dig_gain = 0, + .pa_gain = 0, + .dac_gain = 3, + .mix_gain = 12, + .rf_power = 3, + }, + { + .dig_gain = 0, + .pa_gain = 0, + .dac_gain = 3, + .mix_gain = 13, + .rf_power = 4, + }, + { + .dig_gain = 0, + .pa_gain = 1, + .dac_gain = 3, + .mix_gain = 8, + .rf_power = 6, + }, + { + .dig_gain = 0, + .pa_gain = 1, + .dac_gain = 3, + .mix_gain = 9, + .rf_power = 9, + }, + { + .dig_gain = 0, + .pa_gain = 1, + .dac_gain = 3, + .mix_gain = 10, + .rf_power = 10, + }, + { + .dig_gain = 0, + .pa_gain = 1, + .dac_gain = 3, + .mix_gain = 11, + .rf_power = 12, + }, + { + .dig_gain = 0, + .pa_gain = 1, + .dac_gain = 3, + .mix_gain = 12, + .rf_power = 13, + }, + { + .dig_gain = 0, + .pa_gain = 1, + .dac_gain = 3, + .mix_gain = 13, + .rf_power = 14, + }, + { + .dig_gain = 0, + .pa_gain = 1, + .dac_gain = 3, + .mix_gain = 15, + .rf_power = 16, + }, + { + .dig_gain = 0, + .pa_gain = 2, + .dac_gain = 3, + .mix_gain = 10, + .rf_power = 19, + }, + { + .dig_gain = 0, + .pa_gain = 2, + .dac_gain = 3, + .mix_gain = 11, + .rf_power = 21, + }, + { + .dig_gain = 0, + .pa_gain = 2, + .dac_gain = 3, + .mix_gain = 12, + .rf_power = 22, + }, + { + .dig_gain = 0, + .pa_gain = 2, + .dac_gain = 3, + .mix_gain = 13, + .rf_power = 24, + }, + { + .dig_gain = 0, + .pa_gain = 2, + .dac_gain = 3, + .mix_gain = 14, + .rf_power = 25, + }, +}; + static const struct regmap_range_cfg sx1301_regmap_ranges[] = { { .name = "Pages", @@ -184,6 +299,34 @@ static int sx1301_load_firmware(struct sx1301_priv *priv, int mcu, return 0; } +static int sx1301_agc_transaction(struct sx1301_priv *priv, unsigned int val, + unsigned int *status) +{ + int ret; + + ret = regmap_write(priv->regmap, SX1301_CHRS, SX1301_AGC_CMD_WAIT); + if (ret) { + dev_err(priv->dev, "AGC transaction start failed\n"); + return ret; + } + usleep_range(1000, 2000); + + ret = regmap_write(priv->regmap, SX1301_CHRS, val); + if (ret) { + dev_err(priv->dev, "AGC transaction value failed\n"); + return ret; + } + usleep_range(1000, 2000); + + ret = regmap_read(priv->regmap, SX1301_AGCSTS, status); + if (ret) { + dev_err(priv->dev, "AGC status read failed\n"); + return ret; + } + + return 0; +} + static int sx1301_agc_calibrate(struct sx1301_priv *priv) { const struct firmware *fw; @@ -356,9 +499,53 @@ static int sx1301_load_all_firmware(struct sx1301_priv *priv) return -ENXIO; } - return 0; + return ret; } +static int sx1301_load_tx_gain_lut(struct sx1301_priv *priv) +{ + struct sx1301_tx_gain_lut *lut = priv->tx_gain_lut; + unsigned int val, status; + int ret, i; + + /* HACK use internal gain table in the short term */ + lut = tx_gain_lut; + priv->tx_gain_lut_size = ARRAY_SIZE(tx_gain_lut); + + for (i = 0; i < priv->tx_gain_lut_size; i++) { + val = lut->mix_gain + (lut->dac_gain << 4) + + (lut->pa_gain << 6); + + ret = sx1301_agc_transaction(priv, val, &status); + if (ret) { + dev_err(priv->dev, "AGC LUT load failed\n"); + return ret; + } + if (status != (0x30 + i)) { + dev_err(priv->dev, + "AGC firmware LUT init error: 0x%02X\n", val); + return -ENXIO; + } + lut++; + } + + /* Abort the transaction if there are less then 16 entries */ + if (priv->tx_gain_lut_size < SX1301_TX_GAIN_LUT_MAX) { + ret = sx1301_agc_transaction(priv, SX1301_AGC_CMD_ABORT, &val); + if (ret) { + dev_err(priv->dev, "AGC LUT abort failed\n"); + return ret; + } + if (val != 0x30) { + dev_err(priv->dev, + "AGC firmware LUT abort error: 0x%02X\n", val); + return -ENXIO; + } + } + + return ret; +}; + static netdev_tx_t sx130x_loradev_start_xmit(struct sk_buff *skb, struct net_device *netdev) { @@ -378,6 +565,7 @@ static int sx130x_loradev_open(struct net_device *netdev) { struct sx1301_priv *priv = netdev_priv(netdev); int ret; + unsigned int val; netdev_dbg(netdev, "%s", __func__); @@ -416,12 +604,74 @@ static int sx130x_loradev_open(struct net_device *netdev) if (ret) return ret; - /* TODO */ + /* TODO Load constant adjustments, patches */ + + /* TODO Frequency time drift */ + + /* TODO Configure lora multi demods, bitfield of active */ + + /* TODO Load concenrator multi channel frequencies */ + + /* TODO enale to correlator on enabled frequenies */ + + /* TODO PPMi, and modem enable */ ret = sx1301_load_all_firmware(priv); if (ret) return ret; + usleep_range(1000, 2000); + + ret = regmap_read(priv->regmap, SX1301_AGCSTS, &val); + if (ret) { + dev_err(priv->dev, "AGC status read failed\n"); + return ret; + } + if (val != 0x10) { + dev_err(priv->dev, "AGC firmware init failure: 0x%02X\n", val); + return -ENXIO; + } + + ret = sx1301_load_tx_gain_lut(priv); + if (ret) + return ret; + + /* Load Tx freq MSBs + * Always 3 if f > 768 for SX1257 or f > 384 for SX1255 + */ + ret = sx1301_agc_transaction(priv, 3, &val); + if (ret) { + dev_err(priv->dev, "AGC Tx MSBs load failed\n"); + return ret; + } + if (val != 0x33) { + dev_err(priv->dev, "AGC firmware Tx MSBs error: 0x%02X\n", val); + return -ENXIO; + } + + /* Load chan_select firmware option */ + ret = sx1301_agc_transaction(priv, 0, &val); + if (ret) { + dev_err(priv->dev, "AGC chan select failed\n"); + return ret; + } + if (val != 0x30) { + dev_err(priv->dev, + "AGC firmware chan select error: 0x%02X", val); + return -ENXIO; + } + + /* End AGC firmware init and check status */ + ret = sx1301_agc_transaction(priv, 0, &val); + if (ret) { + dev_err(priv->dev, "AGC radio select failed\n"); + return ret; + } + if (val != 0x40) { + dev_err(priv->dev, "AGC firmware init error: 0x%02X", val); + return -ENXIO; + } + ret = open_loradev(netdev); if (ret) return ret; diff --git a/drivers/net/lora/sx1301.h b/drivers/net/lora/sx1301.h index dd2b7da94fcc..04c9af64c181 100644 --- a/drivers/net/lora/sx1301.h +++ b/drivers/net/lora/sx1301.h @@ -20,6 +20,11 @@ #define SX1301_MCU_AGC_FW_VERSION 4 #define SX1301_MCU_AGC_CAL_FW_VERSION 2 +#define SX1301_AGC_CMD_WAIT 16 +#define SX1301_AGC_CMD_ABORT 17 + +#define SX1301_TX_GAIN_LUT_MAX 16 + /* Page independent */ #define SX1301_PAGE 0x00 #define SX1301_VER 0x01 @@ -105,6 +110,14 @@ static const struct reg_field sx1301_regmap_fields[] = { REG_FIELD(SX1301_EMERGENCY_FORCE_HOST_CTRL, 0, 0), }; +struct sx1301_tx_gain_lut { + unsigned int dig_gain; + unsigned int pa_gain; + unsigned int dac_gain; + unsigned int mix_gain; + int rf_power; /* dBm measured at board connector */ +}; + struct sx1301_priv { struct lora_dev_priv lora; struct device *dev; @@ -112,6 +125,9 @@ struct sx1301_priv { struct gpio_desc *rst_gpio; struct regmap *regmap; struct regmap_field *regmap_fields[ARRAY_SIZE(sx1301_regmap_fields)]; + + struct sx1301_tx_gain_lut tx_gain_lut[SX1301_TX_GAIN_LUT_MAX]; + u8 tx_gain_lut_size; }; int __init sx130x_radio_init(void); From patchwork Wed Dec 19 15:56:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Whitten X-Patchwork-Id: 10737547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CE5B14DE for ; Wed, 19 Dec 2018 15:57:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87C052B434 for ; Wed, 19 Dec 2018 15:57:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7921D2B4BE; Wed, 19 Dec 2018 15:57:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C6B4D2B434 for ; Wed, 19 Dec 2018 15:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/NPdB01BzJu1Y/VlnvUj1bejxm/eYyGXKq5N0La0VKQ=; b=P2jy6MdFmxgkqGxCbCh6jQBhut HhtEjN6R0lFSo2Zln5ec/5TIKTU+gL65nVDzQ10ghYkod3M2xwm2Q/pTmBQT8CWz/dXvIfbHDlLPR WgXY28bmNa5fvdaxmMB2NB+nd511etXgF88m0STzfUPZYS1wWcs7NnaRarEClMjfEute6tSwhycbf EMWIjEcsdIIJxNxoTv2Mfw+URec8LEgKtSvXxu+NGGns0BO8X6QUgdtgcKy9Qut7e5b2HhBglnDoO FBgvQwD/7zgbEzM9kc+X+vQQF1RWr0uHbtbe5o7DEk7b0fY+OQQVqeLrUZTaQxizEwnlVqZakAOJJ jipwJgkA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeDw-00067y-2f; Wed, 19 Dec 2018 15:57:28 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeDB-0005O2-Bc; Wed, 19 Dec 2018 15:56:45 +0000 Received: by mail-wm1-x344.google.com with SMTP id a62so6576348wmh.4; Wed, 19 Dec 2018 07:56:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Yjdj3iu/mF3pgb/qOEW4+jiU3xEZ/IKAQeEQmGe4lEY=; b=NNc2WOqw/ReMZMYkW9ez4MCZWAOSS4LIBgSm5JKxcTvEe5bXydaQmosc9iYof+kG2w /DPjAmku1o9blE7VAh4Ru0i5fMICqS/c/80k4FkKqKtiVlCViVGiccCLMaPga4PU9kOk aBERgu4bfj+5bJCbNbl6uyIWqilX0tAGShQ9HscacyORRo7tqki2TX1e3r6a8q59jplJ wnhLzuI+gXLRs7Q0POIVWUA6LEHhhO6sZnKkcPh0dfB/cCuvczUtNv8hByydawAwuKnx G7F5FEQJ3q2aHt/2bM3pEeP2CGSTGlrKfe5290OGAssaqLi/il6+yEJmaeA4dhSIjxe1 Q/qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Yjdj3iu/mF3pgb/qOEW4+jiU3xEZ/IKAQeEQmGe4lEY=; b=AD1SN4D1RyTSIJapvM/4J7+8r+yEO8JtC4MSjr+tDWFvWpDqA5E56RFsHezbnD+QO+ uK808TatQewWQtfxm2Ig8nsiBAPmnmjVnZ5XU+grQ1MQ6bHABEWFmgLVbtcP3W/iCxxP 8nTEkoupfFDbJZTnmZQ7PpJ++dSw6tsSLouhH+50CRzE5FYc/ta/o0wy4Q50rl0suyMg rY8w2s5MjHNxBBVP3Jx2D+tF7Npb5c+m6PuECvkjj9BM8pl6TbWWJA3ohgpFmwPTXH47 5bBbe5ObI+royZV9VeVD2e5fqyw8wBnWEBRHwvFwuvwLIACU8IHKgMaZLvWej6083l43 SaEA== X-Gm-Message-State: AA+aEWbbqqwy37FVk5X6awYTeOZds2on2H5e1/16tycY7ENYIpEF6WFC AuFY7ho2ksHgk8HF0RJw9pU= X-Google-Smtp-Source: AFSGD/VHzRhZ5EAASjPGCZvBVQO5Kmjgq9gBZEuqlXjQAPLk5CS3qnVyb501uJulC/1HpUsMIwMldA== X-Received: by 2002:a1c:2501:: with SMTP id l1mr8074847wml.102.1545234989325; Wed, 19 Dec 2018 07:56:29 -0800 (PST) Received: from Sarah.corp.lairdtech.com ([109.174.151.67]) by smtp.gmail.com with ESMTPSA id c9sm6836099wmh.27.2018.12.19.07.56.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 07:56:28 -0800 (PST) From: Ben Whitten X-Google-Original-From: Ben Whitten To: starnight@g.ncu.edu.tw, jiri@resnulli.us, afaerber@suse.de Subject: [PATCH RFC lora-next 3/4] net: lora: sx1301: add minimal to get transmission out Date: Wed, 19 Dec 2018 15:56:15 +0000 Message-Id: <20181219155616.9547-4-ben.whitten@lairdtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181219155616.9547-1-ben.whitten@lairdtech.com> References: <20181219155616.9547-1-ben.whitten@lairdtech.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181219_075641_397830_D7D1B4CC X-CRM114-Status: GOOD ( 20.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Whitten , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-lpwan@lists.infradead.org, "David S. Miller" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Because we cannot wait inside start_xmit so we copy the pointer to the skb and schedule transmission work to be done. For the transmission a lot is hard coded to just get a signal out of the sx1301, it looks like using a header like CAN frames do will be a good mechanism to get information such as coding rate, spreading factor and power into the transmission. Signed-off-by: Ben Whitten --- drivers/net/lora/sx1301.c | 166 +++++++++++++++++++++++++++++++++++++- drivers/net/lora/sx1301.h | 21 +++++ 2 files changed, 186 insertions(+), 1 deletion(-) diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c index 0c7b6d0b31af..9bcbb967f307 100644 --- a/drivers/net/lora/sx1301.c +++ b/drivers/net/lora/sx1301.c @@ -24,6 +24,44 @@ #include "sx1301.h" +struct sx1301_tx_header { + u8 tx_freq[3]; + u32 start; + u8 tx_power:4, + modulation_type:1, + radio_select:1, + resered0:2; + u8 reserved1; + + union { + struct lora_t { + u8 sf:4, + cr:3, + crc16_en:1; + u8 payload_len; + u8 mod_bw:2, + implicit_header:1, + ppm_offset:1, + invert_pol:1, + reserved0:3; + u16 preamble; + u8 reserved1; + u8 reserved2; + } lora; + struct fsk_t { + u8 freq_dev; + u8 payload_len; + u8 packet_mode:1, + crc_en:1, + enc_mode:2, + crc_mode:1, + reserved0:3; + u16 preamble; + u16 bitrate; + } fsk; + } u; +} __packed; + static struct sx1301_tx_gain_lut tx_gain_lut[] = { { .dig_gain = 0, @@ -546,9 +584,87 @@ static int sx1301_load_tx_gain_lut(struct sx1301_priv *priv) return ret; }; +static int sx1301_tx(struct sx1301_priv *priv, void *data, int len) +{ + int ret, i; + u8 buff[256 + 16]; + struct sx1301_tx_header *hdr = (struct sx1301_tx_header *)buff; + + /* TODO general checks to make sure we CAN send */ + + /* TODO Enable notch filter for lora 125 */ + + /* TODO get start delay for this TX */ + + /* TODO interpret tx power, HACK just set max power */ + + /* TODO get TX imbalance for this pow index from calibration step */ + + /* TODO set the dig gain */ + + /* TODO set TX PLL freq based on radio used to TX */ + + memset(buff, 0, sizeof(buff)); + + /* HACK set to 868MHz */ + hdr->tx_freq[0] = 217; + hdr->tx_freq[1] = 0; + hdr->tx_freq[3] = 0; + + hdr->start = 0; /* Start imediatly */ + hdr->radio_select = 0; /* HACK Radio A transmit */ + hdr->modulation_type = 0; /* HACK modulation LORA */ + hdr->tx_power = 15; /* HACK power entry 15 */ + + hdr->u.lora.crc16_en = 1; /* Enable CRC16 */ + hdr->u.lora.cr = 1; /* CR 4/5 */ + hdr->u.lora.sf = 7; /* SF7 */ + hdr->u.lora.payload_len = len; /* Set the data len to the skb len */ + hdr->u.lora.implicit_header = 0; /* No implicit header */ + hdr->u.lora.mod_bw = 0; /* Set 125KHz BW */ + hdr->u.lora.ppm_offset = 0; /* TODO no ppm offset? */ + hdr->u.lora.invert_pol = 0; /* TODO set no inverted polarity */ + + hdr->u.lora.preamble = 8; /* Set the standard preamble */ + + /* TODO 2 Msb in tx_freq0 for large narrow filtering, unset for now */ + hdr->tx_freq[0] &= 0x3F; + + /* Copy the TX data into the buffer ready to go */ + + memcpy((void *)&buff[16], data, len); + + /* Reset any transmissions */ + ret = regmap_write(priv->regmap, SX1301_TX_TRIG, 0); + if (ret) + return ret; + + /* Put the buffer into the tranmit fifo */ + ret = regmap_write(priv->regmap, SX1301_TX_DATA_BUF_ADDR, 0); + if (ret) + return ret; + ret = regmap_noinc_write(priv->regmap, SX1301_TX_DATA_BUF_DATA, buff, + len + 16); + if (ret) + return ret; + + /* HACK just go for immediate transfer */ + ret = sx1301_field_write(priv, F_TX_TRIG_IMMEDIATE, 1); + if (ret) + return ret; + + dev_dbg(priv->dev, "Transmitting packet of size %d: ", len); + for (i = 0; i < len + 16; i++) + dev_dbg(priv->dev, "%X", buff[i]); + + return ret; +} + static netdev_tx_t sx130x_loradev_start_xmit(struct sk_buff *skb, struct net_device *netdev) { + struct sx1301_priv *priv = netdev_priv(netdev); + if (skb->protocol != htons(ETH_P_LORA)) { kfree_skb(skb); netdev->stats.tx_dropped++; @@ -556,11 +672,42 @@ static netdev_tx_t sx130x_loradev_start_xmit(struct sk_buff *skb, } netif_stop_queue(netdev); + priv->tx_skb = skb; + queue_work(priv->wq, &priv->tx_work); - /* TODO */ return NETDEV_TX_OK; } +static void sx1301_tx_work_handler(struct work_struct *ws) +{ + struct sx1301_priv *priv = container_of(ws, struct sx1301_priv, + tx_work); + struct net_device *netdev = dev_get_drvdata(priv->dev); + int ret; + + netdev_dbg(netdev, "%s\n", __func__); + + if (priv->tx_skb) { + ret = sx1301_tx(priv, priv->tx_skb->data, priv->tx_skb->len); + if (ret) { + netdev->stats.tx_errors++; + } else { + netdev->stats.tx_packets++; + netdev->stats.tx_bytes += priv->tx_skb->len; + } + + if (!(netdev->flags & IFF_ECHO) || + priv->tx_skb->pkt_type != PACKET_LOOPBACK || + priv->tx_skb->protocol != htons(ETH_P_LORA)) + kfree_skb(priv->tx_skb); + + priv->tx_skb = NULL; + } + + if (netif_queue_stopped(netdev)) + netif_wake_queue(netdev); +} + static int sx130x_loradev_open(struct net_device *netdev) { struct sx1301_priv *priv = netdev_priv(netdev); @@ -676,6 +823,12 @@ static int sx130x_loradev_open(struct net_device *netdev) if (ret) return ret; + priv->tx_skb = NULL; + + priv->wq = alloc_workqueue("sx1301_wq", + WQ_FREEZABLE | WQ_MEM_RECLAIM, 0); + INIT_WORK(&priv->tx_work, sx1301_tx_work_handler); + netif_start_queue(netdev); return 0; @@ -683,11 +836,22 @@ static int sx130x_loradev_open(struct net_device *netdev) static int sx130x_loradev_stop(struct net_device *netdev) { + struct sx1301_priv *priv = netdev_priv(netdev); + netdev_dbg(netdev, "%s", __func__); netif_stop_queue(netdev); close_loradev(netdev); + destroy_workqueue(priv->wq); + priv->wq = NULL; + + if (priv->tx_skb) + netdev->stats.tx_errors++; + if (priv->tx_skb) + dev_kfree_skb(priv->tx_skb); + priv->tx_skb = NULL; + return 0; } diff --git a/drivers/net/lora/sx1301.h b/drivers/net/lora/sx1301.h index 04c9af64c181..86116f3a1fa4 100644 --- a/drivers/net/lora/sx1301.h +++ b/drivers/net/lora/sx1301.h @@ -28,6 +28,10 @@ /* Page independent */ #define SX1301_PAGE 0x00 #define SX1301_VER 0x01 +#define SX1301_RX_DATA_BUF_ADDR 0x02 /* 16 wide */ +#define SX1301_RX_DATA_BUF_DATA 0x04 +#define SX1301_TX_DATA_BUF_ADDR 0x05 +#define SX1301_TX_DATA_BUF_DATA 0x06 #define SX1301_MPA 0x09 #define SX1301_MPD 0x0A #define SX1301_GEN 0x10 @@ -45,6 +49,9 @@ #define SX1301_FORCE_CTRL (SX1301_PAGE_BASE(0) + 0x69) #define SX1301_MCU_CTRL (SX1301_PAGE_BASE(0) + 0x6A) +/* Page 1 */ +#define SX1301_TX_TRIG (SX1301_PAGE_BASE(1) + 0x21) + /* Page 2 */ #define SX1301_RADIO_A_SPI_DATA (SX1301_PAGE_BASE(2) + 0x21) #define SX1301_RADIO_A_SPI_DATA_RB (SX1301_PAGE_BASE(2) + 0x22) @@ -83,6 +90,10 @@ enum sx1301_fields { F_FORCE_DEC_FILTER_GAIN, F_EMERGENCY_FORCE_HOST_CTRL, + + F_TX_TRIG_IMMEDIATE, + F_TX_TRIG_DELAYED, + F_TX_TRIG_GPS, }; static const struct reg_field sx1301_regmap_fields[] = { @@ -108,6 +119,11 @@ static const struct reg_field sx1301_regmap_fields[] = { /* EMERGENCY_FORCE_HOST_CTRL */ [F_EMERGENCY_FORCE_HOST_CTRL] = REG_FIELD(SX1301_EMERGENCY_FORCE_HOST_CTRL, 0, 0), + /* TX_TRIG */ + [F_TX_TRIG_IMMEDIATE] = REG_FIELD(SX1301_TX_TRIG, 0, 0), + [F_TX_TRIG_DELAYED] = REG_FIELD(SX1301_TX_TRIG, 1, 1), + [F_TX_TRIG_GPS] = REG_FIELD(SX1301_TX_TRIG, 2, 2), + }; struct sx1301_tx_gain_lut { @@ -126,6 +142,11 @@ struct sx1301_priv { struct regmap *regmap; struct regmap_field *regmap_fields[ARRAY_SIZE(sx1301_regmap_fields)]; + struct sk_buff *tx_skb; + + struct workqueue_struct *wq; + struct work_struct tx_work; + struct sx1301_tx_gain_lut tx_gain_lut[SX1301_TX_GAIN_LUT_MAX]; u8 tx_gain_lut_size; }; From patchwork Wed Dec 19 15:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Whitten X-Patchwork-Id: 10737549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55E9813B5 for ; Wed, 19 Dec 2018 15:57:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41B0B2B434 for ; Wed, 19 Dec 2018 15:57:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 308832B4BE; Wed, 19 Dec 2018 15:57:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 91F2D2B434 for ; Wed, 19 Dec 2018 15:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7l41RTXaPJuoWu6fyCRzK1AHmEzQj8KDnicSTT65/YU=; b=G1MA4DRyjf4Xk0zT2RvU12X4Ll DX7eYmLMUx3Ui1nqDbSBW2rHi/8ha2MYbBa9wFaBup28capPxC4Z2qrAmWeozLhLxgeS64ga3YWav 4hQfxmlV8ianlZWq0awlDiiqty/eSFg9LVuXM3TohK2LzOYWS4JsJTxhRba5XLNqovFhhcg3GG4x+ 0aFSRsR5XMcEewaRQh+1+JSr3FymBto4cRUi0050TS94Wl8+E7CO0dJd9AFR3Ir4F8xV6+4x1VWhn WVcp1dufinrRUl3o9jKim7ZfSBTIiF9m5GpaQuK0EtanO7jdXKYlvK47tayr2WfSxk1G0a+C22U4a UyDkqyhQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeEB-0006Lp-CZ; Wed, 19 Dec 2018 15:57:43 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gZeDC-0005OK-NG; Wed, 19 Dec 2018 15:56:49 +0000 Received: by mail-wm1-x341.google.com with SMTP id r24so9856524wmh.0; Wed, 19 Dec 2018 07:56:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Dx/xK0RPW2Lm4RTnTSdayPB1mXeHlkjPqDKxt/FlTYM=; b=uT3RP4hZ/DEf3FHnmnLfA0r3NF1GIV1bsBOVPUlc9/prQ9MSPHrlpI4O+/KnlZZaDx IP4kkm0Rd+OPfRycRd5UKqh+mTKCBaz0riQLbsCWStbcwqMjytVZaJf4RBCbHuagNovc chuD2iyqKld37WgcAzc2RzpowHlRjJ1n8RbpBWv828/Bv0fyKw+nCKbrOgmkLV5T66HU nMawDGBcUalrU1AT6rbLpfBU9j9JH5Hsv8wpN1TC3rVV91ruqroIQ1YAXUPdNPG4Bh/8 SGID7Rg3z8pMAJ4JxVEDJ/2vXy2rccCXn1NhHDQH1fdHWfKVTLBVBqhuQqacWvf+nB7V z72w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Dx/xK0RPW2Lm4RTnTSdayPB1mXeHlkjPqDKxt/FlTYM=; b=KOc3l5Z8AdDF1TOrIHCbAdxCE2nyUMeaqVyIdb9F2AhnGQG3XN0HvZBYZkRFY41e+C l44WiYrEVbejEUNlC0TUgrcZJ2nBn0WQGylJGntMLvxDsdRC65+fmtCbo5wDRNJPICUb 5d11xGvgez39eKHalw1RaE2GeAfBdtRCVxcOfMdgujDar+sgE6mU90sjk4GRpSLV6RIJ u8KUbTkStoqg5ijCdOanZXd3DYXkKKNGVsrq0w8B0Rx8IOYLAHaJcAKaF4UkMF8jDKm5 hJc0U+6B8KhMzUbuNZaizHi7MmcJTq7KovSRYWgW+F1eoliCi/jO6OtIhzpvZKK0SG94 uXjw== X-Gm-Message-State: AA+aEWZKEj58vVWFGeLMrvaau6VseNnfTrOXKPjZIF3UnsGi+8+gB9Mp bG3+IxhsohzQnhdCoYIF8nY= X-Google-Smtp-Source: AFSGD/WzrHrGMbMsACXlzav1xUQl3C83IiETnFwMbF8GBgDUaeahhM8ywgLn4QaMgw+3VzWzGQBK6Q== X-Received: by 2002:a1c:b1d5:: with SMTP id a204mr8133515wmf.32.1545234990621; Wed, 19 Dec 2018 07:56:30 -0800 (PST) Received: from Sarah.corp.lairdtech.com ([109.174.151.67]) by smtp.gmail.com with ESMTPSA id c9sm6836099wmh.27.2018.12.19.07.56.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 07:56:30 -0800 (PST) From: Ben Whitten X-Google-Original-From: Ben Whitten To: starnight@g.ncu.edu.tw, jiri@resnulli.us, afaerber@suse.de Subject: [PATCH RFC lora-next 4/4] net: lora: sx1301: introduce a lora frame for packet metadata Date: Wed, 19 Dec 2018 15:56:16 +0000 Message-Id: <20181219155616.9547-5-ben.whitten@lairdtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181219155616.9547-1-ben.whitten@lairdtech.com> References: <20181219155616.9547-1-ben.whitten@lairdtech.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181219_075643_231364_6BCCE12E X-CRM114-Status: GOOD ( 17.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ben Whitten , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-lpwan@lists.infradead.org, "David S. Miller" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Information such as spreading factor, coding rate and power are on a per transmission basis so it makes sence to include this in a header much like CAN frames do. Signed-off-by: Ben Whitten --- drivers/net/lora/dev.c | 2 - drivers/net/lora/sx1301.c | 79 +++++++++++++++++++++++++++++++++------ include/uapi/linux/lora.h | 46 +++++++++++++++++++++++ 3 files changed, 114 insertions(+), 13 deletions(-) diff --git a/drivers/net/lora/dev.c b/drivers/net/lora/dev.c index 0d4823de8c06..62dbe21668b0 100644 --- a/drivers/net/lora/dev.c +++ b/drivers/net/lora/dev.c @@ -11,8 +11,6 @@ #include #include -#define LORA_MTU 256 /* XXX */ - struct sk_buff *alloc_lora_skb(struct net_device *dev, u8 **data) { struct sk_buff *skb; diff --git a/drivers/net/lora/sx1301.c b/drivers/net/lora/sx1301.c index 9bcbb967f307..fed6d6201bf3 100644 --- a/drivers/net/lora/sx1301.c +++ b/drivers/net/lora/sx1301.c @@ -584,7 +584,7 @@ static int sx1301_load_tx_gain_lut(struct sx1301_priv *priv) return ret; }; -static int sx1301_tx(struct sx1301_priv *priv, void *data, int len) +static int sx1301_tx(struct sx1301_priv *priv, struct lora_frame *frame) { int ret, i; u8 buff[256 + 16]; @@ -617,11 +617,67 @@ static int sx1301_tx(struct sx1301_priv *priv, void *data, int len) hdr->tx_power = 15; /* HACK power entry 15 */ hdr->u.lora.crc16_en = 1; /* Enable CRC16 */ - hdr->u.lora.cr = 1; /* CR 4/5 */ - hdr->u.lora.sf = 7; /* SF7 */ - hdr->u.lora.payload_len = len; /* Set the data len to the skb len */ + + switch (frame->cr) { + case LORA_CR_4_5: + hdr->u.lora.cr = 1; /* CR 4/5 */ + break; + case LORA_CR_4_6: + hdr->u.lora.cr = 2; /* CR 4/6 */ + break; + case LORA_CR_4_7: + hdr->u.lora.cr = 3; /* CR 4/7 */ + break; + case LORA_CR_4_8: + hdr->u.lora.cr = 4; /* CR 4/8 */ + break; + default: + return -ENXIO; + } + + switch (frame->sf) { + case LORA_SF_6: + hdr->u.lora.sf = 6; /* SF6 */ + break; + case LORA_SF_7: + hdr->u.lora.sf = 7; /* SF7 */ + break; + case LORA_SF_8: + hdr->u.lora.sf = 8; /* SF8 */ + break; + case LORA_SF_9: + hdr->u.lora.sf = 9; /* SF9 */ + break; + case LORA_SF_10: + hdr->u.lora.sf = 10; /* SF10 */ + break; + case LORA_SF_11: + hdr->u.lora.sf = 11; /* SF11 */ + break; + case LORA_SF_12: + hdr->u.lora.sf = 12; /* SF12 */ + break; + default: + return -ENXIO; + } + + hdr->u.lora.payload_len = frame->len; /* Set the data length */ hdr->u.lora.implicit_header = 0; /* No implicit header */ - hdr->u.lora.mod_bw = 0; /* Set 125KHz BW */ + + switch (frame->bw) { + case LORA_BW_125KHZ: + hdr->u.lora.mod_bw = 0; /* 125KHz BW */ + break; + case LORA_BW_250KHZ: + hdr->u.lora.mod_bw = 1; /* 250KHz BW */ + break; + case LORA_BW_500KHZ: + hdr->u.lora.mod_bw = 2; /* 500KHz BW */ + break; + default: + return -ENXIO; + } + hdr->u.lora.ppm_offset = 0; /* TODO no ppm offset? */ hdr->u.lora.invert_pol = 0; /* TODO set no inverted polarity */ @@ -632,7 +688,7 @@ static int sx1301_tx(struct sx1301_priv *priv, void *data, int len) /* Copy the TX data into the buffer ready to go */ - memcpy((void *)&buff[16], data, len); + memcpy((void *)&buff[16], frame->data, frame->len); /* Reset any transmissions */ ret = regmap_write(priv->regmap, SX1301_TX_TRIG, 0); @@ -644,7 +700,7 @@ static int sx1301_tx(struct sx1301_priv *priv, void *data, int len) if (ret) return ret; ret = regmap_noinc_write(priv->regmap, SX1301_TX_DATA_BUF_DATA, buff, - len + 16); + frame->len + 16); if (ret) return ret; @@ -653,8 +709,8 @@ static int sx1301_tx(struct sx1301_priv *priv, void *data, int len) if (ret) return ret; - dev_dbg(priv->dev, "Transmitting packet of size %d: ", len); - for (i = 0; i < len + 16; i++) + dev_dbg(priv->dev, "Transmitting packet of size %d: ", frame->len); + for (i = 0; i < frame->len + 16; i++) dev_dbg(priv->dev, "%X", buff[i]); return ret; @@ -683,17 +739,18 @@ static void sx1301_tx_work_handler(struct work_struct *ws) struct sx1301_priv *priv = container_of(ws, struct sx1301_priv, tx_work); struct net_device *netdev = dev_get_drvdata(priv->dev); + struct lora_frame *frame = (struct lora_frame *)priv->tx_skb->data; int ret; netdev_dbg(netdev, "%s\n", __func__); if (priv->tx_skb) { - ret = sx1301_tx(priv, priv->tx_skb->data, priv->tx_skb->len); + ret = sx1301_tx(priv, frame); if (ret) { netdev->stats.tx_errors++; } else { netdev->stats.tx_packets++; - netdev->stats.tx_bytes += priv->tx_skb->len; + netdev->stats.tx_bytes += frame->len; } if (!(netdev->flags & IFF_ECHO) || diff --git a/include/uapi/linux/lora.h b/include/uapi/linux/lora.h index 4ff00b9c3c20..d675025d2a6e 100644 --- a/include/uapi/linux/lora.h +++ b/include/uapi/linux/lora.h @@ -21,4 +21,50 @@ struct sockaddr_lora { } lora_addr; }; +#define LORA_MAX_DLEN 256 + +enum lora_bw { + LORA_BW_125KHZ, + LORA_BW_250KHZ, + LORA_BW_500KHZ, +}; + +enum lora_cr { + LORA_CR_4_5, + LORA_CR_4_6, + LORA_CR_4_7, + LORA_CR_4_8, +}; + +enum lora_sf { + LORA_SF_6, + LORA_SF_7, + LORA_SF_8, + LORA_SF_9, + LORA_SF_10, + LORA_SF_11, + LORA_SF_12, +}; + +/** + * struct lora_frame - LoRa frame structure + * @freq: Frequency of LoRa transmission in Hz + * @power: Power of transmission in dBm + * @bw: bandwidth, 125, 250 or 500 KHz + * @cr: coding rate, 4/5 to 4/8 + * @sf: spreading factor from SF6 to 12 + * @data: LoRa frame payload (up to LORA_MAX_DLEN byte) + */ +struct lora_frame { + __u32 freq; /* transmission frequency in Hz */ + __u8 power; /* transmission power in dBm */ + enum lora_bw bw; /* bandwidth */ + enum lora_cr cr; /* coding rate */ + enum lora_sf sf; /* spreading factor */ + __u8 len; + __u8 data[LORA_MAX_DLEN] __attribute__((aligned(8))); +}; + +#define LORA_MTU (sizeof(struct lora_frame)) + #endif /* _UAPI_LINUX_LORA_H */