led.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * (C) Copyright 2006
  3. * Atmel Nordic AB <www.atmel.com>
  4. * Ulf Samuelsson <ulf@atmel.com>
  5. *
  6. * (C) Copyright 2010
  7. * Andreas Bießmann <andreas.devel@gmail.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <asm/arch/gpio.h>
  29. #include <asm/arch/at91_pmc.h>
  30. /* bit mask in PIO port B */
  31. #define GREEN_LED (1<<0)
  32. #define YELLOW_LED (1<<1)
  33. #define RED_LED (1<<2)
  34. void green_LED_on(void)
  35. {
  36. at91_pio_t *pio = (at91_pio_t *)AT91_PIO_BASE;
  37. writel(GREEN_LED, &pio->piob.codr);
  38. }
  39. void yellow_LED_on(void)
  40. {
  41. at91_pio_t *pio = (at91_pio_t *)AT91_PIO_BASE;
  42. writel(YELLOW_LED, &pio->piob.codr);
  43. }
  44. void red_LED_on(void)
  45. {
  46. at91_pio_t *pio = (at91_pio_t *)AT91_PIO_BASE;
  47. writel(RED_LED, &pio->piob.codr);
  48. }
  49. void green_LED_off(void)
  50. {
  51. at91_pio_t *pio = (at91_pio_t *)AT91_PIO_BASE;
  52. writel(GREEN_LED, &pio->piob.sodr);
  53. }
  54. void yellow_LED_off(void)
  55. {
  56. at91_pio_t *pio = (at91_pio_t *)AT91_PIO_BASE;
  57. writel(YELLOW_LED, &pio->piob.sodr);
  58. }
  59. void red_LED_off(void)
  60. {
  61. at91_pio_t *pio = (at91_pio_t *)AT91_PIO_BASE;
  62. writel(RED_LED, &pio->piob.sodr);
  63. }
  64. void coloured_LED_init (void)
  65. {
  66. at91_pmc_t *pmc = (at91_pmc_t *)AT91_PMC_BASE;
  67. at91_pio_t *pio = (at91_pio_t *)AT91_PIO_BASE;
  68. /* Enable PIOB clock */
  69. writel(1 << AT91_ID_PIOB, &pmc->pcer);
  70. /* Disable peripherals on LEDs */
  71. writel(GREEN_LED | YELLOW_LED | RED_LED, &pio->piob.per);
  72. /* Enable pins as outputs */
  73. writel(GREEN_LED | YELLOW_LED | RED_LED, &pio->piob.oer);
  74. /* Turn all LEDs OFF */
  75. writel(GREEN_LED | YELLOW_LED | RED_LED, &pio->piob.sodr);
  76. }