[e35c696] | 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 | \*===============================================================*/ |
---|
[e570c313] | 19 | |
---|
| 20 | /* |
---|
| 21 | * $Id$ |
---|
| 22 | */ |
---|
| 23 | |
---|
[e35c696] | 24 | #include <mpc83xx/mpc83xx_i2cdrv.h> |
---|
| 25 | #include <libchip/i2c-2b-eeprom.h> |
---|
| 26 | #include <bsp/irq.h> |
---|
| 27 | #include <bsp.h> |
---|
| 28 | |
---|
| 29 | static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[2] = { |
---|
| 30 | /* first channel */ |
---|
| 31 | { |
---|
| 32 | {/* public fields */ |
---|
[574fb67] | 33 | .ops = &mpc83xx_i2c_ops, |
---|
| 34 | .size = sizeof(mpc83xx_i2c_bus_tbl[0]), |
---|
[e35c696] | 35 | }, |
---|
| 36 | { /* our private fields */ |
---|
[574fb67] | 37 | .reg_ptr = &mpc83xx.i2c[0], |
---|
| 38 | .initialized = FALSE, |
---|
| 39 | .irq_number = BSP_IPIC_IRQ_I2C1, |
---|
| 40 | .base_frq = 0 /* will be set during initiailization */ |
---|
[e35c696] | 41 | } |
---|
| 42 | }, |
---|
| 43 | /* second channel */ |
---|
| 44 | { |
---|
| 45 | { /* public fields */ |
---|
[574fb67] | 46 | .ops = &mpc83xx_i2c_ops, |
---|
| 47 | .size = sizeof(mpc83xx_i2c_bus_tbl[1]), |
---|
[e35c696] | 48 | }, |
---|
| 49 | { /* our private fields */ |
---|
[574fb67] | 50 | .reg_ptr = &mpc83xx.i2c[1], |
---|
| 51 | .initialized = FALSE, |
---|
| 52 | .irq_number = BSP_IPIC_IRQ_I2C2, |
---|
| 53 | .base_frq = 0 /* will be set during initiailization */ |
---|
[e35c696] | 54 | } |
---|
[ac7af4a] | 55 | } |
---|
[e35c696] | 56 | }; |
---|
| 57 | |
---|
| 58 | rtems_libi2c_bus_t *mpc83xx_i2c_bus_descriptor[2] = { |
---|
| 59 | &mpc83xx_i2c_bus_tbl[0].bus_desc, |
---|
| 60 | &mpc83xx_i2c_bus_tbl[1].bus_desc |
---|
| 61 | }; |
---|
| 62 | |
---|
| 63 | /*=========================================================================*\ |
---|
| 64 | | Function: | |
---|
| 65 | \*-------------------------------------------------------------------------*/ |
---|
| 66 | rtems_status_code bsp_register_i2c |
---|
| 67 | ( |
---|
| 68 | /*-------------------------------------------------------------------------*\ |
---|
| 69 | | Purpose: | |
---|
| 70 | | register I2C busses and devices | |
---|
| 71 | +---------------------------------------------------------------------------+ |
---|
| 72 | | Input Parameters: | |
---|
| 73 | \*-------------------------------------------------------------------------*/ |
---|
| 74 | void /* <none> */ |
---|
| 75 | ) |
---|
| 76 | /*-------------------------------------------------------------------------*\ |
---|
| 77 | | Return Value: | |
---|
| 78 | | 0 or error code | |
---|
| 79 | \*=========================================================================*/ |
---|
| 80 | |
---|
| 81 | { |
---|
| 82 | int ret_code; |
---|
[55a685b] | 83 | int i2c1_busno,i2c2_busno; |
---|
[e35c696] | 84 | |
---|
| 85 | /* |
---|
[55a685b] | 86 | * init I2C library (if not already done) |
---|
[e35c696] | 87 | */ |
---|
| 88 | rtems_libi2c_initialize (); |
---|
| 89 | |
---|
[42bf1b9] | 90 | /* |
---|
| 91 | * update input frequency of I2c modules into descriptor |
---|
| 92 | */ |
---|
| 93 | /* |
---|
| 94 | * I2C1 is clocked with TSEC 1 |
---|
| 95 | */ |
---|
| 96 | if (((mpc83xx.clk.sccr >> (31-1)) & 0x03) > 0) { |
---|
[ac7af4a] | 97 | mpc83xx_i2c_bus_tbl[0].softc.base_frq = |
---|
[42bf1b9] | 98 | (BSP_bus_frequency |
---|
| 99 | /((mpc83xx.clk.sccr >> (31-1)) & 0x03)); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | mpc83xx_i2c_bus_tbl[1].softc.base_frq = BSP_bus_frequency; |
---|
[e35c696] | 103 | /* |
---|
| 104 | * register first I2C bus |
---|
| 105 | */ |
---|
| 106 | ret_code = rtems_libi2c_register_bus("/dev/i2c1", |
---|
| 107 | mpc83xx_i2c_bus_descriptor[0]); |
---|
| 108 | if (ret_code < 0) { |
---|
| 109 | return -ret_code; |
---|
| 110 | } |
---|
[55a685b] | 111 | i2c1_busno = ret_code; |
---|
[e35c696] | 112 | /* |
---|
| 113 | * register second I2C bus |
---|
| 114 | */ |
---|
| 115 | ret_code = rtems_libi2c_register_bus("/dev/i2c2", |
---|
| 116 | mpc83xx_i2c_bus_descriptor[1]); |
---|
| 117 | if (ret_code < 0) { |
---|
| 118 | return -ret_code; |
---|
| 119 | } |
---|
[55a685b] | 120 | i2c2_busno = ret_code; |
---|
[42bf1b9] | 121 | |
---|
[574fb67] | 122 | #ifdef RTEMS_BSP_I2C_EEPROM_DEVICE_NAME |
---|
| 123 | |
---|
[e35c696] | 124 | /* |
---|
| 125 | * register EEPROM to bus 1, Address 0x50 |
---|
| 126 | */ |
---|
| 127 | ret_code = rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME, |
---|
| 128 | i2c_2b_eeprom_driver_descriptor, |
---|
[55a685b] | 129 | i2c1_busno,0x50); |
---|
[574fb67] | 130 | |
---|
[e35c696] | 131 | if (ret_code < 0) { |
---|
| 132 | return -ret_code; |
---|
| 133 | } |
---|
[42bf1b9] | 134 | |
---|
[574fb67] | 135 | #endif /* RTEMS_BSP_I2C_EEPROM_DEVICE_NAME */ |
---|
| 136 | |
---|
[e35c696] | 137 | /* |
---|
| 138 | * FIXME: register RTC driver, when available |
---|
| 139 | */ |
---|
| 140 | return 0; |
---|
| 141 | } |
---|