[go: nahoru, domu]

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