blob: b3b569370ecd89416764ee3b0bf8dab5d8ba22dc [file] [log] [blame]
Harald Welte774330d2021-07-02 15:02:33 +02001/* Code to read/track the status of the WWAN LEDs of attached modems
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16 */
17/* Depending on the board this is running on, it might be possible
18 * for the controller to read the status of the WWAN LED output lines of
19 * the cellular modem. If the board supports this, it sets the
20 * PIN_WWAN1 and/or PIN_WWAN2 defines in its board.h file.
21 */
22#include "board.h"
23#include "wwan_led.h"
24
25#ifdef PIN_WWAN1
26static const Pin pin_wwan1 = PIN_WWAN1;
27
28static void wwan1_irqhandler(const Pin *pPin)
29{
30 int active = wwan_led_active(0);
31
32 TRACE_INFO("0: WWAN LED %u\r\n", active);
33
34 /* TODO: notify host via USB */
35}
36#endif
37
38#ifdef PIN_WWAN2
39static const Pin pin_wwan2 = PIN_WWAN2;
40
41static void wwan2_irqhandler(const Pin *pPin)
42{
43 int active = wwan_led_active(1);
44 TRACE_INFO("1: WWAN LED %u\r\n", active);
45
46 /* TODO: notify host via USB */
47}
48#endif
49
50/* determine if a tiven WWAN led is currently active or not */
51int wwan_led_active(int wwan)
52{
53 const Pin *pin;
54 int active;
55
56 switch (wwan) {
57#ifdef PIN_WWAN1
58 case 0:
59 pin = &pin_wwan1;
60 break;
61#endif
62#ifdef PIN_WWAN2
63 case 1:
64 pin = &pin_wwan2;
65 break;
66#endif
67 default:
68 return -1;
69 }
70
71 active = PIO_Get(pin) ? 0 : 1;
72 return active;
73}
74
75int wwan_led_init(void)
76{
77 int num_leds = 0;
78
79#ifdef PIN_WWAN1
80 PIO_Configure(&pin_wwan1, 1);
81 PIO_ConfigureIt(&pin_wwan1, wwan1_irqhandler);
82 PIO_EnableIt(&pin_wwan1);
83 num_leds++;
84#endif
85
86#ifdef PIN_WWAN2
87 PIO_Configure(&pin_wwan2, 1);
88 PIO_ConfigureIt(&pin_wwan2, wwan2_irqhandler);
89 PIO_EnableIt(&pin_wwan2);
90 num_leds++;
91#endif
92 return num_leds;
93}