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

4.8
Last change on this file since d7196bf was d7196bf, checked in by Joel Sherrill <joel.sherrill@…>, on 05/04/09 at 20:06:43

2009-04-20 Kate Feng <feng1@…>

1396/bsps

  • pci/pci.c : Updated it to be consistent with the original pci.c
  • written by Eric Valette. There is no change in its function.
  • irq/irq_init.c : set defaultIrq->next_handler to be 0
  • for BSP_SHARED_HANDLER_SUPPORT.
  • network/if_1GHz/if_wm.c : fixed some bugs in the 1GHz driver.
  • irq/BSP_irq.c : added supports for shared IRQ.
  • pci/pci_interface.c : Enabled PCI "Read", "Read Line", and "Read Multiple"
  • Agressive Prefetch to improve the performance of the PCI based
  • applications (e.g. 1GHz NIC).
  • irq/BSP_irq.c : Replaced the irq/irq.c, and used GT_GPP_Value
  • register to monitor the cause of the level sensitive interrupts.
  • This unique solution solves various bugs in the 1GHz network drivers
  • Fixed bugs in compute_pic_masks_from_prio()
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/* MVME5500I2C.c
2 *
3 * Copyright (c) 2003, 2004 Brookhaven National Laboratory
4 * Author:    S. Kate Feng <feng1@bnl.gov>
5 *            under the Deaprtment of Energy contract DE-AC02-98CH10886
6 * All rights reserved.
7 *
8 * The license and distribution terms for this file may be
9 * found in the file LICENSE in this distribution.
10 *
11 * To read inoformation of the EEPROM via the I2C
12 *
13 */
14
15#include <rtems/bspIo.h>            /* printk */
16#include "bsp/GT64260TWSI.h"
17
18/* #define I2C_DEBUG*/
19typedef unsigned int u32;
20typedef unsigned char unchar;
21
22unchar I2cAddrPack(unchar busAddr,u32 offset)
23{
24  return(busAddr | ((offset & 0x700) >> 7));
25}
26unchar I2cDevByteAddr(u32 devA2A1A0, unchar byteNum)
27{
28  return(( devA2A1A0 >>(byteNum*8)) & 0xff);
29}
30/****************************************************************************
31* I2Cread_eeprom - read EEPROM VPD from the I2C
32*/
33int I2Cread_eeprom(unchar I2cBusAddr,u32 devA2A1A0,u32 AddrBytes,void *pBuff,u32 numBytes)
34{
35  int status=0, lastByte=0;
36  unchar *ptr=(unchar *) pBuff;
37
38  switch (AddrBytes) {
39    case 1:
40      if ((status=GT64260TWSIstart()) != -1) {
41        if ((status=GT64260TWSIwrite(I2cAddrPack(I2cBusAddr,devA2A1A0)))!= -1){
42          if ((status=GT64260TWSIwrite(devA2A1A0))!=-1){
43            if ((status=GT64260TWSIstart())!=-1)
44                status=GT64260TWSIwrite(I2cAddrPack((I2cBusAddr|0x01),devA2A1A0));
45          }
46        }
47      }
48      break;
49    case 2:
50      if ((status=GT64260TWSIstart())!=-1) {
51        if ((status=GT64260TWSIwrite(I2cBusAddr))!= -1) {
52          if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,1)))!=-1) {
53            if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,0)))!= -1){
54              if ((status=GT64260TWSIstart()) != -1) {
55                status = GT64260TWSIwrite((I2cBusAddr | 0x01));
56              }
57            }
58          }
59        }
60      }
61      break;
62    case 3:
63      if ((status = GT64260TWSIstart())!= -1) {
64        if ((status = GT64260TWSIwrite(I2cBusAddr))!= -1) {
65          if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,2)))!= -1){
66            if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,1)))!= -1){
67              if ((status=GT64260TWSIwrite(I2cDevByteAddr(devA2A1A0,0)))!= -1){
68                if ((status=GT64260TWSIstart())!= -1) {
69                  status = GT64260TWSIwrite(I2cBusAddr | 0x01);
70                }
71              }
72            }
73          }
74        }
75      }
76      break;
77    default:
78      status=-1;
79      break; 
80  }
81  if (status !=-1) {
82#ifdef I2C_DEBUG
83     printk("\n");
84#endif
85     /* read data from device */
86     for ( ; numBytes > 0; numBytes-- ) {     
87       if ( numBytes == 1) lastByte=1;
88       if (GT64260TWSIread(ptr,lastByte) == -1) {
89         printk("numBytes %d\n", numBytes);
90          return (-1);
91       }
92#ifdef I2C_DEBUG
93       printk("%2x ", *ptr);
94       if ( (numBytes % 20)==0 ) printk("\n");
95#endif
96       ptr++;   
97     }
98#ifdef I2C_DEBUG
99     printk("\n");
100#endif
101     if (GT64260TWSIstop() == -1) return (-1);
102  }
103  return (status);
104}
105
Note: See TracBrowser for help on using the repository browser.