Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 1 | /* Code to read/track the status of the WWAN LEDs of attached modems |
| 2 | * |
Kévin Redon | 9a12d68 | 2018-07-08 13:21:16 +0200 | [diff] [blame] | 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 |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 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 | */ |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 22 | #include "board.h" |
| 23 | #include "wwan_led.h" |
| 24 | |
| 25 | #ifdef PIN_WWAN1 |
| 26 | static const Pin pin_wwan1 = PIN_WWAN1; |
| 27 | |
| 28 | static void wwan1_irqhandler(const Pin *pPin) |
| 29 | { |
Harald Welte | e7f2f9a | 2017-11-03 20:38:31 +0100 | [diff] [blame] | 30 | int active = wwan_led_active(0); |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 31 | |
Harald Welte | e7f2f9a | 2017-11-03 20:38:31 +0100 | [diff] [blame] | 32 | TRACE_INFO("0: WWAN LED %u\r\n", active); |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 33 | |
| 34 | /* TODO: notify host via USB */ |
| 35 | } |
| 36 | #endif |
| 37 | |
| 38 | #ifdef PIN_WWAN2 |
| 39 | static const Pin pin_wwan2 = PIN_WWAN2; |
| 40 | |
| 41 | static void wwan2_irqhandler(const Pin *pPin) |
| 42 | { |
Harald Welte | e7f2f9a | 2017-11-03 20:38:31 +0100 | [diff] [blame] | 43 | int active = wwan_led_active(1); |
| 44 | TRACE_INFO("1: WWAN LED %u\r\n", active); |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 45 | |
| 46 | /* TODO: notify host via USB */ |
| 47 | } |
| 48 | #endif |
| 49 | |
| 50 | /* determine if a tiven WWAN led is currently active or not */ |
| 51 | int wwan_led_active(int wwan) |
| 52 | { |
| 53 | const Pin *pin; |
| 54 | int active; |
| 55 | |
| 56 | switch (wwan) { |
| 57 | #ifdef PIN_WWAN1 |
Harald Welte | e7f2f9a | 2017-11-03 20:38:31 +0100 | [diff] [blame] | 58 | case 0: |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 59 | pin = &pin_wwan1; |
| 60 | break; |
| 61 | #endif |
| 62 | #ifdef PIN_WWAN2 |
Harald Welte | e7f2f9a | 2017-11-03 20:38:31 +0100 | [diff] [blame] | 63 | case 1: |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 64 | pin = &pin_wwan2; |
| 65 | break; |
| 66 | #endif |
| 67 | default: |
| 68 | return -1; |
| 69 | } |
| 70 | |
Harald Welte | 7e4390f | 2017-05-05 20:23:23 +0200 | [diff] [blame] | 71 | active = PIO_Get(pin) ? 0 : 1; |
Harald Welte | 2819e9c | 2017-02-03 07:46:01 +0100 | [diff] [blame] | 72 | return active; |
| 73 | } |
| 74 | |
| 75 | int 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 | } |