2 * Linux LED driver for RTL8187
4 * Copyright 2009 Larry Finger <Larry.Finger@lwfinger.net>
6 * Based on the LED handling in the r8187 driver, which is:
7 * Copyright (c) Realtek Semiconductor Corp. All rights reserved.
9 * Thanks to Realtek for their support!
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #ifdef CONFIG_RTL8187_LEDS
18 #include <net/mac80211.h>
19 #include <linux/usb.h>
20 #include <linux/eeprom_93cx6.h>
23 #include "rtl8187_leds.h"
25 static void led_turn_on(struct work_struct
*work
)
27 /* As this routine does read/write operations on the hardware, it must
28 * be run from a work queue.
31 struct rtl8187_priv
*priv
= container_of(work
, struct rtl8187_priv
,
33 struct rtl8187_led
*led
= &priv
->led_tx
;
35 /* Don't change the LED, when the device is down. */
36 if (priv
->mode
== NL80211_IFTYPE_UNSPECIFIED
)
39 /* Skip if the LED is not registered. */
42 mutex_lock(&priv
->conf_mutex
);
43 switch (led
->ledpin
) {
45 rtl818x_iowrite8(priv
, &priv
->map
->GPIO0
, 0x01);
46 rtl818x_iowrite8(priv
, &priv
->map
->GP_ENABLE
, 0x00);
49 reg
= rtl818x_ioread8(priv
, &priv
->map
->PGSELECT
) & ~(1 << 4);
50 rtl818x_iowrite8(priv
, &priv
->map
->PGSELECT
, reg
);
53 reg
= rtl818x_ioread8(priv
, &priv
->map
->PGSELECT
) & ~(1 << 5);
54 rtl818x_iowrite8(priv
, &priv
->map
->PGSELECT
, reg
);
60 mutex_unlock(&priv
->conf_mutex
);
63 static void led_turn_off(struct work_struct
*work
)
65 /* As this routine does read/write operations on the hardware, it must
66 * be run from a work queue.
69 struct rtl8187_priv
*priv
= container_of(work
, struct rtl8187_priv
,
71 struct rtl8187_led
*led
= &priv
->led_tx
;
73 /* Don't change the LED, when the device is down. */
74 if (priv
->mode
== NL80211_IFTYPE_UNSPECIFIED
)
77 /* Skip if the LED is not registered. */
80 mutex_lock(&priv
->conf_mutex
);
81 switch (led
->ledpin
) {
83 rtl818x_iowrite8(priv
, &priv
->map
->GPIO0
, 0x01);
84 rtl818x_iowrite8(priv
, &priv
->map
->GP_ENABLE
, 0x01);
87 reg
= rtl818x_ioread8(priv
, &priv
->map
->PGSELECT
) | (1 << 4);
88 rtl818x_iowrite8(priv
, &priv
->map
->PGSELECT
, reg
);
91 reg
= rtl818x_ioread8(priv
, &priv
->map
->PGSELECT
) | (1 << 5);
92 rtl818x_iowrite8(priv
, &priv
->map
->PGSELECT
, reg
);
98 mutex_unlock(&priv
->conf_mutex
);
101 /* Callback from the LED subsystem. */
102 static void rtl8187_led_brightness_set(struct led_classdev
*led_dev
,
103 enum led_brightness brightness
)
105 struct rtl8187_led
*led
= container_of(led_dev
, struct rtl8187_led
,
107 struct ieee80211_hw
*hw
= led
->dev
;
108 struct rtl8187_priv
*priv
= hw
->priv
;
110 if (brightness
== LED_OFF
) {
111 ieee80211_queue_delayed_work(hw
, &priv
->led_off
, 0);
112 /* The LED is off for 1/20 sec so that it just blinks. */
113 ieee80211_queue_delayed_work(hw
, &priv
->led_on
, HZ
/ 20);
115 ieee80211_queue_delayed_work(hw
, &priv
->led_on
, 0);
118 static int rtl8187_register_led(struct ieee80211_hw
*dev
,
119 struct rtl8187_led
*led
, const char *name
,
120 const char *default_trigger
, u8 ledpin
)
123 struct rtl8187_priv
*priv
= dev
->priv
;
127 if (!default_trigger
)
130 led
->ledpin
= ledpin
;
131 strncpy(led
->name
, name
, sizeof(led
->name
));
133 led
->led_dev
.name
= led
->name
;
134 led
->led_dev
.default_trigger
= default_trigger
;
135 led
->led_dev
.brightness_set
= rtl8187_led_brightness_set
;
137 err
= led_classdev_register(&priv
->udev
->dev
, &led
->led_dev
);
139 printk(KERN_INFO
"LEDs: Failed to register %s\n", name
);
146 static void rtl8187_unregister_led(struct rtl8187_led
*led
)
148 led_classdev_unregister(&led
->led_dev
);
152 void rtl8187_leds_init(struct ieee80211_hw
*dev
, u16 custid
)
154 struct rtl8187_priv
*priv
= dev
->priv
;
155 char name
[RTL8187_LED_MAX_NAME_LEN
+ 1];
159 /* According to the vendor driver, the LED operation depends on the
160 * customer ID encoded in the EEPROM
162 printk(KERN_INFO
"rtl8187: Customer ID is 0x%02X\n", custid
);
164 case EEPROM_CID_RSVD0
:
165 case EEPROM_CID_RSVD1
:
166 case EEPROM_CID_SERCOMM_PS
:
168 case EEPROM_CID_DELL
:
169 case EEPROM_CID_TOSHIBA
:
170 ledpin
= LED_PIN_GPIO0
;
172 case EEPROM_CID_ALPHA0
:
173 ledpin
= LED_PIN_LED0
;
179 ledpin
= LED_PIN_GPIO0
;
182 INIT_DELAYED_WORK(&priv
->led_on
, led_turn_on
);
183 INIT_DELAYED_WORK(&priv
->led_off
, led_turn_off
);
185 snprintf(name
, sizeof(name
),
186 "rtl8187-%s::tx", wiphy_name(dev
->wiphy
));
187 err
= rtl8187_register_led(dev
, &priv
->led_tx
, name
,
188 ieee80211_get_tx_led_name(dev
), ledpin
);
191 snprintf(name
, sizeof(name
),
192 "rtl8187-%s::rx", wiphy_name(dev
->wiphy
));
193 err
= rtl8187_register_led(dev
, &priv
->led_rx
, name
,
194 ieee80211_get_rx_led_name(dev
), ledpin
);
196 ieee80211_queue_delayed_work(dev
, &priv
->led_on
, 0);
199 /* registration of RX LED failed - unregister TX */
200 rtl8187_unregister_led(&priv
->led_tx
);
202 /* If registration of either failed, cancel delayed work */
203 cancel_delayed_work_sync(&priv
->led_off
);
204 cancel_delayed_work_sync(&priv
->led_on
);
207 void rtl8187_leds_exit(struct ieee80211_hw
*dev
)
209 struct rtl8187_priv
*priv
= dev
->priv
;
211 /* turn the LED off before exiting */
212 ieee80211_queue_delayed_work(dev
, &priv
->led_off
, 0);
213 cancel_delayed_work_sync(&priv
->led_off
);
214 cancel_delayed_work_sync(&priv
->led_on
);
215 rtl8187_unregister_led(&priv
->led_rx
);
216 rtl8187_unregister_led(&priv
->led_tx
);
218 #endif /* def CONFIG_RTL8187_LED */