|
| 1 | +/* |
| 2 | + * ODROID sysfs support for extra feature enhancement |
| 3 | + * |
| 4 | + * Copyright (C) 2014, Hardkernel Co,.Ltd |
| 5 | + * Author: Charles Park <[email protected]> |
| 6 | + * Author: Dongjin Kim <[email protected]> |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License version 2 as |
| 10 | + * published by the Free Software Foundation. |
| 11 | + * This program is free software; you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation; either version 2 of the License, or (at |
| 14 | + * your option) any later version. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, but |
| 17 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | + * General Public License for more details. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +#include <linux/module.h> |
| 24 | +#include <linux/err.h> |
| 25 | +#include <linux/platform_device.h> |
| 26 | +#include <linux/power_supply.h> |
| 27 | +#include <linux/types.h> |
| 28 | +#include <linux/pci.h> |
| 29 | +#include <linux/interrupt.h> |
| 30 | +#include <linux/io.h> |
| 31 | + |
| 32 | +static struct platform_device *odroid_pdev; |
| 33 | + |
| 34 | +static int odroid_ac_get_property(struct power_supply *psy, |
| 35 | + enum power_supply_property psp, |
| 36 | + union power_supply_propval *val) |
| 37 | +{ |
| 38 | + int ret = 0; |
| 39 | + |
| 40 | + switch (psp) { |
| 41 | + case POWER_SUPPLY_PROP_ONLINE: |
| 42 | + val->intval = 1; |
| 43 | + break; |
| 44 | + default: |
| 45 | + ret = -EINVAL; |
| 46 | + break; |
| 47 | + } |
| 48 | + return ret; |
| 49 | +} |
| 50 | + |
| 51 | +static int odroid_bat_get_property(struct power_supply *psy, |
| 52 | + enum power_supply_property psp, |
| 53 | + union power_supply_propval *val) |
| 54 | +{ |
| 55 | + int ret = 0; |
| 56 | + |
| 57 | + switch (psp) { |
| 58 | + case POWER_SUPPLY_PROP_STATUS: |
| 59 | + val->intval = POWER_SUPPLY_STATUS_CHARGING; |
| 60 | + break; |
| 61 | + case POWER_SUPPLY_PROP_HEALTH: |
| 62 | + val->intval = POWER_SUPPLY_HEALTH_GOOD; |
| 63 | + break; |
| 64 | + case POWER_SUPPLY_PROP_PRESENT: |
| 65 | + val->intval = 1; |
| 66 | + break; |
| 67 | + case POWER_SUPPLY_PROP_TECHNOLOGY: |
| 68 | + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; |
| 69 | + break; |
| 70 | + case POWER_SUPPLY_PROP_CAPACITY: |
| 71 | + val->intval = 100; |
| 72 | + break; |
| 73 | + case POWER_SUPPLY_PROP_TEMP: |
| 74 | + val->intval = 20; |
| 75 | + break; |
| 76 | + case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
| 77 | + val->intval = 5; |
| 78 | + break; |
| 79 | + default: |
| 80 | + ret = -EINVAL; |
| 81 | + break; |
| 82 | + } |
| 83 | + |
| 84 | + return ret; |
| 85 | +} |
| 86 | + |
| 87 | +static enum power_supply_property odroid_battery_props[] = { |
| 88 | + POWER_SUPPLY_PROP_STATUS, |
| 89 | + POWER_SUPPLY_PROP_HEALTH, |
| 90 | + POWER_SUPPLY_PROP_PRESENT, |
| 91 | + POWER_SUPPLY_PROP_TECHNOLOGY, |
| 92 | + POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 93 | + POWER_SUPPLY_PROP_TEMP, |
| 94 | + POWER_SUPPLY_PROP_CAPACITY, |
| 95 | +}; |
| 96 | + |
| 97 | +static enum power_supply_property odroid_ac_props[] = { |
| 98 | + POWER_SUPPLY_PROP_ONLINE, |
| 99 | +}; |
| 100 | + |
| 101 | +static struct power_supply odroid_bat = { |
| 102 | + .name = "battery", |
| 103 | + .type = POWER_SUPPLY_TYPE_BATTERY, |
| 104 | + .properties = odroid_battery_props, |
| 105 | + .num_properties = ARRAY_SIZE(odroid_battery_props), |
| 106 | + .get_property = odroid_bat_get_property, |
| 107 | + .use_for_apm = 1, |
| 108 | +}; |
| 109 | + |
| 110 | +static struct power_supply odroid_ac = { |
| 111 | + .name = "ac", |
| 112 | + .type = POWER_SUPPLY_TYPE_MAINS, |
| 113 | + .properties = odroid_ac_props, |
| 114 | + .num_properties = ARRAY_SIZE(odroid_ac_props), |
| 115 | + .get_property = odroid_ac_get_property, |
| 116 | +}; |
| 117 | + |
| 118 | +static int __init odroid_init(void) |
| 119 | +{ |
| 120 | + int ret = 0; |
| 121 | + |
| 122 | + odroid_pdev = platform_device_register_simple( |
| 123 | + "battery", 0, NULL, 0); |
| 124 | + if (IS_ERR(odroid_pdev)) |
| 125 | + return PTR_ERR(odroid_pdev); |
| 126 | + |
| 127 | + ret = power_supply_register(&odroid_pdev->dev, &odroid_bat); |
| 128 | + if (ret) |
| 129 | + goto bat_failed; |
| 130 | + |
| 131 | + ret = power_supply_register(&odroid_pdev->dev, &odroid_ac); |
| 132 | + if (ret) |
| 133 | + goto ac_failed; |
| 134 | + |
| 135 | + pr_info("adbattery: android dummy battery driver loaded\n"); |
| 136 | + goto success; |
| 137 | + |
| 138 | +bat_failed: |
| 139 | + power_supply_unregister(&odroid_bat); |
| 140 | +ac_failed: |
| 141 | + power_supply_unregister(&odroid_ac); |
| 142 | + platform_device_unregister(odroid_pdev); |
| 143 | +success: |
| 144 | + return ret; |
| 145 | +} |
| 146 | + |
| 147 | +static void __exit odroid_exit(void) |
| 148 | +{ |
| 149 | + power_supply_unregister(&odroid_bat); |
| 150 | + power_supply_unregister(&odroid_ac); |
| 151 | + platform_device_unregister(odroid_pdev); |
| 152 | + pr_info("adbattery: android dummy battery driver unloaded\n"); |
| 153 | +} |
| 154 | + |
| 155 | +module_init(odroid_init); |
| 156 | +module_exit(odroid_exit); |
| 157 | + |
| 158 | +MODULE_AUTHOR( "Dongjin Kim [email protected]"); |
| 159 | +MODULE_LICENSE("GPL"); |
| 160 | +MODULE_DESCRIPTION("Android dummy battery driver"); |
0 commit comments