diff mbox

[U-Boot,v1,1/2] odroid: pmic77686: allow bucket voltage settings

Message ID 1412257559-14756-1-git-send-email-suriyan.r@gmail.com
State Changes Requested
Delegated to: Minkyu Kang
Headers show

Commit Message

Suriyan Ramasami Oct. 2, 2014, 1:45 p.m. UTC
Allow to set the bucket voltage for the max77686.
This will be used to reset the SMC LAN9730 ethernet on the odroids.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>
---
 drivers/power/pmic/pmic_max77686.c | 48 +++++++++++++++++++++++++++++++++++++-
 include/power/max77686_pmic.h      |  3 +++
 2 files changed, 50 insertions(+), 1 deletion(-)

Comments

Albert ARIBAUD Oct. 2, 2014, 9:03 p.m. UTC | #1
Hi Suriyan,

On Thu,  2 Oct 2014 06:45:58 -0700, Suriyan Ramasami
<suriyan.r@gmail.com> wrote:

> Allow to set the bucket voltage for the max77686.
> This will be used to reset the SMC LAN9730 ethernet on the odroids.

I believe the correct term is "buck", not "bucket".

> Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>
> ---
>  drivers/power/pmic/pmic_max77686.c | 48 +++++++++++++++++++++++++++++++++++++-
>  include/power/max77686_pmic.h      |  3 +++
>  2 files changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c
> index df1fd91..1aeadb4 100644
> --- a/drivers/power/pmic/pmic_max77686.c
> +++ b/drivers/power/pmic/pmic_max77686.c
> @@ -42,6 +42,25 @@ static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV)
>  	return 0;
>  }
>  
> +static unsigned int max77686_buck_volt2hex(int buck, ulong uV)
> +{
> +	unsigned int hex = 0;
> +
> +	if (buck < 5 || buck > 9) {
> +		debug("%s: buck %d is not supported\n", __func__, buck);
> +		return 0;
> +	}
> +
> +	hex = (uV - 750000) / 50000;
> +
> +	if (hex >= 0 && hex <= MAX77686_BUCK_VOLT_MAX_HEX)
> +		return hex;
> +
> +	debug("%s: %ld is wrong voltage value for BUCK%d\n",
> +	      __func__, uV, buck);
> +	return MAX77686_BUCK_VOLT_MAX_HEX + 1;
> +}
> +
>  int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
>  {
>  	unsigned int val, ret, hex, adr;
> @@ -68,6 +87,33 @@ int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
>  	return ret;
>  }
>  
> +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV)
> +{
> +	unsigned int val, ret, hex, adr;
> +
> +	if (buck < 5 && buck > 9) {
> +		printf("%s: %d is an unsupported bucket number\n",
> +		       __func__, buck);
> +		return -1;
> +	}
> +
> +	adr = max77686_buck_addr[buck] + 1;
> +	hex = max77686_buck_volt2hex(buck, uV);
> +
> +	if (hex == MAX77686_BUCK_VOLT_MAX_HEX + 1)
> +		return -1;
> +
> +	ret = pmic_reg_read(p, adr, &val);
> +	if (ret)
> +		return ret;
> +
> +	val &= ~MAX77686_BUCK_VOLT_MASK;
> +	val |= hex;
> +	ret |= pmic_reg_write(p, adr, val);
> +
> +	return ret;
> +}
> +
>  int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode)
>  {
>  	unsigned int val, ret, adr, mode;
> @@ -157,7 +203,7 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode)
>  	/* mode */
>  	switch (opmode) {
>  	case OPMODE_OFF:
> -		mode = MAX77686_BUCK_MODE_OFF;
> +		mode = MAX77686_BUCK_MODE_OFF << mode_shift;
>  		break;
>  	case OPMODE_STANDBY:
>  		switch (buck) {
> diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h
> index c2a772a..b0e4255 100644
> --- a/include/power/max77686_pmic.h
> +++ b/include/power/max77686_pmic.h
> @@ -150,6 +150,7 @@ enum {
>  
>  int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV);
>  int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode);
> +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV);
>  int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
>  
>  #define MAX77686_LDO_VOLT_MAX_HEX	0x3f
> @@ -159,6 +160,8 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
>  #define MAX77686_LDO_MODE_STANDBY	(0x01 << 0x06)
>  #define MAX77686_LDO_MODE_LPM		(0x02 << 0x06)
>  #define MAX77686_LDO_MODE_ON		(0x03 << 0x06)
> +#define MAX77686_BUCK_VOLT_MAX_HEX	0x3f
> +#define MAX77686_BUCK_VOLT_MASK		0x3f
>  #define MAX77686_BUCK_MODE_MASK		0x03
>  #define MAX77686_BUCK_MODE_SHIFT_1	0x00
>  #define MAX77686_BUCK_MODE_SHIFT_2	0x04


Amicalement,
Suriyan Ramasami Oct. 2, 2014, 10:07 p.m. UTC | #2
On Thu, Oct 2, 2014 at 2:03 PM, Albert ARIBAUD
<albert.u.boot@aribaud.net> wrote:
> Hi Suriyan,
>
> On Thu,  2 Oct 2014 06:45:58 -0700, Suriyan Ramasami
> <suriyan.r@gmail.com> wrote:
>
>> Allow to set the bucket voltage for the max77686.
>> This will be used to reset the SMC LAN9730 ethernet on the odroids.
>
> I believe the correct term is "buck", not "bucket".
>

Thanks Albert,
   I always thought they stood for bucket! This prompted me to read up
on BUCK regulators. Thank you. I shall correct it in my next version.

- Suriyan

>> Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>
>> ---
>>  drivers/power/pmic/pmic_max77686.c | 48 +++++++++++++++++++++++++++++++++++++-
>>  include/power/max77686_pmic.h      |  3 +++
>>  2 files changed, 50 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c
>> index df1fd91..1aeadb4 100644
>> --- a/drivers/power/pmic/pmic_max77686.c
>> +++ b/drivers/power/pmic/pmic_max77686.c
>> @@ -42,6 +42,25 @@ static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV)
>>       return 0;
>>  }
>>
>> +static unsigned int max77686_buck_volt2hex(int buck, ulong uV)
>> +{
>> +     unsigned int hex = 0;
>> +
>> +     if (buck < 5 || buck > 9) {
>> +             debug("%s: buck %d is not supported\n", __func__, buck);
>> +             return 0;
>> +     }
>> +
>> +     hex = (uV - 750000) / 50000;
>> +
>> +     if (hex >= 0 && hex <= MAX77686_BUCK_VOLT_MAX_HEX)
>> +             return hex;
>> +
>> +     debug("%s: %ld is wrong voltage value for BUCK%d\n",
>> +           __func__, uV, buck);
>> +     return MAX77686_BUCK_VOLT_MAX_HEX + 1;
>> +}
>> +
>>  int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
>>  {
>>       unsigned int val, ret, hex, adr;
>> @@ -68,6 +87,33 @@ int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
>>       return ret;
>>  }
>>
>> +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV)
>> +{
>> +     unsigned int val, ret, hex, adr;
>> +
>> +     if (buck < 5 && buck > 9) {
>> +             printf("%s: %d is an unsupported bucket number\n",
>> +                    __func__, buck);
>> +             return -1;
>> +     }
>> +
>> +     adr = max77686_buck_addr[buck] + 1;
>> +     hex = max77686_buck_volt2hex(buck, uV);
>> +
>> +     if (hex == MAX77686_BUCK_VOLT_MAX_HEX + 1)
>> +             return -1;
>> +
>> +     ret = pmic_reg_read(p, adr, &val);
>> +     if (ret)
>> +             return ret;
>> +
>> +     val &= ~MAX77686_BUCK_VOLT_MASK;
>> +     val |= hex;
>> +     ret |= pmic_reg_write(p, adr, val);
>> +
>> +     return ret;
>> +}
>> +
>>  int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode)
>>  {
>>       unsigned int val, ret, adr, mode;
>> @@ -157,7 +203,7 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode)
>>       /* mode */
>>       switch (opmode) {
>>       case OPMODE_OFF:
>> -             mode = MAX77686_BUCK_MODE_OFF;
>> +             mode = MAX77686_BUCK_MODE_OFF << mode_shift;
>>               break;
>>       case OPMODE_STANDBY:
>>               switch (buck) {
>> diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h
>> index c2a772a..b0e4255 100644
>> --- a/include/power/max77686_pmic.h
>> +++ b/include/power/max77686_pmic.h
>> @@ -150,6 +150,7 @@ enum {
>>
>>  int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV);
>>  int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode);
>> +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV);
>>  int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
>>
>>  #define MAX77686_LDO_VOLT_MAX_HEX    0x3f
>> @@ -159,6 +160,8 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
>>  #define MAX77686_LDO_MODE_STANDBY    (0x01 << 0x06)
>>  #define MAX77686_LDO_MODE_LPM                (0x02 << 0x06)
>>  #define MAX77686_LDO_MODE_ON         (0x03 << 0x06)
>> +#define MAX77686_BUCK_VOLT_MAX_HEX   0x3f
>> +#define MAX77686_BUCK_VOLT_MASK              0x3f
>>  #define MAX77686_BUCK_MODE_MASK              0x03
>>  #define MAX77686_BUCK_MODE_SHIFT_1   0x00
>>  #define MAX77686_BUCK_MODE_SHIFT_2   0x04
>
>
> Amicalement,
> --
> Albert.
Suriyan Ramasami Oct. 2, 2014, 10:09 p.m. UTC | #3
On Thu, Oct 2, 2014 at 7:31 AM, Przemyslaw Marczak
<p.marczak@samsung.com> wrote:
> Dear Suriyan,
>
> I will try to test it after the weekend.
>
> I'm working on a PMIC framework V3 with Trats2 as a base and the buck
> mode/voltage for Max77686 are yet implemented in my code.
>
> But this is okay because the new driver is fully reworked into new file and
> the support to the old PMIC framework will be still keept before move all
> the drivers to PMIC v3.
>
> The RFC will send soon.
>

Thanks Przemyslaw,
   Just FYI, I tested the USB host on the Odroid U2, a U3 and an X2.

Regards
- Suriyan

>
> On 10/02/2014 03:45 PM, Suriyan Ramasami wrote:
>>
>> Allow to set the bucket voltage for the max77686.
>> This will be used to reset the SMC LAN9730 ethernet on the odroids.
>>
>> Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>
>> ---
>>   drivers/power/pmic/pmic_max77686.c | 48
>> +++++++++++++++++++++++++++++++++++++-
>>   include/power/max77686_pmic.h      |  3 +++
>>   2 files changed, 50 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/power/pmic/pmic_max77686.c
>> b/drivers/power/pmic/pmic_max77686.c
>> index df1fd91..1aeadb4 100644
>> --- a/drivers/power/pmic/pmic_max77686.c
>> +++ b/drivers/power/pmic/pmic_max77686.c
>> @@ -42,6 +42,25 @@ static unsigned int max77686_ldo_volt2hex(int ldo,
>> ulong uV)
>>         return 0;
>>   }
>>
>> +static unsigned int max77686_buck_volt2hex(int buck, ulong uV)
>> +{
>> +       unsigned int hex = 0;
>> +
>> +       if (buck < 5 || buck > 9) {
>> +               debug("%s: buck %d is not supported\n", __func__, buck);
>> +               return 0;
>> +       }
>> +
>> +       hex = (uV - 750000) / 50000;
>> +
>> +       if (hex >= 0 && hex <= MAX77686_BUCK_VOLT_MAX_HEX)
>> +               return hex;
>> +
>> +       debug("%s: %ld is wrong voltage value for BUCK%d\n",
>> +             __func__, uV, buck);
>> +       return MAX77686_BUCK_VOLT_MAX_HEX + 1;
>> +}
>> +
>>   int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
>>   {
>>         unsigned int val, ret, hex, adr;
>> @@ -68,6 +87,33 @@ int max77686_set_ldo_voltage(struct pmic *p, int ldo,
>> ulong uV)
>>         return ret;
>>   }
>>
>> +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV)
>> +{
>> +       unsigned int val, ret, hex, adr;
>> +
>> +       if (buck < 5 && buck > 9) {
>> +               printf("%s: %d is an unsupported bucket number\n",
>> +                      __func__, buck);
>> +               return -1;
>> +       }
>> +
>> +       adr = max77686_buck_addr[buck] + 1;
>> +       hex = max77686_buck_volt2hex(buck, uV);
>> +
>> +       if (hex == MAX77686_BUCK_VOLT_MAX_HEX + 1)
>> +               return -1;
>> +
>> +       ret = pmic_reg_read(p, adr, &val);
>> +       if (ret)
>> +               return ret;
>> +
>> +       val &= ~MAX77686_BUCK_VOLT_MASK;
>> +       val |= hex;
>> +       ret |= pmic_reg_write(p, adr, val);
>> +
>> +       return ret;
>> +}
>> +
>>   int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode)
>>   {
>>         unsigned int val, ret, adr, mode;
>> @@ -157,7 +203,7 @@ int max77686_set_buck_mode(struct pmic *p, int buck,
>> char opmode)
>>         /* mode */
>>         switch (opmode) {
>>         case OPMODE_OFF:
>> -               mode = MAX77686_BUCK_MODE_OFF;
>> +               mode = MAX77686_BUCK_MODE_OFF << mode_shift;
>>                 break;
>>         case OPMODE_STANDBY:
>>                 switch (buck) {
>> diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h
>> index c2a772a..b0e4255 100644
>> --- a/include/power/max77686_pmic.h
>> +++ b/include/power/max77686_pmic.h
>> @@ -150,6 +150,7 @@ enum {
>>
>>   int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV);
>>   int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode);
>> +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV);
>>   int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
>>
>>   #define MAX77686_LDO_VOLT_MAX_HEX     0x3f
>> @@ -159,6 +160,8 @@ int max77686_set_buck_mode(struct pmic *p, int buck,
>> char opmode);
>>   #define MAX77686_LDO_MODE_STANDBY     (0x01 << 0x06)
>>   #define MAX77686_LDO_MODE_LPM         (0x02 << 0x06)
>>   #define MAX77686_LDO_MODE_ON          (0x03 << 0x06)
>> +#define MAX77686_BUCK_VOLT_MAX_HEX     0x3f
>> +#define MAX77686_BUCK_VOLT_MASK                0x3f
>>   #define MAX77686_BUCK_MODE_MASK               0x03
>>   #define MAX77686_BUCK_MODE_SHIFT_1    0x00
>>   #define MAX77686_BUCK_MODE_SHIFT_2    0x04
>>
>
> Best regards,
> --
> Przemyslaw Marczak
> Samsung R&D Institute Poland
> Samsung Electronics
> p.marczak@samsung.com
diff mbox

Patch

diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c
index df1fd91..1aeadb4 100644
--- a/drivers/power/pmic/pmic_max77686.c
+++ b/drivers/power/pmic/pmic_max77686.c
@@ -42,6 +42,25 @@  static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV)
 	return 0;
 }
 
+static unsigned int max77686_buck_volt2hex(int buck, ulong uV)
+{
+	unsigned int hex = 0;
+
+	if (buck < 5 || buck > 9) {
+		debug("%s: buck %d is not supported\n", __func__, buck);
+		return 0;
+	}
+
+	hex = (uV - 750000) / 50000;
+
+	if (hex >= 0 && hex <= MAX77686_BUCK_VOLT_MAX_HEX)
+		return hex;
+
+	debug("%s: %ld is wrong voltage value for BUCK%d\n",
+	      __func__, uV, buck);
+	return MAX77686_BUCK_VOLT_MAX_HEX + 1;
+}
+
 int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
 {
 	unsigned int val, ret, hex, adr;
@@ -68,6 +87,33 @@  int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV)
 	return ret;
 }
 
+int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV)
+{
+	unsigned int val, ret, hex, adr;
+
+	if (buck < 5 && buck > 9) {
+		printf("%s: %d is an unsupported bucket number\n",
+		       __func__, buck);
+		return -1;
+	}
+
+	adr = max77686_buck_addr[buck] + 1;
+	hex = max77686_buck_volt2hex(buck, uV);
+
+	if (hex == MAX77686_BUCK_VOLT_MAX_HEX + 1)
+		return -1;
+
+	ret = pmic_reg_read(p, adr, &val);
+	if (ret)
+		return ret;
+
+	val &= ~MAX77686_BUCK_VOLT_MASK;
+	val |= hex;
+	ret |= pmic_reg_write(p, adr, val);
+
+	return ret;
+}
+
 int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode)
 {
 	unsigned int val, ret, adr, mode;
@@ -157,7 +203,7 @@  int max77686_set_buck_mode(struct pmic *p, int buck, char opmode)
 	/* mode */
 	switch (opmode) {
 	case OPMODE_OFF:
-		mode = MAX77686_BUCK_MODE_OFF;
+		mode = MAX77686_BUCK_MODE_OFF << mode_shift;
 		break;
 	case OPMODE_STANDBY:
 		switch (buck) {
diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h
index c2a772a..b0e4255 100644
--- a/include/power/max77686_pmic.h
+++ b/include/power/max77686_pmic.h
@@ -150,6 +150,7 @@  enum {
 
 int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV);
 int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode);
+int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV);
 int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
 
 #define MAX77686_LDO_VOLT_MAX_HEX	0x3f
@@ -159,6 +160,8 @@  int max77686_set_buck_mode(struct pmic *p, int buck, char opmode);
 #define MAX77686_LDO_MODE_STANDBY	(0x01 << 0x06)
 #define MAX77686_LDO_MODE_LPM		(0x02 << 0x06)
 #define MAX77686_LDO_MODE_ON		(0x03 << 0x06)
+#define MAX77686_BUCK_VOLT_MAX_HEX	0x3f
+#define MAX77686_BUCK_VOLT_MASK		0x3f
 #define MAX77686_BUCK_MODE_MASK		0x03
 #define MAX77686_BUCK_MODE_SHIFT_1	0x00
 #define MAX77686_BUCK_MODE_SHIFT_2	0x04