1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * System Specific setup for PCEngines ALIX. 4 * At the moment this means setup of GPIO control of LEDs 5 * on Alix.2/3/6 boards. 6 * 7 * Copyright (C) 2008 Constantin Baranov <const@mimas.ru> 8 * Copyright (C) 2011 Ed Wildgoose <kernel@wildgooses.com> 9 * and Philip Prindeville <philipp@redfish-solutions.com> 10 */ 11 12 #include <linux/kernel.h> 13 #include <linux/init.h> 14 #include <linux/io.h> 15 #include <linux/string.h> 16 #include <linux/moduleparam.h> 17 #include <linux/dmi.h> 18 19 #include <asm/geode.h> 20 21 #include "geode-common.h" 22 23 #define BIOS_SIGNATURE_TINYBIOS 0xf0000 24 #define BIOS_SIGNATURE_COREBOOT 0x500 25 #define BIOS_REGION_SIZE 0x10000 26 27 /* 28 * This driver is not modular, but to keep back compatibility 29 * with existing use cases, continuing with module_param is 30 * the easiest way forward. 31 */ 32 static bool force = 0; 33 module_param(force, bool, 0444); 34 /* FIXME: Award bios is not automatically detected as Alix platform */ 35 MODULE_PARM_DESC(force, "Force detection as ALIX.2/ALIX.3 platform"); 36 37 static const struct geode_led alix_leds[] __initconst = { 38 { 6, true }, 39 { 25, false }, 40 { 27, false }, 41 }; 42 43 static void __init register_alix(void) 44 { 45 geode_create_restart_key(24); 46 geode_create_leds("alix", alix_leds, ARRAY_SIZE(alix_leds)); 47 } 48 49 static bool __init alix_present(unsigned long bios_phys, 50 const char *alix_sig, 51 size_t alix_sig_len) 52 { 53 const size_t bios_len = BIOS_REGION_SIZE; 54 const char *bios_virt; 55 const char *scan_end; 56 const char *p; 57 char name[64]; 58 59 if (force) { 60 printk(KERN_NOTICE "%s: forced to skip BIOS test, " 61 "assume system is ALIX.2/ALIX.3\n", 62 KBUILD_MODNAME); 63 return true; 64 } 65 66 bios_virt = phys_to_virt(bios_phys); 67 scan_end = bios_virt + bios_len - (alix_sig_len + 2); 68 for (p = bios_virt; p < scan_end; p++) { 69 const char *tail; 70 char *a; 71 72 if (memcmp(p, alix_sig, alix_sig_len) != 0) 73 continue; 74 75 memcpy(name, p, sizeof(name)); 76 77 /* remove the first \0 character from string */ 78 a = strchr(name, '\0'); 79 if (a) 80 *a = ' '; 81 82 /* cut the string at a newline */ 83 a = strchr(name, '\r'); 84 if (a) 85 *a = '\0'; 86 87 tail = p + alix_sig_len; 88 if ((tail[0] == '2' || tail[0] == '3' || tail[0] == '6')) { 89 printk(KERN_INFO 90 "%s: system is recognized as \"%s\"\n", 91 KBUILD_MODNAME, name); 92 return true; 93 } 94 } 95 96 return false; 97 } 98 99 static bool __init alix_present_dmi(void) 100 { 101 const char *vendor, *product; 102 103 vendor = dmi_get_system_info(DMI_SYS_VENDOR); 104 if (!vendor || strcmp(vendor, "PC Engines")) 105 return false; 106 107 product = dmi_get_system_info(DMI_PRODUCT_NAME); 108 if (!product || (strcmp(product, "ALIX.2D") && strcmp(product, "ALIX.6"))) 109 return false; 110 111 printk(KERN_INFO "%s: system is recognized as \"%s %s\"\n", 112 KBUILD_MODNAME, vendor, product); 113 114 return true; 115 } 116 117 static int __init alix_init(void) 118 { 119 const char tinybios_sig[] = "PC Engines ALIX."; 120 const char coreboot_sig[] = "PC Engines\0ALIX."; 121 122 if (!is_geode()) 123 return 0; 124 125 if (alix_present(BIOS_SIGNATURE_TINYBIOS, tinybios_sig, sizeof(tinybios_sig) - 1) || 126 alix_present(BIOS_SIGNATURE_COREBOOT, coreboot_sig, sizeof(coreboot_sig) - 1) || 127 alix_present_dmi()) 128 register_alix(); 129 130 return 0; 131 } 132 device_initcall(alix_init); 133