Blame view
drivers/power/max8998_charger.c
5.43 KB
bb4ce9708 power_supply: Add... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* * max8998_charger.c - Power supply consumer driver for the Maxim 8998/LP3974 * * Copyright (C) 2009-2010 Samsung Electronics * MyungJoo Ham <myungjoo.ham@samsung.com> * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/err.h> |
d555ab6bb max8998_charger: ... |
23 |
#include <linux/module.h> |
bb4ce9708 power_supply: Add... |
24 25 26 27 28 29 30 31 32 |
#include <linux/slab.h> #include <linux/platform_device.h> #include <linux/power_supply.h> #include <linux/mfd/max8998.h> #include <linux/mfd/max8998-private.h> struct max8998_battery_data { struct device *dev; struct max8998_dev *iodev; |
297d716f6 power_supply: Cha... |
33 |
struct power_supply *battery; |
bb4ce9708 power_supply: Add... |
34 35 36 37 38 39 40 41 42 43 44 45 |
}; static enum power_supply_property max8998_battery_props[] = { POWER_SUPPLY_PROP_PRESENT, /* the presence of battery */ POWER_SUPPLY_PROP_ONLINE, /* charger is active or not */ }; /* Note that the charger control is done by a current regulator "CHARGER" */ static int max8998_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { |
297d716f6 power_supply: Cha... |
46 |
struct max8998_battery_data *max8998 = power_supply_get_drvdata(psy); |
bb4ce9708 power_supply: Add... |
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
struct i2c_client *i2c = max8998->iodev->i2c; int ret; u8 reg; switch (psp) { case POWER_SUPPLY_PROP_PRESENT: ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, ®); if (ret) return ret; if (reg & (1 << 4)) val->intval = 0; else val->intval = 1; break; case POWER_SUPPLY_PROP_ONLINE: ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, ®); if (ret) return ret; if (reg & (1 << 3)) val->intval = 0; else val->intval = 1; break; default: return -EINVAL; } return 0; } |
297d716f6 power_supply: Cha... |
76 77 78 79 80 81 82 |
static const struct power_supply_desc max8998_battery_desc = { .name = "max8998_pmic", .type = POWER_SUPPLY_TYPE_BATTERY, .get_property = max8998_battery_get_property, .properties = max8998_battery_props, .num_properties = ARRAY_SIZE(max8998_battery_props), }; |
c8afa6406 power: remove use... |
83 |
static int max8998_battery_probe(struct platform_device *pdev) |
bb4ce9708 power_supply: Add... |
84 85 86 |
{ struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); |
297d716f6 power_supply: Cha... |
87 |
struct power_supply_config psy_cfg = {}; |
bb4ce9708 power_supply: Add... |
88 89 90 91 92 93 94 95 96 |
struct max8998_battery_data *max8998; struct i2c_client *i2c; int ret = 0; if (!pdata) { dev_err(pdev->dev.parent, "No platform init data supplied "); return -ENODEV; } |
acfbf47a9 max8998_charger: ... |
97 98 |
max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_battery_data), GFP_KERNEL); |
bb4ce9708 power_supply: Add... |
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
if (!max8998) return -ENOMEM; max8998->dev = &pdev->dev; max8998->iodev = iodev; platform_set_drvdata(pdev, max8998); i2c = max8998->iodev->i2c; /* Setup "End of Charge" */ /* If EOC value equals 0, * remain value set from bootloader or default value */ if (pdata->eoc >= 10 && pdata->eoc <= 45) { max8998_update_reg(i2c, MAX8998_REG_CHGR1, (pdata->eoc / 5 - 2) << 5, 0x7 << 5); } else if (pdata->eoc == 0) { dev_dbg(max8998->dev, "EOC value not set: leave it unchanged. "); } else { dev_err(max8998->dev, "Invalid EOC value "); |
5e5822f67 power_supply: max... |
120 |
return -EINVAL; |
bb4ce9708 power_supply: Add... |
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
} /* Setup Charge Restart Level */ switch (pdata->restart) { case 100: max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x1 << 3, 0x3 << 3); break; case 150: max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x0 << 3, 0x3 << 3); break; case 200: max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x2 << 3, 0x3 << 3); break; case -1: max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x3 << 3, 0x3 << 3); break; case 0: dev_dbg(max8998->dev, "Restart Level not set: leave it unchanged. "); break; default: dev_err(max8998->dev, "Invalid Restart Level "); |
5e5822f67 power_supply: max... |
145 |
return -EINVAL; |
bb4ce9708 power_supply: Add... |
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
} /* Setup Charge Full Timeout */ switch (pdata->timeout) { case 5: max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x0 << 4, 0x3 << 4); break; case 6: max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x1 << 4, 0x3 << 4); break; case 7: max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x2 << 4, 0x3 << 4); break; case -1: max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x3 << 4, 0x3 << 4); break; case 0: dev_dbg(max8998->dev, "Full Timeout not set: leave it unchanged. "); |
45d116ec2 max8998_charger: ... |
166 |
break; |
bb4ce9708 power_supply: Add... |
167 168 169 |
default: dev_err(max8998->dev, "Invalid Full Timeout value "); |
5e5822f67 power_supply: max... |
170 |
return -EINVAL; |
bb4ce9708 power_supply: Add... |
171 |
} |
297d716f6 power_supply: Cha... |
172 |
psy_cfg.drv_data = max8998; |
bb4ce9708 power_supply: Add... |
173 |
|
5e5822f67 power_supply: max... |
174 175 176 |
max8998->battery = devm_power_supply_register(max8998->dev, &max8998_battery_desc, &psy_cfg); |
297d716f6 power_supply: Cha... |
177 178 179 180 181 |
if (IS_ERR(max8998->battery)) { ret = PTR_ERR(max8998->battery); dev_err(max8998->dev, "failed: power supply register: %d ", ret); |
5e5822f67 power_supply: max... |
182 |
return ret; |
bb4ce9708 power_supply: Add... |
183 184 185 |
} return 0; |
bb4ce9708 power_supply: Add... |
186 187 188 189 |
} static const struct platform_device_id max8998_battery_id[] = { { "max8998-battery", TYPE_MAX8998 }, |
c03bfabb6 max8997_charger&m... |
190 |
{ } |
bb4ce9708 power_supply: Add... |
191 192 193 194 195 |
}; static struct platform_driver max8998_battery_driver = { .driver = { .name = "max8998-battery", |
bb4ce9708 power_supply: Add... |
196 197 |
}, .probe = max8998_battery_probe, |
bb4ce9708 power_supply: Add... |
198 199 |
.id_table = max8998_battery_id, }; |
300bac7fb power_supply: Con... |
200 |
module_platform_driver(max8998_battery_driver); |
bb4ce9708 power_supply: Add... |
201 202 203 204 205 |
MODULE_DESCRIPTION("MAXIM 8998 battery control driver"); MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); MODULE_LICENSE("GPL"); MODULE_ALIAS("platform:max8998-battery"); |