linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Dittmer <j.dittmer@portrix.net>
To: Greg KH <greg@kroah.com>
Cc: Mark Studebaker <mds@paradyne.com>,
	azarah@gentoo.org, KML <linux-kernel@vger.kernel.org>,
	Dominik Brodowski <linux@brodo.de>,
	sensors@Stimpy.netroedge.com
Subject: Re: lm sensors sysfs file structure
Date: Thu, 27 Mar 2003 19:40:26 +0100	[thread overview]
Message-ID: <3E83459A.3090803@portrix.net> (raw)
In-Reply-To: <20030326225234.GA27436@kroah.com>

Greg KH wrote:
> That would give us one value per file, use no floating point in the
> kernel (fake or not) and generally make things a whole lot more orderly.
> Also, if a sensor does not have a max value (for example, I don't really
> know if this is true), instead of having to fake a value, it can just
> not create the file.  Then userspace can easily detect this is not
> supported, and is not a placeholder value.
> 

Is this the way you want to go? Just an example for the voltages.

Btw, is it indended behaviour of sysfs, that after writing to a file, 
the size is zero?

ds666:/sys/devices/legacy/i2c-0/i2c_dev_0# echo 100 > in4_min
ds666:/sys/devices/legacy/i2c-0/i2c_dev_0# ls -l in4_min
-rw-r--r--    1 root     root            0 Mar 27 19:18 in4_min


-r--r--r--    1 root     root         4096 Mar 27 19:18 in0_input
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in0_max
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in0_min
-r--r--r--    1 root     root         4096 Mar 27 19:18 in1_input
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in1_max
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in1_min
-r--r--r--    1 root     root         4096 Mar 27 19:18 in2_input
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in2_max
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in2_min
-r--r--r--    1 root     root         4096 Mar 27 19:18 in3_input
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in3_max
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in3_min
-r--r--r--    1 root     root         4096 Mar 27 19:18 in4_input
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in4_max
-rw-r--r--    1 root     root         4096 Mar 27 19:18 in4_min

/* 7 voltage sensors */
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\n", IN_FROM_REG(data->in[nr], nr) );
}

static ssize_t show_in_min(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\n", IN_FROM_REG(data->in_min[nr], nr) );
}

static ssize_t show_in_max(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\n", IN_FROM_REG(data->in_max[nr], nr) );
}

static ssize_t set_in_min(struct device *dev, const char *buf,
                 size_t count, int nr) {
         struct i2c_client *client = to_i2c_client(dev);
         struct via686a_data *data = i2c_get_clientdata(client);
         unsigned long val = simple_strtoul(buf, NULL, 10);
         data->in_min[nr] = IN_TO_REG(val,nr);
         via686a_write_value(client, VIA686A_REG_IN_MIN(nr),
                         data->in_min[nr]);
         return count;
}
static ssize_t set_in_max(struct device *dev, const char *buf,
                 size_t count, int nr) {
         struct i2c_client *client = to_i2c_client(dev);
         struct via686a_data *data = i2c_get_clientdata(client);
         unsigned long val = simple_strtoul(buf, NULL, 10);
         data->in_max[nr] = IN_TO_REG(val,nr);
         via686a_write_value(client, VIA686A_REG_IN_MAX(nr),
                         data->in_max[nr]);
         return count;
}
#define show_in_offset(offset)                                  \
static ssize_t                                                  \
         show_in##offset (struct device *dev, char *buf)         \
{                                                               \
         return show_in(dev, buf, 0x##offset);                   \
}                                                               \
static ssize_t                                                  \
         show_in##offset##_min (struct device *dev, char *buf)   \
{                                                               \
         return show_in_min(dev, buf, 0x##offset);               \
}                                                               \
static ssize_t                                                  \
         show_in##offset##_max (struct device *dev, char *buf)   \
{                                                               \
         return show_in_max(dev, buf, 0x##offset);               \
}                                                               \
static ssize_t set_in##offset##_min (struct device *dev,        \
                 const char *buf, size_t count)                  \
{                                                               \
         return set_in_min(dev, buf, count, 0x##offset);         \
}                                                               \
static ssize_t set_in##offset##_max (struct device *dev,        \
                         const char *buf, size_t count)          \
{                                                               \
         return set_in_max(dev, buf, count, 0x##offset);         \
}                                                               \
static DEVICE_ATTR(in##offset##_input,                          \
                 S_IRUGO, show_in##offset, NULL)                 \
static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR,         \
                 show_in##offset##_min, set_in##offset##_min)    \
static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR,         \
                 show_in##offset##_max, set_in##offset##_max)

show_in_offset(0);
show_in_offset(1);
show_in_offset(2);
show_in_offset(3);
show_in_offset(4);


  parent reply	other threads:[~2003-03-27 18:29 UTC|newest]

Thread overview: 50+ 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
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 [this message]
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
2003-03-27 23:00 lm sensors sysfs file structure Albert Cahalan
2003-03-27 23:10 ` Greg KH
2003-03-28  7:21   ` Martin Schlemmer
2003-03-28  7:40     ` Greg KH
2003-04-03 21:19 Grover, Andrew
2003-04-14 15:16 ` Patrick Mochel

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=3E83459A.3090803@portrix.net \
    --to=j.dittmer@portrix.net \
    --cc=azarah@gentoo.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@brodo.de \
    --cc=mds@paradyne.com \
    --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;
as well as URLs for NNTP newsgroup(s).