Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * LEDs driver for Soekris net48xx |
| 3 | * |
| 4 | * Copyright (C) 2006 Chris Boot <bootc@bootc.net> |
| 5 | * |
| 6 | * Based on leds-ams-delta.c |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/leds.h> |
| 17 | #include <linux/err.h> |
Sachin Kamat | 6023ff7 | 2012-11-25 12:14:13 +0530 | [diff] [blame] | 18 | #include <linux/io.h> |
Chris Boot | cfedc92 | 2006-09-29 01:59:08 -0700 | [diff] [blame] | 19 | #include <linux/nsc_gpio.h> |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 20 | #include <linux/scx200_gpio.h> |
Paul Gortmaker | 54f4ded | 2011-07-03 13:56:03 -0400 | [diff] [blame] | 21 | #include <linux/module.h> |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 22 | |
Chris Boot | bca3bff | 2006-07-14 00:24:21 -0700 | [diff] [blame] | 23 | #define DRVNAME "net48xx-led" |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 24 | #define NET48XX_ERROR_LED_GPIO 20 |
| 25 | |
| 26 | static struct platform_device *pdev; |
| 27 | |
| 28 | static void net48xx_error_led_set(struct led_classdev *led_cdev, |
| 29 | enum led_brightness value) |
| 30 | { |
Chris Boot | cfedc92 | 2006-09-29 01:59:08 -0700 | [diff] [blame] | 31 | scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0); |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static struct led_classdev net48xx_error_led = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame] | 35 | .name = "net48xx::error", |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 36 | .brightness_set = net48xx_error_led_set, |
Richard Purdie | 859cb7f | 2009-01-08 17:55:03 +0000 | [diff] [blame] | 37 | .flags = LED_CORE_SUSPENDRESUME, |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 40 | static int net48xx_led_probe(struct platform_device *pdev) |
| 41 | { |
| 42 | return led_classdev_register(&pdev->dev, &net48xx_error_led); |
| 43 | } |
| 44 | |
| 45 | static int net48xx_led_remove(struct platform_device *pdev) |
| 46 | { |
| 47 | led_classdev_unregister(&net48xx_error_led); |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static struct platform_driver net48xx_led_driver = { |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 52 | .probe = net48xx_led_probe, |
| 53 | .remove = net48xx_led_remove, |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 54 | .driver = { |
Chris Boot | bca3bff | 2006-07-14 00:24:21 -0700 | [diff] [blame] | 55 | .name = DRVNAME, |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 56 | }, |
| 57 | }; |
| 58 | |
| 59 | static int __init net48xx_led_init(void) |
| 60 | { |
| 61 | int ret; |
| 62 | |
Chris Boot | cfedc92 | 2006-09-29 01:59:08 -0700 | [diff] [blame] | 63 | /* small hack, but scx200_gpio doesn't set .dev if the probe fails */ |
| 64 | if (!scx200_gpio_ops.dev) { |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 65 | ret = -ENODEV; |
| 66 | goto out; |
| 67 | } |
| 68 | |
| 69 | ret = platform_driver_register(&net48xx_led_driver); |
| 70 | if (ret < 0) |
| 71 | goto out; |
| 72 | |
Chris Boot | bca3bff | 2006-07-14 00:24:21 -0700 | [diff] [blame] | 73 | pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); |
Chris Boot | 1a87d94 | 2006-07-10 04:45:34 -0700 | [diff] [blame] | 74 | if (IS_ERR(pdev)) { |
| 75 | ret = PTR_ERR(pdev); |
| 76 | platform_driver_unregister(&net48xx_led_driver); |
| 77 | goto out; |
| 78 | } |
| 79 | |
| 80 | out: |
| 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | static void __exit net48xx_led_exit(void) |
| 85 | { |
| 86 | platform_device_unregister(pdev); |
| 87 | platform_driver_unregister(&net48xx_led_driver); |
| 88 | } |
| 89 | |
| 90 | module_init(net48xx_led_init); |
| 91 | module_exit(net48xx_led_exit); |
| 92 | |
| 93 | MODULE_AUTHOR("Chris Boot <bootc@bootc.net>"); |
| 94 | MODULE_DESCRIPTION("Soekris net48xx LED driver"); |
| 95 | MODULE_LICENSE("GPL"); |
| 96 | |