Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "host_common.h" | 9 #include "host_common.h" |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 * | 76 * |
| 77 * Returns 1 if the bit is set, 0 if clear, or -1 if error. */ | 77 * Returns 1 if the bit is set, 0 if clear, or -1 if error. */ |
| 78 int ReadFileBit(const char* filename, int bitmask) { | 78 int ReadFileBit(const char* filename, int bitmask) { |
| 79 int value = ReadFileInt(filename); | 79 int value = ReadFileInt(filename); |
| 80 if (value == -1) | 80 if (value == -1) |
| 81 return -1; | 81 return -1; |
| 82 else return (value & bitmask ? 1 : 0); | 82 else return (value & bitmask ? 1 : 0); |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 /* Returns non-zero if the FWID starts with the specified string. */ | |
|
Bill Richardson
2011/02/17 19:05:49
s/non-zero/true/ ?
| |
| 87 static int FwidStartsWith(const char *start) { | |
| 88 char fwid[128]; | |
| 89 if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid))) | |
| 90 return 0; | |
| 91 | |
| 92 return 0 == strncmp(fwid, start, strlen(start)); | |
| 93 } | |
| 94 | |
| 95 | |
| 86 /* Read a GPIO of the specified signal type (see ACPI GPIO SignalType). | 96 /* Read a GPIO of the specified signal type (see ACPI GPIO SignalType). |
| 87 * | 97 * |
| 88 * Returns 1 if the signal is asserted, 0 if not asserted, or -1 if error. */ | 98 * Returns 1 if the signal is asserted, 0 if not asserted, or -1 if error. */ |
| 89 int ReadGpio(int signal_type) { | 99 int ReadGpio(int signal_type) { |
| 90 char name[128]; | 100 char name[128]; |
| 91 int index = 0; | 101 int index = 0; |
| 92 int gpio_type; | 102 int gpio_type; |
| 93 int active_high; | 103 int active_high; |
| 94 int controller_offset; | 104 int controller_offset; |
| 95 char controller_name[128]; | 105 char controller_name[128]; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 158 |
| 149 /* Compare the GPIO value with the active value and return 1 if match. */ | 159 /* Compare the GPIO value with the active value and return 1 if match. */ |
| 150 return (value == active_high ? 1 : 0); | 160 return (value == active_high ? 1 : 0); |
| 151 } | 161 } |
| 152 | 162 |
| 153 | 163 |
| 154 /* Read a system property integer. | 164 /* Read a system property integer. |
| 155 * | 165 * |
| 156 * Returns the property value, or -1 if error. */ | 166 * Returns the property value, or -1 if error. */ |
| 157 int VbGetSystemPropertyInt(const char* name) { | 167 int VbGetSystemPropertyInt(const char* name) { |
| 168 int value = -1; | |
| 158 | 169 |
| 159 if (!strcasecmp(name,"devsw_cur")) { | 170 if (!strcasecmp(name,"devsw_cur")) { |
| 160 return ReadGpio(GPIO_SIGNAL_TYPE_DEV); | 171 value = ReadGpio(GPIO_SIGNAL_TYPE_DEV); |
| 161 } else if (!strcasecmp(name,"devsw_boot")) { | 172 } else if (!strcasecmp(name,"devsw_boot")) { |
| 162 return ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT); | 173 value = ReadFileBit(ACPI_CHSW_PATH, CHSW_DEV_BOOT); |
| 163 } else if (!strcasecmp(name,"recoverysw_cur")) { | 174 } else if (!strcasecmp(name,"recoverysw_cur")) { |
| 164 return ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY); | 175 value = ReadGpio(GPIO_SIGNAL_TYPE_RECOVERY); |
| 165 } else if (!strcasecmp(name,"recoverysw_boot")) { | 176 } else if (!strcasecmp(name,"recoverysw_boot")) { |
| 166 return ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT); | 177 value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_BOOT); |
| 167 } else if (!strcasecmp(name,"recoverysw_ec_boot")) { | 178 } else if (!strcasecmp(name,"recoverysw_ec_boot")) { |
| 168 return ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT); | 179 value = ReadFileBit(ACPI_CHSW_PATH, CHSW_RECOVERY_EC_BOOT); |
| 169 } else if (!strcasecmp(name,"wpsw_cur")) { | 180 } else if (!strcasecmp(name,"wpsw_cur")) { |
| 170 return ReadGpio(GPIO_SIGNAL_TYPE_WP); | 181 value = ReadGpio(GPIO_SIGNAL_TYPE_WP); |
| 182 if (FwidStartsWith("Mario.") && -1 != value) | |
|
Bill Richardson
2011/02/17 19:05:49
reverse the order of this expression. you don't ha
| |
| 183 value = 1 - value; /* Mario reports this backwards */ | |
| 171 } else if (!strcasecmp(name,"wpsw_boot")) { | 184 } else if (!strcasecmp(name,"wpsw_boot")) { |
| 172 return ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT); | 185 value = ReadFileBit(ACPI_CHSW_PATH, CHSW_WP_BOOT); |
| 173 } else | 186 if (FwidStartsWith("Mario.") && -1 != value) |
|
Bill Richardson
2011/02/17 19:05:49
ditto
| |
| 174 return -1; | 187 value = 1 - value; /* Mario reports this backwards */ |
| 188 } | |
| 175 | 189 |
| 176 /* TODO: remaining properties from spec */ | 190 /* TODO: remaining properties from spec */ |
| 191 | |
| 192 return value; | |
| 177 } | 193 } |
| 178 | 194 |
| 179 | 195 |
| 180 /* Read a system property string into a destination buffer of the specified | 196 /* Read a system property string into a destination buffer of the specified |
| 181 * size. | 197 * size. |
| 182 * | 198 * |
| 183 * Returns the passed buffer, or NULL if error. */ | 199 * Returns the passed buffer, or NULL if error. */ |
| 184 const char* VbGetSystemPropertyString(const char* name, char* dest, int size) { | 200 const char* VbGetSystemPropertyString(const char* name, char* dest, int size) { |
| 185 | 201 |
| 186 if (!strcasecmp(name,"hwid")) { | 202 if (!strcasecmp(name,"hwid")) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 207 | 223 |
| 208 | 224 |
| 209 /* Set a system property string. | 225 /* Set a system property string. |
| 210 * | 226 * |
| 211 * Returns 0 if success, -1 if error. */ | 227 * Returns 0 if success, -1 if error. */ |
| 212 int VbSetSystemPropertyString(const char* name, const char* value) { | 228 int VbSetSystemPropertyString(const char* name, const char* value) { |
| 213 | 229 |
| 214 /* TODO: support setting */ | 230 /* TODO: support setting */ |
| 215 return -1; | 231 return -1; |
| 216 } | 232 } |
| OLD | NEW |