aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wimax_cmc/firmware.c
blob: d31eb8cf357fd2b81799914334e35d32ddfa92a5 (plain)
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
 * firmware.c
 *
 * functions for Linux filesystem access
 * Firmware binary file is on the filesystem, read fild and send it through SDIO
 */
#include "firmware.h"
#include <linux/wimax/samsung/wimax732.h>

#define SEEK_SET	0
#define SEEK_CUR	1
#define SEEK_END	2
#define WIMAX_BAT_SYSPATH \
	"/sys/devices/platform/sec-battery/power_supply/battery/wimax"

/******************************************************************************
 *                           Library Functions
 ******************************************************************************/

/*!
 *************************************************************************
 * \brief	file open.
 *
 * user context.
 *
 * \return	file pointer, if error, return NULL.
 *************************************************************************/
struct file *klib_fopen(
		const char *filename,	/*!< filename to open */
		/*!< O_RDONLY, O_WRONLY, O_RDWR, O_CREAT,
		O_EXCL, O_TRUNC, O_APPEND, O_NONBLOCK, O_SYNC,...*/
		int flags,
		/*!< file creation permisstion. S_IRxxx
		S_IWxxx S_IXxxx (xxx=USR,GRP,OTH), S_IRWXx(x=U,G,O)*/
		int mode
		)
{
	struct file *filp = filp_open(filename, flags, mode);
	return (IS_ERR(filp)) ? NULL : filp;
}

/*!
 *************************************************************************
 * \brief	file close.
 *
 * user context.
 *
 * \return	none.
 *************************************************************************/
void klib_fclose(
		struct file *filp	/*!< file pointer */
		)
{
	if (filp)
		fput(filp);
}

/*!
 *************************************************************************
 * \brief	move file pointer to the request.
 *
 * user context
 * do not support SEEK_END
 * no boundary check (file position may exceed file size).
 *
 * \return	.
 *************************************************************************/
int klib_fseek(
		struct file *filp,	/*!< file pointer */
		int offset,		/*!<  */
		int whence		/*!< SEEK_SET, SEEK_CUR */
		)
{
	int pos = filp->f_pos;

	if (filp) {
		if (whence == SEEK_SET)
			pos = offset;

		else if (whence == SEEK_CUR)
			pos += offset;

		if (pos < 0)
			pos = 0;

		filp->f_pos = pos;
		return pos;
	} else
		return -ENOENT;
}



/*!
 *************************************************************************
 * \brief	file read function.
 *
 * user context.
 *
 * \return	actually read number, 0 = EOF, negative = error.
 *************************************************************************/
int
klib_fread(
		char *buf,		/*!< buffer to read into */
		int len,		/*!< number of bytes to read */
		struct file *filp	/*!< file pointer */
		)
{
	int readlen;
	mm_segment_t oldfs;

	if (filp == NULL) {
		printk(KERN_INFO "filp == NULL\n");
		return -ENOENT;
	}

	if (filp->f_op->read == NULL) {
		printk(KERN_INFO "filp->f_op->read == NULL\n");
		return -ENOSYS;
	}

	if (((filp->f_flags & O_ACCMODE) & O_RDONLY) != 0) {
		printk(KERN_INFO "((filp->f_flags & O_ACCMODE) & O_RDONLY) != 0\n");
		return -EACCES;
	}

	oldfs = get_fs();
	set_fs(KERNEL_DS);
	readlen = filp->f_op->read(filp, buf, len, &filp->f_pos);
	set_fs(oldfs);

	return readlen;
}

int klib_flen_fcopy(char *buf, int len, struct file *filp)
{
	int readlen;
	mm_segment_t oldfs;

	oldfs = get_fs();
	set_fs(KERNEL_DS);
	readlen = filp->f_op->read(filp, buf, len, &filp->f_pos);
	set_fs(oldfs);

	return readlen;
}

/*!
 *************************************************************************
 * \brief	.
 *
 * user context.
 *
 * \return	read character, EOF if end of file.
 *************************************************************************/
int klib_fgetc(
		struct file *filp	/*!< file pointer */
		)
{
	int len;
	u_char buf[4];

	len = klib_fread((char *)buf, 1, filp);
	if (len > 0)
		return buf[0];
	else if (len == 0)
		return -1;
	else
		return len;
}

/*!
 *************************************************************************
 * \brief	to get the length of file.
 *
 * detailed decrtiption.
 *
 * \return	.
 *************************************************************************/
int klib_flength(
		struct file *filp	/*!< file pointer */
		)
{
	int total_len = 0;
	int buf;

	do {
		buf = klib_fgetc(filp);
		if (buf == -1)
			break;
		total_len++;
	} while (1);

	klib_fseek(filp, 0, SEEK_SET);

	return total_len;
}

/*!
 *************************************************************************
 * \brief	file write function.
 *
 * user context.
 *
 * \return	actually write number, 0 = EOF, negative = error.
 *************************************************************************/
int klib_fwrite(
		char *buf,			/*!< buffer to write into */
		int len,			/*!< number of bytes to write */
		struct file *filp		/*!< file pointer */
		)
{
	int writelen;
	mm_segment_t oldfs;

	if (filp == NULL) {
		printk(KERN_INFO "filp == NULL\n");
		return -ENOENT;
	}

	if (filp->f_op->write == NULL) {
		printk(KERN_INFO "filp->f_op->write == NULL\n");
		return -ENOSYS;
	}

	oldfs = get_fs();
	set_fs(KERNEL_DS);
	writelen = filp->f_op->write(filp, buf, len, &filp->f_pos);
	set_fs(oldfs);

	return writelen;
}

void s3c_bat_use_wimax(int onoff)
{
	struct file     *fp;
	fp = klib_fopen(WIMAX_BAT_SYSPATH, O_RDWR, 0);

	if (!fp)
		pr_err("open fail");
	if (onoff)
			klib_fwrite("1", 1, fp);
	else
		klib_fwrite("0", 1, fp);
		klib_fclose(fp);
}
EXPORT_SYMBOL(s3c_bat_use_wimax);