diff options
| -rw-r--r-- | arch/x86/Kconfig | 1 | ||||
| -rw-r--r-- | arch/x86/platform/olpc/olpc-xo1-sci.c | 207 | ||||
| -rw-r--r-- | include/linux/cs5535.h | 1 |
3 files changed, 208 insertions, 1 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 88889106ac9b..350ccbb4d650 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
| @@ -2090,6 +2090,7 @@ config OLPC_XO1_SCI | |||
| 2090 | - EC-driven system wakeups | 2090 | - EC-driven system wakeups |
| 2091 | - Power button | 2091 | - Power button |
| 2092 | - Ebook switch | 2092 | - Ebook switch |
| 2093 | - Lid switch | ||
| 2093 | 2094 | ||
| 2094 | endif # X86_32 | 2095 | endif # X86_32 |
| 2095 | 2096 | ||
diff --git a/arch/x86/platform/olpc/olpc-xo1-sci.c b/arch/x86/platform/olpc/olpc-xo1-sci.c index 63f50506078b..ad0670bca833 100644 --- a/arch/x86/platform/olpc/olpc-xo1-sci.c +++ b/arch/x86/platform/olpc/olpc-xo1-sci.c | |||
| @@ -32,9 +32,26 @@ | |||
| 32 | static unsigned long acpi_base; | 32 | static unsigned long acpi_base; |
| 33 | static struct input_dev *power_button_idev; | 33 | static struct input_dev *power_button_idev; |
| 34 | static struct input_dev *ebook_switch_idev; | 34 | static struct input_dev *ebook_switch_idev; |
| 35 | static struct input_dev *lid_switch_idev; | ||
| 35 | 36 | ||
| 36 | static int sci_irq; | 37 | static int sci_irq; |
| 37 | 38 | ||
| 39 | static bool lid_open; | ||
| 40 | static bool lid_inverted; | ||
| 41 | static int lid_wake_mode; | ||
| 42 | |||
| 43 | enum lid_wake_modes { | ||
| 44 | LID_WAKE_ALWAYS, | ||
| 45 | LID_WAKE_OPEN, | ||
| 46 | LID_WAKE_CLOSE, | ||
| 47 | }; | ||
| 48 | |||
| 49 | static const char * const lid_wake_mode_names[] = { | ||
| 50 | [LID_WAKE_ALWAYS] = "always", | ||
| 51 | [LID_WAKE_OPEN] = "open", | ||
| 52 | [LID_WAKE_CLOSE] = "close", | ||
| 53 | }; | ||
| 54 | |||
| 38 | /* Report current ebook switch state through input layer */ | 55 | /* Report current ebook switch state through input layer */ |
| 39 | static void send_ebook_state(void) | 56 | static void send_ebook_state(void) |
| 40 | { | 57 | { |
| @@ -49,6 +66,70 @@ static void send_ebook_state(void) | |||
| 49 | input_sync(ebook_switch_idev); | 66 | input_sync(ebook_switch_idev); |
| 50 | } | 67 | } |
| 51 | 68 | ||
| 69 | static void flip_lid_inverter(void) | ||
| 70 | { | ||
| 71 | /* gpio is high; invert so we'll get l->h event interrupt */ | ||
| 72 | if (lid_inverted) | ||
| 73 | cs5535_gpio_clear(OLPC_GPIO_LID, GPIO_INPUT_INVERT); | ||
| 74 | else | ||
| 75 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_INPUT_INVERT); | ||
| 76 | lid_inverted = !lid_inverted; | ||
| 77 | } | ||
| 78 | |||
| 79 | static void detect_lid_state(void) | ||
| 80 | { | ||
| 81 | /* | ||
| 82 | * the edge detector hookup on the gpio inputs on the geode is | ||
| 83 | * odd, to say the least. See http://dev.laptop.org/ticket/5703 | ||
| 84 | * for details, but in a nutshell: we don't use the edge | ||
| 85 | * detectors. instead, we make use of an anomoly: with the both | ||
| 86 | * edge detectors turned off, we still get an edge event on a | ||
| 87 | * positive edge transition. to take advantage of this, we use the | ||
| 88 | * front-end inverter to ensure that that's the edge we're always | ||
| 89 | * going to see next. | ||
| 90 | */ | ||
| 91 | |||
| 92 | int state; | ||
| 93 | |||
| 94 | state = cs5535_gpio_isset(OLPC_GPIO_LID, GPIO_READ_BACK); | ||
| 95 | lid_open = !state ^ !lid_inverted; /* x ^^ y */ | ||
| 96 | if (!state) | ||
| 97 | return; | ||
| 98 | |||
| 99 | flip_lid_inverter(); | ||
| 100 | } | ||
| 101 | |||
| 102 | /* Report current lid switch state through input layer */ | ||
| 103 | static void send_lid_state(void) | ||
| 104 | { | ||
| 105 | input_report_switch(lid_switch_idev, SW_LID, !lid_open); | ||
| 106 | input_sync(lid_switch_idev); | ||
| 107 | } | ||
| 108 | |||
| 109 | static ssize_t lid_wake_mode_show(struct device *dev, | ||
| 110 | struct device_attribute *attr, char *buf) | ||
| 111 | { | ||
| 112 | const char *mode = lid_wake_mode_names[lid_wake_mode]; | ||
| 113 | return sprintf(buf, "%s\n", mode); | ||
| 114 | } | ||
| 115 | static ssize_t lid_wake_mode_set(struct device *dev, | ||
| 116 | struct device_attribute *attr, | ||
| 117 | const char *buf, size_t count) | ||
| 118 | { | ||
| 119 | int i; | ||
| 120 | for (i = 0; i < ARRAY_SIZE(lid_wake_mode_names); i++) { | ||
| 121 | const char *mode = lid_wake_mode_names[i]; | ||
| 122 | if (strlen(mode) != count || strncasecmp(mode, buf, count)) | ||
| 123 | continue; | ||
| 124 | |||
| 125 | lid_wake_mode = i; | ||
| 126 | return count; | ||
| 127 | } | ||
| 128 | return -EINVAL; | ||
| 129 | } | ||
| 130 | static DEVICE_ATTR(lid_wake_mode, S_IWUSR | S_IRUGO, lid_wake_mode_show, | ||
| 131 | lid_wake_mode_set); | ||
| 132 | |||
| 52 | /* | 133 | /* |
| 53 | * Process all items in the EC's SCI queue. | 134 | * Process all items in the EC's SCI queue. |
| 54 | * | 135 | * |
| @@ -111,6 +192,11 @@ static irqreturn_t xo1_sci_intr(int irq, void *dev_id) | |||
| 111 | schedule_work(&sci_work); | 192 | schedule_work(&sci_work); |
| 112 | } | 193 | } |
| 113 | 194 | ||
| 195 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_NEGATIVE_EDGE_STS); | ||
| 196 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_POSITIVE_EDGE_STS); | ||
| 197 | detect_lid_state(); | ||
| 198 | send_lid_state(); | ||
| 199 | |||
| 114 | return IRQ_HANDLED; | 200 | return IRQ_HANDLED; |
| 115 | } | 201 | } |
| 116 | 202 | ||
| @@ -126,11 +212,32 @@ static int xo1_sci_suspend(struct platform_device *pdev, pm_message_t state) | |||
| 126 | else | 212 | else |
| 127 | olpc_ec_wakeup_clear(EC_SCI_SRC_EBOOK); | 213 | olpc_ec_wakeup_clear(EC_SCI_SRC_EBOOK); |
| 128 | 214 | ||
| 215 | if (!device_may_wakeup(&lid_switch_idev->dev)) { | ||
| 216 | cs5535_gpio_clear(OLPC_GPIO_LID, GPIO_EVENTS_ENABLE); | ||
| 217 | } else if ((lid_open && lid_wake_mode == LID_WAKE_OPEN) || | ||
| 218 | (!lid_open && lid_wake_mode == LID_WAKE_CLOSE)) { | ||
| 219 | flip_lid_inverter(); | ||
| 220 | |||
| 221 | /* we may have just caused an event */ | ||
| 222 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_NEGATIVE_EDGE_STS); | ||
| 223 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_POSITIVE_EDGE_STS); | ||
| 224 | |||
| 225 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_EVENTS_ENABLE); | ||
| 226 | } | ||
| 227 | |||
| 129 | return 0; | 228 | return 0; |
| 130 | } | 229 | } |
| 131 | 230 | ||
| 132 | static int xo1_sci_resume(struct platform_device *pdev) | 231 | static int xo1_sci_resume(struct platform_device *pdev) |
| 133 | { | 232 | { |
| 233 | /* | ||
| 234 | * We don't know what may have happened while we were asleep. | ||
| 235 | * Reestablish our lid setup so we're sure to catch all transitions. | ||
| 236 | */ | ||
| 237 | detect_lid_state(); | ||
| 238 | send_lid_state(); | ||
| 239 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_EVENTS_ENABLE); | ||
| 240 | |||
| 134 | /* Enable all EC events */ | 241 | /* Enable all EC events */ |
| 135 | olpc_ec_mask_write(EC_SCI_SRC_ALL); | 242 | olpc_ec_mask_write(EC_SCI_SRC_ALL); |
| 136 | return 0; | 243 | return 0; |
| @@ -221,6 +328,43 @@ static void free_ec_sci(void) | |||
| 221 | gpio_free(OLPC_GPIO_ECSCI); | 328 | gpio_free(OLPC_GPIO_ECSCI); |
| 222 | } | 329 | } |
| 223 | 330 | ||
| 331 | static int __devinit setup_lid_events(void) | ||
| 332 | { | ||
| 333 | int r; | ||
| 334 | |||
| 335 | r = gpio_request(OLPC_GPIO_LID, "OLPC-LID"); | ||
| 336 | if (r) | ||
| 337 | return r; | ||
| 338 | |||
| 339 | gpio_direction_input(OLPC_GPIO_LID); | ||
| 340 | |||
| 341 | cs5535_gpio_clear(OLPC_GPIO_LID, GPIO_INPUT_INVERT); | ||
| 342 | lid_inverted = 0; | ||
| 343 | |||
| 344 | /* Clear edge detection and event enable for now */ | ||
| 345 | cs5535_gpio_clear(OLPC_GPIO_LID, GPIO_EVENTS_ENABLE); | ||
| 346 | cs5535_gpio_clear(OLPC_GPIO_LID, GPIO_NEGATIVE_EDGE_EN); | ||
| 347 | cs5535_gpio_clear(OLPC_GPIO_LID, GPIO_POSITIVE_EDGE_EN); | ||
| 348 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_NEGATIVE_EDGE_STS); | ||
| 349 | cs5535_gpio_set(OLPC_GPIO_LID, GPIO_POSITIVE_EDGE_STS); | ||
