0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/kernel.h>
0010 #include <linux/module.h>
0011 #include <linux/delay.h>
0012 #include <linux/skbuff.h>
0013 #include <linux/netdevice.h>
0014 #include <net/mac80211.h>
0015 #include <linux/etherdevice.h>
0016 #include <asm/unaligned.h>
0017 #include "iwl-io.h"
0018 #include "iwl-trans.h"
0019 #include "iwl-modparams.h"
0020 #include "dev.h"
0021 #include "agn.h"
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 static const struct ieee80211_tpt_blink iwl_blink[] = {
0037 { .throughput = 0, .blink_time = 334 },
0038 { .throughput = 1 * 1024 - 1, .blink_time = 260 },
0039 { .throughput = 5 * 1024 - 1, .blink_time = 220 },
0040 { .throughput = 10 * 1024 - 1, .blink_time = 190 },
0041 { .throughput = 20 * 1024 - 1, .blink_time = 170 },
0042 { .throughput = 50 * 1024 - 1, .blink_time = 150 },
0043 { .throughput = 70 * 1024 - 1, .blink_time = 130 },
0044 { .throughput = 100 * 1024 - 1, .blink_time = 110 },
0045 { .throughput = 200 * 1024 - 1, .blink_time = 80 },
0046 { .throughput = 300 * 1024 - 1, .blink_time = 50 },
0047 };
0048
0049
0050 void iwlagn_led_enable(struct iwl_priv *priv)
0051 {
0052 iwl_write32(priv->trans, CSR_LED_REG, CSR_LED_REG_TURN_ON);
0053 }
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 static inline u8 iwl_blink_compensation(struct iwl_priv *priv,
0067 u8 time, u16 compensation)
0068 {
0069 if (!compensation) {
0070 IWL_ERR(priv, "undefined blink compensation: "
0071 "use pre-defined blinking time\n");
0072 return time;
0073 }
0074
0075 return (u8)((time * compensation) >> 6);
0076 }
0077
0078 static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd)
0079 {
0080 struct iwl_host_cmd cmd = {
0081 .id = REPLY_LEDS_CMD,
0082 .len = { sizeof(struct iwl_led_cmd), },
0083 .data = { led_cmd, },
0084 .flags = CMD_ASYNC,
0085 };
0086 u32 reg;
0087
0088 reg = iwl_read32(priv->trans, CSR_LED_REG);
0089 if (reg != (reg & CSR_LED_BSM_CTRL_MSK))
0090 iwl_write32(priv->trans, CSR_LED_REG,
0091 reg & CSR_LED_BSM_CTRL_MSK);
0092
0093 return iwl_dvm_send_cmd(priv, &cmd);
0094 }
0095
0096
0097 static int iwl_led_cmd(struct iwl_priv *priv,
0098 unsigned long on,
0099 unsigned long off)
0100 {
0101 struct iwl_led_cmd led_cmd = {
0102 .id = IWL_LED_LINK,
0103 .interval = IWL_DEF_LED_INTRVL
0104 };
0105 int ret;
0106
0107 if (!test_bit(STATUS_READY, &priv->status))
0108 return -EBUSY;
0109
0110 if (priv->blink_on == on && priv->blink_off == off)
0111 return 0;
0112
0113 if (off == 0) {
0114
0115 on = IWL_LED_SOLID;
0116 }
0117
0118 led_cmd.on = iwl_blink_compensation(priv, on,
0119 priv->trans->trans_cfg->base_params->led_compensation);
0120 led_cmd.off = iwl_blink_compensation(priv, off,
0121 priv->trans->trans_cfg->base_params->led_compensation);
0122
0123 ret = iwl_send_led_cmd(priv, &led_cmd);
0124 if (!ret) {
0125 priv->blink_on = on;
0126 priv->blink_off = off;
0127 }
0128 return ret;
0129 }
0130
0131 static void iwl_led_brightness_set(struct led_classdev *led_cdev,
0132 enum led_brightness brightness)
0133 {
0134 struct iwl_priv *priv = container_of(led_cdev, struct iwl_priv, led);
0135 unsigned long on = 0;
0136 unsigned long off = 0;
0137
0138 if (brightness > 0)
0139 on = IWL_LED_SOLID;
0140 else
0141 off = IWL_LED_SOLID;
0142
0143 iwl_led_cmd(priv, on, off);
0144 }
0145
0146 static int iwl_led_blink_set(struct led_classdev *led_cdev,
0147 unsigned long *delay_on,
0148 unsigned long *delay_off)
0149 {
0150 struct iwl_priv *priv = container_of(led_cdev, struct iwl_priv, led);
0151
0152 return iwl_led_cmd(priv, *delay_on, *delay_off);
0153 }
0154
0155 void iwl_leds_init(struct iwl_priv *priv)
0156 {
0157 int mode = iwlwifi_mod_params.led_mode;
0158 int ret;
0159
0160 if (mode == IWL_LED_DISABLE) {
0161 IWL_INFO(priv, "Led disabled\n");
0162 return;
0163 }
0164 if (mode == IWL_LED_DEFAULT)
0165 mode = priv->cfg->led_mode;
0166
0167 priv->led.name = kasprintf(GFP_KERNEL, "%s-led",
0168 wiphy_name(priv->hw->wiphy));
0169 if (!priv->led.name)
0170 return;
0171
0172 priv->led.brightness_set = iwl_led_brightness_set;
0173 priv->led.blink_set = iwl_led_blink_set;
0174 priv->led.max_brightness = 1;
0175
0176 switch (mode) {
0177 case IWL_LED_DEFAULT:
0178 WARN_ON(1);
0179 break;
0180 case IWL_LED_BLINK:
0181 priv->led.default_trigger =
0182 ieee80211_create_tpt_led_trigger(priv->hw,
0183 IEEE80211_TPT_LEDTRIG_FL_CONNECTED,
0184 iwl_blink, ARRAY_SIZE(iwl_blink));
0185 break;
0186 case IWL_LED_RF_STATE:
0187 priv->led.default_trigger =
0188 ieee80211_get_radio_led_name(priv->hw);
0189 break;
0190 }
0191
0192 ret = led_classdev_register(priv->trans->dev, &priv->led);
0193 if (ret) {
0194 kfree(priv->led.name);
0195 return;
0196 }
0197
0198 priv->led_registered = true;
0199 }
0200
0201 void iwl_leds_exit(struct iwl_priv *priv)
0202 {
0203 if (!priv->led_registered)
0204 return;
0205
0206 led_classdev_unregister(&priv->led);
0207 kfree(priv->led.name);
0208 }