All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver
@ 2011-09-01  9:13 Lukasz Majewski
  2011-09-01  9:13 ` [U-Boot] [PATCH 1/2] " Lukasz Majewski
                   ` (5 more replies)
  0 siblings, 6 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-01  9:13 UTC (permalink / raw)
  To: u-boot

This patch series add support for MAXIM's MAX8998 power IC chip.
It also enables usage of it on the GONI reference target. 

Lukasz Majewski (2):
  misc:max8998 Support for MAX8998 PMIC driver
  misc:samsung:s5p Enable MAX8998 support at GONI reference target

 drivers/misc/Makefile       |    1 +
 drivers/misc/max8998_pmic.c |   74 ++++++++++++++++++++++++++++++++++++
 include/configs/s5p_goni.h  |    2 +
 include/max8998_pmic.h      |   87 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 164 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/max8998_pmic.c
 create mode 100644 include/max8998_pmic.h

-- 
1.7.2.3

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 1/2] misc:max8998 Support for MAX8998 PMIC driver
  2011-09-01  9:13 [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
@ 2011-09-01  9:13 ` Lukasz Majewski
  2011-09-01  9:13 ` [U-Boot] [PATCH 2/2] misc:samsung:s5p Enable MAX8998 support at GONI reference target Lukasz Majewski
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-01  9:13 UTC (permalink / raw)
  To: u-boot

This commit adds support for MAX8998 driver. CONFIG_MAX8998_PMIC
flag shall be defined on an architecture supporting it.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Cc: Wolfgang Denk <wd@denx.de>
---
 drivers/misc/Makefile       |    1 +
 drivers/misc/max8998_pmic.c |   74 ++++++++++++++++++++++++++++++++++++
 include/max8998_pmic.h      |   87 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 162 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/max8998_pmic.c
 create mode 100644 include/max8998_pmic.h

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b152486..551bea9 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -35,6 +35,7 @@ COBJS-$(CONFIG_NS87308) += ns87308.o
 COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
 COBJS-$(CONFIG_STATUS_LED) += status_led.o
 COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o
+COBJS-$(CONFIG_MAX8998_PMIC) += max8998_pmic.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/misc/max8998_pmic.c b/drivers/misc/max8998_pmic.c
new file mode 100644
index 0000000..0600976
--- /dev/null
+++ b/drivers/misc/max8998_pmic.c
@@ -0,0 +1,74 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <i2c.h>
+#include <max8998_pmic.h>
+
+static int max8998_read_reg(unsigned int reg, unsigned char *val)
+{
+	if (i2c_read(MAX8998_I2C_ADDR, reg, 1, val, 1))
+		return -1;
+
+	return 0;
+}
+
+static int max8998_write_reg(unsigned int reg, unsigned char *val)
+{
+
+	if (i2c_write(MAX8998_I2C_ADDR, reg, 1, val, 1))
+		return -1;
+
+	return 0;
+}
+
+int max8998_probe(void)
+{
+	i2c_set_bus_num(I2C_PMIC);
+
+	if (i2c_probe(MAX8998_I2C_ADDR)) {
+		puts("Can't find max8998\n");
+		return 1;
+	}
+
+	return 0;
+}
+
+int max8998_set_ldo(unsigned int reg, unsigned char ldo, int on)
+{
+	unsigned char val;
+
+	if (max8998_read_reg(reg, &val))
+		return -1;
+
+	if (on)
+		val |= ldo;
+	else
+		val &= ~ldo;
+
+	if (max8998_write_reg(reg, &val))
+		return -1;
+
+	printf("MAX ONOFF1: val:0x%x\n", val);
+	return 0;
+}
diff --git a/include/max8998_pmic.h b/include/max8998_pmic.h
new file mode 100644
index 0000000..1a4281d
--- /dev/null
+++ b/include/max8998_pmic.h
@@ -0,0 +1,87 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __MAX8998_PMIC_H_
+#define __MAX8998_PMIC_H_
+
+/* MAX 8998 registers */
+enum {
+	MAX8998_REG_IRQ1,
+	MAX8998_REG_IRQ2,
+	MAX8998_REG_IRQ3,
+	MAX8998_REG_IRQ4,
+	MAX8998_REG_IRQM1,
+	MAX8998_REG_IRQM2,
+	MAX8998_REG_IRQM3,
+	MAX8998_REG_IRQM4,
+	MAX8998_REG_STATUS1,
+	MAX8998_REG_STATUS2,
+	MAX8998_REG_STATUSM1,
+	MAX8998_REG_STATUSM2,
+	MAX8998_REG_CHGR1,
+	MAX8998_REG_CHGR2,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE1,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE2,
+	MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
+	MAX8998_REG_ONOFF1,
+	MAX8998_REG_ONOFF2,
+	MAX8998_REG_ONOFF3,
+	MAX8998_REG_ONOFF4,
+	MAX8998_REG_BUCK1_VOLTAGE1,
+	MAX8998_REG_BUCK1_VOLTAGE2,
+	MAX8998_REG_BUCK1_VOLTAGE3,
+	MAX8998_REG_BUCK1_VOLTAGE4,
+	MAX8998_REG_BUCK2_VOLTAGE1,
+	MAX8998_REG_BUCK2_VOLTAGE2,
+	MAX8998_REG_BUCK3,
+	MAX8998_REG_BUCK4,
+	MAX8998_REG_LDO2_LDO3,
+	MAX8998_REG_LDO4,
+	MAX8998_REG_LDO5,
+	MAX8998_REG_LDO6,
+	MAX8998_REG_LDO7,
+	MAX8998_REG_LDO8_LDO9,
+	MAX8998_REG_LDO10_LDO11,
+	MAX8998_REG_LDO12,
+	MAX8998_REG_LDO13,
+	MAX8998_REG_LDO14,
+	MAX8998_REG_LDO15,
+	MAX8998_REG_LDO16,
+	MAX8998_REG_LDO17,
+	MAX8998_REG_BKCHR,
+	MAX8998_REG_LBCNFG1,
+	MAX8998_REG_LBCNFG2,
+};
+
+#define MAX8998_LDO3		(1 << 2)
+#define MAX8998_LDO8		(1 << 5)
+
+#define MAX8998_I2C_ADDR        (0xCC >> 1)
+
+enum { LDO_OFF, LDO_ON };
+enum { I2C_PMIC, I2C_NUM, };
+
+int max8998_probe(void);
+int max8998_set_ldo(unsigned int reg, unsigned char ldo, int on);
+
+#endif /* __MAX8998_PMIC_H_ */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 2/2] misc:samsung:s5p Enable MAX8998 support at GONI reference target
  2011-09-01  9:13 [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
  2011-09-01  9:13 ` [U-Boot] [PATCH 1/2] " Lukasz Majewski
@ 2011-09-01  9:13 ` Lukasz Majewski
  2011-09-12  8:14 ` [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-01  9:13 UTC (permalink / raw)
  To: u-boot

Adds support for MAX8998 PMIC at S5PC110 GONI target.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
---
 include/configs/s5p_goni.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
index 886c8be..aef3a9d 100644
--- a/include/configs/s5p_goni.h
+++ b/include/configs/s5p_goni.h
@@ -223,6 +223,8 @@
 
 #define CONFIG_SYS_INIT_SP_ADDR	(CONFIG_SYS_LOAD_ADDR - 0x1000000)
 
+#define CONFIG_MAX8998_PMIC
+
 #include <asm/arch/gpio.h>
 /*
  * I2C Settings
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver
  2011-09-01  9:13 [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
  2011-09-01  9:13 ` [U-Boot] [PATCH 1/2] " Lukasz Majewski
  2011-09-01  9:13 ` [U-Boot] [PATCH 2/2] misc:samsung:s5p Enable MAX8998 support at GONI reference target Lukasz Majewski
@ 2011-09-12  8:14 ` Lukasz Majewski
  2011-09-12 10:50   ` Stefano Babic
  2011-09-19 15:06 ` [U-Boot] [RFC 0/2] Generic " Lukasz Majewski
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-12  8:14 UTC (permalink / raw)
  To: u-boot

On Thu, 01 Sep 2011 11:13:30 +0200
Lukasz Majewski <l.majewski@samsung.com> wrote:

> This patch series add support for MAXIM's MAX8998 power IC chip.
> It also enables usage of it on the GONI reference target. 
> 
> Lukasz Majewski (2):
>   misc:max8998 Support for MAX8998 PMIC driver
>   misc:samsung:s5p Enable MAX8998 support at GONI reference target
> 

Dear all,

Is there any feedback/comments for those patches?
MAX8998 PMIC patches were posted some time ago and no response has been
received.

BTW. On the "u-boot Custodians" page I haven't found anyone responsible
for driver/misc. Is there appropriate person for this, or shall it be
addressed to Wolfgang?

-- 
Best regards,

Lukasz Majewski

Samsung Poland R&D Center
Platform Group

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver
  2011-09-12  8:14 ` [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
@ 2011-09-12 10:50   ` Stefano Babic
  2011-09-12 11:41     ` Wolfgang Denk
  2011-09-12 13:18     ` Lukasz Majewski
  0 siblings, 2 replies; 40+ messages in thread
From: Stefano Babic @ 2011-09-12 10:50 UTC (permalink / raw)
  To: u-boot

On 09/12/2011 10:14 AM, Lukasz Majewski wrote:
> On Thu, 01 Sep 2011 11:13:30 +0200
> Lukasz Majewski <l.majewski@samsung.com> wrote:
> 
>> This patch series add support for MAXIM's MAX8998 power IC chip.
>> It also enables usage of it on the GONI reference target. 
>>
>> Lukasz Majewski (2):
>>   misc:max8998 Support for MAX8998 PMIC driver
>>   misc:samsung:s5p Enable MAX8998 support at GONI reference target
>>
> 
> Dear all,
> 

Hi Lukasz,

> Is there any feedback/comments for those patches?
> MAX8998 PMIC patches were posted some time ago and no response has been
> received.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver
  2011-09-12 10:50   ` Stefano Babic
@ 2011-09-12 11:41     ` Wolfgang Denk
  2011-09-12 13:18     ` Lukasz Majewski
  1 sibling, 0 replies; 40+ messages in thread
From: Wolfgang Denk @ 2011-09-12 11:41 UTC (permalink / raw)
  To: u-boot

Dear Stefano Babic,

In message <4E6DE3EF.6080107@denx.de> you wrote:
>
> > Is there appropriate person for this, or shall it be
> > addressed to Wolfgang?
> 
> I do not know - however, your driver is not strictly related to a
> specific SOC, and could be used by any architecture. We can consider it
> as general code, and I added Wolfgang in CC to ask his opinion.

If nobody else takes it, I will have to.

But I will not protest if you just go ahead and put it on your own
plate :-)

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Science makes godlike -- it is all over with priests and  gods  when
man becomes scientific. Moral: science is the forbidden as such -- it
alone  is  forbidden. Science is the *first* sin, the *original* sin.
*This alone is  morality.*  ``Thou  shalt  not  know''  --  the  rest
follows."                                       - Friedrich Nietzsche

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver
  2011-09-12 10:50   ` Stefano Babic
  2011-09-12 11:41     ` Wolfgang Denk
@ 2011-09-12 13:18     ` Lukasz Majewski
  2011-09-12 13:50       ` Stefano Babic
  1 sibling, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-12 13:18 UTC (permalink / raw)
  To: u-boot

Hi Stefano,

Thanks for your reply.

> 
> From my site I promise I will get a look at it. At the moment I have a
> big question. I see your code is quite similar to other ones
> (fsl_pmic.c is what I know better..). I remember there was already a
> discussion about another pmic, whose patch reassembled some drivers
> in u-boot.
> 
> My big question is: if we have a similar mechanism to access the PMICs
> (SPI/I2C), should we not to found a way to generalize it ? This kind
> of driver has only some pmic_read/pmic_write functions.
> 
> Maybe getting rid of special manufacturer names as fsl_pmic,
> max_pmic... and using a general access for this kind of chips ? From
> code your patch is not very distant from what we currently have. Any
> opinion about this ?

Yes, you are right. I've looked to the fsl_pmic driver when I was
preparing patch for MAX8998. 

As you have written, dealing with those two PMICs boils down to
reading/writing their internal registers via I2C by i2c.h API.

We can think of a common PMIC framework, which is consisting of methods
for reading/writing internal registers, enabling outputs of those
devices.

PMIC specific data (like register map, I2C addresses) can be stored in
*.h files. 

I can prepare some common framework and post proposition on the
mailing list. On the beginning I'll focus on MAX8998 and FSL. 

Any comments/ideas are welcome. 
 
> > 
> > BTW. On the "u-boot Custodians" page I haven't found anyone
> > responsible for driver/misc.
> 
> You are right.
> 
> > Is there appropriate person for this, or shall it be
> > addressed to Wolfgang?
> 
> I do not know - however, your driver is not strictly related to a
> specific SOC, and could be used by any architecture. We can consider
> it as general code, and I added Wolfgang in CC to ask his opinion.
> 
> Best regards,
> Stefano Babic
> 


-- 
Best regards,

Lukasz Majewski

Samsung Poland R&D Center
Platform Group

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver
  2011-09-12 13:18     ` Lukasz Majewski
@ 2011-09-12 13:50       ` Stefano Babic
  0 siblings, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-09-12 13:50 UTC (permalink / raw)
  To: u-boot

On 09/12/2011 03:18 PM, Lukasz Majewski wrote:
> Hi Stefano,
> 
> Thanks for your reply.

Hi Lucasz,

>> Maybe getting rid of special manufacturer names as fsl_pmic,
>> max_pmic... and using a general access for this kind of chips ? From
>> code your patch is not very distant from what we currently have. Any
>> opinion about this ?
> 
> Yes, you are right. I've looked to the fsl_pmic driver when I was
> preparing patch for MAX8998. 

I have supposed...

> 
> As you have written, dealing with those two PMICs boils down to
> reading/writing their internal registers via I2C by i2c.h API.
> 
> We can think of a common PMIC framework, which is consisting of methods
> for reading/writing internal registers, enabling outputs of those
> devices.

Exactly !

> 
> PMIC specific data (like register map, I2C addresses) can be stored in
> *.h files. 

Yes, this is what I meant ;-)

> 
> I can prepare some common framework and post proposition on the
> mailing list. On the beginning I'll focus on MAX8998 and FSL. 

Agree.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [RFC 0/2] Generic PMIC driver
  2011-09-01  9:13 [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
                   ` (2 preceding siblings ...)
  2011-09-12  8:14 ` [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
@ 2011-09-19 15:06 ` Lukasz Majewski
  2011-09-19 15:06   ` [U-Boot] [RFC 1/2] misc:pmic New generic pmic driver Lukasz Majewski
                     ` (2 more replies)
  2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
  5 siblings, 3 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-19 15:06 UTC (permalink / raw)
  To: u-boot

Dear all,

I'd like to propose a new approach for PMIC generic driver.

In my opinion following issues needs discussion:
1. In proposed 
int pmic_reg_read(struct pmic *p, u32 *val) the val is returned by pointer.
Now at fsl_pmic.c read value is returned by return clause.
 
I think, that passing pointer is a better approach,since errors from i2c_read/spi_read can be
caught in upper layers.

2. Since I haven't got a chance to test SPI part of the fsl_pmic.c driver, I've focused
mainly on I2C and place stubs for SPI.

3. Suggestions for struct pmic's additional fields for SPI are more than welcome :-) 

4. Now the pmic_core.c file consist of
   #ifdef PMIC_I2C
   {Code for handling I2C}
   #else
   {Code for handling SPI}
   #endif

The same approach is used at fsl_pmic.c   

I'm wondering if this approach shouldn't be replaced with on-time checking if
SPI or I2C interface is available.
This check can be performed by:

struct pmic *p;
if (p->interface == PMIC_I2C) {

} else {

}

It would allow to remove obscure #ifdefs, but on the other hand it will reduce 
execution speed of the driver.

Thanks in advance,
Lukasz

 
Lukasz Majewski (2):
  misc:pmic New generic pmic driver
  misc:pmic:max8998: Support for max8998 pmic

 arch/arm/lib/board.c       |    5 +
 board/samsung/goni/goni.c  |   18 ++++
 drivers/misc/Makefile      |    1 +
 drivers/misc/pmic_core.c   |  236 ++++++++++++++++++++++++++++++++++++++++++++
 include/configs/s5p_goni.h |    3 +
 include/max8998_pmic.h     |   84 ++++++++++++++++
 include/pmic.h             |   60 +++++++++++
 7 files changed, 407 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pmic_core.c
 create mode 100644 include/max8998_pmic.h
 create mode 100644 include/pmic.h

-- 
1.7.2.3

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [RFC 1/2] misc:pmic New generic pmic driver
  2011-09-19 15:06 ` [U-Boot] [RFC 0/2] Generic " Lukasz Majewski
@ 2011-09-19 15:06   ` Lukasz Majewski
  2011-09-19 15:06   ` [U-Boot] [RFC 2/2] misc:pmic:max8998: Support for max8998 pmic Lukasz Majewski
  2011-09-20  8:23   ` [U-Boot] [RFC 0/2] Generic PMIC driver Stefano Babic
  2 siblings, 0 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-19 15:06 UTC (permalink / raw)
  To: u-boot

This commit adds new PMIC core driver
PMIC IC devices connected via I2C or SPI can be used.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
---
 arch/arm/lib/board.c     |    5 +
 drivers/misc/Makefile    |    1 +
 drivers/misc/pmic_core.c |  236 ++++++++++++++++++++++++++++++++++++++++++++++
 include/pmic.h           |   60 ++++++++++++
 4 files changed, 302 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pmic_core.c
 create mode 100644 include/pmic.h

diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index c899839..bd2c619 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -48,6 +48,7 @@
 #include <nand.h>
 #include <onenand_uboot.h>
 #include <mmc.h>
+#include <pmic.h>
 
 #ifdef CONFIG_BITBANGMII
 #include <miiphy.h>
@@ -580,6 +581,10 @@ void board_init_r(gd_t *id, ulong dest_addr)
 		copy_filename(BootFile, s, sizeof(BootFile));
 #endif
 
+#if defined(CONFIG_PMIC)
+	pmic_init();
+#endif
+
 #ifdef BOARD_LATE_INIT
 	board_late_init();
 #endif
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b152486..f710a29 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -35,6 +35,7 @@ COBJS-$(CONFIG_NS87308) += ns87308.o
 COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
 COBJS-$(CONFIG_STATUS_LED) += status_led.o
 COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o
+COBJS-$(CONFIG_PMIC) += pmic_core.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/misc/pmic_core.c b/drivers/misc/pmic_core.c
new file mode 100644
index 0000000..d96bb87
--- /dev/null
+++ b/drivers/misc/pmic_core.c
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+
+static struct pmic pmic;
+
+#ifdef CONFIG_PMIC_I2C
+#include <i2c.h>
+#define pmic_set_reg(r) (p->hw.i2c.reg = r)
+#define pmic_set_addr(a) (p->hw.i2c.addr = a)
+#define pmic_i2c_addr (p->hw.i2c.addr)
+#define pmic_i2c_reg (p->hw.i2c.reg)
+#define pmic_tx_num (p->hw.i2c.tx_num)
+#define pmic_i2c_bus (p->hw.i2c.bus_num)
+
+int pmic_reg_write(struct pmic *p, u32 *val)
+{
+	unsigned char buf[4] = { 0 };
+
+	switch (pmic_tx_num) {
+	case 3:
+		buf[0] = (*val >> 16) & 0xff;
+		buf[1] = (*val >> 8) & 0xff;
+		buf[2] = (*val) & 0xff;
+		break;
+	case 1:
+		buf[0] = (*val) & 0xff;
+		break;
+	}
+
+	if (i2c_write(pmic_i2c_addr, pmic_i2c_reg, 1, buf, pmic_tx_num))
+		return -1;
+
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 *val)
+{
+	unsigned char buf[4] = { 0 };
+	u32 ret_val = 0;
+
+	if (i2c_read(pmic_i2c_addr, pmic_i2c_reg, 1, buf, pmic_tx_num))
+		return -1;
+
+	switch (pmic_tx_num) {
+	case 3:
+		ret_val = buf[0] << 16 | buf[1] << 8 | buf[2];
+		break;
+	case 1:
+		ret_val = buf[0];
+		break;
+	}
+	memcpy(val, &ret_val, sizeof(ret_val));
+	/* printf("val 0x%x:", *val); */
+
+	return 0;
+}
+
+int pmic_probe(struct pmic *p)
+{
+	i2c_set_bus_num(pmic_i2c_bus);
+	printf("PMIC:%s probed!\n", p->name);
+	if (i2c_probe(pmic_i2c_addr)) {
+		puts("Can't find max8998\n");
+		return -1;
+	}
+
+	return 0;
+}
+#else /* SPI interface */
+#include <spi.h>
+static struct spi_slave *slave;
+
+#define pmic_set_reg(r)
+#define pmic_set_addr(a)
+
+void pmic_spi_free(struct spi_slave *slave)
+{
+	if (slave)
+		spi_free_slave(slave);
+}
+
+
+int pmic_reg_write(struct pmic *p, u32 *val)
+{
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 *val)
+{
+	return 0;
+}
+#endif
+
+int __attribute__((weak)) board_pmic_init(struct pmic *p)
+{
+	puts("weak function");
+	return 0;
+}
+
+int pmic_set_output(struct pmic *p, int out, int on)
+{
+	u32 val;
+
+	if (pmic_reg_read(p, &val))
+		return -1;
+
+	if (on)
+		val |= out;
+	else
+		val &= ~out;
+
+	if (pmic_reg_write(p, &val))
+		return -1;
+
+	return 0;
+}
+
+static void pmic_show_info(struct pmic *p)
+{
+	printf("PMIC: %s\n", p->name);
+}
+
+static void pmic_dump(struct pmic *p)
+{
+	int i, ret;
+	u32 val;
+
+	pmic_show_info(p);
+	for (i = 0; i < p->number_of_regs; i++) {
+		pmic_set_reg(i);
+		ret = pmic_reg_read(p, &val);
+		if (ret)
+			puts("PMIC: Registers dump failed\n");
+
+		if (!(i % 8))
+			printf ("\n0x%02x: ", i);
+
+		printf("%08x ", val);
+	}
+	puts("\n");
+}
+
+
+int pmic_init(void)
+{
+	return board_pmic_init(&pmic);
+}
+
+struct pmic* get_pmic(void) {
+	return &pmic;
+}
+
+int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	u32 ret, reg, val;
+	char *cmd;
+
+	struct pmic *p = &pmic;
+
+	/* at least two arguments please */
+	if (argc < 2)
+		return cmd_usage(cmdtp);
+
+	cmd = argv[1];
+	if (strcmp(cmd, "dump") == 0) {
+		pmic_dump(p);
+		return 0;
+	}
+
+	if (strcmp(cmd, "read") == 0) {
+		if (argc < 3)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+
+		pmic_set_reg(reg);
+		ret = pmic_reg_read(p, &val);
+
+		if (ret)
+			puts("PMIC: Register read failed\n");
+
+		printf("\n0x%02x: 0x%08x \n", reg, val);
+
+		return 0;
+	}
+
+	if (strcmp(cmd, "write") == 0) {
+		if (argc < 4)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+		val = simple_strtoul(argv[3], NULL, 16);
+
+		pmic_set_reg(reg);
+		pmic_reg_write(p, &val);
+
+		return 0;
+	}
+
+	/* No subcommand found */
+	return 1;
+}
+
+U_BOOT_CMD(
+	pmic,	CONFIG_SYS_MAXARGS, 1, do_pmic,
+	"PMIC",
+	"dump - dump PMIC registers\n"
+	"pmic read <reg>  - read register"
+	"pmic write <reg> <value> - write register"
+);
diff --git a/include/pmic.h b/include/pmic.h
new file mode 100644
index 0000000..a048ec7
--- /dev/null
+++ b/include/pmic.h
@@ -0,0 +1,60 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __CORE_PMIC_H_
+#define __CORE_PMIC_H_
+
+enum { PMIC_I2C, PMIC_SPI, };
+enum { I2C_PMIC, I2C_NUM, };
+enum { PMIC_READ, PMIC_WRITE, };
+
+struct p_i2c {
+	unsigned char addr;
+	unsigned char reg;
+	unsigned char *buf;
+	unsigned char tx_num;
+	unsigned char bus_num;
+};
+
+struct p_spi {
+	unsigned int  flags;
+};
+
+struct pmic {
+	char *name;
+	unsigned char interface;
+	unsigned char number_of_regs;
+	union hw {
+		struct p_i2c i2c;
+		struct p_spi spi;
+	} hw;
+};
+
+int pmic_init(void);
+struct pmic *get_pmic(void);
+int pmic_probe(struct pmic *p);
+int pmic_read_reg(struct pmic *p, u32 *val);
+int pmic_write_reg(struct pmic *p, u32 *val);
+int pmic_set_output(struct pmic *p, int ldo, int on);
+
+#endif /* __CORE_PMIC_H_ */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [RFC 2/2] misc:pmic:max8998: Support for max8998 pmic
  2011-09-19 15:06 ` [U-Boot] [RFC 0/2] Generic " Lukasz Majewski
  2011-09-19 15:06   ` [U-Boot] [RFC 1/2] misc:pmic New generic pmic driver Lukasz Majewski
@ 2011-09-19 15:06   ` Lukasz Majewski
  2011-09-20  8:23   ` [U-Boot] [RFC 0/2] Generic PMIC driver Stefano Babic
  2 siblings, 0 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-19 15:06 UTC (permalink / raw)
  To: u-boot

This commit enables the max8998 PMIC to run with pmic_core.c generic
driver.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
---
 board/samsung/goni/goni.c  |   18 +++++++++
 include/configs/s5p_goni.h |    3 ++
 include/max8998_pmic.h     |   84 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 include/max8998_pmic.h

diff --git a/board/samsung/goni/goni.c b/board/samsung/goni/goni.c
index e24cd29..3e0cb74 100644
--- a/board/samsung/goni/goni.c
+++ b/board/samsung/goni/goni.c
@@ -25,6 +25,8 @@
 #include <common.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
+#include <pmic.h>
+#include <max8998_pmic.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -59,6 +61,22 @@ void dram_init_banksize(void)
 	gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
 }
 
+int board_pmic_init(struct pmic *p)
+{
+	static char name[] = "MAX8998_PMIC";
+
+	puts("Board PMIC init\n");
+
+	p->name = name;
+	p->interface = PMIC_I2C;
+	p->number_of_regs = PMIC_NUM_OF_REGS;
+	p->hw.i2c.addr = MAX8998_I2C_ADDR;
+	p->hw.i2c.tx_num = 1;
+	p->hw.i2c.bus_num = I2C_PMIC;
+
+	return 0;
+}
+
 #ifdef CONFIG_DISPLAY_BOARDINFO
 int checkboard(void)
 {
diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
index 886c8be..e26dcb2 100644
--- a/include/configs/s5p_goni.h
+++ b/include/configs/s5p_goni.h
@@ -223,6 +223,9 @@
 
 #define CONFIG_SYS_INIT_SP_ADDR	(CONFIG_SYS_LOAD_ADDR - 0x1000000)
 
+#define CONFIG_PMIC
+#define CONFIG_PMIC_I2C
+
 #include <asm/arch/gpio.h>
 /*
  * I2C Settings
diff --git a/include/max8998_pmic.h b/include/max8998_pmic.h
new file mode 100644
index 0000000..bf28820
--- /dev/null
+++ b/include/max8998_pmic.h
@@ -0,0 +1,84 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __MAX8998_PMIC_H_
+#define __MAX8998_PMIC_H_
+
+/* MAX 8998 registers */
+enum {
+	MAX8998_REG_IRQ1,
+	MAX8998_REG_IRQ2,
+	MAX8998_REG_IRQ3,
+	MAX8998_REG_IRQ4,
+	MAX8998_REG_IRQM1,
+	MAX8998_REG_IRQM2,
+	MAX8998_REG_IRQM3,
+	MAX8998_REG_IRQM4,
+	MAX8998_REG_STATUS1,
+	MAX8998_REG_STATUS2,
+	MAX8998_REG_STATUSM1,
+	MAX8998_REG_STATUSM2,
+	MAX8998_REG_CHGR1,
+	MAX8998_REG_CHGR2,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE1,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE2,
+	MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
+	MAX8998_REG_ONOFF1,
+	MAX8998_REG_ONOFF2,
+	MAX8998_REG_ONOFF3,
+	MAX8998_REG_ONOFF4,
+	MAX8998_REG_BUCK1_VOLTAGE1,
+	MAX8998_REG_BUCK1_VOLTAGE2,
+	MAX8998_REG_BUCK1_VOLTAGE3,
+	MAX8998_REG_BUCK1_VOLTAGE4,
+	MAX8998_REG_BUCK2_VOLTAGE1,
+	MAX8998_REG_BUCK2_VOLTAGE2,
+	MAX8998_REG_BUCK3,
+	MAX8998_REG_BUCK4,
+	MAX8998_REG_LDO2_LDO3,
+	MAX8998_REG_LDO4,
+	MAX8998_REG_LDO5,
+	MAX8998_REG_LDO6,
+	MAX8998_REG_LDO7,
+	MAX8998_REG_LDO8_LDO9,
+	MAX8998_REG_LDO10_LDO11,
+	MAX8998_REG_LDO12,
+	MAX8998_REG_LDO13,
+	MAX8998_REG_LDO14,
+	MAX8998_REG_LDO15,
+	MAX8998_REG_LDO16,
+	MAX8998_REG_LDO17,
+	MAX8998_REG_BKCHR,
+	MAX8998_REG_LBCNFG1,
+	MAX8998_REG_LBCNFG2,
+	PMIC_NUM_OF_REGS,
+};
+
+#define MAX8998_LDO3		(1 << 2)
+#define MAX8998_LDO8		(1 << 5)
+
+#define MAX8998_I2C_ADDR        (0xCC >> 1)
+
+enum { LDO_OFF, LDO_ON };
+
+#endif /* __MAX8998_PMIC_H_ */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [RFC 0/2] Generic PMIC driver
  2011-09-19 15:06 ` [U-Boot] [RFC 0/2] Generic " Lukasz Majewski
  2011-09-19 15:06   ` [U-Boot] [RFC 1/2] misc:pmic New generic pmic driver Lukasz Majewski
  2011-09-19 15:06   ` [U-Boot] [RFC 2/2] misc:pmic:max8998: Support for max8998 pmic Lukasz Majewski
@ 2011-09-20  8:23   ` Stefano Babic
  2011-09-20 12:38     ` Lukasz Majewski
  2 siblings, 1 reply; 40+ messages in thread
From: Stefano Babic @ 2011-09-20  8:23 UTC (permalink / raw)
  To: u-boot

On 09/19/2011 05:06 PM, Lukasz Majewski wrote:
> Dear all,

Hi Lukasz,

> 
> I'd like to propose a new approach for PMIC generic driver.

Fine !

> 
> In my opinion following issues needs discussion:
> 1. In proposed 
> int pmic_reg_read(struct pmic *p, u32 *val) the val is returned by pointer.

And the register to be read/write is embedded in the structure. For
readness I will let it as separate parameter, but this is my personal taste.

Who is responsible to allocate the pmic structure ? It could be (there
is no use case at the moment) that the pmic can be programmed before the
relocation, when malloc() is not available.

This is the main reason because everything is decided at compile time
with CONFIG_ macros. However, we can also decide if it is *really*
required that PMIC can be accessed before relocation.

> Now at fsl_pmic.c read value is returned by return clause.

Yes, we can change - of course, we need to update in one-shot also the
boards already using a pmic.

>  
> I think, that passing pointer is a better approach,since errors from i2c_read/spi_read can be
> caught in upper layers.

Using a pointer is the common way to implement a read routine, so I
cannot argue. The side effect is that the calling code will be filled
with the same and boring check:

	ret = pmic_read_reg(....);
	if (ret) {
		<...error handling, most case only print>
	}
	ret = pmic_read_reg(....);
	if (ret) {
		<...error handling, most case only print>
	}


> 
> 2. Since I haven't got a chance to test SPI part of the fsl_pmic.c driver, I've focused
> mainly on I2C and place stubs for SPI.

Ok, right - this is a RFC. I will do no not review the details in your
sample code, we are discussing the interface ;-).

For the "real" patch, I think we should merge this new code with
fsl_pmic.c, too.

> 
> 3. Suggestions for struct pmic's additional fields for SPI are more than welcome :-) 

We should have the parameters to setup a SPUI connection:
	- SPI chipselect
	- SPI frequency
	- SPI mode
	- SPI bus


> 
> 4. Now the pmic_core.c file consist of
>    #ifdef PMIC_I2C
>    {Code for handling I2C}
>    #else
>    {Code for handling SPI}
>    #endif
> 
> The same approach is used at fsl_pmic.c   
> 
> I'm wondering if this approach shouldn't be replaced with on-time checking if
> SPI or I2C interface is available.
> This check can be performed by:
> 
> struct pmic *p;
> if (p->interface == PMIC_I2C) {
> 
> } else {
> 
> }
> 
> It would allow to remove obscure #ifdefs, but on the other hand it will reduce 
> execution speed of the driver.

Well, I do not worry about time execution. The time to execute the if
branch is maybe negligible compared to the time to make a I2C/SPI transfer.

However, we increase the footprint, and surely only one mechanism is
required on the same board.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [RFC 0/2] Generic PMIC driver
  2011-09-20  8:23   ` [U-Boot] [RFC 0/2] Generic PMIC driver Stefano Babic
@ 2011-09-20 12:38     ` Lukasz Majewski
  2011-09-20 14:08       ` Stefano Babic
  0 siblings, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-20 12:38 UTC (permalink / raw)
  To: u-boot

Hi Stefano,

Thanks for the reply.

> > 
> > In my opinion following issues needs discussion:
> > 1. In proposed 
> > int struct pmic *p, u32 *val) the val is returned by
> > pointer.
> 
> And the register to be read/write is embedded in the structure. For
> readness I will let it as separate parameter, but this is my personal
> taste.
For the first version of the pmic_core.c driver we might stick to this
proposition.


> Who is responsible to allocate the pmic structure ? It could be (there
> is no use case at the moment) that the pmic can be programmed before
> the relocation, when malloc() is not available.

In my opinion on the beginning we should focus on basic scenarios. 
Therefore the pmic struct is defined static at pmic_core.c as
follows:
static struct pmic pmic;

It is simple and efficient (since it's scope is limited to the
translation unit). We shall NOT use malloc() allocation for the first
version of the driver.

> > Now at fsl_pmic.c read value is returned by return clause.
> 
> Yes, we can change - of course, we need to update in one-shot also the
> boards already using a pmic.

Some work for the iMX target boards (e.g. MX51evk) need to be done to
comply with new framework.

As fair as I looked into the code, only iMX power_init methods need
to be fixed. 

> > I think, that passing pointer is a better approach,since errors
> > from i2c_read/spi_read can be caught in upper layers.
> 
> Using a pointer is the common way to implement a read routine, so I
> cannot argue. The side effect is that the calling code will be filled
> with the same and boring check:
> 
> 	ret = pmic_read_reg(....);
> 	if (ret) {
> 		<...error handling, most case only print>
> 	}
> 	ret = pmic_read_reg(....);
> 	if (ret) {
> 		<...error handling, most case only print>
> 	}
> 
I think, that error checking is always welcome :-).

> > 2. Since I haven't got a chance to test SPI part of the fsl_pmic.c
> > driver, I've focused mainly on I2C and place stubs for SPI.
> 
> Ok, right - this is a RFC. I will do no not review the details in your
> sample code, we are discussing the interface ;-).
> 
> For the "real" patch, I think we should merge this new code with
> fsl_pmic.c, too.
> 
In my opinion we shall reuse fsl_pmic.c code as much as possible 
(especially the SPI code - since I cannot test it). 

> > 
> > 3. Suggestions for struct pmic's additional fields for SPI are more
> > than welcome :-) 
> 
> We should have the parameters to setup a SPUI connection:
> 	- SPI chipselect
> 	- SPI frequency
> 	- SPI mode
> 	- SPI bus
> 

OK.


> > 4. Now the pmic_core.c file consist of
> >    #ifdef PMIC_I2C
> >    {Code for handling I2C}
> >    #else
> >    {Code for handling SPI}
> >    #endif
> > 
> > The same approach is used at fsl_pmic.c   
> > 
> > I'm wondering if this approach shouldn't be replaced with on-time
> > checking if SPI or I2C interface is available.
> > This check can be performed by:
> > 
> > struct pmic *p;
> > if (p->interface == PMIC_I2C) {
> > 
> > } else {
> > 
> > }
> > 
> > It would allow to remove obscure #ifdefs, but on the other hand it
> > will reduce execution speed of the driver.
> 
> Well, I do not worry about time execution. The time to execute the if
> branch is maybe negligible compared to the time to make a I2C/SPI
> transfer.
> 
> However, we increase the footprint, and surely only one mechanism is
> required on the same board.
> 
So I will try to use switch-case construct.

switch (p->interface) {
	case PMIC_I2C:

	case PMIC_SPI:

}


> Best regards,
> Stefano Babic
> 

-- 
Best regards,

Lukasz Majewski

Samsung Poland R&D Center
Platform Group

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [RFC 0/2] Generic PMIC driver
  2011-09-20 12:38     ` Lukasz Majewski
@ 2011-09-20 14:08       ` Stefano Babic
  0 siblings, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-09-20 14:08 UTC (permalink / raw)
  To: u-boot

On 09/20/2011 02:38 PM, Lukasz Majewski wrote:

>> Who is responsible to allocate the pmic structure ? It could be (there
>> is no use case at the moment) that the pmic can be programmed before
>> the relocation, when malloc() is not available.
> 
> In my opinion on the beginning we should focus on basic scenarios. 
> Therefore the pmic struct is defined static at pmic_core.c as
> follows:
> static struct pmic pmic;
> 
> It is simple and efficient (since it's scope is limited to the
> translation unit). We shall NOT use malloc() allocation for the first
> version of the driver.

Agree, we must not use malloc.

> 
>>> Now at fsl_pmic.c read value is returned by return clause.
>>
>> Yes, we can change - of course, we need to update in one-shot also the
>> boards already using a pmic.
> 
> Some work for the iMX target boards (e.g. MX51evk) need to be done to
> comply with new framework.

Yes, of course - but if we improve our code, this is not a drawback ;-)

Do not miss the RTC inside the PMIC (drivers/rtc/mc13783-rtc.c)

> As fair as I looked into the code, only iMX power_init methods need
> to be fixed. 

This depends on the board code. There are 6 boards using the PMIC, plus
the RTC driver. For this reason and to avoid to change all boards, maybe
it is not bad to have a compatibility way.

> 
>>> I think, that passing pointer is a better approach,since errors
>>> from i2c_read/spi_read can be caught in upper layers.
>>
>> Using a pointer is the common way to implement a read routine, so I
>> cannot argue. The side effect is that the calling code will be filled
>> with the same and boring check:
>>
>> 	ret = pmic_read_reg(....);
>> 	if (ret) {
>> 		<...error handling, most case only print>
>> 	}
>> 	ret = pmic_read_reg(....);
>> 	if (ret) {
>> 		<...error handling, most case only print>
>> 	}
>>
> I think, that error checking is always welcome :-).

Nothing against checking. We can also

> 
>>> 2. Since I haven't got a chance to test SPI part of the fsl_pmic.c
>>> driver, I've focused mainly on I2C and place stubs for SPI.
>>
>> Ok, right - this is a RFC. I will do no not review the details in your
>> sample code, we are discussing the interface ;-).
>>
>> For the "real" patch, I think we should merge this new code with
>> fsl_pmic.c, too.
>>
> In my opinion we shall reuse fsl_pmic.c code as much as possible 
> (especially the SPI code - since I cannot test it). 

Agree.

>> Well, I do not worry about time execution. The time to execute the if
>> branch is maybe negligible compared to the time to make a I2C/SPI
>> transfer.
>>
>> However, we increase the footprint, and surely only one mechanism is
>> required on the same board.
>>
> So I will try to use switch-case construct.
> 
> switch (p->interface) {
> 	case PMIC_I2C:
> 
> 	case PMIC_SPI:
> 
> }

There is probably a drawback, that is you must link code you do not need
(for example, a board has no I2C at all, but we call and link i2c_write
or another i2 function. The same if a board has only SPI. But I wait for
your proposal !

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver
  2011-09-01  9:13 [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
                   ` (3 preceding siblings ...)
  2011-09-19 15:06 ` [U-Boot] [RFC 0/2] Generic " Lukasz Majewski
@ 2011-09-26 15:10 ` Lukasz Majewski
  2011-09-26 15:10   ` [U-Boot] [PATCH 1/3] misc:pmic New generic pmic driver Lukasz Majewski
                     ` (4 more replies)
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
  5 siblings, 5 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-26 15:10 UTC (permalink / raw)
  To: u-boot

This patch series adds new generic PMIC framework for u-boot.
It is supposed to handle various types of pmic IC's (both
I2C and SPI).

This patch series has been tested on Samsung's GONI reference target.

Moreover a special patch for mx51evk target board has been prepared.
It is compiling, but I cannot test if the driver works. 
Other iMX targets shall be corrected in a similar way that mx51evk.	

The old fsl_pmic.c driver has been preserved.

Lukasz Majewski (3):
  misc:pmic New generic pmic driver
  misc:pmic: Enable PMIC handling at u-boot startup code
  misc:pmic:mx: Code modification for mx51evk board

 arch/arm/lib/board.c              |    5 +
 board/freescale/mx51evk/mx51evk.c |   68 ++++++++++++------
 drivers/misc/Makefile             |    6 +-
 drivers/misc/pmic_core.c          |  148 +++++++++++++++++++++++++++++++++++++
 drivers/misc/pmic_fsl.c           |   57 ++++++++++++++
 drivers/misc/pmic_i2c.c           |   92 +++++++++++++++++++++++
 drivers/misc/pmic_max8998.c       |   43 +++++++++++
 drivers/misc/pmic_spi.c           |  109 +++++++++++++++++++++++++++
 include/configs/mx51evk.h         |    6 +-
 include/configs/s5p_goni.h        |    4 +
 include/fsl_pmic.h                |    5 +-
 include/max8998_pmic.h            |   84 +++++++++++++++++++++
 include/pmic.h                    |   71 ++++++++++++++++++
 13 files changed, 670 insertions(+), 28 deletions(-)
 create mode 100644 drivers/misc/pmic_core.c
 create mode 100644 drivers/misc/pmic_fsl.c
 create mode 100644 drivers/misc/pmic_i2c.c
 create mode 100644 drivers/misc/pmic_max8998.c
 create mode 100644 drivers/misc/pmic_spi.c
 create mode 100644 include/max8998_pmic.h
 create mode 100644 include/pmic.h

-- 
1.7.2.3

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 1/3] misc:pmic New generic pmic driver
  2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
@ 2011-09-26 15:10   ` Lukasz Majewski
  2011-10-02 16:12     ` stefano babic
  2011-09-26 15:10   ` [U-Boot] [PATCH 2/3] misc:pmic: Enable PMIC handling at u-boot startup code Lukasz Majewski
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-26 15:10 UTC (permalink / raw)
  To: u-boot

This commit adds new PMIC core driver.

PMIC IC devices connected via I2C or SPI can be used.
Separate files: pmic_i2c.c and pmic_spi.c are responsible
for handling transmission specific files for I2C or SPI busses.

pmic_fsl.c and pmic_max8998.c are PMIC specific files. They define
pmic_init() method for early init.

New flags added:
CONFIG_PMIC - enable PMIC general device.
CONFIG_PMIC_I2C/SPI - specify the interface to be used.
CONFIG_PMIC_MAX8998/FSL - add routines specific for PMIC chip.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 drivers/misc/Makefile       |    6 ++-
 drivers/misc/pmic_core.c    |  148 +++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/pmic_fsl.c     |   57 +++++++++++++++++
 drivers/misc/pmic_i2c.c     |   92 +++++++++++++++++++++++++++
 drivers/misc/pmic_max8998.c |   43 +++++++++++++
 drivers/misc/pmic_spi.c     |  109 +++++++++++++++++++++++++++++++
 include/configs/mx51evk.h   |    6 ++-
 include/configs/s5p_goni.h  |    4 +
 include/fsl_pmic.h          |    5 +-
 include/max8998_pmic.h      |   84 ++++++++++++++++++++++++
 include/pmic.h              |   71 +++++++++++++++++++++
 11 files changed, 619 insertions(+), 6 deletions(-)
 create mode 100644 drivers/misc/pmic_core.c
 create mode 100644 drivers/misc/pmic_fsl.c
 create mode 100644 drivers/misc/pmic_i2c.c
 create mode 100644 drivers/misc/pmic_max8998.c
 create mode 100644 drivers/misc/pmic_spi.c
 create mode 100644 include/max8998_pmic.h
 create mode 100644 include/pmic.h

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b152486..b388e5a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -28,13 +28,17 @@ LIB	:= $(obj)libmisc.o
 COBJS-$(CONFIG_ALI152X) += ali512x.o
 COBJS-$(CONFIG_DS4510)  += ds4510.o
 COBJS-$(CONFIG_FSL_LAW) += fsl_law.o
-COBJS-$(CONFIG_FSL_PMIC) += fsl_pmic.o
 COBJS-$(CONFIG_GPIO_LED) += gpio_led.o
 COBJS-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o
 COBJS-$(CONFIG_NS87308) += ns87308.o
 COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
 COBJS-$(CONFIG_STATUS_LED) += status_led.o
 COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o
+COBJS-$(CONFIG_PMIC) += pmic_core.o
+COBJS-$(CONFIG_PMIC_I2C) += pmic_i2c.o
+COBJS-$(CONFIG_PMIC_SPI) += pmic_spi.o
+COBJS-$(CONFIG_PMIC_FSL) += pmic_fsl.o
+COBJS-$(CONFIG_PMIC_MAX8998) += pmic_max8998.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/misc/pmic_core.c b/drivers/misc/pmic_core.c
new file mode 100644
index 0000000..d91cd89
--- /dev/null
+++ b/drivers/misc/pmic_core.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+
+static struct pmic pmic;
+
+int check_reg(u32 reg)
+{
+	if (reg >= pmic.number_of_regs) {
+		printf("<reg num> = %d is invalid. Should be less than %d\n",
+		       reg, pmic.number_of_regs);
+		return -1;
+	}
+	return 0;
+}
+
+int pmic_set_output(struct pmic *p, u32 reg, int out, int on)
+{
+	u32 val;
+
+	if (pmic_reg_read(p, reg, &val))
+		return -1;
+
+	if (on)
+		val |= out;
+	else
+		val &= ~out;
+
+	if (pmic_reg_write(p, reg, &val))
+		return -1;
+
+	return 0;
+}
+
+static void pmic_show_info(struct pmic *p)
+{
+	printf("PMIC: %s\n", p->name);
+}
+
+static void pmic_dump(struct pmic *p)
+{
+	int i, ret;
+	u32 val;
+
+	pmic_show_info(p);
+	for (i = 0; i < p->number_of_regs; i++) {
+		ret = pmic_reg_read(p, i, &val);
+		if (ret)
+			puts("PMIC: Registers dump failed\n");
+
+		if (!(i % 8))
+			printf("\n0x%02x: ", i);
+
+		printf("%08x ", val);
+	}
+	puts("\n");
+}
+
+
+struct pmic *get_pmic(void)
+{
+	return &pmic;
+}
+
+int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	u32 ret, reg, val;
+	char *cmd;
+
+	struct pmic *p = &pmic;
+
+	/* at least two arguments please */
+	if (argc < 2)
+		return cmd_usage(cmdtp);
+
+	cmd = argv[1];
+	if (strcmp(cmd, "dump") == 0) {
+		pmic_dump(p);
+		return 0;
+	}
+
+	if (strcmp(cmd, "read") == 0) {
+		if (argc < 3)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+
+		ret = pmic_reg_read(p, reg, &val);
+
+		if (ret)
+			puts("PMIC: Register read failed\n");
+
+		printf("\n0x%02x: 0x%08x\n", reg, val);
+
+		return 0;
+	}
+
+	if (strcmp(cmd, "write") == 0) {
+		if (argc < 4)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+		val = simple_strtoul(argv[3], NULL, 16);
+
+		pmic_reg_write(p, reg, &val);
+
+		return 0;
+	}
+
+	/* No subcommand found */
+	return 1;
+}
+
+U_BOOT_CMD(
+	pmic,	CONFIG_SYS_MAXARGS, 1, do_pmic,
+	"PMIC",
+	"dump - dump PMIC registers\n"
+	"pmic read <reg> - read register\n"
+	"pmic write <reg> <value> - write register"
+);
diff --git a/drivers/misc/pmic_fsl.c b/drivers/misc/pmic_fsl.c
new file mode 100644
index 0000000..13dde47
--- /dev/null
+++ b/drivers/misc/pmic_fsl.c
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <spi.h>
+#include <pmic.h>
+#include <fsl_pmic.h>
+
+static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
+{
+	if ((val == NULL) && (write))
+		return *val & ~(1 << 31);
+	else
+		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
+}
+
+int pmic_init(void)
+{
+	struct pmic *p = get_pmic();
+	static const char name[] = "FSL_PMIC";
+
+	puts("Board PMIC init\n");
+
+	p->name = name;
+	p->interface = PMIC_SPI;
+	p->number_of_regs = PMIC_NUM_OF_REGS;
+	p->bus = CONFIG_FSL_PMIC_BUS;
+
+	p->hw.spi.cs = CONFIG_FSL_PMIC_CS;
+	p->hw.spi.clk = CONFIG_FSL_PMIC_CLK;
+	p->hw.spi.mode = CONFIG_FSL_PMIC_MODE;
+	p->hw.spi.bitlen = CONFIG_FSL_PMIC_BITLEN;
+	p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END;
+	p->hw.spi.prepare_tx = pmic_spi_prepare_tx;
+
+	return 0;
+}
diff --git a/drivers/misc/pmic_i2c.c b/drivers/misc/pmic_i2c.c
new file mode 100644
index 0000000..fbc4b07
--- /dev/null
+++ b/drivers/misc/pmic_i2c.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+#include <i2c.h>
+
+int pmic_reg_write(struct pmic *p, u32 reg, u32 *val)
+{
+	unsigned char buf[4] = { 0 };
+
+	if (check_reg(reg))
+		return -1;
+
+	switch (pmic_i2c_tx_num) {
+	case 3:
+		buf[0] = (*val >> 16) & 0xff;
+		buf[1] = (*val >> 8) & 0xff;
+		buf[2] = (*val) & 0xff;
+		break;
+	case 1:
+		buf[0] = (*val) & 0xff;
+		break;
+	}
+
+	if (i2c_write(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
+		return -1;
+
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
+{
+	unsigned char buf[4] = { 0 };
+	u32 ret_val = 0;
+
+	if (check_reg(reg))
+		return -1;
+
+	if (i2c_read(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
+		return -1;
+
+	switch (pmic_i2c_tx_num) {
+	case 3:
+		ret_val = buf[0] << 16 | buf[1] << 8 | buf[2];
+		break;
+	case 1:
+		ret_val = buf[0];
+		break;
+	}
+	memcpy(val, &ret_val, sizeof(ret_val));
+
+	return 0;
+}
+
+int pmic_probe(struct pmic *p)
+{
+	i2c_set_bus_num(p->bus);
+	printf("PMIC:%s probed!\n", p->name);
+	if (i2c_probe(pmic_i2c_addr)) {
+		puts("Can't find max8998\n");
+		return -1;
+	}
+
+	return 0;
+}
diff --git a/drivers/misc/pmic_max8998.c b/drivers/misc/pmic_max8998.c
new file mode 100644
index 0000000..cc69fd7
--- /dev/null
+++ b/drivers/misc/pmic_max8998.c
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <pmic.h>
+#include <max8998_pmic.h>
+
+int pmic_init(void)
+{
+	struct pmic *p = get_pmic();
+	static const char name[] = "MAX8998_PMIC";
+
+	puts("Board PMIC init\n");
+
+	p->name = name;
+	p->interface = PMIC_I2C;
+	p->number_of_regs = PMIC_NUM_OF_REGS;
+	p->hw.i2c.addr = MAX8998_I2C_ADDR;
+	p->hw.i2c.tx_num = 1;
+	p->bus = I2C_PMIC;
+
+	return 0;
+}
diff --git a/drivers/misc/pmic_spi.c b/drivers/misc/pmic_spi.c
new file mode 100644
index 0000000..ddc75fb
--- /dev/null
+++ b/drivers/misc/pmic_spi.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+#include <spi.h>
+
+static struct spi_slave *slave;
+
+void pmic_spi_free(struct spi_slave *slave)
+{
+	if (slave)
+		spi_free_slave(slave);
+}
+
+struct spi_slave *pmic_spi_probe(struct pmic *p)
+{
+	return spi_setup_slave(p->bus,
+		p->hw.spi.cs,
+		p->hw.spi.clk,
+		p->hw.spi.mode);
+}
+
+static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
+{
+	u32 pmic_tx, pmic_rx;
+	u32 tmp;
+
+	if (!slave) {
+		slave = pmic_spi_probe(p);
+
+		if (!slave)
+			return -1;
+	}
+
+	if (check_reg(reg))
+		return -1;
+
+	if (spi_claim_bus(slave))
+		return -1;
+
+	pmic_tx = p->hw.spi.prepare_tx(reg, val, write);
+
+	tmp = cpu_to_be32(pmic_tx);
+
+	if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
+			pmic_spi_flags)) {
+		spi_release_bus(slave);
+		return -1;
+	}
+
+	if (write) {
+		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
+		pmic_tx &= ~(1 << 31);
+		tmp = cpu_to_be32(pmic_tx);
+		if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
+			pmic_spi_flags)) {
+			spi_release_bus(slave);
+			return -1;
+		}
+	}
+
+	spi_release_bus(slave);
+	*val = cpu_to_be32(pmic_rx);
+
+	return 0;
+}
+
+int pmic_reg_write(struct pmic *p, u32 reg, u32 *val)
+{
+	if (pmic_reg(p, reg, val, 1))
+		return -1;
+
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
+{
+	if (pmic_reg(p, reg, val, 0))
+		return -1;
+
+	return 0;
+}
diff --git a/include/configs/mx51evk.h b/include/configs/mx51evk.h
index 7d05dc8..bbc54f0 100644
--- a/include/configs/mx51evk.h
+++ b/include/configs/mx51evk.h
@@ -69,11 +69,15 @@
 
 #define CONFIG_MXC_SPI
 
-#define CONFIG_FSL_PMIC
+#define CONFIG_PMIC
+#define CONFIG_PMIC_SPI
+#define CONFIG_PMIC_FSL
+
 #define CONFIG_FSL_PMIC_BUS	0
 #define CONFIG_FSL_PMIC_CS	0
 #define CONFIG_FSL_PMIC_CLK	2500000
 #define CONFIG_FSL_PMIC_MODE	(SPI_MODE_0 | SPI_CS_HIGH)
+#define CONFIG_FSL_PMIC_BITLEN	32
 
 /*
  * MMC Configs
diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
index 886c8be..aa51114 100644
--- a/include/configs/s5p_goni.h
+++ b/include/configs/s5p_goni.h
@@ -223,6 +223,10 @@
 
 #define CONFIG_SYS_INIT_SP_ADDR	(CONFIG_SYS_LOAD_ADDR - 0x1000000)
 
+#define CONFIG_PMIC
+#define CONFIG_PMIC_I2C
+#define CONFIG_PMIC_MAX8998
+
 #include <asm/arch/gpio.h>
 /*
  * I2C Settings
diff --git a/include/fsl_pmic.h b/include/fsl_pmic.h
index e3abde6..742f2e1 100644
--- a/include/fsl_pmic.h
+++ b/include/fsl_pmic.h
@@ -99,6 +99,7 @@ enum {
 	REG_TEST2,
 	REG_TEST3,
 	REG_TEST4,
+	PMIC_NUM_OF_REGS,
 };
 
 /* REG_POWER_MISC */
@@ -121,8 +122,4 @@ enum {
 /* Interrupt status 1 */
 #define RTCRSTI		(1 << 7)
 
-void pmic_show_pmic_info(void);
-void pmic_reg_write(u32 reg, u32 value);
-u32 pmic_reg_read(u32 reg);
-
 #endif
diff --git a/include/max8998_pmic.h b/include/max8998_pmic.h
new file mode 100644
index 0000000..bf28820
--- /dev/null
+++ b/include/max8998_pmic.h
@@ -0,0 +1,84 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __MAX8998_PMIC_H_
+#define __MAX8998_PMIC_H_
+
+/* MAX 8998 registers */
+enum {
+	MAX8998_REG_IRQ1,
+	MAX8998_REG_IRQ2,
+	MAX8998_REG_IRQ3,
+	MAX8998_REG_IRQ4,
+	MAX8998_REG_IRQM1,
+	MAX8998_REG_IRQM2,
+	MAX8998_REG_IRQM3,
+	MAX8998_REG_IRQM4,
+	MAX8998_REG_STATUS1,
+	MAX8998_REG_STATUS2,
+	MAX8998_REG_STATUSM1,
+	MAX8998_REG_STATUSM2,
+	MAX8998_REG_CHGR1,
+	MAX8998_REG_CHGR2,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE1,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE2,
+	MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
+	MAX8998_REG_ONOFF1,
+	MAX8998_REG_ONOFF2,
+	MAX8998_REG_ONOFF3,
+	MAX8998_REG_ONOFF4,
+	MAX8998_REG_BUCK1_VOLTAGE1,
+	MAX8998_REG_BUCK1_VOLTAGE2,
+	MAX8998_REG_BUCK1_VOLTAGE3,
+	MAX8998_REG_BUCK1_VOLTAGE4,
+	MAX8998_REG_BUCK2_VOLTAGE1,
+	MAX8998_REG_BUCK2_VOLTAGE2,
+	MAX8998_REG_BUCK3,
+	MAX8998_REG_BUCK4,
+	MAX8998_REG_LDO2_LDO3,
+	MAX8998_REG_LDO4,
+	MAX8998_REG_LDO5,
+	MAX8998_REG_LDO6,
+	MAX8998_REG_LDO7,
+	MAX8998_REG_LDO8_LDO9,
+	MAX8998_REG_LDO10_LDO11,
+	MAX8998_REG_LDO12,
+	MAX8998_REG_LDO13,
+	MAX8998_REG_LDO14,
+	MAX8998_REG_LDO15,
+	MAX8998_REG_LDO16,
+	MAX8998_REG_LDO17,
+	MAX8998_REG_BKCHR,
+	MAX8998_REG_LBCNFG1,
+	MAX8998_REG_LBCNFG2,
+	PMIC_NUM_OF_REGS,
+};
+
+#define MAX8998_LDO3		(1 << 2)
+#define MAX8998_LDO8		(1 << 5)
+
+#define MAX8998_I2C_ADDR        (0xCC >> 1)
+
+enum { LDO_OFF, LDO_ON };
+
+#endif /* __MAX8998_PMIC_H_ */
diff --git a/include/pmic.h b/include/pmic.h
new file mode 100644
index 0000000..73ccf1a
--- /dev/null
+++ b/include/pmic.h
@@ -0,0 +1,71 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __CORE_PMIC_H_
+#define __CORE_PMIC_H_
+
+enum { PMIC_I2C, PMIC_SPI, };
+enum { I2C_PMIC, I2C_NUM, };
+enum { PMIC_READ, PMIC_WRITE, };
+
+struct p_i2c {
+	unsigned char addr;
+	unsigned char *buf;
+	unsigned char tx_num;
+};
+
+struct p_spi {
+	unsigned char cs;
+	unsigned char mode;
+	unsigned char bitlen;
+	unsigned int  clk;
+	unsigned int  flags;
+	u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
+};
+
+struct pmic {
+	char *name;
+	unsigned char bus;
+	unsigned char interface;
+	unsigned char number_of_regs;
+	union hw {
+		struct p_i2c i2c;
+		struct p_spi spi;
+	} hw;
+};
+
+int pmic_init(void);
+int check_reg(u32 reg);
+struct pmic *get_pmic(void);
+int pmic_probe(struct pmic *p);
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
+int pmic_reg_write(struct pmic *p, u32 reg, u32 *val);
+int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
+
+#define pmic_i2c_addr (p->hw.i2c.addr)
+#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
+
+#define pmic_spi_bitlen (p->hw.spi.bitlen)
+#define pmic_spi_flags (p->hw.spi.flags)
+
+#endif /* __CORE_PMIC_H_ */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 2/3] misc:pmic: Enable PMIC handling at u-boot startup code
  2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
  2011-09-26 15:10   ` [U-Boot] [PATCH 1/3] misc:pmic New generic pmic driver Lukasz Majewski
@ 2011-09-26 15:10   ` Lukasz Majewski
  2011-10-02 16:14     ` stefano babic
  2011-09-26 15:10   ` [U-Boot] [PATCH 3/3] misc:pmic:mx: Code modification for mx51evk board Lukasz Majewski
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-26 15:10 UTC (permalink / raw)
  To: u-boot

The pmic_init() initialization handler has been added to
board_init_r function.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 arch/arm/lib/board.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 85320bc..ea9e3d6 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -48,6 +48,7 @@
 #include <nand.h>
 #include <onenand_uboot.h>
 #include <mmc.h>
+#include <pmic.h>
 
 #ifdef CONFIG_BITBANGMII
 #include <miiphy.h>
@@ -578,6 +579,10 @@ void board_init_r(gd_t *id, ulong dest_addr)
 		copy_filename(BootFile, s, sizeof(BootFile));
 #endif
 
+#if defined(CONFIG_PMIC)
+	pmic_init();
+#endif
+
 #ifdef BOARD_LATE_INIT
 	board_late_init();
 #endif
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 3/3] misc:pmic:mx: Code modification for mx51evk board
  2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
  2011-09-26 15:10   ` [U-Boot] [PATCH 1/3] misc:pmic New generic pmic driver Lukasz Majewski
  2011-09-26 15:10   ` [U-Boot] [PATCH 2/3] misc:pmic: Enable PMIC handling at u-boot startup code Lukasz Majewski
@ 2011-09-26 15:10   ` Lukasz Majewski
  2011-10-02 16:15     ` stefano babic
  2011-09-28 11:28   ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Stefano Babic
  2011-10-02 15:58   ` stefano babic
  4 siblings, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-26 15:10 UTC (permalink / raw)
  To: u-boot

This is an example code for adjusting the mx51evk example board to
new pmic_core driver.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 board/freescale/mx51evk/mx51evk.c |   68 +++++++++++++++++++++++++------------
 1 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/board/freescale/mx51evk/mx51evk.c b/board/freescale/mx51evk/mx51evk.c
index 94ea1f2..46562f0 100644
--- a/board/freescale/mx51evk/mx51evk.c
+++ b/board/freescale/mx51evk/mx51evk.c
@@ -34,6 +34,7 @@
 #include <fsl_esdhc.h>
 #include <fsl_pmic.h>
 #include <mc13892.h>
+#include <pmic.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -181,72 +182,94 @@ static void setup_iomux_spi(void)
 static void power_init(void)
 {
 	unsigned int val;
+	struct pmic *p = get_pmic();
 	struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
 
 	/* Write needed to Power Gate 2 register */
-	val = pmic_reg_read(REG_POWER_MISC);
+	if (pmic_reg_read(p, REG_POWER_MISC, &val))
+		puts("PMIC write error!\n");
 	val &= ~PWGT2SPIEN;
-	pmic_reg_write(REG_POWER_MISC, val);
+	if (pmic_reg_write(p, REG_POWER_MISC, &val))
+		puts("PMIC write error!\n");
 
 	/* Externally powered */
-	val = pmic_reg_read(REG_CHARGE);
+	if (pmic_reg_read(p, REG_CHARGE, &val))
+		puts("PMIC write error!\n");
 	val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
-	pmic_reg_write(REG_CHARGE, val);
+	if (pmic_reg_write(p, REG_CHARGE, &val))
+		puts("PMIC write error!\n");
 
 	/* power up the system first */
-	pmic_reg_write(REG_POWER_MISC, PWUP);
+	val = PWUP;
+	if (pmic_reg_write(p, REG_POWER_MISC, &val))
+		puts("PMIC write error!\n");
 
 	/* Set core voltage to 1.1V */
-	val = pmic_reg_read(REG_SW_0);
+	if (pmic_reg_read(p, REG_SW_0, &val))
+		puts("PMIC write error!\n");
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
-	pmic_reg_write(REG_SW_0, val);
+	if (pmic_reg_write(p, REG_SW_0, &val))
+		puts("PMIC write error!\n");
 
 	/* Setup VCC (SW2) to 1.25 */
-	val = pmic_reg_read(REG_SW_1);
+	if (pmic_reg_read(p, REG_SW_1, &val))
+		puts("PMIC write error!\n");
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
-	pmic_reg_write(REG_SW_1, val);
+	if (pmic_reg_write(p, REG_SW_1, &val))
+		puts("PMIC write error!\n");
 
 	/* Setup 1V2_DIG1 (SW3) to 1.25 */
-	val = pmic_reg_read(REG_SW_2);
+	if (pmic_reg_read(p, REG_SW_2, &val))
+		puts("PMIC write error!\n");
 	val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
-	pmic_reg_write(REG_SW_2, val);
-	udelay(50);
+	if (pmic_reg_write(p, REG_SW_2, &val))
+		puts("PMIC write error!\n");
 
 	/* Raise the core frequency to 800MHz */
 	writel(0x0, &mxc_ccm->cacrr);
 
 	/* Set switchers in Auto in NORMAL mode & STANDBY mode */
 	/* Setup the switcher mode for SW1 & SW2*/
-	val = pmic_reg_read(REG_SW_4);
+	if (pmic_reg_read(p, REG_SW_4, &val))
+		puts("PMIC write error!\n");
 	val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
 		(SWMODE_MASK << SWMODE2_SHIFT)));
 	val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
-	pmic_reg_write(REG_SW_4, val);
+	if (pmic_reg_write(p, REG_SW_4, &val))
+		puts("PMIC write error!\n");
 
 	/* Setup the switcher mode for SW3 & SW4 */
-	val = pmic_reg_read(REG_SW_5);
+	if (pmic_reg_read(p, REG_SW_5, &val))
+		puts("PMIC write error!\n");
 	val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
 		(SWMODE_MASK << SWMODE4_SHIFT)));
 	val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
 		(SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
-	pmic_reg_write(REG_SW_5, val);
+	if (pmic_reg_write(p, REG_SW_5, &val))
+		puts("PMIC write error!\n");
 
 	/* Set VDIG to 1.65V, VGEN3 to 1.8V, VCAM to 2.6V */
-	val = pmic_reg_read(REG_SETTING_0);
+	if (pmic_reg_read(p, REG_SETTING_0, &val))
+		puts("PMIC write error!\n");
 	val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
 	val |= VDIG_1_65 | VGEN3_1_8 | VCAM_2_6;
-	pmic_reg_write(REG_SETTING_0, val);
+	if (pmic_reg_write(p, REG_SETTING_0, &val))
+		puts("PMIC write error!\n");
 
 	/* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
-	val = pmic_reg_read(REG_SETTING_1);
+	if (pmic_reg_read(p, REG_SETTING_1, &val))
+		puts("PMIC write error!\n");
 	val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
 	val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775;
-	pmic_reg_write(REG_SETTING_1, val);
+	if (pmic_reg_write(p, REG_SETTING_1, &val))
+		puts("PMIC write error!\n");
 
 	/* Configure VGEN3 and VCAM regulators to use external PNP */
 	val = VGEN3CONFIG | VCAMCONFIG;
-	pmic_reg_write(REG_MODE_1, val);
+	if (pmic_reg_write(p, REG_MODE_1, &val))
+		puts("PMIC write error!\n");
+
 	udelay(200);
 
 	gpio_direction_output(46, 0);
@@ -257,7 +280,8 @@ static void power_init(void)
 	/* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
 	val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
 		VVIDEOEN | VAUDIOEN  | VSDEN;
-	pmic_reg_write(REG_MODE_1, val);
+	if (pmic_reg_write(p, REG_MODE_1, &val))
+		puts("PMIC write error!\n");
 
 	udelay(500);
 
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver
  2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
                     ` (2 preceding siblings ...)
  2011-09-26 15:10   ` [U-Boot] [PATCH 3/3] misc:pmic:mx: Code modification for mx51evk board Lukasz Majewski
@ 2011-09-28 11:28   ` Stefano Babic
  2011-09-28 11:56     ` Lukasz Majewski
  2011-10-02 15:58   ` stefano babic
  4 siblings, 1 reply; 40+ messages in thread
From: Stefano Babic @ 2011-09-28 11:28 UTC (permalink / raw)
  To: u-boot

On 09/26/2011 05:10 PM, Lukasz Majewski wrote:
> This patch series adds new generic PMIC framework for u-boot.
> It is supposed to handle various types of pmic IC's (both
> I2C and SPI).
> 
> This patch series has been tested on Samsung's GONI reference target.
> 
> Moreover a special patch for mx51evk target board has been prepared.
> It is compiling, but I cannot test if the driver works. 
> Other iMX targets shall be corrected in a similar way that mx51evk.	
> 

Hi Lukasz,

I cannot review now your patches, but I will be able to test the SPI
part. Give me only some days..

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver
  2011-09-28 11:28   ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Stefano Babic
@ 2011-09-28 11:56     ` Lukasz Majewski
  0 siblings, 0 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-09-28 11:56 UTC (permalink / raw)
  To: u-boot


Hi Stefano,

> 
> I cannot review now your patches,
Ok, no problem. I will wait :-)


-- 
Best regards,

Lukasz Majewski

Samsung Poland R&D Center
Platform Group

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver
  2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
                     ` (3 preceding siblings ...)
  2011-09-28 11:28   ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Stefano Babic
@ 2011-10-02 15:58   ` stefano babic
  4 siblings, 0 replies; 40+ messages in thread
From: stefano babic @ 2011-10-02 15:58 UTC (permalink / raw)
  To: u-boot

Am 26/09/2011 17:10, schrieb Lukasz Majewski:
> This patch series adds new generic PMIC framework for u-boot.
> It is supposed to handle various types of pmic IC's (both
> I2C and SPI).
> 

Hi Lukasz,

> This patch series has been tested on Samsung's GONI reference target.
> 
> Moreover a special patch for mx51evk target board has been prepared.
> It is compiling, but I cannot test if the driver works. 

I have tested the SPI part on a different board instead of
MX51EVK(vision2). I think you can forget for your patchset about MX5
boards - they can be switched to the general pmic_core when the fsl_pmic
file will be dropped and after merging your patches. Thanks in any case
to have provided an example ;-)

> Other iMX targets shall be corrected in a similar way that mx51evk.	
> 
> The old fsl_pmic.c driver has been preserved.

Ok - it will be removed after including you patches.

The write function is symmetric to the read function:

int pmic_reg_write(struct pmic *p, u32 reg, u32 *val)

However, we do not want to change the value pointed by val. I think it
is should better to pass a u32 instead of a pointer.

> 
> Lukasz Majewski (3):
>   misc:pmic New generic pmic driver
>   misc:pmic: Enable PMIC handling at u-boot startup code
>   misc:pmic:mx: Code modification for mx51evk board
> 
>  arch/arm/lib/board.c              |    5 +
>  board/freescale/mx51evk/mx51evk.c |   68 ++++++++++++------
>  drivers/misc/Makefile             |    6 +-
>  drivers/misc/pmic_core.c          |  148 +++++++++++++++++++++++++++++++++++++
>  drivers/misc/pmic_fsl.c           |   57 ++++++++++++++
>  drivers/misc/pmic_i2c.c           |   92 +++++++++++++++++++++++
>  drivers/misc/pmic_max8998.c       |   43 +++++++++++
>  drivers/misc/pmic_spi.c           |  109 +++++++++++++++++++++++++++
>  include/configs/mx51evk.h         |    6 +-
>  include/configs/s5p_goni.h        |    4 +
>  include/fsl_pmic.h                |    5 +-
>  include/max8998_pmic.h            |   84 +++++++++++++++++++++
>  include/pmic.h                    |   71 ++++++++++++++++++

Logically I see your patchset split into 3 patches, but differently as
you did:
	- adding pmic core driver
	- adding support for max8998
	- adding pmic to the s5p_goni

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 1/3] misc:pmic New generic pmic driver
  2011-09-26 15:10   ` [U-Boot] [PATCH 1/3] misc:pmic New generic pmic driver Lukasz Majewski
@ 2011-10-02 16:12     ` stefano babic
  0 siblings, 0 replies; 40+ messages in thread
From: stefano babic @ 2011-10-02 16:12 UTC (permalink / raw)
  To: u-boot

Am 26/09/2011 17:10, schrieb Lukasz Majewski:
> This commit adds new PMIC core driver.
> 
> PMIC IC devices connected via I2C or SPI can be used.
> Separate files: pmic_i2c.c and pmic_spi.c are responsible
> for handling transmission specific files for I2C or SPI busses.
> 
> pmic_fsl.c and pmic_max8998.c are PMIC specific files. They define
> pmic_init() method for early init.
> 
> New flags added:
> CONFIG_PMIC - enable PMIC general device.
> CONFIG_PMIC_I2C/SPI - specify the interface to be used.
> CONFIG_PMIC_MAX8998/FSL - add routines specific for PMIC chip.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>

Hi Lukasz,

> +
> +		if (!(i % 8))
> +			printf("\n0x%02x: ", i);
> +
> +		printf("%08x ", val);
> +	}
> +	puts("\n");
> +}
> +
> +

Drop the second newline-


> +int pmic_init(void)
> +{
> +	struct pmic *p = get_pmic();
> +	static const char name[] = "FSL_PMIC";
> +
> +	puts("Board PMIC init\n");

This contains no info - you can drop or replace puts with debug().

> +	p->hw.spi.bitlen = CONFIG_FSL_PMIC_BITLEN;
> +	p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END;
> +	p->hw.spi.prepare_tx = pmic_spi_prepare_tx;
> +
> +	return 0;
> +}

Ok - I do not know if CONFIG_FSL_PMIC_BITLEN is really needed, but we
can leave it.



> +int pmic_probe(struct pmic *p)
> +{
> +	i2c_set_bus_num(p->bus);
> +	printf("PMIC:%s probed!\n", p->name);

Probably this comes from your testing - you can drop it or use debug()

> +	if (i2c_probe(pmic_i2c_addr)) {
> +		puts("Can't find max8998\n");

...and we have not always a max8998 !

> +int pmic_init(void)
> +{
> +	struct pmic *p = get_pmic();
> +	static const char name[] = "MAX8998_PMIC";
> +
> +	puts("Board PMIC init\n");

Replace with debug()

> diff --git a/drivers/misc/pmic_spi.c b/drivers/misc/pmic_spi.c
> diff --git a/include/configs/mx51evk.h b/include/configs/mx51evk.h
> index 7d05dc8..bbc54f0 100644
> --- a/include/configs/mx51evk.h
> +++ b/include/configs/mx51evk.h

You can leave away the MX boards (and we have to change all of them or
none of them - there are also MX3 boards that can use the new code).

>   * MMC Configs
> diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
> index 886c8be..aa51114 100644

Put changes to board configuration in a separate patch.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 2/3] misc:pmic: Enable PMIC handling at u-boot startup code
  2011-09-26 15:10   ` [U-Boot] [PATCH 2/3] misc:pmic: Enable PMIC handling at u-boot startup code Lukasz Majewski
@ 2011-10-02 16:14     ` stefano babic
  0 siblings, 0 replies; 40+ messages in thread
From: stefano babic @ 2011-10-02 16:14 UTC (permalink / raw)
  To: u-boot

Am 26/09/2011 17:10, schrieb Lukasz Majewski:
> The pmic_init() initialization handler has been added to
> board_init_r function.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
>  arch/arm/lib/board.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
> index 85320bc..ea9e3d6 100644
> --- a/arch/arm/lib/board.c
> +++ b/arch/arm/lib/board.c
> @@ -48,6 +48,7 @@
>  #include <nand.h>
>  #include <onenand_uboot.h>
>  #include <mmc.h>
> +#include <pmic.h>
>  
>  #ifdef CONFIG_BITBANGMII
>  #include <miiphy.h>
> @@ -578,6 +579,10 @@ void board_init_r(gd_t *id, ulong dest_addr)
>  		copy_filename(BootFile, s, sizeof(BootFile));
>  #endif
>  
> +#if defined(CONFIG_PMIC)
> +	pmic_init();
> +#endif
> +
>  #ifdef BOARD_LATE_INIT
>  	board_late_init();
>  #endif

I do not think this is correct. Only a few boards have a PMIC, and we
put the initialization in the general code for all ARM. And we cannot
decide *when* the PMIC must be initialized. Maybe a board requires some
other parts (GPIO initialization,...) before accessing the PMIC. It is
better to let the board maintainers to decide when to call this
function. So simply drop this patch, and put the call to pmic_init() in
your s5p_goni code.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH 3/3] misc:pmic:mx: Code modification for mx51evk board
  2011-09-26 15:10   ` [U-Boot] [PATCH 3/3] misc:pmic:mx: Code modification for mx51evk board Lukasz Majewski
@ 2011-10-02 16:15     ` stefano babic
  0 siblings, 0 replies; 40+ messages in thread
From: stefano babic @ 2011-10-02 16:15 UTC (permalink / raw)
  To: u-boot

Am 26/09/2011 17:10, schrieb Lukasz Majewski:
> This is an example code for adjusting the mx51evk example board to
> new pmic_core driver.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>

Thnaks for example. In the next version you do not need to repost this code.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 0/3] misc:pmic: New PMIC generic driver
  2011-09-01  9:13 [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
                   ` (4 preceding siblings ...)
  2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
@ 2011-10-04  5:45 ` Lukasz Majewski
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver Lukasz Majewski
                     ` (5 more replies)
  5 siblings, 6 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-10-04  5:45 UTC (permalink / raw)
  To: u-boot

This patch series adds new generic PMIC framework for u-boot.
It is supposed to handle various types of pmic IC's (both,
equippled with I2C or SPI bus).

This patch series has been tested on Samsung's GONI reference target.
---
	Changes for v2:
	- New logical structure of patch series
	- printf/puts replaced with debug() macro where applicable
	- pmic_reg_write(...,u32 *val) replaced with u32 val
	- pmic_init() moved to board_init() function

Lukasz Majewski (3):
  misc:pmic:core New generic PMIC driver
  misc:pmic:max8998 MAX8998 support at a new PMIC driver.
  misc:pmic:samsung Enable PMIC driver at GONI target

 board/samsung/goni/goni.c   |    4 +
 drivers/misc/Makefile       |    4 +
 drivers/misc/pmic_core.c    |  147 +++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/pmic_i2c.c     |   92 +++++++++++++++++++++++++++
 drivers/misc/pmic_max8998.c |   43 +++++++++++++
 drivers/misc/pmic_spi.c     |  109 ++++++++++++++++++++++++++++++++
 include/configs/s5p_goni.h  |    4 +
 include/max8998_pmic.h      |   84 ++++++++++++++++++++++++
 include/pmic.h              |   71 +++++++++++++++++++++
 9 files changed, 558 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pmic_core.c
 create mode 100644 drivers/misc/pmic_i2c.c
 create mode 100644 drivers/misc/pmic_max8998.c
 create mode 100644 drivers/misc/pmic_spi.c
 create mode 100644 include/max8998_pmic.h
 create mode 100644 include/pmic.h

-- 
1.7.2.3

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
@ 2011-10-04  5:45   ` Lukasz Majewski
  2011-10-05 10:52     ` Stefano Babic
  2011-10-06  9:48     ` Stefano Babic
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new " Lukasz Majewski
                     ` (4 subsequent siblings)
  5 siblings, 2 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-10-04  5:45 UTC (permalink / raw)
  To: u-boot

I2C or SPI PMIC devices can be accessed.
Separate files: pmic_i2c.c and pmic_spi.c are responsible
for handling transmission over I2C or SPI bus.

New flags:
CONFIG_PMIC - enable PMIC general device.
CONFIG_PMIC_I2C/SPI - specify the interface to be used.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
    Changes for v2:
    - pmic_reg_write(..., u32 *val) - u32 *val replaced with u32 val.
    - debug() macros added instead of plain printf()
---
 drivers/misc/Makefile    |    3 +
 drivers/misc/pmic_core.c |  147 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/pmic_i2c.c  |   92 +++++++++++++++++++++++++++++
 drivers/misc/pmic_spi.c  |  109 ++++++++++++++++++++++++++++++++++
 include/pmic.h           |   71 ++++++++++++++++++++++
 5 files changed, 422 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pmic_core.c
 create mode 100644 drivers/misc/pmic_i2c.c
 create mode 100644 drivers/misc/pmic_spi.c
 create mode 100644 include/pmic.h

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b152486..91c5bfa 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -35,6 +35,9 @@ COBJS-$(CONFIG_NS87308) += ns87308.o
 COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
 COBJS-$(CONFIG_STATUS_LED) += status_led.o
 COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o
+COBJS-$(CONFIG_PMIC) += pmic_core.o
+COBJS-$(CONFIG_PMIC_I2C) += pmic_i2c.o
+COBJS-$(CONFIG_PMIC_SPI) += pmic_spi.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/misc/pmic_core.c b/drivers/misc/pmic_core.c
new file mode 100644
index 0000000..5d62a56
--- /dev/null
+++ b/drivers/misc/pmic_core.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+
+static struct pmic pmic;
+
+int check_reg(u32 reg)
+{
+	if (reg >= pmic.number_of_regs) {
+		printf("<reg num> = %d is invalid. Should be less than %d\n",
+		       reg, pmic.number_of_regs);
+		return -1;
+	}
+	return 0;
+}
+
+int pmic_set_output(struct pmic *p, u32 reg, int out, int on)
+{
+	u32 val;
+
+	if (pmic_reg_read(p, reg, &val))
+		return -1;
+
+	if (on)
+		val |= out;
+	else
+		val &= ~out;
+
+	if (pmic_reg_write(p, reg, val))
+		return -1;
+
+	return 0;
+}
+
+static void pmic_show_info(struct pmic *p)
+{
+	printf("PMIC: %s\n", p->name);
+}
+
+static void pmic_dump(struct pmic *p)
+{
+	int i, ret;
+	u32 val;
+
+	pmic_show_info(p);
+	for (i = 0; i < p->number_of_regs; i++) {
+		ret = pmic_reg_read(p, i, &val);
+		if (ret)
+			puts("PMIC: Registers dump failed\n");
+
+		if (!(i % 8))
+			printf("\n0x%02x: ", i);
+
+		printf("%08x ", val);
+	}
+	puts("\n");
+}
+
+struct pmic *get_pmic(void)
+{
+	return &pmic;
+}
+
+int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	u32 ret, reg, val;
+	char *cmd;
+
+	struct pmic *p = &pmic;
+
+	/* at least two arguments please */
+	if (argc < 2)
+		return cmd_usage(cmdtp);
+
+	cmd = argv[1];
+	if (strcmp(cmd, "dump") == 0) {
+		pmic_dump(p);
+		return 0;
+	}
+
+	if (strcmp(cmd, "read") == 0) {
+		if (argc < 3)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+
+		ret = pmic_reg_read(p, reg, &val);
+
+		if (ret)
+			puts("PMIC: Register read failed\n");
+
+		printf("\n0x%02x: 0x%08x\n", reg, val);
+
+		return 0;
+	}
+
+	if (strcmp(cmd, "write") == 0) {
+		if (argc < 4)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+		val = simple_strtoul(argv[3], NULL, 16);
+
+		pmic_reg_write(p, reg, val);
+
+		return 0;
+	}
+
+	/* No subcommand found */
+	return 1;
+}
+
+U_BOOT_CMD(
+	pmic,	CONFIG_SYS_MAXARGS, 1, do_pmic,
+	"PMIC",
+	"dump - dump PMIC registers\n"
+	"pmic read <reg> - read register\n"
+	"pmic write <reg> <value> - write register"
+);
diff --git a/drivers/misc/pmic_i2c.c b/drivers/misc/pmic_i2c.c
new file mode 100644
index 0000000..b82e899
--- /dev/null
+++ b/drivers/misc/pmic_i2c.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+#include <i2c.h>
+
+int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
+{
+	unsigned char buf[4] = { 0 };
+
+	if (check_reg(reg))
+		return -1;
+
+	switch (pmic_i2c_tx_num) {
+	case 3:
+		buf[0] = (val >> 16) & 0xff;
+		buf[1] = (val >> 8) & 0xff;
+		buf[2] = val & 0xff;
+		break;
+	case 1:
+		buf[0] = val & 0xff;
+		break;
+	}
+
+	if (i2c_write(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
+		return -1;
+
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
+{
+	unsigned char buf[4] = { 0 };
+	u32 ret_val = 0;
+
+	if (check_reg(reg))
+		return -1;
+
+	if (i2c_read(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
+		return -1;
+
+	switch (pmic_i2c_tx_num) {
+	case 3:
+		ret_val = buf[0] << 16 | buf[1] << 8 | buf[2];
+		break;
+	case 1:
+		ret_val = buf[0];
+		break;
+	}
+	memcpy(val, &ret_val, sizeof(ret_val));
+
+	return 0;
+}
+
+int pmic_probe(struct pmic *p)
+{
+	i2c_set_bus_num(p->bus);
+	debug("PMIC:%s probed!\n", p->name);
+	if (i2c_probe(pmic_i2c_addr)) {
+		printf("Can't find PMIC:%s\n", p->name);
+		return -1;
+	}
+
+	return 0;
+}
diff --git a/drivers/misc/pmic_spi.c b/drivers/misc/pmic_spi.c
new file mode 100644
index 0000000..ff35377
--- /dev/null
+++ b/drivers/misc/pmic_spi.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+#include <spi.h>
+
+static struct spi_slave *slave;
+
+void pmic_spi_free(struct spi_slave *slave)
+{
+	if (slave)
+		spi_free_slave(slave);
+}
+
+struct spi_slave *pmic_spi_probe(struct pmic *p)
+{
+	return spi_setup_slave(p->bus,
+		p->hw.spi.cs,
+		p->hw.spi.clk,
+		p->hw.spi.mode);
+}
+
+static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
+{
+	u32 pmic_tx, pmic_rx;
+	u32 tmp;
+
+	if (!slave) {
+		slave = pmic_spi_probe(p);
+
+		if (!slave)
+			return -1;
+	}
+
+	if (check_reg(reg))
+		return -1;
+
+	if (spi_claim_bus(slave))
+		return -1;
+
+	pmic_tx = p->hw.spi.prepare_tx(reg, val, write);
+
+	tmp = cpu_to_be32(pmic_tx);
+
+	if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
+			pmic_spi_flags)) {
+		spi_release_bus(slave);
+		return -1;
+	}
+
+	if (write) {
+		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
+		pmic_tx &= ~(1 << 31);
+		tmp = cpu_to_be32(pmic_tx);
+		if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
+			pmic_spi_flags)) {
+			spi_release_bus(slave);
+			return -1;
+		}
+	}
+
+	spi_release_bus(slave);
+	*val = cpu_to_be32(pmic_rx);
+
+	return 0;
+}
+
+int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
+{
+	if (pmic_reg(p, reg, &val, 1))
+		return -1;
+
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
+{
+	if (pmic_reg(p, reg, val, 0))
+		return -1;
+
+	return 0;
+}
diff --git a/include/pmic.h b/include/pmic.h
new file mode 100644
index 0000000..052371a
--- /dev/null
+++ b/include/pmic.h
@@ -0,0 +1,71 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __CORE_PMIC_H_
+#define __CORE_PMIC_H_
+
+enum { PMIC_I2C, PMIC_SPI, };
+enum { I2C_PMIC, I2C_NUM, };
+enum { PMIC_READ, PMIC_WRITE, };
+
+struct p_i2c {
+	unsigned char addr;
+	unsigned char *buf;
+	unsigned char tx_num;
+};
+
+struct p_spi {
+	unsigned char cs;
+	unsigned char mode;
+	unsigned char bitlen;
+	unsigned int  clk;
+	unsigned int  flags;
+	u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
+};
+
+struct pmic {
+	const char *name;
+	unsigned char bus;
+	unsigned char interface;
+	unsigned char number_of_regs;
+	union hw {
+		struct p_i2c i2c;
+		struct p_spi spi;
+	} hw;
+};
+
+int pmic_init(void);
+int check_reg(u32 reg);
+struct pmic *get_pmic(void);
+int pmic_probe(struct pmic *p);
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
+int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
+int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
+
+#define pmic_i2c_addr (p->hw.i2c.addr)
+#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
+
+#define pmic_spi_bitlen (p->hw.spi.bitlen)
+#define pmic_spi_flags (p->hw.spi.flags)
+
+#endif /* __CORE_PMIC_H_ */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new PMIC driver.
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver Lukasz Majewski
@ 2011-10-04  5:45   ` Lukasz Majewski
  2011-10-05 10:53     ` Stefano Babic
  2011-10-12 10:55     ` Stefano Babic
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target Lukasz Majewski
                     ` (3 subsequent siblings)
  5 siblings, 2 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-10-04  5:45 UTC (permalink / raw)
  To: u-boot

This commit adds support for MAX8998 PMIC driver.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
    Changes for v2:
    - separate commit for MAX8998 prepared
---
 drivers/misc/Makefile       |    1 +
 drivers/misc/pmic_max8998.c |   43 ++++++++++++++++++++++
 include/max8998_pmic.h      |   84 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pmic_max8998.c
 create mode 100644 include/max8998_pmic.h

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 91c5bfa..6d82c22 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -38,6 +38,7 @@ COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o
 COBJS-$(CONFIG_PMIC) += pmic_core.o
 COBJS-$(CONFIG_PMIC_I2C) += pmic_i2c.o
 COBJS-$(CONFIG_PMIC_SPI) += pmic_spi.o
+COBJS-$(CONFIG_PMIC_MAX8998) += pmic_max8998.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/misc/pmic_max8998.c b/drivers/misc/pmic_max8998.c
new file mode 100644
index 0000000..cc69fd7
--- /dev/null
+++ b/drivers/misc/pmic_max8998.c
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <pmic.h>
+#include <max8998_pmic.h>
+
+int pmic_init(void)
+{
+	struct pmic *p = get_pmic();
+	static const char name[] = "MAX8998_PMIC";
+
+	puts("Board PMIC init\n");
+
+	p->name = name;
+	p->interface = PMIC_I2C;
+	p->number_of_regs = PMIC_NUM_OF_REGS;
+	p->hw.i2c.addr = MAX8998_I2C_ADDR;
+	p->hw.i2c.tx_num = 1;
+	p->bus = I2C_PMIC;
+
+	return 0;
+}
diff --git a/include/max8998_pmic.h b/include/max8998_pmic.h
new file mode 100644
index 0000000..bf28820
--- /dev/null
+++ b/include/max8998_pmic.h
@@ -0,0 +1,84 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __MAX8998_PMIC_H_
+#define __MAX8998_PMIC_H_
+
+/* MAX 8998 registers */
+enum {
+	MAX8998_REG_IRQ1,
+	MAX8998_REG_IRQ2,
+	MAX8998_REG_IRQ3,
+	MAX8998_REG_IRQ4,
+	MAX8998_REG_IRQM1,
+	MAX8998_REG_IRQM2,
+	MAX8998_REG_IRQM3,
+	MAX8998_REG_IRQM4,
+	MAX8998_REG_STATUS1,
+	MAX8998_REG_STATUS2,
+	MAX8998_REG_STATUSM1,
+	MAX8998_REG_STATUSM2,
+	MAX8998_REG_CHGR1,
+	MAX8998_REG_CHGR2,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE1,
+	MAX8998_REG_LDO_ACTIVE_DISCHARGE2,
+	MAX8998_REG_BUCK_ACTIVE_DISCHARGE3,
+	MAX8998_REG_ONOFF1,
+	MAX8998_REG_ONOFF2,
+	MAX8998_REG_ONOFF3,
+	MAX8998_REG_ONOFF4,
+	MAX8998_REG_BUCK1_VOLTAGE1,
+	MAX8998_REG_BUCK1_VOLTAGE2,
+	MAX8998_REG_BUCK1_VOLTAGE3,
+	MAX8998_REG_BUCK1_VOLTAGE4,
+	MAX8998_REG_BUCK2_VOLTAGE1,
+	MAX8998_REG_BUCK2_VOLTAGE2,
+	MAX8998_REG_BUCK3,
+	MAX8998_REG_BUCK4,
+	MAX8998_REG_LDO2_LDO3,
+	MAX8998_REG_LDO4,
+	MAX8998_REG_LDO5,
+	MAX8998_REG_LDO6,
+	MAX8998_REG_LDO7,
+	MAX8998_REG_LDO8_LDO9,
+	MAX8998_REG_LDO10_LDO11,
+	MAX8998_REG_LDO12,
+	MAX8998_REG_LDO13,
+	MAX8998_REG_LDO14,
+	MAX8998_REG_LDO15,
+	MAX8998_REG_LDO16,
+	MAX8998_REG_LDO17,
+	MAX8998_REG_BKCHR,
+	MAX8998_REG_LBCNFG1,
+	MAX8998_REG_LBCNFG2,
+	PMIC_NUM_OF_REGS,
+};
+
+#define MAX8998_LDO3		(1 << 2)
+#define MAX8998_LDO8		(1 << 5)
+
+#define MAX8998_I2C_ADDR        (0xCC >> 1)
+
+enum { LDO_OFF, LDO_ON };
+
+#endif /* __MAX8998_PMIC_H_ */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver Lukasz Majewski
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new " Lukasz Majewski
@ 2011-10-04  5:45   ` Lukasz Majewski
  2011-10-05 10:54     ` Stefano Babic
  2011-10-12 10:56     ` Stefano Babic
  2011-10-05 10:52   ` [U-Boot] [PATCH v2 0/3] misc:pmic: New PMIC generic driver Stefano Babic
                     ` (2 subsequent siblings)
  5 siblings, 2 replies; 40+ messages in thread
From: Lukasz Majewski @ 2011-10-04  5:45 UTC (permalink / raw)
  To: u-boot

Enable support for new PMIC driver at GONI reference target.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
    Changes for v2:
    - pmic_init() function call removed from arch/arm/lib/board.c and
      moved to s5p_goni board_init() function.
    - prepare separate patch for enabling new PMIC driver at GONI
---
 board/samsung/goni/goni.c  |    4 ++++
 include/configs/s5p_goni.h |    4 ++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/board/samsung/goni/goni.c b/board/samsung/goni/goni.c
index e24cd29..e191bfb 100644
--- a/board/samsung/goni/goni.c
+++ b/board/samsung/goni/goni.c
@@ -25,6 +25,7 @@
 #include <common.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
+#include <pmic.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -38,6 +39,9 @@ int board_init(void)
 	gd->bd->bi_arch_number = MACH_TYPE_GONI;
 	gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
 
+#if defined(CONFIG_PMIC)
+	pmic_init();
+#endif
 	return 0;
 }
 
diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
index 886c8be..aa51114 100644
--- a/include/configs/s5p_goni.h
+++ b/include/configs/s5p_goni.h
@@ -223,6 +223,10 @@
 
 #define CONFIG_SYS_INIT_SP_ADDR	(CONFIG_SYS_LOAD_ADDR - 0x1000000)
 
+#define CONFIG_PMIC
+#define CONFIG_PMIC_I2C
+#define CONFIG_PMIC_MAX8998
+
 #include <asm/arch/gpio.h>
 /*
  * I2C Settings
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 0/3] misc:pmic: New PMIC generic driver
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
                     ` (2 preceding siblings ...)
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target Lukasz Majewski
@ 2011-10-05 10:52   ` Stefano Babic
  2011-10-05 10:56   ` [U-Boot] [PATCH v2 4/4] misc: pmic: Freescale PMIC switches to generic PMIC driver Stefano Babic
  2011-10-06 12:37   ` [U-Boot] [PATCH v3 1/3] misc:pmic:core New " Lukasz Majewski
  5 siblings, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-05 10:52 UTC (permalink / raw)
  To: u-boot

On 10/04/2011 07:45 AM, Lukasz Majewski wrote:
> This patch series adds new generic PMIC framework for u-boot.
> It is supposed to handle various types of pmic IC's (both,
> equippled with I2C or SPI bus).
> 
> This patch series has been tested on Samsung's GONI reference target.
> ---
> 	Changes for v2:
> 	- New logical structure of patch series
> 	- printf/puts replaced with debug() macro where applicable
> 	- pmic_reg_write(...,u32 *val) replaced with u32 val
> 	- pmic_init() moved to board_init() function
> 
> Lukasz Majewski (3):
>   misc:pmic:core New generic PMIC driver
>   misc:pmic:max8998 MAX8998 support at a new PMIC driver.
>   misc:pmic:samsung Enable PMIC driver at GONI target
> 

Hi Lukasz,

I retested your patches, they looks ok for me. I have only seen you
dropped also the changes to fsl_pmic.h and pmic_fsl.c, not only the ones
for MX51. Because I need in any case these changes to test your code, I
will merge also these files (I resubmit now a patch with your signed-off
with the code extracted from the V1, as fourth patch of your patchset..).

I tested also the RTC mc13783, this uses also PMIC code. It looks ok ;-).

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver Lukasz Majewski
@ 2011-10-05 10:52     ` Stefano Babic
  2011-10-06  9:48     ` Stefano Babic
  1 sibling, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-05 10:52 UTC (permalink / raw)
  To: u-boot

On 10/04/2011 07:45 AM, Lukasz Majewski wrote:
> I2C or SPI PMIC devices can be accessed.
> Separate files: pmic_i2c.c and pmic_spi.c are responsible
> for handling transmission over I2C or SPI bus.
> 
> New flags:
> CONFIG_PMIC - enable PMIC general device.
> CONFIG_PMIC_I2C/SPI - specify the interface to be used.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new PMIC driver.
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new " Lukasz Majewski
@ 2011-10-05 10:53     ` Stefano Babic
  2011-10-12 10:55     ` Stefano Babic
  1 sibling, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-05 10:53 UTC (permalink / raw)
  To: u-boot

On 10/04/2011 07:45 AM, Lukasz Majewski wrote:
> This commit adds support for MAX8998 PMIC driver.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
>     Changes for v2:
>     - separate commit for MAX8998 prepared

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target Lukasz Majewski
@ 2011-10-05 10:54     ` Stefano Babic
  2011-10-12 10:56     ` Stefano Babic
  1 sibling, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-05 10:54 UTC (permalink / raw)
  To: u-boot

On 10/04/2011 07:45 AM, Lukasz Majewski wrote:
> Enable support for new PMIC driver at GONI reference target.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 4/4] misc: pmic: Freescale PMIC switches to generic PMIC driver
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
                     ` (3 preceding siblings ...)
  2011-10-05 10:52   ` [U-Boot] [PATCH v2 0/3] misc:pmic: New PMIC generic driver Stefano Babic
@ 2011-10-05 10:56   ` Stefano Babic
  2011-10-06 12:37   ` [U-Boot] [PATCH v3 1/3] misc:pmic:core New " Lukasz Majewski
  5 siblings, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-05 10:56 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 Changes:
	this code was part of V1, missing in V2, required for Freescale PMIC

 drivers/misc/Makefile   |    1 +
 drivers/misc/pmic_fsl.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++
 include/fsl_pmic.h      |    5 +---
 3 files changed, 59 insertions(+), 4 deletions(-)
 create mode 100644 drivers/misc/pmic_fsl.c

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 6d82c22..f732a95 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -36,6 +36,7 @@ COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
 COBJS-$(CONFIG_STATUS_LED) += status_led.o
 COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o
 COBJS-$(CONFIG_PMIC) += pmic_core.o
+COBJS-$(CONFIG_PMIC_FSL) += pmic_fsl.o
 COBJS-$(CONFIG_PMIC_I2C) += pmic_i2c.o
 COBJS-$(CONFIG_PMIC_SPI) += pmic_spi.o
 COBJS-$(CONFIG_PMIC_MAX8998) += pmic_max8998.o
diff --git a/drivers/misc/pmic_fsl.c b/drivers/misc/pmic_fsl.c
new file mode 100644
index 0000000..13dde47
--- /dev/null
+++ b/drivers/misc/pmic_fsl.c
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <spi.h>
+#include <pmic.h>
+#include <fsl_pmic.h>
+
+static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
+{
+	if ((val == NULL) && (write))
+		return *val & ~(1 << 31);
+	else
+		return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
+}
+
+int pmic_init(void)
+{
+	struct pmic *p = get_pmic();
+	static const char name[] = "FSL_PMIC";
+
+	puts("Board PMIC init\n");
+
+	p->name = name;
+	p->interface = PMIC_SPI;
+	p->number_of_regs = PMIC_NUM_OF_REGS;
+	p->bus = CONFIG_FSL_PMIC_BUS;
+
+	p->hw.spi.cs = CONFIG_FSL_PMIC_CS;
+	p->hw.spi.clk = CONFIG_FSL_PMIC_CLK;
+	p->hw.spi.mode = CONFIG_FSL_PMIC_MODE;
+	p->hw.spi.bitlen = CONFIG_FSL_PMIC_BITLEN;
+	p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END;
+	p->hw.spi.prepare_tx = pmic_spi_prepare_tx;
+
+	return 0;
+}
diff --git a/include/fsl_pmic.h b/include/fsl_pmic.h
index e3abde6..742f2e1 100644
--- a/include/fsl_pmic.h
+++ b/include/fsl_pmic.h
@@ -99,6 +99,7 @@ enum {
 	REG_TEST2,
 	REG_TEST3,
 	REG_TEST4,
+	PMIC_NUM_OF_REGS,
 };
 
 /* REG_POWER_MISC */
@@ -121,8 +122,4 @@ enum {
 /* Interrupt status 1 */
 #define RTCRSTI		(1 << 7)
 
-void pmic_show_pmic_info(void);
-void pmic_reg_write(u32 reg, u32 value);
-u32 pmic_reg_read(u32 reg);
-
 #endif
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver Lukasz Majewski
  2011-10-05 10:52     ` Stefano Babic
@ 2011-10-06  9:48     ` Stefano Babic
  2011-10-06 11:13       ` Lukasz Majewski
  1 sibling, 1 reply; 40+ messages in thread
From: Stefano Babic @ 2011-10-06  9:48 UTC (permalink / raw)
  To: u-boot

On 10/04/2011 07:45 AM, Lukasz Majewski wrote:
> I2C or SPI PMIC devices can be accessed.
> Separate files: pmic_i2c.c and pmic_spi.c are responsible
> for handling transmission over I2C or SPI bus.
> 
> New flags:
> CONFIG_PMIC - enable PMIC general device.
> CONFIG_PMIC_I2C/SPI - specify the interface to be used.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---

Hi Lukasz,

> +
> +struct p_spi {
> +	unsigned char cs;
> +	unsigned char mode;
> +	unsigned char bitlen;
> +	unsigned int  clk;
> +	unsigned int  flags;
> +	u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
> +};
> +
> +struct pmic {
> +	const char *name;
> +	unsigned char bus;
> +	unsigned char interface;
> +	unsigned char number_of_regs;
> +	union hw {
> +		struct p_i2c i2c;
> +		struct p_spi spi;
> +	} hw;
> +};

I have found an issue with this structure. In some case a char is not
enough. The i.MX SPI driver uses the LSB byte to set a chipselect
provided directly by the controller, and the MSB if a GPIO is selected.
You can see an example in efikamx.h. It is better to replace all
unsigned char in this structure with unsigned int to avoid these problems.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver
  2011-10-06  9:48     ` Stefano Babic
@ 2011-10-06 11:13       ` Lukasz Majewski
  2011-10-06 11:19         ` Stefano Babic
  0 siblings, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-10-06 11:13 UTC (permalink / raw)
  To: u-boot

Hi Stefano,

I suppose you are talking about cases like the following:

> #define CONFIG_SPI_FLASH_CS		(1 | 121 << 8)

Yes, this construct will cause range overflow.

> +struct p_spi {
> +	unsigned char cs;
> +	unsigned char mode;
> +	unsigned char bitlen;

Therefore the above variables need to be at least unsigned shorts.
As you proposed they shall be unsigned int.

On technical question:
Shall I prepare the whole v3 patch series or only v3 for this single
patch ([PATCH v2 1/3] misc:pmic:core New generic PMIC drive)?

What would be easier for You or Wolfgang to pick?


-- 
Best regards,

Lukasz Majewski

Samsung Poland R&D Center
Platform Group

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver
  2011-10-06 11:13       ` Lukasz Majewski
@ 2011-10-06 11:19         ` Stefano Babic
  0 siblings, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-06 11:19 UTC (permalink / raw)
  To: u-boot

On 10/06/2011 01:13 PM, Lukasz Majewski wrote:
> Hi Stefano,
> 

Hi Lukasz,

> I suppose you are talking about cases like the following:
> 
>> #define CONFIG_SPI_FLASH_CS		(1 | 121 << 8)
> 
> Yes, this construct will cause range overflow.
> 
>> +struct p_spi {
>> +	unsigned char cs;
>> +	unsigned char mode;
>> +	unsigned char bitlen;
> 
> Therefore the above variables need to be at least unsigned shorts.
> As you proposed they shall be unsigned int.

Yes

> 
> On technical question:
> Shall I prepare the whole v3 patch series or only v3 for this single
> patch ([PATCH v2 1/3] misc:pmic:core New generic PMIC drive)?

Post only v3 for the single patch.

> 
> What would be easier for You or Wolfgang to pick?

As Wolfgang asked, I will take care of your patchset and I will merge it
with u-boot-imx. It will go into mainline after my pull request.

Best regards,
Stefano

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v3 1/3] misc:pmic:core New generic PMIC driver
  2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
                     ` (4 preceding siblings ...)
  2011-10-05 10:56   ` [U-Boot] [PATCH v2 4/4] misc: pmic: Freescale PMIC switches to generic PMIC driver Stefano Babic
@ 2011-10-06 12:37   ` Lukasz Majewski
  2011-10-12 10:57     ` Stefano Babic
  5 siblings, 1 reply; 40+ messages in thread
From: Lukasz Majewski @ 2011-10-06 12:37 UTC (permalink / raw)
  To: u-boot

I2C or SPI PMIC devices can be accessed.
Separate files: pmic_i2c.c and pmic_spi.c are responsible
for handling transmission over I2C or SPI bus.

New flags:
CONFIG_PMIC - enable PMIC general device.
CONFIG_PMIC_I2C/SPI - specify the interface to be used.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Stefano Babic <sbabic@denx.de>
---
    Changes for v2:
    - pmic_reg_write(..., u32 *val) - u32 *val replaced with u32 val.
    - debug() macros added instead of plain printf()
    Changes for v3:
    - at 'struct p_spi' replace cs, mode and bitlen unsigned char
      variables to unsigned int
---
 drivers/misc/Makefile    |    3 +
 drivers/misc/pmic_core.c |  147 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/pmic_i2c.c  |   92 +++++++++++++++++++++++++++++
 drivers/misc/pmic_spi.c  |  109 ++++++++++++++++++++++++++++++++++
 include/pmic.h           |   71 ++++++++++++++++++++++
 5 files changed, 422 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/pmic_core.c
 create mode 100644 drivers/misc/pmic_i2c.c
 create mode 100644 drivers/misc/pmic_spi.c
 create mode 100644 include/pmic.h

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b152486..91c5bfa 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -35,6 +35,9 @@ COBJS-$(CONFIG_NS87308) += ns87308.o
 COBJS-$(CONFIG_PDSP188x) += pdsp188x.o
 COBJS-$(CONFIG_STATUS_LED) += status_led.o
 COBJS-$(CONFIG_TWL4030_LED) += twl4030_led.o
+COBJS-$(CONFIG_PMIC) += pmic_core.o
+COBJS-$(CONFIG_PMIC_I2C) += pmic_i2c.o
+COBJS-$(CONFIG_PMIC_SPI) += pmic_spi.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
diff --git a/drivers/misc/pmic_core.c b/drivers/misc/pmic_core.c
new file mode 100644
index 0000000..5d62a56
--- /dev/null
+++ b/drivers/misc/pmic_core.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+
+static struct pmic pmic;
+
+int check_reg(u32 reg)
+{
+	if (reg >= pmic.number_of_regs) {
+		printf("<reg num> = %d is invalid. Should be less than %d\n",
+		       reg, pmic.number_of_regs);
+		return -1;
+	}
+	return 0;
+}
+
+int pmic_set_output(struct pmic *p, u32 reg, int out, int on)
+{
+	u32 val;
+
+	if (pmic_reg_read(p, reg, &val))
+		return -1;
+
+	if (on)
+		val |= out;
+	else
+		val &= ~out;
+
+	if (pmic_reg_write(p, reg, val))
+		return -1;
+
+	return 0;
+}
+
+static void pmic_show_info(struct pmic *p)
+{
+	printf("PMIC: %s\n", p->name);
+}
+
+static void pmic_dump(struct pmic *p)
+{
+	int i, ret;
+	u32 val;
+
+	pmic_show_info(p);
+	for (i = 0; i < p->number_of_regs; i++) {
+		ret = pmic_reg_read(p, i, &val);
+		if (ret)
+			puts("PMIC: Registers dump failed\n");
+
+		if (!(i % 8))
+			printf("\n0x%02x: ", i);
+
+		printf("%08x ", val);
+	}
+	puts("\n");
+}
+
+struct pmic *get_pmic(void)
+{
+	return &pmic;
+}
+
+int do_pmic(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	u32 ret, reg, val;
+	char *cmd;
+
+	struct pmic *p = &pmic;
+
+	/* at least two arguments please */
+	if (argc < 2)
+		return cmd_usage(cmdtp);
+
+	cmd = argv[1];
+	if (strcmp(cmd, "dump") == 0) {
+		pmic_dump(p);
+		return 0;
+	}
+
+	if (strcmp(cmd, "read") == 0) {
+		if (argc < 3)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+
+		ret = pmic_reg_read(p, reg, &val);
+
+		if (ret)
+			puts("PMIC: Register read failed\n");
+
+		printf("\n0x%02x: 0x%08x\n", reg, val);
+
+		return 0;
+	}
+
+	if (strcmp(cmd, "write") == 0) {
+		if (argc < 4)
+			return cmd_usage(cmdtp);
+
+		reg = simple_strtoul(argv[2], NULL, 16);
+		val = simple_strtoul(argv[3], NULL, 16);
+
+		pmic_reg_write(p, reg, val);
+
+		return 0;
+	}
+
+	/* No subcommand found */
+	return 1;
+}
+
+U_BOOT_CMD(
+	pmic,	CONFIG_SYS_MAXARGS, 1, do_pmic,
+	"PMIC",
+	"dump - dump PMIC registers\n"
+	"pmic read <reg> - read register\n"
+	"pmic write <reg> <value> - write register"
+);
diff --git a/drivers/misc/pmic_i2c.c b/drivers/misc/pmic_i2c.c
new file mode 100644
index 0000000..b82e899
--- /dev/null
+++ b/drivers/misc/pmic_i2c.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+#include <i2c.h>
+
+int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
+{
+	unsigned char buf[4] = { 0 };
+
+	if (check_reg(reg))
+		return -1;
+
+	switch (pmic_i2c_tx_num) {
+	case 3:
+		buf[0] = (val >> 16) & 0xff;
+		buf[1] = (val >> 8) & 0xff;
+		buf[2] = val & 0xff;
+		break;
+	case 1:
+		buf[0] = val & 0xff;
+		break;
+	}
+
+	if (i2c_write(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
+		return -1;
+
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
+{
+	unsigned char buf[4] = { 0 };
+	u32 ret_val = 0;
+
+	if (check_reg(reg))
+		return -1;
+
+	if (i2c_read(pmic_i2c_addr, reg, 1, buf, pmic_i2c_tx_num))
+		return -1;
+
+	switch (pmic_i2c_tx_num) {
+	case 3:
+		ret_val = buf[0] << 16 | buf[1] << 8 | buf[2];
+		break;
+	case 1:
+		ret_val = buf[0];
+		break;
+	}
+	memcpy(val, &ret_val, sizeof(ret_val));
+
+	return 0;
+}
+
+int pmic_probe(struct pmic *p)
+{
+	i2c_set_bus_num(p->bus);
+	debug("PMIC:%s probed!\n", p->name);
+	if (i2c_probe(pmic_i2c_addr)) {
+		printf("Can't find PMIC:%s\n", p->name);
+		return -1;
+	}
+
+	return 0;
+}
diff --git a/drivers/misc/pmic_spi.c b/drivers/misc/pmic_spi.c
new file mode 100644
index 0000000..ff35377
--- /dev/null
+++ b/drivers/misc/pmic_spi.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2011 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * (C) Copyright 2010
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de
+ *
+ * (C) Copyright 2008-2009 Freescale Semiconductor, Inc.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <linux/types.h>
+#include <pmic.h>
+#include <spi.h>
+
+static struct spi_slave *slave;
+
+void pmic_spi_free(struct spi_slave *slave)
+{
+	if (slave)
+		spi_free_slave(slave);
+}
+
+struct spi_slave *pmic_spi_probe(struct pmic *p)
+{
+	return spi_setup_slave(p->bus,
+		p->hw.spi.cs,
+		p->hw.spi.clk,
+		p->hw.spi.mode);
+}
+
+static u32 pmic_reg(struct pmic *p, u32 reg, u32 *val, u32 write)
+{
+	u32 pmic_tx, pmic_rx;
+	u32 tmp;
+
+	if (!slave) {
+		slave = pmic_spi_probe(p);
+
+		if (!slave)
+			return -1;
+	}
+
+	if (check_reg(reg))
+		return -1;
+
+	if (spi_claim_bus(slave))
+		return -1;
+
+	pmic_tx = p->hw.spi.prepare_tx(reg, val, write);
+
+	tmp = cpu_to_be32(pmic_tx);
+
+	if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
+			pmic_spi_flags)) {
+		spi_release_bus(slave);
+		return -1;
+	}
+
+	if (write) {
+		pmic_tx = p->hw.spi.prepare_tx(0, NULL, write);
+		pmic_tx &= ~(1 << 31);
+		tmp = cpu_to_be32(pmic_tx);
+		if (spi_xfer(slave, pmic_spi_bitlen, &tmp, &pmic_rx,
+			pmic_spi_flags)) {
+			spi_release_bus(slave);
+			return -1;
+		}
+	}
+
+	spi_release_bus(slave);
+	*val = cpu_to_be32(pmic_rx);
+
+	return 0;
+}
+
+int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
+{
+	if (pmic_reg(p, reg, &val, 1))
+		return -1;
+
+	return 0;
+}
+
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
+{
+	if (pmic_reg(p, reg, val, 0))
+		return -1;
+
+	return 0;
+}
diff --git a/include/pmic.h b/include/pmic.h
new file mode 100644
index 0000000..52a1526
--- /dev/null
+++ b/include/pmic.h
@@ -0,0 +1,71 @@
+/*
+ *  Copyright (C) 2011 Samsung Electronics
+ *  Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef __CORE_PMIC_H_
+#define __CORE_PMIC_H_
+
+enum { PMIC_I2C, PMIC_SPI, };
+enum { I2C_PMIC, I2C_NUM, };
+enum { PMIC_READ, PMIC_WRITE, };
+
+struct p_i2c {
+	unsigned char addr;
+	unsigned char *buf;
+	unsigned char tx_num;
+};
+
+struct p_spi {
+	unsigned int cs;
+	unsigned int mode;
+	unsigned int bitlen;
+	unsigned int clk;
+	unsigned int flags;
+	u32 (*prepare_tx)(u32 reg, u32 *val, u32 write);
+};
+
+struct pmic {
+	const char *name;
+	unsigned char bus;
+	unsigned char interface;
+	unsigned char number_of_regs;
+	union hw {
+		struct p_i2c i2c;
+		struct p_spi spi;
+	} hw;
+};
+
+int pmic_init(void);
+int check_reg(u32 reg);
+struct pmic *get_pmic(void);
+int pmic_probe(struct pmic *p);
+int pmic_reg_read(struct pmic *p, u32 reg, u32 *val);
+int pmic_reg_write(struct pmic *p, u32 reg, u32 val);
+int pmic_set_output(struct pmic *p, u32 reg, int ldo, int on);
+
+#define pmic_i2c_addr (p->hw.i2c.addr)
+#define pmic_i2c_tx_num (p->hw.i2c.tx_num)
+
+#define pmic_spi_bitlen (p->hw.spi.bitlen)
+#define pmic_spi_flags (p->hw.spi.flags)
+
+#endif /* __CORE_PMIC_H_ */
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new PMIC driver.
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new " Lukasz Majewski
  2011-10-05 10:53     ` Stefano Babic
@ 2011-10-12 10:55     ` Stefano Babic
  1 sibling, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-12 10:55 UTC (permalink / raw)
  To: u-boot

On 10/04/2011 07:45 AM, Lukasz Majewski wrote:
> This commit adds support for MAX8998 PMIC driver.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
>     Changes for v2:
>     - separate commit for MAX8998 prepared
> ---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target
  2011-10-04  5:45   ` [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target Lukasz Majewski
  2011-10-05 10:54     ` Stefano Babic
@ 2011-10-12 10:56     ` Stefano Babic
  1 sibling, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-12 10:56 UTC (permalink / raw)
  To: u-boot

On 10/04/2011 07:45 AM, Lukasz Majewski wrote:
> Enable support for new PMIC driver at GONI reference target.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
>     Changes for v2:
>     - pmic_init() function call removed from arch/arm/lib/board.c and
>       moved to s5p_goni board_init() function.
>     - prepare separate patch for enabling new PMIC driver at GONI
> ---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [U-Boot] [PATCH v3 1/3] misc:pmic:core New generic PMIC driver
  2011-10-06 12:37   ` [U-Boot] [PATCH v3 1/3] misc:pmic:core New " Lukasz Majewski
@ 2011-10-12 10:57     ` Stefano Babic
  0 siblings, 0 replies; 40+ messages in thread
From: Stefano Babic @ 2011-10-12 10:57 UTC (permalink / raw)
  To: u-boot

On 10/06/2011 02:37 PM, Lukasz Majewski wrote:
> I2C or SPI PMIC devices can be accessed.
> Separate files: pmic_i2c.c and pmic_spi.c are responsible
> for handling transmission over I2C or SPI bus.
> 
> New flags:
> CONFIG_PMIC - enable PMIC general device.
> CONFIG_PMIC_I2C/SPI - specify the interface to be used.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Stefano Babic <sbabic@denx.de>
> ---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2011-10-12 10:57 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-01  9:13 [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
2011-09-01  9:13 ` [U-Boot] [PATCH 1/2] " Lukasz Majewski
2011-09-01  9:13 ` [U-Boot] [PATCH 2/2] misc:samsung:s5p Enable MAX8998 support at GONI reference target Lukasz Majewski
2011-09-12  8:14 ` [U-Boot] [PATCH 0/2] misc:max8998 Support for MAX8998 PMIC driver Lukasz Majewski
2011-09-12 10:50   ` Stefano Babic
2011-09-12 11:41     ` Wolfgang Denk
2011-09-12 13:18     ` Lukasz Majewski
2011-09-12 13:50       ` Stefano Babic
2011-09-19 15:06 ` [U-Boot] [RFC 0/2] Generic " Lukasz Majewski
2011-09-19 15:06   ` [U-Boot] [RFC 1/2] misc:pmic New generic pmic driver Lukasz Majewski
2011-09-19 15:06   ` [U-Boot] [RFC 2/2] misc:pmic:max8998: Support for max8998 pmic Lukasz Majewski
2011-09-20  8:23   ` [U-Boot] [RFC 0/2] Generic PMIC driver Stefano Babic
2011-09-20 12:38     ` Lukasz Majewski
2011-09-20 14:08       ` Stefano Babic
2011-09-26 15:10 ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Lukasz Majewski
2011-09-26 15:10   ` [U-Boot] [PATCH 1/3] misc:pmic New generic pmic driver Lukasz Majewski
2011-10-02 16:12     ` stefano babic
2011-09-26 15:10   ` [U-Boot] [PATCH 2/3] misc:pmic: Enable PMIC handling at u-boot startup code Lukasz Majewski
2011-10-02 16:14     ` stefano babic
2011-09-26 15:10   ` [U-Boot] [PATCH 3/3] misc:pmic:mx: Code modification for mx51evk board Lukasz Majewski
2011-10-02 16:15     ` stefano babic
2011-09-28 11:28   ` [U-Boot] [PATCH 0/3] misc:pmic: New PMIC generic driver Stefano Babic
2011-09-28 11:56     ` Lukasz Majewski
2011-10-02 15:58   ` stefano babic
2011-10-04  5:45 ` [U-Boot] [PATCH v2 " Lukasz Majewski
2011-10-04  5:45   ` [U-Boot] [PATCH v2 1/3] misc:pmic:core New generic PMIC driver Lukasz Majewski
2011-10-05 10:52     ` Stefano Babic
2011-10-06  9:48     ` Stefano Babic
2011-10-06 11:13       ` Lukasz Majewski
2011-10-06 11:19         ` Stefano Babic
2011-10-04  5:45   ` [U-Boot] [PATCH v2 2/3] misc:pmic:max8998 MAX8998 support at a new " Lukasz Majewski
2011-10-05 10:53     ` Stefano Babic
2011-10-12 10:55     ` Stefano Babic
2011-10-04  5:45   ` [U-Boot] [PATCH v2 3/3] misc:pmic:samsung Enable PMIC driver at GONI target Lukasz Majewski
2011-10-05 10:54     ` Stefano Babic
2011-10-12 10:56     ` Stefano Babic
2011-10-05 10:52   ` [U-Boot] [PATCH v2 0/3] misc:pmic: New PMIC generic driver Stefano Babic
2011-10-05 10:56   ` [U-Boot] [PATCH v2 4/4] misc: pmic: Freescale PMIC switches to generic PMIC driver Stefano Babic
2011-10-06 12:37   ` [U-Boot] [PATCH v3 1/3] misc:pmic:core New " Lukasz Majewski
2011-10-12 10:57     ` Stefano Babic

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.