Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2719089imm; Sun, 1 Jul 2018 04:13:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdddS2Z8OosiiWxbcxmJcBkQ5z3EmAp9ENjcQDR6jvw41uJjh1ERgREalu6eaZe+CbJI5BJ X-Received: by 2002:a62:90d4:: with SMTP id q81-v6mr12511936pfk.37.1530443615018; Sun, 01 Jul 2018 04:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443614; cv=none; d=google.com; s=arc-20160816; b=xN78LutPINqUGqqxJmfJE121D2osCEj5I+BwPaV7frczYotgrvjr+H07bGBvKI29QL jHSNe7E4sPqNnbiQyotqp43g0K2tWHmyKUTBWT8Ip7oIxMORQMMM1aqz9dy6oKvTy+OG 1TrqZK31HzZjASPclr5zuQEcCx6X/N22ahTfhPilm8j5up1hha6eYMi3qi10sMuK8dbO brj+DvcOO2GskghQJn+ZqJqZmKYsYFgW/uHnVrmWM2FSpIlCLn8iai1gPp0byGtsTjx4 ki4pTGTaBBCTgidFSW7iUXo9J5oESBHhJjt1ilmaAme+vUlybIpYf2l8jMZmNUtQEvc9 N1HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=t2zdSFuj8q83bQeIuiXmNPVzv5Wvj5naoZs1Ftpb1Yw=; b=0QLGZ1xVjVm2KAZV0Xf9kCsoNNNqZSJDpvKpNyNLKSe8nk7tDyqRHY4AeycaJ8Re73 NuGTMHTK5NyDf4dlP1z2wPzytW/CWKUndDlaNCpyaEtMr8ckFjN8Ko7Xd6y5CFxUDt9P W9fU4F/QlLiWcTb45dzp61MUKXEpuUZ1BOlsHwHIuvjpcxd35DGLP6wKqTRb/HKRhNAc ioIvpDi+MUVjbmOUpWelM5eXJkDbBUQADBfL9/bgX5MgtC5tYtKOjUDCmOx1X0kdGrU9 AlSO+iT/74VpAxfqfwBE2frrEFhyFaZP8iz5O3S9fMiXHgWdNM6GarcaVxHnDryomv3A hG5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3-v6si14196759pfm.0.2018.07.01.04.13.11; Sun, 01 Jul 2018 04:13:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752564AbeGALKU (ORCPT + 99 others); Sun, 1 Jul 2018 07:10:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:47814 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752339AbeGALJE (ORCPT ); Sun, 1 Jul 2018 07:09:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AD20FAFB3; Sun, 1 Jul 2018 11:09:03 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: netdev@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jian-Hong Pan , Jiri Pirko , Marcel Holtmann , "David S . Miller" , Matthias Brugger , Janus Piwek , =?UTF-8?q?Michael=20R=C3=B6der?= , Dollar Chen , Ken Yu , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Ben Whitten , Steve deRosier , Mark Brown Subject: [RFC net-next 14/15] net: lora: Prepare Semtech SX1257 Date: Sun, 1 Jul 2018 13:08:03 +0200 Message-Id: <20180701110804.32415-15-afaerber@suse.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180701110804.32415-1-afaerber@suse.de> References: <20180701110804.32415-1-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The Semtech SX1257 and Sx1255 are usually used for radios A/B of SX1301. This will not implement a netdev itself, but rather needs to interface with SX130x somehow. Cc: Ben Whitten Cc: Steve deRosier Cc: Mark Brown Cc: Michael Röder Cc: Ken Yu (禹凯) Signed-off-by: Andreas Färber --- drivers/net/lora/Kconfig | 7 ++++ drivers/net/lora/Makefile | 3 ++ drivers/net/lora/sx1257.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 drivers/net/lora/sx1257.c diff --git a/drivers/net/lora/Kconfig b/drivers/net/lora/Kconfig index 3e384493cbdd..68c7480d7812 100644 --- a/drivers/net/lora/Kconfig +++ b/drivers/net/lora/Kconfig @@ -31,6 +31,13 @@ config LORA_RN2483 help Microchip RN2483/2903 +config LORA_SX1257 + tristate "Semtech SX125x SPI driver" + default y + depends on SPI + help + Semtech SX1255/1257 + config LORA_SX1276 tristate "Semtech SX127x SPI driver" default y diff --git a/drivers/net/lora/Makefile b/drivers/net/lora/Makefile index 6b6870ffbfd8..44c578bde7d5 100644 --- a/drivers/net/lora/Makefile +++ b/drivers/net/lora/Makefile @@ -16,6 +16,9 @@ obj-$(CONFIG_LORA_RN2483) += lora-rn2483.o lora-rn2483-y := rn2483.o lora-rn2483-y += rn2483_cmd.o +obj-$(CONFIG_LORA_SX1257) += lora-sx1257.o +lora-sx1257-y := sx1257.o + obj-$(CONFIG_LORA_SX1276) += lora-sx1276.o lora-sx1276-y := sx1276.o diff --git a/drivers/net/lora/sx1257.c b/drivers/net/lora/sx1257.c new file mode 100644 index 000000000000..c4e04ee3ec4b --- /dev/null +++ b/drivers/net/lora/sx1257.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Semtech SX1255/SX1257 LoRa transceiver + * + * Copyright (c) 2018 Andreas Färber + * + * Based on SX1301 HAL code: + * Copyright (c) 2013 Semtech-Cycleo + */ + +#include +#include +#include +#include + +static int sx1257_write(struct spi_device *spi, u8 reg, u8 val) +{ + u8 buf[2]; + + buf[0] = reg | BIT(7); + buf[1] = val; + return spi_write(spi, buf, 2); +} + +static int sx1257_read(struct spi_device *spi, u8 reg, u8 *val) +{ + u8 addr = reg & 0x7f; + return spi_write_then_read(spi, &addr, 1, val, 1); +} + +static int sx1257_probe(struct spi_device *spi) +{ + u8 val; + int ret; + + if (true) { + ret = sx1257_read(spi, 0x07, &val); + if (ret) { + dev_err(&spi->dev, "version read failed\n"); + return ret; + } + + dev_info(&spi->dev, "SX125x version: %02x\n", (unsigned)val); + } + + ret = sx1257_write(spi, 0x10, 1 /* + 2 */); + if (ret) { + dev_err(&spi->dev, "clk write failed\n"); + return ret; + } + + dev_info(&spi->dev, "clk written\n"); + + if (true) { + ret = sx1257_write(spi, 0x26, 13 + 2 * 16); + if (ret) { + dev_err(&spi->dev, "xosc write failed\n"); + return ret; + } + } + + dev_info(&spi->dev, "SX1257 module probed\n"); + + return 0; +} + +static int sx1257_remove(struct spi_device *spi) +{ + dev_info(&spi->dev, "SX1257 module removed\n"); + + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id sx1257_dt_ids[] = { + { .compatible = "semtech,sx1255" }, + { .compatible = "semtech,sx1257" }, + {} +}; +MODULE_DEVICE_TABLE(of, sx1257_dt_ids); +#endif + +static struct spi_driver sx1257_spi_driver = { + .driver = { + .name = "sx1257", + .of_match_table = of_match_ptr(sx1257_dt_ids), + }, + .probe = sx1257_probe, + .remove = sx1257_remove, +}; + +module_spi_driver(sx1257_spi_driver); + +MODULE_DESCRIPTION("SX1257 SPI driver"); +MODULE_AUTHOR("Andreas Färber "); +MODULE_LICENSE("GPL"); -- 2.16.4