Commit 47284e3e authored by Marcus Weseloh's avatar Marcus Weseloh Committed by Mark Brown

spi: sun4i: allow transfers to set transmission speed

Allow transfers to set the transmission speed rather than using the
device max_speed_hz value. The SPI core makes sure that the speed_hz
value is always set on the transfer.
Signed-off-by: default avatarMarcus Weseloh <mweseloh42@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 8005c49d
...@@ -229,8 +229,8 @@ static int sun4i_spi_transfer_one(struct spi_master *master, ...@@ -229,8 +229,8 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
/* Ensure that we have a parent clock fast enough */ /* Ensure that we have a parent clock fast enough */
mclk_rate = clk_get_rate(sspi->mclk); mclk_rate = clk_get_rate(sspi->mclk);
if (mclk_rate < (2 * spi->max_speed_hz)) { if (mclk_rate < (2 * tfr->speed_hz)) {
clk_set_rate(sspi->mclk, 2 * spi->max_speed_hz); clk_set_rate(sspi->mclk, 2 * tfr->speed_hz);
mclk_rate = clk_get_rate(sspi->mclk); mclk_rate = clk_get_rate(sspi->mclk);
} }
...@@ -248,14 +248,14 @@ static int sun4i_spi_transfer_one(struct spi_master *master, ...@@ -248,14 +248,14 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
* First try CDR2, and if we can't reach the expected * First try CDR2, and if we can't reach the expected
* frequency, fall back to CDR1. * frequency, fall back to CDR1.
*/ */
div = mclk_rate / (2 * spi->max_speed_hz); div = mclk_rate / (2 * tfr->speed_hz);
if (div <= (SUN4I_CLK_CTL_CDR2_MASK + 1)) { if (div <= (SUN4I_CLK_CTL_CDR2_MASK + 1)) {
if (div > 0) if (div > 0)
div--; div--;
reg = SUN4I_CLK_CTL_CDR2(div) | SUN4I_CLK_CTL_DRS; reg = SUN4I_CLK_CTL_CDR2(div) | SUN4I_CLK_CTL_DRS;
} else { } else {
div = ilog2(mclk_rate) - ilog2(spi->max_speed_hz); div = ilog2(mclk_rate) - ilog2(tfr->speed_hz);
reg = SUN4I_CLK_CTL_CDR1(div); reg = SUN4I_CLK_CTL_CDR1(div);
} }
......
...@@ -217,8 +217,8 @@ static int sun6i_spi_transfer_one(struct spi_master *master, ...@@ -217,8 +217,8 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
/* Ensure that we have a parent clock fast enough */ /* Ensure that we have a parent clock fast enough */
mclk_rate = clk_get_rate(sspi->mclk); mclk_rate = clk_get_rate(sspi->mclk);
if (mclk_rate < (2 * spi->max_speed_hz)) { if (mclk_rate < (2 * tfr->speed_hz)) {
clk_set_rate(sspi->mclk, 2 * spi->max_speed_hz); clk_set_rate(sspi->mclk, 2 * tfr->speed_hz);
mclk_rate = clk_get_rate(sspi->mclk); mclk_rate = clk_get_rate(sspi->mclk);
} }
...@@ -236,14 +236,14 @@ static int sun6i_spi_transfer_one(struct spi_master *master, ...@@ -236,14 +236,14 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
* First try CDR2, and if we can't reach the expected * First try CDR2, and if we can't reach the expected
* frequency, fall back to CDR1. * frequency, fall back to CDR1.
*/ */
div = mclk_rate / (2 * spi->max_speed_hz); div = mclk_rate / (2 * tfr->speed_hz);
if (div <= (SUN6I_CLK_CTL_CDR2_MASK + 1)) { if (div <= (SUN6I_CLK_CTL_CDR2_MASK + 1)) {
if (div > 0) if (div > 0)
div--; div--;
reg = SUN6I_CLK_CTL_CDR2(div) | SUN6I_CLK_CTL_DRS; reg = SUN6I_CLK_CTL_CDR2(div) | SUN6I_CLK_CTL_DRS;
} else { } else {
div = ilog2(mclk_rate) - ilog2(spi->max_speed_hz); div = ilog2(mclk_rate) - ilog2(tfr->speed_hz);
reg = SUN6I_CLK_CTL_CDR1(div); reg = SUN6I_CLK_CTL_CDR1(div);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment