1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2017 Intel Deutschland GmbH
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program;
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2017 Intel Deutschland GmbH
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
38 * * Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in
42 * the documentation and/or other materials provided with the
44 * * Neither the name Intel Corporation nor the names of its
45 * contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
51 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
52 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 *****************************************************************************/
63 #include "iwl-debug.h"
66 void *iwl_acpi_get_object(struct device
*dev
, acpi_string method
)
68 acpi_handle root_handle
;
70 struct acpi_buffer buf
= {ACPI_ALLOCATE_BUFFER
, NULL
};
73 root_handle
= ACPI_HANDLE(dev
);
75 IWL_DEBUG_DEV_RADIO(dev
,
76 "Could not retrieve root port ACPI handle\n");
77 return ERR_PTR(-ENOENT
);
80 /* Get the method's handle */
81 status
= acpi_get_handle(root_handle
, method
, &handle
);
82 if (ACPI_FAILURE(status
)) {
83 IWL_DEBUG_DEV_RADIO(dev
, "%s method not found\n", method
);
84 return ERR_PTR(-ENOENT
);
87 /* Call the method with no arguments */
88 status
= acpi_evaluate_object(handle
, NULL
, NULL
, &buf
);
89 if (ACPI_FAILURE(status
)) {
90 IWL_DEBUG_DEV_RADIO(dev
, "%s invocation failed (0x%x)\n",
92 return ERR_PTR(-ENOENT
);
97 IWL_EXPORT_SYMBOL(iwl_acpi_get_object
);
99 union acpi_object
*iwl_acpi_get_wifi_pkg(struct device
*dev
,
100 union acpi_object
*data
,
104 union acpi_object
*wifi_pkg
;
107 * We need at least one entry in the wifi package that
108 * describes the domain, and one more entry, otherwise there's
109 * no point in reading it.
111 if (WARN_ON_ONCE(data_size
< 2))
112 return ERR_PTR(-EINVAL
);
115 * We need at least two packages, one for the revision and one
116 * for the data itself. Also check that the revision is valid
117 * (i.e. it is an integer set to 0).
119 if (data
->type
!= ACPI_TYPE_PACKAGE
||
120 data
->package
.count
< 2 ||
121 data
->package
.elements
[0].type
!= ACPI_TYPE_INTEGER
||
122 data
->package
.elements
[0].integer
.value
!= 0) {
123 IWL_DEBUG_DEV_RADIO(dev
, "Unsupported packages structure\n");
124 return ERR_PTR(-EINVAL
);
127 /* loop through all the packages to find the one for WiFi */
128 for (i
= 1; i
< data
->package
.count
; i
++) {
129 union acpi_object
*domain
;
131 wifi_pkg
= &data
->package
.elements
[i
];
133 /* skip entries that are not a package with the right size */
134 if (wifi_pkg
->type
!= ACPI_TYPE_PACKAGE
||
135 wifi_pkg
->package
.count
!= data_size
)
138 domain
= &wifi_pkg
->package
.elements
[0];
139 if (domain
->type
== ACPI_TYPE_INTEGER
&&
140 domain
->integer
.value
== ACPI_WIFI_DOMAIN
)
144 return ERR_PTR(-ENOENT
);
149 IWL_EXPORT_SYMBOL(iwl_acpi_get_wifi_pkg
);
151 int iwl_acpi_get_mcc(struct device
*dev
, char *mcc
)
153 union acpi_object
*wifi_pkg
, *data
;
157 data
= iwl_acpi_get_object(dev
, ACPI_WRDD_METHOD
);
159 return PTR_ERR(data
);
161 wifi_pkg
= iwl_acpi_get_wifi_pkg(dev
, data
, ACPI_WRDD_WIFI_DATA_SIZE
);
162 if (IS_ERR(wifi_pkg
)) {
163 ret
= PTR_ERR(wifi_pkg
);
167 if (wifi_pkg
->package
.elements
[1].type
!= ACPI_TYPE_INTEGER
) {
172 mcc_val
= wifi_pkg
->package
.elements
[1].integer
.value
;
174 mcc
[0] = (mcc_val
>> 8) & 0xff;
175 mcc
[1] = mcc_val
& 0xff;
183 IWL_EXPORT_SYMBOL(iwl_acpi_get_mcc
);
185 u64
iwl_acpi_get_pwr_limit(struct device
*dev
)
187 union acpi_object
*data
, *wifi_pkg
;
190 data
= iwl_acpi_get_object(dev
, ACPI_SPLC_METHOD
);
196 wifi_pkg
= iwl_acpi_get_wifi_pkg(dev
, data
,
197 ACPI_SPLC_WIFI_DATA_SIZE
);
198 if (IS_ERR(wifi_pkg
) ||
199 wifi_pkg
->package
.elements
[1].integer
.value
!= ACPI_TYPE_INTEGER
) {
204 dflt_pwr_limit
= wifi_pkg
->package
.elements
[1].integer
.value
;
208 return dflt_pwr_limit
;
210 IWL_EXPORT_SYMBOL(iwl_acpi_get_pwr_limit
);