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