net5501.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * System Specific setup for Soekris net5501
  3. * At the moment this means setup of GPIO control of LEDs and buttons
  4. * on net5501 boards.
  5. *
  6. *
  7. * Copyright (C) 2008-2009 Tower Technologies
  8. * Written by Alessandro Zummo <a.zummo@towertech.it>
  9. *
  10. * Copyright (C) 2008 Constantin Baranov <const@mimas.ru>
  11. * Copyright (C) 2011 Ed Wildgoose <kernel@wildgooses.com>
  12. * and Philip Prindeville <philipp@redfish-solutions.com>
  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 <linux/input.h>
  27. #include <linux/gpio_keys.h>
  28. #include <asm/geode.h>
  29. #define BIOS_REGION_BASE 0xffff0000
  30. #define BIOS_REGION_SIZE 0x00010000
  31. static struct gpio_keys_button net5501_gpio_buttons[] = {
  32. {
  33. .code = KEY_RESTART,
  34. .gpio = 24,
  35. .active_low = 1,
  36. .desc = "Reset button",
  37. .type = EV_KEY,
  38. .wakeup = 0,
  39. .debounce_interval = 100,
  40. .can_disable = 0,
  41. }
  42. };
  43. static struct gpio_keys_platform_data net5501_buttons_data = {
  44. .buttons = net5501_gpio_buttons,
  45. .nbuttons = ARRAY_SIZE(net5501_gpio_buttons),
  46. .poll_interval = 20,
  47. };
  48. static struct platform_device net5501_buttons_dev = {
  49. .name = "gpio-keys-polled",
  50. .id = 1,
  51. .dev = {
  52. .platform_data = &net5501_buttons_data,
  53. }
  54. };
  55. static struct gpio_led net5501_leds[] = {
  56. {
  57. .name = "net5501:1",
  58. .gpio = 6,
  59. .default_trigger = "default-on",
  60. .active_low = 1,
  61. },
  62. };
  63. static struct gpio_led_platform_data net5501_leds_data = {
  64. .num_leds = ARRAY_SIZE(net5501_leds),
  65. .leds = net5501_leds,
  66. };
  67. static struct platform_device net5501_leds_dev = {
  68. .name = "leds-gpio",
  69. .id = -1,
  70. .dev.platform_data = &net5501_leds_data,
  71. };
  72. static struct __initdata platform_device *net5501_devs[] = {
  73. &net5501_buttons_dev,
  74. &net5501_leds_dev,
  75. };
  76. static void __init register_net5501(void)
  77. {
  78. /* Setup LED control through leds-gpio driver */
  79. platform_add_devices(net5501_devs, ARRAY_SIZE(net5501_devs));
  80. }
  81. struct net5501_board {
  82. u16 offset;
  83. u16 len;
  84. char *sig;
  85. };
  86. static struct net5501_board __initdata boards[] = {
  87. { 0xb7b, 7, "net5501" }, /* net5501 v1.33/1.33c */
  88. { 0xb1f, 7, "net5501" }, /* net5501 v1.32i */
  89. };
  90. static bool __init net5501_present(void)
  91. {
  92. int i;
  93. unsigned char *rombase, *bios;
  94. bool found = false;
  95. rombase = ioremap(BIOS_REGION_BASE, BIOS_REGION_SIZE - 1);
  96. if (!rombase) {
  97. printk(KERN_ERR "%s: failed to get rombase\n", KBUILD_MODNAME);
  98. return found;
  99. }
  100. bios = rombase + 0x20; /* null terminated */
  101. if (memcmp(bios, "comBIOS", 7))
  102. goto unmap;
  103. for (i = 0; i < ARRAY_SIZE(boards); i++) {
  104. unsigned char *model = rombase + boards[i].offset;
  105. if (!memcmp(model, boards[i].sig, boards[i].len)) {
  106. printk(KERN_INFO "%s: system is recognized as \"%s\"\n",
  107. KBUILD_MODNAME, model);
  108. found = true;
  109. break;
  110. }
  111. }
  112. unmap:
  113. iounmap(rombase);
  114. return found;
  115. }
  116. static int __init net5501_init(void)
  117. {
  118. if (!is_geode())
  119. return 0;
  120. if (!net5501_present())
  121. return 0;
  122. register_net5501();
  123. return 0;
  124. }
  125. module_init(net5501_init);
  126. MODULE_AUTHOR("Philip Prindeville <philipp@redfish-solutions.com>");
  127. MODULE_DESCRIPTION("Soekris net5501 System Setup");
  128. MODULE_LICENSE("GPL");