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