source: rtems/c/src/lib/libbsp/powerpc/mvme5500/GT64260/MVME5500I2C.c @ 7be6ad9

4.104.114.84.95
Last change on this file since 7be6ad9 was 7be6ad9, checked in by Eric Norum <WENorum@…>, on 10/20/04 at 15:21:05

Add MVME550 BSP

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/* MVME5500I2C.c
2 *
3 * Copyright (c) 2003, 2004 Brookhaven National Laboratory
4 * Author:    S. Kate Feng <feng1@bnl.gov>
5 * All rights reserved.
6 *
7 * The license and distribution terms for this file may be
8 * found in the file LICENSE in this distribution.
9 *
10 * To read inoformation of the EEPROM via the I2C
11 *
12 */
13
14#include <rtems/bspIo.h>            /* printk */
15#include "bsp/GT64260TWSI.h"
16
17/* #define I2C_DEBUG*/
18typedef unsigned int u32;
19typedef unsigned char unchar;
20
21unchar I2cAddrPack(unchar busAddr,u32 offset)
22{
23  return(busAddr | ((offset & 0x700) >> 7));
24}
25unchar I2cDevByteAddr(u32 devA2A1A0, unchar byteNum)
26{
27  return(( devA2A1A0 >>(byteNum*8)) & 0xff);
28}
29/****************************************************************************
30* I2Cread_eeprom - read EEPROM VPD from the I2C
31*/
32int I2Cread_eeprom(unchar I2cBusAddr,u32 devA2A1A0,u32 AddrBytes,unchar *pBuff,u32 numBytes)
33{
34  int status=0, lastByte=0;
35
36  switch (AddrBytes) {
37    case 1:
38      if ((status=GT64260TWSIstart()) != -1) {
39        if ((status=GT64260TWSIwrite(I2cAddrPack(I2cBusAddr,devA2A1A0)))!= -1){
40          if ((status=GT64260TWSIwrite(devA2A1A0))!=-1){
41            if ((status=GT64260TWSIstart())!=-1)
42                status=GT64260TWSIwrite(I2cAddrPack((I2cBusAddr|0x01),devA2A1A0));
43          }
44        }
45      }
46      break;
47    case 2:
48      if ((status=GT64260TWSIstart())!=-1) {
49        if ((status=GT64260TWSIwrite(I2cBusAddr))!= -1) {
50          if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,1)))!=-1) {
51            if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,0)))!= -1){
52              if ((status=GT64260TWSIstart()) != -1) {
53                status = GT64260TWSIwrite((I2cBusAddr | 0x01));
54              }
55            }
56          }
57        }
58      }
59      break;
60    case 3:
61      if ((status = GT64260TWSIstart())!= -1) {
62        if ((status = GT64260TWSIwrite(I2cBusAddr))!= -1) {
63          if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,2)))!= -1){
64            if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,1)))!= -1){
65              if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,0)))!= -1){
66                if ((status=GT64260TWSIstart())!= -1) {
67                  status = GT64260TWSIwrite(I2cBusAddr | 0x01);
68                }
69              }
70            }
71          }
72        }
73      }
74      break;
75    default:
76      status=-1;
77      break; 
78  }
79  if (status !=-1) {
80#ifdef I2C_DEBUG
81     printk("\n");
82#endif
83     /* read data from device */
84     for ( ; numBytes > 0; numBytes-- ) {     
85       if ( numBytes == 1) lastByte=1;
86       if (GT64260TWSIread(pBuff,lastByte) == -1) return (-1);
87#ifdef I2C_DEBUG
88       printk("%2x ", *pBuff);
89       if ( (numBytes % 20)==0 ) printk("\n");
90#endif
91       pBuff++;
92     }
93#ifdef I2C_DEBUG
94     printk("\n");
95#endif
96     if (GT64260TWSIstop() == -1) return (-1);
97  }
98  return (status);
99}
100
Note: See TracBrowser for help on using the repository browser.