#define pr_fmt(fmt) "avm-hw-config: " fmt #include #include #include #include struct _avm_hw_config *avm_current_hw_config = NULL; EXPORT_SYMBOL(avm_current_hw_config); static struct avm_hwrev_info avm_hwrev_info = { }; struct avm_hwrev_info avm_get_hwrev(void) { char *s; if (avm_hwrev_info.hwrev) return avm_hwrev_info; s = prom_getenv("HWRevision"); avm_hwrev_info.hwrev = s ? simple_strtoul(s, NULL, 10) : 0; s = prom_getenv("HWSubRevision"); avm_hwrev_info.subrev = s ? simple_strtoul(s, NULL, 10) : 1; return avm_hwrev_info; } EXPORT_SYMBOL(avm_get_hwrev); struct _avm_hw_config *avm_get_hw_config_table(void) { static struct _avm_hw_config *current_config_table = NULL; struct avm_hwrev_info hwinfo; unsigned int i; if (current_config_table) return current_config_table; hwinfo = avm_get_hwrev(); pr_debug("searching AVM hardware table for HW rev. %u, sub rev. %u\n", hwinfo.hwrev, hwinfo.subrev); if (unlikely(hwinfo.hwrev == 0)) { pr_alert("no HWRevision detected in environment variables\n"); BUG_ON(1); return NULL; } for (i = 0; avm_hw_config_tables[i].hwrev; i++) { pr_debug("found AVM hw table for HW rev. %u, sub rev. %u\n", avm_hw_config_tables[i].hwrev, avm_hw_config_tables[i].hwsubrev); if (avm_hw_config_tables[i].hwrev != hwinfo.hwrev) continue; if ((avm_hw_config_tables[i].hwsubrev == 0) || (avm_hw_config_tables[i].hwsubrev == hwinfo.subrev)) { pr_debug("selecting AVM hw table %d for HW rev. %u, sub rev. %u\n", i, avm_hw_config_tables[i].hwrev, avm_hw_config_tables[i].hwsubrev); current_config_table = avm_hw_config_tables[i].table; return current_config_table; } } pr_alert("No hardware configuration found for HWRevision %d\n", hwinfo.hwrev); BUG_ON(1); return NULL; } EXPORT_SYMBOL(avm_get_hw_config_table);