Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: OMAP: Register tsc2102 on Palm Tungsten E

Add palmte board config bits for TSC2102 controlled devices. This will
enable touchscreen, audio and APM code to report battery level.

If there are other boards at some point that use a TSC2102, similar
code can be used.

Signed-off-by: Andrzej Zaborowski <balrog@zabor.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>

authored by

Andrzej Zaborowski and committed by
Tony Lindgren
cc32658c ec70e8af

+123
+123
arch/arm/mach-omap1/board-palmte.c
··· 321 321 .alsa_config = &palmte_alsa_config, 322 322 }; 323 323 324 + static struct omap_mcbsp_reg_cfg palmte_mcbsp1_regs = { 325 + .spcr2 = FRST | GRST | XRST | XINTM(3), 326 + .xcr2 = XDATDLY(1) | XFIG, 327 + .xcr1 = XWDLEN1(OMAP_MCBSP_WORD_32), 328 + .pcr0 = SCLKME | FSXP | CLKXP, 329 + }; 330 + 331 + static struct omap_alsa_codec_config palmte_alsa_config = { 332 + .name = "TSC2102 audio", 333 + .mcbsp_regs_alsa = &palmte_mcbsp1_regs, 334 + .codec_configure_dev = NULL, /* tsc2102_configure, */ 335 + .codec_set_samplerate = NULL, /* tsc2102_set_samplerate, */ 336 + .codec_clock_setup = NULL, /* tsc2102_clock_setup, */ 337 + .codec_clock_on = NULL, /* tsc2102_clock_on, */ 338 + .codec_clock_off = NULL, /* tsc2102_clock_off, */ 339 + .get_default_samplerate = NULL, /* tsc2102_get_default_samplerate, */ 340 + }; 341 + 342 + #ifdef CONFIG_APM 343 + /* 344 + * Values measured in 10 minute intervals averaged over 10 samples. 345 + * May differ slightly from device to device but should be accurate 346 + * enough to give basic idea of battery life left and trigger 347 + * potential alerts. 348 + */ 349 + static const int palmte_battery_sample[] = { 350 + 2194, 2157, 2138, 2120, 351 + 2104, 2089, 2075, 2061, 352 + 2048, 2038, 2026, 2016, 353 + 2008, 1998, 1989, 1980, 354 + 1970, 1958, 1945, 1928, 355 + 1910, 1888, 1860, 1827, 356 + 1791, 1751, 1709, 1656, 357 + }; 358 + 359 + #define INTERVAL 10 360 + #define BATTERY_HIGH_TRESHOLD 66 361 + #define BATTERY_LOW_TRESHOLD 33 362 + 363 + static void palmte_get_power_status(struct apm_power_info *info, int *battery) 364 + { 365 + int charging, batt, hi, lo, mid; 366 + 367 + charging = !omap_get_gpio_datain(PALMTE_DC_GPIO); 368 + batt = battery[0]; 369 + if (charging) 370 + batt -= 60; 371 + 372 + hi = ARRAY_SIZE(palmte_battery_sample); 373 + lo = 0; 374 + 375 + info->battery_flag = 0; 376 + info->units = APM_UNITS_MINS; 377 + 378 + if (batt > palmte_battery_sample[lo]) { 379 + info->battery_life = 100; 380 + info->time = INTERVAL * ARRAY_SIZE(palmte_battery_sample); 381 + } else if (batt <= palmte_battery_sample[hi - 1]) { 382 + info->battery_life = 0; 383 + info->time = 0; 384 + } else { 385 + while (hi > lo + 1) { 386 + mid = (hi + lo) >> 2; 387 + if (batt <= palmte_battery_sample[mid]) 388 + lo = mid; 389 + else 390 + hi = mid; 391 + } 392 + 393 + mid = palmte_battery_sample[lo] - palmte_battery_sample[hi]; 394 + hi = palmte_battery_sample[lo] - batt; 395 + info->battery_life = 100 - (100 * lo + 100 * hi / mid) / 396 + ARRAY_SIZE(palmte_battery_sample); 397 + info->time = INTERVAL * (ARRAY_SIZE(palmte_battery_sample) - 398 + lo) - INTERVAL * hi / mid; 399 + } 400 + 401 + if (charging) { 402 + info->ac_line_status = APM_AC_ONLINE; 403 + info->battery_status = APM_BATTERY_STATUS_CHARGING; 404 + info->battery_flag |= APM_BATTERY_FLAG_CHARGING; 405 + } else { 406 + info->ac_line_status = APM_AC_OFFLINE; 407 + if (info->battery_life > BATTERY_HIGH_TRESHOLD) 408 + info->battery_status = APM_BATTERY_STATUS_HIGH; 409 + else if (info->battery_life > BATTERY_LOW_TRESHOLD) 410 + info->battery_status = APM_BATTERY_STATUS_LOW; 411 + else 412 + info->battery_status = APM_BATTERY_STATUS_CRITICAL; 413 + } 414 + 415 + if (info->battery_life > BATTERY_HIGH_TRESHOLD) 416 + info->battery_flag |= APM_BATTERY_FLAG_HIGH; 417 + else if (info->battery_life > BATTERY_LOW_TRESHOLD) 418 + info->battery_flag |= APM_BATTERY_FLAG_LOW; 419 + else 420 + info->battery_flag |= APM_BATTERY_FLAG_CRITICAL; 421 + } 422 + #else 423 + #define palmte_get_power_status NULL 424 + #endif 425 + 426 + static struct tsc2102_config palmte_tsc2102_config = { 427 + .use_internal = 0, 428 + .monitor = TSC_BAT1 | TSC_AUX | TSC_TEMP, 429 + .temp_at25c = { 2200, 2615 }, 430 + .apm_report = palmte_get_power_status, 431 + .alsa_config = &palmte_alsa_config, 432 + }; 433 + 324 434 static struct omap_board_config_kernel palmte_config[] = { 325 435 { OMAP_TAG_USB, &palmte_usb_config }, 326 436 { OMAP_TAG_MMC, &palmte_mmc_config }, 327 437 { OMAP_TAG_LCD, &palmte_lcd_config }, 328 438 { OMAP_TAG_UART, &palmte_uart_config }, 439 + }; 440 + 441 + static struct spi_board_info palmte_spi_info[] __initdata = { 442 + { 443 + .modalias = "tsc2102", 444 + .bus_num = 2, /* uWire (officially) */ 445 + .chip_select = 0, /* As opposed to 3 */ 446 + .irq = OMAP_GPIO_IRQ(PALMTE_PINTDAV_GPIO), 447 + .platform_data = &palmte_tsc2102_config, 448 + .max_speed_hz = 8000000, 449 + }, 329 450 }; 330 451 331 452 static struct spi_board_info palmte_spi_info[] __initdata = { ··· 536 415 omap_board_config_size = ARRAY_SIZE(palmte_config); 537 416 538 417 platform_add_devices(devices, ARRAY_SIZE(devices)); 418 + 419 + spi_register_board_info(palmte_spi_info, ARRAY_SIZE(palmte_spi_info)); 539 420 540 421 spi_register_board_info(palmte_spi_info, ARRAY_SIZE(palmte_spi_info)); 541 422