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: 140705 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2849586ljj; Sun, 1 Jul 2018 04:11:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdFtWS0MhfWzdhoKqMGZLiAcC471WhDVrxJM7Fa/kM8kQxBmjIQkcLh2/cizvKwwvA6ggzS X-Received: by 2002:a62:9652:: with SMTP id c79-v6mr21538926pfe.114.1530443508640; Sun, 01 Jul 2018 04:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530443508; cv=none; d=google.com; s=arc-20160816; b=EeT1FmCeiMVaNhDS6vMGHG3BmGgZLXBy6zLMI81avyhAv2BvP59laB12xA5+rOcqfH 2CVHGdeGiqwkj46e1uDNHL1r3gGxuUhXcCiNbZEzHR+I1tL8IoZRfG92oYWcVaS/B1HK UDQNqGhpIPREMIQvfJxPp+IvX5o6lLT70+ZAC6rp472/ICvXeMWNkW7J5Nj9OtbxaMP6 idAuCyJlcqxWgMQ9UR3/B53gw+QVJqAEJY2gNiMvwATKA+f6KVC/0Qta7/8TPPW7rjVu TVOQ6UQjuWftS4CVtOh4RyeaRSvZo2Ud3zlgyFQ/CPVXtrtL0p9sF0rOFKP/de1mTQXS CiJg== 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 a66-v6si13714179pfe.364.2018.07.01.04.11.48; Sun, 01 Jul 2018 04:11:48 -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 S1752570AbeGALKU (ORCPT + 31 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_F=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_R=C3=B6der?= , Dollar Chen , Ken Yu , =?utf-8?q?Andreas_F=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 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 -- 2.16.4 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");