nrhw20: set da9063 current limits
- factor out da9063 function from board.c
This commit is contained in:
parent
26da1f4009
commit
9a753c5ebc
|
|
@ -36,6 +36,7 @@
|
||||||
#include "../common/bdparser.h"
|
#include "../common/bdparser.h"
|
||||||
#include "../common/board_descriptor.h"
|
#include "../common/board_descriptor.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
#include "da9063.h"
|
||||||
#include "shield.h"
|
#include "shield.h"
|
||||||
#include "shield_can.h"
|
#include "shield_can.h"
|
||||||
#include "shield_comio.h"
|
#include "shield_comio.h"
|
||||||
|
|
@ -154,6 +155,16 @@ static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
|
||||||
|
|
||||||
static BD_Context bdctx[3]; /* The descriptor contexts */
|
static BD_Context bdctx[3]; /* The descriptor contexts */
|
||||||
|
|
||||||
|
|
||||||
|
static void init_i2c(void)
|
||||||
|
{
|
||||||
|
i2c_set_bus_num(0);
|
||||||
|
i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
|
||||||
|
i2c_set_bus_num(2);
|
||||||
|
i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
|
||||||
|
i2c_set_bus_num(0);
|
||||||
|
}
|
||||||
|
|
||||||
static int _bd_init(void)
|
static int _bd_init(void)
|
||||||
{
|
{
|
||||||
int old_bus;
|
int old_bus;
|
||||||
|
|
@ -183,7 +194,6 @@ static int _bd_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void init_indicator_leds(void)
|
static void init_indicator_leds(void)
|
||||||
{
|
{
|
||||||
int old_bus;
|
int old_bus;
|
||||||
|
|
@ -294,7 +304,22 @@ void am33xx_spl_board_init(void)
|
||||||
/* Set CORE Frequencies to OPP100 (600MHz) */
|
/* Set CORE Frequencies to OPP100 (600MHz) */
|
||||||
do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
|
do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
|
||||||
|
|
||||||
/* TODO: Modify PMIC settings if required */
|
/* Configure both I2C buses used in NRHW20 */
|
||||||
|
init_i2c();
|
||||||
|
|
||||||
|
/* Configure default PMIC current limits. Will be overridden in Linux.
|
||||||
|
* MEM = 1.5A (0.55A)
|
||||||
|
* IO = 1.5A (0.5A)
|
||||||
|
* PERI = 2.0A (1.0A)
|
||||||
|
* PRO = 0.5A (unused)
|
||||||
|
* CORE2 = 2.0A (0.55A)
|
||||||
|
* CORE1 = 2.0A (0.25A, seems too low)
|
||||||
|
*/
|
||||||
|
da9063_init(CONFIG_PMIC_I2C_BUS);
|
||||||
|
da9063_set_reg(PMIC_REG_BUCK_ILIM_A, 0x00);
|
||||||
|
da9063_set_reg(PMIC_REG_BUCK_ILIM_B, 0x50);
|
||||||
|
da9063_set_reg(PMIC_REG_BUCK_ILIM_C, 0xFF);
|
||||||
|
|
||||||
init_indicator_leds();
|
init_indicator_leds();
|
||||||
set_indicator(0, 1, 1); /* Orange */
|
set_indicator(0, 1, 1); /* Orange */
|
||||||
|
|
||||||
|
|
@ -397,92 +422,6 @@ err_free_gpio:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Create DA9063 Accessor Module */
|
|
||||||
#define CONFIG_PMIC_I2C_BUS 0
|
|
||||||
#define CONFIG_PMIC_I2C_ADDR 0x58 /* Pages 0 and 1, Pages 2 and 3 -> 0x59 */
|
|
||||||
|
|
||||||
#define PMIC_REG_STATUS_A 0x01 /* Status of ON_KEY, WAKE, COMP1V2, DVC */
|
|
||||||
#define PMIC_REG_GPIO_MODE0_7 0x1D /* Control register for GPIOs 0..7 */
|
|
||||||
#define PMIC_REG_GPIO_MODE8_15 0x1E /* Control register for GPIOs 8..15 */
|
|
||||||
|
|
||||||
#define PMIC_REG_BBAT_CONT 0xC5 /* Control register for backup battery */
|
|
||||||
|
|
||||||
|
|
||||||
static int da9063_i2c_bus = 0;
|
|
||||||
|
|
||||||
void da9063_init(int i2c_bus)
|
|
||||||
{
|
|
||||||
da9063_i2c_bus = i2c_bus;
|
|
||||||
}
|
|
||||||
|
|
||||||
int da9093_get_reg(int reg, u8* val)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
int old_bus;
|
|
||||||
u8 temp;
|
|
||||||
|
|
||||||
/* TODO: Check whether switching is required */
|
|
||||||
old_bus = i2c_get_bus_num();
|
|
||||||
i2c_set_bus_num(da9063_i2c_bus);
|
|
||||||
|
|
||||||
/* TODO: Use CONFIG_PMIC_I2C_ADDR+1 if reg > 0xFF */
|
|
||||||
*val = 0;
|
|
||||||
ret = i2c_read(CONFIG_PMIC_I2C_ADDR, reg, 1, &temp, 1);
|
|
||||||
if (ret == 0)
|
|
||||||
*val = temp;
|
|
||||||
|
|
||||||
i2c_set_bus_num(old_bus);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int da9093_set_reg(int reg, u8 val)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
int old_bus;
|
|
||||||
|
|
||||||
/* TODO: Check whether switching is required */
|
|
||||||
old_bus = i2c_get_bus_num();
|
|
||||||
i2c_set_bus_num(da9063_i2c_bus);
|
|
||||||
|
|
||||||
/* TODO: Use CONFIG_PMIC_I2C_ADDR+1 if reg > 0xFF */
|
|
||||||
ret = i2c_write(CONFIG_PMIC_I2C_ADDR, reg, 1, &val, 1);
|
|
||||||
if (ret != 0)
|
|
||||||
puts("da9063 write error\n");
|
|
||||||
|
|
||||||
i2c_set_bus_num(old_bus);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void da9063_set_gpio(unsigned bit, int state)
|
|
||||||
{
|
|
||||||
int pmic_reg;
|
|
||||||
int ret;
|
|
||||||
u8 bitmask;
|
|
||||||
u8 reg = 0x00;
|
|
||||||
|
|
||||||
if (bit <= 7) {
|
|
||||||
pmic_reg = PMIC_REG_GPIO_MODE0_7;
|
|
||||||
bitmask = 1U << (bit-0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pmic_reg = PMIC_REG_GPIO_MODE8_15;
|
|
||||||
bitmask = 1U << (bit-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* printf("da9063_set_gpio %d 0x%04x\n", pmic_reg, bitmask); */
|
|
||||||
ret = da9093_get_reg(pmic_reg, ®);
|
|
||||||
|
|
||||||
if (ret == 0) {
|
|
||||||
if (state) reg |= bitmask;
|
|
||||||
else reg &= ~bitmask;
|
|
||||||
|
|
||||||
(void)da9093_set_reg(pmic_reg, reg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void set_status_led(int red, int green)
|
static void set_status_led(int red, int green)
|
||||||
{
|
{
|
||||||
/* LED outputs are active low, invert state */
|
/* LED outputs are active low, invert state */
|
||||||
|
|
@ -580,19 +519,14 @@ int board_init(void)
|
||||||
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
|
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
|
||||||
|
|
||||||
/* Configure both I2C buses used in NRHW20 */
|
/* Configure both I2C buses used in NRHW20 */
|
||||||
i2c_set_bus_num(0);
|
init_i2c();
|
||||||
i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
|
|
||||||
i2c_set_bus_num(2);
|
|
||||||
i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
|
|
||||||
i2c_set_bus_num(0);
|
|
||||||
|
|
||||||
da9063_init(CONFIG_PMIC_I2C_BUS);
|
da9063_init(CONFIG_PMIC_I2C_BUS);
|
||||||
|
|
||||||
/* Let user know we're starting */
|
/* Let user know we're starting */
|
||||||
init_indicator_leds();
|
init_indicator_leds();
|
||||||
set_status_led(1, 1); /* Orange */
|
set_status_led(1, 1); /* Orange */
|
||||||
set_indicator(0, 0, 1); /* Green */
|
/* set_indicator(0, 0, 1); *//* Green */
|
||||||
set_indicator(1, 0, 1); /* Green */
|
|
||||||
|
|
||||||
/* Initialize pins */
|
/* Initialize pins */
|
||||||
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN);
|
REQUEST_AND_CLEAR_GPIO(NETBIRD_GPIO_WLAN_EN);
|
||||||
|
|
@ -606,7 +540,7 @@ int board_init(void)
|
||||||
init_gsm();
|
init_gsm();
|
||||||
|
|
||||||
/* Enable charging of RTC backup capacitor (1mA, 3.1V) */
|
/* Enable charging of RTC backup capacitor (1mA, 3.1V) */
|
||||||
(void)da9093_set_reg(PMIC_REG_BBAT_CONT, 0xCF);
|
(void)da9063_set_reg(PMIC_REG_BBAT_CONT, 0xCF);
|
||||||
|
|
||||||
printf("OSC: %lu MHz\n", get_osclk()/1000000);
|
printf("OSC: %lu MHz\n", get_osclk()/1000000);
|
||||||
|
|
||||||
|
|
@ -797,7 +731,7 @@ static bool get_button_state(void)
|
||||||
{
|
{
|
||||||
u8 state = 0x00;
|
u8 state = 0x00;
|
||||||
|
|
||||||
(void)da9093_get_reg(PMIC_REG_STATUS_A, &state);
|
(void)da9063_get_reg(PMIC_REG_STATUS_A, &state);
|
||||||
|
|
||||||
return (state & 0x01) == 0x01;
|
return (state & 0x01) == 0x01;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* da9063.c
|
||||||
|
*
|
||||||
|
* Dialog DA9063 PMIC
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 NetModule AG - http://www.netmodule.com/
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0+
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <i2c.h>
|
||||||
|
|
||||||
|
#include "da9063.h"
|
||||||
|
|
||||||
|
|
||||||
|
static int da9063_i2c_bus = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void da9063_init(int i2c_bus)
|
||||||
|
{
|
||||||
|
da9063_i2c_bus = i2c_bus;
|
||||||
|
}
|
||||||
|
|
||||||
|
int da9063_get_reg(int reg, u8* val)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int old_bus;
|
||||||
|
u8 temp;
|
||||||
|
|
||||||
|
/* TODO: Check whether switching is required */
|
||||||
|
old_bus = i2c_get_bus_num();
|
||||||
|
i2c_set_bus_num(da9063_i2c_bus);
|
||||||
|
|
||||||
|
/* TODO: Use CONFIG_PMIC_I2C_ADDR+1 if reg > 0xFF */
|
||||||
|
*val = 0;
|
||||||
|
ret = i2c_read(CONFIG_PMIC_I2C_ADDR, reg, 1, &temp, 1);
|
||||||
|
if (ret == 0)
|
||||||
|
*val = temp;
|
||||||
|
|
||||||
|
i2c_set_bus_num(old_bus);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int da9063_set_reg(int reg, u8 val)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
int old_bus;
|
||||||
|
|
||||||
|
/* TODO: Check whether switching is required */
|
||||||
|
old_bus = i2c_get_bus_num();
|
||||||
|
i2c_set_bus_num(da9063_i2c_bus);
|
||||||
|
|
||||||
|
/* TODO: Use CONFIG_PMIC_I2C_ADDR+1 if reg > 0xFF */
|
||||||
|
ret = i2c_write(CONFIG_PMIC_I2C_ADDR, reg, 1, &val, 1);
|
||||||
|
if (ret != 0)
|
||||||
|
puts("da9063 write error\n");
|
||||||
|
|
||||||
|
i2c_set_bus_num(old_bus);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void da9063_set_gpio(unsigned bit, int state)
|
||||||
|
{
|
||||||
|
int pmic_reg;
|
||||||
|
int ret;
|
||||||
|
u8 bitmask;
|
||||||
|
u8 reg = 0x00;
|
||||||
|
|
||||||
|
if (bit <= 7) {
|
||||||
|
pmic_reg = PMIC_REG_GPIO_MODE0_7;
|
||||||
|
bitmask = 1U << (bit-0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pmic_reg = PMIC_REG_GPIO_MODE8_15;
|
||||||
|
bitmask = 1U << (bit-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* printf("da9063_set_gpio %d 0x%04x\n", pmic_reg, bitmask); */
|
||||||
|
ret = da9063_get_reg(pmic_reg, ®);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
if (state) reg |= bitmask;
|
||||||
|
else reg &= ~bitmask;
|
||||||
|
|
||||||
|
(void)da9063_set_reg(pmic_reg, reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* da9063.c
|
||||||
|
*
|
||||||
|
* Dialog DA9063 PMIC
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 NetModule AG - http://www.netmodule.com/
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0+
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DA9063_H
|
||||||
|
#define DA9063_H
|
||||||
|
|
||||||
|
|
||||||
|
#define CONFIG_PMIC_I2C_BUS 0
|
||||||
|
#define CONFIG_PMIC_I2C_ADDR 0x58 /* Pages 0 and 1, Pages 2 and 3 -> 0x59 */
|
||||||
|
|
||||||
|
#define PMIC_REG_STATUS_A 0x01 /* Status of ON_KEY, WAKE, COMP1V2, DVC */
|
||||||
|
#define PMIC_REG_GPIO_MODE0_7 0x1D /* Control register for GPIOs 0..7 */
|
||||||
|
#define PMIC_REG_GPIO_MODE8_15 0x1E /* Control register for GPIOs 8..15 */
|
||||||
|
|
||||||
|
#define PMIC_REG_BBAT_CONT 0xC5 /* Control register for backup battery */
|
||||||
|
|
||||||
|
#define PMIC_REG_BUCK_ILIM_A 0x9A
|
||||||
|
#define PMIC_REG_BUCK_ILIM_B 0x9B
|
||||||
|
#define PMIC_REG_BUCK_ILIM_C 0x9C
|
||||||
|
|
||||||
|
|
||||||
|
extern void da9063_init(int i2c_bus);
|
||||||
|
extern int da9063_get_reg(int reg, u8* val);
|
||||||
|
extern int da9063_set_reg(int reg, u8 val);
|
||||||
|
|
||||||
|
extern void da9063_set_gpio(unsigned bit, int state);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* DA9063_H */
|
||||||
Loading…
Reference in New Issue