[rtems commit] bsps/powerpc: Add probe handler to I2C driver

Sebastian Huber sebh at rtems.org
Wed Jan 9 15:41:06 UTC 2013


Module:    rtems
Branch:    master
Commit:    aeff597721115e3ba6fa8635e326eee465aecd3d
Changeset: http://git.rtems.org/rtems/commit/?id=aeff597721115e3ba6fa8635e326eee465aecd3d

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jan  9 13:17:18 2013 +0100

bsps/powerpc: Add probe handler to I2C driver

---

 c/src/lib/libbsp/powerpc/gen83xx/i2c/i2c_init.c    |  101 ++++++++++----------
 c/src/lib/libbsp/powerpc/mpc55xxevb/i2c/i2c_init.c |    9 ++-
 .../libcpu/powerpc/mpc83xx/i2c/mpc83xx_i2cdrv.h    |    1 +
 3 files changed, 57 insertions(+), 54 deletions(-)

diff --git a/c/src/lib/libbsp/powerpc/gen83xx/i2c/i2c_init.c b/c/src/lib/libbsp/powerpc/gen83xx/i2c/i2c_init.c
index 9b30d0f..16d11d7 100644
--- a/c/src/lib/libbsp/powerpc/gen83xx/i2c/i2c_init.c
+++ b/c/src/lib/libbsp/powerpc/gen83xx/i2c/i2c_init.c
@@ -23,7 +23,27 @@
 #include <bsp/irq.h>
 #include <bsp.h>
 
-static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[2] = {
+static void i2c1_probe(mpc83xx_i2c_softc_t *self)
+{
+#if MPC83XX_CHIP_TYPE != 8309
+  if (((mpc83xx.clk.sccr >> (31-1)) & 0x03) > 0) {
+    self->base_frq =
+      (BSP_bus_frequency
+       /((mpc83xx.clk.sccr >> (31-1)) & 0x03));
+  }
+#else /* MPC83XX_CHIP_TYPE != 8309 */
+  self->base_frq = BSP_bus_frequency;
+#endif /* MPC83XX_CHIP_TYPE != 8309 */
+}
+
+#ifndef MPC83XX_BOARD_BR_UID
+static void i2c2_probe(mpc83xx_i2c_softc_t *self)
+{
+  self->base_frq = BSP_bus_frequency;
+}
+#endif /* MPC83XX_BOARD_BR_UID */
+
+static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[] = {
   /* first channel */
   {
     {/* public fields */
@@ -34,27 +54,26 @@ static mpc83xx_i2c_desc_t mpc83xx_i2c_bus_tbl[2] = {
       .reg_ptr = &mpc83xx.i2c[0],
       .initialized = FALSE,
       .irq_number = BSP_IPIC_IRQ_I2C1,
-      .base_frq = 0 /* will be set during initiailization */
+      .base_frq = 0, /* will be set during probe */
+      .probe = i2c1_probe
     }
-  },
+  }
+#ifndef MPC83XX_BOARD_BR_UID
   /* second channel */
-  {
+  , {
     { /* public fields */
       .ops = &mpc83xx_i2c_ops,
-      .size = sizeof(mpc83xx_i2c_bus_tbl[1]),
+      .size = sizeof(mpc83xx_i2c_bus_tbl[0]),
     },
     { /* our private fields */
       .reg_ptr = &mpc83xx.i2c[1],
       .initialized = FALSE,
       .irq_number = BSP_IPIC_IRQ_I2C2,
-      .base_frq = 0 /* will be set during initiailization */
+      .base_frq = 0, /* will be set during probe */
+      .probe = i2c2_probe
     }
   }
-};
-
-rtems_libi2c_bus_t *mpc83xx_i2c_bus_descriptor[2] = {
-  &mpc83xx_i2c_bus_tbl[0].bus_desc,
-  &mpc83xx_i2c_bus_tbl[1].bus_desc
+#endif /* MPC83XX_BOARD_BR_UID */
 };
 
 /*=========================================================================*\
@@ -76,8 +95,10 @@ rtems_status_code bsp_register_i2c
 \*=========================================================================*/
 
 {
-  int ret_code;
-  int i2c1_busno,i2c2_busno;
+  char device_path[] = "/dev/i2c?";
+  size_t n = RTEMS_ARRAY_SIZE(mpc83xx_i2c_bus_tbl);
+  size_t i;
+  int i2c_busno[n];
 
   /*
    * init I2C library (if not already done)
@@ -85,54 +106,30 @@ rtems_status_code bsp_register_i2c
   rtems_libi2c_initialize ();
 
   /*
-   * update input frequency of I2c modules into descriptor
-   */
-  /*
-   * I2C1 is clocked with TSEC 1
+   * init I2C buses
    */
-  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));
-  }
+  for (i = 0; i < n; ++i) {
+    mpc83xx_i2c_desc_t *desc = &mpc83xx_i2c_bus_tbl[i];
 
-  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;
+    (*desc->softc.probe)(&desc->softc);
+    device_path[sizeof(device_path) - 2] = (char) ('1' + i);
+    i2c_busno[i] = rtems_libi2c_register_bus(device_path, &desc->bus_desc);
   }
-  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;
+  if (n > 0) {
+    /*
+     * register EEPROM to bus 1, Address 0x50
+     */
+    rtems_libi2c_register_drv(RTEMS_BSP_I2C_EEPROM_DEVICE_NAME,
+                 i2c_2b_eeprom_driver_descriptor,
+                 i2c_busno[0],0x50);
   }
-
 #endif /* RTEMS_BSP_I2C_EEPROM_DEVICE_NAME */
 
   /*
    * FIXME: register RTC driver, when available
    */
-  return 0;
+
+  return RTEMS_SUCCESSFUL;
 }
diff --git a/c/src/lib/libbsp/powerpc/mpc55xxevb/i2c/i2c_init.c b/c/src/lib/libbsp/powerpc/mpc55xxevb/i2c/i2c_init.c
index 3103531..92e830d 100644
--- a/c/src/lib/libbsp/powerpc/mpc55xxevb/i2c/i2c_init.c
+++ b/c/src/lib/libbsp/powerpc/mpc55xxevb/i2c/i2c_init.c
@@ -24,6 +24,11 @@
 #include <bsp/mpc83xx_i2cdrv.h>
 
 #if MPC55XX_CHIP_FAMILY == 551
+  static void i2c_probe(mpc83xx_i2c_softc_t *self)
+  {
+    self->base_frq = bsp_clock_speed;
+  }
+
   static mpc83xx_i2c_desc_t mpc55xx_i2c_bus = {
     .bus_desc = {
       .ops = &mpc83xx_i2c_ops,
@@ -33,7 +38,8 @@
       .reg_ptr = (m83xxI2CRegisters_t *) 0xfff88000,
       .initialized = FALSE,
       .irq_number = MPC55XX_IRQ_I2C(0),
-      .base_frq = 0
+      .base_frq = 0,
+      .probe = i2c_probe
     }
   };
 
@@ -44,7 +50,6 @@
 
     rtems_libi2c_initialize ();
 
-    mpc55xx_i2c_bus.softc.base_frq = bsp_clock_speed;
     busno = rtems_libi2c_register_bus(
       "/dev/i2c1",
       &mpc55xx_i2c_bus.bus_desc
diff --git a/c/src/lib/libcpu/powerpc/mpc83xx/i2c/mpc83xx_i2cdrv.h b/c/src/lib/libcpu/powerpc/mpc83xx/i2c/mpc83xx_i2cdrv.h
index 0353f62..bb3547e 100644
--- a/c/src/lib/libcpu/powerpc/mpc83xx/i2c/mpc83xx_i2cdrv.h
+++ b/c/src/lib/libcpu/powerpc/mpc83xx/i2c/mpc83xx_i2cdrv.h
@@ -49,6 +49,7 @@ typedef struct mpc83xx_i2c_softc {
   rtems_irq_number     irq_number;  /* IRQ number used for this module */
   uint32_t             base_frq;    /* input frq for baud rate divider */
   rtems_id             irq_sema_id; /* SEMA used for IRQ signalling    */
+  void               (*probe)(struct mpc83xx_i2c_softc *self);
 } mpc83xx_i2c_softc_t ;
 
 typedef struct {




More information about the vc mailing list