blob: 70c8fdd6c9da544652d8b3c7399f624482967573 [file] [log] [blame]
Harald Welte31f817c2017-02-03 22:21:32 +01001/* 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 Welte987f59a2017-02-04 12:34:35 +010011#include "osmocom/core/timer.h"
12
Harald Welte9c78cff2017-02-04 12:40:10 +010013#define PERST_DURATION_MS 300
Harald Welte31f817c2017-02-03 22:21:32 +010014
15#ifdef PIN_PERST1
16static const Pin pin_perst1 = PIN_PERST1;
Harald Welte987f59a2017-02-04 12:34:35 +010017static struct osmo_timer_list perst1_timer;
Harald Welte31f817c2017-02-03 22:21:32 +010018#endif
19
20#ifdef PIN_PERST2
21static const Pin pin_perst2 = PIN_PERST2;
Harald Welte987f59a2017-02-04 12:34:35 +010022static struct osmo_timer_list perst2_timer;
Harald Welte31f817c2017-02-03 22:21:32 +010023#endif
24
Harald Welte987f59a2017-02-04 12:34:35 +010025static void perst_tmr_cb(void *data)
26{
27 const Pin *pin = data;
28 /* release the (low-active) reset */
29 PIO_Set(pin);
30}
31
Harald Welte31f817c2017-02-03 22:21:32 +010032int wwan_perst_do_reset(int modem_nr)
33{
Harald Welte987f59a2017-02-04 12:34:35 +010034 const Pin *pin;
35 struct osmo_timer_list *tmr;
Harald Welte31f817c2017-02-03 22:21:32 +010036
37 switch (modem_nr) {
38#ifdef PIN_PERST1
39 case 1:
40 pin = &pin_perst1;
Harald Welte987f59a2017-02-04 12:34:35 +010041 tmr = &perst1_timer;
Harald Welte31f817c2017-02-03 22:21:32 +010042 break;
43#endif
44#ifdef PIN_PERST2
45 case 2:
46 pin = &pin_perst2;
Harald Welte987f59a2017-02-04 12:34:35 +010047 tmr = &perst2_timer;
Harald Welte31f817c2017-02-03 22:21:32 +010048 break;
49#endif
50 default:
51 return -1;
52 }
53 PIO_Clear(pin);
Harald Welte987f59a2017-02-04 12:34:35 +010054 osmo_timer_schedule(tmr, PERST_DURATION_MS/1000, (PERST_DURATION_MS%1000)*1000);
55
Harald Welte31f817c2017-02-03 22:21:32 +010056 return 0;
57}
58
59int wwan_perst_init(void)
60{
61 int num_perst = 0;
62#ifdef PIN_PERST1
63 PIO_Configure(&pin_perst1, 1);
Harald Welte987f59a2017-02-04 12:34:35 +010064 perst1_timer.cb = perst_tmr_cb;
65 perst1_timer.data = (void *) &pin_perst1;
Harald Welte31f817c2017-02-03 22:21:32 +010066 num_perst++;
67#endif
68
69#ifdef PIN_PERST2
70 PIO_Configure(&pin_perst2, 1);
Harald Welte987f59a2017-02-04 12:34:35 +010071 perst2_timer.cb = perst_tmr_cb;
72 perst2_timer.data = (void *) &pin_perst2;
Harald Welte31f817c2017-02-03 22:21:32 +010073 num_perst++;
74#endif
75 return num_perst;
76}