2 * Atheros AR9170 driver
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, see
20 * http://www.gnu.org/licenses/.
22 * This file incorporates work covered by the following copyright and
24 * Copyright (c) 2007-2008 Atheros Communications, Inc.
26 * Permission to use, copy, modify, and/or distribute this software for any
27 * purpose with or without fee is hereby granted, provided that the above
28 * copyright notice and this permission notice appear in all copies.
30 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
31 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
32 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
33 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
34 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
35 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
36 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42 int ar9170_set_leds_state(struct ar9170
*ar
, u32 led_state
)
44 return ar9170_write_reg(ar
, AR9170_GPIO_REG_DATA
, led_state
);
47 int ar9170_init_leds(struct ar9170
*ar
)
52 /* GPIO [0/1 mode: output, 2/3: input] */
53 err
= ar9170_write_reg(ar
, AR9170_GPIO_REG_PORT_TYPE
, 3);
57 /* GPIO 0/1 value: off */
58 err
= ar9170_set_leds_state(ar
, 0);
64 #ifdef CONFIG_AR9170_LEDS
65 static void ar9170_update_leds(struct work_struct
*work
)
67 struct ar9170
*ar
= container_of(work
, struct ar9170
, led_work
.work
);
68 int i
, tmp
, blink_delay
= 1000;
72 if (unlikely(!IS_ACCEPTING_CMD(ar
)))
75 mutex_lock(&ar
->mutex
);
76 for (i
= 0; i
< AR9170_NUM_LEDS
; i
++)
77 if (ar
->leds
[i
].registered
&& ar
->leds
[i
].toggled
) {
80 tmp
= 70 + 200 / (ar
->leds
[i
].toggled
);
81 if (tmp
< blink_delay
)
84 if (ar
->leds
[i
].toggled
> 1)
85 ar
->leds
[i
].toggled
= 0;
90 ar9170_set_leds_state(ar
, led_val
);
91 mutex_unlock(&ar
->mutex
);
96 ieee80211_queue_delayed_work(ar
->hw
,
98 msecs_to_jiffies(blink_delay
));
101 static void ar9170_led_brightness_set(struct led_classdev
*led
,
102 enum led_brightness brightness
)
104 struct ar9170_led
*arl
= container_of(led
, struct ar9170_led
, l
);
105 struct ar9170
*ar
= arl
->ar
;
107 if (unlikely(!arl
->registered
))
110 if (arl
->last_state
!= !!brightness
) {
112 arl
->last_state
= !!brightness
;
115 if (likely(IS_ACCEPTING_CMD(ar
) && arl
->toggled
))
116 ieee80211_queue_delayed_work(ar
->hw
, &ar
->led_work
, HZ
/10);
119 static int ar9170_register_led(struct ar9170
*ar
, int i
, char *name
,
124 snprintf(ar
->leds
[i
].name
, sizeof(ar
->leds
[i
].name
),
125 "ar9170-%s::%s", wiphy_name(ar
->hw
->wiphy
), name
);
128 ar
->leds
[i
].l
.name
= ar
->leds
[i
].name
;
129 ar
->leds
[i
].l
.brightness_set
= ar9170_led_brightness_set
;
130 ar
->leds
[i
].l
.brightness
= 0;
131 ar
->leds
[i
].l
.default_trigger
= trigger
;
133 err
= led_classdev_register(wiphy_dev(ar
->hw
->wiphy
),
136 wiphy_err(ar
->hw
->wiphy
, "failed to register %s LED (%d).\n",
137 ar
->leds
[i
].name
, err
);
139 ar
->leds
[i
].registered
= true;
144 void ar9170_unregister_leds(struct ar9170
*ar
)
148 for (i
= 0; i
< AR9170_NUM_LEDS
; i
++)
149 if (ar
->leds
[i
].registered
) {
150 led_classdev_unregister(&ar
->leds
[i
].l
);
151 ar
->leds
[i
].registered
= false;
152 ar
->leds
[i
].toggled
= 0;
155 cancel_delayed_work_sync(&ar
->led_work
);
158 int ar9170_register_leds(struct ar9170
*ar
)
162 INIT_DELAYED_WORK(&ar
->led_work
, ar9170_update_leds
);
164 err
= ar9170_register_led(ar
, 0, "tx",
165 ieee80211_get_tx_led_name(ar
->hw
));
169 err
= ar9170_register_led(ar
, 1, "assoc",
170 ieee80211_get_assoc_led_name(ar
->hw
));
177 ar9170_unregister_leds(ar
);
181 #endif /* CONFIG_AR9170_LEDS */