linux/arch/ppc/platforms/powerpmc250.c
<<
>>
Prefs
   1/*
   2 * Board setup routines for Force PowerPMC-250 Processor PMC
   3 *
   4 * Author: Troy Benjegerdes <tbenjegerdes@mvista.com>
   5 * Borrowed heavily from prpmc750_*.c by
   6 *      Matt Porter <mporter@mvista.com>
   7 *
   8 * 2001 (c) MontaVista, Software, Inc.  This file is licensed under
   9 * the terms of the GNU General Public License version 2.  This program
  10 * is licensed "as is" without any warranty of any kind, whether express
  11 * or implied.
  12 */
  13
  14#include <linux/stddef.h>
  15#include <linux/kernel.h>
  16#include <linux/init.h>
  17#include <linux/errno.h>
  18#include <linux/reboot.h>
  19#include <linux/pci.h>
  20#include <linux/kdev_t.h>
  21#include <linux/types.h>
  22#include <linux/major.h>
  23#include <linux/initrd.h>
  24#include <linux/console.h>
  25#include <linux/delay.h>
  26#include <linux/slab.h>
  27#include <linux/seq_file.h>
  28#include <linux/ide.h>
  29#include <linux/root_dev.h>
  30
  31#include <asm/byteorder.h>
  32#include <asm/system.h>
  33#include <asm/pgtable.h>
  34#include <asm/page.h>
  35#include <asm/dma.h>
  36#include <asm/io.h>
  37#include <asm/irq.h>
  38#include <asm/machdep.h>
  39#include <asm/time.h>
  40#include <platforms/powerpmc250.h>
  41#include <asm/open_pic.h>
  42#include <asm/pci-bridge.h>
  43#include <asm/mpc10x.h>
  44#include <asm/uaccess.h>
  45#include <asm/bootinfo.h>
  46
  47extern void powerpmc250_find_bridges(void);
  48extern unsigned long loops_per_jiffy;
  49
  50static u_char powerpmc250_openpic_initsenses[] __initdata =
  51{
  52    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  53    1,  /* PMC INTA (also MPC107 output interrupt INTA) */
  54    1,  /* PMC INTB (also I82559 Ethernet controller) */
  55    1,  /* PMC INTC */
  56    1,  /* PMC INTD */
  57    0,  /* DUART interrupt (active high) */
  58};
  59
  60static int
  61powerpmc250_show_cpuinfo(struct seq_file *m)
  62{
  63        seq_printf(m,"machine\t\t: Force PowerPMC250\n");
  64
  65        return 0;
  66}
  67
  68static void __init
  69powerpmc250_setup_arch(void)
  70{
  71        /* init to some ~sane value until calibrate_delay() runs */
  72        loops_per_jiffy = 50000000/HZ;
  73
  74        /* Lookup PCI host bridges */
  75        powerpmc250_find_bridges();
  76
  77#ifdef CONFIG_BLK_DEV_INITRD
  78        if (initrd_start)
  79                ROOT_DEV = Root_RAM0;
  80        else
  81#endif
  82#ifdef CONFIG_ROOT_NFS
  83                ROOT_DEV = Root_NFS;
  84#else
  85                ROOT_DEV = Root_SDA2;
  86#endif
  87
  88        printk("Force PowerPMC250 port (C) 2001 MontaVista Software, Inc. (source@mvista.com)\n");
  89}
  90
  91#if 0
  92/*
  93 * Compute the PrPMC750's bus speed using the baud clock as a
  94 * reference.
  95 */
  96unsigned long __init powerpmc250_get_bus_speed(void)
  97{
  98        unsigned long tbl_start, tbl_end;
  99        unsigned long current_state, old_state, bus_speed;
 100        unsigned char lcr, dll, dlm;
 101        int baud_divisor, count;
 102
 103        /* Read the UART's baud clock divisor */
 104        lcr = readb(PRPMC750_SERIAL_0_LCR);
 105        writeb(lcr | UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
 106        dll = readb(PRPMC750_SERIAL_0_DLL);
 107        dlm = readb(PRPMC750_SERIAL_0_DLM);
 108        writeb(lcr & ~UART_LCR_DLAB, PRPMC750_SERIAL_0_LCR);
 109        baud_divisor = (dlm << 8) | dll;
 110
 111        /*
 112         * Use the baud clock divisor and base baud clock
 113         * to determine the baud rate and use that as
 114         * the number of baud clock edges we use for
 115         * the time base sample.  Make it half the baud
 116         * rate.
 117         */
 118        count = PRPMC750_BASE_BAUD / (baud_divisor * 16);
 119
 120        /* Find the first edge of the baud clock */
 121        old_state = readb(PRPMC750_STATUS_REG) & PRPMC750_BAUDOUT_MASK;
 122        do {
 123                current_state = readb(PRPMC750_STATUS_REG) &
 124                        PRPMC750_BAUDOUT_MASK;
 125        } while(old_state == current_state);
 126
 127        old_state = current_state;
 128
 129        /* Get the starting time base value */
 130        tbl_start = get_tbl();
 131
 132        /*
 133         * Loop until we have found a number of edges equal
 134         * to half the count (half the baud rate)
 135         */
 136        do {
 137                do {
 138                        current_state = readb(PRPMC750_STATUS_REG) &
 139                                PRPMC750_BAUDOUT_MASK;
 140                } while(old_state == current_state);
 141                old_state = current_state;
 142        } while (--count);
 143
 144        /* Get the ending time base value */
 145        tbl_end = get_tbl();
 146
 147        /* Compute bus speed */
 148        bus_speed = (tbl_end-tbl_start)*128;
 149
 150        return bus_speed;
 151}
 152#endif
 153
 154static void __init
 155powerpmc250_calibrate_decr(void)
 156{
 157        unsigned long freq;
 158        int divisor = 4;
 159
 160        //freq = powerpmc250_get_bus_speed();
 161#warning hardcoded bus freq
 162        freq = 100000000;
 163
 164        tb_ticks_per_jiffy = freq / (HZ * divisor);
 165        tb_to_us = mulhwu_scale_factor(freq/divisor, 1000000);
 166}
 167
 168static void
 169powerpmc250_restart(char *cmd)
 170{
 171        local_irq_disable();
 172        /* Hard reset */
 173        writeb(0x11, 0xfe000332);
 174        while(1);
 175}
 176
 177static void
 178powerpmc250_halt(void)
 179{
 180        local_irq_disable();
 181        while (1);
 182}
 183
 184static void
 185powerpmc250_power_off(void)
 186{
 187        powerpmc250_halt();
 188}
 189
 190static void __init
 191powerpmc250_init_IRQ(void)
 192{
 193
 194        OpenPIC_InitSenses = powerpmc250_openpic_initsenses;
 195        OpenPIC_NumInitSenses = sizeof(powerpmc250_openpic_initsenses);
 196        mpc10x_set_openpic();
 197}
 198
 199/*
 200 * Set BAT 3 to map 0xf0000000 to end of physical memory space.
 201 */
 202static __inline__ void
 203powerpmc250_set_bat(void)
 204{
 205        unsigned long   bat3u, bat3l;
 206        static int      mapping_set = 0;
 207
 208        if (!mapping_set)
 209        {
 210                __asm__ __volatile__(
 211                                " lis %0,0xf000\n \
 212                                ori %1,%0,0x002a\n \
 213                                ori %0,%0,0x1ffe\n \
 214                                mtspr 0x21e,%0\n \
 215                                mtspr 0x21f,%1\n \
 216                                isync\n \
 217                                sync "
 218                                : "=r" (bat3u), "=r" (bat3l));
 219
 220                mapping_set = 1;
 221        }
 222        return;
 223}
 224
 225static unsigned long __init
 226powerpmc250_find_end_of_memory(void)
 227{
 228        /* Cover I/O space with a BAT */
 229        /* yuck, better hope your ram size is a power of 2  -- paulus */
 230        powerpmc250_set_bat();
 231
 232        return mpc10x_get_mem_size(MPC10X_MEM_MAP_B);
 233}
 234
 235static void __init
 236powerpmc250_map_io(void)
 237{
 238        io_block_mapping(0xfe000000, 0xfe000000, 0x02000000, _PAGE_IO);
 239}
 240
 241void __init
 242platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
 243              unsigned long r6, unsigned long r7)
 244{
 245        parse_bootinfo(find_bootinfo());
 246
 247#ifdef CONFIG_BLK_DEV_INITRD
 248        if ( r4 )
 249        {
 250                initrd_start = r4 + KERNELBASE;
 251                initrd_end = r5 + KERNELBASE;
 252        }
 253#endif
 254
 255        /* Copy cmd_line parameters */
 256        if ( r6)
 257        {
 258                *(char *)(r7 + KERNELBASE) = 0;
 259                strcpy(cmd_line, (char *)(r6 + KERNELBASE));
 260        }
 261
 262        isa_io_base = MPC10X_MAPB_ISA_IO_BASE;
 263        isa_mem_base = MPC10X_MAPB_ISA_MEM_BASE;
 264        pci_dram_offset = MPC10X_MAPB_DRAM_OFFSET;
 265
 266        ppc_md.setup_arch       = powerpmc250_setup_arch;
 267        ppc_md.show_cpuinfo     = powerpmc250_show_cpuinfo;
 268        ppc_md.init_IRQ         = powerpmc250_init_IRQ;
 269        ppc_md.get_irq          = openpic_get_irq;
 270
 271        ppc_md.find_end_of_memory = powerpmc250_find_end_of_memory;
 272        ppc_md.setup_io_mappings = powerpmc250_map_io;
 273
 274        ppc_md.restart          = powerpmc250_restart;
 275        ppc_md.power_off        = powerpmc250_power_off;
 276        ppc_md.halt             = powerpmc250_halt;
 277
 278        /* PowerPMC250 has no timekeeper part */
 279        ppc_md.time_init        = NULL;
 280        ppc_md.get_rtc_time     = NULL;
 281        ppc_md.set_rtc_time     = NULL;
 282        ppc_md.calibrate_decr   = powerpmc250_calibrate_decr;
 283}
 284
 285
 286/*
 287 * (This used to be arch/ppc/platforms/powerpmc250_pci.c)
 288 *
 289 * PCI support for Force PowerPMC250
 290 *
 291 */
 292
 293#undef DEBUG
 294#ifdef DEBUG
 295#define DBG(x...) printk(x)
 296#else
 297#define DBG(x...)
 298#endif /* DEBUG */
 299
 300static inline int __init
 301powerpmc250_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
 302{
 303        static char pci_irq_table[][4] =
 304        /*
 305         *      PCI IDSEL/INTPIN->INTLINE
 306         *      A       B       C       D
 307         */
 308        {
 309                {17,    0,      0,      0},     /* Device 11 - 82559 */
 310                {0,     0,      0,      0},     /* 12 */
 311                {0,     0,      0,      0},     /* 13 */
 312                {0,     0,      0,      0},     /* 14 */
 313                {0,     0,      0,      0},     /* 15 */
 314                {16,    17,     18,     19},    /* Device 16 - PMC A1?? */
 315                };
 316        const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
 317        return PCI_IRQ_TABLE_LOOKUP;
 318};
 319
 320static int
 321powerpmc250_exclude_device(u_char bus, u_char devfn)
 322{
 323        /*
 324         * While doing PCI Scan  the MPC107 will 'detect' itself as
 325         * device on the PCI Bus, will create an incorrect response and
 326         * later will respond incorrectly to Configuration read coming
 327         * from another device.
 328         *
 329         * The work around is that when doing a PCI Scan one
 330         * should skip its own device number in the scan.
 331         *
 332         * The top IDsel is AD13 and the middle is AD14.
 333         *
 334         * -- Note from force
 335         */
 336
 337        if ((bus == 0) && (PCI_SLOT(devfn) == 13 || PCI_SLOT(devfn) == 14)) {
 338                return PCIBIOS_DEVICE_NOT_FOUND;
 339        }
 340        else {
 341                return PCIBIOS_SUCCESSFUL;
 342        }
 343}
 344
 345void __init
 346powerpmc250_find_bridges(void)
 347{
 348        struct pci_controller* hose;
 349
 350        hose = pcibios_alloc_controller();
 351        if (!hose){
 352                printk("Can't allocate PCI 'hose' structure!!!\n");
 353                return;
 354        }
 355
 356        hose->first_busno = 0;
 357        hose->last_busno = 0xff;
 358
 359        if (mpc10x_bridge_init(hose,
 360                        MPC10X_MEM_MAP_B,
 361                        MPC10X_MEM_MAP_B,
 362                        MPC10X_MAPB_EUMB_BASE) == 0) {
 363
 364                hose->mem_resources[0].end = 0xffffffff;
 365
 366                hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
 367
 368                /* ppc_md.pcibios_fixup = pcore_pcibios_fixup; */
 369                ppc_md.pci_swizzle = common_swizzle;
 370
 371                ppc_md.pci_exclude_device = powerpmc250_exclude_device;
 372                ppc_md.pci_map_irq = powerpmc250_map_irq;
 373        } else {
 374                if (ppc_md.progress)
 375                        ppc_md.progress("Bridge init failed", 0x100);
 376                printk("Host bridge init failed\n");
 377        }
 378
 379}
 380