David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/plat-omap/debug-leds.c |
| 3 | * |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 4 | * Copyright 2011 by Bryan Wu <bryan.wu@canonical.com> |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 5 | * Copyright 2003 by Texas Instruments Incorporated |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 11 | |
| 12 | #include <linux/kernel.h> |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/leds.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 16 | #include <linux/io.h> |
Tony Lindgren | 4b25408 | 2012-08-30 15:37:24 -0700 | [diff] [blame] | 17 | #include <linux/platform_data/gpio-omap.h> |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 18 | #include <linux/slab.h> |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 19 | |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
| 21 | |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 22 | /* Many OMAP development platforms reuse the same "debug board"; these |
| 23 | * platforms include H2, H3, H4, and Perseus2. There are 16 LEDs on the |
| 24 | * debug board (all green), accessed through FPGA registers. |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 25 | */ |
| 26 | |
Tony Lindgren | 21d182b | 2012-10-31 14:02:46 -0700 | [diff] [blame] | 27 | /* NOTE: most boards don't have a static mapping for the FPGA ... */ |
| 28 | struct h2p2_dbg_fpga { |
| 29 | /* offset 0x00 */ |
| 30 | u16 smc91x[8]; |
| 31 | /* offset 0x10 */ |
| 32 | u16 fpga_rev; |
| 33 | u16 board_rev; |
| 34 | u16 gpio_outputs; |
| 35 | u16 leds; |
| 36 | /* offset 0x18 */ |
| 37 | u16 misc_inputs; |
| 38 | u16 lan_status; |
| 39 | u16 lan_reset; |
| 40 | u16 reserved0; |
| 41 | /* offset 0x20 */ |
| 42 | u16 ps2_data; |
| 43 | u16 ps2_ctrl; |
| 44 | /* plus also 4 rs232 ports ... */ |
| 45 | }; |
| 46 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 47 | static struct h2p2_dbg_fpga __iomem *fpga; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 48 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 49 | static u16 fpga_led_state; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 50 | |
| 51 | struct dbg_led { |
| 52 | struct led_classdev cdev; |
| 53 | u16 mask; |
| 54 | }; |
| 55 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 56 | static const struct { |
| 57 | const char *name; |
| 58 | const char *trigger; |
| 59 | } dbg_leds[] = { |
| 60 | { "dbg:d4", "heartbeat", }, |
| 61 | { "dbg:d5", "cpu0", }, |
| 62 | { "dbg:d6", "default-on", }, |
| 63 | { "dbg:d7", }, |
| 64 | { "dbg:d8", }, |
| 65 | { "dbg:d9", }, |
| 66 | { "dbg:d10", }, |
| 67 | { "dbg:d11", }, |
| 68 | { "dbg:d12", }, |
| 69 | { "dbg:d13", }, |
| 70 | { "dbg:d14", }, |
| 71 | { "dbg:d15", }, |
| 72 | { "dbg:d16", }, |
| 73 | { "dbg:d17", }, |
| 74 | { "dbg:d18", }, |
| 75 | { "dbg:d19", }, |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 78 | /* |
| 79 | * The triggers lines up below will only be used if the |
| 80 | * LED triggers are compiled in. |
| 81 | */ |
| 82 | static void dbg_led_set(struct led_classdev *cdev, |
| 83 | enum led_brightness b) |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 84 | { |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 85 | struct dbg_led *led = container_of(cdev, struct dbg_led, cdev); |
| 86 | u16 reg; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 87 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 88 | reg = __raw_readw(&fpga->leds); |
| 89 | if (b != LED_OFF) |
| 90 | reg |= led->mask; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 91 | else |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 92 | reg &= ~led->mask; |
| 93 | __raw_writew(reg, &fpga->leds); |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 96 | static enum led_brightness dbg_led_get(struct led_classdev *cdev) |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 97 | { |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 98 | struct dbg_led *led = container_of(cdev, struct dbg_led, cdev); |
| 99 | u16 reg; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 100 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 101 | reg = __raw_readw(&fpga->leds); |
| 102 | return (reg & led->mask) ? LED_FULL : LED_OFF; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 105 | static int fpga_probe(struct platform_device *pdev) |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 106 | { |
| 107 | struct resource *iomem; |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 108 | int i; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 109 | |
| 110 | iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 111 | if (!iomem) |
| 112 | return -ENODEV; |
| 113 | |
Benoit Cousson | 8de7e37 | 2012-11-12 11:44:03 +0100 | [diff] [blame] | 114 | fpga = ioremap(iomem->start, resource_size(iomem)); |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 115 | __raw_writew(0xff, &fpga->leds); |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 116 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 117 | for (i = 0; i < ARRAY_SIZE(dbg_leds); i++) { |
| 118 | struct dbg_led *led; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 119 | |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 120 | led = kzalloc(sizeof(*led), GFP_KERNEL); |
| 121 | if (!led) |
| 122 | break; |
| 123 | |
| 124 | led->cdev.name = dbg_leds[i].name; |
| 125 | led->cdev.brightness_set = dbg_led_set; |
| 126 | led->cdev.brightness_get = dbg_led_get; |
| 127 | led->cdev.default_trigger = dbg_leds[i].trigger; |
| 128 | led->mask = BIT(i); |
| 129 | |
| 130 | if (led_classdev_register(NULL, &led->cdev) < 0) { |
| 131 | kfree(led); |
| 132 | break; |
| 133 | } |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 139 | static int fpga_suspend_noirq(struct device *dev) |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 140 | { |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 141 | fpga_led_state = __raw_readw(&fpga->leds); |
| 142 | __raw_writew(0xff, &fpga->leds); |
| 143 | |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 147 | static int fpga_resume_noirq(struct device *dev) |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 148 | { |
Bryan Wu | dafbead | 2012-03-14 02:14:39 +0800 | [diff] [blame] | 149 | __raw_writew(~fpga_led_state, &fpga->leds); |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 153 | static const struct dev_pm_ops fpga_dev_pm_ops = { |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 154 | .suspend_noirq = fpga_suspend_noirq, |
| 155 | .resume_noirq = fpga_resume_noirq, |
| 156 | }; |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 157 | |
| 158 | static struct platform_driver led_driver = { |
| 159 | .driver.name = "omap_dbg_led", |
Magnus Damm | 79ee031 | 2009-07-08 13:22:04 +0200 | [diff] [blame] | 160 | .driver.pm = &fpga_dev_pm_ops, |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 161 | .probe = fpga_probe, |
David Brownell | 994c84e | 2006-12-06 17:14:03 -0800 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | static int __init fpga_init(void) |
| 165 | { |
| 166 | if (machine_is_omap_h4() |
| 167 | || machine_is_omap_h3() |
| 168 | || machine_is_omap_h2() |
| 169 | || machine_is_omap_perseus2() |
| 170 | ) |
| 171 | return platform_driver_register(&led_driver); |
| 172 | return 0; |
| 173 | } |
| 174 | fs_initcall(fpga_init); |