Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 1 | /* |
| 2 | * LEDs driver for the Cobalt Raq series. |
| 3 | * |
Yoichi Yuasa | ada8e95 | 2009-07-03 00:39:38 +0900 | [diff] [blame] | 4 | * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org> |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Németh Márton | 4d404fd | 2008-03-09 20:59:57 +0000 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 19 | */ |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/ioport.h> |
| 23 | #include <linux/leds.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/types.h> |
Paul Gortmaker | d131c49 | 2011-07-10 12:24:44 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 28 | |
| 29 | #define LED_WEB 0x04 |
| 30 | #define LED_POWER_OFF 0x08 |
| 31 | |
| 32 | static void __iomem *led_port; |
| 33 | static u8 led_value; |
| 34 | static DEFINE_SPINLOCK(led_value_lock); |
| 35 | |
| 36 | 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] | 37 | enum led_brightness brightness) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 38 | { |
| 39 | unsigned long flags; |
| 40 | |
| 41 | spin_lock_irqsave(&led_value_lock, flags); |
| 42 | |
| 43 | if (brightness) |
| 44 | led_value |= LED_WEB; |
| 45 | else |
| 46 | led_value &= ~LED_WEB; |
| 47 | writeb(led_value, led_port); |
| 48 | |
| 49 | spin_unlock_irqrestore(&led_value_lock, flags); |
| 50 | } |
| 51 | |
| 52 | static struct led_classdev raq_web_led = { |
Olaf Hering | db3f520 | 2009-09-07 14:37:27 +0100 | [diff] [blame] | 53 | .name = "raq::web", |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 54 | .brightness_set = raq_web_led_set, |
| 55 | }; |
| 56 | |
| 57 | 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] | 58 | enum led_brightness brightness) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 59 | { |
| 60 | unsigned long flags; |
| 61 | |
| 62 | spin_lock_irqsave(&led_value_lock, flags); |
| 63 | |
| 64 | if (brightness) |
| 65 | led_value |= LED_POWER_OFF; |
| 66 | else |
| 67 | led_value &= ~LED_POWER_OFF; |
| 68 | writeb(led_value, led_port); |
| 69 | |
| 70 | spin_unlock_irqrestore(&led_value_lock, flags); |
| 71 | } |
| 72 | |
| 73 | static struct led_classdev raq_power_off_led = { |
Olaf Hering | db3f520 | 2009-09-07 14:37:27 +0100 | [diff] [blame] | 74 | .name = "raq::power-off", |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 75 | .brightness_set = raq_power_off_led_set, |
| 76 | .default_trigger = "power-off", |
| 77 | }; |
| 78 | |
Bill Pemberton | 98ea1ea | 2012-11-19 13:23:02 -0500 | [diff] [blame] | 79 | static int cobalt_raq_led_probe(struct platform_device *pdev) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 80 | { |
| 81 | struct resource *res; |
| 82 | int retval; |
| 83 | |
| 84 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 85 | if (!res) |
| 86 | return -EBUSY; |
| 87 | |
Jingoo Han | 50e5194 | 2012-10-23 05:20:50 -0700 | [diff] [blame] | 88 | led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 89 | if (!led_port) |
| 90 | return -ENOMEM; |
| 91 | |
| 92 | retval = led_classdev_register(&pdev->dev, &raq_power_off_led); |
| 93 | if (retval) |
Jingoo Han | 50e5194 | 2012-10-23 05:20:50 -0700 | [diff] [blame] | 94 | goto err_null; |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 95 | |
| 96 | retval = led_classdev_register(&pdev->dev, &raq_web_led); |
| 97 | if (retval) |
| 98 | goto err_unregister; |
| 99 | |
| 100 | return 0; |
| 101 | |
| 102 | err_unregister: |
| 103 | led_classdev_unregister(&raq_power_off_led); |
| 104 | |
Jingoo Han | 50e5194 | 2012-10-23 05:20:50 -0700 | [diff] [blame] | 105 | err_null: |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 106 | led_port = NULL; |
| 107 | |
| 108 | return retval; |
| 109 | } |
| 110 | |
Bill Pemberton | 678e8a6 | 2012-11-19 13:26:00 -0500 | [diff] [blame] | 111 | static int cobalt_raq_led_remove(struct platform_device *pdev) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 112 | { |
| 113 | led_classdev_unregister(&raq_power_off_led); |
| 114 | led_classdev_unregister(&raq_web_led); |
| 115 | |
Jingoo Han | 50e5194 | 2012-10-23 05:20:50 -0700 | [diff] [blame] | 116 | if (led_port) |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 117 | led_port = NULL; |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | static struct platform_driver cobalt_raq_led_driver = { |
| 123 | .probe = cobalt_raq_led_probe, |
Bill Pemberton | df07cf8 | 2012-11-19 13:20:20 -0500 | [diff] [blame] | 124 | .remove = cobalt_raq_led_remove, |
Yoichi Yuasa | 97da7aa | 2007-09-27 17:51:05 +0900 | [diff] [blame] | 125 | .driver = { |
| 126 | .name = "cobalt-raq-leds", |
| 127 | .owner = THIS_MODULE, |
| 128 | }, |
| 129 | }; |
| 130 | |
| 131 | static int __init cobalt_raq_led_init(void) |
| 132 | { |
| 133 | return platform_driver_register(&cobalt_raq_led_driver); |
| 134 | } |
| 135 | |
| 136 | module_init(cobalt_raq_led_init); |