1 | #include <rtems.h> |
---|
2 | #include <bsp.h> |
---|
3 | #include <rtems/libi2c.h> |
---|
4 | #include <libchip/i2c-2b-eeprom.h> |
---|
5 | #include <libchip/i2c-ds1621.h> |
---|
6 | #include <bsp/gti2c_busdrv.h> |
---|
7 | #include <rtems/libio.h> |
---|
8 | |
---|
9 | #include <stdio.h> |
---|
10 | #include <sys/stat.h> |
---|
11 | |
---|
12 | /* Register i2c bus driver & devices */ |
---|
13 | |
---|
14 | /* |
---|
15 | * Authorship |
---|
16 | * ---------- |
---|
17 | * This software ('beatnik' RTEMS BSP for MVME6100 and MVME5500) was |
---|
18 | * created by Till Straumann <strauman@slac.stanford.edu>, 2005-2007, |
---|
19 | * Stanford Linear Accelerator Center, Stanford University. |
---|
20 | * |
---|
21 | * Acknowledgement of sponsorship |
---|
22 | * ------------------------------ |
---|
23 | * The 'beatnik' BSP was produced by |
---|
24 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
25 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
26 | * |
---|
27 | * Government disclaimer of liability |
---|
28 | * ---------------------------------- |
---|
29 | * Neither the United States nor the United States Department of Energy, |
---|
30 | * nor any of their employees, makes any warranty, express or implied, or |
---|
31 | * assumes any legal liability or responsibility for the accuracy, |
---|
32 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
33 | * disclosed, or represents that its use would not infringe privately owned |
---|
34 | * rights. |
---|
35 | * |
---|
36 | * Stanford disclaimer of liability |
---|
37 | * -------------------------------- |
---|
38 | * Stanford University makes no representations or warranties, express or |
---|
39 | * implied, nor assumes any liability for the use of this software. |
---|
40 | * |
---|
41 | * Stanford disclaimer of copyright |
---|
42 | * -------------------------------- |
---|
43 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
44 | * copyright and all other rights in this software. Hence, anyone may |
---|
45 | * freely use it for any purpose without restriction. |
---|
46 | * |
---|
47 | * Maintenance of notices |
---|
48 | * ---------------------- |
---|
49 | * In the interest of clarity regarding the origin and status of this |
---|
50 | * SLAC software, this and all the preceding Stanford University notices |
---|
51 | * are to remain affixed to any copy or derivative of this software made |
---|
52 | * or distributed by the recipient and are to be affixed to any copy of |
---|
53 | * software made or distributed by the recipient that contains a copy or |
---|
54 | * derivative of this software. |
---|
55 | * |
---|
56 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
57 | */ |
---|
58 | |
---|
59 | int |
---|
60 | BSP_i2c_initialize( void ) |
---|
61 | { |
---|
62 | int busno; |
---|
63 | /* Initialize the library */ |
---|
64 | if ( rtems_libi2c_initialize() ) { |
---|
65 | fprintf(stderr,"Initializing I2C library failed\n"); |
---|
66 | return -1; |
---|
67 | } |
---|
68 | |
---|
69 | /* Register our bus driver */ |
---|
70 | if ( (busno=rtems_libi2c_register_bus( |
---|
71 | BSP_I2C_BUS0_NAME, |
---|
72 | BSP_I2C_BUS_DESCRIPTOR) ) < 0 ) { |
---|
73 | perror("Registering gt64260 i2c bus driver"); |
---|
74 | return -1; |
---|
75 | } |
---|
76 | |
---|
77 | /* Now register higher level drivers; note that |
---|
78 | * the i2c address in the manual is actually left-shifted |
---|
79 | * by one bit, i.e., as it would go on the bus. |
---|
80 | */ |
---|
81 | |
---|
82 | /* Use read-only driver for VPD */ |
---|
83 | if ( rtems_libi2c_register_drv( |
---|
84 | BSP_I2C_VPD_EEPROM_NAME, |
---|
85 | i2c_2b_eeprom_ro_driver_descriptor, |
---|
86 | busno, |
---|
87 | BSP_VPD_I2C_ADDR) < 0 ) { |
---|
88 | perror("Registering i2c VPD eeprom driver failed"); |
---|
89 | return -1; |
---|
90 | } |
---|
91 | |
---|
92 | /* Use read-write driver for user eeprom -- you still might |
---|
93 | * have to disable HW write-protection on your board. |
---|
94 | */ |
---|
95 | if ( rtems_libi2c_register_drv( |
---|
96 | BSP_I2C_USR_EEPROM_NAME, |
---|
97 | i2c_2b_eeprom_driver_descriptor, |
---|
98 | busno, |
---|
99 | BSP_USR_I2C_ADDR) < 0 ) { |
---|
100 | perror("Registering i2c USR eeprom driver failed"); |
---|
101 | return -1; |
---|
102 | } |
---|
103 | |
---|
104 | /* The thermostat */ |
---|
105 | if ( rtems_libi2c_register_drv( |
---|
106 | BSP_I2C_DS1621_NAME, |
---|
107 | i2c_ds1621_driver_descriptor, |
---|
108 | busno, |
---|
109 | BSP_THM_I2C_ADDR) < 0 ) { |
---|
110 | perror("Registering i2c ds1621 temp sensor. driver failed"); |
---|
111 | return -1; |
---|
112 | } |
---|
113 | |
---|
114 | /* Finally, as an example, register raw access to the |
---|
115 | * ds1621. The driver above just reads the 8 msb of the |
---|
116 | * temperature but doesn't support anything else. Using |
---|
117 | * the raw device node you can write/read individual |
---|
118 | * control bytes yourself and e.g., program the thermostat... |
---|
119 | */ |
---|
120 | |
---|
121 | if ( mknod( |
---|
122 | BSP_I2C_DS1621_RAW_DEV_NAME, |
---|
123 | 0666 | S_IFCHR, |
---|
124 | rtems_filesystem_make_dev_t(rtems_libi2c_major, |
---|
125 | RTEMS_LIBI2C_MAKE_MINOR(busno,BSP_THM_I2C_ADDR))) ) { |
---|
126 | perror("Creating device node for raw ds1621 access failed"); |
---|
127 | return -1; |
---|
128 | } |
---|
129 | printf("I2C devices registered\n"); |
---|
130 | return 0; |
---|
131 | } |
---|