^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * LED Driver for the Freecom FSG-3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Rod Whitby <rod@whitby.id.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Based on leds-spitz.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright 2005-2006 Openedhand Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Author: Richard Purdie <rpurdie@openedhand.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <mach/hardware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define FSG_LED_WLAN_BIT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define FSG_LED_WAN_BIT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define FSG_LED_SATA_BIT 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define FSG_LED_USB_BIT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define FSG_LED_RING_BIT 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define FSG_LED_SYNC_BIT 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static short __iomem *latch_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static unsigned short latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void fsg_led_wlan_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) latch_value &= ~(1 << FSG_LED_WLAN_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) latch_value |= (1 << FSG_LED_WLAN_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void fsg_led_wan_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) latch_value &= ~(1 << FSG_LED_WAN_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) latch_value |= (1 << FSG_LED_WAN_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void fsg_led_sata_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) latch_value &= ~(1 << FSG_LED_SATA_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) latch_value |= (1 << FSG_LED_SATA_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static void fsg_led_usb_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) latch_value &= ~(1 << FSG_LED_USB_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) latch_value |= (1 << FSG_LED_USB_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static void fsg_led_sync_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) latch_value &= ~(1 << FSG_LED_SYNC_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) latch_value |= (1 << FSG_LED_SYNC_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void fsg_led_ring_set(struct led_classdev *led_cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) enum led_brightness value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) latch_value &= ~(1 << FSG_LED_RING_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) latch_value |= (1 << FSG_LED_RING_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static struct led_classdev fsg_wlan_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .name = "fsg:blue:wlan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .brightness_set = fsg_led_wlan_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .flags = LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static struct led_classdev fsg_wan_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .name = "fsg:blue:wan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .brightness_set = fsg_led_wan_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .flags = LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static struct led_classdev fsg_sata_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .name = "fsg:blue:sata",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .brightness_set = fsg_led_sata_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .flags = LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct led_classdev fsg_usb_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .name = "fsg:blue:usb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .brightness_set = fsg_led_usb_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .flags = LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static struct led_classdev fsg_sync_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .name = "fsg:blue:sync",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .brightness_set = fsg_led_sync_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .flags = LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static struct led_classdev fsg_ring_led = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .name = "fsg:blue:ring",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .brightness_set = fsg_led_ring_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .flags = LED_CORE_SUSPENDRESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int fsg_led_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* Map the LED chip select address space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) latch_address = (unsigned short *) devm_ioremap(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) IXP4XX_EXP_BUS_BASE(2), 512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!latch_address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) latch_value = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) *latch_address = latch_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ret = devm_led_classdev_register(&pdev->dev, &fsg_wlan_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ret = devm_led_classdev_register(&pdev->dev, &fsg_wan_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ret = devm_led_classdev_register(&pdev->dev, &fsg_sata_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ret = devm_led_classdev_register(&pdev->dev, &fsg_usb_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ret = devm_led_classdev_register(&pdev->dev, &fsg_sync_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ret = devm_led_classdev_register(&pdev->dev, &fsg_ring_led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static struct platform_driver fsg_led_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .probe = fsg_led_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .name = "fsg-led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) module_platform_driver(fsg_led_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) MODULE_LICENSE("GPL");