18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Setup pointers to hardware-dependent routines.
38c2ecf20Sopenharmony_ci * Copyright (C) 2000-2001 Toshiba Corporation
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
68c2ecf20Sopenharmony_ci * terms of the GNU General Public License version 2. This program is
78c2ecf20Sopenharmony_ci * licensed "as is" without any warranty of any kind, whether express
88c2ecf20Sopenharmony_ci * or implied.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci#include <linux/init.h>
138c2ecf20Sopenharmony_ci#include <linux/types.h>
148c2ecf20Sopenharmony_ci#include <linux/ioport.h>
158c2ecf20Sopenharmony_ci#include <linux/delay.h>
168c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
178c2ecf20Sopenharmony_ci#include <linux/gpio/driver.h>
188c2ecf20Sopenharmony_ci#include <linux/gpio.h>
198c2ecf20Sopenharmony_ci#include <linux/mtd/physmap.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <asm/reboot.h>
228c2ecf20Sopenharmony_ci#include <asm/io.h>
238c2ecf20Sopenharmony_ci#include <asm/txx9/generic.h>
248c2ecf20Sopenharmony_ci#include <asm/txx9/pci.h>
258c2ecf20Sopenharmony_ci#include <asm/txx9/rbtx4938.h>
268c2ecf20Sopenharmony_ci#include <linux/spi/spi.h>
278c2ecf20Sopenharmony_ci#include <asm/txx9/spi.h>
288c2ecf20Sopenharmony_ci#include <asm/txx9pio.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic void rbtx4938_machine_restart(char *command)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	local_irq_disable();
338c2ecf20Sopenharmony_ci	writeb(1, rbtx4938_softresetlock_addr);
348c2ecf20Sopenharmony_ci	writeb(1, rbtx4938_sfvol_addr);
358c2ecf20Sopenharmony_ci	writeb(1, rbtx4938_softreset_addr);
368c2ecf20Sopenharmony_ci	/* fallback */
378c2ecf20Sopenharmony_ci	(*_machine_halt)();
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic void __init rbtx4938_pci_setup(void)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
438c2ecf20Sopenharmony_ci	int extarb = !(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB);
448c2ecf20Sopenharmony_ci	struct pci_controller *c = &txx9_primary_pcic;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci	register_pci_controller(c);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	if (__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66)
498c2ecf20Sopenharmony_ci		txx9_pci_option =
508c2ecf20Sopenharmony_ci			(txx9_pci_option & ~TXX9_PCI_OPT_CLK_MASK) |
518c2ecf20Sopenharmony_ci			TXX9_PCI_OPT_CLK_66; /* already configured */
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	/* Reset PCI Bus */
548c2ecf20Sopenharmony_ci	writeb(0, rbtx4938_pcireset_addr);
558c2ecf20Sopenharmony_ci	/* Reset PCIC */
568c2ecf20Sopenharmony_ci	txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
578c2ecf20Sopenharmony_ci	if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
588c2ecf20Sopenharmony_ci	    TXX9_PCI_OPT_CLK_66)
598c2ecf20Sopenharmony_ci		tx4938_pciclk66_setup();
608c2ecf20Sopenharmony_ci	mdelay(10);
618c2ecf20Sopenharmony_ci	/* clear PCIC reset */
628c2ecf20Sopenharmony_ci	txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
638c2ecf20Sopenharmony_ci	writeb(1, rbtx4938_pcireset_addr);
648c2ecf20Sopenharmony_ci	iob();
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	tx4938_report_pciclk();
678c2ecf20Sopenharmony_ci	tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
688c2ecf20Sopenharmony_ci	if ((txx9_pci_option & TXX9_PCI_OPT_CLK_MASK) ==
698c2ecf20Sopenharmony_ci	    TXX9_PCI_OPT_CLK_AUTO &&
708c2ecf20Sopenharmony_ci	    txx9_pci66_check(c, 0, 0)) {
718c2ecf20Sopenharmony_ci		/* Reset PCI Bus */
728c2ecf20Sopenharmony_ci		writeb(0, rbtx4938_pcireset_addr);
738c2ecf20Sopenharmony_ci		/* Reset PCIC */
748c2ecf20Sopenharmony_ci		txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
758c2ecf20Sopenharmony_ci		tx4938_pciclk66_setup();
768c2ecf20Sopenharmony_ci		mdelay(10);
778c2ecf20Sopenharmony_ci		/* clear PCIC reset */
788c2ecf20Sopenharmony_ci		txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIRST);
798c2ecf20Sopenharmony_ci		writeb(1, rbtx4938_pcireset_addr);
808c2ecf20Sopenharmony_ci		iob();
818c2ecf20Sopenharmony_ci		/* Reinitialize PCIC */
828c2ecf20Sopenharmony_ci		tx4938_report_pciclk();
838c2ecf20Sopenharmony_ci		tx4927_pcic_setup(tx4938_pcicptr, c, extarb);
848c2ecf20Sopenharmony_ci	}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	if (__raw_readq(&tx4938_ccfgptr->pcfg) &
878c2ecf20Sopenharmony_ci	    (TX4938_PCFG_ETH0_SEL|TX4938_PCFG_ETH1_SEL)) {
888c2ecf20Sopenharmony_ci		/* Reset PCIC1 */
898c2ecf20Sopenharmony_ci		txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
908c2ecf20Sopenharmony_ci		/* PCI1DMD==0 => PCI1CLK==GBUSCLK/2 => PCI66 */
918c2ecf20Sopenharmony_ci		if (!(__raw_readq(&tx4938_ccfgptr->ccfg)
928c2ecf20Sopenharmony_ci		      & TX4938_CCFG_PCI1DMD))
938c2ecf20Sopenharmony_ci			tx4938_ccfg_set(TX4938_CCFG_PCI1_66);
948c2ecf20Sopenharmony_ci		mdelay(10);
958c2ecf20Sopenharmony_ci		/* clear PCIC1 reset */
968c2ecf20Sopenharmony_ci		txx9_clear64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
978c2ecf20Sopenharmony_ci		tx4938_report_pci1clk();
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci		/* mem:64K(max), io:64K(max) (enough for ETH0,ETH1) */
1008c2ecf20Sopenharmony_ci		c = txx9_alloc_pci_controller(NULL, 0, 0x10000, 0, 0x10000);
1018c2ecf20Sopenharmony_ci		register_pci_controller(c);
1028c2ecf20Sopenharmony_ci		tx4927_pcic_setup(tx4938_pcic1ptr, c, 0);
1038c2ecf20Sopenharmony_ci	}
1048c2ecf20Sopenharmony_ci	tx4938_setup_pcierr_irq();
1058c2ecf20Sopenharmony_ci#endif /* CONFIG_PCI */
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* SPI support */
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/* chip select for SPI devices */
1118c2ecf20Sopenharmony_ci#define SEEPROM1_CS	7	/* PIO7 */
1128c2ecf20Sopenharmony_ci#define SEEPROM2_CS	0	/* IOC */
1138c2ecf20Sopenharmony_ci#define SEEPROM3_CS	1	/* IOC */
1148c2ecf20Sopenharmony_ci#define SRTC_CS 2	/* IOC */
1158c2ecf20Sopenharmony_ci#define SPI_BUSNO	0
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic int __init rbtx4938_ethaddr_init(void)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
1208c2ecf20Sopenharmony_ci	unsigned char dat[17];
1218c2ecf20Sopenharmony_ci	unsigned char sum;
1228c2ecf20Sopenharmony_ci	int i;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	/* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
1258c2ecf20Sopenharmony_ci	if (spi_eeprom_read(SPI_BUSNO, SEEPROM1_CS, 0, dat, sizeof(dat))) {
1268c2ecf20Sopenharmony_ci		pr_err("seeprom: read error.\n");
1278c2ecf20Sopenharmony_ci		return -ENODEV;
1288c2ecf20Sopenharmony_ci	} else {
1298c2ecf20Sopenharmony_ci		if (strcmp(dat, "MAC") != 0)
1308c2ecf20Sopenharmony_ci			pr_warn("seeprom: bad signature.\n");
1318c2ecf20Sopenharmony_ci		for (i = 0, sum = 0; i < sizeof(dat); i++)
1328c2ecf20Sopenharmony_ci			sum += dat[i];
1338c2ecf20Sopenharmony_ci		if (sum)
1348c2ecf20Sopenharmony_ci			pr_warn("seeprom: bad checksum.\n");
1358c2ecf20Sopenharmony_ci	}
1368c2ecf20Sopenharmony_ci	tx4938_ethaddr_init(&dat[4], &dat[4 + 6]);
1378c2ecf20Sopenharmony_ci#endif /* CONFIG_PCI */
1388c2ecf20Sopenharmony_ci	return 0;
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic void __init rbtx4938_spi_setup(void)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	/* set SPI_SEL */
1448c2ecf20Sopenharmony_ci	txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_SPI_SEL);
1458c2ecf20Sopenharmony_ci}
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistatic struct resource rbtx4938_fpga_resource;
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic void __init rbtx4938_time_init(void)
1508c2ecf20Sopenharmony_ci{
1518c2ecf20Sopenharmony_ci	tx4938_time_init(0);
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic void __init rbtx4938_mem_setup(void)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci	unsigned long long pcfg;
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	if (txx9_master_clock == 0)
1598c2ecf20Sopenharmony_ci		txx9_master_clock = 25000000; /* 25MHz */
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	tx4938_setup();
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
1648c2ecf20Sopenharmony_ci	txx9_alloc_pci_controller(&txx9_primary_pcic, 0, 0, 0, 0);
1658c2ecf20Sopenharmony_ci	txx9_board_pcibios_setup = tx4927_pcibios_setup;
1668c2ecf20Sopenharmony_ci#else
1678c2ecf20Sopenharmony_ci	set_io_port_base(RBTX4938_ETHER_BASE);
1688c2ecf20Sopenharmony_ci#endif
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	tx4938_sio_init(7372800, 0);
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
1738c2ecf20Sopenharmony_ci	pr_info("PIOSEL: disabling both ATA and NAND selection\n");
1748c2ecf20Sopenharmony_ci	txx9_clear64(&tx4938_ccfgptr->pcfg,
1758c2ecf20Sopenharmony_ci		     TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
1768c2ecf20Sopenharmony_ci#endif
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
1798c2ecf20Sopenharmony_ci	pr_info("PIOSEL: enabling NAND selection\n");
1808c2ecf20Sopenharmony_ci	txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
1818c2ecf20Sopenharmony_ci	txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
1828c2ecf20Sopenharmony_ci#endif
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
1858c2ecf20Sopenharmony_ci	pr_info("PIOSEL: enabling ATA selection\n");
1868c2ecf20Sopenharmony_ci	txx9_set64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_ATA_SEL);
1878c2ecf20Sopenharmony_ci	txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_NDF_SEL);
1888c2ecf20Sopenharmony_ci#endif
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_KEEP
1918c2ecf20Sopenharmony_ci	pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
1928c2ecf20Sopenharmony_ci	pr_info("PIOSEL: NAND %s, ATA %s\n",
1938c2ecf20Sopenharmony_ci		(pcfg & TX4938_PCFG_NDF_SEL) ? "enabled" : "disabled",
1948c2ecf20Sopenharmony_ci		(pcfg & TX4938_PCFG_ATA_SEL) ? "enabled" : "disabled");
1958c2ecf20Sopenharmony_ci#endif
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	rbtx4938_spi_setup();
1988c2ecf20Sopenharmony_ci	pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);	/* updated */
1998c2ecf20Sopenharmony_ci	/* fixup piosel */
2008c2ecf20Sopenharmony_ci	if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
2018c2ecf20Sopenharmony_ci	    TX4938_PCFG_ATA_SEL)
2028c2ecf20Sopenharmony_ci		writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x04,
2038c2ecf20Sopenharmony_ci		       rbtx4938_piosel_addr);
2048c2ecf20Sopenharmony_ci	else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
2058c2ecf20Sopenharmony_ci		 TX4938_PCFG_NDF_SEL)
2068c2ecf20Sopenharmony_ci		writeb((readb(rbtx4938_piosel_addr) & 0x03) | 0x08,
2078c2ecf20Sopenharmony_ci		       rbtx4938_piosel_addr);
2088c2ecf20Sopenharmony_ci	else
2098c2ecf20Sopenharmony_ci		writeb(readb(rbtx4938_piosel_addr) & ~(0x08 | 0x04),
2108c2ecf20Sopenharmony_ci		       rbtx4938_piosel_addr);
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	rbtx4938_fpga_resource.name = "FPGA Registers";
2138c2ecf20Sopenharmony_ci	rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
2148c2ecf20Sopenharmony_ci	rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
2158c2ecf20Sopenharmony_ci	rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
2168c2ecf20Sopenharmony_ci	if (request_resource(&txx9_ce_res[2], &rbtx4938_fpga_resource))
2178c2ecf20Sopenharmony_ci		pr_err("request resource for fpga failed\n");
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	_machine_restart = rbtx4938_machine_restart;
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci	writeb(0xff, rbtx4938_led_addr);
2228c2ecf20Sopenharmony_ci	pr_info("RBTX4938 --- FPGA(Rev %02x) DIPSW:%02x,%02x\n",
2238c2ecf20Sopenharmony_ci		readb(rbtx4938_fpga_rev_addr),
2248c2ecf20Sopenharmony_ci		readb(rbtx4938_dipsw_addr), readb(rbtx4938_bdipsw_addr));
2258c2ecf20Sopenharmony_ci}
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_cistatic void __init rbtx4938_ne_init(void)
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci	struct resource res[] = {
2308c2ecf20Sopenharmony_ci		{
2318c2ecf20Sopenharmony_ci			.start	= RBTX4938_RTL_8019_BASE,
2328c2ecf20Sopenharmony_ci			.end	= RBTX4938_RTL_8019_BASE + 0x20 - 1,
2338c2ecf20Sopenharmony_ci			.flags	= IORESOURCE_IO,
2348c2ecf20Sopenharmony_ci		}, {
2358c2ecf20Sopenharmony_ci			.start	= RBTX4938_RTL_8019_IRQ,
2368c2ecf20Sopenharmony_ci			.flags	= IORESOURCE_IRQ,
2378c2ecf20Sopenharmony_ci		}
2388c2ecf20Sopenharmony_ci	};
2398c2ecf20Sopenharmony_ci	platform_device_register_simple("ne", -1, res, ARRAY_SIZE(res));
2408c2ecf20Sopenharmony_ci}
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cistatic void rbtx4938_spi_gpio_set(struct gpio_chip *chip, unsigned int offset,
2458c2ecf20Sopenharmony_ci				  int value)
2468c2ecf20Sopenharmony_ci{
2478c2ecf20Sopenharmony_ci	u8 val;
2488c2ecf20Sopenharmony_ci	unsigned long flags;
2498c2ecf20Sopenharmony_ci	spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
2508c2ecf20Sopenharmony_ci	val = readb(rbtx4938_spics_addr);
2518c2ecf20Sopenharmony_ci	if (value)
2528c2ecf20Sopenharmony_ci		val |= 1 << offset;
2538c2ecf20Sopenharmony_ci	else
2548c2ecf20Sopenharmony_ci		val &= ~(1 << offset);
2558c2ecf20Sopenharmony_ci	writeb(val, rbtx4938_spics_addr);
2568c2ecf20Sopenharmony_ci	mmiowb();
2578c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistatic int rbtx4938_spi_gpio_dir_out(struct gpio_chip *chip,
2618c2ecf20Sopenharmony_ci				     unsigned int offset, int value)
2628c2ecf20Sopenharmony_ci{
2638c2ecf20Sopenharmony_ci	rbtx4938_spi_gpio_set(chip, offset, value);
2648c2ecf20Sopenharmony_ci	return 0;
2658c2ecf20Sopenharmony_ci}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistatic struct gpio_chip rbtx4938_spi_gpio_chip = {
2688c2ecf20Sopenharmony_ci	.set = rbtx4938_spi_gpio_set,
2698c2ecf20Sopenharmony_ci	.direction_output = rbtx4938_spi_gpio_dir_out,
2708c2ecf20Sopenharmony_ci	.label = "RBTX4938-SPICS",
2718c2ecf20Sopenharmony_ci	.base = 16,
2728c2ecf20Sopenharmony_ci	.ngpio = 3,
2738c2ecf20Sopenharmony_ci};
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_cistatic int __init rbtx4938_spi_init(void)
2768c2ecf20Sopenharmony_ci{
2778c2ecf20Sopenharmony_ci	struct spi_board_info srtc_info = {
2788c2ecf20Sopenharmony_ci		.modalias = "rtc-rs5c348",
2798c2ecf20Sopenharmony_ci		.max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
2808c2ecf20Sopenharmony_ci		.bus_num = 0,
2818c2ecf20Sopenharmony_ci		.chip_select = 16 + SRTC_CS,
2828c2ecf20Sopenharmony_ci		/* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS  */
2838c2ecf20Sopenharmony_ci		.mode = SPI_MODE_1 | SPI_CS_HIGH,
2848c2ecf20Sopenharmony_ci	};
2858c2ecf20Sopenharmony_ci	spi_register_board_info(&srtc_info, 1);
2868c2ecf20Sopenharmony_ci	spi_eeprom_register(SPI_BUSNO, SEEPROM1_CS, 128);
2878c2ecf20Sopenharmony_ci	spi_eeprom_register(SPI_BUSNO, 16 + SEEPROM2_CS, 128);
2888c2ecf20Sopenharmony_ci	spi_eeprom_register(SPI_BUSNO, 16 + SEEPROM3_CS, 128);
2898c2ecf20Sopenharmony_ci	gpio_request(16 + SRTC_CS, "rtc-rs5c348");
2908c2ecf20Sopenharmony_ci	gpio_direction_output(16 + SRTC_CS, 0);
2918c2ecf20Sopenharmony_ci	gpio_request(SEEPROM1_CS, "seeprom1");
2928c2ecf20Sopenharmony_ci	gpio_direction_output(SEEPROM1_CS, 1);
2938c2ecf20Sopenharmony_ci	gpio_request(16 + SEEPROM2_CS, "seeprom2");
2948c2ecf20Sopenharmony_ci	gpio_direction_output(16 + SEEPROM2_CS, 1);
2958c2ecf20Sopenharmony_ci	gpio_request(16 + SEEPROM3_CS, "seeprom3");
2968c2ecf20Sopenharmony_ci	gpio_direction_output(16 + SEEPROM3_CS, 1);
2978c2ecf20Sopenharmony_ci	tx4938_spi_init(SPI_BUSNO);
2988c2ecf20Sopenharmony_ci	return 0;
2998c2ecf20Sopenharmony_ci}
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_cistatic void __init rbtx4938_mtd_init(void)
3028c2ecf20Sopenharmony_ci{
3038c2ecf20Sopenharmony_ci	struct physmap_flash_data pdata = {
3048c2ecf20Sopenharmony_ci		.width = 4,
3058c2ecf20Sopenharmony_ci	};
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	switch (readb(rbtx4938_bdipsw_addr) & 7) {
3088c2ecf20Sopenharmony_ci	case 0:
3098c2ecf20Sopenharmony_ci		/* Boot */
3108c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(0, 0x1fc00000, 0x400000, &pdata);
3118c2ecf20Sopenharmony_ci		/* System */
3128c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(1, 0x1e000000, 0x1000000, &pdata);
3138c2ecf20Sopenharmony_ci		break;
3148c2ecf20Sopenharmony_ci	case 1:
3158c2ecf20Sopenharmony_ci		/* System */
3168c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(0, 0x1f000000, 0x1000000, &pdata);
3178c2ecf20Sopenharmony_ci		/* Boot */
3188c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(1, 0x1ec00000, 0x400000, &pdata);
3198c2ecf20Sopenharmony_ci		break;
3208c2ecf20Sopenharmony_ci	case 2:
3218c2ecf20Sopenharmony_ci		/* Ext */
3228c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(0, 0x1f000000, 0x1000000, &pdata);
3238c2ecf20Sopenharmony_ci		/* System */
3248c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(1, 0x1e000000, 0x1000000, &pdata);
3258c2ecf20Sopenharmony_ci		/* Boot */
3268c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(2, 0x1dc00000, 0x400000, &pdata);
3278c2ecf20Sopenharmony_ci		break;
3288c2ecf20Sopenharmony_ci	case 3:
3298c2ecf20Sopenharmony_ci		/* Boot */
3308c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(1, 0x1bc00000, 0x400000, &pdata);
3318c2ecf20Sopenharmony_ci		/* System */
3328c2ecf20Sopenharmony_ci		txx9_physmap_flash_init(2, 0x1a000000, 0x1000000, &pdata);
3338c2ecf20Sopenharmony_ci		break;
3348c2ecf20Sopenharmony_ci	}
3358c2ecf20Sopenharmony_ci}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cistatic void __init rbtx4938_arch_init(void)
3388c2ecf20Sopenharmony_ci{
3398c2ecf20Sopenharmony_ci	txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
3408c2ecf20Sopenharmony_ci	gpiochip_add_data(&rbtx4938_spi_gpio_chip, NULL);
3418c2ecf20Sopenharmony_ci	rbtx4938_pci_setup();
3428c2ecf20Sopenharmony_ci	rbtx4938_spi_init();
3438c2ecf20Sopenharmony_ci}
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_cistatic void __init rbtx4938_device_init(void)
3468c2ecf20Sopenharmony_ci{
3478c2ecf20Sopenharmony_ci	rbtx4938_ethaddr_init();
3488c2ecf20Sopenharmony_ci	rbtx4938_ne_init();
3498c2ecf20Sopenharmony_ci	tx4938_wdt_init();
3508c2ecf20Sopenharmony_ci	rbtx4938_mtd_init();
3518c2ecf20Sopenharmony_ci	/* TC58DVM82A1FT: tDH=10ns, tWP=tRP=tREADID=35ns */
3528c2ecf20Sopenharmony_ci	tx4938_ndfmc_init(10, 35);
3538c2ecf20Sopenharmony_ci	tx4938_ata_init(RBTX4938_IRQ_IOC_ATA, 0, 1);
3548c2ecf20Sopenharmony_ci	tx4938_dmac_init(0, 2);
3558c2ecf20Sopenharmony_ci	tx4938_aclc_init();
3568c2ecf20Sopenharmony_ci	platform_device_register_simple("txx9aclc-generic", -1, NULL, 0);
3578c2ecf20Sopenharmony_ci	tx4938_sramc_init();
3588c2ecf20Sopenharmony_ci	txx9_iocled_init(RBTX4938_LED_ADDR - IO_BASE, -1, 8, 1, "green", NULL);
3598c2ecf20Sopenharmony_ci}
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cistruct txx9_board_vec rbtx4938_vec __initdata = {
3628c2ecf20Sopenharmony_ci	.system = "Toshiba RBTX4938",
3638c2ecf20Sopenharmony_ci	.prom_init = rbtx4938_prom_init,
3648c2ecf20Sopenharmony_ci	.mem_setup = rbtx4938_mem_setup,
3658c2ecf20Sopenharmony_ci	.irq_setup = rbtx4938_irq_setup,
3668c2ecf20Sopenharmony_ci	.time_init = rbtx4938_time_init,
3678c2ecf20Sopenharmony_ci	.device_init = rbtx4938_device_init,
3688c2ecf20Sopenharmony_ci	.arch_init = rbtx4938_arch_init,
3698c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
3708c2ecf20Sopenharmony_ci	.pci_map_irq = rbtx4938_pci_map_irq,
3718c2ecf20Sopenharmony_ci#endif
3728c2ecf20Sopenharmony_ci};
373