diff options
| author | Evan Wilson <evan@oliodevices.com> | 2016-01-20 02:04:03 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit2@ip-172-31-25-77.us-west-1.compute.internal> | 2015-04-16 10:08:13 +0000 |
| commit | 7a919b1fe2429b091d2c983ed554b431d3828abf (patch) | |
| tree | 567b46234ec41d373b263b842ed114c4aab47b4f | |
| parent | c56a16cac1a6c00629fc407bc8a40a106a47020c (diff) | |
| parent | 9177138cf02829830c8d0003815bcff3c8c6b866 (diff) | |
| download | olio-linux-3.10-7a919b1fe2429b091d2c983ed554b431d3828abf.tar.xz olio-linux-3.10-7a919b1fe2429b091d2c983ed554b431d3828abf.zip | |
Merge "Adding sysfs entries for ts81001 that allows requesting current level. Supposed to work with recent (151203) charger firmware, but there may still be work to do." into android-3.10-bringup
| -rw-r--r-- | drivers/staging/triune/ts81001.c | 89 |
1 files changed, 84 insertions, 5 deletions
diff --git a/drivers/staging/triune/ts81001.c b/drivers/staging/triune/ts81001.c index b5ad6cadc49..ed6f8abc78f 100644 --- a/drivers/staging/triune/ts81001.c +++ b/drivers/staging/triune/ts81001.c @@ -63,6 +63,7 @@ const u8 TS81001_CHARGE_CURR_100_LSB = 0x64; /* 0x64 == 100 */ const u8 TS81001_CHARGE_CURR_100_MSB = 0x00; + /*************************************************************************** * Operations */ @@ -127,6 +128,7 @@ static int ts81001_write_i2c_blk(struct i2c_client * client, u8 reg_addr, return ret; } + /*************************************************************************** * ts81001_get_status - get current charger state. * @@ -167,7 +169,8 @@ static int ts81001_get_status (struct ts81001 * ts) { * ts81001_request_charge - ask for current from charger * * This function allows us to set a new current for the charger. It depends - * on the firmware being recent enough, though. + * on the firmware being recent enough, though. Returns the number of bytes + * written, or error (negative values) if needed. */ static int ts81001_request_charge (struct ts81001 * ts, u16 mA) { @@ -306,19 +309,93 @@ static int ts81001_disconnect (struct ts81001 * ts) { #endif static struct ts81001_ops ts_ops = { - .get_status = ts81001_get_status, + .get_status = ts81001_get_status, .request_charge = ts81001_request_charge, - .charge_stop = ts81001_charging_stop, - .charge_start = ts81001_charging_restart, + .charge_stop = ts81001_charging_stop, + .charge_start = ts81001_charging_restart, }; + + +/*************************************************************************** + * sysfs operations + ***************************************************************************/ + +/* sysfs entry for requesting power, mA's. */ + +/*************************************************************************** + * ts81001_sysfs_set_power_request - request power level from TX + * + * This entry allows us to request a certain power level from the TX unit. + * Mainly used for testing. + */ + +static ssize_t ts81001_sysfs_set_power_request ( + struct device * dev, + struct device_attribute * attr, + const char * buf, + size_t count) +{ + int mA_req; + int s; + u16 mA; + ssize_t retval = 0; + + struct ts81001 * ts81001 = + i2c_get_clientdata (to_i2c_client (dev)); + + if ((s = sscanf (buf, "%d\n", &mA_req)) != 1) { + printk ("%s OLIO wrong number of args (%d, expected 1) " + "for power request.\n", __FUNCTION__, s); + retval = -EINVAL; + goto done; + } else { + printk ("%s OLIO read %d for new power level\n", + __FUNCTION__, mA_req); + } + + if (mA_req > 0xffff) { + printk ("%s OLIO warning, max request is %d.\n", + __FUNCTION__, 0xffff); + mA_req = 0xffff; + } + + mA = (u16) mA_req; + + retval = ts81001_request_charge (ts81001, mA); + +done: + return count; +} + +/*************************************************************************** + * ts81001_sysfs_show_power_request - show the power level last requested + * + * This sysfs entry will read the value of the power request registers in + * the ts81001 and return it. + */ + +static ssize_t ts81001_sysfs_show_power_request (struct device * dev, + struct device_attribute * attr, + char * buf) { + + return 0; +} + +static struct device_attribute ts81001_device_attr = + __ATTR(ts81001_power_request, S_IWUGO | S_IRUGO, + ts81001_sysfs_show_power_request, + ts81001_sysfs_set_power_request); + + + /*************************************************************************** * probe */ static int ts81001_i2c_probe(struct i2c_client * client, - const struct i2c_device_id * id) + const struct i2c_device_id * id) { struct ts81001 *ts81001; @@ -343,6 +420,8 @@ static int ts81001_i2c_probe(struct i2c_client * client, i2c_set_clientdata(client, ts81001); + device_create_file (ts81001->dev, &ts81001_device_attr); + olio_debug ("exiting\n"); return ret; |