Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp170944imm; Mon, 2 Jul 2018 09:29:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdjjsozbw79WT6NP9s9q58d0y+cZy8IuDXocCpOqzKZDwTvx91lhACWF7BGaw4xouxoV4EQ X-Received: by 2002:a62:930c:: with SMTP id b12-v6mr25958479pfe.193.1530548975030; Mon, 02 Jul 2018 09:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530548975; cv=none; d=google.com; s=arc-20160816; b=xKebzKG0RcFsPL5dd5OtrVfTOzaCFukSLSlS54cK6FRIIIpZtOLXgvnpd+XieM+I8I Yky9EyQmIWvvWlfgxkbTo0DfM/vqRWFsw9JR6OP06SsGkQCOi4X/YuvKFJdWtrIwzcXf QRVX0YaKKbWV7GkncTLMvEL0uDR+8Whtl+GE/aNptsELJf8GrpLzqlH78GirZPVVBUHG iPzbMEiYB/fqvj4o+o9ezxilm8CAdlY/8qI+KnmJ6HdGy7bK21LuhVTbzYaLe3o+JWeF ct6SZ7bzSBOXUmxUGP6qjKoiKoQPhzGjuGgYGoKgGw9ZpH7ubVNkj6L/rkn4HwJM2XQo qPIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=MKsy6p8tA1MVGGjKEgjLbg9mT0zCvsdPl5efJmJPJBE=; b=eY7MDvNtMpMwjZ7ivZzIUiMyNy46zJOrYlbYUcbRRX5ST4KsiaoUNixYeCDMgPU4/Z ihCUkEDick32nBl1d9IPWbTgpK/VO1YcErvvNv7JjMKh13BapDYr0IsIqT+uDTDhfWQQ enUa0l9WPTAa4nJVp9CP5TizEN7nT2NVOT6e4Wm/OCXEZle0xuYCVo4OyLFsKX9zH7YB Tz+XToUNC5pYg2u6u9Brr+UwNOZZJUbPrEo74GM8LzMm929kcTFawhYjhfLOTGSEQQ/v hRg9OrQ+JcvaoSSjlHN0v4di8JarqQCI6O/HUrhyz6d/NXRUlaHwGmqZrQEuxdCQ62gx HhgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=mtpkdRFq; 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 f11-v6si15853399plr.316.2018.07.02.09.29.19; Mon, 02 Jul 2018 09:29: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; dkim=pass header.i=@resnulli-us.20150623.gappssmtp.com header.s=20150623 header.b=mtpkdRFq; 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 S1752378AbeGBQ23 (ORCPT + 99 others); Mon, 2 Jul 2018 12:28:29 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34109 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752211AbeGBQ21 (ORCPT ); Mon, 2 Jul 2018 12:28:27 -0400 Received: by mail-wr0-f196.google.com with SMTP id a12-v6so16165157wro.1 for ; Mon, 02 Jul 2018 09:28:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=MKsy6p8tA1MVGGjKEgjLbg9mT0zCvsdPl5efJmJPJBE=; b=mtpkdRFqZRVhKT2aT3Gm23614fUlhBy9N/wkwczr283oWhbz8yrO+Pno8FDlpCI7t1 8ph3BeUb5tZO0JK8eV4rFjFQ5tcP8CXtWVg85ANdgjmnl0yIOIHkpM7PeUxk+lZtEmhd 34H6ebQoQ7QiUddGVXBg8NBgO4xgCKpCPz7iuX8ud9NDtGHqwLCMSRVDemzSJoJGJT6l LuKVwHo0H/vzCjCOHdP6SPCe7gaVjE9YvLO4980CAzxxBtCObdULsJEoujdhnzaQeFB0 g9iQP3GNMOtp+0Qstlxvj0gb6fhU5mk+QBkdw1umLMi2c/iFPyDqX2UnsEhqIU1PzjLc TNhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=MKsy6p8tA1MVGGjKEgjLbg9mT0zCvsdPl5efJmJPJBE=; b=OpMWl0ApJ+2/3nl7LCgLMfxAc7rJblH9ICsUr2FCNNTLNdF93CV+AEVZLhA86GPIbA JB/F3DLWsG5JQ9roZxNzdU3lnYvJE6ByJoCukWh7+Mk17jScxPPcI2Z/s46CD2rvpOZ/ YuUX7rzOwrfb47Z69534dqeYba0R4YZ7aEc0NLvYL7RcxkCuQ5GdN01/QhAoHWQ1rRiO VMFXYQ55o0lHyxAkBAeYeaqtcbON1Wgp23u4HW+ntZ5bAkKciSKMkv5vxhUmkvSV3p0p g+UYRd2aQd1LpbPfAitwCv+oqdCwEoQJdvzp2aV7TDmYatIv7PFGFslWtyRiUOyXB2TY jqhg== X-Gm-Message-State: APt69E3aKIN3220uWlAmYdClne7YqzOFHGc6lixJhfrffsfZyslYBZLD kusg89QH3UPlFkvpIpOp74xOKA== X-Received: by 2002:adf:8796:: with SMTP id b22-v6mr20724568wrb.92.1530548905788; Mon, 02 Jul 2018 09:28:25 -0700 (PDT) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id u7-v6sm8736740wmd.3.2018.07.02.09.28.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Jul 2018 09:28:25 -0700 (PDT) Date: Mon, 2 Jul 2018 18:26:49 +0200 From: Jiri Pirko To: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jian-Hong Pan , Marcel Holtmann , "David S . Miller" , Matthias Brugger , Janus Piwek , Michael =?iso-8859-1?Q?R=F6der?= , Dollar Chen , Ken Yu Subject: Re: [RFC net-next 08/15] net: lora: sx1276: Add debugfs Message-ID: <20180702162649.GC2737@nanopsycho.orion> References: <20180701110804.32415-1-afaerber@suse.de> <20180701110804.32415-9-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180701110804.32415-9-afaerber@suse.de> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sun, Jul 01, 2018 at 01:07:57PM CEST, afaerber@suse.de wrote: >Allow some interactive inspection at runtime via debugfs. > >Signed-off-by: Andreas F?rber >--- > drivers/net/lora/sx1276.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 132 insertions(+) > >diff --git a/drivers/net/lora/sx1276.c b/drivers/net/lora/sx1276.c >index d6732111247a..1072019cfcc1 100644 >--- a/drivers/net/lora/sx1276.c >+++ b/drivers/net/lora/sx1276.c >@@ -5,6 +5,7 @@ > * Copyright (c) 2016-2018 Andreas F?rber > */ > >+#include > #include > #include > #include >@@ -61,6 +62,8 @@ struct sx1276_priv { > > struct workqueue_struct *wq; > struct work_struct tx_work; >+ >+ struct dentry *debugfs; > }; > > static int sx1276_read_single(struct spi_device *spi, u8 reg, u8 *val) >@@ -416,6 +419,128 @@ static const struct net_device_ops sx1276_netdev_ops = { > .ndo_start_xmit = sx1276_loradev_start_xmit, > }; > >+static ssize_t sx1276_freq_read(struct file *file, char __user *user_buf, >+ size_t count, loff_t *ppos) >+{ >+ struct net_device *netdev = file->private_data; >+ struct sx1276_priv *priv = netdev_priv(netdev); >+ struct spi_device *spi = priv->spi; >+ ssize_t size; >+ char *buf; >+ int ret; >+ u8 msb, mid, lsb; >+ u32 freq_xosc; >+ unsigned long long frf; >+ >+ ret = of_property_read_u32(spi->dev.of_node, "clock-frequency", &freq_xosc); >+ if (ret) >+ return 0; >+ >+ mutex_lock(&priv->spi_lock); >+ >+ ret = sx1276_read_single(spi, REG_FRF_MSB, &msb); >+ if (!ret) >+ ret = sx1276_read_single(spi, REG_FRF_MID, &mid); >+ if (!ret) >+ ret = sx1276_read_single(spi, REG_FRF_LSB, &lsb); >+ >+ mutex_unlock(&priv->spi_lock); >+ >+ if (ret) >+ return 0; >+ >+ frf = freq_xosc; >+ frf *= ((ulong)msb << 16) | ((ulong)mid << 8) | lsb; >+ frf /= (1 << 19); >+ >+ buf = kasprintf(GFP_KERNEL, "%llu\n", frf); >+ if (!buf) >+ return 0; >+ >+ size = simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); >+ kfree(buf); >+ >+ return size; >+} >+ >+static const struct file_operations sx1276_freq_fops = { >+ .owner = THIS_MODULE, >+ .open = simple_open, >+ .read = sx1276_freq_read, >+}; >+ >+static ssize_t sx1276_state_read(struct file *file, char __user *user_buf, >+ size_t count, loff_t *ppos) >+{ >+ struct net_device *netdev = file->private_data; >+ struct sx1276_priv *priv = netdev_priv(netdev); >+ struct spi_device *spi = priv->spi; >+ ssize_t size; >+ char *buf; >+ int len = 0; >+ int ret; >+ u8 val; >+ bool lora_mode = true; >+ const int max_len = 4096; >+ >+ buf = kzalloc(max_len, GFP_KERNEL); >+ if (!buf) >+ return 0; >+ >+ mutex_lock(&priv->spi_lock); >+ >+ ret = sx1276_read_single(spi, REG_OPMODE, &val); >+ if (!ret) { >+ len += snprintf(buf + len, max_len - len, "RegOpMode = 0x%02x\n", val); >+ lora_mode = (val & REG_OPMODE_LONG_RANGE_MODE) != 0; >+ } >+ >+ ret = sx1276_read_single(spi, REG_FRF_MSB, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegFrMsb = 0x%02x\n", val); >+ ret = sx1276_read_single(spi, REG_FRF_MID, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegFrMid = 0x%02x\n", val); >+ ret = sx1276_read_single(spi, REG_FRF_LSB, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegFrLsb = 0x%02x\n", val); >+ >+ ret = sx1276_read_single(spi, REG_PA_CONFIG, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegPaConfig = 0x%02x\n", val); >+ >+ if (lora_mode) { >+ ret = sx1276_read_single(spi, LORA_REG_IRQ_FLAGS_MASK, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegIrqFlagsMask = 0x%02x\n", val); >+ >+ ret = sx1276_read_single(spi, LORA_REG_IRQ_FLAGS, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegIrqFlags = 0x%02x\n", val); >+ >+ ret = sx1276_read_single(spi, LORA_REG_SYNC_WORD, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegSyncWord = 0x%02x\n", val); >+ } >+ >+ ret = sx1276_read_single(spi, REG_PA_DAC, &val); >+ if (!ret) >+ len += snprintf(buf + len, max_len - len, "RegPaDac = 0x%02x\n", val); >+ >+ mutex_unlock(&priv->spi_lock); >+ >+ size = simple_read_from_buffer(user_buf, count, ppos, buf, len); >+ kfree(buf); >+ >+ return size; >+} >+ >+static const struct file_operations sx1276_state_fops = { >+ .owner = THIS_MODULE, >+ .open = simple_open, >+ .read = sx1276_state_read, >+}; >+ > static int sx1276_probe(struct spi_device *spi) > { > struct net_device *netdev; >@@ -566,6 +691,10 @@ static int sx1276_probe(struct spi_device *spi) > return ret; > } > >+ priv->debugfs = debugfs_create_dir(dev_name(&spi->dev), NULL); >+ debugfs_create_file("state", S_IRUGO, priv->debugfs, netdev, &sx1276_state_fops); >+ debugfs_create_file("frequency", S_IRUGO, priv->debugfs, netdev, &sx1276_freq_fops); Hmm. These look like useful information not only for debugging. I think it would be worth to expose these via some standard uapi. Like generic netlink, similar to nl80211 >+ > dev_info(&spi->dev, "SX1276 module probed (SX%d)", model); > > return 0; >@@ -574,6 +703,9 @@ static int sx1276_probe(struct spi_device *spi) > static int sx1276_remove(struct spi_device *spi) > { > struct net_device *netdev = spi_get_drvdata(spi); >+ struct sx1276_priv *priv = netdev_priv(netdev); >+ >+ debugfs_remove_recursive(priv->debugfs); > > unregister_loradev(netdev); > free_loradev(netdev); >-- >2.16.4 >