Commit | Line | Data |
---|---|---|
c253a171 AO |
1 | /* |
2 | * netup-init.c | |
3 | * | |
4 | * NetUP Dual DVB-S2 CI driver | |
5 | * | |
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> | |
9 | * | |
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. | |
14 | * | |
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 | |
18 | * | |
19 | * GNU General Public License for more details. | |
c253a171 AO |
20 | */ |
21 | ||
22 | #include "cx23885.h" | |
ada73eee | 23 | #include "netup-init.h" |
c253a171 AO |
24 | |
25 | static void i2c_av_write(struct i2c_adapter *i2c, u16 reg, u8 val) | |
26 | { | |
27 | int ret; | |
28 | u8 buf[3]; | |
29 | struct i2c_msg msg = { | |
30 | .addr = 0x88 >> 1, | |
31 | .flags = 0, | |
32 | .buf = buf, | |
33 | .len = 3 | |
34 | }; | |
35 | ||
36 | buf[0] = reg >> 8; | |
37 | buf[1] = reg & 0xff; | |
38 | buf[2] = val; | |
39 | ||
40 | ret = i2c_transfer(i2c, &msg, 1); | |
41 | ||
42 | if (ret != 1) | |
43 | printk(KERN_ERR "%s: i2c write error!\n", __func__); | |
44 | } | |
45 | ||
46 | static void i2c_av_write4(struct i2c_adapter *i2c, u16 reg, u32 val) | |
47 | { | |
48 | int ret; | |
49 | u8 buf[6]; | |
50 | struct i2c_msg msg = { | |
51 | .addr = 0x88 >> 1, | |
52 | .flags = 0, | |
53 | .buf = buf, | |
54 | .len = 6 | |
55 | }; | |
56 | ||
57 | buf[0] = reg >> 8; | |
58 | buf[1] = reg & 0xff; | |
59 | buf[2] = val & 0xff; | |
60 | buf[3] = (val >> 8) & 0xff; | |
61 | buf[4] = (val >> 16) & 0xff; | |
62 | buf[5] = val >> 24; | |
63 | ||
64 | ret = i2c_transfer(i2c, &msg, 1); | |
65 | ||
66 | if (ret != 1) | |
67 | printk(KERN_ERR "%s: i2c write error!\n", __func__); | |
68 | } | |
69 | ||
70 | static u8 i2c_av_read(struct i2c_adapter *i2c, u16 reg) | |
71 | { | |
72 | int ret; | |
73 | u8 buf[2]; | |
74 | struct i2c_msg msg = { | |
75 | .addr = 0x88 >> 1, | |
76 | .flags = 0, | |
77 | .buf = buf, | |
78 | .len = 2 | |
79 | }; | |
80 | ||
81 | buf[0] = reg >> 8; | |
82 | buf[1] = reg & 0xff; | |
83 | ||
84 | ret = i2c_transfer(i2c, &msg, 1); | |
85 | ||
86 | if (ret != 1) | |
87 | printk(KERN_ERR "%s: i2c write error!\n", __func__); | |
88 | ||
89 | msg.flags = I2C_M_RD; | |
90 | msg.len = 1; | |
91 | ||
92 | ret = i2c_transfer(i2c, &msg, 1); | |
93 | ||
94 | if (ret != 1) | |
95 | printk(KERN_ERR "%s: i2c read error!\n", __func__); | |
96 | ||
97 | return buf[0]; | |
98 | } | |
99 | ||
100 | static void i2c_av_and_or(struct i2c_adapter *i2c, u16 reg, unsigned and_mask, | |
101 | u8 or_value) | |
102 | { | |
103 | i2c_av_write(i2c, reg, (i2c_av_read(i2c, reg) & and_mask) | or_value); | |
104 | } | |
105 | /* set 27MHz on AUX_CLK */ | |
106 | void netup_initialize(struct cx23885_dev *dev) | |
107 | { | |
108 | struct cx23885_i2c *i2c_bus = &dev->i2c_bus[2]; | |
109 | struct i2c_adapter *i2c = &i2c_bus->i2c_adap; | |
110 | ||
111 | /* Stop microcontroller */ | |
112 | i2c_av_and_or(i2c, 0x803, ~0x10, 0x00); | |
113 | ||
114 | /* Aux PLL frac for 27 MHz */ | |
115 | i2c_av_write4(i2c, 0x114, 0xea0eb3); | |
116 | ||
117 | /* Aux PLL int for 27 MHz */ | |
118 | i2c_av_write4(i2c, 0x110, 0x090319); | |
119 | ||
120 | /* start microcontroller */ | |
121 | i2c_av_and_or(i2c, 0x803, ~0x10, 0x10); | |
122 | } |