Hi, thought someone would find this useful. I added sysfs support to the AM335x kernel TPS65217 driver so I can select the analog mux output selection from user space. I wanted to be able to read the various signals using the AM335x ADC inputs.
Forum won't let us upload .patch files...so here it is as .txt.
Index: linux-3.2.0-psp05.06.00.00/drivers/mfd/tps65217.c =================================================================== --- linux-3.2.0-psp05.06.00.00/drivers/mfd/tps65217.c (revision 26) +++ linux-3.2.0-psp05.06.00.00/drivers/mfd/tps65217.c (working copy) @@ -137,6 +137,78 @@ .val_bits = 8, }; +/* Sys Fs Entries */ +static char* tps65217_mux_table[8] = { + "none", + "vbat", + "vsys", + "vts", + "vicharge", + "mux_in", + "none_6", + "none_7", +}; + +static ssize_t tps65217_analog_mux_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct tps65217 *tps = dev_get_drvdata(dev); + int mux_value; + int ret; + + /* Read and output the current analog mux selection */ + ret = tps65217_reg_read(tps, TPS65217_REG_MUXCTRL, &mux_value); + if (ret) + { + return sprintf(buf, "error\n"); + } + + return sprintf(buf, "%s\n", tps65217_mux_table[mux_value]); +} + +static ssize_t tps65217_analog_mux_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct tps65217 *tps = dev_get_drvdata(dev); + char mux_string[10] = {0}; + int mux_value = 0; + int count = 0; + int ret = -EINVAL; + + /* Copy the signal name into our buffer */ + while((count < size) && (*buf != '0') && (*buf != '\n')) + mux_string[count++] = *buf++; + + /* Find the matching parameter in the mux list */ + while(mux_value < 8) + { + if(strcmp(mux_string, tps65217_mux_table[mux_value]) == 0) + { /* Match found */ + break; + } + + mux_value++; + } + + /* Check if parameter is invalid */ + if(mux_value == 8) + { + dev_info(tps->dev, "Unknown analog mux selection, %s", buf); + return ret; + } + + /* Parameter was found, write the value to the mux register */ + ret = tps65217_reg_write(tps, TPS65217_REG_MUXCTRL, mux_value, 0); + if(ret) + dev_err(tps->dev, "Bus error writing new mux selection, %s\n", mux_string); + + return size; +} + +static DEVICE_ATTR(analog_mux, 0644, tps65217_analog_mux_show, + tps65217_analog_mux_store); + static int __devinit tps65217_probe(struct i2c_client *client, const struct i2c_device_id *ids) { @@ -199,6 +271,8 @@ platform_device_add(pdev); } + + ret = device_create_file(tps->dev, &dev_attr_analog_mux); return 0; @@ -212,6 +286,8 @@ { struct tps65217 *tps = i2c_get_clientdata(client); int i; + + device_remove_file(tps->dev, &dev_attr_analog_mux); for (i = 0; i < TPS65217_NUM_REGULATOR; i++) platform_device_unregister(tps->regulator_pdev[i]);