1*d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
24d3cb354SRichard Purdie /*
3f30c2269SUwe Zeisberger * linux/drivers/leds/leds-locomo.c
44d3cb354SRichard Purdie *
54d3cb354SRichard Purdie * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
64d3cb354SRichard Purdie */
74d3cb354SRichard Purdie
84d3cb354SRichard Purdie #include <linux/kernel.h>
94d3cb354SRichard Purdie #include <linux/init.h>
1054f4dedbSPaul Gortmaker #include <linux/module.h>
114d3cb354SRichard Purdie #include <linux/device.h>
124d3cb354SRichard Purdie #include <linux/leds.h>
134d3cb354SRichard Purdie
144d3cb354SRichard Purdie #include <asm/hardware/locomo.h>
154d3cb354SRichard Purdie
locomoled_brightness_set(struct led_classdev * led_cdev,enum led_brightness value,int offset)164d3cb354SRichard Purdie static void locomoled_brightness_set(struct led_classdev *led_cdev,
174d3cb354SRichard Purdie enum led_brightness value, int offset)
184d3cb354SRichard Purdie {
198f115cd5SRichard Purdie struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->dev->parent);
204d3cb354SRichard Purdie unsigned long flags;
214d3cb354SRichard Purdie
224d3cb354SRichard Purdie local_irq_save(flags);
234d3cb354SRichard Purdie if (value)
244d3cb354SRichard Purdie locomo_writel(LOCOMO_LPT_TOFH, locomo_dev->mapbase + offset);
254d3cb354SRichard Purdie else
264d3cb354SRichard Purdie locomo_writel(LOCOMO_LPT_TOFL, locomo_dev->mapbase + offset);
274d3cb354SRichard Purdie local_irq_restore(flags);
284d3cb354SRichard Purdie }
294d3cb354SRichard Purdie
locomoled_brightness_set0(struct led_classdev * led_cdev,enum led_brightness value)304d3cb354SRichard Purdie static void locomoled_brightness_set0(struct led_classdev *led_cdev,
314d3cb354SRichard Purdie enum led_brightness value)
324d3cb354SRichard Purdie {
334d3cb354SRichard Purdie locomoled_brightness_set(led_cdev, value, LOCOMO_LPT0);
344d3cb354SRichard Purdie }
354d3cb354SRichard Purdie
locomoled_brightness_set1(struct led_classdev * led_cdev,enum led_brightness value)364d3cb354SRichard Purdie static void locomoled_brightness_set1(struct led_classdev *led_cdev,
374d3cb354SRichard Purdie enum led_brightness value)
384d3cb354SRichard Purdie {
394d3cb354SRichard Purdie locomoled_brightness_set(led_cdev, value, LOCOMO_LPT1);
404d3cb354SRichard Purdie }
414d3cb354SRichard Purdie
424d3cb354SRichard Purdie static struct led_classdev locomo_led0 = {
436c152beeSRichard Purdie .name = "locomo:amber:charge",
44167c55efSThomas Kunze .default_trigger = "main-battery-charging",
454d3cb354SRichard Purdie .brightness_set = locomoled_brightness_set0,
464d3cb354SRichard Purdie };
474d3cb354SRichard Purdie
484d3cb354SRichard Purdie static struct led_classdev locomo_led1 = {
496c152beeSRichard Purdie .name = "locomo:green:mail",
50b7408affSRichard Purdie .default_trigger = "nand-disk",
514d3cb354SRichard Purdie .brightness_set = locomoled_brightness_set1,
524d3cb354SRichard Purdie };
534d3cb354SRichard Purdie
locomoled_probe(struct locomo_dev * ldev)544d3cb354SRichard Purdie static int locomoled_probe(struct locomo_dev *ldev)
554d3cb354SRichard Purdie {
564d3cb354SRichard Purdie int ret;
574d3cb354SRichard Purdie
58d4398614SFida Mohammad ret = devm_led_classdev_register(&ldev->dev, &locomo_led0);
594d3cb354SRichard Purdie if (ret < 0)
604d3cb354SRichard Purdie return ret;
614d3cb354SRichard Purdie
62d4398614SFida Mohammad return devm_led_classdev_register(&ldev->dev, &locomo_led1);
634d3cb354SRichard Purdie }
644d3cb354SRichard Purdie
654d3cb354SRichard Purdie
664d3cb354SRichard Purdie static struct locomo_driver locomoled_driver = {
674d3cb354SRichard Purdie .drv = {
684d3cb354SRichard Purdie .name = "locomoled"
694d3cb354SRichard Purdie },
704d3cb354SRichard Purdie .devid = LOCOMO_DEVID_LED,
714d3cb354SRichard Purdie .probe = locomoled_probe,
724d3cb354SRichard Purdie };
734d3cb354SRichard Purdie
locomoled_init(void)744d3cb354SRichard Purdie static int __init locomoled_init(void)
754d3cb354SRichard Purdie {
764d3cb354SRichard Purdie return locomo_driver_register(&locomoled_driver);
774d3cb354SRichard Purdie }
784d3cb354SRichard Purdie module_init(locomoled_init);
794d3cb354SRichard Purdie
804d3cb354SRichard Purdie MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
814d3cb354SRichard Purdie MODULE_DESCRIPTION("Locomo LED driver");
824d3cb354SRichard Purdie MODULE_LICENSE("GPL");
83