Subversion Repositories Kolibri OS

Rev

Rev 1403 | Rev 3031 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1403 Rev 1963
Line 41... Line 41...
41
#else
41
#else
42
#define bit_dbg(level, dev, format, args...) \
42
#define bit_dbg(level, dev, format, args...) \
43
	do {} while (0)
43
	do {} while (0)
44
#endif /* DEBUG */
44
#endif /* DEBUG */
Line 45... Line -...
45
 
-
 
46
 
45
 
Line 47... Line 46...
47
/* ----- global variables ---------------------------------------------	*/
46
/* ----- global variables ---------------------------------------------	*/
Line 163... Line 162...
163
	for (i = 7; i >= 0; i--) {
162
	for (i = 7; i >= 0; i--) {
164
		sb = (c >> i) & 1;
163
		sb = (c >> i) & 1;
165
		setsda(adap, sb);
164
		setsda(adap, sb);
166
		udelay((adap->udelay + 1) / 2);
165
		udelay((adap->udelay + 1) / 2);
167
		if (sclhi(adap) < 0) { /* timed out */
166
		if (sclhi(adap) < 0) { /* timed out */
168
//           bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
167
			bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
169
//               "timeout at bit #%d\n", (int)c, i);
168
				"timeout at bit #%d\n", (int)c, i);
170
			return -ETIMEDOUT;
169
			return -ETIMEDOUT;
171
		}
170
		}
172
		/* FIXME do arbitration here:
171
		/* FIXME do arbitration here:
173
		 * if (sb && !getsda(adap)) -> ouch! Get out of here.
172
		 * if (sb && !getsda(adap)) -> ouch! Get out of here.
174
		 *
173
		 *
Line 177... Line 176...
177
		 */
176
		 */
178
		scllo(adap);
177
		scllo(adap);
179
	}
178
	}
180
	sdahi(adap);
179
	sdahi(adap);
181
	if (sclhi(adap) < 0) { /* timeout */
180
	if (sclhi(adap) < 0) { /* timeout */
182
//       bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
181
		bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, "
183
//           "timeout at ack\n", (int)c);
182
			"timeout at ack\n", (int)c);
184
		return -ETIMEDOUT;
183
		return -ETIMEDOUT;
185
	}
184
	}
Line 186... Line 185...
186
 
185
 
187
	/* read ack: SDA should be pulled down by slave, or it may
186
	/* read ack: SDA should be pulled down by slave, or it may
188
	 * NAK (usually to report problems with the data we wrote).
187
	 * NAK (usually to report problems with the data we wrote).
189
	 */
188
	 */
190
	ack = !getsda(adap);    /* ack: sda is pulled low -> success */
189
	ack = !getsda(adap);    /* ack: sda is pulled low -> success */
191
//   bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c,
190
	bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c,
Line 192... Line 191...
192
//       ack ? "A" : "NA");
191
		ack ? "A" : "NA");
193
 
192
 
194
	scllo(adap);
193
	scllo(adap);
195
	return ack;
194
	return ack;
Line 225... Line 224...
225
 
224
 
226
/*
225
/*
227
 * Sanity check for the adapter hardware - check the reaction of
226
 * Sanity check for the adapter hardware - check the reaction of
228
 * the bus lines only if it seems to be idle.
227
 * the bus lines only if it seems to be idle.
229
 */
228
 */
230
static int test_bus(struct i2c_algo_bit_data *adap, char *name)
229
static int test_bus(struct i2c_adapter *i2c_adap)
-
 
230
{
-
 
231
	struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
231
{
232
	const char *name = i2c_adap->name;
-
 
233
	int scl, sda, ret;
-
 
234
 
-
 
235
	if (adap->pre_xfer) {
-
 
236
		ret = adap->pre_xfer(i2c_adap);
-
 
237
		if (ret < 0)
-
 
238
			return -ENODEV;
Line 232... Line 239...
232
	int scl, sda;
239
	}
233
 
240
 
Line 234... Line 241...
234
	if (adap->getscl == NULL)
241
	if (adap->getscl == NULL)
Line 290... Line 297...
290
	if (!sda) {
297
	if (!sda) {
291
		printk(KERN_WARNING "%s: SDA unexpected low "
298
		printk(KERN_WARNING "%s: SDA unexpected low "
292
		       "while pulling SCL high!\n", name);
299
		       "while pulling SCL high!\n", name);
293
		goto bailout;
300
		goto bailout;
294
	}
301
	}
-
 
302
 
-
 
303
	if (adap->post_xfer)
-
 
304
		adap->post_xfer(i2c_adap);
-
 
305
 
295
	pr_info("%s: Test OK\n", name);
306
	pr_info("%s: Test OK\n", name);
296
	return 0;
307
	return 0;
297
bailout:
308
bailout:
298
	sdahi(adap);
309
	sdahi(adap);
299
	sclhi(adap);
310
	sclhi(adap);
-
 
311
 
-
 
312
	if (adap->post_xfer)
-
 
313
		adap->post_xfer(i2c_adap);
-
 
314
 
300
	return -ENODEV;
315
	return -ENODEV;
301
}
316
}
Line 302... Line 317...
302
 
317
 
303
/* ----- Utility functions
318
/* ----- Utility functions
Line 427... Line 442...
427
			   or 2 for a PEC transaction. */
442
			   or 2 for a PEC transaction. */
428
			count += inval;
443
			count += inval;
429
			msg->len += inval;
444
			msg->len += inval;
430
		}
445
		}
Line 431... Line 446...
431
 
446
 
432
//       bit_dbg(2, &i2c_adap->dev, "readbytes: 0x%02x %s\n",
447
		bit_dbg(2, &i2c_adap->dev, "readbytes: 0x%02x %s\n",
433
//           inval,
448
			inval,
434
//           (flags & I2C_M_NO_RD_ACK)
449
			(flags & I2C_M_NO_RD_ACK)
435
//               ? "(no ack/nak)"
450
				? "(no ack/nak)"
Line 436... Line 451...
436
//               : (count ? "A" : "NA"));
451
				: (count ? "A" : "NA"));
437
 
452
 
438
		if (!(flags & I2C_M_NO_RD_ACK)) {
453
		if (!(flags & I2C_M_NO_RD_ACK)) {
439
			inval = acknak(i2c_adap, count);
454
			inval = acknak(i2c_adap, count);
Line 514... Line 529...
514
	struct i2c_msg *pmsg;
529
	struct i2c_msg *pmsg;
515
	struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
530
	struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
516
	int i, ret;
531
	int i, ret;
517
	unsigned short nak_ok;
532
	unsigned short nak_ok;
Line -... Line 533...
-
 
533
 
-
 
534
	//ENTER();
-
 
535
	if (adap->pre_xfer) {
-
 
536
		ret = adap->pre_xfer(i2c_adap);
-
 
537
		if (ret < 0)
-
 
538
			return ret;
-
 
539
	}
518
 
540
 
519
	bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
541
	bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
520
	i2c_start(adap);
542
	i2c_start(adap);
521
	for (i = 0; i < num; i++) {
543
	for (i = 0; i < num; i++) {
522
		pmsg = &msgs[i];
544
		pmsg = &msgs[i];
Line 562... Line 584...
562
	ret = i;
584
	ret = i;
Line 563... Line 585...
563
 
585
 
564
bailout:
586
bailout:
565
	bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
587
	bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
-
 
588
	i2c_stop(adap);
-
 
589
//    LEAVE();
-
 
590
 
-
 
591
	if (adap->post_xfer)
566
	i2c_stop(adap);
592
		adap->post_xfer(i2c_adap);
567
	return ret;
593
	return ret;
Line 568... Line 594...
568
}
594
}
569
 
595
 
Line 584... Line 610...
584
};
610
};
Line 585... Line 611...
585
 
611
 
586
/*
612
/*
587
 * registering functions to load algorithms at runtime
613
 * registering functions to load algorithms at runtime
588
 */
614
 */
-
 
615
static int __i2c_bit_add_bus(struct i2c_adapter *adap,
589
static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
616
			     int (*add_adapter)(struct i2c_adapter *))
590
{
617
{
-
 
618
	struct i2c_algo_bit_data *bit_adap = adap->algo_data;
Line 591... Line 619...
591
	struct i2c_algo_bit_data *bit_adap = adap->algo_data;
619
	int ret;
592
 
620
 
593
//   if (bit_test) {
621
	if (bit_test) {
594
//       int ret = test_bus(bit_adap, adap->name);
622
		ret = test_bus(adap);
595
//       if (ret < 0)
623
		if (ret < 0)
Line 596... Line 624...
596
//           return -ENODEV;
624
			return -ENODEV;
597
//   }
625
	}
598
 
626
 
Line 599... Line 627...
599
	/* register new adapter to i2c module... */
627
	/* register new adapter to i2c module... */
600
	adap->algo = &i2c_bit_algo;
628
	adap->algo = &i2c_bit_algo;
Line 601... Line 629...
601
	adap->retries = 3;
629
	adap->retries = 3;
602
 
630
 
603
	return 0;
-
 
604
}
-
 
605
 
631
	return 0;
606
int i2c_bit_add_bus(struct i2c_adapter *adap)
-
 
607
{
-
 
608
	int err;
-
 
609
 
-
 
610
	err = i2c_bit_prepare_bus(adap);
632
}
Line -... Line 633...
-
 
633