rt2800: initialize BBP_R104 on proper subroutines
[linux/fpc-iii.git] / drivers / media / pci / cx23885 / netup-init.c
blob0044fef7ca24e2adac4d08f55f6d32bc9b08ed5d
1 /*
2 * netup-init.c
4 * NetUP Dual DVB-S2 CI driver
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
8 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "cx23885.h"
27 #include "netup-init.h"
29 static void i2c_av_write(struct i2c_adapter *i2c, u16 reg, u8 val)
31 int ret;
32 u8 buf[3];
33 struct i2c_msg msg = {
34 .addr = 0x88 >> 1,
35 .flags = 0,
36 .buf = buf,
37 .len = 3
40 buf[0] = reg >> 8;
41 buf[1] = reg & 0xff;
42 buf[2] = val;
44 ret = i2c_transfer(i2c, &msg, 1);
46 if (ret != 1)
47 printk(KERN_ERR "%s: i2c write error!\n", __func__);
50 static void i2c_av_write4(struct i2c_adapter *i2c, u16 reg, u32 val)
52 int ret;
53 u8 buf[6];
54 struct i2c_msg msg = {
55 .addr = 0x88 >> 1,
56 .flags = 0,
57 .buf = buf,
58 .len = 6
61 buf[0] = reg >> 8;
62 buf[1] = reg & 0xff;
63 buf[2] = val & 0xff;
64 buf[3] = (val >> 8) & 0xff;
65 buf[4] = (val >> 16) & 0xff;
66 buf[5] = val >> 24;
68 ret = i2c_transfer(i2c, &msg, 1);
70 if (ret != 1)
71 printk(KERN_ERR "%s: i2c write error!\n", __func__);
74 static u8 i2c_av_read(struct i2c_adapter *i2c, u16 reg)
76 int ret;
77 u8 buf[2];
78 struct i2c_msg msg = {
79 .addr = 0x88 >> 1,
80 .flags = 0,
81 .buf = buf,
82 .len = 2
85 buf[0] = reg >> 8;
86 buf[1] = reg & 0xff;
88 ret = i2c_transfer(i2c, &msg, 1);
90 if (ret != 1)
91 printk(KERN_ERR "%s: i2c write error!\n", __func__);
93 msg.flags = I2C_M_RD;
94 msg.len = 1;
96 ret = i2c_transfer(i2c, &msg, 1);
98 if (ret != 1)
99 printk(KERN_ERR "%s: i2c read error!\n", __func__);
101 return buf[0];
104 static void i2c_av_and_or(struct i2c_adapter *i2c, u16 reg, unsigned and_mask,
105 u8 or_value)
107 i2c_av_write(i2c, reg, (i2c_av_read(i2c, reg) & and_mask) | or_value);
109 /* set 27MHz on AUX_CLK */
110 void netup_initialize(struct cx23885_dev *dev)
112 struct cx23885_i2c *i2c_bus = &dev->i2c_bus[2];
113 struct i2c_adapter *i2c = &i2c_bus->i2c_adap;
115 /* Stop microcontroller */
116 i2c_av_and_or(i2c, 0x803, ~0x10, 0x00);
118 /* Aux PLL frac for 27 MHz */
119 i2c_av_write4(i2c, 0x114, 0xea0eb3);
121 /* Aux PLL int for 27 MHz */
122 i2c_av_write4(i2c, 0x110, 0x090319);
124 /* start microcontroller */
125 i2c_av_and_or(i2c, 0x803, ~0x10, 0x10);