~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/mach-shark/leds.c

Version: ~ [ linux-5.10-rc1 ] ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * DIGITAL Shark LED control routines.
  3  *
  4  * Driver for the 3 user LEDs found on the Shark
  5  * Based on Versatile and RealView machine LED code
  6  *
  7  * License terms: GNU General Public License (GPL) version 2
  8  * Author: Bryan Wu <bryan.wu@canonical.com>
  9  */
 10 #include <linux/kernel.h>
 11 #include <linux/init.h>
 12 #include <linux/io.h>
 13 #include <linux/ioport.h>
 14 #include <linux/slab.h>
 15 #include <linux/leds.h>
 16 
 17 #include <asm/mach-types.h>
 18 
 19 #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
 20 struct shark_led {
 21         struct led_classdev cdev;
 22         u8 mask;
 23 };
 24 
 25 /*
 26  * The triggers lines up below will only be used if the
 27  * LED triggers are compiled in.
 28  */
 29 static const struct {
 30         const char *name;
 31         const char *trigger;
 32 } shark_leds[] = {
 33         { "shark:amber0", "default-on", },      /* Bit 5 */
 34         { "shark:green", "heartbeat", },        /* Bit 6 */
 35         { "shark:amber1", "cpu0" },             /* Bit 7 */
 36 };
 37 
 38 static u16 led_reg_read(void)
 39 {
 40         outw(0x09, 0x24);
 41         return inw(0x26);
 42 }
 43 
 44 static void led_reg_write(u16 value)
 45 {
 46         outw(0x09, 0x24);
 47         outw(value, 0x26);
 48 }
 49 
 50 static void shark_led_set(struct led_classdev *cdev,
 51                               enum led_brightness b)
 52 {
 53         struct shark_led *led = container_of(cdev,
 54                                                  struct shark_led, cdev);
 55         u16 reg = led_reg_read();
 56 
 57         if (b != LED_OFF)
 58                 reg |= led->mask;
 59         else
 60                 reg &= ~led->mask;
 61 
 62         led_reg_write(reg);
 63 }
 64 
 65 static enum led_brightness shark_led_get(struct led_classdev *cdev)
 66 {
 67         struct shark_led *led = container_of(cdev,
 68                                                  struct shark_led, cdev);
 69         u16 reg = led_reg_read();
 70 
 71         return (reg & led->mask) ? LED_FULL : LED_OFF;
 72 }
 73 
 74 static int __init shark_leds_init(void)
 75 {
 76         int i;
 77         u16 reg;
 78 
 79         if (!machine_is_shark())
 80                 return -ENODEV;
 81 
 82         for (i = 0; i < ARRAY_SIZE(shark_leds); i++) {
 83                 struct shark_led *led;
 84 
 85                 led = kzalloc(sizeof(*led), GFP_KERNEL);
 86                 if (!led)
 87                         break;
 88 
 89                 led->cdev.name = shark_leds[i].name;
 90                 led->cdev.brightness_set = shark_led_set;
 91                 led->cdev.brightness_get = shark_led_get;
 92                 led->cdev.default_trigger = shark_leds[i].trigger;
 93 
 94                 /* Count in 5 bits offset */
 95                 led->mask = BIT(i + 5);
 96 
 97                 if (led_classdev_register(NULL, &led->cdev) < 0) {
 98                         kfree(led);
 99                         break;
100                 }
101         }
102 
103         /* Make LEDs independent of power-state */
104         request_region(0x24, 4, "led_reg");
105         reg = led_reg_read();
106         reg |= 1 << 10;
107         led_reg_write(reg);
108 
109         return 0;
110 }
111 
112 /*
113  * Since we may have triggers on any subsystem, defer registration
114  * until after subsystem_init.
115  */
116 fs_initcall(shark_leds_init);
117 #endif
118 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp