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

Last change on this file since fe8b4b6c was fe8b4b6c, checked in by Joel Sherrill <joel@…>, on 07/11/22 at 22:28:07

bsps/powerpc/83xx: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * RTEMS support for MPC83xx
5 *
6 * This file contains the low level MPC83xx I2C driver parameters.
7 */
8
9/*
10 * Copyright (c) 2007 embedded brains GmbH. All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <mpc83xx/mpc83xx_i2cdrv.h>
35#include <libchip/i2c-2b-eeprom.h>
36#include <libchip/i2c-sc620.h>
37#include <bsp/irq.h>
38#include <bsp.h>
39
40static void i2c1_probe(mpc83xx_i2c_softc_t *self)
41{
42#if MPC83XX_CHIP_TYPE != 8309
43  if (((mpc83xx.clk.sccr >> (31-1)) & 0x03) > 0) {
44    self->base_frq =
45      (BSP_bus_frequency
46       /((mpc83xx.clk.sccr >> (31-1)) & 0x03));
47  }
48#else /* MPC83XX_CHIP_TYPE != 8309 */
49  self->base_frq = BSP_bus_frequency;
50#endif /* MPC83XX_CHIP_TYPE != 8309 */
51}
52
53#ifndef MPC83XX_BOARD_BR_UID
54static void i2c2_probe(mpc83xx_i2c_softc_t *self)
55{
56  self->base_frq = BSP_bus_frequency;
57}
58#endif /* MPC83XX_BOARD_BR_UID */
59
60static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[] = {
61  /* first channel */
62  {
63    {/* public fields */
64      .ops = &mpc83xx_i2c_ops,
65      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
66    },
67    { /* our private fields */
68      .reg_ptr = &mpc83xx.i2c[0],
69      .initialized = FALSE,
70      .irq_number = BSP_IPIC_IRQ_I2C1,
71      .base_frq = 0, /* will be set during probe */
72      .probe = i2c1_probe
73    }
74  }
75#ifndef MPC83XX_BOARD_BR_UID
76  /* second channel */
77  , {
78    { /* public fields */
79      .ops = &mpc83xx_i2c_ops,
80      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
81    },
82    { /* our private fields */
83      .reg_ptr = &mpc83xx.i2c[1],
84      .initialized = FALSE,
85      .irq_number = BSP_IPIC_IRQ_I2C2,
86      .base_frq = 0, /* will be set during probe */
87      .probe = i2c2_probe
88    }
89  }
90#endif /* MPC83XX_BOARD_BR_UID */
91};
92
93/*=========================================================================*\
94| Function:                                                                 |
95\*-------------------------------------------------------------------------*/
96rtems_status_code bsp_register_i2c
97(
98/*-------------------------------------------------------------------------*\
99| Purpose:                                                                  |
100|   register I2C busses and devices                                         |
101+---------------------------------------------------------------------------+
102| Input Parameters:                                                         |
103\*-------------------------------------------------------------------------*/
104 void                                    /* <none>                         */
105)
106/*-------------------------------------------------------------------------*\
107| Return Value:                                                             |
108|    0 or error code                                                        |
109\*=========================================================================*/
110
111{
112  char device_path[] = "/dev/i2c?";
113  size_t n = RTEMS_ARRAY_SIZE(mpc83xx_i2c_bus_tbl);
114  size_t i;
115  int i2c_busno[n];
116
117  /*
118   * init I2C library (if not already done)
119   */
120  rtems_libi2c_initialize ();
121
122  /*
123   * init I2C buses
124   */
125  for (i = 0; i < n; ++i) {
126    mpc83xx_i2c_desc_t *desc = &mpc83xx_i2c_bus_tbl[i];
127
128    (*desc->softc.probe)(&desc->softc);
129    device_path[sizeof(device_path) - 2] = (char) ('1' + i);
130    i2c_busno[i] = rtems_libi2c_register_bus(device_path, &desc->bus_desc);
131  }
132
133#if defined(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME)
134  if (n > 0) {
135    /*
136     * register EEPROM to bus 1, Address 0x50
137     */
138    rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME,
139                 i2c_2b_eeprom_driver_descriptor,
140                 i2c_busno[0],0x50);
141  }
142#elif defined(MPC83XX_BOARD_BR_UID)
143  if (n > 0) {
144    rtems_libi2c_register_drv(
145      "sc620",
146      &i2c_sc620_driver,
147      i2c_busno[0],
148      0x70
149    );
150  }
151#else
152
153  /*
154   * We have no i2c configuration for this variant but need to mark
155   * i2c_busno as used.
156   */
157   (void) i2c_busno[0]; /* avoid set but not used warning */
158#endif
159
160  /*
161   * FIXME: register RTC driver, when available
162   */
163
164  return RTEMS_SUCCESSFUL;
165}
Note: See TracBrowser for help on using the repository browser.