Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 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> |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 42 | #include <asm/cpm.h> |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 43 | |
| 44 | #include <asm/fs_pd.h> |
| 45 | |
| 46 | #define CPM_MAP_SIZE (0x4000) |
| 47 | |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 48 | #ifndef CONFIG_PPC_CPM_NEW_BINDING |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 49 | static void m8xx_cpm_dpinit(void); |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 50 | #endif |
Scott Wood | 4b218e9 | 2007-08-21 02:36:19 +1000 | [diff] [blame] | 51 | static uint host_buffer; /* One page of host buffer */ |
| 52 | static uint host_end; /* end + 1 */ |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 53 | cpm8xx_t __iomem *cpmp; /* Pointer to comm processor space */ |
| 54 | immap_t __iomem *mpc8xx_immr; |
| 55 | static cpic8xx_t __iomem *cpic_reg; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 56 | |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 57 | static struct irq_host *cpm_pic_host; |
| 58 | |
| 59 | static void cpm_mask_irq(unsigned int irq) |
| 60 | { |
| 61 | unsigned int cpm_vec = (unsigned int)irq_map[irq].hwirq; |
| 62 | |
| 63 | clrbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec)); |
| 64 | } |
| 65 | |
| 66 | static void cpm_unmask_irq(unsigned int irq) |
| 67 | { |
| 68 | unsigned int cpm_vec = (unsigned int)irq_map[irq].hwirq; |
| 69 | |
| 70 | setbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec)); |
| 71 | } |
| 72 | |
| 73 | static void cpm_end_irq(unsigned int irq) |
| 74 | { |
| 75 | unsigned int cpm_vec = (unsigned int)irq_map[irq].hwirq; |
| 76 | |
| 77 | out_be32(&cpic_reg->cpic_cisr, (1 << cpm_vec)); |
| 78 | } |
| 79 | |
| 80 | static struct irq_chip cpm_pic = { |
| 81 | .typename = " CPM PIC ", |
| 82 | .mask = cpm_mask_irq, |
| 83 | .unmask = cpm_unmask_irq, |
| 84 | .eoi = cpm_end_irq, |
| 85 | }; |
| 86 | |
| 87 | int cpm_get_irq(void) |
| 88 | { |
| 89 | int cpm_vec; |
| 90 | |
| 91 | /* Get the vector by setting the ACK bit and then reading |
| 92 | * the register. |
| 93 | */ |
| 94 | out_be16(&cpic_reg->cpic_civr, 1); |
| 95 | cpm_vec = in_be16(&cpic_reg->cpic_civr); |
| 96 | cpm_vec >>= 11; |
| 97 | |
| 98 | return irq_linear_revmap(cpm_pic_host, cpm_vec); |
| 99 | } |
| 100 | |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 101 | static int cpm_pic_host_map(struct irq_host *h, unsigned int virq, |
| 102 | irq_hw_number_t hw) |
| 103 | { |
| 104 | pr_debug("cpm_pic_host_map(%d, 0x%lx)\n", virq, hw); |
| 105 | |
| 106 | get_irq_desc(virq)->status |= IRQ_LEVEL; |
| 107 | set_irq_chip_and_handler(virq, &cpm_pic, handle_fasteoi_irq); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | /* The CPM can generate the error interrupt when there is a race condition |
| 112 | * between generating and masking interrupts. All we have to do is ACK it |
| 113 | * and return. This is a no-op function so we don't need any special |
| 114 | * tests in the interrupt handler. |
| 115 | */ |
Scott Wood | 4b218e9 | 2007-08-21 02:36:19 +1000 | [diff] [blame] | 116 | static irqreturn_t cpm_error_interrupt(int irq, void *dev) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 117 | { |
| 118 | return IRQ_HANDLED; |
| 119 | } |
| 120 | |
| 121 | static struct irqaction cpm_error_irqaction = { |
| 122 | .handler = cpm_error_interrupt, |
| 123 | .mask = CPU_MASK_NONE, |
| 124 | .name = "error", |
| 125 | }; |
| 126 | |
| 127 | static struct irq_host_ops cpm_pic_host_ops = { |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 128 | .map = cpm_pic_host_map, |
| 129 | }; |
| 130 | |
| 131 | unsigned int cpm_pic_init(void) |
| 132 | { |
| 133 | struct device_node *np = NULL; |
| 134 | struct resource res; |
| 135 | unsigned int sirq = NO_IRQ, hwirq, eirq; |
| 136 | int ret; |
| 137 | |
| 138 | pr_debug("cpm_pic_init\n"); |
| 139 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 140 | np = of_find_compatible_node(NULL, NULL, "fsl,cpm1-pic"); |
| 141 | if (np == NULL) |
| 142 | np = of_find_compatible_node(NULL, "cpm-pic", "CPM"); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 143 | if (np == NULL) { |
| 144 | printk(KERN_ERR "CPM PIC init: can not find cpm-pic node\n"); |
| 145 | return sirq; |
| 146 | } |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 147 | |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 148 | ret = of_address_to_resource(np, 0, &res); |
| 149 | if (ret) |
| 150 | goto end; |
| 151 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 152 | cpic_reg = ioremap(res.start, res.end - res.start + 1); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 153 | if (cpic_reg == NULL) |
| 154 | goto end; |
| 155 | |
| 156 | sirq = irq_of_parse_and_map(np, 0); |
| 157 | if (sirq == NO_IRQ) |
| 158 | goto end; |
| 159 | |
| 160 | /* Initialize the CPM interrupt controller. */ |
| 161 | hwirq = (unsigned int)irq_map[sirq].hwirq; |
| 162 | out_be32(&cpic_reg->cpic_cicr, |
| 163 | (CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1) | |
| 164 | ((hwirq/2) << 13) | CICR_HP_MASK); |
| 165 | |
| 166 | out_be32(&cpic_reg->cpic_cimr, 0); |
| 167 | |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 168 | cpm_pic_host = irq_alloc_host(of_node_get(np), IRQ_HOST_MAP_LINEAR, |
| 169 | 64, &cpm_pic_host_ops, 64); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 170 | if (cpm_pic_host == NULL) { |
| 171 | printk(KERN_ERR "CPM2 PIC: failed to allocate irq host!\n"); |
| 172 | sirq = NO_IRQ; |
| 173 | goto end; |
| 174 | } |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 175 | |
| 176 | /* Install our own error handler. */ |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 177 | np = of_find_compatible_node(NULL, NULL, "fsl,cpm1"); |
| 178 | if (np == NULL) |
| 179 | np = of_find_node_by_type(NULL, "cpm"); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 180 | if (np == NULL) { |
| 181 | printk(KERN_ERR "CPM PIC init: can not find cpm node\n"); |
| 182 | goto end; |
| 183 | } |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 184 | |
Scott Wood | 4b218e9 | 2007-08-21 02:36:19 +1000 | [diff] [blame] | 185 | eirq = irq_of_parse_and_map(np, 0); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 186 | if (eirq == NO_IRQ) |
| 187 | goto end; |
| 188 | |
| 189 | if (setup_irq(eirq, &cpm_error_irqaction)) |
| 190 | printk(KERN_ERR "Could not allocate CPM error IRQ!"); |
| 191 | |
| 192 | setbits32(&cpic_reg->cpic_cicr, CICR_IEN); |
| 193 | |
| 194 | end: |
| 195 | of_node_put(np); |
| 196 | return sirq; |
| 197 | } |
| 198 | |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 199 | void __init cpm_reset(void) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 200 | { |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 201 | sysconf8xx_t __iomem *siu_conf; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 202 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 203 | mpc8xx_immr = ioremap(get_immrbase(), 0x4000); |
| 204 | if (!mpc8xx_immr) { |
| 205 | printk(KERN_CRIT "Could not map IMMR\n"); |
| 206 | return; |
| 207 | } |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 208 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 209 | cpmp = &mpc8xx_immr->im_cpm; |
| 210 | |
| 211 | #ifndef CONFIG_PPC_EARLY_DEBUG_CPM |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 212 | /* Perform a reset. |
| 213 | */ |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 214 | out_be16(&cpmp->cp_cpcr, CPM_CR_RST | CPM_CR_FLG); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 215 | |
| 216 | /* Wait for it. |
| 217 | */ |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 218 | while (in_be16(&cpmp->cp_cpcr) & CPM_CR_FLG); |
| 219 | #endif |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 220 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 221 | #ifdef CONFIG_UCODE_PATCH |
| 222 | cpm_load_patch(cpmp); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 223 | #endif |
| 224 | |
| 225 | /* Set SDMA Bus Request priority 5. |
| 226 | * On 860T, this also enables FEC priority 6. I am not sure |
| 227 | * this is what we realy want for some applications, but the |
| 228 | * manual recommends it. |
| 229 | * Bit 25, FAM can also be set to use FEC aggressive mode (860T). |
| 230 | */ |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 231 | siu_conf = immr_map(im_siu_conf); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 232 | out_be32(&siu_conf->sc_sdcr, 1); |
| 233 | immr_unmap(siu_conf); |
| 234 | |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 235 | #ifdef CONFIG_PPC_CPM_NEW_BINDING |
| 236 | cpm_muram_init(); |
| 237 | #else |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 238 | /* Reclaim the DP memory for our use. */ |
| 239 | m8xx_cpm_dpinit(); |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 240 | #endif |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* We used to do this earlier, but have to postpone as long as possible |
| 244 | * to ensure the kernel VM is now running. |
| 245 | */ |
| 246 | static void |
| 247 | alloc_host_memory(void) |
| 248 | { |
| 249 | dma_addr_t physaddr; |
| 250 | |
| 251 | /* Set the host page for allocation. |
| 252 | */ |
| 253 | host_buffer = (uint)dma_alloc_coherent(NULL, PAGE_SIZE, &physaddr, |
| 254 | GFP_KERNEL); |
| 255 | host_end = host_buffer + PAGE_SIZE; |
| 256 | } |
| 257 | |
| 258 | /* We also own one page of host buffer space for the allocation of |
| 259 | * UART "fifos" and the like. |
| 260 | */ |
| 261 | uint |
| 262 | m8xx_cpm_hostalloc(uint size) |
| 263 | { |
| 264 | uint retloc; |
| 265 | |
| 266 | if (host_buffer == 0) |
| 267 | alloc_host_memory(); |
| 268 | |
| 269 | if ((host_buffer + size) >= host_end) |
| 270 | return(0); |
| 271 | |
| 272 | retloc = host_buffer; |
| 273 | host_buffer += size; |
| 274 | |
| 275 | return(retloc); |
| 276 | } |
| 277 | |
| 278 | /* Set a baud rate generator. This needs lots of work. There are |
| 279 | * four BRGs, any of which can be wired to any channel. |
| 280 | * The internal baud rate clock is the system clock divided by 16. |
| 281 | * This assumes the baudrate is 16x oversampled by the uart. |
| 282 | */ |
| 283 | #define BRG_INT_CLK (get_brgfreq()) |
| 284 | #define BRG_UART_CLK (BRG_INT_CLK/16) |
| 285 | #define BRG_UART_CLK_DIV16 (BRG_UART_CLK/16) |
| 286 | |
| 287 | void |
| 288 | cpm_setbrg(uint brg, uint rate) |
| 289 | { |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 290 | u32 __iomem *bp; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 291 | |
| 292 | /* This is good enough to get SMCs running..... |
| 293 | */ |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 294 | bp = &cpmp->cp_brgc1; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 295 | bp += brg; |
| 296 | /* The BRG has a 12-bit counter. For really slow baud rates (or |
| 297 | * really fast processors), we may have to further divide by 16. |
| 298 | */ |
| 299 | if (((BRG_UART_CLK / rate) - 1) < 4096) |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 300 | out_be32(bp, (((BRG_UART_CLK / rate) - 1) << 1) | CPM_BRG_EN); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 301 | else |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 302 | out_be32(bp, (((BRG_UART_CLK_DIV16 / rate) - 1) << 1) | |
| 303 | CPM_BRG_EN | CPM_BRG_DIV16); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 304 | } |
| 305 | |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 306 | #ifndef CONFIG_PPC_CPM_NEW_BINDING |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 307 | /* |
| 308 | * dpalloc / dpfree bits. |
| 309 | */ |
| 310 | static spinlock_t cpm_dpmem_lock; |
| 311 | /* |
| 312 | * 16 blocks should be enough to satisfy all requests |
| 313 | * until the memory subsystem goes up... |
| 314 | */ |
| 315 | static rh_block_t cpm_boot_dpmem_rh_block[16]; |
| 316 | static rh_info_t cpm_dpmem_info; |
| 317 | |
| 318 | #define CPM_DPMEM_ALIGNMENT 8 |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 319 | static u8 __iomem *dpram_vbase; |
| 320 | static phys_addr_t dpram_pbase; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 321 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 322 | static void m8xx_cpm_dpinit(void) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 323 | { |
| 324 | spin_lock_init(&cpm_dpmem_lock); |
| 325 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 326 | dpram_vbase = cpmp->cp_dpmem; |
| 327 | dpram_pbase = get_immrbase() + offsetof(immap_t, im_cpm.cp_dpmem); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 328 | |
| 329 | /* Initialize the info header */ |
| 330 | rh_init(&cpm_dpmem_info, CPM_DPMEM_ALIGNMENT, |
| 331 | sizeof(cpm_boot_dpmem_rh_block) / |
| 332 | sizeof(cpm_boot_dpmem_rh_block[0]), |
| 333 | cpm_boot_dpmem_rh_block); |
| 334 | |
| 335 | /* |
| 336 | * Attach the usable dpmem area. |
| 337 | * XXX: This is actually crap. CPM_DATAONLY_BASE and |
| 338 | * CPM_DATAONLY_SIZE are a subset of the available dparm. It varies |
| 339 | * with the processor and the microcode patches applied / activated. |
| 340 | * But the following should be at least safe. |
| 341 | */ |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 342 | rh_attach_region(&cpm_dpmem_info, CPM_DATAONLY_BASE, CPM_DATAONLY_SIZE); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* |
| 346 | * Allocate the requested size worth of DP memory. |
| 347 | * This function returns an offset into the DPRAM area. |
| 348 | * Use cpm_dpram_addr() to get the virtual address of the area. |
| 349 | */ |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 350 | unsigned long cpm_dpalloc(uint size, uint align) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 351 | { |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 352 | unsigned long start; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 353 | unsigned long flags; |
| 354 | |
| 355 | spin_lock_irqsave(&cpm_dpmem_lock, flags); |
| 356 | cpm_dpmem_info.alignment = align; |
| 357 | start = rh_alloc(&cpm_dpmem_info, size, "commproc"); |
| 358 | spin_unlock_irqrestore(&cpm_dpmem_lock, flags); |
| 359 | |
| 360 | return (uint)start; |
| 361 | } |
| 362 | EXPORT_SYMBOL(cpm_dpalloc); |
| 363 | |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 364 | int cpm_dpfree(unsigned long offset) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 365 | { |
| 366 | int ret; |
| 367 | unsigned long flags; |
| 368 | |
| 369 | spin_lock_irqsave(&cpm_dpmem_lock, flags); |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 370 | ret = rh_free(&cpm_dpmem_info, offset); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 371 | spin_unlock_irqrestore(&cpm_dpmem_lock, flags); |
| 372 | |
| 373 | return ret; |
| 374 | } |
| 375 | EXPORT_SYMBOL(cpm_dpfree); |
| 376 | |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 377 | unsigned long cpm_dpalloc_fixed(unsigned long offset, uint size, uint align) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 378 | { |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 379 | unsigned long start; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 380 | unsigned long flags; |
| 381 | |
| 382 | spin_lock_irqsave(&cpm_dpmem_lock, flags); |
| 383 | cpm_dpmem_info.alignment = align; |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 384 | start = rh_alloc_fixed(&cpm_dpmem_info, offset, size, "commproc"); |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 385 | spin_unlock_irqrestore(&cpm_dpmem_lock, flags); |
| 386 | |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 387 | return start; |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 388 | } |
| 389 | EXPORT_SYMBOL(cpm_dpalloc_fixed); |
| 390 | |
| 391 | void cpm_dpdump(void) |
| 392 | { |
| 393 | rh_dump(&cpm_dpmem_info); |
| 394 | } |
| 395 | EXPORT_SYMBOL(cpm_dpdump); |
| 396 | |
Timur Tabi | 4c35630 | 2007-05-08 14:46:36 -0500 | [diff] [blame] | 397 | void *cpm_dpram_addr(unsigned long offset) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 398 | { |
| 399 | return (void *)(dpram_vbase + offset); |
| 400 | } |
| 401 | EXPORT_SYMBOL(cpm_dpram_addr); |
| 402 | |
Scott Wood | fb533d0 | 2007-09-14 14:22:36 -0500 | [diff] [blame] | 403 | uint cpm_dpram_phys(u8 *addr) |
Vitaly Bordug | f2a0bd3 | 2007-01-24 22:41:24 +0300 | [diff] [blame] | 404 | { |
| 405 | return (dpram_pbase + (uint)(addr - dpram_vbase)); |
| 406 | } |
Jochen Friedrich | 83af919 | 2007-09-24 19:13:46 +0200 | [diff] [blame] | 407 | EXPORT_SYMBOL(cpm_dpram_phys); |
Scott Wood | 15f8c60 | 2007-09-28 14:06:16 -0500 | [diff] [blame] | 408 | #endif /* !CONFIG_PPC_CPM_NEW_BINDING */ |
Scott Wood | 663edbd | 2007-07-16 17:22:01 -0500 | [diff] [blame] | 409 | |
| 410 | struct cpm_ioport16 { |
Jochen Friedrich | 721c0c8 | 2007-11-22 17:54:13 +0100 | [diff] [blame^] | 411 | __be16 dir, par, odr_sor, dat, intr; |
Scott Wood | 663edbd | 2007-07-16 17:22:01 -0500 | [diff] [blame] | 412 | __be16 res[3]; |
| 413 | }; |
| 414 | |
| 415 | struct cpm_ioport32 { |
| 416 | __be32 dir, par, sor; |
| 417 | }; |
| 418 | |
| 419 | static void cpm1_set_pin32(int port, int pin, int flags) |
| 420 | { |
| 421 | struct cpm_ioport32 __iomem *iop; |
| 422 | pin = 1 << (31 - pin); |
| 423 | |
| 424 | if (port == CPM_PORTB) |
| 425 | iop = (struct cpm_ioport32 __iomem *) |
| 426 | &mpc8xx_immr->im_cpm.cp_pbdir; |
| 427 | else |
| 428 | iop = (struct cpm_ioport32 __iomem *) |
| 429 | &mpc8xx_immr->im_cpm.cp_pedir; |
| 430 | |
| 431 | if (flags & CPM_PIN_OUTPUT) |
| 432 | setbits32(&iop->dir, pin); |
| 433 | else |
| 434 | clrbits32(&iop->dir, pin); |
| 435 | |
| 436 | if (!(flags & CPM_PIN_GPIO)) |
| 437 | setbits32(&iop->par, pin); |
| 438 | else |
| 439 | clrbits32(&iop->par, pin); |
| 440 | |
Jochen Friedrich | 721c0c8 | 2007-11-22 17:54:13 +0100 | [diff] [blame^] | 441 | if (port == CPM_PORTB) { |
| 442 | if (flags & CPM_PIN_OPENDRAIN) |
| 443 | setbits16(&mpc8xx_immr->im_cpm.cp_pbodr, pin); |
| 444 | else |
| 445 | clrbits16(&mpc8xx_immr->im_cpm.cp_pbodr, pin); |
| 446 | } |
| 447 | |
Scott Wood | 663edbd | 2007-07-16 17:22:01 -0500 | [diff] [blame] | 448 | if (port == CPM_PORTE) { |
| 449 | if (flags & CPM_PIN_SECONDARY) |
| 450 | setbits32(&iop->sor, pin); |
| 451 | else |
| 452 | clrbits32(&iop->sor, pin); |
| 453 | |
| 454 | if (flags & CPM_PIN_OPENDRAIN) |
| 455 | setbits32(&mpc8xx_immr->im_cpm.cp_peodr, pin); |
| 456 | else |
| 457 | clrbits32(&mpc8xx_immr->im_cpm.cp_peodr, pin); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | static void cpm1_set_pin16(int port, int pin, int flags) |
| 462 | { |
| 463 | struct cpm_ioport16 __iomem *iop = |
| 464 | (struct cpm_ioport16 __iomem *)&mpc8xx_immr->im_ioport; |
| 465 | |
| 466 | pin = 1 << (15 - pin); |
| 467 | |
| 468 | if (port != 0) |
| 469 | iop += port - 1; |
| 470 | |
| 471 | if (flags & CPM_PIN_OUTPUT) |
| 472 | setbits16(&iop->dir, pin); |
| 473 | else |
| 474 | clrbits16(&iop->dir, pin); |
| 475 | |
| 476 | if (!(flags & CPM_PIN_GPIO)) |
| 477 | setbits16(&iop->par, pin); |
| 478 | else |
| 479 | clrbits16(&iop->par, pin); |
| 480 | |
Jochen Friedrich | 721c0c8 | 2007-11-22 17:54:13 +0100 | [diff] [blame^] | 481 | if (port == CPM_PORTA) { |
| 482 | if (flags & CPM_PIN_OPENDRAIN) |
| 483 | setbits16(&iop->odr_sor, pin); |
| 484 | else |
| 485 | clrbits16(&iop->odr_sor, pin); |
| 486 | } |
Scott Wood | 663edbd | 2007-07-16 17:22:01 -0500 | [diff] [blame] | 487 | if (port == CPM_PORTC) { |
| 488 | if (flags & CPM_PIN_SECONDARY) |
Jochen Friedrich | 721c0c8 | 2007-11-22 17:54:13 +0100 | [diff] [blame^] | 489 | setbits16(&iop->odr_sor, pin); |
Scott Wood | 663edbd | 2007-07-16 17:22:01 -0500 | [diff] [blame] | 490 | else |
Jochen Friedrich | 721c0c8 | 2007-11-22 17:54:13 +0100 | [diff] [blame^] | 491 | clrbits16(&iop->odr_sor, pin); |
Scott Wood | 663edbd | 2007-07-16 17:22:01 -0500 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
| 495 | void cpm1_set_pin(enum cpm_port port, int pin, int flags) |
| 496 | { |
| 497 | if (port == CPM_PORTB || port == CPM_PORTE) |
| 498 | cpm1_set_pin32(port, pin, flags); |
| 499 | else |
| 500 | cpm1_set_pin16(port, pin, flags); |
| 501 | } |
| 502 | |
| 503 | int cpm1_clk_setup(enum cpm_clk_target target, int clock, int mode) |
| 504 | { |
| 505 | int shift; |
| 506 | int i, bits = 0; |
| 507 | u32 __iomem *reg; |
| 508 | u32 mask = 7; |
| 509 | |
| 510 | u8 clk_map[][3] = { |
| 511 | {CPM_CLK_SCC1, CPM_BRG1, 0}, |
| 512 | {CPM_CLK_SCC1, CPM_BRG2, 1}, |
| 513 | {CPM_CLK_SCC1, CPM_BRG3, 2}, |
| 514 | {CPM_CLK_SCC1, CPM_BRG4, 3}, |
| 515 | {CPM_CLK_SCC1, CPM_CLK1, 4}, |
| 516 | {CPM_CLK_SCC1, CPM_CLK2, 5}, |
| 517 | {CPM_CLK_SCC1, CPM_CLK3, 6}, |
| 518 | {CPM_CLK_SCC1, CPM_CLK4, 7}, |
| 519 | |
| 520 | {CPM_CLK_SCC2, CPM_BRG1, 0}, |
| 521 | {CPM_CLK_SCC2, CPM_BRG2, 1}, |
| 522 | {CPM_CLK_SCC2, CPM_BRG3, 2}, |
| 523 | {CPM_CLK_SCC2, CPM_BRG4, 3}, |
| 524 | {CPM_CLK_SCC2, CPM_CLK1, 4}, |
| 525 | {CPM_CLK_SCC2, CPM_CLK2, 5}, |
| 526 | {CPM_CLK_SCC2, CPM_CLK3, 6}, |
| 527 | {CPM_CLK_SCC2, CPM_CLK4, 7}, |
| 528 | |
| 529 | {CPM_CLK_SCC3, CPM_BRG1, 0}, |
| 530 | {CPM_CLK_SCC3, CPM_BRG2, 1}, |
| 531 | {CPM_CLK_SCC3, CPM_BRG3, 2}, |
| 532 | {CPM_CLK_SCC3, CPM_BRG4, 3}, |
| 533 | {CPM_CLK_SCC3, CPM_CLK5, 4}, |
| 534 | {CPM_CLK_SCC3, CPM_CLK6, 5}, |
| 535 | {CPM_CLK_SCC3, CPM_CLK7, 6}, |
| 536 | {CPM_CLK_SCC3, CPM_CLK8, 7}, |
| 537 | |
| 538 | {CPM_CLK_SCC4, CPM_BRG1, 0}, |
| 539 | {CPM_CLK_SCC4, CPM_BRG2, 1}, |
| 540 | {CPM_CLK_SCC4, CPM_BRG3, 2}, |
| 541 | {CPM_CLK_SCC4, CPM_BRG4, 3}, |
| 542 | {CPM_CLK_SCC4, CPM_CLK5, 4}, |
| 543 | {CPM_CLK_SCC4, CPM_CLK6, 5}, |
| 544 | {CPM_CLK_SCC4, CPM_CLK7, 6}, |
| 545 | {CPM_CLK_SCC4, CPM_CLK8, 7}, |
| 546 | |
| 547 | {CPM_CLK_SMC1, CPM_BRG1, 0}, |
| 548 | {CPM_CLK_SMC1, CPM_BRG2, 1}, |
| 549 | {CPM_CLK_SMC1, CPM_BRG3, 2}, |
| 550 | {CPM_CLK_SMC1, CPM_BRG4, 3}, |
| 551 | {CPM_CLK_SMC1, CPM_CLK1, 4}, |
| 552 | {CPM_CLK_SMC1, CPM_CLK2, 5}, |
| 553 | {CPM_CLK_SMC1, CPM_CLK3, 6}, |
| 554 | {CPM_CLK_SMC1, CPM_CLK4, 7}, |
| 555 | |
| 556 | {CPM_CLK_SMC2, CPM_BRG1, 0}, |
| 557 | {CPM_CLK_SMC2, CPM_BRG2, 1}, |
| 558 | {CPM_CLK_SMC2, CPM_BRG3, 2}, |
| 559 | {CPM_CLK_SMC2, CPM_BRG4, 3}, |
| 560 | {CPM_CLK_SMC2, CPM_CLK5, 4}, |
| 561 | {CPM_CLK_SMC2, CPM_CLK6, 5}, |
| 562 | {CPM_CLK_SMC2, CPM_CLK7, 6}, |
| 563 | {CPM_CLK_SMC2, CPM_CLK8, 7}, |
| 564 | }; |
| 565 | |
| 566 | switch (target) { |
| 567 | case CPM_CLK_SCC1: |
| 568 | reg = &mpc8xx_immr->im_cpm.cp_sicr; |
| 569 | shift = 0; |
| 570 | break; |
| 571 | |
| 572 | case CPM_CLK_SCC2: |
| 573 | reg = &mpc8xx_immr->im_cpm.cp_sicr; |
| 574 | shift = 8; |
| 575 | break; |
| 576 | |
| 577 | case CPM_CLK_SCC3: |
| 578 | reg = &mpc8xx_immr->im_cpm.cp_sicr; |
| 579 | shift = 16; |
| 580 | break; |
| 581 | |
| 582 | case CPM_CLK_SCC4: |
| 583 | reg = &mpc8xx_immr->im_cpm.cp_sicr; |
| 584 | shift = 24; |
| 585 | break; |
| 586 | |
| 587 | case CPM_CLK_SMC1: |
| 588 | reg = &mpc8xx_immr->im_cpm.cp_simode; |
| 589 | shift = 12; |
| 590 | break; |
| 591 | |
| 592 | case CPM_CLK_SMC2: |
| 593 | reg = &mpc8xx_immr->im_cpm.cp_simode; |
| 594 | shift = 28; |
| 595 | break; |
| 596 | |
| 597 | default: |
| 598 | printk(KERN_ERR "cpm1_clock_setup: invalid clock target\n"); |
| 599 | return -EINVAL; |
| 600 | } |
| 601 | |
| 602 | if (reg == &mpc8xx_immr->im_cpm.cp_sicr && mode == CPM_CLK_RX) |
| 603 | shift += 3; |
| 604 | |
| 605 | for (i = 0; i < ARRAY_SIZE(clk_map); i++) { |
| 606 | if (clk_map[i][0] == target && clk_map[i][1] == clock) { |
| 607 | bits = clk_map[i][2]; |
| 608 | break; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | if (i == ARRAY_SIZE(clk_map)) { |
| 613 | printk(KERN_ERR "cpm1_clock_setup: invalid clock combination\n"); |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | |
| 617 | bits <<= shift; |
| 618 | mask <<= shift; |
| 619 | out_be32(reg, (in_be32(reg) & ~mask) | bits); |
| 620 | |
| 621 | return 0; |
| 622 | } |