18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/slab.h>
79 battery->
cell->enable(battery->
pdev);
87 if (battery->
pdata->info.voltage_max_design <= 2500000)
88 val = (val * 78125
UL) >> 7
UL;
90 val = ((val * 924375
UL) >> 9
UL) + 33000;
96 battery->
cell->disable(battery->
pdev);
104 static int jz_battery_get_capacity(
struct power_supply *psy)
112 voltage = jz_battery_read_voltage(jz_battery);
128 static int jz_battery_get_property(
struct power_supply *psy,
131 struct jz_battery *jz_battery = psy_to_jz_battery(psy);
143 voltage = jz_battery_read_voltage(jz_battery);
150 val->
intval = jz_battery_get_capacity(psy);
153 val->
intval = jz_battery_read_voltage(jz_battery);
172 static void jz_battery_external_power_changed(
struct power_supply *psy)
174 struct jz_battery *jz_battery = psy_to_jz_battery(psy);
181 struct jz_battery *jz_battery =
data;
188 static void jz_battery_update(
struct jz_battery *jz_battery)
192 bool has_changed =
false;
195 if (gpio_is_valid(jz_battery->
pdata->gpio_charge)) {
197 is_charging ^= jz_battery->
pdata->gpio_charge_active_low;
203 if (status != jz_battery->
status) {
209 voltage = jz_battery_read_voltage(jz_battery);
210 if (
abs(voltage - jz_battery->
voltage) < 50000) {
234 struct jz_battery *jz_battery =
container_of(work,
struct jz_battery,
237 jz_battery_update(jz_battery);
245 struct jz_battery *jz_battery;
249 dev_err(&pdev->
dev,
"No platform_data supplied\n");
253 jz_battery = kzalloc(
sizeof(*jz_battery),
GFP_KERNEL);
255 dev_err(&pdev->
dev,
"Failed to allocate driver structure\n");
259 jz_battery->
cell = mfd_get_cell(pdev);
262 if (jz_battery->
irq < 0) {
263 ret = jz_battery->
irq;
264 dev_err(&pdev->
dev,
"Failed to get platform irq: %d\n", ret);
269 if (!jz_battery->
mem) {
271 dev_err(&pdev->
dev,
"Failed to get platform mmio resource\n");
276 resource_size(jz_battery->
mem), pdev->
name);
277 if (!jz_battery->
mem) {
279 dev_err(&pdev->
dev,
"Failed to request mmio memory region\n");
284 resource_size(jz_battery->
mem));
285 if (!jz_battery->
base) {
287 dev_err(&pdev->
dev,
"Failed to ioremap mmio memory\n");
288 goto err_release_mem_region;
291 battery = &jz_battery->
battery;
301 jz_battery->
pdev = pdev;
311 dev_err(&pdev->
dev,
"Failed to request irq %d\n", ret);
319 dev_err(&pdev->
dev,
"charger state gpio request failed.\n");
324 dev_err(&pdev->
dev,
"charger state gpio set direction failed.\n");
332 jz_battery_charge_irq,
334 dev_name(&pdev->
dev), jz_battery);
336 dev_err(&pdev->
dev,
"Failed to request charge irq: %d\n", ret);
344 if (jz_battery->
pdata->info.voltage_max_design <= 2500000)
352 dev_err(&pdev->
dev,
"power supply battery register failed.\n");
353 goto err_free_charge_irq;
356 platform_set_drvdata(pdev, jz_battery);
370 platform_set_drvdata(pdev,
NULL);
372 err_release_mem_region:
381 struct jz_battery *jz_battery = platform_get_drvdata(pdev);
385 if (gpio_is_valid(jz_battery->
pdata->gpio_charge)) {
403 static int jz_battery_suspend(
struct device *
dev)
413 static int jz_battery_resume(
struct device *
dev)
422 static const struct dev_pm_ops jz_battery_pm_ops = {
424 .resume = jz_battery_resume,
427 #define JZ_BATTERY_PM_OPS (&jz_battery_pm_ops)
429 #define JZ_BATTERY_PM_OPS NULL
433 .probe = jz_battery_probe,
436 .name =
"jz4740-battery",