dptf_power.c (668ce99e4ed4c07bb14465f80492bc6cf76ed3c9) | dptf_power.c (7b52b200cf5bdd04f3ee22121960bd6f4ec5efa1) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * dptf_power: DPTF platform power driver 4 * Copyright (c) 2016, Intel Corporation. 5 */ 6 7#include <linux/kernel.h> 8#include <linux/module.h> 9#include <linux/acpi.h> 10#include <linux/platform_device.h> 11 12/* | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * dptf_power: DPTF platform power driver 4 * Copyright (c) 2016, Intel Corporation. 5 */ 6 7#include <linux/kernel.h> 8#include <linux/module.h> 9#include <linux/acpi.h> 10#include <linux/platform_device.h> 11 12/* |
13 * Presentation of attributes which are defined for INT3407. They are: | 13 * Presentation of attributes which are defined for INT3407 and INT3532. 14 * They are: |
14 * PMAX : Maximum platform powe 15 * PSRC : Platform power source 16 * ARTG : Adapter rating 17 * CTYP : Charger type 18 * PBSS : Battery steady power 19 * PROP : Rest of worst case platform Power | 15 * PMAX : Maximum platform powe 16 * PSRC : Platform power source 17 * ARTG : Adapter rating 18 * CTYP : Charger type 19 * PBSS : Battery steady power 20 * PROP : Rest of worst case platform Power |
21 * PBSS : Power Battery Steady State 22 * PBSS : Power Battery Steady State 23 * RBHF : High Frequency Impedance 24 * VBNL : Instantaneous No-Load Voltage 25 * CMPP : Current Discharge Capability |
|
20 */ 21#define DPTF_POWER_SHOW(name, object) \ 22static ssize_t name##_show(struct device *dev,\ 23 struct device_attribute *attr,\ 24 char *buf)\ 25{\ 26 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\ 27 unsigned long long val;\ --- 8 unchanged lines hidden (view full) --- 36} 37 38DPTF_POWER_SHOW(max_platform_power_mw, PMAX) 39DPTF_POWER_SHOW(platform_power_source, PSRC) 40DPTF_POWER_SHOW(adapter_rating_mw, ARTG) 41DPTF_POWER_SHOW(battery_steady_power_mw, PBSS) 42DPTF_POWER_SHOW(charger_type, CTYP) 43DPTF_POWER_SHOW(rest_of_platform_power_mw, PROP) | 26 */ 27#define DPTF_POWER_SHOW(name, object) \ 28static ssize_t name##_show(struct device *dev,\ 29 struct device_attribute *attr,\ 30 char *buf)\ 31{\ 32 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\ 33 unsigned long long val;\ --- 8 unchanged lines hidden (view full) --- 42} 43 44DPTF_POWER_SHOW(max_platform_power_mw, PMAX) 45DPTF_POWER_SHOW(platform_power_source, PSRC) 46DPTF_POWER_SHOW(adapter_rating_mw, ARTG) 47DPTF_POWER_SHOW(battery_steady_power_mw, PBSS) 48DPTF_POWER_SHOW(charger_type, CTYP) 49DPTF_POWER_SHOW(rest_of_platform_power_mw, PROP) |
50DPTF_POWER_SHOW(max_steady_state_power_mw, PBSS) 51DPTF_POWER_SHOW(high_freq_impedance_mohm, RBHF) 52DPTF_POWER_SHOW(no_load_voltage_mv, VBNL) 53DPTF_POWER_SHOW(current_discharge_capbility_ma, CMPP); |
|
44 45static DEVICE_ATTR_RO(max_platform_power_mw); 46static DEVICE_ATTR_RO(platform_power_source); 47static DEVICE_ATTR_RO(adapter_rating_mw); 48static DEVICE_ATTR_RO(battery_steady_power_mw); 49static DEVICE_ATTR_RO(charger_type); 50static DEVICE_ATTR_RO(rest_of_platform_power_mw); | 54 55static DEVICE_ATTR_RO(max_platform_power_mw); 56static DEVICE_ATTR_RO(platform_power_source); 57static DEVICE_ATTR_RO(adapter_rating_mw); 58static DEVICE_ATTR_RO(battery_steady_power_mw); 59static DEVICE_ATTR_RO(charger_type); 60static DEVICE_ATTR_RO(rest_of_platform_power_mw); |
61static DEVICE_ATTR_RO(max_steady_state_power_mw); 62static DEVICE_ATTR_RO(high_freq_impedance_mohm); 63static DEVICE_ATTR_RO(no_load_voltage_mv); 64static DEVICE_ATTR_RO(current_discharge_capbility_ma); |
|
51 52static ssize_t prochot_confirm_store(struct device *dev, 53 struct device_attribute *attr, 54 const char *buf, size_t count) 55{ 56 struct acpi_device *acpi_dev = dev_get_drvdata(dev); 57 acpi_status status; 58 int seq_no; --- 21 unchanged lines hidden (view full) --- 80 NULL 81}; 82 83static const struct attribute_group dptf_power_attribute_group = { 84 .attrs = dptf_power_attrs, 85 .name = "dptf_power" 86}; 87 | 65 66static ssize_t prochot_confirm_store(struct device *dev, 67 struct device_attribute *attr, 68 const char *buf, size_t count) 69{ 70 struct acpi_device *acpi_dev = dev_get_drvdata(dev); 71 acpi_status status; 72 int seq_no; --- 21 unchanged lines hidden (view full) --- 94 NULL 95}; 96 97static const struct attribute_group dptf_power_attribute_group = { 98 .attrs = dptf_power_attrs, 99 .name = "dptf_power" 100}; 101 |
102static struct attribute *dptf_battery_attrs[] = { 103 &dev_attr_max_platform_power_mw.attr, 104 &dev_attr_max_steady_state_power_mw.attr, 105 &dev_attr_high_freq_impedance_mohm.attr, 106 &dev_attr_no_load_voltage_mv.attr, 107 &dev_attr_current_discharge_capbility_ma.attr, 108 NULL 109}; 110 111static const struct attribute_group dptf_battery_attribute_group = { 112 .attrs = dptf_battery_attrs, 113 .name = "dptf_battery" 114}; 115 116#define MAX_POWER_CHANGED 0x80 |
|
88#define POWER_STATE_CHANGED 0x81 | 117#define POWER_STATE_CHANGED 0x81 |
118#define STEADY_STATE_POWER_CHANGED 0x83 |
|
89#define POWER_PROP_CHANGE_EVENT 0x84 | 119#define POWER_PROP_CHANGE_EVENT 0x84 |
120#define IMPEDANCED_CHNGED 0x85 121#define VOLTAGE_CURRENT_CHANGED 0x86 |
|
90 | 122 |
123static long long dptf_participant_type(acpi_handle handle) 124{ 125 unsigned long long ptype; 126 acpi_status status; 127 128 status = acpi_evaluate_integer(handle, "PTYP", NULL, &ptype); 129 if (ACPI_FAILURE(status)) 130 return -ENODEV; 131 132 return ptype; 133} 134 |
|
91static void dptf_power_notify(acpi_handle handle, u32 event, void *data) 92{ 93 struct platform_device *pdev = data; 94 char *attr; 95 96 switch (event) { 97 case POWER_STATE_CHANGED: 98 attr = "platform_power_source"; 99 break; 100 case POWER_PROP_CHANGE_EVENT: 101 attr = "rest_of_platform_power_mw"; 102 break; | 135static void dptf_power_notify(acpi_handle handle, u32 event, void *data) 136{ 137 struct platform_device *pdev = data; 138 char *attr; 139 140 switch (event) { 141 case POWER_STATE_CHANGED: 142 attr = "platform_power_source"; 143 break; 144 case POWER_PROP_CHANGE_EVENT: 145 attr = "rest_of_platform_power_mw"; 146 break; |
147 case MAX_POWER_CHANGED: 148 attr = "max_platform_power_mw"; 149 break; 150 case STEADY_STATE_POWER_CHANGED: 151 attr = "max_steady_state_power_mw"; 152 break; 153 case VOLTAGE_CURRENT_CHANGED: 154 attr = "no_load_voltage_mv"; 155 break; |
|
103 default: 104 dev_err(&pdev->dev, "Unsupported event [0x%x]\n", event); 105 return; 106 } 107 108 /* 109 * Notify that an attribute is changed, so that user space can read 110 * again. 111 */ | 156 default: 157 dev_err(&pdev->dev, "Unsupported event [0x%x]\n", event); 158 return; 159 } 160 161 /* 162 * Notify that an attribute is changed, so that user space can read 163 * again. 164 */ |
112 sysfs_notify(&pdev->dev.kobj, "dptf_power", attr); | 165 if (dptf_participant_type(handle) == 0x0CULL) 166 sysfs_notify(&pdev->dev.kobj, "dptf_battery", attr); 167 else 168 sysfs_notify(&pdev->dev.kobj, "dptf_power", attr); |
113} 114 115static int dptf_power_add(struct platform_device *pdev) 116{ | 169} 170 171static int dptf_power_add(struct platform_device *pdev) 172{ |
173 const struct attribute_group *attr_group; |
|
117 struct acpi_device *acpi_dev; | 174 struct acpi_device *acpi_dev; |
118 acpi_status status; | |
119 unsigned long long ptype; 120 int result; 121 122 acpi_dev = ACPI_COMPANION(&(pdev->dev)); 123 if (!acpi_dev) 124 return -ENODEV; 125 | 175 unsigned long long ptype; 176 int result; 177 178 acpi_dev = ACPI_COMPANION(&(pdev->dev)); 179 if (!acpi_dev) 180 return -ENODEV; 181 |
126 status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype); 127 if (ACPI_FAILURE(status)) | 182 ptype = dptf_participant_type(acpi_dev->handle); 183 if (ptype == 0x11) 184 attr_group = &dptf_power_attribute_group; 185 else if (ptype == 0x0C) 186 attr_group = &dptf_battery_attribute_group; 187 else |
128 return -ENODEV; 129 | 188 return -ENODEV; 189 |
130 if (ptype != 0x11) 131 return -ENODEV; 132 | |
133 result = acpi_install_notify_handler(acpi_dev->handle, 134 ACPI_DEVICE_NOTIFY, 135 dptf_power_notify, 136 (void *)pdev); 137 if (result) 138 return result; 139 140 result = sysfs_create_group(&pdev->dev.kobj, | 190 result = acpi_install_notify_handler(acpi_dev->handle, 191 ACPI_DEVICE_NOTIFY, 192 dptf_power_notify, 193 (void *)pdev); 194 if (result) 195 return result; 196 197 result = sysfs_create_group(&pdev->dev.kobj, |
141 &dptf_power_attribute_group); | 198 attr_group); |
142 if (result) { 143 acpi_remove_notify_handler(acpi_dev->handle, 144 ACPI_DEVICE_NOTIFY, 145 dptf_power_notify); 146 return result; 147 } 148 149 platform_set_drvdata(pdev, acpi_dev); 150 151 return 0; 152} 153 154static int dptf_power_remove(struct platform_device *pdev) 155{ 156 struct acpi_device *acpi_dev = platform_get_drvdata(pdev); 157 158 acpi_remove_notify_handler(acpi_dev->handle, 159 ACPI_DEVICE_NOTIFY, 160 dptf_power_notify); | 199 if (result) { 200 acpi_remove_notify_handler(acpi_dev->handle, 201 ACPI_DEVICE_NOTIFY, 202 dptf_power_notify); 203 return result; 204 } 205 206 platform_set_drvdata(pdev, acpi_dev); 207 208 return 0; 209} 210 211static int dptf_power_remove(struct platform_device *pdev) 212{ 213 struct acpi_device *acpi_dev = platform_get_drvdata(pdev); 214 215 acpi_remove_notify_handler(acpi_dev->handle, 216 ACPI_DEVICE_NOTIFY, 217 dptf_power_notify); |
161 sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group); | |
162 | 218 |
219 if (dptf_participant_type(acpi_dev->handle) == 0x0CULL) 220 sysfs_remove_group(&pdev->dev.kobj, &dptf_battery_attribute_group); 221 else 222 sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group); 223 |
|
163 return 0; 164} 165 166static const struct acpi_device_id int3407_device_ids[] = { 167 {"INT3407", 0}, | 224 return 0; 225} 226 227static const struct acpi_device_id int3407_device_ids[] = { 228 {"INT3407", 0}, |
229 {"INT3532", 0}, |
|
168 {"INTC1047", 0}, 169 {"", 0}, 170}; 171MODULE_DEVICE_TABLE(acpi, int3407_device_ids); 172 173static struct platform_driver dptf_power_driver = { 174 .probe = dptf_power_add, 175 .remove = dptf_power_remove, 176 .driver = { 177 .name = "DPTF Platform Power", 178 .acpi_match_table = int3407_device_ids, 179 }, 180}; 181 182module_platform_driver(dptf_power_driver); 183 184MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); 185MODULE_LICENSE("GPL v2"); 186MODULE_DESCRIPTION("ACPI DPTF platform power driver"); | 230 {"INTC1047", 0}, 231 {"", 0}, 232}; 233MODULE_DEVICE_TABLE(acpi, int3407_device_ids); 234 235static struct platform_driver dptf_power_driver = { 236 .probe = dptf_power_add, 237 .remove = dptf_power_remove, 238 .driver = { 239 .name = "DPTF Platform Power", 240 .acpi_match_table = int3407_device_ids, 241 }, 242}; 243 244module_platform_driver(dptf_power_driver); 245 246MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>"); 247MODULE_LICENSE("GPL v2"); 248MODULE_DESCRIPTION("ACPI DPTF platform power driver"); |