Ejemplo n.º 1
0
I2C::~I2C()
{
	if (_dev) {
		up_i2cuninitialize(_dev);
		_dev = nullptr;
	}
}
Ejemplo n.º 2
0
static int io_expander_init(void)
{
    void *driver_data;
    struct i2c_dev_s *dev;

    dev = up_i2cinitialize(0);
    if (!dev) {
        lowsyslog("%s(): Failed to get I/O Expander I2C bus 0\n", __func__);
        return -ENODEV;
    } else {
        if (tca64xx_init(&driver_data,
                         TCA6408_PART,
                         dev,
                         TCA6408_U72,
                         TCA6408_U72_RST_GPIO,
                         TCA6408_U72_INT_GPIO,
                         TCA6408_GPIO_BASE) < 0) {
            lowsyslog("%s(): Failed to register I/O Expander(0x%02x)\n",
                      __func__, TCA6408_U72);
            up_i2cuninitialize(dev);
            return -ENODEV;
        }
    }

    return 0;
}
Ejemplo n.º 3
0
int stm32_lm75initialize(FAR const char *devpath)
{
  FAR struct i2c_dev_s *i2c;
  int ret;

  /* Configure PB.5 as Input pull-up.  This pin can be used as a temperature
   * sensor interrupt (not fully implemented).
   */

  stm32_configgpio(GPIO_LM75_OSINT);

  /* Get an instance of the I2C1 interface */

  i2c =  up_i2cinitialize(1);
  if (!i2c)
    {
      return -ENODEV;
    }

  /* Then register the temperature sensor */

  ret = lm75_register(devpath, i2c, 0x48);
  if (ret < 0)
    {
      (void)up_i2cuninitialize(i2c);
    }
  return ret;
}
Ejemplo n.º 4
0
void ara_board_exit(void) {
    int i;

    /* Run the board specific code */
    if (board_info->board_exit) {
        board_info->board_exit(board_info);
    }

    /*
     * First unregister the TCA64xx I/O Expanders and associated I2C bus(ses).
     * Done in reverse order from registration to account for IRQ chaining
     * between I/O Expander chips.
     */
    for (i = board_info->nr_io_expanders - 1; i >= 0; i--) {
        struct io_expander_info *io_exp = &board_info->io_expanders[i];

        if (io_exp->io_exp_driver_data)
            tca64xx_deinit(io_exp->io_exp_driver_data);

        if (io_exp->i2c_dev)
            up_i2cuninitialize(io_exp->i2c_dev);
    }

    /* Lastly unregister the GPIO Chip driver */
    stm32_gpio_deinit();

    board_info = NULL;
}
Ejemplo n.º 5
0
void board_exit(void) {
    int i;

    /* If we were able to bringup the refclk, turn it off now. */
    if (vreg_get_pwr_state(&refclk_main_vreg) == VREG_PWR_UP) {
        vreg_put(&refclk_main_vreg);
    }

    /*
     * Unregister the TCA64xx I/O Expanders and associated I2C
     * bus(ses).  Done in reverse order from registration to account
     * for IRQ chaining between I/O Expander chips.
     */
    for (i = evt1_board_info.nr_io_expanders - 1; i >= 0; i--) {
        struct io_expander_info *io_exp = &evt1_board_info.io_expanders[i];

        if (io_exp->io_exp_driver_data)
            tca64xx_deinit(io_exp->io_exp_driver_data);

        if (io_exp->i2c_dev)
            up_i2cuninitialize(io_exp->i2c_dev);
    }

    /* Lastly unregister the GPIO Chip driver */
    stm32_gpio_deinit();
}
Ejemplo n.º 6
0
/**
 * @brief           Initialize the power measurement HW and SW library.
 *                  To be called once, before any other call to the library.
 * @return          0 on success, standard error codes otherwise.
 * @param[in]       current_lsb_uA: current measurement precision (LSB) in uA
 * @param[in]       ct: sampling conversion time to be used
 * @param[in]       avg_count: averaging sample count (>0)
 */
int bdbpm_init(uint32_t current_lsb_uA,
               ina230_conversion_time ct,
               ina230_avg_count avg_count)
{
    dbg_verbose("%s(): Initializing with options lsb=%uuA, ct=%u, avg_count=%u...\n",
                __func__, current_lsb_uA, ct, avg_count);
    /* Initialize I2C internal structs */
    i2c_dev = up_i2cinitialize(PWRM_I2C_BUS);
    if (!i2c_dev) {
        dbg_error("%s(): Failed to get I2C bus %u\n", __func__, PWRM_I2C_BUS);
        return -ENXIO;
    }

    bdbpm_current_lsb = current_lsb_uA;
    if (ct >= ina230_ct_count) {
        dbg_error("%s(): invalid conversion time! (%u)\n", __func__, ct);
        up_i2cuninitialize(i2c_dev);
        return -EINVAL;
    }
    if (avg_count >= ina230_avg_count_max) {
        dbg_error("%s(): invalid average count! (%u)\n", __func__, avg_count);
        up_i2cuninitialize(i2c_dev);
        return -EINVAL;
    }
    bdbpm_ct = ct;
    bdbpm_avg_count = avg_count;

    current_dev = -1;

    /*
     * Setup I/O selection pins on U135
     *
     * Note: U135 is registered to gpio_chip from the board code
     */
    gpio_direction_out(I2C_INA230_SEL1_A, 1);
    gpio_direction_out(I2C_INA230_SEL1_B, 1);
    gpio_direction_out(I2C_INA230_SEL1_INH, 1);
    gpio_direction_out(I2C_INA230_SEL2_A, 1);
    gpio_direction_out(I2C_INA230_SEL2_B, 1);
    gpio_direction_out(I2C_INA230_SEL2_INH, 1);

    dbg_verbose("%s(): done.\n", __func__);

    return OK;
}
Ejemplo n.º 7
0
/**
 * @brief           Deinitialize power measurement HW.
 *                  Last function to be called when measurements completed.
 */
void bdbpm_deinit(void)
{
    gpio_set_value(I2C_INA230_SEL1_A, 1);
    gpio_set_value(I2C_INA230_SEL1_B, 1);
    gpio_set_value(I2C_INA230_SEL1_INH, 1);
    gpio_set_value(I2C_INA230_SEL2_A, 1);
    gpio_set_value(I2C_INA230_SEL2_B, 1);
    gpio_set_value(I2C_INA230_SEL2_INH, 1);

    /* Release I2C resource */
    up_i2cuninitialize(i2c_dev);

    return;
}
Ejemplo n.º 8
0
int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, char **argv)
{
	FAR struct i2c_dev_s *dev;
	int i;

	i2ctool_printf(i2ctool, " BUS   EXISTS?\n");
	for (i = CONFIG_I2CTOOL_MINBUS; i <= CONFIG_I2CTOOL_MAXBUS; i++) {
		dev = up_i2cinitialize(i);
		if (dev) {
			i2ctool_printf(i2ctool, "Bus %d: YES\n", i);
			(void)up_i2cuninitialize(dev);
		} else {
			i2ctool_printf(i2ctool, "Bus %d: NO\n", i);
		}
	}

	return OK;
}
Ejemplo n.º 9
0
void board_exit(void) {
    int i;
    /*
     * First unregister the TCA64xx I/O Expanders and associated I2C bus(ses).
     * Done in reverse order from registration to account for IRQ chaining
     * between I/O Expander chips.
     */
    for (i = sdb_board_info.nr_io_expanders - 1; i >= 0; i--) {
        struct io_expander_info *io_exp = &sdb_board_info.io_expanders[i];

        if (io_exp->io_exp_driver_data)
            tca64xx_deinit(io_exp->io_exp_driver_data);

        if (io_exp->i2c_dev)
            up_i2cuninitialize(io_exp->i2c_dev);
    }

    /* Disable the I/O Expanders power */
    vreg_put(&ioexp_vreg);

    /* Lastly unregister the GPIO Chip driver */
    stm32_gpio_deinit();
}
Ejemplo n.º 10
0
int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
{
  FAR struct i2c_dev_s *dev;
  FAR char *ptr;
  uint16_t rdvalue;
  uint8_t regaddr;
  bool addrinaddr;
  long wrvalue;
  long repititions;
  int nargs;
  int argndx;
  int ret;
  int i;

  /* Parse any command line arguments */

  for (argndx = 1; argndx < argc; )
    {
      /* Break out of the look when the last option has been parsed */

      ptr = argv[argndx];
      if (*ptr != '-')
        {
          break;
        }

      /* Otherwise, check for common options */

      nargs = common_args(i2ctool, &argv[argndx]);
      if (nargs < 0)
        {
          return ERROR;
        }
      argndx += nargs;
    }

  /* The options may be followed by the optional wrvalue to be written.  If omitted, then
   * the register address will be used as the wrvalue, providing an address-in-address
   * test.
   */

  addrinaddr = true;
  wrvalue    = 0;

  if (argndx < argc)
    {
      wrvalue = strtol(argv[argndx], NULL, 16);
      if (i2ctool->width == 8)
        {
          if (wrvalue < 0 || wrvalue > 255)
            {
              i2ctool_printf(i2ctool, g_i2cargrange, argv[0]);
              return ERROR;
            }
        }
      else if (wrvalue < 0 || wrvalue > 65535)
        {
          i2ctool_printf(i2ctool, g_i2cargrange, argv[0]);
          return ERROR;
        }

      addrinaddr = false;
      argndx++;
    }

  /* There may be one more thing on the command line:  The repitition
   * count.
   */

  repititions = 1;
  if (argndx < argc)
    {
      repititions = strtol(argv[argndx], NULL, 16);
      if (repititions < 1)
        {
          i2ctool_printf(i2ctool, g_i2cargrange, argv[0]);
          return ERROR;
        }

      argndx++;
    }

  if (argndx != argc)
    {
      i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]);
      return ERROR;
    }

  /* Get a handle to the I2C bus */

  dev = up_i2cinitialize(i2ctool->bus);
  if (!dev)
    {
       i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
       return ERROR;
    }

  /* Set the frequency and the address (NOTE:  Only 7-bit address supported now) */

  I2C_SETFREQUENCY(dev, i2ctool->freq);
  I2C_SETADDRESS(dev, i2ctool->addr, 7);

  /* Loop for the requested number of repititions */

  regaddr = i2ctool->regaddr;
  ret = OK;

  for (i = 0; i < repititions; i++)
    {
      /* If we are performing an address-in-address test, then use the register
       * address as the value to write.
       */

      if (addrinaddr)
        {
          wrvalue = regaddr;
        }

      /* Write to the I2C bus */

      ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)wrvalue);
      if (ret == OK)
        {
          /* Read the value back from the I2C bus */

          ret = i2ctool_get(i2ctool, dev, regaddr, &rdvalue);
        }

      /* Display the result */

      if (ret == OK)
        {
          i2ctool_printf(i2ctool, "VERIFY Bus: %d Addr: %02x Subaddr: %02x Wrote: ",
                         i2ctool->bus, i2ctool->addr, i2ctool->regaddr);

          if (i2ctool->width == 8)
            {
              i2ctool_printf(i2ctool, "%02x Read: %02x", (int)wrvalue, (int)rdvalue);
            }
          else
            {
              i2ctool_printf(i2ctool, "%04x Read: %04x", (int)wrvalue, (int)rdvalue);
            }

          if (wrvalue != rdvalue)
            {
              i2ctool_printf(i2ctool, "  <<< FAILURE\n");
            }
          else
            {
              i2ctool_printf(i2ctool, "\n");
            }
        }
      else
        {
          i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret);
          break;
        }

      /* Auto-increment the address if so configured */

      if (i2ctool->autoincr)
        {
          regaddr++;
        }
    }

  (void)up_i2cuninitialize(dev);
  return ret;
}
Ejemplo n.º 11
0
I2C::~I2C()
{
	if (_dev)
		up_i2cuninitialize(_dev);
}
Ejemplo n.º 12
0
int
I2C::init()
{
	int ret = OK;
	unsigned bus_index;

	// attach to the i2c bus
	_dev = up_i2cinitialize(_bus);

	if (_dev == nullptr) {
		debug("failed to init I2C");
		ret = -ENOENT;
		goto out;
	}

	// the above call fails for a non-existing bus index,
	// so the index math here is safe.
	bus_index = _bus - 1;

	// abort if the max frequency we allow (the frequency we ask)
	// is smaller than the bus frequency
	if (_bus_clocks[bus_index] > _frequency) {
		(void)up_i2cuninitialize(_dev);
		_dev = nullptr;
		log("FAIL: too slow for bus #%u: %u KHz, device max: %u KHz)",
			_bus, _bus_clocks[bus_index] / 1000, _frequency / 1000);
		ret = -EINVAL;
		goto out;
	}

	// set the bus frequency on the first access if it has
	// not been set yet
	if (_bus_clocks[bus_index] == 0) {
		_bus_clocks[bus_index] = _frequency;
	}

	// set frequency for this instance once to the bus speed
	// the bus speed is the maximum supported by all devices on the bus,
	// as we have to prioritize performance over compatibility.
	// If a new device requires a lower clock speed, this has to be
	// manually set via "fmu i2c <bus> <clock>" before starting any
	// drivers.
	// This is necessary as automatically lowering the bus speed
	// for maximum compatibility could induce timing issues on
	// critical sensors the adopter might be unaware of.
	I2C_SETFREQUENCY(_dev, _bus_clocks[bus_index]);

	// call the probe function to check whether the device is present
	ret = probe();

	if (ret != OK) {
		debug("probe failed");
		goto out;
	}

	// do base class init, which will create device node, etc
	ret = CDev::init();

	if (ret != OK) {
		debug("cdev init failed");
		goto out;
	}

	// tell the world where we are
	log("on I2C bus %d at 0x%02x (bus: %u KHz, max: %u KHz)",
		_bus, _address, _bus_clocks[bus_index] / 1000, _frequency / 1000);

out:
	if ((ret != OK) && (_dev != nullptr)) {
		up_i2cuninitialize(_dev);
		_dev = nullptr;
	}
	return ret;
}
Ejemplo n.º 13
0
struct ara_board_info *ara_board_init(void) {
    int i;
    enum hwid hwid = board_get_hwid();
    board_info = NULL;

    /* Check HWID, assign board_info struct and the Switch ES revision */
    switch (hwid) {
    case HWID_DB3_0_1:
        board_info = &db3_board_info;
        dbg_info("HWID found as DB3.0/3.1\n");
        break;
    case HWID_DB3_2:
        /* DB3.0/1 with ES3 Switch */
        board_info = &db3_board_info;
        board_info->sw_data.rev = SWITCH_REV_ES3;
        dbg_info("HWID found as DB3.2\n");
        break;
    case HWID_DB3_5:
        /* EVT1.5 + DB3.5 pwrmon + specific mapping of physical interfaces */
        board_info = &evt1_5_board_info;
        board_info->pwrmon = &db3_5_pwrmon;
        board_info->interfaces = db3_5_interfaces;
        board_info->nr_interfaces = db3_5_nr_interfaces;
        dbg_info("HWID found as DB3.5\n");
        break;
    case HWID_EVT1:
        board_info = &evt1_board_info;
        dbg_info("HWID found as EVT1\n");
        break;
    case HWID_EVT1_5:
        board_info = &evt1_5_board_info;
        dbg_info("HWID found as EVT1.5\n");
        break;
    case HWID_EVT1_6:
        board_info = &evt1_5_board_info;
        board_info->sw_data.rev = SWITCH_REV_ES2;
        dbg_info("HWID found as EVT1.6\n");
        break;
    default:
        return NULL;
    }

    /* Disable the I/O Expanders for now */
    for (i = 0; i < board_info->nr_io_expanders; i++) {
        struct io_expander_info *io_exp = &board_info->io_expanders[i];
        stm32_configgpio(io_exp->reset);
        stm32_gpiowrite(io_exp->reset, false);
    }

    /*
     * Register the STM32 GPIOs to Gpio Chip
     *
     * This needs to happen before the I/O Expanders registration, which
     * uses some STM32 pins
     */
    stm32_gpio_init();

    /* Register the TCA64xx I/O Expanders GPIOs to Gpio Chip */
    for (i = 0; i < board_info->nr_io_expanders; i++) {
        struct io_expander_info *io_exp = &board_info->io_expanders[i];

        io_exp->i2c_dev = up_i2cinitialize(io_exp->i2c_bus);
        if (!io_exp->i2c_dev) {
            dbg_error("%s(): Failed to get I/O Expander I2C bus %u\n",
                      __func__, io_exp->i2c_bus);
            goto err_deinit_gpio;
        } else {
            if (tca64xx_init(&io_exp->io_exp_driver_data,
                             io_exp->part,
                             io_exp->i2c_dev,
                             io_exp->i2c_addr,
                             io_exp->reset,
                             io_exp->irq,
                             io_exp->gpio_base) < 0) {
                dbg_error("%s(): Failed to register I/O Expander(0x%02x)\n",
                          __func__, io_exp->i2c_addr);
                goto err_uninit_i2c;
            }
        }
    }

    /* Run the board specific code */
    if (board_info->board_init) {
        if (board_info->board_init(board_info)) {
            dbg_error("%s(): Failed to initalize board\n", __func__);
            goto err_uninit_i2c;
        }
    }

    /* Return the board specific info */
    return board_info;

 err_uninit_i2c:
    /* Done in reverse order to account for possible IRQ chaining. */
    for (i = board_info->nr_io_expanders - 1; i >= 0; i--) {
        struct io_expander_info *io_exp = &board_info->io_expanders[i];
        if (io_exp->i2c_dev) {
            up_i2cuninitialize(io_exp->i2c_dev);
        }
    }
 err_deinit_gpio:
    stm32_gpio_deinit();
    /* Leave the I/O expanders in reset here. */

    return NULL;
}
Ejemplo n.º 14
0
struct ara_board_info *board_init(void) {
    int i;

    /* Pretty lights */
    stm32_configgpio(SVC_LED_GREEN);
    stm32_gpiowrite(SVC_LED_GREEN, false);

    /* Disable these for now */
    stm32_configgpio(SVC_RST_IOEXP);
    stm32_gpiowrite(SVC_RST_IOEXP, false);

    /*
     * Register the STM32 GPIOs to Gpio Chip
     *
     * This needs to happen before the I/O Expanders registration, which
     * uses some STM32 pins
     */
    stm32_gpio_init();

    /*
     * Configure the switch and I/O Expander reset and power supply lines.
     * Hold all the lines low while we turn on the power rails.
     */
    vreg_config(&ioexp_vreg);
    vreg_config(&sw_vreg);
    stm32_configgpio(sdb_board_info.sw_data.gpio_reset);
    up_udelay(POWER_SWITCH_OFF_STAB_TIME_US);

    /*
     * Enable 1P1 and 1P8, used by the I/O Expanders
     */
    vreg_get(&ioexp_vreg);

    /* Register the TCA64xx I/O Expanders GPIOs to Gpio Chip */
    for (i = 0; i < sdb_board_info.nr_io_expanders; i++) {
        struct io_expander_info *io_exp = &sdb_board_info.io_expanders[i];

        io_exp->i2c_dev = up_i2cinitialize(io_exp->i2c_bus);
        if (!io_exp->i2c_dev) {
            dbg_error("%s(): Failed to get I/O Expander I2C bus %u\n",
                      __func__, io_exp->i2c_bus);
        } else {
            if (tca64xx_init(&io_exp->io_exp_driver_data,
                             io_exp->part,
                             io_exp->i2c_dev,
                             io_exp->i2c_addr,
                             io_exp->reset,
                             io_exp->irq,
                             io_exp->gpio_base) < 0) {
                dbg_error("%s(): Failed to register I/O Expander(0x%02x)\n",
                          __func__, io_exp->i2c_addr);
                up_i2cuninitialize(io_exp->i2c_dev);
            }
        }
    }

    /* Hold USB_HUB_RESET high */
    gpio_direction_out(USB_HUB_RESET, 1);

    return &sdb_board_info;
}
Ejemplo n.º 15
0
void board_initialize(void)
{
  dbg("%d MHz\n", STM32_SYSCLK_FREQUENCY / 1000000);

#if defined(CONFIG_GPIO_CHIP_STM32)
  stm32_gpio_init();
#endif

#ifdef CONFIG_STM32_LPTIM1
  stm32_lptim1_on();
#endif

#ifdef CONFIG_STM32_SPI
  stm32_spiinitialize();
#endif

#ifdef CONFIG_MODS_DIET
  mods_init();
#endif

#ifndef CONFIG_BOARD_INITTHREAD
# error "Must enable INITTHREAD"
#endif

#ifdef CONFIG_DEVICE_CORE
  device_table_register(&muc_device_table);

#ifdef CONFIG_FUSB302
  fusb302_register(GPIO_MODS_FUSB302_INT_N, GPIO_MODS_VBUS_PWR_EN);
#endif
#ifdef CONFIG_FUSB302_USB_EXT
  extern struct device_driver fusb302_usb_ext_driver;
  device_register_driver(&fusb302_usb_ext_driver);
#endif
#ifdef CONFIG_FUSB302_EXT_POWER
  extern struct device_driver fusb302_ext_power_driver;
  device_register_driver(&fusb302_ext_power_driver);
#endif
#ifdef CONFIG_MODS_RAW
  extern struct device_driver mods_raw_driver;
  device_register_driver(&mods_raw_driver);
#endif
#ifdef CONFIG_MODS_RAW_BLINKY
  extern struct device_driver mods_raw_blinky_driver;
  device_register_driver(&mods_raw_blinky_driver);
#endif
#ifdef CONFIG_MODS_RAW_TERMAPP
  extern struct device_driver mods_raw_termapp_driver;
  device_register_driver(&mods_raw_termapp_driver);
#endif
#ifdef CONFIG_MODS_RAW_TEMPERATURE
  extern struct device_driver mods_raw_temperature_driver;
  device_register_driver(&mods_raw_temperature_driver);
#endif
#ifdef CONFIG_GREYBUS_MODS_PTP_DEVICE
  extern struct device_driver mods_ptp_driver;
  device_register_driver(&mods_ptp_driver);
#endif
#ifdef CONFIG_CHARGER_DEVICE_BQ24292
  extern struct device_driver bq24292_charger_driver;
  device_register_driver(&bq24292_charger_driver);
#endif
#ifdef CONFIG_CHARGER_DEVICE_BQ25896
  extern struct device_driver bq25896_charger_driver;
  device_register_driver(&bq25896_charger_driver);
#endif
#ifdef CONFIG_GREYBUS_MODS_PTP_CHG_DEVICE_SWITCH
  extern struct device_driver switch_ptp_chg_driver;
  device_register_driver(&switch_ptp_chg_driver);
#endif
#ifdef CONFIG_MAX17050_DEVICE
  extern struct device_driver batt_driver;
  device_register_driver(&batt_driver);
#endif
#ifdef CONFIG_BATTERY_TEMP_DEVICE_MAX17050
  extern struct device_driver max17050_battery_temp_driver;
  device_register_driver(&max17050_battery_temp_driver);
#endif
#ifdef CONFIG_BATTERY_LEVEL_DEVICE_MAX17050
  extern struct device_driver max17050_battery_level_driver;
  device_register_driver(&max17050_battery_level_driver);
#endif
#ifdef CONFIG_BATTERY_VOLTAGE_DEVICE_MAX17050
  extern struct device_driver max17050_battery_voltage_driver;
  device_register_driver(&max17050_battery_voltage_driver);
#endif
#ifdef CONFIG_MHB_APBE_CTRL_DEVICE
  extern struct device_driver apbe_pwrctrl_driver;
  device_register_driver(&apbe_pwrctrl_driver);
#endif
#ifdef CONFIG_BATTERY_GOOD_DEVICE_COMP
  extern struct device_driver comp_batt_good_driver;
  device_register_driver(&comp_batt_good_driver);
#endif
#ifdef CONFIG_GREYBUS_SENSORS_EXT_DUMMY_PRESSURE
  extern struct device_driver sensor_dummy_pressure_driver;
  device_register_driver(&sensor_dummy_pressure_driver);
#endif
#ifdef CONFIG_GREYBUS_SENSORS_EXT_DUMMY_ACCEL
  extern struct device_driver sensor_dummy_accel_driver;
  device_register_driver(&sensor_dummy_accel_driver);
#endif
#ifdef CONFIG_HDMI_DISPLAY
   extern struct device_driver hdmi_display_driver;
   device_register_driver(&hdmi_display_driver);
#endif
#ifdef CONFIG_STM32_UART_DEVICE
  extern struct device_driver stm32_uart_driver;
  device_register_driver(&stm32_uart_driver);
#endif
#if CONFIG_MHB_UART
   extern struct device_driver mhb_driver;
   device_register_driver(&mhb_driver);
#endif
#ifdef CONFIG_MHB_DSI_DISPLAY
   extern struct device_driver dsi_display_driver;
   device_register_driver(&dsi_display_driver);
#endif
#ifdef CONFIG_BACKLIGHT_DCS
   extern struct device_driver dcs_backlight_driver;
   device_register_driver(&dcs_backlight_driver);
#endif
#ifdef CONFIG_BACKLIGHT_ISL98611
   extern struct device_driver isl98611_backlight_driver;
   device_register_driver(&isl98611_backlight_driver);
#endif
#ifdef CONFIG_BACKLIGHT_LM27965
   extern struct device_driver lm27965_backlight_driver;
   device_register_driver(&lm27965_backlight_driver);
#endif
#if defined(CONFIG_MHB_CAMERA)
   extern struct device_driver cam_ext_mhb_driver;
   device_register_driver(&cam_ext_mhb_driver);
#endif
#if defined(CONFIG_CAMERA_IMX220)
    extern struct device_driver imx220_mhb_camera_driver;
    device_register_driver(&imx220_mhb_camera_driver);
#endif
#if defined(CONFIG_CAMERA_IMX230)
    extern struct device_driver imx230_mhb_camera_driver;
    device_register_driver(&imx230_mhb_camera_driver);
#endif
#ifdef CONFIG_MODS_AUDIO_TFA9890
  extern struct device_driver tfa9890_i2s_direct_driver;
  device_register_driver(&tfa9890_i2s_direct_driver);
  extern struct device_driver tfa9890_audio_dev_driver;
  device_register_driver(&tfa9890_audio_dev_driver);
#endif
#ifdef CONFIG_MODS_RAW_FACTORY
   extern struct device_driver display_mux_driver;
   device_register_driver(&display_mux_driver);
   extern struct device_driver mods_raw_factory_driver;
   device_register_driver(&mods_raw_factory_driver);
#endif
#endif
#if defined(CONFIG_CHARGER_BQ24292)
   (void)bq24292_driver_init(GPIO_MODS_CHG_INT_N, GPIO_MODS_CHG_PG_N);
#endif

#ifdef CONFIG_BATTERY_MAX17050
   struct i2c_dev_s *i2c = up_i2cinitialize(MAX17050_I2C_BUS);
   if (i2c) {
      g_battery = max17050_initialize(i2c, MAX17050_I2C_FREQ,
                  GPIO_MODS_CC_ALERT);
      if (!g_battery) {
         up_i2cuninitialize(i2c);
      }
   }
# if defined(CONFIG_BATTERY_STATE)
   /* Must be initialized after MAX17050 core driver has been initialized */
   battery_state_init();
# endif
#endif

#if !defined(CONFIG_GREYBUS_PTP_EXT_SUPPORTED)
   /* Set the power paths to be able to use USB VBUS as the system power and
    * to prevent applying voltage to VBUS pin on the Mod connector. Also,
    * prevent accepting power from the PCARD VBUS connection.
    */
   gpio_set_value(GPIO_MODS_CHG_VINA_EN, 1);
   gpio_set_value(GPIO_MODS_CHG_VINB_EN, 0);
#endif
}
Ejemplo n.º 16
0
int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv)
{
  FAR struct i2c_dev_s *dev;
  FAR char *ptr;
  uint16_t result;
  uint8_t regaddr;
  long repititions;
  int nargs;
  int argndx;
  int ret;
  int i;

  /* Parse any command line arguments */

  for (argndx = 1; argndx < argc; )
    {
      /* Break out of the look when the last option has been parsed */

      ptr = argv[argndx];
      if (*ptr != '-')
        {
          break;
        }

      /* Otherwise, check for common options */

      nargs = common_args(i2ctool, &argv[argndx]);
      if (nargs < 0)
        {
          return ERROR;
        }
      argndx += nargs;
    }

  /* There may be one more thing on the command line:  The repitition
   * count.
   */

  repititions = 1;
  if (argndx < argc)
    {
      repititions = strtol(argv[argndx], NULL, 16);
      if (repititions < 1)
        {
          i2ctool_printf(i2ctool, g_i2cargrange, argv[0]);
          return ERROR;
        }

      argndx++;
    }

  if (argndx != argc)
    {
      i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]);
      return ERROR;
    }

  /* Get a handle to the I2C bus */

  dev = up_i2cinitialize(i2ctool->bus);
  if (!dev)
    {
       i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus);
       return ERROR;
    }

  /* Set the frequency and the address (NOTE:  Only 7-bit address supported now) */

  I2C_SETFREQUENCY(dev, i2ctool->freq);
  I2C_SETADDRESS(dev, i2ctool->addr, 7);

  /* Loop for the requested number of repititions */

  regaddr = i2ctool->regaddr;
  ret = OK;

  for (i = 0; i < repititions; i++)
    {
      /* Read from the I2C bus */

      ret = i2ctool_get(i2ctool, dev, regaddr, &result);

      /* Display the result */

      if (ret == OK)
        {
          i2ctool_printf(i2ctool, "READ Bus: %d Addr: %02x Subaddr: %02x Value: ",
                         i2ctool->bus, i2ctool->addr, i2ctool->regaddr);
          if (i2ctool->width == 8)
            {
              i2ctool_printf(i2ctool, "%02x\n", result);
            }
          else
            {
              i2ctool_printf(i2ctool, "%04x\n", result);
            }
        }
      else
        {
          i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret);
          break;
        }

      /* Auto-increment the address if so configured */

      if (i2ctool->autoincr)
        {
          regaddr++;
        }
    }

  (void)up_i2cuninitialize(dev);
  return ret;
}