From 6b9d9c67e5e14c35e82d4dc8d16554f0c1aeedc3 Mon Sep 17 00:00:00 2001
From: David Brownell <david-b@pacbell.net>
Date: Mon, 23 Jul 2007 19:50:09 -0700
Subject: [PATCH -mm 3/3] ATSTK1000 PWM LED glue

This sets up a PWM led device for the STK1000.  To use it, make sure SW3
is in the default position and connect some long jumpers from J29 pins 13
(pwm2) and/or 16 (pwm3) to some unused LED pins.

Note that the PWM labels on the STK1002 SW3 refer to whether those signals
go to the PCI connector.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
---
 arch/avr32/boards/atstk1000/atstk1002.c |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
index 000eb42..0f3ade2 100644
--- a/arch/avr32/boards/atstk1000/atstk1002.c
+++ b/arch/avr32/boards/atstk1000/atstk1002.c
@@ -11,6 +11,7 @@
 #include <linux/etherdevice.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/leds.h>
 #include <linux/platform_device.h>
 #include <linux/string.h>
 #include <linux/types.h>
@@ -186,6 +187,29 @@ void __init setup_board(void)
 	at32_setup_serial_console(0);
 }
 
+#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
+
+static struct gpio_led stk_pwm_led[] = {
+	/* here the "gpio" is actually a PWM channel */
+	{ .name = "pwm2",     .gpio = 2, },
+	{ .name = "pwm3",     .gpio = 3, },
+};
+
+static struct gpio_led_platform_data stk_pwm_led_data = {
+	.num_leds	= ARRAY_SIZE(stk_pwm_led),
+	.leds		= stk_pwm_led,
+};
+
+static struct platform_device stk_pwm_led_dev = {
+	.name		= "leds-atmel-pwm",
+	.id		= -1,
+	.dev		= {
+		.platform_data	= &stk_pwm_led_data,
+	},
+};
+
+#endif
+
 static int __init atstk1002_init(void)
 {
 	/*
@@ -237,6 +261,12 @@ static int __init atstk1002_init(void)
 	at32_add_device_usba(0, NULL);
 #ifndef CONFIG_BOARD_ATSTK100X_SW3_CUSTOM
 	at32_add_device_ssc(0, ATMEL_SSC_TX);
+
+	/* PWM2 and PWM3 are on J29 pins 13 and 16; they would
+	 * be the RX side of SSC0, if this board used it.
+	 */
+	at32_add_device_pwm((1 << 3) | (1 << 2));
+	platform_device_register(&stk_pwm_led_dev);
 #endif
 
 	atstk1000_setup_j2_leds();
-- 
1.5.3.8

