From patchwork Thu Jun 5 09:07:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonghwa Lee X-Patchwork-Id: 4304121 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 34CF39F1D6 for ; Thu, 5 Jun 2014 09:07:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA71F20340 for ; Thu, 5 Jun 2014 09:07:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0DB0E2034E for ; Thu, 5 Jun 2014 09:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751159AbaFEJH2 (ORCPT ); Thu, 5 Jun 2014 05:07:28 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:32897 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbaFEJH0 (ORCPT ); Thu, 5 Jun 2014 05:07:26 -0400 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N6O002BKUOCHVB0@mailout1.samsung.com> for linux-pm@vger.kernel.org; Thu, 05 Jun 2014 18:07:24 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.114]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 31.32.16580.B4330935; Thu, 05 Jun 2014 18:07:24 +0900 (KST) X-AuditID: cbfee691-b7f2f6d0000040c4-a2-5390334b333f Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 43.6A.07139.B4330935; Thu, 05 Jun 2014 18:07:23 +0900 (KST) Received: from localhost.localdomain ([10.252.82.199]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N6O00ICXUO5QXJ0@mmp2.samsung.com>; Thu, 05 Jun 2014 18:07:23 +0900 (KST) From: Jonghwa Lee To: linux-pm@vger.kernel.org Cc: dbaryshkov@gmail.com, dwmw2@infradead.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, Jonghwa Lee Subject: [PATCH v2 4/4] power: max17042_battery: Refactoring max17042 driver Date: Thu, 05 Jun 2014 18:07:10 +0900 Message-id: <1401959231-20940-2-git-send-email-jonghwa3.lee@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1401959231-20940-1-git-send-email-jonghwa3.lee@samsung.com> References: <1401959231-20940-1-git-send-email-jonghwa3.lee@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNLMWRmVeSWpSXmKPExsWyRsSkSNfHeEKwwbYbHBbXvzxntZj05D2z xcSVk5ktOs8+Ybb43HuE0eJ24wo2BzaPnbPusntsXqHl0bdlFaPH501yASxRXDYpqTmZZalF +nYJXBknO5eyFlxpY6y4/PknewNjb0EXIyeHhICJxJInTSwQtpjEhXvr2boYuTiEBJYySlz5 fJIdpuj1hfXMEInpjBLLzneyQjhtTBKzLlwCq2IT0JH4v+8mmC0iICMx9cp+sCJmgQ5GiQ13 +pi6GDk4hAV8JGb8NwOpYRFQlfi0opkZxOYV8JDofPmVFaREQkBBYs4kGxCTU8BTYt95KZAK IaCKK08egx0nIdDPLtE+9xATxBgBiW+TD7FAtMpKbDrADHGzpMTBFTdYJjAKL2BkWMUomlqQ XFCclF5kqlecmFtcmpeul5yfu4kRGNCn/z2buIPx/gHrQ4zJQOMmMkuJJucDIyKvJN7Q2MzI wtTE1NjI3NKMNGElcd70R0lBQgLpiSWp2ampBalF8UWlOanFhxiZODilGhh7psx1efpel6PP ImvNcWEFn1Z9qX1rT/qfuXzxBWeVl1rNnd0Xrrk2hq1bNvnjmgr13wt/nrr62m+q7j+N/i1X rB7dubKhIPFGl8mOy9vl2TaaeR8/8kK4KZA5vHfqzfIMf8PmI0p95yxjOf9wdOrN9d43SXtz Pusi9cuXBDfPCq2RlG749jZYiaU4I9FQi7moOBEA2KnGaX4CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBIsWRmVeSWpSXmKPExsVy+t9jQV1v4wnBBucnWVpc//Kc1WLSk/fM FhNXTma26Dz7hNnic+8RRovbjSvYHNg8ds66y+6xeYWWR9+WVYwenzfJBbBENTDaZKQmpqQW KaTmJeenZOal2yp5B8c7x5uaGRjqGlpamCsp5CXmptoqufgE6Lpl5gAtV1IoS8wpBQoFJBYX K+nbYZoQGuKmawHTGKHrGxIE12NkgAYS1jBmnOxcylpwpY2x4vLnn+wNjL0FXYycHBICJhKv L6xnhrDFJC7cW8/WxcjFISQwnVFi2flOVginjUli1oVL7CBVbAI6Ev/33QSzRQRkJKZe2Q9W xCzQwSix4U4fUxcjB4ewgI/EjP9mIDUsAqoSn1Y0g23gFfCQ6Hz5lRWkREJAQWLOJBsQk1PA U2LfeSmQCiGgiitPHrNNYORdwMiwilE0tSC5oDgpPddIrzgxt7g0L10vOT93EyM4Xp5J72Bc 1WBxiFGAg1GJh3dCQH+wEGtiWXFl7iFGCQ5mJRHepboTgoV4UxIrq1KL8uOLSnNSiw8xJgPd NJFZSjQ5HxjLeSXxhsYmZkaWRuaGFkbG5qQJK4nzHmy1DhQSSE8sSc1OTS1ILYLZwsTBKdXA mJXfJtB+WNd3qu3VfuESi482c/70P7g+sfUu00OnmxGFrQeOFGUb5U5fvlHa4rSD566tszPn bAh89shWZfY5o7kHu69uf/Huu4/TjTIe00Vvomd1/KhpMP/dLbCPP7Fd/qeVT8zcj6eYMntu cTtvqPu/b3bU1V2ec/nn92WqfLh4uONnfaWnpRJLcUaioRZzUXEiAArl89zbAgAA 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.5 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 This patch refactors and optimizes max17042 driver by removing unneccessary wrapping functions and duplicate initialization. Addition to this, it also relocates some codes and functions for better readability. Signed-off-by: Jonghwa Lee Acked-by: Chanwoo Choi Acked-by: MyungJoo Ham --- drivers/power/max17042_battery.c | 362 ++++++++------------------------ include/linux/power/max17042_battery.h | 12 -- 2 files changed, 93 insertions(+), 281 deletions(-) diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c index a30d3c1..d4ec1cd 100644 --- a/drivers/power/max17042_battery.c +++ b/drivers/power/max17042_battery.c @@ -255,106 +255,41 @@ static int max17042_get_property(struct power_supply *psy, static int max17042_write_verify_reg(struct regmap *map, u8 reg, u32 value) { int retries = 8; - int ret; u32 read_value; do { - ret = regmap_write(map, reg, value); - regmap_read(map, reg, &read_value); - if (read_value != value) { - ret = -EIO; - retries--; - } - } while (retries && read_value != value); - - if (ret < 0) - pr_err("%s: err %d\n", __func__, ret); - - return ret; -} - -static inline void max17042_override_por(struct regmap *map, - u8 reg, u16 value) -{ - if (value) regmap_write(map, reg, value); -} - -static inline void max10742_unlock_model(struct max17042_chip *chip) -{ - struct regmap *map = chip->regmap; - regmap_write(map, MAX17042_MLOCKReg1, MODEL_UNLOCK1); - regmap_write(map, MAX17042_MLOCKReg2, MODEL_UNLOCK2); -} - -static inline void max10742_lock_model(struct max17042_chip *chip) -{ - struct regmap *map = chip->regmap; - - regmap_write(map, MAX17042_MLOCKReg1, MODEL_LOCK1); - regmap_write(map, MAX17042_MLOCKReg2, MODEL_LOCK2); -} - -static inline void max17042_write_model_data(struct max17042_chip *chip, - u8 addr, int size) -{ - struct regmap *map = chip->regmap; - int i; - for (i = 0; i < size; i++) - regmap_write(map, addr + i, - chip->pdata->config_data->cell_char_tbl[i]); -} - -static inline void max17042_read_model_data(struct max17042_chip *chip, - u8 addr, u32 *data, int size) -{ - struct regmap *map = chip->regmap; - int i; - - for (i = 0; i < size; i++) - regmap_read(map, addr + i, &data[i]); -} + regmap_read(map, reg, &read_value); + if (read_value == value) + return 0; + } while (--retries); -static inline int max17042_model_data_compare(struct max17042_chip *chip, - u16 *data1, u16 *data2, int size) -{ - int i; + pr_err("%s: failed to update reg(%x)\n", __func__, reg); - if (memcmp(data1, data2, size)) { - dev_err(&chip->client->dev, "%s compare failed\n", __func__); - for (i = 0; i < size; i++) - dev_info(&chip->client->dev, "0x%x, 0x%x", - data1[i], data2[i]); - dev_info(&chip->client->dev, "\n"); - return -EINVAL; - } - return 0; + return -EIO; } static int max17042_init_model(struct max17042_chip *chip) { - int ret; - int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); - u32 *temp_data; - - temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); - if (!temp_data) - return -ENOMEM; + struct max17042_config_data *config = chip->pdata->config_data; + int i, ret = 0; - max10742_unlock_model(chip); - max17042_write_model_data(chip, MAX17042_MODELChrTbl, - table_size); - max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data, - table_size); + /* Unlock model */ + regmap_write(chip->regmap, MAX17042_MLOCKReg1, MODEL_UNLOCK1); + regmap_write(chip->regmap, MAX17042_MLOCKReg2, MODEL_UNLOCK2); - ret = max17042_model_data_compare( - chip, - chip->pdata->config_data->cell_char_tbl, - (u16 *)temp_data, - table_size); + /* Update custom model */ + for (i = 0; i < MAX17042_CHARACTERIZATION_DATA_SIZE; i++) { + ret = max17042_write_verify_reg(chip->regmap, + MAX17042_MODELChrTbl + i, + config->cell_char_tbl[i]); + if (ret) + return ret; + } - max10742_lock_model(chip); - kfree(temp_data); + /* Lock model */ + regmap_write(chip->regmap, MAX17042_MLOCKReg1, MODEL_LOCK1); + regmap_write(chip->regmap, MAX17042_MLOCKReg2, MODEL_LOCK2); return ret; } @@ -362,120 +297,23 @@ static int max17042_init_model(struct max17042_chip *chip) static int max17042_verify_model_lock(struct max17042_chip *chip) { int i; - int table_size = ARRAY_SIZE(chip->pdata->config_data->cell_char_tbl); - u32 *temp_data; - int ret = 0; - - temp_data = kcalloc(table_size, sizeof(*temp_data), GFP_KERNEL); - if (!temp_data) - return -ENOMEM; - - max17042_read_model_data(chip, MAX17042_MODELChrTbl, temp_data, - table_size); - for (i = 0; i < table_size; i++) - if (temp_data[i]) - ret = -EINVAL; - - kfree(temp_data); - return ret; -} - -static void max17042_write_config_regs(struct max17042_chip *chip) -{ - struct max17042_config_data *config = chip->pdata->config_data; - struct regmap *map = chip->regmap; - - regmap_write(map, MAX17042_CONFIG, config->config); - regmap_write(map, MAX17042_LearnCFG, config->learn_cfg); - regmap_write(map, MAX17042_FilterCFG, - config->filter_cfg); - regmap_write(map, MAX17042_RelaxCFG, config->relax_cfg); - if (chip->chip_type == MAX17047) - regmap_write(map, MAX17047_FullSOCThr, - config->full_soc_thresh); -} - -static void max17042_write_custom_regs(struct max17042_chip *chip) -{ - struct max17042_config_data *config = chip->pdata->config_data; - struct regmap *map = chip->regmap; + u32 val; - max17042_write_verify_reg(map, MAX17042_RCOMP0, config->rcomp0); - max17042_write_verify_reg(map, MAX17042_TempCo, config->tcompc0); - max17042_write_verify_reg(map, MAX17042_ICHGTerm, config->ichgt_term); - if (chip->chip_type == MAX17042) { - regmap_write(map, MAX17042_EmptyTempCo, config->empty_tempco); - max17042_write_verify_reg(map, MAX17042_K_empty0, - config->kempty0); - } else { - max17042_write_verify_reg(map, MAX17047_QRTbl00, - config->qrtbl00); - max17042_write_verify_reg(map, MAX17047_QRTbl10, - config->qrtbl10); - max17042_write_verify_reg(map, MAX17047_QRTbl20, - config->qrtbl20); - max17042_write_verify_reg(map, MAX17047_QRTbl30, - config->qrtbl30); + /* After locking model, all registers' value should be zero */ + for (i = 0; i < MAX17042_CHARACTERIZATION_DATA_SIZE; i++) { + regmap_read(chip->regmap, MAX17042_MODELChrTbl + i, &val); + if (val) + return -EIO; } -} - -static void max17042_update_capacity_regs(struct max17042_chip *chip) -{ - struct max17042_config_data *config = chip->pdata->config_data; - struct regmap *map = chip->regmap; - - max17042_write_verify_reg(map, MAX17042_FullCAP, - config->fullcap); - regmap_write(map, MAX17042_DesignCap, config->design_cap); - max17042_write_verify_reg(map, MAX17042_FullCAPNom, - config->fullcapnom); -} - -static void max17042_reset_vfsoc0_reg(struct max17042_chip *chip) -{ - unsigned int vfSoc; - struct regmap *map = chip->regmap; - regmap_read(map, MAX17042_VFSOC, &vfSoc); - regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_UNLOCK); - max17042_write_verify_reg(map, MAX17042_VFSOC0, vfSoc); - regmap_write(map, MAX17042_VFSOC0Enable, VFSOC0_LOCK); + return 0; } -static void max17042_load_new_capacity_params(struct max17042_chip *chip) +static inline void max17042_override_por(struct regmap *map, + u8 reg, u16 value) { - u32 full_cap0, rep_cap, dq_acc, vfSoc; - u32 rem_cap; - - struct max17042_config_data *config = chip->pdata->config_data; - struct regmap *map = chip->regmap; - - regmap_read(map, MAX17042_FullCAP0, &full_cap0); - regmap_read(map, MAX17042_VFSOC, &vfSoc); - - /* fg_vfSoc needs to shifted by 8 bits to get the - * perc in 1% accuracy, to get the right rem_cap multiply - * full_cap0, fg_vfSoc and devide by 100 - */ - rem_cap = ((vfSoc >> 8) * full_cap0) / 100; - max17042_write_verify_reg(map, MAX17042_RemCap, rem_cap); - - rep_cap = rem_cap; - max17042_write_verify_reg(map, MAX17042_RepCap, rep_cap); - - /* Write dQ_acc to 200% of Capacity and dP_acc to 200% */ - dq_acc = config->fullcap / dQ_ACC_DIV; - max17042_write_verify_reg(map, MAX17042_dQacc, dq_acc); - max17042_write_verify_reg(map, MAX17042_dPacc, dP_ACC_200); - - max17042_write_verify_reg(map, MAX17042_FullCAP, - config->fullcap); - regmap_write(map, MAX17042_DesignCap, - config->design_cap); - max17042_write_verify_reg(map, MAX17042_FullCAPNom, - config->fullcapnom); - /* Update SOC register with new SOC */ - regmap_write(map, MAX17042_RepSOC, vfSoc); + if (value) + regmap_write(map, reg, value); } /* @@ -512,27 +350,40 @@ static inline void max17042_override_por_values(struct max17042_chip *chip) max17042_override_por(map, MAX17042_FullCAP, config->fullcap); max17042_override_por(map, MAX17042_FullCAPNom, config->fullcapnom); - if (chip->chip_type == MAX17042) - max17042_override_por(map, MAX17042_SOC_empty, - config->socempty); max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty); - max17042_override_por(map, MAX17042_dQacc, config->dqacc); - max17042_override_por(map, MAX17042_dPacc, config->dpacc); - if (chip->chip_type == MAX17042) - max17042_override_por(map, MAX17042_V_empty, config->vempty); - else - max17042_override_por(map, MAX17047_V_empty, config->vempty); + /* Write dQ_acc to 200% of Capacity and dP_acc to 200% */ + max17042_override_por(map, MAX17042_dQacc, + config->fullcap / dQ_ACC_DIV); + max17042_override_por(map, MAX17042_dPacc, dP_ACC_200); + max17042_override_por(map, MAX17042_TempNom, config->temp_nom); max17042_override_por(map, MAX17042_TempLim, config->temp_lim); max17042_override_por(map, MAX17042_FCTC, config->fctc); max17042_override_por(map, MAX17042_RCOMP0, config->rcomp0); max17042_override_por(map, MAX17042_TempCo, config->tcompc0); - if (chip->chip_type) { + + + if (chip->chip_type == MAX17042) { + max17042_override_por(map, MAX17042_SOC_empty, + config->socempty); + max17042_override_por(map, MAX17042_V_empty, config->vempty); max17042_override_por(map, MAX17042_EmptyTempCo, config->empty_tempco); max17042_override_por(map, MAX17042_K_empty0, config->kempty0); + } else if (chip->chip_type == MAX17047) { + max17042_override_por(map, MAX17047_FullSOCThr, + config->full_soc_thresh); + max17042_override_por(map, MAX17047_V_empty, config->vempty); + max17042_override_por(map, MAX17047_QRTbl00, + config->qrtbl00); + max17042_override_por(map, MAX17047_QRTbl10, + config->qrtbl10); + max17042_override_por(map, MAX17047_QRTbl20, + config->qrtbl20); + max17042_override_por(map, MAX17047_QRTbl30, + config->qrtbl30); } } @@ -540,16 +391,19 @@ static int max17042_init_chip(struct max17042_chip *chip) { struct regmap *map = chip->regmap; int ret; - int val; + long long left_t = 0; + + if (chip->pdata->enable_por_init && chip->pdata->config_data) + goto out; - max17042_override_por_values(chip); /* After Power up, the MAX17042 requires 500mS in order * to perform signal debouncing and initial SOC reporting + * In most cases, max17042 driver is probed after 500ms. */ - msleep(500); - - /* Initialize configaration */ - max17042_write_config_regs(chip); + left_t = jiffies_to_msecs(jiffies - INITIAL_JIFFIES); + left_t -= 500; + if (left_t > 0) + msleep(left_t); /* write cell characterization data */ ret = max17042_init_model(chip); @@ -565,26 +419,18 @@ static int max17042_init_chip(struct max17042_chip *chip) __func__); return -EIO; } - /* write custom parameters */ - max17042_write_custom_regs(chip); - /* update capacity params */ - max17042_update_capacity_regs(chip); + max17042_override_por_values(chip); /* delay must be atleast 350mS to allow VFSOC * to be calculated from the new configuration */ msleep(350); - /* reset vfsoc0 reg */ - max17042_reset_vfsoc0_reg(chip); - - /* load new capacity params */ - max17042_load_new_capacity_params(chip); - +out: /* Init complete, Clear the POR bit */ - regmap_read(map, MAX17042_STATUS, &val); - regmap_write(map, MAX17042_STATUS, val & (~STATUS_POR_BIT)); + regmap_update_bits(map, MAX17042_STATUS, STATUS_POR_BIT, 0); + return 0; } @@ -619,22 +465,6 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) return IRQ_HANDLED; } -static int max17042_init_worker(struct max17042_chip *chip) -{ - struct max17042_chip *chip = container_of(work, - struct max17042_chip, work); - int ret; - - /* Initialize registers according to values from the platform data */ - if (chip->pdata->enable_por_init && chip->pdata->config_data) { - ret = max17042_init_chip(chip); - if (ret) - return ret; - } - - return 0; -} - #ifdef CONFIG_OF static struct max17042_platform_data * max17042_get_pdata(struct device *dev) @@ -680,7 +510,6 @@ static int max17042_probe(struct i2c_client *client, struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); struct max17042_chip *chip; int ret; - int i; u32 val; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) @@ -720,34 +549,6 @@ static int max17042_probe(struct i2c_client *client, dev_dbg(&client->dev, "operates as modelgauge %s\n", chip->mode == MODELGAUGE_M1 ? "M1" : "M3"); - chip->battery.name = "max170xx_battery"; - chip->battery.type = POWER_SUPPLY_TYPE_BATTERY; - chip->battery.get_property = max17042_get_property; - chip->battery.properties = max17042_battery_props; - if (chip->mode == MODELGAUGE_M3) { - /* ModelGauge m3 */ - chip->battery.num_properties = MODELGAUGE_M3_PROPS; - if (chip->pdata->r_sns == 0) - chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR; - } else { - /* ModelGauge m1 */ - chip->battery.num_properties = MODELGAUGE_M1_PROPS; - regmap_write(chip->regmap, MAX17042_CGAIN, 0x0000); - regmap_write(chip->regmap, MAX17042_MiscCFG, 0x0003); - regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007); - - /* Off thermistor - temperature may be externally given */ - regmap_update_bits(chip->regmap, MAX17042_CONFIG, - CONFIG_ETHERM_BIT | CONFIG_TEX_BIT | CONFIG_TEN_BIT, - CONFIG_TEX_BIT); - } - - if (chip->pdata->init_data) - for (i = 0; i < chip->pdata->num_init_data; i++) - regmap_write(chip->regmap, - chip->pdata->init_data[i].addr, - chip->pdata->init_data[i].data); - if (client->irq) { ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, max17042_thread_handler, @@ -767,13 +568,36 @@ static int max17042_probe(struct i2c_client *client, regmap_read(chip->regmap, MAX17042_STATUS, &val); if (val & STATUS_POR_BIT) { - ret = max17042_init_worker(chip); + /* Initialize registers with specified data */ + ret = max17042_init_chip(chip); if (ret) { dev_err(&client->dev, "failed: init chip\n"); return ret; } } + chip->battery.name = "max170xx_battery"; + chip->battery.type = POWER_SUPPLY_TYPE_BATTERY; + chip->battery.get_property = max17042_get_property; + chip->battery.properties = max17042_battery_props; + if (chip->mode == MODELGAUGE_M3) { + /* ModelGauge m3 */ + chip->battery.num_properties = MODELGAUGE_M3_PROPS; + if (chip->pdata->r_sns == 0) + chip->pdata->r_sns = MAX17042_DEFAULT_SNS_RESISTOR; + } else { + /* ModelGauge m1 */ + chip->battery.num_properties = MODELGAUGE_M1_PROPS; + regmap_write(chip->regmap, MAX17042_CGAIN, 0x0000); + regmap_write(chip->regmap, MAX17042_MiscCFG, 0x0003); + regmap_write(chip->regmap, MAX17042_LearnCFG, 0x0007); + + /* Off thermistor - temperature may be externally given */ + regmap_update_bits(chip->regmap, MAX17042_CONFIG, + CONFIG_ETHERM_BIT | CONFIG_TEX_BIT | CONFIG_TEN_BIT, + CONFIG_TEX_BIT); + } + ret = power_supply_register(&client->dev, &chip->battery); if (ret) { dev_err(&client->dev, "failed: power supply register\n"); diff --git a/include/linux/power/max17042_battery.h b/include/linux/power/max17042_battery.h index f8c03c2..7e0c59c 100644 --- a/include/linux/power/max17042_battery.h +++ b/include/linux/power/max17042_battery.h @@ -128,16 +128,6 @@ enum max17047_register { enum max170xx_chip_type {MAX17042, MAX17047}; -/* - * used for setting a register to a desired value - * addr : address for a register - * data : setting value for the register - */ -struct max17042_reg_data { - u8 addr; - u16 data; -}; - struct max17042_config_data { /* External current sense resistor value in milli-ohms */ u32 cur_sense_val; @@ -201,9 +191,7 @@ enum max17042_operation_mode { }; struct max17042_platform_data { - struct max17042_reg_data *init_data; struct max17042_config_data *config_data; - int num_init_data; /* Number of enties in init_data array */ bool enable_por_init; /* Use POR init from Maxim appnote */ enum max17042_operation_mode mode;