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
RevLine 
[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|                                                                 |
[c499856]14| http://www.rtems.org/license/LICENSE.                           |
[e35c696]15|                                                                 |
16+-----------------------------------------------------------------+
17| this file contains the low level MPC83xx I2C driver parameters  |
18\*===============================================================*/
[e570c313]19
20
[e35c696]21#include <mpc83xx/mpc83xx_i2cdrv.h>
22#include <libchip/i2c-2b-eeprom.h>
[da80202]23#include <libchip/i2c-sc620.h>
[e35c696]24#include <bsp/irq.h>
25#include <bsp.h>
26
[aeff597]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[] = {
[e35c696]48  /* first channel */
49  {
50    {/* public fields */
[574fb67]51      .ops = &mpc83xx_i2c_ops,
52      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
[e35c696]53    },
54    { /* our private fields */
[574fb67]55      .reg_ptr = &mpc83xx.i2c[0],
56      .initialized = FALSE,
57      .irq_number = BSP_IPIC_IRQ_I2C1,
[aeff597]58      .base_frq = 0, /* will be set during probe */
59      .probe = i2c1_probe
[e35c696]60    }
[aeff597]61  }
62#ifndef MPC83XX_BOARD_BR_UID
[e35c696]63  /* second channel */
[aeff597]64  , {
[e35c696]65    { /* public fields */
[574fb67]66      .ops = &mpc83xx_i2c_ops,
[aeff597]67      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
[e35c696]68    },
69    { /* our private fields */
[574fb67]70      .reg_ptr = &mpc83xx.i2c[1],
71      .initialized = FALSE,
72      .irq_number = BSP_IPIC_IRQ_I2C2,
[aeff597]73      .base_frq = 0, /* will be set during probe */
74      .probe = i2c2_probe
[e35c696]75    }
[ac7af4a]76  }
[aeff597]77#endif /* MPC83XX_BOARD_BR_UID */
[e35c696]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{
[aeff597]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];
[e35c696]103
104  /*
[55a685b]105   * init I2C library (if not already done)
[e35c696]106   */
107  rtems_libi2c_initialize ();
108
[42bf1b9]109  /*
[aeff597]110   * init I2C buses
[42bf1b9]111   */
[aeff597]112  for (i = 0; i < n; ++i) {
113    mpc83xx_i2c_desc_t *desc = &mpc83xx_i2c_bus_tbl[i];
[42bf1b9]114
[aeff597]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);
[e35c696]118  }
[42bf1b9]119
[b5548e5]120#if defined(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME)
[aeff597]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);
[e35c696]128  }
[b5548e5]129#elif defined(MPC83XX_BOARD_BR_UID)
[da80202]130  if (n > 0) {
131    rtems_libi2c_register_drv(
132      "sc620",
133      &i2c_sc620_driver,
134      i2c_busno[0],
135      0x70
136    );
137  }
[b5548e5]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
[da80202]146
[e35c696]147  /*
148   * FIXME: register RTC driver, when available
149   */
[aeff597]150
151  return RTEMS_SUCCESSFUL;
[e35c696]152}
Note: See TracBrowser for help on using the repository browser.