Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Mar 1997 13:28:40 -0700
From:      Steve Passe <smp@csn.net>
To:        multimedia@freebsd.org
Subject:   table driven tuning
Message-ID:  <199703182028.NAA17830@Ilsa.StevesCafe.com>

next in thread | raw e-mail | index | archive | help
Hi,

could someone confirm that the following patches DO NOT break cable tuning.
I have re-written this code to be table driven, eliminating the seperate
routines for each tuning mode (broadcast, cable, etc).  There are dummy
entries for hrc cable and european cable, please impliment if you can.

sys/i386/include:
------------------------------------- cut -------------------------------------
*** ioctl_bt848.h.orig	1997/03/18 17:40:43	1.2
--- ioctl_bt848.h	1997/03/18 19:21:49
***************
*** 9,14 ****
--- 9,16 ----
  #define TUNERTYPE_CABLEIRC	2
  #define TUNERTYPE_CABLEHRC	3
  #define TUNERTYPE_WEUROPE	4
+ #define TUNERTYPE_MIN		TUNERTYPE_NABCST
+ #define TUNERTYPE_MAX		TUNERTYPE_WEUROPE
  
  
  /*
------------------------------------- cut -------------------------------------

sys/pci:
------------------------------------- cut -------------------------------------
*** brooktree848.c.orig	1997/03/18 17:43:30	1.6
--- brooktree848.c	1997/03/18 20:13:30
***************
*** 1428,1434 ****
  
  	case TVTUNER_SETCHNL:
  		temp = tv_channel( bktr, (int)*(unsigned long *)arg );
! 		if ( temp < 0 ) return EIO;
  		*(unsigned long *)arg = temp;
  		break;
  
--- 1428,1435 ----
  
  	case TVTUNER_SETCHNL:
  		temp = tv_channel( bktr, (int)*(unsigned long *)arg );
! 		if ( temp < 0 )
! 			return EINVAL;
  		*(unsigned long *)arg = temp;
  		break;
  
***************
*** 1437,1443 ****
  		break;
  
  	case TVTUNER_SETTYPE:
! 		bktr->tuner.tunertype = *(unsigned long *)arg;
  		break;
  
  	case TVTUNER_GETTYPE:
--- 1438,1447 ----
  		break;
  
  	case TVTUNER_SETTYPE:
! 		temp = *(unsigned long *)arg;
! 		if ( (temp < TUNERTYPE_MIN) || (temp > TUNERTYPE_MAX) )
! 			return EINVAL;
! 		bktr->tuner.tunertype = temp;
  		break;
  
  	case TVTUNER_GETTYPE:
***************
*** 1451,1457 ****
  
  	case TVTUNER_SETFREQ:
  		temp = tv_freq( bktr, (int)*(unsigned long *)arg );
! 		if ( temp < 0 ) return EIO;
  		*(unsigned long *)arg = temp;
  		break;
  
--- 1455,1462 ----
  
  	case TVTUNER_SETFREQ:
  		temp = tv_freq( bktr, (int)*(unsigned long *)arg );
! 		if ( temp < 0 )
! 			return EINVAL;
  		*(unsigned long *)arg = temp;
  		break;
  
***************
*** 2108,2120 ****
  #endif /* XXXXXX_TUNER */
  
  /* scaling factor for frequencies expressed as ints */
- #define TEST_A
- 
- #if defined( TEST_A )
  #define FREQFACTOR		16
- #else
- #define FREQFACTOR		100
- #endif
  
  
  /******************************* i2c primitives *****************************
*/
--- 2113,2119 ----
***************
*** 2310,2378 ****
  #define I2C_REGADDR()		(i2c_regptr_t)&bktr->base[ BKTR_I2C_CONTROL ]
  
  /*
!  * set the frequency of the tuner
   */
- static int
- tv_freq( bktr_reg_t* bktr, int frequency )
- {
- 	i2c_regptr_t	bti2c;
- 	u_char		band;
- 	int		N;
- 	int		order;
- 
- 	/* select the band based on frequency */
- 	if ( frequency < (160 * FREQFACTOR) )
- 		band = TSA5522_BANDA;
- 	else if ( frequency < (454 * FREQFACTOR) )
- 		band = TSA5522_BANDB;
- 	else
- 		band = TSA5522_BANDC;
- 
- 	/*
- 	 * N = 16 * { fRF(pc) + fIF(pc) }
- 	 * where:
- 	 *  pc is picture carrier, fRF & fIF are in mHz
- 	 */
- #if defined( TEST_A )
- 	/*
- 	 * frequency is mHz * 16, eg. 55.25 mHz * 16 == 884
- 	 */
- 	N = (frequency + 732 /* 45.75 * 16 */);
- #else
- 	/*
- 	 * frequency is mHz to 2 decimal places, ie. 5525 == 55.25 mHz,
- 	 */
- 	N = 16 * ((frequency + IF_FREQUENCY) / FREQFACTOR);
- #endif
- 	/* get the i2c register address */
- 	bti2c = I2C_REGADDR();
- 
- 	/* send the data to the TSA5522 */
- 	disable_intr();
- 	i2cStart( bti2c, TSA5522_WADDR );
- 
- 	/* the data sheet wants the order set according to direction */
- 	if ( frequency > bktr->tuner.frequency ) {
- 		i2cWrite( bti2c, (N >> 8) & 0x7f );	/* divisor MSB */
- 		i2cWrite( bti2c, N & 0xff );		/* divisor LSB */
- 		i2cWrite( bti2c, TSA5522_CONTROL );	/* control bits */
- 		i2cWrite( bti2c, band );		/* band select */
- 	}
- 	else {
- 		i2cWrite( bti2c, TSA5522_CONTROL );	/* control bits */
- 		i2cWrite( bti2c, band );		/* band select */
- 		i2cWrite( bti2c, (N >> 8) & 0x7f );	/* divisor MSB */
- 		i2cWrite( bti2c, N & 0xff );		/* divisor LSB */
- 	}
- 
- 	i2cStop( bti2c );
- 	enable_intr();
- 
- 	bktr->tuner.frequency = frequency;
- 
- 	return 0;
- }
- 
  
  /*
   * North American Broadcast Channels:
--- 2309,2333 ----
  #define I2C_REGADDR()		(i2c_regptr_t)&bktr->base[ BKTR_I2C_CONTROL ]
  
  /*
!  * Format:
!  *	entry 0:         MAX legal channel
!  *	entry 1:         IF frequency
!  *			 expressed as fi{mHz} * 16,
!  *			 eg 45.75mHz == 45.75 * 16 = 732
!  *	entry 2:         [place holder/future]
!  *	entry 3:         base of channel record 0
!  *	entry 3 + (x*3): base of channel record 'x'
!  *	entry LAST:      NULL channel entry marking end of records
!  *
!  * Record:
!  *	int 0:		base channel
!  *	int 1:		frequency of base channel,
!  *			 expressed as fb{mHz} * 16,
!  *			 eg 55.25mHz == 55.25 * 16 = 884
!  *	int 2:		offset frequency between channels,
!  *			 expressed as fo{mHz} * 16,
!  *			 eg 6.00mHz == 6.00 * 16 = 96
   */
  
  /*
   * North American Broadcast Channels:
***************
*** 2393,2437 ****
   * 14	471.25 mHz
   * 83	885.25 mHz
   */
! static int
! frequency_nabcst( int channel )
! {
! 	/* legal channels are 2 thru 83 */
! 	if ( channel > 83 )
! 		return -1;
! 
! 	/* channels 14 thru 83 */
! 	if ( channel >= 14 )
! #if defined( TEST_A )
! 		return 7540 + ((channel-14) * 96 );
! #else
! 		return 47125 + ((channel-14) * 600 );
! #endif
! 	/* channels 7 thru 13 */
! 	if ( channel >= 7 )
! #if defined( TEST_A )
! 		return 2804 + ((channel-7) * 96 );
! #else
! 		return 17525 + ((channel-7) * 600 );
! #endif
! 	/* channels 5 thru 6 */
! 	if ( channel >= 5 )
! #if defined( TEST_A )
! 		return 1236 + ((channel-5) * 96 );
! #else
! 		return 7725 + ((channel-5) * 600 );
! #endif
! 	/* channels 2 thru 4 */
! 	if ( channel >= 2 )
! #if defined( TEST_A )
! 		return 884 + ((channel-2) * 96 );
! #else
! 		return 5525 + ((channel-2) * 600 );
! #endif
! 	/* legal channels are 2 thru 83 */
! 	return -1;
! }
! 
  
  /*
   * North American Cable Channels, IRC(?):
--- 2348,2361 ----
   * 14	471.25 mHz
   * 83	885.25 mHz
   */
! int	nabcst[] = {
! 	83,  732,  0,
! 	14, 7540, 96,
! 	 7, 2804, 96,
! 	 5, 1236, 96,
! 	 2,  884, 96,
! 	 0
! };
  
  /*
   * North American Cable Channels, IRC(?):
***************
*** 2458,2526 ****
   * 95	 91.25 mHz
   * 99	115.25 mHz
   */
  static int
! frequency_irccable( int channel )
  {
! 	/* legal channels are 2 thru 99 */
! 	if ( channel > 99 )
  		return -1;
  
! 	/* channels 95 thru 99 */
! 	if ( channel >= 95 )
! 		return 9125 + ((channel-95) * 600 );
! 
! 	/* channels 23 thru 94 */
! 	if ( channel >= 23 )
! 		return 21725 + ((channel-23) * 600 );
! 
! 	/* channels 14 thru 22 */
! 	if ( channel >= 14 )
! 		return 12125 + ((channel-14) * 600 );
! 
! 	/* channels 7 thru 13 */
! 	if ( channel >= 7 )
! 		return 17525 + ((channel-7) * 600 );
! 
! 	/* channels 5 thru 6 */
! 	if ( channel >= 5 )
! 		return 7725 + ((channel-5) * 600 );
! 
! 	/* channels 2 thru 4 */
! 	if ( channel >= 2 )
! 		return 5525 + ((channel-2) * 600 );
  
! 	/* legal channels are 2 thru 99 */
  	return -1;
  }
  
  
  /*
!  * set the channel of the tuner
   */
  static int
! tv_channel( bktr_reg_t* bktr, int channel )
  {
! 	int frequency, status;
  
! 	/* calculate the frequency according to tuner type */
! 	switch ( bktr->tuner.tunertype ) {
! 	case TUNERTYPE_NABCST:
! 		frequency = frequency_nabcst( channel );
! 		break;
  
! 	case TUNERTYPE_CABLEIRC:
! 		frequency = frequency_irccable( channel );
! 		break;
  
! 	/* FIXME: */
! 	case TUNERTYPE_CABLEHRC:
! 	case TUNERTYPE_WEUROPE:
! 	default:
! 		return -1;
  	}
  
! 	/* check the result of channel to frequency conversion */
! 	if ( frequency < 0 )
  		return -1;
  
  	/* set the new frequency */
--- 2382,2515 ----
   * 95	 91.25 mHz
   * 99	115.25 mHz
   */
+ int	irccable[] = {
+ 	99,  732,  0,
+ 	95, 1460, 96,
+ 	23, 3476, 96,
+ 	14, 1940, 96,
+ 	 7, 2804, 96,
+ 	 5, 1236, 96,
+ 	 2,  884, 96,
+ 	 0
+ };
+ 
+ int	hrccable[] = {
+ 	0, 0, 0,
+ 	0
+ };
+ 
+ int	weurope[] = {
+ 	0, 0, 0,
+ 	0
+ };
+ 
+ int* freqTable[] = {
+ 	NULL,
+ 	nabcst,
+ 	irccable,
+ 	hrccable,
+ 	weurope
+ };
+ 
+ 
+ #define TBL_CHNL	freqTable[ bktr->tuner.tunertype ][ x ]
+ #define TBL_BASE_FREQ	freqTable[ bktr->tuner.tunertype ][ x + 1 ]
+ #define TBL_OFFSET	freqTable[ bktr->tuner.tunertype ][ x + 2 ]
  static int
! frequency_lookup( bktr_reg_t* bktr, int channel )
  {
! 	int	x = 0;
! 
! 	/* check for "> MAX channel" */
! 	if ( channel > TBL_CHNL )
  		return -1;
  
! 	/* search the table for data */
! 	for ( x = 3; TBL_CHNL; x += 3 ) {
! 		if ( channel >= TBL_CHNL ) {
! 			return
! 			  (TBL_BASE_FREQ + ((channel-TBL_CHNL) * TBL_OFFSET));
! 		}
! 	}
  
! 	/* not found, must be below the MIN channel */
  	return -1;
  }
+ #undef TBL_OFFSET
+ #undef TBL_BASE_FREQ
+ #undef TBL_CHNL
  
  
+ #define TBL_IF	freqTable[ bktr->tuner.tunertype ][ 1 ]
  /*
!  * set the frequency of the tuner
   */
  static int
! tv_freq( bktr_reg_t* bktr, int frequency )
  {
! 	i2c_regptr_t	bti2c;
! 	u_char		band;
! 	int		N;
! 	int		order;
  
! 	/* select the band based on frequency */
! 	if ( frequency < (160 * FREQFACTOR) )
! 		band = TSA5522_BANDA;
! 	else if ( frequency < (454 * FREQFACTOR) )
! 		band = TSA5522_BANDB;
! 	else
! 		band = TSA5522_BANDC;
  
! 	/*
! 	 * N = 16 * { fRF(pc) + fIF(pc) }
! 	 * where:
! 	 *  pc is picture carrier, fRF & fIF are in mHz
! 	 *
! 	 * frequency is mHz * 16, eg. 55.25 mHz * 16 == 884
! 	 */
! 	N = frequency + TBL_IF;
  
! 	/* get the i2c register address */
! 	bti2c = I2C_REGADDR();
! 
! 	/* send the data to the TSA5522 */
! 	disable_intr();
! 	i2cStart( bti2c, TSA5522_WADDR );
! 
! 	/* the data sheet wants the order set according to direction */
! 	if ( frequency > bktr->tuner.frequency ) {
! 		i2cWrite( bti2c, (N >> 8) & 0x7f );	/* divisor MSB */
! 		i2cWrite( bti2c, N & 0xff );		/* divisor LSB */
! 		i2cWrite( bti2c, TSA5522_CONTROL );	/* control bits */
! 		i2cWrite( bti2c, band );		/* band select */
! 	}
! 	else {
! 		i2cWrite( bti2c, TSA5522_CONTROL );	/* control bits */
! 		i2cWrite( bti2c, band );		/* band select */
! 		i2cWrite( bti2c, (N >> 8) & 0x7f );	/* divisor MSB */
! 		i2cWrite( bti2c, N & 0xff );		/* divisor LSB */
  	}
  
! 	i2cStop( bti2c );
! 	enable_intr();
! 
! 	bktr->tuner.frequency = frequency;
! 
! 	return 0;
! }
! #undef TBL_IF
! 
! 
! /*
!  * set the channel of the tuner
!  */
! static int
! tv_channel( bktr_reg_t* bktr, int channel )
! {
! 	int frequency;
! 
! 	/* calculate the frequency according to tuner type */
! 	if ( (frequency = frequency_lookup( bktr, channel )) < 0 )
  		return -1;
  
  	/* set the new frequency */
***************
*** 2535,2541 ****
  
  
  /*
!  * set the channel of the tuner
   */
  static int
  tuner_status( bktr_reg_t* bktr )
--- 2524,2530 ----
  
  
  /*
!  * get the status of the tuner
   */
  static int
  tuner_status( bktr_reg_t* bktr )
------------------------------------- cut -------------------------------------

--
Steve Passe	| powered by
smp@csn.net	|            Symmetric MultiProcessor FreeBSD




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199703182028.NAA17830>