alix.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * System Specific setup for PCEngines ALIX.
  3. * At the moment this means setup of GPIO control of LEDs
  4. * on Alix.2/3/6 boards.
  5. *
  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. * 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
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2
  17. * as published by the Free Software Foundation.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/io.h>
  22. #include <linux/string.h>
  23. #include <linux/module.h>
  24. #include <linux/leds.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/gpio.h>
  27. #include <linux/input.h>
  28. #include <linux/gpio_keys.h>
  29. #include <linux/dmi.h>
  30. #include <asm/geode.h>
  31. #define BIOS_SIGNATURE_TINYBIOS 0xf0000
  32. #define BIOS_SIGNATURE_COREBOOT 0x500
  33. #define BIOS_REGION_SIZE 0x10000
  34. static bool force = 0;
  35. module_param(force, bool, 0444);
  36. /* FIXME: Award bios is not automatically detected as Alix platform */
  37. MODULE_PARM_DESC(force, "Force detection as ALIX.2/ALIX.3 platform");
  38. static struct gpio_keys_button alix_gpio_buttons[] = {
  39. {
  40. .code = KEY_RESTART,
  41. .gpio = 24,
  42. .active_low = 1,
  43. .desc = "Reset button",
  44. .type = EV_KEY,
  45. .wakeup = 0,
  46. .debounce_interval = 100,
  47. .can_disable = 0,
  48. }
  49. };
  50. static struct gpio_keys_platform_data alix_buttons_data = {
  51. .buttons = alix_gpio_buttons,
  52. .nbuttons = ARRAY_SIZE(alix_gpio_buttons),
  53. .poll_interval = 20,
  54. };
  55. static struct platform_device alix_buttons_dev = {
  56. .name = "gpio-keys-polled",
  57. .id = 1,
  58. .dev = {
  59. .platform_data = &alix_buttons_data,
  60. }
  61. };
  62. static struct gpio_led alix_leds[] = {
  63. {
  64. .name = "alix:1",
  65. .gpio = 6,
  66. .default_trigger = "default-on",
  67. .active_low = 1,
  68. },
  69. {
  70. .name = "alix:2",
  71. .gpio = 25,
  72. .default_trigger = "default-off",
  73. .active_low = 1,
  74. },
  75. {
  76. .name = "alix:3",
  77. .gpio = 27,
  78. .default_trigger = "default-off",
  79. .active_low = 1,
  80. },
  81. };
  82. static struct gpio_led_platform_data alix_leds_data = {
  83. .num_leds = ARRAY_SIZE(alix_leds),
  84. .leds = alix_leds,
  85. };
  86. static struct platform_device alix_leds_dev = {
  87. .name = "leds-gpio",
  88. .id = -1,
  89. .dev.platform_data = &alix_leds_data,
  90. };
  91. static struct __initdata platform_device *alix_devs[] = {
  92. &alix_buttons_dev,
  93. &alix_leds_dev,
  94. };
  95. static void __init register_alix(void)
  96. {
  97. /* Setup LED control through leds-gpio driver */
  98. platform_add_devices(alix_devs, ARRAY_SIZE(alix_devs));
  99. }
  100. static bool __init alix_present(unsigned long bios_phys,
  101. const char *alix_sig,
  102. size_t alix_sig_len)
  103. {
  104. const size_t bios_len = BIOS_REGION_SIZE;
  105. const char *bios_virt;
  106. const char *scan_end;
  107. const char *p;
  108. char name[64];
  109. if (force) {
  110. printk(KERN_NOTICE "%s: forced to skip BIOS test, "
  111. "assume system is ALIX.2/ALIX.3\n",
  112. KBUILD_MODNAME);
  113. return true;
  114. }
  115. bios_virt = phys_to_virt(bios_phys);
  116. scan_end = bios_virt + bios_len - (alix_sig_len + 2);
  117. for (p = bios_virt; p < scan_end; p++) {
  118. const char *tail;
  119. char *a;
  120. if (memcmp(p, alix_sig, alix_sig_len) != 0)
  121. continue;
  122. memcpy(name, p, sizeof(name));
  123. /* remove the first \0 character from string */
  124. a = strchr(name, '\0');
  125. if (a)
  126. *a = ' ';
  127. /* cut the string at a newline */
  128. a = strchr(name, '\r');
  129. if (a)
  130. *a = '\0';
  131. tail = p + alix_sig_len;
  132. if ((tail[0] == '2' || tail[0] == '3' || tail[0] == '6')) {
  133. printk(KERN_INFO
  134. "%s: system is recognized as \"%s\"\n",
  135. KBUILD_MODNAME, name);
  136. return true;
  137. }
  138. }
  139. return false;
  140. }
  141. static bool __init alix_present_dmi(void)
  142. {
  143. const char *vendor, *product;
  144. vendor = dmi_get_system_info(DMI_SYS_VENDOR);
  145. if (!vendor || strcmp(vendor, "PC Engines"))
  146. return false;
  147. product = dmi_get_system_info(DMI_PRODUCT_NAME);
  148. if (!product || (strcmp(product, "ALIX.2D") && strcmp(product, "ALIX.6")))
  149. return false;
  150. printk(KERN_INFO "%s: system is recognized as \"%s %s\"\n",
  151. KBUILD_MODNAME, vendor, product);
  152. return true;
  153. }
  154. static int __init alix_init(void)
  155. {
  156. const char tinybios_sig[] = "PC Engines ALIX.";
  157. const char coreboot_sig[] = "PC Engines\0ALIX.";
  158. if (!is_geode())
  159. return 0;
  160. if (alix_present(BIOS_SIGNATURE_TINYBIOS, tinybios_sig, sizeof(tinybios_sig) - 1) ||
  161. alix_present(BIOS_SIGNATURE_COREBOOT, coreboot_sig, sizeof(coreboot_sig) - 1) ||
  162. alix_present_dmi())
  163. register_alix();
  164. return 0;
  165. }
  166. module_init(alix_init);
  167. MODULE_AUTHOR("Ed Wildgoose <kernel@wildgooses.com>");
  168. MODULE_DESCRIPTION("PCEngines ALIX System Setup");
  169. MODULE_LICENSE("GPL");