ARM: OMAP1: Remove relative includes
[deliverable/linux.git] / arch / arm / plat-omap / debug-leds.c
CommitLineData
994c84ea
DB
1/*
2 * linux/arch/arm/plat-omap/debug-leds.c
3 *
dafbeadf 4 * Copyright 2011 by Bryan Wu <bryan.wu@canonical.com>
994c84ea
DB
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 */
dafbeadf
BW
11
12#include <linux/kernel.h>
994c84ea
DB
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/leds.h>
fced80c7 16#include <linux/io.h>
4b25408f 17#include <linux/platform_data/gpio-omap.h>
dafbeadf 18#include <linux/slab.h>
994c84ea 19
a09e64fb 20#include <mach/hardware.h>
994c84ea
DB
21#include <asm/mach-types.h>
22
4c98dc6b 23#include "fpga.h"
994c84ea 24
994c84ea
DB
25/* Many OMAP development platforms reuse the same "debug board"; these
26 * platforms include H2, H3, H4, and Perseus2. There are 16 LEDs on the
27 * debug board (all green), accessed through FPGA registers.
994c84ea
DB
28 */
29
dafbeadf 30static struct h2p2_dbg_fpga __iomem *fpga;
994c84ea 31
dafbeadf 32static u16 fpga_led_state;
994c84ea
DB
33
34struct dbg_led {
35 struct led_classdev cdev;
36 u16 mask;
37};
38
dafbeadf
BW
39static const struct {
40 const char *name;
41 const char *trigger;
42} dbg_leds[] = {
43 { "dbg:d4", "heartbeat", },
44 { "dbg:d5", "cpu0", },
45 { "dbg:d6", "default-on", },
46 { "dbg:d7", },
47 { "dbg:d8", },
48 { "dbg:d9", },
49 { "dbg:d10", },
50 { "dbg:d11", },
51 { "dbg:d12", },
52 { "dbg:d13", },
53 { "dbg:d14", },
54 { "dbg:d15", },
55 { "dbg:d16", },
56 { "dbg:d17", },
57 { "dbg:d18", },
58 { "dbg:d19", },
994c84ea
DB
59};
60
dafbeadf
BW
61/*
62 * The triggers lines up below will only be used if the
63 * LED triggers are compiled in.
64 */
65static void dbg_led_set(struct led_classdev *cdev,
66 enum led_brightness b)
994c84ea 67{
dafbeadf
BW
68 struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
69 u16 reg;
994c84ea 70
dafbeadf
BW
71 reg = __raw_readw(&fpga->leds);
72 if (b != LED_OFF)
73 reg |= led->mask;
994c84ea 74 else
dafbeadf
BW
75 reg &= ~led->mask;
76 __raw_writew(reg, &fpga->leds);
994c84ea
DB
77}
78
dafbeadf 79static enum led_brightness dbg_led_get(struct led_classdev *cdev)
994c84ea 80{
dafbeadf
BW
81 struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
82 u16 reg;
994c84ea 83
dafbeadf
BW
84 reg = __raw_readw(&fpga->leds);
85 return (reg & led->mask) ? LED_FULL : LED_OFF;
994c84ea
DB
86}
87
dafbeadf 88static int fpga_probe(struct platform_device *pdev)
994c84ea
DB
89{
90 struct resource *iomem;
dafbeadf 91 int i;
994c84ea
DB
92
93 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
94 if (!iomem)
95 return -ENODEV;
96
97 fpga = ioremap(iomem->start, H2P2_DBG_FPGA_SIZE);
dafbeadf
BW
98 __raw_writew(0xff, &fpga->leds);
99
100 for (i = 0; i < ARRAY_SIZE(dbg_leds); i++) {
101 struct dbg_led *led;
102
103 led = kzalloc(sizeof(*led), GFP_KERNEL);
104 if (!led)
105 break;
994c84ea 106
dafbeadf
BW
107 led->cdev.name = dbg_leds[i].name;
108 led->cdev.brightness_set = dbg_led_set;
109 led->cdev.brightness_get = dbg_led_get;
110 led->cdev.default_trigger = dbg_leds[i].trigger;
111 led->mask = BIT(i);
994c84ea 112
dafbeadf
BW
113 if (led_classdev_register(NULL, &led->cdev) < 0) {
114 kfree(led);
115 break;
116 }
994c84ea
DB
117 }
118
119 return 0;
120}
121
79ee031f 122static int fpga_suspend_noirq(struct device *dev)
994c84ea 123{
dafbeadf
BW
124 fpga_led_state = __raw_readw(&fpga->leds);
125 __raw_writew(0xff, &fpga->leds);
126
994c84ea
DB
127 return 0;
128}
129
79ee031f 130static int fpga_resume_noirq(struct device *dev)
994c84ea 131{
dafbeadf 132 __raw_writew(~fpga_led_state, &fpga->leds);
994c84ea
DB
133 return 0;
134}
135
47145210 136static const struct dev_pm_ops fpga_dev_pm_ops = {
79ee031f
MD
137 .suspend_noirq = fpga_suspend_noirq,
138 .resume_noirq = fpga_resume_noirq,
139};
994c84ea
DB
140
141static struct platform_driver led_driver = {
142 .driver.name = "omap_dbg_led",
79ee031f 143 .driver.pm = &fpga_dev_pm_ops,
994c84ea 144 .probe = fpga_probe,
994c84ea
DB
145};
146
147static int __init fpga_init(void)
148{
149 if (machine_is_omap_h4()
150 || machine_is_omap_h3()
151 || machine_is_omap_h2()
152 || machine_is_omap_perseus2()
153 )
154 return platform_driver_register(&led_driver);
155 return 0;
156}
157fs_initcall(fpga_init);
This page took 0.477522 seconds and 5 git commands to generate.