17b38ebdfSKrzysztof Kozlowski // SPDX-License-Identifier: GPL-2.0 27b38ebdfSKrzysztof Kozlowski // 37b38ebdfSKrzysztof Kozlowski // max17040_battery.c 47b38ebdfSKrzysztof Kozlowski // fuel-gauge systems for lithium-ion (Li+) batteries 57b38ebdfSKrzysztof Kozlowski // 67b38ebdfSKrzysztof Kozlowski // Copyright (C) 2009 Samsung Electronics 77b38ebdfSKrzysztof Kozlowski // Minkyu Kang <mk7.kang@samsung.com> 88c0984e5SSebastian Reichel 98c0984e5SSebastian Reichel #include <linux/module.h> 108c0984e5SSebastian Reichel #include <linux/init.h> 118c0984e5SSebastian Reichel #include <linux/platform_device.h> 128c0984e5SSebastian Reichel #include <linux/mutex.h> 138c0984e5SSebastian Reichel #include <linux/err.h> 148c0984e5SSebastian Reichel #include <linux/i2c.h> 158c0984e5SSebastian Reichel #include <linux/delay.h> 162e17ed94SMatheus Castello #include <linux/interrupt.h> 178c0984e5SSebastian Reichel #include <linux/power_supply.h> 188c0984e5SSebastian Reichel #include <linux/max17040_battery.h> 198c0984e5SSebastian Reichel #include <linux/slab.h> 208c0984e5SSebastian Reichel 2114d60bddSLiu Xiang #define MAX17040_VCELL 0x02 2214d60bddSLiu Xiang #define MAX17040_SOC 0x04 2314d60bddSLiu Xiang #define MAX17040_MODE 0x06 2414d60bddSLiu Xiang #define MAX17040_VER 0x08 2514d60bddSLiu Xiang #define MAX17040_RCOMP 0x0C 2614d60bddSLiu Xiang #define MAX17040_CMD 0xFE 2714d60bddSLiu Xiang 288c0984e5SSebastian Reichel 298c0984e5SSebastian Reichel #define MAX17040_DELAY 1000 308c0984e5SSebastian Reichel #define MAX17040_BATTERY_FULL 95 318c0984e5SSebastian Reichel 32*cccdd0caSMatheus Castello #define MAX17040_ATHD_MASK 0xFFC0 33*cccdd0caSMatheus Castello #define MAX17040_ATHD_DEFAULT_POWER_UP 4 34*cccdd0caSMatheus Castello 358c0984e5SSebastian Reichel struct max17040_chip { 368c0984e5SSebastian Reichel struct i2c_client *client; 378c0984e5SSebastian Reichel struct delayed_work work; 388c0984e5SSebastian Reichel struct power_supply *battery; 398c0984e5SSebastian Reichel struct max17040_platform_data *pdata; 408c0984e5SSebastian Reichel 418c0984e5SSebastian Reichel /* State Of Connect */ 428c0984e5SSebastian Reichel int online; 438c0984e5SSebastian Reichel /* battery voltage */ 448c0984e5SSebastian Reichel int vcell; 458c0984e5SSebastian Reichel /* battery capacity */ 468c0984e5SSebastian Reichel int soc; 478c0984e5SSebastian Reichel /* State Of Charge */ 488c0984e5SSebastian Reichel int status; 49*cccdd0caSMatheus Castello /* Low alert threshold from 32% to 1% of the State of Charge */ 50*cccdd0caSMatheus Castello u32 low_soc_alert; 518c0984e5SSebastian Reichel }; 528c0984e5SSebastian Reichel 538c0984e5SSebastian Reichel static int max17040_get_property(struct power_supply *psy, 548c0984e5SSebastian Reichel enum power_supply_property psp, 558c0984e5SSebastian Reichel union power_supply_propval *val) 568c0984e5SSebastian Reichel { 578c0984e5SSebastian Reichel struct max17040_chip *chip = power_supply_get_drvdata(psy); 588c0984e5SSebastian Reichel 598c0984e5SSebastian Reichel switch (psp) { 608c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_STATUS: 618c0984e5SSebastian Reichel val->intval = chip->status; 628c0984e5SSebastian Reichel break; 638c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_ONLINE: 648c0984e5SSebastian Reichel val->intval = chip->online; 658c0984e5SSebastian Reichel break; 668c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_VOLTAGE_NOW: 678c0984e5SSebastian Reichel val->intval = chip->vcell; 688c0984e5SSebastian Reichel break; 698c0984e5SSebastian Reichel case POWER_SUPPLY_PROP_CAPACITY: 708c0984e5SSebastian Reichel val->intval = chip->soc; 718c0984e5SSebastian Reichel break; 728c0984e5SSebastian Reichel default: 738c0984e5SSebastian Reichel return -EINVAL; 748c0984e5SSebastian Reichel } 758c0984e5SSebastian Reichel return 0; 768c0984e5SSebastian Reichel } 778c0984e5SSebastian Reichel 7814d60bddSLiu Xiang static int max17040_write_reg(struct i2c_client *client, int reg, u16 value) 798c0984e5SSebastian Reichel { 808c0984e5SSebastian Reichel int ret; 818c0984e5SSebastian Reichel 8214d60bddSLiu Xiang ret = i2c_smbus_write_word_swapped(client, reg, value); 838c0984e5SSebastian Reichel 848c0984e5SSebastian Reichel if (ret < 0) 858c0984e5SSebastian Reichel dev_err(&client->dev, "%s: err %d\n", __func__, ret); 868c0984e5SSebastian Reichel 878c0984e5SSebastian Reichel return ret; 888c0984e5SSebastian Reichel } 898c0984e5SSebastian Reichel 908c0984e5SSebastian Reichel static int max17040_read_reg(struct i2c_client *client, int reg) 918c0984e5SSebastian Reichel { 928c0984e5SSebastian Reichel int ret; 938c0984e5SSebastian Reichel 9414d60bddSLiu Xiang ret = i2c_smbus_read_word_swapped(client, reg); 958c0984e5SSebastian Reichel 968c0984e5SSebastian Reichel if (ret < 0) 978c0984e5SSebastian Reichel dev_err(&client->dev, "%s: err %d\n", __func__, ret); 988c0984e5SSebastian Reichel 998c0984e5SSebastian Reichel return ret; 1008c0984e5SSebastian Reichel } 1018c0984e5SSebastian Reichel 1028c0984e5SSebastian Reichel static void max17040_reset(struct i2c_client *client) 1038c0984e5SSebastian Reichel { 10414d60bddSLiu Xiang max17040_write_reg(client, MAX17040_CMD, 0x0054); 1058c0984e5SSebastian Reichel } 1068c0984e5SSebastian Reichel 107*cccdd0caSMatheus Castello static int max17040_set_low_soc_alert(struct i2c_client *client, u32 level) 108*cccdd0caSMatheus Castello { 109*cccdd0caSMatheus Castello int ret; 110*cccdd0caSMatheus Castello u16 data; 111*cccdd0caSMatheus Castello 112*cccdd0caSMatheus Castello level = 32 - level; 113*cccdd0caSMatheus Castello data = max17040_read_reg(client, MAX17040_RCOMP); 114*cccdd0caSMatheus Castello /* clear the alrt bit and set LSb 5 bits */ 115*cccdd0caSMatheus Castello data &= MAX17040_ATHD_MASK; 116*cccdd0caSMatheus Castello data |= level; 117*cccdd0caSMatheus Castello ret = max17040_write_reg(client, MAX17040_RCOMP, data); 118*cccdd0caSMatheus Castello 119*cccdd0caSMatheus Castello return ret; 120*cccdd0caSMatheus Castello } 121*cccdd0caSMatheus Castello 1228c0984e5SSebastian Reichel static void max17040_get_vcell(struct i2c_client *client) 1238c0984e5SSebastian Reichel { 1248c0984e5SSebastian Reichel struct max17040_chip *chip = i2c_get_clientdata(client); 12514d60bddSLiu Xiang u16 vcell; 1268c0984e5SSebastian Reichel 12714d60bddSLiu Xiang vcell = max17040_read_reg(client, MAX17040_VCELL); 1288c0984e5SSebastian Reichel 12914d60bddSLiu Xiang chip->vcell = vcell; 1308c0984e5SSebastian Reichel } 1318c0984e5SSebastian Reichel 1328c0984e5SSebastian Reichel static void max17040_get_soc(struct i2c_client *client) 1338c0984e5SSebastian Reichel { 1348c0984e5SSebastian Reichel struct max17040_chip *chip = i2c_get_clientdata(client); 13514d60bddSLiu Xiang u16 soc; 1368c0984e5SSebastian Reichel 13714d60bddSLiu Xiang soc = max17040_read_reg(client, MAX17040_SOC); 1388c0984e5SSebastian Reichel 13914d60bddSLiu Xiang chip->soc = (soc >> 8); 1408c0984e5SSebastian Reichel } 1418c0984e5SSebastian Reichel 1428c0984e5SSebastian Reichel static void max17040_get_version(struct i2c_client *client) 1438c0984e5SSebastian Reichel { 14414d60bddSLiu Xiang u16 version; 1458c0984e5SSebastian Reichel 14614d60bddSLiu Xiang version = max17040_read_reg(client, MAX17040_VER); 1478c0984e5SSebastian Reichel 14814d60bddSLiu Xiang dev_info(&client->dev, "MAX17040 Fuel-Gauge Ver 0x%x\n", version); 1498c0984e5SSebastian Reichel } 1508c0984e5SSebastian Reichel 1518c0984e5SSebastian Reichel static void max17040_get_online(struct i2c_client *client) 1528c0984e5SSebastian Reichel { 1538c0984e5SSebastian Reichel struct max17040_chip *chip = i2c_get_clientdata(client); 1548c0984e5SSebastian Reichel 1558c0984e5SSebastian Reichel if (chip->pdata && chip->pdata->battery_online) 1568c0984e5SSebastian Reichel chip->online = chip->pdata->battery_online(); 1578c0984e5SSebastian Reichel else 1588c0984e5SSebastian Reichel chip->online = 1; 1598c0984e5SSebastian Reichel } 1608c0984e5SSebastian Reichel 1618c0984e5SSebastian Reichel static void max17040_get_status(struct i2c_client *client) 1628c0984e5SSebastian Reichel { 1638c0984e5SSebastian Reichel struct max17040_chip *chip = i2c_get_clientdata(client); 1648c0984e5SSebastian Reichel 1658c0984e5SSebastian Reichel if (!chip->pdata || !chip->pdata->charger_online 1668c0984e5SSebastian Reichel || !chip->pdata->charger_enable) { 1678c0984e5SSebastian Reichel chip->status = POWER_SUPPLY_STATUS_UNKNOWN; 1688c0984e5SSebastian Reichel return; 1698c0984e5SSebastian Reichel } 1708c0984e5SSebastian Reichel 1718c0984e5SSebastian Reichel if (chip->pdata->charger_online()) { 1728c0984e5SSebastian Reichel if (chip->pdata->charger_enable()) 1738c0984e5SSebastian Reichel chip->status = POWER_SUPPLY_STATUS_CHARGING; 1748c0984e5SSebastian Reichel else 1758c0984e5SSebastian Reichel chip->status = POWER_SUPPLY_STATUS_NOT_CHARGING; 1768c0984e5SSebastian Reichel } else { 1778c0984e5SSebastian Reichel chip->status = POWER_SUPPLY_STATUS_DISCHARGING; 1788c0984e5SSebastian Reichel } 1798c0984e5SSebastian Reichel 1808c0984e5SSebastian Reichel if (chip->soc > MAX17040_BATTERY_FULL) 1818c0984e5SSebastian Reichel chip->status = POWER_SUPPLY_STATUS_FULL; 1828c0984e5SSebastian Reichel } 1838c0984e5SSebastian Reichel 184*cccdd0caSMatheus Castello static int max17040_get_of_data(struct max17040_chip *chip) 185*cccdd0caSMatheus Castello { 186*cccdd0caSMatheus Castello struct device *dev = &chip->client->dev; 187*cccdd0caSMatheus Castello 188*cccdd0caSMatheus Castello chip->low_soc_alert = MAX17040_ATHD_DEFAULT_POWER_UP; 189*cccdd0caSMatheus Castello device_property_read_u32(dev, 190*cccdd0caSMatheus Castello "maxim,alert-low-soc-level", 191*cccdd0caSMatheus Castello &chip->low_soc_alert); 192*cccdd0caSMatheus Castello 193*cccdd0caSMatheus Castello if (chip->low_soc_alert <= 0 || chip->low_soc_alert >= 33) 194*cccdd0caSMatheus Castello return -EINVAL; 195*cccdd0caSMatheus Castello 196*cccdd0caSMatheus Castello return 0; 197*cccdd0caSMatheus Castello } 198*cccdd0caSMatheus Castello 1992e17ed94SMatheus Castello static void max17040_check_changes(struct i2c_client *client) 2002e17ed94SMatheus Castello { 2012e17ed94SMatheus Castello max17040_get_vcell(client); 2022e17ed94SMatheus Castello max17040_get_soc(client); 2032e17ed94SMatheus Castello max17040_get_online(client); 2042e17ed94SMatheus Castello max17040_get_status(client); 2052e17ed94SMatheus Castello } 2062e17ed94SMatheus Castello 2078c0984e5SSebastian Reichel static void max17040_work(struct work_struct *work) 2088c0984e5SSebastian Reichel { 2098c0984e5SSebastian Reichel struct max17040_chip *chip; 2108c0984e5SSebastian Reichel 2118c0984e5SSebastian Reichel chip = container_of(work, struct max17040_chip, work.work); 2122e17ed94SMatheus Castello max17040_check_changes(chip->client); 2138c0984e5SSebastian Reichel 2148c0984e5SSebastian Reichel queue_delayed_work(system_power_efficient_wq, &chip->work, 2158c0984e5SSebastian Reichel MAX17040_DELAY); 2168c0984e5SSebastian Reichel } 2178c0984e5SSebastian Reichel 2182e17ed94SMatheus Castello static irqreturn_t max17040_thread_handler(int id, void *dev) 2192e17ed94SMatheus Castello { 2202e17ed94SMatheus Castello struct max17040_chip *chip = dev; 2212e17ed94SMatheus Castello struct i2c_client *client = chip->client; 2222e17ed94SMatheus Castello 2232e17ed94SMatheus Castello dev_warn(&client->dev, "IRQ: Alert battery low level"); 2242e17ed94SMatheus Castello /* read registers */ 2252e17ed94SMatheus Castello max17040_check_changes(chip->client); 2262e17ed94SMatheus Castello 2272e17ed94SMatheus Castello /* send uevent */ 2282e17ed94SMatheus Castello power_supply_changed(chip->battery); 2292e17ed94SMatheus Castello 230*cccdd0caSMatheus Castello /* reset alert bit */ 231*cccdd0caSMatheus Castello max17040_set_low_soc_alert(client, chip->low_soc_alert); 232*cccdd0caSMatheus Castello 2332e17ed94SMatheus Castello return IRQ_HANDLED; 2342e17ed94SMatheus Castello } 2352e17ed94SMatheus Castello 2362e17ed94SMatheus Castello static int max17040_enable_alert_irq(struct max17040_chip *chip) 2372e17ed94SMatheus Castello { 2382e17ed94SMatheus Castello struct i2c_client *client = chip->client; 2392e17ed94SMatheus Castello unsigned int flags; 2402e17ed94SMatheus Castello int ret; 2412e17ed94SMatheus Castello 2422e17ed94SMatheus Castello flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; 2432e17ed94SMatheus Castello ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, 2442e17ed94SMatheus Castello max17040_thread_handler, flags, 2452e17ed94SMatheus Castello chip->battery->desc->name, chip); 2462e17ed94SMatheus Castello 2472e17ed94SMatheus Castello return ret; 2482e17ed94SMatheus Castello } 2492e17ed94SMatheus Castello 2508c0984e5SSebastian Reichel static enum power_supply_property max17040_battery_props[] = { 2518c0984e5SSebastian Reichel POWER_SUPPLY_PROP_STATUS, 2528c0984e5SSebastian Reichel POWER_SUPPLY_PROP_ONLINE, 2538c0984e5SSebastian Reichel POWER_SUPPLY_PROP_VOLTAGE_NOW, 2548c0984e5SSebastian Reichel POWER_SUPPLY_PROP_CAPACITY, 2558c0984e5SSebastian Reichel }; 2568c0984e5SSebastian Reichel 2578c0984e5SSebastian Reichel static const struct power_supply_desc max17040_battery_desc = { 2588c0984e5SSebastian Reichel .name = "battery", 2598c0984e5SSebastian Reichel .type = POWER_SUPPLY_TYPE_BATTERY, 2608c0984e5SSebastian Reichel .get_property = max17040_get_property, 2618c0984e5SSebastian Reichel .properties = max17040_battery_props, 2628c0984e5SSebastian Reichel .num_properties = ARRAY_SIZE(max17040_battery_props), 2638c0984e5SSebastian Reichel }; 2648c0984e5SSebastian Reichel 2658c0984e5SSebastian Reichel static int max17040_probe(struct i2c_client *client, 2668c0984e5SSebastian Reichel const struct i2c_device_id *id) 2678c0984e5SSebastian Reichel { 2684e9c406dSWolfram Sang struct i2c_adapter *adapter = client->adapter; 2698c0984e5SSebastian Reichel struct power_supply_config psy_cfg = {}; 2708c0984e5SSebastian Reichel struct max17040_chip *chip; 271*cccdd0caSMatheus Castello int ret; 2728c0984e5SSebastian Reichel 2738c0984e5SSebastian Reichel if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 2748c0984e5SSebastian Reichel return -EIO; 2758c0984e5SSebastian Reichel 2768c0984e5SSebastian Reichel chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 2778c0984e5SSebastian Reichel if (!chip) 2788c0984e5SSebastian Reichel return -ENOMEM; 2798c0984e5SSebastian Reichel 2808c0984e5SSebastian Reichel chip->client = client; 2818c0984e5SSebastian Reichel chip->pdata = client->dev.platform_data; 282*cccdd0caSMatheus Castello ret = max17040_get_of_data(chip); 283*cccdd0caSMatheus Castello if (ret) { 284*cccdd0caSMatheus Castello dev_err(&client->dev, 285*cccdd0caSMatheus Castello "failed: low SOC alert OF data out of bounds\n"); 286*cccdd0caSMatheus Castello return ret; 287*cccdd0caSMatheus Castello } 2888c0984e5SSebastian Reichel 2898c0984e5SSebastian Reichel i2c_set_clientdata(client, chip); 2908c0984e5SSebastian Reichel psy_cfg.drv_data = chip; 2918c0984e5SSebastian Reichel 2928c0984e5SSebastian Reichel chip->battery = power_supply_register(&client->dev, 2938c0984e5SSebastian Reichel &max17040_battery_desc, &psy_cfg); 2948c0984e5SSebastian Reichel if (IS_ERR(chip->battery)) { 2958c0984e5SSebastian Reichel dev_err(&client->dev, "failed: power supply register\n"); 2968c0984e5SSebastian Reichel return PTR_ERR(chip->battery); 2978c0984e5SSebastian Reichel } 2988c0984e5SSebastian Reichel 2998c0984e5SSebastian Reichel max17040_reset(client); 3008c0984e5SSebastian Reichel max17040_get_version(client); 3018c0984e5SSebastian Reichel 3022e17ed94SMatheus Castello /* check interrupt */ 3032e17ed94SMatheus Castello if (client->irq && of_device_is_compatible(client->dev.of_node, 3042e17ed94SMatheus Castello "maxim,max77836-battery")) { 305*cccdd0caSMatheus Castello ret = max17040_set_low_soc_alert(client, chip->low_soc_alert); 306*cccdd0caSMatheus Castello if (ret) { 307*cccdd0caSMatheus Castello dev_err(&client->dev, 308*cccdd0caSMatheus Castello "Failed to set low SOC alert: err %d\n", ret); 309*cccdd0caSMatheus Castello return ret; 310*cccdd0caSMatheus Castello } 3112e17ed94SMatheus Castello 3122e17ed94SMatheus Castello ret = max17040_enable_alert_irq(chip); 3132e17ed94SMatheus Castello if (ret) { 3142e17ed94SMatheus Castello client->irq = 0; 3152e17ed94SMatheus Castello dev_warn(&client->dev, 3162e17ed94SMatheus Castello "Failed to get IRQ err %d\n", ret); 3172e17ed94SMatheus Castello } 3182e17ed94SMatheus Castello } 3192e17ed94SMatheus Castello 3208c0984e5SSebastian Reichel INIT_DEFERRABLE_WORK(&chip->work, max17040_work); 3218c0984e5SSebastian Reichel queue_delayed_work(system_power_efficient_wq, &chip->work, 3228c0984e5SSebastian Reichel MAX17040_DELAY); 3238c0984e5SSebastian Reichel 3248c0984e5SSebastian Reichel return 0; 3258c0984e5SSebastian Reichel } 3268c0984e5SSebastian Reichel 3278c0984e5SSebastian Reichel static int max17040_remove(struct i2c_client *client) 3288c0984e5SSebastian Reichel { 3298c0984e5SSebastian Reichel struct max17040_chip *chip = i2c_get_clientdata(client); 3308c0984e5SSebastian Reichel 3318c0984e5SSebastian Reichel power_supply_unregister(chip->battery); 3328c0984e5SSebastian Reichel cancel_delayed_work(&chip->work); 3338c0984e5SSebastian Reichel return 0; 3348c0984e5SSebastian Reichel } 3358c0984e5SSebastian Reichel 3368c0984e5SSebastian Reichel #ifdef CONFIG_PM_SLEEP 3378c0984e5SSebastian Reichel 3388c0984e5SSebastian Reichel static int max17040_suspend(struct device *dev) 3398c0984e5SSebastian Reichel { 3408c0984e5SSebastian Reichel struct i2c_client *client = to_i2c_client(dev); 3418c0984e5SSebastian Reichel struct max17040_chip *chip = i2c_get_clientdata(client); 3428c0984e5SSebastian Reichel 3438c0984e5SSebastian Reichel cancel_delayed_work(&chip->work); 3442e17ed94SMatheus Castello 3452e17ed94SMatheus Castello if (client->irq) { 3462e17ed94SMatheus Castello if (device_may_wakeup(dev)) 3472e17ed94SMatheus Castello enable_irq_wake(client->irq); 3482e17ed94SMatheus Castello else 3492e17ed94SMatheus Castello disable_irq_wake(client->irq); 3502e17ed94SMatheus Castello } 3512e17ed94SMatheus Castello 3528c0984e5SSebastian Reichel return 0; 3538c0984e5SSebastian Reichel } 3548c0984e5SSebastian Reichel 3558c0984e5SSebastian Reichel static int max17040_resume(struct device *dev) 3568c0984e5SSebastian Reichel { 3578c0984e5SSebastian Reichel struct i2c_client *client = to_i2c_client(dev); 3588c0984e5SSebastian Reichel struct max17040_chip *chip = i2c_get_clientdata(client); 3598c0984e5SSebastian Reichel 3608c0984e5SSebastian Reichel queue_delayed_work(system_power_efficient_wq, &chip->work, 3618c0984e5SSebastian Reichel MAX17040_DELAY); 3622e17ed94SMatheus Castello 3632e17ed94SMatheus Castello if (client->irq) { 3642e17ed94SMatheus Castello if (device_may_wakeup(dev)) 3652e17ed94SMatheus Castello disable_irq_wake(client->irq); 3662e17ed94SMatheus Castello else 3672e17ed94SMatheus Castello enable_irq_wake(client->irq); 3682e17ed94SMatheus Castello } 3692e17ed94SMatheus Castello 3708c0984e5SSebastian Reichel return 0; 3718c0984e5SSebastian Reichel } 3728c0984e5SSebastian Reichel 3738c0984e5SSebastian Reichel static SIMPLE_DEV_PM_OPS(max17040_pm_ops, max17040_suspend, max17040_resume); 3748c0984e5SSebastian Reichel #define MAX17040_PM_OPS (&max17040_pm_ops) 3758c0984e5SSebastian Reichel 3768c0984e5SSebastian Reichel #else 3778c0984e5SSebastian Reichel 3788c0984e5SSebastian Reichel #define MAX17040_PM_OPS NULL 3798c0984e5SSebastian Reichel 3808c0984e5SSebastian Reichel #endif /* CONFIG_PM_SLEEP */ 3818c0984e5SSebastian Reichel 3828c0984e5SSebastian Reichel static const struct i2c_device_id max17040_id[] = { 3838c0984e5SSebastian Reichel { "max17040" }, 3848c0984e5SSebastian Reichel { "max77836-battery" }, 3858c0984e5SSebastian Reichel { } 3868c0984e5SSebastian Reichel }; 3878c0984e5SSebastian Reichel MODULE_DEVICE_TABLE(i2c, max17040_id); 3888c0984e5SSebastian Reichel 389da28122cSJavier Martinez Canillas static const struct of_device_id max17040_of_match[] = { 390da28122cSJavier Martinez Canillas { .compatible = "maxim,max17040" }, 391da28122cSJavier Martinez Canillas { .compatible = "maxim,max77836-battery" }, 392da28122cSJavier Martinez Canillas { }, 393da28122cSJavier Martinez Canillas }; 394da28122cSJavier Martinez Canillas MODULE_DEVICE_TABLE(of, max17040_of_match); 395da28122cSJavier Martinez Canillas 3968c0984e5SSebastian Reichel static struct i2c_driver max17040_i2c_driver = { 3978c0984e5SSebastian Reichel .driver = { 3988c0984e5SSebastian Reichel .name = "max17040", 399da28122cSJavier Martinez Canillas .of_match_table = max17040_of_match, 4008c0984e5SSebastian Reichel .pm = MAX17040_PM_OPS, 4018c0984e5SSebastian Reichel }, 4028c0984e5SSebastian Reichel .probe = max17040_probe, 4038c0984e5SSebastian Reichel .remove = max17040_remove, 4048c0984e5SSebastian Reichel .id_table = max17040_id, 4058c0984e5SSebastian Reichel }; 4068c0984e5SSebastian Reichel module_i2c_driver(max17040_i2c_driver); 4078c0984e5SSebastian Reichel 4088c0984e5SSebastian Reichel MODULE_AUTHOR("Minkyu Kang <mk7.kang@samsung.com>"); 4098c0984e5SSebastian Reichel MODULE_DESCRIPTION("MAX17040 Fuel Gauge"); 4108c0984e5SSebastian Reichel MODULE_LICENSE("GPL"); 411