xref: /openbmc/linux/drivers/leds/leds-net48xx.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21a87d942SChris Boot /*
31a87d942SChris Boot  * LEDs driver for Soekris net48xx
41a87d942SChris Boot  *
51a87d942SChris Boot  * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
61a87d942SChris Boot  *
71a87d942SChris Boot  * Based on leds-ams-delta.c
81a87d942SChris Boot  */
91a87d942SChris Boot 
101a87d942SChris Boot #include <linux/kernel.h>
111a87d942SChris Boot #include <linux/init.h>
121a87d942SChris Boot #include <linux/platform_device.h>
131a87d942SChris Boot #include <linux/leds.h>
141a87d942SChris Boot #include <linux/err.h>
156023ff73SSachin Kamat #include <linux/io.h>
16cfedc920SChris Boot #include <linux/nsc_gpio.h>
171a87d942SChris Boot #include <linux/scx200_gpio.h>
1854f4dedbSPaul Gortmaker #include <linux/module.h>
191a87d942SChris Boot 
20bca3bffeSChris Boot #define DRVNAME "net48xx-led"
211a87d942SChris Boot #define NET48XX_ERROR_LED_GPIO	20
221a87d942SChris Boot 
231a87d942SChris Boot static struct platform_device *pdev;
241a87d942SChris Boot 
net48xx_error_led_set(struct led_classdev * led_cdev,enum led_brightness value)251a87d942SChris Boot static void net48xx_error_led_set(struct led_classdev *led_cdev,
261a87d942SChris Boot 		enum led_brightness value)
271a87d942SChris Boot {
28cfedc920SChris Boot 	scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
291a87d942SChris Boot }
301a87d942SChris Boot 
311a87d942SChris Boot static struct led_classdev net48xx_error_led = {
326c152beeSRichard Purdie 	.name		= "net48xx::error",
331a87d942SChris Boot 	.brightness_set	= net48xx_error_led_set,
34859cb7f2SRichard Purdie 	.flags		= LED_CORE_SUSPENDRESUME,
351a87d942SChris Boot };
361a87d942SChris Boot 
net48xx_led_probe(struct platform_device * pdev)371a87d942SChris Boot static int net48xx_led_probe(struct platform_device *pdev)
381a87d942SChris Boot {
3951167623SMuhammad Falak R Wani 	return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
401a87d942SChris Boot }
411a87d942SChris Boot 
421a87d942SChris Boot static struct platform_driver net48xx_led_driver = {
431a87d942SChris Boot 	.probe		= net48xx_led_probe,
441a87d942SChris Boot 	.driver		= {
45bca3bffeSChris Boot 		.name		= DRVNAME,
461a87d942SChris Boot 	},
471a87d942SChris Boot };
481a87d942SChris Boot 
net48xx_led_init(void)491a87d942SChris Boot static int __init net48xx_led_init(void)
501a87d942SChris Boot {
511a87d942SChris Boot 	int ret;
521a87d942SChris Boot 
53cfedc920SChris Boot 	/* small hack, but scx200_gpio doesn't set .dev if the probe fails */
54cfedc920SChris Boot 	if (!scx200_gpio_ops.dev) {
551a87d942SChris Boot 		ret = -ENODEV;
561a87d942SChris Boot 		goto out;
571a87d942SChris Boot 	}
581a87d942SChris Boot 
591a87d942SChris Boot 	ret = platform_driver_register(&net48xx_led_driver);
601a87d942SChris Boot 	if (ret < 0)
611a87d942SChris Boot 		goto out;
621a87d942SChris Boot 
63bca3bffeSChris Boot 	pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
641a87d942SChris Boot 	if (IS_ERR(pdev)) {
651a87d942SChris Boot 		ret = PTR_ERR(pdev);
661a87d942SChris Boot 		platform_driver_unregister(&net48xx_led_driver);
671a87d942SChris Boot 		goto out;
681a87d942SChris Boot 	}
691a87d942SChris Boot 
701a87d942SChris Boot out:
711a87d942SChris Boot 	return ret;
721a87d942SChris Boot }
731a87d942SChris Boot 
net48xx_led_exit(void)741a87d942SChris Boot static void __exit net48xx_led_exit(void)
751a87d942SChris Boot {
761a87d942SChris Boot 	platform_device_unregister(pdev);
771a87d942SChris Boot 	platform_driver_unregister(&net48xx_led_driver);
781a87d942SChris Boot }
791a87d942SChris Boot 
801a87d942SChris Boot module_init(net48xx_led_init);
811a87d942SChris Boot module_exit(net48xx_led_exit);
821a87d942SChris Boot 
831a87d942SChris Boot MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
841a87d942SChris Boot MODULE_DESCRIPTION("Soekris net48xx LED driver");
851a87d942SChris Boot MODULE_LICENSE("GPL");
861a87d942SChris Boot 
87