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;
62 static int bu92747_cir_i2c_read_regs(struct i2c_client *client, u8 reg, u8 *buf, int len)
65 ret = i2c_master_reg8_recv(client, reg, buf, len, CIR_IIC_SPEED);
69 static int bu92747_cir_i2c_set_regs(struct i2c_client *client, u8 reg, u8 *buf, int len)
72 ret = i2c_master_reg8_send(client, reg, buf, len, CIR_IIC_SPEED);
77 static int bu92747_stop(struct i2c_client *client)
80 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
81 //BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
82 printk("line %d: enter %s\n", __LINE__, __FUNCTION__);
83 // disable_irq(bu92747->irq);
84 //diable clk, repeat=1
85 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 2);
86 reg_value[0] = reg_value[0]&0xfe;
87 reg_value[1] = reg_value[1]&0xf1;
88 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 2);
91 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
95 static void bu92747_dwork_handler(struct work_struct *work)
97 struct bu92747_data_info *bu92747 =
98 (struct bu92747_data_info *)container_of(work, struct bu92747_data_info, dwork.work);
101 BU92747_DBG("------- sss enter %s\n", __func__);
103 if ((repeat_flag != -10) && (repeat_flag <= -1)){
104 bu92747_stop(bu92747->client);
105 BU92747_DBG("----------exit %s\n", __func__);
110 bu92747_cir_i2c_read_regs(bu92747->client, REG_SETTING1, reg_value, 1);
111 reg_value[0] &= 0xf0;
112 bu92747_cir_i2c_set_regs(bu92747->client, REG_SETTING1, reg_value, 1);
113 //printk("----------exit %s reg_value = %d\n", __func__, reg_value[1]);
118 bu92747_cir_i2c_set_regs(bu92747->client, REG_SEND, reg_value, 1);
119 // bu92747_cir_i2c_read_regs(bu92747->client, REG_FRMLEN1, reg_value, 2);
121 // printk("frame_interval = 0x%x\n", reg_value[1], reg_value[2]);
124 BU92747_DBG("----------exit %s\n", __func__);
129 static irqreturn_t bu92747_cir_irq(int irq, void *dev_id)
132 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
133 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
135 BU92747_DBG("----------enter %s repeat_flag = %d\n", __func__, repeat_flag);
138 if (start_flag == 1){
139 if (repeat_flag == -10){
140 if ((bu92747->state++)%10 == 0){
141 schedule_delayed_work(&bu92747->dwork, msecs_to_jiffies(0));
144 }else if (((--repeat_flag%16) == 0) || (repeat_flag < 0)){
145 schedule_delayed_work(&bu92747->dwork, msecs_to_jiffies(0));
154 static int bu92747_send_data(struct i2c_client *client, struct rk29_cir_struct_info *cir)
157 unsigned int hlo, hhi;
160 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
161 struct bu92747guw_platform_data *pdata = bu92747->platdata;
162 int sys_clock = bu92747->sys_clock;
165 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
166 //if (bu92747->state == BU92747_BUSY) {
167 // printk("line %d, func: %s, dev is busy now\n", __LINE__, __func__);
171 //bu92747->state = BU92747_BUSY;
173 repeat_flag = cir->repeat%16;
175 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 2);
177 inv0 = cir->inv & 0x01;
178 inv1 = (cir->inv>>1) & 0x01;
179 reg_value[0] = reg_value[0] | (inv0<<1) | (inv1<<2);
180 reg_value[1] = (reg_value[1]&0xf0) | (repeat_flag&0x0f);
181 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 2);
182 BU92747_DBG("inv0 = %d, inv1 = %d, repeat=%d\n", inv0, inv1, repeat_flag);
184 //head maybe different while repeat
185 if ((bu92747->head_burst_time!=cir->head_burst_time)
186 || (bu92747->head_space_time!=cir->head_space_time)) {
187 hlo = (cir->head_space_time*sys_clock)/1000;
188 hhi = (cir->head_burst_time*sys_clock)/1000;
189 reg_value[0] = hlo>>8;
190 reg_value[1] = hlo&0xff;
191 reg_value[2] = hhi>>8;
192 reg_value[3] = hhi&0xff;
193 bu92747_cir_i2c_set_regs(client, REG_HLO1, reg_value, 4);
194 BU92747_DBG("hlo = 0x%x, hhi = 0x%x\n", hlo, hhi);
197 //switch to remote control
201 reg_value[0] = cir->frame_bit_len;
202 bu92747_cir_i2c_set_regs(client, REG_BITLEN, reg_value, 1);
203 BU92747_DBG("frame_bit_len = 0x%x\n", cir->frame_bit_len);
206 nByte = (cir->frame_bit_len+7)/8;
207 for (i=0; i<nByte; i++) {
208 reg_value[i] = ((cir->frame)>>(8*i))&0xff;
209 BU92747_DBG("reg_value[%d] = %d\n", i, reg_value[i]);
211 bu92747_cir_i2c_set_regs(client, REG_OUT0, reg_value, nByte);
212 BU92747_DBG("nByte = %d\n", nByte);
214 //clear irq, start send
217 //bu92747_cir_i2c_set_regs(client, REG_IRQC, reg_value, 2);
220 // while (gpio_get_value(pdata->intr_pin)) {
221 // BU92747_DBG("line %d: data register is not null\n", __LINE__);
224 //switch to irda control
225 //smc0_write(3, smc0_read(3) & 0xfbff);
228 //enable_irq(bu92747->irq);
230 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
238 static int bu92747_set_format(struct i2c_client *client, struct rk29_cir_struct_info *cir)
241 unsigned int clo, chi, clo_org, chi_org;
242 unsigned int d0lo, d0hi, d1lo, d1hi;
244 unsigned int hlo = cir->carry_low , hhi = cir->carry_high;
249 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
250 int sys_clock = bu92747->sys_clock;
252 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
258 inv0 = cir->inv & 0x01;
259 inv1 = (cir->inv>>1) & 0x01;
260 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 3);
261 reg_value[0] = reg_value[0] | (inv0<<1) | (inv1<<2);
262 //bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 1);
263 BU92747_DBG("inv0 = %d, inv1 = %d\n", inv0, inv1);
266 repeat_flag = cir->repeat;
267 printk("repeat 11111 =%d\n", repeat_flag);
269 if (repeat_flag == -1){
272 }else if (repeat_flag > 16){
275 repeat = repeat_flag;
278 repeat = repeat % 16;
279 reg_value[1] = ((reg_value[1]&0xf0) | (repeat&0x0f));
283 clo = XIN_INPUT_FREQ / 3000 * hlo;
284 chi = XIN_INPUT_FREQ / 3000 * hhi;
285 reg_value[3] = clo>>8;
286 reg_value[4] = clo&0xff;
287 reg_value[5] = chi>>8;
288 reg_value[6] = chi&0xff;
289 BU92747_DBG("clo = 0x%x, chi = 0x%x\n", clo, chi);
290 //bu92747_cir_i2c_set_regs(client, REG_CLO1, reg_value, 4);
295 hlo = (cir->head_space_time*sys_clock)/1000;
296 hhi = (cir->head_burst_time*sys_clock)/1000;
297 reg_value[7] = hlo>>8;
298 reg_value[8] = hlo&0xff;
299 reg_value[9] = hhi>>8;
300 reg_value[10] = hhi&0xff;
301 BU92747_DBG("hlo = 0x%x, hhi = 0x%x\n", hlo, hhi);
305 d0lo = (cir->logic_low_space_time*sys_clock)/1000;
306 d0hi = (cir->logic_low_burst_time*sys_clock)/1000;
307 reg_value[11] = d0lo>>8;
308 reg_value[12] = d0lo&0xff;
309 reg_value[13] = d0hi>>8;
310 reg_value[14] = d0hi&0xff;
311 BU92747_DBG("d0lo = 0x%x, d0hi = 0x%x\n", d0lo, d0hi);
315 d1lo = (cir->logic_high_space_time*sys_clock)/1000;
316 d1hi = (cir->logic_high_burst_time*sys_clock)/1000;
317 reg_value[15] = d1lo>>8;
318 reg_value[16] = d1lo&0xff;
319 reg_value[17] = d1hi>>8;
320 reg_value[18] = d1hi&0xff;
321 BU92747_DBG("d1lo = 0x%x, d1hi = 0x%x\n", d1lo, d1hi);
324 end = (cir->stop_bit_interval*sys_clock)/1000;
325 reg_value[19] = end>>8;
326 reg_value[20] = end&0xff;
327 //bu92747_cir_i2c_set_regs(client, REG_CLO1, reg_value, 18);
329 BU92747_DBG("end = 0x%x\n", end);
333 reg_value[21] = cir->frame_bit_len;
334 BU92747_DBG("frame_bit_len = 0x%x\n", cir->frame_bit_len);
337 frame_interval = (cir->frame_interval*sys_clock)/1000;
338 reg_value[22] = frame_interval>>8;
339 reg_value[23] = frame_interval&0xff;
340 //bu92747_cir_i2c_set_regs(client, REG_FRMLEN1, reg_value, 2);
341 BU92747_DBG("cir->frame_interval =%d frame_interval = %d\n\n", cir->frame_interval,frame_interval);
345 nByte = (cir->frame_bit_len+7)/8;
346 for (i=0; i<nByte; i++) {
347 reg_value[24+i] = ((cir->frame)>>(8*i))&0xff;
348 BU92747_DBG("reg_value[%d] = %d\n", 24+i, reg_value[24+i]);
351 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 24+i);
354 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
361 static int bu92747_start(struct i2c_client *client)
364 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
365 printk("line %d: enter %s\n", __LINE__, __FUNCTION__);
369 //enable_irq(bu92747->irq);
371 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 1);
372 reg_value[0] = reg_value[0]|0x01;
373 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 1);
375 //clear irq, start send
378 bu92747_cir_i2c_set_regs(client, REG_IRQC, reg_value, 2);
381 printk("line %d: exit %s\n", __LINE__, __FUNCTION__);
386 static void bu92747_printk_cir(struct rk29_cir_struct_info *cir)
388 BU92747_DBG("\ncir struct:\n");
389 BU92747_DBG("carry_high = %d\n", cir->carry_high);
390 BU92747_DBG("carry_low = %d\n", cir->carry_low);
391 BU92747_DBG("repeat = %d\n", cir->repeat);
392 BU92747_DBG("inv = %d\n", cir->inv);
393 BU92747_DBG("frame_bit_len = %d\n", cir->frame_bit_len);
394 BU92747_DBG("stop_bit_interval = %d\n", cir->stop_bit_interval);
395 BU92747_DBG("frame = %lld\n", cir->frame);
396 BU92747_DBG("frame_interval = %d\n", cir->frame_interval);
397 BU92747_DBG("head_burst_time = %d\n", cir->head_burst_time);
398 BU92747_DBG("head_space_time = %d\n", cir->head_space_time);
399 BU92747_DBG("logic_high_burst_time = %d\n", cir->logic_high_burst_time);
400 BU92747_DBG("logic_high_space_time = %d\n", cir->logic_high_space_time);
401 BU92747_DBG("logic_low_burst_time = %d\n", cir->logic_low_burst_time);
402 BU92747_DBG("logic_low_space_time = %d\n", cir->logic_low_space_time);
407 static int bu92747_set_duration(struct i2c_client *client, struct rk29_cir_struct_info *cir)
412 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
413 int sys_clock = bu92747->sys_clock;
415 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
420 BU92747_DBG("sys_clock = %d, frame_interval = 0x%x\n", sys_clock,cir->frame_interval);
422 frame_interval = (cir->frame_interval*sys_clock)/1000;
424 reg_value[0] = frame_interval>>8;
425 reg_value[1] = frame_interval&0xff;
426 bu92747_cir_i2c_set_regs(client, REG_FRMLEN1, reg_value, 2);
428 BU92747_DBG("frame_interval = 0x%x\n", frame_interval);
430 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
436 static int bu92747_set_data(struct i2c_client *client, struct rk29_cir_struct_info *cir)
444 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
447 reg_value[0] = cir->frame_bit_len;
448 bu92747_cir_i2c_set_regs(client, REG_BITLEN, reg_value, 1);
449 BU92747_DBG("frame_bit_len = 0x%x\n", cir->frame_bit_len);
452 nByte = (cir->frame_bit_len+7)/8;
453 for (i=0; i<nByte; i++) {
454 reg_value[i] = ((cir->frame)>>(8*i))&0xff;
455 BU92747_DBG("reg_value[%d] = %d\n", i, reg_value[i]);
457 bu92747_cir_i2c_set_regs(client, REG_OUT0, reg_value, nByte);
458 BU92747_DBG("nByte = %d\n", nByte);
461 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
466 static int bu92747_set_pulse(struct i2c_client *client, struct rk29_cir_struct_info *cir)
471 unsigned int d0lo, d0hi, d1lo, d1hi;
474 u8 reg_value[8] = {0};
475 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
476 int sys_clock = bu92747->sys_clock;
478 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
484 inv0 = cir->inv & 0x01;
485 inv1 = (cir->inv>>1) & 0x01;
486 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 1);
487 reg_value[0] = reg_value[0] | (inv0<<1) | (inv1<<2);
488 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 1);
489 BU92747_DBG("inv0 = %d, inv1 = %d\n", inv0, inv1);
494 d0lo = (cir->logic_low_space_time*sys_clock)/1000;
495 d0hi = (cir->logic_low_burst_time*sys_clock)/1000;
496 reg_value[0] = d0lo>>8;
497 reg_value[1] = d0lo&0xff;
498 reg_value[2] = d0hi>>8;
499 reg_value[3] = d0hi&0xff;
500 BU92747_DBG("d0lo = 0x%x, d0hi = 0x%x\n", d0lo, d0hi);
503 d1lo = (cir->logic_high_space_time*sys_clock)/1000;
504 d1hi = (cir->logic_high_burst_time*sys_clock)/1000;
505 reg_value[4] = d1lo>>8;
506 reg_value[5] = d1lo&0xff;
507 reg_value[6] = d1hi>>8;
508 reg_value[7] = d1hi&0xff;
509 BU92747_DBG("d1lo = 0x%x, d1hi = 0x%x\n", d1lo, d1hi);
510 bu92747_cir_i2c_set_regs(client, REG_D0LO1, reg_value, 8);
512 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
520 static int bu92747_set_parameter(struct i2c_client *client, struct rk29_cir_struct_info *cir)
522 unsigned int hlo, hhi;
526 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
527 int sys_clock = bu92747->sys_clock;
529 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
535 hlo = (cir->head_space_time*sys_clock)/1000;
536 hhi = (cir->head_burst_time*sys_clock)/1000;
537 reg_value[0] = hlo>>8;
538 reg_value[1] = hlo&0xff;
539 reg_value[2] = hhi>>8;
540 reg_value[3] = hhi&0xff;
541 BU92747_DBG("hlo = 0x%x, hhi = 0x%x\n", hlo, hhi);
542 bu92747_cir_i2c_set_regs(client, REG_HLO1, reg_value, 4);
545 end = (cir->stop_bit_interval*sys_clock)/1000;
546 reg_value[0] = end>>8;
547 reg_value[1] = end&0xff;
548 bu92747_cir_i2c_set_regs(client, REG_ENDLEN1, reg_value, 2);
550 BU92747_DBG("end = 0x%x\n", end);
552 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
559 static int bu92747_set_repeat(struct i2c_client *client, struct rk29_cir_struct_info *cir)
565 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
568 repeat_flag = cir->repeat;
569 printk("repeat 11111 =%d\n", repeat_flag);
571 if (repeat_flag == -1){
574 }else if (repeat_flag > 16){
577 repeat = repeat_flag;
581 repeat = repeat % 16;
583 bu92747_cir_i2c_read_regs(client, REG_SETTING1, reg_value, 1);
585 reg_value[0] = (reg_value[0]&0xf0) | (repeat&0x0f);
586 bu92747_cir_i2c_set_regs(client, REG_SETTING1, reg_value, 1);
587 printk("repeat 2222 =%d reg_value = %d\n", repeat, reg_value[0]);
589 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
594 static int bu92747_set_carrier(struct i2c_client *client, struct rk29_cir_struct_info *cir)
597 u16 clo = 0, chi = 0;
598 unsigned int hlo = cir->carry_low , hhi = cir->carry_high;
600 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
607 clo = XIN_INPUT_FREQ / 3000 * hlo;
608 chi = XIN_INPUT_FREQ / 3000 * hhi;
609 reg_value[0] = clo>>8;
610 reg_value[1] = clo&0xff;
611 reg_value[2] = chi>>8;
612 reg_value[3] = chi&0xff;
613 BU92747_DBG("clo = 0x%x, chi = 0x%x\n", clo, chi);
614 bu92747_cir_i2c_set_regs(client, REG_CLO1, reg_value, 4);
616 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
623 static int bu92747_cir_init_device(struct i2c_client *client, struct bu92747_data_info *bu92747)
627 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
629 //transmission buff null intertupt, base clock div, irq enable, clock power up
630 //reg_value[0] = /*REG0_OPM | */REG0_DIVS | REG0_PWR | REG0_IRQE;
631 reg_value[0] = /*REG0_OPM | */REG0_DIVS | REG0_IRQE;
632 reg_value[1] = REG1_FRME | REG1_RPT; //enable frame interval, repeat = 1
633 reg_value[2] = 80; //base clock = 100KHz
634 BU92747_DBG("line %d: reg0=0x%x, reg1=0x%x, reg2=0x%x\n", __LINE__, reg_value[0], reg_value[1], reg_value[2]);
635 bu92747_cir_i2c_set_regs(client, REG_SETTING0, reg_value, 3);
636 bu92747_cir_i2c_read_regs(client, REG_SETTING0, reg_value, 3);
637 BU92747_DBG("line %d: reg0=0x%x, reg1=0x%x, reg2=0x%x\n", __LINE__, reg_value[0], reg_value[1], reg_value[2]);
639 bu92747->base_clock = 100; //KHz
640 bu92747->sys_clock = bu92747->base_clock;
642 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
647 static int bu92747_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
649 void __user *argp = (void __user *)arg;
650 char msg[CIR_FRAME_SIZE];
652 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
654 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
659 case BU92747_IOCTL_START:
660 ret = bu92747_start(client);
665 case BU92747_IOCTL_STOP:
666 ret = bu92747_stop(client);
671 case BU92747_IOCTL_PULSE:
672 if (copy_from_user(&msg, argp, sizeof(msg)))
675 //bu92747_printk_cir((struct rk29_cir_struct_info *)msg);
676 ret = bu92747_set_pulse(client, (struct rk29_cir_struct_info *)msg);
681 case BU92747_IOCTL_DATA:
682 if (copy_from_user(&msg, argp, sizeof(msg)))
684 ret = bu92747_set_data(client, (struct rk29_cir_struct_info *)msg);
689 case BU92747_IOCTL_CARRIER:
690 if (copy_from_user(&msg, argp, sizeof(msg)))
692 ret = bu92747_set_carrier(client, (struct rk29_cir_struct_info *)msg);
696 case BU92747_IOCTL_REPEAT:
697 if (copy_from_user(&msg, argp, sizeof(msg)))
699 ret = bu92747_set_repeat(client, (struct rk29_cir_struct_info *)msg);
704 case BU92747_IOCTL_DURATION:
705 if (copy_from_user(&msg, argp, sizeof(msg)))
707 ret = bu92747_set_duration(client, (struct rk29_cir_struct_info *)msg);
711 case BU92747_IOCTL_PARAMETER:
712 if (copy_from_user(&msg, argp, sizeof(msg)))
715 ret = bu92747_set_parameter(client, (struct rk29_cir_struct_info *)msg);
719 case BU92747_IOCTL_FORMATE:
720 if (copy_from_user(&msg, argp, sizeof(msg)))
723 ret = bu92747_set_format(client, (struct rk29_cir_struct_info *)msg);
733 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
738 static int bu92747_open(struct inode *inode, struct file *file)
740 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
741 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
742 struct bu92747guw_platform_data *pdata = bu92747->platdata;
744 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
746 printk("bu92747_open\n");
748 // if (BU92747_OPEN == bu92747->state)
750 // bu92747->state = BU92747_OPEN;
753 if (pdata && pdata->cir_pwr_ctl) {
754 pdata->cir_pwr_ctl(1);
757 //switch to remote control, mcr, ec_en=1,rc_mode=1
758 smc0_write(REG_MCR_ADDR, smc0_read(REG_MCR_ADDR)|(3<<10));
759 //set irda pwdownpin = 0
760 smc0_write(REG_TRCR_ADDR, smc0_read(REG_TRCR_ADDR)&0xffbf);
761 BU92747_DBG("irda power down pin = %d\n", gpio_get_value(RK29_PIN5_PA7));
764 bu92747_cir_init_device(client, bu92747);
766 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
771 static int bu92747_release(struct inode *inode, struct file *file)
773 struct i2c_client *client = container_of(bu92747guw_device.parent, struct i2c_client, dev);
774 struct bu92747_data_info *bu92747 = (struct bu92747_data_info *)i2c_get_clientdata(client);
775 struct bu92747guw_platform_data *pdata = bu92747->platdata;
777 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
780 if (pdata && pdata->cir_pwr_ctl) {
781 pdata->cir_pwr_ctl(0);
784 // bu92747->state = BU92747_CLOSE;
786 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
791 static struct file_operations bu92747_fops = {
792 .owner = THIS_MODULE,
793 .open = bu92747_open,
794 .release = bu92747_release,
795 .ioctl = bu92747_ioctl,
798 static struct miscdevice bu92747guw_device = {
799 .minor = MISC_DYNAMIC_MINOR,
801 .fops = &bu92747_fops,
804 static int __devinit bu92747_cir_probe(struct i2c_client *client, const struct i2c_device_id *id)
806 struct bu92747_data_info *bu92747;
807 struct bu92747guw_platform_data *pdata;
810 BU92747_DBG("line %d: enter %s\n", __LINE__, __FUNCTION__);
812 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
815 bu92747 = kzalloc(sizeof(struct bu92747_data_info), GFP_KERNEL);
817 printk("line %d: bu92747 alloc data failed.\n", __LINE__);
822 pdata = client->dev.platform_data;
823 if (pdata && pdata->iomux_init) {
827 bu92747->platdata = pdata;
828 bu92747->client = client;
829 i2c_set_clientdata(client, bu92747);
830 bu92747->state = BU92747_CLOSE;
833 bu92747guw_device.parent = &client->dev;
834 err = misc_register(&bu92747guw_device);
836 printk("line %d: bu92747 misc_register failed.\n", __LINE__);
841 if (pdata && gpio_is_valid(pdata->intr_pin)) {
842 printk("-------request irq\n");
843 err = gpio_request(pdata->intr_pin, "rk29 cir irq");
845 printk("line %d: bu92747 request gpio failed.\n", __LINE__);
848 gpio_direction_input(pdata->intr_pin);
849 gpio_request(RK29_PIN5_PA7, NULL);
851 printk("line %d: bu92747 request gpio failed.\n", __LINE__);
853 gpio_direction_input(RK29_PIN5_PA7);
854 bu92747->irq = gpio_to_irq(pdata->intr_pin);
855 err = request_irq(bu92747->irq, bu92747_cir_irq, IRQF_TRIGGER_FALLING, client->dev.driver->name, bu92747);
857 BU92747_DBG("line %d: bu92747 request gpio failed.\n", __LINE__);
860 //disable_irq(bu92747->irq);
863 //INIT_DELAYED_WORK(&bu92747->dwork, bu92747_dwork_handler);
864 INIT_DELAYED_WORK(&bu92747->dwork, bu92747_dwork_handler);
868 //bu92747_start(client);
870 //bu92747_send_data_test(client);
871 //BU92747_DBG("line %d: test %s\n", __LINE__, __FUNCTION__);
876 BU92747_DBG("line %d: exit %s\n", __LINE__, __FUNCTION__);
880 gpio_free(pdata->intr_pin);
882 misc_deregister(&bu92747guw_device);
884 if (pdata && pdata->iomux_deinit)
885 pdata->iomux_deinit();
891 static int __devexit bu92747_cir_remove(struct i2c_client *client)
894 struct bu92747_data_info *bu92747 = i2c_get_clientdata(client);
895 struct bu92747guw_platform_data *pdata = bu92747->platdata;
897 printk(" cir_remove \n");
899 free_irq(bu92747->irq, bu92747);
900 gpio_free(pdata->intr_pin);
901 misc_deregister(&bu92747guw_device);
902 if (pdata && pdata->iomux_deinit)
903 pdata->iomux_deinit();
908 static const struct i2c_device_id bu92747_cir_id[] = {
909 { "bu92747_cir", 0 },
912 MODULE_DEVICE_TABLE(i2c, bu92747_cir_id);
914 static struct i2c_driver bu92747_cir_driver = {
916 .name = "bu92747_cir",
917 .owner = THIS_MODULE,
919 .probe = bu92747_cir_probe,
920 .remove = __devexit_p(bu92747_cir_remove),
921 .id_table = bu92747_cir_id,
924 static int __init bu92747_cir_init(void)
926 return i2c_add_driver(&bu92747_cir_driver);
929 static void __exit bu92747_cir_exit(void)
931 i2c_del_driver(&bu92747_cir_driver);
934 MODULE_AUTHOR("zyw zyw@rock-chips.com");
935 MODULE_DESCRIPTION("bu92747 cir driver");
936 MODULE_LICENSE("GPL");
938 module_init(bu92747_cir_init);
939 module_exit(bu92747_cir_exit);