source: rtems/bsps/powerpc/gen83xx/i2c/i2c_init.c @ 762fa62

5
Last change on this file since 762fa62 was a2dad96, checked in by Sebastian Huber <sebastian.huber@…>, on 04/23/18 at 07:45:28

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: 4.9 KB
Line 
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.org/license/LICENSE.                           |
15|                                                                 |
16+-----------------------------------------------------------------+
17| this file contains the low level MPC83xx I2C driver parameters  |
18\*===============================================================*/
19
20
21#include <mpc83xx/mpc83xx_i2cdrv.h>
22#include <libchip/i2c-2b-eeprom.h>
23#include <libchip/i2c-sc620.h>
24#include <bsp/irq.h>
25#include <bsp.h>
26
27static void i2c1_probe(mpc83xx_i2c_softc_t *self)
28{
29#if MPC83XX_CHIP_TYPE != 8309
30  if (((mpc83xx.clk.sccr >> (31-1)) & 0x03) > 0) {
31    self->base_frq =
32      (BSP_bus_frequency
33       /((mpc83xx.clk.sccr >> (31-1)) & 0x03));
34  }
35#else /* MPC83XX_CHIP_TYPE != 8309 */
36  self->base_frq = BSP_bus_frequency;
37#endif /* MPC83XX_CHIP_TYPE != 8309 */
38}
39
40#ifndef MPC83XX_BOARD_BR_UID
41static void i2c2_probe(mpc83xx_i2c_softc_t *self)
42{
43  self->base_frq = BSP_bus_frequency;
44}
45#endif /* MPC83XX_BOARD_BR_UID */
46
47static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[] = {
48  /* first channel */
49  {
50    {/* public fields */
51      .ops = &mpc83xx_i2c_ops,
52      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
53    },
54    { /* our private fields */
55      .reg_ptr = &mpc83xx.i2c[0],
56      .initialized = FALSE,
57      .irq_number = BSP_IPIC_IRQ_I2C1,
58      .base_frq = 0, /* will be set during probe */
59      .probe = i2c1_probe
60    }
61  }
62#ifndef MPC83XX_BOARD_BR_UID
63  /* second channel */
64  , {
65    { /* public fields */
66      .ops = &mpc83xx_i2c_ops,
67      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
68    },
69    { /* our private fields */
70      .reg_ptr = &mpc83xx.i2c[1],
71      .initialized = FALSE,
72      .irq_number = BSP_IPIC_IRQ_I2C2,
73      .base_frq = 0, /* will be set during probe */
74      .probe = i2c2_probe
75    }
76  }
77#endif /* MPC83XX_BOARD_BR_UID */
78};
79
80/*=========================================================================*\
81| Function:                                                                 |
82\*-------------------------------------------------------------------------*/
83rtems_status_code bsp_register_i2c
84(
85/*-------------------------------------------------------------------------*\
86| Purpose:                                                                  |
87|   register I2C busses and devices                                         |
88+---------------------------------------------------------------------------+
89| Input Parameters:                                                         |
90\*-------------------------------------------------------------------------*/
91 void                                    /* <none>                         */
92)
93/*-------------------------------------------------------------------------*\
94| Return Value:                                                             |
95|    0 or error code                                                        |
96\*=========================================================================*/
97
98{
99  char device_path[] = "/dev/i2c?";
100  size_t n = RTEMS_ARRAY_SIZE(mpc83xx_i2c_bus_tbl);
101  size_t i;
102  int i2c_busno[n];
103
104  /*
105   * init I2C library (if not already done)
106   */
107  rtems_libi2c_initialize ();
108
109  /*
110   * init I2C buses
111   */
112  for (i = 0; i < n; ++i) {
113    mpc83xx_i2c_desc_t *desc = &mpc83xx_i2c_bus_tbl[i];
114
115    (*desc->softc.probe)(&desc->softc);
116    device_path[sizeof(device_path) - 2] = (char) ('1' + i);
117    i2c_busno[i] = rtems_libi2c_register_bus(device_path, &desc->bus_desc);
118  }
119
120#if defined(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME)
121  if (n > 0) {
122    /*
123     * register EEPROM to bus 1, Address 0x50
124     */
125    rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME,
126                 i2c_2b_eeprom_driver_descriptor,
127                 i2c_busno[0],0x50);
128  }
129#elif defined(MPC83XX_BOARD_BR_UID)
130  if (n > 0) {
131    rtems_libi2c_register_drv(
132      "sc620",
133      &i2c_sc620_driver,
134      i2c_busno[0],
135      0x70
136    );
137  }
138#else
139
140  /*
141   * We have no i2c configuration for this variant but need to mark
142   * i2c_busno as used.
143   */
144   (void) i2c_busno[0]; /* avoid set but not used warning */
145#endif
146
147  /*
148   * FIXME: register RTC driver, when available
149   */
150
151  return RTEMS_SUCCESSFUL;
152}
Note: See TracBrowser for help on using the repository browser.