<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Riccardo,<div>I have merged Daniel’s patch into the 4.0-rc7 kernel (and added some Kconfig + Makefile) [1] but it does not yet work of course.</div><div><br></div><div>I think it will provide the standard /sys/class/power_supply interface. There might be wrappers for older PM APIs but I do not know.</div><div><br></div><div>BR,</div><div>Nikolaus</div><div><br></div><div>[1]: <a href="http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/wip/letux400">http://git.goldelico.com/?p=gta04-kernel.git;a=shortlog;h=refs/heads/wip/letux400</a></div><div><br></div><div><br><div><div>Am 07.04.2015 um 08:58 schrieb Riccardo Mottola <<a href="mailto:multix@gmail.com">multix@gmail.com</a>>:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">This is interesting.<div><br></div><div>What kernel is this patch for and, more important, did you test it a bit?<br><div><br></div><div>O originally hacked GNUstep's battery monitor batmon.app to work on the original 2.4 kernel, using the APM interface, but the values were close to bogus essentially.</div><div><br></div><div><a href="http://gap.nongnu.org/batmon/index.html">http://gap.nongnu.org/batmon/index.html</a><br></div><div><br></div></div><div>I got no continuous voltage and charge information and even the information about the system being plugged in or not were bogus sometimes, wondering if the hardware was actually limited/faulty to just 4 "charge levels".</div><div><br></div><div>Can you tell us more?</div><div><br></div><div>Riccardo</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 4, 2015 at 6:43 PM, Daniel Glöckner <span dir="ltr"><<a href="mailto:daniel-gl@gmx.net" target="_blank">daniel-gl@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The Letux 400 MIPS netbook contains an LPC915 microcontroller to measure<br>
the battery voltage, detect the presence of a charger, and to power the<br>
device off. It is controlled via I2C address 0x28.<br>
<br>
Signed-off-by: Daniel Glöckner <<a href="mailto:daniel-gl@gmx.net">daniel-gl@gmx.net</a>><br>
---<br>
drivers/power/minipc-mcu.c | 167 +++++++++++++++++++++++++++++++++++++++++++++<br>
1 file changed, 167 insertions(+)<br>
create mode 100644 drivers/power/minipc-mcu.c<br>
<br>
diff --git a/drivers/power/minipc-mcu.c b/drivers/power/minipc-mcu.c<br>
new file mode 100644<br>
index 0000000..29d779a<br>
--- /dev/null<br>
+++ b/drivers/power/minipc-mcu.c<br>
@@ -0,0 +1,167 @@<br>
+/*<br>
+ * An I2C driver for the MCU used on the Letux 400<br>
+ * Copyright 2012 Daniel Gloeckner<br>
+ *<br>
+ * This program is free software; you can redistribute it and/or modify<br>
+ * it under the terms of the GNU General Public License version 2 as<br>
+ * published by the Free Software Foundation.<br>
+ */<br>
+<br>
+#include <linux/i2c.h><br>
+#include <linux/power_supply.h><br>
+#include <linux/pm.h><br>
+<br>
+#define DRV_VERSION "1.0"<br>
+<br>
+static struct i2c_client *mcu;<br>
+<br>
+static int minipc_battery_get_properties(struct power_supply *psy,<br>
+ enum power_supply_property psp,<br>
+ union power_supply_propval *val)<br>
+{<br>
+ int ret = 0;<br>
+ switch (psp) {<br>
+ case POWER_SUPPLY_PROP_TECHNOLOGY:<br>
+ val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;<br>
+ break;<br>
+ case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:<br>
+ val->intval = 7000000;<br>
+ break;<br>
+ case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:<br>
+ val->intval = 8400000;<br>
+ break;<br>
+ case POWER_SUPPLY_PROP_VOLTAGE_NOW:<br>
+ ret = i2c_smbus_read_byte_data(mcu, 0xdb);<br>
+ if (ret >= 0) {<br>
+ /* resistor divider scales 8.4V to 3V */<br>
+ /* lpc915 is powered from 3.3V */<br>
+ /* ergo voltage = value * 2.8 * 3.3 / 255 */<br>
+ val->intval = ret * 616000 / 17;<br>
+ ret = 0;<br>
+ }<br>
+ break;<br>
+ default:<br>
+ ret = -EINVAL;<br>
+ }<br>
+ return ret;<br>
+}<br>
+<br>
+static enum power_supply_property minipc_battery_properties[] = {<br>
+ POWER_SUPPLY_PROP_TECHNOLOGY,<br>
+ POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,<br>
+ POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,<br>
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,<br>
+};<br>
+<br>
+static struct power_supply minipc_battery = {<br>
+ .name = "battery",<br>
+ .type = POWER_SUPPLY_TYPE_BATTERY,<br>
+ .properties = minipc_battery_properties,<br>
+ .num_properties = ARRAY_SIZE(minipc_battery_properties),<br>
+ .get_property = minipc_battery_get_properties,<br>
+};<br>
+<br>
+static int minipc_psu_get_properties(struct power_supply *psy,<br>
+ enum power_supply_property psp,<br>
+ union power_supply_propval *val)<br>
+{<br>
+ int ret = 0;<br>
+ switch (psp) {<br>
+ case POWER_SUPPLY_PROP_ONLINE:<br>
+ val->intval = i2c_smbus_read_byte_data(mcu, 0xd9) & 1;<br>
+ if (val->intval < 0)<br>
+ ret = val->intval;<br>
+ break;<br>
+ default:<br>
+ ret = -EINVAL;<br>
+ }<br>
+ return ret;<br>
+}<br>
+<br>
+static enum power_supply_property minipc_psu_properties[] = {<br>
+ POWER_SUPPLY_PROP_ONLINE,<br>
+};<br>
+<br>
+static struct power_supply minipc_psu = {<br>
+ .name = "psu",<br>
+ .type = POWER_SUPPLY_TYPE_MAINS,<br>
+ .properties = minipc_psu_properties,<br>
+ .num_properties = ARRAY_SIZE(minipc_psu_properties),<br>
+ .get_property = minipc_psu_get_properties,<br>
+};<br>
+<br>
+static void minipc_mcu_power_off(void)<br>
+{<br>
+ i2c_smbus_write_byte_data(mcu, 0xd8, 0x01);<br>
+}<br>
+<br>
+static int minipc_mcu_probe(struct i2c_client *client,<br>
+ const struct i2c_device_id *id)<br>
+{<br>
+ dev_dbg(&client->dev, "%s\n", __func__);<br>
+<br>
+ if (mcu)<br>
+ return -EBUSY;<br>
+<br>
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))<br>
+ return -ENODEV;<br>
+<br>
+ dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");<br>
+<br>
+ minipc_battery.use_for_apm = power_supply_register(&client->dev,<br>
+ &minipc_battery);<br>
+ minipc_psu.use_for_apm = power_supply_register(&client->dev,<br>
+ &minipc_psu);<br>
+<br>
+ mcu = client;<br>
+ pm_power_off = minipc_mcu_power_off;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static int minipc_mcu_remove(struct i2c_client *client)<br>
+{<br>
+ if (!mcu)<br>
+ return 0;<br>
+ if (!minipc_battery.use_for_apm)<br>
+ power_supply_unregister(&minipc_battery);<br>
+ if (!minipc_psu.use_for_apm)<br>
+ power_supply_unregister(&minipc_psu);<br>
+ pm_power_off = NULL;<br>
+ mcu = NULL;<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
+static const struct i2c_device_id minipc_mcu_id[] = {<br>
+ { "minipc-mcu", 0 },<br>
+ { }<br>
+};<br>
+MODULE_DEVICE_TABLE(i2c, minipc_mcu_id);<br>
+<br>
+static struct i2c_driver minipc_mcu_driver = {<br>
+ .driver = {<br>
+ .name = "minipc-mcu",<br>
+ },<br>
+ .probe = minipc_mcu_probe,<br>
+ .remove = minipc_mcu_remove,<br>
+ .id_table = minipc_mcu_id,<br>
+};<br>
+<br>
+static int __init minipc_mcu_init(void)<br>
+{<br>
+ return i2c_add_driver(&minipc_mcu_driver);<br>
+}<br>
+<br>
+static void __exit minipc_mcu_exit(void)<br>
+{<br>
+ i2c_del_driver(&minipc_mcu_driver);<br>
+}<br>
+<br>
+MODULE_AUTHOR("Daniel Gloeckner <<a href="mailto:daniel-gl@gmx.net">daniel-gl@gmx.net</a>>");<br>
+MODULE_DESCRIPTION("Letux 400 LPC915 MCU driver");<br>
+MODULE_LICENSE("GPL");<br>
+MODULE_VERSION(DRV_VERSION);<br>
+<br>
+module_init(minipc_mcu_init);<br>
+module_exit(minipc_mcu_exit);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.4<br>
<br>
<br>
_______________________________________________<br>
Mipsbook-devel mailing list<br>
<a href="mailto:Mipsbook-devel@linuxtogo.org">Mipsbook-devel@linuxtogo.org</a><br>
<a href="http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/mipsbook-devel" target="_blank">http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/mipsbook-devel</a><br>
</font></span></blockquote></div><br></div>
_______________________________________________<br>Lenny400 mailing list<br><a href="mailto:Lenny400@goldelico.com">Lenny400@goldelico.com</a><br>http://lists.goldelico.com/mailman/listinfo.cgi/lenny400<br></blockquote></div><br></div></body></html>