vserver 2.0 rc7
[linux-2.6.git] / drivers / media / dvb / ttpci / budget-patch.c
index 619e87f..8142e26 100644 (file)
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
- * 
+ *
  *
  * the project's page is at http://www.linuxtv.org/dvb/
  */
@@ -55,7 +55,7 @@ static struct pci_device_id pci_tbl[] = {
 /* those lines are for budget-patch to be tried
 ** on a true budget card and observe the
 ** behaviour of VSYNC generated by rps1.
-** this code was shamelessly copy/pasted from budget.c 
+** this code was shamelessly copy/pasted from budget.c
 */
 static void gpio_Set22K (struct budget *budget, int state)
 {
@@ -96,10 +96,10 @@ static void DiseqcSendByte (struct budget *budget, int data)
 
 static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long burst)
 {
-        struct saa7146_dev *dev=budget->dev;
+       struct saa7146_dev *dev=budget->dev;
        int i;
 
-        dprintk(2, "budget: %p\n", budget);
+       dprintk(2, "budget: %p\n", budget);
 
        saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
        mdelay(16);
@@ -123,7 +123,7 @@ static int SendDiSEqCMsg (struct budget *budget, int len, u8 *msg, unsigned long
        return 0;
 }
 
-/* shamelessly copy/pasted from budget.c 
+/* shamelessly copy/pasted from budget.c
 */
 static int budget_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
 {
@@ -151,7 +151,7 @@ static int budget_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_dis
 
        SendDiSEqCMsg (budget, cmd->msg_len, cmd->msg, 0);
 
-        return 0;
+       return 0;
 }
 
 static int budget_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
@@ -173,27 +173,25 @@ static int budget_av7110_send_fw_cmd(struct budget_patch *budget, u16* buf, int
         {
                   ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2*i, 2, (u32) buf[i], 0,0);
                   msleep(5);
-        }                  
+        }
         if (length)
                   ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2, 2, (u32) buf[1], 0,0);
         else
                   ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND + 2, 2, 0, 0,0);
-        msleep(5);     
+        msleep(5);
         ttpci_budget_debiwrite(budget, DEBINOSWAP, COMMAND, 2, (u32) buf[0], 0,0);
         msleep(5);
         return 0;
 }
 
-
 static void av7110_set22k(struct budget_patch *budget, int state)
 {
         u16 buf[2] = {( COMTYPE_AUDIODAC << 8) | (state ? ON22K : OFF22K), 0};
-        
+
         dprintk(2, "budget: %p\n", budget);
         budget_av7110_send_fw_cmd(budget, buf, 2);
 }
 
-
 static int av7110_send_diseqc_msg(struct budget_patch *budget, int len, u8 *msg, int burst)
 {
         int i;
@@ -212,7 +210,7 @@ static int av7110_send_diseqc_msg(struct budget_patch *budget, int len, u8 *msg,
                 buf[3]=burst ? 0x01 : 0x00;
         else
                 buf[3]=0xffff;
-                
+
         for (i=0; i<len; i++)
                 buf[i+4]=msg[i];
 
@@ -225,27 +223,29 @@ static int budget_patch_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t ton
        struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
 
        switch (tone) {
-                case SEC_TONE_ON:
-                        av7110_set22k (budget, 1);
-                        break;
-                case SEC_TONE_OFF:
-                        av7110_set22k (budget, 0);
-                        break;
-                default:
-                        return -EINVAL;
-                }
+       case SEC_TONE_ON:
+               av7110_set22k (budget, 1);
+               break;
+
+       case SEC_TONE_OFF:
+               av7110_set22k (budget, 0);
+               break;
+
+       default:
+               return -EINVAL;
+       }
 
        return 0;
 }
 
 static int budget_patch_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd* cmd)
-        {
+{
        struct budget_patch* budget = (struct budget_patch*) fe->dvb->priv;
 
-                av7110_send_diseqc_msg (budget, cmd->msg_len, cmd->msg, 0);
+       av7110_send_diseqc_msg (budget, cmd->msg_len, cmd->msg, 0);
 
        return 0;
-        }
+}
 
 static int budget_patch_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd)
 {
@@ -254,7 +254,7 @@ static int budget_patch_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_c
        av7110_send_diseqc_msg (budget, 0, NULL, minicmd);
 
        return 0;
-        }
+}
 
 static int alps_bsrv2_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
 {
@@ -350,7 +350,7 @@ static int alps_bsru6_set_symbol_rate(struct dvb_frontend* fe, u32 srate, u32 ra
        stv0299_writereg (fe, 0x20, (ratio >>  8) & 0xff);
        stv0299_writereg (fe, 0x21, (ratio      ) & 0xf0);
 
-        return 0;
+       return 0;
 }
 
 static int alps_bsru6_pll_set(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
@@ -406,7 +406,7 @@ static int grundig_29504_451_pll_set(struct dvb_frontend* fe, struct dvb_fronten
        return 0;
 }
 
-struct tda8083_config grundig_29504_451_config = {
+static struct tda8083_config grundig_29504_451_config = {
        .demod_address = 0x68,
        .pll_set = grundig_29504_451_pll_set,
 };
@@ -453,7 +453,7 @@ static void frontend_init(struct budget_patch* budget)
                       budget->dev->pci->subsystem_vendor,
                       budget->dev->pci->subsystem_device);
        } else {
-               if (dvb_register_frontend(budget->dvb_adapter, budget->dvb_frontend)) {
+               if (dvb_register_frontend(&budget->dvb_adapter, budget->dvb_frontend)) {
                        printk("budget-av: Frontend registration failed!\n");
                        if (budget->dvb_frontend->ops->release)
                                budget->dvb_frontend->ops->release(budget->dvb_frontend);
@@ -498,7 +498,7 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
         saa7146_write(dev, CLIP_FORMAT_CTRL, 0);                // r78
         // Set HPS prescaler for port B input
         saa7146_write(dev, HPS_CTRL, (1<<30) | (0<<29) | (1<<28) | (0<<12) );
-        saa7146_write(dev, MC2, 
+        saa7146_write(dev, MC2,
           0 * (MASK_08 | MASK_24)  |   // BRS control
           0 * (MASK_09 | MASK_25)  |   // a
           0 * (MASK_10 | MASK_26)  |   // b
@@ -512,15 +512,15 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
         // RPS1 timeout disable
         saa7146_write(dev, RPS_TOV1, 0);
 
-       // code for autodetection 
+       // code for autodetection
        // will wait for VBI_B event (vertical blank at port B)
        // and will reset GPIO3 after VBI_B is detected.
        // (GPIO3 should be raised high by CPU to
-       // test if GPIO3 will generate vertical blank signal 
+       // test if GPIO3 will generate vertical blank signal
        // in budget patch GPIO3 is connected to VSYNC_B
        count = 0;
 #if 0
-       WRITE_RPS1(cpu_to_le32(CMD_UPLOAD | 
+       WRITE_RPS1(cpu_to_le32(CMD_UPLOAD |
          MASK_10 | MASK_09 | MASK_08 | MASK_06 | MASK_05 | MASK_04 | MASK_03 | MASK_02 ));
 #endif
         WRITE_RPS1(cpu_to_le32(CMD_PAUSE | EVT_VBI_B));
@@ -557,7 +557,7 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
         saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI);
        mdelay(150);
 
-       
+
        if( (saa7146_read(dev, GPIO_CTRL) & 0x10000000) == 0)
                detected = 1;
 
@@ -570,51 +570,51 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
        if(detected == 0)
                 printk("budget-patch not detected or saa7146 in non-default state.\n"
                        "try enabling ressetting of 7146 with MASK_31 in MC1 register\n");
-                
+
        else
                 printk("BUDGET-PATCH DETECTED.\n");
 
 
 /*      OLD (Original design by Roberto Deza):
-**      This code will setup the SAA7146_RPS1 to generate a square 
-**      wave on GPIO3, changing when a field (TS_HEIGHT/2 "lines" of 
-**      TS_WIDTH packets) has been acquired on SAA7146_D1B video port; 
-**      then, this GPIO3 output which is connected to the D1B_VSYNC 
-**      input, will trigger the acquisition of the alternate field 
+**      This code will setup the SAA7146_RPS1 to generate a square
+**      wave on GPIO3, changing when a field (TS_HEIGHT/2 "lines" of
+**      TS_WIDTH packets) has been acquired on SAA7146_D1B video port;
+**      then, this GPIO3 output which is connected to the D1B_VSYNC
+**      input, will trigger the acquisition of the alternate field
 **      and so on.
-**      Currently, the TT_budget / WinTV_Nova cards have two ICs 
-**      (74HCT4040, LVC74) for the generation of this VSYNC signal, 
+**      Currently, the TT_budget / WinTV_Nova cards have two ICs
+**      (74HCT4040, LVC74) for the generation of this VSYNC signal,
 **      which seems that can be done perfectly without this :-)).
-*/                                                      
+*/
 
 /*      New design (By Emard)
 **      this rps1 code will copy internal HS event to GPIO3 pin.
 **      GPIO3 is in budget-patch hardware connectd to port B VSYNC
 
 **      HS is an internal event of 7146, accessible with RPS
-**      and temporarily raised high every n lines 
+**      and temporarily raised high every n lines
 **      (n in defined in the RPS_THRESH1 counter threshold)
 **      I think HS is raised high on the beginning of the n-th line
 **      and remains high until this n-th line that triggered
 **      it is completely received. When the receiption of n-th line
 **      ends, HS is lowered.
 
-**      To transmit data over DMA, 7146 needs changing state at 
-**      port B VSYNC pin. Any changing of port B VSYNC will 
+**      To transmit data over DMA, 7146 needs changing state at
+**      port B VSYNC pin. Any changing of port B VSYNC will
 **      cause some DMA data transfer, with more or less packets loss.
-**      It depends on the phase and frequency of VSYNC and 
+**      It depends on the phase and frequency of VSYNC and
 **      the way of 7146 is instructed to trigger on port B (defined
 **      in DD1_INIT register, 3rd nibble from the right valid
 **      numbers are 0-7, see datasheet)
 **
-**      The correct triggering can minimize packet loss, 
+**      The correct triggering can minimize packet loss,
 **      dvbtraffic should give this stable bandwidths:
 **        22k transponder = 33814 kbit/s
 **      27.5k transponder = 38045 kbit/s
-**      by experiment it is found that the best results 
-**      (stable bandwidths and almost no packet loss) 
-**      are obtained using DD1_INIT triggering number 2 
-**      (Va at rising edge of VS Fa = HS x VS-failing forced toggle) 
+**      by experiment it is found that the best results
+**      (stable bandwidths and almost no packet loss)
+**      are obtained using DD1_INIT triggering number 2
+**      (Va at rising edge of VS Fa = HS x VS-failing forced toggle)
 **      and a VSYNC phase that occurs in the middle of DMA transfer
 **      (about byte 188*512=96256 in the DMA window).
 **
@@ -625,20 +625,20 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
 **      increment. That's how the 7146 is programmed to do event
 **      counting in this budget-patch.c
 **      I *think* HPS setting has something to do with the phase
-**      of HS but I cant be 100% sure in that. 
+**      of HS but I cant be 100% sure in that.
 
 **      hardware debug note: a working budget card (including budget patch)
 **      with vpeirq() interrupt setup in mode "0x90" (every 64K) will
 **      generate 3 interrupts per 25-Hz DMA frame of 2*188*512 bytes
 **      and that means 3*25=75 Hz of interrupt freqency, as seen by
-**      watch cat /proc/interrupts 
+**      watch cat /proc/interrupts
 **
 **      If this frequency is 3x lower (and data received in the DMA
 **      buffer don't start with 0x47, but in the middle of packets,
 **      whose lengths appear to be like 188 292 188 104 etc.
-**      this means VSYNC line is not connected in the hardware. 
+**      this means VSYNC line is not connected in the hardware.
 **      (check soldering pcb and pins)
-**      The same behaviour of missing VSYNC can be duplicated on budget 
+**      The same behaviour of missing VSYNC can be duplicated on budget
 **      cards, by seting DD1_INIT trigger mode 7 in 3rd nibble.
 */
 
@@ -681,14 +681,14 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
         // low 16 bits are set to TS_WIDTH bytes (TS_WIDTH=2*188
         //,then RPS_THRESH1
         // should be set to trigger every TS_HEIGHT (512) lines.
-        // 
+        //
         saa7146_write(dev, RPS_THRESH1, (TS_HEIGHT*1) | MASK_12 );
-        
+
         // saa7146_write(dev, RPS_THRESH0, ((TS_HEIGHT/2)<<16) |MASK_28| (TS_HEIGHT/2) |MASK_12 );
         // Enable RPS1                                                  (rFC p33)
         saa7146_write(dev, MC1, (MASK_13 | MASK_29));
 
-       
+
         if (!(budget = kmalloc (sizeof(struct budget_patch), GFP_KERNEL)))
                 return -ENOMEM;
 
@@ -702,13 +702,12 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
 
         dev->ext_priv = budget;
 
-       budget->dvb_adapter->priv = budget;
+       budget->dvb_adapter.priv = budget;
        frontend_init(budget);
 
         return 0;
 }
 
-
 static int budget_patch_detach (struct saa7146_dev* dev)
 {
         struct budget_patch *budget = (struct budget_patch*) dev->ext_priv;
@@ -723,22 +722,20 @@ static int budget_patch_detach (struct saa7146_dev* dev)
         return err;
 }
 
-
-static int __init budget_patch_init(void) 
+static int __init budget_patch_init(void)
 {
        return saa7146_register_extension(&budget_extension);
 }
 
 static void __exit budget_patch_exit(void)
 {
-        saa7146_unregister_extension(&budget_extension); 
+        saa7146_unregister_extension(&budget_extension);
 }
 
-
 static struct saa7146_extension budget_extension = {
         .name           = "budget_patch dvb\0",
         .flags          = 0,
-        
+
         .module         = THIS_MODULE,
         .pci_tbl        = pci_tbl,
         .attach         = budget_patch_attach,
@@ -748,7 +745,6 @@ static struct saa7146_extension budget_extension = {
         .irq_func       = ttpci_budget_irq10_handler,
 };
 
-
 module_init(budget_patch_init);
 module_exit(budget_patch_exit);
 
@@ -756,4 +752,3 @@ MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Emard, Roberto Deza, Holger Waechtler, Michael Hunold, others");
 MODULE_DESCRIPTION("Driver for full TS modified DVB-S SAA7146+AV7110 "
                    "based so-called Budget Patch cards");
-