Skip to content

Commit 65d5665

Browse files
Nobuhiro Iwamatsubroonie
authored andcommitted
spi: sh-msiof: Update calculation of frequency dividing
sh-msiof of frequency dividing does not perform the calculation, driver have to manage setting value in the table. It is not possible to set frequency dividing value close to the actual data in this way. This changes from frequency dividing of table management to setting by calculation. This driver is able to set a value close to the actual data. Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent c8935ef commit 65d5665

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

‎drivers/spi/spi-sh-msiof.c‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,42 +243,38 @@ static irqreturn_t sh_msiof_spi_irq(int irq, void *data)
243243

244244
static struct {
245245
unsigned short div;
246-
unsigned short scr;
247-
} const sh_msiof_spi_clk_table[] = {
248-
{ 1, SCR_BRPS( 1) | SCR_BRDV_DIV_1 },
249-
{ 2, SCR_BRPS( 1) | SCR_BRDV_DIV_2 },
250-
{ 4, SCR_BRPS( 1) | SCR_BRDV_DIV_4 },
251-
{ 8, SCR_BRPS( 1) | SCR_BRDV_DIV_8 },
252-
{ 16, SCR_BRPS( 1) | SCR_BRDV_DIV_16 },
253-
{ 32, SCR_BRPS( 1) | SCR_BRDV_DIV_32 },
254-
{ 64, SCR_BRPS(32) | SCR_BRDV_DIV_2 },
255-
{ 128, SCR_BRPS(32) | SCR_BRDV_DIV_4 },
256-
{ 256, SCR_BRPS(32) | SCR_BRDV_DIV_8 },
257-
{ 512, SCR_BRPS(32) | SCR_BRDV_DIV_16 },
258-
{ 1024, SCR_BRPS(32) | SCR_BRDV_DIV_32 },
246+
unsigned short brdv;
247+
} const sh_msiof_spi_div_table[] = {
248+
{ 1, SCR_BRDV_DIV_1 },
249+
{ 2, SCR_BRDV_DIV_2 },
250+
{ 4, SCR_BRDV_DIV_4 },
251+
{ 8, SCR_BRDV_DIV_8 },
252+
{ 16, SCR_BRDV_DIV_16 },
253+
{ 32, SCR_BRDV_DIV_32 },
259254
};
260255

261256
static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
262257
unsigned long parent_rate, u32 spi_hz)
263258
{
264259
unsigned long div = 1024;
260+
u32 brps, scr;
265261
size_t k;
266262

267263
if (!WARN_ON(!spi_hz || !parent_rate))
268264
div = DIV_ROUND_UP(parent_rate, spi_hz);
269265

270-
/* TODO: make more fine grained */
271-
272-
for (k = 0; k < ARRAY_SIZE(sh_msiof_spi_clk_table); k++) {
273-
if (sh_msiof_spi_clk_table[k].div >= div)
266+
for (k = 0; k < ARRAY_SIZE(sh_msiof_spi_div_table); k++) {
267+
brps = DIV_ROUND_UP(div, sh_msiof_spi_div_table[k].div);
268+
if (brps <= 32) /* max of brdv is 32 */
274269
break;
275270
}
276271

277-
k = min_t(int, k, ARRAY_SIZE(sh_msiof_spi_clk_table) - 1);
272+
k = min_t(int, k, ARRAY_SIZE(sh_msiof_spi_div_table) - 1);
278273

279-
sh_msiof_write(p, TSCR, sh_msiof_spi_clk_table[k].scr);
274+
scr = sh_msiof_spi_div_table[k].brdv | SCR_BRPS(brps);
275+
sh_msiof_write(p, TSCR, scr);
280276
if (!(p->chipdata->master_flags & SPI_MASTER_MUST_TX))
281-
sh_msiof_write(p, RSCR, sh_msiof_spi_clk_table[k].scr);
277+
sh_msiof_write(p, RSCR, scr);
282278
}
283279

284280
static u32 sh_msiof_get_delay_bit(u32 dtdl_or_syncdl)

0 commit comments

Comments
 (0)