Skip to contentSkip to conversation

leds: Support for MIPS SEAD-3 controlled LEDs

PATCH Bryan Wu 1 participant 1 message May 31, 2012 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Bryan Wu

author
#1 lore raw
Quoted 4 lines · Steven J. Hill

From: "Steven J. Hill" <[email protected]>

Add driver for the two LED banks on the MIPS SEAD-3 platform.

Overall this LED driver looks very specific to MIPS board SEAD-3 and the code is not going to share with other platform. How about just adding this driver in your MIPS machine code, like I did in ARM LED consolidation work here:

http://git.kernel.org/?p=linux/kernel/git/cooloney/linux-leds.git;a=commitdiff;h=a1bebaca84560c691b7ca6c86df541f36ff87432

Quoted 65 lines

---
 drivers/leds/Kconfig      |   13 +++++
 drivers/leds/Makefile     |    1 +
 drivers/leds/leds-sead3.c |  125 +++++++++++++++++++++++++++++++++++++++++++++

 3 files changed, 139 insertions(+)

 create mode 100644 drivers/leds/leds-sead3.c

drivers/leds/Kconfig +0 -0
index ff4b8cf..3407020 100644
@@ -401,6 +401,19 @@ config LEDS_OT200

         This option enables support for the LEDs on the Bachmann OT200. Say Y to enable LEDs on the Bachmann OT200.

drivers/leds/Kconfig +13 -0
+config LEDS_SEAD3
+       tristate "LED support for MIPS SEAD-3"
+       depends on LEDS_CLASS && MIPS_SEAD3
+       help
+         This option enables support for the two LED banks on the MIPS
+         SEAD-3 platform. They are accessible via the sysfs interface:
+
+            /sys/class/leds/sead3::pled/brightness
+            /sys/class/leds/sead3::fled/brightness
+
+         To compile this driver as a module, choose M here: the
+         module will be called leds-sead3.
+

 config LEDS_TRIGGERS
       bool "LED Trigger support"
       depends on LEDS_CLASS

drivers/leds/Makefile +0 -0
index 890481c..2003fee 100644
@@ -45,6 +45,7 @@ obj-$(CONFIG_LEDS_NETXBIG)            += leds-netxbig.o

 obj-$(CONFIG_LEDS_ASIC3)               += leds-asic3.o obj-$(CONFIG_LEDS_RENESAS_TPU)         += leds-renesas-tpu.o obj-$(CONFIG_LEDS_MAX8997)             += leds-max8997.o +obj-$(CONFIG_LEDS_SEAD3)               += leds-sead3.o

 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o

drivers/leds/leds-sead3.c new file +14 -0
new file mode 100644
index 0000000..9d3d437
@@ -0,0 +1,125 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 2010-2012  MIPS Technologies, Inc.
+ *
+ * Based on leds-wrap.c
+ * Copyright (C) 2006 Kristian Kielhofner <[email protected]>
+ */
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/leds.h>

drivers/leds/leds-sead3.c line 24

Quoted 10 lines
drivers/leds/leds-sead3.c new file +10 -0
+#include <linux/platform_device.h>
+
+#define DRVNAME        "sead3-led"
+
+static struct platform_device *pdev;
+
+static void sead3_pled_set(struct led_classdev *led_cdev,
+               enum led_brightness value)
+{
+       writel(value, (void __iomem *)0xbf000210);

No idea for this address, is that a register for brightness? It's better to give a meaningful name.

drivers/leds/leds-sead3.c line 35

Quoted 11 lines
drivers/leds/leds-sead3.c new file +11 -0
+}
+
+static void sead3_fled_set(struct led_classdev *led_cdev,
+               enum led_brightness value)
+{
+       writel(value, (void __iomem *)0xbf000218);
+}
+
+static struct led_classdev sead3_pled = {
+       .name           = "sead3::pled",
+       .brightness_set = sead3_pled_set,

If you need to support suspend/resume, just add this .flags = LED_CORE_SUSPENDRESUME
And don't need following PM functions.

Quoted 93 lines
drivers/leds/leds-sead3.c new file +90 -1
+};
+
+static struct led_classdev sead3_fled = {
+       .name           = "sead3::fled",
+       .brightness_set = sead3_fled_set,
+};
+
+#ifdef CONFIG_PM
+static int sead3_led_suspend(struct platform_device *dev, pm_message_t state)
+{
+       led_classdev_suspend(&sead3_pled);
+       led_classdev_suspend(&sead3_fled);
+       return 0;
+}
+
+static int sead3_led_resume(struct platform_device *dev)
+{
+       led_classdev_resume(&sead3_pled);
+       led_classdev_resume(&sead3_fled);
+       return 0;
+}
+#else
+#define sead3_led_suspend      NULL
+#define sead3_led_resume       NULL
+#endif
+
+static int sead3_led_probe(struct platform_device *pdev)
+{
+       int ret;
+
+       ret = led_classdev_register(&pdev->dev, &sead3_pled);
+       if (ret < 0)
+               return ret;
+
+       ret = led_classdev_register(&pdev->dev, &sead3_fled);
+       if (ret < 0)
+               led_classdev_unregister(&sead3_pled);
+
+       return ret;
+}
+
+static int sead3_led_remove(struct platform_device *pdev)
+{
+       led_classdev_unregister(&sead3_pled);
+       led_classdev_unregister(&sead3_fled);
+       return 0;
+}
+
+static struct platform_driver sead3_led_driver = {
+       .driver         = {
+               .name           = DRVNAME,
+               .owner          = THIS_MODULE,
+       },
+       .probe          = sead3_led_probe,
+       .remove         = sead3_led_remove,
+       .suspend        = sead3_led_suspend,
+       .resume         = sead3_led_resume,
+};
+
+static int __init sead3_led_init(void)
+{
+       int ret;
+
+       ret = platform_driver_register(&sead3_led_driver);
+       if (ret < 0)
+               return ret;
+
+       pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
+       if (IS_ERR(pdev)) {
+               ret = PTR_ERR(pdev);
+               platform_driver_unregister(&sead3_led_driver);
+       }
+
+       return ret;
+}
+module_init(sead3_led_init);
+
+static void __exit sead3_led_exit(void)
+{
+       platform_device_unregister(pdev);
+       platform_driver_unregister(&sead3_led_driver);
+
+       sead3_pled_set(NULL, 0);
+       sead3_fled_set(NULL, 0);
+}
+module_exit(sead3_led_exit);
+
+MODULE_AUTHOR("Chris Dearman <[email protected]");
+MODULE_DESCRIPTION("SEAD-3 LED driver");
+MODULE_LICENSE("GPL");
--

1.7.10

Signature · 4 lines
Bryan Wu <[email protected]>
Kernel Developer    +86.186-168-78255 Mobile
Canonical Ltd.      www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com