u-boot-brain/drivers/spi
Dirk Behme 8d4c4ffb95 spi: mxc_spi: Fix pre and post divider calculation
Fix two issues with the calculation of pre_div and post_div:

1. pre_div: While the calculation of pre_div looks correct, to set the
CONREG[15-12] bits pre_div needs to be decremented by 1:

The i.MX 6Dual/6Quad Applications Processor Reference Manual (IMX6DQRM
Rev. 0, 11/2012) states:

CONREG[15-12]: PRE_DIVIDER
0000 Divide by 1
0001 Divide by 2
0010 Divide by 3
...
1101 Divide by 14
1110 Divide by 15
1111 Divide by 16

I.e. if we want to divide by 2, we have to write 1 to CONREG[15-12].

2. In case the post divider becomes necessary, pre_div will be divided by
16. So set pre_div to 16, too. And not 15.

Both issues above are tested using the following examples:

clk_src = 60000000 (60MHz, default i.MX6 ECSPI clock)

a) max_hz == 23000000 (23MHz, max i.MX6 ECSPI read clock)

-> pre_div =  3 (divide by 3 => CONREG[15-12] == 2)
-> post_div = 0 (divide by 1 => CONREG[11- 8] == 0)
               => 60MHz / 3 = 20MHz SPI clock

b) max_hz == 2000000 (2MHz)

-> pre_div =  16 (divide by 16 => CONREG[15-12] == 15)
-> post_div = 1  (divide by  2 => CONREG[11- 8] == 1)
               => 60MHz / 32 = 1.875MHz SPI clock

c) max_hz == 1000000 (1MHz)

-> pre_div =  16 (divide by 16 => CONREG[15-12] == 15)
-> post_div = 2  (divide by  4 => CONREG[11- 8] == 2)
               => 60MHz / 64 = 937.5kHz SPI clock

d) max_hz == 500000 (500kHz)

-> pre_div =  16 (divide by 16 => CONREG[15-12] == 15)
-> post_div = 3  (divide by  8 => CONREG[11- 8] == 3)
               => 60MHz / 128 = 468.75kHz SPI clock

Signed-off-by: Dirk Behme <dirk.behme@gmail.com>
2013-06-26 16:22:51 +02:00
..
altera_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
andes_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
andes_spi.h andes_spi: add andes_spi interface 2011-07-25 23:40:11 +02:00
armada100_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
atmel_dataflash_spi.c AT91/SPI: fix atmel_dataflash_spi.c to allow building without warnings 2011-08-03 13:00:56 +02:00
atmel_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
atmel_spi.h spi: atmel: add WDRBT bit to avoid receive overrun 2012-09-01 17:06:14 +02:00
bfin_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
bfin_spi6xx.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
cf_qspi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
cf_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
davinci_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
davinci_spi.h TI DaVinci: Driver for the davinci SPI controller 2010-02-12 12:31:53 -06:00
exynos_spi.c Merge branch 'u-boot-samsung/master' into 'u-boot-arm/master' 2013-04-04 15:44:57 +02:00
fdt_spi.c tegra114: add SPI driver 2013-03-25 09:56:07 -07:00
fsl_espi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
ich.c Consolidate bool type 2013-04-01 16:33:52 -04:00
ich.h x86: spi: Add Intel ICH driver 2013-03-19 08:45:36 -07:00
kirkwood_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
Makefile Merge branch 'u-boot/master' into 'u-boot-arm/master' 2013-03-28 18:50:01 +01:00
mpc8xxx_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
mpc52xx_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
mxc_spi.c spi: mxc_spi: Fix pre and post divider calculation 2013-06-26 16:22:51 +02:00
mxs_spi.c imx: Move some header files from arch-mxs to imx-common 2013-04-22 10:22:22 +02:00
oc_tiny_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
omap3_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
omap3_spi.h OMAP3 SPI : Fixed bugs related to SPI transfer 2012-12-10 08:55:25 -07:00
sh_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
sh_spi.h sh_spi: Add 4 chip select signals supporting 2012-03-26 10:09:31 +09:00
soft_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
spi.c spi: Add function to allocate a new SPI slave 2013-03-19 08:45:36 -07:00
tegra20_sflash.c Merge branch 'u-boot/master' into 'u-boot-arm/master' 2013-03-28 18:50:01 +01:00
tegra20_slink.c Merge branch 'u-boot/master' into 'u-boot-arm/master' 2013-03-28 18:50:01 +01:00
tegra114_spi.c tegra114: add SPI driver 2013-03-25 09:56:07 -07:00
xilinx_spi.c spi: Use spi_alloc_slave() in each SPI driver 2013-03-19 08:45:36 -07:00
xilinx_spi.h spi: xilinx_spi: Perform software reset during slave setup 2013-02-04 12:09:49 +01:00