* [PATCH] New Nokia RX-51 power supply battery driver @ 2012-10-30 20:04 Pali Rohár 2012-10-30 22:39 ` Anton Vorontsov 0 siblings, 1 reply; 15+ messages in thread From: Pali Rohár @ 2012-10-30 20:04 UTC (permalink / raw) To: Anton Vorontsov, David Woodhouse Cc: linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov [-- Attachment #1: Type: text/plain, Size: 9717 bytes --] Hello, I'm sending new power_supply driver which export battery design capacity, battery temperature and voltage on Nokia N900. All these properties are read from battery pins throw twl madc channels. I'm working on full BME replacement for Nokia N900. BME is Nokia proprietary buggy userspace software which charging battery. It has a lot of bugs and is blocker for USB host mode. Charging is done by bq24150a chip and some battery properties can be read from bq27200 chip. But battery design capacity and battery temperature must be read directly from battery (via twl madc channels). So this is reason for another power_supply driver on Nokia N900. Except Nokia RX-51 Schematics there is no available documentation about battery, charging and madc channels (for n900), so all information was RE. Big problem was converting RAW values from channels to standard which kernel report (uAh, uV, 1/100 C). There is no information about RAW unit. So conversation formula for capacity and voltage was taken from maemo binary bsi-read. Temperature formula was somehow computed. But what is important is that proprietary SW BME can report current temperature (in K) and design capacity (in mAh) and also reporting corresponding RAW values. We tested this kernel driver and BME and both reported same battery capacity and temperature (+/- 1C). So data from this driver should be correct (if BME is correct). Driver is only for Nokia N900. It is needed for open source project which will replace BME: https://gitorious.org/rx51-bme-replacement Because twl4030_madc_conversion can be called only from kernel and there is battery interface in power supply it make sense me to write battery driver instead creating some method for exporting function twl4030_madc_conversion to user space (which is done on patched maemo kernel to allow BME calling twl4030_madc_conversion). Thanks to Joerg Reisenweber and Ivaylo Dimitrov for collecting needed data, help with some problems and fixing errors! --- /dev/null +++ kernel-power/drivers/power/rx51_battery.c @@ -0,0 +1,257 @@ +/* + rx51_battery.c - Nokia RX-51 battery driver + Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include <linux/module.h> +#include <linux/param.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/slab.h> +#include <linux/i2c/twl4030-madc.h> + +struct rx51_device_info { + struct device *dev; + struct power_supply bat; +}; + +/* + Read ADCIN channel value, code copied from maemo kernel + */ +static int rx51_battery_read_adc(int channel) +{ + struct twl4030_madc_request req; + + req.channels = (1 << channel); + req.do_avg = 1; + req.method = TWL4030_MADC_SW1; + req.func_cb = NULL; + req.type = TWL4030_MADC_WAIT; + + if (twl4030_madc_conversion(&req) > 0) + return req.rbuf[channel]; + else + return -ENODATA; +} + +/* + Read ADCIN channel 12 (voltage) and convert RAW value to micro voltage + This conversion formula was extracted from maemo program bsi-read + */ +static int rx51_battery_read_voltage(struct rx51_device_info *di) +{ + int voltage = rx51_battery_read_adc(12); + if (voltage < 0) + return voltage; + return 1000 * (10000 * voltage / 1705); +} + +/* + Temperature look-up tables + TEMP = (1/(t1 + 1/298) - 273.15) + Where t1 = (1/B) * ln((RAW_ADC_U * 2.5)/(R * I * 255)) + Formula is based on experimental data, RX-51 CAL data, maemo program bme + and formula from da9052 driver with values R = 100, B = 3380, I = 0.00671 + */ + +/* + Table1 (temperature for first 25 RAW values) + Usage: TEMP = rx51_temp_table1[RAW] + RAW is between 1 and 24 + TEMP is between 201 C and 55 C + */ +static u8 rx51_temp_table1[] = { + 255, 201, 159, 138, 124, 114, 106, 99, 94, 89, 85, 82, 78, 75, + 73, 70, 68, 66, 64, 62, 61, 59, 57, 56, 55 +}; + +/* + Table2 (lowest RAW value for temperature) + Usage: RAW = rx51_temp_table2[TEMP-rx51_temp_table2_first] + TEMP is between 53 C and -32 C + RAW is between 25 and 993 + */ +#define rx51_temp_table2_first 53 +static u16 rx51_temp_table2[] = { + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, + 40, 41, 43, 44, 46, 48, 49, 51, 53, 55, 57, 59, 61, 64, + 66, 69, 71, 74, 77, 80, 83, 86, 90, 94, 97, 101, 106, 110, + 115, 119, 125, 130, 136, 141, 148, 154, 161, 168, 176, 184, 202, 211, + 221, 231, 242, 254, 266, 279, 293, 308, 323, 340, 357, 375, 395, 415, + 437, 460, 485, 511, 539, 568, 600, 633, 669, 706, 747, 790, 836, 885, + 937, 993, 1024 +}; + +/* + Read ADCIN channel 0 (battery temp) and convert value to tenths of Celsius + Use Temperature look-up tables for conversation + */ +static int rx51_battery_read_temperature(struct rx51_device_info *di) +{ + int min = 0; + int max = ARRAY_SIZE(rx51_temp_table2)-1; + int raw = rx51_battery_read_adc(0); + + /* Zero and negative values are undefined */ + if (raw <= 0) + return INT_MAX; + + /* ADC channels are 10 bit, higher value are undefined */ + if (raw >= (1 << 10)) + return INT_MIN; + + /* First check for temperature in first direct table */ + if (raw < ARRAY_SIZE(rx51_temp_table1)) + return rx51_temp_table1[raw] * 100; + + /* Binary search RAW value in second inverse table */ + while (max-min > 1) { + int mid = (max+min)/2; + if (rx51_temp_table2[mid] <= raw) + min = mid; + else if (rx51_temp_table2[mid] > raw) + max = mid; + if (rx51_temp_table2[mid] == raw) + break; + } + + return (rx51_temp_table2_first - min) * 100; +} + +/* + Read ADCIN channel 4 (BSI) and convert RAW value to micro Ah + This conversion formula was extracted from maemo program bsi-read + */ +static int rx51_battery_read_capacity(struct rx51_device_info *di) +{ + int capacity = rx51_battery_read_adc(4); + if (capacity < 0) + return capacity; + return 1280 * (1200 * capacity)/(1024 - capacity); +} + +/* + Return power_supply property + */ +static int rx51_battery_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct rx51_device_info *di = container_of((psy), + struct rx51_device_info, bat); + + switch (psp) { + case POWER_SUPPLY_PROP_TECHNOLOGY: + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; + break; + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + val->intval = 4200000; + break; + case POWER_SUPPLY_PROP_PRESENT: + val->intval = rx51_battery_read_voltage(di) ? 1 : 0; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + val->intval = rx51_battery_read_voltage(di); + break; + case POWER_SUPPLY_PROP_TEMP: + val->intval = rx51_battery_read_temperature(di); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval = rx51_battery_read_capacity(di); + break; + default: + return -EINVAL; + } + + if (val->intval == INT_MAX || val->intval == INT_MIN) + return -EINVAL; + + return 0; +} + +static enum power_supply_property rx51_battery_props[] = { + POWER_SUPPLY_PROP_TECHNOLOGY, + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, +}; + +static int __devinit rx51_battery_probe(struct platform_device *pdev) +{ + struct rx51_device_info *di; + int ret; + + di = kzalloc(sizeof(*di), GFP_KERNEL); + if (!di) + return -ENOMEM; + + platform_set_drvdata(pdev, di); + + di->bat.name = dev_name(&pdev->dev); + di->bat.type = POWER_SUPPLY_TYPE_BATTERY; + di->bat.properties = rx51_battery_props; + di->bat.num_properties = ARRAY_SIZE(rx51_battery_props); + di->bat.get_property = rx51_battery_get_property; + + ret = power_supply_register(di->dev, &di->bat); + if (ret) { + platform_set_drvdata(pdev, NULL); + kfree(di); + return ret; + } + + return 0; +} + +static int __devexit rx51_battery_remove(struct platform_device *pdev) +{ + struct rx51_device_info *di = platform_get_drvdata(pdev); + + power_supply_unregister(&di->bat); + platform_set_drvdata(pdev, NULL); + kfree(di); + + return 0; +} + +static struct platform_driver rx51_battery_driver = { + .probe = rx51_battery_probe, + .remove = __devexit_p(rx51_battery_remove), + .driver = { + .name = "rx51-battery", + .owner = THIS_MODULE, + }, +}; + +static int __init rx51_battery_init(void) +{ + return platform_driver_register(&rx51_battery_driver); +} +module_init(rx51_battery_init); + +static void __exit rx51_battery_exit(void) +{ + platform_driver_unregister(&rx51_battery_driver); +} +module_exit(rx51_battery_exit); + +MODULE_ALIAS("platform:rx51-battery"); +MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); +MODULE_DESCRIPTION("Nokia RX-51 battery driver"); +MODULE_LICENSE("GPL"); -- Pali Rohár pali.rohar@gmail.com [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] New Nokia RX-51 power supply battery driver 2012-10-30 20:04 [PATCH] New Nokia RX-51 power supply battery driver Pali Rohár @ 2012-10-30 22:39 ` Anton Vorontsov 2012-10-31 9:48 ` [PATCH v2] " Pali Rohár 0 siblings, 1 reply; 15+ messages in thread From: Anton Vorontsov @ 2012-10-30 22:39 UTC (permalink / raw) To: Pali Rohár Cc: David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov On Tue, Oct 30, 2012 at 09:04:55PM +0100, Pali Rohár wrote: > I'm working on full BME replacement for Nokia N900. BME is Nokia > proprietary buggy userspace software which charging battery. [...] > Except Nokia RX-51 Schematics there is no available documentation > about battery, charging and madc channels (for n900), so all > information was RE. [...] > Thanks to Joerg Reisenweber and Ivaylo Dimitrov for collecting needed > data, help with some problems and fixing errors! Pali and guys, a huge thank you goes out to you, awesome work! The driver looks great, just a few cosmetic issues. (Please include a Signed-off-by tag on the next resend.) > --- /dev/null > +++ kernel-power/drivers/power/rx51_battery.c > @@ -0,0 +1,257 @@ > +/* > + rx51_battery.c - Nokia RX-51 battery driver > + Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com> > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 2 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License along > + with this program; if not, write to the Free Software Foundation, Inc., > + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > +*/ The canonical multi-line comments are like this: /* * 1 * 2 */ > + > +#include <linux/module.h> > +#include <linux/param.h> > +#include <linux/platform_device.h> > +#include <linux/power_supply.h> > +#include <linux/slab.h> > +#include <linux/i2c/twl4030-madc.h> > + > +struct rx51_device_info { > + struct device *dev; > + struct power_supply bat; > +}; > + > +/* > + Read ADCIN channel value, code copied from maemo kernel > + */ Ditto, style. > +static int rx51_battery_read_adc(int channel) > +{ > + struct twl4030_madc_request req; > + > + req.channels = (1 << channel); Parenthesis are not necessary here. > + req.do_avg = 1; > + req.method = TWL4030_MADC_SW1; > + req.func_cb = NULL; > + req.type = TWL4030_MADC_WAIT; > + > + if (twl4030_madc_conversion(&req) > 0) > + return req.rbuf[channel]; > + else No need for 'else'. Plus, to make it look more like a conventional error-handling, I'd write it as if (twl4030_madc_conversion(&req) <= 0) return -ENODATA; return req.rbuf[channel]; > + return -ENODATA; > +} > + > +/* > + Read ADCIN channel 12 (voltage) and convert RAW value to micro voltage > + This conversion formula was extracted from maemo program bsi-read > + */ Style. > +static int rx51_battery_read_voltage(struct rx51_device_info *di) > +{ > + int voltage = rx51_battery_read_adc(12); Need an empty line here. > + if (voltage < 0) > + return voltage; > + return 1000 * (10000 * voltage / 1705); > +} > + > +/* > + Temperature look-up tables > + TEMP = (1/(t1 + 1/298) - 273.15) > + Where t1 = (1/B) * ln((RAW_ADC_U * 2.5)/(R * I * 255)) > + Formula is based on experimental data, RX-51 CAL data, maemo program bme > + and formula from da9052 driver with values R = 100, B = 3380, I = 0.00671 > + */ > + > +/* > + Table1 (temperature for first 25 RAW values) > + Usage: TEMP = rx51_temp_table1[RAW] > + RAW is between 1 and 24 > + TEMP is between 201 C and 55 C > + */ > +static u8 rx51_temp_table1[] = { > + 255, 201, 159, 138, 124, 114, 106, 99, 94, 89, 85, 82, 78, 75, > + 73, 70, 68, 66, 64, 62, 61, 59, 57, 56, 55 > +}; > + > +/* > + Table2 (lowest RAW value for temperature) > + Usage: RAW = rx51_temp_table2[TEMP-rx51_temp_table2_first] > + TEMP is between 53 C and -32 C > + RAW is between 25 and 993 > + */ > +#define rx51_temp_table2_first 53 > +static u16 rx51_temp_table2[] = { > + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, > + 40, 41, 43, 44, 46, 48, 49, 51, 53, 55, 57, 59, 61, 64, > + 66, 69, 71, 74, 77, 80, 83, 86, 90, 94, 97, 101, 106, 110, > + 115, 119, 125, 130, 136, 141, 148, 154, 161, 168, 176, 184, 202, 211, > + 221, 231, 242, 254, 266, 279, 293, 308, 323, 340, 357, 375, 395, 415, > + 437, 460, 485, 511, 539, 568, 600, 633, 669, 706, 747, 790, 836, 885, > + 937, 993, 1024 > +}; > + > +/* > + Read ADCIN channel 0 (battery temp) and convert value to tenths of Celsius > + Use Temperature look-up tables for conversation > + */ > +static int rx51_battery_read_temperature(struct rx51_device_info *di) > +{ > + int min = 0; > + int max = ARRAY_SIZE(rx51_temp_table2)-1; Need spaces around '-'. > + int raw = rx51_battery_read_adc(0); > + > + /* Zero and negative values are undefined */ > + if (raw <= 0) > + return INT_MAX; > + > + /* ADC channels are 10 bit, higher value are undefined */ > + if (raw >= (1 << 10)) > + return INT_MIN; > + > + /* First check for temperature in first direct table */ > + if (raw < ARRAY_SIZE(rx51_temp_table1)) > + return rx51_temp_table1[raw] * 100; > + > + /* Binary search RAW value in second inverse table */ > + while (max-min > 1) { Spaces around '-'. > + int mid = (max+min)/2; Need an empty line here, spaces around '+' and '/'. > + if (rx51_temp_table2[mid] <= raw) > + min = mid; > + else if (rx51_temp_table2[mid] > raw) > + max = mid; > + if (rx51_temp_table2[mid] == raw) > + break; > + } > + > + return (rx51_temp_table2_first - min) * 100; > +} > + > +/* > + Read ADCIN channel 4 (BSI) and convert RAW value to micro Ah > + This conversion formula was extracted from maemo program bsi-read > + */ > +static int rx51_battery_read_capacity(struct rx51_device_info *di) > +{ > + int capacity = rx51_battery_read_adc(4); Empty line here. > + if (capacity < 0) > + return capacity; > + return 1280 * (1200 * capacity)/(1024 - capacity); > +} > + > +/* > + Return power_supply property > + */ > +static int rx51_battery_get_property(struct power_supply *psy, > + enum power_supply_property psp, > + union power_supply_propval *val) > +{ > + struct rx51_device_info *di = container_of((psy), > + struct rx51_device_info, bat); > + > + switch (psp) { > + case POWER_SUPPLY_PROP_TECHNOLOGY: > + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; > + break; > + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: > + val->intval = 4200000; > + break; > + case POWER_SUPPLY_PROP_PRESENT: > + val->intval = rx51_battery_read_voltage(di) ? 1 : 0; > + break; > + case POWER_SUPPLY_PROP_VOLTAGE_NOW: > + val->intval = rx51_battery_read_voltage(di); > + break; > + case POWER_SUPPLY_PROP_TEMP: > + val->intval = rx51_battery_read_temperature(di); > + break; > + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: > + val->intval = rx51_battery_read_capacity(di); > + break; > + default: > + return -EINVAL; > + } > + > + if (val->intval == INT_MAX || val->intval == INT_MIN) > + return -EINVAL; > + > + return 0; > +} > + > +static enum power_supply_property rx51_battery_props[] = { > + POWER_SUPPLY_PROP_TECHNOLOGY, > + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, > + POWER_SUPPLY_PROP_PRESENT, > + POWER_SUPPLY_PROP_VOLTAGE_NOW, > + POWER_SUPPLY_PROP_TEMP, > + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, > +}; > + > +static int __devinit rx51_battery_probe(struct platform_device *pdev) > +{ > + struct rx51_device_info *di; > + int ret; > + > + di = kzalloc(sizeof(*di), GFP_KERNEL); > + if (!di) > + return -ENOMEM; > + > + platform_set_drvdata(pdev, di); > + > + di->bat.name = dev_name(&pdev->dev); > + di->bat.type = POWER_SUPPLY_TYPE_BATTERY; > + di->bat.properties = rx51_battery_props; > + di->bat.num_properties = ARRAY_SIZE(rx51_battery_props); > + di->bat.get_property = rx51_battery_get_property; > + > + ret = power_supply_register(di->dev, &di->bat); > + if (ret) { > + platform_set_drvdata(pdev, NULL); > + kfree(di); > + return ret; > + } > + > + return 0; > +} > + > +static int __devexit rx51_battery_remove(struct platform_device *pdev) > +{ > + struct rx51_device_info *di = platform_get_drvdata(pdev); > + > + power_supply_unregister(&di->bat); > + platform_set_drvdata(pdev, NULL); > + kfree(di); > + > + return 0; > +} > + > +static struct platform_driver rx51_battery_driver = { > + .probe = rx51_battery_probe, > + .remove = __devexit_p(rx51_battery_remove), > + .driver = { > + .name = "rx51-battery", > + .owner = THIS_MODULE, > + }, > +}; > + > +static int __init rx51_battery_init(void) > +{ > + return platform_driver_register(&rx51_battery_driver); > +} > +module_init(rx51_battery_init); > + > +static void __exit rx51_battery_exit(void) > +{ > + platform_driver_unregister(&rx51_battery_driver); > +} > +module_exit(rx51_battery_exit); I guess these two calls can be replaced by module_platform_driver() macro. > +MODULE_ALIAS("platform:rx51-battery"); > +MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); > +MODULE_DESCRIPTION("Nokia RX-51 battery driver"); > +MODULE_LICENSE("GPL"); Otherwise, it looks very good! Thanks, Anton. ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2] New Nokia RX-51 power supply battery driver 2012-10-30 22:39 ` Anton Vorontsov @ 2012-10-31 9:48 ` Pali Rohár 2012-11-18 23:12 ` Anton Vorontsov 2013-03-30 18:07 ` Pavel Machek 0 siblings, 2 replies; 15+ messages in thread From: Pali Rohár @ 2012-10-31 9:48 UTC (permalink / raw) To: Anton Vorontsov Cc: David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov [-- Attachment #1: Type: text/plain, Size: 8821 bytes --] Hello, I fixed style issues and added it to Makefile and Kconfig. power_supply: Add Nokia RX-51 battery driver This driver exporting battery design capacity, temperature and voltage for battery in Nokia RX-51. This driver is needed for open source battery management on Nokia RX-51 (N900). Signed-off-by: Pali Rohár <pali.rohar@gmail.com> --- /dev/null +++ linux/drivers/power/rx51_battery.c @@ -0,0 +1,251 @@ +/* + * rx51_battery.c - Nokia RX-51 battery driver + * Copyright (C) 2012 Pali Rohár <pali.rohar@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <linux/module.h> +#include <linux/param.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/slab.h> +#include <linux/i2c/twl4030-madc.h> + +struct rx51_device_info { + struct device *dev; + struct power_supply bat; +}; + +/* + * Read ADCIN channel value, code copied from maemo kernel + */ +static int rx51_battery_read_adc(int channel) +{ + struct twl4030_madc_request req; + + req.channels = 1 << channel; + req.do_avg = 1; + req.method = TWL4030_MADC_SW1; + req.func_cb = NULL; + req.type = TWL4030_MADC_WAIT; + + if (twl4030_madc_conversion(&req) <= 0) + return -ENODATA; + + return req.rbuf[channel]; +} + +/* + * Read ADCIN channel 12 (voltage) and convert RAW value to micro voltage + * This conversion formula was extracted from maemo program bsi-read + */ +static int rx51_battery_read_voltage(struct rx51_device_info *di) +{ + int voltage = rx51_battery_read_adc(12); + + if (voltage < 0) + return voltage; + + return 1000 * (10000 * voltage / 1705); +} + +/* + * Temperature look-up tables + * TEMP = (1/(t1 + 1/298) - 273.15) + * Where t1 = (1/B) * ln((RAW_ADC_U * 2.5)/(R * I * 255)) + * Formula is based on experimental data, RX-51 CAL data, maemo program bme + * and formula from da9052 driver with values R = 100, B = 3380, I = 0.00671 + */ + +/* + * Table1 (temperature for first 25 RAW values) + * Usage: TEMP = rx51_temp_table1[RAW] + * RAW is between 1 and 24 + * TEMP is between 201 C and 55 C + */ +static u8 rx51_temp_table1[] = { + 255, 201, 159, 138, 124, 114, 106, 99, 94, 89, 85, 82, 78, 75, + 73, 70, 68, 66, 64, 62, 61, 59, 57, 56, 55 +}; + +/* + * Table2 (lowest RAW value for temperature) + * Usage: RAW = rx51_temp_table2[TEMP-rx51_temp_table2_first] + * TEMP is between 53 C and -32 C + * RAW is between 25 and 993 + */ +#define rx51_temp_table2_first 53 +static u16 rx51_temp_table2[] = { + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, + 40, 41, 43, 44, 46, 48, 49, 51, 53, 55, 57, 59, 61, 64, + 66, 69, 71, 74, 77, 80, 83, 86, 90, 94, 97, 101, 106, 110, + 115, 119, 125, 130, 136, 141, 148, 154, 161, 168, 176, 184, 202, 211, + 221, 231, 242, 254, 266, 279, 293, 308, 323, 340, 357, 375, 395, 415, + 437, 460, 485, 511, 539, 568, 600, 633, 669, 706, 747, 790, 836, 885, + 937, 993, 1024 +}; + +/* + * Read ADCIN channel 0 (battery temp) and convert value to tenths of Celsius + * Use Temperature look-up tables for conversation + */ +static int rx51_battery_read_temperature(struct rx51_device_info *di) +{ + int min = 0; + int max = ARRAY_SIZE(rx51_temp_table2) - 1; + int raw = rx51_battery_read_adc(0); + + /* Zero and negative values are undefined */ + if (raw <= 0) + return INT_MAX; + + /* ADC channels are 10 bit, higher value are undefined */ + if (raw >= (1 << 10)) + return INT_MIN; + + /* First check for temperature in first direct table */ + if (raw < ARRAY_SIZE(rx51_temp_table1)) + return rx51_temp_table1[raw] * 100; + + /* Binary search RAW value in second inverse table */ + while (max - min > 1) { + int mid = (max + min) / 2; + if (rx51_temp_table2[mid] <= raw) + min = mid; + else if (rx51_temp_table2[mid] > raw) + max = mid; + if (rx51_temp_table2[mid] == raw) + break; + } + + return (rx51_temp_table2_first - min) * 100; +} + +/* + * Read ADCIN channel 4 (BSI) and convert RAW value to micro Ah + * This conversion formula was extracted from maemo program bsi-read + */ +static int rx51_battery_read_capacity(struct rx51_device_info *di) +{ + int capacity = rx51_battery_read_adc(4); + + if (capacity < 0) + return capacity; + + return 1280 * (1200 * capacity)/(1024 - capacity); +} + +/* + * Return power_supply property + */ +static int rx51_battery_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct rx51_device_info *di = container_of((psy), + struct rx51_device_info, bat); + + switch (psp) { + case POWER_SUPPLY_PROP_TECHNOLOGY: + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; + break; + case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: + val->intval = 4200000; + break; + case POWER_SUPPLY_PROP_PRESENT: + val->intval = rx51_battery_read_voltage(di) ? 1 : 0; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + val->intval = rx51_battery_read_voltage(di); + break; + case POWER_SUPPLY_PROP_TEMP: + val->intval = rx51_battery_read_temperature(di); + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval = rx51_battery_read_capacity(di); + break; + default: + return -EINVAL; + } + + if (val->intval == INT_MAX || val->intval == INT_MIN) + return -EINVAL; + + return 0; +} + +static enum power_supply_property rx51_battery_props[] = { + POWER_SUPPLY_PROP_TECHNOLOGY, + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, +}; + +static int __devinit rx51_battery_probe(struct platform_device *pdev) +{ + struct rx51_device_info *di; + int ret; + + di = kzalloc(sizeof(*di), GFP_KERNEL); + if (!di) + return -ENOMEM; + + platform_set_drvdata(pdev, di); + + di->bat.name = dev_name(&pdev->dev); + di->bat.type = POWER_SUPPLY_TYPE_BATTERY; + di->bat.properties = rx51_battery_props; + di->bat.num_properties = ARRAY_SIZE(rx51_battery_props); + di->bat.get_property = rx51_battery_get_property; + + ret = power_supply_register(di->dev, &di->bat); + if (ret) { + platform_set_drvdata(pdev, NULL); + kfree(di); + return ret; + } + + return 0; +} + +static int __devexit rx51_battery_remove(struct platform_device *pdev) +{ + struct rx51_device_info *di = platform_get_drvdata(pdev); + + power_supply_unregister(&di->bat); + platform_set_drvdata(pdev, NULL); + kfree(di); + + return 0; +} + +static struct platform_driver rx51_battery_driver = { + .probe = rx51_battery_probe, + .remove = __devexit_p(rx51_battery_remove), + .driver = { + .name = "rx51-battery", + .owner = THIS_MODULE, + }, +}; + +module_platform_driver(rx51_battery_driver); + +MODULE_ALIAS("platform:rx51-battery"); +MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); +MODULE_DESCRIPTION("Nokia RX-51 battery driver"); +MODULE_LICENSE("GPL"); --- linux/drivers/power/Kconfig +++ linux/drivers/power/Kconfig @@ -245,6 +245,12 @@ config BATTERY_INTEL_MID Say Y here to enable the battery driver on Intel MID platforms. +config BATTERY_RX51 + tristate "Nokia RX-51 battery driver" + depends on TWL4030_MADC + help + Say Y here to enable support for battery information on Nokia RX-51. + config CHARGER_ISP1704 tristate "ISP1704 USB Charger Detection" depends on USB_OTG_UTILS --- linux/drivers/power/Makefile +++ linux/drivers/power/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_CHARGER_88PM860X) += 88pm860x_charger.o obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o obj-$(CONFIG_BATTERY_JZ4740) += jz4740-battery.o obj-$(CONFIG_BATTERY_INTEL_MID) += intel_mid_battery.o +obj-$(CONFIG_BATTERY_RX51) += rx51_battery.o obj-$(CONFIG_AB8500_BM) += ab8500_charger.o ab8500_btemp.o ab8500_fg.o abx500_chargalg.o obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o -- Pali Rohár pali.rohar@gmail.com [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2012-10-31 9:48 ` [PATCH v2] " Pali Rohár @ 2012-11-18 23:12 ` Anton Vorontsov 2012-11-19 12:18 ` Pali Rohár 2013-03-30 18:07 ` Pavel Machek 1 sibling, 1 reply; 15+ messages in thread From: Anton Vorontsov @ 2012-11-18 23:12 UTC (permalink / raw) To: Pali Rohár Cc: David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov On Wed, Oct 31, 2012 at 10:48:40AM +0100, Pali Rohár wrote: > Hello, I fixed style issues and added it to Makefile and Kconfig. > > power_supply: Add Nokia RX-51 battery driver > > This driver exporting battery design capacity, temperature and voltage > for battery in Nokia RX-51. This driver is needed for open source > battery management on Nokia RX-51 (N900). > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Looks great, thank you! This is now in the battery git tree. p.s. fwiw, I added the N900 reference to the user-visible Kconfig text: config BATTERY_RX51 - tristate "Nokia RX-51 battery driver" + tristate "Nokia RX-51 (N900) battery driver" depends on TWL4030_MADC help - Say Y here to enable support for battery information on Nokia RX-51. + Say Y here to enable support for battery information on Nokia + RX-51, also known as N900 tablet. ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2012-11-18 23:12 ` Anton Vorontsov @ 2012-11-19 12:18 ` Pali Rohár 2012-11-19 18:20 ` Anton Vorontsov 0 siblings, 1 reply; 15+ messages in thread From: Pali Rohár @ 2012-11-19 12:18 UTC (permalink / raw) To: Anton Vorontsov Cc: David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov [-- Attachment #1: Type: text/plain, Size: 2409 bytes --] On Sunday 18 November 2012 15:12:40 Anton Vorontsov wrote: > On Wed, Oct 31, 2012 at 10:48:40AM +0100, Pali Rohár wrote: > > Hello, I fixed style issues and added it to Makefile and > > Kconfig. > > > > power_supply: Add Nokia RX-51 battery driver > > > > This driver exporting battery design capacity, temperature > > and voltage for battery in Nokia RX-51. This driver is > > needed for open source battery management on Nokia RX-51 > > (N900). > > > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> > > Looks great, thank you! This is now in the battery git tree. > > p.s. > > fwiw, I added the N900 reference to the user-visible Kconfig > text: > > config BATTERY_RX51 > - tristate "Nokia RX-51 battery driver" > + tristate "Nokia RX-51 (N900) battery driver" > depends on TWL4030_MADC > help > - Say Y here to enable support for battery information on > Nokia RX-51. + Say Y here to enable support for battery > information on Nokia + RX-51, also known as N900 tablet. Ok. Here is missing patch which register this driver in Nokia N900 board code. Without it driver is not loaded. >From 0b60efd06a71668439bcb761c6572dd7df91dc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com> Date: Mon, 19 Nov 2012 09:05:24 +0100 Subject: [PATCH 1/3] ARM: OMAP: rx51: Register platform device for rx51_battery driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pali Rohár <pali.rohar@gmail.com> --- arch/arm/mach-omap2/board-rx51-peripherals.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c index 020e03c..fe1ac7e 100644 --- a/arch/arm/mach-omap2/board-rx51-peripherals.c +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c @@ -271,11 +271,17 @@ static struct platform_device rx51_charger_device = { }, }; +static struct platform_device rx51_battery_device = { + .name = "rx51-battery", + .id = -1, +}; + static void __init rx51_charger_init(void) { WARN_ON(gpio_request_one(RX51_USB_TRANSCEIVER_RST_GPIO, GPIOF_OUT_INIT_HIGH, "isp1704_reset")); + platform_device_register(&rx51_battery_device); platform_device_register(&rx51_charger_device); } -- 1.7.10.4 -- Pali Rohár pali.rohar@gmail.com [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2012-11-19 12:18 ` Pali Rohár @ 2012-11-19 18:20 ` Anton Vorontsov 2012-11-21 19:20 ` Tony Lindgren 0 siblings, 1 reply; 15+ messages in thread From: Anton Vorontsov @ 2012-11-19 18:20 UTC (permalink / raw) To: Pali Rohár Cc: David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov, Tony Lindgren, linux-omap On Mon, Nov 19, 2012 at 01:18:29PM +0100, Pali Rohár wrote: [...] > Ok. Here is missing patch which register this driver in Nokia N900 board code. Without it driver is not loaded. Cc'ing OMAP folks. > From 0b60efd06a71668439bcb761c6572dd7df91dc17 Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com> > Date: Mon, 19 Nov 2012 09:05:24 +0100 > Subject: [PATCH 1/3] ARM: OMAP: rx51: Register platform device for > rx51_battery driver > MIME-Version: 1.0 > Content-Type: text/plain; charset=UTF-8 > Content-Transfer-Encoding: 8bit > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> > --- > arch/arm/mach-omap2/board-rx51-peripherals.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c > index 020e03c..fe1ac7e 100644 > --- a/arch/arm/mach-omap2/board-rx51-peripherals.c > +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c > @@ -271,11 +271,17 @@ static struct platform_device rx51_charger_device = { > }, > }; > > +static struct platform_device rx51_battery_device = { > + .name = "rx51-battery", > + .id = -1, > +}; > + > static void __init rx51_charger_init(void) > { > WARN_ON(gpio_request_one(RX51_USB_TRANSCEIVER_RST_GPIO, > GPIOF_OUT_INIT_HIGH, "isp1704_reset")); > > + platform_device_register(&rx51_battery_device); > platform_device_register(&rx51_charger_device); > } > > -- > 1.7.10.4 > > -- > Pali Rohár > pali.rohar@gmail.com ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2012-11-19 18:20 ` Anton Vorontsov @ 2012-11-21 19:20 ` Tony Lindgren 2012-12-17 6:55 ` Anton Vorontsov 0 siblings, 1 reply; 15+ messages in thread From: Tony Lindgren @ 2012-11-21 19:20 UTC (permalink / raw) To: Anton Vorontsov Cc: Pali Rohár, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov, linux-omap * Anton Vorontsov <cbouatmailru@gmail.com> [121119 10:25]: > On Mon, Nov 19, 2012 at 01:18:29PM +0100, Pali Rohár wrote: > [...] > > Ok. Here is missing patch which register this driver in Nokia N900 board code. Without it driver is not loaded. > > Cc'ing OMAP folks. Looks OK to me queue with the other patches in the series: Acked-by: Tony Lindgren <tony@atomide.com> > From 0b60efd06a71668439bcb761c6572dd7df91dc17 Mon Sep 17 00:00:00 2001 > > From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com> > > Date: Mon, 19 Nov 2012 09:05:24 +0100 > > Subject: [PATCH 1/3] ARM: OMAP: rx51: Register platform device for > > rx51_battery driver > > MIME-Version: 1.0 > > Content-Type: text/plain; charset=UTF-8 > > Content-Transfer-Encoding: 8bit > > > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> > > --- > > arch/arm/mach-omap2/board-rx51-peripherals.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c > > index 020e03c..fe1ac7e 100644 > > --- a/arch/arm/mach-omap2/board-rx51-peripherals.c > > +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c > > @@ -271,11 +271,17 @@ static struct platform_device rx51_charger_device = { > > }, > > }; > > > > +static struct platform_device rx51_battery_device = { > > + .name = "rx51-battery", > > + .id = -1, > > +}; > > + > > static void __init rx51_charger_init(void) > > { > > WARN_ON(gpio_request_one(RX51_USB_TRANSCEIVER_RST_GPIO, > > GPIOF_OUT_INIT_HIGH, "isp1704_reset")); > > > > + platform_device_register(&rx51_battery_device); > > platform_device_register(&rx51_charger_device); > > } > > > > -- > > 1.7.10.4 > > > > -- > > Pali Rohár > > pali.rohar@gmail.com ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2012-11-21 19:20 ` Tony Lindgren @ 2012-12-17 6:55 ` Anton Vorontsov 0 siblings, 0 replies; 15+ messages in thread From: Anton Vorontsov @ 2012-12-17 6:55 UTC (permalink / raw) To: Tony Lindgren Cc: Pali Rohár, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov, linux-omap On Wed, Nov 21, 2012 at 11:20:43AM -0800, Tony Lindgren wrote: > * Anton Vorontsov <cbouatmailru@gmail.com> [121119 10:25]: > > On Mon, Nov 19, 2012 at 01:18:29PM +0100, Pali Rohár wrote: > > [...] > > > Ok. Here is missing patch which register this driver in Nokia N900 board code. Without it driver is not loaded. > > > > Cc'ing OMAP folks. > > Looks OK to me queue with the other patches in the series: > > Acked-by: Tony Lindgren <tony@atomide.com> Applied, thanks! (I'll make a second pull request for this window, but no sure if it will make it. We will see.) Thanks, Anton ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2012-10-31 9:48 ` [PATCH v2] " Pali Rohár 2012-11-18 23:12 ` Anton Vorontsov @ 2013-03-30 18:07 ` Pavel Machek 2013-03-30 18:35 ` Anton Vorontsov 1 sibling, 1 reply; 15+ messages in thread From: Pavel Machek @ 2013-03-30 18:07 UTC (permalink / raw) To: Pali Rohár Cc: Anton Vorontsov, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov On Wed 2012-10-31 10:48:40, Pali Rohár wrote: > Hello, I fixed style issues and added it to Makefile and Kconfig. > > power_supply: Add Nokia RX-51 battery driver > > This driver exporting battery design capacity, temperature and voltage > for battery in Nokia RX-51. This driver is needed for open source > battery management on Nokia RX-51 (N900). > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Reviewed-by: Pavel Machek <pavel@ucw.cz> Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2013-03-30 18:07 ` Pavel Machek @ 2013-03-30 18:35 ` Anton Vorontsov 2013-03-30 21:42 ` Pavel Machek 0 siblings, 1 reply; 15+ messages in thread From: Anton Vorontsov @ 2013-03-30 18:35 UTC (permalink / raw) To: Pavel Machek Cc: Pali Rohár, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov On Sat, Mar 30, 2013 at 07:07:05PM +0100, Pavel Machek wrote: > On Wed 2012-10-31 10:48:40, Pali Rohár wrote: > > Hello, I fixed style issues and added it to Makefile and Kconfig. > > > > power_supply: Add Nokia RX-51 battery driver > > > > This driver exporting battery design capacity, temperature and voltage > > for battery in Nokia RX-51. This driver is needed for open source > > battery management on Nokia RX-51 (N900). > > > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> > > Reviewed-by: Pavel Machek <pavel@ucw.cz> Thanks for the review, Pavel! Although, the patch is in Linus' tree long ago. ;-) Anton ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2013-03-30 18:35 ` Anton Vorontsov @ 2013-03-30 21:42 ` Pavel Machek 2013-03-30 22:51 ` Pali Rohár 0 siblings, 1 reply; 15+ messages in thread From: Pavel Machek @ 2013-03-30 21:42 UTC (permalink / raw) To: Anton Vorontsov Cc: Pali Rohár, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov On Sat 2013-03-30 11:35:26, Anton Vorontsov wrote: > On Sat, Mar 30, 2013 at 07:07:05PM +0100, Pavel Machek wrote: > > On Wed 2012-10-31 10:48:40, Pali Rohár wrote: > > > Hello, I fixed style issues and added it to Makefile and Kconfig. > > > > > > power_supply: Add Nokia RX-51 battery driver > > > > > > This driver exporting battery design capacity, temperature and voltage > > > for battery in Nokia RX-51. This driver is needed for open source > > > battery management on Nokia RX-51 (N900). > > > > > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> > > > > Reviewed-by: Pavel Machek <pavel@ucw.cz> > > Thanks for the review, Pavel! Although, the patch is in Linus' tree long > ago. ;-) Yeah... I did a bit of history-digging ;-). Now, I should figure out how to put custom kernel on n900 _and_ keep it in working state at the same time. (I installed some kind of multiboot, then, apt decided to install some u-boot extension. Then it got interesting. I never got my own kernel to work, and u-boot magically disappeared, but I still have working phone :-). Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2013-03-30 21:42 ` Pavel Machek @ 2013-03-30 22:51 ` Pali Rohár 2013-04-09 23:55 ` Pavel Machek ` (2 more replies) 0 siblings, 3 replies; 15+ messages in thread From: Pali Rohár @ 2013-03-30 22:51 UTC (permalink / raw) To: Pavel Machek Cc: Anton Vorontsov, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov [-- Attachment #1: Type: Text/Plain, Size: 2648 bytes --] On Saturday 30 March 2013 22:42:29 Pavel Machek wrote: > On Sat 2013-03-30 11:35:26, Anton Vorontsov wrote: > > On Sat, Mar 30, 2013 at 07:07:05PM +0100, Pavel Machek wrote: > > > On Wed 2012-10-31 10:48:40, Pali Rohár wrote: > > > > Hello, I fixed style issues and added it to Makefile and > > > > Kconfig. > > > > > > > > power_supply: Add Nokia RX-51 battery driver > > > > > > > > This driver exporting battery design capacity, > > > > temperature and voltage for battery in Nokia RX-51. > > > > This driver is needed for open source battery > > > > management on Nokia RX-51 (N900). > > > > > > > > Signed-off-by: Pali Rohár <pali.rohar@gmail.com> > > > > > > Reviewed-by: Pavel Machek <pavel@ucw.cz> > > > > Thanks for the review, Pavel! Although, the patch is in > > Linus' tree long ago. ;-) > > Yeah... I did a bit of history-digging ;-). Now, I should > figure out how to put custom kernel on n900 _and_ keep it in > working state at the same time. > > (I installed some kind of multiboot, then, apt decided to > install some u-boot extension. Then it got interesting. I > never got my own kernel to work, and u-boot magically > disappeared, but I still have working phone :-). > > Pavel Hello Pavel, here are some hints for booting 3.8+ kernel on n900: "multiboot" package from Maemo Extras is horrible hack which can be used only for booting maemo 2.6.28 kernel. it flashing new kernel to n900 nand, then reboot device, start maemo init and mount/chroot into new os dir... after reboot it erasing kernel nand area where is normaly uboot placed, so do not install it! uboot in Maemo Extras cannot boot 3.x kernels because autobuilder (Extras server app for buidling packages) has very old gcc which produced semi-(non)working uboot (can boot some 2.6 kernels). my uboot builds compiled by gcc 4.7 (which can boot 3.8 kernel): http://atrey.karlin.mff.cuni.cz/~pali/u-boot/ info thread about uboot on n900: http://talk.maemo.org/showthread.php?t=81613 kernel git repository with n900 patches (now based on v3.8-rc3): https://gitorious.org/linux-n900/linux-n900 open source flasher 0xFFFF (working on x86-64 too) which can load kernel and initfs via usb to n900 RAM without flashing nand: https://gitorious.org/0xffff/0xffff rescueOS - minimalistic n900 initrams distribution with usb mass storage (eMMC and SD) and usb cdc ether for telnet console http://206.253.166.96/N900/rescueOS/ If you need help with booting some upstream kernel on n900 join to freenode #maemo-alternatives channel :-) -- Pali Rohár pali.rohar@gmail.com [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2013-03-30 22:51 ` Pali Rohár @ 2013-04-09 23:55 ` Pavel Machek 2013-04-10 9:26 ` Pavel Machek 2013-04-10 10:06 ` Pavel Machek 2 siblings, 0 replies; 15+ messages in thread From: Pavel Machek @ 2013-04-09 23:55 UTC (permalink / raw) To: Pali Rohár Cc: Anton Vorontsov, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov HI! > kernel git repository with n900 patches (now based on v3.8-rc3): > https://gitorious.org/linux-n900/linux-n900 Ok, I am getting this with defconfig: CC arch/arm/mach-omap2/board-rx51-peripherals.o arch/arm/mach-omap2/board-rx51-peripherals.c:1040: error: unknown field ‘arb_mode’ specified in initializer arch/arm/mach-omap2/board-rx51-peripherals.c:1040: warning: missing braces around initializer arch/arm/mach-omap2/board-rx51-peripherals.c:1040: warning: (near initialization for ‘rx51_ssi_cl[1].tx_cfg.<anonymous>’) make[1]: *** [arch/arm/mach-omap2/board-rx51-peripherals.o] Error 1 make: *** [arch/arm/mach-omap2] Error 2 I hope I have right tree: commit b6537e4a86afe74cc67dc3f96e145024e0638d0c Author: Pali Rohár <pali.rohar@gmail.com> Date: Sun Feb 17 22:37:21 2013 +0100 rx51_defconfig: Use smiapp driver instead smia-sensor driver for front webcam > open source flasher 0xFFFF (working on x86-64 too) which can load > kernel and initfs via usb to n900 RAM without flashing nand: > https://gitorious.org/0xffff/0xffff This compiles ok, lets see if it works. Thanks, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2013-03-30 22:51 ` Pali Rohár 2013-04-09 23:55 ` Pavel Machek @ 2013-04-10 9:26 ` Pavel Machek 2013-04-10 10:06 ` Pavel Machek 2 siblings, 0 replies; 15+ messages in thread From: Pavel Machek @ 2013-04-10 9:26 UTC (permalink / raw) To: Pali Rohár Cc: Anton Vorontsov, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov Hi! > open source flasher 0xFFFF (working on x86-64 too) which can load > kernel and initfs via usb to n900 RAM without flashing nand: > https://gitorious.org/0xffff/0xffff Well, it compiles, and seems to work. Includes extensive documentation, but... How do I put the device into mode where it responds to 0xffff? It seems to be there for only a second after power off...? n90- has very confusing startup sequence... > If you need help with booting some upstream kernel on n900 join > to freenode #maemo-alternatives channel :-) Hmm, I did, seems I'm alone there :-(. Pavel PS: I seem to need attached patches to get defconfig to compile: diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c index 9fe4bdf..4aa13ce 100644 --- a/arch/arm/mach-omap2/board-rx51-peripherals.c +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c @@ -1037,7 +1037,7 @@ static struct hsi_board_info __initdata rx51_ssi_cl[] = { .mode = HSI_MODE_FRAME, .channels = 4, .speed = 55000, - .arb_mode = HSI_ARB_RR, +// .arb_mode = HSI_ARB_RR, }, .rx_cfg = { .mode = HSI_MODE_FRAME, diff --git a/arch/arm/mach-omap2/board-rx51-smc.S b/arch/arm/mach-omap2/board-rx51-smc.S index 70e2eb7..bdfb2d7 100644 --- a/arch/arm/mach-omap2/board-rx51-smc.S +++ b/arch/arm/mach-omap2/board-rx51-smc.S @@ -20,7 +20,7 @@ * with number of parametrs */ ENTRY(rx51_ppa_smc) - .arch_extension sec +// .arch_extension sec stmfd sp!, {r4-r12, lr} mov r12, r0 @ Copy the secure service ID mov r3, r2 @ Copy the pointer to va_list in R3 diff --git a/drivers/char/hw_random/omap3-rom-asm.S b/drivers/char/hw_random/omap3-rom-asm.S index ce82e16..65d2b5e 100644 --- a/drivers/char/hw_random/omap3-rom-asm.S +++ b/drivers/char/hw_random/omap3-rom-asm.S @@ -12,7 +12,7 @@ #include <asm/assembler.h> ENTRY(omap3_rng_call_rom_asm) - .arch_extension sec +// .arch_extension sec stmfd sp!, {r4-r12, lr} stmfd sp!, {r0-r3} bl v7_flush_dcache_all -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] New Nokia RX-51 power supply battery driver 2013-03-30 22:51 ` Pali Rohár 2013-04-09 23:55 ` Pavel Machek 2013-04-10 9:26 ` Pavel Machek @ 2013-04-10 10:06 ` Pavel Machek 2 siblings, 0 replies; 15+ messages in thread From: Pavel Machek @ 2013-04-10 10:06 UTC (permalink / raw) To: Pali Rohár Cc: Anton Vorontsov, David Woodhouse, linux-kernel, Joerg Reisenweber, Ivaylo Dimitrov Hi! > > > Thanks for the review, Pavel! Although, the patch is in > > > Linus' tree long ago. ;-) > > > > Yeah... I did a bit of history-digging ;-). Now, I should > > figure out how to put custom kernel on n900 _and_ keep it in > > working state at the same time. > > > > (I installed some kind of multiboot, then, apt decided to > > install some u-boot extension. Then it got interesting. I > > never got my own kernel to work, and u-boot magically > > disappeared, but I still have working phone :-). > > Hello Pavel, > > here are some hints for booting 3.8+ kernel on n900: Ok, I have compiled defconfig kernel (with patches, as indicated). sudo src/0xFFFF -m /data/l/linux-n900/arch/arm/boot/zImage -l -b seems to boot it, I see kernel messages scrolling, but it reboots instead of going to the GUI. > "multiboot" package from Maemo Extras is horrible hack which can > be used only for booting maemo 2.6.28 kernel. it flashing new > kernel to n900 nand, then reboot device, start maemo init and > mount/chroot into new os dir... after reboot it erasing kernel > nand area where is normaly uboot placed, so do not install it! I had it already :-(. Removed now. I tried running custom kernel, but then multiboot interfered. I got u-boot installed with help from irc. Unfortunately, the u-boot can not boot kernel-power, so I'm back to original kernel without tethering :-(. > uboot in Maemo Extras cannot boot 3.x kernels because autobuilder > (Extras server app for buidling packages) has very old gcc which > produced semi-(non)working uboot (can boot some 2.6 kernels). > > my uboot builds compiled by gcc 4.7 (which can boot 3.8 kernel): > http://atrey.karlin.mff.cuni.cz/~pali/u-boot/ Can I get away with using u-boot package in the repositories? Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2013-04-10 10:06 UTC | newest] Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-10-30 20:04 [PATCH] New Nokia RX-51 power supply battery driver Pali Rohár 2012-10-30 22:39 ` Anton Vorontsov 2012-10-31 9:48 ` [PATCH v2] " Pali Rohár 2012-11-18 23:12 ` Anton Vorontsov 2012-11-19 12:18 ` Pali Rohár 2012-11-19 18:20 ` Anton Vorontsov 2012-11-21 19:20 ` Tony Lindgren 2012-12-17 6:55 ` Anton Vorontsov 2013-03-30 18:07 ` Pavel Machek 2013-03-30 18:35 ` Anton Vorontsov 2013-03-30 21:42 ` Pavel Machek 2013-03-30 22:51 ` Pali Rohár 2013-04-09 23:55 ` Pavel Machek 2013-04-10 9:26 ` Pavel Machek 2013-04-10 10:06 ` Pavel Machek
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).