Skip to contentSkip to conversation

V4L/DVB: dib0700: Fix RC protocol logic to properly handle NEC/NECx and RC-5

PATCH New Mauro Carvalho Chehab 1 participant 3 messages Aug 1, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#3 lore raw

PATCH 3/3 V4L/DVB: dib0700: Fix RC protocol logic to properly handle NEC/NECx and RC-5

In reply to a message not in the archive

Simplifies the logic for handling firmware 1.20 RC messages, fixing the logic.

While here, I tried to use a RC-6 remote controller from my TV set, but it didn't work with dib0700. Not sure why, but maybe this never worked.

drivers/media/dvb/dvb-usb/dib0700_core.c +35 -31
index d73a688..fe81834 100644
@@ -499,7 +499,7 @@ int dib0700_change_protocol(void *priv, u64 ir_type)
 		return ret;
 	}
 
-	d->props.rc.core.protocol = new_proto;
+	d->props.rc.core.protocol = ir_type;
 
 	return ret;
 }
@@ -511,7 +511,13 @@ int dib0700_change_protocol(void *priv, u64 ir_type)
 struct dib0700_rc_response {
 	u8 report_id;
 	u8 data_state;
-	u16 system;
+	union {
+		u16 system16;
+		struct {
+			u8 system;
+			u8 not_system;
+		};
+	};
 	u8 data;
 	u8 not_data;
 };
@@ -521,9 +527,8 @@ static void dib0700_rc_urb_completion(struct urb *purb)
 {
 	struct dvb_usb_device *d = purb->context;
 	struct dib0700_state *st;
-	struct dib0700_rc_response poll_reply;
-	u8 *buf;
-	u32 keycode;
+	struct dib0700_rc_response *poll_reply;
+	u32 uninitialized_var(keycode);
 	u8 toggle;
 
 	deb_info("%s()\n", __func__);
@@ -537,7 +542,7 @@ static void dib0700_rc_urb_completion(struct urb *purb)
 	}
 
 	st = d->priv;
-	buf = (u8 *)purb->transfer_buffer;
+	poll_reply = purb->transfer_buffer;
 
 	if (purb->status < 0) {
 		deb_info("discontinuing polling\n");
@@ -550,52 +555,51 @@ static void dib0700_rc_urb_completion(struct urb *purb)
 		goto resubmit;
 	}
 
-	deb_data("IR raw %02X %02X %02X %02X %02X %02X (len %d)\n", buf[0],
-		 buf[1], buf[2], buf[3], buf[4], buf[5], purb->actual_length);
+	deb_data("IR ID = %02X state = %02X System = %02X %02X Cmd = %02X %02X (len %d)\n",
+		 poll_reply->report_id, poll_reply->data_state,
+		 poll_reply->system, poll_reply->not_system,
+		 poll_reply->data, poll_reply->not_data,
+		 purb->actual_length);
 
 	switch (d->props.rc.core.protocol) {
 	case IR_TYPE_NEC:
-		poll_reply.data_state = 0;
-		poll_reply.system     = buf[2];
-		poll_reply.data       = buf[4];
-		poll_reply.not_data   = buf[5];
 		toggle = 0;
 
 		/* NEC protocol sends repeat code as 0 0 0 FF */
-		if ((poll_reply.system == 0x00) && (poll_reply.data == 0x00)
-		    && (poll_reply.not_data == 0xff)) {
-			poll_reply.data_state = 2;
+		if ((poll_reply->system == 0x00) && (poll_reply->data == 0x00)
+		    && (poll_reply->not_data == 0xff)) {
+			poll_reply->data_state = 2;
 			break;
 		}
 
+		if ((poll_reply->system ^ poll_reply->not_system) != 0xff) {
+			deb_data("NEC extended protocol\n");
+			/* NEC extended code - 24 bits */
+			keycode = poll_reply->system16 << 8 | poll_reply->data;
+		} else {
+			deb_data("NEC normal protocol\n");
+			/* normal NEC code - 16 bits */
+			keycode = poll_reply->system << 8 | poll_reply->data;
+		}
+
 		break;
 	default:
+		deb_data("RC5 protocol\n");
 		/* RC5 Protocol */
-		/* TODO: need to check the mapping for RC6 */
-		poll_reply.report_id  = buf[0];
-		poll_reply.data_state = buf[1];
-		poll_reply.system     = (buf[2] << 8) | buf[3];
-		poll_reply.data       = buf[4];
-		poll_reply.not_data   = buf[5];
-
-		toggle = poll_reply.report_id;
+		toggle = poll_reply->report_id;
+		keycode = poll_reply->system16 << 8 | poll_reply->data;
 
 		break;
 	}
 
-	if ((poll_reply.data + poll_reply.not_data) != 0xff) {
+	if ((poll_reply->data + poll_reply->not_data) != 0xff) {
 		/* Key failed integrity check */
 		err("key failed integrity check: %04x %02x %02x",
-		    poll_reply.system,
-		    poll_reply.data, poll_reply.not_data);
+		    poll_reply->system,
+		    poll_reply->data, poll_reply->not_data);
 		goto resubmit;
 	}
 
-	deb_data("rid=%02x ds=%02x sm=%04x d=%02x nd=%02x\n",
-		 poll_reply.report_id, poll_reply.data_state,
-		 poll_reply.system, poll_reply.data, poll_reply.not_data);
-
-	keycode = poll_reply.system << 8 | poll_reply.data;
 	ir_keydown(d->rc_input_dev, keycode, toggle);
 
 resubmit:
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/3 V4L/DVB: dib0700: break keytable into NEC and RC-5 variants

In reply to a message not in the archive

Instead of having one big keytable with 2 protocols inside, break it into two separate tables, being one for NEC and another for RC-5 variants, and properly identify what variant should be used at the boards entries.

 delete mode 100644 drivers/media/IR/keymaps/rc-dib0700-big.c
 create mode 100644 drivers/media/IR/keymaps/rc-dib0700-nec.c
 create mode 100644 drivers/media/IR/keymaps/rc-dib0700-rc5.c
drivers/media/IR/keymaps/Makefile +2 -1
index 85330d1..cbee062 100644
@@ -14,7 +14,8 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
 			rc-budget-ci-old.o \
 			rc-cinergy-1400.o \
 			rc-cinergy.o \
-			rc-dib0700-big.o \
+			rc-dib0700-nec.o \
+			rc-dib0700-rc5.o \
 			rc-dm1105-nec.o \
 			rc-dntv-live-dvb-t.o \
 			rc-dntv-live-dvbt-pro.o \
drivers/media/IR/keymaps/rc-dib0700-big.c deleted +0 -314

314 lines not on this page · raw message

drivers/media/IR/keymaps/rc-dib0700-nec.c new file +124 -0

124 lines not on this page · raw message

drivers/media/IR/keymaps/rc-dib0700-rc5.c new file +235 -0

235 lines not on this page · raw message

drivers/media/dvb/dvb-usb/dib0700_devices.c +53 -14

157 lines not on this page · raw message

include/media/rc-map.h +2 -3
index adbcccb..9569d08 100644
@@ -69,9 +69,8 @@ void rc_map_init(void);
 #define RC_MAP_BUDGET_CI_OLD             "rc-budget-ci-old"
 #define RC_MAP_CINERGY_1400              "rc-cinergy-1400"
 #define RC_MAP_CINERGY                   "rc-cinergy"
-/* Temporary table - should be broken into smaller tables */
-#define RC_MAP_DIB0700_BIG_TABLE         "rc-dib0700-big"
-
+#define RC_MAP_DIB0700_NEC_TABLE         "rc-dib0700-nec"
+#define RC_MAP_DIB0700_RC5_TABLE         "rc-dib0700-rc5"
 #define RC_MAP_DM1105_NEC                "rc-dm1105-nec"
 #define RC_MAP_DNTV_LIVE_DVBT_PRO        "rc-dntv-live-dvbt-pro"
 #define RC_MAP_DNTV_LIVE_DVB_T           "rc-dntv-live-dvb-t"
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/3 V4L/DVB: dib0700: properly implement IR change_protocol

In reply to a message not in the archive

This patch implements change_protocol callback. With this change, there's no need for an extra modprobe parameter to specify the protocol. When a table is loaded (either from in-kernel rc-map tables or via ir-keytable program), the driver will automatically change the protocol, in order to work with the given table.

drivers/media/dvb/dvb-usb/dib0700.h +1 -0
index 83fc24a..c2c9d23 100644
@@ -60,6 +60,7 @@ extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff);
 extern struct i2c_algorithm dib0700_i2c_algo;
 extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
 			struct dvb_usb_device_description **desc, int *cold);
+extern int dib0700_change_protocol(void *priv, u64 ir_type);
 
 extern int dib0700_device_count;
 extern int dvb_usb_dib0700_ir_proto;
drivers/media/dvb/dvb-usb/dib0700_core.c +37 -16

86 lines not on this page · raw message

drivers/media/dvb/dvb-usb/dib0700_devices.c +100 -18

214 lines not on this page · raw message

drivers/media/dvb/dvb-usb/dvb-usb.h +2 -0
index bcfbf9a..34f7b3b 100644
@@ -179,6 +179,7 @@ struct dvb_rc_legacy {
 /**
  * struct dvb_rc properties of remote controller, using rc-core
  * @rc_codes: name of rc codes table
+ * @protocol: type of protocol(s) currently used by the driver
  * @rc_query: called to query an event event.
  * @rc_interval: time in ms between two queries.
  * @rc_props: remote controller properties
@@ -186,6 +187,7 @@ struct dvb_rc_legacy {
  */
 struct dvb_rc {
 	char *rc_codes;
+	u64 protocol;
 	char *module_name;
 	int (*rc_query) (struct dvb_usb_device *d);
 	int rc_interval;
Signature · 1 line
1.7.1