All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Vašut" <marek.vasut@gmail.com>
To: linux-omap-open-source@linux.omap.com
Subject: [PATCH] ARM: OMAP: PalmZ71 MPUIO monitoring
Date: Sun, 12 Nov 2006 19:34:43 +0100	[thread overview]
Message-ID: <200611121934.43701.marek.vasut@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 273 bytes --]

Hi,

I´ve added some code from board-palmte.c to board-palmz71.c . This code 
monitors the status of power cable and headphones (plugged/unplugged). I´ve 
also added a few new gpio definitions to board-palmz71.h .

Signed-off-by: Marek Vašut <marek.vasut@gmail.com>

[-- Attachment #2: palmz71-power-and-headphones-monitor.patch --]
[-- Type: text/x-diff, Size: 5901 bytes --]

diff -Naur linux-omap-current/arch/arm/mach-omap1/board-palmz71.c linux-omap/arch/arm/mach-omap1/board-palmz71.c
--- linux-omap-current/arch/arm/mach-omap1/board-palmz71.c	2006-11-12 11:24:41.000000000 +0100
+++ linux-omap/arch/arm/mach-omap1/board-palmz71.c	2006-11-12 14:35:03.000000000 +0100
@@ -272,9 +272,8 @@
 static struct omap_mmc_config palmz71_mmc_config __initdata = {
 	.mmc[0] = {
 		.enabled	= 1,
-		.wire4		= 0,
 		.wp_pin		= PALMZ71_MMC_WP_GPIO,
-		.power_pin	= -1,
+		.power_pin	= PALMZ71_MMC_POWER_GPIO,
 		.switch_pin	= PALMZ71_MMC_IN_GPIO,
 	},
 };
@@ -294,21 +293,6 @@
 	{OMAP_TAG_UART,	&palmz71_uart_config},
 };
 
-static irqreturn_t
-palmz71_powercable(int irq, void *dev_id, struct pt_regs *regs)
-{
-	if (omap_get_gpio_datain(PALMZ71_USBDETECT_GPIO)) {
-		printk(KERN_INFO "PM: Power cable connected\n");
-		set_irq_type(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO),
-				IRQT_FALLING);
-	} else {
-		printk(KERN_INFO "PM: Power cable disconnected\n");
-		set_irq_type(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO),
-				IRQT_RISING);
-	}
-	return IRQ_HANDLED;
-}
-
 static void __init
 omap_mpu_wdt_mode(int mode)
 {
@@ -320,40 +304,81 @@
 	}
 }
 
-static void __init
-palmz71_gpio_setup(int early)
+/* Periodically check for changes on important input pins */
+struct timer_list palmz71_pin_timer;
+int prev_power, prev_headphones;
+
+static void palmz71_pin_handler(unsigned long data) {
+	int power, headphones;
+	
+        power = !omap_get_gpio_datain(PALMZ71_CABLE_GPIO);
+	headphones = omap_get_gpio_datain(PALMZ71_HEADPHONES_GPIO);
+
+        if (power && !prev_power)
+		printk(KERN_INFO "PM: cable connected\n");
+	else if (!power && prev_power)
+		printk(KERN_INFO "PM: cable disconnected\n");
+
+	if (headphones && !prev_headphones) {
+    		/* Headphones connected, disable speaker */
+		omap_set_gpio_dataout(PALMZ71_SPEAKER_GPIO, 0);
+		printk(KERN_INFO "PM: speaker off\n");
+        } else if (!headphones && prev_headphones) {
+		/* Headphones unplugged, re-enable speaker */
+		omap_set_gpio_dataout(PALMZ71_SPEAKER_GPIO, 1);
+		printk(KERN_INFO "PM: speaker on\n");
+	}
+
+	prev_power = power;
+	prev_headphones = headphones;
+	mod_timer(&palmz71_pin_timer, jiffies + msecs_to_jiffies(500));
+}
+
+static void __init palmz71_gpio_setup(void)
 {
-	if (early) {
-		/* Only set GPIO1 so we have a working serial */
-		omap_set_gpio_dataout(1, 1);
-		omap_set_gpio_direction(1, 0);
-	} else {
-		/* Set MMC/SD host WP pin as input */
-		if (omap_request_gpio(PALMZ71_MMC_WP_GPIO)) {
-			printk(KERN_ERR "Could not reserve WP GPIO!\n");
-			return;
-		}
-		omap_set_gpio_direction(PALMZ71_MMC_WP_GPIO, 1);
-
-		/* Monitor the Power-cable-connected signal */
-		if (omap_request_gpio(PALMZ71_USBDETECT_GPIO)) {
-			printk(KERN_ERR
-				"Could not reserve cable signal GPIO!\n");
-			return;
-		}
-		omap_set_gpio_direction(PALMZ71_USBDETECT_GPIO, 1);
-		if (request_irq(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO),
-		    palmz71_powercable, SA_SAMPLE_RANDOM, "palmz71-cable", 0))
-			printk(KERN_ERR
-				"IRQ request for power cable failed!\n");
-		palmz71_powercable(OMAP_GPIO_IRQ(PALMZ71_USBDETECT_GPIO), 0, 0);
+	/* Monitor cable-connected signals */
+	if (omap_request_gpio(PALMZ71_CABLE_GPIO) ||
+    	    omap_request_gpio(PALMZ71_USBDETECT_GPIO)) {
+		printk(KERN_ERR "Could not reserve cable signal GPIO!\n");
+		return;
+	}
+	omap_set_gpio_direction(PALMZ71_CABLE_GPIO, 1);
+	omap_set_gpio_direction(PALMZ71_USBDETECT_GPIO, 1);
+
+        /* Set speaker-enable pin as output */
+	if (omap_request_gpio(PALMZ71_SPEAKER_GPIO)) {
+		printk(KERN_ERR "Could not reserve speaker GPIO!\n");
+		return;
+        }
+	omap_set_gpio_direction(PALMZ71_SPEAKER_GPIO, 0);
+
+        /* Monitor the headphones-connected signal */
+	if (omap_request_gpio(PALMZ71_HEADPHONES_GPIO)) {
+    		printk(KERN_ERR "Could not reserve headphones signal GPIO!\n");
+		return;
+        }
+        omap_set_gpio_direction(PALMZ71_HEADPHONES_GPIO, 1);
+
+	prev_power = omap_get_gpio_datain(PALMZ71_CABLE_GPIO);
+        prev_headphones = !omap_get_gpio_datain(PALMZ71_HEADPHONES_GPIO);
+	setup_timer(&palmz71_pin_timer, palmz71_pin_handler, 0);
+        palmz71_pin_handler(0);
+}
+
+static void palmz71_serial_setup(void) {
+	/* Set GPIO1 so we have a working serial */
+	if (omap_request_gpio(PALMZ71_SERIAL_GPIO)) {
+	    printk(KERN_ERR "Could not reserve serial power GPIO!\n");
+	    return;
 	}
+	omap_set_gpio_dataout(PALMZ71_SERIAL_GPIO, 1);
+	omap_set_gpio_direction(PALMZ71_SERIAL_GPIO, 0);
 }
 
 static void __init
 omap_palmz71_init(void)
 {
-	palmz71_gpio_setup(1);
+	palmz71_serial_setup();
 	omap_mpu_wdt_mode(0);
 
 	omap_board_config = palmz71_config;
@@ -364,7 +389,7 @@
 	spi_register_board_info(palmz71_boardinfo,
 				ARRAY_SIZE(palmz71_boardinfo));
 	omap_serial_init();
-	palmz71_gpio_setup(0);
+	palmz71_gpio_setup();
 }
 
 static void __init
diff -Naur linux-omap-current/include/asm-arm/arch-omap/board-palmz71.h linux-omap/include/asm-arm/arch-omap/board-palmz71.h
--- linux-omap-current/include/asm-arm/arch-omap/board-palmz71.h	2006-11-12 11:25:08.000000000 +0100
+++ linux-omap/include/asm-arm/arch-omap/board-palmz71.h	2006-11-12 14:32:54.000000000 +0100
@@ -13,14 +13,23 @@
 #ifndef __OMAP_BOARD_PALMZ71_H
 #define __OMAP_BOARD_PALMZ71_H
 
+#include <asm/arch/gpio.h>
+
 #define PALMZ71_USBDETECT_GPIO	0
+#define PALMZ71_SERIAL_GPIO	1
 #define PALMZ71_PENIRQ_GPIO	6
 #define PALMZ71_MMC_WP_GPIO	8
+#define PALMZ71_MMC_POWER_GPIO	9
 #define PALMZ71_HDQ_GPIO 	11
+#define PALMZ71_HEADPHONES_GPIO	14
+#define PALMZ71_SPEAKER_GPIO	15
 
 #define PALMZ71_HOTSYNC_GPIO	OMAP_MPUIO(1)
 #define PALMZ71_CABLE_GPIO	OMAP_MPUIO(2)
 #define PALMZ71_SLIDER_GPIO	OMAP_MPUIO(3)
 #define PALMZ71_MMC_IN_GPIO	OMAP_MPUIO(4)
+#define PALMZ71_MMC1_GPIO	OMAP_MPUIO(6)
+#define PALMZ71_MMC2_GPIO	OMAP_MPUIO(7)
+#define PALMZ71_MMC3_GPIO	OMAP_MPUIO(11)
 
 #endif	/* __OMAP_BOARD_PALMZ71_H */

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



             reply	other threads:[~2006-11-12 18:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-12 18:34 Marek Vašut [this message]
2006-11-17 22:35 ` [PATCH] ARM: OMAP: PalmZ71 MPUIO monitoring 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=200611121934.43701.marek.vasut@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=linux-omap-open-source@linux.omap.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.