net5501.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/leds.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/gpio.h>
  25. #include <linux/input.h>
  26. #include <linux/gpio_keys.h>
  27. #include <asm/geode.h>
  28. #define BIOS_REGION_BASE 0xffff0000
  29. #define BIOS_REGION_SIZE 0x00010000
  30. static struct gpio_keys_button net5501_gpio_buttons[] = {
  31. {
  32. .code = KEY_RESTART,
  33. .gpio = 24,
  34. .active_low = 1,
  35. .desc = "Reset button",
  36. .type = EV_KEY,
  37. .wakeup = 0,
  38. .debounce_interval = 100,
  39. .can_disable = 0,
  40. }
  41. };
  42. static struct gpio_keys_platform_data net5501_buttons_data = {
  43. .buttons = net5501_gpio_buttons,
  44. .nbuttons = ARRAY_SIZE(net5501_gpio_buttons),
  45. .poll_interval = 20,
  46. };
  47. static struct platform_device net5501_buttons_dev = {
  48. .name = "gpio-keys-polled",
  49. .id = 1,
  50. .dev = {
  51. .platform_data = &net5501_buttons_data,
  52. }
  53. };
  54. static struct gpio_led net5501_leds[] = {
  55. {
  56. .name = "net5501:1",
  57. .gpio = 6,
  58. .default_trigger = "default-on",
  59. .active_low = 0,
  60. },
  61. };
  62. static struct gpio_led_platform_data net5501_leds_data = {
  63. .num_leds = ARRAY_SIZE(net5501_leds),
  64. .leds = net5501_leds,
  65. };
  66. static struct platform_device net5501_leds_dev = {
  67. .name = "leds-gpio",
  68. .id = -1,
  69. .dev.platform_data = &net5501_leds_data,
  70. };
  71. static struct platform_device *net5501_devs[] __initdata = {
  72. &net5501_buttons_dev,
  73. &net5501_leds_dev,
  74. };
  75. static void __init register_net5501(void)
  76. {
  77. /* Setup LED control through leds-gpio driver */
  78. platform_add_devices(net5501_devs, ARRAY_SIZE(net5501_devs));
  79. }
  80. struct net5501_board {
  81. u16 offset;
  82. u16 len;
  83. char *sig;
  84. };
  85. static struct net5501_board __initdata boards[] = {
  86. { 0xb7b, 7, "net5501" }, /* net5501 v1.33/1.33c */
  87. { 0xb1f, 7, "net5501" }, /* net5501 v1.32i */
  88. };
  89. static bool __init net5501_present(void)
  90. {
  91. int i;
  92. unsigned char *rombase, *bios;
  93. bool found = false;
  94. rombase = ioremap(BIOS_REGION_BASE, BIOS_REGION_SIZE - 1);
  95. if (!rombase) {
  96. printk(KERN_ERR "%s: failed to get rombase\n", KBUILD_MODNAME);
  97. return found;
  98. }
  99. bios = rombase + 0x20; /* null terminated */
  100. if (memcmp(bios, "comBIOS", 7))
  101. goto unmap;
  102. for (i = 0; i < ARRAY_SIZE(boards); i++) {
  103. unsigned char *model = rombase + boards[i].offset;
  104. if (!memcmp(model, boards[i].sig, boards[i].len)) {
  105. printk(KERN_INFO "%s: system is recognized as \"%s\"\n",
  106. KBUILD_MODNAME, model);
  107. found = true;
  108. break;
  109. }
  110. }
  111. unmap:
  112. iounmap(rombase);
  113. return found;
  114. }
  115. static int __init net5501_init(void)
  116. {
  117. if (!is_geode())
  118. return 0;
  119. if (!net5501_present())
  120. return 0;
  121. register_net5501();
  122. return 0;
  123. }
  124. device_initcall(net5501_init);