18 #include <linux/types.h>
19 #include <linux/slab.h>
20 #include <linux/pci.h>
22 #include <linux/string.h>
23 #include <linux/kernel.h>
29 #if BITS_PER_LONG == 32
30 #define CT_XFI_DMA_MASK DMA_BIT_MASK(32)
32 #define CT_XFI_DMA_MASK DMA_BIT_MASK(64)
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
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
78 #define SRCCA_CA 0x0FFFFFFF
79 #define SRCCA_RS 0xE0000000
81 #define SRCSA_SA 0x0FFFFFFF
83 #define SRCLA_LA 0x0FFFFFFF
87 #define MPRLH_PITCH 0xFFFFFFFF
138 #define SRCAIM_ARC 0x00000FFF
139 #define SRCAIM_NXT 0x00FF0000
140 #define SRCAIM_SRC 0xFF000000
165 static int src_get_rsc_ctrl_blk(
void **rblk)
179 static int src_put_rsc_ctrl_blk(
void *blk)
186 static int src_set_state(
void *blk,
unsigned int state)
195 static int src_set_bm(
void *blk,
unsigned int bm)
204 static int src_set_rsr(
void *blk,
unsigned int rsr)
213 static int src_set_sf(
void *blk,
unsigned int sf)
222 static int src_set_wr(
void *blk,
unsigned int wr)
231 static int src_set_pm(
void *blk,
unsigned int pm)
240 static int src_set_rom(
void *blk,
unsigned int rom)
249 static int src_set_vo(
void *blk,
unsigned int vo)
258 static int src_set_st(
void *blk,
unsigned int st)
267 static int src_set_ie(
void *blk,
unsigned int ie)
276 static int src_set_ilsz(
void *blk,
unsigned int ilsz)
285 static int src_set_bp(
void *blk,
unsigned int bp)
294 static int src_set_cisz(
void *blk,
unsigned int cisz)
303 static int src_set_ca(
void *blk,
unsigned int ca)
312 static int src_set_sa(
void *blk,
unsigned int sa)
321 static int src_set_la(
void *blk,
unsigned int la)
330 static int src_set_pitch(
void *blk,
unsigned int pitch)
339 static int src_set_clear_zbufs(
void *blk,
unsigned int clear)
345 static int src_set_dirty(
void *blk,
unsigned int flags)
351 static int src_set_dirty_all(
void *blk)
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
362 static unsigned int src_param_pitch_mixer(
unsigned int src_idx)
369 static int src_commit_write(
struct hw *
hw,
unsigned int idx,
void *blk)
376 for (i = 0; i < 8; i++)
377 hw_write_20kx(hw,
SRC_UPZ+idx*0x100+i*0x4, 0);
379 for (i = 0; i < 4; i++)
380 hw_write_20kx(hw,
SRC_DN0Z+idx*0x100+i*0x4, 0);
382 for (i = 0; i < 8; i++)
383 hw_write_20kx(hw,
SRC_DN1Z+idx*0x100+i*0x4, 0);
392 unsigned int pm_idx = src_param_pitch_mixer(idx);
399 hw_write_20kx(hw,
SRC_SA+idx*0x100, ctl->
sa);
403 hw_write_20kx(hw,
SRC_LA+idx*0x100, ctl->
la);
407 hw_write_20kx(hw,
SRC_CA+idx*0x100, ctl->
ca);
412 hw_write_20kx(hw,
SRC_CF+idx*0x100, 0x0);
415 hw_write_20kx(hw,
SRC_CCR+idx*0x100, ctl->
ccr);
419 hw_write_20kx(hw,
SRC_CTL+idx*0x100, ctl->
ctl);
426 static int src_get_ca(
struct hw *hw,
unsigned int idx,
void *blk)
430 ctl->
ca = hw_read_20kx(hw,
SRC_CA+idx*0x100);
436 static unsigned int src_get_dirty(
void *blk)
441 static unsigned int src_dirty_conj_mask(
void)
446 static int src_mgr_enbs_src(
void *blk,
unsigned int idx)
454 static int src_mgr_enb_src(
void *blk,
unsigned int idx)
461 static int src_mgr_dsb_src(
void *blk,
unsigned int idx)
468 static int src_mgr_commit_write(
struct hw *hw,
void *blk)
481 for (i = 0; i < 8; i++) {
483 hw_write_20kx(hw,
SRC_ENB+(i*0x100), ctl->
enb[i]);
491 static int src_mgr_get_ctrl_blk(
void **rblk)
505 static int src_mgr_put_ctrl_blk(
void *blk)
512 static int srcimp_mgr_get_ctrl_blk(
void **rblk)
526 static int srcimp_mgr_put_ctrl_blk(
void *blk)
533 static int srcimp_mgr_set_imaparc(
void *blk,
unsigned int slot)
542 static int srcimp_mgr_set_imapuser(
void *blk,
unsigned int user)
551 static int srcimp_mgr_set_imapnxt(
void *blk,
unsigned int next)
560 static int srcimp_mgr_set_imapaddr(
void *blk,
unsigned int addr)
567 static int srcimp_mgr_commit_write(
struct hw *hw,
void *blk)
584 #define AMOPLO_M 0x00000003
585 #define AMOPLO_IV 0x00000004
586 #define AMOPLO_X 0x0003FFF0
587 #define AMOPLO_Y 0xFFFC0000
589 #define AMOPHI_SADR 0x000000FF
590 #define AMOPHI_SE 0x80000000
609 static int amixer_set_mode(
void *blk,
unsigned int mode)
618 static int amixer_set_iv(
void *blk,
unsigned int iv)
627 static int amixer_set_x(
void *blk,
unsigned int x)
636 static int amixer_set_y(
void *blk,
unsigned int y)
645 static int amixer_set_sadr(
void *blk,
unsigned int sadr)
654 static int amixer_set_se(
void *blk,
unsigned int se)
663 static int amixer_set_dirty(
void *blk,
unsigned int flags)
669 static int amixer_set_dirty_all(
void *blk)
675 static int amixer_commit_write(
struct hw *hw,
unsigned int idx,
void *blk)
689 static int amixer_get_y(
void *blk)
696 static unsigned int amixer_get_dirty(
void *blk)
701 static int amixer_rsc_get_ctrl_blk(
void **rblk)
715 static int amixer_rsc_put_ctrl_blk(
void *blk)
722 static int amixer_mgr_get_ctrl_blk(
void **rblk)
729 static int amixer_mgr_put_ctrl_blk(
void *blk)
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
762 #define AIM_ARC 0x00000FFF
763 #define AIM_NXT 0x007F0000
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
803 #define ARXCTL_EN 0x00000001
824 static int dai_srt_set_srco(
void *blk,
unsigned int src)
833 static int dai_srt_set_srcm(
void *blk,
unsigned int src)
842 static int dai_srt_set_rsr(
void *blk,
unsigned int rsr)
851 static int dai_srt_set_drat(
void *blk,
unsigned int drat)
860 static int dai_srt_set_ec(
void *blk,
unsigned int ec)
869 static int dai_srt_set_et(
void *blk,
unsigned int et)
878 static int dai_commit_write(
struct hw *hw,
unsigned int idx,
void *blk)
890 static int dai_get_ctrl_blk(
void **rblk)
904 static int dai_put_ctrl_blk(
void *blk)
911 static int dao_set_spos(
void *blk,
unsigned int spos)
918 static int dao_commit_write(
struct hw *hw,
unsigned int idx,
void *blk)
934 static int dao_get_spos(
void *blk,
unsigned int *
spos)
940 static int dao_get_ctrl_blk(
void **rblk)
954 static int dao_put_ctrl_blk(
void *blk)
961 static int daio_mgr_enb_dai(
void *blk,
unsigned int idx)
970 static int daio_mgr_dsb_dai(
void *blk,
unsigned int idx)
980 static int daio_mgr_enb_dao(
void *blk,
unsigned int idx)
989 static int daio_mgr_dsb_dao(
void *blk,
unsigned int idx)
998 static int daio_mgr_dao_init(
void *blk,
unsigned int idx,
unsigned int conf)
1004 switch ((conf & 0x7)) {
1027 ((conf >> 3) & 0x1) ? 0 : 0);
1036 static int daio_mgr_set_imaparc(
void *blk,
unsigned int slot)
1045 static int daio_mgr_set_imapnxt(
void *blk,
unsigned int next)
1054 static int daio_mgr_set_imapaddr(
void *blk,
unsigned int addr)
1061 static int daio_mgr_commit_write(
struct hw *hw,
void *blk)
1067 for (i = 0; i < 8; i++) {
1068 if ((ctl->
dirty.
bf.atxctl & (0x1 << i))) {
1071 ctl->
dirty.
bf.atxctl &= ~(0x1 <<
i);
1074 if ((ctl->
dirty.
bf.arxctl & (0x1 << i))) {
1077 ctl->
dirty.
bf.arxctl &= ~(0x1 <<
i);
1090 static int daio_mgr_get_ctrl_blk(
struct hw *hw,
void **rblk)
1100 for (i = 0; i < 8; i++) {
1110 static int daio_mgr_put_ctrl_blk(
void *blk)
1118 static int set_timer_irq(
struct hw *hw,
int enable)
1120 hw_write_20kx(hw,
GIE, enable ?
IT_INT : 0);
1124 static int set_timer_tick(
struct hw *hw,
unsigned int ticks)
1128 hw_write_20kx(hw,
TIMR, ticks);
1132 static unsigned int get_wc(
struct hw *hw)
1134 return hw_read_20kx(hw,
WC);
1144 unsigned char input;
1156 static int hw_daio_init(
struct hw *hw,
const struct daio_conf *
info)
1163 if (1 == info->
msr) {
1167 }
else if (2 == info->
msr) {
1194 for (i = 0; i < 8; i++) {
1226 if (2 == info->
msr) {
1229 }
else if (4 == info->
msr) {
1241 static int hw_trn_init(
struct hw *hw,
const struct trn_conf *info)
1244 u32 ptp_phys_low, ptp_phys_high;
1250 "Wrong device page table page address!!!\n");
1257 if (
sizeof(
void *) == 8)
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);
1265 hw_write_20kx(hw,
VMEM_CTL, vmctl);
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
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
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
1310 static int hw_pll_init(
struct hw *hw,
unsigned int rsr)
1312 unsigned int pllenb;
1313 unsigned int pllctl;
1314 unsigned int pllstat;
1318 hw_write_20kx(hw,
PLL_ENB, pllenb);
1319 pllctl = 0x20C00000;
1323 hw_write_20kx(hw,
PLL_CTL, pllctl);
1326 pllctl = hw_read_20kx(hw,
PLL_CTL);
1328 hw_write_20kx(hw,
PLL_CTL, pllctl);
1331 for (i = 0; i < 1000; i++) {
1332 pllstat = hw_read_20kx(hw,
PLL_STAT);
1362 static int hw_auto_init(
struct hw *hw)
1373 for (i = 0; i < 400000; i++) {
1388 #define CS4382_MC1 0x1
1389 #define CS4382_MC2 0x2
1390 #define CS4382_MC3 0x3
1391 #define CS4382_FC 0x4
1392 #define CS4382_IC 0x5
1393 #define CS4382_XC1 0x6
1394 #define CS4382_VCA1 0x7
1395 #define CS4382_VCB1 0x8
1396 #define CS4382_XC2 0x9
1397 #define CS4382_VCA2 0xA
1398 #define CS4382_VCB2 0xB
1399 #define CS4382_XC3 0xC
1400 #define CS4382_VCA3 0xD
1401 #define CS4382_VCB3 0xE
1402 #define CS4382_XC4 0xF
1403 #define CS4382_VCA4 0x10
1404 #define CS4382_VCB4 0x11
1405 #define CS4382_CREV 0x12
1408 #define STATE_LOCKED 0x00
1409 #define STATE_UNLOCKED 0xAA
1410 #define DATA_READY 0x800000
1411 #define DATA_ABORT 0x10000
1413 #define I2C_STATUS_DCM 0x00000001
1414 #define I2C_STATUS_BC 0x00000006
1415 #define I2C_STATUS_APD 0x00000008
1416 #define I2C_STATUS_AB 0x00010000
1417 #define I2C_STATUS_DR 0x00800000
1419 #define I2C_ADDRESS_PTAD 0x0000FFFF
1420 #define I2C_ADDRESS_SLAD 0x007F0000
1447 static int hw20k2_i2c_unlock_full_access(
struct hw *hw)
1449 u8 UnlockKeySequence_FLASH_FULLACCESS_MODE[2] = {0xB3, 0xD4};
1453 UnlockKeySequence_FLASH_FULLACCESS_MODE[0]);
1455 UnlockKeySequence_FLASH_FULLACCESS_MODE[1]);
1463 static int hw20k2_i2c_lock_chip(
struct hw *hw)
1479 unsigned int i2c_addr;
1481 err = hw20k2_i2c_unlock_full_access(hw);
1503 static int hw20k2_i2c_uninit(
struct hw *hw)
1506 unsigned int i2c_addr;
1519 return hw20k2_i2c_lock_chip(hw);
1522 static int hw20k2_i2c_wait_data_ready(
struct hw *hw)
1534 static int hw20k2_i2c_read(
struct hw *hw,
u16 addr,
u32 *datap)
1536 struct hw20k2 *hw20k2 = (
struct hw20k2 *)hw;
1543 if (!hw20k2_i2c_wait_data_ready(hw))
1547 if (!hw20k2_i2c_wait_data_ready(hw))
1552 if (!hw20k2_i2c_wait_data_ready(hw))
1560 static int hw20k2_i2c_write(
struct hw *hw,
u16 addr,
u32 data)
1562 struct hw20k2 *hw20k2 = (
struct hw20k2 *)hw;
1573 hw20k2_i2c_wait_data_ready(hw);
1576 hw20k2_i2c_wait_data_ready(hw);
1580 hw20k2_i2c_wait_data_ready(hw);
1585 static void hw_dac_stop(
struct hw *hw)
1594 static void hw_dac_start(
struct hw *hw)
1603 static void hw_dac_reset(
struct hw *hw)
1609 static int hw_dac_init(
struct hw *hw,
const struct dac_conf *info)
1641 else if (2 == info->
msr)
1655 err = hw20k2_i2c_init(hw, 0x18, 1, 1);
1659 for (i = 0; i < 2; i++) {
1716 if (
memcmp(&cs_read, &cs_def,
sizeof(cs_read)))
1729 if (1 == info->
msr) {
1734 }
else if (2 == info->
msr) {
1749 hw20k2_i2c_uninit(hw);
1754 #define MAKE_WM8775_ADDR(addr, data) (u32)(((addr<<1)&0xFE)|((data>>8)&0x1))
1755 #define MAKE_WM8775_DATA(data) (u32)(data&0xFF)
1757 #define WM8775_IC 0x0B
1758 #define WM8775_MMC 0x0C
1759 #define WM8775_AADCL 0x0E
1760 #define WM8775_AADCR 0x0F
1761 #define WM8775_ADCMC 0x15
1762 #define WM8775_RESET 0x17
1764 static int hw_is_adc_input_selected(
struct hw *hw,
enum ADCSRC type)
1775 data = (data & (0x1 << 14)) ? 1 : 0;
1778 data = (data & (0x1 << 14)) ? 0 : 1;
1786 #define MIC_BOOST_0DB 0xCF
1787 #define MIC_BOOST_STEPS_PER_DB 2
1789 static void hw_wm8775_input_select(
struct hw *hw,
u8 input,
s8 gain_in_db)
1796 adcmc = ((
u32)1 << input) | 0x100;
1801 if (gain_in_db < -103)
1803 if (gain_in_db > 24)
1815 static int hw_adc_input_select(
struct hw *hw,
enum ADCSRC type)
1821 data |= (0x1 << 14);
1823 hw_wm8775_input_select(hw, 0, 20);
1826 data &= ~(0x1 << 14);
1828 hw_wm8775_input_select(hw, 1, 0);
1837 static int hw_adc_init(
struct hw *hw,
const struct adc_conf *info)
1844 data |= (0x1 << 15);
1848 err = hw20k2_i2c_init(hw, 0x1A, 1, 1);
1856 data &= ~(0x1 << 15);
1864 else if (2 == info->
msr)
1873 data |= (0x1 << 15);
1884 if (1 == info->
msr) {
1888 }
else if ((2 == info->
msr) || (4 == info->
msr)) {
1894 "rate (msr %d)!!!\n", info->
msr);
1906 hw_wm8775_input_select(hw, 0, 0);
1911 hw20k2_i2c_uninit(hw);
1919 cap.digit_io_switch = 0;
1927 static int hw_output_switch_get(
struct hw *hw)
1931 switch (data & 0x30) {
1943 static int hw_output_switch_put(
struct hw *hw,
int position)
1947 if (position == hw_output_switch_get(hw))
1952 data |= (0x03 << 11);
1969 data &= ~(0x03 << 11);
1975 static int hw_mic_source_switch_get(
struct hw *hw)
1977 struct hw20k2 *hw20k2 = (
struct hw20k2 *)hw;
1982 static int hw_mic_source_switch_put(
struct hw *hw,
int position)
1984 struct hw20k2 *hw20k2 = (
struct hw20k2 *)hw;
1991 hw_wm8775_input_select(hw, 0, 0);
1994 hw_wm8775_input_select(hw, 1, 0);
1997 hw_wm8775_input_select(hw, 3, 0);
2008 static irqreturn_t ct_20k2_interrupt(
int irq,
void *dev_id)
2013 status = hw_read_20kx(hw,
GIP);
2020 hw_write_20kx(hw,
GIP, status);
2024 static int hw_card_start(
struct hw *hw)
2064 KBUILD_MODNAME, hw);
2087 static int hw_card_stop(
struct hw *hw)
2095 data = hw_read_20kx(hw,
PLL_ENB);
2096 hw_write_20kx(hw,
PLL_ENB, (data & (~0x07)));
2102 static int hw_card_shutdown(
struct hw *hw)
2124 static int hw_card_init(
struct hw *hw,
struct card_conf *info)
2136 err = hw_card_start(hw);
2141 err = hw_pll_init(hw, info->
rsr);
2146 err = hw_auto_init(hw);
2158 hw_write_20kx(hw,
GIE, 0);
2160 hw_write_20kx(hw,
SRC_IP, 0);
2176 err = hw_trn_init(hw, &trn_info);
2180 daio_info.
msr = info->
msr;
2181 err = hw_daio_init(hw, &daio_info);
2185 dac_info.
msr = info->
msr;
2186 err = hw_dac_init(hw, &dac_info);
2190 adc_info.
msr = info->
msr;
2193 err = hw_adc_init(hw, &adc_info);
2204 #ifdef CONFIG_PM_SLEEP
2205 static int hw_suspend(
struct hw *hw)
2218 static int hw_resume(
struct hw *hw,
struct card_conf *info)
2226 return hw_card_init(hw, info);
2230 static u32 hw_read_20kx(
struct hw *hw,
u32 reg)
2235 static void hw_write_20kx(
struct hw *hw,
u32 reg,
u32 data)
2243 .card_init = hw_card_init,
2244 .card_stop = hw_card_stop,
2245 .pll_init = hw_pll_init,
2246 .is_adc_source_selected = hw_is_adc_input_selected,
2247 .select_adc_source = hw_adc_input_select,
2248 .capabilities = hw_capabilities,
2249 .output_switch_get = hw_output_switch_get,
2250 .output_switch_put = hw_output_switch_put,
2251 .mic_source_switch_get = hw_mic_source_switch_get,
2252 .mic_source_switch_put = hw_mic_source_switch_put,
2253 #ifdef CONFIG_PM_SLEEP
2254 .suspend = hw_suspend,
2255 .resume = hw_resume,
2258 .src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk,
2259 .src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk,
2350 struct hw20k2 *hw20k2;
2353 hw20k2 = kzalloc(
sizeof(*hw20k2),
GFP_KERNEL);
2357 hw20k2->
hw = ct20k2_preset;
2366 hw_card_shutdown(hw);