Lines Matching +full:standard +full:- +full:vt

14  * Copyright(c) 2005-2008 Mauro Carvalho Chehab
15 * - Some cleanups, code fixes, etc
16 * - Convert it to V4L2 API
21 * debug - set to 1 if you'd like to see debug messages
40 #include <media/v4l2-device.h>
41 #include <media/v4l2-ctrls.h>
43 /* ---------------------------------------------------------------------- */
53 #define UNSET (-1U)
55 /* ---------------------------------------------------------------------- */
97 /* functions to convert the values (v4l -> chip) */
121 /* chip-specific description - should point to
147 return &container_of(ctrl->handler, struct CHIPSTATE, hdl)->sd; in to_sd()
151 /* ---------------------------------------------------------------------- */
156 struct v4l2_subdev *sd = &chip->sd; in chip_write()
163 chip->shadow.bytes[1] = val; in chip_write()
170 return -EIO; in chip_write()
173 if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) { in chip_write()
175 "Tried to access a non-existent register: %d\n", in chip_write()
177 return -EINVAL; in chip_write()
182 chip->shadow.bytes[subaddr+1] = val; in chip_write()
191 return -EIO; in chip_write()
200 struct v4l2_subdev *sd = &chip->sd; in chip_write_masked()
204 val = (chip->shadow.bytes[1] & ~mask) | (val & mask); in chip_write_masked()
206 if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) { in chip_write_masked()
208 "Tried to access a non-existent register: %d\n", in chip_write_masked()
210 return -EINVAL; in chip_write_masked()
213 val = (chip->shadow.bytes[subaddr+1] & ~mask) | (val & mask); in chip_write_masked()
221 struct v4l2_subdev *sd = &chip->sd; in chip_read()
231 return -EIO; in chip_read()
239 struct v4l2_subdev *sd = &chip->sd; in chip_read2()
246 .addr = c->addr, in chip_read2()
251 .addr = c->addr, in chip_read2()
260 rc = i2c_transfer(c->adapter, msgs, 2); in chip_read2()
265 return -EIO; in chip_read2()
274 struct v4l2_subdev *sd = &chip->sd; in chip_cmd()
278 if (0 == cmd->count) in chip_cmd()
281 if (cmd->count + cmd->bytes[0] - 1 >= ARRAY_SIZE(chip->shadow.bytes)) { in chip_cmd()
283 "Tried to access a non-existent register range: %d to %d\n", in chip_cmd()
284 cmd->bytes[0] + 1, cmd->bytes[0] + cmd->count - 1); in chip_cmd()
285 return -EINVAL; in chip_cmd()
292 name, cmd->bytes[0]); in chip_cmd()
293 for (i = 1; i < cmd->count; i++) { in chip_cmd()
295 printk(KERN_CONT " 0x%x", cmd->bytes[i]); in chip_cmd()
296 chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i]; in chip_cmd()
302 rc = i2c_master_send(c, cmd->bytes, cmd->count); in chip_cmd()
303 if (rc != cmd->count) { in chip_cmd()
307 return -EIO; in chip_cmd()
312 /* ---------------------------------------------------------------------- */
322 wake_up_process(chip->thread); in chip_thread_wake()
328 struct CHIPDESC *desc = chip->desc; in chip_thread()
329 struct v4l2_subdev *sd = &chip->sd; in chip_thread()
345 if (chip->radio) in chip_thread()
349 mode = desc->getrxsubchans(chip); in chip_thread()
350 if (mode == chip->prevmode) in chip_thread()
353 /* chip detected a new audio mode - set it */ in chip_thread()
356 chip->prevmode = mode; in chip_thread()
359 switch (chip->audmode) { in chip_thread()
383 desc->setaudmode(chip, selected); in chip_thread()
386 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); in chip_thread()
393 /* ---------------------------------------------------------------------- */
394 /* audio chip descriptions - defines+functions for tda9840 */
411 #define TDA9840_PONRES 0x80 /* Power-on reset detected if = 1 */
418 struct v4l2_subdev *sd = &chip->sd; in tda9840_getrxsubchans()
441 int t = chip->shadow.bytes[TDA9840_SW + 1] & ~0x7e; in tda9840_setaudmode()
480 /* ---------------------------------------------------------------------- */
481 /* audio chip descriptions - defines+functions for tda985x */
488 #define TDA9855_SW 0x04 /* Subwoofer - not connected on DTV2000 */
502 /* 0x00 - VR in TDA9855 */
503 /* 0x01 - VL in TDA9855 */
504 /* lower 7 bits control gain from -71dB (0x28) to 16dB (0x7f)
505 * in 1dB steps - mute is 0x27 */
508 /* 0x02 - BA in TDA9855 */
509 /* lower 5 bits control bass gain from -12dB (0x06) to 16.5dB (0x19)
510 * in .5dB steps - 0 is 0x0E */
513 /* 0x03 - TR in TDA9855 */
514 /* 4 bits << 1 control treble gain from -12dB (0x3) to 12dB (0xb)
515 * in 3dB steps - 0 is 0x7 */
518 /* 0x04 - SW in TDA9855, C4/Control 1 in TDA9850 */
520 /* 4 bits << 2 control subwoofer/surround gain from -14db (0x1) to 14db (0xf)
521 * in 3dB steps - mute is 0x0 */
528 /* 0x05 - C5 - Control 1 in TDA9855 , Control 2 in TDA9850*/
533 #define TDA9855_SUR 1<<3 /* Surround / Subwoofer 1==.5(L-R) 0==.5(L+R) */
545 /* 0x06 - C6 - Control 2 in TDA9855, Control 3 in TDA9850 */
558 #define TDA9855_SPAT_30 2 /* Spatial Stereo, 30% anti-phase crosstalk */
559 #define TDA9855_SPAT_50 3 /* Spatial Stereo, 52% anti-phase crosstalk */
560 #define TDA9855_E_MONO 7 /* Forced mono - mono select elseware, so useless*/
562 /* 0x07 - C7 - Control 3 in TDA9855, Control 4 in TDA9850 */
564 /* lower 4 bits control input gain from -3.5dB (0x0) to 4dB (0xF)
565 * in .5dB steps - 0dB is 0x7 */
567 /* 0x08, 0x09 - A1 and A2 (read/write) */
570 * from 0x00 to 0x1f - nominal at 0x0f and 0x10 (read/write) */
571 #define TDA985x_STP 1<<5 /* Stereo Pilot/detect (read-only) */
572 #define TDA985x_SAPP 1<<6 /* SAP Pilot/detect (read-only) */
573 #define TDA985x_STS 1<<7 /* Stereo trigger 1= <35mV 0= <30mV (write-only)*/
575 /* 0x0a - A3 */
577 /* lower 3 bits control timing current for alignment: -30% (0x0), -20% (0x1),
578 * -10% (0x2), nominal (0x3), +10% (0x6), +20% (0x5), +30% (0x4) */
606 int c6 = chip->shadow.bytes[TDA985x_C6+1] & 0x3f; in tda985x_setaudmode()
630 /* ---------------------------------------------------------------------- */
631 /* audio chip descriptions - defines+functions for tda9873h */
674 * B7: auto-mute (1 = auto-mute enabled)
681 /* Subaddress 0x01: Adjust/standard */
683 /* Lower 4 bits (C3..C0) control stereo adjustment on R channel (-0.6 - +0.7 dB)
744 #define TDA9873_PONR 0 /* Power-on reset detected if = 1 */
750 struct v4l2_subdev *sd = &chip->sd; in tda9873_getrxsubchans()
771 struct v4l2_subdev *sd = &chip->sd; in tda9873_setaudmode()
772 int sw_data = chip->shadow.bytes[TDA9873_SW+1] & ~ TDA9873_TR_MASK; in tda9873_setaudmode()
773 /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */ in tda9873_setaudmode()
782 "tda9873_setaudmode(): chip->shadow.bytes[%d] = %d\n", in tda9873_setaudmode()
783 TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]); in tda9873_setaudmode()
824 /* ---------------------------------------------------------------------- */
825 /* audio chip description - defines+functions for tda9874h and tda9874a */
839 #define TDA9874A_FMER 0x0a /* FM de-emphasis */
851 #define TDA9874A_I2SOSR 0x16 /* I2S-bus output select */
852 #define TDA9874A_I2SOLAR 0x17 /* I2S-bus output level adj. */
854 #define TDA9874A_ESP 0xFF /* easy standard progr. (tda9874a) */
862 #define TDA9874A_LLRA 0x05 /* monitor level read-out LSB */
863 #define TDA9874A_LLRB 0x06 /* monitor level read-out MSB */
874 static int tda9874a_ESP = 0x07; /* default standard: NICAM D/K */
875 static int tda9874a_dic = -1; /* device id. code */
887 * - carrier 1 freq. registers (3 bytes)
888 * - carrier 2 freq. registers (3 bytes)
889 * - demudulator config register
890 * - FM de-emphasis register (slow identification mode)
919 struct v4l2_subdev *sd = &chip->sd; in tda9874a_setup()
958 struct v4l2_subdev *sd = &chip->sd; in tda9874a_getrxsubchans()
975 chip->shadow.bytes[MAXREGS-2] = dsr; in tda9874a_getrxsubchans()
976 chip->shadow.bytes[MAXREGS-1] = nsr; in tda9874a_getrxsubchans()
980 * If NICAM auto-muting is enabled, DSR.AMSTAT=1 indicates in tda9874a_getrxsubchans()
983 * error count. So in fact there is no stereo in this case :-( in tda9874a_getrxsubchans()
1006 struct v4l2_subdev *sd = &chip->sd; in tda9874a_setaudmode()
1008 /* Disable/enable NICAM auto-muting (based on DSR.RSSF status bit). */ in tda9874a_setaudmode()
1009 /* If auto-muting is disabled, we can hear a signal of degrading quality. */ in tda9874a_setaudmode()
1011 if(chip->shadow.bytes[MAXREGS-2] & 0x20) /* DSR.RSSF=1 */ in tda9874a_setaudmode()
1019 * and has auto-select function for audio output (AOSR register). in tda9874a_setaudmode()
1022 * on same (all?) tv-cards is not used, anyway (as well as MONOIN). in tda9874a_setaudmode()
1033 aosr = 0x80; /* auto-select, dual A/A */ in tda9874a_setaudmode()
1037 aosr = 0xa0; /* auto-select, dual B/B */ in tda9874a_setaudmode()
1065 aosr = 0x00; /* handled by NICAM auto-mute */ in tda9874a_setaudmode()
1097 struct v4l2_subdev *sd = &chip->sd; in tda9874a_checkit()
1135 tda9874a_NCONR = 0x01; /* auto-mute: analog mono input */ in tda9874a_initialize()
1137 tda9874a_NCONR = 0x05; /* auto-mute: 1st carrier FM or AM */ in tda9874a_initialize()
1143 /* ---------------------------------------------------------------------- */
1144 /* audio chip description - defines+functions for tda9875 */
1147 * TDA9875: I2C-bus controlled DSP audio processor, FM demodulator
1152 #define TDA9875_MUT 0x12 /*General mute (value --> 0b11001100*/
1153 #define TDA9875_CFG 0x01 /* Config register (value --> 0b00000000 */
1177 #define TDA9875_C1MIB 0x04 /* Carrier 1 (FM) frequency register (16-8]b */
1180 #define TDA9875_C2MIB 0x07 /* Carrier 2 (nicam) frequency register (16-8]b */
1183 #define TDA9875_DEEM 0x0a /* FM de-emphasis regirter*/
1201 chip_write(chip, TDA9875_DEEM, 0x44); /*DE-Emph 0b0100 0100*/ in tda9875_initialize()
1227 static int tda9875_volume(int val) { return (unsigned char)(val / 602 - 84); } in tda9875_volume()
1228 static int tda9875_bass(int val) { return (unsigned char)(max(-12, val / 2115 - 15)); } in tda9875_bass()
1229 static int tda9875_treble(int val) { return (unsigned char)(val / 2622 - 12); } in tda9875_treble()
1231 /* ----------------------------------------------------------------------- */
1240 struct v4l2_subdev *sd = &chip->sd; in tda9875_checkit()
1258 /* ---------------------------------------------------------------------- */
1259 /* audio chip descriptions - defines+functions for tea6420 */
1273 #define TEA6320_V 0x00 /* volume (0-5)/loudness off (6)/zero crossing mute(7) */
1274 #define TEA6320_FFR 0x01 /* fader front right (0-5) */
1275 #define TEA6320_FFL 0x02 /* fader front left (0-5) */
1276 #define TEA6320_FRR 0x03 /* fader rear right (0-5) */
1277 #define TEA6320_FRL 0x04 /* fader rear left (0-5) */
1278 #define TEA6320_BA 0x05 /* bass (0-4) */
1279 #define TEA6320_TR 0x06 /* treble (0-4) */
1300 static int tea6320_volume(int val) { return (val / (65535/(63-12)) + 12) & 0x3f; } in tea6320_volume()
1313 /* ---------------------------------------------------------------------- */
1314 /* audio chip descriptions - defines+functions for tda8425 */
1323 #define TDA8425_S1_CH1 0xCE /* audio channel 1 (mute off) - "linear stereo" mode */
1324 #define TDA8425_S1_CH2 0xCF /* audio channel 2 (mute off) - "linear stereo" mode */
1343 int s1 = chip->shadow.bytes[TDA8425_S1+1] & 0xe1; in tda8425_setaudmode()
1373 /* ---------------------------------------------------------------------- */
1374 /* audio chip descriptions - defines+functions for pic16c54 (PV951) */
1386 #define PIC16C54_MISC_SND_MUTE 0x10 /* bit 4, Mute Audio(Line-in and Tuner) */
1388 #define PIC16C54_MISC_SWITCH_TUNER 0x40 /* bit 6 , Switch to Line-in */
1391 /* ---------------------------------------------------------------------- */
1392 /* audio chip descriptions - defines+functions for TA8874Z */
1435 /* v4l2_dbg(1, debug, &chip->sd, in ta8874z_getrxsubchans()
1449 struct v4l2_subdev *sd = &chip->sd; in ta8874z_setaudmode()
1490 /* ---------------------------------------------------------------------- */
1491 /* audio chip descriptions - struct CHIPDESC */
1501 static int tea6300; /* default 0 - address clash with msp34xx */
1502 static int tea6320; /* default 0 - address clash with msp34xx */
1505 static int ta8874z; /* default 0 - address clash with tda9840 */
1679 .inputreg = -1,
1741 /* ---------------------------------------------------------------------- */
1747 struct CHIPDESC *desc = chip->desc; in tvaudio_s_ctrl()
1749 switch (ctrl->id) { in tvaudio_s_ctrl()
1751 chip->muted = ctrl->val; in tvaudio_s_ctrl()
1752 if (chip->muted) in tvaudio_s_ctrl()
1753 chip_write_masked(chip,desc->inputreg,desc->inputmute,desc->inputmask); in tvaudio_s_ctrl()
1755 chip_write_masked(chip,desc->inputreg, in tvaudio_s_ctrl()
1756 desc->inputmap[chip->input],desc->inputmask); in tvaudio_s_ctrl()
1762 volume = chip->volume->val; in tvaudio_s_ctrl()
1763 balance = chip->balance->val; in tvaudio_s_ctrl()
1764 left = (min(65536U - balance, 32768U) * volume) / 32768U; in tvaudio_s_ctrl()
1767 chip_write(chip, desc->leftreg, desc->volfunc(left)); in tvaudio_s_ctrl()
1768 chip_write(chip, desc->rightreg, desc->volfunc(right)); in tvaudio_s_ctrl()
1772 chip_write(chip, desc->bassreg, desc->bassfunc(ctrl->val)); in tvaudio_s_ctrl()
1775 chip_write(chip, desc->treblereg, desc->treblefunc(ctrl->val)); in tvaudio_s_ctrl()
1778 return -EINVAL; in tvaudio_s_ctrl()
1782 /* ---------------------------------------------------------------------- */
1789 chip->radio = 1; in tvaudio_s_radio()
1790 /* del_timer(&chip->wt); */ in tvaudio_s_radio()
1798 struct CHIPDESC *desc = chip->desc; in tvaudio_s_routing()
1800 if (!(desc->flags & CHIP_HAS_INPUTSEL)) in tvaudio_s_routing()
1803 return -EINVAL; in tvaudio_s_routing()
1805 chip->input = input; in tvaudio_s_routing()
1806 if (chip->muted) in tvaudio_s_routing()
1808 chip_write_masked(chip, desc->inputreg, in tvaudio_s_routing()
1809 desc->inputmap[chip->input], desc->inputmask); in tvaudio_s_routing()
1813 static int tvaudio_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt) in tvaudio_s_tuner() argument
1816 struct CHIPDESC *desc = chip->desc; in tvaudio_s_tuner()
1818 if (!desc->setaudmode) in tvaudio_s_tuner()
1820 if (chip->radio) in tvaudio_s_tuner()
1823 switch (vt->audmode) { in tvaudio_s_tuner()
1831 return -EINVAL; in tvaudio_s_tuner()
1833 chip->audmode = vt->audmode; in tvaudio_s_tuner()
1835 if (chip->thread) in tvaudio_s_tuner()
1836 wake_up_process(chip->thread); in tvaudio_s_tuner()
1838 desc->setaudmode(chip, vt->audmode); in tvaudio_s_tuner()
1843 static int tvaudio_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) in tvaudio_g_tuner() argument
1846 struct CHIPDESC *desc = chip->desc; in tvaudio_g_tuner()
1848 if (!desc->getrxsubchans) in tvaudio_g_tuner()
1850 if (chip->radio) in tvaudio_g_tuner()
1853 vt->audmode = chip->audmode; in tvaudio_g_tuner()
1854 vt->rxsubchans = desc->getrxsubchans(chip); in tvaudio_g_tuner()
1855 vt->capability |= V4L2_TUNER_CAP_STEREO | in tvaudio_g_tuner()
1865 chip->radio = 0; in tvaudio_s_std()
1872 struct CHIPDESC *desc = chip->desc; in tvaudio_s_frequency()
1876 created to set the audio standard. In this case, when then in tvaudio_s_frequency()
1879 to follow whatever audio standard is pointed by the in tvaudio_s_frequency()
1882 if (chip->thread) { in tvaudio_s_frequency()
1883 desc->setaudmode(chip, V4L2_TUNER_MODE_MONO); in tvaudio_s_frequency()
1884 chip->prevmode = -1; /* reset previous mode */ in tvaudio_s_frequency()
1885 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); in tvaudio_s_frequency()
1893 struct CHIPDESC *desc = chip->desc; in tvaudio_log_status()
1895 v4l2_info(sd, "Chip: %s\n", desc->name); in tvaudio_log_status()
1896 v4l2_ctrl_handler_log_status(&chip->hdl, sd->name); in tvaudio_log_status()
1900 /* ----------------------------------------------------------------------- */
1932 /* ----------------------------------------------------------------------- */
1947 for (desc = chiplist; desc->name != NULL; desc++) in tvaudio_probe()
1949 (desc == chiplist) ? "" : ", ", desc->name); in tvaudio_probe()
1953 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); in tvaudio_probe()
1955 return -ENOMEM; in tvaudio_probe()
1956 sd = &chip->sd; in tvaudio_probe()
1960 v4l2_dbg(1, debug, sd, "chip found @ 0x%x\n", client->addr<<1); in tvaudio_probe()
1961 for (desc = chiplist; desc->name != NULL; desc++) { in tvaudio_probe()
1962 if (0 == *(desc->insmodopt)) in tvaudio_probe()
1964 if (client->addr < desc->addr_lo || in tvaudio_probe()
1965 client->addr > desc->addr_hi) in tvaudio_probe()
1967 if (desc->checkit && !desc->checkit(chip)) in tvaudio_probe()
1971 if (desc->name == NULL) { in tvaudio_probe()
1973 return -EIO; in tvaudio_probe()
1975 v4l2_info(sd, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name); in tvaudio_probe()
1976 if (desc->flags) { in tvaudio_probe()
1978 (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "", in tvaudio_probe()
1979 (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "", in tvaudio_probe()
1980 (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); in tvaudio_probe()
1985 strscpy(client->name, desc->name, I2C_NAME_SIZE); in tvaudio_probe()
1986 chip->desc = desc; in tvaudio_probe()
1987 chip->shadow.count = desc->registers+1; in tvaudio_probe()
1988 chip->prevmode = -1; in tvaudio_probe()
1989 chip->audmode = V4L2_TUNER_MODE_LANG1; in tvaudio_probe()
1992 if (desc->initialize != NULL) in tvaudio_probe()
1993 desc->initialize(chip); in tvaudio_probe()
1995 chip_cmd(chip, "init", &desc->init); in tvaudio_probe()
1997 v4l2_ctrl_handler_init(&chip->hdl, 5); in tvaudio_probe()
1998 if (desc->flags & CHIP_HAS_INPUTSEL) in tvaudio_probe()
1999 v4l2_ctrl_new_std(&chip->hdl, &tvaudio_ctrl_ops, in tvaudio_probe()
2001 if (desc->flags & CHIP_HAS_VOLUME) { in tvaudio_probe()
2002 if (!desc->volfunc) { in tvaudio_probe()
2007 desc->flags &= ~CHIP_HAS_VOLUME; in tvaudio_probe()
2009 chip->volume = v4l2_ctrl_new_std(&chip->hdl, in tvaudio_probe()
2012 desc->volinit ? desc->volinit : 65535); in tvaudio_probe()
2013 chip->balance = v4l2_ctrl_new_std(&chip->hdl, in tvaudio_probe()
2016 v4l2_ctrl_cluster(2, &chip->volume); in tvaudio_probe()
2019 if (desc->flags & CHIP_HAS_BASSTREBLE) { in tvaudio_probe()
2020 if (!desc->bassfunc || !desc->treblefunc) { in tvaudio_probe()
2025 desc->flags &= ~CHIP_HAS_BASSTREBLE; in tvaudio_probe()
2027 v4l2_ctrl_new_std(&chip->hdl, in tvaudio_probe()
2030 desc->bassinit ? desc->bassinit : 32768); in tvaudio_probe()
2031 v4l2_ctrl_new_std(&chip->hdl, in tvaudio_probe()
2034 desc->trebleinit ? desc->trebleinit : 32768); in tvaudio_probe()
2038 sd->ctrl_handler = &chip->hdl; in tvaudio_probe()
2039 if (chip->hdl.error) { in tvaudio_probe()
2040 int err = chip->hdl.error; in tvaudio_probe()
2042 v4l2_ctrl_handler_free(&chip->hdl); in tvaudio_probe()
2046 v4l2_ctrl_handler_setup(&chip->hdl); in tvaudio_probe()
2048 chip->thread = NULL; in tvaudio_probe()
2049 timer_setup(&chip->wt, chip_thread_wake, 0); in tvaudio_probe()
2050 if (desc->flags & CHIP_NEED_CHECKMODE) { in tvaudio_probe()
2051 if (!desc->getrxsubchans || !desc->setaudmode) { in tvaudio_probe()
2059 chip->thread = kthread_run(chip_thread, chip, "%s", in tvaudio_probe()
2060 client->name); in tvaudio_probe()
2061 if (IS_ERR(chip->thread)) { in tvaudio_probe()
2063 chip->thread = NULL; in tvaudio_probe()
2074 del_timer_sync(&chip->wt); in tvaudio_remove()
2075 if (chip->thread) { in tvaudio_remove()
2077 kthread_stop(chip->thread); in tvaudio_remove()
2078 chip->thread = NULL; in tvaudio_remove()
2082 v4l2_ctrl_handler_free(&chip->hdl); in tvaudio_remove()