From patchwork Wed Sep 17 02:47:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonghwa Lee X-Patchwork-Id: 4922431 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 43ED79F2EC for ; Wed, 17 Sep 2014 02:46:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6DA732017D for ; Wed, 17 Sep 2014 02:48:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B87320160 for ; Wed, 17 Sep 2014 02:48:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755019AbaIQCrm (ORCPT ); Tue, 16 Sep 2014 22:47:42 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:8837 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753919AbaIQCrb (ORCPT ); Tue, 16 Sep 2014 22:47:31 -0400 Received: from epcpsbgr4.samsung.com (u144.gpu120.samsung.co.kr [203.254.230.144]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NC0001MZYF6N270@mailout2.samsung.com>; Wed, 17 Sep 2014 11:47:30 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.115]) by epcpsbgr4.samsung.com (EPCPMTA) with SMTP id CE.99.04442.246F8145; Wed, 17 Sep 2014 11:47:30 +0900 (KST) X-AuditID: cbfee690-f79ce6d00000115a-13-5418f6428e5f Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id F2.0C.05196.246F8145; Wed, 17 Sep 2014 11:47:30 +0900 (KST) Received: from localhost.localdomain ([10.252.82.199]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NC000HGFYF1O370@mmp1.samsung.com>; Wed, 17 Sep 2014 11:47:29 +0900 (KST) From: Jonghwa Lee To: linux-kernel@vger.kernel.org Cc: linux-pm@vger.kernel.org, sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org, anton@enomsg.org, pavel@ucw.cz, Jonghwa Lee Subject: [PATCH 2/2] power: smb347-charger: Support Summit SMB358 charger IC. Date: Wed, 17 Sep 2014 11:47:24 +0900 Message-id: <1410922044-4170-3-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1410922044-4170-1-git-send-email-jonghwa3.lee@samsung.com> References: <1410922044-4170-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOLMWRmVeSWpSXmKPExsWyRsSkWNfpm0SIwfZ/AhYHt2paTHryntli 4srJzBadZ58wW1zeNYfN4nPvEUaLu6eOslmc3l3iwOExof8To8fOWXfZPTav0PLYtKqTzaNv yypGjxWrv7N7fN4kF8AexWWTkpqTWZZapG+XwJUxaeIl1oJ11hUH5u9lamC8q9/FyMkhIWAi 8XPbWlYIW0ziwr31bF2MXBxCAksZJaY37mCCKfrU2M8KkVjEKPHo5HV2CKeNSWLqvdvsIFVs AjoS//fdBLNFBBQkNvc+A+tgFljMKPH01AtmkISwgK/EwmltbCA2i4CqxPbdz8FW8Aq4S/TN uMLSxcgBtE5BYs4kG5Awp4CHxLXZMxlBbCGgkpV/NjJCXLSJXWLxkwyIMQIS3yYfgmqVldh0 gBmiRFLi4IobLBMYhRcwMqxiFE0tSC4oTkovMtErTswtLs1L10vOz93ECAz/0/+eTdjBeO+A 9SFGAQ5GJR7eDZclQoRYE8uKK3MPMZoCbZjILCWanA+MsrySeENjM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qrfp+8Gz5w9sUjuziulXwkHUn64GP++zPhB/upN31j7qLy7qjml506/V2Ip zkg01GIuKk4EAH00YWfFAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Summit microelectronics' SMB358 charger chip has almost same register map and functionality with SMB347. The voltage and current table are only differed. Thus, SMB347 driver can support SMB358 chip fully with few modifications. Signed-off-by: Jonghwa Lee Acked-by : Chanwoo Choi Acked-by : Myungjoo Ham Acked-by: Pavel Machek --- .../bindings/power_supply/smb347_charger.txt | 1 + drivers/power/smb347-charger.c | 98 +++++++++----------- 2 files changed, 47 insertions(+), 52 deletions(-) diff --git a/Documentation/devicetree/bindings/power_supply/smb347_charger.txt b/Documentation/devicetree/bindings/power_supply/smb347_charger.txt index 91570a5..776ae29 100644 --- a/Documentation/devicetree/bindings/power_supply/smb347_charger.txt +++ b/Documentation/devicetree/bindings/power_supply/smb347_charger.txt @@ -3,6 +3,7 @@ smb347_charger bindings [Required porperties] - compatible : "summit,smb347" + "summit,smb358" - reg : Slave address for i2c interface # At least one of followings should be set - enable-usb-charging diff --git a/drivers/power/smb347-charger.c b/drivers/power/smb347-charger.c index 8073879..1bfb115 100644 --- a/drivers/power/smb347-charger.c +++ b/drivers/power/smb347-charger.c @@ -136,6 +136,7 @@ * @pdata: pointer to platform data */ struct smb347_charger { + int id; struct mutex lock; struct device *dev; struct regmap *regmap; @@ -148,58 +149,46 @@ struct smb347_charger { const struct smb347_charger_platform_data *pdata; }; +enum smb_charger_chipid { + SMB347, + SMB358, + NUM_CHIP_TYPES, +}; + /* Fast charge current in uA */ -static const unsigned int fcc_tbl[] = { - 700000, - 900000, - 1200000, - 1500000, - 1800000, - 2000000, - 2200000, - 2500000, +static const unsigned int fcc_tbl[NUM_CHIP_TYPES][8] = { + [SMB347] = { 700000, 900000, 1200000, 1500000, + 1800000, 2000000, 2200000, 2500000 }, + [SMB358] = { 200000, 450000, 600000, 900000, + 1300000, 1500000, 1800000, 2000000 }, }; /* Pre-charge current in uA */ -static const unsigned int pcc_tbl[] = { - 100000, - 150000, - 200000, - 250000, +static const unsigned int pcc_tbl[NUM_CHIP_TYPES][4] = { + [SMB347] = { 100000, 150000, 200000, 250000 }, + [SMB358] = { 150000, 250000, 350000, 450000 }, }; /* Termination current in uA */ -static const unsigned int tc_tbl[] = { - 37500, - 50000, - 100000, - 150000, - 200000, - 250000, - 500000, - 600000, +static const unsigned int tc_tbl[NUM_CHIP_TYPES][8] = { + [SMB347] = { 37500, 50000, 100000, 150000, + 200000, 250000, 500000, 600000 }, + [SMB358] = { 30000, 40000, 60000, 80000, + 100000, 125000, 150000, 200000 }, }; /* Input current limit in uA */ -static const unsigned int icl_tbl[] = { - 300000, - 500000, - 700000, - 900000, - 1200000, - 1500000, - 1800000, - 2000000, - 2200000, - 2500000, +static const unsigned int icl_tbl[NUM_CHIP_TYPES][10] = { + [SMB347] = { 300000, 500000, 700000, 900000, 1200000, + 1500000, 1800000, 2000000, 2200000, 2500000 }, + [SMB358] = { 300000, 500000, 700000, 1000000, 1500000, + 1800000, 2000000, 2000000, 2000000, 2000000 }, }; /* Charge current compensation in uA */ -static const unsigned int ccc_tbl[] = { - 250000, - 700000, - 900000, - 1200000, +static const unsigned int ccc_tbl[NUM_CHIP_TYPES][4] = { + [SMB347] = { 250000, 700000, 900000, 1200000 }, + [SMB358] = { 200000, 450000, 600000, 900000 }, }; /* Convert register value to current using lookup table */ @@ -354,10 +343,10 @@ static int smb347_start_stop_charging(struct smb347_charger *smb) static int smb347_set_charge_current(struct smb347_charger *smb) { - int ret; + int ret, id = smb->id; if (smb->pdata->max_charge_current) { - ret = current_to_hw(fcc_tbl, ARRAY_SIZE(fcc_tbl), + ret = current_to_hw(fcc_tbl[id], ARRAY_SIZE(fcc_tbl[id]), smb->pdata->max_charge_current); if (ret < 0) return ret; @@ -370,7 +359,7 @@ static int smb347_set_charge_current(struct smb347_charger *smb) } if (smb->pdata->pre_charge_current) { - ret = current_to_hw(pcc_tbl, ARRAY_SIZE(pcc_tbl), + ret = current_to_hw(pcc_tbl[id], ARRAY_SIZE(pcc_tbl[id]), smb->pdata->pre_charge_current); if (ret < 0) return ret; @@ -383,7 +372,7 @@ static int smb347_set_charge_current(struct smb347_charger *smb) } if (smb->pdata->termination_current) { - ret = current_to_hw(tc_tbl, ARRAY_SIZE(tc_tbl), + ret = current_to_hw(tc_tbl[id], ARRAY_SIZE(tc_tbl[id]), smb->pdata->termination_current); if (ret < 0) return ret; @@ -399,10 +388,10 @@ static int smb347_set_charge_current(struct smb347_charger *smb) static int smb347_set_current_limits(struct smb347_charger *smb) { - int ret; + int ret, id = smb->id; if (smb->pdata->mains_current_limit) { - ret = current_to_hw(icl_tbl, ARRAY_SIZE(icl_tbl), + ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]), smb->pdata->mains_current_limit); if (ret < 0) return ret; @@ -415,7 +404,7 @@ static int smb347_set_current_limits(struct smb347_charger *smb) } if (smb->pdata->usb_hc_current_limit) { - ret = current_to_hw(icl_tbl, ARRAY_SIZE(icl_tbl), + ret = current_to_hw(icl_tbl[id], ARRAY_SIZE(icl_tbl[id]), smb->pdata->usb_hc_current_limit); if (ret < 0) return ret; @@ -467,7 +456,7 @@ static int smb347_set_temp_limits(struct smb347_charger *smb) { bool enable_therm_monitor = false; int ret = 0; - int val; + int val, id = smb->id; if (smb->pdata->chip_temp_threshold) { val = smb->pdata->chip_temp_threshold; @@ -589,7 +578,7 @@ static int smb347_set_temp_limits(struct smb347_charger *smb) } if (smb->pdata->charge_current_compensation) { - val = current_to_hw(ccc_tbl, ARRAY_SIZE(ccc_tbl), + val = current_to_hw(ccc_tbl[id], ARRAY_SIZE(ccc_tbl[id]), smb->pdata->charge_current_compensation); if (val < 0) return val; @@ -879,7 +868,7 @@ out: */ static int get_const_charge_current(struct smb347_charger *smb) { - int ret, intval; + int ret, intval, id = smb->id; unsigned int v; if (!smb347_is_ps_online(smb)) @@ -894,10 +883,12 @@ static int get_const_charge_current(struct smb347_charger *smb) * and we can detect which table to use from bit 5. */ if (v & 0x20) { - intval = hw_to_current(fcc_tbl, ARRAY_SIZE(fcc_tbl), v & 7); + intval = hw_to_current(fcc_tbl[id], + ARRAY_SIZE(fcc_tbl[id]), v & 7); } else { v >>= 3; - intval = hw_to_current(pcc_tbl, ARRAY_SIZE(pcc_tbl), v & 7); + intval = hw_to_current(pcc_tbl[id], + ARRAY_SIZE(pcc_tbl[id]), v & 7); } return intval; @@ -1282,6 +1273,7 @@ static int smb347_probe(struct i2c_client *client, i2c_set_clientdata(client, smb); mutex_init(&smb->lock); + smb->id = id->driver_data; smb->dev = &client->dev; smb->regmap = devm_regmap_init_i2c(client, &smb347_regmap); @@ -1369,7 +1361,8 @@ static int smb347_remove(struct i2c_client *client) } static const struct i2c_device_id smb347_id[] = { - { "smb347", 0 }, + { "smb347", SMB347 }, + { "smb358", SMB358 }, { } }; MODULE_DEVICE_TABLE(i2c, smb347_id); @@ -1377,6 +1370,7 @@ MODULE_DEVICE_TABLE(i2c, smb347_id); #ifdef CONFIG_OF static struct of_device_id of_smb347_ids[] = { { .compatible = "summit,smb347" }, + { .compatible = "summit,smb358" }, {}, }; #endif