Path: blob/master/arch/powerpc/platforms/83xx/mpc832x_rdb.c
10819 views
/*1* arch/powerpc/platforms/83xx/mpc832x_rdb.c2*3* Copyright (C) Freescale Semiconductor, Inc. 2007. All rights reserved.4*5* Description:6* MPC832x RDB board specific routines.7* This file is based on mpc832x_mds.c and mpc8313_rdb.c8* Author: Michael Barkowski <[email protected]>9*10* This program is free software; you can redistribute it and/or modify it11* under the terms of the GNU General Public License as published by the12* Free Software Foundation; either version 2 of the License, or (at your13* option) any later version.14*/1516#include <linux/pci.h>17#include <linux/interrupt.h>18#include <linux/spi/spi.h>19#include <linux/spi/mmc_spi.h>20#include <linux/mmc/host.h>21#include <linux/of_platform.h>22#include <linux/fsl_devices.h>2324#include <asm/time.h>25#include <asm/ipic.h>26#include <asm/udbg.h>27#include <asm/qe.h>28#include <asm/qe_ic.h>29#include <sysdev/fsl_soc.h>30#include <sysdev/fsl_pci.h>3132#include "mpc83xx.h"3334#undef DEBUG35#ifdef DEBUG36#define DBG(fmt...) udbg_printf(fmt)37#else38#define DBG(fmt...)39#endif4041#ifdef CONFIG_QUICC_ENGINE42static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,43struct spi_board_info *board_infos,44unsigned int num_board_infos,45void (*cs_control)(struct spi_device *dev,46bool on))47{48struct device_node *np;49unsigned int i = 0;5051for_each_compatible_node(np, type, compatible) {52int ret;53unsigned int j;54const void *prop;55struct resource res[2];56struct platform_device *pdev;57struct fsl_spi_platform_data pdata = {58.cs_control = cs_control,59};6061memset(res, 0, sizeof(res));6263pdata.sysclk = sysclk;6465prop = of_get_property(np, "reg", NULL);66if (!prop)67goto err;68pdata.bus_num = *(u32 *)prop;6970prop = of_get_property(np, "cell-index", NULL);71if (prop)72i = *(u32 *)prop;7374prop = of_get_property(np, "mode", NULL);75if (prop && !strcmp(prop, "cpu-qe"))76pdata.flags = SPI_QE_CPU_MODE;7778for (j = 0; j < num_board_infos; j++) {79if (board_infos[j].bus_num == pdata.bus_num)80pdata.max_chipselect++;81}8283if (!pdata.max_chipselect)84continue;8586ret = of_address_to_resource(np, 0, &res[0]);87if (ret)88goto err;8990ret = of_irq_to_resource(np, 0, &res[1]);91if (ret == NO_IRQ)92goto err;9394pdev = platform_device_alloc("mpc83xx_spi", i);95if (!pdev)96goto err;9798ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));99if (ret)100goto unreg;101102ret = platform_device_add_resources(pdev, res,103ARRAY_SIZE(res));104if (ret)105goto unreg;106107ret = platform_device_add(pdev);108if (ret)109goto unreg;110111goto next;112unreg:113platform_device_del(pdev);114err:115pr_err("%s: registration failed\n", np->full_name);116next:117i++;118}119120return i;121}122123static int __init fsl_spi_init(struct spi_board_info *board_infos,124unsigned int num_board_infos,125void (*cs_control)(struct spi_device *spi,126bool on))127{128u32 sysclk = -1;129int ret;130131/* SPI controller is either clocked from QE or SoC clock */132sysclk = get_brgfreq();133if (sysclk == -1) {134sysclk = fsl_get_sys_freq();135if (sysclk == -1)136return -ENODEV;137}138139ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,140num_board_infos, cs_control);141if (!ret)142of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,143num_board_infos, cs_control);144145return spi_register_board_info(board_infos, num_board_infos);146}147148static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on)149{150pr_debug("%s %d %d\n", __func__, spi->chip_select, on);151par_io_data_set(3, 13, on);152}153154static struct mmc_spi_platform_data mpc832x_mmc_pdata = {155.ocr_mask = MMC_VDD_33_34,156};157158static struct spi_board_info mpc832x_spi_boardinfo = {159.bus_num = 0x4c0,160.chip_select = 0,161.max_speed_hz = 50000000,162.modalias = "mmc_spi",163.platform_data = &mpc832x_mmc_pdata,164};165166static int __init mpc832x_spi_init(void)167{168par_io_config_pin(3, 0, 3, 0, 1, 0); /* SPI1 MOSI, I/O */169par_io_config_pin(3, 1, 3, 0, 1, 0); /* SPI1 MISO, I/O */170par_io_config_pin(3, 2, 3, 0, 1, 0); /* SPI1 CLK, I/O */171par_io_config_pin(3, 3, 2, 0, 1, 0); /* SPI1 SEL, I */172173par_io_config_pin(3, 13, 1, 0, 0, 0); /* !SD_CS, O */174par_io_config_pin(3, 14, 2, 0, 0, 0); /* SD_INSERT, I */175par_io_config_pin(3, 15, 2, 0, 0, 0); /* SD_PROTECT,I */176177/*178* Don't bother with legacy stuff when device tree contains179* mmc-spi-slot node.180*/181if (of_find_compatible_node(NULL, NULL, "mmc-spi-slot"))182return 0;183return fsl_spi_init(&mpc832x_spi_boardinfo, 1, mpc83xx_spi_cs_control);184}185machine_device_initcall(mpc832x_rdb, mpc832x_spi_init);186#endif /* CONFIG_QUICC_ENGINE */187188/* ************************************************************************189*190* Setup the architecture191*192*/193static void __init mpc832x_rdb_setup_arch(void)194{195#if defined(CONFIG_PCI) || defined(CONFIG_QUICC_ENGINE)196struct device_node *np;197#endif198199if (ppc_md.progress)200ppc_md.progress("mpc832x_rdb_setup_arch()", 0);201202#ifdef CONFIG_PCI203for_each_compatible_node(np, "pci", "fsl,mpc8349-pci")204mpc83xx_add_bridge(np);205#endif206207#ifdef CONFIG_QUICC_ENGINE208qe_reset();209210if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {211par_io_init(np);212of_node_put(np);213214for (np = NULL; (np = of_find_node_by_name(np, "ucc")) != NULL;)215par_io_of_config(np);216}217#endif /* CONFIG_QUICC_ENGINE */218}219220static struct of_device_id mpc832x_ids[] = {221{ .type = "soc", },222{ .compatible = "soc", },223{ .compatible = "simple-bus", },224{ .type = "qe", },225{ .compatible = "fsl,qe", },226{},227};228229static int __init mpc832x_declare_of_platform_devices(void)230{231/* Publish the QE devices */232of_platform_bus_probe(NULL, mpc832x_ids, NULL);233234return 0;235}236machine_device_initcall(mpc832x_rdb, mpc832x_declare_of_platform_devices);237238static void __init mpc832x_rdb_init_IRQ(void)239{240241struct device_node *np;242243np = of_find_node_by_type(NULL, "ipic");244if (!np)245return;246247ipic_init(np, 0);248249/* Initialize the default interrupt mapping priorities,250* in case the boot rom changed something on us.251*/252ipic_set_default_priority();253of_node_put(np);254255#ifdef CONFIG_QUICC_ENGINE256np = of_find_compatible_node(NULL, NULL, "fsl,qe-ic");257if (!np) {258np = of_find_node_by_type(NULL, "qeic");259if (!np)260return;261}262qe_ic_init(np, 0, qe_ic_cascade_low_ipic, qe_ic_cascade_high_ipic);263of_node_put(np);264#endif /* CONFIG_QUICC_ENGINE */265}266267/*268* Called very early, MMU is off, device-tree isn't unflattened269*/270static int __init mpc832x_rdb_probe(void)271{272unsigned long root = of_get_flat_dt_root();273274return of_flat_dt_is_compatible(root, "MPC832xRDB");275}276277define_machine(mpc832x_rdb) {278.name = "MPC832x RDB",279.probe = mpc832x_rdb_probe,280.setup_arch = mpc832x_rdb_setup_arch,281.init_IRQ = mpc832x_rdb_init_IRQ,282.get_irq = ipic_get_irq,283.restart = mpc83xx_restart,284.time_init = mpc83xx_time_init,285.calibrate_decr = generic_calibrate_decr,286.progress = udbg_progress,287};288289290