led.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/io.h>
  29. #include <asm/arch/hardware.h>
  30. #include <asm/arch/at91_pmc.h>
  31. #include <asm/arch/at91_pio.h>
  32. /* bit mask in PIO port B */
  33. #define GREEN_LED (1<<0)
  34. #define YELLOW_LED (1<<1)
  35. #define RED_LED (1<<2)
  36. void green_led_on(void)
  37. {
  38. at91_pio_t *pio = (at91_pio_t *)ATMEL_BASE_PIO;
  39. writel(GREEN_LED, &pio->piob.codr);
  40. }
  41. void yellow_led_on(void)
  42. {
  43. at91_pio_t *pio = (at91_pio_t *)ATMEL_BASE_PIO;
  44. writel(YELLOW_LED, &pio->piob.codr);
  45. }
  46. void red_led_on(void)
  47. {
  48. at91_pio_t *pio = (at91_pio_t *)ATMEL_BASE_PIO;
  49. writel(RED_LED, &pio->piob.codr);
  50. }
  51. void green_led_off(void)
  52. {
  53. at91_pio_t *pio = (at91_pio_t *)ATMEL_BASE_PIO;
  54. writel(GREEN_LED, &pio->piob.sodr);
  55. }
  56. void yellow_led_off(void)
  57. {
  58. at91_pio_t *pio = (at91_pio_t *)ATMEL_BASE_PIO;
  59. writel(YELLOW_LED, &pio->piob.sodr);
  60. }
  61. void red_led_off(void)
  62. {
  63. at91_pio_t *pio = (at91_pio_t *)ATMEL_BASE_PIO;
  64. writel(RED_LED, &pio->piob.sodr);
  65. }
  66. void coloured_LED_init (void)
  67. {
  68. at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
  69. at91_pio_t *pio = (at91_pio_t *)ATMEL_BASE_PIO;
  70. /* Enable PIOB clock */
  71. writel(1 << ATMEL_ID_PIOB, &pmc->pcer);
  72. /* Disable peripherals on LEDs */
  73. writel(GREEN_LED | YELLOW_LED | RED_LED, &pio->piob.per);
  74. /* Enable pins as outputs */
  75. writel(GREEN_LED | YELLOW_LED | RED_LED, &pio->piob.oer);
  76. /* Turn all LEDs OFF */
  77. writel(GREEN_LED | YELLOW_LED | RED_LED, &pio->piob.sodr);
  78. }