Path: blob/master/arch/powerpc/platforms/83xx/mpc832x_rdb.c
26481 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* arch/powerpc/platforms/83xx/mpc832x_rdb.c3*4* Copyright (C) Freescale Semiconductor, Inc. 2007. All rights reserved.5*6* Description:7* MPC832x RDB board specific routines.8* This file is based on mpc832x_mds.c and mpc8313_rdb.c9* Author: Michael Barkowski <[email protected]>10*/1112#include <linux/pci.h>13#include <linux/interrupt.h>14#include <linux/spi/spi.h>15#include <linux/spi/mmc_spi.h>16#include <linux/mmc/host.h>17#include <linux/of.h>18#include <linux/of_address.h>19#include <linux/of_irq.h>20#include <linux/platform_device.h>21#include <linux/fsl_devices.h>2223#include <asm/time.h>24#include <asm/ipic.h>25#include <asm/udbg.h>26#include <soc/fsl/qe/qe.h>27#include <sysdev/fsl_soc.h>28#include <sysdev/fsl_pci.h>2930#include "mpc83xx.h"3132#undef DEBUG33#ifdef DEBUG34#define DBG(fmt...) udbg_printf(fmt)35#else36#define DBG(fmt...)37#endif3839#ifdef CONFIG_QUICC_ENGINE40static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,41struct spi_board_info *board_infos,42unsigned int num_board_infos,43void (*cs_control)(struct spi_device *dev,44bool on))45{46struct device_node *np;47unsigned int i = 0;4849for_each_compatible_node(np, type, compatible) {50int ret;51unsigned int j;52const void *prop;53struct resource res[2];54struct platform_device *pdev;55struct fsl_spi_platform_data pdata = {56.cs_control = cs_control,57};5859memset(res, 0, sizeof(res));6061pdata.sysclk = sysclk;6263prop = of_get_property(np, "reg", NULL);64if (!prop)65goto err;66pdata.bus_num = *(u32 *)prop;6768prop = of_get_property(np, "cell-index", NULL);69if (prop)70i = *(u32 *)prop;7172prop = of_get_property(np, "mode", NULL);73if (prop && !strcmp(prop, "cpu-qe"))74pdata.flags = SPI_QE_CPU_MODE;7576for (j = 0; j < num_board_infos; j++) {77if (board_infos[j].bus_num == pdata.bus_num)78pdata.max_chipselect++;79}8081if (!pdata.max_chipselect)82continue;8384ret = of_address_to_resource(np, 0, &res[0]);85if (ret)86goto err;8788ret = of_irq_to_resource(np, 0, &res[1]);89if (ret <= 0)90goto err;9192pdev = platform_device_alloc("mpc83xx_spi", i);93if (!pdev)94goto err;9596ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));97if (ret)98goto unreg;99100ret = platform_device_add_resources(pdev, res,101ARRAY_SIZE(res));102if (ret)103goto unreg;104105ret = platform_device_add(pdev);106if (ret)107goto unreg;108109goto next;110unreg:111platform_device_put(pdev);112err:113pr_err("%pOF: registration failed\n", np);114next:115i++;116}117118return i;119}120121static int __init fsl_spi_init(struct spi_board_info *board_infos,122unsigned int num_board_infos,123void (*cs_control)(struct spi_device *spi,124bool on))125{126u32 sysclk = -1;127int ret;128129/* SPI controller is either clocked from QE or SoC clock */130sysclk = get_brgfreq();131if (sysclk == -1) {132sysclk = fsl_get_sys_freq();133if (sysclk == -1)134return -ENODEV;135}136137ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,138num_board_infos, cs_control);139if (!ret)140of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,141num_board_infos, cs_control);142143return spi_register_board_info(board_infos, num_board_infos);144}145146static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on)147{148pr_debug("%s %d %d\n", __func__, spi_get_chipselect(spi, 0), on);149par_io_data_set(3, 13, on);150}151152static struct mmc_spi_platform_data mpc832x_mmc_pdata = {153.ocr_mask = MMC_VDD_33_34,154};155156static struct spi_board_info mpc832x_spi_boardinfo = {157.bus_num = 0x4c0,158.chip_select = 0,159.max_speed_hz = 50000000,160.modalias = "mmc_spi",161.platform_data = &mpc832x_mmc_pdata,162};163164static int __init mpc832x_spi_init(void)165{166struct device_node *np;167168par_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*/181np = of_find_compatible_node(NULL, NULL, "mmc-spi-slot");182of_node_put(np);183if (np)184return 0;185return fsl_spi_init(&mpc832x_spi_boardinfo, 1, mpc83xx_spi_cs_control);186}187machine_device_initcall(mpc832x_rdb, mpc832x_spi_init);188#endif /* CONFIG_QUICC_ENGINE */189190/* ************************************************************************191*192* Setup the architecture193*194*/195static void __init mpc832x_rdb_setup_arch(void)196{197#if defined(CONFIG_QUICC_ENGINE)198struct device_node *np;199#endif200201mpc83xx_setup_arch();202203#ifdef CONFIG_QUICC_ENGINE204if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {205par_io_init(np);206of_node_put(np);207208for_each_node_by_name(np, "ucc")209par_io_of_config(np);210}211#endif /* CONFIG_QUICC_ENGINE */212}213214machine_device_initcall(mpc832x_rdb, mpc83xx_declare_of_platform_devices);215216define_machine(mpc832x_rdb) {217.name = "MPC832x RDB",218.compatible = "MPC832xRDB",219.setup_arch = mpc832x_rdb_setup_arch,220.discover_phbs = mpc83xx_setup_pci,221.init_IRQ = mpc83xx_ipic_init_IRQ,222.get_irq = ipic_get_irq,223.restart = mpc83xx_restart,224.time_init = mpc83xx_time_init,225.progress = udbg_progress,226};227228229