diff options
| -rw-r--r-- | drivers/mfd/max8998.c | 2 | ||||
| -rw-r--r-- | drivers/power/Kconfig | 7 | ||||
| -rw-r--r-- | drivers/power/Makefile | 1 | ||||
| -rw-r--r-- | drivers/power/max8998_charger.c | 218 | ||||
| -rw-r--r-- | include/linux/mfd/max8998.h | 12 |
5 files changed, 240 insertions, 0 deletions
diff --git a/drivers/mfd/max8998.c b/drivers/mfd/max8998.c index 9ec7570f5b81..de4096aee248 100644 --- a/drivers/mfd/max8998.c +++ b/drivers/mfd/max8998.c | |||
| @@ -39,6 +39,8 @@ static struct mfd_cell max8998_devs[] = { | |||
| 39 | .name = "max8998-pmic", | 39 | .name = "max8998-pmic", |
| 40 | }, { | 40 | }, { |
| 41 | .name = "max8998-rtc", | 41 | .name = "max8998-rtc", |
| 42 | }, { | ||
| 43 | .name = "max8998-battery", | ||
| 42 | }, | 44 | }, |
| 43 | }; | 45 | }; |
| 44 | 46 | ||
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index f4f1a31d46a3..fddc392369ed 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig | |||
| @@ -235,4 +235,11 @@ config CHARGER_MAX8997 | |||
| 235 | Say Y to enable support for the battery charger control sysfs and | 235 | Say Y to enable support for the battery charger control sysfs and |
| 236 | platform data of MAX8997/LP3974 PMICs. | 236 | platform data of MAX8997/LP3974 PMICs. |
| 237 | 237 | ||
| 238 | config CHARGER_MAX8998 | ||
| 239 | tristate "Maxim MAX8998/LP3974 PMIC battery charger driver" | ||
| 240 | depends on MFD_MAX8998 && REGULATOR_MAX8998 | ||
| 241 | help | ||
| 242 | Say Y to enable support for the battery charger control sysfs and | ||
| 243 | platform data of MAX8998/LP3974 PMICs. | ||
| 244 | |||
| 238 | endif # POWER_SUPPLY | 245 | endif # POWER_SUPPLY |
diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 39793ef50cd5..a18e899b1f46 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile | |||
| @@ -36,3 +36,4 @@ obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o | |||
| 36 | obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o | 36 | obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o |
| 37 | obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o | 37 | obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o |
| 38 | obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o | 38 | obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o |
| 39 | obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o | ||
diff --git a/drivers/power/max8998_charger.c b/drivers/power/max8998_charger.c new file mode 100644 index 000000000000..cc21fa2120be --- /dev/null +++ b/drivers/power/max8998_charger.c | |||
| @@ -0,0 +1,218 @@ | |||
| 1 | /* | ||
| 2 | * max8998_charger.c - Power supply consumer driver for the Maxim 8998/LP3974 | ||
| 3 | * | ||
| 4 | * Copyright (C) 2009-2010 Samsung Electronics | ||
| 5 | * MyungJoo Ham <myungjoo.ham@samsung.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | * GNU General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <linux/err.h> | ||
| 23 | #include <linux/slab.h> | ||
| 24 | #include <linux/platform_device.h> | ||
| 25 | #include <linux/power_supply.h> | ||
| 26 | #include <linux/mfd/max8998.h> | ||
| 27 | #include <linux/mfd/max8998-private.h> | ||
| 28 | |||
| 29 | struct max8998_battery_data { | ||
| 30 | struct device *dev; | ||
| 31 | struct max8998_dev *iodev; | ||
| 32 | struct power_supply battery; | ||
| 33 | }; | ||
| 34 | |||
| 35 | static enum power_supply_property max8998_battery_props[] = { | ||
| 36 | POWER_SUPPLY_PROP_PRESENT, /* the presence of battery */ | ||
| 37 | POWER_SUPPLY_PROP_ONLINE, /* charger is active or not */ | ||
| 38 | }; | ||
| 39 | |||
| 40 | /* Note that the charger control is done by a current regulator "CHARGER" */ | ||
| 41 | static int max8998_battery_get_property(struct power_supply *psy, | ||
| 42 | enum power_supply_property psp, | ||
| 43 | union power_supply_propval *val) | ||
| 44 | { | ||
| 45 | struct max8998_battery_data *max8998 = container_of(psy, | ||
| 46 | struct max8998_battery_data, battery); | ||
| 47 | struct i2c_client *i2c = max8998->iodev->i2c; | ||
| 48 | int ret; | ||
| 49 | u8 reg; | ||
| 50 | |||
| 51 | switch (psp) { | ||
| 52 | case POWER_SUPPLY_PROP_PRESENT: | ||
| 53 | ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, ®); | ||
| 54 | if (ret) | ||
| 55 | return ret; | ||
| 56 | if (reg & (1 << 4)) | ||
| 57 | val->intval = 0; | ||
| 58 | else | ||
| 59 | val->intval = 1; | ||
| 60 | break; | ||
| 61 | case POWER_SUPPLY_PROP_ONLINE: | ||
| 62 | ret = max8998_read_reg(i2c, MAX8998_REG_STATUS2, ®); | ||
| 63 | if (ret) | ||
| 64 | return ret; | ||
| 65 | if (reg & (1 << 3)) | ||
| 66 | val->intval = 0; | ||
| 67 | else | ||
| 68 | val->intval = 1; | ||
| 69 | break; | ||
| 70 | default: | ||
| 71 | return -EINVAL; | ||
| 72 | } | ||
| 73 | |||
| 74 | return 0; | ||
| 75 | } | ||
| 76 | |||
| 77 | static __devinit int max8998_battery_probe(struct platform_device *pdev) | ||
| 78 | { | ||
| 79 | struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); | ||
| 80 | struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); | ||
| 81 | struct max8998_battery_data *max8998; | ||
| 82 | struct i2c_client *i2c; | ||
| 83 | int ret = 0; | ||
| 84 | |||
| 85 | if (!pdata) { | ||
| 86 | dev_err(pdev->dev.parent, "No platform init data supplied\n"); | ||
| 87 | return -ENODEV; | ||
| 88 | } | ||
| 89 | |||
| 90 | max8998 = kzalloc(sizeof(struct max8998_battery_data), GFP_KERNEL); | ||
| 91 | if (!max8998) | ||
| 92 | return -ENOMEM; | ||
| 93 | |||
| 94 | max8998->dev = &pdev->dev; | ||
| 95 | max8998->iodev = iodev; | ||
| 96 | platform_set_drvdata(pdev, max8998); | ||
| 97 | i2c = max8998->iodev->i2c; | ||
| 98 | |||
| 99 | /* Setup "End of Charge" */ | ||
| 100 | /* If EOC value equals 0, | ||
| 101 | * remain value set from bootloader or default value */ | ||
| 102 | if (pdata->eoc >= 10 && pdata->eoc <= 45) { | ||
| 103 | max8998_update_reg(i2c, MAX8998_REG_CHGR1, | ||
| 104 | (pdata->eoc / 5 - 2) << 5, 0x7 << 5); | ||
| 105 | } else if (pdata->eoc == 0) { | ||
| 106 | dev_dbg(max8998->dev, | ||
| 107 | "EOC value not set: leave it unchanged.\n"); | ||
| 108 | } else { | ||
| 109 | dev_err(max8998->dev, "Invalid EOC value\n"); | ||
| 110 | ret = -EINVAL; | ||
| 111 | goto err; | ||
| 112 | } | ||
| 113 | |||
| 114 | /* Setup Charge Restart Level */ | ||
| 115 | switch (pdata->restart) { | ||
| 116 | case 100: | ||
| 117 | max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x1 << 3, 0x3 << 3); | ||
| 118 | break; | ||
| 119 | case 150: | ||
| 120 | max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x0 << 3, 0x3 << 3); | ||
| 121 | break; | ||
| 122 | case 200: | ||
| 123 | max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x2 << 3, 0x3 << 3); | ||
| 124 | break; | ||
| 125 | case -1: | ||
| 126 | max8998_update_reg(i2c, MAX8998_REG_CHGR1, 0x3 << 3, 0x3 << 3); | ||
| 127 | break; | ||
| 128 | case 0: | ||
| 129 | dev_dbg(max8998->dev, | ||
| 130 | "Restart Level not set: leave it unchanged.\n"); | ||
| 131 | break; | ||
| 132 | default: | ||
| 133 | dev_err(max8998->dev, "Invalid Restart Level\n"); | ||
| 134 | ret = -EINVAL; | ||
| 135 | goto err; | ||
| 136 | } | ||
| 137 | |||
| 138 | /* Setup Charge Full Timeout */ | ||
| 139 | switch (pdata->timeout) { | ||
| 140 | case 5: | ||
| 141 | max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x0 << 4, 0x3 << 4); | ||
| 142 | break; | ||
| 143 | case 6: | ||
| 144 | max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x1 << 4, 0x3 << 4); | ||
| 145 | break; | ||
| 146 | case 7: | ||
| 147 | max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x2 << 4, 0x3 << 4); | ||
| 148 | break; | ||
| 149 | case -1: | ||
| 150 | max8998_update_reg(i2c, MAX8998_REG_CHGR2, 0x3 << 4, 0x3 << 4); | ||
| 151 | break; | ||
| 152 | case 0: | ||
| 153 | dev_dbg(max8998->dev, | ||
| 154 | "Full Timeout not set: leave it unchanged.\n"); | ||
| 155 | default: | ||
| 156 | dev_err(max8998->dev, "Invalid Full Timeout value\n"); | ||
| 157 | ret = -EINVAL; | ||
| 158 | goto err; | ||
| 159 | } | ||
| 160 | |||
| 161 | max8998->battery.name = "max8998_pmic"; | ||
| 162 | max8998->battery.type = POWER_SUPPLY_TYPE_BATTERY; | ||
| 163 | max8998->battery.get_property = max8998_battery_get_property; | ||
| 164 | max8998->battery.properties = max8998_battery_props; | ||
| 165 | max8998->battery.num_properties = ARRAY_SIZE(max8998_battery_props); | ||
| 166 | |||
| 167 | ret = power_supply_register(max8998->dev, &max8998->battery); | ||
| 168 | if (ret) { | ||
| 169 | dev_err(max8998->dev, "failed: power supply register\n"); | ||
| 170 | goto err; | ||
| 171 | } | ||
| 172 | |||
| 173 | return 0; | ||
| 174 | err: | ||
| 175 | kfree(max8998); | ||
| 176 | return ret; | ||
| 177 | } | ||
| 178 | |||
| 179 | static int __devexit max8998_battery_remove(struct platform_device *pdev) | ||
| 180 | { | ||
| 181 | struct max8998_battery_data *max8998 = platform_get_drvdata(pdev); | ||
| 182 | |||
| 183 | power_supply_unregister(&max8998->battery); | ||
| 184 | kfree(max8998); | ||
| 185 | |||
| 186 | return 0; | ||
| 187 | } | ||
| 188 | |||
| 189 | static const struct platform_device_id max8998_battery_id[] = { | ||
| 190 | { "max8998-battery", TYPE_MAX8998 }, | ||
| 191 | }; | ||
| 192 | |||
| 193 | static struct platform_driver max8998_battery_driver = { | ||
| 194 | .driver = { | ||
| 195 | .name = "max8998-battery", | ||
| 196 | .owner = THIS_MODULE, | ||
| 197 | }, | ||
| 198 | .probe = max8998_battery_probe, | ||
| 199 | .remove = __devexit_p(max8998_battery_remove), | ||
| 200 | .id_table = max8998_battery_id, | ||
| 201 | }; | ||
| 202 | |||
| 203 | static int __init max8998_battery_init(void) | ||
| 204 | { | ||
| 205 | return platform_driver_register(&max8998_battery_driver); | ||
| 206 | } | ||
| 207 | module_init(max8998_battery_init); | ||
| 208 | |||
| 209 | static void __exit max8998_battery_cleanup(void) | ||
| 210 | { | ||
| 211 | platform_driver_unregister(&max8998_battery_driver); | ||
| 212 | } | ||
| 213 | module_exit(max8998_battery_cleanup); | ||
| 214 | |||
| 215 | MODULE_DESCRIPTION("MAXIM 8998 battery control driver"); | ||
| 216 | MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); | ||
| 217 | MODULE_LICENSE("GPL"); | ||
| 218 | MODULE_ALIAS("platform:max8998-battery"); | ||
diff --git a/include/linux/mfd/max8998.h b/include/linux/mfd/max8998.h index 61daa167b576..f4f0dfa4698a 100644 --- a/include/linux/mfd/max8998.h +++ b/include/linux/mfd/max8998.h | |||
| @@ -87,6 +87,15 @@ struct max8998_regulator_data { | |||
| 87 | * @wakeup: Allow to wake up from suspend | 87 | * @wakeup: Allow to wake up from suspend |
| 88 | * @rtc_delay: LP3974 RTC chip bug that requires delay after a register | 88 | * @rtc_delay: LP3974 RTC chip bug that requires delay after a register |
| 89 | * write before reading it. | 89 | * write before reading it. |
| 90 | * @eoc: End of Charge Level in percent: 10% ~ 45% by 5% step | ||
| 91 | * If it equals 0, leave it unchanged. | ||
| 92 | * Otherwise, it is a invalid value. | ||
| 93 | * @restart: Restart Level in mV: 100, 150, 200, and -1 for disable. | ||
| 94 | * If it equals 0, leave it unchanged. | ||
| 95 | * Otherwise, it is a invalid value. | ||
| 96 | * @timeout: Full Timeout in hours: 5, 6, 7, and -1 for disable. | ||
| 97 | * If it equals 0, leave it unchanged. | ||
| 98 | * Otherwise, leave it unchanged. | ||
| 90 | */ | 99 | */ |
| 91 | struct max8998_platform_data { | 100 | struct max8998_platform_data { |
| 92 | struct max8998_regulator_data *regulators; | 101 | struct max8998_regulator_data *regulators; |
| @@ -107,6 +116,9 @@ struct max8998_platform_data { | |||
| 107 | int buck2_default_idx; | 116 | int buck2_default_idx; |
| 108 | bool wakeup; | 117 | bool wakeup; |
| 109 | bool rtc_delay; | 118 | bool rtc_delay; |
| 119 | int eoc; | ||
| 120 | int restart; | ||
| 121 | int timeout; | ||
| 110 | }; | 122 | }; |
| 111 | 123 | ||
| 112 | #endif /* __LINUX_MFD_MAX8998_H */ | 124 | #endif /* __LINUX_MFD_MAX8998_H */ |
