コード例 #1
0
ファイル: ar71xx_spi.c プロジェクト: Cribstone/linino
static int ar71xx_spi_setup(struct spi_device *spi)
{
	int status;

	if (spi->bits_per_word > 32)
		return -EINVAL;

	if (!spi->controller_state)
		ar71xx_spi_setup_regs(spi);

	status = spi_bitbang_setup(spi);
	if (status && !spi->controller_state)
		ar71xx_spi_restore_regs(spi);

	return status;
}
コード例 #2
0
ファイル: ar71xx_spi.c プロジェクト: nutbolt/carambola
static int ar71xx_spi_probe(struct platform_device *pdev)
{
	struct spi_master *master;
	struct ar71xx_spi *sp;
	struct ar71xx_spi_platform_data *pdata;
	struct resource	*r;
	int ret;

	master = spi_alloc_master(&pdev->dev, sizeof(*sp));
	if (master == NULL) {
		dev_err(&pdev->dev, "failed to allocate spi master\n");
		return -ENOMEM;
	}

	sp = spi_master_get_devdata(master);
	platform_set_drvdata(pdev, sp);

	pdata = pdev->dev.platform_data;

	master->setup = ar71xx_spi_setup;
	master->cleanup = ar71xx_spi_cleanup;

	sp->bitbang.master = spi_master_get(master);
	sp->bitbang.chipselect = ar71xx_spi_chipselect;
	sp->bitbang.txrx_word[SPI_MODE_0] = ar71xx_spi_txrx_mode0;
	sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;

	sp->get_ioc_base = ar71xx_spi_get_ioc_base;
	if (pdata) {
		sp->bitbang.master->bus_num = pdata->bus_num;
		sp->bitbang.master->num_chipselect = pdata->num_chipselect;
		if (pdata->get_ioc_base)
			sp->get_ioc_base = pdata->get_ioc_base;
	} else {
		sp->bitbang.master->bus_num = 0;
		sp->bitbang.master->num_chipselect = 3;
	}

	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (r == NULL) {
		ret = -ENOENT;
		goto err1;
	}

	sp->base = ioremap_nocache(r->start, r->end - r->start + 1);
	if (!sp->base) {
		ret = -ENXIO;
		goto err1;
	}

	ar71xx_spi_setup_regs(sp);

	ret = spi_bitbang_start(&sp->bitbang);
	if (!ret)
		return 0;

	ar71xx_spi_restore_regs(sp);
	iounmap(sp->base);
err1:
	platform_set_drvdata(pdev, NULL);
	spi_master_put(sp->bitbang.master);

	return ret;
}