blob: 6384c12aa38e8087eb3a5f218473c14f80626203 [file] [log] [blame]
Abylay Ospanb45c0552009-03-03 11:00:18 -03001
2/*
3 * netup-eeprom.c
4 *
5 * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
6 *
7 * Copyright (C) 2009 NetUP Inc.
8 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 *
19 * GNU General Public License for more details.
Abylay Ospanb45c0552009-03-03 11:00:18 -030020 */
21
22#
23#include "cx23885.h"
24#include "netup-eeprom.h"
25
26#define EEPROM_I2C_ADDR 0x50
27
28int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
29{
30 int ret;
31 unsigned char buf[2];
32
33 /* Read from EEPROM */
34 struct i2c_msg msg[] = {
35 {
36 .addr = EEPROM_I2C_ADDR,
37 .flags = 0,
38 .buf = &buf[0],
39 .len = 1
40 }, {
41 .addr = EEPROM_I2C_ADDR,
42 .flags = I2C_M_RD,
43 .buf = &buf[1],
44 .len = 1
45 }
46
47 };
48
49 buf[0] = addr;
50 buf[1] = 0x0;
51
52 ret = i2c_transfer(i2c_adap, msg, 2);
53
54 if (ret != 2) {
Mauro Carvalho Chehabe39682b2016-11-13 09:46:11 -020055 pr_err("eeprom i2c read error, status=%d\n", ret);
Abylay Ospanb45c0552009-03-03 11:00:18 -030056 return -1;
57 }
58
59 return buf[1];
60};
61
62int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
63{
64 int ret;
65 unsigned char bufw[2];
66
67 /* Write into EEPROM */
68 struct i2c_msg msg[] = {
69 {
70 .addr = EEPROM_I2C_ADDR,
71 .flags = 0,
72 .buf = &bufw[0],
73 .len = 2
74 }
75 };
76
77 bufw[0] = addr;
78 bufw[1] = data;
79
80 ret = i2c_transfer(i2c_adap, msg, 1);
81
82 if (ret != 1) {
Mauro Carvalho Chehabe39682b2016-11-13 09:46:11 -020083 pr_err("eeprom i2c write error, status=%d\n", ret);
Abylay Ospanb45c0552009-03-03 11:00:18 -030084 return -1;
85 }
86
87 mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
88 return 0;
89};
90
91void netup_get_card_info(struct i2c_adapter *i2c_adap,
92 struct netup_card_info *cinfo)
93{
94 int i, j;
95
Abylay Ospan20341882009-09-16 14:11:15 -030096 cinfo->rev = netup_eeprom_read(i2c_adap, 63);
Abylay Ospanb45c0552009-03-03 11:00:18 -030097
Abylay Ospan20341882009-09-16 14:11:15 -030098 for (i = 64, j = 0; i < 70; i++, j++)
Abylay Ospanb45c0552009-03-03 11:00:18 -030099 cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
100
Abylay Ospan20341882009-09-16 14:11:15 -0300101 for (i = 70, j = 0; i < 76; i++, j++)
Abylay Ospanb45c0552009-03-03 11:00:18 -0300102 cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
103};