Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Mar 1997 16:24:56 -0800
From:      Amancio Hasty <hasty@rah.star-gate.com>
To:        multimedia@freebsd.org
Cc:        Steve Passe <smp@csn.net>
Subject:   First Cut at separating tuner and capture devices
Message-ID:  <199703230024.QAA00352@rah.star-gate.com>

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

[-- Attachment #1 --]

This is patch is against the /sys/pci/brooktree848.c found in 
3.0-current.


Create a tuner device:
mknod tuner0 c 79 16

This means that there can only be a maximum of 15 capture devices .

Access your tuner ioctl thru your tuner device handle and anything
which controls the video capture process thru the video device handle.

The functions which have been added are:

tuner_open
tuner_close
tuner_ioctl

Which are access thru the minor device. What this means is that
applications if they want to access the tuner, they should open
the device "/dev/tuner0", then set channels, mute audio, etc...


Tuner hackers now have a nice isolated home in the driver 8)

Please let me know if you like the changes or not .


	Enjoy,
	Amancio


[-- Attachment #2 --]
*** brooktree848.c.old	Sat Mar 22 16:10:15 1997
--- brooktree848.c	Sat Mar 22 16:05:11 1997
***************
*** 313,318 ****
--- 313,323 ----
  /*
   * tuner specific functions.
   */
+ int tuner_open( dev_t dev, int flags, int fmt, struct proc *p );
+ int tuner_close( dev_t dev, int flags, int fmt, struct proc *p );
+ int tuner_ioctl( dev_t dev, int cmd, caddr_t arg, int flag, struct proc *pr );
+ 
+ 
  static int	tv_channel( bktr_reg_t* bktr, int channel );
  static int	tv_freq( bktr_reg_t* bktr, int frequency );
  static int	tuner_status( bktr_reg_t* bktr );
***************
*** 633,639 ****
  #endif /* DEVFS */
  }
  
! #define UNIT(x) ((x) & 0x07)
  
  
  /*---------------------------------------------------------
--- 638,644 ----
  #endif /* DEVFS */
  }
  
! #define UNIT(x) ((x) & 0x0f)
  
  
  /*---------------------------------------------------------
***************
*** 648,670 ****
   * 
   */
  int
  bktr_open( dev_t dev, int flags, int fmt, struct proc *p )
  {
  	bktr_reg_t	*bktr;
! 	int		unit;
  	int		i;
  	volatile u_char	*bt848;
  	volatile u_char	*bt_reg;
  	volatile u_long	*btl_reg;
  
  	unit = UNIT(minor(dev));
  	if (unit >= NBKTR)			/* unit out of range */
  		return(ENXIO);
  
  	bktr = &(brooktree[unit]);
  
  	if (!(bktr->flags & METEOR_INITALIZED)) /* device not found */
  		return(ENXIO);	
  
  #if defined( MULTIPLE_OPENS )
  	if (bktr->flags & METEOR_OPEN)		/* device already open */
--- 653,703 ----
   * 
   */
  int
+ tuner_open( dev_t dev, int flags, int fmt, struct proc *p ) {
+ 	bktr_reg_t	*bktr;
+ 	int		unit, minor;
+ 	volatile u_char	*bt848;
+ 	unit = UNIT(minor(dev));
+ 	bktr = &(brooktree[unit]);
+ 
+ #if defined( AUDIO_SUPPORT )
+ 	set_audio( bktr, AUDIO_UNMUTE );
+ 	if ( card_types[ bktr->card_type ].dbx )
+ 	    set_BTSC( bktr, 0 );		/* enable the stereo chip */
+ #endif /* AUDIO_SUPPORT */
+ 	    return 0;
+ 
+ }
+ 
+ 
+ int
  bktr_open( dev_t dev, int flags, int fmt, struct proc *p )
  {
  	bktr_reg_t	*bktr;
! 	int		unit, minor;
  	int		i;
  	volatile u_char	*bt848;
  	volatile u_char	*bt_reg;
  	volatile u_long	*btl_reg;
  
  	unit = UNIT(minor(dev));
+ 	minor = minor(dev);
+ 
  	if (unit >= NBKTR)			/* unit out of range */
  		return(ENXIO);
  
+ 
  	bktr = &(brooktree[unit]);
  
  	if (!(bktr->flags & METEOR_INITALIZED)) /* device not found */
  		return(ENXIO);	
+ 	if (minor != 0 ) {
+ #if defined( AUDIO_SUPPORT )
+ 	    set_audio( bktr, AUDIO_UNMUTE );
+ 	    if ( card_types[ bktr->card_type ].dbx )
+ 		set_BTSC( bktr, 0 );		/* enable the stereo chip */
+ #endif /* AUDIO_SUPPORT */
+ 	}
  
  #if defined( MULTIPLE_OPENS )
  	if (bktr->flags & METEOR_OPEN)		/* device already open */
***************
*** 736,741 ****
--- 769,793 ----
  /*
   * 
   */
+ /* tuner close handle */
+ int 
+ tuner_close( dev_t dev, int flags, int fmt, struct proc *p ) {
+ 	int		unit;
+ 	bktr_reg_t	*bktr;
+ 	unit = UNIT(minor(dev));
+ 	bktr = &(brooktree[unit]);
+ 
+ 	/* Place Holder for tuner specific operations on a close */
+ #if defined( AUDIO_SUPPORT )
+ 	/* mute the audio by switching the mux */
+ 	set_audio( bktr, AUDIO_MUTE );
+ #endif /* AUDIO_SUPPORT */
+ 
+ 
+ 	return 0;
+ }
+ 
+ 
  int
  bktr_close( dev_t dev, int flags, int fmt, struct proc *p )
  {
***************
*** 751,756 ****
--- 803,811 ----
  	unit = UNIT(minor(dev));
  	if (unit >= NBKTR)			/* unit out of range */
  		return(ENXIO);
+ 	if (minor(dev) != 0 ) {
+ 	    return tuner_close(dev, flags, fmt, p);
+ 	}
  
  	bktr = &(brooktree[unit]);
  
***************
*** 771,782 ****
  	btl_reg = (u_long *) &bt848[BKTR_INT_STAT] ;
  	*btl_reg = 0xffffffff;
  
! #if defined( AUDIO_SUPPORT )
! 	/* mute the audio by switching the mux */
! 	set_audio( bktr, AUDIO_MUTE );
! #endif /* AUDIO_SUPPORT */
! 
! 	return(0);
  }
  
  
--- 826,832 ----
  	btl_reg = (u_long *) &bt848[BKTR_INT_STAT] ;
  	*btl_reg = 0xffffffff;
  
! 	return tuner_close (  dev, flags,  fmt,  p );
  }
  
  
***************
*** 792,798 ****
  	int		count;
  	volatile u_char *bt848;
  	u_short		*bts_reg;
! 
  	unit = UNIT(minor(dev));
  	if (unit >= NBKTR)	/* unit out of range */
  		return(ENXIO);
--- 842,849 ----
  	int		count;
  	volatile u_char *bt848;
  	u_short		*bts_reg;
! 	
! 	if (minor(dev) > 0 ) return(ENXIO);
  	unit = UNIT(minor(dev));
  	if (unit >= NBKTR)	/* unit out of range */
  		return(ENXIO);
***************
*** 839,877 ****
  }
  
  
! /*
!  * 
!  */
  int
! bktr_ioctl( dev_t dev, int cmd, caddr_t arg, int flag, struct proc *pr )
  {
  	bktr_reg_t		*bktr;
  	int			unit;
  	int			status;
! 	int			count;
! 	int			tmp_int;
! 	volatile u_char		*bt848, c_temp;
! 	volatile u_short	*bts_reg, s_temp;
! 	volatile u_long		*btl_reg;
! 	unsigned int		temp, temp1;
  	unsigned int		error;
- 	struct meteor_geomet	*geo;
- 	struct meteor_counts	*cnt;
- 	struct meteor_video	*video;
- 	vm_offset_t		buf;
  
  	unit = UNIT(minor(dev));
  	if (unit >= NBKTR)	/* unit out of range */
  		return(ENXIO);
  
  
- 	bktr = &(brooktree[unit]);
- 	if (bktr->bigbuf == 0)	/* no frame buffer allocated (ioctl failed) */
- 		return(ENOMEM);
  
  	bt848 =	 bktr->base;
- 	switch (cmd) {
  
  	case TVTUNER_SETCHNL:
  #if defined( AUDIO_SUPPORT )
  		set_audio( bktr, AUDIO_MUTE );
--- 890,917 ----
  }
  
  
! /* tuner ioctls */
! 
  int
! tuner_ioctl( dev_t dev, int cmd, caddr_t arg, int flag, struct proc *pr )
  {
  	bktr_reg_t		*bktr;
  	int			unit;
  	int			status;
! 	volatile u_char		*bt848;
! 	unsigned int		temp;
  	unsigned int		error;
  
  	unit = UNIT(minor(dev));
  	if (unit >= NBKTR)	/* unit out of range */
  		return(ENXIO);
  
  
  
+ 	bktr = &(brooktree[unit]);
  	bt848 =	 bktr->base;
  
+ 	switch (cmd) {
  	case TVTUNER_SETCHNL:
  #if defined( AUDIO_SUPPORT )
  		set_audio( bktr, AUDIO_MUTE );
***************
*** 921,928 ****
  	case TVTUNER_GETFREQ:
  		*(unsigned long *)arg = bktr->tuner.frequency;
  		break;
  
! 	case METEORSTATUS:	/* get 7196 status */
  		c_temp = bt848[0];
  		temp = 0;
  		if (!(c_temp & 0x40)) temp |= METEOR_STATUS_HCLK;
--- 961,1030 ----
  	case TVTUNER_GETFREQ:
  		*(unsigned long *)arg = bktr->tuner.frequency;
  		break;
+ #if defined( AUDIO_SUPPORT )
+ 	case BT848_SAUDIO:	/* set audio channel */
+ 		if ( set_audio( bktr, *(int*)arg ) < 0 )
+ 			return EIO;
+ 		break;
  
! 	case BT848_GAUDIO:	/* get audio channel */
! 		temp = bktr->audio_mux_select;
! 		if ( bktr->audio_mute_state == TRUE )
! 			temp |= AUDIO_MUTE;
! 		*(int*)arg = temp;
! 		break;
! 
! 	case BT848_SBTSC:	/* set audio channel */
! 		if ( set_BTSC( bktr, *(int*)arg ) < 0 )
! 			return EIO;
! 		break;
! #endif /* AUDIO_SUPPORT */
! 	default:
! 		return ENODEV;
! 	    
! 	}
! 
! 	return 0;
! }
! 
! /*
!  * 
!  */
! int
! bktr_ioctl( dev_t dev, int cmd, caddr_t arg, int flag, struct proc *pr )
! {
! 	bktr_reg_t		*bktr;
! 	int			unit;
! 	int			status;
! 	int			count;
! 	int			tmp_int;
! 	volatile u_char		*bt848, c_temp;
! 	volatile u_short	*bts_reg, s_temp;
! 	volatile u_long		*btl_reg;
! 	unsigned int		temp, temp1;
! 	unsigned int		error;
! 	struct meteor_geomet	*geo;
! 	struct meteor_counts	*cnt;
! 	struct meteor_video	*video;
! 	vm_offset_t		buf;
! 
! 	unit = UNIT(minor(dev));
! 	if (unit >= NBKTR)	/* unit out of range */
! 		return(ENXIO);
! 
! 	if (minor(dev) > 0 ) {
! 	   return  tuner_ioctl(minor(dev), cmd, arg, flag, pr);
! 	}
! 
! 
! 	bktr = &(brooktree[unit]);
! 	if (bktr->bigbuf == 0)	/* no frame buffer allocated (ioctl failed) */
! 		return(ENOMEM);
! 
! 	bt848 =	 bktr->base;
! 	switch (cmd) {
! 
! 	case METEORSTATUS:	/* get Bt848  status */
  		c_temp = bt848[0];
  		temp = 0;
  		if (!(c_temp & 0x40)) temp |= METEOR_STATUS_HCLK;
***************
*** 1229,1253 ****
  		bt848[BKTR_COLOR_CTL] &= ~0x40;
  		break;
  
- #if defined( AUDIO_SUPPORT )
- 	case BT848_SAUDIO:	/* set audio channel */
- 		if ( set_audio( bktr, *(int*)arg ) < 0 )
- 			return EIO;
- 		break;
- 
- 	case BT848_GAUDIO:	/* get audio channel */
- 		temp = bktr->audio_mux_select;
- 		if ( bktr->audio_mute_state == TRUE )
- 			temp |= AUDIO_MUTE;
- 		*(int*)arg = temp;
- 		break;
- 
- 	case BT848_SBTSC:	/* set audio channel */
- 		if ( set_BTSC( bktr, *(int*)arg ) < 0 )
- 			return EIO;
- 		break;
- #endif /* AUDIO_SUPPORT */
- 
  	case METEORSSIGNAL:
  		bktr->signal = *(int *) arg;
  		bktr->proc = pr;
--- 1331,1336 ----
***************
*** 1546,1553 ****
  
  	unit = UNIT(minor(dev));
  
! 	if (unit >= NBKTR)		/* at this point could this happen? */
  		return(-1);
  
  	bktr = &(brooktree[unit]);
  
--- 1629,1637 ----
  
  	unit = UNIT(minor(dev));
  
! 	if (unit >= NBKTR || minor(dev) > 0 )	/* at this point could this happen? */
  		return(-1);
+ 
  
  	bktr = &(brooktree[unit]);
  

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