On some newer Thinkpads we need to set SAR value based on antenna type. This patch provides a sysfs interface that userspace can use to get antenna type and set corresponding SAR value, as is required for FCC certification. Reviewed-by: Mark Pearson <markpearson@xxxxxxxxxx> Signed-off-by: Nitin Joshi <njoshi1@xxxxxxxxxx> --- .../admin-guide/laptops/thinkpad-acpi.rst | 21 ++++++ drivers/platform/x86/thinkpad_acpi.c | 65 +++++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/laptops/thinkpad-acpi.rst b/Documentation/admin-guide/laptops/thinkpad-acpi.rst index 10410811b990..df6904f23dea 100644 --- a/Documentation/admin-guide/laptops/thinkpad-acpi.rst +++ b/Documentation/admin-guide/laptops/thinkpad-acpi.rst @@ -52,6 +52,7 @@ detailed description): - LCD Shadow (PrivacyGuard) enable and disable - Lap mode sensor - WLAN transmission power control + - WWAN Antenna type A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure @@ -1465,6 +1466,26 @@ The available commands are:: The first command restores the wlan transmission power and the latter one reduces wlan transmission power. +WWAN Antenna type +----------------- + +sysfs: wwan_antenna_type + +On some newer Thinkpads we need to set SAR value based on the antenna +type. This interface will be used by userspace to get the antenna type +and set the corresponding SAR value, as is required for FCC certification. + +The available commands are:: + + cat /sys/devices/platform/thinkpad_acpi/wwan_antenna_type + +Currently 2 antenna types are supported as mentioned below: +- type a +- type b + +The property is read-only. If the platform doesn't have support the sysfs +class is not created. + EXPERIMENTAL: UWB ----------------- diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index af90251d79d7..1faf260f6bbf 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -9992,8 +9992,13 @@ static struct ibm_struct proxsensor_driver_data = { #define DPRC_SET_WLAN_POWER_FULL 0x00030100 #define DPRC_WLAN_POWER_REDUCE_BIT BIT(4) #define DPRC_WLAN_POWER_FULL_BIT BIT(8) +#define DPRC_GET_WWAN_ANTENNA_TYPE 0x40000 +#define DPRC_WWAN_ANTENNA_TYPE_A_BIT BIT(4) +#define DPRC_WWAN_ANTENNA_TYPE_B_BIT BIT(8) static bool has_wlantxreduce; static int wlan_txreduce; +static bool has_antennatype; +static int wwan_antennatype; static int dprc_command(int command, int *output) { @@ -10017,6 +10022,25 @@ static int dprc_command(int command, int *output) return 0; } +static int get_wwan_antenna(int *wwan_antennatype) +{ + int output, err; + + /* Get current Antenna type */ + err = dprc_command(DPRC_GET_WWAN_ANTENNA_TYPE, &output); + if (err) + return err; + + if (output & DPRC_WWAN_ANTENNA_TYPE_A_BIT) + *wwan_antennatype = 1; + else if (output & DPRC_WWAN_ANTENNA_TYPE_B_BIT) + *wwan_antennatype = 2; + else + return -ENODATA; + + return 0; +} + static int get_wlan_state(int *wlan_txreduce) { int output, err; @@ -10036,6 +10060,21 @@ static int get_wlan_state(int *wlan_txreduce) return 0; } +/* sysfs wwan antenna type entry */ +static ssize_t wwan_antenna_type_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + switch (wwan_antennatype) { + case 1: + return sysfs_emit(buf, "type a\n"); + case 2: + return sysfs_emit(buf, "type b\n"); + default: + return -ENODATA; + } +} + /* sysfs wlan entry */ static ssize_t wlan_tx_strength_reduce_show(struct device *dev, struct device_attribute *attr, @@ -10071,18 +10110,22 @@ static ssize_t wlan_tx_strength_reduce_store(struct device *dev, return count; } static DEVICE_ATTR_RW(wlan_tx_strength_reduce); +static DEVICE_ATTR_RO(wwan_antenna_type); static int tpacpi_dprc_init(struct ibm_init_struct *iibm) { - int wlantx_err, err; + int wlantx_err, wwanantenna_err, err; wlantx_err = get_wlan_state(&wlan_txreduce); + wwanantenna_err = get_wwan_antenna(&wwan_antennatype); /* - * If support isn't available (ENODEV) for both devices then quit, but - * don't return an error. + * If support isn't available (ENODEV) or no data available (ENODATA) for both devices + * then quit, but don't return an error. */ - if ((wlantx_err == -ENODEV) || (wlantx_err == -ENODATA)) + if (((wlantx_err == -ENODEV) || (wlantx_err == -ENODATA)) && + ((wwanantenna_err == -ENODEV) || (wwanantenna_err == -ENODATA))) return 0; + /* Otherwise, if there was an error return it */ if (wlantx_err && (wlantx_err != -ENODEV) && (wlantx_err != -ENODATA)) return wlantx_err; @@ -10095,6 +10138,18 @@ static int tpacpi_dprc_init(struct ibm_init_struct *iibm) if (err) return err; } + + /* if there was an error return it */ + if (wwanantenna_err && (wwanantenna_err != -ENODEV) && (wwanantenna_err != -ENODATA)) + return wwanantenna_err; + else if (!wwanantenna_err) + has_antennatype = true; + + if (has_antennatype) { + err = sysfs_create_file(&tpacpi_pdev->dev.kobj, &dev_attr_wwan_antenna_type.attr); + if (err) + return err; + } return 0; } @@ -10102,6 +10157,8 @@ static void dprc_exit(void) { if (has_wlantxreduce) sysfs_remove_file(&tpacpi_pdev->dev.kobj, &dev_attr_wlan_tx_strength_reduce.attr); + if (has_antennatype) + sysfs_remove_file(&tpacpi_pdev->dev.kobj, &dev_attr_wwan_antenna_type.attr); } static struct ibm_struct dprc_driver_data = { -- 2.25.1