alix.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. *
  10. * TODO: There are large similarities with leds-net5501.c
  11. * by Alessandro Zummo <a.zummo@towertech.it>
  12. * In the future leds-net5501.c should be migrated over to platform
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2
  16. * as published by the Free Software Foundation.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/io.h>
  21. #include <linux/string.h>
  22. #include <linux/module.h>
  23. #include <linux/leds.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/gpio.h>
  26. #include <asm/geode.h>
  27. static int force = 0;
  28. module_param(force, bool, 0444);
  29. /* FIXME: Award bios is not automatically detected as Alix platform */
  30. MODULE_PARM_DESC(force, "Force detection as ALIX.2/ALIX.3 platform");
  31. static struct gpio_led alix_leds[] = {
  32. {
  33. .name = "alix:1",
  34. .gpio = 6,
  35. .default_trigger = "default-on",
  36. .active_low = 1,
  37. },
  38. {
  39. .name = "alix:2",
  40. .gpio = 25,
  41. .default_trigger = "default-off",
  42. .active_low = 1,
  43. },
  44. {
  45. .name = "alix:3",
  46. .gpio = 27,
  47. .default_trigger = "default-off",
  48. .active_low = 1,
  49. },
  50. };
  51. static struct gpio_led_platform_data alix_leds_data = {
  52. .num_leds = ARRAY_SIZE(alix_leds),
  53. .leds = alix_leds,
  54. };
  55. static struct platform_device alix_leds_dev = {
  56. .name = "leds-gpio",
  57. .id = -1,
  58. .dev.platform_data = &alix_leds_data,
  59. };
  60. static void __init register_alix(void)
  61. {
  62. /* Setup LED control through leds-gpio driver */
  63. platform_device_register(&alix_leds_dev);
  64. }
  65. static int __init alix_present(unsigned long bios_phys,
  66. const char *alix_sig,
  67. size_t alix_sig_len)
  68. {
  69. const size_t bios_len = 0x00010000;
  70. const char *bios_virt;
  71. const char *scan_end;
  72. const char *p;
  73. char name[64];
  74. if (force) {
  75. printk(KERN_NOTICE "%s: forced to skip BIOS test, "
  76. "assume system is ALIX.2/ALIX.3\n",
  77. KBUILD_MODNAME);
  78. return 1;
  79. }
  80. bios_virt = phys_to_virt(bios_phys);
  81. scan_end = bios_virt + bios_len - (alix_sig_len + 2);
  82. for (p = bios_virt; p < scan_end; p++) {
  83. const char *tail;
  84. char *a;
  85. if (memcmp(p, alix_sig, alix_sig_len) != 0)
  86. continue;
  87. memcpy(name, p, sizeof(name));
  88. /* remove the first \0 character from string */
  89. a = strchr(name, '\0');
  90. if (a)
  91. *a = ' ';
  92. /* cut the string at a newline */
  93. a = strchr(name, '\r');
  94. if (a)
  95. *a = '\0';
  96. tail = p + alix_sig_len;
  97. if ((tail[0] == '2' || tail[0] == '3')) {
  98. printk(KERN_INFO
  99. "%s: system is recognized as \"%s\"\n",
  100. KBUILD_MODNAME, name);
  101. return 1;
  102. }
  103. }
  104. return 0;
  105. }
  106. static int __init alix_init(void)
  107. {
  108. const char tinybios_sig[] = "PC Engines ALIX.";
  109. const char coreboot_sig[] = "PC Engines\0ALIX.";
  110. if (!is_geode())
  111. return 0;
  112. if (alix_present(0xf0000, tinybios_sig, sizeof(tinybios_sig) - 1) ||
  113. alix_present(0x500, coreboot_sig, sizeof(coreboot_sig) - 1))
  114. register_alix();
  115. return 0;
  116. }
  117. module_init(alix_init);
  118. MODULE_AUTHOR("Ed Wildgoose <kernel@wildgooses.com>");
  119. MODULE_DESCRIPTION("PCEngines ALIX System Setup");
  120. MODULE_LICENSE("GPL");