2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-09-21 15:51:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
2008-12-21 18:10:36 +00:00
|
|
|
#include "usb.h"
|
|
|
|
#include "usb_core.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "power.h"
|
2010-04-09 01:21:53 +00:00
|
|
|
#include "power-gigabeat-s.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "backlight.h"
|
|
|
|
#include "backlight-target.h"
|
2008-04-12 16:56:45 +00:00
|
|
|
#include "avic-imx31.h"
|
|
|
|
#include "mc13783.h"
|
2010-04-23 15:32:50 +00:00
|
|
|
#include "dvfs_dptc-imx31.h"
|
2008-12-21 19:39:11 +00:00
|
|
|
#if CONFIG_TUNER
|
|
|
|
#include "fmradio_i2c.h"
|
|
|
|
#endif
|
2008-12-09 20:48:04 +00:00
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
static unsigned long power_status = POWER_INPUT_NONE;
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-12-21 18:10:36 +00:00
|
|
|
/* Detect which power sources are present. */
|
2008-12-03 19:54:25 +00:00
|
|
|
unsigned int power_input_status(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-12-21 18:10:36 +00:00
|
|
|
unsigned int status = power_status;
|
2008-12-03 19:54:25 +00:00
|
|
|
|
2008-12-21 18:10:36 +00:00
|
|
|
if (GPIO3_DR & (1 << 20))
|
2008-12-03 19:54:25 +00:00
|
|
|
status |= POWER_INPUT_BATTERY;
|
|
|
|
|
2010-06-05 10:05:27 +00:00
|
|
|
if (usb_charging_maxcurrent() < 500)
|
2008-12-21 18:10:36 +00:00
|
|
|
{
|
|
|
|
/* ACK that USB is connected but NOT chargeable */
|
|
|
|
status &= ~(POWER_INPUT_USB_CHARGER & POWER_INPUT_CHARGER);
|
|
|
|
}
|
2008-12-03 19:54:25 +00:00
|
|
|
|
|
|
|
return status;
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2010-06-05 10:05:27 +00:00
|
|
|
void usb_charging_maxcurrent_change(int maxcurrent)
|
|
|
|
{
|
|
|
|
(void)maxcurrent;
|
|
|
|
/* Nothing to do */
|
|
|
|
}
|
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Helper to update the charger status */
|
|
|
|
static void update_main_charger(bool present)
|
|
|
|
{
|
|
|
|
bitmod32(&power_status, present ? POWER_INPUT_MAIN_CHARGER : 0,
|
|
|
|
POWER_INPUT_MAIN_CHARGER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Detect changes in presence of the AC adaptor. Called from PMIC ISR. */
|
2008-12-21 18:10:36 +00:00
|
|
|
void charger_main_detect_event(void)
|
2008-05-08 14:11:26 +00:00
|
|
|
{
|
2012-01-03 06:13:59 +00:00
|
|
|
update_main_charger(mc13783_event_sense(MC13783_SE1_EVENT));
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:32:35 +00:00
|
|
|
/* Detect changes in USB bus power. Called from usb connect event ISR. */
|
2008-12-21 18:10:36 +00:00
|
|
|
void charger_usb_detect_event(int status)
|
|
|
|
{
|
|
|
|
/* USB plugged does not imply charging is possible or even
|
|
|
|
* powering the device to maintain the battery. */
|
2012-01-02 18:32:35 +00:00
|
|
|
bitmod32(&power_status,
|
|
|
|
status == USB_INSERTED ? POWER_INPUT_USB_CHARGER : 0,
|
|
|
|
POWER_INPUT_USB_CHARGER);
|
2008-12-21 18:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* charging_state is implemented in powermgmt-imx31.c */
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
void ide_power_enable(bool on)
|
|
|
|
{
|
2008-05-08 08:03:08 +00:00
|
|
|
if (!on)
|
|
|
|
{
|
|
|
|
/* Bus must be isolated before power off */
|
2010-06-30 02:02:46 +00:00
|
|
|
bitset32(&GPIO2_DR, (1 << 16));
|
2008-05-08 08:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* HD power switch */
|
2010-06-30 02:02:46 +00:00
|
|
|
bitmod32(&GPIO3_DR, on ? (1 << 5) : 0, (1 << 5));
|
2008-05-08 08:03:08 +00:00
|
|
|
|
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
/* Bus switch may be turned on after powerup */
|
|
|
|
sleep(HZ/10);
|
2010-06-30 02:02:46 +00:00
|
|
|
bitclr32(&GPIO2_DR, (1 << 16));
|
2008-05-08 08:03:08 +00:00
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ide_powered(void)
|
|
|
|
{
|
2008-05-08 14:11:26 +00:00
|
|
|
return (GPIO3_DR & (1 << 5)) != 0;
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-09 20:48:04 +00:00
|
|
|
#if CONFIG_TUNER
|
2008-12-27 19:18:50 +00:00
|
|
|
static bool tuner_on = false;
|
|
|
|
|
2008-12-09 20:48:04 +00:00
|
|
|
bool tuner_power(bool status)
|
|
|
|
{
|
2008-12-27 19:18:50 +00:00
|
|
|
if (status != tuner_on)
|
2008-12-09 20:48:04 +00:00
|
|
|
{
|
2008-12-27 19:18:50 +00:00
|
|
|
tuner_on = status;
|
|
|
|
/* Handle power and pin setup */
|
|
|
|
fmradio_i2c_enable(status);
|
|
|
|
status = !status;
|
2008-12-09 20:48:04 +00:00
|
|
|
}
|
2008-12-21 19:39:11 +00:00
|
|
|
|
2008-12-27 19:18:50 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tuner_powered(void)
|
|
|
|
{
|
|
|
|
return tuner_on;
|
2008-12-09 20:48:04 +00:00
|
|
|
}
|
|
|
|
#endif /* #if CONFIG_TUNER */
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
void power_off(void)
|
|
|
|
{
|
2010-04-23 15:32:50 +00:00
|
|
|
/* Turn off voltage and frequency scaling */
|
2011-01-23 20:21:35 +00:00
|
|
|
dvfs_stop();
|
|
|
|
dptc_stop();
|
2010-04-23 15:32:50 +00:00
|
|
|
|
2008-12-04 04:16:53 +00:00
|
|
|
/* Cut backlight */
|
2015-01-08 23:22:40 +00:00
|
|
|
backlight_hw_off();
|
2008-12-04 04:16:53 +00:00
|
|
|
|
|
|
|
/* Let it fade */
|
|
|
|
sleep(5*HZ/4);
|
|
|
|
|
|
|
|
/* Set user off mode */
|
2008-04-12 16:56:45 +00:00
|
|
|
mc13783_set(MC13783_POWER_CONTROL0, MC13783_USEROFFSPI);
|
|
|
|
|
2008-12-04 04:16:53 +00:00
|
|
|
/* Wait for power cut */
|
2010-04-23 15:32:50 +00:00
|
|
|
system_halt();
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
void power_init(void)
|
|
|
|
{
|
2008-12-27 19:18:50 +00:00
|
|
|
#if CONFIG_TUNER
|
|
|
|
fmradio_i2c_init();
|
|
|
|
#endif
|
|
|
|
|
2008-05-21 08:42:11 +00:00
|
|
|
/* Poll initial state */
|
2012-01-02 18:32:35 +00:00
|
|
|
update_main_charger(mc13783_read(MC13783_INTERRUPT_SENSE0)
|
|
|
|
& MC13783_SE1S);
|
2008-05-21 08:42:11 +00:00
|
|
|
|
|
|
|
/* Enable detect event */
|
2012-01-02 18:32:35 +00:00
|
|
|
mc13783_enable_event(MC13783_SE1_EVENT, true);
|
2008-05-21 08:42:11 +00:00
|
|
|
}
|