Path: blob/master/drivers/media/video/cx23885/netup-init.c
17658 views
/*1* netup-init.c2*3* NetUP Dual DVB-S2 CI driver4*5* Copyright (C) 2009 NetUP Inc.6* Copyright (C) 2009 Igor M. Liplianin <[email protected]>7* Copyright (C) 2009 Abylay Ospan <[email protected]>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17*18* GNU General Public License for more details.19*20* You should have received a copy of the GNU General Public License21* along with this program; if not, write to the Free Software22* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.23*/2425#include "cx23885.h"2627static void i2c_av_write(struct i2c_adapter *i2c, u16 reg, u8 val)28{29int ret;30u8 buf[3];31struct i2c_msg msg = {32.addr = 0x88 >> 1,33.flags = 0,34.buf = buf,35.len = 336};3738buf[0] = reg >> 8;39buf[1] = reg & 0xff;40buf[2] = val;4142ret = i2c_transfer(i2c, &msg, 1);4344if (ret != 1)45printk(KERN_ERR "%s: i2c write error!\n", __func__);46}4748static void i2c_av_write4(struct i2c_adapter *i2c, u16 reg, u32 val)49{50int ret;51u8 buf[6];52struct i2c_msg msg = {53.addr = 0x88 >> 1,54.flags = 0,55.buf = buf,56.len = 657};5859buf[0] = reg >> 8;60buf[1] = reg & 0xff;61buf[2] = val & 0xff;62buf[3] = (val >> 8) & 0xff;63buf[4] = (val >> 16) & 0xff;64buf[5] = val >> 24;6566ret = i2c_transfer(i2c, &msg, 1);6768if (ret != 1)69printk(KERN_ERR "%s: i2c write error!\n", __func__);70}7172static u8 i2c_av_read(struct i2c_adapter *i2c, u16 reg)73{74int ret;75u8 buf[2];76struct i2c_msg msg = {77.addr = 0x88 >> 1,78.flags = 0,79.buf = buf,80.len = 281};8283buf[0] = reg >> 8;84buf[1] = reg & 0xff;8586ret = i2c_transfer(i2c, &msg, 1);8788if (ret != 1)89printk(KERN_ERR "%s: i2c write error!\n", __func__);9091msg.flags = I2C_M_RD;92msg.len = 1;9394ret = i2c_transfer(i2c, &msg, 1);9596if (ret != 1)97printk(KERN_ERR "%s: i2c read error!\n", __func__);9899return buf[0];100}101102static void i2c_av_and_or(struct i2c_adapter *i2c, u16 reg, unsigned and_mask,103u8 or_value)104{105i2c_av_write(i2c, reg, (i2c_av_read(i2c, reg) & and_mask) | or_value);106}107/* set 27MHz on AUX_CLK */108void netup_initialize(struct cx23885_dev *dev)109{110struct cx23885_i2c *i2c_bus = &dev->i2c_bus[2];111struct i2c_adapter *i2c = &i2c_bus->i2c_adap;112113/* Stop microcontroller */114i2c_av_and_or(i2c, 0x803, ~0x10, 0x00);115116/* Aux PLL frac for 27 MHz */117i2c_av_write4(i2c, 0x114, 0xea0eb3);118119/* Aux PLL int for 27 MHz */120i2c_av_write4(i2c, 0x110, 0x090319);121122/* start microcontroller */123i2c_av_and_or(i2c, 0x803, ~0x10, 0x10);124}125126127