162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ciThe bttv driver
462306a36Sopenharmony_ci===============
562306a36Sopenharmony_ci
662306a36Sopenharmony_cibttv and sound mini howto
762306a36Sopenharmony_ci-------------------------
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciThere are a lot of different bt848/849/878/879 based boards available.
1062306a36Sopenharmony_ciMaking video work often is not a big deal, because this is handled
1162306a36Sopenharmony_cicompletely by the bt8xx chip, which is common on all boards.  But
1262306a36Sopenharmony_cisound is handled in slightly different ways on each board.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciTo handle the grabber boards correctly, there is a array tvcards[] in
1562306a36Sopenharmony_cibttv-cards.c, which holds the information required for each board.
1662306a36Sopenharmony_ciSound will work only, if the correct entry is used (for video it often
1762306a36Sopenharmony_cimakes no difference).  The bttv driver prints a line to the kernel
1862306a36Sopenharmony_cilog, telling which card type is used.  Like this one::
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci	bttv0: model: BT848(Hauppauge old) [autodetected]
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciYou should verify this is correct.  If it isn't, you have to pass the
2362306a36Sopenharmony_cicorrect board type as insmod argument, ``insmod bttv card=2`` for
2462306a36Sopenharmony_ciexample.  The file Documentation/admin-guide/media/bttv-cardlist.rst has a list
2562306a36Sopenharmony_ciof valid arguments for card.
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciIf your card isn't listed there, you might check the source code for
2862306a36Sopenharmony_cinew entries which are not listed yet.  If there isn't one for your
2962306a36Sopenharmony_cicard, you can check if one of the existing entries does work for you
3062306a36Sopenharmony_ci(just trial and error...).
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ciSome boards have an extra processor for sound to do stereo decoding
3362306a36Sopenharmony_ciand other nice features.  The msp34xx chips are used by Hauppauge for
3462306a36Sopenharmony_ciexample.  If your board has one, you might have to load a helper
3562306a36Sopenharmony_cimodule like ``msp3400`` to make sound work.  If there isn't one for the
3662306a36Sopenharmony_cichip used on your board:  Bad luck.  Start writing a new one.  Well,
3762306a36Sopenharmony_ciyou might want to check the video4linux mailing list archive first...
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciOf course you need a correctly installed soundcard unless you have the
4062306a36Sopenharmony_cispeakers connected directly to the grabber board.  Hint: check the
4162306a36Sopenharmony_cimixer settings too.  ALSA for example has everything muted by default.
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciHow sound works in detail
4562306a36Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ciStill doesn't work?  Looks like some driver hacking is required.
4862306a36Sopenharmony_ciBelow is a do-it-yourself description for you.
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ciThe bt8xx chips have 32 general purpose pins, and registers to control
5162306a36Sopenharmony_cithese pins.  One register is the output enable register
5262306a36Sopenharmony_ci(``BT848_GPIO_OUT_EN``), it says which pins are actively driven by the
5362306a36Sopenharmony_cibt848 chip.  Another one is the data register (``BT848_GPIO_DATA``), where
5462306a36Sopenharmony_ciyou can get/set the status if these pins.  They can be used for input
5562306a36Sopenharmony_ciand output.
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciMost grabber board vendors use these pins to control an external chip
5862306a36Sopenharmony_ciwhich does the sound routing.  But every board is a little different.
5962306a36Sopenharmony_ciThese pins are also used by some companies to drive remote control
6062306a36Sopenharmony_cireceiver chips.  Some boards use the i2c bus instead of the gpio pins
6162306a36Sopenharmony_cito connect the mux chip.
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciAs mentioned above, there is a array which holds the required
6462306a36Sopenharmony_ciinformation for each known board.  You basically have to create a new
6562306a36Sopenharmony_ciline for your board.  The important fields are these two::
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci  struct tvcard
6862306a36Sopenharmony_ci  {
6962306a36Sopenharmony_ci	[ ... ]
7062306a36Sopenharmony_ci	u32 gpiomask;
7162306a36Sopenharmony_ci	u32 audiomux[6]; /* Tuner, Radio, external, internal, mute, stereo */
7262306a36Sopenharmony_ci  };
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_cigpiomask specifies which pins are used to control the audio mux chip.
7562306a36Sopenharmony_ciThe corresponding bits in the output enable register
7662306a36Sopenharmony_ci(``BT848_GPIO_OUT_EN``) will be set as these pins must be driven by the
7762306a36Sopenharmony_cibt848 chip.
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciThe ``audiomux[]`` array holds the data values for the different inputs
8062306a36Sopenharmony_ci(i.e. which pins must be high/low for tuner/mute/...).  This will be
8162306a36Sopenharmony_ciwritten to the data register (``BT848_GPIO_DATA``) to switch the audio
8262306a36Sopenharmony_cimux.
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciWhat you have to do is figure out the correct values for gpiomask and
8662306a36Sopenharmony_cithe audiomux array.  If you have Windows and the drivers four your
8762306a36Sopenharmony_cicard installed, you might to check out if you can read these registers
8862306a36Sopenharmony_civalues used by the windows driver.  A tool to do this is available
8962306a36Sopenharmony_cifrom http://btwincap.sourceforge.net/download.html.
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ciYou might also dig around in the ``*.ini`` files of the Windows applications.
9262306a36Sopenharmony_ciYou can have a look at the board to see which of the gpio pins are
9362306a36Sopenharmony_ciconnected at all and then start trial-and-error ...
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ciStarting with release 0.7.41 bttv has a number of insmod options to
9762306a36Sopenharmony_cimake the gpio debugging easier:
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	=================	==============================================
10062306a36Sopenharmony_ci	bttv_gpio=0/1		enable/disable gpio debug messages
10162306a36Sopenharmony_ci	gpiomask=n		set the gpiomask value
10262306a36Sopenharmony_ci	audiomux=i,j,...	set the values of the audiomux array
10362306a36Sopenharmony_ci	audioall=a		set the values of the audiomux array (one
10462306a36Sopenharmony_ci				value for all array elements, useful to check
10562306a36Sopenharmony_ci				out which effect the particular value has).
10662306a36Sopenharmony_ci	=================	==============================================
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciThe messages printed with ``bttv_gpio=1`` look like this::
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	bttv0: gpio: en=00000027, out=00000024 in=00ffffd8 [audio: off]
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci	en  =	output _en_able register (BT848_GPIO_OUT_EN)
11362306a36Sopenharmony_ci	out =	_out_put bits of the data register (BT848_GPIO_DATA),
11462306a36Sopenharmony_ci		i.e. BT848_GPIO_DATA & BT848_GPIO_OUT_EN
11562306a36Sopenharmony_ci	in  = 	_in_put bits of the data register,
11662306a36Sopenharmony_ci		i.e. BT848_GPIO_DATA & ~BT848_GPIO_OUT_EN
117