source: rtems/bsps/powerpc/mvme3100/i2c/i2c_init.c @ 8f8ccee

5
Last change on this file since 8f8ccee was a2dad96, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 23, 2018 at 7:45:28 AM

bsps: Move I2C drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/* Register i2c bus driver & devices */
2
3/*
4 * Authorship
5 * ----------
6 * This software ('mvme3100' RTEMS BSP) was created by
7 *
8 *     Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
9 *         Stanford Linear Accelerator Center, Stanford University.
10 *
11 * Acknowledgement of sponsorship
12 * ------------------------------
13 * The 'mvme3100' BSP was produced by
14 *     the Stanford Linear Accelerator Center, Stanford University,
15 *         under Contract DE-AC03-76SFO0515 with the Department of Energy.
16 *
17 * Government disclaimer of liability
18 * ----------------------------------
19 * Neither the United States nor the United States Department of Energy,
20 * nor any of their employees, makes any warranty, express or implied, or
21 * assumes any legal liability or responsibility for the accuracy,
22 * completeness, or usefulness of any data, apparatus, product, or process
23 * disclosed, or represents that its use would not infringe privately owned
24 * rights.
25 *
26 * Stanford disclaimer of liability
27 * --------------------------------
28 * Stanford University makes no representations or warranties, express or
29 * implied, nor assumes any liability for the use of this software.
30 *
31 * Stanford disclaimer of copyright
32 * --------------------------------
33 * Stanford University, owner of the copyright, hereby disclaims its
34 * copyright and all other rights in this software.  Hence, anyone may
35 * freely use it for any purpose without restriction.
36 *
37 * Maintenance of notices
38 * ----------------------
39 * In the interest of clarity regarding the origin and status of this
40 * SLAC software, this and all the preceding Stanford University notices
41 * are to remain affixed to any copy or derivative of this software made
42 * or distributed by the recipient and are to be affixed to any copy of
43 * software made or distributed by the recipient that contains a copy or
44 * derivative of this software.
45 *
46 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
47 */
48
49#include <rtems.h>
50#include <bsp.h>
51#include <rtems/bspIo.h>
52#include <rtems/libi2c.h>
53#include <libchip/i2c-2b-eeprom.h>
54#include <libchip/i2c-ds1621.h>
55#include <bsp/mpc8540_i2c_busdrv.h>
56#include <rtems/libio.h>
57#include <rtems/score/sysstate.h>
58
59#include <stdio.h>
60#include <sys/stat.h>
61#include <errno.h>
62#include <stdarg.h>
63
64static void
65safe_printf (const char *fmt, ...)
66{
67        va_list ap;
68
69        va_start(ap, fmt);
70        if ( _System_state_Is_up( _System_state_Get() ) )
71                vfprintf( stderr, fmt, ap );
72        else
73                vprintk( fmt, ap );
74        va_end(ap);
75}
76
77static void
78safe_perror(const char *s)
79{
80        safe_printf("%s :%s\n", s, strerror(errno));
81}
82
83
84int
85BSP_i2c_initialize(void)
86{
87int busno, succ = 0;
88
89        /* Initialize the library */
90        if ( rtems_libi2c_initialize() ) {
91                safe_printf("Initializing I2C library failed\n");
92                return -1;
93        }
94
95        /* Register our bus driver */
96        if ( (busno=rtems_libi2c_register_bus(
97                                        BSP_I2C_BUS0_NAME,
98                                        BSP_I2C_BUS_DESCRIPTOR) ) < 0 ) {
99                safe_perror("Registering mpc8540 i2c bus driver");
100                return -1;
101        }
102
103        /* Now register higher level drivers; note that
104         * the i2c address in the manual is actually left-shifted
105         * by one bit, i.e., as it would go on the bus.
106         */
107
108        /* Use read-only driver for VPD */
109        if ( rtems_libi2c_register_drv(
110                                BSP_I2C_VPD_EEPROM_NAME,
111                                i2c_2b_eeprom_ro_driver_descriptor,
112                                busno,
113                                BSP_VPD_I2C_ADDR) < 0 ) {
114                safe_perror("Registering i2c VPD eeprom driver failed");
115        } else {
116                succ++;
117        }
118
119        /* Use read-write driver for user eeprom -- you still might
120         * have to disable HW write-protection on your board.
121         */
122        if ( rtems_libi2c_register_drv(
123                                BSP_I2C_USR_EEPROM_NAME,
124                                i2c_2b_eeprom_driver_descriptor,
125                                busno,
126                                BSP_USR0_I2C_ADDR) < 0 ) {
127                safe_perror("Registering i2c 1st USR eeprom driver failed");
128        } else {
129                succ++;
130        }
131
132        /* Use read-write driver for user eeprom -- you still might
133         * have to disable HW write-protection on your board.
134         */
135        if ( rtems_libi2c_register_drv(
136                                BSP_I2C_USR1_EEPROM_NAME,
137                                i2c_2b_eeprom_driver_descriptor,
138                                busno,
139                                BSP_USR1_I2C_ADDR) < 0 ) {
140                safe_perror("Registering i2c 2nd USR eeprom driver failed");
141        } else {
142                succ++;
143        }
144
145        /* The thermostat */
146        if ( rtems_libi2c_register_drv(
147                                BSP_I2C_DS1621_NAME,
148                                i2c_ds1621_driver_descriptor,
149                                busno,
150                                BSP_THM_I2C_ADDR) < 0 ) {
151                safe_perror("Registering i2c ds1621 temp sensor. driver failed");
152        } else {
153                succ++;
154        }
155
156        /* Finally, as an example, register raw access to the
157         * ds1621. The driver above just reads the 8 msb of the
158         * temperature but doesn't support anything else. Using
159         * the raw device node you can write/read individual
160         * control bytes yourself and e.g., program the thermostat...
161         */
162
163        if ( mknod(
164                        BSP_I2C_DS1621_RAW_DEV_NAME,
165                        0666 | S_IFCHR,
166                        rtems_filesystem_make_dev_t(rtems_libi2c_major,
167                                  RTEMS_LIBI2C_MAKE_MINOR(busno,BSP_THM_I2C_ADDR))) ) {
168                safe_perror("Creating device node for raw ds1621 (temp. sensor) access failed");
169        } else {
170                succ++;
171        }
172
173        /* Raw access to RTC */
174        if ( mknod(
175                        BSP_I2C_DS1375_RAW_DEV_NAME,
176                        0666 | S_IFCHR,
177                        rtems_filesystem_make_dev_t(rtems_libi2c_major,
178                                  RTEMS_LIBI2C_MAKE_MINOR(busno,BSP_RTC_I2C_ADDR))) ) {
179                safe_perror("Creating device node for raw ds1375 (rtc) access failed");
180        } else {
181                succ++;
182        }
183
184        safe_printf("%i I2C devices registered\n", succ);
185        return 0;
186}
Note: See TracBrowser for help on using the repository browser.