From patchwork Fri Feb 15 12:44:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14853 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0681C23E2E for ; Fri, 15 Feb 2013 12:46:10 +0000 (UTC) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by fiordland.canonical.com (Postfix) with ESMTP id A25D0A18025 for ; Fri, 15 Feb 2013 12:46:09 +0000 (UTC) Received: by mail-ve0-f177.google.com with SMTP id m1so2948741ves.8 for ; Fri, 15 Feb 2013 04:46:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=VrT9RDgKDh50ykd5Nz4PCNGs/4upmSi5n8zD1shQCnY=; b=mrXM84XM4OcNe4SaJ1awL1njPLOqWnTUZ0I/vpJPy+Up4QaIX7/6q32YiqYm2Zn/Jf wjUwdHiozslKN3yDpk1hKz54O27o4xB1Lgl5hDOGWijp7lALTASI9BrUH7FnMx9BPBsa bbZJHLW4w8jCQHraz+Cm4zbzJ9AylLTaS9SRKWJUM49mZFAUzh2etfaEzzs31O+7wPeO c+a1KnXw5xJtkpocjYPUdpzjLcrWn0VdVic0uahtUi51bTtNbK6uZrd4bIySzGqOHQNP 2g9tewc2mntOaGqF2RxVwrMjI4O6XyxUxHWQ+zSRXNhJN1H28Zg0RLwP4WVHVG+kf3VW VbNw== X-Received: by 10.220.142.71 with SMTP id p7mr2941316vcu.3.1360932369111; Fri, 15 Feb 2013 04:46:09 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.221.4.5 with SMTP id oa5csp10829vcb; Fri, 15 Feb 2013 04:46:02 -0800 (PST) X-Received: by 10.194.9.71 with SMTP id x7mr3853621wja.53.1360932361819; Fri, 15 Feb 2013 04:46:01 -0800 (PST) Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com [74.125.82.51]) by mx.google.com with ESMTPS id cz5si19381471wjb.172.2013.02.15.04.46.01 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:01 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.51 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.51; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.51 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wg0-f51.google.com with SMTP id 8so2689134wgl.18 for ; Fri, 15 Feb 2013 04:46:01 -0800 (PST) X-Received: by 10.180.74.131 with SMTP id t3mr3817132wiv.26.1360932361385; Fri, 15 Feb 2013 04:46:01 -0800 (PST) Received: from localhost.localdomain (cpc34-aztw25-2-0-cust250.18-1.cable.virginmedia.com. [86.16.136.251]) by mx.google.com with ESMTPS id bs6sm5133904wib.4.2013.02.15.04.45.59 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:00 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, linus.walleij@stericsson.com, cbouatmailru@gmail.com, sameo@linux.intel.com, Rupesh Kumar , Lee Jones Subject: [PATCH 09/40] pm2301-charger: Support for over voltage protection on the ab9540 Date: Fri, 15 Feb 2013 12:44:39 +0000 Message-Id: <1360932310-30065-10-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360932310-30065-1-git-send-email-lee.jones@linaro.org> References: <1360932310-30065-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQlI0rvIOgKRYTg4CpsQNq1GlU5tTX3pHVesydJkGfpNJOwZKF5HxtKkNAvmVb/MnnBFZpMz From: Rupesh Kumar Added support for main charger over voltage protection. Signed-off-by: Rupesh Kumar Signed-off-by: Lee Jones Reviewed-by: Philippe LANGLAIS Tested-by: Michel JAOUEN --- drivers/power/pm2301_charger.c | 50 +++++++++++++++++++++++++++++----------- drivers/power/pm2301_charger.h | 1 + 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/drivers/power/pm2301_charger.c b/drivers/power/pm2301_charger.c index 62a172e..2b7c93d 100644 --- a/drivers/power/pm2301_charger.c +++ b/drivers/power/pm2301_charger.c @@ -227,21 +227,14 @@ int pm2xxx_charger_die_therm_mngt(struct pm2xxx_charger *pm2, int val) static int pm2xxx_charger_ovv_mngt(struct pm2xxx_charger *pm2, int val) { - int ret = 0; + dev_err(pm2->dev, "Overvoltage detected\n"); + pm2->flags.ovv = true; + power_supply_changed(&pm2->ac_chg.psy); - pm2->failure_input_ovv++; - if (pm2->failure_input_ovv < 4) { - ret = pm2xxx_charging_enable_mngt(pm2); - goto out; - } else { - pm2->failure_input_ovv = 0; - dev_err(pm2->dev, "Overvoltage detected\n"); - pm2->flags.ovv = true; - power_supply_changed(&pm2->ac_chg.psy); - } + /* Schedule a new HW failure check */ + queue_delayed_work(pm2->charger_wq, &pm2->check_hw_failure_work, 0); -out: - return ret; + return 0; } static int pm2xxx_charger_wd_exp_mngt(struct pm2xxx_charger *pm2, int val) @@ -630,6 +623,8 @@ static int pm2xxx_charger_ac_get_property(struct power_supply *psy, val->intval = POWER_SUPPLY_HEALTH_DEAD; else if (pm2->flags.main_thermal_prot) val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; + else if (pm2->flags.ovv) + val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; else val->intval = POWER_SUPPLY_HEALTH_GOOD; break; @@ -860,6 +855,30 @@ static void pm2xxx_charger_ac_work(struct work_struct *work) sysfs_notify(&pm2->ac_chg.psy.dev->kobj, NULL, "present"); }; +static void pm2xxx_charger_check_hw_failure_work(struct work_struct *work) +{ + u8 reg_value; + + struct pm2xxx_charger *pm2 = container_of(work, + struct pm2xxx_charger, check_hw_failure_work.work); + + if (pm2->flags.ovv) { + pm2xxx_reg_read(pm2, PM2XXX_SRCE_REG_INT4, ®_value); + + if (!(reg_value & (PM2XXX_INT4_S_ITVPWR1OVV | + PM2XXX_INT4_S_ITVPWR2OVV))) { + pm2->flags.ovv = false; + power_supply_changed(&pm2->ac_chg.psy); + } + } + + /* If we still have a failure, schedule a new check */ + if (pm2->flags.ovv) { + queue_delayed_work(pm2->charger_wq, + &pm2->check_hw_failure_work, round_jiffies(HZ)); + } +} + static void pm2xxx_charger_check_main_thermal_prot_work( struct work_struct *work) { @@ -983,6 +1002,10 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client, INIT_WORK(&pm2->check_main_thermal_prot_work, pm2xxx_charger_check_main_thermal_prot_work); + /* Init work for HW failure check */ + INIT_DEFERRABLE_WORK(&pm2->check_hw_failure_work, + pm2xxx_charger_check_hw_failure_work); + /* * VDD ADC supply needs to be enabled from this driver when there * is a charger connected to avoid erroneous BTEMP_HIGH/LOW @@ -1123,4 +1146,3 @@ MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Rajkumar kasirajan, Olivier Launay"); MODULE_ALIAS("platform:pm2xxx-charger"); MODULE_DESCRIPTION("PM2xxx charger management driver"); - diff --git a/drivers/power/pm2301_charger.h b/drivers/power/pm2301_charger.h index e6319cd..fad1f38 100644 --- a/drivers/power/pm2301_charger.h +++ b/drivers/power/pm2301_charger.h @@ -506,6 +506,7 @@ struct pm2xxx_charger { struct delayed_work check_vbat_work; struct work_struct ac_work; struct work_struct check_main_thermal_prot_work; + struct delayed_work check_hw_failure_work; struct ux500_charger ac_chg; struct pm2xxx_charger_event_flags flags; };