// SPDX-License-Identifier: GPL-2.0 /* * For the STS-Thompson TDA7432 audio processor chip * * Handles audio functions: volume, balance, tone, loudness * This driver will not complain if used with any * other i2c device with the same address. * * Muting and tone control by Jonathan Isom <[email protected]> * * Copyright (c) 2000 Eric Sandeen <[email protected]> * Copyright (c) 2006 Mauro Carvalho Chehab <[email protected]> * * Based on tda9855.c by Steve VanDeBogart ([email protected]) * Which was based on tda8425.c by Greg Alexander (c) 1998 * * OPTIONS: * debug - set to 1 if you'd like to see debug messages * set to 2 if you'd like to be inundated with debug messages * * loudness - set between 0 and 15 for varying degrees of loudness effect * * maxvol - set maximum volume to +20db (1), default is 0db(0) */ #include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/string.h> #include <linux/timer.h> #include <linux/delay.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/videodev2.h> #include <linux/i2c.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-ctrls.h> #ifndef VIDEO_AUDIO_BALANCE #define VIDEO_AUDIO_BALANCE … #endif MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; static int maxvol; static int loudness; /* disable loudness by default */ static int debug; /* insmod parameter */ module_param(debug, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(…) …; module_param(loudness, int, S_IRUGO); MODULE_PARM_DESC(…) …; module_param(maxvol, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(…) …; /* Structure of address and subaddresses for the tda7432 */ struct tda7432 { … }; static inline struct tda7432 *to_state(struct v4l2_subdev *sd) { … } static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) { … } /* The TDA7432 is made by STS-Thompson * http://www.st.com * http://us.st.com/stonline/books/pdf/docs/4056.pdf * * TDA7432: I2C-bus controlled basic audio processor * * The TDA7432 controls basic audio functions like volume, balance, * and tone control (including loudness). It also has four channel * output (for front and rear). Since most vidcap cards probably * don't have 4 channel output, this driver will set front & rear * together (no independent control). */ /* Subaddresses for TDA7432 */ #define TDA7432_IN … #define TDA7432_VL … #define TDA7432_TN … #define TDA7432_LF … #define TDA7432_LR … #define TDA7432_RF … #define TDA7432_RR … #define TDA7432_LD … /* Masks for bits in TDA7432 subaddresses */ /* Many of these not used - just for documentation */ /* Subaddress 0x00 - Input selection and bass control */ /* Bits 0,1,2 control input: * 0x00 - Stereo input * 0x02 - Mono input * 0x03 - Mute (Using Attenuators Plays better with modules) * Mono probably isn't used - I'm guessing only the stereo * input is connected on most cards, so we'll set it to stereo. * * Bit 3 controls bass cut: 0/1 is non-symmetric/symmetric bass cut * Bit 4 controls bass range: 0/1 is extended/standard bass range * * Highest 3 bits not used */ #define TDA7432_STEREO_IN … #define TDA7432_MONO_IN … #define TDA7432_BASS_SYM … #define TDA7432_BASS_NORM … /* Subaddress 0x01 - Volume */ /* Lower 7 bits control volume from -79dB to +32dB in 1dB steps * Recommended maximum is +20 dB * * +32dB: 0x00 * +20dB: 0x0c * 0dB: 0x20 * -79dB: 0x6f * * MSB (bit 7) controls loudness: 1/0 is loudness on/off */ #define TDA7432_VOL_0DB … #define TDA7432_LD_ON … /* Subaddress 0x02 - Tone control */ /* Bits 0,1,2 control absolute treble gain from 0dB to 14dB * 0x0 is 14dB, 0x7 is 0dB * * Bit 3 controls treble attenuation/gain (sign) * 1 = gain (+) * 0 = attenuation (-) * * Bits 4,5,6 control absolute bass gain from 0dB to 14dB * (This is only true for normal base range, set in 0x00) * 0x0 << 4 is 14dB, 0x7 is 0dB * * Bit 7 controls bass attenuation/gain (sign) * 1 << 7 = gain (+) * 0 << 7 = attenuation (-) * * Example: * 1 1 0 1 0 1 0 1 is +4dB bass, -4dB treble */ #define TDA7432_TREBLE_0DB … #define TDA7432_TREBLE … #define TDA7432_TREBLE_GAIN … #define TDA7432_BASS_0DB … #define TDA7432_BASS … #define TDA7432_BASS_GAIN … /* Subaddress 0x03 - Left Front attenuation */ /* Subaddress 0x04 - Left Rear attenuation */ /* Subaddress 0x05 - Right Front attenuation */ /* Subaddress 0x06 - Right Rear attenuation */ /* Bits 0,1,2,3,4 control attenuation from 0dB to -37.5dB * in 1.5dB steps. * * 0x00 is 0dB * 0x1f is -37.5dB * * Bit 5 mutes that channel when set (1 = mute, 0 = unmute) * We'll use the mute on the input, though (above) * Bits 6,7 unused */ #define TDA7432_ATTEN_0DB … #define TDA7432_MUTE … /* Subaddress 0x07 - Loudness Control */ /* Bits 0,1,2,3 control loudness from 0dB to -15dB in 1dB steps * when bit 4 is NOT set * * 0x0 is 0dB * 0xf is -15dB * * If bit 4 is set, then there is a flat attenuation according to * the lower 4 bits, as above. * * Bits 5,6,7 unused */ /* Begin code */ static int tda7432_write(struct v4l2_subdev *sd, int subaddr, int val) { … } static int tda7432_set(struct v4l2_subdev *sd) { … } static int tda7432_log_status(struct v4l2_subdev *sd) { … } static int tda7432_s_ctrl(struct v4l2_ctrl *ctrl) { … } /* ----------------------------------------------------------------------- */ static const struct v4l2_ctrl_ops tda7432_ctrl_ops = …; static const struct v4l2_subdev_core_ops tda7432_core_ops = …; static const struct v4l2_subdev_ops tda7432_ops = …; /* ----------------------------------------------------------------------- */ /* *********************** * * i2c interface functions * * *********************** */ static int tda7432_probe(struct i2c_client *client) { … } static void tda7432_remove(struct i2c_client *client) { … } static const struct i2c_device_id tda7432_id[] = …; MODULE_DEVICE_TABLE(i2c, tda7432_id); static struct i2c_driver tda7432_driver = …; module_i2c_driver(…) …;