162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
362306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
462306a36Sopenharmony_ci * for more details.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 2009-2011 Florian Fainelli <florian@openwrt.org>
762306a36Sopenharmony_ci * Copyright (C) 2010 Tanguy Bouzeloc <tanguy.bouzeloc@efixo.com>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/init.h>
1162306a36Sopenharmony_ci#include <linux/kernel.h>
1262306a36Sopenharmony_ci#include <linux/export.h>
1362306a36Sopenharmony_ci#include <linux/platform_device.h>
1462306a36Sopenharmony_ci#include <linux/err.h>
1562306a36Sopenharmony_ci#include <linux/clk.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include <bcm63xx_cpu.h>
1862306a36Sopenharmony_ci#include <bcm63xx_dev_spi.h>
1962306a36Sopenharmony_ci#include <bcm63xx_regs.h>
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_cistatic struct resource spi_resources[] = {
2262306a36Sopenharmony_ci	{
2362306a36Sopenharmony_ci		.start		= -1, /* filled at runtime */
2462306a36Sopenharmony_ci		.end		= -1, /* filled at runtime */
2562306a36Sopenharmony_ci		.flags		= IORESOURCE_MEM,
2662306a36Sopenharmony_ci	},
2762306a36Sopenharmony_ci	{
2862306a36Sopenharmony_ci		.start		= -1, /* filled at runtime */
2962306a36Sopenharmony_ci		.flags		= IORESOURCE_IRQ,
3062306a36Sopenharmony_ci	},
3162306a36Sopenharmony_ci};
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_cistatic struct platform_device bcm63xx_spi_device = {
3462306a36Sopenharmony_ci	.id		= -1,
3562306a36Sopenharmony_ci	.num_resources	= ARRAY_SIZE(spi_resources),
3662306a36Sopenharmony_ci	.resource	= spi_resources,
3762306a36Sopenharmony_ci};
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ciint __init bcm63xx_spi_register(void)
4062306a36Sopenharmony_ci{
4162306a36Sopenharmony_ci	if (BCMCPU_IS_6328() || BCMCPU_IS_6345())
4262306a36Sopenharmony_ci		return -ENODEV;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	spi_resources[0].start = bcm63xx_regset_address(RSET_SPI);
4562306a36Sopenharmony_ci	spi_resources[0].end = spi_resources[0].start;
4662306a36Sopenharmony_ci	spi_resources[1].start = bcm63xx_get_irq_number(IRQ_SPI);
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) {
4962306a36Sopenharmony_ci		bcm63xx_spi_device.name = "bcm6348-spi",
5062306a36Sopenharmony_ci		spi_resources[0].end += BCM_6348_RSET_SPI_SIZE - 1;
5162306a36Sopenharmony_ci	}
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci	if (BCMCPU_IS_3368() || BCMCPU_IS_6358() || BCMCPU_IS_6362() ||
5462306a36Sopenharmony_ci		BCMCPU_IS_6368()) {
5562306a36Sopenharmony_ci		bcm63xx_spi_device.name = "bcm6358-spi",
5662306a36Sopenharmony_ci		spi_resources[0].end += BCM_6358_RSET_SPI_SIZE - 1;
5762306a36Sopenharmony_ci	}
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	return platform_device_register(&bcm63xx_spi_device);
6062306a36Sopenharmony_ci}
61