Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1 | /*-*-linux-c-*-*/ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2008 Cezary Jackiewicz <cezary.jackiewicz (at) gmail.com> |
| 5 | |
| 6 | based on MSI driver |
| 7 | |
| 8 | Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de> |
| 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but |
| 16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 23 | 02110-1301, USA. |
| 24 | */ |
| 25 | |
| 26 | /* |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 27 | * compal-laptop.c - Compal laptop support. |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 28 | * |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 29 | * This driver exports a few files in /sys/devices/platform/compal-laptop/: |
| 30 | * wake_up_XXX Whether or not we listen to such wake up events (rw) |
| 31 | * |
| 32 | * In addition to these platform device attributes the driver |
| 33 | * registers itself in the Linux backlight control, power_supply, rfkill |
| 34 | * and hwmon subsystem and is available to userspace under: |
| 35 | * |
| 36 | * /sys/class/backlight/compal-laptop/ |
| 37 | * /sys/class/power_supply/compal-laptop/ |
| 38 | * /sys/class/rfkill/rfkillX/ |
| 39 | * /sys/class/hwmon/hwmonX/ |
| 40 | * |
| 41 | * Notes on the power_supply battery interface: |
| 42 | * - the "minimum" design voltage is *the* design voltage |
| 43 | * - the ambient temperature is the average battery temperature |
| 44 | * and the value is an educated guess (see commented code below) |
| 45 | * |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 46 | * |
| 47 | * This driver might work on other laptops produced by Compal. If you |
| 48 | * want to try it you can pass force=1 as argument to the module which |
| 49 | * will force it to load even when the DMI data doesn't identify the |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 50 | * laptop as compatible. |
| 51 | * |
| 52 | * Lots of data available at: |
| 53 | * http://service1.marasst.com/Compal/JHL90_91/Service%20Manual/ |
| 54 | * JHL90%20service%20manual-Final-0725.pdf |
| 55 | * |
| 56 | * |
| 57 | * |
| 58 | * Support for the Compal JHL90 added by Roald Frederickx |
| 59 | * (roald.frederickx@gmail.com): |
| 60 | * Driver got large revision. Added functionalities: backlight |
| 61 | * power, wake_on_XXX, a hwmon and power_supply interface. |
| 62 | * |
| 63 | * In case this gets merged into the kernel source: I want to dedicate this |
| 64 | * to Kasper Meerts, the awesome guy who showed me Linux and C! |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 65 | */ |
| 66 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 67 | /* NOTE: currently the wake_on_XXX, hwmon and power_supply interfaces are |
| 68 | * only enabled on a JHL90 board until it is verified that they work on the |
| 69 | * other boards too. See the extra_features variable. */ |
| 70 | |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 71 | #include <linux/module.h> |
| 72 | #include <linux/kernel.h> |
| 73 | #include <linux/init.h> |
| 74 | #include <linux/acpi.h> |
| 75 | #include <linux/dmi.h> |
| 76 | #include <linux/backlight.h> |
| 77 | #include <linux/platform_device.h> |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 78 | #include <linux/rfkill.h> |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 79 | #include <linux/hwmon.h> |
| 80 | #include <linux/hwmon-sysfs.h> |
| 81 | #include <linux/power_supply.h> |
| 82 | #include <linux/fb.h> |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 83 | |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 84 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 85 | /* ======= */ |
| 86 | /* Defines */ |
| 87 | /* ======= */ |
| 88 | #define DRIVER_NAME "compal-laptop" |
| 89 | #define DRIVER_VERSION "0.2.7" |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 90 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 91 | #define BACKLIGHT_LEVEL_ADDR 0xB9 |
| 92 | #define BACKLIGHT_LEVEL_MAX 7 |
| 93 | #define BACKLIGHT_STATE_ADDR 0x59 |
| 94 | #define BACKLIGHT_STATE_ON_DATA 0xE1 |
| 95 | #define BACKLIGHT_STATE_OFF_DATA 0xE2 |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 96 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 97 | #define WAKE_UP_ADDR 0xA4 |
| 98 | #define WAKE_UP_PME (1 << 0) |
| 99 | #define WAKE_UP_MODEM (1 << 1) |
| 100 | #define WAKE_UP_LAN (1 << 2) |
| 101 | #define WAKE_UP_WLAN (1 << 4) |
| 102 | #define WAKE_UP_KEY (1 << 6) |
| 103 | #define WAKE_UP_MOUSE (1 << 7) |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 104 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 105 | #define WIRELESS_ADDR 0xBB |
| 106 | #define WIRELESS_WLAN (1 << 0) |
| 107 | #define WIRELESS_BT (1 << 1) |
| 108 | #define WIRELESS_WLAN_EXISTS (1 << 2) |
| 109 | #define WIRELESS_BT_EXISTS (1 << 3) |
| 110 | #define WIRELESS_KILLSWITCH (1 << 4) |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 111 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 112 | #define PWM_ADDRESS 0x46 |
| 113 | #define PWM_DISABLE_ADDR 0x59 |
| 114 | #define PWM_DISABLE_DATA 0xA5 |
| 115 | #define PWM_ENABLE_ADDR 0x59 |
| 116 | #define PWM_ENABLE_DATA 0xA8 |
| 117 | |
| 118 | #define FAN_ADDRESS 0x46 |
| 119 | #define FAN_DATA 0x81 |
| 120 | #define FAN_FULL_ON_CMD 0x59 /* Doesn't seem to work. Just */ |
| 121 | #define FAN_FULL_ON_ENABLE 0x76 /* force the pwm signal to its */ |
| 122 | #define FAN_FULL_ON_DISABLE 0x77 /* maximum value instead */ |
| 123 | |
| 124 | #define TEMP_CPU 0xB0 |
| 125 | #define TEMP_CPU_LOCAL 0xB1 |
| 126 | #define TEMP_CPU_DTS 0xB5 |
| 127 | #define TEMP_NORTHBRIDGE 0xB6 |
| 128 | #define TEMP_VGA 0xB4 |
| 129 | #define TEMP_SKIN 0xB2 |
| 130 | |
| 131 | #define BAT_MANUFACTURER_NAME_ADDR 0x10 |
| 132 | #define BAT_MANUFACTURER_NAME_LEN 9 |
| 133 | #define BAT_MODEL_NAME_ADDR 0x19 |
| 134 | #define BAT_MODEL_NAME_LEN 6 |
| 135 | #define BAT_SERIAL_NUMBER_ADDR 0xC4 |
| 136 | #define BAT_SERIAL_NUMBER_LEN 5 |
| 137 | #define BAT_CHARGE_NOW 0xC2 |
| 138 | #define BAT_CHARGE_DESIGN 0xCA |
| 139 | #define BAT_VOLTAGE_NOW 0xC6 |
| 140 | #define BAT_VOLTAGE_DESIGN 0xC8 |
| 141 | #define BAT_CURRENT_NOW 0xD0 |
| 142 | #define BAT_CURRENT_AVG 0xD2 |
| 143 | #define BAT_POWER 0xD4 |
| 144 | #define BAT_CAPACITY 0xCE |
| 145 | #define BAT_TEMP 0xD6 |
| 146 | #define BAT_TEMP_AVG 0xD7 |
| 147 | #define BAT_STATUS0 0xC1 |
| 148 | #define BAT_STATUS1 0xF0 |
| 149 | #define BAT_STATUS2 0xF1 |
| 150 | #define BAT_STOP_CHARGE1 0xF2 |
| 151 | #define BAT_STOP_CHARGE2 0xF3 |
| 152 | |
| 153 | #define BAT_S0_DISCHARGE (1 << 0) |
| 154 | #define BAT_S0_DISCHRG_CRITICAL (1 << 2) |
| 155 | #define BAT_S0_LOW (1 << 3) |
| 156 | #define BAT_S0_CHARGING (1 << 1) |
| 157 | #define BAT_S0_AC (1 << 7) |
| 158 | #define BAT_S1_EXISTS (1 << 0) |
| 159 | #define BAT_S1_FULL (1 << 1) |
| 160 | #define BAT_S1_EMPTY (1 << 2) |
| 161 | #define BAT_S1_LiION_OR_NiMH (1 << 7) |
| 162 | #define BAT_S2_LOW_LOW (1 << 0) |
| 163 | #define BAT_STOP_CHRG1_BAD_CELL (1 << 1) |
| 164 | #define BAT_STOP_CHRG1_COMM_FAIL (1 << 2) |
| 165 | #define BAT_STOP_CHRG1_OVERVOLTAGE (1 << 6) |
| 166 | #define BAT_STOP_CHRG1_OVERTEMPERATURE (1 << 7) |
| 167 | |
| 168 | |
| 169 | /* ======= */ |
| 170 | /* Structs */ |
| 171 | /* ======= */ |
| 172 | struct compal_data{ |
| 173 | /* Fan control */ |
| 174 | struct device *hwmon_dev; |
| 175 | int pwm_enable; /* 0:full on, 1:set by pwm1, 2:control by moterboard */ |
| 176 | unsigned char curr_pwm; |
| 177 | |
| 178 | /* Power supply */ |
| 179 | struct power_supply psy; |
| 180 | struct power_supply_info psy_info; |
| 181 | char bat_model_name[BAT_MODEL_NAME_LEN + 1]; |
| 182 | char bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN + 1]; |
| 183 | char bat_serial_number[BAT_SERIAL_NUMBER_LEN + 1]; |
| 184 | }; |
| 185 | |
| 186 | |
| 187 | /* =============== */ |
| 188 | /* General globals */ |
| 189 | /* =============== */ |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 190 | static int force; |
| 191 | module_param(force, bool, 0); |
| 192 | MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); |
| 193 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 194 | /* Support for the wake_on_XXX, hwmon and power_supply interface. Currently |
| 195 | * only gets enabled on a JHL90 board. Might work with the others too */ |
| 196 | static bool extra_features; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 197 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 198 | /* Nasty stuff. For some reason the fan control is very un-linear. I've |
| 199 | * come up with these values by looping through the possible inputs and |
| 200 | * watching the output of address 0x4F (do an ec_transaction writing 0x33 |
| 201 | * into 0x4F and read a few bytes from the output, like so: |
| 202 | * u8 writeData = 0x33; |
| 203 | * ec_transaction(0x4F, &writeData, 1, buffer, 32, 0); |
| 204 | * That address is labled "fan1 table information" in the service manual. |
| 205 | * It should be clear which value in 'buffer' changes). This seems to be |
| 206 | * related to fan speed. It isn't a proper 'realtime' fan speed value |
| 207 | * though, because physically stopping or speeding up the fan doesn't |
| 208 | * change it. It might be the average voltage or current of the pwm output. |
| 209 | * Nevertheless, it is more fine-grained than the actual RPM reading */ |
| 210 | static const unsigned char pwm_lookup_table[256] = { |
| 211 | 0, 0, 0, 1, 1, 1, 2, 253, 254, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, |
| 212 | 7, 7, 7, 8, 86, 86, 9, 9, 9, 10, 10, 10, 11, 92, 92, 12, 12, 95, |
| 213 | 13, 66, 66, 14, 14, 98, 15, 15, 15, 16, 16, 67, 17, 17, 72, 18, 70, |
| 214 | 75, 19, 90, 90, 73, 73, 73, 21, 21, 91, 91, 91, 96, 23, 94, 94, 94, |
| 215 | 94, 94, 94, 94, 94, 94, 94, 141, 141, 238, 223, 192, 139, 139, 139, |
| 216 | 139, 139, 142, 142, 142, 142, 142, 78, 78, 78, 78, 78, 76, 76, 76, |
| 217 | 76, 76, 79, 79, 79, 79, 79, 79, 79, 20, 20, 20, 20, 20, 22, 22, 22, |
| 218 | 22, 22, 24, 24, 24, 24, 24, 24, 219, 219, 219, 219, 219, 219, 219, |
| 219 | 219, 27, 27, 188, 188, 28, 28, 28, 29, 186, 186, 186, 186, 186, |
| 220 | 186, 186, 186, 186, 186, 31, 31, 31, 31, 31, 32, 32, 32, 41, 33, |
| 221 | 33, 33, 33, 33, 252, 252, 34, 34, 34, 43, 35, 35, 35, 36, 36, 38, |
| 222 | 206, 206, 206, 206, 206, 206, 206, 206, 206, 37, 37, 37, 46, 46, |
| 223 | 47, 47, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 48, 48, |
| 224 | 48, 48, 48, 40, 40, 40, 49, 42, 42, 42, 42, 42, 42, 42, 42, 44, |
| 225 | 189, 189, 189, 189, 54, 54, 45, 45, 45, 45, 45, 45, 45, 45, 251, |
| 226 | 191, 199, 199, 199, 199, 199, 215, 215, 215, 215, 187, 187, 187, |
| 227 | 187, 187, 193, 50 |
| 228 | }; |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | /* ========================= */ |
| 234 | /* Hardware access functions */ |
| 235 | /* ========================= */ |
| 236 | /* General access */ |
| 237 | static u8 ec_read_u8(u8 addr) |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 238 | { |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 239 | u8 value; |
| 240 | ec_read(addr, &value); |
| 241 | return value; |
| 242 | } |
| 243 | |
| 244 | static s8 ec_read_s8(u8 addr) |
| 245 | { |
| 246 | return (s8)ec_read_u8(addr); |
| 247 | } |
| 248 | |
| 249 | static u16 ec_read_u16(u8 addr) |
| 250 | { |
| 251 | int hi, lo; |
| 252 | lo = ec_read_u8(addr); |
| 253 | hi = ec_read_u8(addr + 1); |
| 254 | return (hi << 8) + lo; |
| 255 | } |
| 256 | |
| 257 | static s16 ec_read_s16(u8 addr) |
| 258 | { |
| 259 | return (s16) ec_read_u16(addr); |
| 260 | } |
| 261 | |
| 262 | static void ec_read_sequence(u8 addr, u8 *buf, int len) |
| 263 | { |
| 264 | int i; |
| 265 | for (i = 0; i < len; i++) |
| 266 | ec_read(addr + i, buf + i); |
| 267 | } |
| 268 | |
| 269 | |
| 270 | /* Backlight access */ |
| 271 | static int set_backlight_level(int level) |
| 272 | { |
| 273 | if (level < 0 || level > BACKLIGHT_LEVEL_MAX) |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 274 | return -EINVAL; |
| 275 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 276 | ec_write(BACKLIGHT_LEVEL_ADDR, level); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 277 | |
Axel Lin | 80183a4 | 2010-07-20 15:19:40 -0700 | [diff] [blame] | 278 | return 1; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 281 | static int get_backlight_level(void) |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 282 | { |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 283 | return (int) ec_read_u8(BACKLIGHT_LEVEL_ADDR); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 286 | static void set_backlight_state(bool on) |
| 287 | { |
| 288 | u8 data = on ? BACKLIGHT_STATE_ON_DATA : BACKLIGHT_STATE_OFF_DATA; |
| 289 | ec_transaction(BACKLIGHT_STATE_ADDR, &data, 1, NULL, 0, 0); |
| 290 | } |
| 291 | |
| 292 | |
| 293 | /* Fan control access */ |
| 294 | static void pwm_enable_control(void) |
| 295 | { |
| 296 | unsigned char writeData = PWM_ENABLE_DATA; |
| 297 | ec_transaction(PWM_ENABLE_ADDR, &writeData, 1, NULL, 0, 0); |
| 298 | } |
| 299 | |
| 300 | static void pwm_disable_control(void) |
| 301 | { |
| 302 | unsigned char writeData = PWM_DISABLE_DATA; |
| 303 | ec_transaction(PWM_DISABLE_ADDR, &writeData, 1, NULL, 0, 0); |
| 304 | } |
| 305 | |
| 306 | static void set_pwm(int pwm) |
| 307 | { |
| 308 | ec_transaction(PWM_ADDRESS, &pwm_lookup_table[pwm], 1, NULL, 0, 0); |
| 309 | } |
| 310 | |
| 311 | static int get_fan_rpm(void) |
| 312 | { |
| 313 | u8 value, data = FAN_DATA; |
| 314 | ec_transaction(FAN_ADDRESS, &data, 1, &value, 1, 0); |
| 315 | return 100 * (int)value; |
| 316 | } |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | /* =================== */ |
| 322 | /* Interface functions */ |
| 323 | /* =================== */ |
| 324 | |
| 325 | /* Backlight interface */ |
| 326 | static int bl_get_brightness(struct backlight_device *b) |
| 327 | { |
| 328 | return get_backlight_level(); |
| 329 | } |
| 330 | |
| 331 | static int bl_update_status(struct backlight_device *b) |
| 332 | { |
| 333 | int ret = set_backlight_level(b->props.brightness); |
| 334 | if (ret) |
| 335 | return ret; |
| 336 | |
| 337 | set_backlight_state((b->props.power == FB_BLANK_UNBLANK) |
| 338 | && !(b->props.state & BL_CORE_SUSPENDED) |
| 339 | && !(b->props.state & BL_CORE_FBBLANK)); |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static const struct backlight_ops compalbl_ops = { |
| 344 | .get_brightness = bl_get_brightness, |
| 345 | .update_status = bl_update_status, |
| 346 | }; |
| 347 | |
| 348 | |
| 349 | /* Wireless interface */ |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 350 | static int compal_rfkill_set(void *data, bool blocked) |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 351 | { |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 352 | unsigned long radio = (unsigned long) data; |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 353 | u8 result = ec_read_u8(WIRELESS_ADDR); |
| 354 | u8 value; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 355 | |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 356 | if (!blocked) |
| 357 | value = (u8) (result | radio); |
| 358 | else |
| 359 | value = (u8) (result & ~radio); |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 360 | ec_write(WIRELESS_ADDR, value); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 365 | static void compal_rfkill_poll(struct rfkill *rfkill, void *data) |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 366 | { |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 367 | u8 result = ec_read_u8(WIRELESS_ADDR); |
| 368 | bool hw_blocked = !(result & WIRELESS_KILLSWITCH); |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 369 | rfkill_set_hw_state(rfkill, hw_blocked); |
| 370 | } |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 371 | |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 372 | static const struct rfkill_ops compal_rfkill_ops = { |
| 373 | .poll = compal_rfkill_poll, |
| 374 | .set_block = compal_rfkill_set, |
| 375 | }; |
| 376 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 377 | |
| 378 | /* Wake_up interface */ |
| 379 | #define SIMPLE_MASKED_STORE_SHOW(NAME, ADDR, MASK) \ |
| 380 | static ssize_t NAME##_show(struct device *dev, \ |
| 381 | struct device_attribute *attr, char *buf) \ |
| 382 | { \ |
| 383 | return sprintf(buf, "%d\n", ((ec_read_u8(ADDR) & MASK) != 0)); \ |
| 384 | } \ |
| 385 | static ssize_t NAME##_store(struct device *dev, \ |
| 386 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 387 | { \ |
| 388 | int state; \ |
| 389 | u8 old_val = ec_read_u8(ADDR); \ |
| 390 | if (sscanf(buf, "%d", &state) != 1 || (state < 0 || state > 1)) \ |
| 391 | return -EINVAL; \ |
| 392 | ec_write(ADDR, state ? (old_val | MASK) : (old_val & ~MASK)); \ |
| 393 | return count; \ |
| 394 | } |
| 395 | |
| 396 | SIMPLE_MASKED_STORE_SHOW(wake_up_pme, WAKE_UP_ADDR, WAKE_UP_PME) |
| 397 | SIMPLE_MASKED_STORE_SHOW(wake_up_modem, WAKE_UP_ADDR, WAKE_UP_MODEM) |
| 398 | SIMPLE_MASKED_STORE_SHOW(wake_up_lan, WAKE_UP_ADDR, WAKE_UP_LAN) |
| 399 | SIMPLE_MASKED_STORE_SHOW(wake_up_wlan, WAKE_UP_ADDR, WAKE_UP_WLAN) |
| 400 | SIMPLE_MASKED_STORE_SHOW(wake_up_key, WAKE_UP_ADDR, WAKE_UP_KEY) |
| 401 | SIMPLE_MASKED_STORE_SHOW(wake_up_mouse, WAKE_UP_ADDR, WAKE_UP_MOUSE) |
| 402 | |
| 403 | |
| 404 | /* General hwmon interface */ |
| 405 | static ssize_t hwmon_name_show(struct device *dev, |
| 406 | struct device_attribute *attr, char *buf) |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 407 | { |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 408 | return sprintf(buf, "%s\n", DRIVER_NAME); |
| 409 | } |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 410 | |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 411 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 412 | /* Fan control interface */ |
| 413 | static ssize_t pwm_enable_show(struct device *dev, |
| 414 | struct device_attribute *attr, char *buf) |
| 415 | { |
| 416 | struct compal_data *data = dev_get_drvdata(dev); |
| 417 | return sprintf(buf, "%d\n", data->pwm_enable); |
| 418 | } |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 419 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 420 | static ssize_t pwm_enable_store(struct device *dev, |
| 421 | struct device_attribute *attr, const char *buf, size_t count) |
| 422 | { |
| 423 | struct compal_data *data = dev_get_drvdata(dev); |
| 424 | long val; |
| 425 | int err; |
| 426 | err = strict_strtol(buf, 10, &val); |
| 427 | if (err) |
| 428 | return err; |
| 429 | if (val < 0) |
| 430 | return -EINVAL; |
| 431 | |
| 432 | data->pwm_enable = val; |
| 433 | |
| 434 | switch (val) { |
| 435 | case 0: /* Full speed */ |
| 436 | pwm_enable_control(); |
| 437 | set_pwm(255); |
| 438 | break; |
| 439 | case 1: /* As set by pwm1 */ |
| 440 | pwm_enable_control(); |
| 441 | set_pwm(data->curr_pwm); |
| 442 | break; |
| 443 | default: /* Control by motherboard */ |
| 444 | pwm_disable_control(); |
| 445 | break; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 448 | return count; |
| 449 | } |
| 450 | |
| 451 | static ssize_t pwm_show(struct device *dev, struct device_attribute *attr, |
| 452 | char *buf) |
| 453 | { |
| 454 | struct compal_data *data = dev_get_drvdata(dev); |
| 455 | return sprintf(buf, "%hhu\n", data->curr_pwm); |
| 456 | } |
| 457 | |
| 458 | static ssize_t pwm_store(struct device *dev, struct device_attribute *attr, |
| 459 | const char *buf, size_t count) |
| 460 | { |
| 461 | struct compal_data *data = dev_get_drvdata(dev); |
| 462 | long val; |
| 463 | int err; |
| 464 | err = strict_strtol(buf, 10, &val); |
| 465 | if (err) |
| 466 | return err; |
| 467 | if (val < 0 || val > 255) |
| 468 | return -EINVAL; |
| 469 | |
| 470 | data->curr_pwm = val; |
| 471 | |
| 472 | if (data->pwm_enable != 1) |
| 473 | return count; |
| 474 | set_pwm(val); |
| 475 | |
| 476 | return count; |
| 477 | } |
| 478 | |
| 479 | static ssize_t fan_show(struct device *dev, struct device_attribute *attr, |
| 480 | char *buf) |
| 481 | { |
| 482 | return sprintf(buf, "%d\n", get_fan_rpm()); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | /* Temperature interface */ |
| 487 | #define TEMPERATURE_SHOW_TEMP_AND_LABEL(POSTFIX, ADDRESS, LABEL) \ |
| 488 | static ssize_t temp_##POSTFIX(struct device *dev, \ |
| 489 | struct device_attribute *attr, char *buf) \ |
| 490 | { \ |
| 491 | return sprintf(buf, "%d\n", 1000 * (int)ec_read_s8(ADDRESS)); \ |
| 492 | } \ |
| 493 | static ssize_t label_##POSTFIX(struct device *dev, \ |
| 494 | struct device_attribute *attr, char *buf) \ |
| 495 | { \ |
| 496 | return sprintf(buf, "%s\n", LABEL); \ |
| 497 | } |
| 498 | |
| 499 | /* Labels as in service guide */ |
| 500 | TEMPERATURE_SHOW_TEMP_AND_LABEL(cpu, TEMP_CPU, "CPU_TEMP"); |
| 501 | TEMPERATURE_SHOW_TEMP_AND_LABEL(cpu_local, TEMP_CPU_LOCAL, "CPU_TEMP_LOCAL"); |
| 502 | TEMPERATURE_SHOW_TEMP_AND_LABEL(cpu_DTS, TEMP_CPU_DTS, "CPU_DTS"); |
| 503 | TEMPERATURE_SHOW_TEMP_AND_LABEL(northbridge,TEMP_NORTHBRIDGE,"NorthBridge"); |
| 504 | TEMPERATURE_SHOW_TEMP_AND_LABEL(vga, TEMP_VGA, "VGA_TEMP"); |
| 505 | TEMPERATURE_SHOW_TEMP_AND_LABEL(SKIN, TEMP_SKIN, "SKIN_TEMP90"); |
| 506 | |
| 507 | |
| 508 | /* Power supply interface */ |
| 509 | static int bat_status(void) |
| 510 | { |
| 511 | u8 status0 = ec_read_u8(BAT_STATUS0); |
| 512 | u8 status1 = ec_read_u8(BAT_STATUS1); |
| 513 | |
| 514 | if (status0 & BAT_S0_CHARGING) |
| 515 | return POWER_SUPPLY_STATUS_CHARGING; |
| 516 | if (status0 & BAT_S0_DISCHARGE) |
| 517 | return POWER_SUPPLY_STATUS_DISCHARGING; |
| 518 | if (status1 & BAT_S1_FULL) |
| 519 | return POWER_SUPPLY_STATUS_FULL; |
| 520 | return POWER_SUPPLY_STATUS_NOT_CHARGING; |
| 521 | } |
| 522 | |
| 523 | static int bat_health(void) |
| 524 | { |
| 525 | u8 status = ec_read_u8(BAT_STOP_CHARGE1); |
| 526 | |
| 527 | if (status & BAT_STOP_CHRG1_OVERTEMPERATURE) |
| 528 | return POWER_SUPPLY_HEALTH_OVERHEAT; |
| 529 | if (status & BAT_STOP_CHRG1_OVERVOLTAGE) |
| 530 | return POWER_SUPPLY_HEALTH_OVERVOLTAGE; |
| 531 | if (status & BAT_STOP_CHRG1_BAD_CELL) |
| 532 | return POWER_SUPPLY_HEALTH_DEAD; |
| 533 | if (status & BAT_STOP_CHRG1_COMM_FAIL) |
| 534 | return POWER_SUPPLY_HEALTH_UNKNOWN; |
| 535 | return POWER_SUPPLY_HEALTH_GOOD; |
| 536 | } |
| 537 | |
| 538 | static int bat_is_present(void) |
| 539 | { |
| 540 | u8 status = ec_read_u8(BAT_STATUS2); |
| 541 | return ((status & BAT_S1_EXISTS) != 0); |
| 542 | } |
| 543 | |
| 544 | static int bat_technology(void) |
| 545 | { |
| 546 | u8 status = ec_read_u8(BAT_STATUS1); |
| 547 | |
| 548 | if (status & BAT_S1_LiION_OR_NiMH) |
| 549 | return POWER_SUPPLY_TECHNOLOGY_LION; |
| 550 | return POWER_SUPPLY_TECHNOLOGY_NiMH; |
| 551 | } |
| 552 | |
| 553 | static int bat_capacity_level(void) |
| 554 | { |
| 555 | u8 status0 = ec_read_u8(BAT_STATUS0); |
| 556 | u8 status1 = ec_read_u8(BAT_STATUS1); |
| 557 | u8 status2 = ec_read_u8(BAT_STATUS2); |
| 558 | |
| 559 | if (status0 & BAT_S0_DISCHRG_CRITICAL |
| 560 | || status1 & BAT_S1_EMPTY |
| 561 | || status2 & BAT_S2_LOW_LOW) |
| 562 | return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; |
| 563 | if (status0 & BAT_S0_LOW) |
| 564 | return POWER_SUPPLY_CAPACITY_LEVEL_LOW; |
| 565 | if (status1 & BAT_S1_FULL) |
| 566 | return POWER_SUPPLY_CAPACITY_LEVEL_FULL; |
| 567 | return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; |
| 568 | } |
| 569 | |
| 570 | static int bat_get_property(struct power_supply *psy, |
| 571 | enum power_supply_property psp, |
| 572 | union power_supply_propval *val) |
| 573 | { |
| 574 | struct compal_data *data; |
| 575 | data = container_of(psy, struct compal_data, psy); |
| 576 | |
| 577 | switch (psp) { |
| 578 | case POWER_SUPPLY_PROP_STATUS: |
| 579 | val->intval = bat_status(); |
| 580 | break; |
| 581 | case POWER_SUPPLY_PROP_HEALTH: |
| 582 | val->intval = bat_health(); |
| 583 | break; |
| 584 | case POWER_SUPPLY_PROP_PRESENT: |
| 585 | val->intval = bat_is_present(); |
| 586 | break; |
| 587 | case POWER_SUPPLY_PROP_TECHNOLOGY: |
| 588 | val->intval = bat_technology(); |
| 589 | break; |
| 590 | case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: /* THE design voltage... */ |
| 591 | val->intval = ec_read_u16(BAT_VOLTAGE_DESIGN) * 1000; |
| 592 | break; |
| 593 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: |
| 594 | val->intval = ec_read_u16(BAT_VOLTAGE_NOW) * 1000; |
| 595 | break; |
| 596 | case POWER_SUPPLY_PROP_CURRENT_NOW: |
| 597 | val->intval = ec_read_s16(BAT_CURRENT_NOW) * 1000; |
| 598 | break; |
| 599 | case POWER_SUPPLY_PROP_CURRENT_AVG: |
| 600 | val->intval = ec_read_s16(BAT_CURRENT_AVG) * 1000; |
| 601 | break; |
| 602 | case POWER_SUPPLY_PROP_POWER_NOW: |
| 603 | val->intval = ec_read_u8(BAT_POWER) * 1000000; |
| 604 | break; |
| 605 | case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: |
| 606 | val->intval = ec_read_u16(BAT_CHARGE_DESIGN) * 1000; |
| 607 | break; |
| 608 | case POWER_SUPPLY_PROP_CHARGE_NOW: |
| 609 | val->intval = ec_read_u16(BAT_CHARGE_NOW) * 1000; |
| 610 | break; |
| 611 | case POWER_SUPPLY_PROP_CAPACITY: |
| 612 | val->intval = ec_read_u8(BAT_CAPACITY); |
| 613 | break; |
| 614 | case POWER_SUPPLY_PROP_CAPACITY_LEVEL: |
| 615 | val->intval = bat_capacity_level(); |
| 616 | break; |
| 617 | /* It smees that BAT_TEMP_AVG is a (2's complement?) value showing |
| 618 | * the number of degrees, whereas BAT_TEMP is somewhat more |
| 619 | * complicated. It looks like this is a negative nember with a |
| 620 | * 100/256 divider and an offset of 222. Both were determined |
| 621 | * experimentally by comparing BAT_TEMP and BAT_TEMP_AVG. */ |
| 622 | case POWER_SUPPLY_PROP_TEMP: |
| 623 | val->intval = ((222 - (int)ec_read_u8(BAT_TEMP)) * 1000) >> 8; |
| 624 | break; |
| 625 | case POWER_SUPPLY_PROP_TEMP_AMBIENT: /* Ambient, Avg, ... same thing */ |
| 626 | val->intval = ec_read_s8(BAT_TEMP_AVG) * 10; |
| 627 | break; |
| 628 | /* Neither the model name nor manufacturer name work for me. */ |
| 629 | case POWER_SUPPLY_PROP_MODEL_NAME: |
| 630 | val->strval = data->bat_model_name; |
| 631 | break; |
| 632 | case POWER_SUPPLY_PROP_MANUFACTURER: |
| 633 | val->strval = data->bat_manufacturer_name; |
| 634 | break; |
| 635 | case POWER_SUPPLY_PROP_SERIAL_NUMBER: |
| 636 | val->strval = data->bat_serial_number; |
| 637 | break; |
| 638 | default: |
| 639 | break; |
| 640 | } |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 641 | return 0; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 645 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 646 | |
| 647 | |
| 648 | /* ============== */ |
| 649 | /* Driver Globals */ |
| 650 | /* ============== */ |
| 651 | static DEVICE_ATTR(wake_up_pme, |
| 652 | 0644, wake_up_pme_show, wake_up_pme_store); |
| 653 | static DEVICE_ATTR(wake_up_modem, |
| 654 | 0644, wake_up_modem_show, wake_up_modem_store); |
| 655 | static DEVICE_ATTR(wake_up_lan, |
| 656 | 0644, wake_up_lan_show, wake_up_lan_store); |
| 657 | static DEVICE_ATTR(wake_up_wlan, |
| 658 | 0644, wake_up_wlan_show, wake_up_wlan_store); |
| 659 | static DEVICE_ATTR(wake_up_key, |
| 660 | 0644, wake_up_key_show, wake_up_key_store); |
| 661 | static DEVICE_ATTR(wake_up_mouse, |
| 662 | 0644, wake_up_mouse_show, wake_up_mouse_store); |
| 663 | |
| 664 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, hwmon_name_show, NULL, 1); |
| 665 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, fan_show, NULL, 1); |
| 666 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, temp_cpu, NULL, 1); |
| 667 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, temp_cpu_local, NULL, 1); |
| 668 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, temp_cpu_DTS, NULL, 1); |
| 669 | static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, temp_northbridge, NULL, 1); |
| 670 | static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, temp_vga, NULL, 1); |
| 671 | static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, temp_SKIN, NULL, 1); |
| 672 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, label_cpu, NULL, 1); |
| 673 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, label_cpu_local, NULL, 1); |
| 674 | static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, label_cpu_DTS, NULL, 1); |
| 675 | static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, label_northbridge, NULL, 1); |
| 676 | static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO, label_vga, NULL, 1); |
| 677 | static SENSOR_DEVICE_ATTR(temp6_label, S_IRUGO, label_SKIN, NULL, 1); |
| 678 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, pwm_show, pwm_store, 1); |
| 679 | static SENSOR_DEVICE_ATTR(pwm1_enable, |
| 680 | S_IRUGO | S_IWUSR, pwm_enable_show, pwm_enable_store, 0); |
| 681 | |
| 682 | static struct attribute *compal_attributes[] = { |
| 683 | &dev_attr_wake_up_pme.attr, |
| 684 | &dev_attr_wake_up_modem.attr, |
| 685 | &dev_attr_wake_up_lan.attr, |
| 686 | &dev_attr_wake_up_wlan.attr, |
| 687 | &dev_attr_wake_up_key.attr, |
| 688 | &dev_attr_wake_up_mouse.attr, |
| 689 | /* Maybe put the sensor-stuff in a separate hwmon-driver? That way, |
| 690 | * the hwmon sysfs won't be cluttered with the above files. */ |
| 691 | &sensor_dev_attr_name.dev_attr.attr, |
| 692 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 693 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 694 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 695 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 696 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 697 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 698 | &sensor_dev_attr_temp4_input.dev_attr.attr, |
| 699 | &sensor_dev_attr_temp5_input.dev_attr.attr, |
| 700 | &sensor_dev_attr_temp6_input.dev_attr.attr, |
| 701 | &sensor_dev_attr_temp1_label.dev_attr.attr, |
| 702 | &sensor_dev_attr_temp2_label.dev_attr.attr, |
| 703 | &sensor_dev_attr_temp3_label.dev_attr.attr, |
| 704 | &sensor_dev_attr_temp4_label.dev_attr.attr, |
| 705 | &sensor_dev_attr_temp5_label.dev_attr.attr, |
| 706 | &sensor_dev_attr_temp6_label.dev_attr.attr, |
| 707 | NULL |
| 708 | }; |
| 709 | |
| 710 | static struct attribute_group compal_attribute_group = { |
| 711 | .attrs = compal_attributes |
| 712 | }; |
| 713 | |
| 714 | static int __devinit compal_probe(struct platform_device *); |
| 715 | static int __devexit compal_remove(struct platform_device *); |
| 716 | static struct platform_driver compal_driver = { |
| 717 | .driver = { |
| 718 | .name = DRIVER_NAME, |
| 719 | .owner = THIS_MODULE, |
| 720 | }, |
| 721 | .probe = compal_probe, |
| 722 | .remove = __devexit_p(compal_remove) |
| 723 | }; |
| 724 | |
| 725 | static enum power_supply_property compal_bat_properties[] = { |
| 726 | POWER_SUPPLY_PROP_STATUS, |
| 727 | POWER_SUPPLY_PROP_HEALTH, |
| 728 | POWER_SUPPLY_PROP_PRESENT, |
| 729 | POWER_SUPPLY_PROP_TECHNOLOGY, |
| 730 | POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, |
| 731 | POWER_SUPPLY_PROP_VOLTAGE_NOW, |
| 732 | POWER_SUPPLY_PROP_CURRENT_NOW, |
| 733 | POWER_SUPPLY_PROP_CURRENT_AVG, |
| 734 | POWER_SUPPLY_PROP_POWER_NOW, |
| 735 | POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, |
| 736 | POWER_SUPPLY_PROP_CHARGE_NOW, |
| 737 | POWER_SUPPLY_PROP_CAPACITY, |
| 738 | POWER_SUPPLY_PROP_CAPACITY_LEVEL, |
| 739 | POWER_SUPPLY_PROP_TEMP, |
| 740 | POWER_SUPPLY_PROP_TEMP_AMBIENT, |
| 741 | POWER_SUPPLY_PROP_MODEL_NAME, |
| 742 | POWER_SUPPLY_PROP_MANUFACTURER, |
| 743 | POWER_SUPPLY_PROP_SERIAL_NUMBER, |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 744 | }; |
| 745 | |
| 746 | static struct backlight_device *compalbl_device; |
| 747 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 748 | static struct platform_device *compal_device; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 749 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 750 | static struct rfkill *wifi_rfkill; |
| 751 | static struct rfkill *bt_rfkill; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 752 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | /* =================================== */ |
| 758 | /* Initialization & clean-up functions */ |
| 759 | /* =================================== */ |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 760 | |
| 761 | static int dmi_check_cb(const struct dmi_system_id *id) |
| 762 | { |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 763 | printk(KERN_INFO DRIVER_NAME": Identified laptop model '%s'\n", |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 764 | id->ident); |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 765 | extra_features = false; |
| 766 | return 0; |
| 767 | } |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 768 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 769 | static int dmi_check_cb_extra(const struct dmi_system_id *id) |
| 770 | { |
| 771 | printk(KERN_INFO DRIVER_NAME": Identified laptop model '%s', " |
| 772 | "enabling extra features\n", |
| 773 | id->ident); |
| 774 | extra_features = true; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | static struct dmi_system_id __initdata compal_dmi_table[] = { |
| 779 | { |
| 780 | .ident = "FL90/IFL90", |
| 781 | .matches = { |
| 782 | DMI_MATCH(DMI_BOARD_NAME, "IFL90"), |
| 783 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), |
| 784 | }, |
| 785 | .callback = dmi_check_cb |
| 786 | }, |
| 787 | { |
| 788 | .ident = "FL90/IFL90", |
| 789 | .matches = { |
| 790 | DMI_MATCH(DMI_BOARD_NAME, "IFL90"), |
| 791 | DMI_MATCH(DMI_BOARD_VERSION, "REFERENCE"), |
| 792 | }, |
| 793 | .callback = dmi_check_cb |
| 794 | }, |
| 795 | { |
| 796 | .ident = "FL91/IFL91", |
| 797 | .matches = { |
| 798 | DMI_MATCH(DMI_BOARD_NAME, "IFL91"), |
| 799 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), |
| 800 | }, |
| 801 | .callback = dmi_check_cb |
| 802 | }, |
| 803 | { |
| 804 | .ident = "FL92/JFL92", |
| 805 | .matches = { |
| 806 | DMI_MATCH(DMI_BOARD_NAME, "JFL92"), |
| 807 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), |
| 808 | }, |
| 809 | .callback = dmi_check_cb |
| 810 | }, |
| 811 | { |
| 812 | .ident = "FT00/IFT00", |
| 813 | .matches = { |
| 814 | DMI_MATCH(DMI_BOARD_NAME, "IFT00"), |
| 815 | DMI_MATCH(DMI_BOARD_VERSION, "IFT00"), |
| 816 | }, |
| 817 | .callback = dmi_check_cb |
| 818 | }, |
Mario Limonciello | 34325b9 | 2009-08-24 16:00:47 -0500 | [diff] [blame] | 819 | { |
| 820 | .ident = "Dell Mini 9", |
| 821 | .matches = { |
| 822 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 823 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"), |
| 824 | }, |
| 825 | .callback = dmi_check_cb |
| 826 | }, |
| 827 | { |
| 828 | .ident = "Dell Mini 10", |
| 829 | .matches = { |
| 830 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 831 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"), |
| 832 | }, |
| 833 | .callback = dmi_check_cb |
| 834 | }, |
| 835 | { |
| 836 | .ident = "Dell Mini 10v", |
| 837 | .matches = { |
| 838 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 839 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"), |
| 840 | }, |
| 841 | .callback = dmi_check_cb |
| 842 | }, |
| 843 | { |
Victor van den Elzen | c3f755e | 2010-08-15 01:19:33 +0200 | [diff] [blame^] | 844 | .ident = "Dell Mini 1012", |
| 845 | .matches = { |
| 846 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 847 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1012"), |
| 848 | }, |
| 849 | .callback = dmi_check_cb |
| 850 | }, |
| 851 | { |
Mario Limonciello | 34325b9 | 2009-08-24 16:00:47 -0500 | [diff] [blame] | 852 | .ident = "Dell Inspiron 11z", |
| 853 | .matches = { |
| 854 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 855 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"), |
| 856 | }, |
| 857 | .callback = dmi_check_cb |
| 858 | }, |
| 859 | { |
| 860 | .ident = "Dell Mini 12", |
| 861 | .matches = { |
| 862 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 863 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"), |
| 864 | }, |
| 865 | .callback = dmi_check_cb |
| 866 | }, |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 867 | { |
| 868 | .ident = "JHL90", |
| 869 | .matches = { |
| 870 | DMI_MATCH(DMI_BOARD_NAME, "JHL90"), |
| 871 | DMI_MATCH(DMI_BOARD_VERSION, "REFERENCE"), |
| 872 | }, |
| 873 | .callback = dmi_check_cb_extra |
| 874 | }, |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 875 | { } |
| 876 | }; |
| 877 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 878 | static void initialize_power_supply_data(struct compal_data *data) |
| 879 | { |
| 880 | data->psy.name = DRIVER_NAME; |
| 881 | data->psy.type = POWER_SUPPLY_TYPE_BATTERY; |
| 882 | data->psy.properties = compal_bat_properties; |
| 883 | data->psy.num_properties = ARRAY_SIZE(compal_bat_properties); |
| 884 | data->psy.get_property = bat_get_property; |
| 885 | |
| 886 | ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR, |
| 887 | data->bat_manufacturer_name, |
| 888 | BAT_MANUFACTURER_NAME_LEN); |
| 889 | data->bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN] = 0; |
| 890 | |
| 891 | ec_read_sequence(BAT_MODEL_NAME_ADDR, |
| 892 | data->bat_model_name, |
| 893 | BAT_MODEL_NAME_LEN); |
| 894 | data->bat_model_name[BAT_MODEL_NAME_LEN] = 0; |
| 895 | |
| 896 | scnprintf(data->bat_serial_number, BAT_SERIAL_NUMBER_LEN + 1, "%d", |
| 897 | ec_read_u16(BAT_SERIAL_NUMBER_ADDR)); |
| 898 | } |
| 899 | |
| 900 | static void initialize_fan_control_data(struct compal_data *data) |
| 901 | { |
| 902 | data->pwm_enable = 2; /* Keep motherboard in control for now */ |
| 903 | data->curr_pwm = 255; /* Try not to cause a CPU_on_fire exception |
| 904 | if we take over... */ |
| 905 | } |
| 906 | |
| 907 | static int setup_rfkill(void) |
| 908 | { |
| 909 | int ret; |
| 910 | |
| 911 | wifi_rfkill = rfkill_alloc("compal-wifi", &compal_device->dev, |
| 912 | RFKILL_TYPE_WLAN, &compal_rfkill_ops, |
| 913 | (void *) WIRELESS_WLAN); |
| 914 | if (!wifi_rfkill) |
| 915 | return -ENOMEM; |
| 916 | |
| 917 | ret = rfkill_register(wifi_rfkill); |
| 918 | if (ret) |
| 919 | goto err_wifi; |
| 920 | |
| 921 | bt_rfkill = rfkill_alloc("compal-bluetooth", &compal_device->dev, |
| 922 | RFKILL_TYPE_BLUETOOTH, &compal_rfkill_ops, |
| 923 | (void *) WIRELESS_BT); |
| 924 | if (!bt_rfkill) { |
| 925 | ret = -ENOMEM; |
| 926 | goto err_allocate_bt; |
| 927 | } |
| 928 | ret = rfkill_register(bt_rfkill); |
| 929 | if (ret) |
| 930 | goto err_register_bt; |
| 931 | |
| 932 | return 0; |
| 933 | |
| 934 | err_register_bt: |
| 935 | rfkill_destroy(bt_rfkill); |
| 936 | |
| 937 | err_allocate_bt: |
| 938 | rfkill_unregister(wifi_rfkill); |
| 939 | |
| 940 | err_wifi: |
| 941 | rfkill_destroy(wifi_rfkill); |
| 942 | |
| 943 | return ret; |
| 944 | } |
| 945 | |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 946 | static int __init compal_init(void) |
| 947 | { |
| 948 | int ret; |
| 949 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 950 | if (acpi_disabled) { |
| 951 | printk(KERN_ERR DRIVER_NAME": ACPI needs to be enabled for " |
| 952 | "this driver to work!\n"); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 953 | return -ENODEV; |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 954 | } |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 955 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 956 | if (!force && !dmi_check_system(compal_dmi_table)) { |
| 957 | printk(KERN_ERR DRIVER_NAME": Motherboard not recognized (You " |
| 958 | "could try the module's force-parameter)"); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 959 | return -ENODEV; |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 960 | } |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 961 | |
Thomas Renninger | 29454f1 | 2008-08-01 17:37:58 +0200 | [diff] [blame] | 962 | if (!acpi_video_backlight_support()) { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 963 | struct backlight_properties props; |
| 964 | memset(&props, 0, sizeof(struct backlight_properties)); |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 965 | props.max_brightness = BACKLIGHT_LEVEL_MAX; |
| 966 | compalbl_device = backlight_device_register(DRIVER_NAME, |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 967 | NULL, NULL, |
| 968 | &compalbl_ops, |
| 969 | &props); |
Thomas Renninger | 29454f1 | 2008-08-01 17:37:58 +0200 | [diff] [blame] | 970 | if (IS_ERR(compalbl_device)) |
| 971 | return PTR_ERR(compalbl_device); |
Thomas Renninger | 29454f1 | 2008-08-01 17:37:58 +0200 | [diff] [blame] | 972 | } |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 973 | |
| 974 | ret = platform_driver_register(&compal_driver); |
| 975 | if (ret) |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 976 | goto err_backlight; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 977 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 978 | compal_device = platform_device_alloc(DRIVER_NAME, -1); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 979 | if (!compal_device) { |
| 980 | ret = -ENOMEM; |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 981 | goto err_platform_driver; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 984 | ret = platform_device_add(compal_device); /* This calls compal_probe */ |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 985 | if (ret) |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 986 | goto err_platform_device; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 987 | |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 988 | ret = setup_rfkill(); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 989 | if (ret) |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 990 | goto err_rfkill; |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 991 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 992 | printk(KERN_INFO DRIVER_NAME": Driver "DRIVER_VERSION |
| 993 | " successfully loaded\n"); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 994 | return 0; |
| 995 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 996 | err_rfkill: |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 997 | platform_device_del(compal_device); |
| 998 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 999 | err_platform_device: |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1000 | platform_device_put(compal_device); |
| 1001 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1002 | err_platform_driver: |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1003 | platform_driver_unregister(&compal_driver); |
| 1004 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1005 | err_backlight: |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1006 | backlight_device_unregister(compalbl_device); |
| 1007 | |
| 1008 | return ret; |
| 1009 | } |
| 1010 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1011 | static int __devinit compal_probe(struct platform_device *pdev) |
| 1012 | { |
| 1013 | int err; |
| 1014 | struct compal_data *data; |
| 1015 | |
| 1016 | if (!extra_features) |
| 1017 | return 0; |
| 1018 | |
| 1019 | /* Fan control */ |
| 1020 | data = kzalloc(sizeof(struct compal_data), GFP_KERNEL); |
| 1021 | if (!data) |
| 1022 | return -ENOMEM; |
| 1023 | |
| 1024 | initialize_fan_control_data(data); |
| 1025 | |
| 1026 | err = sysfs_create_group(&pdev->dev.kobj, &compal_attribute_group); |
| 1027 | if (err) |
| 1028 | return err; |
| 1029 | |
| 1030 | data->hwmon_dev = hwmon_device_register(&pdev->dev); |
| 1031 | if (IS_ERR(data->hwmon_dev)) { |
| 1032 | err = PTR_ERR(data->hwmon_dev); |
| 1033 | sysfs_remove_group(&pdev->dev.kobj, |
| 1034 | &compal_attribute_group); |
| 1035 | kfree(data); |
| 1036 | return err; |
| 1037 | } |
| 1038 | |
| 1039 | /* Power supply */ |
| 1040 | initialize_power_supply_data(data); |
| 1041 | power_supply_register(&compal_device->dev, &data->psy); |
| 1042 | |
| 1043 | platform_set_drvdata(pdev, data); |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1048 | static void __exit compal_cleanup(void) |
| 1049 | { |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1050 | platform_device_unregister(compal_device); |
| 1051 | platform_driver_unregister(&compal_driver); |
| 1052 | backlight_device_unregister(compalbl_device); |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 1053 | rfkill_unregister(wifi_rfkill); |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 1054 | rfkill_unregister(bt_rfkill); |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1055 | rfkill_destroy(wifi_rfkill); |
Mario Limonciello | 493e914 | 2009-08-25 10:30:13 -0500 | [diff] [blame] | 1056 | rfkill_destroy(bt_rfkill); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1057 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1058 | printk(KERN_INFO DRIVER_NAME": Driver unloaded\n"); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1061 | static int __devexit compal_remove(struct platform_device *pdev) |
| 1062 | { |
| 1063 | struct compal_data *data; |
| 1064 | |
| 1065 | if (!extra_features) |
| 1066 | return 0; |
| 1067 | |
| 1068 | printk(KERN_INFO DRIVER_NAME": Unloading: resetting fan control " |
| 1069 | "to motherboard\n"); |
| 1070 | pwm_disable_control(); |
| 1071 | |
| 1072 | data = platform_get_drvdata(pdev); |
| 1073 | hwmon_device_unregister(data->hwmon_dev); |
| 1074 | power_supply_unregister(&data->psy); |
| 1075 | |
| 1076 | platform_set_drvdata(pdev, NULL); |
| 1077 | kfree(data); |
| 1078 | |
| 1079 | sysfs_remove_group(&pdev->dev.kobj, &compal_attribute_group); |
| 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
| 1084 | |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1085 | module_init(compal_init); |
| 1086 | module_exit(compal_cleanup); |
| 1087 | |
| 1088 | MODULE_AUTHOR("Cezary Jackiewicz"); |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1089 | MODULE_AUTHOR("Roald Frederickx (roald.frederickx@gmail.com)"); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1090 | MODULE_DESCRIPTION("Compal Laptop Support"); |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1091 | MODULE_VERSION(DRIVER_VERSION); |
Cezary Jackiewicz | 5411552 | 2008-06-09 16:22:22 -0700 | [diff] [blame] | 1092 | MODULE_LICENSE("GPL"); |
| 1093 | |
| 1094 | MODULE_ALIAS("dmi:*:rnIFL90:rvrIFT00:*"); |
| 1095 | MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*"); |
| 1096 | MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*"); |
| 1097 | MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*"); |
| 1098 | MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*"); |
Roald Frederickx | 9be0fcb | 2010-07-20 15:19:39 -0700 | [diff] [blame] | 1099 | MODULE_ALIAS("dmi:*:rnJHL90:rvrREFERENCE:*"); |
Mario Limonciello | 34325b9 | 2009-08-24 16:00:47 -0500 | [diff] [blame] | 1100 | MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron910:*"); |
| 1101 | MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1010:*"); |
| 1102 | MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1011:*"); |
Victor van den Elzen | c3f755e | 2010-08-15 01:19:33 +0200 | [diff] [blame^] | 1103 | MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1012:*"); |
Mario Limonciello | 34325b9 | 2009-08-24 16:00:47 -0500 | [diff] [blame] | 1104 | MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1110:*"); |
| 1105 | MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1210:*"); |