Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / media / pci / cx23885 / netup-init.c
blobc653b076651f282b6dd77e022dce8b768ecd5ae8
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * netup-init.c
5 * NetUP Dual DVB-S2 CI driver
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
9 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
12 #include "cx23885.h"
13 #include "netup-init.h"
15 static void i2c_av_write(struct i2c_adapter *i2c, u16 reg, u8 val)
17 int ret;
18 u8 buf[3];
19 struct i2c_msg msg = {
20 .addr = 0x88 >> 1,
21 .flags = 0,
22 .buf = buf,
23 .len = 3
26 buf[0] = reg >> 8;
27 buf[1] = reg & 0xff;
28 buf[2] = val;
30 ret = i2c_transfer(i2c, &msg, 1);
32 if (ret != 1)
33 pr_err("%s: i2c write error!\n", __func__);
36 static void i2c_av_write4(struct i2c_adapter *i2c, u16 reg, u32 val)
38 int ret;
39 u8 buf[6];
40 struct i2c_msg msg = {
41 .addr = 0x88 >> 1,
42 .flags = 0,
43 .buf = buf,
44 .len = 6
47 buf[0] = reg >> 8;
48 buf[1] = reg & 0xff;
49 buf[2] = val & 0xff;
50 buf[3] = (val >> 8) & 0xff;
51 buf[4] = (val >> 16) & 0xff;
52 buf[5] = val >> 24;
54 ret = i2c_transfer(i2c, &msg, 1);
56 if (ret != 1)
57 pr_err("%s: i2c write error!\n", __func__);
60 static u8 i2c_av_read(struct i2c_adapter *i2c, u16 reg)
62 int ret;
63 u8 buf[2];
64 struct i2c_msg msg = {
65 .addr = 0x88 >> 1,
66 .flags = 0,
67 .buf = buf,
68 .len = 2
71 buf[0] = reg >> 8;
72 buf[1] = reg & 0xff;
74 ret = i2c_transfer(i2c, &msg, 1);
76 if (ret != 1)
77 pr_err("%s: i2c write error!\n", __func__);
79 msg.flags = I2C_M_RD;
80 msg.len = 1;
82 ret = i2c_transfer(i2c, &msg, 1);
84 if (ret != 1)
85 pr_err("%s: i2c read error!\n", __func__);
87 return buf[0];
90 static void i2c_av_and_or(struct i2c_adapter *i2c, u16 reg, unsigned and_mask,
91 u8 or_value)
93 i2c_av_write(i2c, reg, (i2c_av_read(i2c, reg) & and_mask) | or_value);
95 /* set 27MHz on AUX_CLK */
96 void netup_initialize(struct cx23885_dev *dev)
98 struct cx23885_i2c *i2c_bus = &dev->i2c_bus[2];
99 struct i2c_adapter *i2c = &i2c_bus->i2c_adap;
101 /* Stop microcontroller */
102 i2c_av_and_or(i2c, 0x803, ~0x10, 0x00);
104 /* Aux PLL frac for 27 MHz */
105 i2c_av_write4(i2c, 0x114, 0xea0eb3);
107 /* Aux PLL int for 27 MHz */
108 i2c_av_write4(i2c, 0x110, 0x090319);
110 /* start microcontroller */
111 i2c_av_and_or(i2c, 0x803, ~0x10, 0x10);