Skip to content

Commit 8aff8ba

Browse files
pitman75Mauro Carvalho Chehab
authored andcommitted
[media] tm6000: add radio support to the driver
Changes: Add function tm6000_set_reg_mask for change some bits in regs. Very usefull, simplify some code with this function. Add control mute Add control volume Add control audio input MUX Add support radio Radio works well. TV works too Known bugs: The programm gnomeradio can't set freq for radio, it use old v4l API. Audio over USB works via arecord. The programm mplayer can set freq but no any audio mplayer -v -rawaudio rate=48000 radio://105.2/capture driver=v4l2:alsa:adevice=hw.1,0:amode=1:audiorate=48000:forceaudio:immediatemode=0 When start watch TV very shortly after radio the kernel crashed hardly. Didn't stop all USB URBs, need some time for stop. [mchehab@redhat.com: fix merge conflicts] Signed-off-by: Beholder Intl. Ltd. Dmitry Belimov <d.belimov@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
1 parent 6ca0004 commit 8aff8ba

6 files changed

Lines changed: 566 additions & 101 deletions

File tree

‎drivers/staging/tm6000/tm6000-alsa.c‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,11 @@ MODULE_PARM_DESC(debug, "enable debug messages");
7676
static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
7777
{
7878
struct tm6000_core *core = chip->core;
79-
int val;
8079

8180
dprintk(1, "Starting audio DMA\n");
8281

8382
/* Enables audio */
84-
val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0);
85-
val |= 0x20;
86-
tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
83+
tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x40, 0x40);
8784

8885
tm6000_set_audio_bitrate(core, 48000);
8986

@@ -98,13 +95,11 @@ static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
9895
static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip)
9996
{
10097
struct tm6000_core *core = chip->core;
101-
int val;
98+
10299
dprintk(1, "Stopping audio DMA\n");
103100

104-
/* Enables audio */
105-
val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0);
106-
val &= ~0x20;
107-
tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
101+
/* Disables audio */
102+
tm6000_set_reg_mask(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x00, 0x40);
108103

109104
tm6000_set_reg(core, TM6010_REQ08_R01_A_INIT, 0);
110105

‎drivers/staging/tm6000/tm6000-cards.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ struct tm6000_board {
6666
char *name;
6767

6868
struct tm6000_capabilities caps;
69+
enum tm6000_inaudio aradio;
70+
enum tm6000_inaudio avideo;
6971

7072
enum tm6000_devtype type; /* variant of the chipset */
7173
int tuner_type; /* type of the tuner */
@@ -230,6 +232,8 @@ struct tm6000_board tm6000_boards[] = {
230232
.tuner_addr = 0xc2 >> 1,
231233
.demod_addr = 0x1e >> 1,
232234
.type = TM6010,
235+
.avideo = TM6000_AIP_SIF1,
236+
.aradio = TM6000_AIP_LINE1,
233237
.caps = {
234238
.has_tuner = 1,
235239
.has_dvb = 1,
@@ -248,6 +252,8 @@ struct tm6000_board tm6000_boards[] = {
248252
.tuner_type = TUNER_XC5000,
249253
.tuner_addr = 0xc2 >> 1,
250254
.type = TM6010,
255+
.avideo = TM6000_AIP_SIF1,
256+
.aradio = TM6000_AIP_LINE1,
251257
.caps = {
252258
.has_tuner = 1,
253259
.has_dvb = 0,
@@ -693,13 +699,12 @@ static void tm6000_config_tuner(struct tm6000_core *dev)
693699
struct xc5000_config ctl = {
694700
.i2c_address = dev->tuner_addr,
695701
.if_khz = 4570,
696-
.radio_input = XC5000_RADIO_FM1,
702+
.radio_input = XC5000_RADIO_FM1_MONO,
697703
};
698704

699705
xc5000_cfg.tuner = TUNER_XC5000;
700706
xc5000_cfg.priv = &ctl;
701707

702-
703708
v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
704709
&xc5000_cfg);
705710
}
@@ -732,6 +737,8 @@ static int tm6000_init_dev(struct tm6000_core *dev)
732737

733738
dev->caps = tm6000_boards[dev->model].caps;
734739

740+
dev->avideo = tm6000_boards[dev->model].avideo;
741+
dev->aradio = tm6000_boards[dev->model].aradio;
735742
/* initialize hardware */
736743
rc = tm6000_init(dev);
737744
if (rc < 0)

‎drivers/staging/tm6000/tm6000-core.c‎

Lines changed: 224 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,29 @@ int tm6000_get_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index)
116116
}
117117
EXPORT_SYMBOL_GPL(tm6000_get_reg);
118118

119+
int tm6000_set_reg_mask(struct tm6000_core *dev, u8 req, u16 value,
120+
u16 index, u16 mask)
121+
{
122+
int rc;
123+
u8 buf[1];
124+
u8 new_index;
125+
126+
rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR, req,
127+
value, index, buf, 1);
128+
129+
if (rc < 0)
130+
return rc;
131+
132+
new_index = (buf[0] & ~mask) | (index & mask);
133+
134+
if (new_index == index)
135+
return 0;
136+
137+
return tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR,
138+
req, value, new_index, NULL, 0);
139+
}
140+
EXPORT_SYMBOL_GPL(tm6000_set_reg_mask);
141+
119142
int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index)
120143
{
121144
int rc;
@@ -245,17 +268,12 @@ int tm6000_init_analog_mode(struct tm6000_core *dev)
245268
struct v4l2_frequency f;
246269

247270
if (dev->dev_type == TM6010) {
248-
int val;
249-
250271
/* Enable video */
251-
val = tm6000_get_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0);
252-
val |= 0x60;
253-
tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
254-
val = tm6000_get_reg(dev,
255-
TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0);
256-
val &= ~0x40;
257-
tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, val);
258272

273+
tm6000_set_reg_mask(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF,
274+
0x60, 0x60);
275+
tm6000_set_reg_mask(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE,
276+
0x00, 0x40);
259277
tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc);
260278

261279
} else {
@@ -471,6 +489,14 @@ struct reg_init tm6010_init_tab[] = {
471489
{ TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0 },
472490
{ TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2 },
473491
{ TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x60 },
492+
{ TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00},
493+
{ TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0x80},
494+
{ TM6010_REQ08_R0C_A_ASD_THRES2, 0x0a},
495+
{ TM6010_REQ08_R0D_A_AMD_THRES, 0x40},
496+
{ TM6010_REQ08_R1A_A_NICAM_SER_MAX, 0x64},
497+
{ TM6010_REQ08_R1B_A_NICAM_SER_MIN, 0x20},
498+
{ TM6010_REQ08_R16_A_AGC_GAIN_MAX, 0xfe},
499+
{ TM6010_REQ08_R17_A_AGC_GAIN_MIN, 0x01},
474500
{ TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc },
475501

476502
{ TM6010_REQ07_R3F_RESET, 0x01 },
@@ -591,51 +617,213 @@ int tm6000_init(struct tm6000_core *dev)
591617

592618
int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate)
593619
{
594-
int val;
620+
int val = 0;
621+
u8 areg_f0 = 0x60; /* ADC MCLK = 250 Fs */
622+
u8 areg_0a = 0x91; /* SIF 48KHz */
623+
624+
switch (bitrate) {
625+
case 48000:
626+
areg_f0 = 0x60; /* ADC MCLK = 250 Fs */
627+
areg_0a = 0x91; /* SIF 48KHz */
628+
dev->audio_bitrate = bitrate;
629+
break;
630+
case 32000:
631+
areg_f0 = 0x00; /* ADC MCLK = 375 Fs */
632+
areg_0a = 0x90; /* SIF 32KHz */
633+
dev->audio_bitrate = bitrate;
634+
break;
635+
default:
636+
return -EINVAL;
637+
}
638+
595639

596640
/* enable I2S, if we use sif or external I2S device */
597641
if (dev->dev_type == TM6010) {
598-
val = tm6000_get_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, 0);
599-
if (val < 0)
600-
return val;
601-
val = (val & 0xf0) | 0x1; /* 48 kHz, not muted */
602-
val = tm6000_set_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, val);
642+
val = tm6000_set_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, areg_0a);
603643
if (val < 0)
604644
return val;
605-
}
606645

607-
/* different reg's to set audio bitrate */
608-
if (dev->dev_type == TM6010) {
609-
val = tm6000_get_reg(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
610-
0x0);
646+
val = tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
647+
areg_f0, 0xf0);
611648
if (val < 0)
612649
return val;
613650
} else {
614-
val = tm6000_get_reg(dev, TM6000_REQ07_REB_VADC_AADC_MODE, 0x0);
651+
val = tm6000_set_reg_mask(dev, TM6000_REQ07_REB_VADC_AADC_MODE,
652+
areg_f0, 0xf0);
615653
if (val < 0)
616654
return val;
617655
}
656+
return 0;
657+
}
658+
EXPORT_SYMBOL_GPL(tm6000_set_audio_bitrate);
618659

619-
val &= 0x0f; /* Preserve the audio input control bits */
620-
switch (bitrate) {
621-
case 44100:
622-
val |= 0xd0;
623-
dev->audio_bitrate = bitrate;
660+
int tm6000_set_audio_input(struct tm6000_core *dev, enum tm6000_inaudio ainp)
661+
{
662+
if (dev->dev_type == TM6010) {
663+
/* Audio crossbar setting, default SIF1 */
664+
u8 areg_f0 = 0x03;
665+
666+
switch (ainp) {
667+
case TM6000_AIP_SIF1:
668+
case TM6000_AIP_SIF2:
669+
areg_f0 = 0x03;
670+
break;
671+
case TM6000_AIP_LINE1:
672+
areg_f0 = 0x00;
673+
break;
674+
case TM6000_AIP_LINE2:
675+
areg_f0 = 0x08;
676+
break;
677+
default:
678+
return 0;
679+
break;
680+
}
681+
/* Set audio input crossbar */
682+
tm6000_set_reg_mask(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
683+
areg_f0, 0x0f);
684+
} else {
685+
/* Audio setting, default LINE1 */
686+
u8 areg_eb = 0x00;
687+
688+
switch (ainp) {
689+
case TM6000_AIP_LINE1:
690+
areg_eb = 0x00;
691+
break;
692+
case TM6000_AIP_LINE2:
693+
areg_eb = 0x04;
694+
break;
695+
default:
696+
return 0;
697+
break;
698+
}
699+
/* Set audio input */
700+
tm6000_set_reg_mask(dev, TM6000_REQ07_REB_VADC_AADC_MODE,
701+
areg_eb, 0x0f);
702+
}
703+
return 0;
704+
}
705+
EXPORT_SYMBOL_GPL(tm6000_set_audio_input);
706+
707+
void tm6010_set_mute_sif(struct tm6000_core *dev, u8 mute)
708+
{
709+
u8 mute_reg = 0;
710+
711+
if (mute)
712+
mute_reg = 0x08;
713+
714+
tm6000_set_reg_mask(dev, TM6010_REQ08_R0A_A_I2S_MOD, mute_reg, 0x08);
715+
}
716+
717+
void tm6010_set_mute_adc(struct tm6000_core *dev, u8 mute)
718+
{
719+
u8 mute_reg = 0;
720+
721+
if (mute)
722+
mute_reg = 0x20;
723+
724+
if (dev->dev_type == TM6010) {
725+
tm6000_set_reg_mask(dev, TM6010_REQ08_RF2_LEFT_CHANNEL_VOL,
726+
mute_reg, 0x20);
727+
tm6000_set_reg_mask(dev, TM6010_REQ08_RF3_RIGHT_CHANNEL_VOL,
728+
mute_reg, 0x20);
729+
} else {
730+
tm6000_set_reg_mask(dev, TM6000_REQ07_REC_VADC_AADC_LVOL,
731+
mute_reg, 0x20);
732+
tm6000_set_reg_mask(dev, TM6000_REQ07_RED_VADC_AADC_RVOL,
733+
mute_reg, 0x20);
734+
}
735+
}
736+
737+
int tm6000_tvaudio_set_mute(struct tm6000_core *dev, u8 mute)
738+
{
739+
enum tm6000_inaudio ainp;
740+
741+
if (dev->radio)
742+
ainp = dev->aradio;
743+
else
744+
ainp = dev->avideo;
745+
746+
switch (ainp) {
747+
case TM6000_AIP_SIF1:
748+
case TM6000_AIP_SIF2:
749+
if (dev->dev_type == TM6010)
750+
tm6010_set_mute_sif(dev, mute);
751+
else {
752+
printk(KERN_INFO "ERROR: TM5600 and TM6000 don't has"
753+
" SIF audio inputs. Please check the %s"
754+
" configuration.\n", dev->name);
755+
return -EINVAL;
756+
}
624757
break;
625-
case 48000:
626-
val |= 0x60;
627-
dev->audio_bitrate = bitrate;
758+
case TM6000_AIP_LINE1:
759+
case TM6000_AIP_LINE2:
760+
tm6010_set_mute_adc(dev, mute);
761+
break;
762+
default:
763+
return -EINVAL;
628764
break;
629765
}
630-
if (dev->dev_type == TM6010)
631-
val = tm6000_set_reg(dev, TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG,
632-
val);
633-
else
634-
val = tm6000_set_reg(dev, TM6000_REQ07_REB_VADC_AADC_MODE, val);
766+
return 0;
767+
}
768+
EXPORT_SYMBOL_GPL(tm6000_tvaudio_set_mute);
769+
770+
void tm6010_set_volume_sif(struct tm6000_core *dev, int vol)
771+
{
772+
u8 vol_reg;
635773

636-
return val;
774+
vol_reg = vol & 0x0F;
775+
776+
if (vol < 0)
777+
vol_reg |= 0x40;
778+
779+
tm6000_set_reg(dev, TM6010_REQ08_R07_A_LEFT_VOL, vol_reg);
780+
tm6000_set_reg(dev, TM6010_REQ08_R08_A_RIGHT_VOL, vol_reg);
637781
}
638-
EXPORT_SYMBOL_GPL(tm6000_set_audio_bitrate);
782+
783+
void tm6010_set_volume_adc(struct tm6000_core *dev, int vol)
784+
{
785+
u8 vol_reg;
786+
787+
vol_reg = (vol + 0x10) & 0x1f;
788+
789+
if (dev->dev_type == TM6010) {
790+
tm6000_set_reg(dev, TM6010_REQ08_RF2_LEFT_CHANNEL_VOL, vol_reg);
791+
tm6000_set_reg(dev, TM6010_REQ08_RF3_RIGHT_CHANNEL_VOL, vol_reg);
792+
} else {
793+
tm6000_set_reg(dev, TM6000_REQ07_REC_VADC_AADC_LVOL, vol_reg);
794+
tm6000_set_reg(dev, TM6000_REQ07_RED_VADC_AADC_RVOL, vol_reg);
795+
}
796+
}
797+
798+
void tm6000_set_volume(struct tm6000_core *dev, int vol)
799+
{
800+
enum tm6000_inaudio ainp;
801+
802+
if (dev->radio) {
803+
ainp = dev->aradio;
804+
vol += 8; /* Offset to 0 dB */
805+
} else
806+
ainp = dev->avideo;
807+
808+
switch (ainp) {
809+
case TM6000_AIP_SIF1:
810+
case TM6000_AIP_SIF2:
811+
if (dev->dev_type == TM6010)
812+
tm6010_set_volume_sif(dev, vol);
813+
else
814+
printk(KERN_INFO "ERROR: TM5600 and TM6000 don't has"
815+
" SIF audio inputs. Please check the %s"
816+
" configuration.\n", dev->name);
817+
break;
818+
case TM6000_AIP_LINE1:
819+
case TM6000_AIP_LINE2:
820+
tm6010_set_volume_adc(dev, vol);
821+
break;
822+
default:
823+
break;
824+
}
825+
}
826+
EXPORT_SYMBOL_GPL(tm6000_set_volume);
639827

640828
static LIST_HEAD(tm6000_devlist);
641829
static DEFINE_MUTEX(tm6000_devlist_mutex);

0 commit comments

Comments
 (0)