Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 1 | /* Code to control the PERST lines of attached modems |
| 2 | * |
| 3 | * Depending on the board this is running on, it might be possible |
| 4 | * for the controller to set the status of the PERST input line of |
| 5 | * the cellular modem. If the board supports this, it sets the |
| 6 | * PIN_PERST1 and/or PIN_PERST2 defines in its board.h file. |
| 7 | */ |
| 8 | |
| 9 | #include "board.h" |
| 10 | #include "wwan_perst.h" |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 11 | #include "osmocom/core/timer.h" |
| 12 | |
Harald Welte | 9c78cff | 2017-02-04 12:40:10 +0100 | [diff] [blame] | 13 | #define PERST_DURATION_MS 300 |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 14 | |
| 15 | #ifdef PIN_PERST1 |
| 16 | static const Pin pin_perst1 = PIN_PERST1; |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 17 | static struct osmo_timer_list perst1_timer; |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 18 | #endif |
| 19 | |
| 20 | #ifdef PIN_PERST2 |
| 21 | static const Pin pin_perst2 = PIN_PERST2; |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 22 | static struct osmo_timer_list perst2_timer; |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 23 | #endif |
| 24 | |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 25 | static void perst_tmr_cb(void *data) |
| 26 | { |
| 27 | const Pin *pin = data; |
| 28 | /* release the (low-active) reset */ |
Harald Welte | 4a9bce1 | 2017-02-07 16:34:05 +0100 | [diff] [blame] | 29 | PIO_Clear(pin); |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 32 | int wwan_perst_do_reset(int modem_nr) |
| 33 | { |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 34 | const Pin *pin; |
| 35 | struct osmo_timer_list *tmr; |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 36 | |
| 37 | switch (modem_nr) { |
| 38 | #ifdef PIN_PERST1 |
| 39 | case 1: |
| 40 | pin = &pin_perst1; |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 41 | tmr = &perst1_timer; |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 42 | break; |
| 43 | #endif |
| 44 | #ifdef PIN_PERST2 |
| 45 | case 2: |
| 46 | pin = &pin_perst2; |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 47 | tmr = &perst2_timer; |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 48 | break; |
| 49 | #endif |
| 50 | default: |
| 51 | return -1; |
| 52 | } |
Harald Welte | 4a9bce1 | 2017-02-07 16:34:05 +0100 | [diff] [blame] | 53 | PIO_Set(pin); |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 54 | osmo_timer_schedule(tmr, PERST_DURATION_MS/1000, (PERST_DURATION_MS%1000)*1000); |
| 55 | |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | int wwan_perst_init(void) |
| 60 | { |
| 61 | int num_perst = 0; |
| 62 | #ifdef PIN_PERST1 |
| 63 | PIO_Configure(&pin_perst1, 1); |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 64 | perst1_timer.cb = perst_tmr_cb; |
| 65 | perst1_timer.data = (void *) &pin_perst1; |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 66 | num_perst++; |
| 67 | #endif |
| 68 | |
| 69 | #ifdef PIN_PERST2 |
| 70 | PIO_Configure(&pin_perst2, 1); |
Harald Welte | 987f59a | 2017-02-04 12:34:35 +0100 | [diff] [blame] | 71 | perst2_timer.cb = perst_tmr_cb; |
| 72 | perst2_timer.data = (void *) &pin_perst2; |
Harald Welte | 31f817c | 2017-02-03 22:21:32 +0100 | [diff] [blame] | 73 | num_perst++; |
| 74 | #endif |
| 75 | return num_perst; |
| 76 | } |