public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: "istvan_v@mailbox.hu" <istvan_v@mailbox.hu>
To: linux-media@vger.kernel.org
Subject: XC4000: simplified seek_firmware()
Date: Sat, 04 Jun 2011 16:52:34 +0200	[thread overview]
Message-ID: <4DEA46B2.7090409@mailbox.hu> (raw)
In-Reply-To: <BANLkTimEEGsMP6PDXf5W5p9wW7wdWEEOiA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 103 bytes --]

This patch simplifies the code in seek_firmware().

Signed-off-by: Istvan Varga <istvan_v@mailbox.hu>


[-- Attachment #2: xc4000_fwseek.patch --]
[-- Type: text/x-patch, Size: 2825 bytes --]

diff -uNr xc4000_orig/drivers/media/common/tuners/xc4000.c xc4000/drivers/media/common/tuners/xc4000.c
--- xc4000_orig/drivers/media/common/tuners/xc4000.c	2011-06-04 12:50:41.000000000 +0200
+++ xc4000/drivers/media/common/tuners/xc4000.c	2011-06-04 13:10:00.000000000 +0200
@@ -606,8 +606,8 @@
 			 v4l2_std_id *id)
 {
 	struct xc4000_priv *priv = fe->tuner_priv;
-	int                 i, best_i = -1, best_nr_matches = 0;
-	unsigned int        type_mask = 0;
+	int		i, best_i = -1;
+	unsigned int	best_nr_diffs = 255U;
 
 	if (!priv->firm) {
 		printk("Error! firmware not loaded\n");
@@ -617,63 +617,42 @@
 	if (((type & ~SCODE) == 0) && (*id == 0))
 		*id = V4L2_STD_PAL;
 
-	if (type & BASE)
-		type_mask = BASE_TYPES;
-	else if (type & SCODE) {
-		type &= SCODE_TYPES;
-		type_mask = SCODE_TYPES & ~HAS_IF;
-	} else if (type & DTV_TYPES)
-		type_mask = DTV_TYPES;
-	else if (type & STD_SPECIFIC_TYPES)
-		type_mask = STD_SPECIFIC_TYPES;
-
-	type &= type_mask;
-
-	if (!(type & SCODE))
-		type_mask = ~0;
-
-	/* Seek for exact match */
-	for (i = 0; i < priv->firm_size; i++) {
-		if ((type == (priv->firm[i].type & type_mask)) &&
-		    (*id == priv->firm[i].id))
-			goto found;
-	}
-
 	/* Seek for generic video standard match */
 	for (i = 0; i < priv->firm_size; i++) {
-		v4l2_std_id match_mask;
-		int nr_matches;
+		v4l2_std_id	id_diff_mask =
+			(priv->firm[i].id ^ (*id)) & (*id);
+		unsigned int	type_diff_mask =
+			(priv->firm[i].type ^ type)
+			& (BASE_TYPES | DTV_TYPES | LCD | NOGD | MONO | SCODE);
+		unsigned int	nr_diffs;
 
-		if (type != (priv->firm[i].type & type_mask))
+		if (type_diff_mask
+		    & (BASE | INIT1 | FM | DTV6 | DTV7 | DTV78 | DTV8 | SCODE))
 			continue;
 
-		match_mask = *id & priv->firm[i].id;
-		if (!match_mask)
-			continue;
-
-		if ((*id & match_mask) == *id)
-			goto found; /* Supports all the requested standards */
+		nr_diffs = hweight64(id_diff_mask) + hweight32(type_diff_mask);
+		if (!nr_diffs)	/* Supports all the requested standards */
+			goto found;
 
-		nr_matches = hweight64(match_mask);
-		if (nr_matches > best_nr_matches) {
-			best_nr_matches = nr_matches;
+		if (nr_diffs < best_nr_diffs) {
+			best_nr_diffs = nr_diffs;
 			best_i = i;
 		}
 	}
 
-	if (best_nr_matches > 0) {
-		printk("Selecting best matching firmware (%d bits) for "
-			  "type=", best_nr_matches);
+	/* FIXME: Would make sense to seek for type "hint" match ? */
+	if (best_i < 0) {
+		i = -ENOENT;
+		goto ret;
+	}
+
+	if (best_nr_diffs > 0U) {
+		printk("Selecting best matching firmware (%u bits differ) for "
+		       "type=", best_nr_diffs);
 		printk("(%x), id %016llx:\n", type, (unsigned long long)*id);
 		i = best_i;
-		goto found;
 	}
 
-	/*FIXME: Would make sense to seek for type "hint" match ? */
-
-	i = -ENOENT;
-	goto ret;
-
 found:
 	*id = priv->firm[i].id;
 

  parent reply	other threads:[~2011-06-04 14:52 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-08 14:54 [linux-dvb] XC4000 patches for kernel 2.6.37.2 Mirek Slugeň
2011-05-31  2:48 ` Dmitri Belimov
2011-05-31  3:49   ` Devin Heitmueller
2011-05-31  7:43     ` Dmitri Belimov
2011-06-02 10:52       ` Devin Heitmueller
2011-06-02 14:41         ` Mauro Carvalho Chehab
2011-06-02 15:17           ` Devin Heitmueller
2011-06-02 16:35             ` Mauro Carvalho Chehab
2011-06-03  1:41           ` Dmitri Belimov
2011-06-03 12:12             ` Mauro Carvalho Chehab
2011-06-02 15:53         ` Mohammad Bahathir Hashim
2011-06-02 17:05           ` Mauro Carvalho Chehab
2011-06-03  3:54             ` Mohammad Bahathir Hashim
     [not found]         ` <4DE8D5AC.7060002@mailbox.hu>
2011-06-03 12:46           ` [linux-dvb] XC4000: added card_type Devin Heitmueller
     [not found]             ` <4DE8DEC6.6080008@mailbox.hu>
2011-06-03 14:00               ` Mauro Carvalho Chehab
2011-06-03 14:22                 ` istvan_v
2011-06-03 13:17           ` Mauro Carvalho Chehab
2011-06-03 13:55         ` XC4000: updated standards table istvan_v
2011-06-03 15:17         ` XC4000: added support for 7 MHz DVB-T istvan_v
2011-06-03 15:23         ` XC4000: added mutex istvan_v
2011-06-03 15:27         ` XC4000: fixed frequency error istvan_v
2011-06-04 14:48         ` XC4000: added firmware_name parameter istvan_v
2011-06-04 14:52         ` istvan_v [this message]
2011-06-04 14:56         ` XC4000: simplified load_scode istvan_v
2011-06-04 14:59         ` XC4000: check_firmware() cleanup istvan_v
2011-06-04 15:03         ` XC4000: implemented power management istvan_v
2011-06-04 15:04         ` XC4000: firmware initialization istvan_v
2011-06-04 15:08         ` XC4000: debug message improvements istvan_v
2011-06-04 15:12         ` XC4000: setting registers istvan_v
2011-06-05 12:05           ` Mauro Carvalho Chehab
2011-06-05 12:28             ` Istvan Varga
2011-06-05 12:56               ` Mauro Carvalho Chehab
2011-06-05 14:30                 ` Istvan Varga
2011-06-04 15:15         ` XC4000: added audio_std module parameter istvan_v
2011-06-04 15:17         ` XC4000: implemented analog TV and radio istvan_v
2011-06-04 15:18         ` XC4000: xc_tune_channel() cleanup istvan_v
2011-06-04 15:21         ` XC4000: removed redundant tuner reset istvan_v
2011-06-04 15:25         ` XC4000: detect XC4100 istvan_v
2011-06-02  4:58     ` [linux-dvb] XC4000 patches for kernel 2.6.37.2 Mohammad Bahathir Hashim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DEA46B2.7090409@mailbox.hu \
    --to=istvan_v@mailbox.hu \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox