lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <A874F61F95741C4A9BA573A70FE3998F41EF1EC6@DQHE02.ent.ti.com>
Date:	Fri, 31 Aug 2012 09:24:28 +0000
From:	"Kim, Milo" <Milo.Kim@...com>
To:	Anton Vorontsov <anton.vorontsov@...aro.org>
CC:	David Woodhouse <dwmw2@...radead.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH 08/22] lp8727_charger: fix code for getting battery temp

 For better understanding, use specific function and definitions
 rather than magic numbers.
 New enum type for die temperature is matched with hex codes.
 Specific temperature names are better than 0x1, 0x2 and 0x3.

 And lp8727_is_high_temperature() function has better readability than
 comparing raw register values.

Signed-off-by: Milo(Woogyom) Kim <milo.kim@...com>
---
 drivers/power/lp8727_charger.c |   31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c
index b5567bc..1a5f4b2 100644
--- a/drivers/power/lp8727_charger.c
+++ b/drivers/power/lp8727_charger.c
@@ -58,6 +58,7 @@
 
 /* STATUS2 register */
 #define TEMP_STAT	(3 << 5)
+#define TEMP_SHIFT	5
 
 enum lp8727_dev_id {
 	ID_NONE,
@@ -75,6 +76,13 @@ enum lp8727_chg_stat {
 	EOC,
 };
 
+enum lp8727_die_temp {
+	LP8788_TEMP_75C,
+	LP8788_TEMP_95C,
+	LP8788_TEMP_115C,
+	LP8788_TEMP_135C,
+};
+
 struct lp8727_psy {
 	struct power_supply ac;
 	struct power_supply usb;
@@ -315,12 +323,25 @@ static int lp8727_charger_get_property(struct power_supply *psy,
 	return 0;
 }
 
+static bool lp8727_is_high_temperature(enum lp8727_die_temp temp)
+{
+	switch (temp) {
+	case LP8788_TEMP_95C:
+	case LP8788_TEMP_115C:
+	case LP8788_TEMP_135C:
+		return true;
+	default:
+		return false;
+	}
+}
+
 static int lp8727_battery_get_property(struct power_supply *psy,
 				       enum power_supply_property psp,
 				       union power_supply_propval *val)
 {
 	struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent);
 	struct lp8727_platform_data *pdata = pchg->pdata;
+	enum lp8727_die_temp temp;
 	u8 read;
 
 	switch (psp) {
@@ -337,11 +358,11 @@ static int lp8727_battery_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_HEALTH:
 		lp8727_read_byte(pchg, STATUS2, &read);
-		read = (read & TEMP_STAT) >> 5;
-		if (read >= 0x1 && read <= 0x3)
-			val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
-		else
-			val->intval = POWER_SUPPLY_HEALTH_GOOD;
+		temp = (read & TEMP_STAT) >> TEMP_SHIFT;
+
+		val->intval = lp8727_is_high_temperature(temp) ?
+			POWER_SUPPLY_HEALTH_OVERHEAT :
+			POWER_SUPPLY_HEALTH_GOOD;
 		break;
 	case POWER_SUPPLY_PROP_PRESENT:
 		if (!pdata)
-- 
1.7.9.5


Best Regards,
Milo


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ