aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/sbs-battery.c
diff options
context:
space:
mode:
authorFrans Klaver <frans.klaver@xsens.com>2015-06-10 08:16:56 -0400
committerSebastian Reichel <sre@kernel.org>2015-06-10 10:18:46 -0400
commitf4ed950a63fc9590287f0f4fb0698e530b42b8a6 (patch)
treeeae551570e396cc9e16c385470cd39ade656fa6d /drivers/power/sbs-battery.c
parentfe27e1dfe9962b07215ee01445926306ddbb7c25 (diff)
sbs-battery: add option to always register battery
Commit a22b41a31e53 ("sbs-battery: Probe should try talking to the device") introduced a step in probing the SBS battery, that tries to talk to the device before actually registering it, saying: this driver doesn't actually try talking to the device at probe time, so if it's incorrectly configured in the device tree or platform data (or if the battery has been removed from the system), then probe will succeed and every access will sit there and time out. The end result is a possibly laggy system that thinks it has a battery but can never read status, which isn't very useful. Which is of course reasonable. However, it is also very well possible for a device to boot up on wall-power and be connected to a battery later on. This is a scenario that the driver supported before said patch was applied, and even easily achieved by booting up with the battery attached and removing it later on. sbs-battery's 'present' sysfs file can be used to determine if the device is available or not. So with automated device detection lacking for now, in some cases it is possible that one wants to register a battery, even if none are attached at the moment. To facilitate this, add a module parameter that can be used to configure forced loading module loading time. If set, the battery will always be registered without checking the sanity of the connection. Signed-off-by: Frans Klaver <frans.klaver@xsens.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers/power/sbs-battery.c')
-rw-r--r--drivers/power/sbs-battery.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index de1178659d4b..d6226d68b574 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -28,6 +28,7 @@
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/gpio.h> 29#include <linux/gpio.h>
30#include <linux/of.h> 30#include <linux/of.h>
31#include <linux/stat.h>
31 32
32#include <linux/power/sbs-battery.h> 33#include <linux/power/sbs-battery.h>
33 34
@@ -170,6 +171,7 @@ struct sbs_info {
170 171
171static char model_name[I2C_SMBUS_BLOCK_MAX + 1]; 172static char model_name[I2C_SMBUS_BLOCK_MAX + 1];
172static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1]; 173static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
174static bool force_load;
173 175
174static int sbs_read_word_data(struct i2c_client *client, u8 address) 176static int sbs_read_word_data(struct i2c_client *client, u8 address)
175{ 177{
@@ -885,14 +887,17 @@ static int sbs_probe(struct i2c_client *client,
885 887
886skip_gpio: 888skip_gpio:
887 /* 889 /*
888 * Before we register, we need to make sure we can actually talk 890 * Before we register, we might need to make sure we can actually talk
889 * to the battery. 891 * to the battery.
890 */ 892 */
891 rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr); 893 if (!force_load) {
892 if (rc < 0) { 894 rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
893 dev_err(&client->dev, "%s: Failed to get device status\n", 895
894 __func__); 896 if (rc < 0) {
895 goto exit_psupply; 897 dev_err(&client->dev, "%s: Failed to get device status\n",
898 __func__);
899 goto exit_psupply;
900 }
896 } 901 }
897 902
898 chip->power_supply = power_supply_register(&client->dev, sbs_desc, 903 chip->power_supply = power_supply_register(&client->dev, sbs_desc,
@@ -991,3 +996,7 @@ module_i2c_driver(sbs_battery_driver);
991 996
992MODULE_DESCRIPTION("SBS battery monitor driver"); 997MODULE_DESCRIPTION("SBS battery monitor driver");
993MODULE_LICENSE("GPL"); 998MODULE_LICENSE("GPL");
999
1000module_param(force_load, bool, S_IRUSR | S_IRGRP | S_IROTH);
1001MODULE_PARM_DESC(force_load,
1002 "Attempt to load the driver even if no battery is connected");