18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciThe bttv driver
48c2ecf20Sopenharmony_ci===============
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_cibttv and sound mini howto
78c2ecf20Sopenharmony_ci-------------------------
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciThere are a lot of different bt848/849/878/879 based boards available.
108c2ecf20Sopenharmony_ciMaking video work often is not a big deal, because this is handled
118c2ecf20Sopenharmony_cicompletely by the bt8xx chip, which is common on all boards.  But
128c2ecf20Sopenharmony_cisound is handled in slightly different ways on each board.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciTo handle the grabber boards correctly, there is a array tvcards[] in
158c2ecf20Sopenharmony_cibttv-cards.c, which holds the information required for each board.
168c2ecf20Sopenharmony_ciSound will work only, if the correct entry is used (for video it often
178c2ecf20Sopenharmony_cimakes no difference).  The bttv driver prints a line to the kernel
188c2ecf20Sopenharmony_cilog, telling which card type is used.  Like this one::
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	bttv0: model: BT848(Hauppauge old) [autodetected]
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciYou should verify this is correct.  If it isn't, you have to pass the
238c2ecf20Sopenharmony_cicorrect board type as insmod argument, ``insmod bttv card=2`` for
248c2ecf20Sopenharmony_ciexample.  The file :doc:`/admin-guide/media/bttv-cardlist` has a list
258c2ecf20Sopenharmony_ciof valid arguments for card.
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciIf your card isn't listed there, you might check the source code for
288c2ecf20Sopenharmony_cinew entries which are not listed yet.  If there isn't one for your
298c2ecf20Sopenharmony_cicard, you can check if one of the existing entries does work for you
308c2ecf20Sopenharmony_ci(just trial and error...).
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciSome boards have an extra processor for sound to do stereo decoding
338c2ecf20Sopenharmony_ciand other nice features.  The msp34xx chips are used by Hauppauge for
348c2ecf20Sopenharmony_ciexample.  If your board has one, you might have to load a helper
358c2ecf20Sopenharmony_cimodule like ``msp3400`` to make sound work.  If there isn't one for the
368c2ecf20Sopenharmony_cichip used on your board:  Bad luck.  Start writing a new one.  Well,
378c2ecf20Sopenharmony_ciyou might want to check the video4linux mailing list archive first...
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciOf course you need a correctly installed soundcard unless you have the
408c2ecf20Sopenharmony_cispeakers connected directly to the grabber board.  Hint: check the
418c2ecf20Sopenharmony_cimixer settings too.  ALSA for example has everything muted by default.
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ciHow sound works in detail
458c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciStill doesn't work?  Looks like some driver hacking is required.
488c2ecf20Sopenharmony_ciBelow is a do-it-yourself description for you.
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciThe bt8xx chips have 32 general purpose pins, and registers to control
518c2ecf20Sopenharmony_cithese pins.  One register is the output enable register
528c2ecf20Sopenharmony_ci(``BT848_GPIO_OUT_EN``), it says which pins are actively driven by the
538c2ecf20Sopenharmony_cibt848 chip.  Another one is the data register (``BT848_GPIO_DATA``), where
548c2ecf20Sopenharmony_ciyou can get/set the status if these pins.  They can be used for input
558c2ecf20Sopenharmony_ciand output.
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ciMost grabber board vendors use these pins to control an external chip
588c2ecf20Sopenharmony_ciwhich does the sound routing.  But every board is a little different.
598c2ecf20Sopenharmony_ciThese pins are also used by some companies to drive remote control
608c2ecf20Sopenharmony_cireceiver chips.  Some boards use the i2c bus instead of the gpio pins
618c2ecf20Sopenharmony_cito connect the mux chip.
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciAs mentioned above, there is a array which holds the required
648c2ecf20Sopenharmony_ciinformation for each known board.  You basically have to create a new
658c2ecf20Sopenharmony_ciline for your board.  The important fields are these two::
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci  struct tvcard
688c2ecf20Sopenharmony_ci  {
698c2ecf20Sopenharmony_ci	[ ... ]
708c2ecf20Sopenharmony_ci	u32 gpiomask;
718c2ecf20Sopenharmony_ci	u32 audiomux[6]; /* Tuner, Radio, external, internal, mute, stereo */
728c2ecf20Sopenharmony_ci  };
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cigpiomask specifies which pins are used to control the audio mux chip.
758c2ecf20Sopenharmony_ciThe corresponding bits in the output enable register
768c2ecf20Sopenharmony_ci(``BT848_GPIO_OUT_EN``) will be set as these pins must be driven by the
778c2ecf20Sopenharmony_cibt848 chip.
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciThe ``audiomux[]`` array holds the data values for the different inputs
808c2ecf20Sopenharmony_ci(i.e. which pins must be high/low for tuner/mute/...).  This will be
818c2ecf20Sopenharmony_ciwritten to the data register (``BT848_GPIO_DATA``) to switch the audio
828c2ecf20Sopenharmony_cimux.
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciWhat you have to do is figure out the correct values for gpiomask and
868c2ecf20Sopenharmony_cithe audiomux array.  If you have Windows and the drivers four your
878c2ecf20Sopenharmony_cicard installed, you might to check out if you can read these registers
888c2ecf20Sopenharmony_civalues used by the windows driver.  A tool to do this is available
898c2ecf20Sopenharmony_cifrom http://btwincap.sourceforge.net/download.html.
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciYou might also dig around in the ``*.ini`` files of the Windows applications.
928c2ecf20Sopenharmony_ciYou can have a look at the board to see which of the gpio pins are
938c2ecf20Sopenharmony_ciconnected at all and then start trial-and-error ...
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ciStarting with release 0.7.41 bttv has a number of insmod options to
978c2ecf20Sopenharmony_cimake the gpio debugging easier:
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	=================	==============================================
1008c2ecf20Sopenharmony_ci	bttv_gpio=0/1		enable/disable gpio debug messages
1018c2ecf20Sopenharmony_ci	gpiomask=n		set the gpiomask value
1028c2ecf20Sopenharmony_ci	audiomux=i,j,...	set the values of the audiomux array
1038c2ecf20Sopenharmony_ci	audioall=a		set the values of the audiomux array (one
1048c2ecf20Sopenharmony_ci				value for all array elements, useful to check
1058c2ecf20Sopenharmony_ci				out which effect the particular value has).
1068c2ecf20Sopenharmony_ci	=================	==============================================
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciThe messages printed with ``bttv_gpio=1`` look like this::
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	bttv0: gpio: en=00000027, out=00000024 in=00ffffd8 [audio: off]
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	en  =	output _en_able register (BT848_GPIO_OUT_EN)
1138c2ecf20Sopenharmony_ci	out =	_out_put bits of the data register (BT848_GPIO_DATA),
1148c2ecf20Sopenharmony_ci		i.e. BT848_GPIO_DATA & BT848_GPIO_OUT_EN
1158c2ecf20Sopenharmony_ci	in  = 	_in_put bits of the data register,
1168c2ecf20Sopenharmony_ci		i.e. BT848_GPIO_DATA & ~BT848_GPIO_OUT_EN
117