Linux Audio

Check our new training course

Loading...
v3.1
 
  1/*
  2 *  OLPC XO-1.5 ebook switch driver
  3 *  (based on generic ACPI button driver)
  4 *
  5 *  Copyright (C) 2009 Paul Fox <pgf@laptop.org>
  6 *  Copyright (C) 2010 One Laptop per Child
  7 *
  8 *  This program is free software; you can redistribute it and/or modify
  9 *  it under the terms of the GNU General Public License as published by
 10 *  the Free Software Foundation; either version 2 of the License, or (at
 11 *  your option) any later version.
 12 */
 13
 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 15
 16#include <linux/kernel.h>
 17#include <linux/module.h>
 18#include <linux/init.h>
 19#include <linux/types.h>
 20#include <linux/input.h>
 21#include <acpi/acpi_bus.h>
 22#include <acpi/acpi_drivers.h>
 23
 24#define MODULE_NAME "xo15-ebook"
 25
 26#define XO15_EBOOK_CLASS		MODULE_NAME
 27#define XO15_EBOOK_TYPE_UNKNOWN	0x00
 28#define XO15_EBOOK_NOTIFY_STATUS	0x80
 29
 30#define XO15_EBOOK_SUBCLASS		"ebook"
 31#define XO15_EBOOK_HID			"XO15EBK"
 32#define XO15_EBOOK_DEVICE_NAME		"EBook Switch"
 33
 34ACPI_MODULE_NAME(MODULE_NAME);
 35
 36MODULE_DESCRIPTION("OLPC XO-1.5 ebook switch driver");
 37MODULE_LICENSE("GPL");
 38
 39static const struct acpi_device_id ebook_device_ids[] = {
 40	{ XO15_EBOOK_HID, 0 },
 41	{ "", 0 },
 42};
 43MODULE_DEVICE_TABLE(acpi, ebook_device_ids);
 44
 45struct ebook_switch {
 46	struct input_dev *input;
 47	char phys[32];			/* for input device */
 48};
 49
 50static int ebook_send_state(struct acpi_device *device)
 51{
 52	struct ebook_switch *button = acpi_driver_data(device);
 53	unsigned long long state;
 54	acpi_status status;
 55
 56	status = acpi_evaluate_integer(device->handle, "EBK", NULL, &state);
 57	if (ACPI_FAILURE(status))
 58		return -EIO;
 59
 60	/* input layer checks if event is redundant */
 61	input_report_switch(button->input, SW_TABLET_MODE, !state);
 62	input_sync(button->input);
 63	return 0;
 64}
 65
 66static void ebook_switch_notify(struct acpi_device *device, u32 event)
 67{
 68	switch (event) {
 69	case ACPI_FIXED_HARDWARE_EVENT:
 70	case XO15_EBOOK_NOTIFY_STATUS:
 71		ebook_send_state(device);
 72		break;
 73	default:
 74		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
 75				  "Unsupported event [0x%x]\n", event));
 76		break;
 77	}
 78}
 79
 80static int ebook_switch_resume(struct acpi_device *device)
 
 81{
 82	return ebook_send_state(device);
 83}
 
 
 
 84
 85static int ebook_switch_add(struct acpi_device *device)
 86{
 87	struct ebook_switch *button;
 88	struct input_dev *input;
 89	const char *hid = acpi_device_hid(device);
 90	char *name, *class;
 91	int error;
 92
 93	button = kzalloc(sizeof(struct ebook_switch), GFP_KERNEL);
 94	if (!button)
 95		return -ENOMEM;
 96
 97	device->driver_data = button;
 98
 99	button->input = input = input_allocate_device();
100	if (!input) {
101		error = -ENOMEM;
102		goto err_free_button;
103	}
104
105	name = acpi_device_name(device);
106	class = acpi_device_class(device);
107
108	if (strcmp(hid, XO15_EBOOK_HID)) {
109		pr_err("Unsupported hid [%s]\n", hid);
110		error = -ENODEV;
111		goto err_free_input;
112	}
113
114	strcpy(name, XO15_EBOOK_DEVICE_NAME);
115	sprintf(class, "%s/%s", XO15_EBOOK_CLASS, XO15_EBOOK_SUBCLASS);
116
117	snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
118
119	input->name = name;
120	input->phys = button->phys;
121	input->id.bustype = BUS_HOST;
122	input->dev.parent = &device->dev;
123
124	input->evbit[0] = BIT_MASK(EV_SW);
125	set_bit(SW_TABLET_MODE, input->swbit);
126
127	error = input_register_device(input);
128	if (error)
129		goto err_free_input;
130
131	ebook_send_state(device);
132
133	if (device->wakeup.flags.valid) {
134		/* Button's GPE is run-wake GPE */
135		acpi_enable_gpe(device->wakeup.gpe_device,
136				device->wakeup.gpe_number);
137		device_set_wakeup_enable(&device->dev, true);
138	}
139
140	return 0;
141
142 err_free_input:
143	input_free_device(input);
144 err_free_button:
145	kfree(button);
146	return error;
147}
148
149static int ebook_switch_remove(struct acpi_device *device, int type)
150{
151	struct ebook_switch *button = acpi_driver_data(device);
152
153	input_unregister_device(button->input);
154	kfree(button);
155	return 0;
156}
157
158static struct acpi_driver xo15_ebook_driver = {
159	.name = MODULE_NAME,
160	.class = XO15_EBOOK_CLASS,
161	.ids = ebook_device_ids,
162	.ops = {
163		.add = ebook_switch_add,
164		.resume = ebook_switch_resume,
165		.remove = ebook_switch_remove,
166		.notify = ebook_switch_notify,
167	},
 
168};
169
170static int __init xo15_ebook_init(void)
171{
172	return acpi_bus_register_driver(&xo15_ebook_driver);
173}
174
175static void __exit xo15_ebook_exit(void)
176{
177	acpi_bus_unregister_driver(&xo15_ebook_driver);
178}
179
180module_init(xo15_ebook_init);
181module_exit(xo15_ebook_exit);
v6.2
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  OLPC XO-1.5 ebook switch driver
  4 *  (based on generic ACPI button driver)
  5 *
  6 *  Copyright (C) 2009 Paul Fox <pgf@laptop.org>
  7 *  Copyright (C) 2010 One Laptop per Child
 
 
 
 
 
  8 */
  9
 10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 11
 12#include <linux/kernel.h>
 13#include <linux/module.h>
 14#include <linux/init.h>
 15#include <linux/types.h>
 16#include <linux/input.h>
 17#include <linux/acpi.h>
 
 18
 19#define MODULE_NAME "xo15-ebook"
 20
 21#define XO15_EBOOK_CLASS		MODULE_NAME
 22#define XO15_EBOOK_TYPE_UNKNOWN	0x00
 23#define XO15_EBOOK_NOTIFY_STATUS	0x80
 24
 25#define XO15_EBOOK_SUBCLASS		"ebook"
 26#define XO15_EBOOK_HID			"XO15EBK"
 27#define XO15_EBOOK_DEVICE_NAME		"EBook Switch"
 28
 
 
 29MODULE_DESCRIPTION("OLPC XO-1.5 ebook switch driver");
 30MODULE_LICENSE("GPL");
 31
 32static const struct acpi_device_id ebook_device_ids[] = {
 33	{ XO15_EBOOK_HID, 0 },
 34	{ "", 0 },
 35};
 36MODULE_DEVICE_TABLE(acpi, ebook_device_ids);
 37
 38struct ebook_switch {
 39	struct input_dev *input;
 40	char phys[32];			/* for input device */
 41};
 42
 43static int ebook_send_state(struct acpi_device *device)
 44{
 45	struct ebook_switch *button = acpi_driver_data(device);
 46	unsigned long long state;
 47	acpi_status status;
 48
 49	status = acpi_evaluate_integer(device->handle, "EBK", NULL, &state);
 50	if (ACPI_FAILURE(status))
 51		return -EIO;
 52
 53	/* input layer checks if event is redundant */
 54	input_report_switch(button->input, SW_TABLET_MODE, !state);
 55	input_sync(button->input);
 56	return 0;
 57}
 58
 59static void ebook_switch_notify(struct acpi_device *device, u32 event)
 60{
 61	switch (event) {
 62	case ACPI_FIXED_HARDWARE_EVENT:
 63	case XO15_EBOOK_NOTIFY_STATUS:
 64		ebook_send_state(device);
 65		break;
 66	default:
 67		acpi_handle_debug(device->handle,
 68				  "Unsupported event [0x%x]\n", event);
 69		break;
 70	}
 71}
 72
 73#ifdef CONFIG_PM_SLEEP
 74static int ebook_switch_resume(struct device *dev)
 75{
 76	return ebook_send_state(to_acpi_device(dev));
 77}
 78#endif
 79
 80static SIMPLE_DEV_PM_OPS(ebook_switch_pm, NULL, ebook_switch_resume);
 81
 82static int ebook_switch_add(struct acpi_device *device)
 83{
 84	struct ebook_switch *button;
 85	struct input_dev *input;
 86	const char *hid = acpi_device_hid(device);
 87	char *name, *class;
 88	int error;
 89
 90	button = kzalloc(sizeof(struct ebook_switch), GFP_KERNEL);
 91	if (!button)
 92		return -ENOMEM;
 93
 94	device->driver_data = button;
 95
 96	button->input = input = input_allocate_device();
 97	if (!input) {
 98		error = -ENOMEM;
 99		goto err_free_button;
100	}
101
102	name = acpi_device_name(device);
103	class = acpi_device_class(device);
104
105	if (strcmp(hid, XO15_EBOOK_HID)) {
106		pr_err("Unsupported hid [%s]\n", hid);
107		error = -ENODEV;
108		goto err_free_input;
109	}
110
111	strcpy(name, XO15_EBOOK_DEVICE_NAME);
112	sprintf(class, "%s/%s", XO15_EBOOK_CLASS, XO15_EBOOK_SUBCLASS);
113
114	snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
115
116	input->name = name;
117	input->phys = button->phys;
118	input->id.bustype = BUS_HOST;
119	input->dev.parent = &device->dev;
120
121	input->evbit[0] = BIT_MASK(EV_SW);
122	set_bit(SW_TABLET_MODE, input->swbit);
123
124	error = input_register_device(input);
125	if (error)
126		goto err_free_input;
127
128	ebook_send_state(device);
129
130	if (device->wakeup.flags.valid) {
131		/* Button's GPE is run-wake GPE */
132		acpi_enable_gpe(device->wakeup.gpe_device,
133				device->wakeup.gpe_number);
134		device_set_wakeup_enable(&device->dev, true);
135	}
136
137	return 0;
138
139 err_free_input:
140	input_free_device(input);
141 err_free_button:
142	kfree(button);
143	return error;
144}
145
146static void ebook_switch_remove(struct acpi_device *device)
147{
148	struct ebook_switch *button = acpi_driver_data(device);
149
150	input_unregister_device(button->input);
151	kfree(button);
 
152}
153
154static struct acpi_driver xo15_ebook_driver = {
155	.name = MODULE_NAME,
156	.class = XO15_EBOOK_CLASS,
157	.ids = ebook_device_ids,
158	.ops = {
159		.add = ebook_switch_add,
 
160		.remove = ebook_switch_remove,
161		.notify = ebook_switch_notify,
162	},
163	.drv.pm = &ebook_switch_pm,
164};
165module_acpi_driver(xo15_ebook_driver);