^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2007-2009 Luca Tettamanti <kronos.it@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * See COPYING in the top level directory of the kernel tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ATK_HID "ATK0110"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static bool new_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) module_param(new_if, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_PARM_DESC(new_if, "Override detection heuristic and force the use of the new ATK0110 interface");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static const struct dmi_system_id __initconst atk_force_new_if[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* Old interface has broken MCH temp monitoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .ident = "Asus Sabertooth X58",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) DMI_MATCH(DMI_BOARD_NAME, "SABERTOOTH X58")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Old interface reads the same sensor for fan0 and fan1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .ident = "Asus M5A78L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) DMI_MATCH(DMI_BOARD_NAME, "M5A78L")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Minimum time between readings, enforced in order to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * hogging the CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define CACHE_TIME HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define BOARD_ID "MBIF"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define METHOD_ENUMERATE "GGRP"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define METHOD_READ "GITM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define METHOD_WRITE "SITM"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define METHOD_OLD_READ_TMP "RTMP"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define METHOD_OLD_READ_VLT "RVLT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define METHOD_OLD_READ_FAN "RFAN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define METHOD_OLD_ENUM_TMP "TSIF"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define METHOD_OLD_ENUM_VLT "VSIF"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define METHOD_OLD_ENUM_FAN "FSIF"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define ATK_MUX_HWMON 0x00000006ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define ATK_MUX_MGMT 0x00000011ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define ATK_CLASS_MASK 0xff000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define ATK_CLASS_FREQ_CTL 0x03000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define ATK_CLASS_FAN_CTL 0x04000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define ATK_CLASS_HWMON 0x06000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define ATK_CLASS_MGMT 0x11000000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define ATK_TYPE_MASK 0x00ff0000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define HWMON_TYPE_VOLT 0x00020000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define HWMON_TYPE_TEMP 0x00030000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define HWMON_TYPE_FAN 0x00040000ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define ATK_ELEMENT_ID_MASK 0x0000ffffULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define ATK_EC_ID 0x11060004ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) enum atk_pack_member {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) HWMON_PACK_FLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) HWMON_PACK_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) HWMON_PACK_LIMIT1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) HWMON_PACK_LIMIT2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) HWMON_PACK_ENABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* New package format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define _HWMON_NEW_PACK_SIZE 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define _HWMON_NEW_PACK_FLAGS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define _HWMON_NEW_PACK_NAME 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define _HWMON_NEW_PACK_UNK1 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define _HWMON_NEW_PACK_UNK2 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define _HWMON_NEW_PACK_LIMIT1 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define _HWMON_NEW_PACK_LIMIT2 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define _HWMON_NEW_PACK_ENABLE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* Old package format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define _HWMON_OLD_PACK_SIZE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define _HWMON_OLD_PACK_FLAGS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define _HWMON_OLD_PACK_NAME 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define _HWMON_OLD_PACK_LIMIT1 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define _HWMON_OLD_PACK_LIMIT2 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define _HWMON_OLD_PACK_ENABLE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct atk_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) acpi_handle atk_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct acpi_device *acpi_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) bool old_interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* old interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) acpi_handle rtmp_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) acpi_handle rvlt_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) acpi_handle rfan_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* new interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) acpi_handle enumerate_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) acpi_handle read_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) acpi_handle write_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) bool disable_ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int voltage_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int temperature_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int fan_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct list_head sensor_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct attribute_group attr_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) const struct attribute_group *attr_groups[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct dentry *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) } debugfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) typedef ssize_t (*sysfs_show_func)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct device_attribute *attr, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static const struct acpi_device_id atk_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {ATK_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) MODULE_DEVICE_TABLE(acpi, atk_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define ATTR_NAME_SIZE 16 /* Worst case is "tempN_input" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct atk_sensor_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct atk_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct device_attribute label_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct device_attribute input_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct device_attribute limit1_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct device_attribute limit2_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) char label_attr_name[ATTR_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) char input_attr_name[ATTR_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) char limit1_attr_name[ATTR_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) char limit2_attr_name[ATTR_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u64 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) u64 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) u64 limit1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) u64 limit2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u64 cached_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) unsigned long last_updated; /* in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) bool is_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) char const *acpi_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Return buffer format:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * [0-3] "value" is valid flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * [4-7] value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * [8- ] unknown stuff on newer mobos
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct atk_acpi_ret_buffer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) u8 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Input buffer used for GITM and SITM methods */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct atk_acpi_input_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u32 param1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u32 param2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int atk_add(struct acpi_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int atk_remove(struct acpi_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static void atk_print_sensor(struct atk_data *data, union acpi_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static int atk_read_value(struct atk_sensor_data *sensor, u64 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static struct acpi_driver atk_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) .name = ATK_HID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .class = "hwmon",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .ids = atk_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .add = atk_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .remove = atk_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #define input_to_atk_sensor(attr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) container_of(attr, struct atk_sensor_data, input_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #define label_to_atk_sensor(attr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) container_of(attr, struct atk_sensor_data, label_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define limit1_to_atk_sensor(attr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) container_of(attr, struct atk_sensor_data, limit1_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #define limit2_to_atk_sensor(attr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) container_of(attr, struct atk_sensor_data, limit2_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static ssize_t atk_input_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct atk_sensor_data *s = input_to_atk_sensor(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) u64 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) err = atk_read_value(s, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (s->type == HWMON_TYPE_TEMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* ACPI returns decidegree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) value *= 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return sprintf(buf, "%llu\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static ssize_t atk_label_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct atk_sensor_data *s = label_to_atk_sensor(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return sprintf(buf, "%s\n", s->acpi_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static ssize_t atk_limit1_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct atk_sensor_data *s = limit1_to_atk_sensor(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) u64 value = s->limit1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (s->type == HWMON_TYPE_TEMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) value *= 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return sprintf(buf, "%lld\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static ssize_t atk_limit2_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct atk_sensor_data *s = limit2_to_atk_sensor(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) u64 value = s->limit2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (s->type == HWMON_TYPE_TEMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) value *= 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return sprintf(buf, "%lld\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static void atk_init_attribute(struct device_attribute *attr, char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) sysfs_show_func show)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) sysfs_attr_init(&attr->attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) attr->attr.name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) attr->attr.mode = 0444;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) attr->show = show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) attr->store = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static union acpi_object *atk_get_pack_member(struct atk_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) union acpi_object *pack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) enum atk_pack_member m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) bool old_if = data->old_interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) switch (m) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) case HWMON_PACK_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) offset = old_if ? _HWMON_OLD_PACK_FLAGS : _HWMON_NEW_PACK_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case HWMON_PACK_NAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) offset = old_if ? _HWMON_OLD_PACK_NAME : _HWMON_NEW_PACK_NAME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) case HWMON_PACK_LIMIT1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) offset = old_if ? _HWMON_OLD_PACK_LIMIT1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) _HWMON_NEW_PACK_LIMIT1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) case HWMON_PACK_LIMIT2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) offset = old_if ? _HWMON_OLD_PACK_LIMIT2 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) _HWMON_NEW_PACK_LIMIT2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) case HWMON_PACK_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) offset = old_if ? _HWMON_OLD_PACK_ENABLE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) _HWMON_NEW_PACK_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return &pack->package.elements[offset];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * New package format is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * - flag (int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * class - used for de-muxing the request to the correct GITn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * type (volt, temp, fan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * sensor id |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * sensor id - used for de-muxing the request _inside_ the GITn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * - name (str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * - unknown (int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * - unknown (int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * - limit1 (int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * - limit2 (int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * - enable (int)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * The old package has the same format but it's missing the two unknown fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int validate_hwmon_pack(struct atk_data *data, union acpi_object *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) union acpi_object *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) bool old_if = data->old_interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int const expected_size = old_if ? _HWMON_OLD_PACK_SIZE :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) _HWMON_NEW_PACK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (obj->type != ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) dev_warn(dev, "Invalid type: %d\n", obj->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (obj->package.count != expected_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) dev_warn(dev, "Invalid package size: %d, expected: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) obj->package.count, expected_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) tmp = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (tmp->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) dev_warn(dev, "Invalid type (flag): %d\n", tmp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) tmp = atk_get_pack_member(data, obj, HWMON_PACK_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (tmp->type != ACPI_TYPE_STRING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) dev_warn(dev, "Invalid type (name): %d\n", tmp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Don't check... we don't know what they're useful for anyway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) tmp = &obj->package.elements[HWMON_PACK_UNK1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (tmp->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) dev_warn(dev, "Invalid type (unk1): %d\n", tmp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) tmp = &obj->package.elements[HWMON_PACK_UNK2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (tmp->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) dev_warn(dev, "Invalid type (unk2): %d\n", tmp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) tmp = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (tmp->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) dev_warn(dev, "Invalid type (limit1): %d\n", tmp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) tmp = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (tmp->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) dev_warn(dev, "Invalid type (limit2): %d\n", tmp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) tmp = atk_get_pack_member(data, obj, HWMON_PACK_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (tmp->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) dev_warn(dev, "Invalid type (enable): %d\n", tmp->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) atk_print_sensor(data, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static char const *atk_sensor_type(union acpi_object *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) u64 type = flags->integer.value & ATK_TYPE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) char const *what;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) case HWMON_TYPE_VOLT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) what = "voltage";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) case HWMON_TYPE_TEMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) what = "temperature";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) case HWMON_TYPE_FAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) what = "fan";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) what = "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return what;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static void atk_print_sensor(struct atk_data *data, union acpi_object *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) union acpi_object *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) union acpi_object *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) union acpi_object *limit1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) union acpi_object *limit2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) union acpi_object *enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) char const *what;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) flags = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) name = atk_get_pack_member(data, obj, HWMON_PACK_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) enable = atk_get_pack_member(data, obj, HWMON_PACK_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) what = atk_sensor_type(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) dev_dbg(dev, "%s: %#llx %s [%llu-%llu] %s\n", what,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) flags->integer.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) name->string.pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) limit1->integer.value, limit2->integer.value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) enable->integer.value ? "enabled" : "disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static int atk_read_value_old(struct atk_sensor_data *sensor, u64 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) struct atk_data *data = sensor->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct acpi_object_list params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) union acpi_object id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) acpi_handle method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) switch (sensor->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) case HWMON_TYPE_VOLT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) method = data->rvlt_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) case HWMON_TYPE_TEMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) method = data->rtmp_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) case HWMON_TYPE_FAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) method = data->rfan_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) id.type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) id.integer.value = sensor->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) params.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) params.pointer = &id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) status = acpi_evaluate_integer(method, NULL, ¶ms, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (status != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) dev_warn(dev, "%s: ACPI exception: %s\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static union acpi_object *atk_ggrp(struct atk_data *data, u16 mux)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) struct acpi_buffer buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) acpi_status ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct acpi_object_list params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) union acpi_object id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) union acpi_object *pack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) id.type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) id.integer.value = mux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) params.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) params.pointer = &id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) buf.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ret = acpi_evaluate_object(data->enumerate_handle, NULL, ¶ms, &buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (ret != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) dev_err(dev, "GGRP[%#x] ACPI exception: %s\n", mux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) acpi_format_exception(ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) pack = buf.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (pack->type != ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) /* Execution was successful, but the id was not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) ACPI_FREE(pack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (pack->package.count < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) dev_err(dev, "GGRP[%#x] package is too small\n", mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) ACPI_FREE(pack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return pack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static union acpi_object *atk_gitm(struct atk_data *data, u64 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct atk_acpi_input_buf buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) union acpi_object tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct acpi_object_list params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct acpi_buffer ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) buf.id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) buf.param1 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) buf.param2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) tmp.type = ACPI_TYPE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) tmp.buffer.pointer = (u8 *)&buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) tmp.buffer.length = sizeof(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) params.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) params.pointer = (void *)&tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) ret.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) status = acpi_evaluate_object_typed(data->read_handle, NULL, ¶ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) &ret, ACPI_TYPE_BUFFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) if (status != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) dev_warn(dev, "GITM[%#llx] ACPI exception: %s\n", id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) obj = ret.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) /* Sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (obj->buffer.length < 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) dev_warn(dev, "Unexpected ASBF length: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) obj->buffer.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static union acpi_object *atk_sitm(struct atk_data *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) struct atk_acpi_input_buf *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct acpi_object_list params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) union acpi_object tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) struct acpi_buffer ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) tmp.type = ACPI_TYPE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) tmp.buffer.pointer = (u8 *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) tmp.buffer.length = sizeof(*buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) params.count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) params.pointer = &tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) ret.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) status = acpi_evaluate_object_typed(data->write_handle, NULL, ¶ms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) &ret, ACPI_TYPE_BUFFER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (status != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) dev_warn(dev, "SITM[%#x] ACPI exception: %s\n", buf->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) obj = ret.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* Sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (obj->buffer.length < 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) dev_warn(dev, "Unexpected ASBF length: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) obj->buffer.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) static int atk_read_value_new(struct atk_sensor_data *sensor, u64 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct atk_data *data = sensor->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) struct atk_acpi_ret_buffer *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) obj = atk_gitm(data, sensor->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (IS_ERR(obj))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) return PTR_ERR(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) buf = (struct atk_acpi_ret_buffer *)obj->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (buf->flags == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * The reading is not valid, possible causes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * - sensor failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * - enumeration was FUBAR (and we didn't notice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) dev_warn(dev, "Read failed, sensor = %#llx\n", sensor->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) *value = buf->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) static int atk_read_value(struct atk_sensor_data *sensor, u64 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (!sensor->is_valid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) time_after(jiffies, sensor->last_updated + CACHE_TIME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (sensor->data->old_interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) err = atk_read_value_old(sensor, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) err = atk_read_value_new(sensor, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) sensor->is_valid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) sensor->last_updated = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) sensor->cached_value = *value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) *value = sensor->cached_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static int atk_debugfs_gitm_get(void *p, u64 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct atk_data *data = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) union acpi_object *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) struct atk_acpi_ret_buffer *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (!data->read_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (!data->debugfs.id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) ret = atk_gitm(data, data->debugfs.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (IS_ERR(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return PTR_ERR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) buf = (struct atk_acpi_ret_buffer *)ret->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (buf->flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) *val = buf->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) ACPI_FREE(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) DEFINE_DEBUGFS_ATTRIBUTE(atk_debugfs_gitm, atk_debugfs_gitm_get, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) "0x%08llx\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) static int atk_acpi_print(char *buf, size_t sz, union acpi_object *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) switch (obj->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) case ACPI_TYPE_INTEGER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) ret = snprintf(buf, sz, "0x%08llx\n", obj->integer.value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) case ACPI_TYPE_STRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) ret = snprintf(buf, sz, "%s\n", obj->string.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) static void atk_pack_print(char *buf, size_t sz, union acpi_object *pack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) for (i = 0; i < pack->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) union acpi_object *obj = &pack->package.elements[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) ret = atk_acpi_print(buf, sz, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (ret >= sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) buf += ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) sz -= ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) static int atk_debugfs_ggrp_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct atk_data *data = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) char *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) union acpi_object *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) u8 cls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (!data->enumerate_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) if (!data->debugfs.id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) cls = (data->debugfs.id & 0xff000000) >> 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) ret = atk_ggrp(data, cls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (IS_ERR(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return PTR_ERR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) for (i = 0; i < ret->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) union acpi_object *pack = &ret->package.elements[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) union acpi_object *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (pack->type != ACPI_TYPE_PACKAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) if (!pack->package.count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) id = &pack->package.elements[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) if (id->integer.value == data->debugfs.id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) /* Print the package */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) buf = kzalloc(512, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) ACPI_FREE(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) atk_pack_print(buf, 512, pack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) ACPI_FREE(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) file->private_data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) return nonseekable_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static ssize_t atk_debugfs_ggrp_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) size_t count, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) char *str = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) size_t len = strlen(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return simple_read_from_buffer(buf, count, pos, str, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) static int atk_debugfs_ggrp_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) kfree(file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) static const struct file_operations atk_debugfs_ggrp_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) .read = atk_debugfs_ggrp_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) .open = atk_debugfs_ggrp_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) .release = atk_debugfs_ggrp_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) static void atk_debugfs_init(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct dentry *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) data->debugfs.id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) d = debugfs_create_dir("asus_atk0110", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) debugfs_create_x32("id", 0600, d, &data->debugfs.id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) debugfs_create_file_unsafe("gitm", 0400, d, data, &atk_debugfs_gitm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) debugfs_create_file("ggrp", 0400, d, data, &atk_debugfs_ggrp_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) data->debugfs.root = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) static void atk_debugfs_cleanup(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) debugfs_remove_recursive(data->debugfs.root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) #else /* CONFIG_DEBUG_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static void atk_debugfs_init(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) static void atk_debugfs_cleanup(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) static int atk_add_sensor(struct atk_data *data, union acpi_object *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) union acpi_object *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) union acpi_object *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) union acpi_object *limit1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) union acpi_object *limit2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) union acpi_object *enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct atk_sensor_data *sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) char const *base_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) char const *limit1_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) char const *limit2_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) u64 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) int *num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) int start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (obj->type != ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) /* wft is this? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) dev_warn(dev, "Unknown type for ACPI object: (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) obj->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) err = validate_hwmon_pack(data, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) /* Ok, we have a valid hwmon package */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) type = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS)->integer.value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) & ATK_TYPE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) case HWMON_TYPE_VOLT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) base_name = "in";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) limit1_name = "min";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) limit2_name = "max";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) num = &data->voltage_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) case HWMON_TYPE_TEMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) base_name = "temp";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) limit1_name = "max";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) limit2_name = "crit";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) num = &data->temperature_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) start = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) case HWMON_TYPE_FAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) base_name = "fan";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) limit1_name = "min";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) limit2_name = "max";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) num = &data->fan_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) start = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) dev_warn(dev, "Unknown sensor type: %#llx\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) enable = atk_get_pack_member(data, obj, HWMON_PACK_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (!enable->integer.value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) /* sensor is disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) flags = atk_get_pack_member(data, obj, HWMON_PACK_FLAGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) name = atk_get_pack_member(data, obj, HWMON_PACK_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) limit1 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) limit2 = atk_get_pack_member(data, obj, HWMON_PACK_LIMIT2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (!sensor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) sensor->acpi_name = devm_kstrdup(dev, name->string.pointer, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (!sensor->acpi_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) INIT_LIST_HEAD(&sensor->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) sensor->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) sensor->data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) sensor->id = flags->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) sensor->limit1 = limit1->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (data->old_interface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) sensor->limit2 = limit2->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) /* The upper limit is expressed as delta from lower limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) sensor->limit2 = sensor->limit1 + limit2->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) snprintf(sensor->input_attr_name, ATTR_NAME_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) "%s%d_input", base_name, start + *num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) atk_init_attribute(&sensor->input_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) sensor->input_attr_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) atk_input_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) snprintf(sensor->label_attr_name, ATTR_NAME_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) "%s%d_label", base_name, start + *num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) atk_init_attribute(&sensor->label_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) sensor->label_attr_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) atk_label_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) snprintf(sensor->limit1_attr_name, ATTR_NAME_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) "%s%d_%s", base_name, start + *num, limit1_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) atk_init_attribute(&sensor->limit1_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) sensor->limit1_attr_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) atk_limit1_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) snprintf(sensor->limit2_attr_name, ATTR_NAME_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) "%s%d_%s", base_name, start + *num, limit2_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) atk_init_attribute(&sensor->limit2_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) sensor->limit2_attr_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) atk_limit2_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) list_add(&sensor->list, &data->sensor_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) (*num)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) static int atk_enumerate_old_hwmon(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct acpi_buffer buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) union acpi_object *pack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) /* Voltages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) buf.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) status = acpi_evaluate_object_typed(data->atk_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) METHOD_OLD_ENUM_VLT, NULL, &buf, ACPI_TYPE_PACKAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (status != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) dev_warn(dev, METHOD_OLD_ENUM_VLT ": ACPI exception: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) pack = buf.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) for (i = 1; i < pack->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) union acpi_object *obj = &pack->package.elements[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) ret = atk_add_sensor(data, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) ACPI_FREE(buf.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) /* Temperatures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) buf.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) status = acpi_evaluate_object_typed(data->atk_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) METHOD_OLD_ENUM_TMP, NULL, &buf, ACPI_TYPE_PACKAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if (status != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) dev_warn(dev, METHOD_OLD_ENUM_TMP ": ACPI exception: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) pack = buf.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) for (i = 1; i < pack->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) union acpi_object *obj = &pack->package.elements[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) ret = atk_add_sensor(data, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) ACPI_FREE(buf.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) /* Fans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) buf.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) status = acpi_evaluate_object_typed(data->atk_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) METHOD_OLD_ENUM_FAN, NULL, &buf, ACPI_TYPE_PACKAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) if (status != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) dev_warn(dev, METHOD_OLD_ENUM_FAN ": ACPI exception: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) pack = buf.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) for (i = 1; i < pack->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) union acpi_object *obj = &pack->package.elements[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) ret = atk_add_sensor(data, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) ACPI_FREE(buf.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static int atk_ec_present(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) union acpi_object *pack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) union acpi_object *ec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) pack = atk_ggrp(data, ATK_MUX_MGMT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) if (IS_ERR(pack)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) if (PTR_ERR(pack) == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /* The MGMT class does not exists - that's ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) dev_dbg(dev, "Class %#llx not found\n", ATK_MUX_MGMT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) return PTR_ERR(pack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) /* Search the EC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) ec = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) for (i = 0; i < pack->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) union acpi_object *obj = &pack->package.elements[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) union acpi_object *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (obj->type != ACPI_TYPE_PACKAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) id = &obj->package.elements[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (id->type != ACPI_TYPE_INTEGER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (id->integer.value == ATK_EC_ID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) ec = obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) ret = (ec != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) /* The system has no EC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) dev_dbg(dev, "EC not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) ACPI_FREE(pack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) static int atk_ec_enabled(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) struct atk_acpi_ret_buffer *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) obj = atk_gitm(data, ATK_EC_ID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (IS_ERR(obj)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) dev_err(dev, "Unable to query EC status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) return PTR_ERR(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) buf = (struct atk_acpi_ret_buffer *)obj->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (buf->flags == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) dev_err(dev, "Unable to query EC status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) err = (buf->value != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) dev_dbg(dev, "EC is %sabled\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) err ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static int atk_ec_ctl(struct atk_data *data, int enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) struct atk_acpi_input_buf sitm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) struct atk_acpi_ret_buffer *ec_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) sitm.id = ATK_EC_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) sitm.param1 = enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) sitm.param2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) obj = atk_sitm(data, &sitm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (IS_ERR(obj)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) dev_err(dev, "Failed to %sable the EC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) enable ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) return PTR_ERR(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) ec_ret = (struct atk_acpi_ret_buffer *)obj->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) if (ec_ret->flags == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) dev_err(dev, "Failed to %sable the EC\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) enable ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) dev_info(dev, "EC %sabled\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) enable ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) ACPI_FREE(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static int atk_enumerate_new_hwmon(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) union acpi_object *pack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) err = atk_ec_present(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) err = atk_ec_enabled(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) /* If the EC was disabled we will disable it again on unload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) data->disable_ec = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) err = atk_ec_ctl(data, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) data->disable_ec = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) dev_dbg(dev, "Enumerating hwmon sensors\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) pack = atk_ggrp(data, ATK_MUX_HWMON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (IS_ERR(pack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) return PTR_ERR(pack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) for (i = 0; i < pack->package.count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) union acpi_object *obj = &pack->package.elements[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) atk_add_sensor(data, obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) err = data->voltage_count + data->temperature_count + data->fan_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) ACPI_FREE(pack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) static int atk_init_attribute_groups(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) struct atk_sensor_data *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) struct attribute **attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) int len = (data->voltage_count + data->temperature_count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) + data->fan_count) * 4 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) attrs = devm_kcalloc(dev, len, sizeof(struct attribute *), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (!attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) list_for_each_entry(s, &data->sensor_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) attrs[i++] = &s->input_attr.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) attrs[i++] = &s->label_attr.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) attrs[i++] = &s->limit1_attr.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) attrs[i++] = &s->limit2_attr.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) data->attr_group.attrs = attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) data->attr_groups[0] = &data->attr_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) static int atk_register_hwmon(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) dev_dbg(dev, "registering hwmon device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) data->hwmon_dev = hwmon_device_register_with_groups(dev, "atk0110",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) data->attr_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) return PTR_ERR_OR_ZERO(data->hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) static int atk_probe_if(struct atk_data *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct device *dev = &data->acpi_dev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) acpi_handle ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) /* RTMP: read temperature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_TMP, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) data->rtmp_handle = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) dev_dbg(dev, "method " METHOD_OLD_READ_TMP " not found: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) /* RVLT: read voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_VLT, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) data->rvlt_handle = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) dev_dbg(dev, "method " METHOD_OLD_READ_VLT " not found: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) /* RFAN: read fan status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) status = acpi_get_handle(data->atk_handle, METHOD_OLD_READ_FAN, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) data->rfan_handle = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) dev_dbg(dev, "method " METHOD_OLD_READ_FAN " not found: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) /* Enumeration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) status = acpi_get_handle(data->atk_handle, METHOD_ENUMERATE, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) data->enumerate_handle = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) dev_dbg(dev, "method " METHOD_ENUMERATE " not found: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) /* De-multiplexer (read) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) status = acpi_get_handle(data->atk_handle, METHOD_READ, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) data->read_handle = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) dev_dbg(dev, "method " METHOD_READ " not found: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) /* De-multiplexer (write) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) status = acpi_get_handle(data->atk_handle, METHOD_WRITE, &ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (ACPI_SUCCESS(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) data->write_handle = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) dev_dbg(dev, "method " METHOD_WRITE " not found: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) acpi_format_exception(status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) * Check for hwmon methods: first check "old" style methods; note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) * both may be present: in this case we stick to the old interface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) * analysis of multiple DSDTs indicates that when both interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) * are present the new one (GGRP/GITM) is not functional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if (new_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) dev_info(dev, "Overriding interface detection\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (data->rtmp_handle &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) data->rvlt_handle && data->rfan_handle && !new_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) data->old_interface = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) else if (data->enumerate_handle && data->read_handle &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) data->write_handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) data->old_interface = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) static int atk_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) acpi_status ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) struct acpi_buffer buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) struct atk_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) dev_dbg(&device->dev, "adding...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) data = devm_kzalloc(&device->dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) data->acpi_dev = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) data->atk_handle = device->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) INIT_LIST_HEAD(&data->sensor_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) data->disable_ec = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) buf.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) ret = acpi_evaluate_object_typed(data->atk_handle, BOARD_ID, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) &buf, ACPI_TYPE_PACKAGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (ret != AE_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) dev_dbg(&device->dev, "atk: method MBIF not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) obj = buf.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) if (obj->package.count >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) union acpi_object *id = &obj->package.elements[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) if (id->type == ACPI_TYPE_STRING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) dev_dbg(&device->dev, "board ID = %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) id->string.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) ACPI_FREE(buf.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) err = atk_probe_if(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) dev_err(&device->dev, "No usable hwmon interface detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) if (data->old_interface) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) dev_dbg(&device->dev, "Using old hwmon interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) err = atk_enumerate_old_hwmon(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) dev_dbg(&device->dev, "Using new hwmon interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) err = atk_enumerate_new_hwmon(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) dev_info(&device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) "No usable sensor detected, bailing out\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) err = atk_init_attribute_groups(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) err = atk_register_hwmon(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) atk_debugfs_init(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) device->driver_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (data->disable_ec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) atk_ec_ctl(data, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) static int atk_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) struct atk_data *data = device->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) dev_dbg(&device->dev, "removing...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) device->driver_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) atk_debugfs_cleanup(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) hwmon_device_unregister(data->hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (data->disable_ec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) if (atk_ec_ctl(data, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) dev_err(&device->dev, "Failed to disable EC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) static int __init atk0110_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) /* Make sure it's safe to access the device through ACPI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) if (!acpi_resources_are_enforced()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) pr_err("Resources not safely usable due to acpi_enforce_resources kernel parameter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (dmi_check_system(atk_force_new_if))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) new_if = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) ret = acpi_bus_register_driver(&atk_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) pr_info("acpi_bus_register_driver failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) static void __exit atk0110_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) acpi_bus_unregister_driver(&atk_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) module_init(atk0110_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) module_exit(atk0110_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) MODULE_LICENSE("GPL");