ALSA: ctxfi - Clean up / optimize
[linux-2.6.git] / sound / pci / ctxfi / cthw20k2.c
index cdcb75cc33b68d4f6cab4140f61539b1dca2b41c..041199fbae160dd0247f758f808dd636bf5f4dc7 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/string.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
+#include <linux/delay.h>
 
 #define CT_XFI_DMA_MASK                DMA_BIT_MASK(32) /* 32 bits */
 
@@ -1143,7 +1144,7 @@ static int hw_daio_init(struct hw *hw, const struct daio_conf *info)
                hw_write_20kx(hw, AUDIO_IO_TX_BLRCLK, 0x11111111);
                hw_write_20kx(hw, AUDIO_IO_RX_BLRCLK, 0);
        } else {
-               printk(KERN_ALERT "ERROR!!! Invalid sampling rate!!!\n");
+               printk(KERN_ALERT "ctxfi: ERROR!!! Invalid sampling rate!!!\n");
                return -EINVAL;
        }
 
@@ -1196,24 +1197,16 @@ static int hw_trn_init(struct hw *hw, const struct trn_conf *info)
 
        /* Set up device page table */
        if ((~0UL) == info->vm_pgt_phys) {
-               printk(KERN_ALERT "Wrong device page table page address!!!\n");
+               printk(KERN_ALERT "ctxfi: "
+                      "Wrong device page table page address!!!\n");
                return -1;
        }
 
        vmctl = 0x80000C0F;  /* 32-bit, 4k-size page */
-#if BITS_PER_LONG == 64
-       ptp_phys_low = info->vm_pgt_phys & ((1UL<<32)-1);
-       ptp_phys_high = (info->vm_pgt_phys>>32) & ((1UL<<32)-1);
-       vmctl |= (3<<8);
-#elif BITS_PER_LONG == 32
-       ptp_phys_low = info->vm_pgt_phys & (~0UL);
-       ptp_phys_high = 0;
-#else
-#      error "Unknown BITS_PER_LONG!"
-#endif
-#if PAGE_SIZE == 8192
-#      error "Don't support 8k-page!"
-#endif
+       ptp_phys_low = (u32)info->vm_pgt_phys;
+       ptp_phys_high = upper_32_bits(info->vm_pgt_phys);
+       if (sizeof(void *) == 8) /* 64bit address */
+               vmctl |= (3 << 8);
        /* Write page table physical address to all PTPAL registers */
        for (i = 0; i < 64; i++) {
                hw_write_20kx(hw, VMEM_PTPAL+(16*i), ptp_phys_low);
@@ -1313,7 +1306,7 @@ static int hw_pll_init(struct hw *hw, unsigned int rsr)
                break;
        }
        if (i >= 1000) {
-               printk(KERN_ALERT "PLL initialization failed!!!\n");
+               printk(KERN_ALERT "ctxfi: PLL initialization failed!!!\n");
                return -EBUSY;
        }
 
@@ -1337,7 +1330,7 @@ static int hw_auto_init(struct hw *hw)
                        break;
        }
        if (!get_field(gctl, GCTL_AID)) {
-               printk(KERN_ALERT "Card Auto-init failed!!!\n");
+               printk(KERN_ALERT "ctxfi: Card Auto-init failed!!!\n");
                return -EBUSY;
        }
 
@@ -1761,7 +1754,7 @@ static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
        /* Initialize I2C */
        err = I2CInit(hw, 0x1A, 1, 1);
        if (err < 0) {
-               printk(KERN_ALERT "Failure to acquire I2C!!!\n");
+               printk(KERN_ALERT "ctxfi: Failure to acquire I2C!!!\n");
                goto error;
        }
 
@@ -1781,7 +1774,7 @@ static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
                I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_MMC, 0x0A),
                                                MAKE_WM8775_DATA(0x0A));
        } else {
-               printk(KERN_ALERT "Invalid master sampling "
+               printk(KERN_ALERT "ctxfi: Invalid master sampling "
                                  "rate (msr %d)!!!\n", info->msr);
                err = -EINVAL;
                goto error;
@@ -1819,7 +1812,7 @@ static int hw_adc_init(struct hw *hw, const struct adc_conf *info)
                I2CWrite(hw, MAKE_WM8775_ADDR(WM8775_AADCR, 0xCF),
                                MAKE_WM8775_DATA(0xCF)); /* No boost */
        } else {
-               printk(KERN_ALERT "ERROR!!! Invalid input mux!!!\n");
+               printk(KERN_ALERT "ctxfi: ERROR!!! Invalid input mux!!!\n");
                err = -EINVAL;
                goto error;
        }
@@ -1851,7 +1844,7 @@ static int hw_card_start(struct hw *hw)
        dma_mask = CT_XFI_DMA_MASK;
        if (pci_set_dma_mask(pci, dma_mask) < 0 ||
            pci_set_consistent_dma_mask(pci, dma_mask) < 0) {
-               printk(KERN_ERR "architecture does not support PCI "
+               printk(KERN_ERR "ctxfi: architecture does not support PCI "
                "busmaster DMA with mask 0x%x\n", dma_mask);
                err = -ENXIO;
                goto error1;
@@ -2013,7 +2006,103 @@ static void hw_write_20kx(struct hw *hw, u32 reg, u32 data)
        writel(data, (void *)(hw->mem_base + reg));
 }
 
-int create_20k2_hw_obj(struct hw **rhw)
+static struct hw ct20k2_preset __devinitdata = {
+       .irq = -1,
+
+       .card_init = hw_card_init,
+       .card_stop = hw_card_stop,
+       .pll_init = hw_pll_init,
+       .is_adc_source_selected = hw_is_adc_input_selected,
+       .select_adc_source = hw_adc_input_select,
+       .have_digit_io_switch = hw_have_digit_io_switch,
+
+       .src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk,
+       .src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk,
+       .src_mgr_get_ctrl_blk = src_mgr_get_ctrl_blk,
+       .src_mgr_put_ctrl_blk = src_mgr_put_ctrl_blk,
+       .src_set_state = src_set_state,
+       .src_set_bm = src_set_bm,
+       .src_set_rsr = src_set_rsr,
+       .src_set_sf = src_set_sf,
+       .src_set_wr = src_set_wr,
+       .src_set_pm = src_set_pm,
+       .src_set_rom = src_set_rom,
+       .src_set_vo = src_set_vo,
+       .src_set_st = src_set_st,
+       .src_set_ie = src_set_ie,
+       .src_set_ilsz = src_set_ilsz,
+       .src_set_bp = src_set_bp,
+       .src_set_cisz = src_set_cisz,
+       .src_set_ca = src_set_ca,
+       .src_set_sa = src_set_sa,
+       .src_set_la = src_set_la,
+       .src_set_pitch = src_set_pitch,
+       .src_set_dirty = src_set_dirty,
+       .src_set_clear_zbufs = src_set_clear_zbufs,
+       .src_set_dirty_all = src_set_dirty_all,
+       .src_commit_write = src_commit_write,
+       .src_get_ca = src_get_ca,
+       .src_get_dirty = src_get_dirty,
+       .src_dirty_conj_mask = src_dirty_conj_mask,
+       .src_mgr_enbs_src = src_mgr_enbs_src,
+       .src_mgr_enb_src = src_mgr_enb_src,
+       .src_mgr_dsb_src = src_mgr_dsb_src,
+       .src_mgr_commit_write = src_mgr_commit_write,
+
+       .srcimp_mgr_get_ctrl_blk = srcimp_mgr_get_ctrl_blk,
+       .srcimp_mgr_put_ctrl_blk = srcimp_mgr_put_ctrl_blk,
+       .srcimp_mgr_set_imaparc = srcimp_mgr_set_imaparc,
+       .srcimp_mgr_set_imapuser = srcimp_mgr_set_imapuser,
+       .srcimp_mgr_set_imapnxt = srcimp_mgr_set_imapnxt,
+       .srcimp_mgr_set_imapaddr = srcimp_mgr_set_imapaddr,
+       .srcimp_mgr_commit_write = srcimp_mgr_commit_write,
+
+       .amixer_rsc_get_ctrl_blk = amixer_rsc_get_ctrl_blk,
+       .amixer_rsc_put_ctrl_blk = amixer_rsc_put_ctrl_blk,
+       .amixer_mgr_get_ctrl_blk = amixer_mgr_get_ctrl_blk,
+       .amixer_mgr_put_ctrl_blk = amixer_mgr_put_ctrl_blk,
+       .amixer_set_mode = amixer_set_mode,
+       .amixer_set_iv = amixer_set_iv,
+       .amixer_set_x = amixer_set_x,
+       .amixer_set_y = amixer_set_y,
+       .amixer_set_sadr = amixer_set_sadr,
+       .amixer_set_se = amixer_set_se,
+       .amixer_set_dirty = amixer_set_dirty,
+       .amixer_set_dirty_all = amixer_set_dirty_all,
+       .amixer_commit_write = amixer_commit_write,
+       .amixer_get_y = amixer_get_y,
+       .amixer_get_dirty = amixer_get_dirty,
+
+       .dai_get_ctrl_blk = dai_get_ctrl_blk,
+       .dai_put_ctrl_blk = dai_put_ctrl_blk,
+       .dai_srt_set_srco = dai_srt_set_srco,
+       .dai_srt_set_srcm = dai_srt_set_srcm,
+       .dai_srt_set_rsr = dai_srt_set_rsr,
+       .dai_srt_set_drat = dai_srt_set_drat,
+       .dai_srt_set_ec = dai_srt_set_ec,
+       .dai_srt_set_et = dai_srt_set_et,
+       .dai_commit_write = dai_commit_write,
+
+       .dao_get_ctrl_blk = dao_get_ctrl_blk,
+       .dao_put_ctrl_blk = dao_put_ctrl_blk,
+       .dao_set_spos = dao_set_spos,
+       .dao_commit_write = dao_commit_write,
+       .dao_get_spos = dao_get_spos,
+
+       .daio_mgr_get_ctrl_blk = daio_mgr_get_ctrl_blk,
+       .daio_mgr_put_ctrl_blk = daio_mgr_put_ctrl_blk,
+       .daio_mgr_enb_dai = daio_mgr_enb_dai,
+       .daio_mgr_dsb_dai = daio_mgr_dsb_dai,
+       .daio_mgr_enb_dao = daio_mgr_enb_dao,
+       .daio_mgr_dsb_dao = daio_mgr_dsb_dao,
+       .daio_mgr_dao_init = daio_mgr_dao_init,
+       .daio_mgr_set_imaparc = daio_mgr_set_imaparc,
+       .daio_mgr_set_imapnxt = daio_mgr_set_imapnxt,
+       .daio_mgr_set_imapaddr = daio_mgr_set_imapaddr,
+       .daio_mgr_commit_write = daio_mgr_commit_write,
+};
+
+int __devinit create_20k2_hw_obj(struct hw **rhw)
 {
        struct hw *hw;
 
@@ -2022,102 +2111,7 @@ int create_20k2_hw_obj(struct hw **rhw)
        if (NULL == hw)
                return -ENOMEM;
 
-       hw->io_base = 0;
-       hw->mem_base = (unsigned long)NULL;
-       hw->irq = -1;
-
-       hw->card_init = hw_card_init;
-       hw->card_stop = hw_card_stop;
-       hw->pll_init = hw_pll_init;
-       hw->is_adc_source_selected = hw_is_adc_input_selected;
-       hw->select_adc_source = hw_adc_input_select;
-       hw->have_digit_io_switch = hw_have_digit_io_switch;
-
-       hw->src_rsc_get_ctrl_blk = src_get_rsc_ctrl_blk;
-       hw->src_rsc_put_ctrl_blk = src_put_rsc_ctrl_blk;
-       hw->src_mgr_get_ctrl_blk = src_mgr_get_ctrl_blk;
-       hw->src_mgr_put_ctrl_blk = src_mgr_put_ctrl_blk;
-       hw->src_set_state = src_set_state;
-       hw->src_set_bm = src_set_bm;
-       hw->src_set_rsr = src_set_rsr;
-       hw->src_set_sf = src_set_sf;
-       hw->src_set_wr = src_set_wr;
-       hw->src_set_pm = src_set_pm;
-       hw->src_set_rom = src_set_rom;
-       hw->src_set_vo = src_set_vo;
-       hw->src_set_st = src_set_st;
-       hw->src_set_ie = src_set_ie;
-       hw->src_set_ilsz = src_set_ilsz;
-       hw->src_set_bp = src_set_bp;
-       hw->src_set_cisz = src_set_cisz;
-       hw->src_set_ca = src_set_ca;
-       hw->src_set_sa = src_set_sa;
-       hw->src_set_la = src_set_la;
-       hw->src_set_pitch = src_set_pitch;
-       hw->src_set_dirty = src_set_dirty;
-       hw->src_set_clear_zbufs = src_set_clear_zbufs;
-       hw->src_set_dirty_all = src_set_dirty_all;
-       hw->src_commit_write = src_commit_write;
-       hw->src_get_ca = src_get_ca;
-       hw->src_get_dirty = src_get_dirty;
-       hw->src_dirty_conj_mask = src_dirty_conj_mask;
-       hw->src_mgr_enbs_src = src_mgr_enbs_src;
-       hw->src_mgr_enb_src = src_mgr_enb_src;
-       hw->src_mgr_dsb_src = src_mgr_dsb_src;
-       hw->src_mgr_commit_write = src_mgr_commit_write;
-
-       hw->srcimp_mgr_get_ctrl_blk = srcimp_mgr_get_ctrl_blk;
-       hw->srcimp_mgr_put_ctrl_blk = srcimp_mgr_put_ctrl_blk;
-       hw->srcimp_mgr_set_imaparc = srcimp_mgr_set_imaparc;
-       hw->srcimp_mgr_set_imapuser = srcimp_mgr_set_imapuser;
-       hw->srcimp_mgr_set_imapnxt = srcimp_mgr_set_imapnxt;
-       hw->srcimp_mgr_set_imapaddr = srcimp_mgr_set_imapaddr;
-       hw->srcimp_mgr_commit_write = srcimp_mgr_commit_write;
-
-       hw->amixer_rsc_get_ctrl_blk = amixer_rsc_get_ctrl_blk;
-       hw->amixer_rsc_put_ctrl_blk = amixer_rsc_put_ctrl_blk;
-       hw->amixer_mgr_get_ctrl_blk = amixer_mgr_get_ctrl_blk;
-       hw->amixer_mgr_put_ctrl_blk = amixer_mgr_put_ctrl_blk;
-       hw->amixer_set_mode = amixer_set_mode;
-       hw->amixer_set_iv = amixer_set_iv;
-       hw->amixer_set_x = amixer_set_x;
-       hw->amixer_set_y = amixer_set_y;
-       hw->amixer_set_sadr = amixer_set_sadr;
-       hw->amixer_set_se = amixer_set_se;
-       hw->amixer_set_dirty = amixer_set_dirty;
-       hw->amixer_set_dirty_all = amixer_set_dirty_all;
-       hw->amixer_commit_write = amixer_commit_write;
-       hw->amixer_get_y = amixer_get_y;
-       hw->amixer_get_dirty = amixer_get_dirty;
-
-       hw->dai_get_ctrl_blk = dai_get_ctrl_blk;
-       hw->dai_put_ctrl_blk = dai_put_ctrl_blk;
-       hw->dai_srt_set_srco = dai_srt_set_srco;
-       hw->dai_srt_set_srcm = dai_srt_set_srcm;
-       hw->dai_srt_set_rsr = dai_srt_set_rsr;
-       hw->dai_srt_set_drat = dai_srt_set_drat;
-       hw->dai_srt_set_ec = dai_srt_set_ec;
-       hw->dai_srt_set_et = dai_srt_set_et;
-       hw->dai_commit_write = dai_commit_write;
-
-       hw->dao_get_ctrl_blk = dao_get_ctrl_blk;
-       hw->dao_put_ctrl_blk = dao_put_ctrl_blk;
-       hw->dao_set_spos = dao_set_spos;
-       hw->dao_commit_write = dao_commit_write;
-       hw->dao_get_spos = dao_get_spos;
-
-       hw->daio_mgr_get_ctrl_blk = daio_mgr_get_ctrl_blk;
-       hw->daio_mgr_put_ctrl_blk = daio_mgr_put_ctrl_blk;
-       hw->daio_mgr_enb_dai = daio_mgr_enb_dai;
-       hw->daio_mgr_dsb_dai = daio_mgr_dsb_dai;
-       hw->daio_mgr_enb_dao = daio_mgr_enb_dao;
-       hw->daio_mgr_dsb_dao = daio_mgr_dsb_dao;
-       hw->daio_mgr_dao_init = daio_mgr_dao_init;
-       hw->daio_mgr_set_imaparc = daio_mgr_set_imaparc;
-       hw->daio_mgr_set_imapnxt = daio_mgr_set_imapnxt;
-       hw->daio_mgr_set_imapaddr = daio_mgr_set_imapaddr;
-       hw->daio_mgr_commit_write = daio_mgr_commit_write;
-
+       *hw = ct20k2_preset;
        *rhw = hw;
 
        return 0;