Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
debug-leds.c
Go to the documentation of this file.
1 /*
2  * linux/arch/arm/plat-omap/debug-leds.c
3  *
4  * Copyright 2011 by Bryan Wu <[email protected]>
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  */
11 
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15 #include <linux/leds.h>
16 #include <linux/io.h>
18 #include <linux/slab.h>
19 
20 #include <mach/hardware.h>
21 #include <asm/mach-types.h>
22 
23 #include <plat/fpga.h>
24 
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.
28  */
29 
30 static struct h2p2_dbg_fpga __iomem *fpga;
31 
32 static u16 fpga_led_state;
33 
34 struct dbg_led {
37 };
38 
39 static 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", },
59 };
60 
61 /*
62  * The triggers lines up below will only be used if the
63  * LED triggers are compiled in.
64  */
65 static void dbg_led_set(struct led_classdev *cdev,
66  enum led_brightness b)
67 {
68  struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
69  u16 reg;
70 
71  reg = __raw_readw(&fpga->leds);
72  if (b != LED_OFF)
73  reg |= led->mask;
74  else
75  reg &= ~led->mask;
76  __raw_writew(reg, &fpga->leds);
77 }
78 
79 static enum led_brightness dbg_led_get(struct led_classdev *cdev)
80 {
81  struct dbg_led *led = container_of(cdev, struct dbg_led, cdev);
82  u16 reg;
83 
84  reg = __raw_readw(&fpga->leds);
85  return (reg & led->mask) ? LED_FULL : LED_OFF;
86 }
87 
88 static int fpga_probe(struct platform_device *pdev)
89 {
90  struct resource *iomem;
91  int i;
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);
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;
106 
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);
112 
113  if (led_classdev_register(NULL, &led->cdev) < 0) {
114  kfree(led);
115  break;
116  }
117  }
118 
119  return 0;
120 }
121 
122 static int fpga_suspend_noirq(struct device *dev)
123 {
124  fpga_led_state = __raw_readw(&fpga->leds);
125  __raw_writew(0xff, &fpga->leds);
126 
127  return 0;
128 }
129 
130 static int fpga_resume_noirq(struct device *dev)
131 {
132  __raw_writew(~fpga_led_state, &fpga->leds);
133  return 0;
134 }
135 
136 static const struct dev_pm_ops fpga_dev_pm_ops = {
137  .suspend_noirq = fpga_suspend_noirq,
138  .resume_noirq = fpga_resume_noirq,
139 };
140 
141 static struct platform_driver led_driver = {
142  .driver.name = "omap_dbg_led",
143  .driver.pm = &fpga_dev_pm_ops,
144  .probe = fpga_probe,
145 };
146 
147 static 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 }
157 fs_initcall(fpga_init);