netxbig.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * arch/arm/mach-mvbu/board-netxbig.c
  3. *
  4. * LaCie 2Big and 5Big Network v2 board setup
  5. *
  6. * Copyright (C) 2010 Simon Guinot <sguinot@lacie.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/of.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/platform_data/leds-kirkwood-netxbig.h>
  22. #include "common.h"
  23. /*****************************************************************************
  24. * GPIO extension LEDs
  25. ****************************************************************************/
  26. /*
  27. * The LEDs are controlled by a CPLD and can be configured through a GPIO
  28. * extension bus:
  29. *
  30. * - address register : bit [0-2] -> GPIO [47-49]
  31. * - data register : bit [0-2] -> GPIO [44-46]
  32. * - enable register : GPIO 29
  33. */
  34. static int netxbig_v2_gpio_ext_addr[] = { 47, 48, 49 };
  35. static int netxbig_v2_gpio_ext_data[] = { 44, 45, 46 };
  36. static struct netxbig_gpio_ext netxbig_v2_gpio_ext = {
  37. .addr = netxbig_v2_gpio_ext_addr,
  38. .num_addr = ARRAY_SIZE(netxbig_v2_gpio_ext_addr),
  39. .data = netxbig_v2_gpio_ext_data,
  40. .num_data = ARRAY_SIZE(netxbig_v2_gpio_ext_data),
  41. .enable = 29,
  42. };
  43. /*
  44. * Address register selection:
  45. *
  46. * addr | register
  47. * ----------------------------
  48. * 0 | front LED
  49. * 1 | front LED brightness
  50. * 2 | SATA LED brightness
  51. * 3 | SATA0 LED
  52. * 4 | SATA1 LED
  53. * 5 | SATA2 LED
  54. * 6 | SATA3 LED
  55. * 7 | SATA4 LED
  56. *
  57. * Data register configuration:
  58. *
  59. * data | LED brightness
  60. * -------------------------------------------------
  61. * 0 | min (off)
  62. * - | -
  63. * 7 | max
  64. *
  65. * data | front LED mode
  66. * -------------------------------------------------
  67. * 0 | fix off
  68. * 1 | fix blue on
  69. * 2 | fix red on
  70. * 3 | blink blue on=1 sec and blue off=1 sec
  71. * 4 | blink red on=1 sec and red off=1 sec
  72. * 5 | blink blue on=2.5 sec and red on=0.5 sec
  73. * 6 | blink blue on=1 sec and red on=1 sec
  74. * 7 | blink blue on=0.5 sec and blue off=2.5 sec
  75. *
  76. * data | SATA LED mode
  77. * -------------------------------------------------
  78. * 0 | fix off
  79. * 1 | SATA activity blink
  80. * 2 | fix red on
  81. * 3 | blink blue on=1 sec and blue off=1 sec
  82. * 4 | blink red on=1 sec and red off=1 sec
  83. * 5 | blink blue on=2.5 sec and red on=0.5 sec
  84. * 6 | blink blue on=1 sec and red on=1 sec
  85. * 7 | fix blue on
  86. */
  87. static int netxbig_v2_red_mled[NETXBIG_LED_MODE_NUM] = {
  88. [NETXBIG_LED_OFF] = 0,
  89. [NETXBIG_LED_ON] = 2,
  90. [NETXBIG_LED_SATA] = NETXBIG_LED_INVALID_MODE,
  91. [NETXBIG_LED_TIMER1] = 4,
  92. [NETXBIG_LED_TIMER2] = NETXBIG_LED_INVALID_MODE,
  93. };
  94. static int netxbig_v2_blue_pwr_mled[NETXBIG_LED_MODE_NUM] = {
  95. [NETXBIG_LED_OFF] = 0,
  96. [NETXBIG_LED_ON] = 1,
  97. [NETXBIG_LED_SATA] = NETXBIG_LED_INVALID_MODE,
  98. [NETXBIG_LED_TIMER1] = 3,
  99. [NETXBIG_LED_TIMER2] = 7,
  100. };
  101. static int netxbig_v2_blue_sata_mled[NETXBIG_LED_MODE_NUM] = {
  102. [NETXBIG_LED_OFF] = 0,
  103. [NETXBIG_LED_ON] = 7,
  104. [NETXBIG_LED_SATA] = 1,
  105. [NETXBIG_LED_TIMER1] = 3,
  106. [NETXBIG_LED_TIMER2] = NETXBIG_LED_INVALID_MODE,
  107. };
  108. static struct netxbig_led_timer netxbig_v2_led_timer[] = {
  109. [0] = {
  110. .delay_on = 500,
  111. .delay_off = 500,
  112. .mode = NETXBIG_LED_TIMER1,
  113. },
  114. [1] = {
  115. .delay_on = 500,
  116. .delay_off = 1000,
  117. .mode = NETXBIG_LED_TIMER2,
  118. },
  119. };
  120. #define NETXBIG_LED(_name, maddr, mval, baddr) \
  121. { .name = _name, \
  122. .mode_addr = maddr, \
  123. .mode_val = mval, \
  124. .bright_addr = baddr }
  125. static struct netxbig_led net2big_v2_leds_ctrl[] = {
  126. NETXBIG_LED("net2big-v2:blue:power", 0, netxbig_v2_blue_pwr_mled, 1),
  127. NETXBIG_LED("net2big-v2:red:power", 0, netxbig_v2_red_mled, 1),
  128. NETXBIG_LED("net2big-v2:blue:sata0", 3, netxbig_v2_blue_sata_mled, 2),
  129. NETXBIG_LED("net2big-v2:red:sata0", 3, netxbig_v2_red_mled, 2),
  130. NETXBIG_LED("net2big-v2:blue:sata1", 4, netxbig_v2_blue_sata_mled, 2),
  131. NETXBIG_LED("net2big-v2:red:sata1", 4, netxbig_v2_red_mled, 2),
  132. };
  133. static struct netxbig_led_platform_data net2big_v2_leds_data = {
  134. .gpio_ext = &netxbig_v2_gpio_ext,
  135. .timer = netxbig_v2_led_timer,
  136. .num_timer = ARRAY_SIZE(netxbig_v2_led_timer),
  137. .leds = net2big_v2_leds_ctrl,
  138. .num_leds = ARRAY_SIZE(net2big_v2_leds_ctrl),
  139. };
  140. static struct netxbig_led net5big_v2_leds_ctrl[] = {
  141. NETXBIG_LED("net5big-v2:blue:power", 0, netxbig_v2_blue_pwr_mled, 1),
  142. NETXBIG_LED("net5big-v2:red:power", 0, netxbig_v2_red_mled, 1),
  143. NETXBIG_LED("net5big-v2:blue:sata0", 3, netxbig_v2_blue_sata_mled, 2),
  144. NETXBIG_LED("net5big-v2:red:sata0", 3, netxbig_v2_red_mled, 2),
  145. NETXBIG_LED("net5big-v2:blue:sata1", 4, netxbig_v2_blue_sata_mled, 2),
  146. NETXBIG_LED("net5big-v2:red:sata1", 4, netxbig_v2_red_mled, 2),
  147. NETXBIG_LED("net5big-v2:blue:sata2", 5, netxbig_v2_blue_sata_mled, 2),
  148. NETXBIG_LED("net5big-v2:red:sata2", 5, netxbig_v2_red_mled, 2),
  149. NETXBIG_LED("net5big-v2:blue:sata3", 6, netxbig_v2_blue_sata_mled, 2),
  150. NETXBIG_LED("net5big-v2:red:sata3", 6, netxbig_v2_red_mled, 2),
  151. NETXBIG_LED("net5big-v2:blue:sata4", 7, netxbig_v2_blue_sata_mled, 2),
  152. NETXBIG_LED("net5big-v2:red:sata4", 7, netxbig_v2_red_mled, 2),
  153. };
  154. static struct netxbig_led_platform_data net5big_v2_leds_data = {
  155. .gpio_ext = &netxbig_v2_gpio_ext,
  156. .timer = netxbig_v2_led_timer,
  157. .num_timer = ARRAY_SIZE(netxbig_v2_led_timer),
  158. .leds = net5big_v2_leds_ctrl,
  159. .num_leds = ARRAY_SIZE(net5big_v2_leds_ctrl),
  160. };
  161. static struct platform_device netxbig_v2_leds = {
  162. .name = "leds-netxbig",
  163. .id = -1,
  164. .dev = {
  165. .platform_data = &net2big_v2_leds_data,
  166. },
  167. };
  168. void __init netxbig_init(void)
  169. {
  170. if (of_machine_is_compatible("lacie,net5big_v2"))
  171. netxbig_v2_leds.dev.platform_data = &net5big_v2_leds_data;
  172. platform_device_register(&netxbig_v2_leds);
  173. }