gpio.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * nios2 gpio driver
  3. *
  4. * This gpio core is described in http://nioswiki.com/GPIO
  5. * bit[0] data
  6. * bit[1] output enable
  7. *
  8. * When CONFIG_SYS_GPIO_BASE is not defined, the board may either
  9. * provide its own driver or the altera_pio driver may be used.
  10. *
  11. * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #ifndef _ASM_NIOS2_GPIO_H_
  18. #define _ASM_NIOS2_GPIO_H_
  19. #ifdef CONFIG_SYS_GPIO_BASE
  20. #include <asm/io.h>
  21. static inline int gpio_request(unsigned gpio, const char *label)
  22. {
  23. return 0;
  24. }
  25. static inline int gpio_free(unsigned gpio)
  26. {
  27. return 0;
  28. }
  29. static inline int gpio_direction_input(unsigned gpio)
  30. {
  31. writel(1, CONFIG_SYS_GPIO_BASE + (gpio << 2));
  32. return 0;
  33. }
  34. static inline int gpio_direction_output(unsigned gpio, int value)
  35. {
  36. writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
  37. return 0;
  38. }
  39. static inline int gpio_get_value(unsigned gpio)
  40. {
  41. return readl(CONFIG_SYS_GPIO_BASE + (gpio << 2));
  42. }
  43. static inline void gpio_set_value(unsigned gpio, int value)
  44. {
  45. writel(value ? 3 : 2, CONFIG_SYS_GPIO_BASE + (gpio << 2));
  46. }
  47. static inline int gpio_is_valid(int number)
  48. {
  49. return ((unsigned)number) < CONFIG_SYS_GPIO_WIDTH;
  50. }
  51. #else
  52. #ifdef CONFIG_ALTERA_PIO
  53. extern int altera_pio_init(u32 base, u8 width, char iot,
  54. u32 rstval, u32 negmask,
  55. const char *label);
  56. extern void altera_pio_info(void);
  57. #define gpio_status() altera_pio_info()
  58. #endif
  59. extern int gpio_request(unsigned gpio, const char *label);
  60. extern int gpio_free(unsigned gpio);
  61. extern int gpio_direction_input(unsigned gpio);
  62. extern int gpio_direction_output(unsigned gpio, int value);
  63. extern int gpio_get_value(unsigned gpio);
  64. extern void gpio_set_value(unsigned gpio, int value);
  65. extern int gpio_is_valid(int number);
  66. #endif /* CONFIG_SYS_GPIO_BASE */
  67. #endif /* _ASM_NIOS2_GPIO_H_ */