Thomas Gleixner | 1621633 | 2019-05-19 15:51:31 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 2 | /* |
| 3 | * LEDs driver for the Cobalt Raq series. |
| 4 | * |
Yoichi Yuasa | ada8e95 | 2009-07-03 00:39:38 +0900 | [diff] [blame] | 5 | * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org> |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/io.h> |
| 9 | #include <linux/ioport.h> |
| 10 | #include <linux/leds.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/types.h> |
Paul Gortmaker | d131c49 | 2011-07-10 12:24:44 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 15 | |
| 16 | #define LED_WEB 0x04 |
| 17 | #define LED_POWER_OFF 0x08 |
| 18 | |
| 19 | static void __iomem *led_port; |
| 20 | static u8 led_value; |
| 21 | static DEFINE_SPINLOCK(led_value_lock); |
| 22 | |
| 23 | static void raq_web_led_set(struct led_classdev *led_cdev, |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 24 | enum led_brightness brightness) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 25 | { |
| 26 | unsigned long flags; |
| 27 | |
| 28 | spin_lock_irqsave(&led_value_lock, flags); |
| 29 | |
| 30 | if (brightness) |
| 31 | led_value |= LED_WEB; |
| 32 | else |
| 33 | led_value &= ~LED_WEB; |
| 34 | writeb(led_value, led_port); |
| 35 | |
| 36 | spin_unlock_irqrestore(&led_value_lock, flags); |
| 37 | } |
| 38 | |
| 39 | static struct led_classdev raq_web_led = { |
Olaf Hering | db3f520 | 2009-09-07 14:37:27 +0100 | [diff] [blame] | 40 | .name = "raq::web", |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 41 | .brightness_set = raq_web_led_set, |
| 42 | }; |
| 43 | |
| 44 | static void raq_power_off_led_set(struct led_classdev *led_cdev, |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 45 | enum led_brightness brightness) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 46 | { |
| 47 | unsigned long flags; |
| 48 | |
| 49 | spin_lock_irqsave(&led_value_lock, flags); |
| 50 | |
| 51 | if (brightness) |
| 52 | led_value |= LED_POWER_OFF; |
| 53 | else |
| 54 | led_value &= ~LED_POWER_OFF; |
| 55 | writeb(led_value, led_port); |
| 56 | |
| 57 | spin_unlock_irqrestore(&led_value_lock, flags); |
| 58 | } |
| 59 | |
| 60 | static struct led_classdev raq_power_off_led = { |
Olaf Hering | db3f520 | 2009-09-07 14:37:27 +0100 | [diff] [blame] | 61 | .name = "raq::power-off", |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 62 | .brightness_set = raq_power_off_led_set, |
| 63 | .default_trigger = "power-off", |
| 64 | }; |
| 65 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 66 | static int cobalt_raq_led_probe(struct platform_device *pdev) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 67 | { |
| 68 | struct resource *res; |
| 69 | int retval; |
| 70 | |
| 71 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 72 | if (!res) |
| 73 | return -EBUSY; |
| 74 | |
Jingoo Han | 50e5194 | 2012-10-23 05:20:50 -0700 | [diff] [blame] | 75 | led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 76 | if (!led_port) |
| 77 | return -ENOMEM; |
| 78 | |
| 79 | retval = led_classdev_register(&pdev->dev, &raq_power_off_led); |
| 80 | if (retval) |
Jingoo Han | 50e5194 | 2012-10-23 05:20:50 -0700 | [diff] [blame] | 81 | goto err_null; |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 82 | |
| 83 | retval = led_classdev_register(&pdev->dev, &raq_web_led); |
| 84 | if (retval) |
| 85 | goto err_unregister; |
| 86 | |
| 87 | return 0; |
| 88 | |
| 89 | err_unregister: |
| 90 | led_classdev_unregister(&raq_power_off_led); |
| 91 | |
Jingoo Han | 50e5194 | 2012-10-23 05:20:50 -0700 | [diff] [blame] | 92 | err_null: |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 93 | led_port = NULL; |
| 94 | |
| 95 | return retval; |
| 96 | } |
| 97 | |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 98 | static struct platform_driver cobalt_raq_led_driver = { |
| 99 | .probe = cobalt_raq_led_probe, |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 100 | .driver = { |
| 101 | .name = "cobalt-raq-leds", |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 102 | }, |
| 103 | }; |
| 104 | |
Geliang Tang | cee0122 | 2016-11-23 22:50:05 +0800 | [diff] [blame] | 105 | builtin_platform_driver(cobalt_raq_led_driver); |