| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  acpi_ec.c - ACPI Embedded Controller Driver ($Revision: 38 $) | 
 | 3 |  * | 
 | 4 |  *  Copyright (C) 2004 Luming Yu <luming.yu@intel.com> | 
 | 5 |  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | 
 | 6 |  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | 
 | 7 |  * | 
 | 8 |  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
 | 9 |  * | 
 | 10 |  *  This program is free software; you can redistribute it and/or modify | 
 | 11 |  *  it under the terms of the GNU General Public License as published by | 
 | 12 |  *  the Free Software Foundation; either version 2 of the License, or (at | 
 | 13 |  *  your option) any later version. | 
 | 14 |  * | 
 | 15 |  *  This program is distributed in the hope that it will be useful, but | 
 | 16 |  *  WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 17 |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
 | 18 |  *  General Public License for more details. | 
 | 19 |  * | 
 | 20 |  *  You should have received a copy of the GNU General Public License along | 
 | 21 |  *  with this program; if not, write to the Free Software Foundation, Inc., | 
 | 22 |  *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | 
 | 23 |  * | 
 | 24 |  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
 | 25 |  */ | 
 | 26 |  | 
 | 27 | #include <linux/kernel.h> | 
 | 28 | #include <linux/module.h> | 
 | 29 | #include <linux/init.h> | 
 | 30 | #include <linux/types.h> | 
 | 31 | #include <linux/delay.h> | 
 | 32 | #include <linux/proc_fs.h> | 
 | 33 | #include <linux/seq_file.h> | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 34 | #include <linux/interrupt.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <asm/io.h> | 
 | 36 | #include <acpi/acpi_bus.h> | 
 | 37 | #include <acpi/acpi_drivers.h> | 
 | 38 | #include <acpi/actypes.h> | 
 | 39 |  | 
 | 40 | #define _COMPONENT		ACPI_EC_COMPONENT | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 41 | ACPI_MODULE_NAME("acpi_ec") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #define ACPI_EC_COMPONENT		0x00100000 | 
 | 43 | #define ACPI_EC_CLASS			"embedded_controller" | 
 | 44 | #define ACPI_EC_HID			"PNP0C09" | 
 | 45 | #define ACPI_EC_DRIVER_NAME		"ACPI Embedded Controller Driver" | 
 | 46 | #define ACPI_EC_DEVICE_NAME		"Embedded Controller" | 
 | 47 | #define ACPI_EC_FILE_INFO		"info" | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 48 |  | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 49 | #undef PREFIX | 
 | 50 | #define PREFIX				"ACPI: EC: " | 
 | 51 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 52 | /* EC status register */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define ACPI_EC_FLAG_OBF	0x01	/* Output buffer full */ | 
 | 54 | #define ACPI_EC_FLAG_IBF	0x02	/* Input buffer full */ | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 55 | #define ACPI_EC_FLAG_BURST	0x10	/* burst mode */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define ACPI_EC_FLAG_SCI	0x20	/* EC-SCI occurred */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 57 |  | 
 | 58 | /* EC commands */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #define ACPI_EC_COMMAND_READ	0x80 | 
 | 60 | #define ACPI_EC_COMMAND_WRITE	0x81 | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 61 | #define ACPI_EC_BURST_ENABLE	0x82 | 
 | 62 | #define ACPI_EC_BURST_DISABLE	0x83 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define ACPI_EC_COMMAND_QUERY	0x84 | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 64 |  | 
 | 65 | /* EC events */ | 
 | 66 | enum { | 
 | 67 | 	ACPI_EC_EVENT_OBF_1 = 1,	/* Output buffer full */ | 
 | 68 | 	ACPI_EC_EVENT_IBF_0,		/* Input buffer empty */ | 
 | 69 | }; | 
 | 70 |  | 
| Alexey Starikovskiy | 5c40641 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 71 | #define ACPI_EC_DELAY		500	/* Wait 500ms max. during EC ops */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 72 | #define ACPI_EC_UDELAY_GLK	1000	/* Wait 1ms max. to get global lock */ | 
 | 73 | #define ACPI_EC_UDELAY         100	/* Poll @ 100us increments */ | 
| Alexey Starikovskiy | 5c40641 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 74 | #define ACPI_EC_UDELAY_COUNT   1000	/* Wait 100ms max. during EC ops */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 75 |  | 
 | 76 | enum { | 
 | 77 | 	EC_INTR = 1,	/* Output buffer full */ | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 78 | 	EC_POLL,	/* Input buffer empty */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 79 | }; | 
 | 80 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 81 | static int acpi_ec_remove(struct acpi_device *device, int type); | 
 | 82 | static int acpi_ec_start(struct acpi_device *device); | 
 | 83 | static int acpi_ec_stop(struct acpi_device *device, int type); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 84 | static int acpi_ec_add(struct acpi_device *device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 |  | 
 | 86 | static struct acpi_driver acpi_ec_driver = { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 87 | 	.name = ACPI_EC_DRIVER_NAME, | 
 | 88 | 	.class = ACPI_EC_CLASS, | 
 | 89 | 	.ids = ACPI_EC_HID, | 
 | 90 | 	.ops = { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 91 | 		.add = acpi_ec_add, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 92 | 		.remove = acpi_ec_remove, | 
 | 93 | 		.start = acpi_ec_start, | 
 | 94 | 		.stop = acpi_ec_stop, | 
 | 95 | 		}, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | }; | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 97 |  | 
 | 98 | /* If we find an EC via the ECDT, we need to keep a ptr to its context */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 99 | struct acpi_ec { | 
 | 100 | 	acpi_handle handle; | 
 | 101 | 	unsigned long uid; | 
 | 102 | 	unsigned long gpe_bit; | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 103 | 	unsigned long command_addr; | 
 | 104 | 	unsigned long data_addr; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 105 | 	unsigned long global_lock; | 
| Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame^] | 106 | 	struct mutex lock; | 
| Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 107 | 	atomic_t query_pending; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 108 | 	atomic_t leaving_burst;	/* 0 : No, 1 : Yes, 2: abort */ | 
 | 109 | 	wait_queue_head_t wait; | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 110 | } *ec_ecdt; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 111 |  | 
 | 112 | /* External interfaces use first EC only, so remember */ | 
 | 113 | static struct acpi_device *first_ec; | 
 | 114 | static int acpi_ec_mode = EC_INTR; | 
 | 115 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | /* -------------------------------------------------------------------------- | 
 | 117 |                              Transaction Management | 
 | 118 |    -------------------------------------------------------------------------- */ | 
 | 119 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 120 | static inline u8 acpi_ec_read_status(struct acpi_ec *ec) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 122 | 	return inb(ec->command_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } | 
 | 124 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 125 | static inline u8 acpi_ec_read_data(struct acpi_ec *ec) | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 126 | { | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 127 | 	return inb(ec->data_addr); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 128 | } | 
 | 129 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 130 | static inline void acpi_ec_write_cmd(struct acpi_ec *ec, u8 command) | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 131 | { | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 132 | 	outb(command, ec->command_addr); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 133 | } | 
 | 134 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 135 | static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 136 | { | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 137 | 	outb(data, ec->data_addr); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 138 | } | 
 | 139 |  | 
| Alexey Starikovskiy | bec5a1e | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 140 | static int acpi_ec_check_status(struct acpi_ec *ec, u8 event) | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 141 | { | 
| Alexey Starikovskiy | bec5a1e | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 142 | 	u8 status = acpi_ec_read_status(ec); | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 143 | 	switch (event) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 144 | 	case ACPI_EC_EVENT_OBF_1: | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 145 | 		if (status & ACPI_EC_FLAG_OBF) | 
 | 146 | 			return 1; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 147 | 		break; | 
 | 148 | 	case ACPI_EC_EVENT_IBF_0: | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 149 | 		if (!(status & ACPI_EC_FLAG_IBF)) | 
 | 150 | 			return 1; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 151 | 		break; | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 152 | 	default: | 
 | 153 | 		break; | 
 | 154 | 	} | 
 | 155 |  | 
 | 156 | 	return 0; | 
 | 157 | } | 
 | 158 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 159 | static int acpi_ec_wait(struct acpi_ec *ec, u8 event) | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 160 | { | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 161 | 	if (acpi_ec_mode == EC_POLL) { | 
 | 162 | 		int i; | 
 | 163 | 		for (i = 0; i < ACPI_EC_UDELAY_COUNT; ++i) { | 
 | 164 | 			if (acpi_ec_check_status(ec, event)) | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 165 | 				return 0; | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 166 | 			udelay(ACPI_EC_UDELAY); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 167 | 		} | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 168 | 	} else { | 
 | 169 | 		if (wait_event_timeout(ec->wait, | 
 | 170 | 				       acpi_ec_check_status(ec, event), | 
 | 171 | 				       msecs_to_jiffies(ACPI_EC_DELAY)) || | 
 | 172 | 		    acpi_ec_check_status(ec, event)) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 173 | 			return 0; | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 174 | 		} else { | 
 | 175 | 			printk(KERN_ERR PREFIX "acpi_ec_wait timeout," | 
 | 176 | 			       " status = %d, expect_event = %d\n", | 
 | 177 | 			     acpi_ec_read_status(ec), event); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 178 | 		} | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 179 | 	} | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 180 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 181 | 	return -ETIME; | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 182 | } | 
 | 183 |  | 
| Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 184 | #ifdef ACPI_FUTURE_USAGE | 
| Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 185 | /* | 
 | 186 |  * Note: samsung nv5000 doesn't work with ec burst mode. | 
 | 187 |  * http://bugzilla.kernel.org/show_bug.cgi?id=4980 | 
 | 188 |  */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 189 | int acpi_ec_enter_burst_mode(struct acpi_ec *ec) | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 190 | { | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 191 | 	u8 tmp = 0; | 
 | 192 | 	u8 status = 0; | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 193 |  | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 194 |  | 
 | 195 | 	status = acpi_ec_read_status(ec); | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 196 | 	if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 197 | 		status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 198 | 		if (status) | 
| Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 199 | 			goto end; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 200 | 		acpi_ec_write_cmd(ec, ACPI_EC_BURST_ENABLE); | 
 | 201 | 		status = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); | 
 | 202 | 		tmp = acpi_ec_read_data(ec); | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 203 | 		if (tmp != 0x90) {	/* Burst ACK byte */ | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 204 | 			return -EINVAL; | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 205 | 		} | 
| Luming Yu | 668d74c | 2005-07-23 00:26:33 -0400 | [diff] [blame] | 206 | 	} | 
 | 207 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 208 | 	atomic_set(&ec->leaving_burst, 0); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 209 | 	return 0; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 210 |   end: | 
 | 211 | 	ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 212 | 	return -1; | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 213 | } | 
 | 214 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 215 | int acpi_ec_leave_burst_mode(struct acpi_ec *ec) | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 216 | { | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 217 | 	u8 status = 0; | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 218 |  | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 219 |  | 
| Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 220 | 	status = acpi_ec_read_status(ec); | 
 | 221 | 	if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 222 | 		status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | 
| Luming Yu | 06a2a38 | 2005-09-27 00:43:00 -0400 | [diff] [blame] | 223 | 		if(status) | 
 | 224 | 			goto end; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 225 | 		acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE); | 
 | 226 | 		acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 227 | 	} | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 228 | 	atomic_set(&ec->leaving_burst, 1); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 229 | 	return 0; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 230 |   end: | 
 | 231 | 	ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 232 | 	return -1; | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 233 | } | 
| Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 234 | #endif /* ACPI_FUTURE_USAGE */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 236 | static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 237 | 					const u8 *wdata, unsigned wdata_len, | 
 | 238 | 					u8 *rdata, unsigned rdata_len) | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 239 | { | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 240 | 	int result = 0; | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 241 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 242 | 	acpi_ec_write_cmd(ec, command); | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 243 |  | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 244 | 	for (; wdata_len > 0; wdata_len --) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 245 | 		result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 246 | 		if (result) { | 
 | 247 | 			printk(KERN_ERR PREFIX "write_cmd timeout, command = %d\n", | 
 | 248 | 			     command); | 
 | 249 | 			goto end; | 
 | 250 | 		} | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 251 | 		acpi_ec_write_data(ec, *(wdata++)); | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 252 | 	} | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 253 |  | 
| Alexey Starikovskiy | d91df1a | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 254 | 	if (!rdata_len) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 255 | 		result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 256 | 		if (result) { | 
 | 257 | 			printk(KERN_ERR PREFIX "finish-write timeout, command = %d\n", | 
 | 258 | 			     command); | 
 | 259 | 			goto end; | 
 | 260 | 		} | 
| Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 261 | 	} else if (command == ACPI_EC_COMMAND_QUERY) { | 
 | 262 | 		atomic_set(&ec->query_pending, 0); | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 263 | 	} | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 264 |  | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 265 | 	for (; rdata_len > 0; rdata_len --) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 266 | 		result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 267 | 		if (result) { | 
 | 268 | 			printk(KERN_ERR PREFIX "read timeout, command = %d\n", | 
 | 269 | 			     command); | 
 | 270 | 			goto end; | 
 | 271 | 		} | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 272 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 273 | 		*(rdata++) = acpi_ec_read_data(ec); | 
| Denis M. Sadykov | 7c6db5e | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 274 | 	} | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 275 |       end: | 
 | 276 | 	return result; | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 277 | } | 
 | 278 |  | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 279 | static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, | 
 | 280 | 				const u8 *wdata, unsigned wdata_len, | 
 | 281 | 				u8 *rdata, unsigned rdata_len) | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 282 | { | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 283 | 	int status; | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 284 | 	u32 glk; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 286 | 	if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 287 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 289 |         if (rdata) | 
 | 290 |                 memset(rdata, 0, rdata_len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 292 | 	if (ec->global_lock) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | 		status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); | 
 | 294 | 		if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 295 | 			return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | 	} | 
| Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame^] | 297 | 	mutex_lock(&ec->lock); | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 298 |  | 
| Alexey Starikovskiy | 5d57a6a | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 299 | 	/* Make sure GPE is enabled before doing transaction */ | 
 | 300 | 	acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 
 | 301 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 302 | 	status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); | 
| Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 303 | 	if (status) { | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 304 | 		printk(KERN_DEBUG PREFIX "read EC, IB not empty\n"); | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 305 | 		goto end; | 
| Luming Yu | 716e084 | 2005-08-10 01:40:00 -0400 | [diff] [blame] | 306 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 308 |         status = acpi_ec_transaction_unlocked(ec, command, | 
 | 309 |                                               wdata, wdata_len, | 
 | 310 |                                               rdata, rdata_len); | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 311 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 312 | end: | 
| Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame^] | 313 | 	mutex_unlock(&ec->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 315 | 	if (ec->global_lock) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | 		acpi_release_global_lock(glk); | 
 | 317 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 318 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } | 
 | 320 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 321 | static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data) | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 322 | { | 
 | 323 | 	int result; | 
 | 324 | 	u8 d; | 
 | 325 |  | 
 | 326 | 	result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ, | 
 | 327 | 				     &address, 1, &d, 1); | 
 | 328 | 	*data = d; | 
 | 329 | 	return result; | 
 | 330 | } | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 331 |  | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 332 | static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) | 
 | 333 | { | 
 | 334 |         u8 wdata[2] = { address, data }; | 
 | 335 |         return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, | 
 | 336 | 				   wdata, 2, NULL, 0); | 
 | 337 | } | 
 | 338 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* | 
 | 340 |  * Externally callable EC access functions. For now, assume 1 EC only | 
 | 341 |  */ | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 342 | int ec_read(u8 addr, u8 *val) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 344 | 	struct acpi_ec *ec; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | 	int err; | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 346 | 	u8 temp_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 |  | 
 | 348 | 	if (!first_ec) | 
 | 349 | 		return -ENODEV; | 
 | 350 |  | 
 | 351 | 	ec = acpi_driver_data(first_ec); | 
 | 352 |  | 
 | 353 | 	err = acpi_ec_read(ec, addr, &temp_data); | 
 | 354 |  | 
 | 355 | 	if (!err) { | 
 | 356 | 		*val = temp_data; | 
 | 357 | 		return 0; | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 358 | 	} else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | 		return err; | 
 | 360 | } | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 361 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | EXPORT_SYMBOL(ec_read); | 
 | 363 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 364 | int ec_write(u8 addr, u8 val) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 366 | 	struct acpi_ec *ec; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | 	int err; | 
 | 368 |  | 
 | 369 | 	if (!first_ec) | 
 | 370 | 		return -ENODEV; | 
 | 371 |  | 
 | 372 | 	ec = acpi_driver_data(first_ec); | 
 | 373 |  | 
 | 374 | 	err = acpi_ec_write(ec, addr, val); | 
 | 375 |  | 
 | 376 | 	return err; | 
 | 377 | } | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 378 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | EXPORT_SYMBOL(ec_write); | 
 | 380 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 381 | extern int ec_transaction(u8 command, | 
 | 382 |                           const u8 *wdata, unsigned wdata_len, | 
 | 383 |                           u8 *rdata, unsigned rdata_len) | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 384 | { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 385 | 	struct acpi_ec *ec; | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 386 |  | 
 | 387 | 	if (!first_ec) | 
 | 388 | 		return -ENODEV; | 
 | 389 |  | 
 | 390 | 	ec = acpi_driver_data(first_ec); | 
 | 391 |  | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 392 | 	return acpi_ec_transaction(ec, command, wdata, | 
 | 393 | 				   wdata_len, rdata, rdata_len); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 394 | } | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 395 |  | 
| Lennart Poettering | ab9e43c | 2006-10-03 22:49:00 -0400 | [diff] [blame] | 396 | EXPORT_SYMBOL(ec_transaction); | 
 | 397 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 398 | static int acpi_ec_query(struct acpi_ec *ec, u8 *data) | 
| Denis M. Sadykov | 3576cf6 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 399 | { | 
 | 400 | 	int result; | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 401 |         u8 d; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 402 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 403 |         if (!ec || !data) | 
 | 404 |                 return -EINVAL; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 405 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 406 |         /* | 
 | 407 |          * Query the EC to find out which _Qxx method we need to evaluate. | 
 | 408 |          * Note that successful completion of the query causes the ACPI_EC_SCI | 
 | 409 |          * bit to be cleared (and thus clearing the interrupt source). | 
 | 410 |          */ | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 411 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 412 |         result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1); | 
 | 413 |         if (result) | 
 | 414 |                 return result; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 415 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 416 |         if (!d) | 
 | 417 |                 return -ENODATA; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 418 |  | 
| Lennart Poettering | d7a76e4 | 2006-09-05 12:12:24 -0400 | [diff] [blame] | 419 |         *data = d; | 
 | 420 |         return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } | 
 | 422 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /* -------------------------------------------------------------------------- | 
 | 424 |                                 Event Management | 
 | 425 |    -------------------------------------------------------------------------- */ | 
 | 426 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 427 | static void acpi_ec_gpe_query(void *ec_cxt) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 429 | 	struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 430 | 	u8 value = 0; | 
| Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 431 | 	char object_name[8]; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 432 |  | 
| Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 433 | 	if (!ec || acpi_ec_query(ec, &value)) | 
| Alexey Starikovskiy | e41334c | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 434 | 		return; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 435 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 436 | 	snprintf(object_name, 8, "_Q%2.2X", value); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 437 |  | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 438 | 	printk(KERN_INFO PREFIX "evaluating %s\n", object_name); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 439 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 440 | 	acpi_evaluate_object(ec->handle, object_name, NULL, NULL); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 441 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 443 | static u32 acpi_ec_gpe_handler(void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 445 | 	acpi_status status = AE_OK; | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 446 | 	u8 value; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 447 | 	struct acpi_ec *ec = (struct acpi_ec *)data; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 448 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 |  | 
| Denis M. Sadykov | 8e0341b | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 450 | 	if (acpi_ec_mode == EC_INTR) { | 
| Alexey Starikovskiy | af3fd14 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 451 | 		wake_up(&ec->wait); | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 452 | 	} | 
 | 453 |  | 
| Alexey Starikovskiy | bec5a1e | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 454 | 	value = acpi_ec_read_status(ec); | 
| Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 455 | 	if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) { | 
 | 456 | 		atomic_set(&ec->query_pending, 1); | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 457 | 		status = acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec); | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 458 | 	} | 
| Alexey Starikovskiy | e41334c | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 459 |  | 
| Dmitry Torokhov | 451566f | 2005-03-19 01:10:05 -0500 | [diff] [blame] | 460 | 	return status == AE_OK ? | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 461 | 	    ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } | 
 | 463 |  | 
 | 464 | /* -------------------------------------------------------------------------- | 
 | 465 |                              Address Space Management | 
 | 466 |    -------------------------------------------------------------------------- */ | 
 | 467 |  | 
 | 468 | static acpi_status | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 469 | acpi_ec_space_setup(acpi_handle region_handle, | 
 | 470 | 		    u32 function, void *handler_context, void **return_context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { | 
 | 472 | 	/* | 
 | 473 | 	 * The EC object is in the handler context and is needed | 
 | 474 | 	 * when calling the acpi_ec_space_handler. | 
 | 475 | 	 */ | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 476 | 	*return_context = (function != ACPI_REGION_DEACTIVATE) ? | 
 | 477 | 	    handler_context : NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 |  | 
 | 479 | 	return AE_OK; | 
 | 480 | } | 
 | 481 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | static acpi_status | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 483 | acpi_ec_space_handler(u32 function, | 
 | 484 | 		      acpi_physical_address address, | 
 | 485 | 		      u32 bit_width, | 
 | 486 | 		      acpi_integer * value, | 
 | 487 | 		      void *handler_context, void *region_context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 489 | 	int result = 0; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 490 | 	struct acpi_ec *ec = NULL; | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 491 | 	u64 temp = *value; | 
 | 492 | 	acpi_integer f_v = 0; | 
 | 493 | 	int i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 |  | 
 | 496 | 	if ((address > 0xFF) || !value || !handler_context) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 497 | 		return AE_BAD_PARAMETER; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 |  | 
| Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 499 | 	if (bit_width != 8 && acpi_strict) { | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 500 | 		return AE_BAD_PARAMETER; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | 	} | 
 | 502 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 503 | 	ec = (struct acpi_ec *)handler_context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 505 |       next_byte: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | 	switch (function) { | 
 | 507 | 	case ACPI_READ: | 
| Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 508 | 		temp = 0; | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 509 | 		result = acpi_ec_read(ec, (u8) address, (u8 *) &temp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | 		break; | 
 | 511 | 	case ACPI_WRITE: | 
| Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 512 | 		result = acpi_ec_write(ec, (u8) address, (u8) temp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | 		break; | 
 | 514 | 	default: | 
 | 515 | 		result = -EINVAL; | 
 | 516 | 		goto out; | 
 | 517 | 		break; | 
 | 518 | 	} | 
 | 519 |  | 
 | 520 | 	bit_width -= 8; | 
| Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 521 | 	if (bit_width) { | 
 | 522 | 		if (function == ACPI_READ) | 
 | 523 | 			f_v |= temp << 8 * i; | 
 | 524 | 		if (function == ACPI_WRITE) | 
 | 525 | 			temp >>= 8; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | 		i++; | 
| Andrew Morton | 83ea744 | 2005-03-30 22:12:13 -0500 | [diff] [blame] | 527 | 		address++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | 		goto next_byte; | 
 | 529 | 	} | 
 | 530 |  | 
| Luming Yu | fa9cd54 | 2005-03-19 01:54:47 -0500 | [diff] [blame] | 531 | 	if (function == ACPI_READ) { | 
 | 532 | 		f_v |= temp << 8 * i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | 		*value = f_v; | 
 | 534 | 	} | 
 | 535 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 536 |       out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | 	switch (result) { | 
 | 538 | 	case -EINVAL: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 539 | 		return AE_BAD_PARAMETER; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | 		break; | 
 | 541 | 	case -ENODEV: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 542 | 		return AE_NOT_FOUND; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | 		break; | 
 | 544 | 	case -ETIME: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 545 | 		return AE_TIME; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | 		break; | 
 | 547 | 	default: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 548 | 		return AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } | 
 | 551 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | /* -------------------------------------------------------------------------- | 
 | 553 |                               FS Interface (/proc) | 
 | 554 |    -------------------------------------------------------------------------- */ | 
 | 555 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 556 | static struct proc_dir_entry *acpi_ec_dir; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 558 | static int acpi_ec_read_info(struct seq_file *seq, void *offset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 560 | 	struct acpi_ec *ec = (struct acpi_ec *)seq->private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 |  | 
 | 563 | 	if (!ec) | 
 | 564 | 		goto end; | 
 | 565 |  | 
 | 566 | 	seq_printf(seq, "gpe bit:                 0x%02x\n", | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 567 | 		   (u32) ec->gpe_bit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | 	seq_printf(seq, "ports:                   0x%02x, 0x%02x\n", | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 569 | 		   (u32) ec->command_addr, | 
 | 570 | 		   (u32) ec->data_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | 	seq_printf(seq, "use global lock:         %s\n", | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 572 | 		   ec->global_lock ? "yes" : "no"); | 
 | 573 | 	acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 575 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 576 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } | 
 | 578 |  | 
 | 579 | static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) | 
 | 580 | { | 
 | 581 | 	return single_open(file, acpi_ec_read_info, PDE(inode)->data); | 
 | 582 | } | 
 | 583 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 584 | static struct file_operations acpi_ec_info_ops = { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 585 | 	.open = acpi_ec_info_open_fs, | 
 | 586 | 	.read = seq_read, | 
 | 587 | 	.llseek = seq_lseek, | 
 | 588 | 	.release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | 	.owner = THIS_MODULE, | 
 | 590 | }; | 
 | 591 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 592 | static int acpi_ec_add_fs(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 594 | 	struct proc_dir_entry *entry = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 |  | 
 | 597 | 	if (!acpi_device_dir(device)) { | 
 | 598 | 		acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 599 | 						     acpi_ec_dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | 		if (!acpi_device_dir(device)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 601 | 			return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | 	} | 
 | 603 |  | 
 | 604 | 	entry = create_proc_entry(ACPI_EC_FILE_INFO, S_IRUGO, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 605 | 				  acpi_device_dir(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | 	if (!entry) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 607 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | 	else { | 
 | 609 | 		entry->proc_fops = &acpi_ec_info_ops; | 
 | 610 | 		entry->data = acpi_driver_data(device); | 
 | 611 | 		entry->owner = THIS_MODULE; | 
 | 612 | 	} | 
 | 613 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 614 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } | 
 | 616 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 617 | static int acpi_ec_remove_fs(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 |  | 
 | 620 | 	if (acpi_device_dir(device)) { | 
 | 621 | 		remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); | 
 | 622 | 		remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); | 
 | 623 | 		acpi_device_dir(device) = NULL; | 
 | 624 | 	} | 
 | 625 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 626 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } | 
 | 628 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | /* -------------------------------------------------------------------------- | 
 | 630 |                                Driver Interface | 
 | 631 |    -------------------------------------------------------------------------- */ | 
 | 632 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 633 | static int acpi_ec_add(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 635 | 	int result = 0; | 
 | 636 | 	acpi_status status = AE_OK; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 637 | 	struct acpi_ec *ec = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 |  | 
 | 640 | 	if (!device) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 641 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 643 | 	ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | 	if (!ec) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 645 | 		return -ENOMEM; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 646 | 	memset(ec, 0, sizeof(struct acpi_ec)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 648 | 	ec->handle = device->handle; | 
 | 649 | 	ec->uid = -1; | 
| Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame^] | 650 | 	mutex_init(&ec->lock); | 
| Alexey Starikovskiy | 5d0c288 | 2006-12-07 18:42:16 +0300 | [diff] [blame] | 651 | 	atomic_set(&ec->query_pending, 0); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 652 | 	if (acpi_ec_mode == EC_INTR) { | 
 | 653 | 		atomic_set(&ec->leaving_burst, 1); | 
 | 654 | 		init_waitqueue_head(&ec->wait); | 
 | 655 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | 	strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME); | 
 | 657 | 	strcpy(acpi_device_class(device), ACPI_EC_CLASS); | 
 | 658 | 	acpi_driver_data(device) = ec; | 
 | 659 |  | 
 | 660 | 	/* Use the global lock for all EC transactions? */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 661 | 	acpi_evaluate_integer(ec->handle, "_GLK", NULL, | 
 | 662 | 			      &ec->global_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 |  | 
| Jiri Slaby | ff2fc3e | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 664 | 	/* XXX we don't test uids, because on some boxes ecdt uid = 0, see: | 
 | 665 | 	   http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ | 
 | 666 | 	if (ec_ecdt) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | 		acpi_remove_address_space_handler(ACPI_ROOT_OBJECT, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 668 | 						  ACPI_ADR_SPACE_EC, | 
 | 669 | 						  &acpi_ec_space_handler); | 
 | 670 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 671 | 		acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 672 | 					&acpi_ec_gpe_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 |  | 
 | 674 | 		kfree(ec_ecdt); | 
 | 675 | 	} | 
 | 676 |  | 
 | 677 | 	/* Get GPE bit assignment (EC events). */ | 
 | 678 | 	/* TODO: Add support for _GPE returning a package */ | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 679 | 	status = | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 680 | 	    acpi_evaluate_integer(ec->handle, "_GPE", NULL, | 
 | 681 | 				  &ec->gpe_bit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | 	if (ACPI_FAILURE(status)) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 683 | 		ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit assignment")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | 		result = -ENODEV; | 
 | 685 | 		goto end; | 
 | 686 | 	} | 
 | 687 |  | 
 | 688 | 	result = acpi_ec_add_fs(device); | 
 | 689 | 	if (result) | 
 | 690 | 		goto end; | 
 | 691 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 692 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 693 | 	       acpi_device_name(device), acpi_device_bid(device), | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 694 | 	       (u32) ec->gpe_bit)); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 695 |  | 
 | 696 | 	if (!first_ec) | 
 | 697 | 		first_ec = device; | 
 | 698 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 699 |   end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | 	if (result) | 
 | 701 | 		kfree(ec); | 
 | 702 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 703 | 	return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | } | 
 | 705 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 706 | static int acpi_ec_remove(struct acpi_device *device, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 708 | 	struct acpi_ec *ec = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 |  | 
 | 711 | 	if (!device) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 712 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 |  | 
 | 714 | 	ec = acpi_driver_data(device); | 
 | 715 |  | 
 | 716 | 	acpi_ec_remove_fs(device); | 
 | 717 |  | 
 | 718 | 	kfree(ec); | 
 | 719 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 720 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } | 
 | 722 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | static acpi_status | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 724 | acpi_ec_io_ports(struct acpi_resource *resource, void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 726 | 	struct acpi_ec *ec = (struct acpi_ec *)context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 |  | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 728 | 	if (resource->type != ACPI_RESOURCE_TYPE_IO) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | 		return AE_OK; | 
 | 730 | 	} | 
 | 731 |  | 
 | 732 | 	/* | 
 | 733 | 	 * The first address region returned is the data port, and | 
 | 734 | 	 * the second address region returned is the status/command | 
 | 735 | 	 * port. | 
 | 736 | 	 */ | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 737 | 	if (ec->data_addr == 0) { | 
 | 738 | 		ec->data_addr = resource->data.io.minimum; | 
 | 739 | 	} else if (ec->command_addr == 0) { | 
 | 740 | 		ec->command_addr = resource->data.io.minimum; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | 	} else { | 
 | 742 | 		return AE_CTRL_TERMINATE; | 
 | 743 | 	} | 
 | 744 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | 	return AE_OK; | 
 | 746 | } | 
 | 747 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 748 | static int acpi_ec_start(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 750 | 	acpi_status status = AE_OK; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 751 | 	struct acpi_ec *ec = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 |  | 
 | 754 | 	if (!device) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 755 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 |  | 
 | 757 | 	ec = acpi_driver_data(device); | 
 | 758 |  | 
 | 759 | 	if (!ec) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 760 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 |  | 
 | 762 | 	/* | 
 | 763 | 	 * Get I/O port addresses. Convert to GAS format. | 
 | 764 | 	 */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 765 | 	status = acpi_walk_resources(ec->handle, METHOD_NAME__CRS, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 766 | 				     acpi_ec_io_ports, ec); | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 767 | 	if (ACPI_FAILURE(status) || ec->command_addr == 0) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 768 | 		ACPI_EXCEPTION((AE_INFO, status, | 
 | 769 | 				"Error getting I/O port addresses")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 770 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | 	} | 
 | 772 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 773 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx", | 
 | 774 | 			  ec->gpe_bit, ec->command_addr, ec->data_addr)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 |  | 
 | 776 | 	/* | 
 | 777 | 	 * Install GPE handler | 
 | 778 | 	 */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 779 | 	status = acpi_install_gpe_handler(NULL, ec->gpe_bit, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 780 | 					  ACPI_GPE_EDGE_TRIGGERED, | 
 | 781 | 					  &acpi_ec_gpe_handler, ec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | 	if (ACPI_FAILURE(status)) { | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 783 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | 	} | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 785 | 	acpi_set_gpe_type(NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME); | 
 | 786 | 	acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 788 | 	status = acpi_install_address_space_handler(ec->handle, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 789 | 						    ACPI_ADR_SPACE_EC, | 
 | 790 | 						    &acpi_ec_space_handler, | 
 | 791 | 						    &acpi_ec_space_setup, ec); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | 	if (ACPI_FAILURE(status)) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 793 | 		acpi_remove_gpe_handler(NULL, ec->gpe_bit, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 794 | 					&acpi_ec_gpe_handler); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 795 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | 	} | 
 | 797 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 798 | 	return AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | } | 
 | 800 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 801 | static int acpi_ec_stop(struct acpi_device *device, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 803 | 	acpi_status status = AE_OK; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 804 | 	struct acpi_ec *ec = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 |  | 
 | 807 | 	if (!device) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 808 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 |  | 
 | 810 | 	ec = acpi_driver_data(device); | 
 | 811 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 812 | 	status = acpi_remove_address_space_handler(ec->handle, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 813 | 						   ACPI_ADR_SPACE_EC, | 
 | 814 | 						   &acpi_ec_space_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | 	if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 816 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 818 | 	status = | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 819 | 	    acpi_remove_gpe_handler(NULL, ec->gpe_bit, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 820 | 				    &acpi_ec_gpe_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | 	if (ACPI_FAILURE(status)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 822 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 824 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } | 
 | 826 |  | 
 | 827 | static acpi_status __init | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 828 | acpi_fake_ecdt_callback(acpi_handle handle, | 
 | 829 | 			u32 Level, void *context, void **retval) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 831 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 |  | 
| Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame^] | 833 | 	mutex_init(&ec_ecdt->lock); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 834 | 	if (acpi_ec_mode == EC_INTR) { | 
 | 835 | 		init_waitqueue_head(&ec_ecdt->wait); | 
 | 836 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | 	status = acpi_walk_resources(handle, METHOD_NAME__CRS, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 838 | 				     acpi_ec_io_ports, ec_ecdt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | 	if (ACPI_FAILURE(status)) | 
 | 840 | 		return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 842 | 	ec_ecdt->uid = -1; | 
 | 843 | 	acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 845 | 	status = | 
 | 846 | 	    acpi_evaluate_integer(handle, "_GPE", NULL, | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 847 | 				  &ec_ecdt->gpe_bit); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | 	if (ACPI_FAILURE(status)) | 
 | 849 | 		return status; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 850 | 	ec_ecdt->global_lock = TRUE; | 
 | 851 | 	ec_ecdt->handle = handle; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 |  | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 853 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx", | 
 | 854 | 	       ec_ecdt->gpe_bit, ec_ecdt->command_addr, ec_ecdt->data_addr)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 |  | 
 | 856 | 	return AE_CTRL_TERMINATE; | 
 | 857 | } | 
 | 858 |  | 
 | 859 | /* | 
 | 860 |  * Some BIOS (such as some from Gateway laptops) access EC region very early | 
 | 861 |  * such as in BAT0._INI or EC._INI before an EC device is found and | 
 | 862 |  * do not provide an ECDT. According to ACPI spec, ECDT isn't mandatorily | 
 | 863 |  * required, but if EC regison is accessed early, it is required. | 
 | 864 |  * The routine tries to workaround the BIOS bug by pre-scan EC device | 
 | 865 |  * It assumes that _CRS, _HID, _GPE, _UID methods of EC don't touch any | 
 | 866 |  * op region (since _REG isn't invoked yet). The assumption is true for | 
 | 867 |  * all systems found. | 
 | 868 |  */ | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 869 | static int __init acpi_ec_fake_ecdt(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 871 | 	acpi_status status; | 
 | 872 | 	int ret = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 874 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 876 | 	ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | 	if (!ec_ecdt) { | 
 | 878 | 		ret = -ENOMEM; | 
 | 879 | 		goto error; | 
 | 880 | 	} | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 881 | 	memset(ec_ecdt, 0, sizeof(struct acpi_ec)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 883 | 	status = acpi_get_devices(ACPI_EC_HID, | 
 | 884 | 				  acpi_fake_ecdt_callback, NULL, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | 	if (ACPI_FAILURE(status)) { | 
 | 886 | 		kfree(ec_ecdt); | 
 | 887 | 		ec_ecdt = NULL; | 
 | 888 | 		ret = -ENODEV; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 889 | 		ACPI_EXCEPTION((AE_INFO, status, "Can't make an fake ECDT")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | 		goto error; | 
 | 891 | 	} | 
 | 892 | 	return 0; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 893 |   error: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | 	return ret; | 
 | 895 | } | 
 | 896 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 897 | static int __init acpi_ec_get_real_ecdt(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 899 | 	acpi_status status; | 
 | 900 | 	struct acpi_table_ecdt *ecdt_ptr; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 901 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 902 | 	status = acpi_get_firmware_table("ECDT", 1, ACPI_LOGICAL_ADDRESSING, | 
 | 903 | 					 (struct acpi_table_header **) | 
 | 904 | 					 &ecdt_ptr); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 905 | 	if (ACPI_FAILURE(status)) | 
 | 906 | 		return -ENODEV; | 
 | 907 |  | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 908 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT")); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 909 |  | 
 | 910 | 	/* | 
 | 911 | 	 * Generate a temporary ec context to use until the namespace is scanned | 
 | 912 | 	 */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 913 | 	ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 914 | 	if (!ec_ecdt) | 
 | 915 | 		return -ENOMEM; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 916 | 	memset(ec_ecdt, 0, sizeof(struct acpi_ec)); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 917 |  | 
| Alexey Starikovskiy | c787a85 | 2006-12-07 18:42:16 +0300 | [diff] [blame^] | 918 | 	mutex_init(&ec_ecdt->lock); | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 919 | 	if (acpi_ec_mode == EC_INTR) { | 
 | 920 | 		init_waitqueue_head(&ec_ecdt->wait); | 
 | 921 | 	} | 
| Denis M. Sadykov | 6ffb221 | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 922 | 	ec_ecdt->command_addr = ecdt_ptr->ec_control.address; | 
 | 923 | 	ec_ecdt->data_addr = ecdt_ptr->ec_data.address; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 924 | 	ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 925 | 	/* use the GL just to be safe */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 926 | 	ec_ecdt->global_lock = TRUE; | 
 | 927 | 	ec_ecdt->uid = ecdt_ptr->uid; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 928 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 929 | 	status = | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 930 | 	    acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle); | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 931 | 	if (ACPI_FAILURE(status)) { | 
 | 932 | 		goto error; | 
 | 933 | 	} | 
 | 934 |  | 
 | 935 | 	return 0; | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 936 |   error: | 
 | 937 | 	ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | 	kfree(ec_ecdt); | 
 | 939 | 	ec_ecdt = NULL; | 
 | 940 |  | 
 | 941 | 	return -ENODEV; | 
 | 942 | } | 
 | 943 |  | 
 | 944 | static int __initdata acpi_fake_ecdt_enabled; | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 945 | int __init acpi_ec_ecdt_probe(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 947 | 	acpi_status status; | 
 | 948 | 	int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 |  | 
 | 950 | 	ret = acpi_ec_get_real_ecdt(); | 
 | 951 | 	/* Try to make a fake ECDT */ | 
 | 952 | 	if (ret && acpi_fake_ecdt_enabled) { | 
 | 953 | 		ret = acpi_ec_fake_ecdt(); | 
 | 954 | 	} | 
 | 955 |  | 
 | 956 | 	if (ret) | 
 | 957 | 		return 0; | 
 | 958 |  | 
 | 959 | 	/* | 
 | 960 | 	 * Install GPE handler | 
 | 961 | 	 */ | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 962 | 	status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 963 | 					  ACPI_GPE_EDGE_TRIGGERED, | 
 | 964 | 					  &acpi_ec_gpe_handler, ec_ecdt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | 	if (ACPI_FAILURE(status)) { | 
 | 966 | 		goto error; | 
 | 967 | 	} | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 968 | 	acpi_set_gpe_type(NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME); | 
 | 969 | 	acpi_enable_gpe(NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 971 | 	status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, | 
 | 972 | 						    ACPI_ADR_SPACE_EC, | 
 | 973 | 						    &acpi_ec_space_handler, | 
 | 974 | 						    &acpi_ec_space_setup, | 
 | 975 | 						    ec_ecdt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | 	if (ACPI_FAILURE(status)) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 977 | 		acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 978 | 					&acpi_ec_gpe_handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | 		goto error; | 
 | 980 | 	} | 
 | 981 |  | 
 | 982 | 	return 0; | 
 | 983 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 984 |       error: | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 985 | 	ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | 	kfree(ec_ecdt); | 
 | 987 | 	ec_ecdt = NULL; | 
 | 988 |  | 
 | 989 | 	return -ENODEV; | 
 | 990 | } | 
 | 991 |  | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 992 | static int __init acpi_ec_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 994 | 	int result = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 |  | 
 | 997 | 	if (acpi_disabled) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 998 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 |  | 
 | 1000 | 	acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); | 
 | 1001 | 	if (!acpi_ec_dir) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1002 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 |  | 
 | 1004 | 	/* Now register the driver for the EC */ | 
 | 1005 | 	result = acpi_bus_register_driver(&acpi_ec_driver); | 
 | 1006 | 	if (result < 0) { | 
 | 1007 | 		remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1008 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | 	} | 
 | 1010 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1011 | 	return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | } | 
 | 1013 |  | 
 | 1014 | subsys_initcall(acpi_ec_init); | 
 | 1015 |  | 
 | 1016 | /* EC driver currently not unloadable */ | 
 | 1017 | #if 0 | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1018 | static void __exit acpi_ec_exit(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 |  | 
 | 1021 | 	acpi_bus_unregister_driver(&acpi_ec_driver); | 
 | 1022 |  | 
 | 1023 | 	remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); | 
 | 1024 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1025 | 	return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | } | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1027 | #endif				/* 0 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 |  | 
 | 1029 | static int __init acpi_fake_ecdt_setup(char *str) | 
 | 1030 | { | 
 | 1031 | 	acpi_fake_ecdt_enabled = 1; | 
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1032 | 	return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | } | 
| Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1034 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | __setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); | 
| Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1036 | static int __init acpi_ec_set_intr_mode(char *str) | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1037 | { | 
| Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1038 | 	int intr; | 
| Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1039 |  | 
| Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1040 | 	if (!get_option(&str, &intr)) | 
| Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1041 | 		return 0; | 
 | 1042 |  | 
| Len Brown | 02b28a3 | 2005-12-05 16:33:04 -0500 | [diff] [blame] | 1043 | 	if (intr) { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 1044 | 		acpi_ec_mode = EC_INTR; | 
| Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1045 | 	} else { | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 1046 | 		acpi_ec_mode = EC_POLL; | 
| Luming Yu | 7b15f5e | 2005-08-03 17:38:04 -0400 | [diff] [blame] | 1047 | 	} | 
| Denis M. Sadykov | 703959d | 2006-09-26 19:50:33 +0400 | [diff] [blame] | 1048 | 	acpi_ec_driver.ops.add = acpi_ec_add; | 
 | 1049 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", intr ? "interrupt" : "polling")); | 
 | 1050 |  | 
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1051 | 	return 1; | 
| Luming Yu | 45bea15 | 2005-07-23 04:08:00 -0400 | [diff] [blame] | 1052 | } | 
| Len Brown | 50526df | 2005-08-11 17:32:05 -0400 | [diff] [blame] | 1053 |  | 
| Len Brown | 53f11d4 | 2005-12-05 16:46:36 -0500 | [diff] [blame] | 1054 | __setup("ec_intr=", acpi_ec_set_intr_mode); |