postProcessingDataMemoryDefinition.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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;
  193. return mux_mode;
  194. }
  195. return -ENODEV;
  196. }
  197. int __init omap_mux_init_signal(const char *muxname, int val)
  198. {
  199. struct omap_mux_partition *partition = NULL;
  200. struct omap_mux *mux = NULL;
  201. u16 old_mode;
  202. int mux_mode;
  203. mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
  204. if (mux_mode < 0 || !mux)
  205. return mux_mode;
  206. old_mode = omap_mux_read(partition, mux->reg_offset);
  207. mux_mode |= val;
  208. pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n",
  209. __func__, muxname, old_mode, mux_mode);
  210. omap_mux_write(partition, mux_mode, mux->reg_offset);
  211. return 0;
  212. }
  213. struct omap_hwmod_mux_info * __init
  214. omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
  215. {
  216. struct omap_hwmod_mux_info *hmux;
  217. int i, nr_pads_dynamic = 0;
  218. if (!bpads || nr_pads < 1)
  219. return NULL;
  220. hmux = kzalloc(sizeof(struct omap_hwmod_mux_info), GFP_KERNEL);
  221. if (!hmux)
  222. goto err1;
  223. hmux->nr_pads = nr_pads;
  224. hmux->pads = kzalloc(sizeof(struct omap_device_pad) *
  225. nr_pads, GFP_KERNEL);
  226. if (!hmux->pads)
  227. goto err2;
  228. for (i = 0; i < hmux->nr_pads; i++) {
  229. struct omap_mux_partition *partition;
  230. struct omap_device_pad *bpad = &bpads[i], *pad = &hmux->pads[i];
  231. struct omap_mux *mux;
  232. int mux_mode;
  233. mux_mode = omap_mux_get_by_name(bpad->name, &partition, &mux);
  234. if (mux_mode < 0)
  235. goto err3;
  236. if (!pad->partition)
  237. pad->partition = partition;
  238. if (!pad->mux)
  239. pad->mux = mux;
  240. pad->name = kzalloc(strlen(bpad->name) + 1, GFP_KERNEL);
  241. if (!pad->name) {
  242. int j;
  243. for (j = i - 1; j >= 0; j--)
  244. kfree(hmux->pads[j].name);
  245. goto err3;
  246. }
  247. strcpy(pad->name, bpad->name);
  248. pad->flags = bpad->flags;
  249. pad->enable = bpad->enable;
  250. pad->idle = bpad->idle;
  251. pad->off = bpad->off;
  252. if (pad->flags &
  253. (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP))
  254. nr_pads_dynamic++;
  255. pr_debug("%s: Initialized %s\n", __func__, pad->name);
  256. }
  257. if (!nr_pads_dynamic)
  258. return hmux;
  259. /*
  260. * Add pads that need dynamic muxing into a separate list
  261. */
  262. hmux->nr_pads_dynamic = nr_pads_dynamic;
  263. hmux->pads_dynamic = kzalloc(sizeof(struct omap_device_pad *) *
  264. nr_pads_dynamic, GFP_KERNEL);
  265. if (!hmux->pads_dynamic) {
  266. pr_err("%s: Could not allocate dynamic pads\n", __func__);
  267. return hmux;
  268. }
  269. nr_pads_dynamic = 0;
  270. for (i = 0; i < hmux->nr_pads; i++) {
  271. struct omap_device_pad *pad = &hmux->pads[i];
  272. if (pad->flags &
  273. (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP)) {
  274. pr_debug("%s: pad %s tagged dynamic\n",
  275. __func__, pad->name);
  276. hmux->pads_dynamic[nr_pads_dynamic] = pad;
  277. nr_pads_dynamic++;
  278. }
  279. }
  280. return hmux;
  281. err3:
  282. kfree(hmux->pads);
  283. err2:
  284. kfree(hmux);
  285. err1:
  286. pr_err("%s: Could not allocate device mux entry\n", __func__);
  287. return NULL;
  288. }
  289. /**
  290. * omap_hwmod_mux_scan_wakeups - omap hwmod scan wakeup pads
  291. * @hmux: Pads for a hwmod
  292. * @mpu_irqs: MPU irq array for a hwmod
  293. *
  294. * Scans the wakeup status of pads for a single hwmod. If an irq
  295. * array is defined for this mux, the parser will call the registered
  296. * ISRs for corresponding pads, otherwise the parser will stop at the
  297. * first wakeup active pad and return. Returns true if there is a
  298. * pending and non-served wakeup event for the mux, otherwise false.
  299. */
  300. static bool omap_hwmod_mux_scan_wakeups(struct omap_hwmod_mux_info *hmux,
  301. struct omap_hwmod_irq_info *mpu_irqs)
  302. {
  303. int i, irq;
  304. unsigned int val;
  305. u32 handled_irqs = 0;
  306. for (i = 0; i < hmux->nr_pads_dynamic; i++) {
  307. struct omap_device_pad *pad = hmux->pads_dynamic[i];
  308. if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP) ||
  309. !(pad->idle & OMAP_WAKEUP_EN))
  310. continue;
  311. val = omap_mux_read(pad->partition, pad->mux->reg_offset);
  312. if (!(val & OMAP_WAKEUP_EVENT))
  313. continue;
  314. if (!hmux->irqs)
  315. return true;
  316. irq = hmux->irqs[i];
  317. /* make sure we only handle each irq once */
  318. if (handled_irqs & 1 << irq)
  319. continue;
  320. handled_irqs |= 1 << irq;
  321. generic_handle_irq(mpu_irqs[irq].irq);
  322. }
  323. return false;
  324. }
  325. /**
  326. * _omap_hwmod_mux_handle_irq - Process wakeup events for a single hwmod
  327. *
  328. * Checks a single hwmod for every wakeup capable pad to see if there is an
  329. * active wakeup event. If this is the case, call the corresponding ISR.
  330. */
  331. static int _omap_hwmod_mux_handle_irq(struct omap_hwmod *oh, void *data)
  332. {
  333. if (!oh->mux || !oh->mux->enabled)
  334. return 0;
  335. if (omap_hwmod_mux_scan_wakeups(oh->mux, oh->mpu_irqs))
  336. generic_handle_irq(oh->mpu_irqs[0].irq);
  337. return 0;
  338. }
  339. /**
  340. * omap_hwmod_mux_handle_irq - Process pad wakeup irqs.
  341. *
  342. * Calls a function for each registered omap_hwmod to check
  343. * pad wakeup statuses.
  344. */
  345. static irqreturn_t omap_hwmod_mux_handle_irq(int irq, void *unused)
  346. {
  347. omap_hwmod_for_each(_omap_hwmod_mux_handle_irq, NULL);
  348. return IRQ_HANDLED;
  349. }
  350. /* Assumes the calling function takes care of locking */
  351. void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
  352. {
  353. int i;
  354. /* Runtime idling of dynamic pads */
  355. if (state == _HWMOD_STATE_IDLE && hmux->enabled) {
  356. for (i = 0; i < hmux->nr_pads_dynamic; i++) {
  357. struct omap_device_pad *pad = hmux->pads_dynamic[i];
  358. int val = -EINVAL;
  359. val = pad->idle;
  360. omap_mux_write(pad->partition, val,
  361. pad->mux->reg_offset);
  362. }
  363. return;
  364. }
  365. /* Runtime enabling of dynamic pads */
  366. if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic
  367. && hmux->enabled) {
  368. for (i = 0; i < hmux->nr_pads_dynamic; i++) {
  369. struct omap_device_pad *pad = hmux->pads_dynamic[i];
  370. int val = -EINVAL;
  371. val = pad->enable;
  372. omap_mux_write(pad->partition, val,
  373. pad->mux->reg_offset);
  374. }
  375. return;
  376. }
  377. /* Enabling or disabling of all pads */
  378. for (i = 0; i < hmux->nr_pads; i++) {
  379. struct omap_device_pad *pad = &hmux->pads[i];
  380. int flags, val = -EINVAL;
  381. flags = pad->flags;
  382. switch (state) {
  383. case _HWMOD_STATE_ENABLED:
  384. val = pad->enable;
  385. pr_debug("%s: Enabling %s %x\n", __func__,
  386. pad->name, val);
  387. break;
  388. case _HWMOD_STATE_DISABLED:
  389. /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
  390. if (flags & OMAP_DEVICE_PAD_REMUX)