drm/radeon: reorganize ATPX support (v2)
- rework the acpi execute code - User proper parameters for ATPX functions v2: rebase fixes Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
parent
48fa412b74
commit
492b49a2f2
1 changed files with 108 additions and 58 deletions
|
@ -26,6 +26,7 @@ struct radeon_atpx_functions {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct radeon_atpx {
|
struct radeon_atpx {
|
||||||
|
acpi_handle handle;
|
||||||
struct radeon_atpx_functions functions;
|
struct radeon_atpx_functions functions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +34,6 @@ static struct radeon_atpx_priv {
|
||||||
bool atpx_detected;
|
bool atpx_detected;
|
||||||
/* handle for device - and atpx */
|
/* handle for device - and atpx */
|
||||||
acpi_handle dhandle;
|
acpi_handle dhandle;
|
||||||
acpi_handle atpx_handle;
|
|
||||||
struct radeon_atpx atpx;
|
struct radeon_atpx atpx;
|
||||||
} radeon_atpx_priv;
|
} radeon_atpx_priv;
|
||||||
|
|
||||||
|
@ -43,6 +43,16 @@ struct atpx_verify_interface {
|
||||||
u32 function_bits; /* supported functions bit vector */
|
u32 function_bits; /* supported functions bit vector */
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
|
struct atpx_power_control {
|
||||||
|
u16 size;
|
||||||
|
u8 dgpu_state;
|
||||||
|
} __packed;
|
||||||
|
|
||||||
|
struct atpx_mux {
|
||||||
|
u16 size;
|
||||||
|
u16 mux;
|
||||||
|
} __packed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* radeon_atpx_call - call an ATPX method
|
* radeon_atpx_call - call an ATPX method
|
||||||
*
|
*
|
||||||
|
@ -123,15 +133,14 @@ static void radeon_atpx_parse_functions(struct radeon_atpx_functions *f, u32 mas
|
||||||
* (all asics).
|
* (all asics).
|
||||||
* returns 0 on success, error on failure.
|
* returns 0 on success, error on failure.
|
||||||
*/
|
*/
|
||||||
static int radeon_atpx_verify_interface(acpi_handle handle,
|
static int radeon_atpx_verify_interface(struct radeon_atpx *atpx)
|
||||||
struct radeon_atpx *atpx)
|
|
||||||
{
|
{
|
||||||
union acpi_object *info;
|
union acpi_object *info;
|
||||||
struct atpx_verify_interface output;
|
struct atpx_verify_interface output;
|
||||||
size_t size;
|
size_t size;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
info = radeon_atpx_call(handle, ATPX_FUNCTION_VERIFY_INTERFACE, NULL);
|
info = radeon_atpx_call(atpx->handle, ATPX_FUNCTION_VERIFY_INTERFACE, NULL);
|
||||||
if (!info)
|
if (!info)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
|
@ -157,82 +166,124 @@ out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_execute(acpi_handle handle, int cmd_id, u16 value)
|
static int radeon_atpx_set_discrete_state(struct radeon_atpx *atpx, u8 state)
|
||||||
{
|
{
|
||||||
acpi_status status;
|
struct acpi_buffer params;
|
||||||
union acpi_object atpx_arg_elements[2];
|
union acpi_object *info;
|
||||||
struct acpi_object_list atpx_arg;
|
struct atpx_power_control input;
|
||||||
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
|
||||||
uint8_t buf[4] = {0};
|
|
||||||
|
|
||||||
if (!handle)
|
if (atpx->functions.power_cntl) {
|
||||||
return -EINVAL;
|
input.size = 3;
|
||||||
|
input.dgpu_state = state;
|
||||||
atpx_arg.count = 2;
|
params.length = input.size;
|
||||||
atpx_arg.pointer = &atpx_arg_elements[0];
|
params.pointer = &input;
|
||||||
|
info = radeon_atpx_call(atpx->handle,
|
||||||
atpx_arg_elements[0].type = ACPI_TYPE_INTEGER;
|
ATPX_FUNCTION_POWER_CONTROL,
|
||||||
atpx_arg_elements[0].integer.value = cmd_id;
|
¶ms);
|
||||||
|
if (!info)
|
||||||
buf[2] = value & 0xff;
|
return -EIO;
|
||||||
buf[3] = (value >> 8) & 0xff;
|
kfree(info);
|
||||||
|
|
||||||
atpx_arg_elements[1].type = ACPI_TYPE_BUFFER;
|
|
||||||
atpx_arg_elements[1].buffer.length = 4;
|
|
||||||
atpx_arg_elements[1].buffer.pointer = buf;
|
|
||||||
|
|
||||||
status = acpi_evaluate_object(handle, NULL, &atpx_arg, &buffer);
|
|
||||||
if (ACPI_FAILURE(status)) {
|
|
||||||
printk("%s: failed to call ATPX: %s\n", __func__, acpi_format_exception(status));
|
|
||||||
return -ENOSYS;
|
|
||||||
}
|
}
|
||||||
kfree(buffer.pointer);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_set_discrete_state(acpi_handle handle, int state)
|
static int radeon_atpx_switch_disp_mux(struct radeon_atpx *atpx, u16 mux_id)
|
||||||
{
|
{
|
||||||
return radeon_atpx_execute(handle, ATPX_FUNCTION_POWER_CONTROL, state);
|
struct acpi_buffer params;
|
||||||
|
union acpi_object *info;
|
||||||
|
struct atpx_mux input;
|
||||||
|
|
||||||
|
if (atpx->functions.disp_mux_cntl) {
|
||||||
|
input.size = 4;
|
||||||
|
input.mux = mux_id;
|
||||||
|
params.length = input.size;
|
||||||
|
params.pointer = &input;
|
||||||
|
info = radeon_atpx_call(atpx->handle,
|
||||||
|
ATPX_FUNCTION_DISPLAY_MUX_CONTROL,
|
||||||
|
¶ms);
|
||||||
|
if (!info)
|
||||||
|
return -EIO;
|
||||||
|
kfree(info);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_switch_mux(acpi_handle handle, int mux_id)
|
static int radeon_atpx_switch_i2c_mux(struct radeon_atpx *atpx, u16 mux_id)
|
||||||
{
|
{
|
||||||
return radeon_atpx_execute(handle, ATPX_FUNCTION_DISPLAY_MUX_CONTROL, mux_id);
|
struct acpi_buffer params;
|
||||||
|
union acpi_object *info;
|
||||||
|
struct atpx_mux input;
|
||||||
|
|
||||||
|
if (atpx->functions.i2c_mux_cntl) {
|
||||||
|
input.size = 4;
|
||||||
|
input.mux = mux_id;
|
||||||
|
params.length = input.size;
|
||||||
|
params.pointer = &input;
|
||||||
|
info = radeon_atpx_call(atpx->handle,
|
||||||
|
ATPX_FUNCTION_I2C_MUX_CONTROL,
|
||||||
|
¶ms);
|
||||||
|
if (!info)
|
||||||
|
return -EIO;
|
||||||
|
kfree(info);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_switch_i2c_mux(acpi_handle handle, int mux_id)
|
static int radeon_atpx_switch_start(struct radeon_atpx *atpx, u16 mux_id)
|
||||||
{
|
{
|
||||||
return radeon_atpx_execute(handle, ATPX_FUNCTION_I2C_MUX_CONTROL, mux_id);
|
struct acpi_buffer params;
|
||||||
|
union acpi_object *info;
|
||||||
|
struct atpx_mux input;
|
||||||
|
|
||||||
|
if (atpx->functions.switch_start) {
|
||||||
|
input.size = 4;
|
||||||
|
input.mux = mux_id;
|
||||||
|
params.length = input.size;
|
||||||
|
params.pointer = &input;
|
||||||
|
info = radeon_atpx_call(atpx->handle,
|
||||||
|
ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION,
|
||||||
|
¶ms);
|
||||||
|
if (!info)
|
||||||
|
return -EIO;
|
||||||
|
kfree(info);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_switch_start(acpi_handle handle, int gpu_id)
|
static int radeon_atpx_switch_end(struct radeon_atpx *atpx, u16 mux_id)
|
||||||
{
|
{
|
||||||
return radeon_atpx_execute(handle,
|
struct acpi_buffer params;
|
||||||
ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION,
|
union acpi_object *info;
|
||||||
gpu_id);
|
struct atpx_mux input;
|
||||||
}
|
|
||||||
|
|
||||||
static int radeon_atpx_switch_end(acpi_handle handle, int gpu_id)
|
if (atpx->functions.switch_end) {
|
||||||
{
|
input.size = 4;
|
||||||
return radeon_atpx_execute(handle,
|
input.mux = mux_id;
|
||||||
ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION,
|
params.length = input.size;
|
||||||
gpu_id);
|
params.pointer = &input;
|
||||||
|
info = radeon_atpx_call(atpx->handle,
|
||||||
|
ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION,
|
||||||
|
¶ms);
|
||||||
|
if (!info)
|
||||||
|
return -EIO;
|
||||||
|
kfree(info);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_switchto(enum vga_switcheroo_client_id id)
|
static int radeon_atpx_switchto(enum vga_switcheroo_client_id id)
|
||||||
{
|
{
|
||||||
int gpu_id;
|
u16 gpu_id;
|
||||||
|
|
||||||
if (id == VGA_SWITCHEROO_IGD)
|
if (id == VGA_SWITCHEROO_IGD)
|
||||||
gpu_id = ATPX_INTEGRATED_GPU;
|
gpu_id = ATPX_INTEGRATED_GPU;
|
||||||
else
|
else
|
||||||
gpu_id = ATPX_DISCRETE_GPU;
|
gpu_id = ATPX_DISCRETE_GPU;
|
||||||
|
|
||||||
radeon_atpx_switch_start(radeon_atpx_priv.atpx_handle, gpu_id);
|
radeon_atpx_switch_start(&radeon_atpx_priv.atpx, gpu_id);
|
||||||
radeon_atpx_switch_mux(radeon_atpx_priv.atpx_handle, gpu_id);
|
radeon_atpx_switch_disp_mux(&radeon_atpx_priv.atpx, gpu_id);
|
||||||
radeon_atpx_switch_i2c_mux(radeon_atpx_priv.atpx_handle, gpu_id);
|
radeon_atpx_switch_i2c_mux(&radeon_atpx_priv.atpx, gpu_id);
|
||||||
radeon_atpx_switch_end(radeon_atpx_priv.atpx_handle, gpu_id);
|
radeon_atpx_switch_end(&radeon_atpx_priv.atpx, gpu_id);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -244,7 +295,7 @@ static int radeon_atpx_power_state(enum vga_switcheroo_client_id id,
|
||||||
if (id == VGA_SWITCHEROO_IGD)
|
if (id == VGA_SWITCHEROO_IGD)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
radeon_atpx_set_discrete_state(radeon_atpx_priv.atpx_handle, state);
|
radeon_atpx_set_discrete_state(&radeon_atpx_priv.atpx, state);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,15 +313,14 @@ static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
radeon_atpx_priv.dhandle = dhandle;
|
radeon_atpx_priv.dhandle = dhandle;
|
||||||
radeon_atpx_priv.atpx_handle = atpx_handle;
|
radeon_atpx_priv.atpx.handle = atpx_handle;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_init(void)
|
static int radeon_atpx_init(void)
|
||||||
{
|
{
|
||||||
/* set up the ATPX handle */
|
/* set up the ATPX handle */
|
||||||
return radeon_atpx_verify_interface(radeon_atpx_priv.atpx_handle,
|
return radeon_atpx_verify_interface(&radeon_atpx_priv.atpx);
|
||||||
&radeon_atpx_priv.atpx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radeon_atpx_get_client_id(struct pci_dev *pdev)
|
static int radeon_atpx_get_client_id(struct pci_dev *pdev)
|
||||||
|
@ -303,7 +353,7 @@ static bool radeon_atpx_detect(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_atpx && vga_count == 2) {
|
if (has_atpx && vga_count == 2) {
|
||||||
acpi_get_name(radeon_atpx_priv.atpx_handle, ACPI_FULL_PATHNAME, &buffer);
|
acpi_get_name(radeon_atpx_priv.atpx.handle, ACPI_FULL_PATHNAME, &buffer);
|
||||||
printk(KERN_INFO "VGA switcheroo: detected switching method %s handle\n",
|
printk(KERN_INFO "VGA switcheroo: detected switching method %s handle\n",
|
||||||
acpi_method_name);
|
acpi_method_name);
|
||||||
radeon_atpx_priv.atpx_detected = true;
|
radeon_atpx_priv.atpx_detected = true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue