geos.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * System Specific setup for Traverse Technologies GEOS.
  4. * At the moment this means setup of GPIO control of LEDs.
  5. *
  6. * Copyright (C) 2008 Constantin Baranov <[email protected]>
  7. * Copyright (C) 2011 Ed Wildgoose <[email protected]>
  8. * and Philip Prindeville <[email protected]>
  9. *
  10. * TODO: There are large similarities with leds-net5501.c
  11. * by Alessandro Zummo <[email protected]>
  12. * In the future leds-net5501.c should be migrated over to platform
  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 <linux/dmi.h>
  24. #include <asm/geode.h>
  25. static struct gpio_keys_button geos_gpio_buttons[] = {
  26. {
  27. .code = KEY_RESTART,
  28. .gpio = 3,
  29. .active_low = 1,
  30. .desc = "Reset button",
  31. .type = EV_KEY,
  32. .wakeup = 0,
  33. .debounce_interval = 100,
  34. .can_disable = 0,
  35. }
  36. };
  37. static struct gpio_keys_platform_data geos_buttons_data = {
  38. .buttons = geos_gpio_buttons,
  39. .nbuttons = ARRAY_SIZE(geos_gpio_buttons),
  40. .poll_interval = 20,
  41. };
  42. static struct platform_device geos_buttons_dev = {
  43. .name = "gpio-keys-polled",
  44. .id = 1,
  45. .dev = {
  46. .platform_data = &geos_buttons_data,
  47. }
  48. };
  49. static struct gpio_led geos_leds[] = {
  50. {
  51. .name = "geos:1",
  52. .default_trigger = "default-on",
  53. },
  54. {
  55. .name = "geos:2",
  56. .default_trigger = "default-off",
  57. },
  58. {
  59. .name = "geos:3",
  60. .default_trigger = "default-off",
  61. },
  62. };
  63. static struct gpio_led_platform_data geos_leds_data = {
  64. .num_leds = ARRAY_SIZE(geos_leds),
  65. .leds = geos_leds,
  66. };
  67. static struct gpiod_lookup_table geos_leds_gpio_table = {
  68. .dev_id = "leds-gpio",
  69. .table = {
  70. /* The Geode GPIOs should be on the CS5535 companion chip */
  71. GPIO_LOOKUP_IDX("cs5535-gpio", 6, NULL, 0, GPIO_ACTIVE_LOW),
  72. GPIO_LOOKUP_IDX("cs5535-gpio", 25, NULL, 1, GPIO_ACTIVE_LOW),
  73. GPIO_LOOKUP_IDX("cs5535-gpio", 27, NULL, 2, GPIO_ACTIVE_LOW),
  74. { }
  75. },
  76. };
  77. static struct platform_device geos_leds_dev = {
  78. .name = "leds-gpio",
  79. .id = -1,
  80. .dev.platform_data = &geos_leds_data,
  81. };
  82. static struct platform_device *geos_devs[] __initdata = {
  83. &geos_buttons_dev,
  84. &geos_leds_dev,
  85. };
  86. static void __init register_geos(void)
  87. {
  88. /* Setup LED control through leds-gpio driver */
  89. gpiod_add_lookup_table(&geos_leds_gpio_table);
  90. platform_add_devices(geos_devs, ARRAY_SIZE(geos_devs));
  91. }
  92. static int __init geos_init(void)
  93. {
  94. const char *vendor, *product;
  95. if (!is_geode())
  96. return 0;
  97. vendor = dmi_get_system_info(DMI_SYS_VENDOR);
  98. if (!vendor || strcmp(vendor, "Traverse Technologies"))
  99. return 0;
  100. product = dmi_get_system_info(DMI_PRODUCT_NAME);
  101. if (!product || strcmp(product, "Geos"))
  102. return 0;
  103. printk(KERN_INFO "%s: system is recognized as \"%s %s\"\n",
  104. KBUILD_MODNAME, vendor, product);
  105. register_geos();
  106. return 0;
  107. }
  108. device_initcall(geos_init);