1*c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2b285192aSMauro Carvalho Chehab
3b285192aSMauro Carvalho Chehab /*
4b285192aSMauro Carvalho Chehab * netup-eeprom.c
5b285192aSMauro Carvalho Chehab *
6b285192aSMauro Carvalho Chehab * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
7b285192aSMauro Carvalho Chehab *
8b285192aSMauro Carvalho Chehab * Copyright (C) 2009 NetUP Inc.
9b285192aSMauro Carvalho Chehab * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
10b285192aSMauro Carvalho Chehab */
11b285192aSMauro Carvalho Chehab
12b285192aSMauro Carvalho Chehab #
13b285192aSMauro Carvalho Chehab #include "cx23885.h"
14b285192aSMauro Carvalho Chehab #include "netup-eeprom.h"
15b285192aSMauro Carvalho Chehab
16b285192aSMauro Carvalho Chehab #define EEPROM_I2C_ADDR 0x50
17b285192aSMauro Carvalho Chehab
netup_eeprom_read(struct i2c_adapter * i2c_adap,u8 addr)18b285192aSMauro Carvalho Chehab int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
19b285192aSMauro Carvalho Chehab {
20b285192aSMauro Carvalho Chehab int ret;
21b285192aSMauro Carvalho Chehab unsigned char buf[2];
22b285192aSMauro Carvalho Chehab
23b285192aSMauro Carvalho Chehab /* Read from EEPROM */
24b285192aSMauro Carvalho Chehab struct i2c_msg msg[] = {
25b285192aSMauro Carvalho Chehab {
26b285192aSMauro Carvalho Chehab .addr = EEPROM_I2C_ADDR,
27b285192aSMauro Carvalho Chehab .flags = 0,
28b285192aSMauro Carvalho Chehab .buf = &buf[0],
29b285192aSMauro Carvalho Chehab .len = 1
30b285192aSMauro Carvalho Chehab }, {
31b285192aSMauro Carvalho Chehab .addr = EEPROM_I2C_ADDR,
32b285192aSMauro Carvalho Chehab .flags = I2C_M_RD,
33b285192aSMauro Carvalho Chehab .buf = &buf[1],
34b285192aSMauro Carvalho Chehab .len = 1
35b285192aSMauro Carvalho Chehab }
36b285192aSMauro Carvalho Chehab
37b285192aSMauro Carvalho Chehab };
38b285192aSMauro Carvalho Chehab
39b285192aSMauro Carvalho Chehab buf[0] = addr;
40b285192aSMauro Carvalho Chehab buf[1] = 0x0;
41b285192aSMauro Carvalho Chehab
42b285192aSMauro Carvalho Chehab ret = i2c_transfer(i2c_adap, msg, 2);
43b285192aSMauro Carvalho Chehab
44b285192aSMauro Carvalho Chehab if (ret != 2) {
45e39682b5SMauro Carvalho Chehab pr_err("eeprom i2c read error, status=%d\n", ret);
46b285192aSMauro Carvalho Chehab return -1;
47b285192aSMauro Carvalho Chehab }
48b285192aSMauro Carvalho Chehab
49b285192aSMauro Carvalho Chehab return buf[1];
50b285192aSMauro Carvalho Chehab };
51b285192aSMauro Carvalho Chehab
netup_eeprom_write(struct i2c_adapter * i2c_adap,u8 addr,u8 data)52b285192aSMauro Carvalho Chehab int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
53b285192aSMauro Carvalho Chehab {
54b285192aSMauro Carvalho Chehab int ret;
55b285192aSMauro Carvalho Chehab unsigned char bufw[2];
56b285192aSMauro Carvalho Chehab
57b285192aSMauro Carvalho Chehab /* Write into EEPROM */
58b285192aSMauro Carvalho Chehab struct i2c_msg msg[] = {
59b285192aSMauro Carvalho Chehab {
60b285192aSMauro Carvalho Chehab .addr = EEPROM_I2C_ADDR,
61b285192aSMauro Carvalho Chehab .flags = 0,
62b285192aSMauro Carvalho Chehab .buf = &bufw[0],
63b285192aSMauro Carvalho Chehab .len = 2
64b285192aSMauro Carvalho Chehab }
65b285192aSMauro Carvalho Chehab };
66b285192aSMauro Carvalho Chehab
67b285192aSMauro Carvalho Chehab bufw[0] = addr;
68b285192aSMauro Carvalho Chehab bufw[1] = data;
69b285192aSMauro Carvalho Chehab
70b285192aSMauro Carvalho Chehab ret = i2c_transfer(i2c_adap, msg, 1);
71b285192aSMauro Carvalho Chehab
72b285192aSMauro Carvalho Chehab if (ret != 1) {
73e39682b5SMauro Carvalho Chehab pr_err("eeprom i2c write error, status=%d\n", ret);
74b285192aSMauro Carvalho Chehab return -1;
75b285192aSMauro Carvalho Chehab }
76b285192aSMauro Carvalho Chehab
77b285192aSMauro Carvalho Chehab mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
78b285192aSMauro Carvalho Chehab return 0;
79b285192aSMauro Carvalho Chehab };
80b285192aSMauro Carvalho Chehab
netup_get_card_info(struct i2c_adapter * i2c_adap,struct netup_card_info * cinfo)81b285192aSMauro Carvalho Chehab void netup_get_card_info(struct i2c_adapter *i2c_adap,
82b285192aSMauro Carvalho Chehab struct netup_card_info *cinfo)
83b285192aSMauro Carvalho Chehab {
84b285192aSMauro Carvalho Chehab int i, j;
85b285192aSMauro Carvalho Chehab
86b285192aSMauro Carvalho Chehab cinfo->rev = netup_eeprom_read(i2c_adap, 63);
87b285192aSMauro Carvalho Chehab
88b285192aSMauro Carvalho Chehab for (i = 64, j = 0; i < 70; i++, j++)
89b285192aSMauro Carvalho Chehab cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
90b285192aSMauro Carvalho Chehab
91b285192aSMauro Carvalho Chehab for (i = 70, j = 0; i < 76; i++, j++)
92b285192aSMauro Carvalho Chehab cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
93b285192aSMauro Carvalho Chehab };
94