postProcessingDataMemoryDefinition.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * linux/arch/arm/mach-omap2/mux.c
  3. *
  4. * OMAP2, OMAP3 and OMAP4 pin multiplexing configurations
  5. *
  6. * Copyright (C) 2004 - 2010 Texas Instruments Inc.
  7. * Copyright (C) 2003 - 2008 Nokia Corporation
  8. *
  9. * Written by Tony Lindgren
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. *
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/io.h>
  29. #include <linux/list.h>
  30. #include <linux/slab.h>
  31. #include <linux/ctype.h>
  32. #include <linux/debugfs.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/irq.h>
  36. #include <linux/interrupt.h>
  37. #include "omap_hwmod.h"
  38. #include "soc.h"
  39. #include "control.h"
  40. #include "mux.h"
  41. #include "prm.h"
  42. #include "common.h"
  43. #define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
  44. #define OMAP_MUX_BASE_SZ 0x5ca
  45. struct omap_mux_entry {
  46. struct omap_mux mux;
  47. struct list_head node;
  48. };
  49. static LIST_HEAD(mux_partitions);
  50. static DEFINE_MUTEX(muxmode_mutex);
  51. struct omap_mux_partition *omap_mux_get(const char *name)
  52. {
  53. struct omap_mux_partition *partition;
  54. list_for_each_entry(partition, &mux_partitions, node) {
  55. if (!strcmp(name, partition->name))
  56. return partition;
  57. }
  58. return NULL;
  59. }
  60. u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg)
  61. {
  62. if (partition->flags & OMAP_MUX_REG_8BIT)
  63. return __raw_readb(partition->base + reg);
  64. else
  65. return __raw_readw(partition->base + reg);
  66. }
  67. void omap_mux_write(struct omap_mux_partition *partition, u16 val,
  68. u16 reg)
  69. {
  70. if (partition->flags & OMAP_MUX_REG_8BIT)
  71. __raw_writeb(val, partition->base + reg);
  72. else
  73. __raw_writew(val, partition->base + reg);
  74. }
  75. void omap_mux_write_array(struct omap_mux_partition *partition,
  76. struct omap_board_mux *board_mux)
  77. {
  78. if (!board_mux)
  79. return;
  80. while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) {
  81. omap_mux_write(partition, board_mux->value,
  82. board_mux->reg_offset);
  83. board_mux++;
  84. }
  85. }
  86. #ifdef CONFIG_OMAP_MUX
  87. static char *omap_mux_options;
  88. static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
  89. int gpio, int val)
  90. {
  91. struct omap_mux_entry *e;
  92. struct omap_mux *gpio_mux = NULL;
  93. u16 old_mode;
  94. u16 mux_mode;
  95. int found = 0;
  96. struct list_head *muxmodes = &partition->muxmodes;
  97. if (!gpio)
  98. return -EINVAL;
  99. list_for_each_entry(e, muxmodes, node) {
  100. struct omap_mux *m = &e->mux;
  101. if (gpio == m->gpio) {
  102. gpio_mux = m;
  103. found++;
  104. }
  105. }
  106. if (found == 0) {
  107. pr_err("%s: Could not set gpio%i\n", __func__, gpio);
  108. return -ENODEV;
  109. }
  110. if (found > 1) {
  111. pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
  112. found, gpio);
  113. return -EINVAL;
  114. }
  115. old_mode = omap_mux_read(partition, gpio_mux->reg_offset);
  116. mux_mode = val & ~(OMAP_MUX_NR_MODES - 1);
  117. mux_mode |= partition->gpio;
  118. pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__,
  119. gpio_mux->muxnames[0], gpio, old_mode, mux_mode);
  120. omap_mux_write(partition, mux_mode, gpio_mux->reg_offset);
  121. return 0;
  122. }
  123. int __init omap_mux_init_gpio(int gpio, int val)
  124. {
  125. struct omap_mux_partition *partition;
  126. int ret;
  127. list_for_each_entry(partition, &mux_partitions, node) {
  128. ret = _omap_mux_init_gpio(partition, gpio, val);
  129. if (!ret)
  130. return ret;
  131. }
  132. return -ENODEV;
  133. }
  134. static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition,
  135. const char *muxname,
  136. struct omap_mux **found_mux)
  137. {
  138. struct omap_mux *mux = NULL;
  139. struct omap_mux_entry *e;
  140. const char *mode_name;
  141. int found = 0, found_mode = 0, mode0_len = 0;
  142. struct list_head *muxmodes = &partition->muxmodes;
  143. mode_name = strchr(muxname, '.');
  144. if (mode_name) {
  145. mode0_len = strlen(muxname) - strlen(mode_name);
  146. mode_name++;
  147. } else {
  148. mode_name = muxname;
  149. }
  150. list_for_each_entry(e, muxmodes, node) {
  151. char *m0_entry;
  152. int i;
  153. mux = &e->mux;
  154. m0_entry = mux->muxnames[0];
  155. /* First check for full name in mode0.muxmode format */
  156. if (mode0_len && strncmp(muxname, m0_entry, mode0_len))
  157. continue;
  158. /* Then check for muxmode only */
  159. for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
  160. char *mode_cur = mux->muxnames[i];
  161. if (!mode_cur)
  162. continue;
  163. if (!strcmp(mode_name, mode_cur)) {
  164. *found_mux = mux;
  165. found++;
  166. found_mode = i;
  167. }
  168. }
  169. }
  170. if (found == 1) {
  171. return found_mode;
  172. }
  173. if (found > 1) {
  174. pr_err("%s: Multiple signal paths (%i) for %s\n", __func__,
  175. found, muxname);
  176. return -EINVAL;
  177. }
  178. pr_err("%s: Could not find signal %s\n", __func__, muxname);
  179. return -ENODEV;
  180. }
  181. int __init omap_mux_get_by_name(const char *muxname,
  182. struct omap_mux_partition **found_partition,
  183. struct omap_mux **found_mux)
  184. {
  185. struct omap_mux_partition *partition;
  186. list_for_each_entry(partition, &mux_partitions, node) {
  187. struct omap_mux *mux = NULL;
  188. int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux);
  189. if (mux_mode < 0)
  190. continue;
  191. *found_partition = partition;
  192. *found_mux = mux;