Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1 | /* cx25840 audio functions |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or |
| 4 | * modify it under the terms of the GNU General Public License |
| 5 | * as published by the Free Software Foundation; either version 2 |
| 6 | * of the License, or (at your option) any later version. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | #include <linux/videodev2.h> |
| 20 | #include <linux/i2c.h> |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 21 | #include <media/v4l2-common.h> |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 22 | #include <media/cx25840.h> |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 23 | |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 24 | #include "cx25840-core.h" |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 25 | |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 26 | static int set_audclk_freq(struct i2c_client *client, u32 freq) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 27 | { |
Hans Verkuil | 9357b31 | 2008-11-29 12:50:06 -0300 | [diff] [blame] | 28 | struct cx25840_state *state = to_state(i2c_get_clientdata(client)); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 29 | |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 30 | if (freq != 32000 && freq != 44100 && freq != 48000) |
| 31 | return -EINVAL; |
| 32 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 33 | /* common for all inputs and rates */ |
| 34 | /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */ |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 35 | if (!state->is_cx23885 && !state->is_cx231xx) |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 36 | cx25840_write(client, 0x127, 0x50); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 37 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 38 | if (state->aud_input != CX25840_AUDIO_SERIAL) { |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 39 | switch (freq) { |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 40 | case 32000: |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 41 | if (state->is_cx23885) { |
| 42 | /* We don't have register values |
| 43 | * so avoid destroying registers. */ |
| 44 | break; |
| 45 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 46 | |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 47 | if (!state->is_cx231xx) { |
| 48 | |
| 49 | /* VID_PLL and AUX_PLL */ |
| 50 | cx25840_write4(client, 0x108, 0x1006040f); |
| 51 | |
| 52 | /* AUX_PLL_FRAC */ |
| 53 | cx25840_write4(client, 0x110, 0x01bb39ee); |
| 54 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 55 | |
Hans Verkuil | e2b8cf4 | 2006-04-22 10:22:46 -0300 | [diff] [blame] | 56 | if (state->is_cx25836) |
| 57 | break; |
| 58 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 59 | /* src3/4/6_ctl = 0x0801f77f */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 60 | cx25840_write4(client, 0x900, 0x0801f77f); |
| 61 | cx25840_write4(client, 0x904, 0x0801f77f); |
| 62 | cx25840_write4(client, 0x90c, 0x0801f77f); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 63 | break; |
| 64 | |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 65 | case 44100: |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 66 | if (state->is_cx23885) { |
| 67 | /* We don't have register values |
| 68 | * so avoid destroying registers. */ |
| 69 | break; |
| 70 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 71 | |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 72 | if (!state->is_cx231xx) { |
| 73 | |
| 74 | /* VID_PLL and AUX_PLL */ |
| 75 | cx25840_write4(client, 0x108, 0x1009040f); |
| 76 | |
| 77 | /* AUX_PLL_FRAC */ |
| 78 | cx25840_write4(client, 0x110, 0x00ec6bd6); |
| 79 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 80 | |
Hans Verkuil | e2b8cf4 | 2006-04-22 10:22:46 -0300 | [diff] [blame] | 81 | if (state->is_cx25836) |
| 82 | break; |
| 83 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 84 | /* src3/4/6_ctl = 0x08016d59 */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 85 | cx25840_write4(client, 0x900, 0x08016d59); |
| 86 | cx25840_write4(client, 0x904, 0x08016d59); |
| 87 | cx25840_write4(client, 0x90c, 0x08016d59); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 88 | break; |
| 89 | |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 90 | case 48000: |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 91 | if (state->is_cx23885) { |
| 92 | /* We don't have register values |
| 93 | * so avoid destroying registers. */ |
| 94 | break; |
| 95 | } |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 96 | |
| 97 | if (!state->is_cx231xx) { |
| 98 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 99 | /* VID_PLL and AUX_PLL */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 100 | cx25840_write4(client, 0x108, 0x100a040f); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 101 | |
| 102 | /* AUX_PLL_FRAC */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 103 | cx25840_write4(client, 0x110, 0x0098d6e5); |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 104 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 105 | |
Hans Verkuil | e2b8cf4 | 2006-04-22 10:22:46 -0300 | [diff] [blame] | 106 | if (state->is_cx25836) |
| 107 | break; |
| 108 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 109 | /* src3/4/6_ctl = 0x08014faa */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 110 | cx25840_write4(client, 0x900, 0x08014faa); |
| 111 | cx25840_write4(client, 0x904, 0x08014faa); |
| 112 | cx25840_write4(client, 0x90c, 0x08014faa); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 113 | break; |
| 114 | } |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 115 | } else { |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 116 | switch (freq) { |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 117 | case 32000: |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 118 | if (state->is_cx23885) { |
| 119 | /* We don't have register values |
| 120 | * so avoid destroying registers. */ |
| 121 | break; |
| 122 | } |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 123 | |
| 124 | if (!state->is_cx231xx) { |
| 125 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 126 | /* VID_PLL and AUX_PLL */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 127 | cx25840_write4(client, 0x108, 0x1e08040f); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 128 | |
| 129 | /* AUX_PLL_FRAC */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 130 | cx25840_write4(client, 0x110, 0x012a0869); |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 131 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 132 | |
Hans Verkuil | e2b8cf4 | 2006-04-22 10:22:46 -0300 | [diff] [blame] | 133 | if (state->is_cx25836) |
| 134 | break; |
| 135 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 136 | /* src1_ctl = 0x08010000 */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 137 | cx25840_write4(client, 0x8f8, 0x08010000); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 138 | |
| 139 | /* src3/4/6_ctl = 0x08020000 */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 140 | cx25840_write4(client, 0x900, 0x08020000); |
| 141 | cx25840_write4(client, 0x904, 0x08020000); |
| 142 | cx25840_write4(client, 0x90c, 0x08020000); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 143 | |
| 144 | /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */ |
| 145 | cx25840_write(client, 0x127, 0x54); |
| 146 | break; |
| 147 | |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 148 | case 44100: |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 149 | if (state->is_cx23885) { |
| 150 | /* We don't have register values |
| 151 | * so avoid destroying registers. */ |
| 152 | break; |
| 153 | } |
| 154 | |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 155 | |
| 156 | if (!state->is_cx231xx) { |
| 157 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 158 | /* VID_PLL and AUX_PLL */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 159 | cx25840_write4(client, 0x108, 0x1809040f); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 160 | |
| 161 | /* AUX_PLL_FRAC */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 162 | cx25840_write4(client, 0x110, 0x00ec6bd6); |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 163 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 164 | |
Hans Verkuil | e2b8cf4 | 2006-04-22 10:22:46 -0300 | [diff] [blame] | 165 | if (state->is_cx25836) |
| 166 | break; |
| 167 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 168 | /* src1_ctl = 0x08010000 */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 169 | cx25840_write4(client, 0x8f8, 0x080160cd); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 170 | |
| 171 | /* src3/4/6_ctl = 0x08020000 */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 172 | cx25840_write4(client, 0x900, 0x08017385); |
| 173 | cx25840_write4(client, 0x904, 0x08017385); |
| 174 | cx25840_write4(client, 0x90c, 0x08017385); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 175 | break; |
| 176 | |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 177 | case 48000: |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 178 | if (!state->is_cx23885 && !state->is_cx231xx) { |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 179 | /* VID_PLL and AUX_PLL */ |
| 180 | cx25840_write4(client, 0x108, 0x180a040f); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 181 | |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 182 | /* AUX_PLL_FRAC */ |
| 183 | cx25840_write4(client, 0x110, 0x0098d6e5); |
| 184 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 185 | |
Hans Verkuil | e2b8cf4 | 2006-04-22 10:22:46 -0300 | [diff] [blame] | 186 | if (state->is_cx25836) |
| 187 | break; |
| 188 | |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 189 | if (!state->is_cx23885 && !state->is_cx231xx) { |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 190 | /* src1_ctl */ |
| 191 | cx25840_write4(client, 0x8f8, 0x08018000); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 192 | |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 193 | /* src3/4/6_ctl */ |
| 194 | cx25840_write4(client, 0x900, 0x08015555); |
| 195 | cx25840_write4(client, 0x904, 0x08015555); |
| 196 | cx25840_write4(client, 0x90c, 0x08015555); |
| 197 | } else { |
| 198 | |
| 199 | cx25840_write4(client, 0x8f8, 0x0801867c); |
| 200 | |
| 201 | cx25840_write4(client, 0x900, 0x08014faa); |
| 202 | cx25840_write4(client, 0x904, 0x08014faa); |
| 203 | cx25840_write4(client, 0x90c, 0x08014faa); |
| 204 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 205 | break; |
| 206 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 209 | state->audclk_freq = freq; |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 214 | void cx25840_audio_set_path(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 215 | { |
Hans Verkuil | 9357b31 | 2008-11-29 12:50:06 -0300 | [diff] [blame] | 216 | struct cx25840_state *state = to_state(i2c_get_clientdata(client)); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 217 | |
Hans Verkuil | 8267761 | 2007-08-07 07:16:07 -0300 | [diff] [blame] | 218 | /* assert soft reset */ |
| 219 | cx25840_and_or(client, 0x810, ~0x1, 0x01); |
| 220 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 221 | /* stop microcontroller */ |
| 222 | cx25840_and_or(client, 0x803, ~0x10, 0); |
| 223 | |
| 224 | /* Mute everything to prevent the PFFT! */ |
| 225 | cx25840_write(client, 0x8d3, 0x1f); |
| 226 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 227 | if (state->aud_input == CX25840_AUDIO_SERIAL) { |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 228 | /* Set Path1 to Serial Audio Input */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 229 | cx25840_write4(client, 0x8d0, 0x01011012); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 230 | |
| 231 | /* The microcontroller should not be started for the |
| 232 | * non-tuner inputs: autodetection is specific for |
| 233 | * TV audio. */ |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 234 | } else { |
| 235 | /* Set Path1 to Analog Demod Main Channel */ |
Hans Verkuil | 4a56eb3 | 2007-12-02 07:03:45 -0300 | [diff] [blame] | 236 | cx25840_write4(client, 0x8d0, 0x1f063870); |
Hans Verkuil | c0c044a | 2006-04-29 12:11:18 -0300 | [diff] [blame] | 237 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 238 | |
Hans Verkuil | c0c044a | 2006-04-29 12:11:18 -0300 | [diff] [blame] | 239 | set_audclk_freq(client, state->audclk_freq); |
| 240 | |
| 241 | if (state->aud_input != CX25840_AUDIO_SERIAL) { |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 242 | /* When the microcontroller detects the |
| 243 | * audio format, it will unmute the lines */ |
| 244 | cx25840_and_or(client, 0x803, ~0x10, 0x10); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 245 | } |
Hans Verkuil | 8267761 | 2007-08-07 07:16:07 -0300 | [diff] [blame] | 246 | |
| 247 | /* deassert soft reset */ |
| 248 | cx25840_and_or(client, 0x810, ~0x1, 0x00); |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 249 | |
Sri Deevi | 149783b | 2009-03-03 06:07:42 -0300 | [diff] [blame^] | 250 | if (state->is_cx23885 || state->is_cx231xx) { |
Steven Toth | f234081 | 2008-01-10 01:22:39 -0300 | [diff] [blame] | 251 | /* Ensure the controller is running when we exit */ |
| 252 | cx25840_and_or(client, 0x803, ~0x10, 0x10); |
| 253 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 256 | static int get_volume(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 257 | { |
Hans Verkuil | 9357b31 | 2008-11-29 12:50:06 -0300 | [diff] [blame] | 258 | struct cx25840_state *state = to_state(i2c_get_clientdata(client)); |
Hans Verkuil | 87410da | 2007-08-05 08:00:36 -0300 | [diff] [blame] | 259 | int vol; |
| 260 | |
| 261 | if (state->unmute_volume >= 0) |
| 262 | return state->unmute_volume; |
| 263 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 264 | /* Volume runs +18dB to -96dB in 1/2dB steps |
| 265 | * change to fit the msp3400 -114dB to +12dB range */ |
| 266 | |
| 267 | /* check PATH1_VOLUME */ |
Hans Verkuil | 87410da | 2007-08-05 08:00:36 -0300 | [diff] [blame] | 268 | vol = 228 - cx25840_read(client, 0x8d4); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 269 | vol = (vol / 2) + 23; |
| 270 | return vol << 9; |
| 271 | } |
| 272 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 273 | static void set_volume(struct i2c_client *client, int volume) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 274 | { |
Hans Verkuil | 9357b31 | 2008-11-29 12:50:06 -0300 | [diff] [blame] | 275 | struct cx25840_state *state = to_state(i2c_get_clientdata(client)); |
Hans Verkuil | 87410da | 2007-08-05 08:00:36 -0300 | [diff] [blame] | 276 | int vol; |
| 277 | |
| 278 | if (state->unmute_volume >= 0) { |
| 279 | state->unmute_volume = volume; |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | /* Convert the volume to msp3400 values (0-127) */ |
| 284 | vol = volume >> 9; |
| 285 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 286 | /* now scale it up to cx25840 values |
| 287 | * -114dB to -96dB maps to 0 |
| 288 | * this should be 19, but in my testing that was 4dB too loud */ |
| 289 | if (vol <= 23) { |
| 290 | vol = 0; |
| 291 | } else { |
| 292 | vol -= 23; |
| 293 | } |
| 294 | |
| 295 | /* PATH1_VOLUME */ |
| 296 | cx25840_write(client, 0x8d4, 228 - (vol * 2)); |
| 297 | } |
| 298 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 299 | static int get_bass(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 300 | { |
| 301 | /* bass is 49 steps +12dB to -12dB */ |
| 302 | |
| 303 | /* check PATH1_EQ_BASS_VOL */ |
| 304 | int bass = cx25840_read(client, 0x8d9) & 0x3f; |
| 305 | bass = (((48 - bass) * 0xffff) + 47) / 48; |
| 306 | return bass; |
| 307 | } |
| 308 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 309 | static void set_bass(struct i2c_client *client, int bass) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 310 | { |
| 311 | /* PATH1_EQ_BASS_VOL */ |
| 312 | cx25840_and_or(client, 0x8d9, ~0x3f, 48 - (bass * 48 / 0xffff)); |
| 313 | } |
| 314 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 315 | static int get_treble(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 316 | { |
| 317 | /* treble is 49 steps +12dB to -12dB */ |
| 318 | |
| 319 | /* check PATH1_EQ_TREBLE_VOL */ |
| 320 | int treble = cx25840_read(client, 0x8db) & 0x3f; |
| 321 | treble = (((48 - treble) * 0xffff) + 47) / 48; |
| 322 | return treble; |
| 323 | } |
| 324 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 325 | static void set_treble(struct i2c_client *client, int treble) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 326 | { |
| 327 | /* PATH1_EQ_TREBLE_VOL */ |
| 328 | cx25840_and_or(client, 0x8db, ~0x3f, 48 - (treble * 48 / 0xffff)); |
| 329 | } |
| 330 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 331 | static int get_balance(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 332 | { |
| 333 | /* balance is 7 bit, 0 to -96dB */ |
| 334 | |
| 335 | /* check PATH1_BAL_LEVEL */ |
| 336 | int balance = cx25840_read(client, 0x8d5) & 0x7f; |
| 337 | /* check PATH1_BAL_LEFT */ |
| 338 | if ((cx25840_read(client, 0x8d5) & 0x80) == 0) |
| 339 | balance = 0x80 - balance; |
| 340 | else |
| 341 | balance = 0x80 + balance; |
| 342 | return balance << 8; |
| 343 | } |
| 344 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 345 | static void set_balance(struct i2c_client *client, int balance) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 346 | { |
| 347 | int bal = balance >> 8; |
| 348 | if (bal > 0x80) { |
| 349 | /* PATH1_BAL_LEFT */ |
| 350 | cx25840_and_or(client, 0x8d5, 0x7f, 0x80); |
| 351 | /* PATH1_BAL_LEVEL */ |
| 352 | cx25840_and_or(client, 0x8d5, ~0x7f, bal & 0x7f); |
| 353 | } else { |
| 354 | /* PATH1_BAL_LEFT */ |
| 355 | cx25840_and_or(client, 0x8d5, 0x7f, 0x00); |
| 356 | /* PATH1_BAL_LEVEL */ |
| 357 | cx25840_and_or(client, 0x8d5, ~0x7f, 0x80 - bal); |
| 358 | } |
| 359 | } |
| 360 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 361 | static int get_mute(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 362 | { |
Hans Verkuil | 9357b31 | 2008-11-29 12:50:06 -0300 | [diff] [blame] | 363 | struct cx25840_state *state = to_state(i2c_get_clientdata(client)); |
Hans Verkuil | 87410da | 2007-08-05 08:00:36 -0300 | [diff] [blame] | 364 | |
| 365 | return state->unmute_volume >= 0; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 368 | static void set_mute(struct i2c_client *client, int mute) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 369 | { |
Hans Verkuil | 9357b31 | 2008-11-29 12:50:06 -0300 | [diff] [blame] | 370 | struct cx25840_state *state = to_state(i2c_get_clientdata(client)); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 371 | |
Hans Verkuil | 87410da | 2007-08-05 08:00:36 -0300 | [diff] [blame] | 372 | if (mute && state->unmute_volume == -1) { |
| 373 | int vol = get_volume(client); |
| 374 | |
| 375 | set_volume(client, 0); |
| 376 | state->unmute_volume = vol; |
| 377 | } |
| 378 | else if (!mute && state->unmute_volume != -1) { |
| 379 | int vol = state->unmute_volume; |
| 380 | |
| 381 | state->unmute_volume = -1; |
| 382 | set_volume(client, vol); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 386 | int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 387 | { |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 388 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 389 | struct cx25840_state *state = to_state(sd); |
Hans Verkuil | c0c044a | 2006-04-29 12:11:18 -0300 | [diff] [blame] | 390 | int retval; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 391 | |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 392 | if (!state->is_cx25836) |
| 393 | cx25840_and_or(client, 0x810, ~0x1, 1); |
| 394 | if (state->aud_input != CX25840_AUDIO_SERIAL) { |
| 395 | cx25840_and_or(client, 0x803, ~0x10, 0); |
| 396 | cx25840_write(client, 0x8d3, 0x1f); |
| 397 | } |
| 398 | retval = set_audclk_freq(client, freq); |
| 399 | if (state->aud_input != CX25840_AUDIO_SERIAL) |
| 400 | cx25840_and_or(client, 0x803, ~0x10, 0x10); |
| 401 | if (!state->is_cx25836) |
| 402 | cx25840_and_or(client, 0x810, ~0x1, 0); |
| 403 | return retval; |
| 404 | } |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 405 | |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 406 | int cx25840_audio_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
| 407 | { |
| 408 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 409 | |
| 410 | switch (ctrl->id) { |
| 411 | case V4L2_CID_AUDIO_VOLUME: |
| 412 | ctrl->value = get_volume(client); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 413 | break; |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 414 | case V4L2_CID_AUDIO_BASS: |
| 415 | ctrl->value = get_bass(client); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 416 | break; |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 417 | case V4L2_CID_AUDIO_TREBLE: |
| 418 | ctrl->value = get_treble(client); |
| 419 | break; |
| 420 | case V4L2_CID_AUDIO_BALANCE: |
| 421 | ctrl->value = get_balance(client); |
| 422 | break; |
| 423 | case V4L2_CID_AUDIO_MUTE: |
| 424 | ctrl->value = get_mute(client); |
| 425 | break; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 426 | default: |
| 427 | return -EINVAL; |
| 428 | } |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 429 | return 0; |
| 430 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 431 | |
Hans Verkuil | df1d5ed | 2009-03-30 06:26:40 -0300 | [diff] [blame] | 432 | int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
| 433 | { |
| 434 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 435 | |
| 436 | switch (ctrl->id) { |
| 437 | case V4L2_CID_AUDIO_VOLUME: |
| 438 | set_volume(client, ctrl->value); |
| 439 | break; |
| 440 | case V4L2_CID_AUDIO_BASS: |
| 441 | set_bass(client, ctrl->value); |
| 442 | break; |
| 443 | case V4L2_CID_AUDIO_TREBLE: |
| 444 | set_treble(client, ctrl->value); |
| 445 | break; |
| 446 | case V4L2_CID_AUDIO_BALANCE: |
| 447 | set_balance(client, ctrl->value); |
| 448 | break; |
| 449 | case V4L2_CID_AUDIO_MUTE: |
| 450 | set_mute(client, ctrl->value); |
| 451 | break; |
| 452 | default: |
| 453 | return -EINVAL; |
| 454 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 455 | return 0; |
| 456 | } |