Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

platform/x86: BIOS SAR driver for Intel M.2 Modem

Dynamic BIOS SAR driver exposing dynamic SAR information from BIOS

The Dynamic SAR (Specific Absorption Rate) driver uses ACPI DSM
(Device Specific Method) to communicate with BIOS and retrieve
dynamic SAR information and change notifications. The driver uses
sysfs to expose this data to userspace via read and notify.

Sysfs interface is documented in detail under:
Documentation/ABI/testing/sysfs-driver-intc_sar

Signed-off-by: Shravan S <s.shravan@intel.com>
Link: https://lore.kernel.org/r/20210723211452.27995-2-s.shravan@intel.com
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>

authored by

Shravan S and committed by
Hans de Goede
dcfbd31e ef195e8a

+480
+54
Documentation/ABI/testing/sysfs-driver-intc_sar
··· 1 + What: /sys/bus/platform/devices/INTC1092:00/intc_reg 2 + Date: August 2021 3 + KernelVersion: 5.15 4 + Contact: Shravan S <s.shravan@intel.com>, 5 + An Sudhakar <sudhakar.an@intel.com> 6 + Description: 7 + Specific Absorption Rate (SAR) regulatory mode is typically 8 + derived based on information like mcc (Mobile Country Code) and 9 + mnc (Mobile Network Code) that is available for the currently 10 + attached LTE network. A userspace application is required to set 11 + the current SAR regulatory mode on the Dynamic SAR driver using 12 + this sysfs node. Such an application can also read back using 13 + this sysfs node, the currently configured regulatory mode value 14 + from the Dynamic SAR driver. 15 + 16 + Acceptable regulatory modes are: 17 + == ==== 18 + 0 FCC 19 + 1 CE 20 + 2 ISED 21 + == ==== 22 + 23 + - The regulatory mode value has one of the above values. 24 + - The default regulatory mode used in the driver is 0. 25 + 26 + What: /sys/bus/platform/devices/INTC1092:00/intc_data 27 + Date: August 2021 28 + KernelVersion: 5.15 29 + Contact: Shravan S <s.shravan@intel.com>, 30 + An Sudhakar <sudhakar.an@intel.com> 31 + Description: 32 + This sysfs entry is used to retrieve Dynamic SAR information 33 + emitted/maintained by a BIOS that supports Dynamic SAR. 34 + 35 + The retrieved information is in the order given below: 36 + - device_mode 37 + - bandtable_index 38 + - antennatable_index 39 + - sartable_index 40 + 41 + The above information is sent as integer values separated 42 + by a single space. This information can then be pushed to a 43 + WWAN modem that uses this to control the transmit signal 44 + level using the Band/Antenna/SAR table index information. 45 + These parameters are derived/decided by aggregating 46 + device-mode like laptop/tablet/clamshell etc. and the 47 + proximity-sensor data available to the embedded controller on 48 + given host. The regulatory mode configured on Dynamic SAR 49 + driver also influences these values. 50 + 51 + The userspace applications can poll for changes to this file 52 + using POLLPRI event on file-descriptor (fd) obtained by opening 53 + this sysfs entry. Application can then read this information from 54 + the sysfs node and consume the given information.
+7
MAINTAINERS
··· 9220 9220 S: Maintained 9221 9221 F: drivers/platform/x86/intel_atomisp2_led.c 9222 9222 9223 + INTEL BIOS SAR INT1092 DRIVER 9224 + M: Shravan S <s.shravan@intel.com> 9225 + M: Intel Corporation <linuxwwan@intel.com> 9226 + L: platform-driver-x86@vger.kernel.org 9227 + S: Maintained 9228 + F: drivers/platform/x86/intel/int1092/ 9229 + 9223 9230 INTEL BROXTON PMC DRIVER 9224 9231 M: Mika Westerberg <mika.westerberg@linux.intel.com> 9225 9232 M: Zha Qipeng <qipeng.zha@intel.com>
+1
drivers/platform/x86/intel/Kconfig
··· 16 16 17 17 if X86_PLATFORM_DRIVERS_INTEL 18 18 19 + source "drivers/platform/x86/intel/int1092/Kconfig" 19 20 source "drivers/platform/x86/intel/int33fe/Kconfig" 20 21 source "drivers/platform/x86/intel/int3472/Kconfig" 21 22 source "drivers/platform/x86/intel/pmt/Kconfig"
+1
drivers/platform/x86/intel/Makefile
··· 4 4 # Intel x86 Platform-Specific Drivers 5 5 # 6 6 7 + obj-$(CONFIG_INTEL_SAR_INT1092) += int1092/ 7 8 obj-$(CONFIG_INTEL_CHT_INT33FE) += int33fe/ 8 9 obj-$(CONFIG_INTEL_SKL_INT3472) += int3472/ 9 10 obj-$(CONFIG_INTEL_PMT_CLASS) += pmt/
+14
drivers/platform/x86/intel/int1092/Kconfig
··· 1 + config INTEL_SAR_INT1092 2 + tristate "Intel Specific Absorption Rate Driver" 3 + depends on ACPI 4 + help 5 + This driver helps to limit the exposure of human body to RF frequency by 6 + providing information to userspace application that will inform the Intel 7 + M.2 modem to regulate the RF power based on SAR data obtained from the 8 + sensors captured in the BIOS. ACPI interface exposes this data from the BIOS 9 + to SAR driver. The front end application in userspace will interact with SAR 10 + driver to obtain information like the device mode, Antenna index, baseband index, 11 + SAR table index and use available communication like MBIM interface to enable 12 + data communication to modem for RF power regulation. Enable this config when 13 + given platform needs to support "Dynamic SAR" configuration for a modem available 14 + on the platform.
+1
drivers/platform/x86/intel/int1092/Makefile
··· 1 + obj-$(CONFIG_INTEL_SAR_INT1092) += intel_sar.o
+316
drivers/platform/x86/intel/int1092/intel_sar.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (c) 2021, Intel Corporation. 4 + */ 5 + 6 + #include <linux/acpi.h> 7 + #include <linux/kobject.h> 8 + #include <linux/platform_device.h> 9 + #include <linux/sysfs.h> 10 + #include "intel_sar.h" 11 + 12 + /** 13 + * get_int_value: Retrieve integer values from ACPI Object 14 + * @obj: acpi_object pointer which has the integer value 15 + * @out: output pointer will get integer value 16 + * 17 + * Function is used to retrieve integer value from acpi object. 18 + * 19 + * Return: 20 + * * 0 on success 21 + * * -EIO if there is an issue in acpi_object passed. 22 + */ 23 + static int get_int_value(union acpi_object *obj, int *out) 24 + { 25 + if (!obj || obj->type != ACPI_TYPE_INTEGER) 26 + return -EIO; 27 + *out = (int)obj->integer.value; 28 + return 0; 29 + } 30 + 31 + /** 32 + * update_sar_data: sar data is updated based on regulatory mode 33 + * @context: pointer to driver context structure 34 + * 35 + * sar_data is updated based on regulatory value 36 + * context->reg_value will never exceed MAX_REGULATORY 37 + */ 38 + static void update_sar_data(struct wwan_sar_context *context) 39 + { 40 + struct wwan_device_mode_configuration *config = 41 + &context->config_data[context->reg_value]; 42 + 43 + if (config->device_mode_info && 44 + context->sar_data.device_mode < config->total_dev_mode) { 45 + struct wwan_device_mode_info *dev_mode = 46 + &config->device_mode_info[context->sar_data.device_mode]; 47 + 48 + context->sar_data.antennatable_index = dev_mode->antennatable_index; 49 + context->sar_data.bandtable_index = dev_mode->bandtable_index; 50 + context->sar_data.sartable_index = dev_mode->sartable_index; 51 + } 52 + } 53 + 54 + /** 55 + * parse_package: parse acpi package for retrieving SAR information 56 + * @context: pointer to driver context structure 57 + * @item : acpi_object pointer 58 + * 59 + * Given acpi_object is iterated to retrieve information for each device mode. 60 + * If a given package corresponding to a specific device mode is faulty, it is 61 + * skipped and the specific entry in context structure will have the default value 62 + * of zero. Decoding of subsequent device modes is realized by having "continue" 63 + * statements in the for loop on encountering error in parsing given device mode. 64 + * 65 + * Return: 66 + * AE_OK if success 67 + * AE_ERROR on error 68 + */ 69 + static acpi_status parse_package(struct wwan_sar_context *context, union acpi_object *item) 70 + { 71 + struct wwan_device_mode_configuration *data; 72 + int value, itr, reg; 73 + union acpi_object *num; 74 + 75 + num = &item->package.elements[0]; 76 + if (get_int_value(num, &value) || value < 0 || value >= MAX_REGULATORY) 77 + return AE_ERROR; 78 + 79 + reg = value; 80 + 81 + data = &context->config_data[reg]; 82 + if (data->total_dev_mode > MAX_DEV_MODES || data->total_dev_mode == 0 || 83 + item->package.count <= data->total_dev_mode) 84 + return AE_ERROR; 85 + 86 + data->device_mode_info = kmalloc_array(data->total_dev_mode, 87 + sizeof(struct wwan_device_mode_info), GFP_KERNEL); 88 + if (!data->device_mode_info) 89 + return AE_ERROR; 90 + 91 + for (itr = 0; itr < data->total_dev_mode; itr++) { 92 + struct wwan_device_mode_info temp = { 0 }; 93 + 94 + num = &item->package.elements[itr + 1]; 95 + if (num->type != ACPI_TYPE_PACKAGE || num->package.count < TOTAL_DATA) 96 + continue; 97 + if (get_int_value(&num->package.elements[0], &temp.device_mode)) 98 + continue; 99 + if (get_int_value(&num->package.elements[1], &temp.bandtable_index)) 100 + continue; 101 + if (get_int_value(&num->package.elements[2], &temp.antennatable_index)) 102 + continue; 103 + if (get_int_value(&num->package.elements[3], &temp.sartable_index)) 104 + continue; 105 + data->device_mode_info[itr] = temp; 106 + } 107 + return AE_OK; 108 + } 109 + 110 + /** 111 + * sar_get_device_mode: Extraction of information from BIOS via DSM calls 112 + * @device: ACPI device for which to retrieve the data 113 + * 114 + * Retrieve the current device mode information from the BIOS. 115 + * 116 + * Return: 117 + * AE_OK on success 118 + * AE_ERROR on error 119 + */ 120 + static acpi_status sar_get_device_mode(struct platform_device *device) 121 + { 122 + struct wwan_sar_context *context = dev_get_drvdata(&device->dev); 123 + acpi_status status = AE_OK; 124 + union acpi_object *out; 125 + u32 rev = 0; 126 + int value; 127 + 128 + out = acpi_evaluate_dsm(context->handle, &context->guid, rev, 129 + COMMAND_ID_DEV_MODE, NULL); 130 + if (get_int_value(out, &value)) { 131 + dev_err(&device->dev, "DSM cmd:%d Failed to retrieve value\n", COMMAND_ID_DEV_MODE); 132 + status = AE_ERROR; 133 + goto dev_mode_error; 134 + } 135 + context->sar_data.device_mode = value; 136 + update_sar_data(context); 137 + sysfs_notify(&device->dev.kobj, NULL, SYSFS_DATANAME); 138 + 139 + dev_mode_error: 140 + ACPI_FREE(out); 141 + return status; 142 + } 143 + 144 + static const struct acpi_device_id sar_device_ids[] = { 145 + { "INTC1092", 0}, 146 + {} 147 + }; 148 + MODULE_DEVICE_TABLE(acpi, sar_device_ids); 149 + 150 + static ssize_t intc_data_show(struct device *dev, struct device_attribute *attr, char *buf) 151 + { 152 + struct wwan_sar_context *context = dev_get_drvdata(dev); 153 + 154 + return sysfs_emit(buf, "%d %d %d %d\n", context->sar_data.device_mode, 155 + context->sar_data.bandtable_index, 156 + context->sar_data.antennatable_index, 157 + context->sar_data.sartable_index); 158 + } 159 + static DEVICE_ATTR_RO(intc_data); 160 + 161 + static ssize_t intc_reg_show(struct device *dev, struct device_attribute *attr, char *buf) 162 + { 163 + struct wwan_sar_context *context = dev_get_drvdata(dev); 164 + 165 + return sysfs_emit(buf, "%d\n", context->reg_value); 166 + } 167 + 168 + static ssize_t intc_reg_store(struct device *dev, struct device_attribute *attr, 169 + const char *buf, size_t count) 170 + { 171 + struct wwan_sar_context *context = dev_get_drvdata(dev); 172 + unsigned int value; 173 + int read; 174 + 175 + if (!count) 176 + return -EINVAL; 177 + read = kstrtouint(buf, 10, &value); 178 + if (read < 0) 179 + return read; 180 + if (value >= MAX_REGULATORY) 181 + return -EOVERFLOW; 182 + context->reg_value = value; 183 + update_sar_data(context); 184 + sysfs_notify(&dev->kobj, NULL, SYSFS_DATANAME); 185 + return count; 186 + } 187 + static DEVICE_ATTR_RW(intc_reg); 188 + 189 + static struct attribute *intcsar_attrs[] = { 190 + &dev_attr_intc_data.attr, 191 + &dev_attr_intc_reg.attr, 192 + NULL 193 + }; 194 + 195 + static struct attribute_group intcsar_group = { 196 + .attrs = intcsar_attrs, 197 + }; 198 + 199 + static void sar_notify(acpi_handle handle, u32 event, void *data) 200 + { 201 + struct platform_device *device = data; 202 + 203 + if (event == SAR_EVENT) { 204 + if (sar_get_device_mode(device) != AE_OK) 205 + dev_err(&device->dev, "sar_get_device_mode error"); 206 + } 207 + } 208 + 209 + static void sar_get_data(int reg, struct wwan_sar_context *context) 210 + { 211 + union acpi_object *out, req; 212 + u32 rev = 0; 213 + 214 + req.type = ACPI_TYPE_INTEGER; 215 + req.integer.value = reg; 216 + out = acpi_evaluate_dsm(context->handle, &context->guid, rev, 217 + COMMAND_ID_CONFIG_TABLE, &req); 218 + if (!out) 219 + return; 220 + if (out->type == ACPI_TYPE_PACKAGE && out->package.count >= 3 && 221 + out->package.elements[0].type == ACPI_TYPE_INTEGER && 222 + out->package.elements[1].type == ACPI_TYPE_INTEGER && 223 + out->package.elements[2].type == ACPI_TYPE_PACKAGE && 224 + out->package.elements[2].package.count > 0) { 225 + context->config_data[reg].version = out->package.elements[0].integer.value; 226 + context->config_data[reg].total_dev_mode = 227 + out->package.elements[1].integer.value; 228 + if (context->config_data[reg].total_dev_mode <= 0 || 229 + context->config_data[reg].total_dev_mode > MAX_DEV_MODES) { 230 + ACPI_FREE(out); 231 + return; 232 + } 233 + parse_package(context, &out->package.elements[2]); 234 + } 235 + ACPI_FREE(out); 236 + } 237 + 238 + static int sar_probe(struct platform_device *device) 239 + { 240 + struct wwan_sar_context *context; 241 + int reg; 242 + int result; 243 + 244 + context = kzalloc(sizeof(*context), GFP_KERNEL); 245 + if (!context) 246 + return -ENOMEM; 247 + 248 + context->sar_device = device; 249 + context->handle = ACPI_HANDLE(&device->dev); 250 + dev_set_drvdata(&device->dev, context); 251 + 252 + result = guid_parse(SAR_DSM_UUID, &context->guid); 253 + if (result) { 254 + dev_err(&device->dev, "SAR UUID parse error: %d\n", result); 255 + goto r_free; 256 + } 257 + 258 + for (reg = 0; reg < MAX_REGULATORY; reg++) 259 + sar_get_data(reg, context); 260 + 261 + if (sar_get_device_mode(device) != AE_OK) { 262 + dev_err(&device->dev, "Failed to get device mode\n"); 263 + result = -EIO; 264 + goto r_free; 265 + } 266 + 267 + result = sysfs_create_group(&device->dev.kobj, &intcsar_group); 268 + if (result) { 269 + dev_err(&device->dev, "sysfs creation failed\n"); 270 + goto r_free; 271 + } 272 + 273 + if (acpi_install_notify_handler(ACPI_HANDLE(&device->dev), ACPI_DEVICE_NOTIFY, 274 + sar_notify, (void *)device) != AE_OK) { 275 + dev_err(&device->dev, "Failed acpi_install_notify_handler\n"); 276 + result = -EIO; 277 + goto r_sys; 278 + } 279 + return 0; 280 + 281 + r_sys: 282 + sysfs_remove_group(&device->dev.kobj, &intcsar_group); 283 + r_free: 284 + kfree(context); 285 + return result; 286 + } 287 + 288 + static int sar_remove(struct platform_device *device) 289 + { 290 + struct wwan_sar_context *context = dev_get_drvdata(&device->dev); 291 + int reg; 292 + 293 + acpi_remove_notify_handler(ACPI_HANDLE(&device->dev), 294 + ACPI_DEVICE_NOTIFY, sar_notify); 295 + sysfs_remove_group(&device->dev.kobj, &intcsar_group); 296 + for (reg = 0; reg < MAX_REGULATORY; reg++) 297 + kfree(context->config_data[reg].device_mode_info); 298 + 299 + kfree(context); 300 + return 0; 301 + } 302 + 303 + static struct platform_driver sar_driver = { 304 + .probe = sar_probe, 305 + .remove = sar_remove, 306 + .driver = { 307 + .name = DRVNAME, 308 + .owner = THIS_MODULE, 309 + .acpi_match_table = ACPI_PTR(sar_device_ids) 310 + } 311 + }; 312 + module_platform_driver(sar_driver); 313 + 314 + MODULE_LICENSE("GPL v2"); 315 + MODULE_DESCRIPTION("Platform device driver for INTEL MODEM BIOS SAR"); 316 + MODULE_AUTHOR("Shravan S <s.shravan@intel.com>");
+86
drivers/platform/x86/intel/int1092/intel_sar.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (c) 2021, Intel Corporation. 4 + */ 5 + #ifndef INTEL_SAR_H 6 + #define INTEL_SAR_H 7 + 8 + #define COMMAND_ID_DEV_MODE 1 9 + #define COMMAND_ID_CONFIG_TABLE 2 10 + #define DRVNAME "intc_sar" 11 + #define MAX_DEV_MODES 50 12 + #define MAX_REGULATORY 3 13 + #define SAR_DSM_UUID "82737E72-3A33-4C45-A9C7-57C0411A5F13" 14 + #define SAR_EVENT 0x80 15 + #define SYSFS_DATANAME "intc_data" 16 + #define TOTAL_DATA 4 17 + 18 + /** 19 + * Structure wwan_device_mode_info - device mode information 20 + * Holds the data that needs to be passed to userspace. 21 + * The data is updated from the BIOS sensor information. 22 + * @device_mode: Specific mode of the device 23 + * @bandtable_index: Index of RF band 24 + * @antennatable_index: Index of antenna 25 + * @sartable_index: Index of SAR 26 + */ 27 + struct wwan_device_mode_info { 28 + int device_mode; 29 + int bandtable_index; 30 + int antennatable_index; 31 + int sartable_index; 32 + }; 33 + 34 + /** 35 + * Structure wwan_device_mode_configuration - device configuration 36 + * Holds the data that is configured and obtained on probe event. 37 + * The data is updated from the BIOS sensor information. 38 + * @version: Mode configuration version 39 + * @total_dev_mode: Total number of device modes 40 + * @device_mode_info: pointer to structure wwan_device_mode_info 41 + */ 42 + struct wwan_device_mode_configuration { 43 + int version; 44 + int total_dev_mode; 45 + struct wwan_device_mode_info *device_mode_info; 46 + }; 47 + 48 + /** 49 + * Structure wwan_supported_info - userspace datastore 50 + * Holds the data that is obtained from userspace 51 + * The data is updated from the userspace and send value back in the 52 + * structure format that is mentioned here. 53 + * @reg_mode_needed: regulatory mode set by user for tests 54 + * @bios_table_revision: Version of SAR table 55 + * @num_supported_modes: Total supported modes based on reg_mode 56 + */ 57 + struct wwan_supported_info { 58 + int reg_mode_needed; 59 + int bios_table_revision; 60 + int num_supported_modes; 61 + }; 62 + 63 + /** 64 + * Structure wwan_sar_context - context of SAR 65 + * Holds the complete context as long as the driver is in existence 66 + * The context holds instance of the data used for different cases. 67 + * @guid: Group id 68 + * @handle: store acpi handle 69 + * @reg_value: regulatory value 70 + * Regulatory 0: FCC, 1: CE, 2: ISED 71 + * @sar_device: platform_device type 72 + * @sar_kobject: kobject for sysfs 73 + * @supported_data: wwan_supported_info struct 74 + * @sar_data: wwan_device_mode_info struct 75 + * @config_data: wwan_device_mode_configuration array struct 76 + */ 77 + struct wwan_sar_context { 78 + guid_t guid; 79 + acpi_handle handle; 80 + int reg_value; 81 + struct platform_device *sar_device; 82 + struct wwan_supported_info supported_data; 83 + struct wwan_device_mode_info sar_data; 84 + struct wwan_device_mode_configuration config_data[MAX_REGULATORY]; 85 + }; 86 + #endif /* INTEL_SAR_H */