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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/*
* Copyright 2012 WonderMedia Technologies, Inc. All Rights Reserved.
*
* This PROPRIETARY SOFTWARE is the property of WonderMedia Technologies, Inc.
* and may contain trade secrets and/or other confidential information of
* WonderMedia Technologies, Inc. This file shall not be disclosed to any third party,
* in whole or in part, without prior written consent of WonderMedia.
*
* THIS PROPRIETARY SOFTWARE AND ANY RELATED DOCUMENTATION ARE PROVIDED AS IS,
* WITH ALL FAULTS, AND WITHOUT WARRANTY OF ANY KIND EITHER EXPRESS OR IMPLIED,
* AND WonderMedia TECHNOLOGIES, INC. DISCLAIMS ALL EXPRESS OR IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*/
#include <linux/module.h> /* Specifically, a module */
#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
#include <linux/uaccess.h> //for copy_from_user
#include <linux/pwm.h>
#include <mach/hardware.h>//WMT_MMAP_OFFSET
#define procfs_name "bt_test"
int skip = 0x00;
extern struct proc_dir_entry proc_root;
//extern void mt_bt_power_off(void);
//extern int mt_bt_power_on(void);
/**
* This structure hold information about the /proc file
*
*/
struct proc_dir_entry *Our_Proc_test;
extern void dump_uart_info(void);
static int procfile_read(char *buffer,
char **buffer_location,
off_t offset, int buffer_length, int *eof, void *data)
{
int ret = 0;
/*
* We give all of our information in one go, so if the
* user asks us if we have more information the
* answer should always be no.
*
* This is important because the standard read
* function from the library would continue to issue
* the read system call until the kernel replies
* that it has no more information, or until its
* buffer is filled.
*/
printk("enter dump\n");
dump_uart_info();
return ret;
}
//configure pwm1 pin
void config_pwm1_pin1(int enable)
{
int val;
if(enable) {
val = readb(0xd8110200+WMT_MMAP_OFFSET);
val &= ~(1 << 7);
writeb(val, 0xd8110200+WMT_MMAP_OFFSET);
}else{
val = readb(0xd8110200+WMT_MMAP_OFFSET);
val |= (1 << 7);
writeb(val, 0xd8110200+WMT_MMAP_OFFSET);
}
}
static struct pwm_device * g_pwm1 =NULL;
void enable_pwm1_32KHz1(int enable)
{
static int first = 0x01;
if(first) {
first = 0x00;
printk("begint ot pwm request\n");
g_pwm1 = pwm_request(0x01,"mtk6622 bluetooth 32KHz");
if(!g_pwm1){
printk("can not request pwm1 for bluetooth mtk6622\n");
return;
}
}
if(enable) {
pwm_config(g_pwm1, 15625, 31250);
pwm_enable(g_pwm1);
printk("enable 32khz output\n");
}else{
pwm_disable(g_pwm1);
printk("disable 32khz output\n");
}
}
/*
*this funciton just for facilitate debugging
*command formater: echo "digital strings" > /proc/usb_serail
* setenv wmt.6620.pmu "e3:3:D8110040:D8110080:D81100c0:D81100c4:D81100c8"
* saveenv
*/
static int procfile_write(struct file *file, const char __user *buffer,
unsigned long count, void *data)
{
char tmp[128];
char printbuf[128];
int num;
int option;
if(buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
num = sscanf(tmp, "%d", &option);
printk("your input: option:%d\n",option);
switch(option) {
case 0: //power off bluetooth
//mt_bt_power_off();
break;
case 1: //power on bluetooth chip
//mt_bt_power_on();
break;
case 2: //open bluetooth interruption
//mt_bt_enable_irq();
break;
case 3: //close bluetooth interruption
//mt_bt_disable_irq();
break;
case 4: //enable 32KHz
//config_pwm1_pin1(1);
//enable_pwm1_32KHz1(1);
pwm_32KHZ_control(1);
break;
case 5: //disable 32KHz
//enable_pwm1_32KHz1(0);
pwm_32KHZ_control(0);
break;
default:
printk("test command,for example: echo 1 > /proc/bt_test\n");
}
return strlen(tmp);
}else{
printk("copy_from_user failed or buffer is null\n");
}
}
int test_skeleton_proc_init(void)
{
printk("enter test_skeleton_proc_init\n");
Our_Proc_test = create_proc_entry(procfs_name, 0644, NULL);
if (Our_Proc_test == NULL) {
//remove_proc_entry(procfs_name, &proc_root);
printk(KERN_ALERT "Error: Could not initialize /proc/%s\n",
procfs_name);
return -ENOMEM;
}
Our_Proc_test->read_proc = procfile_read;
Our_Proc_test->write_proc = procfile_write;
// //Our_Proc_test->owner = THIS_MODULE;
// Our_Proc_test->mode = S_IFREG | S_IRUGO;
// Our_Proc_test->uid = 0;
// Our_Proc_test->gid = 0;
// Our_Proc_test->size = 37; //size what is its mean ?
return 0; /* everything is ok */
}
int deinit_proc_init(void)
{
if(Our_Proc_test != NULL){
remove_proc_entry(procfs_name,NULL);
Our_Proc_test = NULL;
}
return 0;
}
EXPORT_SYMBOL(test_skeleton_proc_init);
|