Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Tony Lindgren | 7c38cf0 | 2005-09-08 23:07:38 +0100 | [diff] [blame] | 2 | * linux/arch/arm/mach-omap1/leds-h2p2-debug.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright 2003 by Texas Instruments Incorporated |
| 5 | * |
| 6 | * There are 16 LEDs on the debug board (all green); four may be used |
| 7 | * for logical 'green', 'amber', 'red', and 'blue' (after "claiming"). |
| 8 | * |
| 9 | * The "surfer" expansion board and H2 sample board also have two-color |
| 10 | * green+red LEDs (in parallel), used here for timer and idle indicators. |
| 11 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/kernel_stat.h> |
| 14 | #include <linux/sched.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 15 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 17 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/leds.h> |
| 19 | #include <asm/system.h> |
Tony Lindgren | 3179a01 | 2005-11-10 14:26:48 +0000 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 22 | #include <mach/fpga.h> |
| 23 | #include <mach/gpio.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include "leds.h" |
| 26 | |
| 27 | |
| 28 | #define GPIO_LED_RED 3 |
| 29 | #define GPIO_LED_GREEN OMAP_MPUIO(4) |
| 30 | |
| 31 | |
| 32 | #define LED_STATE_ENABLED 0x01 |
| 33 | #define LED_STATE_CLAIMED 0x02 |
| 34 | #define LED_TIMER_ON 0x04 |
| 35 | |
| 36 | #define GPIO_IDLE GPIO_LED_GREEN |
| 37 | #define GPIO_TIMER GPIO_LED_RED |
| 38 | |
| 39 | |
| 40 | void h2p2_dbg_leds_event(led_event_t evt) |
| 41 | { |
| 42 | unsigned long flags; |
| 43 | |
| 44 | static struct h2p2_dbg_fpga __iomem *fpga; |
| 45 | static u16 led_state, hw_led_state; |
| 46 | |
| 47 | local_irq_save(flags); |
| 48 | |
| 49 | if (!(led_state & LED_STATE_ENABLED) && evt != led_start) |
| 50 | goto done; |
| 51 | |
| 52 | switch (evt) { |
| 53 | case led_start: |
| 54 | if (!fpga) |
| 55 | fpga = ioremap(H2P2_DBG_FPGA_START, |
| 56 | H2P2_DBG_FPGA_SIZE); |
| 57 | if (fpga) { |
| 58 | led_state |= LED_STATE_ENABLED; |
| 59 | __raw_writew(~0, &fpga->leds); |
| 60 | } |
| 61 | break; |
| 62 | |
| 63 | case led_stop: |
| 64 | case led_halted: |
| 65 | /* all leds off during suspend or shutdown */ |
Tony Lindgren | 3179a01 | 2005-11-10 14:26:48 +0000 | [diff] [blame] | 66 | |
| 67 | if (! machine_is_omap_perseus2()) { |
| 68 | omap_set_gpio_dataout(GPIO_TIMER, 0); |
| 69 | omap_set_gpio_dataout(GPIO_IDLE, 0); |
| 70 | } |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | __raw_writew(~0, &fpga->leds); |
| 73 | led_state &= ~LED_STATE_ENABLED; |
| 74 | if (evt == led_halted) { |
| 75 | iounmap(fpga); |
| 76 | fpga = NULL; |
| 77 | } |
Tony Lindgren | 3179a01 | 2005-11-10 14:26:48 +0000 | [diff] [blame] | 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | goto done; |
| 80 | |
| 81 | case led_claim: |
| 82 | led_state |= LED_STATE_CLAIMED; |
| 83 | hw_led_state = 0; |
| 84 | break; |
| 85 | |
| 86 | case led_release: |
| 87 | led_state &= ~LED_STATE_CLAIMED; |
| 88 | break; |
| 89 | |
| 90 | #ifdef CONFIG_LEDS_TIMER |
| 91 | case led_timer: |
| 92 | led_state ^= LED_TIMER_ON; |
Tony Lindgren | 3179a01 | 2005-11-10 14:26:48 +0000 | [diff] [blame] | 93 | |
| 94 | if (machine_is_omap_perseus2()) |
| 95 | hw_led_state ^= H2P2_DBG_FPGA_P2_LED_TIMER; |
| 96 | else { |
| 97 | omap_set_gpio_dataout(GPIO_TIMER, led_state & LED_TIMER_ON); |
| 98 | goto done; |
| 99 | } |
| 100 | |
| 101 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #endif |
| 103 | |
| 104 | #ifdef CONFIG_LEDS_CPU |
| 105 | case led_idle_start: |
Tony Lindgren | 3179a01 | 2005-11-10 14:26:48 +0000 | [diff] [blame] | 106 | if (machine_is_omap_perseus2()) |
| 107 | hw_led_state |= H2P2_DBG_FPGA_P2_LED_IDLE; |
| 108 | else { |
| 109 | omap_set_gpio_dataout(GPIO_IDLE, 1); |
| 110 | goto done; |
| 111 | } |
| 112 | |
| 113 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | case led_idle_end: |
Tony Lindgren | 3179a01 | 2005-11-10 14:26:48 +0000 | [diff] [blame] | 116 | if (machine_is_omap_perseus2()) |
| 117 | hw_led_state &= ~H2P2_DBG_FPGA_P2_LED_IDLE; |
| 118 | else { |
| 119 | omap_set_gpio_dataout(GPIO_IDLE, 0); |
| 120 | goto done; |
| 121 | } |
| 122 | |
| 123 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #endif |
| 125 | |
| 126 | case led_green_on: |
| 127 | hw_led_state |= H2P2_DBG_FPGA_LED_GREEN; |
| 128 | break; |
| 129 | case led_green_off: |
| 130 | hw_led_state &= ~H2P2_DBG_FPGA_LED_GREEN; |
| 131 | break; |
| 132 | |
| 133 | case led_amber_on: |
| 134 | hw_led_state |= H2P2_DBG_FPGA_LED_AMBER; |
| 135 | break; |
| 136 | case led_amber_off: |
| 137 | hw_led_state &= ~H2P2_DBG_FPGA_LED_AMBER; |
| 138 | break; |
| 139 | |
| 140 | case led_red_on: |
| 141 | hw_led_state |= H2P2_DBG_FPGA_LED_RED; |
| 142 | break; |
| 143 | case led_red_off: |
| 144 | hw_led_state &= ~H2P2_DBG_FPGA_LED_RED; |
| 145 | break; |
| 146 | |
| 147 | case led_blue_on: |
| 148 | hw_led_state |= H2P2_DBG_FPGA_LED_BLUE; |
| 149 | break; |
| 150 | case led_blue_off: |
| 151 | hw_led_state &= ~H2P2_DBG_FPGA_LED_BLUE; |
| 152 | break; |
| 153 | |
| 154 | default: |
| 155 | break; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | /* |
| 160 | * Actually burn the LEDs |
| 161 | */ |
Tony Lindgren | 3179a01 | 2005-11-10 14:26:48 +0000 | [diff] [blame] | 162 | if (led_state & LED_STATE_ENABLED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | __raw_writew(~hw_led_state, &fpga->leds); |
| 164 | |
| 165 | done: |
| 166 | local_irq_restore(flags); |
| 167 | } |