blob: 3bae0ff81cdb55223ec386606afe77b4f9d24f67 [file] [log] [blame]
Harald Welte2819e9c2017-02-03 07:46:01 +01001/* Code to read/track the status of the WWAN LEDs of attached modems
2 *
3 * Depending on the board this is running on, it might be possible
4 * for the controller to read the status of the WWAN LED output lines of
5 * the cellular modem. If the board supports this, it sets the
6 * PIN_WWAN1 and/or PIN_WWAN2 defines in its board.h file.
7 */
8
9#include "board.h"
10#include "wwan_led.h"
11
12#ifdef PIN_WWAN1
13static const Pin pin_wwan1 = PIN_WWAN1;
14
15static void wwan1_irqhandler(const Pin *pPin)
16{
17 int active = wwan_led_active(1);
18
19 TRACE_INFO("WWAN1 LED %u\r\n", active);
20
21 /* TODO: notify host via USB */
22}
23#endif
24
25#ifdef PIN_WWAN2
26static const Pin pin_wwan2 = PIN_WWAN2;
27
28static void wwan2_irqhandler(const Pin *pPin)
29{
30 int active = wwan_led_active(2);
31 TRACE_INFO("WWAN2 LED %u\r\n", active);
32
33 /* TODO: notify host via USB */
34}
35#endif
36
37/* determine if a tiven WWAN led is currently active or not */
38int wwan_led_active(int wwan)
39{
40 const Pin *pin;
41 int active;
42
43 switch (wwan) {
44#ifdef PIN_WWAN1
45 case 1:
46 pin = &pin_wwan1;
47 break;
48#endif
49#ifdef PIN_WWAN2
50 case 2:
51 pin = &pin_wwan2;
52 break;
53#endif
54 default:
55 return -1;
56 }
57
58 active = PIO_Get(&pin_wwan1) ? 0 : 1;
59 return active;
60}
61
62int wwan_led_init(void)
63{
64 int num_leds = 0;
65
66#ifdef PIN_WWAN1
67 PIO_Configure(&pin_wwan1, 1);
68 PIO_ConfigureIt(&pin_wwan1, wwan1_irqhandler);
69 PIO_EnableIt(&pin_wwan1);
70 num_leds++;
71#endif
72
73#ifdef PIN_WWAN2
74 PIO_Configure(&pin_wwan2, 1);
75 PIO_ConfigureIt(&pin_wwan2, wwan2_irqhandler);
76 PIO_EnableIt(&pin_wwan2);
77 num_leds++;
78#endif
79 return num_leds;
80}