Skip to content

Commit 04e6bb0

Browse files
Mason Zhangbroonie
authored andcommitted
spi: modify set_cs_timing parameter
This patch modified set_cs_timing parameter, no need pass in spi_delay to set_cs_timing callback. By the way, we modified the mediatek and tegra114 spi driver to fix build err. In mediatek spi driver, We have support set absolute time not clk_count, and call this function in prepare_message not user's API. Signed-off-by: Mason Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 8c33ebf commit 04e6bb0

File tree

3 files changed

+66
-52
lines changed

3 files changed

+66
-52
lines changed

drivers/spi/spi-mt65xx.c

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,65 @@ static void mtk_spi_reset(struct mtk_spi *mdata)
208208
writel(reg_val, mdata->base + SPI_CMD_REG);
209209
}
210210

211+
static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
212+
{
213+
struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
214+
struct spi_delay *cs_setup = &spi->cs_setup;
215+
struct spi_delay *cs_hold = &spi->cs_hold;
216+
struct spi_delay *cs_inactive = &spi->cs_inactive;
217+
u16 setup, hold, inactive;
218+
u32 reg_val;
219+
int delay;
220+
221+
delay = spi_delay_to_ns(cs_setup, NULL);
222+
if (delay < 0)
223+
return delay;
224+
setup = (delay * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000)) / 1000;
225+
226+
delay = spi_delay_to_ns(cs_hold, NULL);
227+
if (delay < 0)
228+
return delay;
229+
hold = (delay * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000)) / 1000;
230+
231+
delay = spi_delay_to_ns(cs_inactive, NULL);
232+
if (delay < 0)
233+
return delay;
234+
inactive = (delay * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000)) / 1000;
235+
236+
setup = setup ? setup : 1;
237+
hold = hold ? hold : 1;
238+
inactive = inactive ? inactive : 1;
239+
240+
reg_val = readl(mdata->base + SPI_CFG0_REG);
241+
if (mdata->dev_comp->enhance_timing) {
242+
hold = min(hold, 0xffff);
243+
setup = min(setup, 0xffff);
244+
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
245+
reg_val |= (((hold - 1) & 0xffff)
246+
<< SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
247+
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
248+
reg_val |= (((setup - 1) & 0xffff)
249+
<< SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
250+
} else {
251+
hold = min(hold, 0xff);
252+
setup = min(setup, 0xff);
253+
reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
254+
reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
255+
reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
256+
reg_val |= (((setup - 1) & 0xff)
257+
<< SPI_CFG0_CS_SETUP_OFFSET);
258+
}
259+
writel(reg_val, mdata->base + SPI_CFG0_REG);
260+
261+
inactive = min(inactive, 0xff);
262+
reg_val = readl(mdata->base + SPI_CFG1_REG);
263+
reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
264+
reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
265+
writel(reg_val, mdata->base + SPI_CFG1_REG);
266+
267+
return 0;
268+
}
269+
211270
static int mtk_spi_prepare_message(struct spi_master *master,
212271
struct spi_message *msg)
213272
{
@@ -284,6 +343,8 @@ static int mtk_spi_prepare_message(struct spi_master *master,
284343
<< SPI_CFG1_GET_TICK_DLY_OFFSET);
285344
writel(reg_val, mdata->base + SPI_CFG1_REG);
286345

346+
/* set hw cs timing */
347+
mtk_spi_set_hw_cs_timing(spi);
287348
return 0;
288349
}
289350

@@ -528,52 +589,6 @@ static bool mtk_spi_can_dma(struct spi_master *master,
528589
(unsigned long)xfer->rx_buf % 4 == 0);
529590
}
530591

531-
static int mtk_spi_set_hw_cs_timing(struct spi_device *spi,
532-
struct spi_delay *setup,
533-
struct spi_delay *hold,
534-
struct spi_delay *inactive)
535-
{
536-
struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
537-
u16 setup_dly, hold_dly, inactive_dly;
538-
u32 reg_val;
539-
540-
if ((setup && setup->unit != SPI_DELAY_UNIT_SCK) ||
541-
(hold && hold->unit != SPI_DELAY_UNIT_SCK) ||
542-
(inactive && inactive->unit != SPI_DELAY_UNIT_SCK)) {
543-
dev_err(&spi->dev,
544-
"Invalid delay unit, should be SPI_DELAY_UNIT_SCK\n");
545-
return -EINVAL;
546-
}
547-
548-
setup_dly = setup ? setup->value : 1;
549-
hold_dly = hold ? hold->value : 1;
550-
inactive_dly = inactive ? inactive->value : 1;
551-
552-
reg_val = readl(mdata->base + SPI_CFG0_REG);
553-
if (mdata->dev_comp->enhance_timing) {
554-
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
555-
reg_val |= (((hold_dly - 1) & 0xffff)
556-
<< SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
557-
reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
558-
reg_val |= (((setup_dly - 1) & 0xffff)
559-
<< SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
560-
} else {
561-
reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
562-
reg_val |= (((hold_dly - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
563-
reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
564-
reg_val |= (((setup_dly - 1) & 0xff)
565-
<< SPI_CFG0_CS_SETUP_OFFSET);
566-
}
567-
writel(reg_val, mdata->base + SPI_CFG0_REG);
568-
569-
reg_val = readl(mdata->base + SPI_CFG1_REG);
570-
reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
571-
reg_val |= (((inactive_dly - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
572-
writel(reg_val, mdata->base + SPI_CFG1_REG);
573-
574-
return 0;
575-
}
576-
577592
static int mtk_spi_setup(struct spi_device *spi)
578593
{
579594
struct mtk_spi *mdata = spi_master_get_devdata(spi->master);

drivers/spi/spi-tegra114.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,12 @@ static void tegra_spi_deinit_dma_param(struct tegra_spi_data *tspi,
717717
dma_release_channel(dma_chan);
718718
}
719719

720-
static int tegra_spi_set_hw_cs_timing(struct spi_device *spi,
721-
struct spi_delay *setup,
722-
struct spi_delay *hold,
723-
struct spi_delay *inactive)
720+
static int tegra_spi_set_hw_cs_timing(struct spi_device *spi)
724721
{
725722
struct tegra_spi_data *tspi = spi_master_get_devdata(spi->master);
723+
struct spi_delay *setup = &spi->cs_setup;
724+
struct spi_delay *hold = &spi->cs_hold;
725+
struct spi_delay *inactive = &spi->cs_inactive;
726726
u8 setup_dly, hold_dly, inactive_dly;
727727
u32 setup_hold;
728728
u32 spi_cs_timing;

include/linux/spi/spi.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,7 @@ struct spi_controller {
554554
* to configure specific CS timing through spi_set_cs_timing() after
555555
* spi_setup().
556556
*/
557-
int (*set_cs_timing)(struct spi_device *spi, struct spi_delay *setup,
558-
struct spi_delay *hold, struct spi_delay *inactive);
557+
int (*set_cs_timing)(struct spi_device *spi);
559558

560559
/* bidirectional bulk transfers
561560
*

0 commit comments

Comments
 (0)