commproc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * General Purpose functions for the global management of the
  3. * Communication Processor Module.
  4. * Copyright (c) 1997 Dan error_act (dmalek@jlc.net)
  5. *
  6. * In addition to the individual control of the communication
  7. * channels, there are a few functions that globally affect the
  8. * communication processor.
  9. *
  10. * Buffer descriptors must be allocated from the dual ported memory
  11. * space. The allocator for that is here. When the communication
  12. * process is reset, we reclaim the memory available. There is
  13. * currently no deallocator for this memory.
  14. * The amount of space available is platform dependent. On the
  15. * MBX, the EPPC software loads additional microcode into the
  16. * communication processor, and uses some of the DP ram for this
  17. * purpose. Current, the first 512 bytes and the last 256 bytes of
  18. * memory are used. Right now I am conservative and only use the
  19. * memory that can never be used for microcode. If there are
  20. * applications that require more DP ram, we can expand the boundaries
  21. * but then we have to be careful of any downloaded microcode.
  22. */
  23. #include <linux/errno.h>
  24. #include <linux/sched.h>
  25. #include <linux/kernel.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/param.h>
  28. #include <linux/string.h>
  29. #include <linux/mm.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/irq.h>
  32. #include <linux/module.h>
  33. #include <asm/mpc8xx.h>
  34. #include <asm/page.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/8xx_immap.h>
  37. #include <asm/commproc.h>
  38. #include <asm/io.h>
  39. #include <asm/tlbflush.h>
  40. #include <asm/rheap.h>
  41. #include <asm/prom.h>
  42. #include <asm/cpm.h>
  43. #include <asm/fs_pd.h>
  44. #define CPM_MAP_SIZE (0x4000)
  45. #ifndef CONFIG_PPC_CPM_NEW_BINDING
  46. static void m8xx_cpm_dpinit(void);
  47. #endif
  48. cpm8xx_t __iomem *cpmp; /* Pointer to comm processor space */
  49. immap_t __iomem *mpc8xx_immr;
  50. static cpic8xx_t __iomem *cpic_reg;
  51. static struct irq_host *cpm_pic_host;
  52. static void cpm_mask_irq(unsigned int irq)
  53. {
  54. unsigned int cpm_vec = (unsigned int)irq_map[irq].hwirq;
  55. clrbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec));
  56. }
  57. static void cpm_unmask_irq(unsigned int irq)
  58. {
  59. unsigned int cpm_vec = (unsigned int)irq_map[irq].hwirq;
  60. setbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec));
  61. }
  62. static void cpm_end_irq(unsigned int irq)
  63. {
  64. unsigned int cpm_vec = (unsigned int)irq_map[irq].hwirq;
  65. out_be32(&cpic_reg->cpic_cisr, (1 << cpm_vec));
  66. }
  67. static struct irq_chip cpm_pic = {
  68. .typename = " CPM PIC ",
  69. .mask = cpm_mask_irq,
  70. .unmask = cpm_unmask_irq,
  71. .eoi = cpm_end_irq,
  72. };
  73. int cpm_get_irq(void)
  74. {
  75. int cpm_vec;
  76. /* Get the vector by setting the ACK bit and then reading
  77. * the register.
  78. */
  79. out_be16(&cpic_reg->cpic_civr, 1);
  80. cpm_vec = in_be16(&cpic_reg->cpic_civr);
  81. cpm_vec >>= 11;
  82. return irq_linear_revmap(cpm_pic_host, cpm_vec);
  83. }
  84. static int cpm_pic_host_map(struct irq_host *h, unsigned int virq,
  85. irq_hw_number_t hw)
  86. {
  87. pr_debug("cpm_pic_host_map(%d, 0x%lx)\n", virq, hw);
  88. get_irq_desc(virq)->status |= IRQ_LEVEL;
  89. set_irq_chip_and_handler(virq, &cpm_pic, handle_fasteoi_irq);
  90. return 0;
  91. }
  92. /* The CPM can generate the error interrupt when there is a race condition
  93. * between generating and masking interrupts. All we have to do is ACK it
  94. * and return. This is a no-op function so we don't need any special
  95. * tests in the interrupt handler.
  96. */
  97. static irqreturn_t cpm_error_interrupt(int irq, void *dev)
  98. {
  99. return IRQ_HANDLED;
  100. }
  101. static struct irqaction cpm_error_irqaction = {
  102. .handler = cpm_error_interrupt,
  103. .mask = CPU_MASK_NONE,
  104. .name = "error",
  105. };
  106. static struct irq_host_ops cpm_pic_host_ops = {
  107. .map = cpm_pic_host_map,
  108. };
  109. unsigned int cpm_pic_init(void)
  110. {
  111. struct device_node *np = NULL;
  112. struct resource res;
  113. unsigned int sirq = NO_IRQ, hwirq, eirq;
  114. int ret;
  115. pr_debug("cpm_pic_init\n");
  116. np = of_find_compatible_node(NULL, NULL, "fsl,cpm1-pic");
  117. if (np == NULL)
  118. np = of_find_compatible_node(NULL, "cpm-pic", "CPM");
  119. if (np == NULL) {
  120. printk(KERN_ERR "CPM PIC init: can not find cpm-pic node\n");
  121. return sirq;
  122. }
  123. ret = of_address_to_resource(np, 0, &res);
  124. if (ret)
  125. goto end;
  126. cpic_reg = ioremap(res.start, res.end - res.start + 1);
  127. if (cpic_reg == NULL)
  128. goto end;
  129. sirq = irq_of_parse_and_map(np, 0);
  130. if (sirq == NO_IRQ)
  131. goto end;
  132. /* Initialize the CPM interrupt controller. */
  133. hwirq = (unsigned int)irq_map[sirq].hwirq;
  134. out_be32(&cpic_reg->cpic_cicr,
  135. (CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1) |
  136. ((hwirq/2) << 13) | CICR_HP_MASK);
  137. out_be32(&cpic_reg->cpic_cimr, 0);
  138. cpm_pic_host = irq_alloc_host(of_node_get(np), IRQ_HOST_MAP_LINEAR,
  139. 64, &cpm_pic_host_ops, 64);
  140. if (cpm_pic_host == NULL) {
  141. printk(KERN_ERR "CPM2 PIC: failed to allocate irq host!\n");
  142. sirq = NO_IRQ;
  143. goto end;
  144. }
  145. /* Install our own error handler. */
  146. np = of_find_compatible_node(NULL, NULL, "fsl,cpm1");
  147. if (np == NULL)
  148. np = of_find_node_by_type(NULL, "cpm");
  149. if (np == NULL) {
  150. printk(KERN_ERR "CPM PIC init: can not find cpm node\n");
  151. goto end;
  152. }
  153. eirq = irq_of_parse_and_map(np, 0);
  154. if (eirq == NO_IRQ)
  155. goto end;
  156. if (setup_irq(eirq, &cpm_error_irqaction))
  157. printk(KERN_ERR "Could not allocate CPM error IRQ!");
  158. setbits32(&cpic_reg->cpic_cicr, CICR_IEN);
  159. end:
  160. of_node_put(np);
  161. return sirq;
  162. }
  163. void __init cpm_reset(void)
  164. {
  165. sysconf8xx_t __iomem *siu_conf;
  166. mpc8xx_immr = ioremap(get_immrbase(), 0x4000);
  167. if (!mpc8xx_immr) {
  168. printk(KERN_CRIT "Could not map IMMR\n");
  169. return;
  170. }
  171. cpmp = &mpc8xx_immr->im_cpm;
  172. #ifndef CONFIG_PPC_EARLY_DEBUG_CPM
  173. /* Perform a reset.
  174. */
  175. out_be16(&cpmp->cp_cpcr, CPM_CR_RST | CPM_CR_FLG);
  176. /* Wait for it.
  177. */
  178. while (in_be16(&cpmp->cp_cpcr) & CPM_CR_FLG);
  179. #endif
  180. #ifdef CONFIG_UCODE_PATCH
  181. cpm_load_patch(cpmp);
  182. #endif
  183. /* Set SDMA Bus Request priority 5.
  184. * On 860T, this also enables FEC priority 6. I am not sure
  185. * this is what we realy want for some applications, but the
  186. * manual recommends it.
  187. * Bit 25, FAM can also be set to use FEC aggressive mode (860T).
  188. */
  189. siu_conf = immr_map(im_siu_conf);
  190. out_be32(&siu_conf->sc_sdcr, 1);
  191. immr_unmap(siu_conf);
  192. #ifdef CONFIG_PPC_CPM_NEW_BINDING
  193. cpm_muram_init();
  194. #else
  195. /* Reclaim the DP memory for our use. */
  196. m8xx_cpm_dpinit();
  197. #endif
  198. }
  199. static DEFINE_SPINLOCK(cmd_lock);
  200. #define MAX_CR_CMD_LOOPS 10000
  201. int cpm_command(u32 command, u8 opcode)
  202. {
  203. int i, ret;
  204. unsigned long flags;
  205. if (command & 0xffffff0f)
  206. return -EINVAL;
  207. spin_lock_irqsave(&cmd_lock, flags);
  208. ret = 0;
  209. out_be16(&cpmp->cp_cpcr, command | CPM_CR_FLG | (opcode << 8));
  210. for (i = 0; i < MAX_CR_CMD_LOOPS; i++)
  211. if ((in_be16(&cpmp->cp_cpcr) & CPM_CR_FLG) == 0)
  212. goto out;
  213. printk(KERN_ERR "%s(): Not able to issue CPM command\n", __FUNCTION__);
  214. ret = -EIO;
  215. out:
  216. spin_unlock_irqrestore(&cmd_lock, flags);
  217. return ret;
  218. }
  219. EXPORT_SYMBOL(cpm_command);
  220. /* Set a baud rate generator. This needs lots of work. There are
  221. * four BRGs, any of which can be wired to any channel.
  222. * The internal baud rate clock is the system clock divided by 16.
  223. * This assumes the baudrate is 16x oversampled by the uart.
  224. */
  225. #define BRG_INT_CLK (get_brgfreq())
  226. #define BRG_UART_CLK (BRG_INT_CLK/16)
  227. #define BRG_UART_CLK_DIV16 (BRG_UART_CLK/16)
  228. void
  229. cpm_setbrg(uint brg, uint rate)
  230. {
  231. u32 __iomem *bp;
  232. /* This is good enough to get SMCs running.....
  233. */
  234. bp = &cpmp->cp_brgc1;
  235. bp += brg;
  236. /* The BRG has a 12-bit counter. For really slow baud rates (or
  237. * really fast processors), we may have to further divide by 16.
  238. */
  239. if (((BRG_UART_CLK / rate) - 1) < 4096)
  240. out_be32(bp, (((BRG_UART_CLK / rate) - 1) << 1) | CPM_BRG_EN);
  241. else
  242. out_be32(bp, (((BRG_UART_CLK_DIV16 / rate) - 1) << 1) |
  243. CPM_BRG_EN | CPM_BRG_DIV16);
  244. }
  245. #ifndef CONFIG_PPC_CPM_NEW_BINDING
  246. /*
  247. * dpalloc / dpfree bits.
  248. */
  249. static spinlock_t cpm_dpmem_lock;
  250. /*
  251. * 16 blocks should be enough to satisfy all requests
  252. * until the memory subsystem goes up...
  253. */
  254. static rh_block_t cpm_boot_dpmem_rh_block[16];
  255. static rh_info_t cpm_dpmem_info;
  256. #define CPM_DPMEM_ALIGNMENT 8
  257. static u8 __iomem *dpram_vbase;
  258. static phys_addr_t dpram_pbase;
  259. static void m8xx_cpm_dpinit(void)
  260. {
  261. spin_lock_init(&cpm_dpmem_lock);
  262. dpram_vbase = cpmp->cp_dpmem;
  263. dpram_pbase = get_immrbase() + offsetof(immap_t, im_cpm.cp_dpmem);
  264. /* Initialize the info header */
  265. rh_init(&cpm_dpmem_info, CPM_DPMEM_ALIGNMENT,
  266. sizeof(cpm_boot_dpmem_rh_block) /
  267. sizeof(cpm_boot_dpmem_rh_block[0]),
  268. cpm_boot_dpmem_rh_block);
  269. /*
  270. * Attach the usable dpmem area.
  271. * XXX: This is actually crap. CPM_DATAONLY_BASE and
  272. * CPM_DATAONLY_SIZE are a subset of the available dparm. It varies
  273. * with the processor and the microcode patches applied / activated.
  274. * But the following should be at least safe.
  275. */
  276. rh_attach_region(&cpm_dpmem_info, CPM_DATAONLY_BASE, CPM_DATAONLY_SIZE);
  277. }
  278. /*
  279. * Allocate the requested size worth of DP memory.
  280. * This function returns an offset into the DPRAM area.
  281. * Use cpm_dpram_addr() to get the virtual address of the area.
  282. */
  283. unsigned long cpm_dpalloc(uint size, uint align)
  284. {
  285. unsigned long start;
  286. unsigned long flags;
  287. spin_lock_irqsave(&cpm_dpmem_lock, flags);
  288. cpm_dpmem_info.alignment = align;
  289. start = rh_alloc(&cpm_dpmem_info, size, "commproc");
  290. spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
  291. return (uint)start;
  292. }
  293. EXPORT_SYMBOL(cpm_dpalloc);
  294. int cpm_dpfree(unsigned long offset)
  295. {
  296. int ret;
  297. unsigned long flags;
  298. spin_lock_irqsave(&cpm_dpmem_lock, flags);
  299. ret = rh_free(&cpm_dpmem_info, offset);
  300. spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
  301. return ret;
  302. }
  303. EXPORT_SYMBOL(cpm_dpfree);
  304. unsigned long cpm_dpalloc_fixed(unsigned long offset, uint size, uint align)
  305. {
  306. unsigned long start;
  307. unsigned long flags;
  308. spin_lock_irqsave(&cpm_dpmem_lock, flags);
  309. cpm_dpmem_info.alignment = align;
  310. start = rh_alloc_fixed(&cpm_dpmem_info, offset, size, "commproc");
  311. spin_unlock_irqrestore(&cpm_dpmem_lock, flags);
  312. return start;
  313. }
  314. EXPORT_SYMBOL(cpm_dpalloc_fixed);
  315. void cpm_dpdump(void)
  316. {
  317. rh_dump(&cpm_dpmem_info);
  318. }
  319. EXPORT_SYMBOL(cpm_dpdump);
  320. void *cpm_dpram_addr(unsigned long offset)
  321. {
  322. return (void *)(dpram_vbase + offset);
  323. }
  324. EXPORT_SYMBOL(cpm_dpram_addr);
  325. uint cpm_dpram_phys(u8 *addr)
  326. {
  327. return (dpram_pbase + (uint)(addr - dpram_vbase));
  328. }
  329. EXPORT_SYMBOL(cpm_dpram_phys);
  330. #endif /* !CONFIG_PPC_CPM_NEW_BINDING */
  331. struct cpm_ioport16 {
  332. __be16 dir, par, odr_sor, dat, intr;
  333. __be16 res[3];
  334. };
  335. struct cpm_ioport32 {
  336. __be32 dir, par, sor;
  337. };
  338. static void cpm1_set_pin32(int port, int pin, int flags)
  339. {
  340. struct cpm_ioport32 __iomem *iop;
  341. pin = 1 << (31 - pin);
  342. if (port == CPM_PORTB)
  343. iop = (struct cpm_ioport32 __iomem *)
  344. &mpc8xx_immr->im_cpm.cp_pbdir;
  345. else
  346. iop = (struct cpm_ioport32 __iomem *)
  347. &mpc8xx_immr->im_cpm.cp_pedir;
  348. if (flags & CPM_PIN_OUTPUT)
  349. setbits32(&iop->dir, pin);
  350. else
  351. clrbits32(&iop->dir, pin);
  352. if (!(flags & CPM_PIN_GPIO))
  353. setbits32(&iop->par, pin);
  354. else
  355. clrbits32(&iop->par, pin);
  356. if (port == CPM_PORTB) {
  357. if (flags & CPM_PIN_OPENDRAIN)
  358. setbits16(&mpc8xx_immr->im_cpm.cp_pbodr, pin);
  359. else
  360. clrbits16(&mpc8xx_immr->im_cpm.cp_pbodr, pin);
  361. }
  362. if (port == CPM_PORTE) {
  363. if (flags & CPM_PIN_SECONDARY)
  364. setbits32(&iop->sor, pin);
  365. else
  366. clrbits32(&iop->sor, pin);
  367. if (flags & CPM_PIN_OPENDRAIN)
  368. setbits32(&mpc8xx_immr->im_cpm.cp_peodr, pin);
  369. else
  370. clrbits32(&mpc8xx_immr->im_cpm.cp_peodr, pin);
  371. }
  372. }
  373. static void cpm1_set_pin16(int port, int pin, int flags)
  374. {
  375. struct cpm_ioport16 __iomem *iop =
  376. (struct cpm_ioport16 __iomem *)&mpc8xx_immr->im_ioport;
  377. pin = 1 << (15 - pin);
  378. if (port != 0)
  379. iop += port - 1;
  380. if (flags & CPM_PIN_OUTPUT)
  381. setbits16(&iop->dir, pin);
  382. else
  383. clrbits16(&iop->dir, pin);
  384. if (!(flags & CPM_PIN_GPIO))
  385. setbits16(&iop->par, pin);
  386. else
  387. clrbits16(&iop->par, pin);
  388. if (port == CPM_PORTA) {
  389. if (flags & CPM_PIN_OPENDRAIN)
  390. setbits16(&iop->odr_sor, pin);
  391. else
  392. clrbits16(&iop->odr_sor, pin);
  393. }
  394. if (port == CPM_PORTC) {
  395. if (flags & CPM_PIN_SECONDARY)
  396. setbits16(&iop->odr_sor, pin);
  397. else
  398. clrbits16(&iop->odr_sor, pin);
  399. }
  400. }
  401. void cpm1_set_pin(enum cpm_port port, int pin, int flags)
  402. {
  403. if (port == CPM_PORTB || port == CPM_PORTE)
  404. cpm1_set_pin32(port, pin, flags);
  405. else
  406. cpm1_set_pin16(port, pin, flags);
  407. }
  408. int cpm1_clk_setup(enum cpm_clk_target target, int clock, int mode)
  409. {
  410. int shift;
  411. int i, bits = 0;
  412. u32 __iomem *reg;
  413. u32 mask = 7;
  414. u8 clk_map[][3] = {
  415. {CPM_CLK_SCC1, CPM_BRG1, 0},
  416. {CPM_CLK_SCC1, CPM_BRG2, 1},
  417. {CPM_CLK_SCC1, CPM_BRG3, 2},
  418. {CPM_CLK_SCC1, CPM_BRG4, 3},
  419. {CPM_CLK_SCC1, CPM_CLK1, 4},
  420. {CPM_CLK_SCC1, CPM_CLK2, 5},
  421. {CPM_CLK_SCC1, CPM_CLK3, 6},
  422. {CPM_CLK_SCC1, CPM_CLK4, 7},
  423. {CPM_CLK_SCC2, CPM_BRG1, 0},
  424. {CPM_CLK_SCC2, CPM_BRG2, 1},
  425. {CPM_CLK_SCC2, CPM_BRG3, 2},
  426. {CPM_CLK_SCC2, CPM_BRG4, 3},
  427. {CPM_CLK_SCC2, CPM_CLK1, 4},
  428. {CPM_CLK_SCC2, CPM_CLK2, 5},
  429. {CPM_CLK_SCC2, CPM_CLK3, 6},
  430. {CPM_CLK_SCC2, CPM_CLK4, 7},
  431. {CPM_CLK_SCC3, CPM_BRG1, 0},
  432. {CPM_CLK_SCC3, CPM_BRG2, 1},
  433. {CPM_CLK_SCC3, CPM_BRG3, 2},
  434. {CPM_CLK_SCC3, CPM_BRG4, 3},
  435. {CPM_CLK_SCC3, CPM_CLK5, 4},
  436. {CPM_CLK_SCC3, CPM_CLK6, 5},
  437. {CPM_CLK_SCC3, CPM_CLK7, 6},
  438. {CPM_CLK_SCC3, CPM_CLK8, 7},
  439. {CPM_CLK_SCC4, CPM_BRG1, 0},
  440. {CPM_CLK_SCC4, CPM_BRG2, 1},
  441. {CPM_CLK_SCC4, CPM_BRG3, 2},
  442. {CPM_CLK_SCC4, CPM_BRG4, 3},
  443. {CPM_CLK_SCC4, CPM_CLK5, 4},
  444. {CPM_CLK_SCC4, CPM_CLK6, 5},
  445. {CPM_CLK_SCC4, CPM_CLK7, 6},
  446. {CPM_CLK_SCC4, CPM_CLK8, 7},
  447. {CPM_CLK_SMC1, CPM_BRG1, 0},
  448. {CPM_CLK_SMC1, CPM_BRG2, 1},
  449. {CPM_CLK_SMC1, CPM_BRG3, 2},
  450. {CPM_CLK_SMC1, CPM_BRG4, 3},
  451. {CPM_CLK_SMC1, CPM_CLK1, 4},
  452. {CPM_CLK_SMC1, CPM_CLK2, 5},
  453. {CPM_CLK_SMC1, CPM_CLK3, 6},
  454. {CPM_CLK_SMC1, CPM_CLK4, 7},
  455. {CPM_CLK_SMC2, CPM_BRG1, 0},
  456. {CPM_CLK_SMC2, CPM_BRG2, 1},
  457. {CPM_CLK_SMC2, CPM_BRG3, 2},
  458. {CPM_CLK_SMC2, CPM_BRG4, 3},
  459. {CPM_CLK_SMC2, CPM_CLK5, 4},
  460. {CPM_CLK_SMC2, CPM_CLK6, 5},
  461. {CPM_CLK_SMC2, CPM_CLK7, 6},
  462. {CPM_CLK_SMC2, CPM_CLK8, 7},
  463. };
  464. switch (target) {
  465. case CPM_CLK_SCC1:
  466. reg = &mpc8xx_immr->im_cpm.cp_sicr;
  467. shift = 0;
  468. break;
  469. case CPM_CLK_SCC2:
  470. reg = &mpc8xx_immr->im_cpm.cp_sicr;
  471. shift = 8;
  472. break;
  473. case CPM_CLK_SCC3:
  474. reg = &mpc8xx_immr->im_cpm.cp_sicr;
  475. shift = 16;
  476. break;
  477. case CPM_CLK_SCC4:
  478. reg = &mpc8xx_immr->im_cpm.cp_sicr;
  479. shift = 24;
  480. break;
  481. case CPM_CLK_SMC1:
  482. reg = &mpc8xx_immr->im_cpm.cp_simode;
  483. shift = 12;
  484. break;
  485. case CPM_CLK_SMC2:
  486. reg = &mpc8xx_immr->im_cpm.cp_simode;
  487. shift = 28;
  488. break;
  489. default:
  490. printk(KERN_ERR "cpm1_clock_setup: invalid clock target\n");
  491. return -EINVAL;
  492. }
  493. if (reg == &mpc8xx_immr->im_cpm.cp_sicr && mode == CPM_CLK_RX)
  494. shift += 3;
  495. for (i = 0; i < ARRAY_SIZE(clk_map); i++) {
  496. if (clk_map[i][0] == target && clk_map[i][1] == clock) {
  497. bits = clk_map[i][2];
  498. break;
  499. }
  500. }
  501. if (i == ARRAY_SIZE(clk_map)) {
  502. printk(KERN_ERR "cpm1_clock_setup: invalid clock combination\n");
  503. return -EINVAL;
  504. }
  505. bits <<= shift;
  506. mask <<= shift;
  507. out_be32(reg, (in_be32(reg) & ~mask) | bits);
  508. return 0;
  509. }