Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved. |
| 3 | * |
| 4 | * This source file is released under GPL v2 license (no other versions). |
| 5 | * See the COPYING file included in the main directory of this source |
| 6 | * distribution for the license terms and conditions. |
| 7 | * |
| 8 | * @File cthw20k2.c |
| 9 | * |
| 10 | * @Brief |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 11 | * This file contains the implementation of hardware access method for 20k2. |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 12 | * |
| 13 | * @Author Liu Chun |
| 14 | * @Date May 14 2008 |
| 15 | * |
| 16 | */ |
| 17 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 18 | #include <linux/types.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/pci.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/interrupt.h> |
Takashi Iwai | d0da727 | 2009-05-14 10:56:04 +0200 | [diff] [blame] | 25 | #include <linux/delay.h> |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 26 | #include "cthw20k2.h" |
| 27 | #include "ct20k2reg.h" |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 28 | |
Takashi Iwai | 4836ac6 | 2009-06-08 14:49:26 +0200 | [diff] [blame] | 29 | #if BITS_PER_LONG == 32 |
| 30 | #define CT_XFI_DMA_MASK DMA_BIT_MASK(32) /* 32 bit PTE */ |
| 31 | #else |
| 32 | #define CT_XFI_DMA_MASK DMA_BIT_MASK(64) /* 64 bit PTE */ |
| 33 | #endif |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 34 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 35 | struct hw20k2 { |
| 36 | struct hw hw; |
| 37 | /* for i2c */ |
| 38 | unsigned char dev_id; |
| 39 | unsigned char addr_size; |
| 40 | unsigned char data_size; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 41 | |
| 42 | int mic_source; |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 45 | static u32 hw_read_20kx(struct hw *hw, u32 reg); |
| 46 | static void hw_write_20kx(struct hw *hw, u32 reg, u32 data); |
| 47 | |
| 48 | /* |
| 49 | * Type definition block. |
| 50 | * The layout of control structures can be directly applied on 20k2 chip. |
| 51 | */ |
| 52 | |
| 53 | /* |
| 54 | * SRC control block definitions. |
| 55 | */ |
| 56 | |
| 57 | /* SRC resource control block */ |
| 58 | #define SRCCTL_STATE 0x00000007 |
| 59 | #define SRCCTL_BM 0x00000008 |
| 60 | #define SRCCTL_RSR 0x00000030 |
| 61 | #define SRCCTL_SF 0x000001C0 |
| 62 | #define SRCCTL_WR 0x00000200 |
| 63 | #define SRCCTL_PM 0x00000400 |
| 64 | #define SRCCTL_ROM 0x00001800 |
| 65 | #define SRCCTL_VO 0x00002000 |
| 66 | #define SRCCTL_ST 0x00004000 |
| 67 | #define SRCCTL_IE 0x00008000 |
| 68 | #define SRCCTL_ILSZ 0x000F0000 |
| 69 | #define SRCCTL_BP 0x00100000 |
| 70 | |
| 71 | #define SRCCCR_CISZ 0x000007FF |
| 72 | #define SRCCCR_CWA 0x001FF800 |
| 73 | #define SRCCCR_D 0x00200000 |
| 74 | #define SRCCCR_RS 0x01C00000 |
| 75 | #define SRCCCR_NAL 0x3E000000 |
| 76 | #define SRCCCR_RA 0xC0000000 |
| 77 | |
| 78 | #define SRCCA_CA 0x0FFFFFFF |
| 79 | #define SRCCA_RS 0xE0000000 |
| 80 | |
| 81 | #define SRCSA_SA 0x0FFFFFFF |
| 82 | |
| 83 | #define SRCLA_LA 0x0FFFFFFF |
| 84 | |
| 85 | /* Mixer Parameter Ring ram Low and Hight register. |
| 86 | * Fixed-point value in 8.24 format for parameter channel */ |
| 87 | #define MPRLH_PITCH 0xFFFFFFFF |
| 88 | |
| 89 | /* SRC resource register dirty flags */ |
| 90 | union src_dirty { |
| 91 | struct { |
| 92 | u16 ctl:1; |
| 93 | u16 ccr:1; |
| 94 | u16 sa:1; |
| 95 | u16 la:1; |
| 96 | u16 ca:1; |
| 97 | u16 mpr:1; |
| 98 | u16 czbfs:1; /* Clear Z-Buffers */ |
| 99 | u16 rsv:9; |
| 100 | } bf; |
| 101 | u16 data; |
| 102 | }; |
| 103 | |
| 104 | struct src_rsc_ctrl_blk { |
| 105 | unsigned int ctl; |
| 106 | unsigned int ccr; |
| 107 | unsigned int ca; |
| 108 | unsigned int sa; |
| 109 | unsigned int la; |
| 110 | unsigned int mpr; |
| 111 | union src_dirty dirty; |
| 112 | }; |
| 113 | |
| 114 | /* SRC manager control block */ |
| 115 | union src_mgr_dirty { |
| 116 | struct { |
| 117 | u16 enb0:1; |
| 118 | u16 enb1:1; |
| 119 | u16 enb2:1; |
| 120 | u16 enb3:1; |
| 121 | u16 enb4:1; |
| 122 | u16 enb5:1; |
| 123 | u16 enb6:1; |
| 124 | u16 enb7:1; |
| 125 | u16 enbsa:1; |
| 126 | u16 rsv:7; |
| 127 | } bf; |
| 128 | u16 data; |
| 129 | }; |
| 130 | |
| 131 | struct src_mgr_ctrl_blk { |
| 132 | unsigned int enbsa; |
| 133 | unsigned int enb[8]; |
| 134 | union src_mgr_dirty dirty; |
| 135 | }; |
| 136 | |
| 137 | /* SRCIMP manager control block */ |
| 138 | #define SRCAIM_ARC 0x00000FFF |
| 139 | #define SRCAIM_NXT 0x00FF0000 |
| 140 | #define SRCAIM_SRC 0xFF000000 |
| 141 | |
| 142 | struct srcimap { |
| 143 | unsigned int srcaim; |
| 144 | unsigned int idx; |
| 145 | }; |
| 146 | |
| 147 | /* SRCIMP manager register dirty flags */ |
| 148 | union srcimp_mgr_dirty { |
| 149 | struct { |
| 150 | u16 srcimap:1; |
| 151 | u16 rsv:15; |
| 152 | } bf; |
| 153 | u16 data; |
| 154 | }; |
| 155 | |
| 156 | struct srcimp_mgr_ctrl_blk { |
| 157 | struct srcimap srcimap; |
| 158 | union srcimp_mgr_dirty dirty; |
| 159 | }; |
| 160 | |
| 161 | /* |
| 162 | * Function implementation block. |
| 163 | */ |
| 164 | |
| 165 | static int src_get_rsc_ctrl_blk(void **rblk) |
| 166 | { |
| 167 | struct src_rsc_ctrl_blk *blk; |
| 168 | |
| 169 | *rblk = NULL; |
| 170 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 171 | if (!blk) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 172 | return -ENOMEM; |
| 173 | |
| 174 | *rblk = blk; |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static int src_put_rsc_ctrl_blk(void *blk) |
| 180 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 181 | kfree(blk); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int src_set_state(void *blk, unsigned int state) |
| 187 | { |
| 188 | struct src_rsc_ctrl_blk *ctl = blk; |
| 189 | |
| 190 | set_field(&ctl->ctl, SRCCTL_STATE, state); |
| 191 | ctl->dirty.bf.ctl = 1; |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int src_set_bm(void *blk, unsigned int bm) |
| 196 | { |
| 197 | struct src_rsc_ctrl_blk *ctl = blk; |
| 198 | |
| 199 | set_field(&ctl->ctl, SRCCTL_BM, bm); |
| 200 | ctl->dirty.bf.ctl = 1; |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static int src_set_rsr(void *blk, unsigned int rsr) |
| 205 | { |
| 206 | struct src_rsc_ctrl_blk *ctl = blk; |
| 207 | |
| 208 | set_field(&ctl->ctl, SRCCTL_RSR, rsr); |
| 209 | ctl->dirty.bf.ctl = 1; |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static int src_set_sf(void *blk, unsigned int sf) |
| 214 | { |
| 215 | struct src_rsc_ctrl_blk *ctl = blk; |
| 216 | |
| 217 | set_field(&ctl->ctl, SRCCTL_SF, sf); |
| 218 | ctl->dirty.bf.ctl = 1; |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static int src_set_wr(void *blk, unsigned int wr) |
| 223 | { |
| 224 | struct src_rsc_ctrl_blk *ctl = blk; |
| 225 | |
| 226 | set_field(&ctl->ctl, SRCCTL_WR, wr); |
| 227 | ctl->dirty.bf.ctl = 1; |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int src_set_pm(void *blk, unsigned int pm) |
| 232 | { |
| 233 | struct src_rsc_ctrl_blk *ctl = blk; |
| 234 | |
| 235 | set_field(&ctl->ctl, SRCCTL_PM, pm); |
| 236 | ctl->dirty.bf.ctl = 1; |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static int src_set_rom(void *blk, unsigned int rom) |
| 241 | { |
| 242 | struct src_rsc_ctrl_blk *ctl = blk; |
| 243 | |
| 244 | set_field(&ctl->ctl, SRCCTL_ROM, rom); |
| 245 | ctl->dirty.bf.ctl = 1; |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static int src_set_vo(void *blk, unsigned int vo) |
| 250 | { |
| 251 | struct src_rsc_ctrl_blk *ctl = blk; |
| 252 | |
| 253 | set_field(&ctl->ctl, SRCCTL_VO, vo); |
| 254 | ctl->dirty.bf.ctl = 1; |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static int src_set_st(void *blk, unsigned int st) |
| 259 | { |
| 260 | struct src_rsc_ctrl_blk *ctl = blk; |
| 261 | |
| 262 | set_field(&ctl->ctl, SRCCTL_ST, st); |
| 263 | ctl->dirty.bf.ctl = 1; |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int src_set_ie(void *blk, unsigned int ie) |
| 268 | { |
| 269 | struct src_rsc_ctrl_blk *ctl = blk; |
| 270 | |
| 271 | set_field(&ctl->ctl, SRCCTL_IE, ie); |
| 272 | ctl->dirty.bf.ctl = 1; |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static int src_set_ilsz(void *blk, unsigned int ilsz) |
| 277 | { |
| 278 | struct src_rsc_ctrl_blk *ctl = blk; |
| 279 | |
| 280 | set_field(&ctl->ctl, SRCCTL_ILSZ, ilsz); |
| 281 | ctl->dirty.bf.ctl = 1; |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int src_set_bp(void *blk, unsigned int bp) |
| 286 | { |
| 287 | struct src_rsc_ctrl_blk *ctl = blk; |
| 288 | |
| 289 | set_field(&ctl->ctl, SRCCTL_BP, bp); |
| 290 | ctl->dirty.bf.ctl = 1; |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int src_set_cisz(void *blk, unsigned int cisz) |
| 295 | { |
| 296 | struct src_rsc_ctrl_blk *ctl = blk; |
| 297 | |
| 298 | set_field(&ctl->ccr, SRCCCR_CISZ, cisz); |
| 299 | ctl->dirty.bf.ccr = 1; |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | static int src_set_ca(void *blk, unsigned int ca) |
| 304 | { |
| 305 | struct src_rsc_ctrl_blk *ctl = blk; |
| 306 | |
| 307 | set_field(&ctl->ca, SRCCA_CA, ca); |
| 308 | ctl->dirty.bf.ca = 1; |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static int src_set_sa(void *blk, unsigned int sa) |
| 313 | { |
| 314 | struct src_rsc_ctrl_blk *ctl = blk; |
| 315 | |
| 316 | set_field(&ctl->sa, SRCSA_SA, sa); |
| 317 | ctl->dirty.bf.sa = 1; |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static int src_set_la(void *blk, unsigned int la) |
| 322 | { |
| 323 | struct src_rsc_ctrl_blk *ctl = blk; |
| 324 | |
| 325 | set_field(&ctl->la, SRCLA_LA, la); |
| 326 | ctl->dirty.bf.la = 1; |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static int src_set_pitch(void *blk, unsigned int pitch) |
| 331 | { |
| 332 | struct src_rsc_ctrl_blk *ctl = blk; |
| 333 | |
| 334 | set_field(&ctl->mpr, MPRLH_PITCH, pitch); |
| 335 | ctl->dirty.bf.mpr = 1; |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int src_set_clear_zbufs(void *blk, unsigned int clear) |
| 340 | { |
| 341 | ((struct src_rsc_ctrl_blk *)blk)->dirty.bf.czbfs = (clear ? 1 : 0); |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | static int src_set_dirty(void *blk, unsigned int flags) |
| 346 | { |
| 347 | ((struct src_rsc_ctrl_blk *)blk)->dirty.data = (flags & 0xffff); |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | static int src_set_dirty_all(void *blk) |
| 352 | { |
| 353 | ((struct src_rsc_ctrl_blk *)blk)->dirty.data = ~(0x0); |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | #define AR_SLOT_SIZE 4096 |
| 358 | #define AR_SLOT_BLOCK_SIZE 16 |
| 359 | #define AR_PTS_PITCH 6 |
| 360 | #define AR_PARAM_SRC_OFFSET 0x60 |
| 361 | |
| 362 | static unsigned int src_param_pitch_mixer(unsigned int src_idx) |
| 363 | { |
| 364 | return ((src_idx << 4) + AR_PTS_PITCH + AR_SLOT_SIZE |
| 365 | - AR_PARAM_SRC_OFFSET) % AR_SLOT_SIZE; |
| 366 | |
| 367 | } |
| 368 | |
| 369 | static int src_commit_write(struct hw *hw, unsigned int idx, void *blk) |
| 370 | { |
| 371 | struct src_rsc_ctrl_blk *ctl = blk; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 372 | int i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 373 | |
| 374 | if (ctl->dirty.bf.czbfs) { |
| 375 | /* Clear Z-Buffer registers */ |
| 376 | for (i = 0; i < 8; i++) |
| 377 | hw_write_20kx(hw, SRC_UPZ+idx*0x100+i*0x4, 0); |
| 378 | |
| 379 | for (i = 0; i < 4; i++) |
| 380 | hw_write_20kx(hw, SRC_DN0Z+idx*0x100+i*0x4, 0); |
| 381 | |
| 382 | for (i = 0; i < 8; i++) |
| 383 | hw_write_20kx(hw, SRC_DN1Z+idx*0x100+i*0x4, 0); |
| 384 | |
| 385 | ctl->dirty.bf.czbfs = 0; |
| 386 | } |
| 387 | if (ctl->dirty.bf.mpr) { |
| 388 | /* Take the parameter mixer resource in the same group as that |
| 389 | * the idx src is in for simplicity. Unlike src, all conjugate |
| 390 | * parameter mixer resources must be programmed for |
| 391 | * corresponding conjugate src resources. */ |
| 392 | unsigned int pm_idx = src_param_pitch_mixer(idx); |
| 393 | hw_write_20kx(hw, MIXER_PRING_LO_HI+4*pm_idx, ctl->mpr); |
| 394 | hw_write_20kx(hw, MIXER_PMOPLO+8*pm_idx, 0x3); |
| 395 | hw_write_20kx(hw, MIXER_PMOPHI+8*pm_idx, 0x0); |
| 396 | ctl->dirty.bf.mpr = 0; |
| 397 | } |
| 398 | if (ctl->dirty.bf.sa) { |
| 399 | hw_write_20kx(hw, SRC_SA+idx*0x100, ctl->sa); |
| 400 | ctl->dirty.bf.sa = 0; |
| 401 | } |
| 402 | if (ctl->dirty.bf.la) { |
| 403 | hw_write_20kx(hw, SRC_LA+idx*0x100, ctl->la); |
| 404 | ctl->dirty.bf.la = 0; |
| 405 | } |
| 406 | if (ctl->dirty.bf.ca) { |
| 407 | hw_write_20kx(hw, SRC_CA+idx*0x100, ctl->ca); |
| 408 | ctl->dirty.bf.ca = 0; |
| 409 | } |
| 410 | |
| 411 | /* Write srccf register */ |
| 412 | hw_write_20kx(hw, SRC_CF+idx*0x100, 0x0); |
| 413 | |
| 414 | if (ctl->dirty.bf.ccr) { |
| 415 | hw_write_20kx(hw, SRC_CCR+idx*0x100, ctl->ccr); |
| 416 | ctl->dirty.bf.ccr = 0; |
| 417 | } |
| 418 | if (ctl->dirty.bf.ctl) { |
| 419 | hw_write_20kx(hw, SRC_CTL+idx*0x100, ctl->ctl); |
| 420 | ctl->dirty.bf.ctl = 0; |
| 421 | } |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | static int src_get_ca(struct hw *hw, unsigned int idx, void *blk) |
| 427 | { |
| 428 | struct src_rsc_ctrl_blk *ctl = blk; |
| 429 | |
| 430 | ctl->ca = hw_read_20kx(hw, SRC_CA+idx*0x100); |
| 431 | ctl->dirty.bf.ca = 0; |
| 432 | |
| 433 | return get_field(ctl->ca, SRCCA_CA); |
| 434 | } |
| 435 | |
| 436 | static unsigned int src_get_dirty(void *blk) |
| 437 | { |
| 438 | return ((struct src_rsc_ctrl_blk *)blk)->dirty.data; |
| 439 | } |
| 440 | |
| 441 | static unsigned int src_dirty_conj_mask(void) |
| 442 | { |
| 443 | return 0x20; |
| 444 | } |
| 445 | |
| 446 | static int src_mgr_enbs_src(void *blk, unsigned int idx) |
| 447 | { |
| 448 | ((struct src_mgr_ctrl_blk *)blk)->enbsa |= (0x1 << ((idx%128)/4)); |
| 449 | ((struct src_mgr_ctrl_blk *)blk)->dirty.bf.enbsa = 1; |
| 450 | ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32)); |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static int src_mgr_enb_src(void *blk, unsigned int idx) |
| 455 | { |
| 456 | ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] |= (0x1 << (idx%32)); |
| 457 | ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32)); |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | static int src_mgr_dsb_src(void *blk, unsigned int idx) |
| 462 | { |
| 463 | ((struct src_mgr_ctrl_blk *)blk)->enb[idx/32] &= ~(0x1 << (idx%32)); |
| 464 | ((struct src_mgr_ctrl_blk *)blk)->dirty.data |= (0x1 << (idx/32)); |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static int src_mgr_commit_write(struct hw *hw, void *blk) |
| 469 | { |
| 470 | struct src_mgr_ctrl_blk *ctl = blk; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 471 | int i; |
| 472 | unsigned int ret; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 473 | |
| 474 | if (ctl->dirty.bf.enbsa) { |
| 475 | do { |
| 476 | ret = hw_read_20kx(hw, SRC_ENBSTAT); |
| 477 | } while (ret & 0x1); |
| 478 | hw_write_20kx(hw, SRC_ENBSA, ctl->enbsa); |
| 479 | ctl->dirty.bf.enbsa = 0; |
| 480 | } |
| 481 | for (i = 0; i < 8; i++) { |
| 482 | if ((ctl->dirty.data & (0x1 << i))) { |
| 483 | hw_write_20kx(hw, SRC_ENB+(i*0x100), ctl->enb[i]); |
| 484 | ctl->dirty.data &= ~(0x1 << i); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | static int src_mgr_get_ctrl_blk(void **rblk) |
| 492 | { |
| 493 | struct src_mgr_ctrl_blk *blk; |
| 494 | |
| 495 | *rblk = NULL; |
| 496 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 497 | if (!blk) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 498 | return -ENOMEM; |
| 499 | |
| 500 | *rblk = blk; |
| 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | static int src_mgr_put_ctrl_blk(void *blk) |
| 506 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 507 | kfree(blk); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static int srcimp_mgr_get_ctrl_blk(void **rblk) |
| 513 | { |
| 514 | struct srcimp_mgr_ctrl_blk *blk; |
| 515 | |
| 516 | *rblk = NULL; |
| 517 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 518 | if (!blk) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 519 | return -ENOMEM; |
| 520 | |
| 521 | *rblk = blk; |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | static int srcimp_mgr_put_ctrl_blk(void *blk) |
| 527 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 528 | kfree(blk); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static int srcimp_mgr_set_imaparc(void *blk, unsigned int slot) |
| 534 | { |
| 535 | struct srcimp_mgr_ctrl_blk *ctl = blk; |
| 536 | |
| 537 | set_field(&ctl->srcimap.srcaim, SRCAIM_ARC, slot); |
| 538 | ctl->dirty.bf.srcimap = 1; |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static int srcimp_mgr_set_imapuser(void *blk, unsigned int user) |
| 543 | { |
| 544 | struct srcimp_mgr_ctrl_blk *ctl = blk; |
| 545 | |
| 546 | set_field(&ctl->srcimap.srcaim, SRCAIM_SRC, user); |
| 547 | ctl->dirty.bf.srcimap = 1; |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static int srcimp_mgr_set_imapnxt(void *blk, unsigned int next) |
| 552 | { |
| 553 | struct srcimp_mgr_ctrl_blk *ctl = blk; |
| 554 | |
| 555 | set_field(&ctl->srcimap.srcaim, SRCAIM_NXT, next); |
| 556 | ctl->dirty.bf.srcimap = 1; |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | static int srcimp_mgr_set_imapaddr(void *blk, unsigned int addr) |
| 561 | { |
| 562 | ((struct srcimp_mgr_ctrl_blk *)blk)->srcimap.idx = addr; |
| 563 | ((struct srcimp_mgr_ctrl_blk *)blk)->dirty.bf.srcimap = 1; |
| 564 | return 0; |
| 565 | } |
| 566 | |
| 567 | static int srcimp_mgr_commit_write(struct hw *hw, void *blk) |
| 568 | { |
| 569 | struct srcimp_mgr_ctrl_blk *ctl = blk; |
| 570 | |
| 571 | if (ctl->dirty.bf.srcimap) { |
| 572 | hw_write_20kx(hw, SRC_IMAP+ctl->srcimap.idx*0x100, |
| 573 | ctl->srcimap.srcaim); |
| 574 | ctl->dirty.bf.srcimap = 0; |
| 575 | } |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * AMIXER control block definitions. |
| 582 | */ |
| 583 | |
| 584 | #define AMOPLO_M 0x00000003 |
| 585 | #define AMOPLO_IV 0x00000004 |
| 586 | #define AMOPLO_X 0x0003FFF0 |
| 587 | #define AMOPLO_Y 0xFFFC0000 |
| 588 | |
| 589 | #define AMOPHI_SADR 0x000000FF |
| 590 | #define AMOPHI_SE 0x80000000 |
| 591 | |
| 592 | /* AMIXER resource register dirty flags */ |
| 593 | union amixer_dirty { |
| 594 | struct { |
| 595 | u16 amoplo:1; |
| 596 | u16 amophi:1; |
| 597 | u16 rsv:14; |
| 598 | } bf; |
| 599 | u16 data; |
| 600 | }; |
| 601 | |
| 602 | /* AMIXER resource control block */ |
| 603 | struct amixer_rsc_ctrl_blk { |
| 604 | unsigned int amoplo; |
| 605 | unsigned int amophi; |
| 606 | union amixer_dirty dirty; |
| 607 | }; |
| 608 | |
| 609 | static int amixer_set_mode(void *blk, unsigned int mode) |
| 610 | { |
| 611 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 612 | |
| 613 | set_field(&ctl->amoplo, AMOPLO_M, mode); |
| 614 | ctl->dirty.bf.amoplo = 1; |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | static int amixer_set_iv(void *blk, unsigned int iv) |
| 619 | { |
| 620 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 621 | |
| 622 | set_field(&ctl->amoplo, AMOPLO_IV, iv); |
| 623 | ctl->dirty.bf.amoplo = 1; |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | static int amixer_set_x(void *blk, unsigned int x) |
| 628 | { |
| 629 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 630 | |
| 631 | set_field(&ctl->amoplo, AMOPLO_X, x); |
| 632 | ctl->dirty.bf.amoplo = 1; |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int amixer_set_y(void *blk, unsigned int y) |
| 637 | { |
| 638 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 639 | |
| 640 | set_field(&ctl->amoplo, AMOPLO_Y, y); |
| 641 | ctl->dirty.bf.amoplo = 1; |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | static int amixer_set_sadr(void *blk, unsigned int sadr) |
| 646 | { |
| 647 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 648 | |
| 649 | set_field(&ctl->amophi, AMOPHI_SADR, sadr); |
| 650 | ctl->dirty.bf.amophi = 1; |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static int amixer_set_se(void *blk, unsigned int se) |
| 655 | { |
| 656 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 657 | |
| 658 | set_field(&ctl->amophi, AMOPHI_SE, se); |
| 659 | ctl->dirty.bf.amophi = 1; |
| 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | static int amixer_set_dirty(void *blk, unsigned int flags) |
| 664 | { |
| 665 | ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data = (flags & 0xffff); |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | static int amixer_set_dirty_all(void *blk) |
| 670 | { |
| 671 | ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data = ~(0x0); |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static int amixer_commit_write(struct hw *hw, unsigned int idx, void *blk) |
| 676 | { |
| 677 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 678 | |
| 679 | if (ctl->dirty.bf.amoplo || ctl->dirty.bf.amophi) { |
| 680 | hw_write_20kx(hw, MIXER_AMOPLO+idx*8, ctl->amoplo); |
| 681 | ctl->dirty.bf.amoplo = 0; |
| 682 | hw_write_20kx(hw, MIXER_AMOPHI+idx*8, ctl->amophi); |
| 683 | ctl->dirty.bf.amophi = 0; |
| 684 | } |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | static int amixer_get_y(void *blk) |
| 690 | { |
| 691 | struct amixer_rsc_ctrl_blk *ctl = blk; |
| 692 | |
| 693 | return get_field(ctl->amoplo, AMOPLO_Y); |
| 694 | } |
| 695 | |
| 696 | static unsigned int amixer_get_dirty(void *blk) |
| 697 | { |
| 698 | return ((struct amixer_rsc_ctrl_blk *)blk)->dirty.data; |
| 699 | } |
| 700 | |
| 701 | static int amixer_rsc_get_ctrl_blk(void **rblk) |
| 702 | { |
| 703 | struct amixer_rsc_ctrl_blk *blk; |
| 704 | |
| 705 | *rblk = NULL; |
| 706 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 707 | if (!blk) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 708 | return -ENOMEM; |
| 709 | |
| 710 | *rblk = blk; |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | static int amixer_rsc_put_ctrl_blk(void *blk) |
| 716 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 717 | kfree(blk); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 718 | |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | static int amixer_mgr_get_ctrl_blk(void **rblk) |
| 723 | { |
| 724 | *rblk = NULL; |
| 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static int amixer_mgr_put_ctrl_blk(void *blk) |
| 730 | { |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | /* |
| 735 | * DAIO control block definitions. |
| 736 | */ |
| 737 | |
| 738 | /* Receiver Sample Rate Tracker Control register */ |
| 739 | #define SRTCTL_SRCO 0x000000FF |
| 740 | #define SRTCTL_SRCM 0x0000FF00 |
| 741 | #define SRTCTL_RSR 0x00030000 |
| 742 | #define SRTCTL_DRAT 0x00300000 |
| 743 | #define SRTCTL_EC 0x01000000 |
| 744 | #define SRTCTL_ET 0x10000000 |
| 745 | |
| 746 | /* DAIO Receiver register dirty flags */ |
| 747 | union dai_dirty { |
| 748 | struct { |
| 749 | u16 srt:1; |
| 750 | u16 rsv:15; |
| 751 | } bf; |
| 752 | u16 data; |
| 753 | }; |
| 754 | |
| 755 | /* DAIO Receiver control block */ |
| 756 | struct dai_ctrl_blk { |
| 757 | unsigned int srt; |
| 758 | union dai_dirty dirty; |
| 759 | }; |
| 760 | |
| 761 | /* Audio Input Mapper RAM */ |
| 762 | #define AIM_ARC 0x00000FFF |
| 763 | #define AIM_NXT 0x007F0000 |
| 764 | |
| 765 | struct daoimap { |
| 766 | unsigned int aim; |
| 767 | unsigned int idx; |
| 768 | }; |
| 769 | |
| 770 | /* Audio Transmitter Control and Status register */ |
| 771 | #define ATXCTL_EN 0x00000001 |
| 772 | #define ATXCTL_MODE 0x00000010 |
| 773 | #define ATXCTL_CD 0x00000020 |
| 774 | #define ATXCTL_RAW 0x00000100 |
| 775 | #define ATXCTL_MT 0x00000200 |
| 776 | #define ATXCTL_NUC 0x00003000 |
| 777 | #define ATXCTL_BEN 0x00010000 |
| 778 | #define ATXCTL_BMUX 0x00700000 |
| 779 | #define ATXCTL_B24 0x01000000 |
| 780 | #define ATXCTL_CPF 0x02000000 |
| 781 | #define ATXCTL_RIV 0x10000000 |
| 782 | #define ATXCTL_LIV 0x20000000 |
| 783 | #define ATXCTL_RSAT 0x40000000 |
| 784 | #define ATXCTL_LSAT 0x80000000 |
| 785 | |
| 786 | /* XDIF Transmitter register dirty flags */ |
| 787 | union dao_dirty { |
| 788 | struct { |
| 789 | u16 atxcsl:1; |
| 790 | u16 rsv:15; |
| 791 | } bf; |
| 792 | u16 data; |
| 793 | }; |
| 794 | |
| 795 | /* XDIF Transmitter control block */ |
| 796 | struct dao_ctrl_blk { |
| 797 | /* XDIF Transmitter Channel Status Low Register */ |
| 798 | unsigned int atxcsl; |
| 799 | union dao_dirty dirty; |
| 800 | }; |
| 801 | |
| 802 | /* Audio Receiver Control register */ |
| 803 | #define ARXCTL_EN 0x00000001 |
| 804 | |
| 805 | /* DAIO manager register dirty flags */ |
| 806 | union daio_mgr_dirty { |
| 807 | struct { |
| 808 | u32 atxctl:8; |
| 809 | u32 arxctl:8; |
| 810 | u32 daoimap:1; |
| 811 | u32 rsv:15; |
| 812 | } bf; |
| 813 | u32 data; |
| 814 | }; |
| 815 | |
| 816 | /* DAIO manager control block */ |
| 817 | struct daio_mgr_ctrl_blk { |
| 818 | struct daoimap daoimap; |
| 819 | unsigned int txctl[8]; |
| 820 | unsigned int rxctl[8]; |
| 821 | union daio_mgr_dirty dirty; |
| 822 | }; |
| 823 | |
| 824 | static int dai_srt_set_srco(void *blk, unsigned int src) |
| 825 | { |
| 826 | struct dai_ctrl_blk *ctl = blk; |
| 827 | |
| 828 | set_field(&ctl->srt, SRTCTL_SRCO, src); |
| 829 | ctl->dirty.bf.srt = 1; |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | static int dai_srt_set_srcm(void *blk, unsigned int src) |
| 834 | { |
| 835 | struct dai_ctrl_blk *ctl = blk; |
| 836 | |
| 837 | set_field(&ctl->srt, SRTCTL_SRCM, src); |
| 838 | ctl->dirty.bf.srt = 1; |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | static int dai_srt_set_rsr(void *blk, unsigned int rsr) |
| 843 | { |
| 844 | struct dai_ctrl_blk *ctl = blk; |
| 845 | |
| 846 | set_field(&ctl->srt, SRTCTL_RSR, rsr); |
| 847 | ctl->dirty.bf.srt = 1; |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | static int dai_srt_set_drat(void *blk, unsigned int drat) |
| 852 | { |
| 853 | struct dai_ctrl_blk *ctl = blk; |
| 854 | |
| 855 | set_field(&ctl->srt, SRTCTL_DRAT, drat); |
| 856 | ctl->dirty.bf.srt = 1; |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static int dai_srt_set_ec(void *blk, unsigned int ec) |
| 861 | { |
| 862 | struct dai_ctrl_blk *ctl = blk; |
| 863 | |
| 864 | set_field(&ctl->srt, SRTCTL_EC, ec ? 1 : 0); |
| 865 | ctl->dirty.bf.srt = 1; |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | static int dai_srt_set_et(void *blk, unsigned int et) |
| 870 | { |
| 871 | struct dai_ctrl_blk *ctl = blk; |
| 872 | |
| 873 | set_field(&ctl->srt, SRTCTL_ET, et ? 1 : 0); |
| 874 | ctl->dirty.bf.srt = 1; |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | static int dai_commit_write(struct hw *hw, unsigned int idx, void *blk) |
| 879 | { |
| 880 | struct dai_ctrl_blk *ctl = blk; |
| 881 | |
| 882 | if (ctl->dirty.bf.srt) { |
| 883 | hw_write_20kx(hw, AUDIO_IO_RX_SRT_CTL+0x40*idx, ctl->srt); |
| 884 | ctl->dirty.bf.srt = 0; |
| 885 | } |
| 886 | |
| 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | static int dai_get_ctrl_blk(void **rblk) |
| 891 | { |
| 892 | struct dai_ctrl_blk *blk; |
| 893 | |
| 894 | *rblk = NULL; |
| 895 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 896 | if (!blk) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 897 | return -ENOMEM; |
| 898 | |
| 899 | *rblk = blk; |
| 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | static int dai_put_ctrl_blk(void *blk) |
| 905 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 906 | kfree(blk); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static int dao_set_spos(void *blk, unsigned int spos) |
| 912 | { |
| 913 | ((struct dao_ctrl_blk *)blk)->atxcsl = spos; |
| 914 | ((struct dao_ctrl_blk *)blk)->dirty.bf.atxcsl = 1; |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | static int dao_commit_write(struct hw *hw, unsigned int idx, void *blk) |
| 919 | { |
| 920 | struct dao_ctrl_blk *ctl = blk; |
| 921 | |
| 922 | if (ctl->dirty.bf.atxcsl) { |
| 923 | if (idx < 4) { |
| 924 | /* S/PDIF SPOSx */ |
| 925 | hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_L+0x40*idx, |
| 926 | ctl->atxcsl); |
| 927 | } |
| 928 | ctl->dirty.bf.atxcsl = 0; |
| 929 | } |
| 930 | |
| 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | static int dao_get_spos(void *blk, unsigned int *spos) |
| 935 | { |
| 936 | *spos = ((struct dao_ctrl_blk *)blk)->atxcsl; |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | static int dao_get_ctrl_blk(void **rblk) |
| 941 | { |
| 942 | struct dao_ctrl_blk *blk; |
| 943 | |
| 944 | *rblk = NULL; |
| 945 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 946 | if (!blk) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 947 | return -ENOMEM; |
| 948 | |
| 949 | *rblk = blk; |
| 950 | |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | static int dao_put_ctrl_blk(void *blk) |
| 955 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 956 | kfree(blk); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | static int daio_mgr_enb_dai(void *blk, unsigned int idx) |
| 962 | { |
| 963 | struct daio_mgr_ctrl_blk *ctl = blk; |
| 964 | |
| 965 | set_field(&ctl->rxctl[idx], ARXCTL_EN, 1); |
| 966 | ctl->dirty.bf.arxctl |= (0x1 << idx); |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static int daio_mgr_dsb_dai(void *blk, unsigned int idx) |
| 971 | { |
| 972 | struct daio_mgr_ctrl_blk *ctl = blk; |
| 973 | |
| 974 | set_field(&ctl->rxctl[idx], ARXCTL_EN, 0); |
| 975 | |
| 976 | ctl->dirty.bf.arxctl |= (0x1 << idx); |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | static int daio_mgr_enb_dao(void *blk, unsigned int idx) |
| 981 | { |
| 982 | struct daio_mgr_ctrl_blk *ctl = blk; |
| 983 | |
| 984 | set_field(&ctl->txctl[idx], ATXCTL_EN, 1); |
| 985 | ctl->dirty.bf.atxctl |= (0x1 << idx); |
| 986 | return 0; |
| 987 | } |
| 988 | |
| 989 | static int daio_mgr_dsb_dao(void *blk, unsigned int idx) |
| 990 | { |
| 991 | struct daio_mgr_ctrl_blk *ctl = blk; |
| 992 | |
| 993 | set_field(&ctl->txctl[idx], ATXCTL_EN, 0); |
| 994 | ctl->dirty.bf.atxctl |= (0x1 << idx); |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | static int daio_mgr_dao_init(void *blk, unsigned int idx, unsigned int conf) |
| 999 | { |
| 1000 | struct daio_mgr_ctrl_blk *ctl = blk; |
| 1001 | |
| 1002 | if (idx < 4) { |
| 1003 | /* S/PDIF output */ |
| 1004 | switch ((conf & 0x7)) { |
| 1005 | case 1: |
| 1006 | set_field(&ctl->txctl[idx], ATXCTL_NUC, 0); |
| 1007 | break; |
| 1008 | case 2: |
| 1009 | set_field(&ctl->txctl[idx], ATXCTL_NUC, 1); |
| 1010 | break; |
| 1011 | case 4: |
| 1012 | set_field(&ctl->txctl[idx], ATXCTL_NUC, 2); |
| 1013 | break; |
| 1014 | case 8: |
| 1015 | set_field(&ctl->txctl[idx], ATXCTL_NUC, 3); |
| 1016 | break; |
| 1017 | default: |
| 1018 | break; |
| 1019 | } |
| 1020 | /* CDIF */ |
| 1021 | set_field(&ctl->txctl[idx], ATXCTL_CD, (!(conf & 0x7))); |
| 1022 | /* Non-audio */ |
| 1023 | set_field(&ctl->txctl[idx], ATXCTL_LIV, (conf >> 4) & 0x1); |
| 1024 | /* Non-audio */ |
| 1025 | set_field(&ctl->txctl[idx], ATXCTL_RIV, (conf >> 4) & 0x1); |
| 1026 | set_field(&ctl->txctl[idx], ATXCTL_RAW, |
| 1027 | ((conf >> 3) & 0x1) ? 0 : 0); |
| 1028 | ctl->dirty.bf.atxctl |= (0x1 << idx); |
| 1029 | } else { |
| 1030 | /* I2S output */ |
| 1031 | /*idx %= 4; */ |
| 1032 | } |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
| 1036 | static int daio_mgr_set_imaparc(void *blk, unsigned int slot) |
| 1037 | { |
| 1038 | struct daio_mgr_ctrl_blk *ctl = blk; |
| 1039 | |
| 1040 | set_field(&ctl->daoimap.aim, AIM_ARC, slot); |
| 1041 | ctl->dirty.bf.daoimap = 1; |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | static int daio_mgr_set_imapnxt(void *blk, unsigned int next) |
| 1046 | { |
| 1047 | struct daio_mgr_ctrl_blk *ctl = blk; |
| 1048 | |
| 1049 | set_field(&ctl->daoimap.aim, AIM_NXT, next); |
| 1050 | ctl->dirty.bf.daoimap = 1; |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | static int daio_mgr_set_imapaddr(void *blk, unsigned int addr) |
| 1055 | { |
| 1056 | ((struct daio_mgr_ctrl_blk *)blk)->daoimap.idx = addr; |
| 1057 | ((struct daio_mgr_ctrl_blk *)blk)->dirty.bf.daoimap = 1; |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | static int daio_mgr_commit_write(struct hw *hw, void *blk) |
| 1062 | { |
| 1063 | struct daio_mgr_ctrl_blk *ctl = blk; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1064 | unsigned int data; |
| 1065 | int i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1066 | |
| 1067 | for (i = 0; i < 8; i++) { |
| 1068 | if ((ctl->dirty.bf.atxctl & (0x1 << i))) { |
| 1069 | data = ctl->txctl[i]; |
| 1070 | hw_write_20kx(hw, (AUDIO_IO_TX_CTL+(0x40*i)), data); |
| 1071 | ctl->dirty.bf.atxctl &= ~(0x1 << i); |
| 1072 | mdelay(1); |
| 1073 | } |
| 1074 | if ((ctl->dirty.bf.arxctl & (0x1 << i))) { |
| 1075 | data = ctl->rxctl[i]; |
| 1076 | hw_write_20kx(hw, (AUDIO_IO_RX_CTL+(0x40*i)), data); |
| 1077 | ctl->dirty.bf.arxctl &= ~(0x1 << i); |
| 1078 | mdelay(1); |
| 1079 | } |
| 1080 | } |
| 1081 | if (ctl->dirty.bf.daoimap) { |
| 1082 | hw_write_20kx(hw, AUDIO_IO_AIM+ctl->daoimap.idx*4, |
| 1083 | ctl->daoimap.aim); |
| 1084 | ctl->dirty.bf.daoimap = 0; |
| 1085 | } |
| 1086 | |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int daio_mgr_get_ctrl_blk(struct hw *hw, void **rblk) |
| 1091 | { |
| 1092 | struct daio_mgr_ctrl_blk *blk; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1093 | int i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1094 | |
| 1095 | *rblk = NULL; |
| 1096 | blk = kzalloc(sizeof(*blk), GFP_KERNEL); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 1097 | if (!blk) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1098 | return -ENOMEM; |
| 1099 | |
| 1100 | for (i = 0; i < 8; i++) { |
| 1101 | blk->txctl[i] = hw_read_20kx(hw, AUDIO_IO_TX_CTL+(0x40*i)); |
| 1102 | blk->rxctl[i] = hw_read_20kx(hw, AUDIO_IO_RX_CTL+(0x40*i)); |
| 1103 | } |
| 1104 | |
| 1105 | *rblk = blk; |
| 1106 | |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | static int daio_mgr_put_ctrl_blk(void *blk) |
| 1111 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1112 | kfree(blk); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
Takashi Iwai | bc5304b | 2009-07-20 13:41:35 +0200 | [diff] [blame] | 1117 | /* Timer interrupt */ |
| 1118 | static int set_timer_irq(struct hw *hw, int enable) |
| 1119 | { |
| 1120 | hw_write_20kx(hw, GIE, enable ? IT_INT : 0); |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | static int set_timer_tick(struct hw *hw, unsigned int ticks) |
| 1125 | { |
| 1126 | if (ticks) |
| 1127 | ticks |= TIMR_IE | TIMR_IP; |
| 1128 | hw_write_20kx(hw, TIMR, ticks); |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | static unsigned int get_wc(struct hw *hw) |
| 1133 | { |
| 1134 | return hw_read_20kx(hw, WC); |
| 1135 | } |
| 1136 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1137 | /* Card hardware initialization block */ |
| 1138 | struct dac_conf { |
| 1139 | unsigned int msr; /* master sample rate in rsrs */ |
| 1140 | }; |
| 1141 | |
| 1142 | struct adc_conf { |
| 1143 | unsigned int msr; /* master sample rate in rsrs */ |
| 1144 | unsigned char input; /* the input source of ADC */ |
| 1145 | unsigned char mic20db; /* boost mic by 20db if input is microphone */ |
| 1146 | }; |
| 1147 | |
| 1148 | struct daio_conf { |
| 1149 | unsigned int msr; /* master sample rate in rsrs */ |
| 1150 | }; |
| 1151 | |
| 1152 | struct trn_conf { |
| 1153 | unsigned long vm_pgt_phys; |
| 1154 | }; |
| 1155 | |
| 1156 | static int hw_daio_init(struct hw *hw, const struct daio_conf *info) |
| 1157 | { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1158 | u32 data; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1159 | int i; |
| 1160 | |
| 1161 | /* Program I2S with proper sample rate and enable the correct I2S |
| 1162 | * channel. ED(0/8/16/24): Enable all I2S/I2X master clock output */ |
| 1163 | if (1 == info->msr) { |
| 1164 | hw_write_20kx(hw, AUDIO_IO_MCLK, 0x01010101); |
| 1165 | hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x01010101); |
| 1166 | hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0); |
| 1167 | } else if (2 == info->msr) { |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1168 | if (hw->model != CTSB1270) { |
| 1169 | hw_write_20kx(hw, AUDIO_IO_MCLK, 0x11111111); |
| 1170 | } else { |
| 1171 | /* PCM4220 on Titanium HD is different. */ |
| 1172 | hw_write_20kx(hw, AUDIO_IO_MCLK, 0x11011111); |
| 1173 | } |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1174 | /* Specify all playing 96khz |
| 1175 | * EA [0] - Enabled |
| 1176 | * RTA [4:5] - 96kHz |
| 1177 | * EB [8] - Enabled |
| 1178 | * RTB [12:13] - 96kHz |
| 1179 | * EC [16] - Enabled |
| 1180 | * RTC [20:21] - 96kHz |
| 1181 | * ED [24] - Enabled |
| 1182 | * RTD [28:29] - 96kHz */ |
| 1183 | hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x11111111); |
| 1184 | hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1185 | } else if ((4 == info->msr) && (hw->model == CTSB1270)) { |
| 1186 | hw_write_20kx(hw, AUDIO_IO_MCLK, 0x21011111); |
| 1187 | hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x21212121); |
| 1188 | hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1189 | } else { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1190 | printk(KERN_ALERT "ctxfi: ERROR!!! Invalid sampling rate!!!\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1191 | return -EINVAL; |
| 1192 | } |
| 1193 | |
| 1194 | for (i = 0; i < 8; i++) { |
| 1195 | if (i <= 3) { |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1196 | /* This comment looks wrong since loop is over 4 */ |
| 1197 | /* channels and emu20k2 supports 4 spdif IOs. */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1198 | /* 1st 3 channels are SPDIFs (SB0960) */ |
| 1199 | if (i == 3) |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1200 | data = 0x1001001; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1201 | else |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1202 | data = 0x1000001; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1203 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1204 | hw_write_20kx(hw, (AUDIO_IO_TX_CTL+(0x40*i)), data); |
| 1205 | hw_write_20kx(hw, (AUDIO_IO_RX_CTL+(0x40*i)), data); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1206 | |
| 1207 | /* Initialize the SPDIF Out Channel status registers. |
| 1208 | * The value specified here is based on the typical |
| 1209 | * values provided in the specification, namely: Clock |
| 1210 | * Accuracy of 1000ppm, Sample Rate of 48KHz, |
| 1211 | * unspecified source number, Generation status = 1, |
| 1212 | * Category code = 0x12 (Digital Signal Mixer), |
| 1213 | * Mode = 0, Emph = 0, Copy Permitted, AN = 0 |
| 1214 | * (indicating that we're transmitting digital audio, |
| 1215 | * and the Professional Use bit is 0. */ |
| 1216 | |
| 1217 | hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_L+(0x40*i), |
| 1218 | 0x02109204); /* Default to 48kHz */ |
| 1219 | |
| 1220 | hw_write_20kx(hw, AUDIO_IO_TX_CSTAT_H+(0x40*i), 0x0B); |
| 1221 | } else { |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1222 | /* Again, loop is over 4 channels not 5. */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1223 | /* Next 5 channels are I2S (SB0960) */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1224 | data = 0x11; |
| 1225 | hw_write_20kx(hw, AUDIO_IO_RX_CTL+(0x40*i), data); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1226 | if (2 == info->msr) { |
| 1227 | /* Four channels per sample period */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1228 | data |= 0x1000; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1229 | } else if (4 == info->msr) { |
| 1230 | /* FIXME: check this against the chip spec */ |
| 1231 | data |= 0x2000; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1232 | } |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1233 | hw_write_20kx(hw, AUDIO_IO_TX_CTL+(0x40*i), data); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | /* TRANSPORT operations */ |
| 1241 | static int hw_trn_init(struct hw *hw, const struct trn_conf *info) |
| 1242 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1243 | u32 vmctl, data; |
| 1244 | u32 ptp_phys_low, ptp_phys_high; |
| 1245 | int i; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1246 | |
| 1247 | /* Set up device page table */ |
| 1248 | if ((~0UL) == info->vm_pgt_phys) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1249 | printk(KERN_ALERT "ctxfi: " |
| 1250 | "Wrong device page table page address!!!\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1251 | return -1; |
| 1252 | } |
| 1253 | |
| 1254 | vmctl = 0x80000C0F; /* 32-bit, 4k-size page */ |
Takashi Iwai | cd391e2 | 2009-06-02 15:04:29 +0200 | [diff] [blame] | 1255 | ptp_phys_low = (u32)info->vm_pgt_phys; |
| 1256 | ptp_phys_high = upper_32_bits(info->vm_pgt_phys); |
| 1257 | if (sizeof(void *) == 8) /* 64bit address */ |
| 1258 | vmctl |= (3 << 8); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1259 | /* Write page table physical address to all PTPAL registers */ |
| 1260 | for (i = 0; i < 64; i++) { |
| 1261 | hw_write_20kx(hw, VMEM_PTPAL+(16*i), ptp_phys_low); |
| 1262 | hw_write_20kx(hw, VMEM_PTPAH+(16*i), ptp_phys_high); |
| 1263 | } |
| 1264 | /* Enable virtual memory transfer */ |
| 1265 | hw_write_20kx(hw, VMEM_CTL, vmctl); |
| 1266 | /* Enable transport bus master and queueing of request */ |
| 1267 | hw_write_20kx(hw, TRANSPORT_CTL, 0x03); |
| 1268 | hw_write_20kx(hw, TRANSPORT_INT, 0x200c01); |
| 1269 | /* Enable transport ring */ |
| 1270 | data = hw_read_20kx(hw, TRANSPORT_ENB); |
| 1271 | hw_write_20kx(hw, TRANSPORT_ENB, (data | 0x03)); |
| 1272 | |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | /* Card initialization */ |
| 1277 | #define GCTL_AIE 0x00000001 |
| 1278 | #define GCTL_UAA 0x00000002 |
| 1279 | #define GCTL_DPC 0x00000004 |
| 1280 | #define GCTL_DBP 0x00000008 |
| 1281 | #define GCTL_ABP 0x00000010 |
| 1282 | #define GCTL_TBP 0x00000020 |
| 1283 | #define GCTL_SBP 0x00000040 |
| 1284 | #define GCTL_FBP 0x00000080 |
| 1285 | #define GCTL_ME 0x00000100 |
| 1286 | #define GCTL_AID 0x00001000 |
| 1287 | |
| 1288 | #define PLLCTL_SRC 0x00000007 |
| 1289 | #define PLLCTL_SPE 0x00000008 |
| 1290 | #define PLLCTL_RD 0x000000F0 |
| 1291 | #define PLLCTL_FD 0x0001FF00 |
| 1292 | #define PLLCTL_OD 0x00060000 |
| 1293 | #define PLLCTL_B 0x00080000 |
| 1294 | #define PLLCTL_AS 0x00100000 |
| 1295 | #define PLLCTL_LF 0x03E00000 |
| 1296 | #define PLLCTL_SPS 0x1C000000 |
| 1297 | #define PLLCTL_AD 0x60000000 |
| 1298 | |
| 1299 | #define PLLSTAT_CCS 0x00000007 |
| 1300 | #define PLLSTAT_SPL 0x00000008 |
| 1301 | #define PLLSTAT_CRD 0x000000F0 |
| 1302 | #define PLLSTAT_CFD 0x0001FF00 |
| 1303 | #define PLLSTAT_SL 0x00020000 |
| 1304 | #define PLLSTAT_FAS 0x00040000 |
| 1305 | #define PLLSTAT_B 0x00080000 |
| 1306 | #define PLLSTAT_PD 0x00100000 |
| 1307 | #define PLLSTAT_OCA 0x00200000 |
| 1308 | #define PLLSTAT_NCA 0x00400000 |
| 1309 | |
| 1310 | static int hw_pll_init(struct hw *hw, unsigned int rsr) |
| 1311 | { |
| 1312 | unsigned int pllenb; |
| 1313 | unsigned int pllctl; |
| 1314 | unsigned int pllstat; |
| 1315 | int i; |
| 1316 | |
| 1317 | pllenb = 0xB; |
| 1318 | hw_write_20kx(hw, PLL_ENB, pllenb); |
| 1319 | pllctl = 0x20D00000; |
| 1320 | set_field(&pllctl, PLLCTL_FD, 16 - 4); |
| 1321 | hw_write_20kx(hw, PLL_CTL, pllctl); |
| 1322 | mdelay(40); |
| 1323 | pllctl = hw_read_20kx(hw, PLL_CTL); |
| 1324 | set_field(&pllctl, PLLCTL_B, 0); |
| 1325 | if (48000 == rsr) { |
| 1326 | set_field(&pllctl, PLLCTL_FD, 16 - 2); |
Przemyslaw Bruski | 19002fd | 2011-03-13 16:18:55 +0100 | [diff] [blame] | 1327 | set_field(&pllctl, PLLCTL_RD, 1 - 1); /* 3000*16/1 = 48000 */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1328 | } else { /* 44100 */ |
| 1329 | set_field(&pllctl, PLLCTL_FD, 147 - 2); |
Przemyslaw Bruski | 19002fd | 2011-03-13 16:18:55 +0100 | [diff] [blame] | 1330 | set_field(&pllctl, PLLCTL_RD, 10 - 1); /* 3000*147/10 = 44100 */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1331 | } |
| 1332 | hw_write_20kx(hw, PLL_CTL, pllctl); |
| 1333 | mdelay(40); |
| 1334 | for (i = 0; i < 1000; i++) { |
| 1335 | pllstat = hw_read_20kx(hw, PLL_STAT); |
| 1336 | if (get_field(pllstat, PLLSTAT_PD)) |
| 1337 | continue; |
| 1338 | |
| 1339 | if (get_field(pllstat, PLLSTAT_B) != |
| 1340 | get_field(pllctl, PLLCTL_B)) |
| 1341 | continue; |
| 1342 | |
| 1343 | if (get_field(pllstat, PLLSTAT_CCS) != |
| 1344 | get_field(pllctl, PLLCTL_SRC)) |
| 1345 | continue; |
| 1346 | |
| 1347 | if (get_field(pllstat, PLLSTAT_CRD) != |
| 1348 | get_field(pllctl, PLLCTL_RD)) |
| 1349 | continue; |
| 1350 | |
| 1351 | if (get_field(pllstat, PLLSTAT_CFD) != |
| 1352 | get_field(pllctl, PLLCTL_FD)) |
| 1353 | continue; |
| 1354 | |
| 1355 | break; |
| 1356 | } |
| 1357 | if (i >= 1000) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1358 | printk(KERN_ALERT "ctxfi: PLL initialization failed!!!\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1359 | return -EBUSY; |
| 1360 | } |
| 1361 | |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
| 1365 | static int hw_auto_init(struct hw *hw) |
| 1366 | { |
| 1367 | unsigned int gctl; |
| 1368 | int i; |
| 1369 | |
| 1370 | gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL); |
| 1371 | set_field(&gctl, GCTL_AIE, 0); |
| 1372 | hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl); |
| 1373 | set_field(&gctl, GCTL_AIE, 1); |
| 1374 | hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl); |
| 1375 | mdelay(10); |
| 1376 | for (i = 0; i < 400000; i++) { |
| 1377 | gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL); |
| 1378 | if (get_field(gctl, GCTL_AID)) |
| 1379 | break; |
| 1380 | } |
| 1381 | if (!get_field(gctl, GCTL_AID)) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1382 | printk(KERN_ALERT "ctxfi: Card Auto-init failed!!!\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1383 | return -EBUSY; |
| 1384 | } |
| 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
| 1389 | /* DAC operations */ |
| 1390 | |
| 1391 | #define CS4382_MC1 0x1 |
| 1392 | #define CS4382_MC2 0x2 |
| 1393 | #define CS4382_MC3 0x3 |
| 1394 | #define CS4382_FC 0x4 |
| 1395 | #define CS4382_IC 0x5 |
| 1396 | #define CS4382_XC1 0x6 |
| 1397 | #define CS4382_VCA1 0x7 |
| 1398 | #define CS4382_VCB1 0x8 |
| 1399 | #define CS4382_XC2 0x9 |
| 1400 | #define CS4382_VCA2 0xA |
| 1401 | #define CS4382_VCB2 0xB |
| 1402 | #define CS4382_XC3 0xC |
| 1403 | #define CS4382_VCA3 0xD |
| 1404 | #define CS4382_VCB3 0xE |
| 1405 | #define CS4382_XC4 0xF |
| 1406 | #define CS4382_VCA4 0x10 |
| 1407 | #define CS4382_VCB4 0x11 |
| 1408 | #define CS4382_CREV 0x12 |
| 1409 | |
| 1410 | /* I2C status */ |
| 1411 | #define STATE_LOCKED 0x00 |
| 1412 | #define STATE_UNLOCKED 0xAA |
| 1413 | #define DATA_READY 0x800000 /* Used with I2C_IF_STATUS */ |
| 1414 | #define DATA_ABORT 0x10000 /* Used with I2C_IF_STATUS */ |
| 1415 | |
| 1416 | #define I2C_STATUS_DCM 0x00000001 |
| 1417 | #define I2C_STATUS_BC 0x00000006 |
| 1418 | #define I2C_STATUS_APD 0x00000008 |
| 1419 | #define I2C_STATUS_AB 0x00010000 |
| 1420 | #define I2C_STATUS_DR 0x00800000 |
| 1421 | |
| 1422 | #define I2C_ADDRESS_PTAD 0x0000FFFF |
| 1423 | #define I2C_ADDRESS_SLAD 0x007F0000 |
| 1424 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1425 | struct regs_cs4382 { |
| 1426 | u32 mode_control_1; |
| 1427 | u32 mode_control_2; |
| 1428 | u32 mode_control_3; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1429 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1430 | u32 filter_control; |
| 1431 | u32 invert_control; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1432 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1433 | u32 mix_control_P1; |
| 1434 | u32 vol_control_A1; |
| 1435 | u32 vol_control_B1; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1436 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1437 | u32 mix_control_P2; |
| 1438 | u32 vol_control_A2; |
| 1439 | u32 vol_control_B2; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1440 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1441 | u32 mix_control_P3; |
| 1442 | u32 vol_control_A3; |
| 1443 | u32 vol_control_B3; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1444 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1445 | u32 mix_control_P4; |
| 1446 | u32 vol_control_A4; |
| 1447 | u32 vol_control_B4; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1448 | }; |
| 1449 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1450 | static int hw20k2_i2c_unlock_full_access(struct hw *hw) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1451 | { |
| 1452 | u8 UnlockKeySequence_FLASH_FULLACCESS_MODE[2] = {0xB3, 0xD4}; |
| 1453 | |
| 1454 | /* Send keys for forced BIOS mode */ |
| 1455 | hw_write_20kx(hw, I2C_IF_WLOCK, |
| 1456 | UnlockKeySequence_FLASH_FULLACCESS_MODE[0]); |
| 1457 | hw_write_20kx(hw, I2C_IF_WLOCK, |
| 1458 | UnlockKeySequence_FLASH_FULLACCESS_MODE[1]); |
| 1459 | /* Check whether the chip is unlocked */ |
| 1460 | if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_UNLOCKED) |
| 1461 | return 0; |
| 1462 | |
| 1463 | return -1; |
| 1464 | } |
| 1465 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1466 | static int hw20k2_i2c_lock_chip(struct hw *hw) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1467 | { |
| 1468 | /* Write twice */ |
| 1469 | hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED); |
| 1470 | hw_write_20kx(hw, I2C_IF_WLOCK, STATE_LOCKED); |
| 1471 | if (hw_read_20kx(hw, I2C_IF_WLOCK) == STATE_LOCKED) |
| 1472 | return 0; |
| 1473 | |
| 1474 | return -1; |
| 1475 | } |
| 1476 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1477 | static int hw20k2_i2c_init(struct hw *hw, u8 dev_id, u8 addr_size, u8 data_size) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1478 | { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1479 | struct hw20k2 *hw20k2 = (struct hw20k2 *)hw; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1480 | int err; |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1481 | unsigned int i2c_status; |
| 1482 | unsigned int i2c_addr; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1483 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1484 | err = hw20k2_i2c_unlock_full_access(hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1485 | if (err < 0) |
| 1486 | return err; |
| 1487 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1488 | hw20k2->addr_size = addr_size; |
| 1489 | hw20k2->data_size = data_size; |
| 1490 | hw20k2->dev_id = dev_id; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1491 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1492 | i2c_addr = 0; |
| 1493 | set_field(&i2c_addr, I2C_ADDRESS_SLAD, dev_id); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1494 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1495 | hw_write_20kx(hw, I2C_IF_ADDRESS, i2c_addr); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1496 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1497 | i2c_status = hw_read_20kx(hw, I2C_IF_STATUS); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1498 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1499 | set_field(&i2c_status, I2C_STATUS_DCM, 1); /* Direct control mode */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1500 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1501 | hw_write_20kx(hw, I2C_IF_STATUS, i2c_status); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1502 | |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1506 | static int hw20k2_i2c_uninit(struct hw *hw) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1507 | { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1508 | unsigned int i2c_status; |
| 1509 | unsigned int i2c_addr; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1510 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1511 | i2c_addr = 0; |
| 1512 | set_field(&i2c_addr, I2C_ADDRESS_SLAD, 0x57); /* I2C id */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1513 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1514 | hw_write_20kx(hw, I2C_IF_ADDRESS, i2c_addr); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1515 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1516 | i2c_status = hw_read_20kx(hw, I2C_IF_STATUS); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1517 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1518 | set_field(&i2c_status, I2C_STATUS_DCM, 0); /* I2C mode */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1519 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1520 | hw_write_20kx(hw, I2C_IF_STATUS, i2c_status); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1521 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1522 | return hw20k2_i2c_lock_chip(hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1525 | static int hw20k2_i2c_wait_data_ready(struct hw *hw) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1526 | { |
| 1527 | int i = 0x400000; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1528 | unsigned int ret; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1529 | |
| 1530 | do { |
| 1531 | ret = hw_read_20kx(hw, I2C_IF_STATUS); |
| 1532 | } while ((!(ret & DATA_READY)) && --i); |
| 1533 | |
| 1534 | return i; |
| 1535 | } |
| 1536 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1537 | static int hw20k2_i2c_read(struct hw *hw, u16 addr, u32 *datap) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1538 | { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1539 | struct hw20k2 *hw20k2 = (struct hw20k2 *)hw; |
| 1540 | unsigned int i2c_status; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1541 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1542 | i2c_status = hw_read_20kx(hw, I2C_IF_STATUS); |
| 1543 | set_field(&i2c_status, I2C_STATUS_BC, |
| 1544 | (4 == hw20k2->addr_size) ? 0 : hw20k2->addr_size); |
| 1545 | hw_write_20kx(hw, I2C_IF_STATUS, i2c_status); |
| 1546 | if (!hw20k2_i2c_wait_data_ready(hw)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1547 | return -1; |
| 1548 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1549 | hw_write_20kx(hw, I2C_IF_WDATA, addr); |
| 1550 | if (!hw20k2_i2c_wait_data_ready(hw)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1551 | return -1; |
| 1552 | |
| 1553 | /* Force a read operation */ |
| 1554 | hw_write_20kx(hw, I2C_IF_RDATA, 0); |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1555 | if (!hw20k2_i2c_wait_data_ready(hw)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1556 | return -1; |
| 1557 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1558 | *datap = hw_read_20kx(hw, I2C_IF_RDATA); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1559 | |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1563 | static int hw20k2_i2c_write(struct hw *hw, u16 addr, u32 data) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1564 | { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1565 | struct hw20k2 *hw20k2 = (struct hw20k2 *)hw; |
| 1566 | unsigned int i2c_data = (data << (hw20k2->addr_size * 8)) | addr; |
| 1567 | unsigned int i2c_status; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1568 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1569 | i2c_status = hw_read_20kx(hw, I2C_IF_STATUS); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1570 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1571 | set_field(&i2c_status, I2C_STATUS_BC, |
| 1572 | (4 == (hw20k2->addr_size + hw20k2->data_size)) ? |
| 1573 | 0 : (hw20k2->addr_size + hw20k2->data_size)); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1574 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1575 | hw_write_20kx(hw, I2C_IF_STATUS, i2c_status); |
| 1576 | hw20k2_i2c_wait_data_ready(hw); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1577 | /* Dummy write to trigger the write operation */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1578 | hw_write_20kx(hw, I2C_IF_WDATA, 0); |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1579 | hw20k2_i2c_wait_data_ready(hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1580 | |
| 1581 | /* This is the real data */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1582 | hw_write_20kx(hw, I2C_IF_WDATA, i2c_data); |
| 1583 | hw20k2_i2c_wait_data_ready(hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1584 | |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1588 | static void hw_dac_stop(struct hw *hw) |
| 1589 | { |
| 1590 | u32 data; |
| 1591 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1592 | data &= 0xFFFFFFFD; |
| 1593 | hw_write_20kx(hw, GPIO_DATA, data); |
| 1594 | mdelay(10); |
| 1595 | } |
| 1596 | |
| 1597 | static void hw_dac_start(struct hw *hw) |
| 1598 | { |
| 1599 | u32 data; |
| 1600 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1601 | data |= 0x2; |
| 1602 | hw_write_20kx(hw, GPIO_DATA, data); |
| 1603 | mdelay(50); |
| 1604 | } |
| 1605 | |
| 1606 | static void hw_dac_reset(struct hw *hw) |
| 1607 | { |
| 1608 | hw_dac_stop(hw); |
| 1609 | hw_dac_start(hw); |
| 1610 | } |
| 1611 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1612 | static int hw_dac_init(struct hw *hw, const struct dac_conf *info) |
| 1613 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1614 | int err; |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1615 | u32 data; |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1616 | int i; |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1617 | struct regs_cs4382 cs_read = {0}; |
| 1618 | struct regs_cs4382 cs_def = { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1619 | 0x00000001, /* Mode Control 1 */ |
| 1620 | 0x00000000, /* Mode Control 2 */ |
| 1621 | 0x00000084, /* Mode Control 3 */ |
| 1622 | 0x00000000, /* Filter Control */ |
| 1623 | 0x00000000, /* Invert Control */ |
| 1624 | 0x00000024, /* Mixing Control Pair 1 */ |
| 1625 | 0x00000000, /* Vol Control A1 */ |
| 1626 | 0x00000000, /* Vol Control B1 */ |
| 1627 | 0x00000024, /* Mixing Control Pair 2 */ |
| 1628 | 0x00000000, /* Vol Control A2 */ |
| 1629 | 0x00000000, /* Vol Control B2 */ |
| 1630 | 0x00000024, /* Mixing Control Pair 3 */ |
| 1631 | 0x00000000, /* Vol Control A3 */ |
| 1632 | 0x00000000, /* Vol Control B3 */ |
| 1633 | 0x00000024, /* Mixing Control Pair 4 */ |
| 1634 | 0x00000000, /* Vol Control A4 */ |
| 1635 | 0x00000000 /* Vol Control B4 */ |
| 1636 | }; |
| 1637 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1638 | if (hw->model == CTSB1270) { |
| 1639 | hw_dac_stop(hw); |
| 1640 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1641 | data &= ~0x0600; |
| 1642 | if (1 == info->msr) |
| 1643 | data |= 0x0000; /* Single Speed Mode 0-50kHz */ |
| 1644 | else if (2 == info->msr) |
| 1645 | data |= 0x0200; /* Double Speed Mode 50-100kHz */ |
| 1646 | else |
| 1647 | data |= 0x0600; /* Quad Speed Mode 100-200kHz */ |
| 1648 | hw_write_20kx(hw, GPIO_DATA, data); |
| 1649 | hw_dac_start(hw); |
| 1650 | return 0; |
| 1651 | } |
| 1652 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1653 | /* Set DAC reset bit as output */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1654 | data = hw_read_20kx(hw, GPIO_CTRL); |
| 1655 | data |= 0x02; |
| 1656 | hw_write_20kx(hw, GPIO_CTRL, data); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1657 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1658 | err = hw20k2_i2c_init(hw, 0x18, 1, 1); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1659 | if (err < 0) |
| 1660 | goto End; |
| 1661 | |
| 1662 | for (i = 0; i < 2; i++) { |
| 1663 | /* Reset DAC twice just in-case the chip |
| 1664 | * didn't initialized properly */ |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1665 | hw_dac_reset(hw); |
| 1666 | hw_dac_reset(hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1667 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1668 | if (hw20k2_i2c_read(hw, CS4382_MC1, &cs_read.mode_control_1)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1669 | continue; |
| 1670 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1671 | if (hw20k2_i2c_read(hw, CS4382_MC2, &cs_read.mode_control_2)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1672 | continue; |
| 1673 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1674 | if (hw20k2_i2c_read(hw, CS4382_MC3, &cs_read.mode_control_3)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1675 | continue; |
| 1676 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1677 | if (hw20k2_i2c_read(hw, CS4382_FC, &cs_read.filter_control)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1678 | continue; |
| 1679 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1680 | if (hw20k2_i2c_read(hw, CS4382_IC, &cs_read.invert_control)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1681 | continue; |
| 1682 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1683 | if (hw20k2_i2c_read(hw, CS4382_XC1, &cs_read.mix_control_P1)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1684 | continue; |
| 1685 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1686 | if (hw20k2_i2c_read(hw, CS4382_VCA1, &cs_read.vol_control_A1)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1687 | continue; |
| 1688 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1689 | if (hw20k2_i2c_read(hw, CS4382_VCB1, &cs_read.vol_control_B1)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1690 | continue; |
| 1691 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1692 | if (hw20k2_i2c_read(hw, CS4382_XC2, &cs_read.mix_control_P2)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1693 | continue; |
| 1694 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1695 | if (hw20k2_i2c_read(hw, CS4382_VCA2, &cs_read.vol_control_A2)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1696 | continue; |
| 1697 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1698 | if (hw20k2_i2c_read(hw, CS4382_VCB2, &cs_read.vol_control_B2)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1699 | continue; |
| 1700 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1701 | if (hw20k2_i2c_read(hw, CS4382_XC3, &cs_read.mix_control_P3)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1702 | continue; |
| 1703 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1704 | if (hw20k2_i2c_read(hw, CS4382_VCA3, &cs_read.vol_control_A3)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1705 | continue; |
| 1706 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1707 | if (hw20k2_i2c_read(hw, CS4382_VCB3, &cs_read.vol_control_B3)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1708 | continue; |
| 1709 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1710 | if (hw20k2_i2c_read(hw, CS4382_XC4, &cs_read.mix_control_P4)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1711 | continue; |
| 1712 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1713 | if (hw20k2_i2c_read(hw, CS4382_VCA4, &cs_read.vol_control_A4)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1714 | continue; |
| 1715 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1716 | if (hw20k2_i2c_read(hw, CS4382_VCB4, &cs_read.vol_control_B4)) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1717 | continue; |
| 1718 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1719 | if (memcmp(&cs_read, &cs_def, sizeof(cs_read))) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1720 | continue; |
| 1721 | else |
| 1722 | break; |
| 1723 | } |
| 1724 | |
| 1725 | if (i >= 2) |
| 1726 | goto End; |
| 1727 | |
| 1728 | /* Note: Every I2C write must have some delay. |
| 1729 | * This is not a requirement but the delay works here... */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1730 | hw20k2_i2c_write(hw, CS4382_MC1, 0x80); |
| 1731 | hw20k2_i2c_write(hw, CS4382_MC2, 0x10); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1732 | if (1 == info->msr) { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1733 | hw20k2_i2c_write(hw, CS4382_XC1, 0x24); |
| 1734 | hw20k2_i2c_write(hw, CS4382_XC2, 0x24); |
| 1735 | hw20k2_i2c_write(hw, CS4382_XC3, 0x24); |
| 1736 | hw20k2_i2c_write(hw, CS4382_XC4, 0x24); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1737 | } else if (2 == info->msr) { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1738 | hw20k2_i2c_write(hw, CS4382_XC1, 0x25); |
| 1739 | hw20k2_i2c_write(hw, CS4382_XC2, 0x25); |
| 1740 | hw20k2_i2c_write(hw, CS4382_XC3, 0x25); |
| 1741 | hw20k2_i2c_write(hw, CS4382_XC4, 0x25); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1742 | } else { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1743 | hw20k2_i2c_write(hw, CS4382_XC1, 0x26); |
| 1744 | hw20k2_i2c_write(hw, CS4382_XC2, 0x26); |
| 1745 | hw20k2_i2c_write(hw, CS4382_XC3, 0x26); |
| 1746 | hw20k2_i2c_write(hw, CS4382_XC4, 0x26); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | return 0; |
| 1750 | End: |
| 1751 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1752 | hw20k2_i2c_uninit(hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1753 | return -1; |
| 1754 | } |
| 1755 | |
| 1756 | /* ADC operations */ |
| 1757 | #define MAKE_WM8775_ADDR(addr, data) (u32)(((addr<<1)&0xFE)|((data>>8)&0x1)) |
| 1758 | #define MAKE_WM8775_DATA(data) (u32)(data&0xFF) |
| 1759 | |
| 1760 | #define WM8775_IC 0x0B |
| 1761 | #define WM8775_MMC 0x0C |
| 1762 | #define WM8775_AADCL 0x0E |
| 1763 | #define WM8775_AADCR 0x0F |
| 1764 | #define WM8775_ADCMC 0x15 |
| 1765 | #define WM8775_RESET 0x17 |
| 1766 | |
| 1767 | static int hw_is_adc_input_selected(struct hw *hw, enum ADCSRC type) |
| 1768 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1769 | u32 data; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1770 | if (hw->model == CTSB1270) { |
| 1771 | /* Titanium HD has two ADC chips, one for line in and one */ |
| 1772 | /* for MIC. We don't need to switch the ADC input. */ |
| 1773 | return 1; |
| 1774 | } |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1775 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1776 | switch (type) { |
| 1777 | case ADC_MICIN: |
| 1778 | data = (data & (0x1 << 14)) ? 1 : 0; |
| 1779 | break; |
| 1780 | case ADC_LINEIN: |
| 1781 | data = (data & (0x1 << 14)) ? 0 : 1; |
| 1782 | break; |
| 1783 | default: |
| 1784 | data = 0; |
| 1785 | } |
| 1786 | return data; |
| 1787 | } |
| 1788 | |
Przemyslaw Bruski | 19002fd | 2011-03-13 16:18:55 +0100 | [diff] [blame] | 1789 | #define MIC_BOOST_0DB 0xCF |
| 1790 | #define MIC_BOOST_STEPS_PER_DB 2 |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1791 | |
| 1792 | static void hw_wm8775_input_select(struct hw *hw, u8 input, s8 gain_in_db) |
| 1793 | { |
| 1794 | u32 adcmc, gain; |
| 1795 | |
| 1796 | if (input > 3) |
| 1797 | input = 3; |
| 1798 | |
| 1799 | adcmc = ((u32)1 << input) | 0x100; /* Link L+R gain... */ |
| 1800 | |
| 1801 | hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_ADCMC, adcmc), |
| 1802 | MAKE_WM8775_DATA(adcmc)); |
| 1803 | |
| 1804 | if (gain_in_db < -103) |
| 1805 | gain_in_db = -103; |
| 1806 | if (gain_in_db > 24) |
| 1807 | gain_in_db = 24; |
| 1808 | |
| 1809 | gain = gain_in_db * MIC_BOOST_STEPS_PER_DB + MIC_BOOST_0DB; |
| 1810 | |
| 1811 | hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCL, gain), |
| 1812 | MAKE_WM8775_DATA(gain)); |
| 1813 | /* ...so there should be no need for the following. */ |
| 1814 | hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_AADCR, gain), |
| 1815 | MAKE_WM8775_DATA(gain)); |
| 1816 | } |
Przemyslaw Bruski | 19002fd | 2011-03-13 16:18:55 +0100 | [diff] [blame] | 1817 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1818 | static int hw_adc_input_select(struct hw *hw, enum ADCSRC type) |
| 1819 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1820 | u32 data; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1821 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1822 | switch (type) { |
| 1823 | case ADC_MICIN: |
| 1824 | data |= (0x1 << 14); |
| 1825 | hw_write_20kx(hw, GPIO_DATA, data); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1826 | hw_wm8775_input_select(hw, 0, 20); /* Mic, 20dB */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1827 | break; |
| 1828 | case ADC_LINEIN: |
| 1829 | data &= ~(0x1 << 14); |
| 1830 | hw_write_20kx(hw, GPIO_DATA, data); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1831 | hw_wm8775_input_select(hw, 1, 0); /* Line-in, 0dB */ |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1832 | break; |
| 1833 | default: |
| 1834 | break; |
| 1835 | } |
| 1836 | |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
| 1840 | static int hw_adc_init(struct hw *hw, const struct adc_conf *info) |
| 1841 | { |
Takashi Iwai | 514eef9 | 2009-06-08 14:57:57 +0200 | [diff] [blame] | 1842 | int err; |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1843 | u32 data, ctl; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1844 | |
| 1845 | /* Set ADC reset bit as output */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1846 | data = hw_read_20kx(hw, GPIO_CTRL); |
| 1847 | data |= (0x1 << 15); |
| 1848 | hw_write_20kx(hw, GPIO_CTRL, data); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1849 | |
| 1850 | /* Initialize I2C */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1851 | err = hw20k2_i2c_init(hw, 0x1A, 1, 1); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1852 | if (err < 0) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1853 | printk(KERN_ALERT "ctxfi: Failure to acquire I2C!!!\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1854 | goto error; |
| 1855 | } |
| 1856 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1857 | /* Reset the ADC (reset is active low). */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1858 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1859 | data &= ~(0x1 << 15); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1860 | hw_write_20kx(hw, GPIO_DATA, data); |
| 1861 | |
| 1862 | if (hw->model == CTSB1270) { |
| 1863 | /* Set up the PCM4220 ADC on Titanium HD */ |
| 1864 | data &= ~0x0C; |
| 1865 | if (1 == info->msr) |
| 1866 | data |= 0x00; /* Single Speed Mode 32-50kHz */ |
| 1867 | else if (2 == info->msr) |
| 1868 | data |= 0x08; /* Double Speed Mode 50-108kHz */ |
| 1869 | else |
| 1870 | data |= 0x04; /* Quad Speed Mode 108kHz-216kHz */ |
| 1871 | hw_write_20kx(hw, GPIO_DATA, data); |
| 1872 | } |
| 1873 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1874 | mdelay(10); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1875 | /* Return the ADC to normal operation. */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1876 | data |= (0x1 << 15); |
| 1877 | hw_write_20kx(hw, GPIO_DATA, data); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1878 | mdelay(50); |
| 1879 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1880 | /* I2C write to register offset 0x0B to set ADC LRCLK polarity */ |
| 1881 | /* invert bit, interface format to I2S, word length to 24-bit, */ |
| 1882 | /* enable ADC high pass filter. Fixes bug 5323? */ |
| 1883 | hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_IC, 0x26), |
| 1884 | MAKE_WM8775_DATA(0x26)); |
| 1885 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1886 | /* Set the master mode (256fs) */ |
| 1887 | if (1 == info->msr) { |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1888 | /* slave mode, 128x oversampling 256fs */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1889 | hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x02), |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1890 | MAKE_WM8775_DATA(0x02)); |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1891 | } else if ((2 == info->msr) || (4 == info->msr)) { |
| 1892 | /* slave mode, 64x oversampling, 256fs */ |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1893 | hw20k2_i2c_write(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x0A), |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1894 | MAKE_WM8775_DATA(0x0A)); |
| 1895 | } else { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 1896 | printk(KERN_ALERT "ctxfi: Invalid master sampling " |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1897 | "rate (msr %d)!!!\n", info->msr); |
| 1898 | err = -EINVAL; |
| 1899 | goto error; |
| 1900 | } |
| 1901 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1902 | if (hw->model != CTSB1270) { |
| 1903 | /* Configure GPIO bit 14 change to line-in/mic-in */ |
| 1904 | ctl = hw_read_20kx(hw, GPIO_CTRL); |
| 1905 | ctl |= 0x1 << 14; |
| 1906 | hw_write_20kx(hw, GPIO_CTRL, ctl); |
| 1907 | hw_adc_input_select(hw, ADC_LINEIN); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1908 | } else { |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1909 | hw_wm8775_input_select(hw, 0, 0); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | return 0; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1913 | error: |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 1914 | hw20k2_i2c_uninit(hw); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1915 | return err; |
| 1916 | } |
| 1917 | |
| 1918 | static int hw_have_digit_io_switch(struct hw *hw) |
| 1919 | { |
| 1920 | return 0; |
| 1921 | } |
| 1922 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 1923 | static int hw_have_dedicated_mic(struct hw *hw) |
| 1924 | { |
| 1925 | return hw->model == CTSB1270; |
| 1926 | } |
| 1927 | |
| 1928 | static int hw_have_output_switch(struct hw *hw) |
| 1929 | { |
| 1930 | return hw->model == CTSB1270; |
| 1931 | } |
| 1932 | |
| 1933 | static int hw_output_switch_get(struct hw *hw) |
| 1934 | { |
| 1935 | u32 data = hw_read_20kx(hw, GPIO_EXT_DATA); |
| 1936 | |
| 1937 | switch (data & 0x30) { |
| 1938 | case 0x00: |
| 1939 | return 0; |
| 1940 | case 0x10: |
| 1941 | return 1; |
| 1942 | case 0x20: |
| 1943 | return 2; |
| 1944 | default: |
| 1945 | return 3; |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | static int hw_output_switch_put(struct hw *hw, int position) |
| 1950 | { |
| 1951 | u32 data; |
| 1952 | |
| 1953 | if (position == hw_output_switch_get(hw)) |
| 1954 | return 0; |
| 1955 | |
| 1956 | /* Mute line and headphones (intended for anti-pop). */ |
| 1957 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1958 | data |= (0x03 << 11); |
| 1959 | hw_write_20kx(hw, GPIO_DATA, data); |
| 1960 | |
| 1961 | data = hw_read_20kx(hw, GPIO_EXT_DATA) & ~0x30; |
| 1962 | switch (position) { |
| 1963 | case 0: |
| 1964 | break; |
| 1965 | case 1: |
| 1966 | data |= 0x10; |
| 1967 | break; |
| 1968 | default: |
| 1969 | data |= 0x20; |
| 1970 | } |
| 1971 | hw_write_20kx(hw, GPIO_EXT_DATA, data); |
| 1972 | |
| 1973 | /* Unmute line and headphones. */ |
| 1974 | data = hw_read_20kx(hw, GPIO_DATA); |
| 1975 | data &= ~(0x03 << 11); |
| 1976 | hw_write_20kx(hw, GPIO_DATA, data); |
| 1977 | |
| 1978 | return 1; |
| 1979 | } |
| 1980 | |
| 1981 | static int hw_have_mic_source_switch(struct hw *hw) |
| 1982 | { |
| 1983 | return hw->model == CTSB1270; |
| 1984 | } |
| 1985 | |
| 1986 | static int hw_mic_source_switch_get(struct hw *hw) |
| 1987 | { |
| 1988 | struct hw20k2 *hw20k2 = (struct hw20k2 *)hw; |
| 1989 | |
| 1990 | return hw20k2->mic_source; |
| 1991 | } |
| 1992 | |
| 1993 | static int hw_mic_source_switch_put(struct hw *hw, int position) |
| 1994 | { |
| 1995 | struct hw20k2 *hw20k2 = (struct hw20k2 *)hw; |
| 1996 | |
| 1997 | if (position == hw20k2->mic_source) |
| 1998 | return 0; |
| 1999 | |
| 2000 | switch (position) { |
| 2001 | case 0: |
| 2002 | hw_wm8775_input_select(hw, 0, 0); /* Mic, 0dB */ |
| 2003 | break; |
| 2004 | case 1: |
| 2005 | hw_wm8775_input_select(hw, 1, 0); /* FP Mic, 0dB */ |
| 2006 | break; |
| 2007 | case 2: |
| 2008 | hw_wm8775_input_select(hw, 3, 0); /* Aux Ext, 0dB */ |
| 2009 | break; |
| 2010 | default: |
| 2011 | return 0; |
| 2012 | } |
| 2013 | |
| 2014 | hw20k2->mic_source = position; |
| 2015 | |
| 2016 | return 1; |
| 2017 | } |
| 2018 | |
Takashi Iwai | bc5304b | 2009-07-20 13:41:35 +0200 | [diff] [blame] | 2019 | static irqreturn_t ct_20k2_interrupt(int irq, void *dev_id) |
| 2020 | { |
| 2021 | struct hw *hw = dev_id; |
| 2022 | unsigned int status; |
| 2023 | |
| 2024 | status = hw_read_20kx(hw, GIP); |
| 2025 | if (!status) |
| 2026 | return IRQ_NONE; |
| 2027 | |
| 2028 | if (hw->irq_callback) |
| 2029 | hw->irq_callback(hw->irq_callback_data, status); |
| 2030 | |
| 2031 | hw_write_20kx(hw, GIP, status); |
| 2032 | return IRQ_HANDLED; |
| 2033 | } |
| 2034 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2035 | static int hw_card_start(struct hw *hw) |
| 2036 | { |
| 2037 | int err = 0; |
| 2038 | struct pci_dev *pci = hw->pci; |
| 2039 | unsigned int gctl; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2040 | |
| 2041 | err = pci_enable_device(pci); |
| 2042 | if (err < 0) |
| 2043 | return err; |
| 2044 | |
| 2045 | /* Set DMA transfer mask */ |
Takashi Iwai | 4836ac6 | 2009-06-08 14:49:26 +0200 | [diff] [blame] | 2046 | if (pci_set_dma_mask(pci, CT_XFI_DMA_MASK) < 0 || |
| 2047 | pci_set_consistent_dma_mask(pci, CT_XFI_DMA_MASK) < 0) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 2048 | printk(KERN_ERR "ctxfi: architecture does not support PCI " |
Takashi Iwai | 4836ac6 | 2009-06-08 14:49:26 +0200 | [diff] [blame] | 2049 | "busmaster DMA with mask 0x%llx\n", CT_XFI_DMA_MASK); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2050 | err = -ENXIO; |
| 2051 | goto error1; |
| 2052 | } |
| 2053 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 2054 | if (!hw->io_base) { |
| 2055 | err = pci_request_regions(pci, "XFi"); |
| 2056 | if (err < 0) |
| 2057 | goto error1; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2058 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 2059 | hw->io_base = pci_resource_start(hw->pci, 2); |
| 2060 | hw->mem_base = (unsigned long)ioremap(hw->io_base, |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2061 | pci_resource_len(hw->pci, 2)); |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 2062 | if (!hw->mem_base) { |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 2063 | err = -ENOENT; |
| 2064 | goto error2; |
| 2065 | } |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | /* Switch to 20k2 mode from UAA mode. */ |
| 2069 | gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL); |
| 2070 | set_field(&gctl, GCTL_UAA, 0); |
| 2071 | hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl); |
| 2072 | |
Takashi Iwai | bc5304b | 2009-07-20 13:41:35 +0200 | [diff] [blame] | 2073 | if (hw->irq < 0) { |
| 2074 | err = request_irq(pci->irq, ct_20k2_interrupt, IRQF_SHARED, |
| 2075 | "ctxfi", hw); |
| 2076 | if (err < 0) { |
| 2077 | printk(KERN_ERR "XFi: Cannot get irq %d\n", pci->irq); |
| 2078 | goto error2; |
| 2079 | } |
| 2080 | hw->irq = pci->irq; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2081 | } |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2082 | |
| 2083 | pci_set_master(pci); |
| 2084 | |
| 2085 | return 0; |
| 2086 | |
| 2087 | /*error3: |
| 2088 | iounmap((void *)hw->mem_base); |
| 2089 | hw->mem_base = (unsigned long)NULL;*/ |
| 2090 | error2: |
| 2091 | pci_release_regions(pci); |
| 2092 | hw->io_base = 0; |
| 2093 | error1: |
| 2094 | pci_disable_device(pci); |
| 2095 | return err; |
| 2096 | } |
| 2097 | |
| 2098 | static int hw_card_stop(struct hw *hw) |
| 2099 | { |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 2100 | unsigned int data; |
| 2101 | |
| 2102 | /* disable transport bus master and queueing of request */ |
| 2103 | hw_write_20kx(hw, TRANSPORT_CTL, 0x00); |
| 2104 | |
| 2105 | /* disable pll */ |
| 2106 | data = hw_read_20kx(hw, PLL_ENB); |
| 2107 | hw_write_20kx(hw, PLL_ENB, (data & (~0x07))); |
| 2108 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2109 | /* TODO: Disable interrupt and so on... */ |
| 2110 | return 0; |
| 2111 | } |
| 2112 | |
| 2113 | static int hw_card_shutdown(struct hw *hw) |
| 2114 | { |
| 2115 | if (hw->irq >= 0) |
| 2116 | free_irq(hw->irq, hw); |
| 2117 | |
| 2118 | hw->irq = -1; |
| 2119 | |
Takashi Iwai | 35ebf6e | 2009-07-22 17:12:34 +0200 | [diff] [blame] | 2120 | if (hw->mem_base) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2121 | iounmap((void *)hw->mem_base); |
| 2122 | |
| 2123 | hw->mem_base = (unsigned long)NULL; |
| 2124 | |
| 2125 | if (hw->io_base) |
| 2126 | pci_release_regions(hw->pci); |
| 2127 | |
| 2128 | hw->io_base = 0; |
| 2129 | |
| 2130 | pci_disable_device(hw->pci); |
| 2131 | |
| 2132 | return 0; |
| 2133 | } |
| 2134 | |
| 2135 | static int hw_card_init(struct hw *hw, struct card_conf *info) |
| 2136 | { |
| 2137 | int err; |
| 2138 | unsigned int gctl; |
| 2139 | u32 data = 0; |
| 2140 | struct dac_conf dac_info = {0}; |
| 2141 | struct adc_conf adc_info = {0}; |
| 2142 | struct daio_conf daio_info = {0}; |
| 2143 | struct trn_conf trn_info = {0}; |
| 2144 | |
| 2145 | /* Get PCI io port/memory base address and |
| 2146 | * do 20kx core switch if needed. */ |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 2147 | err = hw_card_start(hw); |
| 2148 | if (err) |
| 2149 | return err; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2150 | |
| 2151 | /* PLL init */ |
| 2152 | err = hw_pll_init(hw, info->rsr); |
| 2153 | if (err < 0) |
| 2154 | return err; |
| 2155 | |
| 2156 | /* kick off auto-init */ |
| 2157 | err = hw_auto_init(hw); |
| 2158 | if (err < 0) |
| 2159 | return err; |
| 2160 | |
| 2161 | gctl = hw_read_20kx(hw, GLOBAL_CNTL_GCTL); |
| 2162 | set_field(&gctl, GCTL_DBP, 1); |
| 2163 | set_field(&gctl, GCTL_TBP, 1); |
| 2164 | set_field(&gctl, GCTL_FBP, 1); |
| 2165 | set_field(&gctl, GCTL_DPC, 0); |
| 2166 | hw_write_20kx(hw, GLOBAL_CNTL_GCTL, gctl); |
| 2167 | |
| 2168 | /* Reset all global pending interrupts */ |
Takashi Iwai | bc5304b | 2009-07-20 13:41:35 +0200 | [diff] [blame] | 2169 | hw_write_20kx(hw, GIE, 0); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2170 | /* Reset all SRC pending interrupts */ |
| 2171 | hw_write_20kx(hw, SRC_IP, 0); |
| 2172 | |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 2173 | if (hw->model != CTSB1270) { |
| 2174 | /* TODO: detect the card ID and configure GPIO accordingly. */ |
| 2175 | /* Configures GPIO (0xD802 0x98028) */ |
| 2176 | /*hw_write_20kx(hw, GPIO_CTRL, 0x7F07);*/ |
| 2177 | /* Configures GPIO (SB0880) */ |
| 2178 | /*hw_write_20kx(hw, GPIO_CTRL, 0xFF07);*/ |
| 2179 | hw_write_20kx(hw, GPIO_CTRL, 0xD802); |
| 2180 | } else { |
| 2181 | hw_write_20kx(hw, GPIO_CTRL, 0x9E5F); |
| 2182 | } |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2183 | /* Enable audio ring */ |
| 2184 | hw_write_20kx(hw, MIXER_AR_ENABLE, 0x01); |
| 2185 | |
| 2186 | trn_info.vm_pgt_phys = info->vm_pgt_phys; |
| 2187 | err = hw_trn_init(hw, &trn_info); |
| 2188 | if (err < 0) |
| 2189 | return err; |
| 2190 | |
| 2191 | daio_info.msr = info->msr; |
| 2192 | err = hw_daio_init(hw, &daio_info); |
| 2193 | if (err < 0) |
| 2194 | return err; |
| 2195 | |
| 2196 | dac_info.msr = info->msr; |
| 2197 | err = hw_dac_init(hw, &dac_info); |
| 2198 | if (err < 0) |
| 2199 | return err; |
| 2200 | |
| 2201 | adc_info.msr = info->msr; |
| 2202 | adc_info.input = ADC_LINEIN; |
| 2203 | adc_info.mic20db = 0; |
| 2204 | err = hw_adc_init(hw, &adc_info); |
| 2205 | if (err < 0) |
| 2206 | return err; |
| 2207 | |
| 2208 | data = hw_read_20kx(hw, SRC_MCTL); |
| 2209 | data |= 0x1; /* Enables input from the audio ring */ |
| 2210 | hw_write_20kx(hw, SRC_MCTL, data); |
| 2211 | |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 2215 | #ifdef CONFIG_PM |
| 2216 | static int hw_suspend(struct hw *hw, pm_message_t state) |
| 2217 | { |
| 2218 | struct pci_dev *pci = hw->pci; |
| 2219 | |
| 2220 | hw_card_stop(hw); |
| 2221 | |
| 2222 | pci_disable_device(pci); |
| 2223 | pci_save_state(pci); |
| 2224 | pci_set_power_state(pci, pci_choose_state(pci, state)); |
| 2225 | |
| 2226 | return 0; |
| 2227 | } |
| 2228 | |
| 2229 | static int hw_resume(struct hw *hw, struct card_conf *info) |
| 2230 | { |
| 2231 | struct pci_dev *pci = hw->pci; |
| 2232 | |
| 2233 | pci_set_power_state(pci, PCI_D0); |
| 2234 | pci_restore_state(pci); |
| 2235 | |
| 2236 | /* Re-initialize card hardware. */ |
| 2237 | return hw_card_init(hw, info); |
| 2238 | } |
| 2239 | #endif |
| 2240 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2241 | static u32 hw_read_20kx(struct hw *hw, u32 reg) |
| 2242 | { |
| 2243 | return readl((void *)(hw->mem_base + reg)); |
| 2244 | } |
| 2245 | |
| 2246 | static void hw_write_20kx(struct hw *hw, u32 reg, u32 data) |
| 2247 | { |
| 2248 | writel(data, (void *)(hw->mem_base + reg)); |
| 2249 | } |
| 2250 | |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 2251 | static struct hw ct20k2_preset __devinitdata = { |
| 2252 | .irq = -1, |
| 2253 | |
| 2254 | .card_init = hw_card_init, |
| 2255 | .card_stop = hw_card_stop, |
| 2256 | .pll_init = hw_pll_init, |
| 2257 | .is_adc_source_selected = hw_is_adc_input_selected, |
| 2258 | .select_adc_source = hw_adc_input_select, |
| 2259 | .have_digit_io_switch = hw_have_digit_io_switch, |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame^] | 2260 | .have_dedicated_mic = hw_have_dedicated_mic, |
| 2261 | .have_output_switch = hw_have_output_switch, |
| 2262 | .output_switch_get = hw_output_switch_get, |
| 2263 | .output_switch_put = hw_output_switch_put, |
| 2264 | .have_mic_source_switch = hw_have_mic_source_switch, |
| 2265 | .mic_source_switch_get = hw_mic_source_switch_get, |
| 2266 | .mic_source_switch_put = hw_mic_source_switch_put, |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 2267 | #ifdef CONFIG_PM |
| 2268 | .suspend = hw_suspend, |
| 2269 | .resume = hw_resume, |
| 2270 | #endif |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 2271 | |
| 2272 | .src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk, |
| 2273 | .src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk, |
| 2274 | .src_mgr_get_ctrl_blk = src_mgr_get_ctrl_blk, |
| 2275 | .src_mgr_put_ctrl_blk = src_mgr_put_ctrl_blk, |
| 2276 | .src_set_state = src_set_state, |
| 2277 | .src_set_bm = src_set_bm, |
| 2278 | .src_set_rsr = src_set_rsr, |
| 2279 | .src_set_sf = src_set_sf, |
| 2280 | .src_set_wr = src_set_wr, |
| 2281 | .src_set_pm = src_set_pm, |
| 2282 | .src_set_rom = src_set_rom, |
| 2283 | .src_set_vo = src_set_vo, |
| 2284 | .src_set_st = src_set_st, |
| 2285 | .src_set_ie = src_set_ie, |
| 2286 | .src_set_ilsz = src_set_ilsz, |
| 2287 | .src_set_bp = src_set_bp, |
| 2288 | .src_set_cisz = src_set_cisz, |
| 2289 | .src_set_ca = src_set_ca, |
| 2290 | .src_set_sa = src_set_sa, |
| 2291 | .src_set_la = src_set_la, |
| 2292 | .src_set_pitch = src_set_pitch, |
| 2293 | .src_set_dirty = src_set_dirty, |
| 2294 | .src_set_clear_zbufs = src_set_clear_zbufs, |
| 2295 | .src_set_dirty_all = src_set_dirty_all, |
| 2296 | .src_commit_write = src_commit_write, |
| 2297 | .src_get_ca = src_get_ca, |
| 2298 | .src_get_dirty = src_get_dirty, |
| 2299 | .src_dirty_conj_mask = src_dirty_conj_mask, |
| 2300 | .src_mgr_enbs_src = src_mgr_enbs_src, |
| 2301 | .src_mgr_enb_src = src_mgr_enb_src, |
| 2302 | .src_mgr_dsb_src = src_mgr_dsb_src, |
| 2303 | .src_mgr_commit_write = src_mgr_commit_write, |
| 2304 | |
| 2305 | .srcimp_mgr_get_ctrl_blk = srcimp_mgr_get_ctrl_blk, |
| 2306 | .srcimp_mgr_put_ctrl_blk = srcimp_mgr_put_ctrl_blk, |
| 2307 | .srcimp_mgr_set_imaparc = srcimp_mgr_set_imaparc, |
| 2308 | .srcimp_mgr_set_imapuser = srcimp_mgr_set_imapuser, |
| 2309 | .srcimp_mgr_set_imapnxt = srcimp_mgr_set_imapnxt, |
| 2310 | .srcimp_mgr_set_imapaddr = srcimp_mgr_set_imapaddr, |
| 2311 | .srcimp_mgr_commit_write = srcimp_mgr_commit_write, |
| 2312 | |
| 2313 | .amixer_rsc_get_ctrl_blk = amixer_rsc_get_ctrl_blk, |
| 2314 | .amixer_rsc_put_ctrl_blk = amixer_rsc_put_ctrl_blk, |
| 2315 | .amixer_mgr_get_ctrl_blk = amixer_mgr_get_ctrl_blk, |
| 2316 | .amixer_mgr_put_ctrl_blk = amixer_mgr_put_ctrl_blk, |
| 2317 | .amixer_set_mode = amixer_set_mode, |
| 2318 | .amixer_set_iv = amixer_set_iv, |
| 2319 | .amixer_set_x = amixer_set_x, |
| 2320 | .amixer_set_y = amixer_set_y, |
| 2321 | .amixer_set_sadr = amixer_set_sadr, |
| 2322 | .amixer_set_se = amixer_set_se, |
| 2323 | .amixer_set_dirty = amixer_set_dirty, |
| 2324 | .amixer_set_dirty_all = amixer_set_dirty_all, |
| 2325 | .amixer_commit_write = amixer_commit_write, |
| 2326 | .amixer_get_y = amixer_get_y, |
| 2327 | .amixer_get_dirty = amixer_get_dirty, |
| 2328 | |
| 2329 | .dai_get_ctrl_blk = dai_get_ctrl_blk, |
| 2330 | .dai_put_ctrl_blk = dai_put_ctrl_blk, |
| 2331 | .dai_srt_set_srco = dai_srt_set_srco, |
| 2332 | .dai_srt_set_srcm = dai_srt_set_srcm, |
| 2333 | .dai_srt_set_rsr = dai_srt_set_rsr, |
| 2334 | .dai_srt_set_drat = dai_srt_set_drat, |
| 2335 | .dai_srt_set_ec = dai_srt_set_ec, |
| 2336 | .dai_srt_set_et = dai_srt_set_et, |
| 2337 | .dai_commit_write = dai_commit_write, |
| 2338 | |
| 2339 | .dao_get_ctrl_blk = dao_get_ctrl_blk, |
| 2340 | .dao_put_ctrl_blk = dao_put_ctrl_blk, |
| 2341 | .dao_set_spos = dao_set_spos, |
| 2342 | .dao_commit_write = dao_commit_write, |
| 2343 | .dao_get_spos = dao_get_spos, |
| 2344 | |
| 2345 | .daio_mgr_get_ctrl_blk = daio_mgr_get_ctrl_blk, |
| 2346 | .daio_mgr_put_ctrl_blk = daio_mgr_put_ctrl_blk, |
| 2347 | .daio_mgr_enb_dai = daio_mgr_enb_dai, |
| 2348 | .daio_mgr_dsb_dai = daio_mgr_dsb_dai, |
| 2349 | .daio_mgr_enb_dao = daio_mgr_enb_dao, |
| 2350 | .daio_mgr_dsb_dao = daio_mgr_dsb_dao, |
| 2351 | .daio_mgr_dao_init = daio_mgr_dao_init, |
| 2352 | .daio_mgr_set_imaparc = daio_mgr_set_imaparc, |
| 2353 | .daio_mgr_set_imapnxt = daio_mgr_set_imapnxt, |
| 2354 | .daio_mgr_set_imapaddr = daio_mgr_set_imapaddr, |
| 2355 | .daio_mgr_commit_write = daio_mgr_commit_write, |
Takashi Iwai | bc5304b | 2009-07-20 13:41:35 +0200 | [diff] [blame] | 2356 | |
| 2357 | .set_timer_irq = set_timer_irq, |
| 2358 | .set_timer_tick = set_timer_tick, |
| 2359 | .get_wc = get_wc, |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 2360 | }; |
| 2361 | |
| 2362 | int __devinit create_20k2_hw_obj(struct hw **rhw) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2363 | { |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 2364 | struct hw20k2 *hw20k2; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2365 | |
| 2366 | *rhw = NULL; |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 2367 | hw20k2 = kzalloc(sizeof(*hw20k2), GFP_KERNEL); |
| 2368 | if (!hw20k2) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2369 | return -ENOMEM; |
| 2370 | |
Takashi Iwai | d362af6 | 2009-06-08 15:31:22 +0200 | [diff] [blame] | 2371 | hw20k2->hw = ct20k2_preset; |
| 2372 | *rhw = &hw20k2->hw; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 2373 | |
| 2374 | return 0; |
| 2375 | } |
| 2376 | |
| 2377 | int destroy_20k2_hw_obj(struct hw *hw) |
| 2378 | { |
| 2379 | if (hw->io_base) |
| 2380 | hw_card_shutdown(hw); |
| 2381 | |
| 2382 | kfree(hw); |
| 2383 | return 0; |
| 2384 | } |