summaryrefslogtreecommitdiff
path: root/linux
diff options
context:
space:
mode:
authorDouglas Schilling Landgraf <dougsland@gmail.com>2007-10-01 00:32:25 -0300
committerDouglas Schilling Landgraf <dougsland@gmail.com>2007-10-01 00:32:25 -0300
commit7d87167e58928af2e5d43f9a501b55d7d2f8976f (patch)
tree73aa9e97aad837eb14fa8f8d17fa883044a4af9c /linux
parente41e02be862d5497ad7d8c41f15704fa77043bc8 (diff)
downloadmediapointer-dvb-s2-7d87167e58928af2e5d43f9a501b55d7d2f8976f.tar.gz
mediapointer-dvb-s2-7d87167e58928af2e5d43f9a501b55d7d2f8976f.tar.bz2
[PATCH] GemTek Radio card - frequency calculation
From: Trent Piepho <xyzzy@speakeasy.org> Frequency calculation to use better math. It's still the same IF offset and step size (which are not the same as the datasheet says) as the code was before. It's just more efficient and accurate. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Douglas Schilling Landgraf <dougsland@gmail.com>
Diffstat (limited to 'linux')
-rw-r--r--linux/drivers/media/radio/radio-gemtek.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/linux/drivers/media/radio/radio-gemtek.c b/linux/drivers/media/radio/radio-gemtek.c
index e63ff3a4e..1bc000f15 100644
--- a/linux/drivers/media/radio/radio-gemtek.c
+++ b/linux/drivers/media/radio/radio-gemtek.c
@@ -90,6 +90,14 @@ module_param(radio_nr, int, 0444);
#define GEMTEK_LOWFREQ (87*16000)
#define GEMTEK_HIGHFREQ (108*16000)
+/*
+ * Frequency calculation constants. Intermediate frequency 10.52 MHz (nominal
+ * value 10.7 MHz), reference divisor 6.39 kHz (nominal 6.25 kHz).
+ */
+#define FSCALE 8
+#define IF_OFFSET ((unsigned int)(10.52 * 16000 * (1<<FSCALE)))
+#define REF_FREQ ((unsigned int)(6.39 * 16 * (1<<FSCALE)))
+
#define GEMTEK_CK 0x01 /* Clock signal */
#define GEMTEK_DA 0x02 /* Serial data */
#define GEMTEK_CE 0x04 /* Chip enable */
@@ -220,14 +228,11 @@ static void gemtek_bu2614_transmit(struct gemtek_device *dev)
}
/*
- * Convert FM-frequency for BU2614FS (3.125 KHz STDF expected).
+ * Calculate divisor from FM-frequency for BU2614FS (3.125 KHz STDF expected).
*/
-static inline void gemtek_convfreq(unsigned long *freq)
+static unsigned long gemtek_convfreq(unsigned long freq)
{
- (*freq) /= 160;
- (*freq) += 1052; /* FMIN, 10.52 MHz */
- (*freq) *= 1565; /* STDF, 1 / 156.5 = 0.00639 */
- (*freq) /= 1000;
+ return ((freq<<FSCALE) + IF_OFFSET + REF_FREQ/2) / REF_FREQ;
}
/*
@@ -254,10 +259,8 @@ static void gemtek_setfreq(struct gemtek_device *dev, unsigned long freq)
gemtek_bu2614_set(dev, BU2614_FMUN, 1); /* GT bit set */
gemtek_bu2614_set(dev, BU2614_TEST, 0);
- gemtek_convfreq(&freq);
-
gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_STDF_3_125_KHZ);
- gemtek_bu2614_set(dev, BU2614_FREQ, freq);
+ gemtek_bu2614_set(dev, BU2614_FREQ, gemtek_convfreq(freq));
gemtek_bu2614_transmit(dev);
}