1 | /*===============================================================*\ |
---|
2 | | Project: RTEMS support for MPC83xx | |
---|
3 | +-----------------------------------------------------------------+ |
---|
4 | | Copyright (c) 2007 | |
---|
5 | | Embedded Brains GmbH | |
---|
6 | | Obere Lagerstr. 30 | |
---|
7 | | D-82178 Puchheim | |
---|
8 | | Germany | |
---|
9 | | rtems@embedded-brains.de | |
---|
10 | +-----------------------------------------------------------------+ |
---|
11 | | The license and distribution terms for this file may be | |
---|
12 | | found in the file LICENSE in this distribution or at | |
---|
13 | | | |
---|
14 | | http://www.rtems.com/license/LICENSE. | |
---|
15 | | | |
---|
16 | +-----------------------------------------------------------------+ |
---|
17 | | this file contains the low level MPC83xx I2C driver parameters | |
---|
18 | \*===============================================================*/ |
---|
19 | #include <mpc83xx/mpc83xx_i2cdrv.h> |
---|
20 | #include <libchip/i2c-2b-eeprom.h> |
---|
21 | #include <bsp/irq.h> |
---|
22 | #include <bsp.h> |
---|
23 | |
---|
24 | static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[2] = { |
---|
25 | /* first channel */ |
---|
26 | { |
---|
27 | {/* public fields */ |
---|
28 | .ops = &mpc83xx_i2c_ops, |
---|
29 | .size = sizeof(mpc83xx_i2c_bus_tbl[0]), |
---|
30 | }, |
---|
31 | { /* our private fields */ |
---|
32 | .reg_ptr = &mpc83xx.i2c[0], |
---|
33 | .initialized = FALSE, |
---|
34 | .irq_number = BSP_IPIC_IRQ_I2C1, |
---|
35 | .base_frq = 0 /* will be set during initiailization */ |
---|
36 | } |
---|
37 | }, |
---|
38 | /* second channel */ |
---|
39 | { |
---|
40 | { /* public fields */ |
---|
41 | .ops = &mpc83xx_i2c_ops, |
---|
42 | .size = sizeof(mpc83xx_i2c_bus_tbl[1]), |
---|
43 | }, |
---|
44 | { /* our private fields */ |
---|
45 | .reg_ptr = &mpc83xx.i2c[1], |
---|
46 | .initialized = FALSE, |
---|
47 | .irq_number = BSP_IPIC_IRQ_I2C2, |
---|
48 | .base_frq = 0 /* will be set during initiailization */ |
---|
49 | } |
---|
50 | } |
---|
51 | }; |
---|
52 | |
---|
53 | rtems_libi2c_bus_t *mpc83xx_i2c_bus_descriptor[2] = { |
---|
54 | &mpc83xx_i2c_bus_tbl[0].bus_desc, |
---|
55 | &mpc83xx_i2c_bus_tbl[1].bus_desc |
---|
56 | }; |
---|
57 | |
---|
58 | /*=========================================================================*\ |
---|
59 | | Function: | |
---|
60 | \*-------------------------------------------------------------------------*/ |
---|
61 | rtems_status_code bsp_register_i2c |
---|
62 | ( |
---|
63 | /*-------------------------------------------------------------------------*\ |
---|
64 | | Purpose: | |
---|
65 | | register I2C busses and devices | |
---|
66 | +---------------------------------------------------------------------------+ |
---|
67 | | Input Parameters: | |
---|
68 | \*-------------------------------------------------------------------------*/ |
---|
69 | void /* <none> */ |
---|
70 | ) |
---|
71 | /*-------------------------------------------------------------------------*\ |
---|
72 | | Return Value: | |
---|
73 | | 0 or error code | |
---|
74 | \*=========================================================================*/ |
---|
75 | |
---|
76 | { |
---|
77 | int ret_code; |
---|
78 | int i2c1_busno,i2c2_busno; |
---|
79 | |
---|
80 | /* |
---|
81 | * init I2C library (if not already done) |
---|
82 | */ |
---|
83 | rtems_libi2c_initialize (); |
---|
84 | |
---|
85 | /* |
---|
86 | * update input frequency of I2c modules into descriptor |
---|
87 | */ |
---|
88 | /* |
---|
89 | * I2C1 is clocked with TSEC 1 |
---|
90 | */ |
---|
91 | if (((mpc83xx.clk.sccr >> (31-1)) & 0x03) > 0) { |
---|
92 | mpc83xx_i2c_bus_tbl[0].softc.base_frq = |
---|
93 | (BSP_bus_frequency |
---|
94 | /((mpc83xx.clk.sccr >> (31-1)) & 0x03)); |
---|
95 | } |
---|
96 | |
---|
97 | mpc83xx_i2c_bus_tbl[1].softc.base_frq = BSP_bus_frequency; |
---|
98 | /* |
---|
99 | * register first I2C bus |
---|
100 | */ |
---|
101 | ret_code = rtems_libi2c_register_bus("/dev/i2c1", |
---|
102 | mpc83xx_i2c_bus_descriptor[0]); |
---|
103 | if (ret_code < 0) { |
---|
104 | return -ret_code; |
---|
105 | } |
---|
106 | i2c1_busno = ret_code; |
---|
107 | /* |
---|
108 | * register second I2C bus |
---|
109 | */ |
---|
110 | ret_code = rtems_libi2c_register_bus("/dev/i2c2", |
---|
111 | mpc83xx_i2c_bus_descriptor[1]); |
---|
112 | if (ret_code < 0) { |
---|
113 | return -ret_code; |
---|
114 | } |
---|
115 | i2c2_busno = ret_code; |
---|
116 | |
---|
117 | #ifdef RTEMS_BSP_I2C_EEPROM_DEVICE_NAME |
---|
118 | |
---|
119 | /* |
---|
120 | * register EEPROM to bus 1, Address 0x50 |
---|
121 | */ |
---|
122 | ret_code = rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME, |
---|
123 | i2c_2b_eeprom_driver_descriptor, |
---|
124 | i2c1_busno,0x50); |
---|
125 | |
---|
126 | if (ret_code < 0) { |
---|
127 | return -ret_code; |
---|
128 | } |
---|
129 | |
---|
130 | #endif /* RTEMS_BSP_I2C_EEPROM_DEVICE_NAME */ |
---|
131 | |
---|
132 | /* |
---|
133 | * FIXME: register RTC driver, when available |
---|
134 | */ |
---|
135 | return 0; |
---|
136 | } |
---|