public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] power: rx51_battery: Replace hardcoded channels values.
@ 2013-08-21 22:45 Marek Belisko
  2013-08-28  1:27 ` Anton Vorontsov
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Belisko @ 2013-08-21 22:45 UTC (permalink / raw)
  To: anton, dwmw2; +Cc: linux-kernel, pali.rohar, Marek Belisko

In twl4030_madc header exist defines for fixed channels
+ add rx51 specific channels and replace all hardcoded channels
values.

Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>
---
 drivers/power/rx51_battery.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/power/rx51_battery.c b/drivers/power/rx51_battery.c
index 8a6288d..03f5761 100644
--- a/drivers/power/rx51_battery.c
+++ b/drivers/power/rx51_battery.c
@@ -25,6 +25,10 @@
 #include <linux/slab.h>
 #include <linux/i2c/twl4030-madc.h>
 
+/* RX51 specific channels */
+#define TWL4030_MADC_BTEMP_RX51	TWL4030_MADC_ADCIN0
+#define TWL4030_MADC_BCI_RX51	TWL4030_MADC_ADCIN4
+
 struct rx51_device_info {
 	struct device *dev;
 	struct power_supply bat;
@@ -37,7 +41,7 @@ static int rx51_battery_read_adc(int channel)
 {
 	struct twl4030_madc_request req;
 
-	req.channels = 1 << channel;
+	req.channels = channel;
 	req.do_avg = 1;
 	req.method = TWL4030_MADC_SW1;
 	req.func_cb = NULL;
@@ -56,7 +60,7 @@ static int rx51_battery_read_adc(int channel)
  */
 static int rx51_battery_read_voltage(struct rx51_device_info *di)
 {
-	int voltage = rx51_battery_read_adc(12);
+	int voltage = rx51_battery_read_adc(TWL4030_MADC_VBAT);
 
 	if (voltage < 0)
 		return voltage;
@@ -108,7 +112,7 @@ static int rx51_battery_read_temperature(struct rx51_device_info *di)
 {
 	int min = 0;
 	int max = ARRAY_SIZE(rx51_temp_table2) - 1;
-	int raw = rx51_battery_read_adc(0);
+	int raw = rx51_battery_read_adc(TWL4030_MADC_BTEMP_RX51);
 
 	/* Zero and negative values are undefined */
 	if (raw <= 0)
@@ -142,7 +146,7 @@ static int rx51_battery_read_temperature(struct rx51_device_info *di)
  */
 static int rx51_battery_read_capacity(struct rx51_device_info *di)
 {
-	int capacity = rx51_battery_read_adc(4);
+	int capacity = rx51_battery_read_adc(TWL4030_MADC_BCI_RX51);
 
 	if (capacity < 0)
 		return capacity;
-- 
1.8.1.2


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

* Re: [PATCH] power: rx51_battery: Replace hardcoded channels values.
  2013-08-21 22:45 [PATCH] power: rx51_battery: Replace hardcoded channels values Marek Belisko
@ 2013-08-28  1:27 ` Anton Vorontsov
  2013-08-28  6:07   ` Belisko Marek
  0 siblings, 1 reply; 4+ messages in thread
From: Anton Vorontsov @ 2013-08-28  1:27 UTC (permalink / raw)
  To: Marek Belisko; +Cc: dwmw2, linux-kernel, pali.rohar

On Thu, Aug 22, 2013 at 12:45:10AM +0200, Marek Belisko wrote:
> In twl4030_madc header exist defines for fixed channels
> + add rx51 specific channels and replace all hardcoded channels
> values.
> 
> Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>

Applied, thanks!

Anton

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

* Re: [PATCH] power: rx51_battery: Replace hardcoded channels values.
  2013-08-28  1:27 ` Anton Vorontsov
@ 2013-08-28  6:07   ` Belisko Marek
  2013-08-31  0:56     ` Anton Vorontsov
  0 siblings, 1 reply; 4+ messages in thread
From: Belisko Marek @ 2013-08-28  6:07 UTC (permalink / raw)
  To: Anton Vorontsov; +Cc: David Woodhouse, LKML, pali.rohar

Hi Anton,

On Wed, Aug 28, 2013 at 3:27 AM, Anton Vorontsov <anton@enomsg.org> wrote:
> On Thu, Aug 22, 2013 at 12:45:10AM +0200, Marek Belisko wrote:
>> In twl4030_madc header exist defines for fixed channels
>> + add rx51 specific channels and replace all hardcoded channels
>> values.
>>
>> Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>
>
> Applied, thanks!
Thanks for that. Unfortunately yesterday I was working on similar code
and found issue (wrong channel index) which was introduced by this
commit.
Fix is below. Sorry for troubles.

From: Marek Belisko <marek.belisko@open-nandra.com>
Date: Wed, 28 Aug 2013 08:04:10 +0200
Subject: [PATCH] power: rx51_battery: Fix channel number when reading adc
 value.

This issue was introduced in commit:
power: rx51_battery: Replace hardcoded channels values.

Original code use channel as argument which was shifted by one in function.
After mentioned commit argument is already shifted so we need to get index
back.

Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>
---
 drivers/power/rx51_battery.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/rx51_battery.c b/drivers/power/rx51_battery.c
index 03f5761..1bc5857 100644
--- a/drivers/power/rx51_battery.c
+++ b/drivers/power/rx51_battery.c
@@ -51,7 +51,7 @@ static int rx51_battery_read_adc(int channel)
  if (twl4030_madc_conversion(&req) <= 0)
  return -ENODATA;

- return req.rbuf[channel];
+ return req.rbuf[ffs(channel) - 1];
 }

 /*
-- 
1.7.9.5

>
> Anton

BR,

marek

-- 
as simple and primitive as possible
-------------------------------------------------
Marek Belisko - OPEN-NANDRA
Freelance Developer

Ruska Nova Ves 219 | Presov, 08005 Slovak Republic
Tel: +421 915 052 184
skype: marekwhite
twitter: #opennandra
web: http://open-nandra.com

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

* Re: [PATCH] power: rx51_battery: Replace hardcoded channels values.
  2013-08-28  6:07   ` Belisko Marek
@ 2013-08-31  0:56     ` Anton Vorontsov
  0 siblings, 0 replies; 4+ messages in thread
From: Anton Vorontsov @ 2013-08-31  0:56 UTC (permalink / raw)
  To: Belisko Marek; +Cc: David Woodhouse, LKML, pali.rohar

> This issue was introduced in commit:
> power: rx51_battery: Replace hardcoded channels values.
> 
> Original code use channel as argument which was shifted by one in function.
> After mentioned commit argument is already shifted so we need to get index
> back.
> 
> Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>

Applied, thanks!

> ---
>  drivers/power/rx51_battery.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/rx51_battery.c b/drivers/power/rx51_battery.c
> index 03f5761..1bc5857 100644
> --- a/drivers/power/rx51_battery.c
> +++ b/drivers/power/rx51_battery.c
> @@ -51,7 +51,7 @@ static int rx51_battery_read_adc(int channel)
>   if (twl4030_madc_conversion(&req) <= 0)
>   return -ENODATA;
> 
> - return req.rbuf[channel];
> + return req.rbuf[ffs(channel) - 1];
>  }
> 
>  /*

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

end of thread, other threads:[~2013-08-31  0:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-21 22:45 [PATCH] power: rx51_battery: Replace hardcoded channels values Marek Belisko
2013-08-28  1:27 ` Anton Vorontsov
2013-08-28  6:07   ` Belisko Marek
2013-08-31  0:56     ` Anton Vorontsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox