ebsa285.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/arm/mach-footbridge/ebsa285.c
  4. *
  5. * EBSA285 machine fixup
  6. */
  7. #include <linux/init.h>
  8. #include <linux/io.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/slab.h>
  11. #include <linux/leds.h>
  12. #include <asm/hardware/dec21285.h>
  13. #include <asm/mach-types.h>
  14. #include <asm/mach/arch.h>
  15. #include "common.h"
  16. /* LEDs */
  17. #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
  18. #define XBUS_AMBER_L BIT(0)
  19. #define XBUS_GREEN_L BIT(1)
  20. #define XBUS_RED_L BIT(2)
  21. #define XBUS_TOGGLE BIT(7)
  22. struct ebsa285_led {
  23. struct led_classdev cdev;
  24. u8 mask;
  25. };
  26. /*
  27. * The triggers lines up below will only be used if the
  28. * LED triggers are compiled in.
  29. */
  30. static const struct {
  31. const char *name;
  32. const char *trigger;
  33. } ebsa285_leds[] = {
  34. { "ebsa285:amber", "cpu0", },
  35. { "ebsa285:green", "heartbeat", },
  36. { "ebsa285:red",},
  37. };
  38. static unsigned char hw_led_state;
  39. static void __iomem *xbus;
  40. static void ebsa285_led_set(struct led_classdev *cdev,
  41. enum led_brightness b)
  42. {
  43. struct ebsa285_led *led = container_of(cdev,
  44. struct ebsa285_led, cdev);
  45. if (b == LED_OFF)
  46. hw_led_state |= led->mask;
  47. else
  48. hw_led_state &= ~led->mask;
  49. writeb(hw_led_state, xbus);
  50. }
  51. static enum led_brightness ebsa285_led_get(struct led_classdev *cdev)
  52. {
  53. struct ebsa285_led *led = container_of(cdev,
  54. struct ebsa285_led, cdev);
  55. return hw_led_state & led->mask ? LED_OFF : LED_FULL;
  56. }
  57. static int __init ebsa285_leds_init(void)
  58. {
  59. int i;
  60. if (!machine_is_ebsa285())
  61. return -ENODEV;
  62. xbus = ioremap(XBUS_CS2, SZ_4K);
  63. if (!xbus)
  64. return -ENOMEM;
  65. /* 3 LEDS all off */
  66. hw_led_state = XBUS_AMBER_L | XBUS_GREEN_L | XBUS_RED_L;
  67. writeb(hw_led_state, xbus);
  68. for (i = 0; i < ARRAY_SIZE(ebsa285_leds); i++) {
  69. struct ebsa285_led *led;
  70. led = kzalloc(sizeof(*led), GFP_KERNEL);
  71. if (!led)
  72. break;
  73. led->cdev.name = ebsa285_leds[i].name;
  74. led->cdev.brightness_set = ebsa285_led_set;
  75. led->cdev.brightness_get = ebsa285_led_get;
  76. led->cdev.default_trigger = ebsa285_leds[i].trigger;
  77. led->mask = BIT(i);
  78. if (led_classdev_register(NULL, &led->cdev) < 0) {
  79. kfree(led);
  80. break;
  81. }
  82. }
  83. return 0;
  84. }
  85. /*
  86. * Since we may have triggers on any subsystem, defer registration
  87. * until after subsystem_init.
  88. */
  89. fs_initcall(ebsa285_leds_init);
  90. #endif
  91. MACHINE_START(EBSA285, "EBSA285")
  92. /* Maintainer: Russell King */
  93. .atag_offset = 0x100,
  94. .video_start = 0x000a0000,
  95. .video_end = 0x000bffff,
  96. .map_io = footbridge_map_io,
  97. .init_early = footbridge_sched_clock,
  98. .init_irq = footbridge_init_irq,
  99. .init_time = footbridge_timer_init,
  100. .restart = footbridge_restart,
  101. MACHINE_END