ARM: dts: qcom: Add binding for the qcom coincell charger
PATCH v2 1/3 ARM: dts: qcom: Add binding for the qcom coincell charger
This binding is used to configure the driver for the coincell charger found in Qualcomm PMICs.
---
Changes in v2:
- remove 'qcom,' from example node name
- Added reference to parent node pm8941@0 and binding doc for it
.../bindings/power/qcom,coincell-charger.txt | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/qcom,coincell-charger.txt
Documentation/devicetree/bindings/power/qcom,coincell-charger.txt new file +50 -0
@@ -0,0 +1,50 @@ +Qualcomm Coincell Charger: + +The hardware block controls charging for a coincell or capacitor that is +used to provide power backup for certain features of the power management +IC (PMIC) + +- compatible: + Usage: required + Value type: <string> + Definition: must be: "qcom,pm8941-coincell" + +- reg: + Usage: required + Value type: <u32> + Definition: base address of the coincell charger registers + +- qcom,rset-ohms: + Usage: required + Value type: <u32> + Definition: resistance (in ohms) for current-limiting resistor + must be one of: 800, 1200, 1700, 2100 + +- qcom,vset-millivolts: + Usage: required + Value type: <u32> + Definition: voltage (in millivolts) to apply for charging + must be one of: 2500, 3000, 3100, 3200 + +- qcom,charge-enable: + Usage: optional + Value type: <u32> or <none> + Definition: definining this property, with an optional non-zero + value, enables charging + +This charger is a sub-node of one of the 8941 PMIC blocks, and is specified +as a child node in DTS of that node. See ../mfd/qcom,spmi-pmic.txt and +../mfd/qcom-pm8xxx.txt + +Examples: + + pm8941@0 { + coincell@2800 { + compatible = "qcom,pm8941-coincell"; + reg = <0x2800>; + + qcom,rset-ohms = <2100>; + qcom,vset-millivolts = <3000>; + qcom,charge-enable; + }; + };
Signature · 1 line
1.8.2.2
PATCH v2 2/3 ARM: qcom: Add coincell charger driver
This driver is used to configure the coincell charger found in Qualcomm PMICs.
The driver allows configuring the current-limiting resistor for the charger, as well as the voltage to apply to the coincell (or capacitor) when charging.
---
Changes in v2:
- (none in this file, but dts changes in 1/3 and 3/3)
drivers/misc/Kconfig | 11 ++++ drivers/misc/Makefile | 1 + drivers/misc/qcom-coincell.c | 154 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 drivers/misc/qcom-coincell.c
drivers/misc/Kconfig +11 -0
@@ -271,6 +271,17 @@ config HP_ILO To compile this driver as a module, choose M here: the module will be called hpilo. +config QCOM_COINCELL + tristate "Qualcomm coincell charger support" + depends on OF + select REGMAP + help + This driver supports the coincell block found inside of + Qualcomm PMICs. The coincell charger provides a means to + charge a coincell battery or backup capacitor which is used + to maintain PMIC register and RTC state in the absence of + external power. + config SGI_GRU tristate "SGI GRU driver" depends on X86_UV && SMP
drivers/misc/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_LKDTM) += lkdtm.o obj-$(CONFIG_TIFM_CORE) += tifm_core.o obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o obj-$(CONFIG_PHANTOM) += phantom.o +obj-$(CONFIG_QCOM_COINCELL) += qcom-coincell.o obj-$(CONFIG_SENSORS_BH1780) += bh1780gli.o obj-$(CONFIG_SENSORS_BH1770) += bh1770glc.o obj-$(CONFIG_SENSORS_APDS990X) += apds990x.o
drivers/misc/qcom-coincell.c new file +154 -0
154 lines not on this page · raw message
Signature · 1 line
1.8.2.2
Re: [PATCH v2 2/3] ARM: qcom: Add coincell charger driver
Quoted 8 lines · Tim Bird
3 files changed, 166 insertions(+)create mode 100644
drivers/misc/qcom-coincell.cdrivers/misc/Kconfig +0
-0
drivers/misc/Kconfig config HP_ILO · line 276
Quoted 6 lines
drivers/misc/Kconfig +3
-0@@ -271,6 +271,17 @@ config HP_ILO To compile this driver as a module, choose M here: the module will be called hpilo. +config QCOM_COINCELL + tristate "Qualcomm coincell charger support" + depends on OF
It looks like it would compile fine without OF, so can we drop this dependency? Or make it into
depends on MFD_SPMI_PMIC || COMPILE_TEST
?
Quoted 54 lines
drivers/misc/Kconfig +8
-0+ select REGMAP + help + This driver supports the coincell block found inside of + Qualcomm PMICs. The coincell charger provides a means to + charge a coincell battery or backup capacitor which is used + to maintain PMIC register and RTC state in the absence of + external power. + config SGI_GRU tristate "SGI GRU driver" depends on X86_UV && SMPdrivers/misc/Makefile +1
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_LKDTM) += lkdtm.o obj-$(CONFIG_TIFM_CORE) += tifm_core.o obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o obj-$(CONFIG_PHANTOM) += phantom.o +obj-$(CONFIG_QCOM_COINCELL) += qcom-coincell.o obj-$(CONFIG_SENSORS_BH1780) += bh1780gli.o obj-$(CONFIG_SENSORS_BH1770) += bh1770glc.o obj-$(CONFIG_SENSORS_APDS990X) += apds990x.odrivers/misc/qcom-coincell.c new file +25
-0@@ -0,0 +1,154 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* Copyright (c) 2015, Sony Mobile Communications Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regmap.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> + +struct qcom_coincell { +struct device *dev; +struct regmap *regmap; +u32 base_addr;
drivers/misc/qcom-coincell.c line 35
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+}; + +#define QCOM_COINCELL_REG_RSET 0x44 +#define QCOM_COINCELL_REG_VSET 0x45 +#define QCOM_COINCELL_REG_ENABLE 0x46 + +#define QCOM_COINCELL_ENABLE BIT(7) + +static const int qcom_rset_map[] = {2100 ,1700 ,1200 ,800 }; +static const int qcom_vset_map[] = {2500 ,3200 ,3100 ,3000 };
Nitpick: put spaces around those braces.
drivers/misc/qcom-coincell.c line 39
Quoted 4 lines
drivers/misc/qcom-coincell.c new file +4
-0+/* NOTE: for pm8921 and others, voltage of 2500 is 16 (10000b), not 0 */ + +static int qcom_coincell_chgr_config (struct qcom_coincell *chgr,int rset, +int vset,int enable)
bool enable?
Quoted 9 lines
drivers/misc/qcom-coincell.c new file +9
-0+{ +int i, rc; +unsigned int value; + +/* select current-limiting resistor */ +for (i =0 ; i <ARRAY_SIZE (qcom_rset_map); i++) +if (rset == qcom_rset_map[i]) +break ; +
drivers/misc/qcom-coincell.c line 58
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+if (i >=ARRAY_SIZE (qcom_rset_map)) { +dev_err (chgr->dev,"invalid rset-ohms value %d\n" , rset); +return -EINVAL ; + } + + rc =regmap_write (chgr->regmap, + chgr->base_addr +QCOM_COINCELL_REG_RSET , i); +if (rc) +dev_err (chgr->dev,"could not write to RSET register\n" ); +return rc;
Missing braces?
Quoted 6 lines
drivers/misc/qcom-coincell.c new file +6
-0+ +/* select charge voltage */ +for (i =0 ; i <ARRAY_SIZE (qcom_vset_map); i++) +if (vset == qcom_vset_map[i]) +break ; +
drivers/misc/qcom-coincell.c line 74
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+if (i >=ARRAY_SIZE (qcom_vset_map)) { +dev_err (chgr->dev,"invalid vset-millivolts value %d\n" , vset); +return -EINVAL ; + } + + rc =regmap_write (chgr->regmap, + chgr->base_addr +QCOM_COINCELL_REG_VSET , i); +if (rc) +dev_err (chgr->dev,"could not write to VSET register\n" ); +return rc;
Missing braces? I guess this hardware just works out of the bootloader after the resistor is configured?
drivers/misc/qcom-coincell.c line 82
Quoted 8 lines
drivers/misc/qcom-coincell.c new file +8
-0+ +/* set 'enable' register */ + value = enable ?QCOM_COINCELL_ENABLE :0 ; + rc =regmap_write (chgr->regmap, + chgr->base_addr +QCOM_COINCELL_REG_ENABLE , value); +if (rc) +dev_err (chgr->dev,"could not write to ENABLE register\n" ); +
Honestly these printks seems pretty useless and could probably be left out.
Quoted 4 lines
drivers/misc/qcom-coincell.c new file +4
-0+return rc; +} + +static int qcom_coincell_probe (struct platform_device *pdev)
drivers/misc/qcom-coincell.c line 96
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+{ +struct device_node *node = pdev->dev.of_node; +struct qcom_coincell *chgr; +u32 rset, vset, enable; +int rc; + +if (!node) { +dev_err (&pdev->dev,"%s: device node missing\n" , __func__); +return -ENODEV ; + }
Does this happen?
Quoted 21 lines
drivers/misc/qcom-coincell.c new file +21
-0+ + chgr =devm_kzalloc (&pdev->dev,sizeof (*chgr),GFP_KERNEL ); +if (!chgr) +return -ENOMEM ; + + chgr->dev = &pdev->dev; + + chgr->regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!chgr->regmap) { +dev_err (chgr->dev,"Unable to get regmap\n" ); +return -EINVAL ; + } + + rc =of_property_read_u32 (node,"reg" , &chgr->base_addr); +if (rc) +return rc; + + rc =of_property_read_u32 (node,"qcom,rset-ohms" , &rset); +if (rc) { +dev_err (chgr->dev,"can't find 'qcom,rset-ohms' in DT block" ); +return rc;
drivers/misc/qcom-coincell.c line 127
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+ } + + rc =of_property_read_u32 (node,"qcom,vset-millivolts" , &vset); +if (rc) { +dev_err (chgr->dev, +"can't find 'qcom,vset-millivolts' in DT block" ); +return rc; + } + + rc =of_property_read_u32 (node,"qcom,charge-enable" , &enable);
This should be a bool:
enable = of_property_read_bool(node, "qcom,charge-enable");
Quoted 8 lines
drivers/misc/qcom-coincell.c new file +8
-0+if (rc) + enable =0 ; + + rc =qcom_coincell_chgr_config (chgr, rset, vset, enable); + +return rc; +} +
drivers/misc/qcom-coincell.c line 145
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+static const struct of_device_id qcom_coincell_match_table[] = { + { .compatible ="qcom,pm8941-coincell" , }, + {} +}; + +MODULE_DEVICE_TABLE (of, qcom_coincell_match_table); + +static struct platform_driver qcom_coincell_driver = { + .driver = { + .name ="qcom,pm8941-coincell" ,
Maybe a better driver name would be qcom-spmi-coincell?
Signature · 7 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 2/3] ARM: qcom: Add coincell charger driver
Quoted 20 lines · Stephen Boyd
Quoted 8 lines · Tim Bird
3 files changed, 166 insertions(+)create mode 100644
drivers/misc/qcom-coincell.cdrivers/misc/Kconfig +0
-0drivers/misc/Kconfig config HP_ILO · line 276
Quoted 6 lines
drivers/misc/Kconfig +3
-0@@ -271,6 +271,17 @@ config HP_ILO To compile this driver as a module, choose M here: the module will be called hpilo. +config QCOM_COINCELL + tristate "Qualcomm coincell charger support" + depends on OFIt looks like it would compile fine without OF, so can we drop this dependency? Or make it into
Quoted 3 lines
depends on MFD_SPMI_PMIC || COMPILE_TEST?
I think I had CONFIG_OF off one time, and I spent the better part of the afternoon trying to figure out why the driver wasn't loading. So it compiles but doesn't actually work. But I think a dependency on MFD_SPMI_PMIC solves this issue. So, OK on the second suggestion.
Quoted 59 lines
Quoted 59 lines
drivers/misc/Kconfig +8
-0+ select REGMAP + help + This driver supports the coincell block found inside of + Qualcomm PMICs. The coincell charger provides a means to + charge a coincell battery or backup capacitor which is used + to maintain PMIC register and RTC state in the absence of + external power. + config SGI_GRU tristate "SGI GRU driver" depends on X86_UV && SMPdrivers/misc/Makefile +1
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_LKDTM) += lkdtm.o obj-$(CONFIG_TIFM_CORE) += tifm_core.o obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o obj-$(CONFIG_PHANTOM) += phantom.o +obj-$(CONFIG_QCOM_COINCELL) += qcom-coincell.o obj-$(CONFIG_SENSORS_BH1780) += bh1780gli.o obj-$(CONFIG_SENSORS_BH1770) += bh1770glc.o obj-$(CONFIG_SENSORS_APDS990X) += apds990x.odrivers/misc/qcom-coincell.c new file +29
-0@@ -0,0 +1,154 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* Copyright (c) 2015, Sony Mobile Communications Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regmap.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> + +struct qcom_coincell { +struct device *dev; +struct regmap *regmap; +u32 base_addr; +}; + +#define QCOM_COINCELL_REG_RSET 0x44 +#define QCOM_COINCELL_REG_VSET 0x45
Quoted 8 lines
drivers/misc/qcom-coincell.c line 35
Quoted 6 lines
drivers/misc/qcom-coincell.c new file +6
-0+#define QCOM_COINCELL_REG_ENABLE 0x46 + +#define QCOM_COINCELL_ENABLE BIT(7) + +static const int qcom_rset_map[] = {2100 ,1700 ,1200 ,800 }; +static const int qcom_vset_map[] = {2500 ,3200 ,3100 ,3000 };Nitpick: put spaces around those braces.
OK. I presume you mean like this:
{ 2100, 1700, 1200, 800 };
Quoted 7 lines
drivers/misc/qcom-coincell.c line 39
Quoted 4 lines
drivers/misc/qcom-coincell.c new file +4
-0+/* NOTE: for pm8921 and others, voltage of 2500 is 16 (10000b), not 0 */ + +static int qcom_coincell_chgr_config (struct qcom_coincell *chgr,int rset, +int vset,int enable)bool enable?
OK
Quoted 13 lines
Quoted 13 lines
drivers/misc/qcom-coincell.c new file +13
-0+{ +int i, rc; +unsigned int value; + +/* select current-limiting resistor */ +for (i =0 ; i <ARRAY_SIZE (qcom_rset_map); i++) +if (rset == qcom_rset_map[i]) +break ; + +if (i >=ARRAY_SIZE (qcom_rset_map)) { +dev_err (chgr->dev,"invalid rset-ohms value %d\n" , rset); +return -EINVAL ; + }
Quoted 9 lines
drivers/misc/qcom-coincell.c line 58
Quoted 6 lines
drivers/misc/qcom-coincell.c new file +6
-0+ + rc =regmap_write (chgr->regmap, + chgr->base_addr +QCOM_COINCELL_REG_RSET , i); +if (rc) +dev_err (chgr->dev,"could not write to RSET register\n" ); +return rc;Missing braces?
Ouch! Yes. Thanks.
<rant - mostly at myself>
Of all the kernel CodingStyle rules, the one I absolutely hate is not using braces on single statement blocks. It trips me up like this a lot. Maybe I should add a checkpatch rule to catch this kind of thing. </rant>
Quoted 11 lines
Quoted 11 lines
drivers/misc/qcom-coincell.c new file +11
-0+ +/* select charge voltage */ +for (i =0 ; i <ARRAY_SIZE (qcom_vset_map); i++) +if (vset == qcom_vset_map[i]) +break ; + +if (i >=ARRAY_SIZE (qcom_vset_map)) { +dev_err (chgr->dev,"invalid vset-millivolts value %d\n" , vset); +return -EINVAL ; + } +
Quoted 8 lines
drivers/misc/qcom-coincell.c line 74
Quoted 5 lines
drivers/misc/qcom-coincell.c new file +5
-0+ rc =regmap_write (chgr->regmap, + chgr->base_addr +QCOM_COINCELL_REG_VSET , i); +if (rc) +dev_err (chgr->dev,"could not write to VSET register\n" ); +return rc;Missing braces? I guess this hardware just works out of the bootloader after the resistor is configured?
Yes, again. Doh!
I swear I tested the register values after loading the driver with different rset and vset values, to make sure they were taking effect. But that was on a dragonboard with no actual coincell present. I was too chicken to mess with the values on an actual phone (since I can't actually change the capacitor used for this, and didn't want to damage it with the wrong values.)
I must have done the value testing before messing up my braces. Sorry!
Will fix. Also, I will repeat testing of the values taking effect, on the next iteration.
Quoted 10 lines
drivers/misc/qcom-coincell.c line 82
Quoted 8 lines
drivers/misc/qcom-coincell.c new file +8
-0+ +/* set 'enable' register */ + value = enable ?QCOM_COINCELL_ENABLE :0 ; + rc =regmap_write (chgr->regmap, + chgr->base_addr +QCOM_COINCELL_REG_ENABLE , value); +if (rc) +dev_err (chgr->dev,"could not write to ENABLE register\n" ); +Honestly these printks seems pretty useless and could probably be left out.
I'm torn. This driver and hardware is simple enough that the most likely thing these printks will catch is a mis-configured "reg" value in the DTS, and that would apply to most of these printks. Inability to write to a valid register should be pretty rare.
I *would* like to visibly flag that case somehow, as I'm loathe to have some DTS author have to traipse through kernel code to figure out where the error is coming from. I'm not sure, but I think things are pretty quiet on probe errors, and if I don't print something, it makes a lot of work for a developer to find the problem, when all they've done is mistyped something in the DTS.
Quoted 8 lines
Quoted 8 lines
drivers/misc/qcom-coincell.c new file +8
-0+return rc; +} + +static int qcom_coincell_probe (struct platform_device *pdev) +{ +struct device_node *node = pdev->dev.of_node; +struct qcom_coincell *chgr; +u32 rset, vset, enable;
Quoted 8 lines
drivers/misc/qcom-coincell.c line 96
Quoted 6 lines
drivers/misc/qcom-coincell.c new file +6
-0+int rc; + +if (!node) { +dev_err (&pdev->dev,"%s: device node missing\n" , __func__); +return -ENODEV ; + }Does this happen?
Probably not any more. The only way this device gets initialized now is via OF operations. This code was forward-ported from when this driver also operated as a platform device. In the current situation, I don't know of a way for the kernel to get here if of_node is missing (but I'm not an OF expert, and I didn't want to start using
a NULL of_node.)
What does of_property_read...() do with a NULL node?
I'm a little leery of taking this check out, but if you think it's OK I'm fine doing it.
Quoted 35 lines
Quoted 22 lines
drivers/misc/qcom-coincell.c new file +21
-0+ + chgr =devm_kzalloc (&pdev->dev,sizeof (*chgr),GFP_KERNEL ); +if (!chgr) +return -ENOMEM ; + + chgr->dev = &pdev->dev; + + chgr->regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!chgr->regmap) { +dev_err (chgr->dev,"Unable to get regmap\n" ); +return -EINVAL ; + } + + rc =of_property_read_u32 (node,"reg" , &chgr->base_addr); +if (rc) +return rc; + + rc =of_property_read_u32 (node,"qcom,rset-ohms" , &rset); +if (rc) { +dev_err (chgr->dev,"can't find 'qcom,rset-ohms' in DT block" ); +return rc;drivers/misc/qcom-coincell.c line 127
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+ } + + rc =of_property_read_u32 (node,"qcom,vset-millivolts" , &vset); +if (rc) { +dev_err (chgr->dev, +"can't find 'qcom,vset-millivolts' in DT block" ); +return rc; + } + + rc =of_property_read_u32 (node,"qcom,charge-enable" , &enable);This should be a bool:
Quoted 1 line
enable = of_property_read_bool(node, "qcom,charge-enable");
OK.
Quoted 12 lines
Quoted 12 lines
drivers/misc/qcom-coincell.c new file +12
-0+if (rc) + enable =0 ; + + rc =qcom_coincell_chgr_config (chgr, rset, vset, enable); + +return rc; +} + +static const struct of_device_id qcom_coincell_match_table[] = { + { .compatible ="qcom,pm8941-coincell" , }, + {} +};
Quoted 8 lines
drivers/misc/qcom-coincell.c line 145
Quoted 6 lines
drivers/misc/qcom-coincell.c new file +6
-0+ +MODULE_DEVICE_TABLE (of, qcom_coincell_match_table); + +static struct platform_driver qcom_coincell_driver = { + .driver = { + .name ="qcom,pm8941-coincell" ,Maybe a better driver name would be qcom-spmi-coincell?
OK by me.
Thanks for the review!!
-- Tim
Re: [PATCH v2 2/3] ARM: qcom: Add coincell charger driver
Quoted 23 lines · Tim Bird
Quoted 21 lines · Stephen Boyd
Quoted 8 lines · Tim Bird
3 files changed, 166 insertions(+)create mode 100644
drivers/misc/qcom-coincell.cdrivers/misc/Kconfig +0
-0drivers/misc/Kconfig config HP_ILO · line 276
Quoted 6 lines
drivers/misc/Kconfig +3
-0@@ -271,6 +271,17 @@ config HP_ILO To compile this driver as a module, choose M here: the module will be called hpilo. +config QCOM_COINCELL + tristate "Qualcomm coincell charger support" + depends on OFIt looks like it would compile fine without OF, so can we drop this dependency? Or make it into
depends on MFD_SPMI_PMIC || COMPILE_TEST
Quoted 8 lines
Quoted 1 line
?
I think I had
CONFIG_OFoff one time, and I spent the better part of the afternoon trying to figure out why the driver wasn't loading. So it compiles but doesn't actually work. But I think a dependency onMFD_SPMI_PMICsolves this issue. So, OK on the second suggestion.Quoted 1 line
drivers/misc/Kconfig config HP_ILO · line 277
Quoted 1 line
drivers/misc/Kconfig +1
-0+ select REGMAP
This config wouldn't be necessary either then because it would be selected implicitly by the SPMI parent driver.
Quoted 42 lines
Quoted 34 lines
Quoted 34 lines
drivers/misc/qcom-coincell.c new file +28
-0@@ -0,0 +1,154 @@ +/* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* Copyright (c) 2015, Sony Mobile Communications Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/of.h> +#include <linux/regmap.h> +#include <linux/of_device.h> +#include <linux/platform_device.h> + +struct qcom_coincell { +struct device *dev; +struct regmap *regmap; +u32 base_addr; +}; + +#define QCOM_COINCELL_REG_RSET 0x44Quoted 8 lines
drivers/misc/qcom-coincell.c line 35
Quoted 7 lines
drivers/misc/qcom-coincell.c new file +7
-0+#define QCOM_COINCELL_REG_VSET 0x45 +#define QCOM_COINCELL_REG_ENABLE 0x46 + +#define QCOM_COINCELL_ENABLE BIT(7) + +static const int qcom_rset_map[] = {2100 ,1700 ,1200 ,800 }; +static const int qcom_vset_map[] = {2500 ,3200 ,3100 ,3000 };Nitpick: put spaces around those braces.
Quoted 2 lines
OK. I presume you mean like this:
{ 2100, 1700, 1200, 800 };
Yep.
Quoted 17 lines
Quoted 17 lines
Quoted 6 lines
drivers/misc/qcom-coincell.c new file +4
-0+return rc; +} + +static int qcom_coincell_probe (struct platform_device *pdev)drivers/misc/qcom-coincell.c line 96
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+{ +struct device_node *node = pdev->dev.of_node; +struct qcom_coincell *chgr; +u32 rset, vset, enable; +int rc; + +if (!node) { +dev_err (&pdev->dev,"%s: device node missing\n" , __func__); +return -ENODEV ; + }Does this happen?
Quoted 8 lines
Probably not any more. The only way this device gets initialized now is via OF operations. This code was forward-ported from when this driver also operated as a platform device. In the current situation, I don't know of a way for the kernel to get here if
of_nodeis missing (but I'm not an OF expert, and I didn't want to start using
a NULLof_node.)What does of_property_read...() do with a NULL node?
I'm pretty sure it returns success or nothing when the node is NULL.
Quoted 3 lines
I'm a little leery of taking this check out, but if you think it's OK I'm fine doing it.
I'll fix any problems with the removal of the check :)
Quoted 35 lines
Quoted 34 lines
Quoted 22 lines
drivers/misc/qcom-coincell.c new file +21
-0+ + chgr =devm_kzalloc (&pdev->dev,sizeof (*chgr),GFP_KERNEL ); +if (!chgr) +return -ENOMEM ; + + chgr->dev = &pdev->dev; + + chgr->regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!chgr->regmap) { +dev_err (chgr->dev,"Unable to get regmap\n" ); +return -EINVAL ; + } + + rc =of_property_read_u32 (node,"reg" , &chgr->base_addr); +if (rc) +return rc; + + rc =of_property_read_u32 (node,"qcom,rset-ohms" , &rset); +if (rc) { +dev_err (chgr->dev,"can't find 'qcom,rset-ohms' in DT block" ); +return rc;drivers/misc/qcom-coincell.c line 127
Quoted 10 lines
drivers/misc/qcom-coincell.c new file +10
-0+ } + + rc =of_property_read_u32 (node,"qcom,vset-millivolts" , &vset); +if (rc) { +dev_err (chgr->dev, +"can't find 'qcom,vset-millivolts' in DT block" ); +return rc; + } + + rc =of_property_read_u32 (node,"qcom,charge-enable" , &enable);This should be a bool:
Quoted 1 line
enable = of_property_read_bool(node, "qcom,charge-enable");
Quoted 8 lines
OK.
Quoted 6 lines
drivers/misc/qcom-coincell.c line 133
Quoted 6 lines
drivers/misc/qcom-coincell.c new file +6
-0+if (rc) + enable =0 ; + + rc =qcom_coincell_chgr_config (chgr, rset, vset, enable); + +return rc;
This could be simplified to a return qcom_coincell_chrg_config() too.
Also, do we even need the chgr structure allocated anywhere besides on the stack? It seems that it will be memory that's just lying around for no use after probe.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v2 2/3] ARM: qcom: Add coincell charger driver
Quoted 31 lines · Stephen Boyd
Quoted 30 lines · Tim Bird
Quoted 19 lines · Stephen Boyd
Quoted 8 lines · Tim Bird
3 files changed, 166 insertions(+)create mode 100644
drivers/misc/qcom-coincell.cdrivers/misc/Kconfig +0
-0drivers/misc/Kconfig config HP_ILO · line 276
Quoted 6 lines
drivers/misc/Kconfig +3
-0@@ -271,6 +271,17 @@ config HP_ILO To compile this driver as a module, choose M here: the module will be called hpilo. +config QCOM_COINCELL + tristate "Qualcomm coincell charger support" + depends on OFIt looks like it would compile fine without OF, so can we drop this dependency? Or make it into
Quoted 3 lines
depends on MFD_SPMI_PMIC || COMPILE_TEST?
I think I had
CONFIG_OFoff one time, and I spent the better part of the afternoon trying to figure out why the driver wasn't loading. So it compiles but doesn't actually work. But I think a dependency onMFD_SPMI_PMICsolves this issue. So, OK on the second suggestion.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
drivers/misc/Kconfig config HP_ILO · line 277
Quoted 1 line
drivers/misc/Kconfig +1
-0+ select REGMAPThis config wouldn't be necessary either then because it would be selected implicitly by the SPMI parent driver.
OK. I seem to recall having problems with this with an earlier kernel version, but it looks like the parent does indeed have a "select REMAP_SPMI" now. So I'll get rid of this here.
[...]
Quoted 24 lines
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
drivers/misc/Kconfig +7
-0+ return rc; +} + +static int qcom_coincell_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + struct qcom_coincell *chgr;Quoted 8 lines
drivers/misc/Kconfig config HP_ILO
Quoted 7 lines
drivers/misc/Kconfig +7
-0+ u32 rset, vset, enable; + int rc; + + if (!node) { + dev_err(&pdev->dev, "%s: device node missing\n", __func__); + return -ENODEV; + }Does this happen?
Quoted 8 lines
Probably not any more. The only way this device gets initialized now is via OF operations. This code was forward-ported from when this driver also operated as a platform device. In the current situation, I don't know of a way for the kernel to get here if
of_nodeis missing (but I'm not an OF expert, and I didn't want to start using
a NULLof_node.)What does of_property_read...() do with a NULL node?
Quoted 7 lines
I'm pretty sure it returns success or nothing when the node is NULL.
Quoted 3 lines
I'm a little leery of taking this check out, but if you think it's OK I'm fine doing it.
I'll fix any problems with the removal of the check :)
LOL. It's a deal! :-)
[...]
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
drivers/misc/Kconfig
Quoted 6 lines
drivers/misc/Kconfig +6
-0+ if (rc) + enable = 0; + + rc = qcom_coincell_chgr_config(chgr, rset, vset, enable); + + return rc;This could be simplified to a return
qcom_coincell_chrg_config()too.
OK
Quoted 3 lines
Also, do we even need the chgr structure allocated anywhere besides on the stack? It seems that it will be memory that's just lying around for no use after probe.
Nope. And Agreed. I'll change this.
Thanks for the help!
-- Tim
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 3/3 ARM: dts: qcom: Add dts changes for qcom coincell charger
In reply to Tim BirdAdd framework for the coincell charger DT block in pm8941 file, and actual values for honami battery in the honami dts file.
---
Changes in v2:
- change coincell node name to remove 'qcom,' prefix
arch/arm/boot/dts/qcom-msm8974-sony-xperia-honami.dts | 11 +++++++++++ arch/arm/boot/dts/qcom-pm8941.dtsi | 6 ++++++ 2 files changed, 17 insertions(+)
arch/arm/boot/dts/qcom-msm8974-sony-xperia-honami.dts +11 -0
@@ -17,3 +17,14 @@ status = "ok"; }; }; + +&spmi_bus { + pm8941@0 { + coincell@2800 { + status = "ok"; + qcom,rset-ohms = <2100>; + qcom,vset-millivolts = <3000>; + qcom,charge-enable; + }; + }; +};
arch/arm/boot/dts/qcom-pm8941.dtsi +6 -0
@@ -125,6 +125,12 @@ interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>; qcom,external-resistor-micro-ohms = <10000>; }; + + coincell@2800 { + compatible = "qcom,pm8941-coincell"; + reg = <0x2800>; + status = "disabled"; + }; }; usid1: pm8941@1 {
Signature · 1 line
1.8.2.2