Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:53

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * RTEMS support for MPC83xx
0005  *
0006  * This file contains the low level MPC83xx I2C driver parameters.
0007  */
0008 
0009 /*
0010  * Copyright (c) 2007 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 #include <mpc83xx/mpc83xx_i2cdrv.h>
0035 #include <libchip/i2c-2b-eeprom.h>
0036 #include <libchip/i2c-sc620.h>
0037 #include <bsp/irq.h>
0038 #include <bsp.h>
0039 
0040 static void i2c1_probe(mpc83xx_i2c_softc_t *self)
0041 {
0042 #if MPC83XX_CHIP_TYPE != 8309
0043   if (((mpc83xx.clk.sccr >> (31-1)) & 0x03) > 0) {
0044     self->base_frq =
0045       (BSP_bus_frequency
0046        /((mpc83xx.clk.sccr >> (31-1)) & 0x03));
0047   }
0048 #else /* MPC83XX_CHIP_TYPE != 8309 */
0049   self->base_frq = BSP_bus_frequency;
0050 #endif /* MPC83XX_CHIP_TYPE != 8309 */
0051 }
0052 
0053 #ifndef MPC83XX_BOARD_BR_UID
0054 static void i2c2_probe(mpc83xx_i2c_softc_t *self)
0055 {
0056   self->base_frq = BSP_bus_frequency;
0057 }
0058 #endif /* MPC83XX_BOARD_BR_UID */
0059 
0060 static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[] = {
0061   /* first channel */
0062   {
0063     {/* public fields */
0064       .ops = &mpc83xx_i2c_ops,
0065       .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
0066     },
0067     { /* our private fields */
0068       .reg_ptr = &mpc83xx.i2c[0],
0069       .initialized = FALSE,
0070       .irq_number = BSP_IPIC_IRQ_I2C1,
0071       .base_frq = 0, /* will be set during probe */
0072       .probe = i2c1_probe
0073     }
0074   }
0075 #ifndef MPC83XX_BOARD_BR_UID
0076   /* second channel */
0077   , {
0078     { /* public fields */
0079       .ops = &mpc83xx_i2c_ops,
0080       .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
0081     },
0082     { /* our private fields */
0083       .reg_ptr = &mpc83xx.i2c[1],
0084       .initialized = FALSE,
0085       .irq_number = BSP_IPIC_IRQ_I2C2,
0086       .base_frq = 0, /* will be set during probe */
0087       .probe = i2c2_probe
0088     }
0089   }
0090 #endif /* MPC83XX_BOARD_BR_UID */
0091 };
0092 
0093 /*=========================================================================*\
0094 | Function:                                                                 |
0095 \*-------------------------------------------------------------------------*/
0096 rtems_status_code bsp_register_i2c
0097 (
0098 /*-------------------------------------------------------------------------*\
0099 | Purpose:                                                                  |
0100 |   register I2C busses and devices                                         |
0101 +---------------------------------------------------------------------------+
0102 | Input Parameters:                                                         |
0103 \*-------------------------------------------------------------------------*/
0104  void                                    /* <none>                         */
0105 )
0106 /*-------------------------------------------------------------------------*\
0107 | Return Value:                                                             |
0108 |    0 or error code                                                        |
0109 \*=========================================================================*/
0110 
0111 {
0112   char device_path[] = "/dev/i2c?";
0113   size_t n = RTEMS_ARRAY_SIZE(mpc83xx_i2c_bus_tbl);
0114   size_t i;
0115   int i2c_busno[n];
0116 
0117   /*
0118    * init I2C library (if not already done)
0119    */
0120   rtems_libi2c_initialize ();
0121 
0122   /*
0123    * init I2C buses
0124    */
0125   for (i = 0; i < n; ++i) {
0126     mpc83xx_i2c_desc_t *desc = &mpc83xx_i2c_bus_tbl[i];
0127 
0128     (*desc->softc.probe)(&desc->softc);
0129     device_path[sizeof(device_path) - 2] = (char) ('1' + i);
0130     i2c_busno[i] = rtems_libi2c_register_bus(device_path, &desc->bus_desc);
0131   }
0132 
0133 #if defined(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME)
0134   if (n > 0) {
0135     /*
0136      * register EEPROM to bus 1, Address 0x50
0137      */
0138     rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME,
0139                  i2c_2b_eeprom_driver_descriptor,
0140                  i2c_busno[0],0x50);
0141   }
0142 #elif defined(MPC83XX_BOARD_BR_UID)
0143   if (n > 0) {
0144     rtems_libi2c_register_drv(
0145       "sc620",
0146       &i2c_sc620_driver,
0147       i2c_busno[0],
0148       0x70
0149     );
0150   }
0151 #else
0152 
0153   /*
0154    * We have no i2c configuration for this variant but need to mark
0155    * i2c_busno as used.
0156    */
0157    (void) i2c_busno[0]; /* avoid set but not used warning */
0158 #endif
0159 
0160   /*
0161    * FIXME: register RTC driver, when available
0162    */
0163 
0164   return RTEMS_SUCCESSFUL;
0165 }