alix.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 <[email protected]>
  8. * Copyright (C) 2011 Ed Wildgoose <[email protected]>
  9. * and Philip Prindeville <[email protected]>
  10. *
  11. * TODO: There are large similarities with leds-net5501.c
  12. * by Alessandro Zummo <[email protected]>
  13. * In the future leds-net5501.c should be migrated over to platform
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/io.h>
  18. #include <linux/string.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/leds.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/input.h>
  23. #include <linux/gpio_keys.h>
  24. #include <linux/gpio/machine.h>
  25. #include <linux/dmi.h>
  26. #include <asm/geode.h>
  27. #define BIOS_SIGNATURE_TINYBIOS 0xf0000
  28. #define BIOS_SIGNATURE_COREBOOT 0x500
  29. #define BIOS_REGION_SIZE 0x10000
  30. /*
  31. * This driver is not modular, but to keep back compatibility
  32. * with existing use cases, continuing with module_param is
  33. * the easiest way forward.
  34. */
  35. static bool force = 0;
  36. module_param(force, bool, 0444);
  37. /* FIXME: Award bios is not automatically detected as Alix platform */
  38. MODULE_PARM_DESC(force, "Force detection as ALIX.2/ALIX.3 platform");
  39. static struct gpio_keys_button alix_gpio_buttons[] = {
  40. {
  41. .code = KEY_RESTART,
  42. .gpio = 24,
  43. .active_low = 1,
  44. .desc = "Reset button",
  45. .type = EV_KEY,
  46. .wakeup = 0,
  47. .debounce_interval = 100,
  48. .can_disable = 0,
  49. }
  50. };
  51. static struct gpio_keys_platform_data alix_buttons_data = {
  52. .buttons = alix_gpio_buttons,
  53. .nbuttons = ARRAY_SIZE(alix_gpio_buttons),
  54. .poll_interval = 20,
  55. };
  56. static struct platform_device alix_buttons_dev = {
  57. .name = "gpio-keys-polled",
  58. .id = 1,
  59. .dev = {
  60. .platform_data = &alix_buttons_data,
  61. }
  62. };
  63. static struct gpio_led alix_leds[] = {
  64. {
  65. .name = "alix:1",
  66. .default_trigger = "default-on",
  67. },
  68. {
  69. .name = "alix:2",
  70. .default_trigger = "default-off",
  71. },
  72. {
  73. .name = "alix:3",
  74. .default_trigger = "default-off",
  75. },
  76. };
  77. static struct gpio_led_platform_data alix_leds_data = {
  78. .num_leds = ARRAY_SIZE(alix_leds),
  79. .leds = alix_leds,
  80. };
  81. static struct gpiod_lookup_table alix_leds_gpio_table = {
  82. .dev_id = "leds-gpio",
  83. .table = {
  84. /* The Geode GPIOs should be on the CS5535 companion chip */
  85. GPIO_LOOKUP_IDX("cs5535-gpio", 6, NULL, 0, GPIO_ACTIVE_LOW),
  86. GPIO_LOOKUP_IDX("cs5535-gpio", 25, NULL, 1, GPIO_ACTIVE_LOW),
  87. GPIO_LOOKUP_IDX("cs5535-gpio", 27, NULL, 2, GPIO_ACTIVE_LOW),
  88. { }
  89. },
  90. };
  91. static struct platform_device alix_leds_dev = {
  92. .name = "leds-gpio",
  93. .id = -1,
  94. .dev.platform_data = &alix_leds_data,
  95. };
  96. static struct platform_device *alix_devs[] __initdata = {
  97. &alix_buttons_dev,
  98. &alix_leds_dev,
  99. };
  100. static void __init register_alix(void)
  101. {
  102. /* Setup LED control through leds-gpio driver */
  103. gpiod_add_lookup_table(&alix_leds_gpio_table);
  104. platform_add_devices(alix_devs, ARRAY_SIZE(alix_devs));
  105. }
  106. static bool __init alix_present(unsigned long bios_phys,
  107. const char *alix_sig,
  108. size_t alix_sig_len)
  109. {
  110. const size_t bios_len = BIOS_REGION_SIZE;
  111. const char *bios_virt;
  112. const char *scan_end;
  113. const char *p;
  114. char name[64];
  115. if (force) {
  116. printk(KERN_NOTICE "%s: forced to skip BIOS test, "
  117. "assume system is ALIX.2/ALIX.3\n",
  118. KBUILD_MODNAME);
  119. return true;
  120. }
  121. bios_virt = phys_to_virt(bios_phys);
  122. scan_end = bios_virt + bios_len - (alix_sig_len + 2);
  123. for (p = bios_virt; p < scan_end; p++) {
  124. const char *tail;
  125. char *a;
  126. if (memcmp(p, alix_sig, alix_sig_len) != 0)
  127. continue;
  128. memcpy(name, p, sizeof(name));
  129. /* remove the first \0 character from string */
  130. a = strchr(name, '\0');
  131. if (a)
  132. *a = ' ';
  133. /* cut the string at a newline */
  134. a = strchr(name, '\r');
  135. if (a)
  136. *a = '\0';
  137. tail = p + alix_sig_len;
  138. if ((tail[0] == '2' || tail[0] == '3' || tail[0] == '6')) {
  139. printk(KERN_INFO
  140. "%s: system is recognized as \"%s\"\n",
  141. KBUILD_MODNAME, name);
  142. return true;
  143. }
  144. }
  145. return false;
  146. }
  147. static bool __init alix_present_dmi(void)
  148. {
  149. const char *vendor, *product;
  150. vendor = dmi_get_system_info(DMI_SYS_VENDOR);
  151. if (!vendor || strcmp(vendor, "PC Engines"))
  152. return false;
  153. product = dmi_get_system_info(DMI_PRODUCT_NAME);
  154. if (!product || (strcmp(product, "ALIX.2D") && strcmp(product, "ALIX.6")))
  155. return false;
  156. printk(KERN_INFO "%s: system is recognized as \"%s %s\"\n",
  157. KBUILD_MODNAME, vendor, product);
  158. return true;
  159. }
  160. static int __init alix_init(void)
  161. {
  162. const char tinybios_sig[] = "PC Engines ALIX.";
  163. const char coreboot_sig[] = "PC Engines\0ALIX.";
  164. if (!is_geode())
  165. return 0;
  166. if (alix_present(BIOS_SIGNATURE_TINYBIOS, tinybios_sig, sizeof(tinybios_sig) - 1) ||
  167. alix_present(BIOS_SIGNATURE_COREBOOT, coreboot_sig, sizeof(coreboot_sig) - 1) ||
  168. alix_present_dmi())
  169. register_alix();
  170. return 0;
  171. }
  172. device_initcall(alix_init);