Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:52

0001 #include <rtems.h>
0002 #include <bsp.h>
0003 #include <rtems/libi2c.h>
0004 #include <libchip/i2c-2b-eeprom.h>
0005 #include <libchip/i2c-ds1621.h>
0006 #include <bsp/gti2c_busdrv.h>
0007 #include <rtems/libio.h>
0008 
0009 #include <stdio.h>
0010 #include <sys/stat.h>
0011 
0012 /* Register i2c bus driver & devices */
0013 
0014 /* 
0015  * Authorship
0016  * ----------
0017  * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was
0018  *     created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
0019  *     Stanford Linear Accelerator Center, Stanford University.
0020  * 
0021  * Acknowledgement of sponsorship
0022  * ------------------------------
0023  * The 'beatnik' BSP was produced by
0024  *     the Stanford Linear Accelerator Center, Stanford University,
0025  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0026  * 
0027  * Government disclaimer of liability
0028  * ----------------------------------
0029  * Neither the United States nor the United States Department of Energy,
0030  * nor any of their employees, makes any warranty, express or implied, or
0031  * assumes any legal liability or responsibility for the accuracy,
0032  * completeness, or usefulness of any data, apparatus, product, or process
0033  * disclosed, or represents that its use would not infringe privately owned
0034  * rights.
0035  * 
0036  * Stanford disclaimer of liability
0037  * --------------------------------
0038  * Stanford University makes no representations or warranties, express or
0039  * implied, nor assumes any liability for the use of this software.
0040  * 
0041  * Stanford disclaimer of copyright
0042  * --------------------------------
0043  * Stanford University, owner of the copyright, hereby disclaims its
0044  * copyright and all other rights in this software.  Hence, anyone may
0045  * freely use it for any purpose without restriction.  
0046  * 
0047  * Maintenance of notices
0048  * ----------------------
0049  * In the interest of clarity regarding the origin and status of this
0050  * SLAC software, this and all the preceding Stanford University notices
0051  * are to remain affixed to any copy or derivative of this software made
0052  * or distributed by the recipient and are to be affixed to any copy of
0053  * software made or distributed by the recipient that contains a copy or
0054  * derivative of this software.
0055  * 
0056  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0057  */ 
0058 
0059 int
0060 BSP_i2c_initialize( void )
0061 {
0062 int busno;
0063     /* Initialize the library */
0064     if ( rtems_libi2c_initialize() ) {
0065         fprintf(stderr,"Initializing I2C library failed\n");
0066         return -1;
0067     }
0068     
0069     /* Register our bus driver */
0070     if ( (busno=rtems_libi2c_register_bus(
0071                     BSP_I2C_BUS0_NAME,
0072                     BSP_I2C_BUS_DESCRIPTOR) ) < 0 ) {
0073         perror("Registering gt64260 i2c bus driver");
0074         return -1;
0075     }
0076 
0077     /* Now register higher level drivers; note that
0078      * the i2c address in the manual is actually left-shifted
0079      * by one bit, i.e., as it would go on the bus.
0080      */
0081 
0082     /* Use read-only driver for VPD */
0083     if ( rtems_libi2c_register_drv(
0084                 BSP_I2C_VPD_EEPROM_NAME,
0085                 i2c_2b_eeprom_ro_driver_descriptor,
0086                 busno,
0087                 BSP_VPD_I2C_ADDR) < 0 ) {
0088         perror("Registering i2c VPD eeprom driver failed");
0089         return -1;
0090     }
0091 
0092     /* Use read-write driver for user eeprom -- you still might
0093      * have to disable HW write-protection on your board.
0094      */
0095     if ( rtems_libi2c_register_drv(
0096                 BSP_I2C_USR_EEPROM_NAME,
0097                 i2c_2b_eeprom_driver_descriptor,
0098                 busno,
0099                 BSP_USR_I2C_ADDR) < 0 ) {
0100         perror("Registering i2c USR eeprom driver failed");
0101         return -1;
0102     }
0103 
0104     /* The thermostat */
0105     if ( rtems_libi2c_register_drv(
0106                 BSP_I2C_DS1621_NAME,
0107                 i2c_ds1621_driver_descriptor,
0108                 busno,
0109                 BSP_THM_I2C_ADDR) < 0 ) {
0110         perror("Registering i2c ds1621 temp sensor. driver failed");
0111         return -1;
0112     }
0113 
0114     /* Finally, as an example, register raw access to the
0115      * ds1621. The driver above just reads the 8 msb of the
0116      * temperature but doesn't support anything else. Using
0117      * the raw device node you can write/read individual
0118      * control bytes yourself and e.g., program the thermostat...
0119      */
0120 
0121     if ( mknod(
0122             BSP_I2C_DS1621_RAW_DEV_NAME,
0123             0666 | S_IFCHR,
0124             rtems_filesystem_make_dev_t(rtems_libi2c_major,
0125                   RTEMS_LIBI2C_MAKE_MINOR(busno,BSP_THM_I2C_ADDR))) ) {
0126         perror("Creating device node for raw ds1621 access failed");
0127         return -1;
0128     }
0129     printf("I2C devices registered\n");
0130     return 0;
0131 }