From ee6fb222f647a8799778eae09d68a4b4bd2f985b Mon Sep 17 00:00:00 2001 From: Colleen Twitty Date: Mon, 12 Aug 2013 15:05:22 -0700 Subject: [PATCH] mvl8787: add debugfs for reading from scratch register --- drivers/net/wireless/mwl8787/Makefile | 2 +- drivers/net/wireless/mwl8787/debugfs.c | 69 ++++++++++++++++++++++++++ drivers/net/wireless/mwl8787/main.c | 1 + drivers/net/wireless/mwl8787/mwl8787.h | 1 + drivers/net/wireless/mwl8787/sdio.c | 21 ++++++++ drivers/net/wireless/mwl8787/sdio.h | 5 ++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 drivers/net/wireless/mwl8787/debugfs.c diff --git a/drivers/net/wireless/mwl8787/Makefile b/drivers/net/wireless/mwl8787/Makefile index 3d5546e84fe2..418d6060ca9b 100644 --- a/drivers/net/wireless/mwl8787/Makefile +++ b/drivers/net/wireless/mwl8787/Makefile @@ -1,4 +1,4 @@ -mwl8787_sdio-objs := main.o tx.o rx.o cmd.o sdio.o scan.o event.o +mwl8787_sdio-objs := main.o tx.o rx.o cmd.o sdio.o scan.o event.o debugfs.o mwl8787_sdio-$(CONFIG_NL80211_TESTMODE) += testmode.o obj-$(CONFIG_MWL8787) += mwl8787_sdio.o diff --git a/drivers/net/wireless/mwl8787/debugfs.c b/drivers/net/wireless/mwl8787/debugfs.c new file mode 100644 index 000000000000..72fce006280c --- /dev/null +++ b/drivers/net/wireless/mwl8787/debugfs.c @@ -0,0 +1,69 @@ +#include +#include "mwl8787.h" +#include "sdio.h" + +static ssize_t +mwl8787_scratch_read(struct file *file, char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct mwl8787_priv *priv = + (struct mwl8787_priv *) file->private_data; + + char buf[17] = {}; + int pos = 0, ret = 0; + u64 reg_value; + + /* read scratch reg */ + ret = mwl8787_read_scratch_area(priv, ®_value); + + if (ret) { + ret = -EINVAL; + goto done; + } + + pos += snprintf(buf, sizeof(buf), "%016llx\n", reg_value); + + ret = simple_read_from_buffer(ubuf, count, ppos, buf, pos); +done: + return ret; +} + +#define MWL8787_DFS_ADD_FILE(name) \ + debugfs_create_file(#name, 0644, priv->dfs_dev_dir, \ + priv, &mwl8787_dfs_##name##_fops); \ + + +#define MWL8787_DFS_FILE_READ_OPS(name) \ +static const struct file_operations mwl8787_dfs_##name##_fops = { \ + .read = mwl8787_##name##_read, \ + .open = simple_open, \ +}; + +MWL8787_DFS_FILE_READ_OPS(scratch); + +/* + * This function creates the debugfs directory and files. + */ +void +mwl8787_dev_debugfs_init(struct mwl8787_priv *priv) +{ + if (!priv) + return; + + priv->dfs_dev_dir = debugfs_create_dir("mwl8787", + priv->hw->wiphy->debugfsdir); + + MWL8787_DFS_ADD_FILE(scratch); +} + +/* + * This function removes the debugfs directory and files + */ +void +mwl8787_dev_debugfs_remove(struct mwl8787_priv *priv) +{ + if (!priv) + return; + + debugfs_remove_recursive(priv->dfs_dev_dir); +} diff --git a/drivers/net/wireless/mwl8787/main.c b/drivers/net/wireless/mwl8787/main.c index f56bf4e855ad..8774b8893ee8 100644 --- a/drivers/net/wireless/mwl8787/main.c +++ b/drivers/net/wireless/mwl8787/main.c @@ -4,6 +4,7 @@ #include "mwl8787.h" #include "fw.h" +#include "sdio.h" #define CREATE_TRACE_POINTS #include "trace.h" diff --git a/drivers/net/wireless/mwl8787/mwl8787.h b/drivers/net/wireless/mwl8787/mwl8787.h index 3fa218a3bccd..fdb91fd0b596 100644 --- a/drivers/net/wireless/mwl8787/mwl8787.h +++ b/drivers/net/wireless/mwl8787/mwl8787.h @@ -67,6 +67,7 @@ struct mwl8787_priv struct sk_buff_head tx_queue; struct ieee80211_channel *channel; + struct dentry *dfs_dev_dir; /* sdio */ u32 ioport; diff --git a/drivers/net/wireless/mwl8787/sdio.c b/drivers/net/wireless/mwl8787/sdio.c index 5944cfae943c..1e12a40a1659 100644 --- a/drivers/net/wireless/mwl8787/sdio.c +++ b/drivers/net/wireless/mwl8787/sdio.c @@ -135,6 +135,23 @@ mwl8787_sdio_poll_card_status(struct mwl8787_priv *priv, u8 bits) return -1; } +/* + * This function reads the scratch area used by firmware to report error codes. + */ +int mwl8787_read_scratch_area(struct mwl8787_priv *priv, u64 *dat) +{ + u32 i; + u8 scrch; + + for (i = 0; i < MWL8787_REG_SCRATCH_LEN; i++) { + if (mwl8787_read_reg(priv, MWL8787_REG_SCRATCH_START + i, &scrch)) + return -1; + *dat = ((*dat << 8) | scrch); + } + + return 0; +} + /* * This function reads the firmware status. */ @@ -930,6 +947,9 @@ static void mwl8787_fw_cb(const struct firmware *fw, void *context) /* FW loaded, so register with mac80211 */ ret = mwl8787_register(priv); + + /* create debugfs */ + mwl8787_dev_debugfs_init(priv); if (ret) goto disable; @@ -1012,6 +1032,7 @@ static void mwl8787_sdio_remove(struct sdio_func *func) sdio_release_host(func); kfree(priv->mp_regs); + mwl8787_dev_debugfs_remove(priv); mwl8787_free(priv); } diff --git a/drivers/net/wireless/mwl8787/sdio.h b/drivers/net/wireless/mwl8787/sdio.h index 2267401afe5a..42d26375a06c 100644 --- a/drivers/net/wireless/mwl8787/sdio.h +++ b/drivers/net/wireless/mwl8787/sdio.h @@ -116,10 +116,15 @@ #define MWL8787_REG_POLL 0x30 #define MWL8787_REG_STATUS_0 0x60 #define MWL8787_REG_STATUS_1 0x61 +#define MWL8787_REG_SCRATCH_START 0x62 +#define MWL8787_REG_SCRATCH_LEN 0x8 #define MWL8787_REG_CARD_MISC_CFG 0x6c #define MWL8787_SDIO_BLOCK_SIZE 256 +int mwl8787_read_scratch_area(struct mwl8787_priv *priv, u64 *dat); +void mwl8787_dev_debugfs_init(struct mwl8787_priv *priv); +void mwl8787_dev_debugfs_remove(struct mwl8787_priv *priv); enum mwl8787_sdio_type { MWL8787_TYPE_DATA = 0,