From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Liu Date: Wed, 11 May 2011 16:03:41 +0800 Subject: [U-Boot] [PATCH V7 2/3] PMIC: Add dialog pmic support In-Reply-To: <1305101022-22546-1-git-send-email-jason.hui@linaro.org> References: <1305101022-22546-1-git-send-email-jason.hui@linaro.org> Message-ID: <1305101022-22546-2-git-send-email-jason.hui@linaro.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de This patch add dialog pmic(DA9053) driver with I2C interface support In order to not duplicate code and according to the discussion on the mail-list, change fsl_pmic.c to spi_i2c_pmic.c.Actaully,spi_i2c_pmic.c is just a wrapper for PMIC communication when SPI or I2C is used. Signed-off-by: Jason Liu Cc: sbabic at denx.de Cc: Detlev Zundel --- change since v1: - use one file to support fsl pmic and dialog pmic - rename fsl_pmic.c to spi_i2c_pmic.c --- drivers/misc/Makefile | 3 +- drivers/misc/{fsl_pmic.c => spi_i2c_pmic.c} | 72 +++++++++-- include/da9053.h | 186 +++++++++++++++++++++++++++ 3 files changed, 248 insertions(+), 13 deletions(-) diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index b152486..b2e150e 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -26,9 +26,10 @@ include $(TOPDIR)/config.mk LIB := $(obj)libmisc.o COBJS-$(CONFIG_ALI152X) += ali512x.o +COBJS-$(CONFIG_DIALOG_PMIC) += spi_i2c_pmic.o COBJS-$(CONFIG_DS4510) += ds4510.o COBJS-$(CONFIG_FSL_LAW) += fsl_law.o -COBJS-$(CONFIG_FSL_PMIC) += fsl_pmic.o +COBJS-$(CONFIG_FSL_PMIC) += spi_i2c_pmic.o COBJS-$(CONFIG_GPIO_LED) += gpio_led.o COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o COBJS-$(CONFIG_NS87308) += ns87308.o diff --git a/drivers/misc/fsl_pmic.c b/drivers/misc/spi_i2c_pmic.c similarity index 76% rename from drivers/misc/fsl_pmic.c rename to drivers/misc/spi_i2c_pmic.c index ef80ad9..5fbfb40 100644 --- a/drivers/misc/fsl_pmic.c +++ b/drivers/misc/spi_i2c_pmic.c @@ -22,13 +22,16 @@ #include #include +#include #include #include +#if defined(CONFIG_FSL_PMIC) #include +#endif -static int check_param(u32 reg, u32 write) +static int check_param(u32 reg, u32 write, u32 max_reg) { - if (reg > 63 || write > 1) { + if (reg > max_reg || write > 1) { printf(" = %d is invalid. Should be less then 63\n", reg); return -1; @@ -37,15 +40,13 @@ static int check_param(u32 reg, u32 write) return 0; } -#ifdef CONFIG_FSL_PMIC_I2C -#include - -u32 pmic_reg(u32 reg, u32 val, u32 write) +#if defined(CONFIG_FSL_PMIC_I2C) +u32 fsl_pmic_reg(u32 reg, u32 val, u32 write) { - unsigned char buf[4] = { 0 }; u32 ret_val = 0; + unsigned char buf[4] = { 0 }; - if (check_param(reg, write)) + if (check_param(reg, write, 63)) return -1; if (write) { @@ -62,7 +63,44 @@ u32 pmic_reg(u32 reg, u32 val, u32 write) return ret_val; } -#else /* SPI interface */ +#endif + +#if defined(CONFIG_DIALOG_PMIC_I2C) +u32 dlg_pmic_reg(u32 reg, u32 val, u32 write) +{ + u32 ret_val = 0; + unsigned char buf[1] = { 0 }; + + if (check_param(reg, write, 142)) + return -1; + + if (write) { + buf[0] = (val) & 0xff; + if (i2c_write(CONFIG_SYS_DIALOG_PMIC_I2C_ADDR, reg, 1, buf, 1)) + return -1; + } else { + if (i2c_read(CONFIG_SYS_DIALOG_PMIC_I2C_ADDR, reg, 1, buf, 1)) + return -1; + ret_val = buf[0]; + } + + return ret_val; +} +#endif + +#if defined(CONFIG_FSL_PMIC_I2C) || defined(CONFIG_DIALOG_PMIC_I2C) +#include +u32 pmic_reg(u32 reg, u32 val, u32 write) +{ +#if defined(CONFIG_FSL_PMIC_I2C) + return fsl_pmic_reg(reg, val, write); +#endif + +#if defined(CONFIG_DIALOG_PMIC_I2C) + return dlg_pmic_reg(reg, val, write); +#endif +} +#elif defined(CONFIG_FSL_PMIC) /* SPI interface */ #include static struct spi_slave *slave; @@ -92,7 +130,7 @@ u32 pmic_reg(u32 reg, u32 val, u32 write) return -1; } - if (check_param(reg, write)) + if (check_param(reg, write, 63)) return -1; if (spi_claim_bus(slave)) @@ -135,6 +173,7 @@ u32 pmic_reg_read(u32 reg) void pmic_show_pmic_info(void) { +#if defined(CONFIG_FSL_PMIC) u32 rev_id; rev_id = pmic_reg_read(REG_IDENTIFICATION); @@ -178,6 +217,7 @@ void pmic_show_pmic_info(void) break; } puts("]\n"); +#endif } static void pmic_dump(int numregs) @@ -189,7 +229,7 @@ static void pmic_dump(int numregs) for (i = 0; i < numregs; i++) { val = pmic_reg_read(i); if (!(i % 8)) - printf ("\n0x%02x: ", i); + printf("\n0x%02x: ", i); printf("%08x ", val); } puts("\n"); @@ -227,9 +267,17 @@ int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return 1; } +#if defined(CONFIG_FSL_PMIC) +#define PMIC_NAME "Freescale PMIC (Atlas)" +#elif defined(CONFIG_DIALOG_PMIC) +#define PMIC_NAME "Dialog PMIC (DA905x)" +#else +#error "Unkown PMIC name" +#endif + U_BOOT_CMD( pmic, CONFIG_SYS_MAXARGS, 1, do_pmic, - "Freescale PMIC (Atlas)", + PMIC_NAME, "dump [numregs] dump registers\n" "pmic write - write register" ); diff --git a/include/da9053.h b/include/da9053.h new file mode 100644 index 0000000..f69408a --- /dev/null +++ b/include/da9053.h @@ -0,0 +1,186 @@ +/* + * da9053 register declarations. + * + * Copyright(c) 2009 Dialog Semiconductor Ltd. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __DA9053_REG_H__ +#define __DA9053_REG_H__ + +enum { + DA9053_PAGECON0_REG = 0, + DA9053_STATUSA_REG, + DA9053_STATUSB_REG, + DA9053_STATUSC_REG, + DA9053_STATUSD_REG, + DA9053_EVENTA_REG, + DA9053_EVENTB_REG, + DA9053_EVENTC_REG, + DA9053_EVENTD_REG, + DA9053_FAULTLOG_REG, + DA9053_IRQMASKA_REG, + DA9053_IRQMASKB_REG, + DA9053_IRQMASKC_REG, + DA9053_IRQMASKD_REG, + DA9053_CONTROLA_REG, + DA9053_CONTROLB_REG, + DA9053_CONTROLC_REG, + DA9053_CONTROLD_REG, + DA9053_PDDIS_REG, + DA9053_INTERFACE_REG, + DA9053_RESET_REG, + DA9053_GPIO0001_REG, + DA9053_GPIO0203_REG, + DA9053_GPIO0405_REG, + DA9053_GPIO0607_REG, + DA9053_GPIO0809_REG, + DA9053_GPIO1011_REG, + DA9053_GPIO1213_REG, + DA9053_GPIO1415_REG, + DA9053_ID01_REG, + DA9053_ID23_REG, + DA9053_ID45_REG, + DA9053_ID67_REG, + DA9053_ID89_REG, + DA9053_ID1011_REG, + DA9053_ID1213_REG, + DA9053_ID1415_REG, + DA9053_ID1617_REG, + DA9053_ID1819_REG, + DA9053_ID2021_REG, + DA9053_SEQSTATUS_REG, + DA9053_SEQA_REG, + DA9053_SEQB_REG, + DA9053_SEQTIMER_REG, + DA9053_BUCKA_REG, + DA9053_BUCKB_REG, + DA9053_BUCKCORE_REG, + DA9053_BUCKPRO_REG, + DA9053_BUCKMEM_REG, + DA9053_BUCKPERI_REG, + DA9053_LDO1_REG, + DA9053_LDO2_REG, + DA9053_LDO3_REG, + DA9053_LDO4_REG, + DA9053_LDO5_REG, + DA9053_LDO6_REG, + DA9053_LDO7_REG, + DA9053_LDO8_REG, + DA9053_LDO9_REG, + DA9053_LDO10_REG, + DA9053_SUPPLY_REG, + DA9053_PULLDOWN_REG, + DA9053_CHGBUCK_REG, + DA9053_WAITCONT_REG, + DA9053_ISET_REG, + DA9053_BATCHG_REG, + DA9053_CHGCONT_REG, + DA9053_INPUTCONT_REG, + DA9053_CHGTIME_REG, + DA9053_BBATCONT_REG, + DA9053_BOOST_REG, + DA9053_LEDCONT_REG, + DA9053_LEDMIN123_REG, + DA9053_LED1CONF_REG, + DA9053_LED2CONF_REG, + DA9053_LED3CONF_REG, + DA9053_LED1CONT_REG, + DA9053_LED2CONT_REG, + DA9053_LED3CONT_REG, + DA9053_LED4CONT_REG, + DA9053_LED5CONT_REG, + DA9053_ADCMAN_REG, + DA9053_ADCCONT_REG, + DA9053_ADCRESL_REG, + DA9053_ADCRESH_REG, + DA9053_VDDRES_REG, + DA9053_VDDMON_REG, + DA9053_ICHGAV_REG, + DA9053_ICHGTHD_REG, + DA9053_ICHGEND_REG, + DA9053_TBATRES_REG, + DA9053_TBATHIGHP_REG, + DA9053_TBATHIGHIN_REG, + DA9053_TBATLOW_REG, + DA9053_TOFFSET_REG, + DA9053_ADCIN4RES_REG, + DA9053_AUTO4HIGH_REG, + DA9053_AUTO4LOW_REG, + DA9053_ADCIN5RES_REG, + DA9053_AUTO5HIGH_REG, + DA9053_AUTO5LOW_REG, + DA9053_ADCIN6RES_REG, + DA9053_AUTO6HIGH_REG, + DA9053_AUTO6LOW_REG, + DA9053_TJUNCRES_REG, + DA9053_TSICONTA_REG, + DA9053_TSICONTB_REG, + DA9053_TSIXMSB_REG, + DA9053_TSIYMSB_REG, + DA9053_TSILSB_REG, + DA9053_TSIZMSB_REG, + DA9053_COUNTS_REG, + DA9053_COUNTMI_REG, + DA9053_COUNTH_REG, + DA9053_COUNTD_REG, + DA9053_COUNTMO_REG, + DA9053_COUNTY_REG, + DA9053_ALARMMI_REG, + DA9053_ALARMH_REG, + DA9053_ALARMD_REG, + DA9053_ALARMMO_REG, + DA9053_ALARMY_REG, + DA9053_SECONDA_REG, + DA9053_SECONDB_REG, + DA9053_SECONDC_REG, + DA9053_SECONDD_REG, + DA9053_PAGECON128_REG, + DA9053_CHIPID_REG, + DA9053_CONFIGID_REG, + DA9053_OTPCONT_REG, + DA9053_OSCTRIM_REG, + DA9053_GPID0_REG, + DA9053_GPID1_REG, + DA9053_GPID2_REG, + DA9053_GPID3_REG, + DA9053_GPID4_REG, + DA9053_GPID5_REG, + DA9053_GPID6_REG, + DA9053_GPID7_REG, + DA9053_GPID8_REG, + DA9053_GPID9_REG, +}; + +#define DA_BUCKCORE_VBCORE_1_250V 0x1e + +/* BUCKCORE REGISTER */ +#define DA9052_BUCKCORE_BCORECONF (1<<7) +#define DA9052_BUCKCORE_BCOREEN (1<<6) +#define DA9052_BUCKCORE_VBCORE (63<<0) + +/* SUPPLY REGISTER */ +#define DA9052_SUPPLY_VLOCK (1<<7) +#define DA9052_SUPPLY_VMEMSWEN (1<<6) +#define DA9052_SUPPLY_VPERISWEN (1<<5) +#define DA9052_SUPPLY_VLDO3GO (1<<4) +#define DA9052_SUPPLY_VLDO2GO (1<<3) +#define DA9052_SUPPLY_VBMEMGO (1<<2) +#define DA9052_SUPPLY_VBPROGO (1<<1) +#define DA9052_SUPPLY_VBCOREGO (1<<0) + +#endif /* __DA9053_REG_H__ */ -- 1.7.1