16256ebd5SSrinivas Pandruvada /* 26256ebd5SSrinivas Pandruvada * dptf_power: DPTF platform power driver 36256ebd5SSrinivas Pandruvada * Copyright (c) 2016, Intel Corporation. 46256ebd5SSrinivas Pandruvada * 56256ebd5SSrinivas Pandruvada * This program is free software; you can redistribute it and/or modify it 66256ebd5SSrinivas Pandruvada * under the terms and conditions of the GNU General Public License, 76256ebd5SSrinivas Pandruvada * version 2, as published by the Free Software Foundation. 86256ebd5SSrinivas Pandruvada * 96256ebd5SSrinivas Pandruvada * This program is distributed in the hope it will be useful, but WITHOUT 106256ebd5SSrinivas Pandruvada * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 116256ebd5SSrinivas Pandruvada * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 126256ebd5SSrinivas Pandruvada * more details. 136256ebd5SSrinivas Pandruvada * 146256ebd5SSrinivas Pandruvada */ 156256ebd5SSrinivas Pandruvada 166256ebd5SSrinivas Pandruvada #include <linux/kernel.h> 176256ebd5SSrinivas Pandruvada #include <linux/module.h> 186256ebd5SSrinivas Pandruvada #include <linux/acpi.h> 196256ebd5SSrinivas Pandruvada #include <linux/platform_device.h> 206256ebd5SSrinivas Pandruvada 216256ebd5SSrinivas Pandruvada /* 226256ebd5SSrinivas Pandruvada * Presentation of attributes which are defined for INT3407. They are: 236256ebd5SSrinivas Pandruvada * PMAX : Maximum platform powe 246256ebd5SSrinivas Pandruvada * PSRC : Platform power source 256256ebd5SSrinivas Pandruvada * ARTG : Adapter rating 266256ebd5SSrinivas Pandruvada * CTYP : Charger type 276256ebd5SSrinivas Pandruvada * PBSS : Battery steady power 286256ebd5SSrinivas Pandruvada */ 296256ebd5SSrinivas Pandruvada #define DPTF_POWER_SHOW(name, object) \ 306256ebd5SSrinivas Pandruvada static ssize_t name##_show(struct device *dev,\ 316256ebd5SSrinivas Pandruvada struct device_attribute *attr,\ 326256ebd5SSrinivas Pandruvada char *buf)\ 336256ebd5SSrinivas Pandruvada {\ 34*b0f65b91SKefeng Wang struct acpi_device *acpi_dev = dev_get_drvdata(dev);\ 356256ebd5SSrinivas Pandruvada unsigned long long val;\ 366256ebd5SSrinivas Pandruvada acpi_status status;\ 376256ebd5SSrinivas Pandruvada \ 386256ebd5SSrinivas Pandruvada status = acpi_evaluate_integer(acpi_dev->handle, #object,\ 396256ebd5SSrinivas Pandruvada NULL, &val);\ 406256ebd5SSrinivas Pandruvada if (ACPI_SUCCESS(status))\ 416256ebd5SSrinivas Pandruvada return sprintf(buf, "%d\n", (int)val);\ 426256ebd5SSrinivas Pandruvada else \ 436256ebd5SSrinivas Pandruvada return -EINVAL;\ 446256ebd5SSrinivas Pandruvada } 456256ebd5SSrinivas Pandruvada 466256ebd5SSrinivas Pandruvada DPTF_POWER_SHOW(max_platform_power_mw, PMAX) 476256ebd5SSrinivas Pandruvada DPTF_POWER_SHOW(platform_power_source, PSRC) 486256ebd5SSrinivas Pandruvada DPTF_POWER_SHOW(adapter_rating_mw, ARTG) 496256ebd5SSrinivas Pandruvada DPTF_POWER_SHOW(battery_steady_power_mw, PBSS) 506256ebd5SSrinivas Pandruvada DPTF_POWER_SHOW(charger_type, CTYP) 516256ebd5SSrinivas Pandruvada 526256ebd5SSrinivas Pandruvada static DEVICE_ATTR_RO(max_platform_power_mw); 536256ebd5SSrinivas Pandruvada static DEVICE_ATTR_RO(platform_power_source); 546256ebd5SSrinivas Pandruvada static DEVICE_ATTR_RO(adapter_rating_mw); 556256ebd5SSrinivas Pandruvada static DEVICE_ATTR_RO(battery_steady_power_mw); 566256ebd5SSrinivas Pandruvada static DEVICE_ATTR_RO(charger_type); 576256ebd5SSrinivas Pandruvada 586256ebd5SSrinivas Pandruvada static struct attribute *dptf_power_attrs[] = { 596256ebd5SSrinivas Pandruvada &dev_attr_max_platform_power_mw.attr, 606256ebd5SSrinivas Pandruvada &dev_attr_platform_power_source.attr, 616256ebd5SSrinivas Pandruvada &dev_attr_adapter_rating_mw.attr, 626256ebd5SSrinivas Pandruvada &dev_attr_battery_steady_power_mw.attr, 636256ebd5SSrinivas Pandruvada &dev_attr_charger_type.attr, 646256ebd5SSrinivas Pandruvada NULL 656256ebd5SSrinivas Pandruvada }; 666256ebd5SSrinivas Pandruvada 679e4de6a8SArvind Yadav static const struct attribute_group dptf_power_attribute_group = { 686256ebd5SSrinivas Pandruvada .attrs = dptf_power_attrs, 696256ebd5SSrinivas Pandruvada .name = "dptf_power" 706256ebd5SSrinivas Pandruvada }; 716256ebd5SSrinivas Pandruvada 726256ebd5SSrinivas Pandruvada static int dptf_power_add(struct platform_device *pdev) 736256ebd5SSrinivas Pandruvada { 746256ebd5SSrinivas Pandruvada struct acpi_device *acpi_dev; 756256ebd5SSrinivas Pandruvada acpi_status status; 766256ebd5SSrinivas Pandruvada unsigned long long ptype; 776256ebd5SSrinivas Pandruvada int result; 786256ebd5SSrinivas Pandruvada 796256ebd5SSrinivas Pandruvada acpi_dev = ACPI_COMPANION(&(pdev->dev)); 806256ebd5SSrinivas Pandruvada if (!acpi_dev) 816256ebd5SSrinivas Pandruvada return -ENODEV; 826256ebd5SSrinivas Pandruvada 836256ebd5SSrinivas Pandruvada status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype); 846256ebd5SSrinivas Pandruvada if (ACPI_FAILURE(status)) 856256ebd5SSrinivas Pandruvada return -ENODEV; 866256ebd5SSrinivas Pandruvada 876256ebd5SSrinivas Pandruvada if (ptype != 0x11) 886256ebd5SSrinivas Pandruvada return -ENODEV; 896256ebd5SSrinivas Pandruvada 906256ebd5SSrinivas Pandruvada result = sysfs_create_group(&pdev->dev.kobj, 916256ebd5SSrinivas Pandruvada &dptf_power_attribute_group); 926256ebd5SSrinivas Pandruvada if (result) 936256ebd5SSrinivas Pandruvada return result; 946256ebd5SSrinivas Pandruvada 956256ebd5SSrinivas Pandruvada platform_set_drvdata(pdev, acpi_dev); 966256ebd5SSrinivas Pandruvada 976256ebd5SSrinivas Pandruvada return 0; 986256ebd5SSrinivas Pandruvada } 996256ebd5SSrinivas Pandruvada 1006256ebd5SSrinivas Pandruvada static int dptf_power_remove(struct platform_device *pdev) 1016256ebd5SSrinivas Pandruvada { 1026256ebd5SSrinivas Pandruvada 1036256ebd5SSrinivas Pandruvada sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group); 1046256ebd5SSrinivas Pandruvada 1056256ebd5SSrinivas Pandruvada return 0; 1066256ebd5SSrinivas Pandruvada } 1076256ebd5SSrinivas Pandruvada 1086256ebd5SSrinivas Pandruvada static const struct acpi_device_id int3407_device_ids[] = { 1096256ebd5SSrinivas Pandruvada {"INT3407", 0}, 1106256ebd5SSrinivas Pandruvada {"", 0}, 1116256ebd5SSrinivas Pandruvada }; 1126256ebd5SSrinivas Pandruvada MODULE_DEVICE_TABLE(acpi, int3407_device_ids); 1136256ebd5SSrinivas Pandruvada 1146256ebd5SSrinivas Pandruvada static struct platform_driver dptf_power_driver = { 1156256ebd5SSrinivas Pandruvada .probe = dptf_power_add, 1166256ebd5SSrinivas Pandruvada .remove = dptf_power_remove, 1176256ebd5SSrinivas Pandruvada .driver = { 1186256ebd5SSrinivas Pandruvada .name = "DPTF Platform Power", 1196256ebd5SSrinivas Pandruvada .acpi_match_table = int3407_device_ids, 1206256ebd5SSrinivas Pandruvada }, 1216256ebd5SSrinivas Pandruvada }; 1226256ebd5SSrinivas Pandruvada 1236256ebd5SSrinivas Pandruvada module_platform_driver(dptf_power_driver); 1246256ebd5SSrinivas Pandruvada 1256256ebd5SSrinivas Pandruvada MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); 1266256ebd5SSrinivas Pandruvada MODULE_LICENSE("GPL v2"); 1276256ebd5SSrinivas Pandruvada MODULE_DESCRIPTION("ACPI DPTF platform power driver"); 128