From 302db9bb94ad26223e4eec23a52ff31361fdce05 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 8 Dec 2015 15:34:17 +0100 Subject: [PATCH] move debugfs code to common code Signed-off-by: Felix Fietkau --- Makefile | 2 +- debugfs.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ mt76.h | 4 ++++ mt7603_init.c | 2 ++ mt76x2.h | 2 -- mt76x2_debugfs.c | 25 +----------------------- 6 files changed, 57 insertions(+), 27 deletions(-) create mode 100644 debugfs.c diff --git a/Makefile b/Makefile index fbde0167..5efba43b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ EXTRA_CFLAGS += -Werror obj-m := mt76.o mt76x2e.o mt7603e.o mt76-y := \ - mmio.o util.o trace.o dma.o mac80211.o + mmio.o util.o trace.o dma.o mac80211.o debugfs.o mt76x2e-y := \ mt76x2_pci.o mt76x2_dma.o \ diff --git a/debugfs.c b/debugfs.c new file mode 100644 index 00000000..67a48228 --- /dev/null +++ b/debugfs.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Felix Fietkau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include "mt76.h" + +static int +mt76_reg_set(void *data, u64 val) +{ + struct mt76_dev *dev = data; + + dev->bus->wr(dev, dev->debugfs_reg, val); + return 0; +} + +static int +mt76_reg_get(void *data, u64 *val) +{ + struct mt76_dev *dev = data; + + *val = dev->bus->rr(dev, dev->debugfs_reg); + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n"); + + +struct dentry *mt76_register_debugfs(struct mt76_dev *dev) +{ + struct dentry *dir; + + dir = debugfs_create_dir("mt76", dev->hw->wiphy->debugfsdir); + if (!dir) + return NULL; + + debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg); + debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev, &fops_regval); + + return dir; +} +EXPORT_SYMBOL_GPL(mt76_register_debugfs); diff --git a/mt76.h b/mt76.h index 11979907..44ebb004 100644 --- a/mt76.h +++ b/mt76.h @@ -106,6 +106,8 @@ struct mt76_dev { struct ieee80211_supported_band sband_2g; struct ieee80211_supported_band sband_5g; + + u32 debugfs_reg; }; enum mt76_phy_type { @@ -160,4 +162,6 @@ static inline u16 mt76_rev(struct mt76_dev *dev) int mt76_register_device(struct mt76_dev *dev, int bands, bool vht, struct ieee80211_rate *rates, int n_rates); +struct dentry *mt76_register_debugfs(struct mt76_dev *dev); + #endif diff --git a/mt7603_init.c b/mt7603_init.c index d34aec64..590dd7cf 100644 --- a/mt7603_init.c +++ b/mt7603_init.c @@ -167,5 +167,7 @@ int mt7603_register_device(struct mt7603_dev *dev) sband = wiphy->bands[IEEE80211_BAND_2GHZ]; dev->chandef.chan = &sband->channels[0]; + mt76_register_debugfs(&dev->mt76); + return 0; } diff --git a/mt76x2.h b/mt76x2.h index 2e7bd506..23fd2c4a 100644 --- a/mt76x2.h +++ b/mt76x2.h @@ -164,8 +164,6 @@ struct mt76x2_dev { struct debugfs_blob_wrapper otp; struct mt76x2_hw_cap cap; - u32 debugfs_reg; - s8 target_power; s8 target_power_delta[2]; struct mt76x2_rate_power rate_power; diff --git a/mt76x2_debugfs.c b/mt76x2_debugfs.c index c40d4914..9e4b85d1 100644 --- a/mt76x2_debugfs.c +++ b/mt76x2_debugfs.c @@ -14,27 +14,6 @@ #include #include "mt76x2.h" -static int -mt76x2_reg_set(void *data, u64 val) -{ - struct mt76x2_dev *dev = data; - - mt76_wr(dev, dev->debugfs_reg, val); - return 0; -} - -static int -mt76x2_reg_get(void *data, u64 *val) -{ - struct mt76x2_dev *dev = data; - - *val = mt76_rr(dev, dev->debugfs_reg); - return 0; -} - -DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76x2_reg_get, mt76x2_reg_set, "0x%08llx\n"); - - static int mt76x2_ampdu_stat_read(struct seq_file *file, void *data) { @@ -106,7 +85,7 @@ void mt76x2_init_debugfs(struct mt76x2_dev *dev) { struct dentry *dir; - dir = debugfs_create_dir("mt76", mt76_hw(dev)->wiphy->debugfsdir); + dir = mt76_register_debugfs(&dev->mt76); if (!dir) return; @@ -114,8 +93,6 @@ void mt76x2_init_debugfs(struct mt76x2_dev *dev) debugfs_create_blob("otp", S_IRUSR, dir, &dev->otp); debugfs_create_u8("temperature", S_IRUSR, dir, &dev->cal.temp); - debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg); - debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev, &fops_regval); debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat); debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir, read_txpower); }