From: Greg KH <greg@kroah.com>
To: Jan Dittmer <j.dittmer@portrix.net>
Cc: azarah@gentoo.org, KML <linux-kernel@vger.kernel.org>,
Dominik Brodowski <linux@brodo.de>,
sensors@stimpy.netroedge.com
Subject: Re: w83781d i2c driver updated for 2.5.66 (without sysfs support)
Date: Wed, 26 Mar 2003 12:26:23 -0800 [thread overview]
Message-ID: <20030326202622.GJ24689@kroah.com> (raw)
In-Reply-To: <3E82024A.4000809@portrix.net>
On Wed, Mar 26, 2003 at 08:40:58PM +0100, Jan Dittmer wrote:
> Martin Schlemmer wrote:
> >
> >I did look at the changes needed for sysfs, but this beast have
> >about 6 ctl_tables, and is hairy in general. I am not sure what
> >is the best way to do it for the different chips, so here is what
> >I have until I or somebody else can do the sysfs stuff.
> >
> I've just done this with the via686a driver. Saves about 100 lines of code.
>
> Comments?
<snip>
> +/* following are the sysfs callback functions */
> +static ssize_t show_in(struct device *dev, char *buf, int nr) {
> + struct i2c_client *client = to_i2c_client(dev);
> + struct via686a_data *data = i2c_get_clientdata(client);
> + via686a_update_client(client);
> +
> + return sprintf(buf,"%ld %ld %ld\n",
> + IN_FROM_REG(data->in_min[nr], nr),
> + IN_FROM_REG(data->in_max[nr], nr),
> + IN_FROM_REG(data->in[nr], nr) );
> +}
We should really split these multivalue files up into individual files,
as sysfs is for single value files. Makes parsing easier too.
Here's a patch for the lm75.c driver that does this. As we are going to
need a "generic" read and write for the "real" values that the i2c
drivers use, I added these files to the i2c-proc.c file.
Yes, i2c_read_real() doesn't really work just yet :)
Anyway, I think this is the direction we should be moving to. And what
is "temp_os" and "temp_hyst"? Should these files be named something a
bit more descriptive?
thanks,
greg k-h
diff -Nru a/drivers/i2c/chips/lm75.c b/drivers/i2c/chips/lm75.c
--- a/drivers/i2c/chips/lm75.c Wed Mar 26 12:28:45 2003
+++ b/drivers/i2c/chips/lm75.c Wed Mar 26 12:28:45 2003
@@ -102,6 +102,49 @@
static int lm75_id = 0;
+#define show(value) \
+static ssize_t show_##value(struct device *dev, char *buf) \
+{ \
+ struct i2c_client *client = to_i2c_client(dev); \
+ struct lm75_data *data = i2c_get_clientdata(client); \
+ int temp; \
+ \
+ lm75_update_client(client); \
+ temp = TEMP_FROM_REG(data->value); \
+ return i2c_write_real(buf, temp, 1); \
+}
+show(temp);
+show(temp_os);
+show(temp_hyst);
+
+static ssize_t set_temp_os(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct lm75_data *data = i2c_get_clientdata(client);
+ int temp;
+
+ i2c_read_real(buf, &temp, 1);
+ data->temp_os = TEMP_TO_REG(temp);
+ lm75_write_value(client, LM75_REG_TEMP_OS, data->temp_os);
+ return count;
+}
+
+static ssize_t set_temp_hyst(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct lm75_data *data = i2c_get_clientdata(client);
+ int temp;
+
+ i2c_read_real(buf, &temp, 1);
+ data->temp_hyst = TEMP_TO_REG(temp);
+ lm75_write_value(client, LM75_REG_TEMP_HYST, data->temp_hyst);
+ return count;
+}
+
+static DEVICE_ATTR(temp, S_IRUGO, show_temp, NULL);
+static DEVICE_ATTR(temp_os, 0644, show_temp_os, set_temp_os);
+static DEVICE_ATTR(temp_hyst, 0644, show_temp_hyst, set_temp_hyst);
+
static int lm75_attach_adapter(struct i2c_adapter *adapter)
{
return i2c_detect(adapter, &addr_data, lm75_detect);
@@ -192,6 +235,10 @@
if ((err = i2c_attach_client(new_client)))
goto error3;
+ device_create_file(&new_client->dev, &dev_attr_temp);
+ device_create_file(&new_client->dev, &dev_attr_temp_os);
+ device_create_file(&new_client->dev, &dev_attr_temp_hyst);
+
/* Register a new directory entry with module sensors */
i = i2c_register_entry(new_client, type_name, lm75_dir_table_template);
if (i < 0) {
diff -Nru a/drivers/i2c/i2c-proc.c b/drivers/i2c/i2c-proc.c
--- a/drivers/i2c/i2c-proc.c Wed Mar 26 12:28:45 2003
+++ b/drivers/i2c/i2c-proc.c Wed Mar 26 12:28:45 2003
@@ -381,6 +381,14 @@
return ret;
}
+int i2c_read_real(const char *buf, int *real, int magnitude)
+{
+ char *temp;
+
+ *real = simple_strtoul(buf, &temp, 10);
+
+ return 0;
+}
/* nrels contains initially the maximum number of elements which can be
put in results, and finally the number of elements actually put there.
@@ -499,6 +507,29 @@
return 0;
}
+int i2c_write_real(char *buf, int real, int magnitude)
+{
+ char printfstr[12];
+ int mag;
+ int times;
+ int field_location;
+
+ mag = magnitude;
+ for (times = 1; mag-- > 0; times *= 10)
+ ;
+
+ if (real < 0) {
+ strcpy(printfstr, "-%ld.%0Xld");
+ field_location = 7;
+ } else {
+ strcpy(printfstr, "%ld.%0Xld");
+ field_location = 6;
+ }
+ printfstr[field_location] = magnitude + '0';
+ real = abs(real);
+ return sprintf(buf, printfstr, real / times, real % times);
+}
+
static int i2c_write_reals(int nrels, void *buffer, size_t *bufsize,
long *results, int magnitude)
{
@@ -724,6 +755,8 @@
EXPORT_SYMBOL(i2c_proc_real);
EXPORT_SYMBOL(i2c_sysctl_real);
EXPORT_SYMBOL(i2c_detect);
+EXPORT_SYMBOL(i2c_write_real);
+EXPORT_SYMBOL(i2c_read_real);
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
MODULE_DESCRIPTION("i2c-proc driver");
diff -Nru a/include/linux/i2c-proc.h b/include/linux/i2c-proc.h
--- a/include/linux/i2c-proc.h Wed Mar 26 12:28:45 2003
+++ b/include/linux/i2c-proc.h Wed Mar 26 12:28:45 2003
@@ -410,5 +410,8 @@
char name[SENSORS_PREFIX_MAX + 13];
};
+extern int i2c_write_real(char *buf, int real, int magnitude);
+extern int i2c_read_real(const char *buf, int *real, int magnitude);
+
#endif /* def _LINUX_I2C_PROC_H */
next prev parent reply other threads:[~2003-03-26 20:16 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-25 8:53 i2c driver changes for 2.5.66; adding w83781d support Martin Schlemmer
2003-03-25 17:56 ` Greg KH
2003-03-26 19:04 ` w83781d i2c driver updated for 2.5.66 (without sysfs support) Martin Schlemmer
2003-03-26 19:40 ` Jan Dittmer
2003-03-26 19:54 ` Martin Schlemmer
2003-03-26 20:26 ` Greg KH [this message]
2003-03-26 20:43 ` Christoph Hellwig
2003-03-26 21:23 ` Greg KH
2003-03-26 22:26 ` Mark Studebaker
2003-03-26 22:52 ` lm sensors sysfs file structure Greg KH
2003-03-27 10:46 ` Jan Dittmer
2003-03-27 10:50 ` Martin Schlemmer
2003-03-27 12:27 ` Jan Dittmer
2003-03-27 12:33 ` Martin Schlemmer
2003-03-27 13:05 ` Jan Dittmer
2003-03-27 13:31 ` Jean Delvare
2003-03-27 17:16 ` Mark M. Hoffman
2003-03-27 17:25 ` Greg KH
2003-03-27 18:06 ` Jan Dittmer
2003-03-27 18:13 ` Greg KH
2003-03-30 19:23 ` Pavel Machek
2003-04-01 6:44 ` Greg KH
2003-04-01 20:22 ` Pavel Machek
2003-04-01 23:27 ` Dave Jones
2003-04-03 0:28 ` Greg KH
2003-04-03 10:49 ` Dave Jones
2003-04-03 18:43 ` Dominik Brodowski
2003-03-27 18:40 ` Jan Dittmer
2003-03-27 18:52 ` Greg KH
2003-03-27 18:17 ` Patrick Mochel
2003-03-27 18:57 ` Jan Dittmer
2003-03-27 19:15 ` Martin Schlemmer
2003-03-27 19:25 ` Greg KH
2003-03-27 19:42 ` Greg KH
2003-03-27 20:32 ` Jan Dittmer
2003-03-27 21:53 ` Greg KH
2003-03-27 22:23 ` Mark M. Hoffman
2003-03-28 6:05 ` Martin Schlemmer
2003-03-28 18:34 ` Pavel Machek
2003-03-26 20:29 ` w83781d i2c driver updated for 2.5.66 (without sysfs support) Greg KH
2003-03-26 23:34 ` Martin Schlemmer
2003-03-26 23:46 ` Greg KH
2003-03-30 12:47 ` [PATCH-2.5] w83781d i2c driver updated for 2.5.66-bk4 (with sysfs support, empty tree) Martin Schlemmer
2003-04-02 22:22 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030326202622.GJ24689@kroah.com \
--to=greg@kroah.com \
--cc=azarah@gentoo.org \
--cc=j.dittmer@portrix.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@brodo.de \
--cc=sensors@stimpy.netroedge.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox