Skip to content

Commit

Permalink
spi: sh-msiof: Move default FIFO sizes to device ID data
Browse files Browse the repository at this point in the history
As different variants of MSIOF have different FIFO sizes, move the default
FIFO sizes to a new struct sh_msiof_chipdata, pointed to from the device
ID data.

[Moved ifdef to fix build -- broonie]

Signed-off-by: Geert Uytterhoeven <geert+renesas@linux-m68k.org>
Acked-by: Magnus Damm <damm@opensource.se>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Geert Uytterhoeven authored and Mark Brown committed Feb 27, 2014
1 parent 32d3b2d commit 50a7e23
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions drivers/spi/spi-sh-msiof.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>

Expand All @@ -30,11 +31,18 @@

#include <asm/unaligned.h>


struct sh_msiof_chipdata {
u16 tx_fifo_size;
u16 rx_fifo_size;
};

struct sh_msiof_spi_priv {
struct spi_bitbang bitbang; /* must be first for spi_bitbang.c */
void __iomem *mapbase;
struct clk *clk;
struct platform_device *pdev;
const struct sh_msiof_chipdata *chipdata;
struct sh_msiof_spi_info *info;
struct completion done;
unsigned long flags;
Expand Down Expand Up @@ -113,10 +121,6 @@ struct sh_msiof_spi_priv {
#define STR_REOF 0x00000080 /* Frame Reception End */


#define DEFAULT_TX_FIFO_SIZE 64
#define DEFAULT_RX_FIFO_SIZE 64


static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs)
{
switch (reg_offs) {
Expand Down Expand Up @@ -659,6 +663,18 @@ static u32 sh_msiof_spi_txrx_word(struct spi_device *spi, unsigned nsecs,
return 0;
}

static const struct sh_msiof_chipdata sh_data = {
.tx_fifo_size = 64,
.rx_fifo_size = 64,
};

static const struct of_device_id sh_msiof_match[] = {
{ .compatible = "renesas,sh-msiof", .data = &sh_data },
{ .compatible = "renesas,sh-mobile-msiof", .data = &sh_data },
{},
};
MODULE_DEVICE_TABLE(of, sh_msiof_match);

#ifdef CONFIG_OF
static struct sh_msiof_spi_info *sh_msiof_spi_parse_dt(struct device *dev)
{
Expand Down Expand Up @@ -694,6 +710,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
{
struct resource *r;
struct spi_master *master;
const struct of_device_id *of_id;
struct sh_msiof_spi_priv *p;
int i;
int ret;
Expand All @@ -707,10 +724,15 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
p = spi_master_get_devdata(master);

platform_set_drvdata(pdev, p);
if (pdev->dev.of_node)

of_id = of_match_device(sh_msiof_match, &pdev->dev);
if (of_id) {
p->chipdata = of_id->data;
p->info = sh_msiof_spi_parse_dt(&pdev->dev);
else
} else {
p->chipdata = (const void *)pdev->id_entry->driver_data;
p->info = dev_get_platdata(&pdev->dev);
}

if (!p->info) {
dev_err(&pdev->dev, "failed to obtain device info\n");
Expand Down Expand Up @@ -757,11 +779,9 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
p->pdev = pdev;
pm_runtime_enable(&pdev->dev);

/* The standard version of MSIOF use 64 word FIFOs */
p->tx_fifo_size = DEFAULT_TX_FIFO_SIZE;
p->rx_fifo_size = DEFAULT_RX_FIFO_SIZE;

/* Platform data may override FIFO sizes */
p->tx_fifo_size = p->chipdata->tx_fifo_size;
p->rx_fifo_size = p->chipdata->rx_fifo_size;
if (p->info->tx_fifo_override)
p->tx_fifo_size = p->info->tx_fifo_override;
if (p->info->rx_fifo_override)
Expand Down Expand Up @@ -811,18 +831,16 @@ static int sh_msiof_spi_remove(struct platform_device *pdev)
return ret;
}

#ifdef CONFIG_OF
static const struct of_device_id sh_msiof_match[] = {
{ .compatible = "renesas,sh-msiof", },
{ .compatible = "renesas,sh-mobile-msiof", },
static struct platform_device_id spi_driver_ids[] = {
{ "spi_sh_msiof", (kernel_ulong_t)&sh_data },
{},
};
MODULE_DEVICE_TABLE(of, sh_msiof_match);
#endif
MODULE_DEVICE_TABLE(platform, spi_driver_ids);

static struct platform_driver sh_msiof_spi_drv = {
.probe = sh_msiof_spi_probe,
.remove = sh_msiof_spi_remove,
.id_table = spi_driver_ids,
.driver = {
.name = "spi_sh_msiof",
.owner = THIS_MODULE,
Expand Down

0 comments on commit 50a7e23

Please sign in to comment.