hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * Copyright (C) 2018 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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 <linux/debugfs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <wcn_bus.h>
 
#include "mdbg_type.h"
#include "../sleep/slp_mgr.h"
 
struct wcn_reg_ctl {
   unsigned int addr;
   unsigned int len;
   /* 1: rw_extended; 0:rw_direct */
   unsigned int rw_extended;
   /*
    * make sure sdio critical buf >512,
    * but the frame size is larger than 2048
    * bytes is not permission in kernel to android
    */
   unsigned int value[256];
};
 
static ssize_t read_wcn_reg(struct file *file, char __user *user_buf,
                size_t count, loff_t *ppos)
{
   struct wcn_reg_ctl reg_rd;
   int i;
 
   WCN_INFO("wsh __read_wcn_reg\n");
 
   if (copy_from_user(&reg_rd, user_buf, sizeof(reg_rd))) {
       WCN_ERR("reg value copy's ret value is -eFAULT\n");
       return -EFAULT;
   }
 
   /* rw_direct SDIO */
   if (reg_rd.rw_extended == 0) {
       for (i = 0; i < reg_rd.len; i++)
       sprdwcn_bus_aon_readb(reg_rd.addr + i,
                     (unsigned char *) &reg_rd.value[i]);
   } else {
       /* rw_extended reg */
       switch (reg_rd.len) {
       case 1:
           sprdwcn_bus_reg_read(reg_rd.addr, &reg_rd.value[0], 4);
           break;
       default:
           sprdwcn_bus_direct_read(reg_rd.addr, reg_rd.value,
                       reg_rd.len * 4);
           break;
       }
   }
 
 
   if (copy_to_user(user_buf, &reg_rd, sizeof(reg_rd))) {
       WCN_ERR("reg copy_to_user ret value is -eFAULT\n");
       return -EFAULT;
   }
 
   return count;
}
 
static ssize_t write_wcn_reg(struct file *file, const char __user *user_buf,
                 size_t count, loff_t *ppos)
{
   struct wcn_reg_ctl reg_wr;
   int i;
 
   WCN_INFO("wsh _write_wcn_reg\n");
   if (copy_from_user(&reg_wr, user_buf, sizeof(reg_wr))) {
       WCN_ERR("write_wcn_reg copy's ret value is -eFAULT\n");
       return -EFAULT;
   }
 
   /* rw_direct SDIO */
   if (reg_wr.rw_extended == 0) {
       for (i = 0; i < reg_wr.len; i++)
       sprdwcn_bus_aon_writeb(reg_wr.addr + i,
                      (unsigned char)reg_wr.value[i]);
   } else {
       /* rw_extended reg */
       switch (reg_wr.len) {
       case 1:
           sprdwcn_bus_reg_write(reg_wr.addr, &reg_wr.value[0], 4);
           break;
       default:
           sprdwcn_bus_direct_write(reg_wr.addr, reg_wr.value,
                        reg_wr.len * 4);
           break;
       }
   }
 
 
   return count;
 
}
 
static const struct file_operations reg_debug_fops = {
   .read = read_wcn_reg,
   .write = write_wcn_reg,
   .open = simple_open,
   .owner = THIS_MODULE,
   .llseek = default_llseek,
};
 
static int __init wcn_init_debugfs(void)
{
   struct dentry *ent, *root = debugfs_create_dir("wcn", NULL);
 
   if (!root)
       return -ENXIO;
 
   ent = debugfs_create_file("regctl", 0644,
                 (struct dentry *)root, NULL,
                 &reg_debug_fops);
   if (IS_ERR(ent))
       return PTR_ERR(ent);
 
   return 0;
}
 
device_initcall(wcn_init_debugfs);