From: Aaron Lu <aaron.lu@intel.com>
To: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Alan Stern <stern@rowland.harvard.edu>,
Jeff Garzik <jgarzik@pobox.com>
Cc: linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org,
Aaron Lu <aaron.lwe@gmail.com>, Aaron Lu <aaron.lu@intel.com>
Subject: [PATCH 3/3] scsi: sd: add may_power_off sysfs entry
Date: Thu, 30 Aug 2012 14:44:00 +0800 [thread overview]
Message-ID: <1346309040-27112-4-git-send-email-aaron.lu@intel.com> (raw)
In-Reply-To: <1346309040-27112-1-git-send-email-aaron.lu@intel.com>
If the platform is able to power off the scsi device, add a sysfs entry
may_power_off to let user control the may_power_off flag of the device.
This flag will control when the scsi device is runtime suspended, can we
remove power from it(e.g. let it enter D3 cold ACPI device state).
This flag is used in libata-acpi.c to decide which ACPI D-State it will
enter when runtime suspended.
Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
drivers/scsi/sd.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 4df73e5..db25569 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2584,6 +2584,38 @@ static int sd_format_disk_name(char *prefix, int index, char *buf, int buflen)
return 0;
}
+static ssize_t
+may_power_off_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct scsi_device *sdev = to_scsi_device(dev);
+ return snprintf(buf, 10, "%d\n", sdev->may_power_off);
+}
+
+static ssize_t
+may_power_off_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int value = -EINVAL;
+ struct scsi_device *sdev = to_scsi_device(dev);
+
+ if (buf[1] == '\0' || (buf[1] == '\n' && buf[2] == '\0')) {
+ if (buf[0] == '1')
+ value = 1;
+ else if (buf[0] == '0')
+ value = 0;
+ }
+
+ if (value >= 0) {
+ sdev->may_power_off = value;
+ value = count;
+ }
+
+ return value;
+}
+DEVICE_ATTR(may_power_off, S_IRUGO | S_IWUSR,
+ may_power_off_show, may_power_off_store);
+
/*
* The asynchronous part of sd_probe
*/
@@ -2638,6 +2670,8 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n",
sdp->removable ? "removable " : "");
+ if (sdp->can_power_off)
+ device_create_file(&sdp->sdev_gendev, &dev_attr_may_power_off);
scsi_autopm_put_device(sdp);
put_device(&sdkp->dev);
}
--
1.7.11.5
prev parent reply other threads:[~2012-08-30 6:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-30 6:43 [PATCH 0/3] may_power_off for scsi device Aaron Lu
2012-08-30 6:43 ` [PATCH 1/3] scsi: pm: add may_power_off flag Aaron Lu
2012-08-30 14:24 ` Alan Stern
2012-08-31 11:39 ` Aaron Lu
2012-08-30 6:43 ` [PATCH 2/3] scsi: sr: use may_power_off to enable/disable ZPODD Aaron Lu
2012-08-30 6:44 ` Aaron Lu [this message]
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=1346309040-27112-4-git-send-email-aaron.lu@intel.com \
--to=aaron.lu@intel.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=aaron.lwe@gmail.com \
--cc=jgarzik@pobox.com \
--cc=linux-pm@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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).