2019-05-27 14:55:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-03-03 22:00:18 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* netup-eeprom.c
|
|
|
|
*
|
|
|
|
* 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 NetUP Inc.
|
|
|
|
* Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#
|
|
|
|
#include "cx23885.h"
|
|
|
|
#include "netup-eeprom.h"
|
|
|
|
|
|
|
|
#define EEPROM_I2C_ADDR 0x50
|
|
|
|
|
|
|
|
int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned char buf[2];
|
|
|
|
|
|
|
|
/* Read from EEPROM */
|
|
|
|
struct i2c_msg msg[] = {
|
|
|
|
{
|
|
|
|
.addr = EEPROM_I2C_ADDR,
|
|
|
|
.flags = 0,
|
|
|
|
.buf = &buf[0],
|
|
|
|
.len = 1
|
|
|
|
}, {
|
|
|
|
.addr = EEPROM_I2C_ADDR,
|
|
|
|
.flags = I2C_M_RD,
|
|
|
|
.buf = &buf[1],
|
|
|
|
.len = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
buf[0] = addr;
|
|
|
|
buf[1] = 0x0;
|
|
|
|
|
|
|
|
ret = i2c_transfer(i2c_adap, msg, 2);
|
|
|
|
|
|
|
|
if (ret != 2) {
|
2016-11-13 19:46:11 +08:00
|
|
|
pr_err("eeprom i2c read error, status=%d\n", ret);
|
2009-03-03 22:00:18 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned char bufw[2];
|
|
|
|
|
|
|
|
/* Write into EEPROM */
|
|
|
|
struct i2c_msg msg[] = {
|
|
|
|
{
|
|
|
|
.addr = EEPROM_I2C_ADDR,
|
|
|
|
.flags = 0,
|
|
|
|
.buf = &bufw[0],
|
|
|
|
.len = 2
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bufw[0] = addr;
|
|
|
|
bufw[1] = data;
|
|
|
|
|
|
|
|
ret = i2c_transfer(i2c_adap, msg, 1);
|
|
|
|
|
|
|
|
if (ret != 1) {
|
2016-11-13 19:46:11 +08:00
|
|
|
pr_err("eeprom i2c write error, status=%d\n", ret);
|
2009-03-03 22:00:18 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void netup_get_card_info(struct i2c_adapter *i2c_adap,
|
|
|
|
struct netup_card_info *cinfo)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2009-09-17 01:11:15 +08:00
|
|
|
cinfo->rev = netup_eeprom_read(i2c_adap, 63);
|
2009-03-03 22:00:18 +08:00
|
|
|
|
2009-09-17 01:11:15 +08:00
|
|
|
for (i = 64, j = 0; i < 70; i++, j++)
|
2009-03-03 22:00:18 +08:00
|
|
|
cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
|
|
|
|
|
2009-09-17 01:11:15 +08:00
|
|
|
for (i = 70, j = 0; i < 76; i++, j++)
|
2009-03-03 22:00:18 +08:00
|
|
|
cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
|
|
|
|
};
|