Path: blob/master/arch/powerpc/platforms/chrp/pegasos_eth.c
26481 views
// SPDX-License-Identifier: GPL-2.01/*2* Copyright (C) 2005 Sven Luther <[email protected]>3* Thanks to :4* Dale Farnsworth <[email protected]>5* Mark A. Greer <[email protected]>6* Nicolas DET <[email protected]>7* Benjamin Herrenschmidt <[email protected]>8* And anyone else who helped me on this.9*/1011#include <linux/types.h>12#include <linux/init.h>13#include <linux/ioport.h>14#include <linux/device.h>15#include <linux/platform_device.h>16#include <linux/mv643xx_eth.h>17#include <linux/pci.h>1819#define PEGASOS2_MARVELL_REGBASE (0xf1000000)20#define PEGASOS2_MARVELL_REGSIZE (0x00004000)21#define PEGASOS2_SRAM_BASE (0xf2000000)22#define PEGASOS2_SRAM_SIZE (256*1024)2324#define PEGASOS2_SRAM_BASE_ETH_PORT0 (PEGASOS2_SRAM_BASE)25#define PEGASOS2_SRAM_BASE_ETH_PORT1 (PEGASOS2_SRAM_BASE_ETH_PORT0 + (PEGASOS2_SRAM_SIZE / 2) )2627#define PEGASOS2_SRAM_RXRING_SIZE (PEGASOS2_SRAM_SIZE/4)28#define PEGASOS2_SRAM_TXRING_SIZE (PEGASOS2_SRAM_SIZE/4)2930#undef BE_VERBOSE3132#define MV64340_BASE_ADDR_ENABLE 0x27833#define MV64340_INTEGRATED_SRAM_BASE_ADDR 0x26834#define MV64340_SRAM_CONFIG 0x3803536static struct resource mv643xx_eth_shared_resources[] = {37[0] = {38.name = "ethernet shared base",39.start = 0xf1000000 + MV643XX_ETH_SHARED_REGS,40.end = 0xf1000000 + MV643XX_ETH_SHARED_REGS +41MV643XX_ETH_SHARED_REGS_SIZE - 1,42.flags = IORESOURCE_MEM,43},44};4546static struct platform_device mv643xx_eth_shared_device = {47.name = MV643XX_ETH_SHARED_NAME,48.id = 0,49.num_resources = ARRAY_SIZE(mv643xx_eth_shared_resources),50.resource = mv643xx_eth_shared_resources,51};5253/*54* The orion mdio driver only covers shared + 0x4 up to shared + 0x84 - 155*/56static struct resource mv643xx_eth_mvmdio_resources[] = {57[0] = {58.name = "ethernet mdio base",59.start = 0xf1000000 + MV643XX_ETH_SHARED_REGS + 0x4,60.end = 0xf1000000 + MV643XX_ETH_SHARED_REGS + 0x83,61.flags = IORESOURCE_MEM,62},63};6465static struct platform_device mv643xx_eth_mvmdio_device = {66.name = "orion-mdio",67.id = -1,68.num_resources = ARRAY_SIZE(mv643xx_eth_mvmdio_resources),69.resource = mv643xx_eth_mvmdio_resources,70};7172static struct resource mv643xx_eth_port1_resources[] = {73[0] = {74.name = "eth port1 irq",75.start = 9,76.end = 9,77.flags = IORESOURCE_IRQ,78},79};8081static struct mv643xx_eth_platform_data eth_port1_pd = {82.shared = &mv643xx_eth_shared_device,83.port_number = 1,84.phy_addr = MV643XX_ETH_PHY_ADDR(7),8586.tx_sram_addr = PEGASOS2_SRAM_BASE_ETH_PORT1,87.tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE,88.tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,8990.rx_sram_addr = PEGASOS2_SRAM_BASE_ETH_PORT1 + PEGASOS2_SRAM_TXRING_SIZE,91.rx_sram_size = PEGASOS2_SRAM_RXRING_SIZE,92.rx_queue_size = PEGASOS2_SRAM_RXRING_SIZE/16,93};9495static struct platform_device eth_port1_device = {96.name = MV643XX_ETH_NAME,97.id = 1,98.num_resources = ARRAY_SIZE(mv643xx_eth_port1_resources),99.resource = mv643xx_eth_port1_resources,100.dev = {101.platform_data = ð_port1_pd,102},103};104105static struct platform_device *mv643xx_eth_pd_devs[] __initdata = {106&mv643xx_eth_shared_device,107&mv643xx_eth_mvmdio_device,108ð_port1_device,109};110111/***********/112/***********/113#define MV_READ(offset,val) { val = readl(mv643xx_reg_base + offset); }114#define MV_WRITE(offset,data) writel(data, mv643xx_reg_base + offset)115116static void __iomem *mv643xx_reg_base;117118static int __init Enable_SRAM(void)119{120u32 ALong;121122if (mv643xx_reg_base == NULL)123mv643xx_reg_base = ioremap(PEGASOS2_MARVELL_REGBASE,124PEGASOS2_MARVELL_REGSIZE);125126if (mv643xx_reg_base == NULL)127return -ENOMEM;128129#ifdef BE_VERBOSE130printk("Pegasos II/Marvell MV64361: register remapped from %p to %p\n",131(void *)PEGASOS2_MARVELL_REGBASE, (void *)mv643xx_reg_base);132#endif133134MV_WRITE(MV64340_SRAM_CONFIG, 0);135136MV_WRITE(MV64340_INTEGRATED_SRAM_BASE_ADDR, PEGASOS2_SRAM_BASE >> 16);137138MV_READ(MV64340_BASE_ADDR_ENABLE, ALong);139ALong &= ~(1 << 19);140MV_WRITE(MV64340_BASE_ADDR_ENABLE, ALong);141142ALong = 0x02;143ALong |= PEGASOS2_SRAM_BASE & 0xffff0000;144MV_WRITE(MV643XX_ETH_BAR_4, ALong);145146MV_WRITE(MV643XX_ETH_SIZE_REG_4, (PEGASOS2_SRAM_SIZE-1) & 0xffff0000);147148MV_READ(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);149ALong &= ~(1 << 4);150MV_WRITE(MV643XX_ETH_BASE_ADDR_ENABLE_REG, ALong);151152#ifdef BE_VERBOSE153printk("Pegasos II/Marvell MV64361: register unmapped\n");154printk("Pegasos II/Marvell MV64361: SRAM at %p, size=%x\n", (void*) PEGASOS2_SRAM_BASE, PEGASOS2_SRAM_SIZE);155#endif156157iounmap(mv643xx_reg_base);158mv643xx_reg_base = NULL;159160return 1;161}162163164/***********/165/***********/166static int __init mv643xx_eth_add_pds(void)167{168int ret = 0;169static struct pci_device_id pci_marvell_mv64360[] = {170{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_MV64360) },171{ }172};173174#ifdef BE_VERBOSE175printk("Pegasos II/Marvell MV64361: init\n");176#endif177178if (pci_dev_present(pci_marvell_mv64360)) {179ret = platform_add_devices(mv643xx_eth_pd_devs,180ARRAY_SIZE(mv643xx_eth_pd_devs));181182if ( Enable_SRAM() < 0)183{184eth_port1_pd.tx_sram_addr = 0;185eth_port1_pd.tx_sram_size = 0;186eth_port1_pd.rx_sram_addr = 0;187eth_port1_pd.rx_sram_size = 0;188189#ifdef BE_VERBOSE190printk("Pegasos II/Marvell MV64361: Can't enable the "191"SRAM\n");192#endif193}194}195196#ifdef BE_VERBOSE197printk("Pegasos II/Marvell MV64361: init is over\n");198#endif199200return ret;201}202203device_initcall(mv643xx_eth_add_pds);204205206