1 // SPDX-License-Identifier: GPL-2.0-only
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.
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>
11 * TODO: There are large similarities with leds-net5501.c
12 * by Alessandro Zummo <a.zummo@towertech.it>
13 * In the future leds-net5501.c should be migrated over to platform
16 #include <linux/kernel.h>
17 #include <linux/init.h>
19 #include <linux/string.h>
20 #include <linux/moduleparam.h>
21 #include <linux/leds.h>
22 #include <linux/platform_device.h>
23 #include <linux/gpio.h>
24 #include <linux/input.h>
25 #include <linux/gpio_keys.h>
26 #include <linux/dmi.h>
28 #include <asm/geode.h>
30 #define BIOS_SIGNATURE_TINYBIOS 0xf0000
31 #define BIOS_SIGNATURE_COREBOOT 0x500
32 #define BIOS_REGION_SIZE 0x10000
35 * This driver is not modular, but to keep back compatibility
36 * with existing use cases, continuing with module_param is
37 * the easiest way forward.
39 static bool force = 0;
40 module_param(force, bool, 0444);
41 /* FIXME: Award bios is not automatically detected as Alix platform */
42 MODULE_PARM_DESC(force, "Force detection as ALIX.2/ALIX.3 platform");
44 static struct gpio_keys_button alix_gpio_buttons[] = {
49 .desc = "Reset button",
52 .debounce_interval = 100,
56 static struct gpio_keys_platform_data alix_buttons_data = {
57 .buttons = alix_gpio_buttons,
58 .nbuttons = ARRAY_SIZE(alix_gpio_buttons),
62 static struct platform_device alix_buttons_dev = {
63 .name = "gpio-keys-polled",
66 .platform_data = &alix_buttons_data,
70 static struct gpio_led alix_leds[] = {
74 .default_trigger = "default-on",
80 .default_trigger = "default-off",
86 .default_trigger = "default-off",
91 static struct gpio_led_platform_data alix_leds_data = {
92 .num_leds = ARRAY_SIZE(alix_leds),
96 static struct platform_device alix_leds_dev = {
99 .dev.platform_data = &alix_leds_data,
102 static struct platform_device *alix_devs[] __initdata = {
107 static void __init register_alix(void)
109 /* Setup LED control through leds-gpio driver */
110 platform_add_devices(alix_devs, ARRAY_SIZE(alix_devs));
113 static bool __init alix_present(unsigned long bios_phys,
114 const char *alix_sig,
117 const size_t bios_len = BIOS_REGION_SIZE;
118 const char *bios_virt;
119 const char *scan_end;
124 printk(KERN_NOTICE "%s: forced to skip BIOS test, "
125 "assume system is ALIX.2/ALIX.3\n",
130 bios_virt = phys_to_virt(bios_phys);
131 scan_end = bios_virt + bios_len - (alix_sig_len + 2);
132 for (p = bios_virt; p < scan_end; p++) {
136 if (memcmp(p, alix_sig, alix_sig_len) != 0)
139 memcpy(name, p, sizeof(name));
141 /* remove the first \0 character from string */
142 a = strchr(name, '\0');
146 /* cut the string at a newline */
147 a = strchr(name, '\r');
151 tail = p + alix_sig_len;
152 if ((tail[0] == '2' || tail[0] == '3' || tail[0] == '6')) {
154 "%s: system is recognized as \"%s\"\n",
155 KBUILD_MODNAME, name);
163 static bool __init alix_present_dmi(void)
165 const char *vendor, *product;
167 vendor = dmi_get_system_info(DMI_SYS_VENDOR);
168 if (!vendor || strcmp(vendor, "PC Engines"))
171 product = dmi_get_system_info(DMI_PRODUCT_NAME);
172 if (!product || (strcmp(product, "ALIX.2D") && strcmp(product, "ALIX.6")))
175 printk(KERN_INFO "%s: system is recognized as \"%s %s\"\n",
176 KBUILD_MODNAME, vendor, product);
181 static int __init alix_init(void)
183 const char tinybios_sig[] = "PC Engines ALIX.";
184 const char coreboot_sig[] = "PC Engines\0ALIX.";
189 if (alix_present(BIOS_SIGNATURE_TINYBIOS, tinybios_sig, sizeof(tinybios_sig) - 1) ||
190 alix_present(BIOS_SIGNATURE_COREBOOT, coreboot_sig, sizeof(coreboot_sig) - 1) ||
196 device_initcall(alix_init);