Re: [PATCH 2/3] ideapad: Add nodes in sysfs
From: Corentin Chary
Date: Thu Jun 02 2011 - 05:48:37 EST
On Thu, Jun 2, 2011 at 11:24 AM, Ike Panhc <ike.pan@xxxxxxxxxxxxx> wrote:
> Create the following nodes in sysfs
> Â Â Â Â/sys/devices/platform/ideapad/brightness
> Â Â Â Â/sys/devices/platform/ideapad/touchpad
> Â Â Â Â/sys/devices/platform/ideapad/cfg
> Â Â Â Â/sys/devices/platform/ideapad/backlight
>
> Signed-off-by: Ike Panhc <ike.pan@xxxxxxxxxxxxx>
> ---
> Â.../ABI/testing/sysfs-platform-ideapad-laptop   Â|  30 +++++
> Âdrivers/platform/x86/ideapad-laptop.c       Â| Â128 +++++++++++++++++---
> Â2 files changed, 140 insertions(+), 18 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop
> index 807fca2..869f0c4 100644
> --- a/Documentation/ABI/testing/sysfs-platform-ideapad-laptop
> +++ b/Documentation/ABI/testing/sysfs-platform-ideapad-laptop
> @@ -4,3 +4,33 @@ KernelVersion: 2.6.37
> ÂContact: Â Â Â "Ike Panhc <ike.pan@xxxxxxxxxxxxx>"
> ÂDescription:
> Â Â Â Â Â Â Â ÂControl the power of camera module. 1 means on, 0 means off.
> +
> +What: Â Â Â Â Â/sys/devices/platform/ideapad/brightness
> +Date: Â Â Â Â ÂJun 2011
> +KernelVersion: 3.0.1
> +Contact: Â Â Â "Ike Panhc <ike.pan@xxxxxxxxxxxxx>"
> +Description:
> + Â Â Â Â Â Â Â Brightness control. When reading, it shows <current>/<max>.
> + Â Â Â Â Â Â Â When writing, it accepts new brightness value.
> +
> +What: Â Â Â Â Â/sys/devices/platform/ideapad/touchpad
> +Date: Â Â Â Â ÂJun 2011
> +KernelVersion: 3.0.1
> +Contact: Â Â Â "Ike Panhc <ike.pan@xxxxxxxxxxxxx>"
> +Description:
> + Â Â Â Â Â Â Â Control the power of touchpad. 1 means on, 0 means off.
> +
> +What: Â Â Â Â Â/sys/devices/platform/ideapad/cfg
> +Date: Â Â Â Â ÂJun 2011
> +KernelVersion: 3.0.1
> +Contact: Â Â Â "Ike Panhc <ike.pan@xxxxxxxxxxxxx>"
> +Description:
> + Â Â Â Â Â Â Â Ideapad capability bits.
> +
> +What: Â Â Â Â Â/sys/devices/platform/ideapad/backlight
> +Date: Â Â Â Â ÂJun 2011
> +KernelVersion: 3.0.1
> +Contact: Â Â Â "Ike Panhc <ike.pan@xxxxxxxxxxxxx>"
> +Description:
> + Â Â Â Â Â Â Â Control the power of backlight. 1 means on, 0 means off.
> +
> diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
> index a5c0efa..9c09891 100644
> --- a/drivers/platform/x86/ideapad-laptop.c
> +++ b/drivers/platform/x86/ideapad-laptop.c
> @@ -160,22 +160,25 @@ static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
> Â}
>
> Â/*
> - * camera power
> + * sysfs helper
> Â*/
> -static ssize_t show_ideapad_cam(struct device *dev,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct device_attribute *attr,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *buf)
> +static ssize_t show_ideapad_helper(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âchar *buf,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âint cmd)
> Â{
> Â Â Â Âunsigned long result;
>
> - Â Â Â if (read_ec_data(ideapad_handle, 0x1D, &result))
> + Â Â Â if (read_ec_data(ideapad_handle, cmd, &result))
> Â Â Â Â Â Â Â Âreturn sprintf(buf, "-1\n");
> Â Â Â Âreturn sprintf(buf, "%lu\n", result);
> Â}
>
> -static ssize_t store_ideapad_cam(struct device *dev,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct device_attribute *attr,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âconst char *buf, size_t count)
> +static ssize_t store_ideapad_helper(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const char *buf,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â size_t count,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â int cmd)
> Â{
> Â Â Â Âint ret, state;
>
> @@ -183,14 +186,112 @@ static ssize_t store_ideapad_cam(struct device *dev,
> Â Â Â Â Â Â Â Âreturn 0;
> Â Â Â Âif (sscanf(buf, "%i", &state) != 1)
> Â Â Â Â Â Â Â Âreturn -EINVAL;
> - Â Â Â ret = write_ec_cmd(ideapad_handle, 0x1E, state);
> + Â Â Â ret = write_ec_cmd(ideapad_handle, cmd, state);
> Â Â Â Âif (ret < 0)
> Â Â Â Â Â Â Â Âreturn ret;
> Â Â Â Âreturn count;
> Â}
>
> +/*
> + * sysfs node
> + */
> +static ssize_t show_ideapad_cam(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *buf)
> +{
> + Â Â Â return show_ideapad_helper(dev, attr, buf, 0x1D);
> +}
> +
> +static ssize_t store_ideapad_cam(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âconst char *buf, size_t count)
> +{
> + Â Â Â return store_ideapad_helper(dev, attr, buf, count, 0x1E);
> +}
> +
> Âstatic DEVICE_ATTR(camera_power, 0644, show_ideapad_cam, store_ideapad_cam);
>
> +static ssize_t show_ideapad_touchpad(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âchar *buf)
> +{
> + Â Â Â return show_ideapad_helper(dev, attr, buf, 0x1B);
> +}
> +
> +static ssize_t store_ideapad_touchpad(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const char *buf, size_t count)
> +{
> + Â Â Â return store_ideapad_helper(dev, attr, buf, count, 0x1C);
> +}
> +
> +static DEVICE_ATTR(touchpad, 0644, show_ideapad_touchpad,
> + Â Â Â Â Â Â Â Â Âstore_ideapad_touchpad);
> +
> +static ssize_t show_ideapad_brightness(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âchar *buf)
> +{
> + Â Â Â unsigned long now, max;
> +
> + Â Â Â if (read_ec_data(ideapad_handle, 0x11, &max))
> + Â Â Â Â Â Â Â max = -1;
> + Â Â Â if (read_ec_data(ideapad_handle, 0x12, &now))
> + Â Â Â Â Â Â Â now = -1;
> + Â Â Â return sprintf(buf, "%lu/%lu\n", now, max);
> +}
> +
> +static ssize_t store_ideapad_brightness(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const char *buf, size_t count)
> +{
> + Â Â Â return store_ideapad_helper(dev, attr, buf, count, 0x13);
> +}
> +
> +static DEVICE_ATTR(brightness, 0644, show_ideapad_brightness,
> + Â Â Â Â Â Â Â Â Âstore_ideapad_brightness);
> +
> +static ssize_t show_ideapad_cfg(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *buf)
> +{
> + Â Â Â struct ideapad_private *priv = dev_get_drvdata(dev);
> +
> + Â Â Â return sprintf(buf, "0x%.8X\n", (unsigned int)(priv->cfg));
> +}
> +
> +static DEVICE_ATTR(cfg, 0444, show_ideapad_cfg, NULL);
> +
> +static ssize_t show_ideapad_backlight(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *buf)
> +{
> + Â Â Â return show_ideapad_helper(dev, attr, buf, 0x18);
> +}
> +
> +static ssize_t store_ideapad_backlight(struct device *dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct device_attribute *attr,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âconst char *buf, size_t count)
> +{
> + Â Â Â return store_ideapad_helper(dev, attr, buf, count, 0x33);
> +}
> +
> +static DEVICE_ATTR(backlight, 0644, show_ideapad_backlight,
> + Â Â Â Â Â Â Â Â Âstore_ideapad_backlight);
> +
> +static struct attribute *ideapad_attributes[] = {
> + Â Â Â &dev_attr_camera_power.attr,
> + Â Â Â &dev_attr_brightness.attr,
> + Â Â Â &dev_attr_touchpad.attr,
> + Â Â Â &dev_attr_cfg.attr,
> + Â Â Â &dev_attr_backlight.attr,
> + Â Â Â NULL
> +};
> +
> +static struct attribute_group ideapad_attribute_group = {
> + Â Â Â .attrs = ideapad_attributes
> +};
> +
> Â/*
> Â* Rfkill
> Â*/
> @@ -285,15 +386,6 @@ static void __devexit ideapad_unregister_rfkill(struct acpi_device *adevice,
> Â/*
> Â* Platform device
> Â*/
> -static struct attribute *ideapad_attributes[] = {
> - Â Â Â &dev_attr_camera_power.attr,
> - Â Â Â NULL
> -};
> -
> -static struct attribute_group ideapad_attribute_group = {
> - Â Â Â .attrs = ideapad_attributes
> -};
> -
> Âstatic int __devinit ideapad_platform_init(struct ideapad_private *priv)
> Â{
> Â Â Â Âint result;
> --
> 1.7.4.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>
Hi Ike,
Why do you want to addÂ/sys/devices/platform/ideapad/brightness and
 Â/sys/devices/platform/ideapad/backlight ?
Both of these files should be handled by the generic backlight class
(using brightness and bl_power).
Also, could you describe what are these "capabilities" in the sysfs doc file ?
Thanks
--
Corentin Chary
http://xf.iksaif.net
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/