WIP FPC-III support
[linux/fpc-iii.git] / drivers / media / pci / cx23885 / netup-eeprom.c
blob26dd5b3884e689b2dfd8208b0a250f234503c357
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /*
4 * netup-eeprom.c
6 * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
8 * Copyright (C) 2009 NetUP Inc.
9 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
13 #include "cx23885.h"
14 #include "netup-eeprom.h"
16 #define EEPROM_I2C_ADDR 0x50
18 int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
20 int ret;
21 unsigned char buf[2];
23 /* Read from EEPROM */
24 struct i2c_msg msg[] = {
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
39 buf[0] = addr;
40 buf[1] = 0x0;
42 ret = i2c_transfer(i2c_adap, msg, 2);
44 if (ret != 2) {
45 pr_err("eeprom i2c read error, status=%d\n", ret);
46 return -1;
49 return buf[1];
52 int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
54 int ret;
55 unsigned char bufw[2];
57 /* Write into EEPROM */
58 struct i2c_msg msg[] = {
60 .addr = EEPROM_I2C_ADDR,
61 .flags = 0,
62 .buf = &bufw[0],
63 .len = 2
67 bufw[0] = addr;
68 bufw[1] = data;
70 ret = i2c_transfer(i2c_adap, msg, 1);
72 if (ret != 1) {
73 pr_err("eeprom i2c write error, status=%d\n", ret);
74 return -1;
77 mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
78 return 0;
81 void netup_get_card_info(struct i2c_adapter *i2c_adap,
82 struct netup_card_info *cinfo)
84 int i, j;
86 cinfo->rev = netup_eeprom_read(i2c_adap, 63);
88 for (i = 64, j = 0; i < 70; i++, j++)
89 cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
91 for (i = 70, j = 0; i < 76; i++, j++)
92 cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);