i.MX: vf610: Add support for ZII VF610 Dev Family
Subsystems (5)
PATCH 1/1 spi: i.MX: Add driver for DSPI
In reply to Andrey SmirnovAdd driver for DSPI - SPI IP core found on various Freescale/NXP products (including Vybrid/VF610).
--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/dspi_spi.c | 413 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 422 insertions(+) create mode 100644 drivers/spi/dspi_spi.c
drivers/spi/Kconfig +8 -0
@@ -54,6 +54,14 @@ config DRIVER_SPI_OMAP3 bool "OMAP3 McSPI Master driver" depends on ARCH_OMAP3 || ARCH_AM33XX +config DRIVER_SPI_DSPI + tristate "Freescale DSPI SPI Master driver" + depends on ARCH_VF610 + default y + help + This enables support for the Freescale DSPI controller in master + mode. VF610 platform uses the controller. + endif endmenu
drivers/spi/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_DRIVER_SPI_MXS) += mxs_spi.o obj-$(CONFIG_DRIVER_SPI_ALTERA) += altera_spi.o obj-$(CONFIG_DRIVER_SPI_ATMEL) += atmel_spi.o obj-$(CONFIG_DRIVER_SPI_OMAP3) += omap3_spi.o +obj-$(CONFIG_DRIVER_SPI_DSPI) += dspi_spi.o
drivers/spi/dspi_spi.c new file +413 -0
413 lines not on this page · raw message
Signature · 7 lines
2.9.3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/1 i.MX: vf610: Add support for ZII VF610 Dev Family
Add support for ZII VF610 Dev based designs such as:
- VF610 Dev, revision B
- VF610 Dev, revision C
- CFU1, revision A
- SPU3, revision A
- SCU4 AIB, revision C
---
Sascha, this patch is rebased on 'next' instead of 'master' so that you won't have to resolve conflicts with RDU2 patches in 'next'. Let me know if you'd rather have it rebased on 'master'.
arch/arm/boards/Makefile | 1 + arch/arm/boards/zii-vf610-dev/Makefile | 3 + arch/arm/boards/zii-vf610-dev/board.c | 145 +++++++ .../zii-vf610-dev/defaultenv-zii-vf610-dev/boot/sd | 4 + .../defaultenv-zii-vf610-dev/init/automount-sd | 13 + .../defaultenv-zii-vf610-dev/init/choose-dtb | 4 + .../flash-header-zii-vf610-dev.imxcfg | 243 +++++++++++ arch/arm/boards/zii-vf610-dev/lowlevel.c | 132 ++++++ arch/arm/configs/zii_vf610_dev_defconfig | 164 ++++++++ arch/arm/dts/Makefile | 7 + arch/arm/dts/vf610-zii-cfu1-rev-a.dts | 208 ++++++++++ arch/arm/dts/vf610-zii-dev-rev-b.dts | 431 +++++++++++++++++++ arch/arm/dts/vf610-zii-dev-rev-c.dts | 445 ++++++++++++++++++++ arch/arm/dts/vf610-zii-dev.dtsi | 436 ++++++++++++++++++++ arch/arm/dts/vf610-zii-scu4-aib-rev-c.dts | 457 +++++++++++++++++++++ arch/arm/dts/vf610-zii-spu3-rev-a.dts | 140 +++++++ arch/arm/mach-imx/Kconfig | 5 + images/Makefile.imx | 5 + 18 files changed, 2843 insertions(+) create mode 100644 arch/arm/boards/zii-vf610-dev/Makefile create mode 100644 arch/arm/boards/zii-vf610-dev/board.c create mode 100644 arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/boot/sd create mode 100644 arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/init/automount-sd create mode 100644 arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/init/choose-dtb create mode 100644 arch/arm/boards/zii-vf610-dev/flash-header-zii-vf610-dev.imxcfg create mode 100644 arch/arm/boards/zii-vf610-dev/lowlevel.c create mode 100644 arch/arm/configs/zii_vf610_dev_defconfig create mode 100644 arch/arm/dts/vf610-zii-cfu1-rev-a.dts create mode 100644 arch/arm/dts/vf610-zii-dev-rev-b.dts create mode 100644 arch/arm/dts/vf610-zii-dev-rev-c.dts create mode 100644 arch/arm/dts/vf610-zii-dev.dtsi create mode 100644 arch/arm/dts/vf610-zii-scu4-aib-rev-c.dts create mode 100644 arch/arm/dts/vf610-zii-spu3-rev-a.dts
arch/arm/boards/Makefile +1 -0
@@ -142,3 +142,4 @@ obj-$(CONFIG_MACH_VSCOM_BALTOS) += vscom-baltos/ obj-$(CONFIG_MACH_QEMU_VIRT64) += qemu-virt64/ obj-$(CONFIG_MACH_VF610_TWR) += freescale-vf610-twr/ obj-$(CONFIG_MACH_ZII_RDU2) += zii-imx6q-rdu2/ +obj-$(CONFIG_MACH_ZII_VF610_DEV) += zii-vf610-dev/
arch/arm/boards/zii-vf610-dev/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-y += board.o +lwl-y += lowlevel.o +bbenv-y += defaultenv-zii-vf610-dev
arch/arm/boards/zii-vf610-dev/board.c new file +145 -0
145 lines not on this page · raw message
arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/boot/sd new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh + +global.bootm.image=/mnt/sd/zImage +global.bootm.oftree=/mnt/sd/${global.bootm.oftree}
arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/init/automount-sd new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/sh + +if [ x${global.hostname} = xdev-rev-b -o x${global.hostname} = xdev-rev-c ]; +then + global sd=0 +else + global sd=1 +fi + +mkdir -p /mnt/sd +automount /mnt/sd 'mci${global.sd}.probe=1 && mount /dev/disk${global.sd}.0 /mnt/sd' + +exit 0
arch/arm/boards/zii-vf610-dev/defaultenv-zii-vf610-dev/init/choose-dtb new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh + +global.bootm.oftree=vf610-zii-${global.hostname}.dtb +
arch/arm/boards/zii-vf610-dev/flash-header-zii-vf610-dev.imxcfg new file +243 -0
243 lines not on this page · raw message
arch/arm/boards/zii-vf610-dev/lowlevel.c new file +132 -0
132 lines not on this page · raw message
arch/arm/configs/zii_vf610_dev_defconfig new file +164 -0
164 lines not on this page · raw message
arch/arm/dts/Makefile +7 -0
@@ -81,5 +81,12 @@ pbl-dtb-$(CONFIG_MACH_VARISCITE_MX6) += imx6q-var-custom.dtb.o pbl-dtb-$(CONFIG_MACH_VSCOM_BALTOS) += am335x-baltos-minimal.dtb.o pbl-dtb-$(CONFIG_MACH_VF610_TWR) += vf610-twr.dtb.o pbl-dtb-$(CONFIG_MACH_ZII_RDU2) += imx6q-zii-rdu2.dtb.o imx6qp-zii-rdu2.dtb.o +pbl-dtb-$(CONFIG_MACH_ZII_VF610_DEV) += \ + vf610-zii-dev-rev-b.dtb.o \ + vf610-zii-dev-rev-c.dtb.o \ + vf610-zii-cfu1-rev-a.dtb.o \ + vf610-zii-spu3-rev-a.dtb.o \ + vf610-zii-scu4-aib-rev-c.dtb.o + clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.lzo
arch/arm/dts/vf610-zii-cfu1-rev-a.dts new file +208 -0
208 lines not on this page · raw message
arch/arm/dts/vf610-zii-dev-rev-b.dts new file +431 -0
431 lines not on this page · raw message
arch/arm/dts/vf610-zii-dev-rev-c.dts new file +445 -0
445 lines not on this page · raw message
arch/arm/dts/vf610-zii-dev.dtsi new file +436 -0
436 lines not on this page · raw message
arch/arm/dts/vf610-zii-scu4-aib-rev-c.dts new file +457 -0
457 lines not on this page · raw message
arch/arm/dts/vf610-zii-spu3-rev-a.dts new file +140 -0
140 lines not on this page · raw message
arch/arm/mach-imx/Kconfig +5 -0
@@ -355,6 +355,11 @@ config MACH_ZII_RDU2 bool "ZII i.MX6Q(+) RDU2" select ARCH_IMX6 +config MACH_ZII_VF610_DEV + bool "Zodiac VF610 Dev Family" + select ARCH_VF610 + select CLKDEV_LOOKUP + endif # ----------------------------------------------------------
images/Makefile.imx +5 -0
@@ -423,3 +423,8 @@ pblx-$(CONFIG_MACH_ZII_RDU2) += start_imx6qp_zii_rdu2 CFG_start_imx6qp_zii_rdu2.pblx.imximg = $(board)/zii-imx6q-rdu2/flash-header-imx6qp-rdu2.imxcfg FILE_barebox-zii-imx6qp-rdu2.img = start_imx6qp_zii_rdu2.pblx.imximg image-$(CONFIG_MACH_ZII_RDU2) += barebox-zii-imx6qp-rdu2.img + +pblx-$(CONFIG_MACH_ZII_VF610_DEV) += start_zii_vf610_dev +CFG_start_zii_vf610_dev.pblx.imximg = $(board)/zii-vf610-dev/flash-header-zii-vf610-dev.imxcfg +FILE_barebox-zii-vf610-dev.img = start_zii_vf610_dev.pblx.imximg +image-$(CONFIG_MACH_ZII_VF610_DEV) += barebox-zii-vf610-dev.img
Signature · 7 lines
2.9.3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerHi Andrey,
Quoted 8 lines · Andrey Smirnov
Add support for ZII VF610 Dev based designs such as:
- VF610 Dev, revision B
- VF610 Dev, revision C
- CFU1, revision A
- SPU3, revision A
- SCU4 AIB, revision C
Quoted 6 lines
Signed-off-by Andrey Smirnov <[email protected]>---
Sascha, this patch is rebased on 'next' instead of 'master' so that you won't have to resolve conflicts with RDU2 patches in 'next'. Let me know if you'd rather have it rebased on 'master'.
It's fine to base on next in this case.
Quoted 13 lines
arch/arm/boards/zii-vf610-dev/board.c new file +13
-0+struct named_signal { +unsigned int gpio; +const char *name; +int value; +}; + +static int expose_signals (const struct named_signal *signals, +size_t signal_num) +{ +int ret, i; + +for (i =0 ; i < signal_num; i++) { +const struct named_signal *signal = &signals[i];
arch/arm/boards/zii-vf610-dev/board.c line 44
Quoted 10 lines
arch/arm/boards/zii-vf610-dev/board.c new file +10
-0+ +if (signal->value <0 ) + ret =gpio_direction_input (signal->gpio); +else + ret =gpio_direction_output (signal->gpio, signal->value); + +if (ret) { +pr_err ("Failed to configure \"%s\"\n" , signal->name); +return ret; + }
This looks like gpio_request_array(). Could you use this instead?
Quoted 13 lines
index 0000000..4465632
arch/arm/boards/zii-vf610-dev/lowlevel.c new file +9
-0@@ -0,0 +1,132 @@ +#include <common.h> +#include <linux/sizes.h> +#include <mach/generic.h> +#include <asm/barebox-arm-head.h> +#include <asm/barebox-arm.h> +#include <mach/vf610-regs.h> +#include <mach/clock-vf610.h> +#include <mach/iomux-vf610.h> +#include <debug_ll.h>
arch/arm/boards/zii-vf610-dev/lowlevel.c line 19
Quoted 10 lines
arch/arm/boards/zii-vf610-dev/lowlevel.c new file +10
-0+ +#if defined(CONFIG_DEBUG_LL ) +# if !defined(CONFIG_DEBUG_VF610_UART ) +# warning "CONFIG_DEBUG_LL is enabled but CONFIG_DEBUG_VF610_UART is not" +# else +# if CONFIG_DEBUG_IMX_UART_PORT !=1 +# warning "CONFIG_DEBUG_LL output is not drirected to port 1" +# endif +# endif +#endif
Just because this board is enabled doesn't mean the user is actually currently interested in this board. He might want to enable CONFIG_DEBUG_LL for another board, still he is warned about an invalid config here. This is not good.
You could drop the DEBUG_LL support and instead go to PBL console support. See arch/arm/boards/freescale-mx6-sabrelite/lowlevel.c for a good example. Basically it means you call this right after entry:
arm_early_mmu_cache_invalidate();
relocate_to_current_adr();
setup_c();
barrier();From here on you have a valid C environment (And thus don't need to work around switch/case with wrong LUTs) and can also call:
pbl_set_putc(xxx_uart_putc, uart);
after that you can use printf like functions to print messages.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH] spi: i.MX: Add driver for DSPI
In reply to Andrey SmirnovQuoted 16 lines · Andrey Smirnov
Add driver for DSPI - SPI IP core found on various Freescale/NXP products (including Vybrid/VF610).
Signed-off-by Andrey Smirnov <[email protected]>--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/dspi_spi.c | 413 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 422 insertions(+) create mode 100644 drivers/spi/dspi_spi.cdrivers/spi/Kconfig +0
-0
drivers/spi/Kconfig config DRIVER_SPI_OMAP3 · line 60
Quoted 7 lines
drivers/spi/Kconfig +4
-0@@ -54,6 +54,14 @@ config DRIVER_SPI_OMAP3 bool "OMAP3 McSPI Master driver" depends on ARCH_OMAP3 || ARCH_AM33XX +config DRIVER_SPI_DSPI + tristate "Freescale DSPI SPI Master driver" + depends on ARCH_VF610 + default y
Please no default y for optional features.
Quoted 31 lines
drivers/spi/Kconfig +27
-0+ help + This enables support for the Freescale DSPI controller in master + mode. VF610 platform uses the controller. + endif endmenu +static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, + unsigned long clkrate) +{ + /* Valid baud rate pre-scaler values */ + int pbr_tbl[4] = {2, 3, 5, 7}; + int brs[16] = { 2, 4, 6, 8, + 16, 32, 64, 128, + 256, 512, 1024, 2048, + 4096, 8192, 16384, 32768 }; + int scale_needed, scale, minscale = INT_MAX; + int i, j; + + scale_needed = clkrate / speed_hz; + if (clkrate % speed_hz) + scale_needed++; + + for (i = 0; i < ARRAY_SIZE(brs); i++) + for (j = 0; j < ARRAY_SIZE(pbr_tbl); j++) { + scale = brs[i] * pbr_tbl[j]; + if (scale >= scale_needed) { + if (scale < minscale) { + minscale = scale; + *br = i;
drivers/spi/Kconfig config DRIVER_SPI_OMAP3
Quoted 10 lines
drivers/spi/Kconfig +10
-0+ *pbr = j; + } + break; + } + } + + if (minscale == INT_MAX) { + pr_warn("Can not find valid baud rate,speed_hz is %d," + "clkrate is %ld, we use the max prescaler value.\n", + speed_hz, clkrate);
Use dev_* for drivers please.
Quoted 215 lines
drivers/spi/Kconfig +215
-0+ *pbr = ARRAY_SIZE(pbr_tbl) - 1; + *br = ARRAY_SIZE(brs) - 1; + } +} + +static void ns_delay_scale(char *psc, char *sc, int delay_ns, + unsigned long clkrate) +{ + int pscale_tbl[4] = {1, 3, 5, 7}; + int scale_needed, scale, minscale = INT_MAX; + int i, j; + u32 remainder; + + scale_needed = div_u64_rem((u64)delay_ns * clkrate, NSEC_PER_SEC, + &remainder); + if (remainder) + scale_needed++; + + for (i = 0; i < ARRAY_SIZE(pscale_tbl); i++) + for (j = 0; j <= SPI_CTAR_SCALE_BITS; j++) { + scale = pscale_tbl[i] * (2 << j); + if (scale >= scale_needed) { + if (scale < minscale) { + minscale = scale; + *psc = i; + *sc = j; + } + break; + } + } + + if (minscale == INT_MAX) { + pr_warn("Cannot find correct scale values for %dns " + "delay at clkrate %ld, using max prescaler value", + delay_ns, clkrate); + *psc = ARRAY_SIZE(pscale_tbl) - 1; + *sc = SPI_CTAR_SCALE_BITS; + } +} + +static u32 dspi_xchg_single(struct fsl_dspi *dspi, u32 in) +{ + const uint32_t sr_ready = (SPI_SR_EOQF | SPI_SR_RFDF); + + writel(in, dspi->base + SPI_PUSHR); + + while ((readl(dspi->base + SPI_SR) & sr_ready) != sr_ready) + ; + + writel(sr_ready, dspi->base + SPI_SR); + + return readl(dspi->base + SPI_POPR); +} + +static const void *dspi_load_and_advance(const void *buffer, + size_t word_size, uint32_t *word) +{ + if (!buffer) { + *word = 0; + return NULL; + } + + switch (word_size) { + case 2: + *word = *(const uint16_t *)buffer; + break; + case 1: + *word = *(const uint8_t *)buffer; + break; + } + + return buffer + word_size; +} + +static void *dspi_store_and_advance(void *buffer, + size_t word_size, uint32_t word) +{ + if (!buffer) + return NULL; + + switch (word_size) { + case 2: + *(uint16_t *)buffer = word; + break; + case 1: + *(uint8_t *)buffer = word; + break; + } + + return buffer + word_size; +} + + +static void dspi_do_transfer(struct spi_device *spi, + struct spi_transfer *transfer, + bool last) +{ + size_t i; + void *rx; + const void *tx; + unsigned int flags; + struct fsl_dspi *dspi = to_dspi(spi->master); + const size_t word_size = spi->bits_per_word <= 8 ? 1 : 2; + const size_t count = transfer->len / word_size; + + flags = SPI_PUSHR_PCS(spi->chip_select) + | SPI_PUSHR_CTAS(spi->chip_select) + | SPI_PUSHR_EOQ + | SPI_PUSHR_CONT; + + tx = transfer->tx_buf; + rx = transfer->rx_buf; + + for (i = 0; i < count; i++) { + uint32_t in, out; + + if (i == count - 1 && + (last || transfer->cs_change)) + flags &= ~SPI_PUSHR_CONT; + + tx = dspi_load_and_advance(tx, word_size, &out); + in = dspi_xchg_single(dspi, flags | out); + rx = dspi_store_and_advance(rx, word_size, in); + } +} + +static int dspi_transfer(struct spi_device *spi, + struct spi_message *message) +{ + struct spi_transfer *transfer; + + message->actual_length = 0; + + list_for_each_entry(transfer, &message->transfers, transfer_list) { + + if (spi->bits_per_word > 8 && + transfer->len % 2) + dev_err(spi->master->dev, + "Transfer doesn't contain exact number of SPI " + "words. Last partial word will be truncated"); + + dspi_do_transfer(spi, transfer, + list_is_last(&transfer->transfer_list, + &message->transfers)); + message->actual_length += transfer->len; + } + + return 0; +} + +static int dspi_setup(struct spi_device *spi) +{ + struct fsl_dspi *dspi = to_dspi(spi->master); + unsigned char br = 0, pbr = 0, pcssck = 0, cssck = 0; + unsigned char pasc = 0, asc = 0, fmsz = 0; + unsigned long clkrate; + + if (4 <= spi->bits_per_word && spi->bits_per_word <= 16) + fmsz = spi->bits_per_word - 1; + else + return -ENODEV; + + clkrate = clk_get_rate(dspi->clk); + hz_to_spi_baud(&pbr, &br, spi->max_speed_hz, clkrate); + + /* Set PCS to SCK delay scale values */ + ns_delay_scale(&pcssck, &cssck, dspi->cs_sck_delay, clkrate); + + /* Set After SCK delay scale values */ + ns_delay_scale(&pasc, &asc, dspi->sck_cs_delay, clkrate); + + writel(SPI_CTAR_FMSZ(fmsz) + | SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0) + | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0) + | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0) + | SPI_CTAR_PCSSCK(pcssck) + | SPI_CTAR_CSSCK(cssck) + | SPI_CTAR_PASC(pasc) + | SPI_CTAR_ASC(asc) + | SPI_CTAR_PBR(pbr) + | SPI_CTAR_BR(br), + dspi->base + SPI_CTAR(spi->chip_select)); + + return 0; +} + +static int dspi_probe(struct device_d *dev) +{ + struct resource *io; + struct fsl_dspi *dspi; + struct spi_master *master; + struct device_node *np = dev->device_node; + + int ret = 0; + uint32_t bus_num = 0; + uint32_t cs_num; + + dspi = xzalloc(sizeof(*dspi)); + + dspi->devtype_data = of_device_get_match_data(dev); + if (!dspi->devtype_data) { + dev_err(dev, "can't get devtype_data\n"); + ret = -EFAULT; + goto free_memory; + } + + master = &dspi->master; + master->dev = dev; + master->bus_num = dev->id; + master->setup = dspi_setup; + master->transfer = dspi_transfer; + + ret = of_property_read_u32(np, "spi-num-chipselects", &cs_num); + if (ret < 0) { + dev_err(dev, "can't get spi-num-chipselects\n");
drivers/spi/Kconfig
Quoted 10 lines
drivers/spi/Kconfig +10
-0+ goto free_memory; + } + master->num_chipselect = cs_num; + + ret = of_property_read_u32(np, "bus-num", &bus_num); + if (ret < 0) { + dev_err(dev, "can't get bus-num\n"); + goto free_memory; + } + master->bus_num = bus_num;
I don't think the presence of a bus-num property should be enforced. It seems nobody has reviewed the binding since normally such a property shouldn't even exist. You can honor it if it's present, but shouldn't enforce it.
drivers/spi/Kconfig
Quoted 9 lines
drivers/spi/Kconfig +9
-0+ + of_property_read_u32(dev->device_node, "fsl,spi-cs-sck-delay", + &dspi->cs_sck_delay); + of_property_read_u32(dev->device_node, "fsl,spi-sck-cs-delay", + &dspi->sck_cs_delay); + + io = dev_request_mem_resource(dev, 0); + if (IS_ERR(io)) + return PTR_ERR(io);
I don't care much about cleaning up properly in the probe error pathes in barebox, but now that you started with "goto free_memory" in the driver, you can use it here aswell ;)
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH] spi: i.MX: Add driver for DSPI
Quoted 20 lines · Sascha Hauer
Quoted 19 lines · Andrey Smirnov
Add driver for DSPI - SPI IP core found on various Freescale/NXP products (including Vybrid/VF610).
Signed-off-by Andrey Smirnov <[email protected]>--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/dspi_spi.c | 413 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 422 insertions(+) create mode 100644 drivers/spi/dspi_spi.cdrivers/spi/Kconfig +0
-0@@ -54,6 +54,14 @@ config DRIVER_SPI_OMAP3 bool "OMAP3 McSPI Master driver" depends on ARCH_OMAP3 || ARCH_AM33XX
Quoted 6 lines
drivers/spi/Kconfig config DRIVER_SPI_OMAP3 · line 60
Quoted 4 lines
drivers/spi/Kconfig +4
-0+config DRIVER_SPI_DSPI + tristate "Freescale DSPI SPI Master driver" + depends on ARCH_VF610 + default yPlease no default y for optional features.
OK, will fix in v2.
Quoted 36 lines
Quoted 36 lines
drivers/spi/Kconfig +31
-0+ help + This enables support for the Freescale DSPI controller in master + mode. VF610 platform uses the controller. + endif endmenu +static void hz_to_spi_baud(char *pbr, char *br, int speed_hz, + unsigned long clkrate) +{ + /* Valid baud rate pre-scaler values */ + int pbr_tbl[4] = {2, 3, 5, 7}; + int brs[16] = { 2, 4, 6, 8, + 16, 32, 64, 128, + 256, 512, 1024, 2048, + 4096, 8192, 16384, 32768 }; + int scale_needed, scale, minscale = INT_MAX; + int i, j; + + scale_needed = clkrate / speed_hz; + if (clkrate % speed_hz) + scale_needed++; + + for (i = 0; i < ARRAY_SIZE(brs); i++) + for (j = 0; j < ARRAY_SIZE(pbr_tbl); j++) { + scale = brs[i] * pbr_tbl[j]; + if (scale >= scale_needed) { + if (scale < minscale) { + minscale = scale; + *br = i; + *pbr = j; + } + break; + }
Quoted 8 lines
drivers/spi/Kconfig
Quoted 6 lines
drivers/spi/Kconfig +6
-0+ } + + if (minscale == INT_MAX) { + pr_warn("Can not find valid baud rate,speed_hz is %d," + "clkrate is %ld, we use the max prescaler value.\n", + speed_hz, clkrate);Use dev_* for drivers please.
WIll do in v2.
Quoted 223 lines
Quoted 223 lines
drivers/spi/Kconfig +222
-0+ *pbr = ARRAY_SIZE(pbr_tbl) - 1; + *br = ARRAY_SIZE(brs) - 1; + } +} + +static void ns_delay_scale(char *psc, char *sc, int delay_ns, + unsigned long clkrate) +{ + int pscale_tbl[4] = {1, 3, 5, 7}; + int scale_needed, scale, minscale = INT_MAX; + int i, j; + u32 remainder; + + scale_needed = div_u64_rem((u64)delay_ns * clkrate, NSEC_PER_SEC, + &remainder); + if (remainder) + scale_needed++; + + for (i = 0; i < ARRAY_SIZE(pscale_tbl); i++) + for (j = 0; j <= SPI_CTAR_SCALE_BITS; j++) { + scale = pscale_tbl[i] * (2 << j); + if (scale >= scale_needed) { + if (scale < minscale) { + minscale = scale; + *psc = i; + *sc = j; + } + break; + } + } + + if (minscale == INT_MAX) { + pr_warn("Cannot find correct scale values for %dns " + "delay at clkrate %ld, using max prescaler value", + delay_ns, clkrate); + *psc = ARRAY_SIZE(pscale_tbl) - 1; + *sc = SPI_CTAR_SCALE_BITS; + } +} + +static u32 dspi_xchg_single(struct fsl_dspi *dspi, u32 in) +{ + const uint32_t sr_ready = (SPI_SR_EOQF | SPI_SR_RFDF); + + writel(in, dspi->base + SPI_PUSHR); + + while ((readl(dspi->base + SPI_SR) & sr_ready) != sr_ready) + ; + + writel(sr_ready, dspi->base + SPI_SR); + + return readl(dspi->base + SPI_POPR); +} + +static const void *dspi_load_and_advance(const void *buffer, + size_t word_size, uint32_t *word) +{ + if (!buffer) { + *word = 0; + return NULL; + } + + switch (word_size) { + case 2: + *word = *(const uint16_t *)buffer; + break; + case 1: + *word = *(const uint8_t *)buffer; + break; + } + + return buffer + word_size; +} + +static void *dspi_store_and_advance(void *buffer, + size_t word_size, uint32_t word) +{ + if (!buffer) + return NULL; + + switch (word_size) { + case 2: + *(uint16_t *)buffer = word; + break; + case 1: + *(uint8_t *)buffer = word; + break; + } + + return buffer + word_size; +} + + +static void dspi_do_transfer(struct spi_device *spi, + struct spi_transfer *transfer, + bool last) +{ + size_t i; + void *rx; + const void *tx; + unsigned int flags; + struct fsl_dspi *dspi = to_dspi(spi->master); + const size_t word_size = spi->bits_per_word <= 8 ? 1 : 2; + const size_t count = transfer->len / word_size; + + flags = SPI_PUSHR_PCS(spi->chip_select) + | SPI_PUSHR_CTAS(spi->chip_select) + | SPI_PUSHR_EOQ + | SPI_PUSHR_CONT; + + tx = transfer->tx_buf; + rx = transfer->rx_buf; + + for (i = 0; i < count; i++) { + uint32_t in, out; + + if (i == count - 1 && + (last || transfer->cs_change)) + flags &= ~SPI_PUSHR_CONT; + + tx = dspi_load_and_advance(tx, word_size, &out); + in = dspi_xchg_single(dspi, flags | out); + rx = dspi_store_and_advance(rx, word_size, in); + } +} + +static int dspi_transfer(struct spi_device *spi, + struct spi_message *message) +{ + struct spi_transfer *transfer; + + message->actual_length = 0; + + list_for_each_entry(transfer, &message->transfers, transfer_list) { + + if (spi->bits_per_word > 8 && + transfer->len % 2) + dev_err(spi->master->dev, + "Transfer doesn't contain exact number of SPI " + "words. Last partial word will be truncated"); + + dspi_do_transfer(spi, transfer, + list_is_last(&transfer->transfer_list, + &message->transfers)); + message->actual_length += transfer->len; + } + + return 0; +} + +static int dspi_setup(struct spi_device *spi) +{ + struct fsl_dspi *dspi = to_dspi(spi->master); + unsigned char br = 0, pbr = 0, pcssck = 0, cssck = 0; + unsigned char pasc = 0, asc = 0, fmsz = 0; + unsigned long clkrate; + + if (4 <= spi->bits_per_word && spi->bits_per_word <= 16) + fmsz = spi->bits_per_word - 1; + else + return -ENODEV; + + clkrate = clk_get_rate(dspi->clk); + hz_to_spi_baud(&pbr, &br, spi->max_speed_hz, clkrate); + + /* Set PCS to SCK delay scale values */ + ns_delay_scale(&pcssck, &cssck, dspi->cs_sck_delay, clkrate); + + /* Set After SCK delay scale values */ + ns_delay_scale(&pasc, &asc, dspi->sck_cs_delay, clkrate); + + writel(SPI_CTAR_FMSZ(fmsz) + | SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0) + | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0) + | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0) + | SPI_CTAR_PCSSCK(pcssck) + | SPI_CTAR_CSSCK(cssck) + | SPI_CTAR_PASC(pasc) + | SPI_CTAR_ASC(asc) + | SPI_CTAR_PBR(pbr) + | SPI_CTAR_BR(br), + dspi->base + SPI_CTAR(spi->chip_select)); + + return 0; +} + +static int dspi_probe(struct device_d *dev) +{ + struct resource *io; + struct fsl_dspi *dspi; + struct spi_master *master; + struct device_node *np = dev->device_node; + + int ret = 0; + uint32_t bus_num = 0; + uint32_t cs_num; + + dspi = xzalloc(sizeof(*dspi)); + + dspi->devtype_data = of_device_get_match_data(dev); + if (!dspi->devtype_data) { + dev_err(dev, "can't get devtype_data\n"); + ret = -EFAULT; + goto free_memory; + } + + master = &dspi->master; + master->dev = dev; + master->bus_num = dev->id; + master->setup = dspi_setup; + master->transfer = dspi_transfer; + + ret = of_property_read_u32(np, "spi-num-chipselects", &cs_num); + if (ret < 0) { + dev_err(dev, "can't get spi-num-chipselects\n"); + goto free_memory; + } + master->num_chipselect = cs_num; + + ret = of_property_read_u32(np, "bus-num", &bus_num); + if (ret < 0) { + dev_err(dev, "can't get bus-num\n");
Quoted 8 lines
drivers/spi/Kconfig
Quoted 3 lines
drivers/spi/Kconfig +3
-0+ goto free_memory; + } + master->bus_num = bus_num;I don't think the presence of a bus-num property should be enforced. It seems nobody has reviewed the binding since normally such a property shouldn't even exist. You can honor it if it's present, but shouldn't enforce it.
Good point. Will fix in v2.
Quoted 14 lines
drivers/spi/Kconfig
Quoted 10 lines
drivers/spi/Kconfig +9
-0+ + of_property_read_u32(dev->device_node, "fsl,spi-cs-sck-delay", + &dspi->cs_sck_delay); + of_property_read_u32(dev->device_node, "fsl,spi-sck-cs-delay", + &dspi->sck_cs_delay); + + io = dev_request_mem_resource(dev, 0); + if (IS_ERR(io)) + return PTR_ERR(io);I don't care much about cleaning up properly in the probe error pathes in barebox, but now that you started with "goto
free_memory" in the driver, you can use it here aswell ;)
True :-) Will fix in v2.
Thanks,
Andrey Smirnov
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Quoted 37 lines · Sascha Hauer
Hi Andrey,
Quoted 8 lines · Andrey Smirnov
Add support for ZII VF610 Dev based designs such as:
- VF610 Dev, revision B
- VF610 Dev, revision C
- CFU1, revision A
- SPU3, revision A
- SCU4 AIB, revision CQuoted 6 lines
Signed-off-by Andrey Smirnov <[email protected]>---
Sascha, this patch is rebased on 'next' instead of 'master' so that you won't have to resolve conflicts with RDU2 patches in 'next'. Let me know if you'd rather have it rebased on 'master'.
It's fine to base on next in this case.
Quoted 17 lines
arch/arm/boards/zii-vf610-dev/board.c new file +17
-0+struct named_signal { +unsigned int gpio; +const char *name; +int value; +}; + +static int expose_signals (const struct named_signal *signals, +size_t signal_num) +{ +int ret, i; + +for (i =0 ; i < signal_num; i++) { +const struct named_signal *signal = &signals[i]; + +if (signal->value <0 ) + ret =gpio_direction_input (signal->gpio); +else
Quoted 8 lines
arch/arm/boards/zii-vf610-dev/board.c line 44
Quoted 6 lines
arch/arm/boards/zii-vf610-dev/board.c new file +6
-0+ ret =gpio_direction_output (signal->gpio, signal->value); + +if (ret) { +pr_err ("Failed to configure \"%s\"\n" , signal->name); +return ret; + }This looks like
gpio_request_array(). Could you use this instead?
Almost. Unfortunately, gpio_request_array doesn't do much with "label' portion of a descriptor, except to use it when displaying information about GPIOs.
What I am doing here as well is exposing those GPIO in a very primitive way by calling
export_env_ull(signal->name, signal->gpio);
and so it becomes possible to do things like
gpio_set_value ${soc_sw_rstn} 0
instead of having to use numeric value to designate desired GPIO. If there's a way this can be done better or if there a good change we can make to gpio_request_array(), I am more than happy to change this code.
Quoted 21 lines
Quoted 21 lines
index 0000000..4465632
arch/arm/boards/zii-vf610-dev/lowlevel.c new file +16
-0@@ -0,0 +1,132 @@ +#include <common.h> +#include <linux/sizes.h> +#include <mach/generic.h> +#include <asm/barebox-arm-head.h> +#include <asm/barebox-arm.h> +#include <mach/vf610-regs.h> +#include <mach/clock-vf610.h> +#include <mach/iomux-vf610.h> +#include <debug_ll.h> + +#if defined(CONFIG_DEBUG_LL ) +# if !defined(CONFIG_DEBUG_VF610_UART ) +# warning "CONFIG_DEBUG_LL is enabled but CONFIG_DEBUG_VF610_UART is not" +# else +# if CONFIG_DEBUG_IMX_UART_PORT !=1 +# warning "CONFIG_DEBUG_LL output is not drirected to port 1"
Quoted 9 lines
arch/arm/boards/zii-vf610-dev/lowlevel.c line 19
Quoted 3 lines
arch/arm/boards/zii-vf610-dev/lowlevel.c new file +3
-0+# endif +# endif +#endif Just because this board is enabled doesn't mean the user is actually currently interested in this board. He might want to enable
CONFIG_DEBUG_LLfor another board, still he is warned about an invalid config here. This is not good.
Heh, I added this portion of the code because I was having exactly the opposite issue, but I see your point.
Quoted 9 lines
You could drop the
DEBUG_LLsupport and instead go to PBL console support. Seearch/arm/boards/freescale-mx6-sabrelite/lowlevel.cfor a good example. Basically it means you call this right after entry:arm_early_mmu_cache_invalidate(); relocate_to_current_adr(); setup_c(); barrier();
Quoted 7 lines
From here on you have a valid C environment (And thus don't need to work around switch/case with wrong LUTs) and can also call:
pbl_set_putc(xxx_uart_putc, uart);after that you can use printf like functions to print messages.
Thank you for the suggestion, if it is all the same to you I think I'll just drop the preprocessor check, though. DEBUG_LL is more of a debugging feature that very few people would use and switching to PBL console would mean a bunch of additional work.
Thanks,
Andrey Smirnov
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerQuoted 47 lines · Andrey Smirnov
Quoted 37 lines · Sascha Hauer
Hi Andrey,
Quoted 8 lines · Andrey Smirnov
Add support for ZII VF610 Dev based designs such as:
- VF610 Dev, revision B
- VF610 Dev, revision C
- CFU1, revision A
- SPU3, revision A
- SCU4 AIB, revision CQuoted 6 lines
Signed-off-by Andrey Smirnov <[email protected]>---
Sascha, this patch is rebased on 'next' instead of 'master' so that you won't have to resolve conflicts with RDU2 patches in 'next'. Let me know if you'd rather have it rebased on 'master'.
It's fine to base on next in this case.
Quoted 17 lines
arch/arm/boards/zii-vf610-dev/board.c new file +17
-0+struct named_signal { +unsigned int gpio; +const char *name; +int value; +}; + +static int expose_signals (const struct named_signal *signals, +size_t signal_num) +{ +int ret, i; + +for (i =0 ; i < signal_num; i++) { +const struct named_signal *signal = &signals[i]; + +if (signal->value <0 ) + ret =gpio_direction_input (signal->gpio); +else Quoted 8 lines
arch/arm/boards/zii-vf610-dev/board.c line 44
Quoted 6 lines
arch/arm/boards/zii-vf610-dev/board.c new file +6
-0+ ret =gpio_direction_output (signal->gpio, signal->value); + +if (ret) { +pr_err ("Failed to configure \"%s\"\n" , signal->name); +return ret; + }This looks like
gpio_request_array(). Could you use this instead?
Quoted 8 lines
Almost. Unfortunately,
gpio_request_arraydoesn't do much with "label' portion of a descriptor, except to use it when displaying information about GPIOs.What I am doing here as well is exposing those GPIO in a very primitive way by calling
export_env_ull(signal->name, signal->gpio);
What I meant was something like:
static int expose_signals(const struct gpio *array, size_t num)
{
int ret;
ret = gpio_request_array(gpios);
if (ret)
returen ret;
for (i = 0; i < num; i++) {
const struct gpio *gpio = &array[i];
export_env_ull(gpio->label, gpio->gpio);
}
}Quoted 9 lines
and so it becomes possible to do things like
gpio_set_value${soc_sw_rstn} 0instead of having to use numeric value to designate desired GPIO. If there's a way this can be done better or if there a good change we can make to
gpio_request_array(), I am more than happy to change this code.
I have no good idea how we could change gpio_request_array. Unfortunately the gpio labels are not unique, so we can't just export the variables unconditionally. A new gpio_request_array_export() function maybe could work, but doesn't look too nice either.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 60 lines · Sascha Hauer
Quoted 47 lines · Andrey Smirnov
Quoted 37 lines · Sascha Hauer
Hi Andrey,
Quoted 8 lines · Andrey Smirnov
Add support for ZII VF610 Dev based designs such as:
- VF610 Dev, revision B
- VF610 Dev, revision C
- CFU1, revision A
- SPU3, revision A
- SCU4 AIB, revision CQuoted 6 lines
Signed-off-by Andrey Smirnov <[email protected]>---
Sascha, this patch is rebased on 'next' instead of 'master' so that you won't have to resolve conflicts with RDU2 patches in 'next'. Let me know if you'd rather have it rebased on 'master'.
It's fine to base on next in this case.
Quoted 17 lines
arch/arm/boards/zii-vf610-dev/board.c new file +17
-0+struct named_signal { +unsigned int gpio; +const char *name; +int value; +}; + +static int expose_signals (const struct named_signal *signals, +size_t signal_num) +{ +int ret, i; + +for (i =0 ; i < signal_num; i++) { +const struct named_signal *signal = &signals[i]; + +if (signal->value <0 ) + ret =gpio_direction_input (signal->gpio); +else Quoted 8 lines
arch/arm/boards/zii-vf610-dev/board.c line 44
Quoted 6 lines
arch/arm/boards/zii-vf610-dev/board.c new file +6
-0+ ret =gpio_direction_output (signal->gpio, signal->value); + +if (ret) { +pr_err ("Failed to configure \"%s\"\n" , signal->name); +return ret; + }This looks like
gpio_request_array(). Could you use this instead?Quoted 8 lines
Almost. Unfortunately,
gpio_request_arraydoesn't do much with "label' portion of a descriptor, except to use it when displaying information about GPIOs.What I am doing here as well is exposing those GPIO in a very primitive way by calling
export_env_ull(signal->name, signal->gpio);What I meant was something like:
static int
expose_signals(const struct gpio *array, size_t num)
Quoted 12 lines
{
int ret;
ret = gpio_request_array(gpios);
if (ret)
returen ret;
for (i = 0; i < num; i++) {
const struct gpio *gpio = &array[i];
export_env_ull(gpio->label, gpio->gpio);
}
}Doh, I completely missed the fact that I can avoid declaring a pointless custom type if I do this. Good idea, will fix in v2.
Thanks,
Andrey
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox