blob: 349e7b567c4012ab61103c8e733010c3446392e8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Reinhard Arlt46911792009-07-25 06:19:12 +02002/*
3 * pci.c -- esd VME8349 PCI board support.
4 * Copyright (c) 2006 Wind River Systems, Inc.
5 * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
Reinhard Arlt0fa68f62009-12-08 09:21:41 +01006 * Copyright (c) 2009 esd gmbh.
7 *
8 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
Reinhard Arlt46911792009-07-25 06:19:12 +02009 *
10 * Based on MPC8349 PCI support but w/o PIB related code.
Reinhard Arlt46911792009-07-25 06:19:12 +020011 */
12
Simon Glass18afe102019-11-14 12:57:47 -070013#include <init.h>
Reinhard Arlt46911792009-07-25 06:19:12 +020014#include <asm/mmu.h>
15#include <asm/io.h>
16#include <common.h>
17#include <mpc83xx.h>
18#include <pci.h>
19#include <i2c.h>
20#include <asm/fsl_i2c.h>
Reinhard Arlt0fa68f62009-12-08 09:21:41 +010021#include "vme8349pin.h"
Reinhard Arlt46911792009-07-25 06:19:12 +020022
Reinhard Arlt46911792009-07-25 06:19:12 +020023static struct pci_region pci1_regions[] = {
24 {
25 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
26 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
27 size: CONFIG_SYS_PCI1_MEM_SIZE,
28 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
29 },
30 {
31 bus_start: CONFIG_SYS_PCI1_IO_BASE,
32 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
33 size: CONFIG_SYS_PCI1_IO_SIZE,
34 flags: PCI_REGION_IO
35 },
36 {
37 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
38 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
39 size: CONFIG_SYS_PCI1_MMIO_SIZE,
40 flags: PCI_REGION_MEM
41 },
42};
43
44/*
45 * pci_init_board()
46 *
47 * NOTICE: PCI2 is not supported. There is only one
48 * physical PCI slot on the board.
49 *
50 */
51void
52pci_init_board(void)
53{
54 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
55 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
56 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
57 struct pci_region *reg[] = { pci1_regions };
58 u8 reg8;
59 int monarch = 0;
60
61 i2c_set_bus_num(1);
62 /* Read the PCI_M66EN jumper setting */
63 if ((i2c_read(CONFIG_SYS_I2C_8574_ADDR2, 0, 0, &reg8, 1) == 0) ||
64 (i2c_read(0x38 , 0, 0, &reg8, 1) == 0)) {
65 if (reg8 & 0x40) {
66 clk->occr = 0xff000000; /* 66 MHz PCI */
67 printf("PCI: 66MHz\n");
68 } else {
69 clk->occr = 0xffff0003; /* 33 MHz PCI */
70 printf("PCI: 33MHz\n");
71 }
72 if (((reg8 & 0x01) == 0) || ((reg8 & 0x02) == 0))
73 monarch = 1;
74 } else {
75 clk->occr = 0xffff0003; /* 33 MHz PCI */
76 printf("PCI: 33MHz (I2C read failed)\n");
77 }
78 udelay(2000);
79
80 /*
Reinhard Arlt0fa68f62009-12-08 09:21:41 +010081 * Assert/deassert VME reset
Reinhard Arlt46911792009-07-25 06:19:12 +020082 */
Reinhard Arlt0fa68f62009-12-08 09:21:41 +010083 clrsetbits_be32(&immr->gpio[1].dat,
84 GPIO2_TSI_POWERUP_RESET_N | GPIO2_TSI_PLL_RESET_N,
85 GPIO2_VME_RESET_N | GPIO2_L_RESET_EN_N);
86 setbits_be32(&immr->gpio[1].dir, GPIO2_TSI_PLL_RESET_N |
87 GPIO2_TSI_POWERUP_RESET_N |
88 GPIO2_VME_RESET_N |
89 GPIO2_L_RESET_EN_N);
90 clrbits_be32(&immr->gpio[1].dir, GPIO2_V_SCON);
Reinhard Arlt46911792009-07-25 06:19:12 +020091 udelay(200);
Reinhard Arlt0fa68f62009-12-08 09:21:41 +010092 setbits_be32(&immr->gpio[1].dat, GPIO2_TSI_PLL_RESET_N);
Reinhard Arlt46911792009-07-25 06:19:12 +020093 udelay(200);
Reinhard Arlt0fa68f62009-12-08 09:21:41 +010094 setbits_be32(&immr->gpio[1].dat, GPIO2_TSI_POWERUP_RESET_N);
Reinhard Arlt46911792009-07-25 06:19:12 +020095 udelay(600000);
Reinhard Arlt0fa68f62009-12-08 09:21:41 +010096 clrbits_be32(&immr->gpio[1].dat, GPIO2_L_RESET_EN_N);
Reinhard Arlt46911792009-07-25 06:19:12 +020097
98 /* Configure PCI Local Access Windows */
99 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
100 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
101
102 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
103 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
104
105 udelay(2000);
106
Reinhard Arlt0fa68f62009-12-08 09:21:41 +0100107 if (monarch == 0) {
Peter Tysere2283322010-09-14 19:13:50 -0500108 mpc83xx_pci_init(1, reg);
Reinhard Arlt0fa68f62009-12-08 09:21:41 +0100109 } else {
110 /*
111 * Release PCI RST Output signal
112 */
113 out_be32(&immr->pci_ctrl[0].gcr, 0);
114 udelay(2000);
115 out_be32(&immr->pci_ctrl[0].gcr, 1);
116 }
Reinhard Arlt46911792009-07-25 06:19:12 +0200117}