olpc_battery.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /*
  2. * Battery driver for One Laptop Per Child board.
  3. *
  4. * Copyright © 2006-2010 David Woodhouse <dwmw2@infradead.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/err.h>
  14. #include <linux/device.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/power_supply.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/sched.h>
  19. #include <linux/olpc-ec.h>
  20. #include <asm/olpc.h>
  21. #define EC_BAT_VOLTAGE 0x10 /* uint16_t, *9.76/32, mV */
  22. #define EC_BAT_CURRENT 0x11 /* int16_t, *15.625/120, mA */
  23. #define EC_BAT_ACR 0x12 /* int16_t, *6250/15, µAh */
  24. #define EC_BAT_TEMP 0x13 /* uint16_t, *100/256, °C */
  25. #define EC_AMB_TEMP 0x14 /* uint16_t, *100/256, °C */
  26. #define EC_BAT_STATUS 0x15 /* uint8_t, bitmask */
  27. #define EC_BAT_SOC 0x16 /* uint8_t, percentage */
  28. #define EC_BAT_SERIAL 0x17 /* uint8_t[6] */
  29. #define EC_BAT_EEPROM 0x18 /* uint8_t adr as input, uint8_t output */
  30. #define EC_BAT_ERRCODE 0x1f /* uint8_t, bitmask */
  31. #define BAT_STAT_PRESENT 0x01
  32. #define BAT_STAT_FULL 0x02
  33. #define BAT_STAT_LOW 0x04
  34. #define BAT_STAT_DESTROY 0x08
  35. #define BAT_STAT_AC 0x10
  36. #define BAT_STAT_CHARGING 0x20
  37. #define BAT_STAT_DISCHARGING 0x40
  38. #define BAT_STAT_TRICKLE 0x80
  39. #define BAT_ERR_INFOFAIL 0x02
  40. #define BAT_ERR_OVERVOLTAGE 0x04
  41. #define BAT_ERR_OVERTEMP 0x05
  42. #define BAT_ERR_GAUGESTOP 0x06
  43. #define BAT_ERR_OUT_OF_CONTROL 0x07
  44. #define BAT_ERR_ID_FAIL 0x09
  45. #define BAT_ERR_ACR_FAIL 0x10
  46. #define BAT_ADDR_MFR_TYPE 0x5F
  47. /*********************************************************************
  48. * Power
  49. *********************************************************************/
  50. static int olpc_ac_get_prop(struct power_supply *psy,
  51. enum power_supply_property psp,
  52. union power_supply_propval *val)
  53. {
  54. int ret = 0;
  55. uint8_t status;
  56. switch (psp) {
  57. case POWER_SUPPLY_PROP_ONLINE:
  58. ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &status, 1);
  59. if (ret)
  60. return ret;
  61. val->intval = !!(status & BAT_STAT_AC);
  62. break;
  63. default:
  64. ret = -EINVAL;
  65. break;
  66. }
  67. return ret;
  68. }
  69. static enum power_supply_property olpc_ac_props[] = {
  70. POWER_SUPPLY_PROP_ONLINE,
  71. };
  72. static struct power_supply olpc_ac = {
  73. .name = "olpc-ac",
  74. .type = POWER_SUPPLY_TYPE_MAINS,
  75. .properties = olpc_ac_props,
  76. .num_properties = ARRAY_SIZE(olpc_ac_props),
  77. .get_property = olpc_ac_get_prop,
  78. };
  79. static char bat_serial[17]; /* Ick */
  80. static int olpc_bat_get_status(union power_supply_propval *val, uint8_t ec_byte)
  81. {
  82. if (olpc_platform_info.ecver > 0x44) {
  83. if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
  84. val->intval = POWER_SUPPLY_STATUS_CHARGING;
  85. else if (ec_byte & BAT_STAT_DISCHARGING)
  86. val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
  87. else if (ec_byte & BAT_STAT_FULL)
  88. val->intval = POWER_SUPPLY_STATUS_FULL;
  89. else /* er,... */
  90. val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
  91. } else {
  92. /* Older EC didn't report charge/discharge bits */
  93. if (!(ec_byte & BAT_STAT_AC)) /* No AC means discharging */
  94. val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
  95. else if (ec_byte & BAT_STAT_FULL)
  96. val->intval = POWER_SUPPLY_STATUS_FULL;
  97. else /* Not _necessarily_ true but EC doesn't tell all yet */
  98. val->intval = POWER_SUPPLY_STATUS_CHARGING;
  99. }
  100. return 0;
  101. }
  102. static int olpc_bat_get_health(union power_supply_propval *val)
  103. {
  104. uint8_t ec_byte;
  105. int ret;
  106. ret = olpc_ec_cmd(EC_BAT_ERRCODE, NULL, 0, &ec_byte, 1);
  107. if (ret)
  108. return ret;
  109. switch (ec_byte) {
  110. case 0:
  111. val->intval = POWER_SUPPLY_HEALTH_GOOD;
  112. break;
  113. case BAT_ERR_OVERTEMP:
  114. val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
  115. break;
  116. case BAT_ERR_OVERVOLTAGE:
  117. val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
  118. break;
  119. case BAT_ERR_INFOFAIL:
  120. case BAT_ERR_OUT_OF_CONTROL:
  121. case BAT_ERR_ID_FAIL:
  122. case BAT_ERR_ACR_FAIL:
  123. val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
  124. break;
  125. default:
  126. /* Eep. We don't know this failure code */
  127. ret = -EIO;
  128. }
  129. return ret;
  130. }
  131. static int olpc_bat_get_mfr(union power_supply_propval *val)
  132. {
  133. uint8_t ec_byte;
  134. int ret;
  135. ec_byte = BAT_ADDR_MFR_TYPE;
  136. ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, &ec_byte, 1);
  137. if (ret)
  138. return ret;
  139. switch (ec_byte >> 4) {
  140. case 1:
  141. val->strval = "Gold Peak";
  142. break;
  143. case 2:
  144. val->strval = "BYD";
  145. break;
  146. default:
  147. val->strval = "Unknown";
  148. break;
  149. }
  150. return ret;
  151. }
  152. static int olpc_bat_get_tech(union power_supply_propval *val)
  153. {
  154. uint8_t ec_byte;
  155. int ret;
  156. ec_byte = BAT_ADDR_MFR_TYPE;
  157. ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, &ec_byte, 1);
  158. if (ret)
  159. return ret;
  160. switch (ec_byte & 0xf) {
  161. case 1:
  162. val->intval = POWER_SUPPLY_TECHNOLOGY_NiMH;
  163. break;
  164. case 2:
  165. val->intval = POWER_SUPPLY_TECHNOLOGY_LiFe;
  166. break;
  167. default:
  168. val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
  169. break;
  170. }
  171. return ret;
  172. }
  173. static int olpc_bat_get_charge_full_design(union power_supply_propval *val)
  174. {
  175. uint8_t ec_byte;
  176. union power_supply_propval tech;
  177. int ret, mfr;
  178. ret = olpc_bat_get_tech(&tech);
  179. if (ret)
  180. return ret;
  181. ec_byte = BAT_ADDR_MFR_TYPE;
  182. ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, &ec_byte, 1);
  183. if (ret)
  184. return ret;
  185. mfr = ec_byte >> 4;
  186. switch (tech.intval) {
  187. case POWER_SUPPLY_TECHNOLOGY_NiMH:
  188. switch (mfr) {
  189. case 1: /* Gold Peak */
  190. val->intval = 3000000*.8;
  191. break;
  192. default:
  193. return -EIO;
  194. }
  195. break;
  196. case POWER_SUPPLY_TECHNOLOGY_LiFe:
  197. switch (mfr) {
  198. case 1: /* Gold Peak */
  199. val->intval = 2800000;
  200. break;
  201. case 2: /* BYD */
  202. val->intval = 3100000;
  203. break;
  204. default:
  205. return -EIO;
  206. }
  207. break;
  208. default:
  209. return -EIO;
  210. }
  211. return ret;
  212. }
  213. static int olpc_bat_get_charge_now(union power_supply_propval *val)
  214. {
  215. uint8_t soc;
  216. union power_supply_propval full;
  217. int ret;
  218. ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &soc, 1);
  219. if (ret)
  220. return ret;
  221. ret = olpc_bat_get_charge_full_design(&full);
  222. if (ret)
  223. return ret;
  224. val->intval = soc * (full.intval / 100);
  225. return 0;
  226. }
  227. /*********************************************************************
  228. * Battery properties
  229. *********************************************************************/
  230. static int olpc_bat_get_property(struct power_supply *psy,
  231. enum power_supply_property psp,
  232. union power_supply_propval *val)
  233. {
  234. int ret = 0;
  235. __be16 ec_word;
  236. uint8_t ec_byte;
  237. __be64 ser_buf;
  238. ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &ec_byte, 1);
  239. if (ret)
  240. return ret;
  241. /* Theoretically there's a race here -- the battery could be
  242. removed immediately after we check whether it's present, and
  243. then we query for some other property of the now-absent battery.
  244. It doesn't matter though -- the EC will return the last-known
  245. information, and it's as if we just ran that _little_ bit faster
  246. and managed to read it out before the battery went away. */
  247. if (!(ec_byte & (BAT_STAT_PRESENT | BAT_STAT_TRICKLE)) &&
  248. psp != POWER_SUPPLY_PROP_PRESENT)
  249. return -ENODEV;
  250. switch (psp) {
  251. case POWER_SUPPLY_PROP_STATUS:
  252. ret = olpc_bat_get_status(val, ec_byte);
  253. if (ret)
  254. return ret;
  255. break;
  256. case POWER_SUPPLY_PROP_CHARGE_TYPE:
  257. if (ec_byte & BAT_STAT_TRICKLE)
  258. val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
  259. else if (ec_byte & BAT_STAT_CHARGING)
  260. val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
  261. else
  262. val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
  263. break;
  264. case POWER_SUPPLY_PROP_PRESENT:
  265. val->intval = !!(ec_byte & (BAT_STAT_PRESENT |
  266. BAT_STAT_TRICKLE));
  267. break;
  268. case POWER_SUPPLY_PROP_HEALTH:
  269. if (ec_byte & BAT_STAT_DESTROY)
  270. val->intval = POWER_SUPPLY_HEALTH_DEAD;
  271. else {
  272. ret = olpc_bat_get_health(val);
  273. if (ret)
  274. return ret;
  275. }
  276. break;
  277. case POWER_SUPPLY_PROP_MANUFACTURER:
  278. ret = olpc_bat_get_mfr(val);
  279. if (ret)
  280. return ret;
  281. break;
  282. case POWER_SUPPLY_PROP_TECHNOLOGY:
  283. ret = olpc_bat_get_tech(val);
  284. if (ret)
  285. return ret;
  286. break;
  287. case POWER_SUPPLY_PROP_VOLTAGE_AVG:
  288. case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  289. ret = olpc_ec_cmd(EC_BAT_VOLTAGE, NULL, 0, (void *)&ec_word, 2);
  290. if (ret)
  291. return ret;
  292. val->intval = (s16)be16_to_cpu(ec_word) * 9760L / 32;
  293. break;
  294. case POWER_SUPPLY_PROP_CURRENT_AVG:
  295. case POWER_SUPPLY_PROP_CURRENT_NOW:
  296. ret = olpc_ec_cmd(EC_BAT_CURRENT, NULL, 0, (void *)&ec_word, 2);
  297. if (ret)
  298. return ret;
  299. val->intval = (s16)be16_to_cpu(ec_word) * 15625L / 120;
  300. break;
  301. case POWER_SUPPLY_PROP_CAPACITY:
  302. ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1);
  303. if (ret)
  304. return ret;
  305. val->intval = ec_byte;
  306. break;
  307. case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
  308. if (ec_byte & BAT_STAT_FULL)
  309. val->intval = POWER_SUPPLY_CAPACITY_LEVEL_FULL;
  310. else if (ec_byte & BAT_STAT_LOW)
  311. val->intval = POWER_SUPPLY_CAPACITY_LEVEL_LOW;
  312. else
  313. val->intval = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
  314. break;
  315. case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
  316. ret = olpc_bat_get_charge_full_design(val);
  317. if (ret)
  318. return ret;
  319. break;
  320. case POWER_SUPPLY_PROP_CHARGE_NOW:
  321. ret = olpc_bat_get_charge_now(val);
  322. if (ret)
  323. return ret;
  324. break;
  325. case POWER_SUPPLY_PROP_TEMP:
  326. ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
  327. if (ret)
  328. return ret;
  329. val->intval = (s16)be16_to_cpu(ec_word) * 100 / 256;
  330. break;
  331. case POWER_SUPPLY_PROP_TEMP_AMBIENT:
  332. ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
  333. if (ret)
  334. return ret;
  335. val->intval = (int)be16_to_cpu(ec_word) * 100 / 256;
  336. break;
  337. case POWER_SUPPLY_PROP_CHARGE_COUNTER:
  338. ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2);
  339. if (ret)
  340. return ret;
  341. val->intval = (s16)be16_to_cpu(ec_word) * 6250 / 15;
  342. break;
  343. case POWER_SUPPLY_PROP_SERIAL_NUMBER:
  344. ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8);
  345. if (ret)
  346. return ret;
  347. sprintf(bat_serial, "%016llx", (long long)be64_to_cpu(ser_buf));
  348. val->strval = bat_serial;
  349. break;
  350. default:
  351. ret = -EINVAL;
  352. break;
  353. }
  354. return ret;
  355. }
  356. static enum power_supply_property olpc_xo1_bat_props[] = {
  357. POWER_SUPPLY_PROP_STATUS,
  358. POWER_SUPPLY_PROP_CHARGE_TYPE,
  359. POWER_SUPPLY_PROP_PRESENT,
  360. POWER_SUPPLY_PROP_HEALTH,
  361. POWER_SUPPLY_PROP_TECHNOLOGY,
  362. POWER_SUPPLY_PROP_VOLTAGE_AVG,
  363. POWER_SUPPLY_PROP_VOLTAGE_NOW,
  364. POWER_SUPPLY_PROP_CURRENT_AVG,
  365. POWER_SUPPLY_PROP_CURRENT_NOW,
  366. POWER_SUPPLY_PROP_CAPACITY,
  367. POWER_SUPPLY_PROP_CAPACITY_LEVEL,
  368. POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
  369. POWER_SUPPLY_PROP_CHARGE_NOW,
  370. POWER_SUPPLY_PROP_TEMP,
  371. POWER_SUPPLY_PROP_TEMP_AMBIENT,
  372. POWER_SUPPLY_PROP_MANUFACTURER,
  373. POWER_SUPPLY_PROP_SERIAL_NUMBER,
  374. POWER_SUPPLY_PROP_CHARGE_COUNTER,
  375. };
  376. /* XO-1.5 does not have ambient temperature property */
  377. static enum power_supply_property olpc_xo15_bat_props[] = {
  378. POWER_SUPPLY_PROP_STATUS,
  379. POWER_SUPPLY_PROP_CHARGE_TYPE,
  380. POWER_SUPPLY_PROP_PRESENT,
  381. POWER_SUPPLY_PROP_HEALTH,
  382. POWER_SUPPLY_PROP_TECHNOLOGY,
  383. POWER_SUPPLY_PROP_VOLTAGE_AVG,
  384. POWER_SUPPLY_PROP_VOLTAGE_NOW,
  385. POWER_SUPPLY_PROP_CURRENT_AVG,
  386. POWER_SUPPLY_PROP_CURRENT_NOW,
  387. POWER_SUPPLY_PROP_CAPACITY,
  388. POWER_SUPPLY_PROP_CAPACITY_LEVEL,
  389. POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
  390. POWER_SUPPLY_PROP_CHARGE_NOW,
  391. POWER_SUPPLY_PROP_TEMP,
  392. POWER_SUPPLY_PROP_MANUFACTURER,
  393. POWER_SUPPLY_PROP_SERIAL_NUMBER,
  394. POWER_SUPPLY_PROP_CHARGE_COUNTER,
  395. };
  396. /* EEPROM reading goes completely around the power_supply API, sadly */
  397. #define EEPROM_START 0x20
  398. #define EEPROM_END 0x80
  399. #define EEPROM_SIZE (EEPROM_END - EEPROM_START)
  400. static ssize_t olpc_bat_eeprom_read(struct file *filp, struct kobject *kobj,
  401. struct bin_attribute *attr, char *buf, loff_t off, size_t count)
  402. {
  403. uint8_t ec_byte;
  404. int ret;
  405. int i;
  406. if (off >= EEPROM_SIZE)
  407. return 0;
  408. if (off + count > EEPROM_SIZE)
  409. count = EEPROM_SIZE - off;
  410. for (i = 0; i < count; i++) {
  411. ec_byte = EEPROM_START + off + i;
  412. ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, &buf[i], 1);
  413. if (ret) {
  414. pr_err("olpc-battery: "
  415. "EC_BAT_EEPROM cmd @ 0x%x failed - %d!\n",
  416. ec_byte, ret);
  417. return -EIO;
  418. }
  419. }
  420. return count;
  421. }
  422. static struct bin_attribute olpc_bat_eeprom = {
  423. .attr = {
  424. .name = "eeprom",
  425. .mode = S_IRUGO,
  426. },
  427. .size = 0,
  428. .read = olpc_bat_eeprom_read,
  429. };
  430. /* Allow userspace to see the specific error value pulled from the EC */
  431. static ssize_t olpc_bat_error_read(struct device *dev,
  432. struct device_attribute *attr, char *buf)
  433. {
  434. uint8_t ec_byte;
  435. ssize_t ret;
  436. ret = olpc_ec_cmd(EC_BAT_ERRCODE, NULL, 0, &ec_byte, 1);
  437. if (ret < 0)
  438. return ret;
  439. return sprintf(buf, "%d\n", ec_byte);
  440. }
  441. static struct device_attribute olpc_bat_error = {
  442. .attr = {
  443. .name = "error",
  444. .mode = S_IRUGO,
  445. },
  446. .show = olpc_bat_error_read,
  447. };
  448. /*********************************************************************
  449. * Initialisation
  450. *********************************************************************/
  451. static struct power_supply olpc_bat = {
  452. .name = "olpc-battery",
  453. .get_property = olpc_bat_get_property,
  454. .use_for_apm = 1,
  455. };
  456. static int olpc_battery_suspend(struct platform_device *pdev,
  457. pm_message_t state)
  458. {
  459. if (device_may_wakeup(olpc_ac.dev))
  460. olpc_ec_wakeup_set(EC_SCI_SRC_ACPWR);
  461. else
  462. olpc_ec_wakeup_clear(EC_SCI_SRC_ACPWR);
  463. if (device_may_wakeup(olpc_bat.dev))
  464. olpc_ec_wakeup_set(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
  465. | EC_SCI_SRC_BATERR);
  466. else
  467. olpc_ec_wakeup_clear(EC_SCI_SRC_BATTERY | EC_SCI_SRC_BATSOC
  468. | EC_SCI_SRC_BATERR);
  469. return 0;
  470. }
  471. static int __devinit olpc_battery_probe(struct platform_device *pdev)
  472. {
  473. int ret;
  474. uint8_t status;
  475. /*
  476. * We've seen a number of EC protocol changes; this driver requires
  477. * the latest EC protocol, supported by 0x44 and above.
  478. */
  479. if (olpc_platform_info.ecver < 0x44) {
  480. printk(KERN_NOTICE "OLPC EC version 0x%02x too old for "
  481. "battery driver.\n", olpc_platform_info.ecver);
  482. return -ENXIO;
  483. }
  484. ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &status, 1);
  485. if (ret)
  486. return ret;
  487. /* Ignore the status. It doesn't actually matter */
  488. ret = power_supply_register(&pdev->dev, &olpc_ac);
  489. if (ret)
  490. return ret;
  491. if (olpc_board_at_least(olpc_board_pre(0xd0))) { /* XO-1.5 */
  492. olpc_bat.properties = olpc_xo15_bat_props;
  493. olpc_bat.num_properties = ARRAY_SIZE(olpc_xo15_bat_props);
  494. } else { /* XO-1 */
  495. olpc_bat.properties = olpc_xo1_bat_props;
  496. olpc_bat.num_properties = ARRAY_SIZE(olpc_xo1_bat_props);
  497. }
  498. ret = power_supply_register(&pdev->dev, &olpc_bat);
  499. if (ret)
  500. goto battery_failed;
  501. ret = device_create_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
  502. if (ret)
  503. goto eeprom_failed;
  504. ret = device_create_file(olpc_bat.dev, &olpc_bat_error);
  505. if (ret)
  506. goto error_failed;
  507. if (olpc_ec_wakeup_available()) {
  508. device_set_wakeup_capable(olpc_ac.dev, true);
  509. device_set_wakeup_capable(olpc_bat.dev, true);
  510. }
  511. return 0;
  512. error_failed:
  513. device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
  514. eeprom_failed:
  515. power_supply_unregister(&olpc_bat);
  516. battery_failed:
  517. power_supply_unregister(&olpc_ac);
  518. return ret;
  519. }
  520. static int __devexit olpc_battery_remove(struct platform_device *pdev)
  521. {
  522. device_remove_file(olpc_bat.dev, &olpc_bat_error);
  523. device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
  524. power_supply_unregister(&olpc_bat);
  525. power_supply_unregister(&olpc_ac);
  526. return 0;
  527. }
  528. static const struct of_device_id olpc_battery_ids[] __devinitconst = {
  529. { .compatible = "olpc,xo1-battery" },
  530. {}
  531. };
  532. MODULE_DEVICE_TABLE(of, olpc_battery_ids);
  533. static struct platform_driver olpc_battery_driver = {
  534. .driver = {
  535. .name = "olpc-battery",
  536. .owner = THIS_MODULE,
  537. .of_match_table = olpc_battery_ids,
  538. },
  539. .probe = olpc_battery_probe,
  540. .remove = __devexit_p(olpc_battery_remove),
  541. .suspend = olpc_battery_suspend,
  542. };
  543. module_platform_driver(olpc_battery_driver);
  544. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  545. MODULE_LICENSE("GPL");
  546. MODULE_DESCRIPTION("Battery driver for One Laptop Per Child 'XO' machine");