blob: b3b569370ecd89416764ee3b0bf8dab5d8ba22dc [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 *
Kévin Redon9a12d682018-07-08 13:21:16 +02003 * 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
Harald Welte2819e9c2017-02-03 07:46:01 +010018 * 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 */
Harald Welte2819e9c2017-02-03 07:46:01 +010022#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{
Harald Weltee7f2f9a2017-11-03 20:38:31 +010030 int active = wwan_led_active(0);
Harald Welte2819e9c2017-02-03 07:46:01 +010031
Harald Weltee7f2f9a2017-11-03 20:38:31 +010032 TRACE_INFO("0: WWAN LED %u\r\n", active);
Harald Welte2819e9c2017-02-03 07:46:01 +010033
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{
Harald Weltee7f2f9a2017-11-03 20:38:31 +010043 int active = wwan_led_active(1);
44 TRACE_INFO("1: WWAN LED %u\r\n", active);
Harald Welte2819e9c2017-02-03 07:46:01 +010045
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
Harald Weltee7f2f9a2017-11-03 20:38:31 +010058 case 0:
Harald Welte2819e9c2017-02-03 07:46:01 +010059 pin = &pin_wwan1;
60 break;
61#endif
62#ifdef PIN_WWAN2
Harald Weltee7f2f9a2017-11-03 20:38:31 +010063 case 1:
Harald Welte2819e9c2017-02-03 07:46:01 +010064 pin = &pin_wwan2;
65 break;
66#endif
67 default:
68 return -1;
69 }
70
Harald Welte7e4390f2017-05-05 20:23:23 +020071 active = PIO_Get(pin) ? 0 : 1;
Harald Welte2819e9c2017-02-03 07:46:01 +010072 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}