From: Tony Lindgren <tony@atomide.com>
To: linux-kernel@vger.kernel.org
Cc: Tony Lindgren <tony@atomide.com>
Subject: [PATCH 4/14] ARM: OMAP: Register tsc2102 on Palm Tungsten E
Date: Mon, 9 Apr 2007 17:28:29 -0400 [thread overview]
Message-ID: <117615414325-git-send-email-tony@atomide.com> (raw)
In-Reply-To: <1176154139299-git-send-email-tony@atomide.com>
From: Andrzej Zaborowski <balrog@zabor.org>
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>
---
arch/arm/mach-omap1/board-palmte.c | 123 ++++++++++++++++++++++++++++++++++++
1 files changed, 123 insertions(+), 0 deletions(-)
--- a/arch/arm/mach-omap1/board-palmte.c
+++ b/arch/arm/mach-omap1/board-palmte.c
@@ -321,6 +321,116 @@ static struct tsc2102_config palmte_tsc2102_config = {
.alsa_config = &palmte_alsa_config,
};
+static struct omap_mcbsp_reg_cfg palmte_mcbsp1_regs = {
+ .spcr2 = FRST | GRST | XRST | XINTM(3),
+ .xcr2 = XDATDLY(1) | XFIG,
+ .xcr1 = XWDLEN1(OMAP_MCBSP_WORD_32),
+ .pcr0 = SCLKME | FSXP | CLKXP,
+};
+
+static struct omap_alsa_codec_config palmte_alsa_config = {
+ .name = "TSC2102 audio",
+ .mcbsp_regs_alsa = &palmte_mcbsp1_regs,
+ .codec_configure_dev = NULL, /* tsc2102_configure, */
+ .codec_set_samplerate = NULL, /* tsc2102_set_samplerate, */
+ .codec_clock_setup = NULL, /* tsc2102_clock_setup, */
+ .codec_clock_on = NULL, /* tsc2102_clock_on, */
+ .codec_clock_off = NULL, /* tsc2102_clock_off, */
+ .get_default_samplerate = NULL, /* tsc2102_get_default_samplerate, */
+};
+
+#ifdef CONFIG_APM
+/*
+ * Values measured in 10 minute intervals averaged over 10 samples.
+ * May differ slightly from device to device but should be accurate
+ * enough to give basic idea of battery life left and trigger
+ * potential alerts.
+ */
+static const int palmte_battery_sample[] = {
+ 2194, 2157, 2138, 2120,
+ 2104, 2089, 2075, 2061,
+ 2048, 2038, 2026, 2016,
+ 2008, 1998, 1989, 1980,
+ 1970, 1958, 1945, 1928,
+ 1910, 1888, 1860, 1827,
+ 1791, 1751, 1709, 1656,
+};
+
+#define INTERVAL 10
+#define BATTERY_HIGH_TRESHOLD 66
+#define BATTERY_LOW_TRESHOLD 33
+
+static void palmte_get_power_status(struct apm_power_info *info, int *battery)
+{
+ int charging, batt, hi, lo, mid;
+
+ charging = !omap_get_gpio_datain(PALMTE_DC_GPIO);
+ batt = battery[0];
+ if (charging)
+ batt -= 60;
+
+ hi = ARRAY_SIZE(palmte_battery_sample);
+ lo = 0;
+
+ info->battery_flag = 0;
+ info->units = APM_UNITS_MINS;
+
+ if (batt > palmte_battery_sample[lo]) {
+ info->battery_life = 100;
+ info->time = INTERVAL * ARRAY_SIZE(palmte_battery_sample);
+ } else if (batt <= palmte_battery_sample[hi - 1]) {
+ info->battery_life = 0;
+ info->time = 0;
+ } else {
+ while (hi > lo + 1) {
+ mid = (hi + lo) >> 2;
+ if (batt <= palmte_battery_sample[mid])
+ lo = mid;
+ else
+ hi = mid;
+ }
+
+ mid = palmte_battery_sample[lo] - palmte_battery_sample[hi];
+ hi = palmte_battery_sample[lo] - batt;
+ info->battery_life = 100 - (100 * lo + 100 * hi / mid) /
+ ARRAY_SIZE(palmte_battery_sample);
+ info->time = INTERVAL * (ARRAY_SIZE(palmte_battery_sample) -
+ lo) - INTERVAL * hi / mid;
+ }
+
+ if (charging) {
+ info->ac_line_status = APM_AC_ONLINE;
+ info->battery_status = APM_BATTERY_STATUS_CHARGING;
+ info->battery_flag |= APM_BATTERY_FLAG_CHARGING;
+ } else {
+ info->ac_line_status = APM_AC_OFFLINE;
+ if (info->battery_life > BATTERY_HIGH_TRESHOLD)
+ info->battery_status = APM_BATTERY_STATUS_HIGH;
+ else if (info->battery_life > BATTERY_LOW_TRESHOLD)
+ info->battery_status = APM_BATTERY_STATUS_LOW;
+ else
+ info->battery_status = APM_BATTERY_STATUS_CRITICAL;
+ }
+
+ if (info->battery_life > BATTERY_HIGH_TRESHOLD)
+ info->battery_flag |= APM_BATTERY_FLAG_HIGH;
+ else if (info->battery_life > BATTERY_LOW_TRESHOLD)
+ info->battery_flag |= APM_BATTERY_FLAG_LOW;
+ else
+ info->battery_flag |= APM_BATTERY_FLAG_CRITICAL;
+}
+#else
+#define palmte_get_power_status NULL
+#endif
+
+static struct tsc2102_config palmte_tsc2102_config = {
+ .use_internal = 0,
+ .monitor = TSC_BAT1 | TSC_AUX | TSC_TEMP,
+ .temp_at25c = { 2200, 2615 },
+ .apm_report = palmte_get_power_status,
+ .alsa_config = &palmte_alsa_config,
+};
+
static struct omap_board_config_kernel palmte_config[] = {
{ OMAP_TAG_USB, &palmte_usb_config },
{ OMAP_TAG_MMC, &palmte_mmc_config },
@@ -339,6 +449,17 @@ static struct spi_board_info palmte_spi_info[] __initdata = {
},
};
+static struct spi_board_info palmte_spi_info[] __initdata = {
+ {
+ .modalias = "tsc2102",
+ .bus_num = 2, /* uWire (officially) */
+ .chip_select = 0, /* As opposed to 3 */
+ .irq = OMAP_GPIO_IRQ(PALMTE_PINTDAV_GPIO),
+ .platform_data = &palmte_tsc2102_config,
+ .max_speed_hz = 8000000,
+ },
+};
+
/* Periodically check for changes on important input pins */
struct timer_list palmte_pin_timer;
int prev_power, prev_headphones;
@@ -418,6 +539,8 @@ static void __init omap_palmte_init(void)
spi_register_board_info(palmte_spi_info, ARRAY_SIZE(palmte_spi_info));
+ spi_register_board_info(palmte_spi_info, ARRAY_SIZE(palmte_spi_info));
+
omap_serial_init();
palmte_gpio_setup();
}
--
1.4.4.2
next prev parent reply other threads:[~2007-04-09 21:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-09 21:28 [PATCH 0/14] ARM: OMAP: Board updates and additions for OMAP1 Tony Lindgren
2007-04-09 21:28 ` [PATCH 1/14] ARM: OMAP: Palm Tungsten E board update Tony Lindgren
2007-04-09 21:28 ` [PATCH 2/14] ARM: OMAP: Add support for Amstrad Delta keypad Tony Lindgren
2007-04-09 21:28 ` [PATCH 3/14] ARM: OMAP: PalmZ71 support Tony Lindgren
2007-04-09 21:28 ` Tony Lindgren [this message]
2007-04-09 21:28 ` [PATCH 5/14] ARM: OMAP: Palm Tungsten|T support Tony Lindgren
2007-04-09 21:28 ` [PATCH 6/14] ARM: OMAP: Basic support for siemens sx1 Tony Lindgren
2007-04-09 21:28 ` [PATCH 7/14] ARM: OMAP: Sync board specific files with linux-omap Tony Lindgren
2007-04-09 21:28 ` [PATCH 8/14] ARM: OMAP: Update omap h2 defconfig Tony Lindgren
2007-04-09 21:28 ` [PATCH 9/14] ARM: OMAP: Add omap osk defconfig Tony Lindgren
2007-04-09 21:28 ` [PATCH 10/14] ARM: OMAP: osk+mistral backlight, power, board specific Tony Lindgren
2007-04-09 21:28 ` [PATCH 11/14] ARM: OMAP: H3 workqueue fixes Tony Lindgren
2007-04-09 21:28 ` [PATCH 12/14] ARM: OMAP: N770: add missing LCD, LCD controller, touchscreen device registration Tony Lindgren
2007-04-09 21:28 ` [PATCH 13/14] ARM: OMAP: TSC2101: add platform init / registration to board files Tony Lindgren
2007-04-09 21:28 ` [PATCH 14/14] ARM: OMAP: H2 lcd updates for SPI framework Tony Lindgren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=117615414325-git-send-email-tony@atomide.com \
--to=tony@atomide.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox