Ejemplo n.º 1
0
void _backlight_on(void)
{
    ascodec_write(0x25, ascodec_read(0x25) | 2);    /* lcd power */
    ascodec_write(0x1c, 8|1);
    ascodec_write(0x1b, 0x90);
    lcd_enable(true);
}
Ejemplo n.º 2
0
static inline void charger_control(void)
{
    switch (charge_state)
    {
    case DISCHARGING:
    {
        unsigned int millivolts;
        unsigned int thresh = batt_threshold;

        if (BATT_FULL_VOLTAGE == thresh)
        {
            /* Wait for CHG_status to be indicated. */
            if ((ascodec_read(AS3514_IRQ_ENRD0) & CHG_STATUS) == 0)
                break;

            batt_threshold = BATT_VAUTO_RECHARGE;
        }

        millivolts = battery_voltage();

        if (millivolts <= thresh)
            enable_charger();
        break;
        } /* DISCHARGING: */

    case CHARGING:
    {
        if ((ascodec_read(AS3514_IRQ_ENRD0) & CHG_ENDOFCH) == 0)
        {
            if (--charger_total_timer > 0)
                break;

            /* Timer ran out - require replug. */
            charge_state = CHARGE_STATE_ERROR;
        }
        /* else end of charge */

        disable_charger();
        break;
        } /* CHARGING: */

    default:
        /* DISABLED, ERROR */
        break;
    }
}
int ascodec_readbytes(unsigned int index, unsigned int len, unsigned char *data)
{
    int i, val, ret = 0;

    for (i = 0; i < (int)len; i++)
    {
        val = ascodec_read(i + index);
        if (val >= 0) data[i] = val;
        else ret = -1;
    }

    return (ret ?: (int)len);
}
Ejemplo n.º 4
0
/* Enable charger with specified settings. Start timers, etc. */
static void enable_charger(void)
{
    ascodec_write(AS3514_CHARGER, BATT_CHG_I | BATT_CHG_V);
    /* Watch for end of charge. Temperature supervision is handled in
     * hardware. Charger status can be read and has no interrupt enable. */
    ascodec_write(AS3514_IRQ_ENRD0, CHG_ENDOFCH);

    sleep(HZ/10); /* Allow charger turn-on time (it could be gradual). */

    ascodec_read(AS3514_IRQ_ENRD0); /* Clear out interrupts (important!) */

    charge_state = CHARGING;
    charger_total_timer = CHARGER_TOTAL_TIMER;
    battery_voltage_sync();
}
void usb_drv_exit(void)
{
    tick_remove_task(usb_tick);
    USB_DEV_CTRL |= (1<<10); /* soft disconnect */
    usb_phy_suspend();
    /*
     * mask all interrupts _before_ writing to VIC_INT_EN_CLEAR,
     * or else the core might latch the interrupt while
     * the write ot VIC_INT_EN_CLEAR is in the pipeline and
     * so cause a fake spurious interrupt.
     */
    USB_DEV_EP_INTR_MASK = 0xffffffff;
    USB_DEV_INTR_MASK    = 0xffffffff;
    VIC_INT_EN_CLEAR = INTERRUPT_USB;
    CGU_USB &= ~(1<<5);
    bitclr32(&CGU_PERI, CGU_USB_CLOCK_ENABLE);
    /* Disable UVDD generating LDO */
    ascodec_write(AS3515_USB_UTIL, ascodec_read(AS3515_USB_UTIL) & ~(1<<4));
    usb_disable_pll();
    cpu_boost(0);
    initialized = false;
    logf("usb_drv_exit() !!!!\n");
}
static void usb_phy_on(void)
{
    /* PHY clock */
    CGU_USB = 1<<5 /* enable */
        | (CLK_DIV(AS3525_PLLB_FREQ, 48000000) / 2) << 2
        | 2; /* source = PLLB */

    /* UVDD on */
    ascodec_write(AS3515_USB_UTIL, ascodec_read(AS3515_USB_UTIL) | (1<<4));
    mdelay(100);

    /* reset */
    CCU_SRC = CCU_SRC_USB_AHB_EN|CCU_SRC_USB_PHY_EN;
    CCU_SRL = CCU_SRL_MAGIC_NUMBER;
    mdelay(1);
    CCU_SRC = CCU_SRC_USB_AHB_EN;
    mdelay(1);
    CCU_SRC = CCU_SRL = 0;

    USB_GPIO_CSR = USB_GPIO_TX_ENABLE_N
                 | USB_GPIO_TX_BIT_STUFF_EN
                 | USB_GPIO_XO_ON
                 | USB_GPIO_CLK_SEL10; /* 0x06180000; */
}
Ejemplo n.º 7
0
void _backlight_off(void)
{
    lcd_enable(false);
    ascodec_write(0x25, ascodec_read(0x25) & ~2);    /* lcd power */
    ascodec_write_pmu(AS3543_BACKLIGHT, 1, 0x0);
}
Ejemplo n.º 8
0
void _backlight_on(void)
{
    ascodec_write(0x25, ascodec_read(0x25) | 2);    /* lcd power */
    ascodec_write_pmu(AS3543_BACKLIGHT, 1, 0x90);
    lcd_enable(true);
}
void usb_drv_init(void)
{
    logf("usb_drv_init() !!!!\n");

    if (!initialized)
    {
        int i;
        for (i = 0; i < USB_NUM_EPS; i++)
        {
            semaphore_init(&endpoints[i][0].complete, 1, 0);
            semaphore_init(&endpoints[i][1].complete, 1, 0);
        }

        initialized = true;
    }

    usb_enable_pll();

    /* we have external power, so boost cpu */
    cpu_boost(1);

    /* length regulator: normal operation */
    ascodec_write(AS3514_CVDD_DCDC3, ascodec_read(AS3514_CVDD_DCDC3) | 1<<2);

    /* AHB part */
    bitset32(&CGU_PERI, CGU_USB_CLOCK_ENABLE);

    /* reset AHB */
    CCU_SRC = CCU_SRC_USB_AHB_EN;
    CCU_SRL = CCU_SRL_MAGIC_NUMBER;
    mdelay(1);
    CCU_SRC = CCU_SRL = 0;

    USB_GPIO_CSR = USB_GPIO_TX_ENABLE_N
                 | USB_GPIO_TX_BIT_STUFF_EN
                 | USB_GPIO_XO_ON
                 | USB_GPIO_CLK_SEL10; /* 0x06180000; */

    /* bug workaround according to linux patch */
    USB_DEV_CFG = (USB_DEV_CFG & ~3) | 1; /* full speed */

    /* enable soft disconnect */
    USB_DEV_CTRL |= USB_DEV_CTRL_SOFT_DISCONN;

    usb_phy_on();
    usb_phy_suspend();
    USB_DEV_CTRL |= USB_DEV_CTRL_SOFT_DISCONN;

    /* We don't care about SVC or SOF events */
    /* Right now we don't handle suspend, so mask those too */
    USB_DEV_INTR_MASK = USB_DEV_INTR_SVC |
                        USB_DEV_INTR_SOF |
                        USB_DEV_INTR_USB_SUSPEND |
                        USB_DEV_INTR_EARLY_SUSPEND;

    USB_DEV_CFG = USB_DEV_CFG_STAT_ACK      |
                  USB_DEV_CFG_UNI_DIR       |
                  USB_DEV_CFG_PI_16BIT      |
                  USB_DEV_CFG_HS            |
                  USB_DEV_CFG_SELF_POWERED  |
                  USB_DEV_CFG_CSR_PRG       |
                  USB_DEV_CFG_PHY_ERR_DETECT;

    USB_DEV_CTRL = USB_DEV_CTRL_DESC_UPDATE  |
                   USB_DEV_CTRL_THRES_ENABLE |
                   USB_DEV_CTRL_BURST_ENABLE |
                   USB_DEV_CTRL_BLEN_8DWORDS |
                   USB_DEV_CTRL_TLEN_8THMAXSIZE;

    USB_DEV_EP_INTR_MASK &= ~((1<<0) | (1<<16));    /* ep 0 */

    reset_endpoints(1);

    /* clear pending interrupts */
    USB_DEV_EP_INTR = 0xffffffff;
    USB_DEV_INTR    = 0xffffffff;

    VIC_INT_ENABLE = INTERRUPT_USB;

    usb_phy_resume();
    USB_DEV_CTRL &= ~USB_DEV_CTRL_SOFT_DISCONN;

    USB_GPIO_CSR = USB_GPIO_TX_ENABLE_N
                 | USB_GPIO_TX_BIT_STUFF_EN
                 | USB_GPIO_XO_ON
                 | USB_GPIO_HS_INTR
                 | USB_GPIO_CLK_SEL10; /* 0x06180000; */

    tick_add_task(usb_tick);

    usb_enum_timeout = HZ; /* one second timeout for enumeration */
}
Ejemplo n.º 10
0
int rtc_read_datetime(struct tm *tm)
{
    char tmp[4];
    int i, year, mday, hour, min;
    unsigned int seconds;

    /* RTC_AS3514's slave address is 0x46*/
    for (i = 0; i < 4; i++){
        tmp[i] = ascodec_read(AS3514_RTC_0 + i);
    }
    seconds = tmp[0] + (tmp[1]<<8) + (tmp[2]<<16) + (tmp[3]<<24);
    seconds -= SECS_ADJUST;

    /* Convert seconds since Jan-1-1980 to format compatible with
     * get_time() from firmware/common/timefuncs.c */

    /* weekday */
    tm->tm_wday = ((seconds % WEEK_SECONDS) / DAY_SECONDS + 2) % 7;

    /* Year */
    year = 1980;
    while (seconds >= LEAP_YEAR_SECONDS)
    {
        if (is_leapyear(year)){
            seconds -= LEAP_YEAR_SECONDS;
        } else {
            seconds -= YEAR_SECONDS;
        }

        year++;
    }

    if (is_leapyear(year)) {
        days_in_month[1] = 29;
    } else {
        days_in_month[1] = 28;
        if(seconds>YEAR_SECONDS){
            year++;
            seconds -= YEAR_SECONDS;
        }
    }
    tm->tm_year = year%100 + 100;

    /* Month */
    for (i = 0; i < 12; i++)
    {
        if (seconds < days_in_month[i]*DAY_SECONDS){
            tm->tm_mon = i;
            break;
        }

        seconds -= days_in_month[i]*DAY_SECONDS;
    }

    /* Month Day */
    mday = seconds/DAY_SECONDS;
    seconds -= mday*DAY_SECONDS;
    tm->tm_mday = mday + 1; /* 1 ... 31 */

    /* Hour */
    hour = seconds/HOUR_SECONDS;
    seconds -= hour*HOUR_SECONDS;
    tm->tm_hour = hour;

    /* Minute */
    min = seconds/MINUTE_SECONDS;
    seconds -= min*MINUTE_SECONDS;
    tm->tm_min = min;

    /* Second */
    tm->tm_sec = seconds;

    return 7;
}
Ejemplo n.º 11
0
void _backlight_off(void)
{
    ascodec_write(0x25, ascodec_read(0x25) & ~2);    /* lcd power */
    lcd_enable(false);
}