/* GT64260TWSI.c : Two-Wire Serial Interface (TWSI) support for the GT64260 * * Copyright (c) 2004, Brookhaven National Laboratory and * Shuchen Kate Feng * All rights reserved. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution. * * See section 24:TWSI interface of "the GT-64260B System Controller * for powerPc Processors Data Sheet". * * For full TWSI protocol description look in Philips Semiconductor * TWSI spec. * * We need it to read out I2C devices used for the MVME5500 * (eg. the memory SPD and VPD). * */ #include /*registers.h included here for rtems_bsp_delay()*/ #include #include /* printk */ #include "bsp/gtreg.h" #include "bsp/GT64260TWSI.h" #define MAX_LOOP 100 #define TWSI_DEBUG 0 int TWSI_initFlg = 0; /* TWSI Initialization Flag */ void GT64260TWSIinit(void) { if ( !TWSI_initFlg) { #if TWSI_DEBUG printk("GT64260TWSIinit("); #endif outl( 0, TWSI_SFT_RST); /* soft reset */ rtems_bsp_delay(1000); /* See 24.2.5 : Assume bus speed is 133MHZ * Try to be close to the default frequency : 62.5KHZ * value 0x2c: 69.27 KHz TWSI bus clock */ outl(0x2c, TWSI_BAUDE_RATE); rtems_bsp_delay(1000); /* Set Acknowledge and enable TWSI in the Control register */ outl(0x44, TWSI_CTRL); rtems_bsp_delay(4000); TWSI_initFlg = 1; #if TWSI_DEBUG printk(")\n"); #endif } } /* return the interrupt flag */ int GT64260TWSIintFlag(void) { unsigned int loop; for (loop = 0; loop < MAX_LOOP; loop++ ) { /* Return 1 if the interrupt flag is set */ if (inl(TWSI_CTRL) & TWSI_INTFLG) return(1); rtems_bsp_delay(1000); } return(0); } int GT64260TWSIstop(void) { #if TWSI_DEBUG printk("GT64260TWSIstop("); #endif outl((inl(TWSI_CTRL) | TWSI_STOP), TWSI_CTRL); rtems_bsp_delay(1000); /* Check if interrupt flag bit is set*/ if (GT64260TWSIintFlag()) { outl((inl( TWSI_CTRL) & ~TWSI_INTFLG), TWSI_CTRL); rtems_bsp_delay(1000); #if TWSI_DEBUG printk(")\n"); #endif return(0); } #if TWSI_DEBUG printk("NoIntFlag\n"); #endif return(-1); } int GT64260TWSIstart(void) { unsigned int loop; unsigned int status; #if TWSI_DEBUG printk("GT64260TWSIstart("); #endif /* Initialize the TWSI interface */ GT64260TWSIinit(); /* set the start bit */ outl((TWSI_START | TWSI_TWSIEN), TWSI_CTRL); rtems_bsp_delay(1000); if (GT64260TWSIintFlag()) { /* Check for completion of START sequence */ for (loop = 0; loop