25 #include <linux/slab.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include <linux/i2c.h>
31 #include <linux/wait.h>
38 #define MAX_BUFFER_SIZE 248
66 struct i2c_msg msg = {.addr = adr, .flags = 0, .buf =
m, .len = 2};
79 struct i2c_msg msg = {.
addr = adr, .flags = 0, .buf =
data, .len = len};
92 .buf = &
reg, .len = 1},
94 .buf =
val, .len = 1} };
106 struct i2c_msg msgs[2] = {{.
addr = adr, .flags = 0,
107 .buf = &
reg, .len = 1},
109 .buf =
data, .len = n} };
118 static int read_block(
struct cxd *ci,
u8 adr,
u8 *data,
u8 n)
122 status = i2c_write_reg(ci->
i2c, ci->
cfg.adr, 0, adr);
132 return read_block(ci, reg, val, 1);
139 u8 addr[3] = {2, address & 0xff, address >> 8};
147 static int write_pccard(
struct cxd *ci,
u16 address,
u8 *data,
u8 n)
150 u8 addr[3] = {2, address & 0xff, address >> 8};
161 static int read_io(
struct cxd *ci,
u16 address,
u8 *val)
164 u8 addr[3] = {2, address & 0xff, address >> 8};
172 static int write_io(
struct cxd *ci,
u16 address,
u8 val)
175 u8 addr[3] = {2, address & 0xff, address >> 8};
176 u8 buf[2] = {3, val};
185 static int read_io_data(
struct cxd *ci,
u8 *data,
u8 n)
188 u8 addr[3] = { 2, 0, 0 };
196 static int write_io_data(
struct cxd *ci,
u8 *data,
u8 n)
199 u8 addr[3] = {2, 0, 0};
211 static int write_regm(
struct cxd *ci,
u8 reg,
u8 val,
u8 mask)
215 status = i2c_write_reg(ci->
i2c, ci->
cfg.adr, 0, reg);
216 if (!status && reg >= 6 && reg <= 8 && mask != 0xff)
217 status = i2c_read_reg(ci->
i2c, ci->
cfg.adr, 1, &ci->
regs[reg]);
221 status = i2c_write_reg(ci->
i2c, ci->
cfg.adr, 1, ci->
regs[reg]);
230 return write_regm(ci, reg, val, 0xff);
234 static int write_block(
struct cxd *ci,
u8 adr,
u8 *data,
int n)
239 status = i2c_write_reg(ci->
i2c, ci->
cfg.adr, 0, adr);
251 if (mode == ci->
mode)
256 write_regm(ci, 0x06, 0x00, 0x07);
259 write_regm(ci, 0x06, 0x02, 0x07);
267 static void cam_mode(
struct cxd *ci,
int mode)
274 write_regm(ci, 0x20, 0x80, 0x80);
278 if (!ci->
en.read_data)
283 write_regm(ci, 0x08, 0x40, 0x40);
285 write_regm(ci, 0x08, 0x80, 0x80);
296 static int init(
struct cxd *ci)
347 status = write_regm(ci, 0x14, 0x00, 0x0F);
353 status = write_regm(ci, 0x16, 0x00, 0x0F);
360 if (ci->
cfg.clock_mode) {
361 if (ci->
cfg.polarity) {
380 if (ci->
cfg.polarity) {
401 status = write_regm(ci, 0x20, 0x80, 0x80);
404 status = write_regm(ci, 0x03, 0x02, 0x02);
415 status = write_regm(ci, 0x09, 0x08, 0x08);
427 int slot,
int address)
438 write_regm(ci, 0x06, 0x00, 0x05);
439 read_pccard(ci, 0, &ci->
amem[0], 128);
440 read_pccard(ci, 128, &ci->
amem[0], 128);
441 read_pccard(ci, 256, &ci->
amem[0], 128);
442 read_pccard(ci, 384, &ci->
amem[0], 128);
443 write_regm(ci, 0x06, 0x05, 0x05);
450 read_pccard(ci, address, &val, 1);
457 static int write_attribute_mem(
struct dvb_ca_en50221 *ca,
int slot,
464 write_pccard(ci, address, &value, 1);
470 int slot,
u8 address)
477 read_io(ci, address, &val);
489 write_io(ci, address, value);
512 write_regm(ci, 0x20, 0x80, 0x80);
523 for (i = 0; i < 100; i++) {
547 write_regm(ci, 0x09, 0x08, 0x08);
548 write_regm(ci, 0x20, 0x80, 0x80);
549 write_regm(ci, 0x06, 0x07, 0x07);
560 write_regm(ci, 0x09, 0x00, 0x08);
570 static int campoll(
struct cxd *ci)
593 write_regm(ci, 0x03, 0x08, 0x08);
599 write_regm(ci, 0x03, 0x00, 0x08);
627 static int read_data(
struct dvb_ca_en50221 *ca,
int slot,
u8 *ebuf,
int ecount)
645 read_block(ci, 0x12, ebuf, len);
652 static int write_data(
struct dvb_ca_en50221 *ca,
int slot,
u8 *ebuf,
int ecount)
657 printk(kern_INFO
"write_data %d\n", ecount);
660 write_block(ci, 0x11, ebuf, ecount);
676 .read_data = read_data,
677 .write_data = write_data,
689 if (i2c_read_reg(i2c, cfg->
adr, 0, &val) < 0) {