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