| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/device.h> |
| 5 |
#include <device/pnp.h> |
| 6 |
#include <ec/acpi/ec.h> |
| 7 |
#include <option.h> |
| 8 |
#include <pc80/mc146818rtc.h> |
| 9 |
#include <halt.h> |
| 10 |
|
| 11 |
#include "ecdefs.h" |
| 12 |
#include "option_table.h" |
| 13 |
#include "ec.h" |
| 14 |
|
| 15 |
#define ITE_IT5570 0x5570 |
| 16 |
#define ITE_IT8987 0x8987 |
| 17 |
|
| 18 |
uint16_t ec_get_version(void) |
| 19 |
{ |
| 20 |
return (ec_read(ECRAM_MAJOR_VERSION) << 8) | ec_read(ECRAM_MINOR_VERSION); |
| 21 |
} |
| 22 |
|
| 23 |
static uint8_t get_cmos_value(uint32_t bit, uint32_t length) |
| 24 |
{ |
| 25 |
uint32_t byte, byte_bit; |
| 26 |
uint8_t uchar; |
| 27 |
|
| 28 |
byte = bit / 8; |
| 29 |
byte_bit = bit % 8; |
| 30 |
|
| 31 |
uchar = cmos_read(byte); |
| 32 |
uchar >>= byte_bit; |
| 33 |
|
| 34 |
return uchar & ((1U << length) - 1); |
| 35 |
} |
| 36 |
|
| 37 |
static uint8_t get_ec_value_from_option(const char *name, |
| 38 |
uint32_t fallback, |
| 39 |
const uint8_t *lut, |
| 40 |
size_t lut_size, |
| 41 |
uint32_t cmos_start_bit, |
| 42 |
uint32_t cmos_length) |
| 43 |
{ |
| 44 |
unsigned int index; |
| 45 |
|
| 46 |
if (cmos_start_bit != UINT_MAX) |
| 47 |
index = get_cmos_value(cmos_start_bit, cmos_length); |
| 48 |
else |
| 49 |
index = get_uint_option(name, fallback); |
| 50 |
|
| 51 |
if (index >= lut_size) |
| 52 |
index = fallback; |
| 53 |
return lut[index]; |
| 54 |
} |
| 55 |
|
| 56 |
static uint16_t ec_get_chip_id(unsigned int port) |
| 57 |
{ |
| 58 |
return (pnp_read_index(port, ITE_CHIPID1) << 8) | |
| 59 |
pnp_read_index(port, ITE_CHIPID2); |
| 60 |
} |
| 61 |
|
| 62 |
static void merlin_init(struct device *dev) |
| 63 |
{ |
| 64 |
if (!dev->enabled) |
| 65 |
return; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
if (dev->path.pnp.port != ITE_FIXED_ADDR) { |
| 74 |
printk(BIOS_ERR, "ITE: Incorrect ports defined in devicetree.cb.\n"); |
| 75 |
printk(BIOS_ERR, "ITE: Serious operational issues will arise.\n"); |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
const uint16_t chip_id = ec_get_chip_id(dev->path.pnp.port); |
| 80 |
|
| 81 |
if (chip_id != ITE_IT5570 && chip_id != ITE_IT8987) { |
| 82 |
printk(BIOS_ERR, "ITE: Unsupported chip ID 0x%04x.\n", chip_id); |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
const uint8_t kbl_timeout[] = { |
| 112 |
SEC_30, |
| 113 |
MIN_1, |
| 114 |
MIN_3, |
| 115 |
MIN_5, |
| 116 |
NEVER |
| 117 |
}; |
| 118 |
|
| 119 |
ec_write(ECRAM_KBL_TIMEOUT, |
| 120 |
get_ec_value_from_option("kbl_timeout", |
| 121 |
0, |
| 122 |
kbl_timeout, |
| 123 |
ARRAY_SIZE(kbl_timeout), |
| 124 |
UINT_MAX, |
| 125 |
UINT_MAX)); |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
const uint8_t fn_ctrl_swap[] = { |
| 137 |
FN_CTRL, |
| 138 |
CTRL_FN |
| 139 |
}; |
| 140 |
|
| 141 |
ec_write(ECRAM_FN_CTRL_REVERSE, |
| 142 |
get_ec_value_from_option("fn_ctrl_swap", |
| 143 |
0, |
| 144 |
fn_ctrl_swap, |
| 145 |
ARRAY_SIZE(fn_ctrl_swap), |
| 146 |
UINT_MAX, |
| 147 |
UINT_MAX)); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
const uint8_t max_charge[] = { |
| 159 |
CHARGE_100, |
| 160 |
CHARGE_80, |
| 161 |
CHARGE_60 |
| 162 |
}; |
| 163 |
|
| 164 |
if (CONFIG(EC_STARLABS_MAX_CHARGE)) |
| 165 |
ec_write(ECRAM_MAX_CHARGE, |
| 166 |
get_ec_value_from_option("max_charge", |
| 167 |
0, |
| 168 |
max_charge, |
| 169 |
ARRAY_SIZE(max_charge), |
| 170 |
UINT_MAX, |
| 171 |
UINT_MAX)); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
const uint8_t fan_mode[] = { |
| 183 |
FAN_NORMAL, |
| 184 |
FAN_AGGRESSIVE, |
| 185 |
FAN_QUIET, |
| 186 |
FAN_DISABLED |
| 187 |
}; |
| 188 |
|
| 189 |
if (CONFIG(EC_STARLABS_FAN)) |
| 190 |
ec_write(ECRAM_FAN_MODE, |
| 191 |
get_ec_value_from_option("fan_mode", |
| 192 |
0, |
| 193 |
fan_mode, |
| 194 |
ARRAY_SIZE(fan_mode), |
| 195 |
UINT_MAX, |
| 196 |
UINT_MAX)); |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
#ifdef CMOS_VLEN_fn_lock_state |
| 208 |
const uint8_t fn_lock_state[] = { |
| 209 |
UNLOCKED, |
| 210 |
LOCKED |
| 211 |
}; |
| 212 |
|
| 213 |
ec_write(ECRAM_FN_LOCK_STATE, |
| 214 |
get_ec_value_from_option("fn_lock_state", |
| 215 |
1, |
| 216 |
fn_lock_state, |
| 217 |
ARRAY_SIZE(fn_lock_state), |
| 218 |
CMOS_VSTART_fn_lock_state, |
| 219 |
CMOS_VLEN_fn_lock_state)); |
| 220 |
#endif |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
#ifdef CMOS_VSTART_trackpad_state |
| 232 |
const uint8_t trackpad_state[] = { |
| 233 |
TRACKPAD_ENABLED, |
| 234 |
TRACKPAD_DISABLED |
| 235 |
}; |
| 236 |
|
| 237 |
ec_write(ECRAM_TRACKPAD_STATE, |
| 238 |
get_ec_value_from_option("trackpad_state", |
| 239 |
0, |
| 240 |
trackpad_state, |
| 241 |
ARRAY_SIZE(trackpad_state), |
| 242 |
CMOS_VSTART_trackpad_state, |
| 243 |
CMOS_VLEN_trackpad_state)); |
| 244 |
#endif |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
#ifdef CMOS_VSTART_kbl_brightness |
| 256 |
const uint8_t kbl_brightness[] = { |
| 257 |
KBL_ON, |
| 258 |
KBL_OFF, |
| 259 |
KBL_LOW, |
| 260 |
KBL_HIGH |
| 261 |
}; |
| 262 |
|
| 263 |
ec_write(ECRAM_KBL_BRIGHTNESS, |
| 264 |
get_ec_value_from_option("kbl_brightness", |
| 265 |
CONFIG(EC_STARLABS_KBL_LEVELS) ? 2 : 0, |
| 266 |
kbl_brightness, |
| 267 |
ARRAY_SIZE(kbl_brightness), |
| 268 |
CMOS_VSTART_kbl_brightness, |
| 269 |
CMOS_VLEN_kbl_brightness)); |
| 270 |
|
| 271 |
#endif |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
ec_write(ECRAM_KBL_STATE, KBL_ENABLED); |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
const uint8_t charging_speed[] = { |
| 298 |
SPEED_1_0C, |
| 299 |
SPEED_0_5C, |
| 300 |
SPEED_0_2C |
| 301 |
}; |
| 302 |
|
| 303 |
if (CONFIG(EC_STARLABS_CHARGING_SPEED)) |
| 304 |
ec_write(ECRAM_CHARGING_SPEED, |
| 305 |
get_ec_value_from_option("charging_speed", |
| 306 |
SPEED_0_5C, |
| 307 |
charging_speed, |
| 308 |
ARRAY_SIZE(charging_speed), |
| 309 |
UINT_MAX, |
| 310 |
UINT_MAX)); |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
const uint8_t lid_switch[] = { |
| 322 |
SWITCH_ENABLED, |
| 323 |
SWITCH_DISABLED |
| 324 |
}; |
| 325 |
|
| 326 |
if (CONFIG(EC_STARLABS_LID_SWITCH)) |
| 327 |
ec_write(ECRAM_LID_SWITCH, |
| 328 |
get_ec_value_from_option("lid_switch", |
| 329 |
0, |
| 330 |
lid_switch, |
| 331 |
ARRAY_SIZE(lid_switch), |
| 332 |
UINT_MAX, |
| 333 |
UINT_MAX)); |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
const uint8_t power_led[] = { |
| 345 |
LED_NORMAL, |
| 346 |
LED_REDUCED, |
| 347 |
LED_OFF |
| 348 |
}; |
| 349 |
|
| 350 |
if (CONFIG(EC_STARLABS_POWER_LED)) |
| 351 |
ec_write(ECRAM_POWER_LED, |
| 352 |
get_ec_value_from_option("power_led", |
| 353 |
0, |
| 354 |
power_led, |
| 355 |
ARRAY_SIZE(power_led), |
| 356 |
UINT_MAX, |
| 357 |
UINT_MAX)); |
| 358 |
} |
| 359 |
|
| 360 |
static struct device_operations ops = { |
| 361 |
.init = merlin_init, |
| 362 |
.read_resources = noop_read_resources, |
| 363 |
.set_resources = noop_set_resources, |
| 364 |
}; |
| 365 |
|
| 366 |
static struct pnp_info pnp_dev_info[] = { |
| 367 |
|
| 368 |
{ NULL, ITE_SP1, PNP_IO0 | PNP_IRQ0, 0x0ff8, }, |
| 369 |
|
| 370 |
{ NULL, ITE_SP2, PNP_IO0 | PNP_IRQ0, 0x0ff8, }, |
| 371 |
|
| 372 |
{ NULL, ITE_SWUC, PNP_IO0 | PNP_IRQ0, 0xfff0, }, |
| 373 |
|
| 374 |
{ NULL, ITE_SWUC, PNP_IRQ0, }, |
| 375 |
|
| 376 |
{ NULL, ITE_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, }, |
| 377 |
|
| 378 |
{ NULL, ITE_IR, PNP_IO0 | PNP_IRQ0, 0xfff8, }, |
| 379 |
|
| 380 |
{ NULL, ITE_SMFI, PNP_IO0 | PNP_IRQ0, 0xfff0, }, |
| 381 |
|
| 382 |
{ NULL, ITE_RTCT, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IO3 | PNP_IRQ0, |
| 383 |
0xfffe, 0xfffe, 0xfffe, 0xfffe, }, |
| 384 |
|
| 385 |
{ NULL, ITE_PMC1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, }, |
| 386 |
|
| 387 |
{ NULL, ITE_PMC2, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IRQ0, 0x07fc, |
| 388 |
0x07fc, 0xfff0, }, |
| 389 |
|
| 390 |
{ NULL, ITE_SSPI, PNP_IO0 | PNP_IRQ0, 0xfff8, }, |
| 391 |
|
| 392 |
{ NULL, ITE_PECI, PNP_IRQ0, 0xfff8, }, |
| 393 |
|
| 394 |
{ NULL, ITE_PMC3, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, }, |
| 395 |
|
| 396 |
{ NULL, ITE_PMC4, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, }, |
| 397 |
|
| 398 |
{ NULL, ITE_PMC5, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, }, |
| 399 |
}; |
| 400 |
|
| 401 |
static void enable_dev(struct device *dev) |
| 402 |
{ |
| 403 |
pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 404 |
} |
| 405 |
|
| 406 |
struct chip_operations ec_starlabs_merlin_ops = { |
| 407 |
.name = "ITE EC", |
| 408 |
.enable_dev = enable_dev |
| 409 |
}; |