summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/staging/triune/ts81001.c89
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;