Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * LEDs driver for Amstrad Delta (E3) |
| 3 | * |
| 4 | * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li> |
| 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 version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 11 | #include <linux/kernel.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/leds.h> |
| 15 | #include <asm/arch/board-ams-delta.h> |
| 16 | |
| 17 | /* |
| 18 | * Our context |
| 19 | */ |
| 20 | struct ams_delta_led { |
| 21 | struct led_classdev cdev; |
| 22 | u8 bitmask; |
| 23 | }; |
| 24 | |
| 25 | static void ams_delta_led_set(struct led_classdev *led_cdev, |
| 26 | enum led_brightness value) |
| 27 | { |
| 28 | struct ams_delta_led *led_dev = |
| 29 | container_of(led_cdev, struct ams_delta_led, cdev); |
| 30 | |
| 31 | if (value) |
| 32 | ams_delta_latch1_write(led_dev->bitmask, led_dev->bitmask); |
| 33 | else |
| 34 | ams_delta_latch1_write(led_dev->bitmask, 0); |
| 35 | } |
| 36 | |
| 37 | static struct ams_delta_led ams_delta_leds[] = { |
| 38 | { |
| 39 | .cdev = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 40 | .name = "ams-delta::camera", |
Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 41 | .brightness_set = ams_delta_led_set, |
| 42 | }, |
| 43 | .bitmask = AMS_DELTA_LATCH1_LED_CAMERA, |
| 44 | }, |
| 45 | { |
| 46 | .cdev = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 47 | .name = "ams-delta::advert", |
Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 48 | .brightness_set = ams_delta_led_set, |
| 49 | }, |
| 50 | .bitmask = AMS_DELTA_LATCH1_LED_ADVERT, |
| 51 | }, |
| 52 | { |
| 53 | .cdev = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 54 | .name = "ams-delta::email", |
Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 55 | .brightness_set = ams_delta_led_set, |
| 56 | }, |
| 57 | .bitmask = AMS_DELTA_LATCH1_LED_EMAIL, |
| 58 | }, |
| 59 | { |
| 60 | .cdev = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 61 | .name = "ams-delta::handsfree", |
Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 62 | .brightness_set = ams_delta_led_set, |
| 63 | }, |
| 64 | .bitmask = AMS_DELTA_LATCH1_LED_HANDSFREE, |
| 65 | }, |
| 66 | { |
| 67 | .cdev = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 68 | .name = "ams-delta::voicemail", |
Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 69 | .brightness_set = ams_delta_led_set, |
| 70 | }, |
| 71 | .bitmask = AMS_DELTA_LATCH1_LED_VOICEMAIL, |
| 72 | }, |
| 73 | { |
| 74 | .cdev = { |
Richard Purdie | 6c152be | 2007-10-31 15:00:07 +0100 | [diff] [blame^] | 75 | .name = "ams-delta::voice", |
Jonathan McDowell | 9becde7 | 2006-06-23 02:05:33 -0700 | [diff] [blame] | 76 | .brightness_set = ams_delta_led_set, |
| 77 | }, |
| 78 | .bitmask = AMS_DELTA_LATCH1_LED_VOICE, |
| 79 | }, |
| 80 | }; |
| 81 | |
| 82 | #ifdef CONFIG_PM |
| 83 | static int ams_delta_led_suspend(struct platform_device *dev, |
| 84 | pm_message_t state) |
| 85 | { |
| 86 | int i; |
| 87 | |
| 88 | for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) |
| 89 | led_classdev_suspend(&ams_delta_leds[i].cdev); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int ams_delta_led_resume(struct platform_device *dev) |
| 95 | { |
| 96 | int i; |
| 97 | |
| 98 | for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) |
| 99 | led_classdev_resume(&ams_delta_leds[i].cdev); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | #else |
| 104 | #define ams_delta_led_suspend NULL |
| 105 | #define ams_delta_led_resume NULL |
| 106 | #endif |
| 107 | |
| 108 | static int ams_delta_led_probe(struct platform_device *pdev) |
| 109 | { |
| 110 | int i; |
| 111 | int ret; |
| 112 | |
| 113 | for (i = ret = 0; ret >= 0 && i < ARRAY_SIZE(ams_delta_leds); i++) { |
| 114 | ret = led_classdev_register(&pdev->dev, |
| 115 | &ams_delta_leds[i].cdev); |
| 116 | } |
| 117 | |
| 118 | if (ret < 0 && i > 1) { |
| 119 | for (i = i - 2; i >= 0; i--) |
| 120 | led_classdev_unregister(&ams_delta_leds[i].cdev); |
| 121 | } |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | static int ams_delta_led_remove(struct platform_device *pdev) |
| 127 | { |
| 128 | int i; |
| 129 | |
| 130 | for (i = ARRAY_SIZE(ams_delta_leds) - 1; i >= 0; i--) |
| 131 | led_classdev_unregister(&ams_delta_leds[i].cdev); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static struct platform_driver ams_delta_led_driver = { |
| 137 | .probe = ams_delta_led_probe, |
| 138 | .remove = ams_delta_led_remove, |
| 139 | .suspend = ams_delta_led_suspend, |
| 140 | .resume = ams_delta_led_resume, |
| 141 | .driver = { |
| 142 | .name = "ams-delta-led", |
| 143 | }, |
| 144 | }; |
| 145 | |
| 146 | static int __init ams_delta_led_init(void) |
| 147 | { |
| 148 | return platform_driver_register(&ams_delta_led_driver); |
| 149 | } |
| 150 | |
| 151 | static void __exit ams_delta_led_exit(void) |
| 152 | { |
| 153 | return platform_driver_unregister(&ams_delta_led_driver); |
| 154 | } |
| 155 | |
| 156 | module_init(ams_delta_led_init); |
| 157 | module_exit(ams_delta_led_exit); |
| 158 | |
| 159 | MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>"); |
| 160 | MODULE_DESCRIPTION("Amstrad Delta LED driver"); |
| 161 | MODULE_LICENSE("GPL"); |