2f5e75be8a305162a7ef65befa092cc514e2b791
[openwrt/staging/nbd.git] / package / kernel / mac80211 / patches / ath9k / 500-ath9k_eeprom_debugfs.patch
1 --- a/drivers/net/wireless/ath/ath9k/debug.c
2 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3 @@ -1413,6 +1413,54 @@ void ath9k_deinit_debug(struct ath_softc
4 ath9k_cmn_spectral_deinit_debug(&sc->spec_priv);
5 }
6
7 +static ssize_t read_file_eeprom(struct file *file, char __user *user_buf,
8 + size_t count, loff_t *ppos)
9 +{
10 + struct ath_softc *sc = file->private_data;
11 + struct ath_hw *ah = sc->sc_ah;
12 + struct ath_common *common = ath9k_hw_common(ah);
13 + int bytes = 0;
14 + int pos = *ppos;
15 + int size = 4096;
16 + u16 val;
17 + int i;
18 +
19 + if (AR_SREV_9300_20_OR_LATER(ah))
20 + size = 16384;
21 +
22 + if (*ppos < 0)
23 + return -EINVAL;
24 +
25 + if (count > size - *ppos)
26 + count = size - *ppos;
27 +
28 + for (i = *ppos / 2; count > 0; count -= bytes, *ppos += bytes, i++) {
29 + void *from = &val;
30 +
31 + if (!common->bus_ops->eeprom_read(common, i, &val))
32 + val = 0xffff;
33 +
34 + if (*ppos % 2) {
35 + from++;
36 + bytes = 1;
37 + } else if (count == 1) {
38 + bytes = 1;
39 + } else {
40 + bytes = 2;
41 + }
42 + if (copy_to_user(user_buf, from, bytes))
43 + return -EFAULT;
44 + user_buf += bytes;
45 + }
46 + return *ppos - pos;
47 +}
48 +
49 +static const struct file_operations fops_eeprom = {
50 + .read = read_file_eeprom,
51 + .open = simple_open,
52 + .owner = THIS_MODULE
53 +};
54 +
55 int ath9k_init_debug(struct ath_hw *ah)
56 {
57 struct ath_common *common = ath9k_hw_common(ah);
58 @@ -1432,6 +1480,8 @@ int ath9k_init_debug(struct ath_hw *ah)
59 ath9k_tx99_init_debug(sc);
60 ath9k_cmn_spectral_init_debug(&sc->spec_priv, sc->debug.debugfs_phy);
61
62 + debugfs_create_file("eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
63 + &fops_eeprom);
64 debugfs_create_devm_seqfile(sc->dev, "dma", sc->debug.debugfs_phy,
65 read_file_dma);
66 debugfs_create_devm_seqfile(sc->dev, "interrupt", sc->debug.debugfs_phy,