From d8e328b3bd65fdefc9c49a27ee80c28e0a44b653 Mon Sep 17 00:00:00 2001 From: Grant Likely Date: Sun, 20 May 2012 00:08:13 -0600 Subject: spi: Add "spi:" prefix to modalias attribute of spi devices The modalias attribute of spi devices doesn't have the "spi:" prefix that is used in the UEVENT and in spi device drivers. This patch adds the prefix so the modprobe can correctly match modules to devices. Reported-by: David Daney Signed-off-by: Grant Likely diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 1041cb8..84c2861 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -53,7 +53,7 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf) { const struct spi_device *spi = to_spi_device(dev); - return sprintf(buf, "%s\n", spi->modalias); + return sprintf(buf, "%s%s\n", SPI_MODULE_PREFIX, spi->modalias); } static struct device_attribute spi_dev_attrs[] = { -- cgit v0.10.2 From fd316941cfee1fbd12746afea83720fb7823888a Mon Sep 17 00:00:00 2001 From: Virupax Sadashivpetimath Date: Tue, 12 Jun 2012 15:10:58 +0200 Subject: spi/pl022: disable port when unused Commit ffbbdd21329f3e15eeca6df2d4bc11c04d9d91c0 "spi: create a message queueing infrastructure" Accidentally deleted the logic to disable the port when unused leading to higher power consumption. Fix this up. Cc: stable@kernel.org Cc: Vinit Shenoy Signed-off-by: Virupax Sadashivpetimath Signed-off-by: Linus Walleij diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 400ae21..469eb28 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c @@ -489,6 +489,11 @@ static void giveback(struct pl022 *pl022) pl022->cur_transfer = NULL; pl022->cur_chip = NULL; spi_finalize_current_message(pl022->master); + + /* disable the SPI/SSP operation */ + writew((readw(SSP_CR1(pl022->virtbase)) & + (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase)); + } /** -- cgit v0.10.2 From 42f978c3ef26db2a125eff24557a007ab8dd3e8d Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 12 Jun 2012 15:06:44 +0200 Subject: spi/pl022: delete DB5500 support This ASIC variant has been deleted from the ARM tree, no need to keep support around. Cc: Vinit Shenoy Signed-off-by: Linus Walleij diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 469eb28..5eab281 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c @@ -2256,15 +2256,6 @@ static struct vendor_data vendor_st_pl023 = { .loopback = false, }; -static struct vendor_data vendor_db5500_pl023 = { - .fifodepth = 32, - .max_bpw = 32, - .unidir = false, - .extended_cr = true, - .pl023 = true, - .loopback = true, -}; - static struct amba_id pl022_ids[] = { { /* @@ -2296,11 +2287,6 @@ static struct amba_id pl022_ids[] = { .mask = 0xffffffff, .data = &vendor_st_pl023, }, - { - .id = 0x10080023, - .mask = 0xffffffff, - .data = &vendor_db5500_pl023, - }, { 0, 0 }, }; -- cgit v0.10.2 From 2fb30d1147c599f5657e8c62c862f9a0f58d9d99 Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Tue, 12 Jun 2012 16:14:51 +0200 Subject: spi/pl022: enable runtime PM If we're gonna use runtime PM it's a pretty good idea to actually enable it in probe() and disable it in remove() too, so it gets used for real. Up until now we only fooled around with the reference count. Cc: Vinit Shenoy Signed-off-by: Linus Walleij diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c index 5eab281..aab518e 100644 --- a/drivers/spi/spi-pl022.c +++ b/drivers/spi/spi-pl022.c @@ -2053,6 +2053,9 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id) printk(KERN_INFO "pl022: mapped registers from 0x%08x to %p\n", adev->res.start, pl022->virtbase); + pm_runtime_enable(dev); + pm_runtime_resume(dev); + pl022->clk = clk_get(&adev->dev, NULL); if (IS_ERR(pl022->clk)) { status = PTR_ERR(pl022->clk); @@ -2163,6 +2166,7 @@ pl022_remove(struct amba_device *adev) clk_disable(pl022->clk); clk_unprepare(pl022->clk); clk_put(pl022->clk); + pm_runtime_disable(&adev->dev); iounmap(pl022->virtbase); amba_release_regions(adev); tasklet_disable(&pl022->pump_transfers); -- cgit v0.10.2 From 5b063b87deba33ed1676db9d16c52ede662132d8 Mon Sep 17 00:00:00 2001 From: Alexandre Pereira da Silva Date: Thu, 14 Jun 2012 10:10:32 -0300 Subject: spi/pl022: cleanup pl022 header documentation Remove the unused fields from struct ssp_config_chip that was removed before Add bus_id documentation to pl022_ssp_controller Signed-off-by: Alexandre Pereira da Silva Signed-off-by: Roland Stigge diff --git a/include/linux/amba/pl022.h b/include/linux/amba/pl022.h index 76dd1b1..fe1d7b2 100644 --- a/include/linux/amba/pl022.h +++ b/include/linux/amba/pl022.h @@ -231,6 +231,7 @@ enum ssp_chip_select { struct dma_chan; /** * struct pl022_ssp_master - device.platform_data for SPI controller devices. + * @bus_id: identifier for this bus * @num_chipselect: chipselects are used to distinguish individual * SPI slaves, and are numbered from zero to num_chipselects - 1. * each slave has a chipselect signal, but it's common that not @@ -259,19 +260,13 @@ struct pl022_ssp_controller { * struct ssp_config_chip - spi_board_info.controller_data for SPI * slave devices, copied to spi_device.controller_data. * - * @lbm: used for test purpose to internally connect RX and TX * @iface: Interface type(Motorola, TI, Microwire, Universal) * @hierarchy: sets whether interface is master or slave * @slave_tx_disable: SSPTXD is disconnected (in slave mode only) * @clk_freq: Tune freq parameters of SSP(when in master mode) - * @endian_rx: Endianess of Data in Rx FIFO - * @endian_tx: Endianess of Data in Tx FIFO - * @data_size: Width of data element(4 to 32 bits) * @com_mode: communication mode: polling, Interrupt or DMA * @rx_lev_trig: Rx FIFO watermark level (for IT & DMA mode) * @tx_lev_trig: Tx FIFO watermark level (for IT & DMA mode) - * @clk_phase: Motorola SPI interface Clock phase - * @clk_pol: Motorola SPI interface Clock polarity * @ctrl_len: Microwire interface: Control length * @wait_state: Microwire interface: Wait state * @duplex: Microwire interface: Full/Half duplex @@ -279,8 +274,6 @@ struct pl022_ssp_controller { * before sampling the incoming line * @cs_control: function pointer to board-specific function to * assert/deassert I/O port to control HW generation of devices chip-select. - * @dma_xfer_type: Type of DMA xfer (Mem-to-periph or Periph-to-Periph) - * @dma_config: DMA configuration for SSP controller and peripheral */ struct pl022_config_chip { enum ssp_interface iface; -- cgit v0.10.2 From 619ac8d3e582ccd806f24dcfc369c4c250ca9814 Mon Sep 17 00:00:00 2001 From: Laxman Dewangan Date: Tue, 10 Jul 2012 19:08:37 +0530 Subject: spi: tegra: use dmaengine based dma driver Use the dmaengine based Tegra APB DMA driver for data transfer between SPI FIFO and memory in place of legacy Tegra APB DMA. The new driver is selected if legacy driver is not selected and new DMA driver is enabled through config file. Signed-off-by: Laxman Dewangan Acked-by: Stephen Warren Signed-off-by: Mark Brown diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 00c0240..6eeb8a2 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -357,7 +357,7 @@ config SPI_STMP3XXX config SPI_TEGRA tristate "Nvidia Tegra SPI controller" - depends on ARCH_TEGRA && TEGRA_SYSTEM_DMA + depends on ARCH_TEGRA && (TEGRA_SYSTEM_DMA || TEGRA20_APB_DMA) help SPI driver for NVidia Tegra SoCs diff --git a/drivers/spi/spi-tegra.c b/drivers/spi/spi-tegra.c index ae6d78a..956ff4a 100644 --- a/drivers/spi/spi-tegra.c +++ b/drivers/spi/spi-tegra.c @@ -30,6 +30,7 @@ #include #include +#include #include @@ -162,12 +163,23 @@ struct spi_tegra_data { * require transfers to be 4 byte aligned we need a bounce buffer * for the generic case. */ + int dma_req_len; +#if defined(CONFIG_TEGRA_SYSTEM_DMA) struct tegra_dma_req rx_dma_req; struct tegra_dma_channel *rx_dma; +#else + struct dma_chan *rx_dma; + struct dma_slave_config sconfig; + struct dma_async_tx_descriptor *rx_dma_desc; + dma_cookie_t rx_cookie; +#endif u32 *rx_bb; dma_addr_t rx_bb_phys; }; +#if !defined(CONFIG_TEGRA_SYSTEM_DMA) +static void tegra_spi_rx_dma_complete(void *args); +#endif static inline unsigned long spi_tegra_readl(struct spi_tegra_data *tspi, unsigned long reg) @@ -190,10 +202,24 @@ static void spi_tegra_go(struct spi_tegra_data *tspi) val = spi_tegra_readl(tspi, SLINK_DMA_CTL); val &= ~SLINK_DMA_BLOCK_SIZE(~0) & ~SLINK_DMA_EN; - val |= SLINK_DMA_BLOCK_SIZE(tspi->rx_dma_req.size / 4 - 1); + val |= SLINK_DMA_BLOCK_SIZE(tspi->dma_req_len / 4 - 1); spi_tegra_writel(tspi, val, SLINK_DMA_CTL); - +#if defined(CONFIG_TEGRA_SYSTEM_DMA) + tspi->rx_dma_req.size = tspi->dma_req_len; tegra_dma_enqueue_req(tspi->rx_dma, &tspi->rx_dma_req); +#else + tspi->rx_dma_desc = dmaengine_prep_slave_single(tspi->rx_dma, + tspi->rx_bb_phys, tspi->dma_req_len, + DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); + if (!tspi->rx_dma_desc) { + dev_err(&tspi->pdev->dev, "dmaengine slave prep failed\n"); + return; + } + tspi->rx_dma_desc->callback = tegra_spi_rx_dma_complete; + tspi->rx_dma_desc->callback_param = tspi; + tspi->rx_cookie = dmaengine_submit(tspi->rx_dma_desc); + dma_async_issue_pending(tspi->rx_dma); +#endif val |= SLINK_DMA_EN; spi_tegra_writel(tspi, val, SLINK_DMA_CTL); @@ -221,7 +247,7 @@ static unsigned spi_tegra_fill_tx_fifo(struct spi_tegra_data *tspi, spi_tegra_writel(tspi, val, SLINK_TX_FIFO); } - tspi->rx_dma_req.size = len / tspi->cur_bytes_per_word * 4; + tspi->dma_req_len = len / tspi->cur_bytes_per_word * 4; return len; } @@ -318,9 +344,8 @@ static void spi_tegra_start_message(struct spi_device *spi, spi_tegra_start_transfer(spi, t); } -static void tegra_spi_rx_dma_complete(struct tegra_dma_req *req) +static void handle_spi_rx_dma_complete(struct spi_tegra_data *tspi) { - struct spi_tegra_data *tspi = req->dev; unsigned long flags; struct spi_message *m; struct spi_device *spi; @@ -380,6 +405,19 @@ static void tegra_spi_rx_dma_complete(struct tegra_dma_req *req) spin_unlock_irqrestore(&tspi->lock, flags); } +#if defined(CONFIG_TEGRA_SYSTEM_DMA) +static void tegra_spi_rx_dma_complete(struct tegra_dma_req *req) +{ + struct spi_tegra_data *tspi = req->dev; + handle_spi_rx_dma_complete(tspi); +} +#else +static void tegra_spi_rx_dma_complete(void *args) +{ + struct spi_tegra_data *tspi = args; + handle_spi_rx_dma_complete(tspi); +} +#endif static int spi_tegra_setup(struct spi_device *spi) { @@ -471,6 +509,9 @@ static int __devinit spi_tegra_probe(struct platform_device *pdev) struct spi_tegra_data *tspi; struct resource *r; int ret; +#if !defined(CONFIG_TEGRA_SYSTEM_DMA) + dma_cap_mask_t mask; +#endif master = spi_alloc_master(&pdev->dev, sizeof *tspi); if (master == NULL) { @@ -522,12 +563,24 @@ static int __devinit spi_tegra_probe(struct platform_device *pdev) INIT_LIST_HEAD(&tspi->queue); +#if defined(CONFIG_TEGRA_SYSTEM_DMA) tspi->rx_dma = tegra_dma_allocate_channel(TEGRA_DMA_MODE_ONESHOT); if (!tspi->rx_dma) { dev_err(&pdev->dev, "can not allocate rx dma channel\n"); ret = -ENODEV; goto err3; } +#else + dma_cap_zero(mask); + dma_cap_set(DMA_SLAVE, mask); + tspi->rx_dma = dma_request_channel(mask, NULL, NULL); + if (!tspi->rx_dma) { + dev_err(&pdev->dev, "can not allocate rx dma channel\n"); + ret = -ENODEV; + goto err3; + } + +#endif tspi->rx_bb = dma_alloc_coherent(&pdev->dev, sizeof(u32) * BB_LEN, &tspi->rx_bb_phys, GFP_KERNEL); @@ -537,6 +590,7 @@ static int __devinit spi_tegra_probe(struct platform_device *pdev) goto err4; } +#if defined(CONFIG_TEGRA_SYSTEM_DMA) tspi->rx_dma_req.complete = tegra_spi_rx_dma_complete; tspi->rx_dma_req.to_memory = 1; tspi->rx_dma_req.dest_addr = tspi->rx_bb_phys; @@ -546,6 +600,23 @@ static int __devinit spi_tegra_probe(struct platform_device *pdev) tspi->rx_dma_req.source_wrap = 4; tspi->rx_dma_req.req_sel = spi_tegra_req_sels[pdev->id]; tspi->rx_dma_req.dev = tspi; +#else + /* Dmaengine Dma slave config */ + tspi->sconfig.src_addr = tspi->phys + SLINK_RX_FIFO; + tspi->sconfig.dst_addr = tspi->phys + SLINK_RX_FIFO; + tspi->sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; + tspi->sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; + tspi->sconfig.slave_id = spi_tegra_req_sels[pdev->id]; + tspi->sconfig.src_maxburst = 1; + tspi->sconfig.dst_maxburst = 1; + ret = dmaengine_device_control(tspi->rx_dma, + DMA_SLAVE_CONFIG, (unsigned long) &tspi->sconfig); + if (ret < 0) { + dev_err(&pdev->dev, "can not do slave configure for dma %d\n", + ret); + goto err4; + } +#endif master->dev.of_node = pdev->dev.of_node; ret = spi_register_master(master); @@ -559,7 +630,11 @@ err5: dma_free_coherent(&pdev->dev, sizeof(u32) * BB_LEN, tspi->rx_bb, tspi->rx_bb_phys); err4: +#if defined(CONFIG_TEGRA_SYSTEM_DMA) tegra_dma_free_channel(tspi->rx_dma); +#else + dma_release_channel(tspi->rx_dma); +#endif err3: clk_put(tspi->clk); err2: @@ -581,7 +656,11 @@ static int __devexit spi_tegra_remove(struct platform_device *pdev) tspi = spi_master_get_devdata(master); spi_unregister_master(master); +#if defined(CONFIG_TEGRA_SYSTEM_DMA) tegra_dma_free_channel(tspi->rx_dma); +#else + dma_release_channel(tspi->rx_dma); +#endif dma_free_coherent(&pdev->dev, sizeof(u32) * BB_LEN, tspi->rx_bb, tspi->rx_bb_phys); -- cgit v0.10.2 From 05644147064acabb8587c4cbd690047494f7b3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Thu, 9 Feb 2012 22:21:45 +0100 Subject: spi/gpio: start with CS non-active MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The chip select line was configured as output with the initial value being active explicitly. It was later deasserted during spi_bitbang_setup() without any clock activity in between. So it makes no sense to activate the device at all and the chip select line can better start non-active. Signed-off-by: Uwe Kleine-König Acked-by: Linus Walleij Signed-off-by: Mark Brown diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 0094c645..0b56cfc 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c @@ -235,7 +235,8 @@ static int spi_gpio_setup(struct spi_device *spi) status = gpio_request(cs, dev_name(&spi->dev)); if (status) return status; - status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH); + status = gpio_direction_output(cs, + !(spi->mode & SPI_CS_HIGH)); } } if (!status) -- cgit v0.10.2 From 872675df2795389fd47b7a0ad084ba1e91665c87 Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Fri, 13 Jul 2012 10:51:28 +0800 Subject: spi/imx: remove redundant config.speed_hz setting The config.speed_hz is just setted at the two lines ahead of it, obviously we don't need to copy the code to set the config.speed_hz again. Remove it for a cleanup. Cc: Mark Brown Acked-by: Sascha Hauer Signed-off-by: Hui Wang Signed-off-by: Mark Brown diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 47877d6..c12052f 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -688,8 +688,6 @@ static int spi_imx_setupxfer(struct spi_device *spi, config.speed_hz = spi->max_speed_hz; if (!config.bpw) config.bpw = spi->bits_per_word; - if (!config.speed_hz) - config.speed_hz = spi->max_speed_hz; /* Initialize the functions for transfer */ if (config.bpw <= 8) { -- cgit v0.10.2 From 8b17e0559fe728b89b45f4d88b4b30b498862709 Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Fri, 13 Jul 2012 10:51:29 +0800 Subject: spi/imx: use gpio_is_valid to determine if a gpio is valid Use gpio_is_valid() to replace "gpio >= 0" or "gpio < 0". Cc: Mark Brown Acked-by: Sascha Hauer Signed-off-by: Hui Wang Signed-off-by: Mark Brown diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index c12052f..e834ff8 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -626,7 +626,7 @@ static void spi_imx_chipselect(struct spi_device *spi, int is_active) int active = is_active != BITBANG_CS_INACTIVE; int dev_is_lowactive = !(spi->mode & SPI_CS_HIGH); - if (gpio < 0) + if (!gpio_is_valid(gpio)) return; gpio_set_value(gpio, dev_is_lowactive ^ active); @@ -736,7 +736,7 @@ static int spi_imx_setup(struct spi_device *spi) dev_dbg(&spi->dev, "%s: mode %d, %u bpw, %d hz\n", __func__, spi->mode, spi->bits_per_word, spi->max_speed_hz); - if (gpio >= 0) + if (gpio_is_valid(gpio)) gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH ? 0 : 1); spi_imx_chipselect(spi, BITBANG_CS_INACTIVE); @@ -789,11 +789,11 @@ static int __devinit spi_imx_probe(struct platform_device *pdev) for (i = 0; i < master->num_chipselect; i++) { int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); - if (cs_gpio < 0 && mxc_platform_info) + if (!gpio_is_valid(cs_gpio) && mxc_platform_info) cs_gpio = mxc_platform_info->chipselect[i]; spi_imx->chipselect[i] = cs_gpio; - if (cs_gpio < 0) + if (!gpio_is_valid(cs_gpio)) continue; ret = gpio_request(spi_imx->chipselect[i], DRIVER_NAME); @@ -895,7 +895,7 @@ out_release_mem: release_mem_region(res->start, resource_size(res)); out_gpio_free: while (--i >= 0) { - if (spi_imx->chipselect[i] >= 0) + if (gpio_is_valid(spi_imx->chipselect[i])) gpio_free(spi_imx->chipselect[i]); } spi_master_put(master); @@ -920,7 +920,7 @@ static int __devexit spi_imx_remove(struct platform_device *pdev) iounmap(spi_imx->base); for (i = 0; i < master->num_chipselect; i++) - if (spi_imx->chipselect[i] >= 0) + if (gpio_is_valid(spi_imx->chipselect[i])) gpio_free(spi_imx->chipselect[i]); spi_master_put(master); -- cgit v0.10.2 From b316590043372c2ca0040567a480396eb4bb2f0b Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 19 Jul 2012 18:44:07 +0200 Subject: spi: Add AD-FMCOMMS1-EBZ I2C-SPI bridge driver This patch adds support for the I2C-SPI bridge which can be found on the Analog Devices AD-FMCOMMS1-EBZ board. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 0a72569..12468e5 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -384,6 +384,13 @@ config SPI_TXX9 help SPI driver for Toshiba TXx9 MIPS SoCs +config SPI_XCOMM + tristate "Analog Devices AD-FMCOMMS1-EBZ SPI-I2C-bridge driver" + depends on I2C + help + Support for the SPI-I2C bridge found on the Analog Devices + AD-FMCOMMS1-EBZ board. + config SPI_XILINX tristate "Xilinx SPI controller common module" depends on HAS_IOMEM && EXPERIMENTAL diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index 9d75d21..273f50d 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -61,5 +61,6 @@ obj-$(CONFIG_SPI_TI_SSP) += spi-ti-ssp.o obj-$(CONFIG_SPI_TLE62X0) += spi-tle62x0.o obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi-topcliff-pch.o obj-$(CONFIG_SPI_TXX9) += spi-txx9.o +obj-$(CONFIG_SPI_XCOMM) += spi-xcomm.o obj-$(CONFIG_SPI_XILINX) += spi-xilinx.o diff --git a/drivers/spi/spi-xcomm.c b/drivers/spi/spi-xcomm.c new file mode 100644 index 0000000..266a847 --- /dev/null +++ b/drivers/spi/spi-xcomm.c @@ -0,0 +1,276 @@ +/* + * Analog Devices AD-FMCOMMS1-EBZ board I2C-SPI bridge driver + * + * Copyright 2012 Analog Devices Inc. + * Author: Lars-Peter Clausen + * + * Licensed under the GPL-2 or later. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define SPI_XCOMM_SETTINGS_LEN_OFFSET 10 +#define SPI_XCOMM_SETTINGS_3WIRE BIT(6) +#define SPI_XCOMM_SETTINGS_CS_HIGH BIT(5) +#define SPI_XCOMM_SETTINGS_SAMPLE_END BIT(4) +#define SPI_XCOMM_SETTINGS_CPHA BIT(3) +#define SPI_XCOMM_SETTINGS_CPOL BIT(2) +#define SPI_XCOMM_SETTINGS_CLOCK_DIV_MASK 0x3 +#define SPI_XCOMM_SETTINGS_CLOCK_DIV_64 0x2 +#define SPI_XCOMM_SETTINGS_CLOCK_DIV_16 0x1 +#define SPI_XCOMM_SETTINGS_CLOCK_DIV_4 0x0 + +#define SPI_XCOMM_CMD_UPDATE_CONFIG 0x03 +#define SPI_XCOMM_CMD_WRITE 0x04 + +#define SPI_XCOMM_CLOCK 48000000 + +struct spi_xcomm { + struct i2c_client *i2c; + + uint16_t settings; + uint16_t chipselect; + + unsigned int current_speed; + + uint8_t buf[63]; +}; + +static int spi_xcomm_sync_config(struct spi_xcomm *spi_xcomm, unsigned int len) +{ + uint16_t settings; + uint8_t *buf = spi_xcomm->buf; + + settings = spi_xcomm->settings; + settings |= len << SPI_XCOMM_SETTINGS_LEN_OFFSET; + + buf[0] = SPI_XCOMM_CMD_UPDATE_CONFIG; + put_unaligned_be16(settings, &buf[1]); + put_unaligned_be16(spi_xcomm->chipselect, &buf[3]); + + return i2c_master_send(spi_xcomm->i2c, buf, 5); +} + +static void spi_xcomm_chipselect(struct spi_xcomm *spi_xcomm, + struct spi_device *spi, int is_active) +{ + unsigned long cs = spi->chip_select; + uint16_t chipselect = spi_xcomm->chipselect; + + if (is_active) + chipselect |= BIT(cs); + else + chipselect &= ~BIT(cs); + + spi_xcomm->chipselect = chipselect; +} + +static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm, + struct spi_device *spi, struct spi_transfer *t, unsigned int *settings) +{ + unsigned int speed; + + if ((t->bits_per_word && t->bits_per_word != 8) || t->len > 62) + return -EINVAL; + + speed = t->speed_hz ? t->speed_hz : spi->max_speed_hz; + + if (speed != spi_xcomm->current_speed) { + unsigned int divider = DIV_ROUND_UP(SPI_XCOMM_CLOCK, speed); + if (divider >= 64) + *settings |= SPI_XCOMM_SETTINGS_CLOCK_DIV_64; + else if (divider >= 16) + *settings |= SPI_XCOMM_SETTINGS_CLOCK_DIV_16; + else + *settings |= SPI_XCOMM_SETTINGS_CLOCK_DIV_4; + + spi_xcomm->current_speed = speed; + } + + if (spi->mode & SPI_CPOL) + *settings |= SPI_XCOMM_SETTINGS_CPOL; + else + *settings &= ~SPI_XCOMM_SETTINGS_CPOL; + + if (spi->mode & SPI_CPHA) + *settings &= ~SPI_XCOMM_SETTINGS_CPHA; + else + *settings |= SPI_XCOMM_SETTINGS_CPHA; + + if (spi->mode & SPI_3WIRE) + *settings |= SPI_XCOMM_SETTINGS_3WIRE; + else + *settings &= ~SPI_XCOMM_SETTINGS_3WIRE; + + return 0; +} + +static int spi_xcomm_txrx_bufs(struct spi_xcomm *spi_xcomm, + struct spi_device *spi, struct spi_transfer *t) +{ + int ret; + + if (t->tx_buf) { + spi_xcomm->buf[0] = SPI_XCOMM_CMD_WRITE; + memcpy(spi_xcomm->buf + 1, t->tx_buf, t->len); + + ret = i2c_master_send(spi_xcomm->i2c, spi_xcomm->buf, t->len + 1); + if (ret < 0) + return ret; + else if (ret != t->len + 1) + return -EIO; + } else if (t->rx_buf) { + ret = i2c_master_recv(spi_xcomm->i2c, t->rx_buf, t->len); + if (ret < 0) + return ret; + else if (ret != t->len) + return -EIO; + } + + return t->len; +} + +static int spi_xcomm_transfer_one(struct spi_master *master, + struct spi_message *msg) +{ + struct spi_xcomm *spi_xcomm = spi_master_get_devdata(master); + unsigned int settings = spi_xcomm->settings; + struct spi_device *spi = msg->spi; + unsigned cs_change = 0; + struct spi_transfer *t; + bool is_first = true; + int status = 0; + bool is_last; + + is_first = true; + + spi_xcomm_chipselect(spi_xcomm, spi, true); + + list_for_each_entry(t, &msg->transfers, transfer_list) { + + if (!t->tx_buf && !t->rx_buf && t->len) { + status = -EINVAL; + break; + } + + status = spi_xcomm_setup_transfer(spi_xcomm, spi, t, &settings); + if (status < 0) + break; + + is_last = list_is_last(&t->transfer_list, &msg->transfers); + cs_change = t->cs_change; + + if (cs_change ^ is_last) + settings |= BIT(5); + else + settings &= ~BIT(5); + + if (t->rx_buf) { + spi_xcomm->settings = settings; + status = spi_xcomm_sync_config(spi_xcomm, t->len); + if (status < 0) + break; + } else if (settings != spi_xcomm->settings || is_first) { + spi_xcomm->settings = settings; + status = spi_xcomm_sync_config(spi_xcomm, 0); + if (status < 0) + break; + } + + if (t->len) { + status = spi_xcomm_txrx_bufs(spi_xcomm, spi, t); + + if (status < 0) + break; + + if (status > 0) + msg->actual_length += status; + } + status = 0; + + if (t->delay_usecs) + udelay(t->delay_usecs); + + is_first = false; + } + + if (status != 0 || !cs_change) + spi_xcomm_chipselect(spi_xcomm, spi, false); + + msg->status = status; + spi_finalize_current_message(master); + + return status; +} + +static int spi_xcomm_setup(struct spi_device *spi) +{ + if (spi->bits_per_word != 8) + return -EINVAL; + + return 0; +} + +static int __devinit spi_xcomm_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ + struct spi_xcomm *spi_xcomm; + struct spi_master *master; + int ret; + + master = spi_alloc_master(&i2c->dev, sizeof(*spi_xcomm)); + if (!master) + return -ENOMEM; + + spi_xcomm = spi_master_get_devdata(master); + spi_xcomm->i2c = i2c; + + master->num_chipselect = 16; + master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_3WIRE; + master->flags = SPI_MASTER_HALF_DUPLEX; + master->setup = spi_xcomm_setup; + master->transfer_one_message = spi_xcomm_transfer_one; + master->dev.of_node = i2c->dev.of_node; + i2c_set_clientdata(i2c, master); + + ret = spi_register_master(master); + if (ret < 0) + spi_master_put(master); + + return ret; +} + +static int __devexit spi_xcomm_remove(struct i2c_client *i2c) +{ + struct spi_master *master = i2c_get_clientdata(i2c); + + spi_unregister_master(master); + + return 0; +} + +static const struct i2c_device_id spi_xcomm_ids[] = { + { "spi-xcomm" }, + { }, +}; + +static struct i2c_driver spi_xcomm_driver = { + .driver = { + .name = "spi-xcomm", + .owner = THIS_MODULE, + }, + .id_table = spi_xcomm_ids, + .probe = spi_xcomm_probe, + .remove = __devexit_p(spi_xcomm_remove), +}; +module_i2c_driver(spi_xcomm_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Lars-Peter Clausen "); +MODULE_DESCRIPTION("Analog Devices AD-FMCOMMS1-EBZ board I2C-SPI bridge driver"); -- cgit v0.10.2 From a3ce9a801b56e9b2118ce8d25b4f6f84f1d37dd4 Mon Sep 17 00:00:00 2001 From: Shubhrajyoti D Date: Thu, 19 Jul 2012 23:16:52 +0530 Subject: spi: omap2-mcspi: Fix the below warning The dma_map and dma_unmap should have same parameter passed otherwise we get the below warn. ks8851 spi1.0: DMA-API: device driver tries to free DMA memory it has not allocated [device address=0x000000009f22] [ 2.066925] Modules linked in: [ 2.070312] [ 2.071929] [] (unwind_backtrace+0x0/0x130) from [] (warn_slowpath_common+0x4c/0x64) [ 2.081909] [] (warn_slowpath_common+0x4c/0x64) from [] (warn_slowpath_fmt+0x30/0x40) [ 2.091949] [] (warn_slowpath_fmt+0x30/0x40) from [] (check_unmap+0x6d0/0x7b0) [ 2.101348] [] (check_unmap+0x6d0/0x7b0) from [] (debug_dma_unmap_page+0x64/0x70) [ 2.111053] [] (debug_dma_unmap_page+0x64/0x70) from [] (omap2_mcspi_txrx_dma+0x2d8/0x4fc) [ 2.121582] [] (omap2_mcspi_txrx_dma+0x2d8/0x4fc) from [] (omap2_mcspi_work.clone.4+0xf0/0x290) [ 2.132537] [] (omap2_mcspi_work.clone.4+0xf0/0x290) from [] (omap2_mcspi_transfer_one_message+0x288/0x438) [ 2.144592] [] (omap2_mcspi_transfer_one_message+0x288/0x438) from [] (spi_pump_messages+0x100/0x160) [ 2.156127] [] (spi_pump_messages+0x100/0x160) from [] (kthread_worker_fn+0xac/0x180) [ 2.166168] [] (kthread_worker_fn+0xac/0x180) from [] (kthread+0x90/0x9c) [ 2.175140] [] (kthread+0x90/0x9c) from [] (kernel_thread_exit+0x0/0x8) [ 2.183898] ---[ end trace d1830ce6e44292f2 ]--- Fix the warn by changing the unmap parameter. Reported-by: Russell King - ARM Linux Signed-off-by: Shubhrajyoti D Signed-off-by: Mark Brown diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 0c73dd4..37ccdb7 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -388,7 +388,8 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) if (tx != NULL) { wait_for_completion(&mcspi_dma->dma_tx_completion); - dma_unmap_single(&spi->dev, xfer->tx_dma, count, DMA_TO_DEVICE); + dma_unmap_single(mcspi->dev, xfer->tx_dma, count, + DMA_TO_DEVICE); /* for TX_ONLY mode, be sure all words have shifted out */ if (rx == NULL) { @@ -403,7 +404,8 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) if (rx != NULL) { wait_for_completion(&mcspi_dma->dma_rx_completion); - dma_unmap_single(&spi->dev, xfer->rx_dma, count, DMA_FROM_DEVICE); + dma_unmap_single(mcspi->dev, xfer->rx_dma, count, + DMA_FROM_DEVICE); omap2_mcspi_set_enable(spi, 0); if (l & OMAP2_MCSPI_CHCONF_TURBO) { -- cgit v0.10.2 From 24ab32751183d4063d195c943af3cd6f1cad6794 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Fri, 20 Jul 2012 16:01:43 +0530 Subject: spi/omap2: mark omap2_mcspi_master_setup as __devinit This warning recently appeared with omap2plus_defconfig: WARNING: drivers/spi/built-in.o(.devinit.text+0x3c4): Section mismatch in reference from the function omap2_mcspi_probe() to the function .init.text:omap2_mcspi_master_setup() The function __devinit omap2_mcspi_probe() references a function __init omap2_mcspi_master_setup(). If omap2_mcspi_master_setup is only used by omap2_mcspi_probe then annotate omap2_mcspi_master_setup with a matching annotation. The fix is obviously to mark the omap2_mcspi_master_setup function as __devinit, rather than __init. Signed-off-by: Arnd Bergmann Signed-off-by: Shubhrajyoti D Signed-off-by: Mark Brown diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 37ccdb7..7d46b15 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -1034,7 +1034,7 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master, return 0; } -static int __init omap2_mcspi_master_setup(struct omap2_mcspi *mcspi) +static int __devinit omap2_mcspi_master_setup(struct omap2_mcspi *mcspi) { struct spi_master *master = mcspi->master; struct omap2_mcspi_regs *ctx = &mcspi->ctx; -- cgit v0.10.2 From f814f9ac5a819542fdf6db97305db9da603c1eeb Mon Sep 17 00:00:00 2001 From: Andrew Lunn Date: Mon, 23 Jul 2012 12:08:09 +0200 Subject: spi/orion: add device tree binding Signed-off-by: Michael Walle Signed-off-by: Andrew Lunn Acked-by: Jason Cooper Acked-by: Sebastian Hesselbarth Signed-off-by: Mark Brown diff --git a/Documentation/devicetree/bindings/spi/spi-orion.txt b/Documentation/devicetree/bindings/spi/spi-orion.txt new file mode 100644 index 0000000..a3ff50f --- /dev/null +++ b/Documentation/devicetree/bindings/spi/spi-orion.txt @@ -0,0 +1,19 @@ +Marvell Orion SPI device + +Required properties: +- compatible : should be "marvell,orion-spi". +- reg : offset and length of the register set for the device +- cell-index : Which of multiple SPI controllers is this. +Optional properties: +- interrupts : Is currently not used. + +Example: + spi@10600 { + compatible = "marvell,orion-spi"; + #address-cells = <1>; + #size-cells = <0>; + cell-index = <0>; + reg = <0x10600 0x28>; + interrupts = <23>; + status = "disabled"; + }; diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index dfd04e9..74312a8 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -453,6 +454,8 @@ static int __init orion_spi_probe(struct platform_device *pdev) struct orion_spi_info *spi_info; unsigned long tclk_hz; int status = 0; + const u32 *iprop; + int size; spi_info = pdev->dev.platform_data; @@ -464,6 +467,12 @@ static int __init orion_spi_probe(struct platform_device *pdev) if (pdev->id != -1) master->bus_num = pdev->id; + if (pdev->dev.of_node) { + iprop = of_get_property(pdev->dev.of_node, "cell-index", + &size); + if (iprop && size == sizeof(*iprop)) + master->bus_num = *iprop; + } /* we support only mode 0, and no options */ master->mode_bits = 0; @@ -511,6 +520,7 @@ static int __init orion_spi_probe(struct platform_device *pdev) if (orion_spi_reset(spi) < 0) goto out_rel_mem; + master->dev.of_node = pdev->dev.of_node; status = spi_register_master(master); if (status < 0) goto out_rel_mem; @@ -552,10 +562,17 @@ static int __exit orion_spi_remove(struct platform_device *pdev) MODULE_ALIAS("platform:" DRIVER_NAME); +static const struct of_device_id orion_spi_of_match_table[] __devinitdata = { + { .compatible = "marvell,orion-spi", }, + {} +}; +MODULE_DEVICE_TABLE(of, orion_spi_of_match_table); + static struct platform_driver orion_spi_driver = { .driver = { .name = DRIVER_NAME, .owner = THIS_MODULE, + .of_match_table = of_match_ptr(orion_spi_of_match_table), }, .remove = __exit_p(orion_spi_remove), }; -- cgit v0.10.2 From d76ea24ac4c92e7e0700e047fcbf716c4de2b107 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Mon, 23 Jul 2012 14:44:36 +0200 Subject: spi/bcm63xx: fix clock configuration selection We are currently using an inferior or equal operator for comparing the transfer frequency with the clock frequency table. Because of this, we always end up selecting 20Mhz as a frequency, due to the inequality transfer hz <= 20 Mhz being always true. Fix this by reversing the inequality, which is how the comparison should be done. Signed-off-by: Florian Fainelli Signed-off-by: Mark Brown diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c index 7491971..6e25ef1 100644 --- a/drivers/spi/spi-bcm63xx.c +++ b/drivers/spi/spi-bcm63xx.c @@ -129,7 +129,7 @@ static void bcm63xx_spi_setup_transfer(struct spi_device *spi, /* Find the closest clock configuration */ for (i = 0; i < SPI_CLK_MASK; i++) { - if (hz <= bcm63xx_spi_freq_table[i][0]) { + if (hz >= bcm63xx_spi_freq_table[i][0]) { clk_cfg = bcm63xx_spi_freq_table[i][1]; break; } -- cgit v0.10.2 From 8ceffa7c4a4c378d8e371fe2f444656e75390b34 Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Mon, 23 Jul 2012 13:16:54 +0200 Subject: spi/orion: remove uneeded spi_info This was formerly used to store the tclk value. This is now discovered using the clk API, rather than pass it as platform data. Signed-off-by: Michael Walle Acked-by: Jason Cooper Signed-off-by: Andrew Lunn Acked-by: Sebastian Hesselbarth Signed-off-by: Mark Brown diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index 74312a8..9b0cadd 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -46,7 +46,6 @@ struct orion_spi { void __iomem *base; unsigned int max_speed; unsigned int min_speed; - struct orion_spi_info *spi_info; struct clk *clk; }; @@ -451,14 +450,11 @@ static int __init orion_spi_probe(struct platform_device *pdev) struct spi_master *master; struct orion_spi *spi; struct resource *r; - struct orion_spi_info *spi_info; unsigned long tclk_hz; int status = 0; const u32 *iprop; int size; - spi_info = pdev->dev.platform_data; - master = spi_alloc_master(&pdev->dev, sizeof *spi); if (master == NULL) { dev_dbg(&pdev->dev, "master allocation failed\n"); @@ -485,7 +481,6 @@ static int __init orion_spi_probe(struct platform_device *pdev) spi = spi_master_get_devdata(master); spi->master = master; - spi->spi_info = spi_info; spi->clk = clk_get(&pdev->dev, NULL); if (IS_ERR(spi->clk)) { -- cgit v0.10.2