aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/cx23885
diff options
context:
space:
mode:
authorAbylay Ospan <aospan@netup.ru>2009-03-03 09:00:18 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:43:04 -0400
commitb45c0551f94dbc160e94f48a034a51312acec81d (patch)
tree1a9703ec1a055550de2874ed8ffc0e4e2bdcbcea /drivers/media/video/cx23885
parentc253a17126d6e841720d5926c6d426745693676b (diff)
V4L/DVB (10797): Add EEPROM code for NetUP Dual DVB-S2 CI card.
Signed-off-by: Abylay Ospan <aospan@netup.ru> Signed-off-by: Igor M. Liplianin <liplianin@netup.ru> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/cx23885')
-rw-r--r--drivers/media/video/cx23885/netup-eeprom.c107
-rw-r--r--drivers/media/video/cx23885/netup-eeprom.h42
2 files changed, 149 insertions, 0 deletions
diff --git a/drivers/media/video/cx23885/netup-eeprom.c b/drivers/media/video/cx23885/netup-eeprom.c
new file mode 100644
index 000000000000..042bbbbd48f8
--- /dev/null
+++ b/drivers/media/video/cx23885/netup-eeprom.c
@@ -0,0 +1,107 @@
1
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.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#
27#include "cx23885.h"
28#include "netup-eeprom.h"
29
30#define EEPROM_I2C_ADDR 0x50
31
32int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr)
33{
34 int ret;
35 unsigned char buf[2];
36
37 /* Read from EEPROM */
38 struct i2c_msg msg[] = {
39 {
40 .addr = EEPROM_I2C_ADDR,
41 .flags = 0,
42 .buf = &buf[0],
43 .len = 1
44 }, {
45 .addr = EEPROM_I2C_ADDR,
46 .flags = I2C_M_RD,
47 .buf = &buf[1],
48 .len = 1
49 }
50
51 };
52
53 buf[0] = addr;
54 buf[1] = 0x0;
55
56 ret = i2c_transfer(i2c_adap, msg, 2);
57
58 if (ret != 2) {
59 printk(KERN_ERR "eeprom i2c read error, status=%d\n", ret);
60 return -1;
61 }
62
63 return buf[1];
64};
65
66int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data)
67{
68 int ret;
69 unsigned char bufw[2];
70
71 /* Write into EEPROM */
72 struct i2c_msg msg[] = {
73 {
74 .addr = EEPROM_I2C_ADDR,
75 .flags = 0,
76 .buf = &bufw[0],
77 .len = 2
78 }
79 };
80
81 bufw[0] = addr;
82 bufw[1] = data;
83
84 ret = i2c_transfer(i2c_adap, msg, 1);
85
86 if (ret != 1) {
87 printk(KERN_ERR "eeprom i2c write error, status=%d\n", ret);
88 return -1;
89 }
90
91 mdelay(10); /* prophylactic delay, datasheet write cycle time = 5 ms */
92 return 0;
93};
94
95void netup_get_card_info(struct i2c_adapter *i2c_adap,
96 struct netup_card_info *cinfo)
97{
98 int i, j;
99
100 cinfo->rev = netup_eeprom_read(i2c_adap, 13);
101
102 for (i = 0, j = 0; i < 6; i++, j++)
103 cinfo->port[0].mac[j] = netup_eeprom_read(i2c_adap, i);
104
105 for (i = 6, j = 0; i < 12; i++, j++)
106 cinfo->port[1].mac[j] = netup_eeprom_read(i2c_adap, i);
107};
diff --git a/drivers/media/video/cx23885/netup-eeprom.h b/drivers/media/video/cx23885/netup-eeprom.h
new file mode 100644
index 000000000000..13926e18feba
--- /dev/null
+++ b/drivers/media/video/cx23885/netup-eeprom.h
@@ -0,0 +1,42 @@
1/*
2 * netup-eeprom.h
3 *
4 * 24LC02 EEPROM driver in conjunction with NetUP Dual DVB-S2 CI card
5 *
6 * Copyright (C) 2009 NetUP Inc.
7 * Copyright (C) 2009 Abylay Ospan <aospan@netup.ru>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 *
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#ifndef NETUP_EEPROM_H
26#define NETUP_EEPROM_H
27
28struct netup_port_info {
29 u8 mac[6];/* card MAC address */
30};
31
32struct netup_card_info {
33 struct netup_port_info port[2];/* ports - 1,2 */
34 u8 rev;/* card revision */
35};
36
37extern int netup_eeprom_read(struct i2c_adapter *i2c_adap, u8 addr);
38extern int netup_eeprom_write(struct i2c_adapter *i2c_adap, u8 addr, u8 data);
39extern void netup_get_card_info(struct i2c_adapter *i2c_adap,
40 struct netup_card_info *cinfo);
41
42#endif