Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002-2009 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | |
| 10 | /* 'inline' - We have to do it fast */ |
| 11 | static inline void mdm_readline(char *buf, int bufsiz) |
| 12 | { |
| 13 | char c; |
| 14 | char *p; |
| 15 | int n; |
| 16 | |
| 17 | n = 0; |
| 18 | p = buf; |
| 19 | for(;;) { |
| 20 | c = serial_getc(); |
| 21 | |
Tom Rini | 73144da | 2014-10-24 20:26:19 -0400 | [diff] [blame] | 22 | debug("(%c)", c); |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 23 | |
| 24 | switch(c) { |
| 25 | case '\r': |
| 26 | break; |
| 27 | case '\n': |
| 28 | *p = '\0'; |
| 29 | return; |
| 30 | |
| 31 | default: |
| 32 | if(n++ > bufsiz) { |
| 33 | *p = '\0'; |
| 34 | return; /* sanity check */ |
| 35 | } |
| 36 | *p = c; |
| 37 | p++; |
| 38 | break; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 43 | int mdm_init (void) |
| 44 | { |
| 45 | char env_str[16]; |
| 46 | char *init_str; |
| 47 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 48 | extern void enable_putc(void); |
| 49 | extern int hwflow_onoff(int); |
| 50 | |
| 51 | enable_putc(); /* enable serial_putc() */ |
| 52 | |
| 53 | #ifdef CONFIG_HWFLOW |
| 54 | init_str = getenv("mdm_flow_control"); |
| 55 | if (init_str && (strcmp(init_str, "rts/cts") == 0)) |
| 56 | hwflow_onoff (1); |
| 57 | else |
| 58 | hwflow_onoff(-1); |
| 59 | #endif |
| 60 | |
| 61 | for (i = 1;;i++) { |
| 62 | sprintf(env_str, "mdm_init%d", i); |
| 63 | if ((init_str = getenv(env_str)) != NULL) { |
| 64 | serial_puts(init_str); |
| 65 | serial_puts("\n"); |
| 66 | for(;;) { |
| 67 | mdm_readline(console_buffer, CONFIG_SYS_CBSIZE); |
Tom Rini | 73144da | 2014-10-24 20:26:19 -0400 | [diff] [blame] | 68 | debug("ini%d: [%s]", i, console_buffer); |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 69 | |
| 70 | if ((strcmp(console_buffer, "OK") == 0) || |
| 71 | (strcmp(console_buffer, "ERROR") == 0)) { |
Tom Rini | 73144da | 2014-10-24 20:26:19 -0400 | [diff] [blame] | 72 | debug("ini%d: cmd done", i); |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 73 | break; |
| 74 | } else /* in case we are originating call ... */ |
| 75 | if (strncmp(console_buffer, "CONNECT", 7) == 0) { |
Tom Rini | 73144da | 2014-10-24 20:26:19 -0400 | [diff] [blame] | 76 | debug("ini%d: connect", i); |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | } |
| 80 | } else |
| 81 | break; /* no init string - stop modem init */ |
| 82 | |
| 83 | udelay(100000); |
| 84 | } |
| 85 | |
| 86 | udelay(100000); |
| 87 | |
| 88 | /* final stage - wait for connect */ |
| 89 | for(;i > 1;) { /* if 'i' > 1 - wait for connection |
| 90 | message from modem */ |
| 91 | mdm_readline(console_buffer, CONFIG_SYS_CBSIZE); |
Tom Rini | 73144da | 2014-10-24 20:26:19 -0400 | [diff] [blame] | 92 | debug("ini_f: [%s]", console_buffer); |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 93 | if (strncmp(console_buffer, "CONNECT", 7) == 0) { |
Tom Rini | 73144da | 2014-10-24 20:26:19 -0400 | [diff] [blame] | 94 | debug("ini_f: connected"); |
Jean-Christophe PLAGNIOL-VILLARD | 55e0ed6 | 2009-04-25 14:57:52 +0200 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |