// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/acpi.h>
#include <linux/backlight.h>
#include <linux/input.h>
#include <linux/rfkill.h>
MODULE_LICENSE("GPL");
struct cmpc_accel {
int sensitivity;
int g_select;
int inputdev_state;
};
#define CMPC_ACCEL_DEV_STATE_CLOSED 0
#define CMPC_ACCEL_DEV_STATE_OPEN 1
#define CMPC_ACCEL_SENSITIVITY_DEFAULT 5
#define CMPC_ACCEL_G_SELECT_DEFAULT 0
#define CMPC_ACCEL_HID "ACCE0000"
#define CMPC_ACCEL_HID_V4 "ACCE0001"
#define CMPC_TABLET_HID "TBLT0000"
#define CMPC_IPML_HID "IPML200"
#define CMPC_KEYS_HID "FNBT0000"
/*
* Generic input device code.
*/
typedef void (*input_device_init)(struct input_dev *dev);
static int cmpc_add_acpi_notify_device(struct acpi_device *acpi, char *name,
input_device_init idev_init)
{
struct input_dev *inputdev;
int error;
inputdev = input_allocate_device();
if (!inputdev)
return -ENOMEM;
inputdev->name = name;
inputdev->dev.parent = &acpi->dev;
idev_init(inputdev);
error = input_register_device(inputdev);
if (error) {
input_free_device(inputdev);
return error;
}
dev_set_drvdata(&acpi->dev, inputdev);
return 0;
}
static int cmpc_remove_acpi_notify_device(struct acpi_device *acpi)
{
struct input_dev *inputdev = dev_get_drvdata(&acpi->dev);
input_unregister_device(inputdev);
return 0;
}
/*
* Accelerometer code for Classmate V4
*/
static acpi_status cmpc_start_accel_v4(acpi_handle handle)
{
union acpi_object param[4];
struct acpi_object_list input;
acpi_status status;
param[0].type = ACPI_TYPE_INTEGER;
param[0].integer.value = 0x3;
param[1].type = ACPI_TYPE_INTEGER;
param[1].integer.value = 0;
param[2].type = ACPI_TYPE_INTEGER;
param[2].integer.value = 0;
param[3].type = ACPI_TYPE_INTEGER;
param[3].integer.value = 0;
input.count = 4;
input.pointer = param;
status = acpi_evaluate_object(handle, "ACMD", &input, NULL);
return status;
}
static acpi_status cmpc_stop_accel_v4(acpi_handle handle)
{
union acpi_object param[4];
struct acpi_object_list input;
acpi_status status;
param[0].type = ACPI_TYPE_INTEGER;
param[0].integer.value = 0x4;
param[1].type = ACPI_TYPE_INTEGER;
param[1].integer.value = 0;
param[2].type = ACPI_TYPE_INTEGER;
param[2].integer.value = 0;
param[3].type = ACPI_TYPE_INTEGER;
param[3].integer.value = 0;
input.count = 4;
input.pointer = param;
status = acpi_evaluate_object(handle, "ACMD", &input, NULL);
return status;
}
static acpi_status cmpc_accel_set_sensitivity_v4(acpi_handle handle, int val)
{
union acpi_object param[4];
struct acpi_object_list input;
param[0].type = ACPI_TYPE_INTEGER;
param[0