| 158 | } |
| 159 | |
| 160 | int get_ec_ports(void) |
| 161 | { |
| 162 | FILE *fp = fopen("/proc/ioports", "r"); |
| 163 | int data = 0, cmd = 0; |
| 164 | char line[100]; |
| 165 | |
| 166 | if (fp == NULL) |
| 167 | return -1; |
| 168 | |
| 169 | while (!feof(fp) && (data == 0 || cmd == 0)) { |
| 170 | if (fgets(line, sizeof(line), fp) == NULL) { |
| 171 | fprintf(stderr, "Can not read from /proc/ioports.\n"); |
| 172 | break; |
| 173 | } |
| 174 | if (strstr(line, "EC data") != NULL) |
| 175 | data = strtol(line, NULL, 16); |
| 176 | |
| 177 | if (strstr(line, "EC cmd") != NULL) |
| 178 | cmd = strtol(line, NULL, 16); |
| 179 | } |
| 180 | |
| 181 | fclose(fp); |
| 182 | if (data != 0 && cmd != 0) { |
| 183 | debug("EC data = 0x%x, EC cmd = 0x%x\n", data, cmd); |
| 184 | ec_data = data; |
| 185 | ec_sc = cmd; |
| 186 | } else { |
| 187 | return -1; |
| 188 | } |
| 189 | return 0; |
| 190 | } |