xref: /linux/drivers/media/common/b2c2/flexcop-i2c.c (revision 3785bc170f79ef04129731582b468c28e1326d6d)
1*3785bc17SMauro Carvalho Chehab /*
2*3785bc17SMauro Carvalho Chehab  * Linux driver for digital TV devices equipped with B2C2 FlexcopII(b)/III
3*3785bc17SMauro Carvalho Chehab  * flexcop-i2c.c - flexcop internal 2Wire bus (I2C) and dvb i2c initialization
4*3785bc17SMauro Carvalho Chehab  * see flexcop.c for copyright information
5*3785bc17SMauro Carvalho Chehab  */
6*3785bc17SMauro Carvalho Chehab #include "flexcop.h"
7*3785bc17SMauro Carvalho Chehab 
8*3785bc17SMauro Carvalho Chehab #define FC_MAX_I2C_RETRIES 100000
9*3785bc17SMauro Carvalho Chehab 
10*3785bc17SMauro Carvalho Chehab static int flexcop_i2c_operation(struct flexcop_device *fc,
11*3785bc17SMauro Carvalho Chehab 		flexcop_ibi_value *r100)
12*3785bc17SMauro Carvalho Chehab {
13*3785bc17SMauro Carvalho Chehab 	int i;
14*3785bc17SMauro Carvalho Chehab 	flexcop_ibi_value r;
15*3785bc17SMauro Carvalho Chehab 
16*3785bc17SMauro Carvalho Chehab 	r100->tw_sm_c_100.working_start = 1;
17*3785bc17SMauro Carvalho Chehab 	deb_i2c("r100 before: %08x\n",r100->raw);
18*3785bc17SMauro Carvalho Chehab 
19*3785bc17SMauro Carvalho Chehab 	fc->write_ibi_reg(fc, tw_sm_c_100, ibi_zero);
20*3785bc17SMauro Carvalho Chehab 	fc->write_ibi_reg(fc, tw_sm_c_100, *r100); /* initiating i2c operation */
21*3785bc17SMauro Carvalho Chehab 
22*3785bc17SMauro Carvalho Chehab 	for (i = 0; i < FC_MAX_I2C_RETRIES; i++) {
23*3785bc17SMauro Carvalho Chehab 		r = fc->read_ibi_reg(fc, tw_sm_c_100);
24*3785bc17SMauro Carvalho Chehab 
25*3785bc17SMauro Carvalho Chehab 		if (!r.tw_sm_c_100.no_base_addr_ack_error) {
26*3785bc17SMauro Carvalho Chehab 			if (r.tw_sm_c_100.st_done) {
27*3785bc17SMauro Carvalho Chehab 				*r100 = r;
28*3785bc17SMauro Carvalho Chehab 				deb_i2c("i2c success\n");
29*3785bc17SMauro Carvalho Chehab 				return 0;
30*3785bc17SMauro Carvalho Chehab 			}
31*3785bc17SMauro Carvalho Chehab 		} else {
32*3785bc17SMauro Carvalho Chehab 			deb_i2c("suffering from an i2c ack_error\n");
33*3785bc17SMauro Carvalho Chehab 			return -EREMOTEIO;
34*3785bc17SMauro Carvalho Chehab 		}
35*3785bc17SMauro Carvalho Chehab 	}
36*3785bc17SMauro Carvalho Chehab 	deb_i2c("tried %d times i2c operation, "
37*3785bc17SMauro Carvalho Chehab 			"never finished or too many ack errors.\n", i);
38*3785bc17SMauro Carvalho Chehab 	return -EREMOTEIO;
39*3785bc17SMauro Carvalho Chehab }
40*3785bc17SMauro Carvalho Chehab 
41*3785bc17SMauro Carvalho Chehab static int flexcop_i2c_read4(struct flexcop_i2c_adapter *i2c,
42*3785bc17SMauro Carvalho Chehab 		flexcop_ibi_value r100, u8 *buf)
43*3785bc17SMauro Carvalho Chehab {
44*3785bc17SMauro Carvalho Chehab 	flexcop_ibi_value r104;
45*3785bc17SMauro Carvalho Chehab 	int len = r100.tw_sm_c_100.total_bytes,
46*3785bc17SMauro Carvalho Chehab 		/* remember total_bytes is buflen-1 */
47*3785bc17SMauro Carvalho Chehab 		ret;
48*3785bc17SMauro Carvalho Chehab 
49*3785bc17SMauro Carvalho Chehab 	/* work-around to have CableStar2 and SkyStar2 rev 2.7 work
50*3785bc17SMauro Carvalho Chehab 	 * correctly:
51*3785bc17SMauro Carvalho Chehab 	 *
52*3785bc17SMauro Carvalho Chehab 	 * the ITD1000 is behind an i2c-gate which closes automatically
53*3785bc17SMauro Carvalho Chehab 	 * after an i2c-transaction the STV0297 needs 2 consecutive reads
54*3785bc17SMauro Carvalho Chehab 	 * one with no_base_addr = 0 and one with 1
55*3785bc17SMauro Carvalho Chehab 	 *
56*3785bc17SMauro Carvalho Chehab 	 * those two work-arounds are conflictin: we check for the card
57*3785bc17SMauro Carvalho Chehab 	 * type, it is set when probing the ITD1000 */
58*3785bc17SMauro Carvalho Chehab 	if (i2c->fc->dev_type == FC_SKY_REV27)
59*3785bc17SMauro Carvalho Chehab 		r100.tw_sm_c_100.no_base_addr_ack_error = i2c->no_base_addr;
60*3785bc17SMauro Carvalho Chehab 
61*3785bc17SMauro Carvalho Chehab 	ret = flexcop_i2c_operation(i2c->fc, &r100);
62*3785bc17SMauro Carvalho Chehab 	if (ret != 0) {
63*3785bc17SMauro Carvalho Chehab 		deb_i2c("Retrying operation\n");
64*3785bc17SMauro Carvalho Chehab 		r100.tw_sm_c_100.no_base_addr_ack_error = i2c->no_base_addr;
65*3785bc17SMauro Carvalho Chehab 		ret = flexcop_i2c_operation(i2c->fc, &r100);
66*3785bc17SMauro Carvalho Chehab 	}
67*3785bc17SMauro Carvalho Chehab 	if (ret != 0) {
68*3785bc17SMauro Carvalho Chehab 		deb_i2c("read failed. %d\n", ret);
69*3785bc17SMauro Carvalho Chehab 		return ret;
70*3785bc17SMauro Carvalho Chehab 	}
71*3785bc17SMauro Carvalho Chehab 
72*3785bc17SMauro Carvalho Chehab 	buf[0] = r100.tw_sm_c_100.data1_reg;
73*3785bc17SMauro Carvalho Chehab 
74*3785bc17SMauro Carvalho Chehab 	if (len > 0) {
75*3785bc17SMauro Carvalho Chehab 		r104 = i2c->fc->read_ibi_reg(i2c->fc, tw_sm_c_104);
76*3785bc17SMauro Carvalho Chehab 		deb_i2c("read: r100: %08x, r104: %08x\n", r100.raw, r104.raw);
77*3785bc17SMauro Carvalho Chehab 
78*3785bc17SMauro Carvalho Chehab 		/* there is at least one more byte, otherwise we wouldn't be here */
79*3785bc17SMauro Carvalho Chehab 		buf[1] = r104.tw_sm_c_104.data2_reg;
80*3785bc17SMauro Carvalho Chehab 		if (len > 1) buf[2] = r104.tw_sm_c_104.data3_reg;
81*3785bc17SMauro Carvalho Chehab 		if (len > 2) buf[3] = r104.tw_sm_c_104.data4_reg;
82*3785bc17SMauro Carvalho Chehab 	}
83*3785bc17SMauro Carvalho Chehab 	return 0;
84*3785bc17SMauro Carvalho Chehab }
85*3785bc17SMauro Carvalho Chehab 
86*3785bc17SMauro Carvalho Chehab static int flexcop_i2c_write4(struct flexcop_device *fc,
87*3785bc17SMauro Carvalho Chehab 		flexcop_ibi_value r100, u8 *buf)
88*3785bc17SMauro Carvalho Chehab {
89*3785bc17SMauro Carvalho Chehab 	flexcop_ibi_value r104;
90*3785bc17SMauro Carvalho Chehab 	int len = r100.tw_sm_c_100.total_bytes; /* remember total_bytes is buflen-1 */
91*3785bc17SMauro Carvalho Chehab 	r104.raw = 0;
92*3785bc17SMauro Carvalho Chehab 
93*3785bc17SMauro Carvalho Chehab 	/* there is at least one byte, otherwise we wouldn't be here */
94*3785bc17SMauro Carvalho Chehab 	r100.tw_sm_c_100.data1_reg = buf[0];
95*3785bc17SMauro Carvalho Chehab 	r104.tw_sm_c_104.data2_reg = len > 0 ? buf[1] : 0;
96*3785bc17SMauro Carvalho Chehab 	r104.tw_sm_c_104.data3_reg = len > 1 ? buf[2] : 0;
97*3785bc17SMauro Carvalho Chehab 	r104.tw_sm_c_104.data4_reg = len > 2 ? buf[3] : 0;
98*3785bc17SMauro Carvalho Chehab 
99*3785bc17SMauro Carvalho Chehab 	deb_i2c("write: r100: %08x, r104: %08x\n", r100.raw, r104.raw);
100*3785bc17SMauro Carvalho Chehab 
101*3785bc17SMauro Carvalho Chehab 	/* write the additional i2c data before doing the actual i2c operation */
102*3785bc17SMauro Carvalho Chehab 	fc->write_ibi_reg(fc, tw_sm_c_104, r104);
103*3785bc17SMauro Carvalho Chehab 	return flexcop_i2c_operation(fc, &r100);
104*3785bc17SMauro Carvalho Chehab }
105*3785bc17SMauro Carvalho Chehab 
106*3785bc17SMauro Carvalho Chehab int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c,
107*3785bc17SMauro Carvalho Chehab 		flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len)
108*3785bc17SMauro Carvalho Chehab {
109*3785bc17SMauro Carvalho Chehab 	int ret;
110*3785bc17SMauro Carvalho Chehab 
111*3785bc17SMauro Carvalho Chehab #ifdef DUMP_I2C_MESSAGES
112*3785bc17SMauro Carvalho Chehab 	int i;
113*3785bc17SMauro Carvalho Chehab #endif
114*3785bc17SMauro Carvalho Chehab 
115*3785bc17SMauro Carvalho Chehab 	u16 bytes_to_transfer;
116*3785bc17SMauro Carvalho Chehab 	flexcop_ibi_value r100;
117*3785bc17SMauro Carvalho Chehab 
118*3785bc17SMauro Carvalho Chehab 	deb_i2c("op = %d\n",op);
119*3785bc17SMauro Carvalho Chehab 	r100.raw = 0;
120*3785bc17SMauro Carvalho Chehab 	r100.tw_sm_c_100.chipaddr = chipaddr;
121*3785bc17SMauro Carvalho Chehab 	r100.tw_sm_c_100.twoWS_rw = op;
122*3785bc17SMauro Carvalho Chehab 	r100.tw_sm_c_100.twoWS_port_reg = i2c->port;
123*3785bc17SMauro Carvalho Chehab 
124*3785bc17SMauro Carvalho Chehab #ifdef DUMP_I2C_MESSAGES
125*3785bc17SMauro Carvalho Chehab 	printk(KERN_DEBUG "%d ", i2c->port);
126*3785bc17SMauro Carvalho Chehab 	if (op == FC_READ)
127*3785bc17SMauro Carvalho Chehab 		printk("rd(");
128*3785bc17SMauro Carvalho Chehab 	else
129*3785bc17SMauro Carvalho Chehab 		printk("wr(");
130*3785bc17SMauro Carvalho Chehab 	printk("%02x): %02x ", chipaddr, addr);
131*3785bc17SMauro Carvalho Chehab #endif
132*3785bc17SMauro Carvalho Chehab 
133*3785bc17SMauro Carvalho Chehab 	/* in that case addr is the only value ->
134*3785bc17SMauro Carvalho Chehab 	 * we write it twice as baseaddr and val0
135*3785bc17SMauro Carvalho Chehab 	 * BBTI is doing it like that for ISL6421 at least */
136*3785bc17SMauro Carvalho Chehab 	if (i2c->no_base_addr && len == 0 && op == FC_WRITE) {
137*3785bc17SMauro Carvalho Chehab 		buf = &addr;
138*3785bc17SMauro Carvalho Chehab 		len = 1;
139*3785bc17SMauro Carvalho Chehab 	}
140*3785bc17SMauro Carvalho Chehab 
141*3785bc17SMauro Carvalho Chehab 	while (len != 0) {
142*3785bc17SMauro Carvalho Chehab 		bytes_to_transfer = len > 4 ? 4 : len;
143*3785bc17SMauro Carvalho Chehab 
144*3785bc17SMauro Carvalho Chehab 		r100.tw_sm_c_100.total_bytes = bytes_to_transfer - 1;
145*3785bc17SMauro Carvalho Chehab 		r100.tw_sm_c_100.baseaddr = addr;
146*3785bc17SMauro Carvalho Chehab 
147*3785bc17SMauro Carvalho Chehab 		if (op == FC_READ)
148*3785bc17SMauro Carvalho Chehab 			ret = flexcop_i2c_read4(i2c, r100, buf);
149*3785bc17SMauro Carvalho Chehab 		else
150*3785bc17SMauro Carvalho Chehab 			ret = flexcop_i2c_write4(i2c->fc, r100, buf);
151*3785bc17SMauro Carvalho Chehab 
152*3785bc17SMauro Carvalho Chehab #ifdef DUMP_I2C_MESSAGES
153*3785bc17SMauro Carvalho Chehab 		for (i = 0; i < bytes_to_transfer; i++)
154*3785bc17SMauro Carvalho Chehab 			printk("%02x ", buf[i]);
155*3785bc17SMauro Carvalho Chehab #endif
156*3785bc17SMauro Carvalho Chehab 
157*3785bc17SMauro Carvalho Chehab 		if (ret < 0)
158*3785bc17SMauro Carvalho Chehab 			return ret;
159*3785bc17SMauro Carvalho Chehab 
160*3785bc17SMauro Carvalho Chehab 		buf  += bytes_to_transfer;
161*3785bc17SMauro Carvalho Chehab 		addr += bytes_to_transfer;
162*3785bc17SMauro Carvalho Chehab 		len  -= bytes_to_transfer;
163*3785bc17SMauro Carvalho Chehab 	}
164*3785bc17SMauro Carvalho Chehab 
165*3785bc17SMauro Carvalho Chehab #ifdef DUMP_I2C_MESSAGES
166*3785bc17SMauro Carvalho Chehab 	printk("\n");
167*3785bc17SMauro Carvalho Chehab #endif
168*3785bc17SMauro Carvalho Chehab 
169*3785bc17SMauro Carvalho Chehab 	return 0;
170*3785bc17SMauro Carvalho Chehab }
171*3785bc17SMauro Carvalho Chehab /* exported for PCI i2c */
172*3785bc17SMauro Carvalho Chehab EXPORT_SYMBOL(flexcop_i2c_request);
173*3785bc17SMauro Carvalho Chehab 
174*3785bc17SMauro Carvalho Chehab /* master xfer callback for demodulator */
175*3785bc17SMauro Carvalho Chehab static int flexcop_master_xfer(struct i2c_adapter *i2c_adap,
176*3785bc17SMauro Carvalho Chehab 		struct i2c_msg msgs[], int num)
177*3785bc17SMauro Carvalho Chehab {
178*3785bc17SMauro Carvalho Chehab 	struct flexcop_i2c_adapter *i2c = i2c_get_adapdata(i2c_adap);
179*3785bc17SMauro Carvalho Chehab 	int i, ret = 0;
180*3785bc17SMauro Carvalho Chehab 
181*3785bc17SMauro Carvalho Chehab 	/* Some drivers use 1 byte or 0 byte reads as probes, which this
182*3785bc17SMauro Carvalho Chehab 	 * driver doesn't support.  These probes will always fail, so this
183*3785bc17SMauro Carvalho Chehab 	 * hack makes them always succeed.  If one knew how, it would of
184*3785bc17SMauro Carvalho Chehab 	 * course be better to actually do the read.  */
185*3785bc17SMauro Carvalho Chehab 	if (num == 1 && msgs[0].flags == I2C_M_RD && msgs[0].len <= 1)
186*3785bc17SMauro Carvalho Chehab 		return 1;
187*3785bc17SMauro Carvalho Chehab 
188*3785bc17SMauro Carvalho Chehab 	if (mutex_lock_interruptible(&i2c->fc->i2c_mutex))
189*3785bc17SMauro Carvalho Chehab 		return -ERESTARTSYS;
190*3785bc17SMauro Carvalho Chehab 
191*3785bc17SMauro Carvalho Chehab 	for (i = 0; i < num; i++) {
192*3785bc17SMauro Carvalho Chehab 		/* reading */
193*3785bc17SMauro Carvalho Chehab 		if (i+1 < num && (msgs[i+1].flags == I2C_M_RD)) {
194*3785bc17SMauro Carvalho Chehab 			ret = i2c->fc->i2c_request(i2c, FC_READ, msgs[i].addr,
195*3785bc17SMauro Carvalho Chehab 					msgs[i].buf[0], msgs[i+1].buf,
196*3785bc17SMauro Carvalho Chehab 					msgs[i+1].len);
197*3785bc17SMauro Carvalho Chehab 			i++; /* skip the following message */
198*3785bc17SMauro Carvalho Chehab 		} else /* writing */
199*3785bc17SMauro Carvalho Chehab 			ret = i2c->fc->i2c_request(i2c, FC_WRITE, msgs[i].addr,
200*3785bc17SMauro Carvalho Chehab 					msgs[i].buf[0], &msgs[i].buf[1],
201*3785bc17SMauro Carvalho Chehab 					msgs[i].len - 1);
202*3785bc17SMauro Carvalho Chehab 		if (ret < 0) {
203*3785bc17SMauro Carvalho Chehab 			deb_i2c("i2c master_xfer failed");
204*3785bc17SMauro Carvalho Chehab 			break;
205*3785bc17SMauro Carvalho Chehab 		}
206*3785bc17SMauro Carvalho Chehab 	}
207*3785bc17SMauro Carvalho Chehab 
208*3785bc17SMauro Carvalho Chehab 	mutex_unlock(&i2c->fc->i2c_mutex);
209*3785bc17SMauro Carvalho Chehab 
210*3785bc17SMauro Carvalho Chehab 	if (ret == 0)
211*3785bc17SMauro Carvalho Chehab 		ret = num;
212*3785bc17SMauro Carvalho Chehab 	return ret;
213*3785bc17SMauro Carvalho Chehab }
214*3785bc17SMauro Carvalho Chehab 
215*3785bc17SMauro Carvalho Chehab static u32 flexcop_i2c_func(struct i2c_adapter *adapter)
216*3785bc17SMauro Carvalho Chehab {
217*3785bc17SMauro Carvalho Chehab 	return I2C_FUNC_I2C;
218*3785bc17SMauro Carvalho Chehab }
219*3785bc17SMauro Carvalho Chehab 
220*3785bc17SMauro Carvalho Chehab static struct i2c_algorithm flexcop_algo = {
221*3785bc17SMauro Carvalho Chehab 	.master_xfer	= flexcop_master_xfer,
222*3785bc17SMauro Carvalho Chehab 	.functionality	= flexcop_i2c_func,
223*3785bc17SMauro Carvalho Chehab };
224*3785bc17SMauro Carvalho Chehab 
225*3785bc17SMauro Carvalho Chehab int flexcop_i2c_init(struct flexcop_device *fc)
226*3785bc17SMauro Carvalho Chehab {
227*3785bc17SMauro Carvalho Chehab 	int ret;
228*3785bc17SMauro Carvalho Chehab 	mutex_init(&fc->i2c_mutex);
229*3785bc17SMauro Carvalho Chehab 
230*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[0].fc = fc;
231*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[1].fc = fc;
232*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[2].fc = fc;
233*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[0].port = FC_I2C_PORT_DEMOD;
234*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[1].port = FC_I2C_PORT_EEPROM;
235*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[2].port = FC_I2C_PORT_TUNER;
236*3785bc17SMauro Carvalho Chehab 
237*3785bc17SMauro Carvalho Chehab 	strlcpy(fc->fc_i2c_adap[0].i2c_adap.name, "B2C2 FlexCop I2C to demod",
238*3785bc17SMauro Carvalho Chehab 			sizeof(fc->fc_i2c_adap[0].i2c_adap.name));
239*3785bc17SMauro Carvalho Chehab 	strlcpy(fc->fc_i2c_adap[1].i2c_adap.name, "B2C2 FlexCop I2C to eeprom",
240*3785bc17SMauro Carvalho Chehab 			sizeof(fc->fc_i2c_adap[1].i2c_adap.name));
241*3785bc17SMauro Carvalho Chehab 	strlcpy(fc->fc_i2c_adap[2].i2c_adap.name, "B2C2 FlexCop I2C to tuner",
242*3785bc17SMauro Carvalho Chehab 			sizeof(fc->fc_i2c_adap[2].i2c_adap.name));
243*3785bc17SMauro Carvalho Chehab 
244*3785bc17SMauro Carvalho Chehab 	i2c_set_adapdata(&fc->fc_i2c_adap[0].i2c_adap, &fc->fc_i2c_adap[0]);
245*3785bc17SMauro Carvalho Chehab 	i2c_set_adapdata(&fc->fc_i2c_adap[1].i2c_adap, &fc->fc_i2c_adap[1]);
246*3785bc17SMauro Carvalho Chehab 	i2c_set_adapdata(&fc->fc_i2c_adap[2].i2c_adap, &fc->fc_i2c_adap[2]);
247*3785bc17SMauro Carvalho Chehab 
248*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[0].i2c_adap.algo =
249*3785bc17SMauro Carvalho Chehab 		fc->fc_i2c_adap[1].i2c_adap.algo =
250*3785bc17SMauro Carvalho Chehab 		fc->fc_i2c_adap[2].i2c_adap.algo = &flexcop_algo;
251*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[0].i2c_adap.algo_data =
252*3785bc17SMauro Carvalho Chehab 		fc->fc_i2c_adap[1].i2c_adap.algo_data =
253*3785bc17SMauro Carvalho Chehab 		fc->fc_i2c_adap[2].i2c_adap.algo_data = NULL;
254*3785bc17SMauro Carvalho Chehab 	fc->fc_i2c_adap[0].i2c_adap.dev.parent =
255*3785bc17SMauro Carvalho Chehab 		fc->fc_i2c_adap[1].i2c_adap.dev.parent =
256*3785bc17SMauro Carvalho Chehab 		fc->fc_i2c_adap[2].i2c_adap.dev.parent = fc->dev;
257*3785bc17SMauro Carvalho Chehab 
258*3785bc17SMauro Carvalho Chehab 	ret = i2c_add_adapter(&fc->fc_i2c_adap[0].i2c_adap);
259*3785bc17SMauro Carvalho Chehab 	if (ret < 0)
260*3785bc17SMauro Carvalho Chehab 		return ret;
261*3785bc17SMauro Carvalho Chehab 
262*3785bc17SMauro Carvalho Chehab 	ret = i2c_add_adapter(&fc->fc_i2c_adap[1].i2c_adap);
263*3785bc17SMauro Carvalho Chehab 	if (ret < 0)
264*3785bc17SMauro Carvalho Chehab 		goto adap_1_failed;
265*3785bc17SMauro Carvalho Chehab 
266*3785bc17SMauro Carvalho Chehab 	ret = i2c_add_adapter(&fc->fc_i2c_adap[2].i2c_adap);
267*3785bc17SMauro Carvalho Chehab 	if (ret < 0)
268*3785bc17SMauro Carvalho Chehab 		goto adap_2_failed;
269*3785bc17SMauro Carvalho Chehab 
270*3785bc17SMauro Carvalho Chehab 	fc->init_state |= FC_STATE_I2C_INIT;
271*3785bc17SMauro Carvalho Chehab 	return 0;
272*3785bc17SMauro Carvalho Chehab 
273*3785bc17SMauro Carvalho Chehab adap_2_failed:
274*3785bc17SMauro Carvalho Chehab 	i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap);
275*3785bc17SMauro Carvalho Chehab adap_1_failed:
276*3785bc17SMauro Carvalho Chehab 	i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap);
277*3785bc17SMauro Carvalho Chehab 	return ret;
278*3785bc17SMauro Carvalho Chehab }
279*3785bc17SMauro Carvalho Chehab 
280*3785bc17SMauro Carvalho Chehab void flexcop_i2c_exit(struct flexcop_device *fc)
281*3785bc17SMauro Carvalho Chehab {
282*3785bc17SMauro Carvalho Chehab 	if (fc->init_state & FC_STATE_I2C_INIT) {
283*3785bc17SMauro Carvalho Chehab 		i2c_del_adapter(&fc->fc_i2c_adap[2].i2c_adap);
284*3785bc17SMauro Carvalho Chehab 		i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap);
285*3785bc17SMauro Carvalho Chehab 		i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap);
286*3785bc17SMauro Carvalho Chehab 	}
287*3785bc17SMauro Carvalho Chehab 	fc->init_state &= ~FC_STATE_I2C_INIT;
288*3785bc17SMauro Carvalho Chehab }
289