aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform
diff options
context:
space:
mode:
authorAzael Avalos <coproscefalo@gmail.com>2015-01-18 20:30:24 -0500
committerDarren Hart <dvhart@linux.intel.com>2015-01-23 12:08:25 -0500
commitbb3fe01ff693cbc05d4d06edbe9ec868050a262c (patch)
tree3d7a0df89e997041129e0d2a691b615e19fd53db /drivers/platform
parent182bcaa5c90a66429fcf00a6a02a7bf845bf27c5 (diff)
toshiba_acpi: Add support for USB Rapid Charge
Newer Toshiba laptops equipped with USB 3.0 ports now have the functionality of rapid charging devices connected to their USB hubs. This patch adds support to use such feature by creating a sysfs entry named "usb_rapid_charge", accepting only two values, 0 to disable and 1 to enable, however, the machine needs a restart everytime the function is toggled. Signed-off-by: Azael Avalos <coproscefalo@gmail.com> Signed-off-by: Darren Hart <dvhart@linux.intel.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r--drivers/platform/x86/toshiba_acpi.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index a8b719f481f9..0f1b7a8ed802 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -155,6 +155,7 @@ MODULE_LICENSE("GPL");
155#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1 155#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
156#define SCI_USB_CHARGE_BAT_LVL_ON 0x4 156#define SCI_USB_CHARGE_BAT_LVL_ON 0x4
157#define SCI_USB_CHARGE_BAT_LVL 0x0200 157#define SCI_USB_CHARGE_BAT_LVL 0x0200
158#define SCI_USB_CHARGE_RAPID_DSP 0x0300
158 159
159struct toshiba_acpi_dev { 160struct toshiba_acpi_dev {
160 struct acpi_device *acpi_dev; 161 struct acpi_device *acpi_dev;
@@ -188,6 +189,7 @@ struct toshiba_acpi_dev {
188 unsigned int eco_supported:1; 189 unsigned int eco_supported:1;
189 unsigned int accelerometer_supported:1; 190 unsigned int accelerometer_supported:1;
190 unsigned int usb_sleep_charge_supported:1; 191 unsigned int usb_sleep_charge_supported:1;
192 unsigned int usb_rapid_charge_supported:1;
191 unsigned int sysfs_created:1; 193 unsigned int sysfs_created:1;
192 194
193 struct mutex mutex; 195 struct mutex mutex;
@@ -873,6 +875,60 @@ static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
873 return 0; 875 return 0;
874} 876}
875 877
878static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
879 u32 *state)
880{
881 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
882 u32 out[TCI_WORDS];
883 acpi_status status;
884
885 if (!sci_open(dev))
886 return -EIO;
887
888 in[5] = SCI_USB_CHARGE_RAPID_DSP;
889 status = tci_raw(dev, in, out);
890 sci_close(dev);
891 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
892 pr_err("ACPI call to get USB S&C battery level failed\n");
893 return -EIO;
894 } else if (out[0] == TOS_NOT_SUPPORTED ||
895 out[0] == TOS_INPUT_DATA_ERROR) {
896 pr_info("USB Sleep and Charge not supported\n");
897 return -ENODEV;
898 }
899
900 *state = out[2];
901
902 return 0;
903}
904
905static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
906 u32 state)
907{
908 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
909 u32 out[TCI_WORDS];
910 acpi_status status;
911
912 if (!sci_open(dev))
913 return -EIO;
914
915 in[2] = state;
916 in[5] = SCI_USB_CHARGE_RAPID_DSP;
917 status = tci_raw(dev, in, out);
918 sci_close(dev);
919 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
920 pr_err("ACPI call to set USB S&C battery level failed\n");
921 return -EIO;
922 } else if (out[0] == TOS_NOT_SUPPORTED) {
923 pr_info("USB Sleep and Charge not supported\n");
924 return -ENODEV;
925 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
926 return -EIO;
927 }
928
929 return 0;
930}
931
876/* Bluetooth rfkill handlers */ 932/* Bluetooth rfkill handlers */
877 933
878static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present) 934static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
@@ -1438,6 +1494,12 @@ static ssize_t sleep_functions_on_battery_show(struct device *dev,
1438static ssize_t sleep_functions_on_battery_store(struct device *dev, 1494static ssize_t sleep_functions_on_battery_store(struct device *dev,
1439 struct device_attribute *attr, 1495 struct device_attribute *attr,
1440 const char *buf, size_t count); 1496 const char *buf, size_t count);
1497static ssize_t toshiba_usb_rapid_charge_show(struct device *dev,
1498 struct device_attribute *attr,
1499 char *buf);
1500static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
1501 struct device_attribute *attr,
1502 const char *buf, size_t count);
1441 1503
1442static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR, 1504static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
1443 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store); 1505 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
@@ -1455,6 +1517,9 @@ static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
1455static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR, 1517static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR,
1456 sleep_functions_on_battery_show, 1518 sleep_functions_on_battery_show,
1457 sleep_functions_on_battery_store); 1519 sleep_functions_on_battery_store);
1520static DEVICE_ATTR(usb_rapid_charge, S_IRUGO | S_IWUSR,
1521 toshiba_usb_rapid_charge_show,
1522 toshiba_usb_rapid_charge_store);
1458 1523
1459static struct attribute *toshiba_attributes[] = { 1524static struct attribute *toshiba_attributes[] = {
1460 &dev_attr_kbd_backlight_mode.attr, 1525 &dev_attr_kbd_backlight_mode.attr,
@@ -1465,6 +1530,7 @@ static struct attribute *toshiba_attributes[] = {
1465 &dev_attr_position.attr, 1530 &dev_attr_position.attr,
1466 &dev_attr_usb_sleep_charge.attr, 1531 &dev_attr_usb_sleep_charge.attr,
1467 &dev_attr_sleep_functions_on_battery.attr, 1532 &dev_attr_sleep_functions_on_battery.attr,
1533 &dev_attr_usb_rapid_charge.attr,
1468 NULL, 1534 NULL,
1469}; 1535};
1470 1536
@@ -1793,6 +1859,42 @@ static ssize_t sleep_functions_on_battery_store(struct device *dev,
1793 return count; 1859 return count;
1794} 1860}
1795 1861
1862static ssize_t toshiba_usb_rapid_charge_show(struct device *dev,
1863 struct device_attribute *attr,
1864 char *buf)
1865{
1866 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1867 u32 state;
1868 int ret;
1869
1870 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
1871 if (ret < 0)
1872 return ret;
1873
1874 return sprintf(buf, "%d\n", state);
1875}
1876
1877static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
1878 struct device_attribute *attr,
1879 const char *buf, size_t count)
1880{
1881 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1882 int state;
1883 int ret;
1884
1885 ret = kstrtoint(buf, 0, &state);
1886 if (ret)
1887 return ret;
1888 if (state != 0 && state != 1)
1889 return -EINVAL;
1890
1891 ret = toshiba_usb_rapid_charge_set(toshiba, state);
1892 if (ret)
1893 return ret;
1894
1895 return count;
1896}
1897
1796static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, 1898static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
1797 struct attribute *attr, int idx) 1899 struct attribute *attr, int idx)
1798{ 1900{
@@ -1812,6 +1914,8 @@ static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
1812 exists = (drv->usb_sleep_charge_supported) ? true : false; 1914 exists = (drv->usb_sleep_charge_supported) ? true : false;
1813 else if (attr == &dev_attr_sleep_functions_on_battery.attr) 1915 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
1814 exists = (drv->usb_sleep_charge_supported) ? true : false; 1916 exists = (drv->usb_sleep_charge_supported) ? true : false;
1917 else if (attr == &dev_attr_usb_rapid_charge.attr)
1918 exists = (drv->usb_rapid_charge_supported) ? true : false;
1815 1919
1816 return exists ? attr->mode : 0; 1920 return exists ? attr->mode : 0;
1817} 1921}
@@ -2224,6 +2328,9 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
2224 ret = toshiba_usb_sleep_charge_get(dev, &dummy); 2328 ret = toshiba_usb_sleep_charge_get(dev, &dummy);
2225 dev->usb_sleep_charge_supported = !ret; 2329 dev->usb_sleep_charge_supported = !ret;
2226 2330
2331 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2332 dev->usb_rapid_charge_supported = !ret;
2333
2227 /* Determine whether or not BIOS supports fan and video interfaces */ 2334 /* Determine whether or not BIOS supports fan and video interfaces */
2228 2335
2229 ret = get_video_status(dev, &dummy); 2336 ret = get_video_status(dev, &dummy);