From patchwork Fri Feb 15 12:44:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14858 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 831D923E2E for ; Fri, 15 Feb 2013 12:46:16 +0000 (UTC) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by fiordland.canonical.com (Postfix) with ESMTP id 19F6AA18025 for ; Fri, 15 Feb 2013 12:46:16 +0000 (UTC) Received: by mail-vc0-f179.google.com with SMTP id gb23so2079459vcb.38 for ; Fri, 15 Feb 2013 04:46:15 -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=vnGc3fUOw681YbywnPilWTyiDFLNvRybIs/0Fe071gw=; b=DVExEecidEeZ1Z3BOsu2DAfzvQnfxLYz1f9UfZFa1R2cYs/h3thYus/SQOlwsVnz6M C6r9n7zWYlI8+UXQ0H0d7Uo4JCVzm2K5lF/44fAHiAeJI1u5fLDDlCzegO2BfZuvdEaf oze7y8WH1LjFuIMdbAZ/ZdsMbGeRfXF1TeqNNtN2Vj0OHuZ8Uxx4MPAqiK/e9aN/21mX IK1/kDcuV73B1WwoE6JYocJ4Qe+i09i3VMWF08h0GGu8voqvWFUHZ3L3dzANE6rXKM/R OY0rDt4NcoDXRK0cBbmW8ZSoU0ARWrJvaTfgVi0s5PQhTYSnIkQw3OI9bSYL8h+cZdPO iHVw== X-Received: by 10.58.213.37 with SMTP id np5mr2827093vec.54.1360932375582; Fri, 15 Feb 2013 04:46:15 -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 oa5csp10849vcb; Fri, 15 Feb 2013 04:46:14 -0800 (PST) X-Received: by 10.180.89.101 with SMTP id bn5mr5697307wib.14.1360932374034; Fri, 15 Feb 2013 04:46:14 -0800 (PST) Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]) by mx.google.com with ESMTPS id r19si1052179wiw.3.2013.02.15.04.46.13 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:14 -0800 (PST) Received-SPF: neutral (google.com: 2a00:1450:400c:c00::229 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=2a00:1450:400c:c00::229; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c00::229 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-f41.google.com with SMTP id ds1so852342wgb.2 for ; Fri, 15 Feb 2013 04:46:13 -0800 (PST) X-Received: by 10.180.98.232 with SMTP id el8mr2243921wib.22.1360932368519; Fri, 15 Feb 2013 04:46:08 -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.46.06 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 15 Feb 2013 04:46:07 -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, Mustapha Ben Zoubeir , Lee Jones Subject: [PATCH 12/40] pm2301-charger: Resolve I2C detection problem on ab9540 Date: Fri, 15 Feb 2013 12:44:42 +0000 Message-Id: <1360932310-30065-13-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: ALoCoQmNSWQyMoVFhEphaJROcfqXYZ4EvXPnA92jcmHnHuz6vADT+RT9W4FcRFQaVFS2VQTpwftq From: Mustapha Ben Zoubeir Signed-off-by: Mustapha Ben Zoubeir Signed-off-by: Lee Jones Reviewed-by: Marcus COOPER Reviewed-by: Philippe LANGLAIS Tested-by: Olivier CLERGEAUD --- drivers/power/pm2301_charger.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/power/pm2301_charger.c b/drivers/power/pm2301_charger.c index 63f515e..4cb8f7f 100644 --- a/drivers/power/pm2301_charger.c +++ b/drivers/power/pm2301_charger.c @@ -34,6 +34,8 @@ #define to_pm2xxx_charger_ac_device_info(x) container_of((x), \ struct pm2xxx_charger, ac_chg) +#define SLEEP_MIN 50 +#define SLEEP_MAX 100 static int pm2xxx_interrupt_registers[] = { PM2XXX_REG_INT1, @@ -113,17 +115,14 @@ static const struct i2c_device_id pm2xxx_ident[] = { static void set_lpn_pin(struct pm2xxx_charger *pm2) { - if (pm2->ac.charger_connected) - return; gpio_set_value(pm2->lpn_pin, 1); + usleep_range(SLEEP_MIN, SLEEP_MAX); return; } static void clear_lpn_pin(struct pm2xxx_charger *pm2) { - if (pm2->ac.charger_connected) - return; gpio_set_value(pm2->lpn_pin, 0); return; @@ -139,7 +138,6 @@ static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val) * and receive I2C "acknowledge" from PM2301. */ mutex_lock(&pm2->lock); - set_lpn_pin(pm2); ret = i2c_smbus_read_i2c_block_data(pm2->config.pm2xxx_i2c, reg, 1, val); @@ -147,7 +145,6 @@ static int pm2xxx_reg_read(struct pm2xxx_charger *pm2, int reg, u8 *val) dev_err(pm2->dev, "Error reading register at 0x%x\n", reg); else ret = 0; - clear_lpn_pin(pm2); mutex_unlock(&pm2->lock); return ret; @@ -163,7 +160,6 @@ static int pm2xxx_reg_write(struct pm2xxx_charger *pm2, int reg, u8 val) * and receive I2C "acknowledge" from PM2301. */ mutex_lock(&pm2->lock); - set_lpn_pin(pm2); ret = i2c_smbus_write_i2c_block_data(pm2->config.pm2xxx_i2c, reg, 1, &val); @@ -171,7 +167,6 @@ static int pm2xxx_reg_write(struct pm2xxx_charger *pm2, int reg, u8 val) dev_err(pm2->dev, "Error writing register at 0x%x\n", reg); else ret = 0; - clear_lpn_pin(pm2); mutex_unlock(&pm2->lock); return ret; @@ -478,7 +473,6 @@ static int pm2_int_reg5(void *pm2_data, int val) struct pm2xxx_charger *pm2 = pm2_data; int ret = 0; - if (val & (PM2XXX_INT6_ITVPWR2DROP | PM2XXX_INT6_ITVPWR1DROP)) { dev_dbg(pm2->dev, "VMPWR drop to VBAT level\n"); } @@ -899,12 +893,34 @@ static struct pm2xxx_irq pm2xxx_charger_irq[] = { static int pm2xxx_wall_charger_resume(struct i2c_client *i2c_client) { + struct pm2xxx_charger *pm2; + + pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client); + set_lpn_pin(pm2); + + /* If we still have a HW failure, schedule a new check */ + if (pm2->flags.ovv) + queue_delayed_work(pm2->charger_wq, + &pm2->check_hw_failure_work, 0); + return 0; } static int pm2xxx_wall_charger_suspend(struct i2c_client *i2c_client, pm_message_t state) { + struct pm2xxx_charger *pm2; + + pm2 = (struct pm2xxx_charger *)i2c_get_clientdata(i2c_client); + clear_lpn_pin(pm2); + + /* Cancel any pending HW failure check */ + if (delayed_work_pending(&pm2->check_hw_failure_work)) + cancel_delayed_work(&pm2->check_hw_failure_work); + + flush_work(&pm2->ac_work); + flush_work(&pm2->check_main_thermal_prot_work); + return 0; } @@ -1056,6 +1072,7 @@ static int __devinit pm2xxx_wall_charger_probe(struct i2c_client *i2c_client, goto free_gpio; } + set_lpn_pin(pm2); ret = pm2xxx_charger_detection(pm2, &val); if ((ret == 0) && val) {