Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Samsung Laptop driver |
| 3 | * |
| 4 | * Copyright (C) 2009,2011 Greg Kroah-Hartman (gregkh@suse.de) |
| 5 | * Copyright (C) 2009,2011 Novell Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | * |
| 11 | */ |
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/pci.h> |
| 19 | #include <linux/backlight.h> |
| 20 | #include <linux/fb.h> |
| 21 | #include <linux/dmi.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/rfkill.h> |
Corentin Chary | f34cd9c | 2011-11-26 11:00:00 +0100 | [diff] [blame] | 24 | #include <linux/acpi.h> |
Corentin Chary | 5b80fc4 | 2011-11-26 11:00:03 +0100 | [diff] [blame] | 25 | #include <linux/seq_file.h> |
| 26 | #include <linux/debugfs.h> |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * This driver is needed because a number of Samsung laptops do not hook |
| 30 | * their control settings through ACPI. So we have to poke around in the |
| 31 | * BIOS to do things like brightness values, and "special" key controls. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * We have 0 - 8 as valid brightness levels. The specs say that level 0 should |
| 36 | * be reserved by the BIOS (which really doesn't make much sense), we tell |
| 37 | * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8 |
| 38 | */ |
| 39 | #define MAX_BRIGHT 0x07 |
| 40 | |
| 41 | |
| 42 | #define SABI_IFACE_MAIN 0x00 |
| 43 | #define SABI_IFACE_SUB 0x02 |
| 44 | #define SABI_IFACE_COMPLETE 0x04 |
| 45 | #define SABI_IFACE_DATA 0x05 |
| 46 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 47 | /* Structure get/set data using sabi */ |
| 48 | struct sabi_data { |
| 49 | union { |
| 50 | struct { |
| 51 | u32 d0; |
| 52 | u32 d1; |
| 53 | u16 d2; |
| 54 | u8 d3; |
| 55 | }; |
| 56 | u8 data[11]; |
| 57 | }; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | struct sabi_header_offsets { |
| 61 | u8 port; |
| 62 | u8 re_mem; |
| 63 | u8 iface_func; |
| 64 | u8 en_mem; |
| 65 | u8 data_offset; |
| 66 | u8 data_segment; |
| 67 | }; |
| 68 | |
| 69 | struct sabi_commands { |
| 70 | /* |
| 71 | * Brightness is 0 - 8, as described above. |
| 72 | * Value 0 is for the BIOS to use |
| 73 | */ |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 74 | u16 get_brightness; |
| 75 | u16 set_brightness; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * first byte: |
| 79 | * 0x00 - wireless is off |
| 80 | * 0x01 - wireless is on |
| 81 | * second byte: |
| 82 | * 0x02 - 3G is off |
| 83 | * 0x03 - 3G is on |
| 84 | * TODO, verify 3G is correct, that doesn't seem right... |
| 85 | */ |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 86 | u16 get_wireless_button; |
| 87 | u16 set_wireless_button; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 88 | |
| 89 | /* 0 is off, 1 is on */ |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 90 | u16 get_backlight; |
| 91 | u16 set_backlight; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * 0x80 or 0x00 - no action |
| 95 | * 0x81 - recovery key pressed |
| 96 | */ |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 97 | u16 get_recovery_mode; |
| 98 | u16 set_recovery_mode; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * on seclinux: 0 is low, 1 is high, |
| 102 | * on swsmi: 0 is normal, 1 is silent, 2 is turbo |
| 103 | */ |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 104 | u16 get_performance_level; |
| 105 | u16 set_performance_level; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Tell the BIOS that Linux is running on this machine. |
| 109 | * 81 is on, 80 is off |
| 110 | */ |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 111 | u16 set_linux; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | struct sabi_performance_level { |
| 115 | const char *name; |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 116 | u16 value; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | struct sabi_config { |
| 120 | const char *test_string; |
| 121 | u16 main_function; |
| 122 | const struct sabi_header_offsets header_offsets; |
| 123 | const struct sabi_commands commands; |
| 124 | const struct sabi_performance_level performance_levels[4]; |
| 125 | u8 min_brightness; |
| 126 | u8 max_brightness; |
| 127 | }; |
| 128 | |
| 129 | static const struct sabi_config sabi_configs[] = { |
| 130 | { |
| 131 | .test_string = "SECLINUX", |
| 132 | |
| 133 | .main_function = 0x4c49, |
| 134 | |
| 135 | .header_offsets = { |
| 136 | .port = 0x00, |
| 137 | .re_mem = 0x02, |
| 138 | .iface_func = 0x03, |
| 139 | .en_mem = 0x04, |
| 140 | .data_offset = 0x05, |
| 141 | .data_segment = 0x07, |
| 142 | }, |
| 143 | |
| 144 | .commands = { |
| 145 | .get_brightness = 0x00, |
| 146 | .set_brightness = 0x01, |
| 147 | |
| 148 | .get_wireless_button = 0x02, |
| 149 | .set_wireless_button = 0x03, |
| 150 | |
| 151 | .get_backlight = 0x04, |
| 152 | .set_backlight = 0x05, |
| 153 | |
| 154 | .get_recovery_mode = 0x06, |
| 155 | .set_recovery_mode = 0x07, |
| 156 | |
| 157 | .get_performance_level = 0x08, |
| 158 | .set_performance_level = 0x09, |
| 159 | |
| 160 | .set_linux = 0x0a, |
| 161 | }, |
| 162 | |
| 163 | .performance_levels = { |
| 164 | { |
| 165 | .name = "silent", |
| 166 | .value = 0, |
| 167 | }, |
| 168 | { |
| 169 | .name = "normal", |
| 170 | .value = 1, |
| 171 | }, |
| 172 | { }, |
| 173 | }, |
| 174 | .min_brightness = 1, |
| 175 | .max_brightness = 8, |
| 176 | }, |
| 177 | { |
| 178 | .test_string = "SwSmi@", |
| 179 | |
| 180 | .main_function = 0x5843, |
| 181 | |
| 182 | .header_offsets = { |
| 183 | .port = 0x00, |
| 184 | .re_mem = 0x04, |
| 185 | .iface_func = 0x02, |
| 186 | .en_mem = 0x03, |
| 187 | .data_offset = 0x05, |
| 188 | .data_segment = 0x07, |
| 189 | }, |
| 190 | |
| 191 | .commands = { |
| 192 | .get_brightness = 0x10, |
| 193 | .set_brightness = 0x11, |
| 194 | |
| 195 | .get_wireless_button = 0x12, |
| 196 | .set_wireless_button = 0x13, |
| 197 | |
| 198 | .get_backlight = 0x2d, |
| 199 | .set_backlight = 0x2e, |
| 200 | |
| 201 | .get_recovery_mode = 0xff, |
| 202 | .set_recovery_mode = 0xff, |
| 203 | |
| 204 | .get_performance_level = 0x31, |
| 205 | .set_performance_level = 0x32, |
| 206 | |
| 207 | .set_linux = 0xff, |
| 208 | }, |
| 209 | |
| 210 | .performance_levels = { |
| 211 | { |
| 212 | .name = "normal", |
| 213 | .value = 0, |
| 214 | }, |
| 215 | { |
| 216 | .name = "silent", |
| 217 | .value = 1, |
| 218 | }, |
| 219 | { |
| 220 | .name = "overclock", |
| 221 | .value = 2, |
| 222 | }, |
| 223 | { }, |
| 224 | }, |
| 225 | .min_brightness = 0, |
| 226 | .max_brightness = 8, |
| 227 | }, |
| 228 | { }, |
| 229 | }; |
| 230 | |
Corentin Chary | 5b80fc4 | 2011-11-26 11:00:03 +0100 | [diff] [blame] | 231 | /* |
| 232 | * samsung-laptop/ - debugfs root directory |
| 233 | * f0000_segment - dump f0000 segment |
| 234 | * command - current command |
| 235 | * data - current data |
| 236 | * d0, d1, d2, d3 - data fields |
| 237 | * call - call SABI using command and data |
| 238 | * |
| 239 | * This allow to call arbitrary sabi commands wihout |
| 240 | * modifying the driver at all. |
| 241 | * For example, setting the keyboard backlight brightness to 5 |
| 242 | * |
| 243 | * echo 0x78 > command |
| 244 | * echo 0x0582 > d0 |
| 245 | * echo 0 > d1 |
| 246 | * echo 0 > d2 |
| 247 | * echo 0 > d3 |
| 248 | * cat call |
| 249 | */ |
| 250 | |
| 251 | struct samsung_laptop_debug { |
| 252 | struct dentry *root; |
| 253 | struct sabi_data data; |
| 254 | u16 command; |
| 255 | |
| 256 | struct debugfs_blob_wrapper f0000_wrapper; |
| 257 | struct debugfs_blob_wrapper data_wrapper; |
| 258 | }; |
| 259 | |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 260 | struct samsung_laptop { |
| 261 | const struct sabi_config *config; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 262 | |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 263 | void __iomem *sabi; |
| 264 | void __iomem *sabi_iface; |
| 265 | void __iomem *f0000_segment; |
| 266 | |
| 267 | struct mutex sabi_mutex; |
| 268 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 269 | struct platform_device *platform_device; |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 270 | struct backlight_device *backlight_device; |
| 271 | struct rfkill *rfk; |
| 272 | |
Corentin Chary | 5b80fc4 | 2011-11-26 11:00:03 +0100 | [diff] [blame] | 273 | struct samsung_laptop_debug debug; |
| 274 | |
Corentin Chary | f34cd9c | 2011-11-26 11:00:00 +0100 | [diff] [blame] | 275 | bool handle_backlight; |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 276 | bool has_stepping_quirk; |
| 277 | }; |
| 278 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 279 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 280 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 281 | static bool force; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 282 | module_param(force, bool, 0); |
| 283 | MODULE_PARM_DESC(force, |
| 284 | "Disable the DMI check and forces the driver to be loaded"); |
| 285 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 286 | static bool debug; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 287 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 288 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |
| 289 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 290 | static int sabi_command(struct samsung_laptop *samsung, u16 command, |
| 291 | struct sabi_data *in, |
| 292 | struct sabi_data *out) |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 293 | { |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 294 | const struct sabi_config *config = samsung->config; |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 295 | int ret = 0; |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 296 | u16 port = readw(samsung->sabi + config->header_offsets.port); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 297 | u8 complete, iface_data; |
| 298 | |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 299 | mutex_lock(&samsung->sabi_mutex); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 300 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 301 | if (debug) { |
| 302 | if (in) |
| 303 | pr_info("SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}", |
| 304 | command, in->d0, in->d1, in->d2, in->d3); |
| 305 | else |
| 306 | pr_info("SABI 0x%04x", command); |
| 307 | } |
| 308 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 309 | /* enable memory to be able to write to it */ |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 310 | outb(readb(samsung->sabi + config->header_offsets.en_mem), port); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 311 | |
| 312 | /* write out the command */ |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 313 | writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN); |
| 314 | writew(command, samsung->sabi_iface + SABI_IFACE_SUB); |
| 315 | writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE); |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 316 | if (in) { |
| 317 | writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA); |
| 318 | writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4); |
| 319 | writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8); |
| 320 | writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10); |
| 321 | } |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 322 | outb(readb(samsung->sabi + config->header_offsets.iface_func), port); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 323 | |
| 324 | /* write protect memory to make it safe */ |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 325 | outb(readb(samsung->sabi + config->header_offsets.re_mem), port); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 326 | |
| 327 | /* see if the command actually succeeded */ |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 328 | complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE); |
| 329 | iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 330 | if (complete != 0xaa || iface_data == 0xff) { |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 331 | pr_warn("SABI command 0x%04x failed with" |
| 332 | " completion flag 0x%02x and interface data 0x%02x", |
| 333 | command, complete, iface_data); |
| 334 | ret = -EINVAL; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 335 | goto exit; |
| 336 | } |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 337 | |
| 338 | if (out) { |
| 339 | out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA); |
| 340 | out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4); |
| 341 | out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2); |
| 342 | out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1); |
| 343 | } |
| 344 | |
| 345 | if (debug && out) { |
| 346 | pr_info("SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}", |
| 347 | out->d0, out->d1, out->d2, out->d3); |
| 348 | } |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 349 | |
| 350 | exit: |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 351 | mutex_unlock(&samsung->sabi_mutex); |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 352 | return ret; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 353 | } |
| 354 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 355 | /* simple wrappers usable with most commands */ |
| 356 | static int sabi_set_commandb(struct samsung_laptop *samsung, |
| 357 | u16 command, u8 data) |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 358 | { |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 359 | struct sabi_data in = { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 }; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 360 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 361 | in.data[0] = data; |
| 362 | return sabi_command(samsung, command, &in, NULL); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 363 | } |
| 364 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 365 | static int read_brightness(struct samsung_laptop *samsung) |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 366 | { |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 367 | const struct sabi_config *config = samsung->config; |
| 368 | const struct sabi_commands *commands = &samsung->config->commands; |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 369 | struct sabi_data sretval; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 370 | int user_brightness = 0; |
| 371 | int retval; |
| 372 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 373 | retval = sabi_command(samsung, commands->get_brightness, |
| 374 | NULL, &sretval); |
| 375 | if (retval) |
| 376 | return retval; |
| 377 | |
| 378 | user_brightness = sretval.data[0]; |
| 379 | if (user_brightness > config->min_brightness) |
| 380 | user_brightness -= config->min_brightness; |
| 381 | else |
| 382 | user_brightness = 0; |
| 383 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 384 | return user_brightness; |
| 385 | } |
| 386 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 387 | static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness) |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 388 | { |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 389 | const struct sabi_config *config = samsung->config; |
| 390 | const struct sabi_commands *commands = &samsung->config->commands; |
| 391 | u8 user_level = user_brightness + config->min_brightness; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 392 | |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 393 | if (samsung->has_stepping_quirk && user_level != 0) { |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 394 | /* |
| 395 | * short circuit if the specified level is what's already set |
| 396 | * to prevent the screen from flickering needlessly |
| 397 | */ |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 398 | if (user_brightness == read_brightness(samsung)) |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 399 | return; |
| 400 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 401 | sabi_set_commandb(samsung, commands->set_brightness, 0); |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 404 | sabi_set_commandb(samsung, commands->set_brightness, user_level); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static int get_brightness(struct backlight_device *bd) |
| 408 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 409 | struct samsung_laptop *samsung = bl_get_data(bd); |
| 410 | |
| 411 | return read_brightness(samsung); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 414 | static void check_for_stepping_quirk(struct samsung_laptop *samsung) |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 415 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 416 | int initial_level; |
| 417 | int check_level; |
| 418 | int orig_level = read_brightness(samsung); |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 419 | |
| 420 | /* |
| 421 | * Some laptops exhibit the strange behaviour of stepping toward |
| 422 | * (rather than setting) the brightness except when changing to/from |
| 423 | * brightness level 0. This behaviour is checked for here and worked |
| 424 | * around in set_brightness. |
| 425 | */ |
| 426 | |
John Serock | ba05b23 | 2011-10-13 06:42:01 -0400 | [diff] [blame] | 427 | if (orig_level == 0) |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 428 | set_brightness(samsung, 1); |
John Serock | ba05b23 | 2011-10-13 06:42:01 -0400 | [diff] [blame] | 429 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 430 | initial_level = read_brightness(samsung); |
John Serock | ba05b23 | 2011-10-13 06:42:01 -0400 | [diff] [blame] | 431 | |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 432 | if (initial_level <= 2) |
| 433 | check_level = initial_level + 2; |
| 434 | else |
| 435 | check_level = initial_level - 2; |
| 436 | |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 437 | samsung->has_stepping_quirk = false; |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 438 | set_brightness(samsung, check_level); |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 439 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 440 | if (read_brightness(samsung) != check_level) { |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 441 | samsung->has_stepping_quirk = true; |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 442 | pr_info("enabled workaround for brightness stepping quirk\n"); |
| 443 | } |
| 444 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 445 | set_brightness(samsung, orig_level); |
Jason Stubbs | ac08052 | 2011-09-20 09:16:13 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 448 | static int update_status(struct backlight_device *bd) |
| 449 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 450 | struct samsung_laptop *samsung = bl_get_data(bd); |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 451 | const struct sabi_commands *commands = &samsung->config->commands; |
| 452 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 453 | set_brightness(samsung, bd->props.brightness); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 454 | |
| 455 | if (bd->props.power == FB_BLANK_UNBLANK) |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 456 | sabi_set_commandb(samsung, commands->set_backlight, 1); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 457 | else |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 458 | sabi_set_commandb(samsung, commands->set_backlight, 0); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 459 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static const struct backlight_ops backlight_ops = { |
| 464 | .get_brightness = get_brightness, |
| 465 | .update_status = update_status, |
| 466 | }; |
| 467 | |
| 468 | static int rfkill_set(void *data, bool blocked) |
| 469 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 470 | struct samsung_laptop *samsung = data; |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 471 | const struct sabi_commands *commands = &samsung->config->commands; |
| 472 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 473 | /* Do something with blocked...*/ |
| 474 | /* |
| 475 | * blocked == false is on |
| 476 | * blocked == true is off |
| 477 | */ |
| 478 | if (blocked) |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 479 | sabi_set_commandb(samsung, commands->set_wireless_button, 0); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 480 | else |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 481 | sabi_set_commandb(samsung, commands->set_wireless_button, 1); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | static struct rfkill_ops rfkill_ops = { |
| 487 | .set_block = rfkill_set, |
| 488 | }; |
| 489 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 490 | static ssize_t get_performance_level(struct device *dev, |
| 491 | struct device_attribute *attr, char *buf) |
| 492 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 493 | struct samsung_laptop *samsung = dev_get_drvdata(dev); |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 494 | const struct sabi_config *config = samsung->config; |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 495 | const struct sabi_commands *commands = &config->commands; |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 496 | struct sabi_data sretval; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 497 | int retval; |
| 498 | int i; |
| 499 | |
| 500 | /* Read the state */ |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 501 | retval = sabi_command(samsung, commands->get_performance_level, |
| 502 | NULL, &sretval); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 503 | if (retval) |
| 504 | return retval; |
| 505 | |
| 506 | /* The logic is backwards, yeah, lots of fun... */ |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 507 | for (i = 0; config->performance_levels[i].name; ++i) { |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 508 | if (sretval.data[0] == config->performance_levels[i].value) |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 509 | return sprintf(buf, "%s\n", config->performance_levels[i].name); |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 510 | } |
| 511 | return sprintf(buf, "%s\n", "unknown"); |
| 512 | } |
| 513 | |
| 514 | static ssize_t set_performance_level(struct device *dev, |
| 515 | struct device_attribute *attr, const char *buf, |
| 516 | size_t count) |
| 517 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 518 | struct samsung_laptop *samsung = dev_get_drvdata(dev); |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 519 | const struct sabi_config *config = samsung->config; |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 520 | const struct sabi_commands *commands = &config->commands; |
| 521 | int i; |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 522 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 523 | if (count < 1) |
| 524 | return count; |
| 525 | |
| 526 | for (i = 0; config->performance_levels[i].name; ++i) { |
| 527 | const struct sabi_performance_level *level = |
| 528 | &config->performance_levels[i]; |
| 529 | if (!strncasecmp(level->name, buf, strlen(level->name))) { |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 530 | sabi_set_commandb(samsung, |
| 531 | commands->set_performance_level, |
| 532 | level->value); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 533 | break; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 534 | } |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 535 | } |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 536 | |
| 537 | if (!config->performance_levels[i].name) |
| 538 | return -EINVAL; |
| 539 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 540 | return count; |
| 541 | } |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 542 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 543 | static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO, |
| 544 | get_performance_level, set_performance_level); |
| 545 | |
Corentin Chary | a66c166 | 2011-11-26 11:00:01 +0100 | [diff] [blame] | 546 | static struct attribute *platform_attributes[] = { |
| 547 | &dev_attr_performance_level.attr, |
| 548 | NULL |
| 549 | }; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 550 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 551 | static int find_signature(void __iomem *memcheck, const char *testStr) |
| 552 | { |
| 553 | int i = 0; |
| 554 | int loca; |
| 555 | |
| 556 | for (loca = 0; loca < 0xffff; loca++) { |
| 557 | char temp = readb(memcheck + loca); |
| 558 | |
| 559 | if (temp == testStr[i]) { |
| 560 | if (i == strlen(testStr)-1) |
| 561 | break; |
| 562 | ++i; |
| 563 | } else { |
| 564 | i = 0; |
| 565 | } |
| 566 | } |
| 567 | return loca; |
| 568 | } |
| 569 | |
| 570 | static void samsung_rfkill_exit(struct samsung_laptop *samsung) |
| 571 | { |
| 572 | if (samsung->rfk) { |
| 573 | rfkill_unregister(samsung->rfk); |
| 574 | rfkill_destroy(samsung->rfk); |
| 575 | samsung->rfk = NULL; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | static int __init samsung_rfkill_init(struct samsung_laptop *samsung) |
| 580 | { |
| 581 | int retval; |
| 582 | |
| 583 | samsung->rfk = rfkill_alloc("samsung-wifi", |
| 584 | &samsung->platform_device->dev, |
| 585 | RFKILL_TYPE_WLAN, |
| 586 | &rfkill_ops, samsung); |
| 587 | if (!samsung->rfk) |
| 588 | return -ENOMEM; |
| 589 | |
| 590 | retval = rfkill_register(samsung->rfk); |
| 591 | if (retval) { |
| 592 | rfkill_destroy(samsung->rfk); |
| 593 | samsung->rfk = NULL; |
| 594 | return -ENODEV; |
| 595 | } |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static void samsung_backlight_exit(struct samsung_laptop *samsung) |
| 601 | { |
| 602 | if (samsung->backlight_device) { |
| 603 | backlight_device_unregister(samsung->backlight_device); |
| 604 | samsung->backlight_device = NULL; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | static int __init samsung_backlight_init(struct samsung_laptop *samsung) |
| 609 | { |
| 610 | struct backlight_device *bd; |
| 611 | struct backlight_properties props; |
| 612 | |
Corentin Chary | f34cd9c | 2011-11-26 11:00:00 +0100 | [diff] [blame] | 613 | if (!samsung->handle_backlight) |
| 614 | return 0; |
| 615 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 616 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 617 | props.type = BACKLIGHT_PLATFORM; |
| 618 | props.max_brightness = samsung->config->max_brightness - |
| 619 | samsung->config->min_brightness; |
| 620 | |
| 621 | bd = backlight_device_register("samsung", |
| 622 | &samsung->platform_device->dev, |
| 623 | samsung, &backlight_ops, |
| 624 | &props); |
| 625 | if (IS_ERR(bd)) |
| 626 | return PTR_ERR(bd); |
| 627 | |
| 628 | samsung->backlight_device = bd; |
| 629 | samsung->backlight_device->props.brightness = read_brightness(samsung); |
| 630 | samsung->backlight_device->props.power = FB_BLANK_UNBLANK; |
| 631 | backlight_update_status(samsung->backlight_device); |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
Corentin Chary | a66c166 | 2011-11-26 11:00:01 +0100 | [diff] [blame] | 636 | static mode_t samsung_sysfs_is_visible(struct kobject *kobj, |
| 637 | struct attribute *attr, int idx) |
| 638 | { |
| 639 | struct device *dev = container_of(kobj, struct device, kobj); |
| 640 | struct platform_device *pdev = to_platform_device(dev); |
| 641 | struct samsung_laptop *samsung = platform_get_drvdata(pdev); |
| 642 | bool ok = true; |
| 643 | |
| 644 | if (attr == &dev_attr_performance_level.attr) |
| 645 | ok = !!samsung->config->performance_levels[0].name; |
| 646 | |
| 647 | return ok ? attr->mode : 0; |
| 648 | } |
| 649 | |
| 650 | static struct attribute_group platform_attribute_group = { |
| 651 | .is_visible = samsung_sysfs_is_visible, |
| 652 | .attrs = platform_attributes |
| 653 | }; |
| 654 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 655 | static void samsung_sysfs_exit(struct samsung_laptop *samsung) |
| 656 | { |
Corentin Chary | a66c166 | 2011-11-26 11:00:01 +0100 | [diff] [blame] | 657 | struct platform_device *device = samsung->platform_device; |
| 658 | |
| 659 | sysfs_remove_group(&device->dev.kobj, &platform_attribute_group); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static int __init samsung_sysfs_init(struct samsung_laptop *samsung) |
| 663 | { |
Corentin Chary | a66c166 | 2011-11-26 11:00:01 +0100 | [diff] [blame] | 664 | struct platform_device *device = samsung->platform_device; |
| 665 | |
| 666 | return sysfs_create_group(&device->dev.kobj, &platform_attribute_group); |
| 667 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 668 | } |
| 669 | |
Corentin Chary | 5b80fc4 | 2011-11-26 11:00:03 +0100 | [diff] [blame] | 670 | static int show_call(struct seq_file *m, void *data) |
| 671 | { |
| 672 | struct samsung_laptop *samsung = m->private; |
| 673 | struct sabi_data *sdata = &samsung->debug.data; |
| 674 | int ret; |
| 675 | |
| 676 | seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n", |
| 677 | samsung->debug.command, |
| 678 | sdata->d0, sdata->d1, sdata->d2, sdata->d3); |
| 679 | |
| 680 | ret = sabi_command(samsung, samsung->debug.command, sdata, sdata); |
| 681 | |
| 682 | if (ret) { |
| 683 | seq_printf(m, "SABI command 0x%04x failed\n", |
| 684 | samsung->debug.command); |
| 685 | return ret; |
| 686 | } |
| 687 | |
| 688 | seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n", |
| 689 | sdata->d0, sdata->d1, sdata->d2, sdata->d3); |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static int samsung_debugfs_open(struct inode *inode, struct file *file) |
| 694 | { |
| 695 | return single_open(file, show_call, inode->i_private); |
| 696 | } |
| 697 | |
| 698 | static const struct file_operations samsung_laptop_call_io_ops = { |
| 699 | .owner = THIS_MODULE, |
| 700 | .open = samsung_debugfs_open, |
| 701 | .read = seq_read, |
| 702 | .llseek = seq_lseek, |
| 703 | .release = single_release, |
| 704 | }; |
| 705 | |
| 706 | static void samsung_debugfs_exit(struct samsung_laptop *samsung) |
| 707 | { |
| 708 | debugfs_remove_recursive(samsung->debug.root); |
| 709 | } |
| 710 | |
| 711 | static int samsung_debugfs_init(struct samsung_laptop *samsung) |
| 712 | { |
| 713 | struct dentry *dent; |
| 714 | |
| 715 | samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL); |
| 716 | if (!samsung->debug.root) { |
| 717 | pr_err("failed to create debugfs directory"); |
| 718 | goto error_debugfs; |
| 719 | } |
| 720 | |
| 721 | samsung->debug.f0000_wrapper.data = samsung->f0000_segment; |
| 722 | samsung->debug.f0000_wrapper.size = 0xffff; |
| 723 | |
| 724 | samsung->debug.data_wrapper.data = &samsung->debug.data; |
| 725 | samsung->debug.data_wrapper.size = sizeof(samsung->debug.data); |
| 726 | |
| 727 | dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR, |
| 728 | samsung->debug.root, &samsung->debug.command); |
| 729 | if (!dent) |
| 730 | goto error_debugfs; |
| 731 | |
| 732 | dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root, |
| 733 | &samsung->debug.data.d0); |
| 734 | if (!dent) |
| 735 | goto error_debugfs; |
| 736 | |
| 737 | dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root, |
| 738 | &samsung->debug.data.d1); |
| 739 | if (!dent) |
| 740 | goto error_debugfs; |
| 741 | |
| 742 | dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root, |
| 743 | &samsung->debug.data.d2); |
| 744 | if (!dent) |
| 745 | goto error_debugfs; |
| 746 | |
| 747 | dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root, |
| 748 | &samsung->debug.data.d3); |
| 749 | if (!dent) |
| 750 | goto error_debugfs; |
| 751 | |
| 752 | dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR, |
| 753 | samsung->debug.root, |
| 754 | &samsung->debug.data_wrapper); |
| 755 | if (!dent) |
| 756 | goto error_debugfs; |
| 757 | |
| 758 | dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR, |
| 759 | samsung->debug.root, |
| 760 | &samsung->debug.f0000_wrapper); |
| 761 | if (!dent) |
| 762 | goto error_debugfs; |
| 763 | |
| 764 | dent = debugfs_create_file("call", S_IFREG | S_IRUGO, |
| 765 | samsung->debug.root, samsung, |
| 766 | &samsung_laptop_call_io_ops); |
| 767 | if (!dent) |
| 768 | goto error_debugfs; |
| 769 | |
| 770 | return 0; |
| 771 | |
| 772 | error_debugfs: |
| 773 | samsung_debugfs_exit(samsung); |
| 774 | return -ENOMEM; |
| 775 | } |
| 776 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 777 | static void samsung_sabi_exit(struct samsung_laptop *samsung) |
| 778 | { |
| 779 | const struct sabi_config *config = samsung->config; |
| 780 | |
| 781 | /* Turn off "Linux" mode in the BIOS */ |
| 782 | if (config && config->commands.set_linux != 0xff) |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 783 | sabi_set_commandb(samsung, config->commands.set_linux, 0x80); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 784 | |
| 785 | if (samsung->sabi_iface) { |
| 786 | iounmap(samsung->sabi_iface); |
| 787 | samsung->sabi_iface = NULL; |
| 788 | } |
| 789 | if (samsung->f0000_segment) { |
| 790 | iounmap(samsung->f0000_segment); |
| 791 | samsung->f0000_segment = NULL; |
| 792 | } |
| 793 | |
| 794 | samsung->config = NULL; |
| 795 | } |
| 796 | |
Corentin Chary | 49dd773 | 2011-11-26 11:00:04 +0100 | [diff] [blame^] | 797 | static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca, |
| 798 | unsigned int ifaceP) |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 799 | { |
| 800 | const struct sabi_config *config = samsung->config; |
| 801 | |
| 802 | printk(KERN_DEBUG "This computer supports SABI==%x\n", |
| 803 | loca + 0xf0000 - 6); |
Corentin Chary | 49dd773 | 2011-11-26 11:00:04 +0100 | [diff] [blame^] | 804 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 805 | printk(KERN_DEBUG "SABI header:\n"); |
| 806 | printk(KERN_DEBUG " SMI Port Number = 0x%04x\n", |
| 807 | readw(samsung->sabi + config->header_offsets.port)); |
| 808 | printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n", |
| 809 | readb(samsung->sabi + config->header_offsets.iface_func)); |
| 810 | printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n", |
| 811 | readb(samsung->sabi + config->header_offsets.en_mem)); |
| 812 | printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n", |
| 813 | readb(samsung->sabi + config->header_offsets.re_mem)); |
| 814 | printk(KERN_DEBUG " SABI data offset = 0x%04x\n", |
| 815 | readw(samsung->sabi + config->header_offsets.data_offset)); |
| 816 | printk(KERN_DEBUG " SABI data segment = 0x%04x\n", |
| 817 | readw(samsung->sabi + config->header_offsets.data_segment)); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 818 | |
Corentin Chary | 49dd773 | 2011-11-26 11:00:04 +0100 | [diff] [blame^] | 819 | printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static int __init samsung_sabi_init(struct samsung_laptop *samsung) |
| 823 | { |
| 824 | const struct sabi_config *config = NULL; |
| 825 | const struct sabi_commands *commands; |
| 826 | unsigned int ifaceP; |
| 827 | int ret = 0; |
| 828 | int i; |
| 829 | int loca; |
| 830 | |
| 831 | samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff); |
| 832 | if (!samsung->f0000_segment) { |
| 833 | pr_err("Can't map the segment at 0xf0000\n"); |
| 834 | ret = -EINVAL; |
| 835 | goto exit; |
| 836 | } |
| 837 | |
| 838 | /* Try to find one of the signatures in memory to find the header */ |
| 839 | for (i = 0; sabi_configs[i].test_string != 0; ++i) { |
| 840 | samsung->config = &sabi_configs[i]; |
| 841 | loca = find_signature(samsung->f0000_segment, |
| 842 | samsung->config->test_string); |
| 843 | if (loca != 0xffff) |
| 844 | break; |
| 845 | } |
| 846 | |
| 847 | if (loca == 0xffff) { |
| 848 | pr_err("This computer does not support SABI\n"); |
| 849 | ret = -ENODEV; |
| 850 | goto exit; |
| 851 | } |
| 852 | |
| 853 | config = samsung->config; |
| 854 | commands = &config->commands; |
| 855 | |
| 856 | /* point to the SMI port Number */ |
| 857 | loca += 1; |
| 858 | samsung->sabi = (samsung->f0000_segment + loca); |
| 859 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 860 | /* Get a pointer to the SABI Interface */ |
| 861 | ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4; |
| 862 | ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff; |
Corentin Chary | 49dd773 | 2011-11-26 11:00:04 +0100 | [diff] [blame^] | 863 | |
| 864 | if (debug) |
| 865 | samsung_sabi_infos(samsung, loca, ifaceP); |
| 866 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 867 | samsung->sabi_iface = ioremap_nocache(ifaceP, 16); |
| 868 | if (!samsung->sabi_iface) { |
| 869 | pr_err("Can't remap %x\n", ifaceP); |
| 870 | ret = -EINVAL; |
| 871 | goto exit; |
| 872 | } |
| 873 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 874 | /* Turn on "Linux" mode in the BIOS */ |
| 875 | if (commands->set_linux != 0xff) { |
Corentin Chary | 7e96071 | 2011-11-26 11:00:02 +0100 | [diff] [blame] | 876 | int retval = sabi_set_commandb(samsung, |
| 877 | commands->set_linux, 0x81); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 878 | if (retval) { |
| 879 | pr_warn("Linux mode was not set!\n"); |
| 880 | ret = -ENODEV; |
| 881 | goto exit; |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /* Check for stepping quirk */ |
Corentin Chary | f34cd9c | 2011-11-26 11:00:00 +0100 | [diff] [blame] | 886 | if (samsung->handle_backlight) |
| 887 | check_for_stepping_quirk(samsung); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 888 | |
| 889 | exit: |
| 890 | if (ret) |
| 891 | samsung_sabi_exit(samsung); |
| 892 | |
| 893 | return ret; |
| 894 | } |
| 895 | |
| 896 | static void samsung_platform_exit(struct samsung_laptop *samsung) |
| 897 | { |
| 898 | if (samsung->platform_device) { |
| 899 | platform_device_unregister(samsung->platform_device); |
| 900 | samsung->platform_device = NULL; |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | static int __init samsung_platform_init(struct samsung_laptop *samsung) |
| 905 | { |
| 906 | struct platform_device *pdev; |
| 907 | |
| 908 | pdev = platform_device_register_simple("samsung", -1, NULL, 0); |
| 909 | if (IS_ERR(pdev)) |
| 910 | return PTR_ERR(pdev); |
| 911 | |
| 912 | samsung->platform_device = pdev; |
| 913 | platform_set_drvdata(samsung->platform_device, samsung); |
| 914 | return 0; |
| 915 | } |
| 916 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 917 | static int __init dmi_check_cb(const struct dmi_system_id *id) |
| 918 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 919 | pr_info("found laptop model '%s'\n", id->ident); |
Axel Lin | 2783658 | 2011-03-14 18:56:18 +0800 | [diff] [blame] | 920 | return 1; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | static struct dmi_system_id __initdata samsung_dmi_table[] = { |
| 924 | { |
| 925 | .ident = "N128", |
| 926 | .matches = { |
| 927 | DMI_MATCH(DMI_SYS_VENDOR, |
| 928 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 929 | DMI_MATCH(DMI_PRODUCT_NAME, "N128"), |
| 930 | DMI_MATCH(DMI_BOARD_NAME, "N128"), |
| 931 | }, |
| 932 | .callback = dmi_check_cb, |
| 933 | }, |
| 934 | { |
| 935 | .ident = "N130", |
| 936 | .matches = { |
| 937 | DMI_MATCH(DMI_SYS_VENDOR, |
| 938 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 939 | DMI_MATCH(DMI_PRODUCT_NAME, "N130"), |
| 940 | DMI_MATCH(DMI_BOARD_NAME, "N130"), |
| 941 | }, |
| 942 | .callback = dmi_check_cb, |
| 943 | }, |
| 944 | { |
J Witteveen | 4e2441c | 2011-07-03 13:15:44 +0200 | [diff] [blame] | 945 | .ident = "N510", |
| 946 | .matches = { |
| 947 | DMI_MATCH(DMI_SYS_VENDOR, |
| 948 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 949 | DMI_MATCH(DMI_PRODUCT_NAME, "N510"), |
| 950 | DMI_MATCH(DMI_BOARD_NAME, "N510"), |
| 951 | }, |
| 952 | .callback = dmi_check_cb, |
| 953 | }, |
| 954 | { |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 955 | .ident = "X125", |
| 956 | .matches = { |
| 957 | DMI_MATCH(DMI_SYS_VENDOR, |
| 958 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 959 | DMI_MATCH(DMI_PRODUCT_NAME, "X125"), |
| 960 | DMI_MATCH(DMI_BOARD_NAME, "X125"), |
| 961 | }, |
| 962 | .callback = dmi_check_cb, |
| 963 | }, |
| 964 | { |
| 965 | .ident = "X120/X170", |
| 966 | .matches = { |
| 967 | DMI_MATCH(DMI_SYS_VENDOR, |
| 968 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 969 | DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"), |
| 970 | DMI_MATCH(DMI_BOARD_NAME, "X120/X170"), |
| 971 | }, |
| 972 | .callback = dmi_check_cb, |
| 973 | }, |
| 974 | { |
| 975 | .ident = "NC10", |
| 976 | .matches = { |
| 977 | DMI_MATCH(DMI_SYS_VENDOR, |
| 978 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 979 | DMI_MATCH(DMI_PRODUCT_NAME, "NC10"), |
| 980 | DMI_MATCH(DMI_BOARD_NAME, "NC10"), |
| 981 | }, |
| 982 | .callback = dmi_check_cb, |
| 983 | }, |
| 984 | { |
| 985 | .ident = "NP-Q45", |
| 986 | .matches = { |
| 987 | DMI_MATCH(DMI_SYS_VENDOR, |
| 988 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 989 | DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"), |
| 990 | DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"), |
| 991 | }, |
| 992 | .callback = dmi_check_cb, |
| 993 | }, |
| 994 | { |
| 995 | .ident = "X360", |
| 996 | .matches = { |
| 997 | DMI_MATCH(DMI_SYS_VENDOR, |
| 998 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 999 | DMI_MATCH(DMI_PRODUCT_NAME, "X360"), |
| 1000 | DMI_MATCH(DMI_BOARD_NAME, "X360"), |
| 1001 | }, |
| 1002 | .callback = dmi_check_cb, |
| 1003 | }, |
| 1004 | { |
Alberto Mardegan | 3d536ed | 2011-04-08 17:02:03 +0200 | [diff] [blame] | 1005 | .ident = "R410 Plus", |
| 1006 | .matches = { |
| 1007 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1008 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 1009 | DMI_MATCH(DMI_PRODUCT_NAME, "R410P"), |
| 1010 | DMI_MATCH(DMI_BOARD_NAME, "R460"), |
| 1011 | }, |
| 1012 | .callback = dmi_check_cb, |
| 1013 | }, |
| 1014 | { |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1015 | .ident = "R518", |
| 1016 | .matches = { |
| 1017 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1018 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 1019 | DMI_MATCH(DMI_PRODUCT_NAME, "R518"), |
| 1020 | DMI_MATCH(DMI_BOARD_NAME, "R518"), |
| 1021 | }, |
| 1022 | .callback = dmi_check_cb, |
| 1023 | }, |
| 1024 | { |
| 1025 | .ident = "R519/R719", |
| 1026 | .matches = { |
| 1027 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1028 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 1029 | DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"), |
| 1030 | DMI_MATCH(DMI_BOARD_NAME, "R519/R719"), |
| 1031 | }, |
| 1032 | .callback = dmi_check_cb, |
| 1033 | }, |
| 1034 | { |
Thomas Courbon | 78a7539 | 2011-07-20 22:57:44 +0200 | [diff] [blame] | 1035 | .ident = "N150/N210/N220", |
| 1036 | .matches = { |
| 1037 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1038 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 1039 | DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"), |
| 1040 | DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"), |
| 1041 | }, |
| 1042 | .callback = dmi_check_cb, |
| 1043 | }, |
| 1044 | { |
Raul Gutierrez Segales | f689c87 | 2011-09-20 09:16:15 -0700 | [diff] [blame] | 1045 | .ident = "N220", |
| 1046 | .matches = { |
| 1047 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1048 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 1049 | DMI_MATCH(DMI_PRODUCT_NAME, "N220"), |
| 1050 | DMI_MATCH(DMI_BOARD_NAME, "N220"), |
| 1051 | }, |
| 1052 | .callback = dmi_check_cb, |
| 1053 | }, |
| 1054 | { |
Greg Kroah-Hartman | 1016507 | 2011-04-08 17:02:04 +0200 | [diff] [blame] | 1055 | .ident = "N150/N210/N220/N230", |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1056 | .matches = { |
| 1057 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1058 | "SAMSUNG ELECTRONICS CO., LTD."), |
Greg Kroah-Hartman | 1016507 | 2011-04-08 17:02:04 +0200 | [diff] [blame] | 1059 | DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"), |
| 1060 | DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"), |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1061 | }, |
| 1062 | .callback = dmi_check_cb, |
| 1063 | }, |
| 1064 | { |
| 1065 | .ident = "N150P/N210P/N220P", |
| 1066 | .matches = { |
| 1067 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1068 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 1069 | DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"), |
| 1070 | DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"), |
| 1071 | }, |
| 1072 | .callback = dmi_check_cb, |
| 1073 | }, |
| 1074 | { |
Stefan Beller | f87d029 | 2011-09-20 09:16:08 -0700 | [diff] [blame] | 1075 | .ident = "R700", |
| 1076 | .matches = { |
| 1077 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1078 | DMI_MATCH(DMI_PRODUCT_NAME, "SR700"), |
| 1079 | DMI_MATCH(DMI_BOARD_NAME, "SR700"), |
| 1080 | }, |
| 1081 | .callback = dmi_check_cb, |
| 1082 | }, |
| 1083 | { |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1084 | .ident = "R530/R730", |
| 1085 | .matches = { |
| 1086 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1087 | DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"), |
| 1088 | DMI_MATCH(DMI_BOARD_NAME, "R530/R730"), |
| 1089 | }, |
| 1090 | .callback = dmi_check_cb, |
| 1091 | }, |
| 1092 | { |
| 1093 | .ident = "NF110/NF210/NF310", |
| 1094 | .matches = { |
| 1095 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1096 | DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"), |
| 1097 | DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"), |
| 1098 | }, |
| 1099 | .callback = dmi_check_cb, |
| 1100 | }, |
| 1101 | { |
| 1102 | .ident = "N145P/N250P/N260P", |
| 1103 | .matches = { |
| 1104 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1105 | DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"), |
| 1106 | DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"), |
| 1107 | }, |
| 1108 | .callback = dmi_check_cb, |
| 1109 | }, |
| 1110 | { |
| 1111 | .ident = "R70/R71", |
| 1112 | .matches = { |
| 1113 | DMI_MATCH(DMI_SYS_VENDOR, |
| 1114 | "SAMSUNG ELECTRONICS CO., LTD."), |
| 1115 | DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"), |
| 1116 | DMI_MATCH(DMI_BOARD_NAME, "R70/R71"), |
| 1117 | }, |
| 1118 | .callback = dmi_check_cb, |
| 1119 | }, |
| 1120 | { |
| 1121 | .ident = "P460", |
| 1122 | .matches = { |
| 1123 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1124 | DMI_MATCH(DMI_PRODUCT_NAME, "P460"), |
| 1125 | DMI_MATCH(DMI_BOARD_NAME, "P460"), |
| 1126 | }, |
| 1127 | .callback = dmi_check_cb, |
| 1128 | }, |
Smelov Andrey | 093ed56 | 2011-09-20 09:16:10 -0700 | [diff] [blame] | 1129 | { |
| 1130 | .ident = "R528/R728", |
| 1131 | .matches = { |
| 1132 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1133 | DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"), |
| 1134 | DMI_MATCH(DMI_BOARD_NAME, "R528/R728"), |
| 1135 | }, |
| 1136 | .callback = dmi_check_cb, |
| 1137 | }, |
Jason Stubbs | 7b3c257 | 2011-09-20 09:16:14 -0700 | [diff] [blame] | 1138 | { |
| 1139 | .ident = "NC210/NC110", |
| 1140 | .matches = { |
| 1141 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1142 | DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"), |
| 1143 | DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"), |
| 1144 | }, |
| 1145 | .callback = dmi_check_cb, |
| 1146 | }, |
Tommaso Massimi | 7500eeb | 2011-09-20 09:16:09 -0700 | [diff] [blame] | 1147 | { |
| 1148 | .ident = "X520", |
| 1149 | .matches = { |
| 1150 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), |
| 1151 | DMI_MATCH(DMI_PRODUCT_NAME, "X520"), |
| 1152 | DMI_MATCH(DMI_BOARD_NAME, "X520"), |
| 1153 | }, |
| 1154 | .callback = dmi_check_cb, |
| 1155 | }, |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1156 | { }, |
| 1157 | }; |
| 1158 | MODULE_DEVICE_TABLE(dmi, samsung_dmi_table); |
| 1159 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1160 | static struct platform_device *samsung_platform_device; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1161 | |
| 1162 | static int __init samsung_init(void) |
| 1163 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1164 | struct samsung_laptop *samsung; |
| 1165 | int ret; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1166 | |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1167 | if (!force && !dmi_check_system(samsung_dmi_table)) |
| 1168 | return -ENODEV; |
| 1169 | |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 1170 | samsung = kzalloc(sizeof(*samsung), GFP_KERNEL); |
| 1171 | if (!samsung) |
| 1172 | return -ENOMEM; |
| 1173 | |
| 1174 | mutex_init(&samsung->sabi_mutex); |
Corentin Chary | f34cd9c | 2011-11-26 11:00:00 +0100 | [diff] [blame] | 1175 | samsung->handle_backlight = true; |
| 1176 | |
| 1177 | #ifdef CONFIG_ACPI |
| 1178 | /* Don't handle backlight here if the acpi video already handle it */ |
| 1179 | if (acpi_video_backlight_support()) { |
| 1180 | pr_info("Backlight controlled by ACPI video driver\n"); |
| 1181 | samsung->handle_backlight = false; |
| 1182 | } |
| 1183 | #endif |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 1184 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1185 | ret = samsung_platform_init(samsung); |
| 1186 | if (ret) |
| 1187 | goto error_platform; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1188 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1189 | ret = samsung_sabi_init(samsung); |
| 1190 | if (ret) |
| 1191 | goto error_sabi; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1192 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1193 | ret = samsung_sysfs_init(samsung); |
| 1194 | if (ret) |
| 1195 | goto error_sysfs; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1196 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1197 | ret = samsung_backlight_init(samsung); |
| 1198 | if (ret) |
| 1199 | goto error_backlight; |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 1200 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1201 | ret = samsung_rfkill_init(samsung); |
| 1202 | if (ret) |
| 1203 | goto error_rfkill; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1204 | |
Corentin Chary | 5b80fc4 | 2011-11-26 11:00:03 +0100 | [diff] [blame] | 1205 | ret = samsung_debugfs_init(samsung); |
| 1206 | if (ret) |
| 1207 | goto error_debugfs; |
| 1208 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1209 | samsung_platform_device = samsung->platform_device; |
| 1210 | return ret; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1211 | |
Corentin Chary | 5b80fc4 | 2011-11-26 11:00:03 +0100 | [diff] [blame] | 1212 | error_debugfs: |
| 1213 | samsung_rfkill_exit(samsung); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1214 | error_rfkill: |
| 1215 | samsung_backlight_exit(samsung); |
| 1216 | error_backlight: |
| 1217 | samsung_sysfs_exit(samsung); |
| 1218 | error_sysfs: |
| 1219 | samsung_sabi_exit(samsung); |
| 1220 | error_sabi: |
| 1221 | samsung_platform_exit(samsung); |
| 1222 | error_platform: |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 1223 | kfree(samsung); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1224 | return ret; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | static void __exit samsung_exit(void) |
| 1228 | { |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1229 | struct samsung_laptop *samsung; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1230 | |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1231 | samsung = platform_get_drvdata(samsung_platform_device); |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 1232 | |
Corentin Chary | 5b80fc4 | 2011-11-26 11:00:03 +0100 | [diff] [blame] | 1233 | samsung_debugfs_exit(samsung); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1234 | samsung_rfkill_exit(samsung); |
| 1235 | samsung_backlight_exit(samsung); |
| 1236 | samsung_sysfs_exit(samsung); |
| 1237 | samsung_sabi_exit(samsung); |
| 1238 | samsung_platform_exit(samsung); |
| 1239 | |
Corentin Chary | a6df489 | 2011-11-26 10:59:58 +0100 | [diff] [blame] | 1240 | kfree(samsung); |
Corentin Chary | 5dea7a2 | 2011-11-26 10:59:59 +0100 | [diff] [blame] | 1241 | samsung_platform_device = NULL; |
Greg Kroah-Hartman | 2d70b73 | 2011-03-11 12:41:19 -0500 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | module_init(samsung_init); |
| 1245 | module_exit(samsung_exit); |
| 1246 | |
| 1247 | MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>"); |
| 1248 | MODULE_DESCRIPTION("Samsung Backlight driver"); |
| 1249 | MODULE_LICENSE("GPL"); |