1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /*
4 * netup-eeprom.c
5 *
6 * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
7 *
8 * Copyright (C) 2009 NetUP Inc.
9 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
10 */
11
12 #
13 #include "cx23885.h"
14 #include "netup-eeprom.h"
15
16 #define EEPROM_I2C_ADDR 0x50
17
netup_eeprom_read(struct i2c_adapter * i2c_adap,u8 addr)18 int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
19 {
20 int ret;
21 unsigned char buf[2];
22
23 /* Read from EEPROM */
24 struct i2c_msg msg[] = {
25 {
26 .addr = EEPROM_I2C_ADDR,
27 .flags = 0,
28 .buf = &buf[0],
29 .len = 1
30 }, {
31 .addr = EEPROM_I2C_ADDR,
32 .flags = I2C_M_RD,
33 .buf = &buf[1],
34 .len = 1
35 }
36
37 };
38
39 buf[0] = addr;
40 buf[1] = 0x0;
41
42 ret = i2c_transfer(i2c_adap, msg, 2);
43
44 if (ret != 2) {
45 pr_err("eeprom i2c read error, status=%d\n", ret);
46 return -1;
47 }
48
49 return buf[1];
50 };
51
netup_get_card_info(struct i2c_adapter * i2c_adap,struct netup_card_info * cinfo)52 void netup_get_card_info(struct i2c_adapter *i2c_adap,
53 struct netup_card_info *cinfo)
54 {
55 int i, j;
56
57 cinfo->rev = netup_eeprom_read(i2c_adap, 63);
58
59 for (i = 64, j = 0; i < 70; i++, j++)
60 cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
61
62 for (i = 70, j = 0; i < 76; i++, j++)
63 cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
64 };
65