summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/gen83xx/i2c/i2c_init.c
blob: 0ed7cf8d1e076c7b99ba6d240967f36e8a962638 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*===============================================================*\
| Project: RTEMS support for MPC83xx                              |
+-----------------------------------------------------------------+
|                    Copyright (c) 2007                           |
|                    Embedded Brains GmbH                         |
|                    Obere Lagerstr. 30                           |
|                    D-82178 Puchheim                             |
|                    Germany                                      |
|                    rtems@embedded-brains.de                     |
+-----------------------------------------------------------------+
| The license and distribution terms for this file may be         |
| found in the file LICENSE in this distribution or at            |
|                                                                 |
| http://www.rtems.com/license/LICENSE.                           |
|                                                                 |
+-----------------------------------------------------------------+
| this file contains the low level MPC83xx I2C driver parameters  |
\*===============================================================*/

/*
 *  $Id$
 */

#include <mpc83xx/mpc83xx_i2cdrv.h>
#include <libchip/i2c-2b-eeprom.h>
#include <bsp/irq.h>
#include <bsp.h>

static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[2] = {
  /* first channel */
  {
    {/* public fields */
      .ops = &mpc83xx_i2c_ops,
      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
    },
    { /* our private fields */
      .reg_ptr = &mpc83xx.i2c[0],
      .initialized = FALSE,
      .irq_number = BSP_IPIC_IRQ_I2C1,
      .base_frq = 0 /* will be set during initiailization */
    }
  },
  /* second channel */
  {
    { /* public fields */
      .ops = &mpc83xx_i2c_ops,
      .size = sizeof(mpc83xx_i2c_bus_tbl[1]),
    },
    { /* our private fields */
      .reg_ptr = &mpc83xx.i2c[1],
      .initialized = FALSE,
      .irq_number = BSP_IPIC_IRQ_I2C2,
      .base_frq = 0 /* will be set during initiailization */
    }
  }
};

rtems_libi2c_bus_t *mpc83xx_i2c_bus_descriptor[2] = {
  &mpc83xx_i2c_bus_tbl[0].bus_desc,
  &mpc83xx_i2c_bus_tbl[1].bus_desc
};

/*=========================================================================*\
| Function:                                                                 |
\*-------------------------------------------------------------------------*/
rtems_status_code bsp_register_i2c
(
/*-------------------------------------------------------------------------*\
| Purpose:                                                                  |
|   register I2C busses and devices                                         |
+---------------------------------------------------------------------------+
| Input Parameters:                                                         |
\*-------------------------------------------------------------------------*/
 void                                    /* <none>                         */
)
/*-------------------------------------------------------------------------*\
| Return Value:                                                             |
|    0 or error code                                                        |
\*=========================================================================*/

{
  int ret_code;
  int i2c1_busno,i2c2_busno;

  /*
   * init I2C library (if not already done)
   */
  rtems_libi2c_initialize ();

  /*
   * update input frequency of I2c modules into descriptor
   */
  /*
   * I2C1 is clocked with TSEC 1
   */
  if (((mpc83xx.clk.sccr >> (31-1)) & 0x03) > 0) {
    mpc83xx_i2c_bus_tbl[0].softc.base_frq =
      (BSP_bus_frequency
       /((mpc83xx.clk.sccr >> (31-1)) & 0x03));
  }

  mpc83xx_i2c_bus_tbl[1].softc.base_frq = BSP_bus_frequency;
  /*
   * register first I2C bus
   */
  ret_code = rtems_libi2c_register_bus("/dev/i2c1",
				       mpc83xx_i2c_bus_descriptor[0]);
  if (ret_code < 0) {
    return -ret_code;
  }
  i2c1_busno = ret_code;
  /*
   * register second I2C bus
   */
  ret_code = rtems_libi2c_register_bus("/dev/i2c2",
				       mpc83xx_i2c_bus_descriptor[1]);
  if (ret_code < 0) {
    return -ret_code;
  }
  i2c2_busno = ret_code;

#ifdef RTEMS_BSP_I2C_EEPROM_DEVICE_NAME

  /*
   * register EEPROM to bus 1, Address 0x50
   */
  ret_code = rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME,
				       i2c_2b_eeprom_driver_descriptor,
				       i2c1_busno,0x50);

  if (ret_code < 0) {
    return -ret_code;
  }

#endif /* RTEMS_BSP_I2C_EEPROM_DEVICE_NAME */

  /*
   * FIXME: register RTC driver, when available
   */
  return 0;
}