drivers/platform/x86/intel/int1092/intel_sar.c

Source file repositories/reference/linux-study-clean/drivers/platform/x86/intel/int1092/intel_sar.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/x86/intel/int1092/intel_sar.c
Extension
.c
Size
9155 bytes
Lines
327
Domain
Driver Families
Bucket
drivers/platform
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2021, Intel Corporation.
 */

#include <linux/acpi.h>
#include <linux/kobject.h>
#include <linux/platform_device.h>
#include <linux/sysfs.h>
#include "intel_sar.h"

/**
 * get_int_value: Retrieve integer values from ACPI Object
 * @obj: acpi_object pointer which has the integer value
 * @out: output pointer will get integer value
 *
 * Function is used to retrieve integer value from acpi object.
 *
 * Return:
 * * 0 on success
 * * -EIO if there is an issue in acpi_object passed.
 */
static int get_int_value(union acpi_object *obj, int *out)
{
	if (!obj || obj->type != ACPI_TYPE_INTEGER)
		return -EIO;
	*out = (int)obj->integer.value;
	return 0;
}

/**
 * update_sar_data: sar data is updated based on regulatory mode
 * @context: pointer to driver context structure
 *
 * sar_data is updated based on regulatory value
 * context->reg_value will never exceed MAX_REGULATORY
 */
static void update_sar_data(struct wwan_sar_context *context)
{
	struct wwan_device_mode_configuration *config =
		&context->config_data[context->reg_value];

	if (config->device_mode_info &&
	    context->sar_data.device_mode < config->total_dev_mode) {
		int itr = 0;

		for (itr = 0; itr < config->total_dev_mode; itr++) {
			if (context->sar_data.device_mode ==
				config->device_mode_info[itr].device_mode) {
				struct wwan_device_mode_info *dev_mode =
				&config->device_mode_info[itr];

				context->sar_data.antennatable_index = dev_mode->antennatable_index;
				context->sar_data.bandtable_index = dev_mode->bandtable_index;
				context->sar_data.sartable_index = dev_mode->sartable_index;
				break;
			}
		}
	}
}

/**
 * parse_package: parse acpi package for retrieving SAR information
 * @context: pointer to driver context structure
 * @item : acpi_object pointer
 *
 * Given acpi_object is iterated to retrieve information for each device mode.
 * If a given package corresponding to a specific device mode is faulty, it is
 * skipped and the specific entry in context structure will have the default value
 * of zero. Decoding of subsequent device modes is realized by having "continue"
 * statements in the for loop on encountering error in parsing given device mode.
 *
 * Return:
 * AE_OK if success
 * AE_ERROR on error
 */
static acpi_status parse_package(struct wwan_sar_context *context, union acpi_object *item)
{
	struct wwan_device_mode_configuration *data;
	int value, itr, reg;
	union acpi_object *num;

	num = &item->package.elements[0];
	if (get_int_value(num, &value) || value < 0 || value >= MAX_REGULATORY)
		return AE_ERROR;

	reg = value;

	data = &context->config_data[reg];
	if (data->total_dev_mode > MAX_DEV_MODES ||	data->total_dev_mode == 0 ||

Annotation

Implementation Notes