Path: blob/master/drivers/media/video/cx23885/netup-eeprom.c
17653 views
1/*2* netup-eeprom.c3*4* 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card5*6* Copyright (C) 2009 NetUP Inc.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#26#include "cx23885.h"27#include "netup-eeprom.h"2829#define EEPROM_I2C_ADDR 0x503031int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)32{33int ret;34unsigned char buf[2];3536/* Read from EEPROM */37struct i2c_msg msg[] = {38{39.addr = EEPROM_I2C_ADDR,40.flags = 0,41.buf = &buf[0],42.len = 143}, {44.addr = EEPROM_I2C_ADDR,45.flags = I2C_M_RD,46.buf = &buf[1],47.len = 148}4950};5152buf[0] = addr;53buf[1] = 0x0;5455ret = i2c_transfer(i2c_adap, msg, 2);5657if (ret != 2) {58printk(KERN_ERR "eeprom i2c read error, status=%d\n", ret);59return -1;60}6162return buf[1];63};6465int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)66{67int ret;68unsigned char bufw[2];6970/* Write into EEPROM */71struct i2c_msg msg[] = {72{73.addr = EEPROM_I2C_ADDR,74.flags = 0,75.buf = &bufw[0],76.len = 277}78};7980bufw[0] = addr;81bufw[1] = data;8283ret = i2c_transfer(i2c_adap, msg, 1);8485if (ret != 1) {86printk(KERN_ERR "eeprom i2c write error, status=%d\n", ret);87return -1;88}8990mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */91return 0;92};9394void netup_get_card_info(struct i2c_adapter *i2c_adap,95struct netup_card_info *cinfo)96{97int i, j;9899cinfo->rev = netup_eeprom_read(i2c_adap, 63);100101for (i = 64, j = 0; i < 70; i++, j++)102cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);103104for (i = 70, j = 0; i < 76; i++, j++)105cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);106};107108109