diff mbox

tm6000 and IR

Message ID 20101201144704.43b58f2c@glory.local (mailing list archive)
State RFC
Headers show

Commit Message

Dmitri Belimov Dec. 1, 2010, 5:47 a.m. UTC
None
diff mbox

Patch

diff --git a/drivers/staging/tm6000/Kconfig b/drivers/staging/tm6000/Kconfig
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/Makefile b/drivers/staging/tm6000/Makefile
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/README b/drivers/staging/tm6000/README
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/TODO b/drivers/staging/tm6000/TODO
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000-alsa.c b/drivers/staging/tm6000/tm6000-alsa.c
old mode 100644
new mode 100755
index a99101f..6605260
--- a/drivers/staging/tm6000/tm6000-alsa.c
+++ b/drivers/staging/tm6000/tm6000-alsa.c
@@ -326,7 +326,7 @@  static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd)
 	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
 	int err;
 
-	spin_lock(&chip->reg_lock);
+//	spin_lock(&chip->reg_lock);
 
 	switch (cmd) {
 	case SNDRV_PCM_TRIGGER_START:
@@ -340,7 +340,7 @@  static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd)
 		break;
 	}
 
-	spin_unlock(&chip->reg_lock);
+//	spin_unlock(&chip->reg_lock);
 
 	return err;
 }
@@ -425,7 +425,7 @@  int tm6000_audio_init(struct tm6000_core *dev)
 	chip->core = dev;
 	chip->card = card;
 	dev->adev = chip;
-	spin_lock_init(&chip->reg_lock);
+//	spin_lock_init(&chip->reg_lock);
 
 	rc = snd_pcm_new(card, "TM6000 Audio", 0, 0, 1, &pcm);
 	if (rc < 0)
diff --git a/drivers/staging/tm6000/tm6000-cards.c b/drivers/staging/tm6000/tm6000-cards.c
old mode 100644
new mode 100755
index 9d091c3..878e292
--- a/drivers/staging/tm6000/tm6000-cards.c
+++ b/drivers/staging/tm6000/tm6000-cards.c
@@ -36,22 +36,6 @@ 
 #include "tuner-xc2028.h"
 #include "xc5000.h"
 
-#define TM6000_BOARD_UNKNOWN			0
-#define TM5600_BOARD_GENERIC			1
-#define TM6000_BOARD_GENERIC			2
-#define TM6010_BOARD_GENERIC			3
-#define TM5600_BOARD_10MOONS_UT821		4
-#define TM5600_BOARD_10MOONS_UT330		5
-#define TM6000_BOARD_ADSTECH_DUAL_TV		6
-#define TM6000_BOARD_FREECOM_AND_SIMILAR	7
-#define TM6000_BOARD_ADSTECH_MINI_DUAL_TV	8
-#define TM6010_BOARD_HAUPPAUGE_900H		9
-#define TM6010_BOARD_BEHOLD_WANDER		10
-#define TM6010_BOARD_BEHOLD_VOYAGER		11
-#define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE	12
-#define TM6010_BOARD_TWINHAN_TU501		13
-
-#define TM6000_MAXBOARDS        16
 static unsigned int card[]     = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
 
 module_param_array(card,  int, NULL, 0444);
@@ -239,6 +223,7 @@  struct tm6000_board tm6000_boards[] = {
 			.demod_reset	= TM6010_GPIO_1,
 			.power_led	= TM6010_GPIO_6,
 		},
+		.ir_codes = RC_MAP_BEHOLD_COLUMBUS,
 	},
 	[TM6010_BOARD_BEHOLD_VOYAGER] = {
 		.name         = "Beholder Voyager TV/FM USB2.0",
@@ -256,6 +241,7 @@  struct tm6000_board tm6000_boards[] = {
 			.tuner_reset	= TM6010_GPIO_0,
 			.power_led	= TM6010_GPIO_6,
 		},
+		.ir_codes = RC_MAP_BEHOLD_COLUMBUS,
 	},
 	[TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
 		.name         = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
@@ -328,6 +314,46 @@  struct usb_device_id tm6000_id_table[] = {
 	{ },
 };
 
+void tm6000_flash_led(struct tm6000_core *dev, u8 state)
+{
+	/* Power LED unconfigured */
+	if (!dev->gpio.power_led)
+		return;
+
+	/* ON Power LED */
+	if (state) {
+		switch (dev->model) {
+		case TM6010_BOARD_HAUPPAUGE_900H:
+		case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
+		case TM6010_BOARD_TWINHAN_TU501:
+			tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+				dev->gpio.power_led, 0x00);
+			break;
+		case TM6010_BOARD_BEHOLD_WANDER:
+		case TM6010_BOARD_BEHOLD_VOYAGER:
+			tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+				dev->gpio.power_led, 0x01);
+			break;
+		}
+	}
+	/* OFF Power LED */
+	else {
+		switch (dev->model) {
+		case TM6010_BOARD_HAUPPAUGE_900H:
+		case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
+		case TM6010_BOARD_TWINHAN_TU501:
+			tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+				dev->gpio.power_led, 0x01);
+			break;
+		case TM6010_BOARD_BEHOLD_WANDER:
+		case TM6010_BOARD_BEHOLD_VOYAGER:
+			tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+				dev->gpio.power_led, 0x00);
+			break;
+		}
+	}
+}
+
 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
 {
@@ -857,7 +883,6 @@  static int tm6000_usb_probe(struct usb_interface *interface,
 		}
 	}
 
-
 	printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
 		speed,
 		le16_to_cpu(dev->udev->descriptor.idVendor),
diff --git a/drivers/staging/tm6000/tm6000-core.c b/drivers/staging/tm6000/tm6000-core.c
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000-dvb.c b/drivers/staging/tm6000/tm6000-dvb.c
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000-input.c b/drivers/staging/tm6000/tm6000-input.c
old mode 100644
new mode 100755
index daca3a5..e1c624e
--- a/drivers/staging/tm6000/tm6000-input.c
+++ b/drivers/staging/tm6000/tm6000-input.c
@@ -38,6 +38,10 @@  static unsigned int enable_ir = 1;
 module_param(enable_ir, int, 0644);
 MODULE_PARM_DESC(enable_ir, "enable ir (default is enable)");
 
+/* number of 50ms for ON-OFF-ON power led */
+/* show IR activity */
+#define PWLED_OFF 2
+
 #undef dprintk
 
 #define dprintk(fmt, arg...) \
@@ -61,6 +65,8 @@  struct tm6000_IR {
 	struct delayed_work	work;
 	u8			wait:1;
 	u8			key:1;
+	u8			pwled:1;
+	u8			pwledcnt;
 	struct urb		*int_urb;
 	u8			*urb_data;
 
@@ -91,26 +97,50 @@  static int tm6000_ir_config(struct tm6000_IR *ir)
 	u8 buf[10];
 	int rc;
 
-	/* hack */
-	buf[0] = 0xff;
-	buf[1] = 0xff;
-	buf[2] = 0xf2;
-	buf[3] = 0x2b;
-	buf[4] = 0x20;
-	buf[5] = 0x35;
-	buf[6] = 0x60;
-	buf[7] = 0x04;
-	buf[8] = 0xc0;
-	buf[9] = 0x08;
-
-	rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
+	switch (dev->model) {
+	case TM6010_BOARD_BEHOLD_WANDER:
+	case TM6010_BOARD_BEHOLD_VOYAGER:
+		/* Setup IR decoder for NEC standard */
+		/* IR_LEADER_CNT = 0.9ms             */
+		tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_LEADER1, 0xaa);
+		tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_LEADER0, 0x30);
+		/* IR_PULSE_CNT = 0.7ms              */
+		tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT1, 0x20);
+		tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT0, 0xd0);
+		/* Remote WAKEUP = enable */
+		tm6000_set_reg(dev, TM6010_REQ07_RE5_REMOTE_WAKEUP, 0xfe);
+		/* IR_WKUP_SEL = Low byte in decoded IR data */
+		tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0xfc);
+		/* IR_WKU_ADD code 0x12 */
+		tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_ADD, 0x12);
+		tm6000_flash_led(dev, 0);
+		msleep(100);
+		tm6000_flash_led(dev, 1);
+		break;
+	default:
+		/* hack */
+		buf[0] = 0xff;
+		buf[1] = 0xff;
+		buf[2] = 0xf2;
+		buf[3] = 0x2b;
+		buf[4] = 0x20;
+		buf[5] = 0x35;
+		buf[6] = 0x60;
+		buf[7] = 0x04;
+		buf[8] = 0xc0;
+		buf[9] = 0x08;
+
+		rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
 		USB_RECIP_DEVICE, REQ_00_SET_IR_VALUE, 0, 0, buf, 0x0a);
-	msleep(100);
+		msleep(100);
 
-	if (rc < 0) {
-		printk(KERN_INFO "IR configuration failed");
-		return rc;
+		if (rc < 0) {
+			printk(KERN_INFO "IR configuration failed");
+			return rc;
+		}
+		break;
 	}
+
 	return 0;
 }
 
@@ -119,15 +149,15 @@  static void tm6000_ir_urb_received(struct urb *urb)
 	struct tm6000_core *dev = urb->context;
 	struct tm6000_IR *ir = dev->ir;
 	int rc;
-
+printk("tm6000_ir_urb_received start\n");
 	if (urb->status != 0)
 		printk(KERN_INFO "not ready\n");
 	else if (urb->actual_length > 0) {
 		memcpy(ir->urb_data, urb->transfer_buffer, urb->actual_length);
-
+printk("int_in ir urb received %02x %02x %02x %02x\n", ir->urb_data[0],
+			ir->urb_data[1], ir->urb_data[2], ir->urb_data[3]);
 		dprintk("data %02x %02x %02x %02x\n", ir->urb_data[0],
 			ir->urb_data[1], ir->urb_data[2], ir->urb_data[3]);
-
 		ir->key = 1;
 	}
 
@@ -148,7 +178,15 @@  static int default_polling_getkey(struct tm6000_IR *ir,
 		if (ir->ir.ir_type == IR_TYPE_RC5)
 			poll_result->rc_data = ir->urb_data[0];
 		else
-			poll_result->rc_data = ir->urb_data[0] | ir->urb_data[1] << 8;
+			if (((dev->model == TM6010_BOARD_BEHOLD_WANDER) ||
+				(dev->model == TM6010_BOARD_BEHOLD_VOYAGER)) &&
+				(ir->urb_data[1] == 0x86)) {
+				poll_result->rc_data = ir->urb_data[0];
+			}
+			else {
+				poll_result->rc_data = ir->urb_data[0]
+					| ir->urb_data[1] << 8;
+			}
 	} else {
 		tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0);
 		msleep(10);
@@ -188,6 +226,7 @@  static int default_polling_getkey(struct tm6000_IR *ir,
 
 static void tm6000_ir_handle_key(struct tm6000_IR *ir)
 {
+	struct tm6000_core *dev = ir->dev;
 	int result;
 	struct tm6000_ir_poll_result poll_result;
 
@@ -200,12 +239,25 @@  static void tm6000_ir_handle_key(struct tm6000_IR *ir)
 
 	dprintk("ir->get_key result data=%04x\n", poll_result.rc_data);
 
+	if (ir->pwled) {
+		if (ir->pwledcnt >= PWLED_OFF) {
+			ir->pwled = 0;
+			ir->pwledcnt = 0;
+			tm6000_flash_led(dev, 1);
+		}
+		else
+			ir->pwledcnt += 1;
+	}
+
 	if (ir->key) {
 		ir_input_keydown(ir->input->input_dev, &ir->ir,
 				(u32)poll_result.rc_data);
 
 		ir_input_nokey(ir->input->input_dev, &ir->ir);
 		ir->key = 0;
+		ir->pwled = 1;
+		ir->pwledcnt = 0;
+		tm6000_flash_led(dev, 0);
 	}
 	return;
 }
@@ -231,7 +283,7 @@  static int tm6000_ir_start(void *priv)
 static void tm6000_ir_stop(void *priv)
 {
 	struct tm6000_IR *ir = priv;
-
+printk("tm600o_ir_stop\n");
 	cancel_delayed_work_sync(&ir->work);
 }
 
@@ -283,6 +335,8 @@  int tm6000_ir_init(struct tm6000_core *dev)
 	ir->props.driver_type = RC_DRIVER_SCANCODE;
 
 	ir->polling = 50;
+	ir->pwled = 0;
+	ir->pwledcnt = 0;
 
 	snprintf(ir->name, sizeof(ir->name), "tm5600/60x0 IR (%s)",
 						dev->name);
@@ -342,6 +396,7 @@  int tm6000_ir_init(struct tm6000_core *dev)
 	if (err)
 		goto err_out_stop;
 
+
 	return 0;
 
 err_out_stop:
@@ -357,12 +412,12 @@  int tm6000_ir_fini(struct tm6000_core *dev)
 	struct tm6000_IR *ir = dev->ir;
 
 	/* skip detach on non attached board */
-
+printk("befor if (!ir)\n");
 	if (!ir)
 		return 0;
-
+printk("befor ir_input_unregister(ir->input->input_dev);\n");
 	ir_input_unregister(ir->input->input_dev);
-
+printk("befor if (ir->int_urb) {\n");
 	if (ir->int_urb) {
 		usb_kill_urb(ir->int_urb);
 		kfree(ir->int_urb->transfer_buffer);
@@ -371,10 +426,12 @@  int tm6000_ir_fini(struct tm6000_core *dev)
 		kfree(ir->urb_data);
 		ir->urb_data = NULL;
 	}
-
+printk("befor kfree(ir->input);\n");
 	kfree(ir->input);
+printk("befor ir->input = NULL;\n");
 	ir->input = NULL;
 	kfree(ir);
+printk("befor dev->ir = NULL;\n");
 	dev->ir = NULL;
 
 	return 0;
diff --git a/drivers/staging/tm6000/tm6000-regs.h b/drivers/staging/tm6000/tm6000-regs.h
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000-stds.c b/drivers/staging/tm6000/tm6000-stds.c
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000-usb-isoc.h b/drivers/staging/tm6000/tm6000-usb-isoc.h
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000-video.c b/drivers/staging/tm6000/tm6000-video.c
old mode 100644
new mode 100755
diff --git a/drivers/staging/tm6000/tm6000.h b/drivers/staging/tm6000/tm6000.h
old mode 100644
new mode 100755
index 1ec1bff..549d487
--- a/drivers/staging/tm6000/tm6000.h
+++ b/drivers/staging/tm6000/tm6000.h
@@ -39,6 +39,23 @@ 
 
 #define TM6000_VERSION KERNEL_VERSION(0, 0, 2)
 
+#define TM6000_BOARD_UNKNOWN			0
+#define TM5600_BOARD_GENERIC			1
+#define TM6000_BOARD_GENERIC			2
+#define TM6010_BOARD_GENERIC			3
+#define TM5600_BOARD_10MOONS_UT821		4
+#define TM5600_BOARD_10MOONS_UT330		5
+#define TM6000_BOARD_ADSTECH_DUAL_TV		6
+#define TM6000_BOARD_FREECOM_AND_SIMILAR	7
+#define TM6000_BOARD_ADSTECH_MINI_DUAL_TV	8
+#define TM6010_BOARD_HAUPPAUGE_900H		9
+#define TM6010_BOARD_BEHOLD_WANDER		10
+#define TM6010_BOARD_BEHOLD_VOYAGER		11
+#define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE	12
+#define TM6010_BOARD_TWINHAN_TU501		13
+
+#define TM6000_MAXBOARDS        16
+
 /* Inputs */
 
 enum tm6000_itype {
@@ -260,6 +277,7 @@  struct tm6000_fh {
 int tm6000_tuner_callback(void *ptr, int component, int command, int arg);
 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg);
 int tm6000_cards_setup(struct tm6000_core *dev);
+void tm6000_flash_led(struct tm6000_core *dev, u8 state);
 
 /* In tm6000-core.c */
 
@@ -270,6 +288,7 @@  int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index);
 int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index);
 int tm6000_set_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
 int tm6000_i2c_reset(struct tm6000_core *dev, u16 tsleep);
+
 int tm6000_init(struct tm6000_core *dev);
 
 int tm6000_init_analog_mode(struct tm6000_core *dev);