media: FM radio for the Hauppauge WinTV-HVR-1950
A message that is not in the archive (sent off-list or not yet received): [email protected]
v2 cover media: FM radio for the Hauppauge WinTV-HVR-1950
The HVR-1950 (pvrusb2, 75xxx) has an FM tuner, but Linux has never offered radio on it ("no FM support on HVR-1950 ... requires some enhancements to the cx25840 chip-level driver and possibly also the pvrusb2 driver", pvrusb2 web page). This series adds it.
The cause: in FM mode the TDA8295 hands FM radio to the cx25843 as a 5.5 MHz sound IF, and the cx25840 radio setting (0x808 = 0xf9) never locks onto that with the audio firmware in linux-firmware.
1/4 cx25840: on boards that say so (new platform data flag), demodulate
radio as forced 5.5 MHz FM: mono, 50 us de-emphasis, works with the existing firmware.
2/4 cx25840: FM stereo when Hauppauge's HVR-1950 audio firmware is
installed as v4l-cx25840-fmstereo.fw (optional, loaded with firmware_request_nowarn). Radio then uses the Windows driver's setting, 0x808 = 0xfa (audio system 0xa, not in the data sheet), reports stereo and switches mono/stereo through the tuner audio mode; de-emphasis is 75 us. Without the file nothing changes from 1/4.
3/4 tda8290: FM signal strength from the TDA8295 IF AGC (the H-PLL lock
bit used today is always off in FM mode).
4/4 pvrusb2: radio input, routing and cx25840 platform data for the
750xx/751xx models.
About the firmware: the image is Driver73/Hcw73MlC.rom (16382 bytes, sha256 a6505aee99fa71768daece0a7ced1ac1f60bf7f8d823707640778fe0a4fd0a81) from Hauppauge's WinTV packages. It is the same file on the original 2007 driver CD and in the current WinTV v7, v8.5 and v10 installers from hauppauge.com. It is not redistributable as far as I know, so it can't go into linux-firmware, and the series doesn't depend on it. A user can extract it from the WinTV installer; I have a small script that does that and checks the hash, and can send it (e.g. for Documentation/admin-guide/media) if that is wanted. The 0xfa setting was found by looking at the register writes of Hauppauge's Windows driver for this board (hcw73bda.sys).
Testing, on an HVR-1950 model 75111 (kernel 7.0 with these changes backported; this series is compile-tested on media/next, every patch):
- radio across the FM band; signal meter 30-84 % on local stations, 0-26 % where the band is empty, but it stays high between closely spaced stations too (IF AGC over the whole passband, see 3/4)
- the low end of the 65-108 MHz range, where I have no stations: an RF modulator's channel 4 sound carrier (71.75 MHz FM) on the FM input quiets the audio by about 55 dB against the empty channels around it
- with the firmware file: stereo on 20 of 20 starts on two stations, live mono/stereo switching; without it: mono, as in 1/4
- de-emphasis measured on the hiss of an empty channel: 50 us (1/4), 75 us (2/4), both within 0.5 dB of the model curves
- switching between radio, analog TV (BTSC), composite and ATSC, with v4l2-ctl, dvbv5-zap and tvheadend
- v4l2-compliance 1.32: no new failures. The video node gives the same result as the stock driver (48 tests, 11 failed, identical fail and warning lines); the radio node (new on this card) fails 7, all in pvrusb2-v4l2.c, which this series doesn't touch: the radio node advertising read() I/O (how pvrusb2 streams radio), an empty tuner name, VIDIOC_S_EXT_CTRLS error_idx, and the control enumeration fixed by the separate patch below
- unplugging the card during an FM capture: the reader gets -EIO, the driver tears down cleanly, no warnings
- radio and video open at the same time: whichever node streams first keeps streaming without a gap, and read() on the other gets -EBUSY. Opening the radio node while TV is streaming still switches the input to radio (pvr2_channel_limit_inputs() in pvrusb2-v4l2.c, not changed here; the card just had no radio node before), and the input stays on radio after the radio node is closed
- rmmod pvrusb2 while /dev/radio0 is streaming: refused ("in use"), the capture carries on, and the module unloads once it is closed
- a 72 h soak with the firmware file and another 72 h without it. Every hour: 30 min of ATSC (dvbv5-zap), then FM on two stations (stereo, and once forced mono), analog TV and composite. Both runs finished 72 of 72 cycles with no failed step: the ATSC lock was never lost (314 GB in each run), every radio capture had audio (with the file, 133 of 144 stereo captures had separated channels; the rest were near-mono programme material) and every TV capture had video. The card never re-enumerated and there were no oopses. The only kernel warning was the existing cx2341x "encoder appears to be stuck" message, about 3 per cycle. The stock driver prints it too, and it recovered every time with no failed firmware reload (the soaks ran on v1; the v2 changes are covered by the run below)
- v2, with the firmware file: a 4 h soak in 15 min cycles (5 min of ATSC, then FM on two stations, stereo and once forced mono, analog TV and composite). 16 of 16 cycles with no failed step: the ATSC lock was never lost, every radio capture had audio (26 of 32 stereo captures had separated channels, the rest near-mono programme material; the 16 forced-mono captures had L = R) and every TV capture had video. The encoder "stuck" warning came about 3 times per cycle, as on v1, and recovered every time with no failed firmware reload; no oopses. The pvrusb2 module in this run was a local test build with an extra encoder power-cycle recovery path (for a card problem I hit between the v1 and v2 runs, also with v1); that path never triggered
Not covered: the 73xxx models (HVR-1900, same chips as far as I know) are left as they are because I can't test them. 4/4 enables radio on both 750xx and 751xx, but only a 751xx was tested; the 750xx has the same tuner, IF demodulator and cx25843 (only its ATSC demodulator differs, s5h1409), so it gets the same routing. The other cx25840 users (ivtv, cx23885, cx231xx) are untested on hardware: 2/4 moves the tuner audio-mode switch into a helper, and everything new is gated by the new platform data flag, so their code paths are unchanged by inspection. Suspend/resume with the radio running wasn't tested.
Not supported: RDS and hardware seek. The cx25843 has an RDS demodulator, but its registers only give raw I/Q, polled over I2C, and the audio reaches the host through the cx2341x encoder at 48 kHz, which loses the 57 kHz RDS subcarrier, so the radio node doesn't advertise RDS. The data sheet also lists an RDS output that can be routed to the audio path; I haven't tried that yet. For seek, the TDA8295's AFC reads 0 on every station in FM mode and the signal meter (3/4) is too broad to stop on one. A read-only sweep of the band did turn up two cx25843 registers in the reserved 0x81c-0x9c8 range (0x9b8 and 0x94f) that dip over about 0.3 MHz around each of the 18 local stations and recover between closely spaced ones, with and without the firmware file. Seek could be built on those, but as they are undocumented I'd rather leave that for a follow-up.
How this was made: I used an AI coding assistant (Claude Opus 5.5) to analyse the problem, look at the Windows driver's register writes, run and evaluate the experiments on my card, and write the code and the changelogs. I reviewed the changes, ran the hardware tests and am responsible for the result; each patch carries an Assisted-by tag.
Two separate patches don't depend on this series: one (now at v2,
https://lore.kernel.org/r/[email protected])
fixes "s5h1411_writereg: writereg error ... -5" when an analog open follows closing the DVB frontend on this card, the other fixes pvrusb2 control enumeration with V4L2_CTRL_FLAG_NEXT_COMPOUND (v4l2-ctl -l lists only the user class controls today).
Two more patches that report the fixed FM de-emphasis (75 us with the stereo firmware, 50 us without) through V4L2_CID_TUNE_DEEMPHASIS are tested and ready; I'll send them as a follow-up once this series is settled.
Changes in v2 (all from the Sashiko review of v1; no functional change intended on the tested paths):
- 2/4 cx25840: radio keeps its own audio mode (radio_audmode, mono or stereo) instead of overwriting the TV audmode, so a VIDIOC_S_TUNER on the radio node no longer changes what TV restores in 0x809 or what TV's G_TUNER reports; radio audmode values other than mono are taken as stereo instead of being stored unchecked.
- 2/4 cx25840: set fm_stereo only after check_fw_load() succeeds, so a failed firmware download doesn't leave the stereo setting (0x808 = 0xfa) in use without the stereo firmware.
- 3/4 tda8290: return -EREMOTEIO when the IF AGC read fails instead of computing the signal strength from an uninitialised byte.
- 4/4 pvrusb2: keep the cx25840 platform data in struct pvr2_hdw (like ir_init_data) instead of on the stack: the I2C core keeps the platform_data pointer, and cx25840_probe() reads it again if the driver is rebound.
- 1/4: unchanged.
Link to v1: https://lore.kernel.org/r/[email protected]
Ext745 (4):
media: cx25840: demodulate FM radio from a 5.5 MHz sound IF
media: cx25840: FM stereo with an optional HVR-1950 audio firmware
media: tda8290: report FM signal strength on the TDA8295
media: pvrusb2: enable FM radio on the HVR-1950
drivers/media/i2c/cx25840/cx25840-core.c | 152 +++++++++++++----- drivers/media/i2c/cx25840/cx25840-core.h | 9 ++ drivers/media/i2c/cx25840/cx25840-firmware.c | 30 +++- drivers/media/tuners/tda8290.c | 15 ++ .../media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c | 26 +++ drivers/media/usb/pvrusb2/pvrusb2-devattr.c | 8 +- drivers/media/usb/pvrusb2/pvrusb2-devattr.h | 4 + .../media/usb/pvrusb2/pvrusb2-hdw-internal.h | 2 + drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 27 +++- include/media/drv-intf/cx25840.h | 8 +- 10 files changed, 230 insertions(+), 51 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/4 media: cx25840: demodulate FM radio from a 5.5 MHz sound IF
Some boards feed FM radio to the cx2584x the same way as TV sound, as a sound IF from the analog demodulator. On the Hauppauge HVR-1950 the TDA8295 outputs FM radio as a 5.5 MHz SSIF on the cx25843's tuner audio input. The radio setting cx25840 uses (0x808 = 0xf9, FM radio with automatic detection) never locks onto that carrier with the standard audio firmware: 0x805 keeps reading 0xff (no standard detected) and only noise comes out.
Add a radio_sif_5_5mhz platform data flag. For such boards force the 5.5 MHz FM (A2-BG) standard, mono, in radio mode. That demodulates broadcast FM cleanly, with 50 us de-emphasis (the hiss spectrum of an empty channel follows the 50 us curve within 0.5 dB). The 4.5 MHz A2-M standard would give 75 us but clips at broadcast FM deviation.
This path is mono only, so say so in g_tuner for radio: tuner-core reports stereo capability for every radio.
Tested on an HVR-1950 (model 75111) with the pvrusb2 patch later in this
series: local stations across the band are clean, and switching between radio, analog TV, composite and ATSC is unchanged.
---
v2: unchanged
drivers/media/i2c/cx25840/cx25840-core.c | 23 +++++++++++++++++++++-- drivers/media/i2c/cx25840/cx25840-core.h | 3 +++ include/media/drv-intf/cx25840.h | 6 +++++- 3 files changed, 29 insertions(+), 3 deletions(-)
drivers/media/i2c/cx25840/cx25840-core.c +21 -2
@@ -1302,7 +1302,15 @@ static void input_change(struct i2c_client *client)cx25840_and_or (client,0x810 , ~0x01 ,1 ); -if (state->radio) { +if (state->radio && state->radio_sif_5_5mhz) { +/* +* Forced 5.5 MHz FM (A2-BG standard), MONO1, which applies +* 50 us de-emphasis. The 4.5 MHz A2-M path (75 us) clips +* broadcast FM deviation. +*/ +cx25840_write (client,0x808 ,0x40 ); +cx25840_write (client,0x80b ,0x00 ); + }else if (state->radio) {cx25840_write (client,0x808 ,0xf9 );cx25840_write (client,0x80b ,0x00 ); }else if (std &V4L2_STD_525_60 ) {
@@ -2565,8 +2573,18 @@ static int cx25840_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)u8 mode;int val =0 ; -if (state->radio) +if (state->radio) { +if (!state->radio_sif_5_5mhz) +return 0 ; +/* +* The bridge calls this after the tuner, so that the audio +* decoder has the last word: this FM path is mono only. +*/ + vt->capability &= ~V4L2_TUNER_CAP_STEREO ; + vt->rxsubchans =V4L2_TUNER_SUB_MONO ; + vt->audmode =V4L2_TUNER_MODE_MONO ;return 0 ; + } vt->signal = vpres ?0xffff :0x0 ;if (is_cx2583x (state))
@@ -3972,6 +3990,7 @@ static int cx25840_probe(struct i2c_client *client)struct cx25840_platform_data *pdata = client->dev.platform_data; state->pvr150_workaround = pdata->pvr150_workaround; + state->radio_sif_5_5mhz = pdata->radio_sif_5_5mhz; }cx25840_ir_probe (sd);
drivers/media/i2c/cx25840/cx25840-core.h +3 -0
@@ -43,6 +43,8 @@ enum cx25840_media_pads {* @mute: audio mute V4L2 control (non-cx2583x devices only) * @pvr150_workaround: whether we enable workaround for Hauppauge PVR150 * hardware bug (audio dropping out) +* @radio_sif_5_5mhz: FM radio arrives as a 5.5 MHz sound IF (e.g. from a +* TDA8295): demodulate it as 5.5 MHz FM mono * @generic_mode: whether we disable ivtv-specific hacks * this mode gets turned on when the bridge driver calls * cx25840 subdevice init core op
@@ -78,6 +80,7 @@ struct cx25840_state {struct v4l2_ctrl *mute; };int pvr150_workaround; +int radio_sif_5_5mhz;bool generic_mode;int radio;v4l2_std_id std;
include/media/drv-intf/cx25840.h +5 -1
@@ -253,10 +253,14 @@ enum cx23885_io_pad {* is to select the audio standard explicitly. Many thanks to Hauppauge for * providing this information. * -* This platform data only needs to be supplied by the ivtv driver. +* radio_sif_5_5mhz is for boards whose analog tuner delivers FM radio to the +* cx2584x as a 5.5 MHz sound IF, as the TDA8295 does in FM radio mode (e.g. +* the Hauppauge HVR-1950). The audio firmware's FM radio mode does not find +* that carrier, so radio is demodulated as forced 5.5 MHz FM mono instead. */ struct cx25840_platform_data {int pvr150_workaround; +int radio_sif_5_5mhz; };#endif
Signature · 1 line
2.53.0
PATCH v2 2/4 media: cx25840: FM stereo with an optional HVR-1950 audio firmware
In reply to Ext745The HVR-1950's Windows driver loads its own cx25843 audio firmware (Hcw73MlC.rom) and puts the audio core in radio mode with 0x808 = 0xfa:
automatic standard detection, audio system 0xa, which the CX25840/1/2/3 data sheet doesn't document. With that firmware, 0xfa finds FM radio on the 5.5 MHz sound IF (0x805 = 0x0e), detects the stereo pilot (0x804 = 0x01) and decodes stereo; the firmware sets the dematrix (0x8ce) to FM stereo itself. The linux-firmware image (v4l-cx25840.fw) detects nothing with either 0xfa or 0xf9, and 0xf9 with the HVR-1950 firmware detects FM but stays mono.
That image can't go into linux-firmware, so make it optional: on radio_sif_5_5mhz boards try v4l-cx25840-fmstereo.fw first, without a warning when it is missing, and use v4l-cx25840.fw and the mono path otherwise. With it:
- radio sets 0x808 = 0xfa. The audio soft reset is not pulsed again
afterwards: a second restart of the audio core left the stereo decoder hissy in 23 of 24 tries, and in none without it.
- g_tuner reports stereo capability and, from 0x804, whether a stereo pilot is received.
- s_tuner maps the audio mode to the preferred mode in 0x809: mono gives mono (useful on weak stations), anything else stereo. Both take effect immediately. Radio keeps its own mono/stereo setting, so TV's audio mode is restored when leaving radio (both share 0x809).
De-emphasis is fixed at 75 us in this mode (measured within 0.5 dB; the 0x809 DE_EMPHASIS_TIME bit has no effect), as used in the Americas.
The preferred-mode switch moves out of s_tuner into a helper so that input_change can use it too.
Tested on an HVR-1950: stereo on every start (20 of 20) on two local stations, mono/stereo switching, BTSC TV after radio, and switching between radio, analog TV, composite and ATSC. Without the file radio stays mono as before.
---
v2:
- keep a separate radio_audmode so S_TUNER on the radio node doesn't overwrite the TV audmode; radio modes other than mono map to stereo
- set fm_stereo only once check_fw_load() succeeds
drivers/media/i2c/cx25840/cx25840-core.c | 145 +++++++++++++------ drivers/media/i2c/cx25840/cx25840-core.h | 8 +- drivers/media/i2c/cx25840/cx25840-firmware.c | 30 +++- include/media/drv-intf/cx25840.h | 6 +- 4 files changed, 133 insertions(+), 56 deletions(-)
drivers/media/i2c/cx25840/cx25840-core.c +99 -46
@@ -1280,6 +1280,56 @@ void cx25840_std_setup(struct i2c_client *client)/* ----------------------------------------------------------------------- */ +/* Program the audio decoder's preferred mode (0x809 [3:0]) for audmode */ +static int set_pref_mode (struct i2c_client *client,u32 audmode,bool radio) +{ +if (radio) { +/* FM radio is mono or stereo; anything but mono means stereo */ +cx25840_and_or (client,0x809 , ~0xf , + audmode ==V4L2_TUNER_MODE_MONO ?0x00 :0x04 ); +return 0 ; + } + +switch (audmode) { +case V4L2_TUNER_MODE_MONO : +/* +* mono -> mono +* stereo -> mono +* bilingual -> lang1 +*/ +cx25840_and_or (client,0x809 , ~0xf ,0x00 ); +break ; +case V4L2_TUNER_MODE_STEREO : +case V4L2_TUNER_MODE_LANG1 : +/* +* mono -> mono +* stereo -> stereo +* bilingual -> lang1 +*/ +cx25840_and_or (client,0x809 , ~0xf ,0x04 ); +break ; +case V4L2_TUNER_MODE_LANG1_LANG2 : +/* +* mono -> mono +* stereo -> stereo +* bilingual -> lang1/lang2 +*/ +cx25840_and_or (client,0x809 , ~0xf ,0x07 ); +break ; +case V4L2_TUNER_MODE_LANG2 : +/* +* mono -> mono +* stereo -> stereo +* bilingual -> lang2 +*/ +cx25840_and_or (client,0x809 , ~0xf ,0x01 ); +break ; +default : +return -EINVAL ; + } +return 0 ; +} +static void input_change (struct i2c_client *client) {struct cx25840_state *state =to_state (i2c_get_clientdata (client));
@@ -1302,11 +1352,23 @@ static void input_change(struct i2c_client *client)cx25840_and_or (client,0x810 , ~0x01 ,1 ); -if (state->radio && state->radio_sif_5_5mhz) { +if (state->radio && state->radio_sif_5_5mhz && state->fm_stereo) { +/* +* The FM stereo firmware's automatic FM radio system (0xA) +* locks onto the 5.5 MHz sound IF and decodes the stereo +* pilot, with fixed 75 us de-emphasis. 0x809 picks mono or +* stereo. Don't pulse the soft reset again after this: a +* second restart of the audio core often leaves the stereo +* decoder hissy. +*/ +cx25840_write (client,0x808 ,0xfa ); +cx25840_write (client,0x80b ,0x00 ); +set_pref_mode (client, state->radio_audmode, true); + }else if (state->radio && state->radio_sif_5_5mhz) {/* -* Forced 5.5 MHz FM (A2-BG standard), MONO1, which applies -* 50 us de-emphasis. The 4.5 MHz A2-M path (75 us) clips -* broadcast FM deviation. +* Standard firmware: forced 5.5 MHz FM (A2-BG standard), +* MONO1, which applies 50 us de-emphasis. The 4.5 MHz A2-M +* path (75 us) clips broadcast FM deviation. */ cx25840_write (client,0x808 ,0x40 );cx25840_write (client,0x80b ,0x00 );
@@ -1365,6 +1427,10 @@ static void input_change(struct i2c_client *client) } } +/* Radio mode may have left 0x809 at its FM setting: restore TV's */ +if (!state->radio && state->radio_sif_5_5mhz) +set_pref_mode (client, state->audmode, false); +cx25840_and_or (client,0x810 , ~0x01 ,0 ); }
@@ -2578,11 +2644,21 @@ static int cx25840_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)return 0 ;/* * The bridge calls this after the tuner, so that the audio -* decoder has the last word: this FM path is mono only. +* decoder has the last word on FM stereo: only the FM stereo +* firmware decodes it. */ - vt->capability &= ~V4L2_TUNER_CAP_STEREO ; - vt->rxsubchans =V4L2_TUNER_SUB_MONO ; - vt->audmode =V4L2_TUNER_MODE_MONO ; +if (!state->fm_stereo) { + vt->capability &= ~V4L2_TUNER_CAP_STEREO ; + vt->rxsubchans =V4L2_TUNER_SUB_MONO ; + vt->audmode =V4L2_TUNER_MODE_MONO ; +return 0 ; + } + vt->capability |=V4L2_TUNER_CAP_STEREO ; + mode =cx25840_read (client,0x804 ); + vt->rxsubchans = (mode &0xf ) ==1 ? +V4L2_TUNER_SUB_MONO |V4L2_TUNER_SUB_STEREO : +V4L2_TUNER_SUB_MONO ; + vt->audmode = state->radio_audmode;return 0 ; }
@@ -2616,47 +2692,23 @@ static int cx25840_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt) {struct cx25840_state *state =to_state (sd);struct i2c_client *client =v4l2_get_subdevdata (sd); +int ret; -if (state->radio ||is_cx2583x (state)) +if (is_cx2583x (state)) +return 0 ; +if (state->radio) { +if (!(state->radio_sif_5_5mhz && state->fm_stereo)) +return 0 ; +/* FM radio is mono or stereo; keep TV's audmode for TV */ + state->radio_audmode = vt->audmode ==V4L2_TUNER_MODE_MONO ? +V4L2_TUNER_MODE_MONO :V4L2_TUNER_MODE_STEREO ; +set_pref_mode (client, state->radio_audmode, true);return 0 ; - -switch (vt->audmode) { -case V4L2_TUNER_MODE_MONO : -/* -* mono -> mono -* stereo -> mono -* bilingual -> lang1 -*/ -cx25840_and_or (client,0x809 , ~0xf ,0x00 ); -break ; -case V4L2_TUNER_MODE_STEREO : -case V4L2_TUNER_MODE_LANG1 : -/* -* mono -> mono -* stereo -> stereo -* bilingual -> lang1 -*/ -cx25840_and_or (client,0x809 , ~0xf ,0x04 ); -break ; -case V4L2_TUNER_MODE_LANG1_LANG2 : -/* -* mono -> mono -* stereo -> stereo -* bilingual -> lang1/lang2 -*/ -cx25840_and_or (client,0x809 , ~0xf ,0x07 ); -break ; -case V4L2_TUNER_MODE_LANG2 : -/* -* mono -> mono -* stereo -> stereo -* bilingual -> lang2 -*/ -cx25840_and_or (client,0x809 , ~0xf ,0x01 ); -break ; -default : -return -EINVAL ; } + + ret =set_pref_mode (client, vt->audmode, false); +if (ret) +return ret; state->audmode = vt->audmode;return 0 ; }
@@ -3923,6 +3975,7 @@ static int cx25840_probe(struct i2c_client *client) state->aud_input =CX25840_AUDIO8 ; state->audclk_freq =48000 ; state->audmode =V4L2_TUNER_MODE_LANG1 ; + state->radio_audmode =V4L2_TUNER_MODE_STEREO ; state->vbi_line_offset =8 ; state->id = id; state->rev = device_id;
drivers/media/i2c/cx25840/cx25840-core.h +7 -1
@@ -44,7 +44,9 @@ enum cx25840_media_pads {* @pvr150_workaround: whether we enable workaround for Hauppauge PVR150 * hardware bug (audio dropping out) * @radio_sif_5_5mhz: FM radio arrives as a 5.5 MHz sound IF (e.g. from a -* TDA8295): demodulate it as 5.5 MHz FM mono +* TDA8295) +* @fm_stereo: the FM stereo firmware is loaded: decode that IF as +* FM stereo, else as 5.5 MHz FM mono * @generic_mode: whether we disable ivtv-specific hacks * this mode gets turned on when the bridge driver calls * cx25840 subdevice init core op
@@ -57,6 +59,8 @@ enum cx25840_media_pads {* @aud_input: currently set audio input * @audclk_freq: currently set audio sample rate * @audmode: currently set audio mode (when in non-radio mode) +* @radio_audmode: audio mode set in radio mode, mono or stereo (FM stereo +* firmware only) * @vbi_line_offset: vbi line number offset * @id: exact device model * @rev: raw device id read from the chip
@@ -81,6 +85,7 @@ struct cx25840_state { };int pvr150_workaround;int radio_sif_5_5mhz; +int fm_stereo;bool generic_mode;int radio;v4l2_std_id std;
@@ -89,6 +94,7 @@ struct cx25840_state {enum cx25840_audio_input aud_input;u32 audclk_freq;int audmode; +int radio_audmode;int vbi_line_offset;enum cx25840_model id;u32 rev;
drivers/media/i2c/cx25840/cx25840-firmware.c +23 -7
@@ -51,6 +51,12 @@ static void end_fw_load(struct i2c_client *client)#define CX2388x_FIRMWARE "v4l-cx23885-avcore-01.fw"#define CX231xx_FIRMWARE "v4l-cx231xx-avcore-01.fw"#define CX25840_FIRMWARE "v4l-cx25840.fw" +/* +* Optional audio firmware for boards whose FM radio arrives as a 5.5 MHz +* sound IF (cx25840_platform_data.radio_sif_5_5mhz). Hauppauge's HVR-1950 +* image (Hcw73MlC.rom) decodes FM stereo there; the standard image doesn't. +*/ +#define CX25840_FM_STEREO_FIRMWARE "v4l-cx25840-fmstereo.fw"static const char *get_fw_name (struct i2c_client *client) {
@@ -65,20 +71,19 @@ static const char *get_fw_name(struct i2c_client *client)return CX25840_FIRMWARE ; } -static int check_fw_load (struct i2c_client *client,int size) +static int check_fw_load (struct i2c_client *client,const char *fwname, +int size) {/* DL_ADDR_HB DL_ADDR_LB */ int s =cx25840_read (client,0x801 ) <<8 ; s |=cx25840_read (client,0x800 );if (size != s) { -v4l_err (client,"firmware %s load failed\n" , -get_fw_name (client)); +v4l_err (client,"firmware %s load failed\n" , fwname);return -EINVAL ; } -v4l_info (client,"loaded %s firmware (%d bytes)\n" , -get_fw_name (client), size); +v4l_info (client,"loaded %s firmware (%d bytes)\n" , fwname, size);return 0 ; }
@@ -101,6 +106,7 @@ int cx25840_loadfw(struct i2c_client *client)const char *fwname =get_fw_name (client);int size, retval;int max_buf_size =FWSEND ; +bool fm_stereo = false;u32 gpio_oe =0 , gpio_da =0 ;if (is_cx2388x (state)) {
@@ -113,7 +119,13 @@ int cx25840_loadfw(struct i2c_client *client)if (is_cx231xx (state) && max_buf_size >16 ) max_buf_size =16 ; -if (request_firmware (&fw, fwname,FWDEV (client)) !=0 ) { + state->fm_stereo =0 ; +if (state->radio_sif_5_5mhz && !firmware[0 ] && + !firmware_request_nowarn (&fw,CX25840_FM_STEREO_FIRMWARE , +FWDEV (client))) { + fwname =CX25840_FM_STEREO_FIRMWARE ; + fm_stereo = true; + }else if (request_firmware (&fw, fwname,FWDEV (client)) !=0 ) {v4l_err (client,"unable to open firmware %s\n" , fwname);return -EINVAL ; }
@@ -152,10 +164,14 @@ int cx25840_loadfw(struct i2c_client *client)cx25840_write (client,0x164 , gpio_da); } -return check_fw_load (client, size); + retval =check_fw_load (client, fwname, size); +if (!retval) + state->fm_stereo = fm_stereo; +return retval; }MODULE_FIRMWARE (CX2388x_FIRMWARE);MODULE_FIRMWARE (CX231xx_FIRMWARE);MODULE_FIRMWARE (CX25840_FIRMWARE ); +MODULE_FIRMWARE (CX25840_FM_STEREO_FIRMWARE );
include/media/drv-intf/cx25840.h +4 -2
@@ -255,8 +255,10 @@ enum cx23885_io_pad {* * radio_sif_5_5mhz is for boards whose analog tuner delivers FM radio to the * cx2584x as a 5.5 MHz sound IF, as the TDA8295 does in FM radio mode (e.g. -* the Hauppauge HVR-1950). The audio firmware's FM radio mode does not find -* that carrier, so radio is demodulated as forced 5.5 MHz FM mono instead. +* the Hauppauge HVR-1950). The standard audio firmware's FM radio mode does +* not find that carrier, so radio is demodulated as forced 5.5 MHz FM mono. +* If the optional v4l-cx25840-fmstereo.fw (Hauppauge's HVR-1950 audio +* firmware) is installed, it is loaded instead and radio is FM stereo. */ struct cx25840_platform_data {int pvr150_workaround;
Signature · 1 line
2.53.0
PATCH v2 3/4 media: tda8290: report FM signal strength on the TDA8295
In reply to Ext745In FM radio mode the TDA8295's picture carrier PLL is off, so the H-PLL lock bit that tda8295_has_signal() reads is never set and radio always reports 0 % signal. In radio mode use the tuner IF AGC level instead (0x28, T_IF_AGC_STAT): 0xff is maximum gain (no signal), strong local stations read around 0x90.
Tested on an HVR-1950 in a dense urban FM band (stations 400 kHz apart): 30 to 84 % on local stations, 0 to 26 % where the band is empty (87.9-88.9 MHz); TV unchanged. The AGC acts on the whole IF passband, so between closely spaced stations the meter stays near their level (73 to 86 % across 100-104 MHz): it shows that a signal is there, not that this exact channel holds a station. Seek in such a band can't rely on the level alone.
---
v2:
- return -EREMOTEIO if the IF AGC read fails
drivers/media/tuners/tda8290.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/media/tuners/tda8290.c +15 -0
@@ -384,8 +384,23 @@ static int tda8295_has_signal(struct dvb_frontend *fe, u16 *signal)struct tda8290_priv *priv = fe->analog_demod_priv;unsigned char hvpll_stat =0x26 ; +unsigned char t_if_agc_stat =0x28 ;unsigned char ret; +if (priv->tda8290_easy_mode ==0x80 ) { +/* +* FM radio: the picture carrier PLL is off, so the H-PLL +* lock bit is never set. Use the tuner IF AGC level +* instead: 0xff is maximum gain (no signal), strong local +* stations read around 0x90. +*/ +if (tuner_i2c_xfer_send_recv (&priv->i2c_props, + &t_if_agc_stat,1 , &ret,1 ) !=1 ) +return -EREMOTEIO ; + *signal =min (0xff - ret,0x80 ) *65535 /0x80 ; +return 0 ; + } +tuner_i2c_xfer_send_recv (&priv->i2c_props, &hvpll_stat,1 , &ret,1 ); *signal = (ret &0x01 ) ?65535 :0 ;return 0 ;
Signature · 1 line
2.53.0
PATCH v2 4/4 media: pvrusb2: enable FM radio on the HVR-1950
In reply to Ext745The HVR-1950 (75xxx) has an FM tuner (the retail box lists FM stereo radio, with a separate FM antenna input), but pvrusb2 never enabled it:
the 750xx and 751xx device descriptions lack flag_has_fmradio, so there is no radio device. Their routing scheme can't simply gain it either:
its radio entry selects the line input meant for the external FM module of the older PVR-USB2 models. On the HVR-1950 FM comes from the analog tuner, like TV sound.
- Set flag_has_fmradio for 750xx/751xx and give them a routing scheme whose radio input is the tuner (COMPOSITE7 / AUDIO8, as for TV).
- Pass cx25840 platform data with radio_sif_5_5mhz (the TDA8295's FM output) through v4l2_i2c_new_subdev_board.
- In radio mode ask the cx25840 again at the end of the tuner status poll, so that tuner-core's default stereo report doesn't override what the audio decoder can do.
The band is tuner-core's radio range, 65 to 108 MHz.
Tested on an HVR-1950 (model 75111): /dev/radio0 tunes the FM band accurately, the signal meter works, stereo with the optional cx25840 firmware and mono without, and switching between radio, analog TV, composite and ATSC (with tvheadend and v4l2-ctl/dvbv5-zap) works.
---
v2:
- keep the cx25840 platform data in struct pvr2_hdw instead of on the stack (the I2C core keeps the pointer)
.../media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c | 26 ++++++++++++++++++ drivers/media/usb/pvrusb2/pvrusb2-devattr.c | 8 ++++-- drivers/media/usb/pvrusb2/pvrusb2-devattr.h | 4 +++ .../media/usb/pvrusb2/pvrusb2-hdw-internal.h | 2 ++ drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 27 ++++++++++++++++++- 5 files changed, 64 insertions(+), 3 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c +26 -0
@@ -125,11 +125,37 @@ static const struct routing_scheme routing_def160xxx = { .cnt = ARRAY_SIZE(routing_scheme160xxx), }; +/* HVR-1950: FM radio comes from the analog tuner, like television audio */ +static const struct routing_scheme_item routing_scheme75xxx[] = { + [PVR2_CVAL_INPUT_TV ] = { + .vid =CX25840_COMPOSITE7 , + .aud =CX25840_AUDIO8 , + }, + [PVR2_CVAL_INPUT_RADIO ] = { + .vid =CX25840_COMPOSITE7 , + .aud =CX25840_AUDIO8 , + }, + [PVR2_CVAL_INPUT_COMPOSITE ] = { + .vid =CX25840_COMPOSITE3 , + .aud =CX25840_AUDIO_SERIAL , + }, + [PVR2_CVAL_INPUT_SVIDEO ] = { + .vid =CX25840_SVIDEO1 , + .aud =CX25840_AUDIO_SERIAL , + }, +}; + +static const struct routing_scheme routing_def75xxx = { + .def = routing_scheme75xxx, + .cnt =ARRAY_SIZE (routing_scheme75xxx), +}; +static const struct routing_scheme *routing_schemes[] = { [PVR2_ROUTING_SCHEME_HAUPPAUGE ] = &routing_def0, [PVR2_ROUTING_SCHEME_GOTVIEW ] = &routing_defgv, [PVR2_ROUTING_SCHEME_AV400 ] = &routing_defav400, [PVR2_ROUTING_SCHEME_HAUP160XXX ] = &routing_def160xxx, + [PVR2_ROUTING_SCHEME_HAUP75XXX ] = &routing_def75xxx, };void pvr2_cx25840_subdev_update (struct pvr2_hdw *hdw,struct v4l2_subdev *sd)
drivers/media/usb/pvrusb2/pvrusb2-devattr.c +6 -2
@@ -482,10 +482,12 @@ static const struct pvr2_device_desc pvr2_device_750xx = { .flag_has_cx25840 = !0, .flag_has_hauppauge_rom = !0, .flag_has_analogtuner = !0, + .flag_has_fmradio = !0, .flag_has_composite = !0, .flag_has_svideo = !0, .flag_fx2_16kb = !0, - .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, + .flag_radio_sif_5_5mhz = !0, + .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUP75XXX, .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE, .default_std_mask = V4L2_STD_NTSC_M, .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
@@ -505,10 +507,12 @@ static const struct pvr2_device_desc pvr2_device_751xx = { .flag_has_cx25840 = !0, .flag_has_hauppauge_rom = !0, .flag_has_analogtuner = !0, + .flag_has_fmradio = !0, .flag_has_composite = !0, .flag_has_svideo = !0, .flag_fx2_16kb = !0, - .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, + .flag_radio_sif_5_5mhz = !0, + .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUP75XXX, .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE, .default_std_mask = V4L2_STD_NTSC_M, .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
drivers/media/usb/pvrusb2/pvrusb2-devattr.h +4 -0
@@ -57,6 +57,7 @@ struct pvr2_string_table {#define PVR2_ROUTING_SCHEME_ONAIR 2#define PVR2_ROUTING_SCHEME_AV400 3#define PVR2_ROUTING_SCHEME_HAUP160XXX 4 +#define PVR2_ROUTING_SCHEME_HAUP75XXX 5#define PVR2_DIGITAL_SCHEME_NONE 0#define PVR2_DIGITAL_SCHEME_HAUPPAUGE 1
@@ -165,6 +166,9 @@ struct pvr2_device_desc { unsigned int flag_has_svideo:1; /* Has s-video input */ unsigned int flag_fx2_16kb:1; /* 16KB FX2 firmware OK here */ +/* FM radio reaches the cx2584x as a 5.5 MHz sound IF (TDA8295) */ + unsigned int flag_radio_sif_5_5mhz:1; +/* If this driver is considered experimental, i.e. not all aspects are working correctly and/or it is untested, mark that fact with this flag. */
drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h +2 -0
@@ -26,6 +26,7 @@#include "pvrusb2-io.h" #include <media/v4l2-device.h> #include <media/drv-intf/cx2341x.h> +#include <media/drv-intf/cx25840.h> #include <media/i2c/ir-kbd-i2c.h> #include "pvrusb2-devattr.h"
@@ -189,6 +190,7 @@ struct pvr2_hdw {/* IR related */ unsigned int ir_scheme_active;/* IR scheme as seen from the outside */ struct IR_i2c_init_data ir_init_data;/* params passed to IR modules */ +struct cx25840_platform_data cx25840_pdata;/* passed to cx25840 */ /* Frequency table */ unsigned int freqTable[FREQTABLE_SIZE ];
drivers/media/usb/pvrusb2/pvrusb2-hdw.c +26 -1
@@ -2015,7 +2015,22 @@ static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw,return -EINVAL ; } -if (i2ccnt ==1 ) { +if (i2ccnt ==1 && mid ==PVR2_CLIENT_ID_CX25840 ) { +/* in hdw: the I2C core keeps the platform_data pointer */ +struct i2c_board_info info = { + .addr = i2caddr[0 ], + .platform_data = &hdw->cx25840_pdata, + }; + + hdw->cx25840_pdata.radio_sif_5_5mhz = + hdw->hdw_desc->flag_radio_sif_5_5mhz; +pvr2_trace (PVR2_TRACE_INIT , +"Module ID %u: Setting up with specified i2c address 0x%x" , + mid, i2caddr[0 ]); +strscpy (info.type, fname,sizeof (info.type)); + sd =v4l2_i2c_new_subdev_board (&hdw->v4l2_dev, &hdw->i2c_adap, + &info,NULL ); + }else if (i2ccnt ==1 ) {pvr2_trace (PVR2_TRACE_INIT ,"Module ID %u: Setting up with specified i2c address 0x%x" , mid, i2caddr[0 ]);
@@ -5057,6 +5072,16 @@ void pvr2_hdw_status_poll(struct pvr2_hdw *hdw)now. (Of course, no sub-drivers seem to implement it either. But now it's a chicken and egg problem...) */ v4l2_device_call_all (&hdw->v4l2_dev,0 , tuner, g_tuner, vtp); +if (vtp->type ==V4L2_TUNER_RADIO && + hdw->hdw_desc->flag_radio_sif_5_5mhz) { +/* +* Whether this FM path is stereo depends on the cx2584x +* audio firmware: ask it again last, so tuner-core's +* default doesn't decide. +*/ +v4l2_device_call_all (&hdw->v4l2_dev,PVR2_CLIENT_ID_CX25840 , + tuner, g_tuner, vtp); + } pvr2_trace(PVR2_TRACE_CHIPS, "subdev status poll type=%u strength=%u audio=0x%x cap=0x%x low=%u hi=%u", vtp->type, vtp->signal, vtp->rxsubchans, vtp->capability,
Signature · 1 line
2.53.0