2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-11-30 18:43:09 +00:00
|
|
|
/*
|
2019-02-08 17:42:12 +00:00
|
|
|
* Copyright (C) 2014-2019, Toradex AG
|
2016-11-30 18:43:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helpers for Freescale PMIC PF0100
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <i2c.h>
|
|
|
|
#include <asm/arch/imx-regs.h>
|
|
|
|
#include <asm/arch/iomux.h>
|
|
|
|
#include <asm/arch/mx6-pins.h>
|
|
|
|
#include <asm/gpio.h>
|
2017-06-29 08:16:06 +00:00
|
|
|
#include <asm/mach-imx/iomux-v3.h>
|
2016-11-30 18:43:09 +00:00
|
|
|
|
|
|
|
#include "pf0100_otp.inc"
|
|
|
|
#include "pf0100.h"
|
|
|
|
|
|
|
|
/* define for PMIC register dump */
|
|
|
|
/*#define DEBUG */
|
|
|
|
|
|
|
|
/* use GPIO: EXT_IO1 to switch on VPGM, ON: 1 */
|
2018-01-03 14:19:17 +00:00
|
|
|
static __maybe_unused iomux_v3_cfg_t const pmic_prog_pads[] = {
|
2016-11-30 18:43:09 +00:00
|
|
|
MX6_PAD_NANDF_D3__GPIO2_IO03 | MUX_PAD_CTRL(NO_PAD_CTRL),
|
|
|
|
# define PMIC_PROG_VOLTAGE IMX_GPIO_NR(2, 3)
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned pmic_init(void)
|
|
|
|
{
|
2019-02-08 17:42:12 +00:00
|
|
|
int rc;
|
|
|
|
struct udevice *dev = NULL;
|
2016-11-30 18:43:09 +00:00
|
|
|
unsigned programmed = 0;
|
|
|
|
uchar bus = 1;
|
|
|
|
uchar devid, revid, val;
|
|
|
|
|
|
|
|
puts("PMIC: ");
|
2019-02-08 17:42:12 +00:00
|
|
|
rc = i2c_get_chip_for_busnum(bus, PFUZE100_I2C_ADDR, 1, &dev);
|
|
|
|
if (rc) {
|
|
|
|
printf("failed to get device for PMIC at address 0x%x\n",
|
|
|
|
PFUZE100_I2C_ADDR);
|
2016-11-30 18:43:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* get device ident */
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_read(dev, PFUZE100_DEVICEID, &devid, 1) < 0) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c pmic devid read failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_read(dev, PFUZE100_REVID, &revid, 1) < 0) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c pmic revid read failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
printf("device id: 0x%.2x, revision id: 0x%.2x\n", devid, revid);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2019-02-08 17:42:12 +00:00
|
|
|
unsigned int i, j;
|
2016-11-30 18:43:09 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
printf("\t%x", i);
|
|
|
|
for (j = 0; j < 0x80; ) {
|
|
|
|
printf("\n%2x", j);
|
|
|
|
for (i = 0; i < 16; i++) {
|
2019-02-08 17:42:12 +00:00
|
|
|
dm_i2c_read(dev, j + i, &val, 1);
|
2016-11-30 18:43:09 +00:00
|
|
|
printf("\t%2x", val);
|
|
|
|
}
|
|
|
|
j += 0x10;
|
|
|
|
}
|
|
|
|
printf("\nEXT Page 1");
|
|
|
|
|
|
|
|
val = PFUZE100_PAGE_REGISTER_PAGE1;
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_write(dev, PFUZE100_PAGE_REGISTER, &val, 1)) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c write failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0x80; j < 0x100; ) {
|
|
|
|
printf("\n%2x", j);
|
|
|
|
for (i = 0; i < 16; i++) {
|
2019-02-08 17:42:12 +00:00
|
|
|
dm_i2c_read(dev, j + i, &val, 1);
|
2016-11-30 18:43:09 +00:00
|
|
|
printf("\t%2x", val);
|
|
|
|
}
|
|
|
|
j += 0x10;
|
|
|
|
}
|
|
|
|
printf("\nEXT Page 2");
|
|
|
|
|
|
|
|
val = PFUZE100_PAGE_REGISTER_PAGE2;
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_write(dev, PFUZE100_PAGE_REGISTER, &val, 1)) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c write failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0x80; j < 0x100; ) {
|
|
|
|
printf("\n%2x", j);
|
|
|
|
for (i = 0; i < 16; i++) {
|
2019-02-08 17:42:12 +00:00
|
|
|
dm_i2c_read(dev, j + i, &val, 1);
|
2016-11-30 18:43:09 +00:00
|
|
|
printf("\t%2x", val);
|
|
|
|
}
|
|
|
|
j += 0x10;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2019-02-08 17:42:12 +00:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2016-11-30 18:43:09 +00:00
|
|
|
/* get device programmed state */
|
|
|
|
val = PFUZE100_PAGE_REGISTER_PAGE1;
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_write(dev, PFUZE100_PAGE_REGISTER, &val, 1)) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c write failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_read(dev, PFUZE100_FUSE_POR1, &val, 1) < 0) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c fuse_por read failed\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (val & PFUZE100_FUSE_POR_M)
|
|
|
|
programmed++;
|
|
|
|
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_read(dev, PFUZE100_FUSE_POR2, &val, 1) < 0) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c fuse_por read failed\n");
|
|
|
|
return programmed;
|
|
|
|
}
|
|
|
|
if (val & PFUZE100_FUSE_POR_M)
|
|
|
|
programmed++;
|
|
|
|
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_read(dev, PFUZE100_FUSE_POR3, &val, 1) < 0) {
|
2016-11-30 18:43:09 +00:00
|
|
|
puts("i2c fuse_por read failed\n");
|
|
|
|
return programmed;
|
|
|
|
}
|
|
|
|
if (val & PFUZE100_FUSE_POR_M)
|
|
|
|
programmed++;
|
|
|
|
|
|
|
|
switch (programmed) {
|
|
|
|
case 0:
|
|
|
|
printf("PMIC: not programmed\n");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
printf("PMIC: programmed\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("PMIC: undefined programming state\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return programmed;
|
|
|
|
}
|
|
|
|
|
2018-01-03 14:19:17 +00:00
|
|
|
#ifndef CONFIG_SPL_BUILD
|
|
|
|
static int pf0100_prog(void)
|
2016-11-30 18:43:09 +00:00
|
|
|
{
|
2019-02-08 17:42:12 +00:00
|
|
|
int rc;
|
|
|
|
struct udevice *dev = NULL;
|
2016-11-30 18:43:09 +00:00
|
|
|
unsigned char bus = 1;
|
|
|
|
unsigned char val;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (pmic_init() == 3) {
|
|
|
|
puts("PMIC already programmed, exiting\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
/* set up gpio to manipulate vprog, initially off */
|
|
|
|
imx_iomux_v3_setup_multiple_pads(pmic_prog_pads,
|
|
|
|
ARRAY_SIZE(pmic_prog_pads));
|
|
|
|
gpio_direction_output(PMIC_PROG_VOLTAGE, 0);
|
|
|
|
|
2019-02-08 17:42:12 +00:00
|
|
|
rc = i2c_get_chip_for_busnum(bus, PFUZE100_I2C_ADDR, 1, &dev);
|
|
|
|
if (rc) {
|
|
|
|
printf("failed to get device for PMIC at address 0x%x\n",
|
|
|
|
PFUZE100_I2C_ADDR);
|
2016-11-30 18:43:09 +00:00
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(pmic_otp_prog); i++) {
|
|
|
|
switch (pmic_otp_prog[i].cmd) {
|
|
|
|
case pmic_i2c:
|
|
|
|
val = (unsigned char) (pmic_otp_prog[i].value & 0xff);
|
2019-02-08 17:42:12 +00:00
|
|
|
if (dm_i2c_write(dev, pmic_otp_prog[i].reg, &val, 1)) {
|
2016-11-30 18:43:09 +00:00
|
|
|
printf("i2c write failed, reg 0x%2x, value 0x%2x\n",
|
|
|
|
pmic_otp_prog[i].reg, val);
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pmic_delay:
|
|
|
|
udelay(pmic_otp_prog[i].value * 1000);
|
|
|
|
break;
|
|
|
|
case pmic_vpgm:
|
|
|
|
gpio_direction_output(PMIC_PROG_VOLTAGE,
|
|
|
|
pmic_otp_prog[i].value);
|
|
|
|
break;
|
|
|
|
case pmic_pwr:
|
|
|
|
/* TODO */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2018-01-03 14:19:17 +00:00
|
|
|
static int do_pf0100_prog(cmd_tbl_t *cmdtp, int flag, int argc,
|
2016-11-30 18:43:09 +00:00
|
|
|
char * const argv[])
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
puts("Programming PMIC OTP...");
|
|
|
|
ret = pf0100_prog();
|
|
|
|
if (ret == CMD_RET_SUCCESS)
|
|
|
|
puts("done.\n");
|
|
|
|
else
|
|
|
|
puts("failed.\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
pf0100_otp_prog, 1, 0, do_pf0100_prog,
|
|
|
|
"Program the OTP fuses on the PMIC PF0100",
|
|
|
|
""
|
|
|
|
);
|
2019-02-08 17:42:12 +00:00
|
|
|
#endif /* CONFIG_SPL_BUILD */
|