All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Liu <jason.hui@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V7 2/3] PMIC: Add dialog pmic support
Date: Wed, 11 May 2011 16:03:41 +0800	[thread overview]
Message-ID: <1305101022-22546-2-git-send-email-jason.hui@linaro.org> (raw)
In-Reply-To: <1305101022-22546-1-git-send-email-jason.hui@linaro.org>

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 <jason.hui@linaro.org>
Cc: sbabic at denx.de <sbabic@denx.de>
Cc: Detlev Zundel <dzu@denx.de>
---
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 <config.h>
 #include <common.h>
+#include <i2c.h>
 #include <asm/errno.h>
 #include <linux/types.h>
+#if defined(CONFIG_FSL_PMIC)
 #include <fsl_pmic.h>
+#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("<reg num> = %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 <i2c.h>
-
-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 <i2c.h>
+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 <spi.h>
 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 <reg> <value> - 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

  reply	other threads:[~2011-05-11  8:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-11  8:03 [U-Boot] [PATCH V7 1/3] MX5: clock: Add clock config interface Jason Liu
2011-05-11  8:03 ` Jason Liu [this message]
2011-05-12  9:19   ` [U-Boot] [PATCH V7 2/3] PMIC: Add dialog pmic support Stefano Babic
2011-05-13  3:08     ` Jason Liu
2011-05-13  6:38       ` Stefano Babic
2011-05-13  8:41         ` Jason Liu
2011-05-13  8:47           ` Stefano Babic
2011-05-13  9:04             ` Jason Hui
2011-05-11  8:03 ` [U-Boot] [PATCH V7 3/3] MX53: support for freescale MX53LOCO board Jason Liu
2011-05-11 12:03   ` Fabio Estevam
2011-05-12  5:31     ` Jason Hui
2011-05-11 12:37   ` Stefano Babic
2011-05-12  5:32     ` Jason Hui
2011-05-12  6:13     ` Jason Liu
2011-05-12  9:03       ` Stefano Babic
2011-05-13  3:13         ` Jason Hui
2011-05-20 18:35   ` Albert ARIBAUD
2011-05-16  9:26 ` [U-Boot] [PATCH V7 1/3] MX5: clock: Add clock config interface Stefano Babic
2011-05-17  6:25   ` Jason Liu
2011-05-17 11:15     ` Stefano Babic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305101022-22546-2-git-send-email-jason.hui@linaro.org \
    --to=jason.hui@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.