devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Dannenberg <dannenberg@ti.com>
To: Sebastian Reichel <sre@kernel.org>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Laurentiu Palcu <laurentiu.palcu@intel.com>,
	Krzysztof Kozlowski <k.kozlowski@samsung.com>
Cc: Ramakrishna Pallala <ramakrishna.pallala@intel.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-api@vger.kernel.org, Andreas Dannenberg <dannenberg@ti.com>
Subject: [PATCH v7 06/15] power: bq24257: Add basic support for bq24250/bq24251
Date: Fri, 25 Sep 2015 10:54:11 -0500	[thread overview]
Message-ID: <1443196460-26156-7-git-send-email-dannenberg@ti.com> (raw)
In-Reply-To: <1443196460-26156-1-git-send-email-dannenberg@ti.com>

This patch adds basic support for bq24250 and bq24251 which are very
similar to the bq24257 the driver was originally written for. Basic
support means the ability to select a device through Kconfig, DT and
ACPI, an instance variable allowing to check which chip is active, and
the reporting back of the selected device through the model_name power
supply sysfs property.

This patch by itself is not sufficient to actually use those two added
devices in a real-world setting due to some feature differences which
are addressed by other patches in this series.

Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
---
 drivers/power/Kconfig           |  5 ++--
 drivers/power/bq24257_charger.c | 52 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 52 insertions(+), 5 deletions(-)

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index eeb5776..9e68853 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -409,12 +409,13 @@ config CHARGER_BQ24190
 	  Say Y to enable support for the TI BQ24190 battery charger.
 
 config CHARGER_BQ24257
-	tristate "TI BQ24257 battery charger driver"
+	tristate "TI BQ24250/24251/24257 battery charger driver"
 	depends on I2C
 	depends on GPIOLIB || COMPILE_TEST
 	depends on REGMAP_I2C
 	help
-	  Say Y to enable support for the TI BQ24257 battery charger.
+	  Say Y to enable support for the TI BQ24250, BQ24251, and BQ24257 battery
+	  chargers.
 
 config CHARGER_BQ24735
 	tristate "TI BQ24735 battery charger support"
diff --git a/drivers/power/bq24257_charger.c b/drivers/power/bq24257_charger.c
index 060f754..b0c8533 100644
--- a/drivers/power/bq24257_charger.c
+++ b/drivers/power/bq24257_charger.c
@@ -13,6 +13,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
+ * Datasheets:
+ * http://www.ti.com/product/bq24250
+ * http://www.ti.com/product/bq24251
+ * http://www.ti.com/product/bq24257
  */
 
 #include <linux/module.h>
@@ -40,6 +44,22 @@
 
 #define BQ24257_ILIM_SET_DELAY		1000	/* msec */
 
+/*
+ * When adding support for new devices make sure that enum bq2425x_chip and
+ * bq2425x_chip_name[] always stay in sync!
+ */
+enum bq2425x_chip {
+	BQ24250,
+	BQ24251,
+	BQ24257,
+};
+
+static const char *const bq2425x_chip_name[] = {
+	"bq24250",
+	"bq24251",
+	"bq24257",
+};
+
 enum bq24257_fields {
 	F_WD_FAULT, F_WD_EN, F_STAT, F_FAULT,			    /* REG 1 */
 	F_RESET, F_IILIMIT, F_EN_STAT, F_EN_TERM, F_CE, F_HZ_MODE,  /* REG 2 */
@@ -70,6 +90,8 @@ struct bq24257_device {
 	struct device *dev;
 	struct power_supply *charger;
 
+	enum bq2425x_chip chip;
+
 	struct regmap *rmap;
 	struct regmap_field *rmap_fields[F_MAX_FIELDS];
 
@@ -248,6 +270,10 @@ static int bq24257_power_supply_get_property(struct power_supply *psy,
 		val->strval = BQ24257_MANUFACTURER;
 		break;
 
+	case POWER_SUPPLY_PROP_MODEL_NAME:
+		val->strval = bq2425x_chip_name[bq->chip];
+		break;
+
 	case POWER_SUPPLY_PROP_ONLINE:
 		val->intval = state.power_good;
 		break;
@@ -561,6 +587,7 @@ static int bq24257_hw_init(struct bq24257_device *bq)
 
 static enum power_supply_property bq24257_power_supply_props[] = {
 	POWER_SUPPLY_PROP_MANUFACTURER,
+	POWER_SUPPLY_PROP_MODEL_NAME,
 	POWER_SUPPLY_PROP_STATUS,
 	POWER_SUPPLY_PROP_ONLINE,
 	POWER_SUPPLY_PROP_HEALTH,
@@ -644,6 +671,7 @@ static int bq24257_probe(struct i2c_client *client,
 {
 	struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
 	struct device *dev = &client->dev;
+	const struct acpi_device_id *acpi_id;
 	struct bq24257_device *bq;
 	int ret;
 	int i;
@@ -660,6 +688,18 @@ static int bq24257_probe(struct i2c_client *client,
 	bq->client = client;
 	bq->dev = dev;
 
+	if (ACPI_HANDLE(dev)) {
+		acpi_id = acpi_match_device(dev->driver->acpi_match_table,
+					    &client->dev);
+		if (!acpi_id) {
+			dev_err(dev, "Failed to match ACPI device\n");
+			return -ENODEV;
+		}
+		bq->chip = (enum bq2425x_chip)acpi_id->driver_data;
+	} else {
+		bq->chip = (enum bq2425x_chip)id->driver_data;
+	}
+
 	mutex_init(&bq->lock);
 
 	bq->rmap = devm_regmap_init_i2c(client, &bq24257_regmap_config);
@@ -722,7 +762,7 @@ static int bq24257_probe(struct i2c_client *client,
 					bq24257_irq_handler_thread,
 					IRQF_TRIGGER_FALLING |
 					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
-					"bq24257", bq);
+					bq2425x_chip_name[bq->chip], bq);
 	if (ret) {
 		dev_err(dev, "Failed to request IRQ #%d\n", client->irq);
 		return ret;
@@ -793,19 +833,25 @@ static const struct dev_pm_ops bq24257_pm = {
 };
 
 static const struct i2c_device_id bq24257_i2c_ids[] = {
-	{ "bq24257", 0 },
+	{ "bq24250", BQ24250 },
+	{ "bq24251", BQ24251 },
+	{ "bq24257", BQ24257 },
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, bq24257_i2c_ids);
 
 static const struct of_device_id bq24257_of_match[] = {
+	{ .compatible = "ti,bq24250", },
+	{ .compatible = "ti,bq24251", },
 	{ .compatible = "ti,bq24257", },
 	{ },
 };
 MODULE_DEVICE_TABLE(of, bq24257_of_match);
 
 static const struct acpi_device_id bq24257_acpi_match[] = {
-	{"BQ242570", 0},
+	{ "BQ242500", BQ24250 },
+	{ "BQ242510", BQ24251 },
+	{ "BQ242570", BQ24257 },
 	{},
 };
 MODULE_DEVICE_TABLE(acpi, bq24257_acpi_match);
-- 
1.9.1


  reply	other threads:[~2015-09-25 15:54 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-25 15:54 [PATCH v7 00/15] power: bq24257: Add support for bq24250/bq24251 Andreas Dannenberg
2015-09-25 15:54 ` Andreas Dannenberg [this message]
     [not found]   ` <1443196460-26156-7-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-28 13:14     ` [PATCH v7 06/15] power: bq24257: Add basic " Krzysztof Kozlowski
2015-09-28 13:38       ` Andreas Dannenberg
2015-09-25 15:54 ` [PATCH v7 07/15] power: bq24257: Add bit definition for temp sense enable Andreas Dannenberg
     [not found] ` <1443196460-26156-1-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-25 15:54   ` [PATCH v7 01/15] dt: power: bq24257-charger: Cover additional devices Andreas Dannenberg
     [not found]     ` <1443196460-26156-2-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-28 12:16       ` Krzysztof Kozlowski
2015-09-28 18:16       ` Sebastian Reichel
2015-09-25 15:54   ` [PATCH v7 02/15] power: bq24257: Remove IRQ config through stat-gpios Andreas Dannenberg
     [not found]     ` <1443196460-26156-3-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-28 16:38       ` Sebastian Reichel
2015-09-25 15:54   ` [PATCH v7 03/15] power: bq24257: Streamline input current limit setup Andreas Dannenberg
     [not found]     ` <1443196460-26156-4-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-28 16:53       ` Sebastian Reichel
2015-09-25 15:54   ` [PATCH v7 04/15] power: bq24257: Use managed power supply register Andreas Dannenberg
     [not found]     ` <1443196460-26156-5-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-28 13:10       ` Krzysztof Kozlowski
2015-09-28 17:22       ` Sebastian Reichel
2015-09-25 15:54   ` [PATCH v7 05/15] power: bq24257: Simplify bq24257_power_supply_init() Andreas Dannenberg
     [not found]     ` <1443196460-26156-6-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-28 13:10       ` Krzysztof Kozlowski
2015-09-25 15:54   ` [PATCH v7 08/15] power: bq24257: Allow manual setting of input current limit Andreas Dannenberg
2015-09-29  6:02     ` Krzysztof Kozlowski
2015-09-25 15:54   ` [PATCH v7 09/15] power: bq24257: Add SW-based approach for Power Good determination Andreas Dannenberg
     [not found]     ` <1443196460-26156-10-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-27 20:20       ` Sebastian Reichel
2015-09-28 12:04         ` Andreas Dannenberg
2015-09-28 15:49           ` Andreas Dannenberg
2015-09-28 16:02           ` Sebastian Reichel
2015-09-25 15:54   ` [PATCH v7 10/15] power: bq24257: Add over voltage protection setting support Andreas Dannenberg
2015-09-25 15:54   ` [PATCH v7 11/15] power: bq24257: Add input DPM voltage threshold " Andreas Dannenberg
2015-09-25 15:54   ` [PATCH v7 12/15] power: bq24257: Allow input current limit sysfs access Andreas Dannenberg
2015-09-25 15:54   ` [PATCH v7 13/15] power: bq24257: Add various device-specific sysfs properties Andreas Dannenberg
2015-09-25 15:54   ` [PATCH v7 14/15] power: bq24257: Add platform data based initialization Andreas Dannenberg
     [not found]     ` <1443196460-26156-15-git-send-email-dannenberg-l0cyMroinI0@public.gmane.org>
2015-09-28 17:58       ` Sebastian Reichel
2015-09-28 22:50         ` Andreas Dannenberg
2015-09-28 18:19   ` [PATCH v7 00/15] power: bq24257: Add support for bq24250/bq24251 Sebastian Reichel
2015-09-25 15:54 ` [PATCH v7 15/15] Documentation: power: bq24257: Document exported sysfs entries Andreas Dannenberg
2015-09-28 12:14 ` [PATCH v7 00/15] power: bq24257: Add support for bq24250/bq24251 Krzysztof Kozlowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443196460-26156-7-git-send-email-dannenberg@ti.com \
    --to=dannenberg@ti.com \
    --cc=dbaryshkov@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=k.kozlowski@samsung.com \
    --cc=laurentiu.palcu@intel.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=ramakrishna.pallala@intel.com \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).