From patchwork Sun Jul 1 11:08:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 10498649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D4ED360284 for ; Sun, 1 Jul 2018 11:21:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6DC628A93 for ; Sun, 1 Jul 2018 11:21:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8D9C28AF7; Sun, 1 Jul 2018 11:21:22 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI 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 33D5128A93 for ; Sun, 1 Jul 2018 11:21:22 +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=x8sh1U+Oge9YuPZFcquJWsnIHZ5qUdFuchvkysUFK2o=; b=Fco7CAk0ji41It IoUTVVMfNNPwC8DXHLZz/4bE5XSfe5Gd4ILc/aZvbTEc3vVed3TuRCf4Qpy1cPPryXrGwrkd/thXB xaQ9GRF8wkaGElACnfvVsvWkZovaM5H+8EFfTsxUzxkl6zioIv5Y7EouPm0hzXRBBQoqO/TAciAZC 4njQIOhJr3YkIf0tqcKQSKwQ8rtch4QQvEdBQLx23zVONyNshQpOU5QRF3cB/dffPlTcwHtuvkiMb Fb6JSMkKP84QSSZm1vDnbw3mpS3HwQNRDpEs+/3C+rPwPDFHhccx6y3I2Jo/4xu8myZvabbUtdaC6 Lox+KEEFrnyqclg6kaTQ==; 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 1fZaPt-0003zs-3n; Sun, 01 Jul 2018 11:21:17 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZaEP-0004aT-9B for linux-arm-kernel@lists.infradead.org; Sun, 01 Jul 2018 11:09:39 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180701_040926_258664_BFBA9434 X-CRM114-Status: GOOD ( 14.77 ) 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: Steve deRosier , Matthias Brugger , Jiri Pirko , Ben Whitten , Marcel Holtmann , Dollar Chen , linux-kernel@vger.kernel.org, =?UTF-8?q?Michael=20R=C3=B6der?= , Janus Piwek , Mark Brown , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Jian-Hong Pan , Ken Yu , "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 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");