123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689 |
- /*++
- Copyright (c) 2014 Minoca Corp. All rights reserved.
- Module Name:
- pmic.c
- Abstract:
- This module implements support for the TWL4030 PMIC that usually
- accompanies the TI OMAP4.
- Author:
- Evan Green 13-Mar-2014
- Environment:
- Kernel
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <uefifw.h>
- #include "../twl6030.h"
- #include "../pandafw.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- #define OMAP4_SYSCTRL_PADCONF_CORE_BASE 0x4A100000
- #define OMAP4_SYSTEM_CONTROL_PBIASLITE 0x600
- #define OMAP4_MMC1_VMODE (1 << 21)
- #define OMAP4_MMC1_PBIASLITE_PWRDNZ (1 << 22)
- #define OMAP4_MMC1_PWRDNZ (1 << 26)
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- EFI_STATUS
- Omap4Twl6030I2cWrite8 (
- UINT8 ChipNumber,
- UINT8 Register,
- UINT8 Value
- );
- EFI_STATUS
- Omap4Twl6030I2cRead8 (
- UINT8 ChipNumber,
- UINT8 Register,
- UINT8 *Value
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // ------------------------------------------------------------------ Functions
- //
- EFI_STATUS
- Omap4Twl6030InitializeMmcPower (
- VOID
- )
- /*++
- Routine Description:
- This routine enables the MMC power rails controlled by the TWL4030.
- Arguments:
- None.
- Return Value:
- Status code.
- --*/
- {
- volatile UINT32 *PbiasLite;
- EFI_STATUS Status;
- VOID *SystemControlBase;
- UINT32 Value;
- SystemControlBase = (VOID *)OMAP4_SYSCTRL_PADCONF_CORE_BASE;
- PbiasLite = SystemControlBase + OMAP4_SYSTEM_CONTROL_PBIASLITE;
- Value = *PbiasLite;
- Value &= ~(OMAP4_MMC1_PBIASLITE_PWRDNZ | OMAP4_MMC1_PWRDNZ);
- *PbiasLite = Value;
- //
- // Set VMMC1 to 3.00 Volts.
- //
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- VMMC_CFG_VOLTAGE,
- VMMC_VOLTAGE_3V0);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, VMMC_CFG_STATE, 0x21);
- if (!EFI_ERROR(Status)) {
- Value = *PbiasLite;
- Value |= OMAP4_MMC1_PBIASLITE_PWRDNZ | OMAP4_MMC1_PWRDNZ |
- OMAP4_MMC1_VMODE;
- *PbiasLite = Value;
- }
- return Status;
- }
- EFI_STATUS
- Omap4Twl6030InitializeRtc (
- VOID
- )
- /*++
- Routine Description:
- This routine enables the RTC controlled by the TWL4030.
- Arguments:
- None.
- Return Value:
- Status code.
- --*/
- {
- EFI_STATUS Status;
- UINT8 Value;
- //
- // Write to the RTC control register to start the counter ticking if it
- // isn't already.
- //
- Value = TWL6030_RTC_CONTROL_RUN;
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_CONTROL, Value);
- return Status;
- }
- EFI_STATUS
- Omap4Twl6030ReadRtc (
- EFI_TIME *Time
- )
- /*++
- Routine Description:
- This routine reads the current time from the TWL6030.
- Arguments:
- Time - Supplies a pointer where the time is returned on success.
- Return Value:
- Status code.
- --*/
- {
- EFI_STATUS Status;
- UINT8 Value;
- //
- // Read and clear the power up status and alarm bits.
- //
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_STATUS,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_STATUS, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- //
- // Write a zero and then a one to snap the current time into the shadow
- // registers.
- //
- Value = TWL6030_RTC_CONTROL_READ_SHADOWED | TWL6030_RTC_CONTROL_RUN;
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_CONTROL,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value |= TWL6030_RTC_CONTROL_GET_TIME;
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_CONTROL,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM, TWL6030_RTC_SECONDS, &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Second = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM, TWL6030_RTC_MINUTES, &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Minute = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM, TWL6030_RTC_HOURS, &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Hour = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM, TWL6030_RTC_DAYS, &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Day = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM, TWL6030_RTC_MONTHS, &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Month = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM, TWL6030_RTC_YEARS, &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Year = EFI_BCD_TO_BINARY(Value) + 2000;
- Time->Nanosecond = 0;
- Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
- Time->Daylight = 0;
- return EFI_SUCCESS;
- }
- EFI_STATUS
- Omap4Twl6030ReadRtcWakeupTime (
- BOOLEAN *Enabled,
- BOOLEAN *Pending,
- EFI_TIME *Time
- )
- /*++
- Routine Description:
- This routine reads the wake alarm time from the TWL6030.
- Arguments:
- Enabled - Supplies a pointer where a boolean will be returned indicating if
- the wake time interrupt is enabled.
- Pending - Supplies a pointer where a boolean will be returned indicating if
- the wake alarm interrupt is pending and requires service.
- Time - Supplies a pointer where the time is returned on success.
- Return Value:
- Status code.
- --*/
- {
- EFI_STATUS Status;
- UINT8 Value;
- *Enabled = FALSE;
- *Pending = FALSE;
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_INTERRUPTS,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- if ((Value & TWL6030_RTC_INTERRUPT_ALARM) != 0) {
- *Enabled = TRUE;
- }
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM, TWL6030_RTC_STATUS, &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- if ((Value & TWL6030_RTC_STATUS_ALARM) != 0) {
- *Pending = TRUE;
- }
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_SECONDS,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Second = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_MINUTES,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Minute = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_HOURS,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Hour = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_DAYS,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Day = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_MONTHS,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Month = EFI_BCD_TO_BINARY(Value);
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_YEARS,
- &Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Time->Year = EFI_BCD_TO_BINARY(Value) + 2000;
- Time->Nanosecond = 0;
- Time->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
- Time->Daylight = 0;
- return EFI_SUCCESS;
- }
- EFI_STATUS
- Omap4Twl6030WriteRtc (
- EFI_TIME *Time
- )
- /*++
- Routine Description:
- This routine writes the current time to the TWL6030.
- Arguments:
- Time - Supplies a pointer to the new time to set.
- Return Value:
- Status code.
- --*/
- {
- EFI_STATUS Status;
- UINT8 Value;
- //
- // Stop the clock while programming.
- //
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_CONTROL, 0);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Second);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_SECONDS, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Minute);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_MINUTES, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Hour);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_HOURS, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Day);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_DAYS, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Month);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_MONTHS, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- if (Time->Year < 2000) {
- Value = EFI_BINARY_TO_BCD(Time->Year - 1900);
- } else {
- Value = EFI_BINARY_TO_BCD(Time->Year - 2000);
- }
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_YEARS, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- //
- // Fire the clock back up.
- //
- Value = TWL6030_RTC_CONTROL_RUN;
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM, TWL6030_RTC_CONTROL, Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- return Status;
- }
- EFI_STATUS
- Omap4Twl6030WriteRtcWakeupTime (
- BOOLEAN Enable,
- EFI_TIME *Time
- )
- /*++
- Routine Description:
- This routine writes the alarm time to the TWL6030.
- Arguments:
- Enable - Supplies a boolean enabling or disabling the wakeup timer.
- Time - Supplies an optional pointer to the time to set. This parameter is
- only optional if the enable parameter is FALSE.
- Return Value:
- Status code.
- --*/
- {
- UINT8 Interrupts;
- EFI_STATUS Status;
- UINT8 Value;
- //
- // Clear the interrupt first.
- //
- Status = Omap4Twl6030I2cRead8(TWL6030_CHIP_PM,
- TWL6030_RTC_INTERRUPTS,
- &Interrupts);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Interrupts &= ~TWL6030_RTC_INTERRUPT_ALARM;
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_INTERRUPTS,
- Interrupts);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- if (Enable == FALSE) {
- return Status;
- }
- if (Time == NULL) {
- return EFI_INVALID_PARAMETER;
- }
- //
- // Program the new time.
- //
- Value = EFI_BINARY_TO_BCD(Time->Second);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_SECONDS,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Minute);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_MINUTES,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Hour);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_HOURS,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Day);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_DAYS,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- Value = EFI_BINARY_TO_BCD(Time->Month);
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_MONTHS,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- if (Time->Year < 2000) {
- Value = EFI_BINARY_TO_BCD(Time->Year - 1900);
- } else {
- Value = EFI_BINARY_TO_BCD(Time->Year - 2000);
- }
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_ALARM_YEARS,
- Value);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- //
- // Enable the interrupt.
- //
- Interrupts |= TWL6030_RTC_INTERRUPT_ALARM;
- Status = Omap4Twl6030I2cWrite8(TWL6030_CHIP_PM,
- TWL6030_RTC_INTERRUPTS,
- Interrupts);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- return Status;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
- EFI_STATUS
- Omap4Twl6030I2cWrite8 (
- UINT8 ChipNumber,
- UINT8 Register,
- UINT8 Value
- )
- /*++
- Routine Description:
- This routine writes a register on the TWL6030.
- Arguments:
- ChipNumber - Supplies the device address of the TWL4030 on the I2C bus.
- Register - Supplies the register number to write.
- Value - Supplies the register value.
- Return Value:
- Status code.
- --*/
- {
- return EfipOmapI2cWrite(ChipNumber, Register, 1, &Value, 1);
- }
- EFI_STATUS
- Omap4Twl6030I2cRead8 (
- UINT8 ChipNumber,
- UINT8 Register,
- UINT8 *Value
- )
- /*++
- Routine Description:
- This routine reads a register on the TWL6030.
- Arguments:
- ChipNumber - Supplies the device address of the TWL4030 on the I2C bus.
- Register - Supplies the register number to write.
- Value - Supplies a pointer where the read value will be returned.
- Return Value:
- Status code.
- --*/
- {
- return EfipOmapI2cRead(ChipNumber, Register, 1, Value, 1);
- }
|