[RFC PATCH] NFC: st21nfcb: Avoid use of skb after free

2015-01-15 Thread Anda-Maria Nicolae
Do not insert in send queue the skb that contains unknown Packet Control Byte

Signed-off-by: Anda-Maria Nicolae 
---
Only compile tested, please have a look

 drivers/nfc/st21nfcb/ndlc.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nfc/st21nfcb/ndlc.c b/drivers/nfc/st21nfcb/ndlc.c
index bac50e8..72659a3 100644
--- a/drivers/nfc/st21nfcb/ndlc.c
+++ b/drivers/nfc/st21nfcb/ndlc.c
@@ -138,7 +138,7 @@ static void llt_ndlc_requeue_data_pending(struct llt_ndlc 
*ndlc)
default:
pr_err("UNKNOWN Packet Control Byte=%d\n", pcb);
kfree_skb(skb);
-   break;
+   continue;
}
skb_queue_head(&ndlc->send_q, skb);
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] power_supply: Add support for Richtek rt9455 battery charger

2015-04-24 Thread Anda-Maria Nicolae
Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---
 .../devicetree/bindings/power/rt9455_charger.txt   |   38 +
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 drivers/power/Kconfig  |6 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1770 
 5 files changed, 1816 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
 create mode 100644 drivers/power/rt9455_charger.c

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..f716cf6
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,38 @@
+Binding for RT rt9455 battery charger
+
+Required properties:
+- compatible: Should contain one of the following:
+ * "rt,rt9455"
+
+- reg: integer, i2c address of the device.
+- rt,ICHRG:integer, output charge current in uA.
+- rt,IEOC_PERCENTAGE:  integer, the percent of the output charge current 
(ICHRG).
+   When the current in constant-voltage phase drops below
+   ICHRG x IEOC_PERCENTAGE, charge is terminated.
+- rt,VOREG:integer, battery regulation voltage in uV.
+
+Optional properties:
+- rt,VMIVR:integer, minimum input voltage regulation in uV.
+   Prevents input voltage drop due to insufficient current
+   provided by the power source.
+- rt,IAICR:integer, input current regulation in uA.
+
+Example:
+
+rt9455@22 {
+   compatible = "rt,rt9455";
+   reg = <0x22>;
+
+   interrupt-parent = <&gpio1>;
+   interrupts = <0 1>;
+
+   interrupt-gpio = <&gpio1 0 1>;
+   reset-gpio = <&gpio1 1 1>;
+
+   rt,ICHRG = <50>;
+   rt,IEOC_PERCENTAGE = <10>;
+   rt,VOREG = <420>;
+
+   rt,VMIVR = <450>;
+   rt,IAICR = <50>;
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 389ca13..dc868ed 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -148,6 +148,7 @@ raidsonic   RaidSonic Technology GmbH
 ralink Mediatek/Ralink Technology Corp.
 ramtronRamtron International
 realtek Realtek Semiconductor Corp.
+rt Richtek Technology Corporation
 renesasRenesas Electronics Corporation
 ricoh  Ricoh Co. Ltd.
 rockchip   Fuzhou Rockchip Electronics Co., Ltd
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 4091fb0..39f208d 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -439,6 +439,12 @@ config BATTERY_RT5033
  The fuelgauge calculates and determines the battery state of charge
  according to battery open circuit voltage.
 
+config CHARGER_RT9455
+   tristate "Richtek RT9455 battery charger driver"
+   depends on I2C && GPIOLIB
+   help
+   Say Y to enable support for the Richtek RT9455 battery charger.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index b7b0181..e49abbf 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_BATTERY_MAX17040)+= max17040_battery.o
 obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o
 obj-$(CONFIG_BATTERY_Z2)   += z2_battery.o
 obj-$(CONFIG_BATTERY_RT5033)   += rt5033_battery.o
+obj-$(CONFIG_CHARGER_RT9455)   += rt9455_charger.o
 obj-$(CONFIG_BATTERY_S3C_ADC)  += s3c_adc_battery.o
 obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o
 obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o
diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
new file mode 100644
index 000..57bb97d
--- /dev/null
+++ b/drivers/power/rt9455_charger.c
@@ -0,0 +1,1770 @@
+/*
+ * Driver for Richtek RT9455WSC battery charger.
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#d

[PATCH] power_supply: Add ACPI support to bq2415x battery charger

2015-04-24 Thread Anda-Maria Nicolae
Replace of_property_read_u32() function call with device_property_read_u32(),
which is a wrapper over ACPI and devicetree enumeration methods.

Fix minor existing coding style issues reported by checkpatch.pl.

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/bq2415x_charger.c |   76 ---
 1 file changed, 56 insertions(+), 20 deletions(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 6c534dc..38c2ad3 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -1530,13 +1531,15 @@ static int bq2415x_probe(struct i2c_client *client,
 {
int ret;
int num;
-   char *name;
+   char *name = NULL;
struct bq2415x_device *bq;
struct device_node *np = client->dev.of_node;
struct bq2415x_platform_data *pdata = client->dev.platform_data;
+   const struct acpi_device_id *acpi_id = NULL;
+   struct device *dev = &client->dev;
 
-   if (!np && !pdata) {
-   dev_err(&client->dev, "platform data missing\n");
+   if (!np && !pdata && !ACPI_HANDLE(dev)) {
+   dev_err(dev, "Neither devicetree, nor platform data, nor ACPI 
support\n");
return -ENODEV;
}
 
@@ -1547,22 +1550,27 @@ static int bq2415x_probe(struct i2c_client *client,
if (num < 0)
return num;
 
-   name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
+   if (id)
+   name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
+   else if (ACPI_HANDLE(dev)) {
+   acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
+   name = kasprintf(GFP_KERNEL, "%s-%d", acpi_id->id, num);
+   }
if (!name) {
-   dev_err(&client->dev, "failed to allocate device name\n");
+   dev_err(dev, "failed to allocate device name\n");
ret = -ENOMEM;
goto error_1;
}
 
-   bq = devm_kzalloc(&client->dev, sizeof(*bq), GFP_KERNEL);
+   bq = devm_kzalloc(dev, sizeof(*bq), GFP_KERNEL);
if (!bq) {
-   dev_err(&client->dev, "failed to allocate device data\n");
ret = -ENOMEM;
goto error_2;
}
 
if (np) {
-   bq->notify_psy = power_supply_get_by_phandle(np, 
"ti,usb-charger-detection");
+   bq->notify_psy =
+   power_supply_get_by_phandle(np, "ti,usb-charger-detection");
 
if (IS_ERR(bq->notify_psy)) {
dev_info(&client->dev,
@@ -1573,8 +1581,7 @@ static int bq2415x_probe(struct i2c_client *client,
ret = -EPROBE_DEFER;
goto error_2;
}
-   }
-   else if (pdata->notify_device)
+   } else if (pdata && pdata->notify_device)
bq->notify_psy = power_supply_get_by_name(pdata->notify_device);
else
bq->notify_psy = NULL;
@@ -1582,36 +1589,45 @@ static int bq2415x_probe(struct i2c_client *client,
i2c_set_clientdata(client, bq);
 
bq->id = num;
-   bq->dev = &client->dev;
-   bq->chip = id->driver_data;
+   bq->dev = dev;
+   if (id)
+   bq->chip = id->driver_data;
+   else if (ACPI_HANDLE(dev))
+   bq->chip = acpi_id->driver_data;
bq->name = name;
bq->mode = BQ2415X_MODE_OFF;
bq->reported_mode = BQ2415X_MODE_OFF;
bq->autotimer = 0;
bq->automode = 0;
 
-   if (np) {
-   ret = of_property_read_u32(np, "ti,current-limit",
+   if (np || ACPI_HANDLE(bq->dev)) {
+   ret = device_property_read_u32(bq->dev,
+   "ti,current-limit",
&bq->init_data.current_limit);
if (ret)
goto error_3;
-   ret = of_property_read_u32(np, "ti,weak-battery-voltage",
+   ret = device_property_read_u32(bq->dev,
+   "ti,weak-battery-voltage",
&bq->init_data.weak_battery_voltage);
if (ret)
goto error_3;
-   ret = of_property_read_u32(np, "ti,battery-regulation-voltage",
+   ret = device_property_read_u32(bq->dev,
+   "ti,battery-regulation-voltage",
&bq->init_data.battery_regulation_voltage);
if (ret)
goto

[PATCHv2] power_supply: Add support for Richtek rt9455 battery charger

2015-04-29 Thread Anda-Maria Nicolae
Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Updates from the previous version:
- replaced license GPLv2 with GPL
- replaced vendor prefix rt with richtek
- replaced uppercase properties names from devicetree with lowercase separated 
by dash properties names
- replaced I/O read/write API with regmap_read/write and regmap_field_read/write
- used kernel multiline comment
- used DELAYED_WORK and scheduled the works in system_power_efficient_wq. It is 
high probability that the device is in suspend state while charging (i.e. the 
user leaves the device to charge during night) and it is needed that the 
scheduled works to be executed as planned.
- replaced struct power_supply_desc rt9455_charger_desc with static const 
struct power_supply_desc rt9455_charger_desc 
- replaced if (IS_ERR_OR_NULL(info->charger)) with if (IS_ERR(info->charger))
- replaced {"RTK9455", 0} with { "RTK9455", 0 }
- removed .owner = THIS_MODULE

Signed-off-by: Anda-Maria Nicolae 
---
 .../devicetree/bindings/power/rt9455_charger.txt   |   43 +
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 drivers/power/Kconfig  |6 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1758 
 5 files changed, 1809 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
 create mode 100644 drivers/power/rt9455_charger.c

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..7e8aed6
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,43 @@
+Binding for Richtek rt9455 battery charger
+
+Required properties:
+- compatible: Should contain one of the following:
+ * "richtek,rt9455"
+
+- reg: integer, i2c address of the device.
+- richtek,output-charge-current:   integer, output current from the 
charger to the
+   battery, in uA.
+- richtek,end-of-charge-percentage:integer, percent of the output charge 
current.
+   When the current in constant-voltage 
phase drops
+   below output_charge_current x 
end-of-charge-percentage,
+   charge is terminated.
+- richtek,battery-regulation-voltage:  integer, maximum battery voltage in uV.
+
+Optional properties:
+- richtek,min-input-voltage-regulation: integer, input voltage level in uA, 
used to
+   decrease voltage level when the over 
current
+   of the input power source occurs.
+   This prevents input voltage drop due to 
insufficient
+   current provided by the power source.
+- richtek,avg-input-current-regulation: integer, input current value drained 
by the
+   charger from the power source.
+
+Example:
+
+rt9455@22 {
+   compatible = "richtek,rt9455";
+   reg = <0x22>;
+
+   interrupt-parent = <&gpio1>;
+   interrupts = <0 1>;
+
+   interrupt-gpio = <&gpio1 0 1>;
+   reset-gpio = <&gpio1 1 1>;
+
+   richtek,output-charge-current   = <50>;
+   richtek,end-of-charge-percentage= <10>;
+   richtek,battery-regulation-voltage  = <420>;
+
+   richtek,min-input-voltage-regulation = <450>;
+   richtek,avg-input-current-regulation = <50>;
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 389ca13..92a9508 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -148,6 +148,7 @@ raidsonic   RaidSonic Technology GmbH
 ralink Mediatek/Ralink Technology Corp.
 ramtronRamtron International
 realtek Realtek Semiconductor Corp.
+richtekRichtek Technology Corporation
 renesasRenesas Electronics Corporation
 ricoh  Ricoh Co. Ltd.
 rockchip   Fuzhou Rockchip Electronics Co., Ltd
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 4091fb0..39f208d 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -439,6 +439,12 @@ config BATTERY_RT5033
  The fuelgauge calculates and determines the battery state of charge
  according to battery open circuit voltage.
 
+config CHARGER_RT9455
+   tristate "Richtek RT9455 battery charger driver"
+   depends on I2C && GPIOLIB
+   help
+   Say Y to enable support for the Richtek RT9455 battery charger.
+
 source "drivers/power/reset/Kconfig&quo

[PATCH] power_supply: rt9455_charger: Fix error reported by static analysis tool

2015-06-12 Thread Anda-Maria Nicolae
The result of container_of macro cannot be NULL, so there is no need to
check whether info is NULL.

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/rt9455_charger.c |3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
index de86913..08baac6 100644
--- a/drivers/power/rt9455_charger.c
+++ b/drivers/power/rt9455_charger.c
@@ -1412,9 +1412,6 @@ static int rt9455_usb_event(struct notifier_block *nb,
unsigned int opa_mode, iaicr;
int ret;
 
-   if (!info)
-   return NOTIFY_DONE;
-
/*
 * Determine whether the charger is in charge mode
 * or in boost mode.
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] power_supply: rt9455_charger: Properly notify userspace about charging events

2015-06-17 Thread Anda-Maria Nicolae
Do not call power_supply_changed() when CHRVPI interrupt has occurred.
CHRVPI interrupt occurs when the charger is connected to or disconnected
from the power source. Call power_supply_changed() after PWR_RDY bit is
read, to distinguish between connection to or disconnection from the power
source.
Also, call power_supply_changed() after the battery is reconnected to the
charger, to notify userspace that the battery is no longer absent.

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/rt9455_charger.c |   16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
index 08baac6..a49a9d4 100644
--- a/drivers/power/rt9455_charger.c
+++ b/drivers/power/rt9455_charger.c
@@ -973,7 +973,6 @@ static int rt9455_irq_handler_check_irq2_register(struct 
rt9455_info *info,
 
if (irq2 & GET_MASK(F_CHRVPI)) {
dev_dbg(dev, "Charger fault occurred\n");
-   alert_userspace = true;
/*
 * CHRVPI bit is set in 2 cases:
 * 1. when the power source is connected to the charger.
@@ -981,6 +980,9 @@ static int rt9455_irq_handler_check_irq2_register(struct 
rt9455_info *info,
 * To identify the case, PWR_RDY bit is checked. Because
 * PWR_RDY bit is set / cleared after CHRVPI interrupt is
 * triggered, it is used delayed_work to later read PWR_RDY bit.
+* Also, do not set to true alert_userspace, because there is no
+* need to notify userspace when CHRVPI interrupt has occurred.
+* Userspace will be notified after PWR_RDY bit is read.
 */
queue_delayed_work(system_power_efficient_wq,
   &info->pwr_rdy_work,
@@ -1178,7 +1180,7 @@ static irqreturn_t rt9455_irq_handler_thread(int irq, 
void *data)
/*
 * Sometimes, an interrupt occurs while rt9455_probe() function
 * is executing and power_supply_register() is not yet called.
-* Do not call power_supply_charged() in this case.
+* Do not call power_supply_changed() in this case.
 */
if (info->charger)
power_supply_changed(info->charger);
@@ -1478,6 +1480,11 @@ static void rt9455_pwr_rdy_work_callback(struct 
work_struct *work)
   RT9455_MAX_CHARGING_TIME * HZ);
break;
}
+   /*
+* Notify userspace that the charger has been either connected to or
+* disconnected from the power source.
+*/
+   power_supply_changed(info->charger);
 }
 
 static void rt9455_max_charging_time_work_callback(struct work_struct *work)
@@ -1533,6 +1540,11 @@ static void rt9455_batt_presence_work_callback(struct 
work_struct *work)
if (ret)
dev_err(dev, "Failed to unmask BATAB 
interrupt\n");
}
+   /*
+* Notify userspace that the battery is now connected to the
+* charger.
+*/
+   power_supply_changed(info->charger);
}
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] power_supply: rt9455_charger: Check if CONFIG_USB_PHY is enabled

2015-06-03 Thread Anda-Maria Nicolae
If CONFIG_USB_PHY is not enabled, struct notifier_block is not defined and
compilation fails. Therefore, the functions that process USB event
notifications are defined only if CONFIG_USB_PHY is enabled.
There is no need to define these functions if CONFIG_USB_PHY is not
enabled, since no USB notifications are received in this case.
Also, since rt9455_set_boost_voltage_before_boost_mode() function is
called only if USB_EVENT_ID notification is received, this function should
also be defined only if CONFIG_USB_PHY is enabled.

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/rt9455_charger.c |4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
index 7c0c1ff..de86913 100644
--- a/drivers/power/rt9455_charger.c
+++ b/drivers/power/rt9455_charger.c
@@ -804,6 +804,7 @@ static int rt9455_hw_init(struct rt9455_info *info, u32 
ichrg,
return 0;
 }
 
+#if IS_ENABLED(CONFIG_USB_PHY)
 /*
  * Before setting the charger into boost mode, boost output voltage is
  * set. This is needed because boost output voltage may differ from battery
@@ -828,6 +829,7 @@ static int 
rt9455_set_boost_voltage_before_boost_mode(struct rt9455_info *info)
 
return 0;
 }
+#endif
 
 /*
  * Before setting the charger into charge mode, battery regulation voltage is
@@ -1241,6 +1243,7 @@ static int rt9455_discover_charger(struct rt9455_info 
*info, u32 *ichrg,
return 0;
 }
 
+#if IS_ENABLED(CONFIG_USB_PHY)
 static int rt9455_usb_event_none(struct rt9455_info *info,
 u8 opa_mode, u8 iaicr)
 {
@@ -1445,6 +1448,7 @@ static int rt9455_usb_event(struct notifier_block *nb,
}
return NOTIFY_DONE;
 }
+#endif
 
 static void rt9455_pwr_rdy_work_callback(struct work_struct *work)
 {
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] Documentation: devicetree: Add Richtek RT9455 bindings

2015-05-29 Thread Anda-Maria Nicolae
Signed-off-by: Anda-Maria Nicolae 
---
 .../devicetree/bindings/power/rt9455_charger.txt   |   46 
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..0580e24
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,46 @@
+Binding for Richtek rt9455 battery charger
+
+Required properties:
+- compatible:  it should contain one of the following:
+   "richtek,rt9455".
+- reg: integer, i2c address of the device.
+- interrupt-parent:the phandle for the interrupt 
controller that
+   services interrupts for this device.
+- interrupts:  interrupt mapping for GPIO IRQ, it 
should be
+   configured with IRQ_TYPE_LEVEL_LOW flag.
+- richtek,output-charge-current:   integer, output current from the 
charger to the
+   battery, in uA.
+- richtek,end-of-charge-percentage:integer, percent of the output charge 
current.
+   When the current in constant-voltage 
phase drops
+   below output_charge_current x 
end-of-charge-percentage,
+   charge is terminated.
+- richtek,battery-regulation-voltage:  integer, maximum battery voltage in uV.
+- richtek,boost-output-voltage:integer, maximum voltage 
provided to consumer
+   devices, when the charger is in boost 
mode.
+
+Optional properties:
+- richtek,min-input-voltage-regulation: integer, input voltage level in uA, 
used to
+   decrease voltage level when the over 
current
+   of the input power source occurs.
+   This prevents input voltage drop due to 
insufficient
+   current provided by the power source.
+- richtek,avg-input-current-regulation: integer, input current value drained 
by the
+   charger from the power source.
+
+Example:
+
+rt9455@22 {
+   compatible = "richtek,rt9455";
+   reg = <0x22>;
+
+   interrupt-parent = <&gpio1>;
+   interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
+
+   richtek,output-charge-current   = <50>;
+   richtek,end-of-charge-percentage= <10>;
+   richtek,battery-regulation-voltage  = <420>;
+   richtek,boost-output-voltage= <505>;
+
+   richtek,min-input-voltage-regulation = <450>;
+   richtek,avg-input-current-regulation = <50>;
+};
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7 0/3] Add support for Richtek RT9455 battery charger

2015-05-29 Thread Anda-Maria Nicolae
The next 3 patches do the following:
- first patch adds Richtek Technology Corporation in the vendor-prefixes list
- second patch adds device tree binding example for Richtek RT9455 battery 
charger
- third patch adds the driver for Richtek RT9455 battery charger

The reason why v6 did not contain any modification except for patch splitting, 
is that
I did not scroll down the e-mail and I thought the patch splitting was the only 
modification
I need to do. My bad.

Updates from v6:
- added interrupt-parent and interrupts as required properties in DT file 
rt9455_charger.txt.
- removed interrupt-gpio and reset-gpio from DT file rt9455_charger.txt.
- used IRQ_TYPE_LEVEL_LOW (for this charger, it works the same with 
IRQ_TYPE_EDGE_RISING and
  with IRQ_TYPE_LEVEL_LOW, but I prefer IRQ_TYPE_LEVEL_LOW) in interrupt 
specification, 
  in DT file rt9455_charger.txt.
- removed gpiod_irq and gpio_irq from rt9455_info structure.
- set boost voltage value without previously reading the existing value in the 
register.
- set voreg value without previously reading the existing value in the register.
- removed rt9455_setup_irq function. client->irq is set even without calling 
of_irq_get().
- used devm_power_supply_register() and removed power_supply_unregister() from 
rt9455_remove().

Anda-Maria Nicolae (3):
  of: Add vendor prefix for Richtek Technology Corporation
  Documentation: devicetree: Add Richtek RT9455 bindings
  power_supply: Add support for Richtek RT9455 battery charger

 .../devicetree/bindings/power/rt9455_charger.txt   |   46 +
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 drivers/power/Kconfig  |7 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1751 
 5 files changed, 1806 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
 create mode 100644 drivers/power/rt9455_charger.c

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] of: Add vendor prefix for Richtek Technology Corporation

2015-05-29 Thread Anda-Maria Nicolae
Signed-off-by: Anda-Maria Nicolae 
---
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 8033919..7b8c129 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -161,6 +161,7 @@ ralink  Mediatek/Ralink Technology Corp.
 ramtronRamtron International
 realtek Realtek Semiconductor Corp.
 renesasRenesas Electronics Corporation
+richtekRichtek Technology Corporation
 ricoh  Ricoh Co. Ltd.
 rockchip   Fuzhou Rockchip Electronics Co., Ltd
 samsungSamsung Semiconductor
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] power_supply: Add support for Richtek RT9455 battery charger

2015-05-29 Thread Anda-Maria Nicolae
Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/Kconfig  |7 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1751 
 3 files changed, 1759 insertions(+)
 create mode 100644 drivers/power/rt9455_charger.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index a848b1a..08beeed 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -460,6 +460,13 @@ config BATTERY_RT5033
  The fuelgauge calculates and determines the battery state of charge
  according to battery open circuit voltage.
 
+config CHARGER_RT9455
+   tristate "Richtek RT9455 battery charger driver"
+   depends on I2C && GPIOLIB
+   select REGMAP_I2C
+   help
+ Say Y to enable support for Richtek RT9455 battery charger.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 3572a72..5752ce8 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_BATTERY_MAX17040)+= max17040_battery.o
 obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o
 obj-$(CONFIG_BATTERY_Z2)   += z2_battery.o
 obj-$(CONFIG_BATTERY_RT5033)   += rt5033_battery.o
+obj-$(CONFIG_CHARGER_RT9455)   += rt9455_charger.o
 obj-$(CONFIG_BATTERY_S3C_ADC)  += s3c_adc_battery.o
 obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o
 obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o
diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
new file mode 100644
index 000..7c0c1ff
--- /dev/null
+++ b/drivers/power/rt9455_charger.c
@@ -0,0 +1,1751 @@
+/*
+ * Driver for Richtek RT9455WSC battery charger.
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RT9455_MANUFACTURER"Richtek"
+#define RT9455_MODEL_NAME  "RT9455"
+#define RT9455_DRIVER_NAME "rt9455-charger"
+
+#define RT9455_IRQ_NAME"interrupt"
+
+#define RT9455_PWR_RDY_DELAY   1 /* 1 second */
+#define RT9455_MAX_CHARGING_TIME   21600 /* 6 hrs */
+#define RT9455_BATT_PRESENCE_DELAY 60 /* 60 seconds */
+
+#define RT9455_CHARGE_MODE 0x00
+#define RT9455_BOOST_MODE  0x01
+
+#define RT9455_FAULT   0x03
+
+#define RT9455_IAICR_100MA 0x00
+#define RT9455_IAICR_500MA 0x01
+#define RT9455_IAICR_NO_LIMIT  0x03
+
+#define RT9455_CHARGE_DISABLE  0x00
+#define RT9455_CHARGE_ENABLE   0x01
+
+#define RT9455_PWR_FAULT   0x00
+#define RT9455_PWR_GOOD0x01
+
+#define RT9455_REG_CTRL1   0x00 /* CTRL1 reg address */
+#define RT9455_REG_CTRL2   0x01 /* CTRL2 reg address */
+#define RT9455_REG_CTRL3   0x02 /* CTRL3 reg address */
+#define RT9455_REG_DEV_ID  0x03 /* DEV_ID reg address */
+#define RT9455_REG_CTRL4   0x04 /* CTRL4 reg address */
+#define RT9455_REG_CTRL5   0x05 /* CTRL5 reg address */
+#define RT9455_REG_CTRL6   0x06 /* CTRL6 reg address */
+#define RT9455_REG_CTRL7   0x07 /* CTRL7 reg address */
+#define RT9455_REG_IRQ10x08 /* IRQ1 reg 
address */
+#define RT9455_REG_IRQ20x09 /* IRQ2 reg 
address */
+#define RT9455_REG_IRQ30x0A /* IRQ3 reg 
address */
+#define RT9455_REG_MASK1   0x0B /* MASK1 reg address */
+#define RT9455_REG_MASK2   0x0C /* MASK2 reg address */
+#define RT9455_REG_MASK3   0x0D /* MASK3 reg address */
+
+enum rt9455_fields {
+   F_STAT, F_BOOST, F_PWR_RDY, F_OTG_PIN_POLARITY, /* CTRL1 reg fields */
+
+   F_IAICR, F_TE_SHDN_EN, F_HIGHER_OCP, F_TE, F_IAICR_INT, F_HIZ,
+   F_OPA_MODE, /* CTRL2 reg fields */
+
+   F_VOREG, F_OTG_PL, F_OTG_EN, /* CTRL3 reg fields */
+
+   F_VENDOR_I

[PATCH 0/3] Add support for Richtek RT9455 battery charger

2015-05-25 Thread Anda-Maria Nicolae
Hello,

The next 3 patches do the following:
- first patch adds Richtek Technology Corporation in the vendor-prefixes list
- second patch adds device tree binding example for Richtek RT9455 battery 
charger
- third patch adds the driver for Richtek RT9455 battery charger

Thanks,
Anda

Anda-Maria Nicolae (3):
  of: Add vendor prefix for Richtek Technology Corporation
  Documentation: devicetree: Add Richtek RT9455 bindings
  power_supply: Add support for Richtek RT9455 battery charger

 .../devicetree/bindings/power/rt9455_charger.txt   |   46 +
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 drivers/power/Kconfig  |7 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1821 
 5 files changed, 1876 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
 create mode 100644 drivers/power/rt9455_charger.c

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 3/3] power_supply: Add support for Richtek RT9455 battery charger

2015-05-25 Thread Anda-Maria Nicolae
Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/Kconfig  |7 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1821 
 3 files changed, 1829 insertions(+)
 create mode 100644 drivers/power/rt9455_charger.c

diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index a848b1a..9bb906a 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -460,6 +460,13 @@ config BATTERY_RT5033
  The fuelgauge calculates and determines the battery state of charge
  according to battery open circuit voltage.
 
+config CHARGER_RT9455
+   tristate "Richtek RT9455 battery charger driver"
+   depends on I2C && GPIOLIB
+   select REGMAP_I2C
+   help
+ Say Y to enable support for the Richtek RT9455 battery charger.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 3572a72..5752ce8 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_BATTERY_MAX17040)+= max17040_battery.o
 obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o
 obj-$(CONFIG_BATTERY_Z2)   += z2_battery.o
 obj-$(CONFIG_BATTERY_RT5033)   += rt5033_battery.o
+obj-$(CONFIG_CHARGER_RT9455)   += rt9455_charger.o
 obj-$(CONFIG_BATTERY_S3C_ADC)  += s3c_adc_battery.o
 obj-$(CONFIG_BATTERY_TWL4030_MADC) += twl4030_madc_battery.o
 obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o
diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
new file mode 100644
index 000..4f6db92
--- /dev/null
+++ b/drivers/power/rt9455_charger.c
@@ -0,0 +1,1821 @@
+/*
+ * Driver for Richtek RT9455WSC battery charger.
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define RT9455_MANUFACTURER"Richtek"
+#define RT9455_MODEL_NAME  "RT9455"
+#define RT9455_DRIVER_NAME "rt9455-charger"
+
+#define RT9455_IRQ_NAME"interrupt"
+
+#define RT9455_PWR_RDY_DELAY   1 /* 1 second */
+#define RT9455_MAX_CHARGING_TIME   21600 /* 6 hrs */
+#define RT9455_BATT_PRESENCE_DELAY 60 /* 60 seconds */
+
+#define RT9455_CHARGE_MODE 0x00
+#define RT9455_BOOST_MODE  0x01
+
+#define RT9455_FAULT   0x03
+
+#define RT9455_IAICR_100MA 0x00
+#define RT9455_IAICR_500MA 0x01
+#define RT9455_IAICR_NO_LIMIT  0x03
+
+#define RT9455_CHARGE_DISABLE  0x00
+#define RT9455_CHARGE_ENABLE   0x01
+
+#define RT9455_PWR_FAULT   0x00
+#define RT9455_PWR_GOOD0x01
+
+#define RT9455_REG_CTRL1   0x00 /* CTRL1 reg address */
+#define RT9455_REG_CTRL2   0x01 /* CTRL2 reg address */
+#define RT9455_REG_CTRL3   0x02 /* CTRL3 reg address */
+#define RT9455_REG_DEV_ID  0x03 /* DEV_ID reg address */
+#define RT9455_REG_CTRL4   0x04 /* CTRL4 reg address */
+#define RT9455_REG_CTRL5   0x05 /* CTRL5 reg address */
+#define RT9455_REG_CTRL6   0x06 /* CTRL6 reg address */
+#define RT9455_REG_CTRL7   0x07 /* CTRL7 reg address */
+#define RT9455_REG_IRQ10x08 /* IRQ1 reg 
address */
+#define RT9455_REG_IRQ20x09 /* IRQ2 reg 
address */
+#define RT9455_REG_IRQ30x0A /* IRQ3 reg 
address */
+#define RT9455_REG_MASK1   0x0B /* MASK1 reg address */
+#define RT9455_REG_MASK2   0x0C /* MASK2 reg address */
+#define RT9455_REG_MASK3   0x0D /* MASK3 reg address */
+
+enum rt9455_fields {
+   F_STAT, F_BOOST, F_PWR_RDY, F_OTG_PIN_POLARITY, /* CTRL1 reg fields */
+
+   F_IAICR, F_TE_SHDN_EN, F_HIGHER_OCP, F_TE, F_IAICR_INT, F_HIZ,
+   F_OPA_MODE, /* CTRL2 reg fields */
+
+   F_VOREG, F_OTG_PL, F_OTG_EN, /* CTRL3 r

[PATCH 1/3] of: Add vendor prefix for Richtek Technology Corporation

2015-05-25 Thread Anda-Maria Nicolae
Signed-off-by: Anda-Maria Nicolae 
---
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 8033919..7b8c129 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -161,6 +161,7 @@ ralink  Mediatek/Ralink Technology Corp.
 ramtronRamtron International
 realtek Realtek Semiconductor Corp.
 renesasRenesas Electronics Corporation
+richtekRichtek Technology Corporation
 ricoh  Ricoh Co. Ltd.
 rockchip   Fuzhou Rockchip Electronics Co., Ltd
 samsungSamsung Semiconductor
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3] Documentation: devicetree: Add Richtek RT9455 bindings

2015-05-25 Thread Anda-Maria Nicolae
Signed-off-by: Anda-Maria Nicolae 
---
 .../devicetree/bindings/power/rt9455_charger.txt   |   46 
 1 file changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..bb46842
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,46 @@
+Binding for Richtek rt9455 battery charger
+
+Required properties:
+- compatible: Should contain one of the following:
+ * "richtek,rt9455"
+
+- reg: integer, i2c address of the device.
+- richtek,output-charge-current:   integer, output current in uA, from the
+   charger to the battery.
+- richtek,end-of-charge-percentage:integer, percent of the output charge 
current.
+   When the current in constant-voltage 
phase drops
+   below output_charge_current x 
end-of-charge-percentage,
+   charge is terminated.
+- richtek,battery-regulation-voltage:  integer, maximum battery voltage in uV.
+- richtek,boost-output-voltage:integer, maximum voltage in uV, 
provided to consumer
+   devices, when the charger is in boost 
mode.
+
+Optional properties:
+- richtek,min-input-voltage-regulation: integer, input voltage threshold in 
uA, used to
+   determine when to decrease voltage 
level when
+   the over current of the input power 
source occurs.
+   This prevents input voltage drop due to 
insufficient
+   current provided by the power source.
+- richtek,avg-input-current-regulation: integer, input current in uA, the 
charger should
+   drain from the power source.
+
+Example:
+
+rt9455@22 {
+   compatible = "richtek,rt9455";
+   reg = <0x22>;
+
+   interrupt-parent = <&gpio1>;
+   interrupts = <0 1>;
+
+   interrupt-gpio = <&gpio1 0 1>;
+   reset-gpio = <&gpio1 1 1>;
+
+   richtek,output-charge-current   = <50>;
+   richtek,end-of-charge-percentage= <10>;
+   richtek,battery-regulation-voltage  = <420>;
+   richtek,boost-output-voltage= <505>;
+
+   richtek,min-input-voltage-regulation = <450>;
+   richtek,avg-input-current-regulation = <50>;
+};
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] power_supply: Add support for Richtek rt9455 battery charger

2015-05-06 Thread Anda-Maria Nicolae


On 05/06/2015 10:58 AM, Krzysztof Kozłowski wrote:

2015-05-06 1:32 GMT+09:00 Anda-Maria Nicolae :

Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---

Updates from v2 version:
- removed unused masks and keep the used ones. I have tried to access mask field
from struct regmap_field, but I have received the following compilation error:
"dereferencing pointer to incomplete type". I think this happens because I 
include
the file include/linux/regmap.h and in this file struct regmap_field is only 
declared
and not defined. Struct regmap_field is defined in 
drivers/base/regmap/internal.h.
If I include this file, compilation works. But I do not think it is a good idea
to include it; I did not find any other driver which includes this file. I also
could not find any driver that accesses mask field from struct regmap_field.
For instance, drivers/pwm/pwm-sti.c at lines 157, 158, also uses masks.

- I have also kept REG_FIELD definitions for interrupt registers, since, for 
instance,
I use F_BATAB to check battery presence property.

- cached regs 0x05 and 0x06. Also, I have added rt9455_is_writeable_reg function
for writeable_reg field of regmap_config.

- used POWER_STATUS_DISCHARGING, replaced break with and replaced it with 
return and
indented it correctly. I spent some time on this and I finally understood what 
is happening.
So, if PWR_RDY bit is set, but STAT bits value is 0, the charger may be in one
of the following cases:
1. CHG_EN bit is 0.
2. CHG_EN bit is 1 but the battery is not connected.
In any of these cases, POWER_SUPPLY_STATUS_NOT_CHARGING is returned.
If the PWR_RDY bit is cleared, POWER_SUPPLY_STATUS_DISCHARGING is returned.

- used VOREG bits value instead of VMREG in functions 
rt9455_charger_get_voltage_max()/
rt9455_charger_set_voltage_max(). Although RT9455 charger has VMREG bits which,
according to the datasheet, represent "Maximum battery regulation voltage", the
charger never uses VMREG value as maximum threshold for battery voltage. This
happens because TE and TE_SHDN_EN bits are set during rt9455_probe(), and 
charging
operation is terminated when charging current is less than ICHRG x IEOC. When 
charging
operation is terminated, battery voltage is almost equal to VOREG. Therefore,
VMREG value is not taken into account. This is the reason why VOREG value is
set/returned in these functions.

- corrected comment from rt9455_usb_event_id() function.

- replaced IS_ERR_OR_NULL() with IS_ERR() to check the result of usb_get_phy()
function. Also, if usb_register_notifier() fails, since usb_put_phy() is 
immediately
called, I have set info->usb_phy to ERR_PTR(-ENODEV) so that in rt9455_remove()
usb_put_phy is not mistakenly called again.

  .../devicetree/bindings/power/rt9455_charger.txt   |   43 +
  .../devicetree/bindings/vendor-prefixes.txt|1 +
  drivers/power/Kconfig  |6 +
  drivers/power/Makefile |1 +
  drivers/power/rt9455_charger.c | 1801 
  5 files changed, 1852 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
  create mode 100644 drivers/power/rt9455_charger.c

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..7e8aed6
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,43 @@
+Binding for Richtek rt9455 battery charger
+
+Required properties:
+- compatible: Should contain one of the following:
+ * "richtek,rt9455"
+
+- reg: integer, i2c address of the device.
+- richtek,output-charge-current:   integer, output current from the 
charger to the
+   battery, in uA.
+- richtek,end-of-charge-percentage:integer, percent of the output charge 
current.
+   When the current in constant-voltage 
phase drops
+   below output_charge_current x 
end-of-charge-percentage,
+   charge is terminated.
+- richtek,battery-regulation-voltage:  integer, maximum battery voltage in uV.
+
+Optional properties:
+- richtek,min-input-voltage-regulation: integer, input voltage level in uA, 
used to
+   decrease voltage level when the over 
current
+   of the input power source occurs.
+   This prevents input voltage drop due to 
insufficient
+   current provided by the power source.
+- richtek,avg-input-current-regulation: integer, input current value drained 
by the
+   charger from the power source.
+
+Example:
+
+rt9455@22 {
+  

[PATCH v4] power_supply: Add support for Richtek rt9455 battery charger

2015-05-08 Thread Anda-Maria Nicolae
Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---

Updates from v3 version:
- added "depends on REGMAP_I2C" in Kconfig

- removed MASK* macros and used GET_MASK as per Laurentiu's suggestion

- removed charger_set_properties_* API

- read PWR_RDY bit first and if it is 1, check STAT bits, in 
rt9455_charger_get_status()

- used VMREG max value (which equals VOREG max value) in 
rt9455_charger_get_voltage_max()

- used devm_usb_get_phy as per Laurentiu's suggestion, removed usb_put_phy, 
removed
  put_usb_phy label, added new label put_usb_notifier, added "goto 
put_usb_notifier"
  if devm_request_threaded_irq() fails, or rt9455_hw_init() fails, or 
power_supply_register()
  fails

- I have downloaded USB 2.0 spec from 
http://www.usb.org/developers/docs/usb20_docs/#usb20spec
  and max VBUS output voltage value has changed from 5.25V to 5.5V. Please 
check 
  USB 2.0 ECN VBUS Max Limit.pdf from the downlooaded archive. Max boost output 
voltage
  RT945 charger can provide is 5.6V. We can suppose that the consumer device 
will never
  experience 5.6V, due to loss on connection cables. I have added Device-tree/ 
ACPI property
  so that the user can set the desired boost voltage value. Whenever the 
charger goes into boost mode,
  boost output voltage value from device tree/ACPI is set. Whenever the charger 
goes into charge mode,
  battery regulation voltage value from device tree/ACPI is again set.

 .../devicetree/bindings/power/rt9455_charger.txt   |   44 +
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 drivers/power/Kconfig  |7 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1821 
 5 files changed, 1874 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
 create mode 100644 drivers/power/rt9455_charger.c

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..095ddf4
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,44 @@
+Binding for Richtek rt9455 battery charger
+
+Required properties:
+- compatible: Should contain one of the following:
+ * "richtek,rt9455"
+
+- reg: integer, i2c address of the device.
+- richtek,output-charge-current:   integer, output current from the 
charger to the
+   battery, in uA.
+- richtek,end-of-charge-percentage:integer, percent of the output charge 
current.
+   When the current in constant-voltage 
phase drops
+   below output_charge_current x 
end-of-charge-percentage,
+   charge is terminated.
+- richtek,battery-regulation-voltage:  integer, maximum battery voltage in uV.
+
+Optional properties:
+- richtek,min-input-voltage-regulation: integer, input voltage level in uA, 
used to
+   decrease voltage level when the over 
current
+   of the input power source occurs.
+   This prevents input voltage drop due to 
insufficient
+   current provided by the power source.
+- richtek,avg-input-current-regulation: integer, input current value drained 
by the
+   charger from the power source.
+
+Example:
+
+rt9455@22 {
+   compatible = "richtek,rt9455";
+   reg = <0x22>;
+
+   interrupt-parent = <&gpio1>;
+   interrupts = <0 1>;
+
+   interrupt-gpio = <&gpio1 0 1>;
+   reset-gpio = <&gpio1 1 1>;
+
+   richtek,output-charge-current   = <50>;
+   richtek,end-of-charge-percentage= <10>;
+   richtek,battery-regulation-voltage  = <420>;
+   richtek,boost-output-voltage= <505>;
+
+   richtek,min-input-voltage-regulation = <450>;
+   richtek,avg-input-current-regulation = <50>;
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 389ca13..92a9508 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -148,6 +148,7 @@ raidsonic   RaidSonic Technology GmbH
 ralink Mediatek/Ralink Technology Corp.
 ramtronRamtron International
 realtek Realtek Semiconductor Corp.
+richtekRichtek Technology Corporation
 renesasRenesas Electronics Corporation
 ricoh  Ricoh Co. Ltd.
 rockchip   Fuzhou Rockchip Electronics Co., Ltd
diff --git a/drivers/power/Kconfig

[PATCH v5] power_supply: Add support for Richtek rt9455 battery charger

2015-05-08 Thread Anda-Maria Nicolae
Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---

Updates from v4 version:
- replaced depends on REGMAP_I2C with select REGMAP_I2C
- got the latest version of vendor_prefixes file; prev patch contained an older 
one
- added explanation in rt9455_charger.txt about what boost-output-voltage 
represents

 .../devicetree/bindings/power/rt9455_charger.txt   |   46 +
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 drivers/power/Kconfig  |7 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1821 
 5 files changed, 1876 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
 create mode 100644 drivers/power/rt9455_charger.c

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..a87c0f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,46 @@
+Binding for Richtek rt9455 battery charger
+
+Required properties:
+- compatible: Should contain one of the following:
+ * "richtek,rt9455"
+
+- reg: integer, i2c address of the device.
+- richtek,output-charge-current:   integer, output current from the 
charger to the
+   battery, in uA.
+- richtek,end-of-charge-percentage:integer, percent of the output charge 
current.
+   When the current in constant-voltage 
phase drops
+   below output_charge_current x 
end-of-charge-percentage,
+   charge is terminated.
+- richtek,battery-regulation-voltage:  integer, maximum battery voltage in uV.
+- richtek,boost-output-voltage:integer, maximum voltage 
provided to consumer
+   devices, when the charger is in boost 
mode.
+
+Optional properties:
+- richtek,min-input-voltage-regulation: integer, input voltage level in uA, 
used to
+   decrease voltage level when the over 
current
+   of the input power source occurs.
+   This prevents input voltage drop due to 
insufficient
+   current provided by the power source.
+- richtek,avg-input-current-regulation: integer, input current value drained 
by the
+   charger from the power source.
+
+Example:
+
+rt9455@22 {
+   compatible = "richtek,rt9455";
+   reg = <0x22>;
+
+   interrupt-parent = <&gpio1>;
+   interrupts = <0 1>;
+
+   interrupt-gpio = <&gpio1 0 1>;
+   reset-gpio = <&gpio1 1 1>;
+
+   richtek,output-charge-current   = <50>;
+   richtek,end-of-charge-percentage= <10>;
+   richtek,battery-regulation-voltage  = <420>;
+   richtek,boost-output-voltage= <505>;
+
+   richtek,min-input-voltage-regulation = <450>;
+   richtek,avg-input-current-regulation = <50>;
+};
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt 
b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 8033919..7b8c129 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -161,6 +161,7 @@ ralink  Mediatek/Ralink Technology Corp.
 ramtronRamtron International
 realtek Realtek Semiconductor Corp.
 renesasRenesas Electronics Corporation
+richtekRichtek Technology Corporation
 ricoh  Ricoh Co. Ltd.
 rockchip   Fuzhou Rockchip Electronics Co., Ltd
 samsungSamsung Semiconductor
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 4091fb0..0233a40 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -439,6 +439,13 @@ config BATTERY_RT5033
  The fuelgauge calculates and determines the battery state of charge
  according to battery open circuit voltage.
 
+config CHARGER_RT9455
+   tristate "Richtek RT9455 battery charger driver"
+   depends on I2C && GPIOLIB
+   select REGMAP_I2C
+   help
+ Say Y to enable support for the Richtek RT9455 battery charger.
+
 source "drivers/power/reset/Kconfig"
 
 endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index b7b0181..e49abbf 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_BATTERY_MAX17040)+= max17040_battery.o
 obj-$(CONFIG_BATTERY_MAX17042) += max17042_battery.o
 o

[PATCH v3] power_supply: Add support for Richtek rt9455 battery charger

2015-05-05 Thread Anda-Maria Nicolae
Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---

Updates from v2 version:
- removed unused masks and keep the used ones. I have tried to access mask field
from struct regmap_field, but I have received the following compilation error:
"dereferencing pointer to incomplete type". I think this happens because I 
include
the file include/linux/regmap.h and in this file struct regmap_field is only 
declared
and not defined. Struct regmap_field is defined in 
drivers/base/regmap/internal.h.
If I include this file, compilation works. But I do not think it is a good idea
to include it; I did not find any other driver which includes this file. I also
could not find any driver that accesses mask field from struct regmap_field.
For instance, drivers/pwm/pwm-sti.c at lines 157, 158, also uses masks.

- I have also kept REG_FIELD definitions for interrupt registers, since, for 
instance,
I use F_BATAB to check battery presence property.

- cached regs 0x05 and 0x06. Also, I have added rt9455_is_writeable_reg function
for writeable_reg field of regmap_config.

- used POWER_STATUS_DISCHARGING, replaced break with and replaced it with 
return and
indented it correctly. I spent some time on this and I finally understood what 
is happening.
So, if PWR_RDY bit is set, but STAT bits value is 0, the charger may be in one
of the following cases:
1. CHG_EN bit is 0.
2. CHG_EN bit is 1 but the battery is not connected.
In any of these cases, POWER_SUPPLY_STATUS_NOT_CHARGING is returned.
If the PWR_RDY bit is cleared, POWER_SUPPLY_STATUS_DISCHARGING is returned.

- used VOREG bits value instead of VMREG in functions 
rt9455_charger_get_voltage_max()/
rt9455_charger_set_voltage_max(). Although RT9455 charger has VMREG bits which,
according to the datasheet, represent "Maximum battery regulation voltage", the
charger never uses VMREG value as maximum threshold for battery voltage. This
happens because TE and TE_SHDN_EN bits are set during rt9455_probe(), and 
charging
operation is terminated when charging current is less than ICHRG x IEOC. When 
charging
operation is terminated, battery voltage is almost equal to VOREG. Therefore,
VMREG value is not taken into account. This is the reason why VOREG value is
set/returned in these functions. 

- corrected comment from rt9455_usb_event_id() function.

- replaced IS_ERR_OR_NULL() with IS_ERR() to check the result of usb_get_phy()
function. Also, if usb_register_notifier() fails, since usb_put_phy() is 
immediately
called, I have set info->usb_phy to ERR_PTR(-ENODEV) so that in rt9455_remove()
usb_put_phy is not mistakenly called again.

 .../devicetree/bindings/power/rt9455_charger.txt   |   43 +
 .../devicetree/bindings/vendor-prefixes.txt|1 +
 drivers/power/Kconfig  |6 +
 drivers/power/Makefile |1 +
 drivers/power/rt9455_charger.c | 1801 
 5 files changed, 1852 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
 create mode 100644 drivers/power/rt9455_charger.c

diff --git a/Documentation/devicetree/bindings/power/rt9455_charger.txt 
b/Documentation/devicetree/bindings/power/rt9455_charger.txt
new file mode 100644
index 000..7e8aed6
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/rt9455_charger.txt
@@ -0,0 +1,43 @@
+Binding for Richtek rt9455 battery charger
+
+Required properties:
+- compatible: Should contain one of the following:
+ * "richtek,rt9455"
+
+- reg: integer, i2c address of the device.
+- richtek,output-charge-current:   integer, output current from the 
charger to the
+   battery, in uA.
+- richtek,end-of-charge-percentage:integer, percent of the output charge 
current.
+   When the current in constant-voltage 
phase drops
+   below output_charge_current x 
end-of-charge-percentage,
+   charge is terminated.
+- richtek,battery-regulation-voltage:  integer, maximum battery voltage in uV.
+
+Optional properties:
+- richtek,min-input-voltage-regulation: integer, input voltage level in uA, 
used to
+   decrease voltage level when the over 
current
+   of the input power source occurs.
+   This prevents input voltage drop due to 
insufficient
+   current provided by the power source.
+- richtek,avg-input-current-regulation: integer, input current value drained 
by the
+   charger from the power source.
+
+Example:
+
+rt9455@22 {
+   compatible = "richtek,rt9455";
+   reg = <0x22>;
+
+   inter

Re: [PATCH v3] power_supply: Add support for Richtek rt9455 battery charger

2015-05-06 Thread Anda-Maria Nicolae

Hi Laurentiu,

Inline are the answers to your comments.

Thanks,
Anda

On 05/06/2015 02:40 PM, Laurentiu Palcu wrote:

On Tue, May 05, 2015 at 07:32:10PM +0300, Anda-Maria Nicolae wrote:

Based on the datasheet found here:
http://www.richtek.com/download_ds.jsp?p=RT9455

Signed-off-by: Anda-Maria Nicolae 
---

Updates from v2 version:
- removed unused masks and keep the used ones. I have tried to access mask field
from struct regmap_field, but I have received the following compilation error:
"dereferencing pointer to incomplete type". I think this happens because I 
include
the file include/linux/regmap.h and in this file struct regmap_field is only 
declared
and not defined. Struct regmap_field is defined in 
drivers/base/regmap/internal.h.
If I include this file, compilation works. But I do not think it is a good idea
to include it; I did not find any other driver which includes this file. I also
could not find any driver that accesses mask field from struct regmap_field.

If you want to go this path, which looks promising since you can get rid
of all mask macros, you don't need regmap_field to compute your masks.
You need reg_field (include/linux/regmap.h). When you setup your fields,
you use:

static const struct reg_field rt9455_reg_fields[] = {...};

Hence, you have access to both msb and lsb of each field and you can
easily compute your mask. Just an idea.

Because the masks are constant, I believe it is better to define macros 
for them instead of calculating every time the driver uses one of them. 
This is why I wanted to use mask field: to avoid calculating them and to 
remove the macros.

For instance, drivers/pwm/pwm-sti.c at lines 157, 158, also uses masks.

- I have also kept REG_FIELD definitions for interrupt registers, since, for 
instance,
I use F_BATAB to check battery presence property.

- cached regs 0x05 and 0x06. Also, I have added rt9455_is_writeable_reg function
for writeable_reg field of regmap_config.

- used POWER_STATUS_DISCHARGING, replaced break with and replaced it with 
return and
indented it correctly. I spent some time on this and I finally understood what 
is happening.
So, if PWR_RDY bit is set, but STAT bits value is 0, the charger may be in one
of the following cases:
1. CHG_EN bit is 0.
2. CHG_EN bit is 1 but the battery is not connected.
In any of these cases, POWER_SUPPLY_STATUS_NOT_CHARGING is returned.
If the PWR_RDY bit is cleared, POWER_SUPPLY_STATUS_DISCHARGING is returned.

- used VOREG bits value instead of VMREG in functions 
rt9455_charger_get_voltage_max()/
rt9455_charger_set_voltage_max(). Although RT9455 charger has VMREG bits which,
according to the datasheet, represent "Maximum battery regulation voltage", the
charger never uses VMREG value as maximum threshold for battery voltage. This
happens because TE and TE_SHDN_EN bits are set during rt9455_probe(), and 
charging
operation is terminated when charging current is less than ICHRG x IEOC. When 
charging
operation is terminated, battery voltage is almost equal to VOREG. Therefore,
VMREG value is not taken into account. This is the reason why VOREG value is
set/returned in these functions.

Something's not right... What happens in the following scenario:
VMREG=4.2V (default value) and user sets VOREG=4.45V? Did you test this
case. I really doubt VMREG field is not used at all. Of course, you can set
VMREG to maximum value in which case VMREG doesn't really matter.


I have set VMREG to its maximum value in rt9455_hw_init() function. 
Please take a look at my last patch.
Yes, I have tested this case with a battery whose voltage is 3.97V, 
VOREG = 4.45V and VMREG = 4.2V. The charger drains current from the 
power source. If I set VOREG to 4V, from 4.45V, Charge done interrupt is 
triggered and no current is drained from the power source. If I increase 
VMREG to 4.45V, and keep VOREG to 4V, no input current is drained from 
the power source, but if I increase VOREG to 4.2V, the charger drains 
current from the power source. This is why I have decided to use VOREG 
instead of VMREG.





- corrected comment from rt9455_usb_event_id() function.

- replaced IS_ERR_OR_NULL() with IS_ERR() to check the result of usb_get_phy()
function. Also, if usb_register_notifier() fails, since usb_put_phy() is 
immediately
called, I have set info->usb_phy to ERR_PTR(-ENODEV) so that in rt9455_remove()
usb_put_phy is not mistakenly called again.

  .../devicetree/bindings/power/rt9455_charger.txt   |   43 +
  .../devicetree/bindings/vendor-prefixes.txt|1 +
  drivers/power/Kconfig  |6 +
  drivers/power/Makefile |1 +
  drivers/power/rt9455_charger.c | 1801 
  5 files changed, 1852 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/power/rt9455_charger.txt
  create mode 100644 drivers/power/rt9455_charger.c


(...)


+static int rt9455_charg

[PATCH 0/2] power_supply: bq2415x_charger: Fix coding style issues && add ACPI support

2015-05-12 Thread Anda-Maria Nicolae
Hi all,

The following 2 patches do the following to bq2415x_charger:
- first patch fixes pre-existing coding style issues reported by checkpatch.pl
- second patch adds ACPI enumeration support

Thanks,
Anda

Anda-Maria Nicolae (2):
  power_supply: bq2415x_charger: Fix coding style issues
  power_supply: bq2415x_charger: Add ACPI support

 drivers/power/bq2415x_charger.c |   94 +++
 1 file changed, 66 insertions(+), 28 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] power_supply: bq2415x_charger: Add ACPI support

2015-05-12 Thread Anda-Maria Nicolae
Replace of_property_read_u32() with device_property_read_u32(), which is a
wrapper over ACPI and device tree enumeration methods.
When ACPI enumeration is used, automode is not supported. Therefore,
bq2415x_charger does not update its input current automatically, depending
on the USB port type that is connected to. Input current may be updated via
sysfs.

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/bq2415x_charger.c |   73 +--
 1 file changed, 55 insertions(+), 18 deletions(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 2cf8ec7..e98dcb6 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -1530,13 +1531,14 @@ static int bq2415x_probe(struct i2c_client *client,
 {
int ret;
int num;
-   char *name;
+   char *name = NULL;
struct bq2415x_device *bq;
struct device_node *np = client->dev.of_node;
struct bq2415x_platform_data *pdata = client->dev.platform_data;
+   const struct acpi_device_id *acpi_id = NULL;
 
-   if (!np && !pdata) {
-   dev_err(&client->dev, "platform data missing\n");
+   if (!np && !pdata && !ACPI_HANDLE(&client->dev)) {
+   dev_err(&client->dev, "Neither devicetree, nor platform data, 
nor ACPI support\n");
return -ENODEV;
}
 
@@ -1547,7 +1549,14 @@ static int bq2415x_probe(struct i2c_client *client,
if (num < 0)
return num;
 
-   name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
+   if (id) {
+   name = kasprintf(GFP_KERNEL, "%s-%d", id->name, num);
+   } else if (ACPI_HANDLE(&client->dev)) {
+   acpi_id =
+   acpi_match_device(client->dev.driver->acpi_match_table,
+ &client->dev);
+   name = kasprintf(GFP_KERNEL, "%s-%d", acpi_id->id, num);
+   }
if (!name) {
dev_err(&client->dev, "failed to allocate device name\n");
ret = -ENOMEM;
@@ -1573,7 +1582,7 @@ static int bq2415x_probe(struct i2c_client *client,
ret = -EPROBE_DEFER;
goto error_2;
}
-   } else if (pdata->notify_device) {
+   } else if (pdata && pdata->notify_device) {
bq->notify_psy = power_supply_get_by_name(pdata->notify_device);
} else {
bq->notify_psy = NULL;
@@ -1583,36 +1592,45 @@ static int bq2415x_probe(struct i2c_client *client,
 
bq->id = num;
bq->dev = &client->dev;
-   bq->chip = id->driver_data;
+   if (id)
+   bq->chip = id->driver_data;
+   else if (ACPI_HANDLE(bq->dev))
+   bq->chip = acpi_id->driver_data;
bq->name = name;
bq->mode = BQ2415X_MODE_OFF;
bq->reported_mode = BQ2415X_MODE_OFF;
bq->autotimer = 0;
bq->automode = 0;
 
-   if (np) {
-   ret = of_property_read_u32(np, "ti,current-limit",
-  &bq->init_data.current_limit);
+   if (np || ACPI_HANDLE(bq->dev)) {
+   ret = device_property_read_u32(bq->dev,
+  "ti,current-limit",
+  &bq->init_data.current_limit);
if (ret)
goto error_3;
-   ret = of_property_read_u32(np, "ti,weak-battery-voltage",
-  &bq->init_data.weak_battery_voltage);
+   ret = device_property_read_u32(bq->dev,
+   "ti,weak-battery-voltage",
+   &bq->init_data.weak_battery_voltage);
if (ret)
goto error_3;
-   ret = of_property_read_u32(np, "ti,battery-regulation-voltage",
+   ret = device_property_read_u32(bq->dev,
+   "ti,battery-regulation-voltage",
&bq->init_data.battery_regulation_voltage);
if (ret)
goto error_3;
-   ret = of_property_read_u32(np, "ti,charge-current",
-  &bq->init_data.charge_current);
+   ret = device_property_read_u32(bq->dev,
+  "ti,charge-current",
+  &bq->init_data.charge_current);

[PATCH 1/2] power_supply: bq2415x_charger: Fix coding style issues

2015-05-12 Thread Anda-Maria Nicolae
This patch fixes the following issues reported by checkpatch.pl:
- use -EINVAL instead of -ENOSYS, to fix warning message:
  "ENOSYS means 'invalid syscall nr' and nothing else"
- remove unnecessary log message
- split lines whose length is greater than 80 characters
- if an arm statement uses braces, add braces to the other arms of the
  respective statement, too
- match alignment with open parenthesis

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/bq2415x_charger.c |   35 ++-
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 6c534dc..2cf8ec7 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -631,7 +631,7 @@ static int bq2415x_set_charge_current(struct bq2415x_device 
*bq, int mA)
int val;
 
if (bq->init_data.resistor_sense <= 0)
-   return -ENOSYS;
+   return -EINVAL;
 
val = (mA * bq->init_data.resistor_sense - 37400) / 6800;
if (val < 0)
@@ -650,7 +650,7 @@ static int bq2415x_get_charge_current(struct bq2415x_device 
*bq)
int ret;
 
if (bq->init_data.resistor_sense <= 0)
-   return -ENOSYS;
+   return -EINVAL;
 
ret = bq2415x_i2c_read_mask(bq, BQ2415X_REG_CURRENT,
BQ2415X_MASK_VI_CHRG, BQ2415X_SHIFT_VI_CHRG);
@@ -665,7 +665,7 @@ static int bq2415x_set_termination_current(struct 
bq2415x_device *bq, int mA)
int val;
 
if (bq->init_data.resistor_sense <= 0)
-   return -ENOSYS;
+   return -EINVAL;
 
val = (mA * bq->init_data.resistor_sense - 3400) / 3400;
if (val < 0)
@@ -684,7 +684,7 @@ static int bq2415x_get_termination_current(struct 
bq2415x_device *bq)
int ret;
 
if (bq->init_data.resistor_sense <= 0)
-   return -ENOSYS;
+   return -EINVAL;
 
ret = bq2415x_i2c_read_mask(bq, BQ2415X_REG_CURRENT,
BQ2415X_MASK_VI_TERM, BQ2415X_SHIFT_VI_TERM);
@@ -1166,7 +1166,7 @@ static ssize_t bq2415x_sysfs_set_mode(struct device *dev,
 
if (strncmp(buf, "auto", 4) == 0) {
if (bq->automode < 0)
-   return -ENOSYS;
+   return -EINVAL;
bq->automode = 1;
mode = bq->reported_mode;
} else if (strncmp(buf, "off", 3) == 0) {
@@ -1556,28 +1556,28 @@ static int bq2415x_probe(struct i2c_client *client,
 
bq = devm_kzalloc(&client->dev, sizeof(*bq), GFP_KERNEL);
if (!bq) {
-   dev_err(&client->dev, "failed to allocate device data\n");
ret = -ENOMEM;
goto error_2;
}
 
if (np) {
-   bq->notify_psy = power_supply_get_by_phandle(np, 
"ti,usb-charger-detection");
+   bq->notify_psy = power_supply_get_by_phandle(np,
+   "ti,usb-charger-detection");
 
if (IS_ERR(bq->notify_psy)) {
dev_info(&client->dev,
-   "no 'ti,usb-charger-detection' property 
(err=%ld)\n",
+"no 'ti,usb-charger-detection' property 
(err=%ld)\n",
PTR_ERR(bq->notify_psy));
bq->notify_psy = NULL;
} else if (!bq->notify_psy) {
ret = -EPROBE_DEFER;
goto error_2;
}
-   }
-   else if (pdata->notify_device)
+   } else if (pdata->notify_device) {
bq->notify_psy = power_supply_get_by_name(pdata->notify_device);
-   else
+   } else {
bq->notify_psy = NULL;
+   }
 
i2c_set_clientdata(client, bq);
 
@@ -1592,11 +1592,11 @@ static int bq2415x_probe(struct i2c_client *client,
 
if (np) {
ret = of_property_read_u32(np, "ti,current-limit",
-   &bq->init_data.current_limit);
+  &bq->init_data.current_limit);
if (ret)
goto error_3;
ret = of_property_read_u32(np, "ti,weak-battery-voltage",
-   &bq->init_data.weak_battery_voltage);
+  &bq->init_data.weak_battery_voltage);
if (ret)
goto error_3;
ret = of_property_read_u32(np, "ti,battery-regulation-voltage",
@@ -1604,15 +1604,15 @@ static int bq2415x_probe(struct i2c_client *client,
if (ret)
goto error_3

[PATCH 2/2] bq2415x_charger: Add support for bq24157s

2015-03-05 Thread Anda-Maria Nicolae
This patch adds bq24157s charger in the list of supported chargers.
bq24157s is similar to bq24158, except for Bit6 from Special Charger
Voltage/Enable Pin Status register, but this register is currently
not used by bq2415x_charger.

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/bq2415x_charger.c |8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index 628a2ed..41f6c4c 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -26,6 +26,8 @@
  * http://www.ti.com/product/bq24153
  * http://www.ti.com/product/bq24153a
  * http://www.ti.com/product/bq24155
+ * http://www.ti.com/product/bq24157s
+ * http://www.ti.com/product/bq24158
  */
 
 #include 
@@ -147,6 +149,7 @@ enum bq2415x_chip {
BQ24155,
BQ24156,
BQ24156A,
+   BQ24157S,
BQ24158,
 };
 
@@ -162,6 +165,7 @@ static char *bq2415x_chip_name[] = {
"bq24155",
"bq24156",
"bq24156a",
+   "bq24157s",
"bq24158",
 };
 
@@ -448,6 +452,8 @@ static enum bq2415x_chip bq2415x_detect_chip(struct 
bq2415x_device *bq)
return bq->chip;
return BQ24156;
case 2:
+   if (bq->chip == BQ24157S)
+   return bq->chip;
return BQ24158;
default:
return BQUNKNOWN;
@@ -480,6 +486,7 @@ static int bq2415x_detect_revision(struct bq2415x_device 
*bq)
case BQ24153A:
case BQ24156:
case BQ24156A:
+   case BQ24157S:
case BQ24158:
if (ret == 3)
return 0;
@@ -1716,6 +1723,7 @@ static const struct i2c_device_id bq2415x_i2c_id_table[] 
= {
{ "bq24155", BQ24155 },
{ "bq24156", BQ24156 },
{ "bq24156a", BQ24156A },
+   { "bq24157s", BQ24157S },
{ "bq24158", BQ24158 },
{},
 };
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 0/2] bq2415x_charger: Fix coding style issues and add new charger in the list of supported chargers

2015-03-05 Thread Anda-Maria Nicolae
Hello,

First patch from patchset fixes coding style issues: removes unnecessary else 
after return.
This way, the coding style complies with checkpatch.pl.

Second patch from patchset updates bq2415x driver to support bq24157s charger.

Thanks,
Anda

Anda-Maria Nicolae (2):
  bq2415x_charger: Remove unnecessary else after return
  bq2415x_charger: Add support for bq24157s

 drivers/power/bq2415x_charger.c |   32 
 1 file changed, 16 insertions(+), 16 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] bq2415x_charger: Remove unnecessary else after return

2015-03-05 Thread Anda-Maria Nicolae
Fix coding style to comply with checkpatch.pl

Signed-off-by: Anda-Maria Nicolae 
---
 drivers/power/bq2415x_charger.c |   24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index e384844..628a2ed 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -352,8 +352,7 @@ static int bq2415x_exec_command(struct bq2415x_device *bq,
BQ2415X_BIT_CE);
if (ret < 0)
return ret;
-   else
-   return ret > 0 ? 0 : 1;
+   return ret > 0 ? 0 : 1;
case BQ2415X_CHARGER_ENABLE:
return bq2415x_i2c_write_bit(bq, BQ2415X_REG_CONTROL,
0, BQ2415X_BIT_CE);
@@ -426,20 +425,17 @@ static enum bq2415x_chip bq2415x_detect_chip(struct 
bq2415x_device *bq)
case 0:
if (bq->chip == BQ24151A)
return bq->chip;
-   else
-   return BQ24151;
+   return BQ24151;
case 1:
if (bq->chip == BQ24150A ||
bq->chip == BQ24152 ||
bq->chip == BQ24155)
return bq->chip;
-   else
-   return BQ24150;
+   return BQ24150;
case 2:
if (bq->chip == BQ24153A)
return bq->chip;
-   else
-   return BQ24153;
+   return BQ24153;
default:
return BQUNKNOWN;
}
@@ -450,8 +446,7 @@ static enum bq2415x_chip bq2415x_detect_chip(struct 
bq2415x_device *bq)
case 0:
if (bq->chip == BQ24156A)
return bq->chip;
-   else
-   return BQ24156;
+   return BQ24156;
case 2:
return BQ24158;
default:
@@ -480,8 +475,7 @@ static int bq2415x_detect_revision(struct bq2415x_device 
*bq)
case BQ24152:
if (ret >= 0 && ret <= 3)
return ret;
-   else
-   return -1;
+   return -1;
case BQ24153:
case BQ24153A:
case BQ24156:
@@ -491,13 +485,11 @@ static int bq2415x_detect_revision(struct bq2415x_device 
*bq)
return 0;
else if (ret == 1)
return 1;
-   else
-   return -1;
+   return -1;
case BQ24155:
if (ret == 3)
return 3;
-   else
-   return -1;
+   return -1;
case BQUNKNOWN:
return -1;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] power_supply: rt9455_charger: Properly notify userspace about charging events

2015-07-02 Thread Anda-Maria Nicolae

Hello Krzysztof,

The information provided to userspace is not accurate in current driver 
implementation and it is accurate with this patch.
Also, when the battery is reconnected to the charger (after it has been 
disconnected from the charger), the charger does not trigger any 
interrupt. Since power_supply_changed() is called only in interrupt 
handler, the userspace is never notified that the battery is reconnected.


Let me explain to you why power_supply_changed() is called in 
rt9455_pwr_rdy_work_callback() and not in interrupt handler, when CHRVPI 
interrupt occurs.


I created a userspace tool that waits for notifications from the driver. 
A notification is sent when the driver calls power_supply_changed().
When my userspace tool receives a notification, it reads the files from 
/sys/class/power_supply/rt9455-charger/ folder. The tool reads each file 
this to figure it out what has been changed, since the driver notifies 
the tool only when a change has been made.
These files include /sys/class/power_supply/rt9455-charger/online. This 
file displays 1 if the power source is connected to the charger and 0 
otherwise.
When the userspace tool reads 
/sys/class/power_supply/rt9455-charger/online, 
rt9455_charger_get_online() function from the driver is called.

rt9455_charger_get_online() returns the value of PWR_RDY bit.
But whenever the power source is connected to / disconnected from the 
charger, RT9455 first sets CHRVPI interrupt bit, triggers an interrupt, 
and after almost 1-2 seconds, the charger also updates PWR_RDY bit.
So, if we check PWR_RDY bit immediately after CHRVPI bit is set, we will 
not obtain accurate info about the change that has been made (i.e.: if 
the power source was connected or disconnected).
This is why the driver has struct delayed_work pwr_rdy_work, which is 
scheduled whenever CHRVPI interrupt bit is set.
This is why in this patch, in rt9455_pwr_rdy_work_callback(), 
power_supply_changed() is called, and not in interrupt handler.


Let me explain to you why power_supply_changed() is called in 
rt9455_batt_presence_work_callback().


As previously stated, the userspace tool is never notified that the 
battery is reconnected. But since the driver uses struct delayed_work 
batt_presence_work, to determine whether the battery has been 
reconnected, we can call power_supply_changed() whenever the driver 
determines the battery is reconnected (i.e. BATAB interrupt bit is cleared).
This is why in this patch, in rt9455_batt_presence_work_callback(), 
power_supply_changed() is called.


On 07/02/2015 03:49 AM, Krzysztof Kozlowski wrote:

2015-06-18 1:28 GMT+09:00 Anda-Maria Nicolae :

Do not call power_supply_changed() when CHRVPI interrupt has occurred.

What I cannot find here is the answer to: why? I am not familiar with
the driver so this is just guessing that you wanted to notify
userspace about connected/disconnected charger. In both cases (before
and after the patch) this is achieved, isn't it?

Best regards,
Krzysztof



CHRVPI interrupt occurs when the charger is connected to or disconnected
from the power source. Call power_supply_changed() after PWR_RDY bit is
read, to distinguish between connection to or disconnection from the power
source.
Also, call power_supply_changed() after the battery is reconnected to the
charger, to notify userspace that the battery is no longer absent.

Signed-off-by: Anda-Maria Nicolae 
---
  drivers/power/rt9455_charger.c |   16 ++--
  1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
index 08baac6..a49a9d4 100644
--- a/drivers/power/rt9455_charger.c
+++ b/drivers/power/rt9455_charger.c
@@ -973,7 +973,6 @@ static int rt9455_irq_handler_check_irq2_register(struct 
rt9455_info *info,

 if (irq2 & GET_MASK(F_CHRVPI)) {
 dev_dbg(dev, "Charger fault occurred\n");
-   alert_userspace = true;
 /*
  * CHRVPI bit is set in 2 cases:
  * 1. when the power source is connected to the charger.
@@ -981,6 +980,9 @@ static int rt9455_irq_handler_check_irq2_register(struct 
rt9455_info *info,
  * To identify the case, PWR_RDY bit is checked. Because
  * PWR_RDY bit is set / cleared after CHRVPI interrupt is
  * triggered, it is used delayed_work to later read PWR_RDY 
bit.
+* Also, do not set to true alert_userspace, because there is no
+* need to notify userspace when CHRVPI interrupt has occurred.
+* Userspace will be notified after PWR_RDY bit is read.
  */
 queue_delayed_work(system_power_efficient_wq,
&info->pwr_rdy_work,
@@ -1178,7 +1180,7 @@ static irqreturn_t rt9455_irq_handler_thread(int irq, 
void *data)
 /*
  * Sometimes, an interrupt occurs whi

[PATCH v2] power_supply: rt9455_charger: Properly notify userspace about charging events

2015-07-07 Thread Anda-Maria Nicolae
Charging events this patch refers to are:
- charger is connected to/disconnected from the power source
- battery is reconnected to the charger, after it was absent.

When the charger is connected to/disconnected from the power source, CHRVPI
interrupt occurs and PWR_RDY bit is either set or cleared. PWR_RDY bit is
updated after 1-2 seconds CHRVPI interrupt has occurred.
power_supply_changed() should be called after PWR_RDY bit is updated.
/sys/class/power_supply/rt9455-charger/online file displays the value of
PWR_RDY bit.
This way, if the userspace is notified that a charging event has occurred
and the userspace reads /sys/class/power_supply/rt9455-charger/online file,
this file is properly updated when the userspace reads it.
This is the reason why power_supply_changed() is called in
rt9455_pwr_rdy_work_callback(), instead of being called in interrupt
handler.

Since no interrupt is triggered when the battery is reconnected to the
charger, the userspace is never notified that the battery is reconnected.
This is why power_supply_changed() is called in
rt9455_max_charging_time_work_callback(), so that the userspace is notified
that the battery is reconnected.

Signed-off-by: Anda-Maria Nicolae 
---

Updates from v1 version:
- I have followed Kzrysztof's suggestion and I have added explanations in
the commit message so that the change is more clear
- Code is the same as in v1

 drivers/power/rt9455_charger.c |   16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/power/rt9455_charger.c b/drivers/power/rt9455_charger.c
index 08baac6..a49a9d4 100644
--- a/drivers/power/rt9455_charger.c
+++ b/drivers/power/rt9455_charger.c
@@ -973,7 +973,6 @@ static int rt9455_irq_handler_check_irq2_register(struct 
rt9455_info *info,
 
if (irq2 & GET_MASK(F_CHRVPI)) {
dev_dbg(dev, "Charger fault occurred\n");
-   alert_userspace = true;
/*
 * CHRVPI bit is set in 2 cases:
 * 1. when the power source is connected to the charger.
@@ -981,6 +980,9 @@ static int rt9455_irq_handler_check_irq2_register(struct 
rt9455_info *info,
 * To identify the case, PWR_RDY bit is checked. Because
 * PWR_RDY bit is set / cleared after CHRVPI interrupt is
 * triggered, it is used delayed_work to later read PWR_RDY bit.
+* Also, do not set to true alert_userspace, because there is no
+* need to notify userspace when CHRVPI interrupt has occurred.
+* Userspace will be notified after PWR_RDY bit is read.
 */
queue_delayed_work(system_power_efficient_wq,
   &info->pwr_rdy_work,
@@ -1178,7 +1180,7 @@ static irqreturn_t rt9455_irq_handler_thread(int irq, 
void *data)
/*
 * Sometimes, an interrupt occurs while rt9455_probe() function
 * is executing and power_supply_register() is not yet called.
-* Do not call power_supply_charged() in this case.
+* Do not call power_supply_changed() in this case.
 */
if (info->charger)
power_supply_changed(info->charger);
@@ -1478,6 +1480,11 @@ static void rt9455_pwr_rdy_work_callback(struct 
work_struct *work)
   RT9455_MAX_CHARGING_TIME * HZ);
break;
}
+   /*
+* Notify userspace that the charger has been either connected to or
+* disconnected from the power source.
+*/
+   power_supply_changed(info->charger);
 }
 
 static void rt9455_max_charging_time_work_callback(struct work_struct *work)
@@ -1533,6 +1540,11 @@ static void rt9455_batt_presence_work_callback(struct 
work_struct *work)
if (ret)
dev_err(dev, "Failed to unmask BATAB 
interrupt\n");
}
+   /*
+* Notify userspace that the battery is now connected to the
+* charger.
+*/
+   power_supply_changed(info->charger);
}
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/