net5501.c 3.3 KB

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