Path: blob/master/arch/sh/boards/mach-sdk7786/setup.c
15126 views
/*1* Renesas Technology Europe SDK7786 Support.2*3* Copyright (C) 2010 Matt Fleming4* Copyright (C) 2010 Paul Mundt5*6* This file is subject to the terms and conditions of the GNU General Public7* License. See the file "COPYING" in the main directory of this archive8* for more details.9*/10#include <linux/init.h>11#include <linux/platform_device.h>12#include <linux/io.h>13#include <linux/smsc911x.h>14#include <linux/i2c.h>15#include <linux/irq.h>16#include <linux/clk.h>17#include <linux/clkdev.h>18#include <mach/fpga.h>19#include <mach/irq.h>20#include <asm/machvec.h>21#include <asm/heartbeat.h>22#include <asm/sizes.h>23#include <asm/clock.h>24#include <asm/reboot.h>25#include <asm/smp-ops.h>2627static struct resource heartbeat_resource = {28.start = 0x07fff8b0,29.end = 0x07fff8b0 + sizeof(u16) - 1,30.flags = IORESOURCE_MEM | IORESOURCE_MEM_16BIT,31};3233static struct platform_device heartbeat_device = {34.name = "heartbeat",35.id = -1,36.num_resources = 1,37.resource = &heartbeat_resource,38};3940static struct resource smsc911x_resources[] = {41[0] = {42.name = "smsc911x-memory",43.start = 0x07ffff00,44.end = 0x07ffff00 + SZ_256 - 1,45.flags = IORESOURCE_MEM,46},47[1] = {48.name = "smsc911x-irq",49.start = evt2irq(0x2c0),50.end = evt2irq(0x2c0),51.flags = IORESOURCE_IRQ,52},53};5455static struct smsc911x_platform_config smsc911x_config = {56.irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,57.irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,58.flags = SMSC911X_USE_32BIT,59.phy_interface = PHY_INTERFACE_MODE_MII,60};6162static struct platform_device smsc911x_device = {63.name = "smsc911x",64.id = -1,65.num_resources = ARRAY_SIZE(smsc911x_resources),66.resource = smsc911x_resources,67.dev = {68.platform_data = &smsc911x_config,69},70};7172static struct resource smbus_fpga_resource = {73.start = 0x07fff9e0,74.end = 0x07fff9e0 + SZ_32 - 1,75.flags = IORESOURCE_MEM,76};7778static struct platform_device smbus_fpga_device = {79.name = "i2c-sdk7786",80.id = 0,81.num_resources = 1,82.resource = &smbus_fpga_resource,83};8485static struct resource smbus_pcie_resource = {86.start = 0x07fffc30,87.end = 0x07fffc30 + SZ_32 - 1,88.flags = IORESOURCE_MEM,89};9091static struct platform_device smbus_pcie_device = {92.name = "i2c-sdk7786",93.id = 1,94.num_resources = 1,95.resource = &smbus_pcie_resource,96};9798static struct i2c_board_info __initdata sdk7786_i2c_devices[] = {99{100I2C_BOARD_INFO("max6900", 0x68),101},102};103104static struct platform_device *sh7786_devices[] __initdata = {105&heartbeat_device,106&smsc911x_device,107&smbus_fpga_device,108&smbus_pcie_device,109};110111static int sdk7786_i2c_setup(void)112{113unsigned int tmp;114115/*116* Hand over I2C control to the FPGA.117*/118tmp = fpga_read_reg(SBCR);119tmp &= ~SCBR_I2CCEN;120tmp |= SCBR_I2CMEN;121fpga_write_reg(tmp, SBCR);122123return i2c_register_board_info(0, sdk7786_i2c_devices,124ARRAY_SIZE(sdk7786_i2c_devices));125}126127static int __init sdk7786_devices_setup(void)128{129int ret;130131ret = platform_add_devices(sh7786_devices, ARRAY_SIZE(sh7786_devices));132if (unlikely(ret != 0))133return ret;134135return sdk7786_i2c_setup();136}137device_initcall(sdk7786_devices_setup);138139static int sdk7786_mode_pins(void)140{141return fpga_read_reg(MODSWR);142}143144/*145* FPGA-driven PCIe clocks146*147* Historically these include the oscillator, clock B (slots 2/3/4) and148* clock A (slot 1 and the CPU clock). Newer revs of the PCB shove149* everything under a single PCIe clocks enable bit that happens to map150* to the same bit position as the oscillator bit for earlier FPGA151* versions.152*153* Given that the legacy clocks have the side-effect of shutting the CPU154* off through the FPGA along with the PCI slots, we simply leave them in155* their initial state and don't bother registering them with the clock156* framework.157*/158static int sdk7786_pcie_clk_enable(struct clk *clk)159{160fpga_write_reg(fpga_read_reg(PCIECR) | PCIECR_CLKEN, PCIECR);161return 0;162}163164static void sdk7786_pcie_clk_disable(struct clk *clk)165{166fpga_write_reg(fpga_read_reg(PCIECR) & ~PCIECR_CLKEN, PCIECR);167}168169static struct clk_ops sdk7786_pcie_clk_ops = {170.enable = sdk7786_pcie_clk_enable,171.disable = sdk7786_pcie_clk_disable,172};173174static struct clk sdk7786_pcie_clk = {175.ops = &sdk7786_pcie_clk_ops,176};177178static struct clk_lookup sdk7786_pcie_cl = {179.con_id = "pcie_plat_clk",180.clk = &sdk7786_pcie_clk,181};182183static int sdk7786_clk_init(void)184{185struct clk *clk;186int ret;187188/*189* Only handle the EXTAL case, anyone interfacing a crystal190* resonator will need to provide their own input clock.191*/192if (test_mode_pin(MODE_PIN9))193return -EINVAL;194195clk = clk_get(NULL, "extal");196if (!clk || IS_ERR(clk))197return PTR_ERR(clk);198ret = clk_set_rate(clk, 33333333);199clk_put(clk);200201/*202* Setup the FPGA clocks.203*/204ret = clk_register(&sdk7786_pcie_clk);205if (unlikely(ret)) {206pr_err("FPGA clock registration failed\n");207return ret;208}209210clkdev_add(&sdk7786_pcie_cl);211212return 0;213}214215static void sdk7786_restart(char *cmd)216{217fpga_write_reg(0xa5a5, SRSTR);218}219220static void sdk7786_power_off(void)221{222fpga_write_reg(fpga_read_reg(PWRCR) | PWRCR_PDWNREQ, PWRCR);223224/*225* It can take up to 20us for the R8C to do its job, back off and226* wait a bit until we've been shut off. Even though newer FPGA227* versions don't set the ACK bit, the latency issue remains.228*/229while ((fpga_read_reg(PWRCR) & PWRCR_PDWNACK) == 0)230cpu_sleep();231}232233/* Initialize the board */234static void __init sdk7786_setup(char **cmdline_p)235{236pr_info("Renesas Technology Europe SDK7786 support:\n");237238sdk7786_fpga_init();239sdk7786_nmi_init();240241pr_info("\tPCB revision:\t%d\n", fpga_read_reg(PCBRR) & 0xf);242243machine_ops.restart = sdk7786_restart;244pm_power_off = sdk7786_power_off;245246register_smp_ops(&shx3_smp_ops);247}248249/*250* The Machine Vector251*/252static struct sh_machine_vector mv_sdk7786 __initmv = {253.mv_name = "SDK7786",254.mv_setup = sdk7786_setup,255.mv_mode_pins = sdk7786_mode_pins,256.mv_clk_init = sdk7786_clk_init,257.mv_init_irq = sdk7786_init_irq,258};259260261