1 /*drivers/cir/bu92747guw_cir.c - driver for bu92747guw
3 * Copyright (C) 2010 ROCKCHIP, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 #include <linux/interrupt.h>
15 #include <linux/slab.h>
16 #include <linux/irq.h>
17 #include <linux/gpio.h>
18 #include <asm/uaccess.h>
19 #include <linux/workqueue.h>
20 #include <linux/module.h>
21 #include <linux/i2c.h>
22 #include <linux/platform_device.h>
23 #include <linux/types.h>
24 #include <linux/bcd.h>
25 #include <linux/spinlock.h>
27 #include <linux/delay.h>
28 #include <linux/wakelock.h>
29 #include <linux/miscdevice.h>
30 #include <linux/freezer.h>
31 #include <mach/gpio.h>
32 #include <mach/iomux.h>
33 #include <mach/rk29_smc.h>
35 #include "bu92747guw_cir.h"
38 #define BU92747_DBG(x...) printk(x)
40 #define BU92747_DBG(x...)
43 #define CIR_IIC_SPEED 100 * 1000
45 #define XIN_INPUT_FREQ 48*1000 //KHz
47 struct bu92747_data_info {
48 struct bu92747guw_platform_data *platdata;
49 struct i2c_client *client;
54 struct delayed_work dwork;
57 static struct miscdevice bu92747guw_device;
61 //mutex lock between remote and irda
62 static DEFINE_MUTEX(bu92747_mutex);
63 void bu92747_lock(void)
65 mutex_lock(&bu92747_mutex);
67 void bu92747_unlock(void)
69 mutex_unlock(&bu92747_mutex);
76 static int bu92747_cir_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf, int len)
79 ret = i2c_master_reg8_recv(client, reg, buf, len, CIR_IIC_SPEED);
83 static int bu92747_cir_i2c_set_regs(struct i2c_client *client, u8 reg, u8 *buf, int len)
86 ret = i2c_master_reg8_send(client, reg, buf, len, CIR_IIC_SPEED);
91 static int bu92747_stop(struct i2c_client *client)
94 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
95 //BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
96 printk("line %d: enter %s\n", __LINE__, __FUNCTION__);
97 // disable_irq(bu92747->irq);
98 //diable clk, repeat=1
99 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 2);
100 reg_value[0] = reg_value[0]&0xfe;
101 reg_value[1] = reg_value[1]&0xf1;
102 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 2);
105 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
109 static void bu92747_dwork_handler(struct work_struct *work)
111 struct bu92747_data_info *bu92747 =
112 (struct bu92747_data_info *)container_of(work, struct bu92747_data_info, dwork.work);
115 BU92747_DBG("------- sss enter %s\n", __func__);
117 if ((repeat_flag != -10) && (repeat_flag <= -1)){
118 bu92747_stop(bu92747->client);
119 BU92747_DBG("----------exit %s\n", __func__);
124 bu92747_cir_i2c_read_regs(bu92747->client, REG_SETTING1, reg_value, 1);
125 reg_value[0] &= 0xf0;
126 bu92747_cir_i2c_set_regs(bu92747->client, REG_SETTING1, reg_value, 1);
127 //printk("----------exit %s reg_value = %d\n", __func__, reg_value[1]);
132 bu92747_cir_i2c_set_regs(bu92747->client, REG_SEND, reg_value, 1);
133 // bu92747_cir_i2c_read_regs(bu92747->client, REG_FRMLEN1, reg_value, 2);
135 // printk("frame_interval = 0x%x\n", reg_value[1], reg_value[2]);
138 BU92747_DBG("----------exit %s\n", __func__);
143 static irqreturn_t bu92747_cir_irq(int irq, void *dev_id)
146 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
147 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
149 BU92747_DBG("----------enter %s repeat_flag = %d\n", __func__, repeat_flag);
152 if (start_flag == 1){
153 if (repeat_flag == -10){
154 if ((bu92747->state++)%10 == 0){
155 schedule_delayed_work(&bu92747->dwork, msecs_to_jiffies(0));
158 }else if (((--repeat_flag%16) == 0) || (repeat_flag < 0)){
159 schedule_delayed_work(&bu92747->dwork, msecs_to_jiffies(0));
168 static int bu92747_send_data(struct i2c_client *client, struct rk29_cir_struct_info *cir)
171 unsigned int hlo, hhi;
174 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
175 struct bu92747guw_platform_data *pdata = bu92747->platdata;
176 int sys_clock = bu92747->sys_clock;
179 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
180 //if (bu92747->state == BU92747_BUSY) {
181 // printk("line %d, func: %s, dev is busy now\n", __LINE__, __func__);
185 //bu92747->state = BU92747_BUSY;
187 repeat_flag = cir->repeat%16;
189 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 2);
191 inv0 = cir->inv & 0x01;
192 inv1 = (cir->inv>>1) & 0x01;
193 reg_value[0] = reg_value[0] | (inv0<<1) | (inv1<<2);
194 reg_value[1] = (reg_value[1]&0xf0) | (repeat_flag&0x0f);
195 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 2);
196 BU92747_DBG("inv0 = %d, inv1 = %d, repeat=%d\n", inv0, inv1, repeat_flag);
198 //head maybe different while repeat
199 if ((bu92747->head_burst_time!=cir->head_burst_time)
200 || (bu92747->head_space_time!=cir->head_space_time)) {
201 hlo = (cir->head_space_time*sys_clock)/1000;
202 hhi = (cir->head_burst_time*sys_clock)/1000;
203 reg_value[0] = hlo>>8;
204 reg_value[1] = hlo&0xff;
205 reg_value[2] = hhi>>8;
206 reg_value[3] = hhi&0xff;
207 bu92747_cir_i2c_set_regs(client, REG_HLO1, reg_value, 4);
208 BU92747_DBG("hlo = 0x%x, hhi = 0x%x\n", hlo, hhi);
211 //switch to remote control
215 reg_value[0] = cir->frame_bit_len;
216 bu92747_cir_i2c_set_regs(client, REG_BITLEN, reg_value, 1);
217 BU92747_DBG("frame_bit_len = 0x%x\n", cir->frame_bit_len);
220 nByte = (cir->frame_bit_len+7)/8;
221 for (i=0; i<nByte; i++) {
222 reg_value[i] = ((cir->frame)>>(8*i))&0xff;
223 BU92747_DBG("reg_value[%d] = %d\n", i, reg_value[i]);
225 bu92747_cir_i2c_set_regs(client, REG_OUT0, reg_value, nByte);
226 BU92747_DBG("nByte = %d\n", nByte);
228 //clear irq, start send
231 //bu92747_cir_i2c_set_regs(client, REG_IRQC, reg_value, 2);
234 // while (gpio_get_value(pdata->intr_pin)) {
235 // BU92747_DBG("line %d: data register is not null\n", __LINE__);
238 //switch to irda control
239 //smc0_write(3, smc0_read(3) & 0xfbff);
242 //enable_irq(bu92747->irq);
244 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
252 static int bu92747_set_format(struct i2c_client *client, struct rk29_cir_struct_info *cir)
255 unsigned int clo, chi, clo_org, chi_org;
256 unsigned int d0lo, d0hi, d1lo, d1hi;
258 unsigned int hlo = cir->carry_low , hhi = cir->carry_high;
263 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
264 int sys_clock = bu92747->sys_clock;
266 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
272 inv0 = cir->inv & 0x01;
273 inv1 = (cir->inv>>1) & 0x01;
274 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 3);
275 reg_value[0] = reg_value[0] | (inv0<<1) | (inv1<<2);
276 //bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 1);
277 BU92747_DBG("inv0 = %d, inv1 = %d\n", inv0, inv1);
280 repeat_flag = cir->repeat;
281 printk("repeat 11111 =%d\n", repeat_flag);
283 if (repeat_flag == -1){
286 }else if (repeat_flag > 16){
289 repeat = repeat_flag;
292 repeat = repeat % 16;
293 reg_value[1] = ((reg_value[1]&0xf0) | (repeat&0x0f));
297 clo = XIN_INPUT_FREQ / 3000 * hlo;
298 chi = XIN_INPUT_FREQ / 3000 * hhi;
299 reg_value[3] = clo>>8;
300 reg_value[4] = clo&0xff;
301 reg_value[5] = chi>>8;
302 reg_value[6] = chi&0xff;
303 BU92747_DBG("clo = 0x%x, chi = 0x%x\n", clo, chi);
304 //bu92747_cir_i2c_set_regs(client, REG_CLO1, reg_value, 4);
309 hlo = (cir->head_space_time*sys_clock)/1000;
310 hhi = (cir->head_burst_time*sys_clock)/1000;
311 reg_value[7] = hlo>>8;
312 reg_value[8] = hlo&0xff;
313 reg_value[9] = hhi>>8;
314 reg_value[10] = hhi&0xff;
315 BU92747_DBG("hlo = 0x%x, hhi = 0x%x\n", hlo, hhi);
319 d0lo = (cir->logic_low_space_time*sys_clock)/1000;
320 d0hi = (cir->logic_low_burst_time*sys_clock)/1000;
321 reg_value[11] = d0lo>>8;
322 reg_value[12] = d0lo&0xff;
323 reg_value[13] = d0hi>>8;
324 reg_value[14] = d0hi&0xff;
325 BU92747_DBG("d0lo = 0x%x, d0hi = 0x%x\n", d0lo, d0hi);
329 d1lo = (cir->logic_high_space_time*sys_clock)/1000;
330 d1hi = (cir->logic_high_burst_time*sys_clock)/1000;
331 reg_value[15] = d1lo>>8;
332 reg_value[16] = d1lo&0xff;
333 reg_value[17] = d1hi>>8;
334 reg_value[18] = d1hi&0xff;
335 BU92747_DBG("d1lo = 0x%x, d1hi = 0x%x\n", d1lo, d1hi);
338 end = (cir->stop_bit_interval*sys_clock)/1000;
339 reg_value[19] = end>>8;
340 reg_value[20] = end&0xff;
341 //bu92747_cir_i2c_set_regs(client, REG_CLO1, reg_value, 18);
343 BU92747_DBG("end = 0x%x\n", end);
347 reg_value[21] = cir->frame_bit_len;
348 BU92747_DBG("frame_bit_len = 0x%x\n", cir->frame_bit_len);
351 frame_interval = (cir->frame_interval*sys_clock)/1000;
352 reg_value[22] = frame_interval>>8;
353 reg_value[23] = frame_interval&0xff;
354 //bu92747_cir_i2c_set_regs(client, REG_FRMLEN1, reg_value, 2);
355 BU92747_DBG("cir->frame_interval =%d frame_interval = %d\n\n", cir->frame_interval,frame_interval);
359 nByte = (cir->frame_bit_len+7)/8;
360 for (i=0; i<nByte; i++) {
361 reg_value[24+i] = ((cir->frame)>>(8*i))&0xff;
362 BU92747_DBG("reg_value[%d] = %d\n", 24+i, reg_value[24+i]);
365 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 24+i);
368 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
375 static int bu92747_start(struct i2c_client *client)
378 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
379 printk("line %d: enter %s\n", __LINE__, __FUNCTION__);
383 //enable_irq(bu92747->irq);
385 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 1);
386 reg_value[0] = reg_value[0]|0x01;
387 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 1);
389 //clear irq, start send
392 bu92747_cir_i2c_set_regs(client, REG_IRQC, reg_value, 2);
395 printk("line %d: exit %s\n", __LINE__, __FUNCTION__);
400 static void bu92747_printk_cir(struct rk29_cir_struct_info *cir)
402 BU92747_DBG("\ncir struct:\n");
403 BU92747_DBG("carry_high = %d\n", cir->carry_high);
404 BU92747_DBG("carry_low = %d\n", cir->carry_low);
405 BU92747_DBG("repeat = %d\n", cir->repeat);
406 BU92747_DBG("inv = %d\n", cir->inv);
407 BU92747_DBG("frame_bit_len = %d\n", cir->frame_bit_len);
408 BU92747_DBG("stop_bit_interval = %d\n", cir->stop_bit_interval);
409 BU92747_DBG("frame = %lld\n", cir->frame);
410 BU92747_DBG("frame_interval = %d\n", cir->frame_interval);
411 BU92747_DBG("head_burst_time = %d\n", cir->head_burst_time);
412 BU92747_DBG("head_space_time = %d\n", cir->head_space_time);
413 BU92747_DBG("logic_high_burst_time = %d\n", cir->logic_high_burst_time);
414 BU92747_DBG("logic_high_space_time = %d\n", cir->logic_high_space_time);
415 BU92747_DBG("logic_low_burst_time = %d\n", cir->logic_low_burst_time);
416 BU92747_DBG("logic_low_space_time = %d\n", cir->logic_low_space_time);
421 static int bu92747_set_duration(struct i2c_client *client, struct rk29_cir_struct_info *cir)
426 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
427 int sys_clock = bu92747->sys_clock;
429 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
434 BU92747_DBG("sys_clock = %d, frame_interval = 0x%x\n", sys_clock,cir->frame_interval);
436 frame_interval = (cir->frame_interval*sys_clock)/1000;
438 reg_value[0] = frame_interval>>8;
439 reg_value[1] = frame_interval&0xff;
440 bu92747_cir_i2c_set_regs(client, REG_FRMLEN1, reg_value, 2);
442 BU92747_DBG("frame_interval = 0x%x\n", frame_interval);
444 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
450 static int bu92747_set_data(struct i2c_client *client, struct rk29_cir_struct_info *cir)
458 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
461 reg_value[0] = cir->frame_bit_len;
462 bu92747_cir_i2c_set_regs(client, REG_BITLEN, reg_value, 1);
463 BU92747_DBG("frame_bit_len = 0x%x\n", cir->frame_bit_len);
466 nByte = (cir->frame_bit_len+7)/8;
467 for (i=0; i<nByte; i++) {
468 reg_value[i] = ((cir->frame)>>(8*i))&0xff;
469 BU92747_DBG("reg_value[%d] = %d\n", i, reg_value[i]);
471 bu92747_cir_i2c_set_regs(client, REG_OUT0, reg_value, nByte);
472 BU92747_DBG("nByte = %d\n", nByte);
475 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
480 static int bu92747_set_pulse(struct i2c_client *client, struct rk29_cir_struct_info *cir)
485 unsigned int d0lo, d0hi, d1lo, d1hi;
488 u8 reg_value[8] = {0};
489 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
490 int sys_clock = bu92747->sys_clock;
492 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
498 inv0 = cir->inv & 0x01;
499 inv1 = (cir->inv>>1) & 0x01;
500 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 1);
501 reg_value[0] = reg_value[0] | (inv0<<1) | (inv1<<2);
502 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 1);
503 BU92747_DBG("inv0 = %d, inv1 = %d\n", inv0, inv1);
508 d0lo = (cir->logic_low_space_time*sys_clock)/1000;
509 d0hi = (cir->logic_low_burst_time*sys_clock)/1000;
510 reg_value[0] = d0lo>>8;
511 reg_value[1] = d0lo&0xff;
512 reg_value[2] = d0hi>>8;
513 reg_value[3] = d0hi&0xff;
514 BU92747_DBG("d0lo = 0x%x, d0hi = 0x%x\n", d0lo, d0hi);
517 d1lo = (cir->logic_high_space_time*sys_clock)/1000;
518 d1hi = (cir->logic_high_burst_time*sys_clock)/1000;
519 reg_value[4] = d1lo>>8;
520 reg_value[5] = d1lo&0xff;
521 reg_value[6] = d1hi>>8;
522 reg_value[7] = d1hi&0xff;
523 BU92747_DBG("d1lo = 0x%x, d1hi = 0x%x\n", d1lo, d1hi);
524 bu92747_cir_i2c_set_regs(client, REG_D0LO1, reg_value, 8);
526 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
534 static int bu92747_set_parameter(struct i2c_client *client, struct rk29_cir_struct_info *cir)
536 unsigned int hlo, hhi;
540 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
541 int sys_clock = bu92747->sys_clock;
543 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
549 hlo = (cir->head_space_time*sys_clock)/1000;
550 hhi = (cir->head_burst_time*sys_clock)/1000;
551 reg_value[0] = hlo>>8;
552 reg_value[1] = hlo&0xff;
553 reg_value[2] = hhi>>8;
554 reg_value[3] = hhi&0xff;
555 BU92747_DBG("hlo = 0x%x, hhi = 0x%x\n", hlo, hhi);
556 bu92747_cir_i2c_set_regs(client, REG_HLO1, reg_value, 4);
559 end = (cir->stop_bit_interval*sys_clock)/1000;
560 reg_value[0] = end>>8;
561 reg_value[1] = end&0xff;
562 bu92747_cir_i2c_set_regs(client, REG_ENDLEN1, reg_value, 2);
564 BU92747_DBG("end = 0x%x\n", end);
566 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
573 static int bu92747_set_repeat(struct i2c_client *client, struct rk29_cir_struct_info *cir)
579 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
582 repeat_flag = cir->repeat;
583 printk("repeat 11111 =%d\n", repeat_flag);
585 if (repeat_flag == -1){
588 }else if (repeat_flag > 16){
591 repeat = repeat_flag;
595 repeat = repeat % 16;
597 bu92747_cir_i2c_read_regs(client, REG_SETTING1, reg_value, 1);
599 reg_value[0] = (reg_value[0]&0xf0) | (repeat&0x0f);
600 bu92747_cir_i2c_set_regs(client, REG_SETTING1, reg_value, 1);
601 printk("repeat 2222 =%d reg_value = %d\n", repeat, reg_value[0]);
603 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
608 static int bu92747_set_carrier(struct i2c_client *client, struct rk29_cir_struct_info *cir)
611 u16 clo = 0, chi = 0;
612 unsigned int hlo = cir->carry_low , hhi = cir->carry_high;
614 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
621 clo = XIN_INPUT_FREQ / 3000 * hlo;
622 chi = XIN_INPUT_FREQ / 3000 * hhi;
623 reg_value[0] = clo>>8;
624 reg_value[1] = clo&0xff;
625 reg_value[2] = chi>>8;
626 reg_value[3] = chi&0xff;
627 BU92747_DBG("clo = 0x%x, chi = 0x%x\n", clo, chi);
628 bu92747_cir_i2c_set_regs(client, REG_CLO1, reg_value, 4);
630 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
637 static int bu92747_cir_init_device(struct i2c_client *client, struct bu92747_data_info *bu92747)
641 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
643 //transmission buff null intertupt, base clock div, irq enable, clock power up
644 //reg_value[0] = /*REG0_OPM | */REG0_DIVS | REG0_PWR | REG0_IRQE;
645 reg_value[0] = /*REG0_OPM | */REG0_DIVS | REG0_IRQE;
646 reg_value[1] = REG1_FRME | REG1_RPT; //enable frame interval, repeat = 1
647 reg_value[2] = 80; //base clock = 100KHz
648 BU92747_DBG("line %d: reg0=0x%x, reg1=0x%x, reg2=0x%x\n", __LINE__, reg_value[0], reg_value[1], reg_value[2]);
649 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 3);
650 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 3);
651 BU92747_DBG("line %d: reg0=0x%x, reg1=0x%x, reg2=0x%x\n", __LINE__, reg_value[0], reg_value[1], reg_value[2]);
653 bu92747->base_clock = 100; //KHz
654 bu92747->sys_clock = bu92747->base_clock;
656 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
661 static int bu92747_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
663 void __user *argp = (void __user *)arg;
664 char msg[CIR_FRAME_SIZE];
666 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
668 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
673 case BU92747_IOCTL_START:
674 ret = bu92747_start(client);
679 case BU92747_IOCTL_STOP:
680 ret = bu92747_stop(client);
685 case BU92747_IOCTL_PULSE:
686 if (copy_from_user(&msg, argp, sizeof(msg)))
689 //bu92747_printk_cir((struct rk29_cir_struct_info *)msg);
690 ret = bu92747_set_pulse(client, (struct rk29_cir_struct_info *)msg);
695 case BU92747_IOCTL_DATA:
696 if (copy_from_user(&msg, argp, sizeof(msg)))
698 ret = bu92747_set_data(client, (struct rk29_cir_struct_info *)msg);
703 case BU92747_IOCTL_CARRIER:
704 if (copy_from_user(&msg, argp, sizeof(msg)))
706 ret = bu92747_set_carrier(client, (struct rk29_cir_struct_info *)msg);
710 case BU92747_IOCTL_REPEAT:
711 if (copy_from_user(&msg, argp, sizeof(msg)))
713 ret = bu92747_set_repeat(client, (struct rk29_cir_struct_info *)msg);
718 case BU92747_IOCTL_DURATION:
719 if (copy_from_user(&msg, argp, sizeof(msg)))
721 ret = bu92747_set_duration(client, (struct rk29_cir_struct_info *)msg);
725 case BU92747_IOCTL_PARAMETER:
726 if (copy_from_user(&msg, argp, sizeof(msg)))
729 ret = bu92747_set_parameter(client, (struct rk29_cir_struct_info *)msg);
733 case BU92747_IOCTL_FORMATE:
734 if (copy_from_user(&msg, argp, sizeof(msg)))
737 ret = bu92747_set_format(client, (struct rk29_cir_struct_info *)msg);
747 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
752 static int bu92747_open(struct inode *inode, struct file *file)
754 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
755 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
756 struct bu92747guw_platform_data *pdata = bu92747->platdata;
758 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
760 printk("bu92747_open\n");
762 // if (BU92747_OPEN == bu92747->state)
764 // bu92747->state = BU92747_OPEN;
767 if (pdata && pdata->cir_pwr_ctl) {
768 pdata->cir_pwr_ctl(1);
771 //switch to remote control, mcr, ec_en=1,rc_mode=1
772 smc0_write(REG_MCR_ADDR, smc0_read(REG_MCR_ADDR)|(3<<10));
773 //set irda pwdownpin = 0
774 smc0_write(REG_TRCR_ADDR, smc0_read(REG_TRCR_ADDR)&0xffbf);
775 BU92747_DBG("irda power down pin = %d\n", gpio_get_value(RK29_PIN5_PA7));
778 bu92747_cir_init_device(client, bu92747);
780 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
785 static int bu92747_release(struct inode *inode, struct file *file)
787 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
788 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
789 struct bu92747guw_platform_data *pdata = bu92747->platdata;
791 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
794 if (pdata && pdata->cir_pwr_ctl) {
795 pdata->cir_pwr_ctl(0);
798 // bu92747->state = BU92747_CLOSE;
800 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
805 static struct file_operations bu92747_fops = {
806 .owner = THIS_MODULE,
807 .open = bu92747_open,
808 .release = bu92747_release,
809 .ioctl = bu92747_ioctl,
812 static struct miscdevice bu92747guw_device = {
813 .minor = MISC_DYNAMIC_MINOR,
815 .fops = &bu92747_fops,
818 static int __devinit bu92747_cir_probe(struct i2c_client *client, const struct i2c_device_id *id)
820 struct bu92747_data_info *bu92747;
821 struct bu92747guw_platform_data *pdata;
824 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
826 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
829 bu92747 = kzalloc(sizeof(struct bu92747_data_info), GFP_KERNEL);
831 printk("line %d: bu92747 alloc data failed.\n", __LINE__);
836 pdata = client->dev.platform_data;
837 if (pdata && pdata->iomux_init) {
841 bu92747->platdata = pdata;
842 bu92747->client = client;
843 i2c_set_clientdata(client, bu92747);
844 bu92747->state = BU92747_CLOSE;
847 bu92747guw_device.parent = &client->dev;
848 err = misc_register(&bu92747guw_device);
850 printk("line %d: bu92747 misc_register failed.\n", __LINE__);
855 if (pdata && gpio_is_valid(pdata->intr_pin)) {
856 printk("-------request irq\n");
857 err = gpio_request(pdata->intr_pin, "rk29 cir irq");
859 printk("line %d: bu92747 request gpio failed.\n", __LINE__);
862 gpio_direction_input(pdata->intr_pin);
863 gpio_request(RK29_PIN5_PA7, NULL);
865 printk("line %d: bu92747 request gpio failed.\n", __LINE__);
867 gpio_direction_input(RK29_PIN5_PA7);
868 bu92747->irq = gpio_to_irq(pdata->intr_pin);
869 err = request_irq(bu92747->irq, bu92747_cir_irq, IRQF_TRIGGER_FALLING, client->dev.driver->name, bu92747);
871 BU92747_DBG("line %d: bu92747 request gpio failed.\n", __LINE__);
874 //disable_irq(bu92747->irq);
877 //INIT_DELAYED_WORK(&bu92747->dwork, bu92747_dwork_handler);
878 INIT_DELAYED_WORK(&bu92747->dwork, bu92747_dwork_handler);
882 //bu92747_start(client);
884 //bu92747_send_data_test(client);
885 //BU92747_DBG("line %d: test %s\n", __LINE__, __FUNCTION__);
890 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
894 gpio_free(pdata->intr_pin);
896 misc_deregister(&bu92747guw_device);
898 if (pdata && pdata->iomux_deinit)
899 pdata->iomux_deinit();
905 static int __devexit bu92747_cir_remove(struct i2c_client *client)
908 struct bu92747_data_info *bu92747 = i2c_get_clientdata(client);
909 struct bu92747guw_platform_data *pdata = bu92747->platdata;
911 printk(" cir_remove \n");
913 free_irq(bu92747->irq, bu92747);
914 gpio_free(pdata->intr_pin);
915 misc_deregister(&bu92747guw_device);
916 if (pdata && pdata->iomux_deinit)
917 pdata->iomux_deinit();
922 static const struct i2c_device_id bu92747_cir_id[] = {
923 { "bu92747_cir", 0 },
926 MODULE_DEVICE_TABLE(i2c, bu92747_cir_id);
928 static struct i2c_driver bu92747_cir_driver = {
930 .name = "bu92747_cir",
931 .owner = THIS_MODULE,
933 .probe = bu92747_cir_probe,
934 .remove = __devexit_p(bu92747_cir_remove),
935 .id_table = bu92747_cir_id,
938 static int __init bu92747_cir_init(void)
940 return i2c_add_driver(&bu92747_cir_driver);
943 static void __exit bu92747_cir_exit(void)
945 i2c_del_driver(&bu92747_cir_driver);
948 MODULE_AUTHOR("zyw zyw@rock-chips.com");
949 MODULE_DESCRIPTION("bu92747 cir driver");
950 MODULE_LICENSE("GPL");
952 module_init(bu92747_cir_init);
953 module_exit(bu92747_cir_exit);