aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/isdbt/fc8100/fc8100.c
blob: 1d4a7a358045262cf692d21c0fcf0cb8dbcd7b59 (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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/miscdevice.h>

#include <asm/uaccess.h>
#include <asm/io.h>

#include <linux/delay.h>
#include <linux/gpio.h>

#include <plat/gpio-cfg.h>
#include <plat/gpio-core.h>
#include <mach/regs-gpio.h>
#include <mach/gpio.h>

#include "fc8100.h"
#include "bbm.h"
#include "fci_oal.h"

#define FC8100_NAME		"isdbt"

int dmb_open (struct inode *inode, struct file *filp);
loff_t dmb_llseek (struct file *filp, loff_t off, int whence);
ssize_t dmb_read (struct file *filp, char *buf, size_t count, loff_t *f_pos);
ssize_t dmb_write (struct file *filp, const char *buf, size_t count, loff_t *f_pos);
static long dmb_ioctl (struct file *filp, unsigned int cmd, unsigned long arg);
int dmb_release (struct inode *inode, struct file *filp);

/* GPIO Setting */
void dmb_hw_setting(void);
void dmb_hw_init(void);
void dmb_hw_deinit(void);

static struct file_operations dmb_fops = {
	.owner		= THIS_MODULE,
	.llseek		= dmb_llseek,
	.read		= dmb_read,
	.write		= dmb_write,
	.unlocked_ioctl		= dmb_ioctl,
	.open		= dmb_open,
	.release	= dmb_release,
};

static struct miscdevice fc8100_misc_device = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = FC8100_NAME,
    .fops = &dmb_fops,
};

int dmb_open (struct inode *inode, struct file *filp)
{
	int num = MINOR(inode->i_rdev);

	/* ISDBT PWR ENABLE  FOR I2C*/
	dmb_hw_setting();
	dmb_hw_init();

	PRINTF(0, "dmb open -> minor : %d\n", num);

	return 0;
}

loff_t dmb_llseek (struct file *filp, loff_t off, int whence)
{
	PRINTF(0, "dmb llseek -> off : %08X, whence : %08X\n", off, whence);
	return 0x23;
}

ssize_t dmb_read (struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
	PRINTF(0, "dmb read -> buf : %08X, count : %08X \n", buf, count);
	return 0x33;
}

ssize_t dmb_write (struct file *filp, const char *buf, size_t count, loff_t *f_pos)
{
	PRINTF(0, "dmb write -> buf : %08X, count : %08X \n", buf, count);
	return 0x43;
}

static long dmb_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
{
	s32 res = BBM_NOK;
	int status = 0;
	int status_usr = 0;
	ioctl_info info;
	int size;

	if (_IOC_TYPE(cmd) != IOCTL_MAGIC)
			return -EINVAL;
	if (_IOC_NR(cmd) >= IOCTL_MAXNR)
			return -EINVAL;

	size = _IOC_SIZE(cmd);

	switch (cmd) {
		case IOCTL_DMB_RESET:
			res = BBM_RESET(0);
			break;
		case IOCTL_DMB_INIT:
			res = BBM_INIT(0);
			break;
		case IOCTL_DMB_BYTE_READ:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_BYTE_READ(0, (u16)info.buff[0], (u8 *)(&info.buff[1]));
			status_usr = copy_to_user((void *)arg, (void *)&info, size);
			break;
		case IOCTL_DMB_WORD_READ:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_WORD_READ(0, (u16)info.buff[0], (u16 *)(&info.buff[1]));
			status_usr = copy_to_user((void *)arg, (void *)&info, size);
			break;
		case IOCTL_DMB_LONG_READ:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_LONG_READ(0, (u16)info.buff[0], (u32 *)(&info.buff[1]));
			status_usr = copy_to_user((void *)arg, (void *)&info, size);
			break;
		case IOCTL_DMB_BULK_READ:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_BULK_READ(0, (u16)info.buff[0], (u8 *)(&info.buff[2]), info.buff[1]);
			status_usr = copy_to_user((void *)arg, (void *)&info, size);
			break;
		case IOCTL_DMB_BYTE_WRITE:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_BYTE_WRITE(0, (u16)info.buff[0], (u8)info.buff[1]);
			break;
		case IOCTL_DMB_WORD_WRITE:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_WORD_WRITE(0, (u16)info.buff[0], (u16)info.buff[1]);
			break;
		case IOCTL_DMB_LONG_WRITE:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_LONG_WRITE(0, (u16)info.buff[0], (u32)info.buff[1]);
			break;
		case IOCTL_DMB_BULK_WRITE:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_BULK_WRITE(0, (u16)info.buff[0], (u8 *)(&info.buff[2]), info.buff[1]);
			break;
		case IOCTL_DMB_TUNER_SELECT:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_TUNER_SELECT(0, (u32)info.buff[0], 0);
			break;
		case IOCTL_DMB_TUNER_READ:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_TUNER_READ(0, (u8)info.buff[0], (u8)info.buff[1],  (u8 *)(&info.buff[3]), (u8)info.buff[2]);
			status_usr = copy_to_user((void *)arg, (void *)&info, size);
			break;
		case IOCTL_DMB_TUNER_WRITE:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_TUNER_WRITE(0, (u8)info.buff[0], (u8)info.buff[1], (u8 *)(&info.buff[3]), (u8)info.buff[2]);
			break;
		case IOCTL_DMB_TUNER_SET_FREQ:
			status = copy_from_user((void *)&info, (void *)arg, size);
			res = BBM_TUNER_SET_FREQ(0, (u8)info.buff[0]);
			break;
		case IOCTL_DMB_POWER_ON:
			PRINTF(0, "DMB_POWER_ON enter..\n");
			dmb_hw_init();
			break;
		case IOCTL_DMB_POWER_OFF:
			PRINTF(0, "DMB_POWER_OFF enter..\n");
			dmb_hw_deinit();
			break;
	}
	if ((status < 0) || (status_usr < 0)) {
		PRINTF(0, " copy to user or copy from user : ERROR..\n");
		return -EINVAL;
	}

	/* return status */
	if (res < 0)
			res = -BBM_NOK;
	else
			res = BBM_OK;

	return res;
}

int dmb_release(struct inode *inode, struct file *filp)
{
	/* ISDBT PWR ENABLE  FOR I2C*/
	PRINTF(0, "dmb release\n");
	return 0;
}

void dmb_hw_setting(void)
{
	s3c_gpio_cfgpin(GPIO_ISDBT_SDA_28V, S3C_GPIO_INPUT);
	s3c_gpio_setpull(GPIO_ISDBT_SDA_28V, S3C_GPIO_PULL_NONE);
	s3c_gpio_cfgpin(GPIO_ISDBT_SCL_28V, S3C_GPIO_INPUT);
	s3c_gpio_setpull(GPIO_ISDBT_SCL_28V, S3C_GPIO_PULL_NONE);
	s3c_gpio_cfgpin(GPIO_ISDBT_PWR_EN, S3C_GPIO_OUTPUT);
	gpio_set_value(GPIO_ISDBT_PWR_EN, GPIO_LEVEL_LOW);
	s3c_gpio_cfgpin(GPIO_ISDBT_RST, S3C_GPIO_OUTPUT);
	gpio_set_value(GPIO_ISDBT_RST, GPIO_LEVEL_HIGH);
}

void dmb_init_hw_setting(void)
{
	s3c_gpio_cfgpin(GPIO_ISDBT_SDA_28V, S3C_GPIO_INPUT);
	s3c_gpio_setpull(GPIO_ISDBT_SDA_28V, S3C_GPIO_PULL_NONE);
	s3c_gpio_cfgpin(GPIO_ISDBT_SCL_28V, S3C_GPIO_INPUT);
	s3c_gpio_setpull(GPIO_ISDBT_SCL_28V, S3C_GPIO_PULL_NONE);
	s3c_gpio_cfgpin(GPIO_ISDBT_PWR_EN, S3C_GPIO_OUTPUT);
	gpio_set_value(GPIO_ISDBT_PWR_EN, GPIO_LEVEL_LOW);
	s3c_gpio_cfgpin(GPIO_ISDBT_RST, S3C_GPIO_OUTPUT);
	gpio_set_value(GPIO_ISDBT_RST, GPIO_LEVEL_LOW);
}

void dmb_hw_init(void)
{
	mdelay(1);
	gpio_set_value(GPIO_ISDBT_PWR_EN, GPIO_LEVEL_HIGH);
	mdelay(1);
	gpio_set_value(GPIO_ISDBT_RST, GPIO_LEVEL_HIGH);
	mdelay(100);
}

void dmb_hw_deinit(void)
{
	mdelay(1);
	gpio_set_value(GPIO_ISDBT_RST, GPIO_LEVEL_LOW);
	mdelay(1);
	gpio_set_value(GPIO_ISDBT_PWR_EN, GPIO_LEVEL_LOW);
	mdelay(100);
}


int dmb_init(void)
{
	int result;

	PRINTF(0, "dmb dmb_init\n");

	dmb_init_hw_setting();
/*
	dmb_hw_init();
*/
	/*misc device registration*/
	result = misc_register(&fc8100_misc_device);

	if (result < 0)
		return result;

	BBM_HOSTIF_SELECT(0, BBM_I2C);

	dmb_hw_deinit();

	return 0;
}

void dmb_exit(void)
{
	PRINTF(0, "dmb dmb_exit\n");

	BBM_HOSTIF_DESELECT(0);
	dmb_hw_deinit();

	/*misc device deregistration*/
	misc_deregister(&fc8100_misc_device);
}

module_init(dmb_init);
module_exit(dmb_exit);

MODULE_LICENSE("Dual BSD/GPL");