io.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Helper functions for I/O pins.
  3. *
  4. * Copyright (c) 2005-2007 Axis Communications AB.
  5. */
  6. #include <linux/types.h>
  7. #include <linux/errno.h>
  8. #include <linux/init.h>
  9. #include <linux/string.h>
  10. #include <linux/ctype.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <asm/io.h>
  14. #include <mach/pinmux.h>
  15. #include <hwregs/gio_defs.h>
  16. struct crisv32_ioport crisv32_ioports[] = {
  17. {
  18. (unsigned long *)REG_ADDR(gio, regi_gio, rw_pa_oe),
  19. (unsigned long *)REG_ADDR(gio, regi_gio, rw_pa_dout),
  20. (unsigned long *)REG_ADDR(gio, regi_gio, r_pa_din),
  21. 32
  22. },
  23. {
  24. (unsigned long *)REG_ADDR(gio, regi_gio, rw_pb_oe),
  25. (unsigned long *)REG_ADDR(gio, regi_gio, rw_pb_dout),
  26. (unsigned long *)REG_ADDR(gio, regi_gio, r_pb_din),
  27. 32
  28. },
  29. {
  30. (unsigned long *)REG_ADDR(gio, regi_gio, rw_pc_oe),
  31. (unsigned long *)REG_ADDR(gio, regi_gio, rw_pc_dout),
  32. (unsigned long *)REG_ADDR(gio, regi_gio, r_pc_din),
  33. 16
  34. },
  35. };
  36. #define NBR_OF_PORTS ARRAY_SIZE(crisv32_ioports)
  37. struct crisv32_iopin crisv32_led_net0_green;
  38. struct crisv32_iopin crisv32_led_net0_red;
  39. struct crisv32_iopin crisv32_led2_green;
  40. struct crisv32_iopin crisv32_led2_red;
  41. struct crisv32_iopin crisv32_led3_green;
  42. struct crisv32_iopin crisv32_led3_red;
  43. /* Dummy port used when green LED and red LED is on the same bit */
  44. static unsigned long io_dummy;
  45. static struct crisv32_ioport dummy_port = {
  46. &io_dummy,
  47. &io_dummy,
  48. &io_dummy,
  49. 32
  50. };
  51. static struct crisv32_iopin dummy_led = {
  52. &dummy_port,
  53. 0
  54. };
  55. static int __init crisv32_io_init(void)
  56. {
  57. int ret = 0;
  58. u32 i;
  59. /* Locks *should* be dynamically initialized. */
  60. for (i = 0; i < ARRAY_SIZE(crisv32_ioports); i++)
  61. spin_lock_init(&crisv32_ioports[i].lock);
  62. spin_lock_init(&dummy_port.lock);
  63. /* Initialize LEDs */
  64. #if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO))
  65. ret += crisv32_io_get_name(&crisv32_led_net0_green,
  66. CONFIG_ETRAX_LED_G_NET0);
  67. crisv32_io_set_dir(&crisv32_led_net0_green, crisv32_io_dir_out);
  68. if (strcmp(CONFIG_ETRAX_LED_G_NET0, CONFIG_ETRAX_LED_R_NET0)) {
  69. ret += crisv32_io_get_name(&crisv32_led_net0_red,
  70. CONFIG_ETRAX_LED_R_NET0);
  71. crisv32_io_set_dir(&crisv32_led_net0_red, crisv32_io_dir_out);
  72. } else
  73. crisv32_led_net0_red = dummy_led;
  74. #endif
  75. ret += crisv32_io_get_name(&crisv32_led2_green, CONFIG_ETRAX_V32_LED2G);
  76. ret += crisv32_io_get_name(&crisv32_led2_red, CONFIG_ETRAX_V32_LED2R);
  77. ret += crisv32_io_get_name(&crisv32_led3_green, CONFIG_ETRAX_V32_LED3G);
  78. ret += crisv32_io_get_name(&crisv32_led3_red, CONFIG_ETRAX_V32_LED3R);
  79. crisv32_io_set_dir(&crisv32_led2_green, crisv32_io_dir_out);
  80. crisv32_io_set_dir(&crisv32_led2_red, crisv32_io_dir_out);
  81. crisv32_io_set_dir(&crisv32_led3_green, crisv32_io_dir_out);
  82. crisv32_io_set_dir(&crisv32_led3_red, crisv32_io_dir_out);
  83. return ret;
  84. }
  85. __initcall(crisv32_io_init);
  86. int crisv32_io_get(struct crisv32_iopin *iopin,
  87. unsigned int port, unsigned int pin)
  88. {
  89. if (port > NBR_OF_PORTS)
  90. return -EINVAL;
  91. if (port > crisv32_ioports[port].pin_count)
  92. return -EINVAL;
  93. iopin->bit = 1 << pin;
  94. iopin->port = &crisv32_ioports[port];
  95. if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio))
  96. return -EIO;
  97. return 0;
  98. }
  99. int crisv32_io_get_name(struct crisv32_iopin *iopin, const char *name)
  100. {
  101. int port;
  102. int pin;
  103. if (toupper(*name) == 'P')
  104. name++;
  105. if (toupper(*name) < 'A' || toupper(*name) > 'E')
  106. return -EINVAL;
  107. port = toupper(*name) - 'A';
  108. name++;
  109. pin = simple_strtoul(name, NULL, 10);
  110. if (pin < 0 || pin > crisv32_ioports[port].pin_count)
  111. return -EINVAL;
  112. iopin->bit = 1 << pin;
  113. iopin->port = &crisv32_ioports[port];
  114. if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio))
  115. return -EIO;
  116. return 0;
  117. }
  118. #ifdef CONFIG_PCI
  119. /* PCI I/O access stuff */
  120. struct cris_io_operations *cris_iops = NULL;
  121. EXPORT_SYMBOL(cris_iops);
  122. #endif