Beispiel #1
0
/**
 * @brief Configure all the GPIOs associated with a voltage regulator
 * to their default states.
 * @param vreg regulator to configure
 */
int vreg_config(struct vreg *vreg) {
    unsigned int i;
    int rc = 0;

    if (!vreg) {
        return -ENODEV;
    }

    dbg_verbose("%s %s\n", __func__,  vreg->name ? vreg->name : "unknown");

    for (i = 0; i < vreg->nr_vregs; i++) {
        if (!&vreg->vregs[i]) {
            rc = -EINVAL;
            break;
        }
        dbg_insane("%s: %s vreg, gpio %d\n", __func__,
                   vreg->name ? vreg->name : "unknown",
                   vreg->vregs[i].gpio);
        // First set default value then switch line to output mode
        gpio_set_value(vreg->vregs[i].gpio, vreg->vregs[i].def_val);
        gpio_direction_out(vreg->vregs[i].gpio, vreg->vregs[i].def_val);
    }

    atomic_init(&vreg->use_count, 0);
    vreg->power_state = false;

    return rc;
}
Beispiel #2
0
/**
 * @brief Hardware initialization
 *
 * The function initializes the GPIO pins used in the bit-bang interface and
 * also assigned a default output value for SPI signal.
 *
 * @param dev pointer to structure of device data
 * @return 0 on success, negative errno on error
 */
static int tsb_spi_hw_init(struct device *dev)
{
    struct tsb_spi_info *info = NULL;
    int i = 0;
    int retval;

    /* check input parameters */
    if (!dev || !device_get_private(dev)) {
        return -EINVAL;
    }

    info = device_get_private(dev);

    retval = tsb_request_pinshare(TSB_PIN_GPIO10);
    if (retval) {
        lowsyslog("SPI: cannot get ownership of GPIO10 pin.\n");
        return retval;
    }

    /* backup pinshare#5 setting */
    info->pinshare = tsb_get_pinshare();

    /* set pinshare#5 (DBG) to normal GPIO */
    if (!(info->pinshare & TSB_PIN_GPIO10)) {
        tsb_set_pinshare(TSB_PIN_GPIO10);
    }

    /* setup GPIO pins */
    gpio_activate(SPI_SCK);
    gpio_direction_out(SPI_SCK, 0);

    gpio_activate(SPI_SDI);
    gpio_direction_in(SPI_SDI);

    gpio_activate(SPI_SDO);
    gpio_direction_out(SPI_SDO, 0);

    /* setup all chip-select pins */
    for (i = 0; i < info->caps.csnum; i++) {
        gpio_activate(info->chipselect[i]);
        gpio_direction_out(info->chipselect[i], 1);
    }

    return 0;
}
Beispiel #3
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;
}
Beispiel #4
0
static int gpio_wrls_tx_probe(struct device *dev)
{
    struct gpio_wrls_tx_info *info = zalloc(sizeof(*info));
    struct device_resource *r;

    if (!info) {
        dbg("failed to allocate memory\n");
        return -ENOMEM;
    }

    r = device_resource_get_by_name(dev, DEVICE_RESOURCE_TYPE_GPIO,
                                    "wrls_tx_cntrl");
    if (!r) {
        dbg("failed to get wrls_tx_cntrl gpio\n");
        return -EINVAL;
    }

    info->gpio = r->start;
    gpio_direction_out(info->gpio, WCHG_TX_ENABLE);

    device_set_private(dev, info);
    return 0;
}
Beispiel #5
0
/**
 * Release the usb hub from reset
 *
 * @param dev Device
 * @return 0 if successful
 */
static int usb3813_release_reset(struct device *dev)
{
    gpio_direction_out(HUB_LINE_N_RESET, 1);
    up_mdelay(HUB_RESET_DEASSERTION_TIME_IN_MSEC);
    return 0;
}
Beispiel #6
0
/**
 * Hold the usb hub under reset
 *
 * @param dev Device
 * @return 0 if successful
 */
static int usb3813_hold_reset(struct device *dev)
{
    gpio_direction_out(HUB_LINE_N_RESET, 0);
    up_udelay(HUB_RESET_ASSERTION_TIME_IN_USEC);
    return 0;
}
Beispiel #7
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;
}
Beispiel #8
0
/* EVT1.5 */
static int evt1_5_board_init(struct ara_board_info *board_info) {
    int rc;

    /*
     * VSYS and VCHG are active high with a pull-up.
     * Initialize these lines as output low to prevent any spurious
     * activation at boot time.
     */
    gpio_direction_out(VSYS_EN1_N, 0);
    gpio_direction_out(VSYS_EN2_N, 0);
    gpio_direction_out(VSYS_EN3A_N, 0);
    gpio_direction_out(VSYS_EN3B_N, 0);
    gpio_direction_out(VSYS_EN4A_N, 0);
    gpio_direction_out(VSYS_EN4B_N, 0);
    gpio_direction_out(VSYS_EN5_N, 0);
    gpio_direction_out(VCHG_EN1_N, 0);
    gpio_direction_out(VCHG_EN2_N, 0);
    gpio_direction_out(VCHG_EN3A_N, 0);
    gpio_direction_out(VCHG_EN3B_N, 0);
    gpio_direction_out(VCHG_EN4A_N, 0);
    gpio_direction_out(VCHG_EN4B_N, 0);
    gpio_direction_out(VCHG_EN5_N, 0);

    /* For now, just always enable REFCLK_MAIN and the buffers. */
    rc = vreg_config(&refclk_main_vreg) || vreg_get(&refclk_main_vreg);
    if (rc) {
        dbg_error("%s: can't start REFCLK_MAIN: %d\n", __func__, rc);
        return ERROR;
    }

    /* Configure Switch Standby Boot line */
    stm32_configgpio(SW_STANDBY_N);

    /* Configure the switch power supply lines. */
    rc = vreg_config(&sw_vreg);
    if (rc) {
        dbg_error("%s: can't configure switch regulators: %d\n", __func__, rc);
        return ERROR;
    }
    stm32_configgpio(evt1_5_board_info.sw_data.gpio_reset);
    up_udelay(POWER_SWITCH_OFF_STAB_TIME_US);

    /* Configure the wake/detect lines. */
    stm32_configgpio(WD_1_DET_IN_GPIO);
    stm32_configgpio(WD_2_DET_IN_GPIO);
    stm32_configgpio(WD_3A_DET_IN_GPIO);
    stm32_configgpio(WD_3B_DET_IN_GPIO);
    stm32_configgpio(WD_4A_DET_IN_GPIO);
    stm32_configgpio(WD_4B_DET_IN_GPIO);
    stm32_configgpio(WD_5_DET_IN_GPIO);
    stm32_configgpio(WD_8A_DET_IN_GPIO);
    stm32_configgpio(WD_8B_DET_IN_GPIO);

    /* Configure the module release pins */
    stm32_configgpio(MOD_RELEASE_1_CONFIG);
    stm32_configgpio(MOD_RELEASE_2_CONFIG);
    stm32_configgpio(MOD_RELEASE_3A_CONFIG);
    stm32_configgpio(MOD_RELEASE_3B_CONFIG);
    stm32_configgpio(MOD_RELEASE_4A_CONFIG);
    stm32_configgpio(MOD_RELEASE_4B_CONFIG);
    stm32_configgpio(MOD_RELEASE_5_CONFIG);

    /* Configure ARA key input pin */
    stm32_configgpio(ARA_KEY_CONFIG);

    /*
     * (Module hotplug pins unconfigured. TODO, part of SW-1942.)
     */

    /* Configure AP Wake from OFF pin */
    gpio_set_value(PM_CBL_PWR_N_GPIO, 1);
    gpio_direction_out(PM_CBL_PWR_N_GPIO, 1);

    return 0;
}