* [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
@ 2021-08-03 10:24 ` Mason Zhang
0 siblings, 0 replies; 9+ messages in thread
From: Mason Zhang @ 2021-08-03 10:24 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Laxman Dewangan, linux-spi, linux-kernel, linux-arm-kernel,
linux-mediatek, wsd_upstream, Mason Zhang
This patch modified set_cs_timing callback:
1 support spi_device set cs_timing in their driver;
2 support set absolute time but no clk count, because;
clk src will change in different platform;
3 call this function in prepare_message but not in other API.
Signed-off-by: Mason Zhang <Mason.Zhang@mediatek.com>
---
drivers/spi/spi-mt65xx.c | 102 +++++++++++++++++++++------------------
1 file changed, 56 insertions(+), 46 deletions(-)
diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 6f2925118b98..7a34f5b1201d 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -208,6 +208,60 @@ static void mtk_spi_reset(struct mtk_spi *mdata)
writel(reg_val, mdata->base + SPI_CMD_REG);
}
+static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
+{
+ struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
+ struct spi_delay *cs_setup = &spi->cs_setup;
+ struct spi_delay *cs_hold = &spi->cs_hold;
+ struct spi_delay *cs_inactive = &spi->cs_inactive;
+ u16 setup, hold, inactive;
+ u32 reg_val;
+ int delay;
+
+ delay = spi_delay_to_ns(cs_setup, NULL);
+ if (delay < 0)
+ return delay;
+ setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ delay = spi_delay_to_ns(cs_hold, NULL);
+ if (delay < 0)
+ return delay;
+ hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ delay = spi_delay_to_ns(cs_inactive, NULL);
+ if (delay < 0)
+ return delay;
+ inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ setup = setup ? setup : 1;
+ hold = hold ? hold : 1;
+ inactive = inactive ? inactive : 1;
+
+ reg_val = readl(mdata->base + SPI_CFG0_REG);
+ if (mdata->dev_comp->enhance_timing) {
+ reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
+ reg_val |= (((hold - 1) & 0xffff)
+ << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
+ reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
+ reg_val |= (((setup - 1) & 0xffff)
+ << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
+ } else {
+ reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
+ reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
+ reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
+ reg_val |= (((setup - 1) & 0xff)
+ << SPI_CFG0_CS_SETUP_OFFSET);
+ }
+ writel(reg_val, mdata->base + SPI_CFG0_REG);
+
+ reg_val = readl(mdata->base + SPI_CFG1_REG);
+ reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
+ reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
+ writel(reg_val, mdata->base + SPI_CFG1_REG);
+
+ return 0;
+}
+
static int mtk_spi_prepare_message(struct spi_master *master,
struct spi_message *msg)
{
@@ -284,6 +338,8 @@ static int mtk_spi_prepare_message(struct spi_master *master,
<< SPI_CFG1_GET_TICK_DLY_OFFSET);
writel(reg_val, mdata->base + SPI_CFG1_REG);
+ /* set hw cs timing */
+ mtk_spi_set_hw_cs_timing(spi);
return 0;
}
@@ -528,52 +584,6 @@ static bool mtk_spi_can_dma(struct spi_master *master,
(unsigned long)xfer->rx_buf % 4 == 0);
}
-static int mtk_spi_set_hw_cs_timing(struct spi_device *spi,
- struct spi_delay *setup,
- struct spi_delay *hold,
- struct spi_delay *inactive)
-{
- struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
- u16 setup_dly, hold_dly, inactive_dly;
- u32 reg_val;
-
- if ((setup && setup->unit != SPI_DELAY_UNIT_SCK) ||
- (hold && hold->unit != SPI_DELAY_UNIT_SCK) ||
- (inactive && inactive->unit != SPI_DELAY_UNIT_SCK)) {
- dev_err(&spi->dev,
- "Invalid delay unit, should be SPI_DELAY_UNIT_SCK\n");
- return -EINVAL;
- }
-
- setup_dly = setup ? setup->value : 1;
- hold_dly = hold ? hold->value : 1;
- inactive_dly = inactive ? inactive->value : 1;
-
- reg_val = readl(mdata->base + SPI_CFG0_REG);
- if (mdata->dev_comp->enhance_timing) {
- reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
- reg_val |= (((hold_dly - 1) & 0xffff)
- << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
- reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
- reg_val |= (((setup_dly - 1) & 0xffff)
- << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
- } else {
- reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
- reg_val |= (((hold_dly - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
- reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
- reg_val |= (((setup_dly - 1) & 0xff)
- << SPI_CFG0_CS_SETUP_OFFSET);
- }
- writel(reg_val, mdata->base + SPI_CFG0_REG);
-
- reg_val = readl(mdata->base + SPI_CFG1_REG);
- reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
- reg_val |= (((inactive_dly - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
- writel(reg_val, mdata->base + SPI_CFG1_REG);
-
- return 0;
-}
-
static int mtk_spi_setup(struct spi_device *spi)
{
struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
--
2.18.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
@ 2021-08-03 10:24 ` Mason Zhang
0 siblings, 0 replies; 9+ messages in thread
From: Mason Zhang @ 2021-08-03 10:24 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Laxman Dewangan, linux-spi, linux-kernel, linux-arm-kernel,
linux-mediatek, wsd_upstream, Mason Zhang
This patch modified set_cs_timing callback:
1 support spi_device set cs_timing in their driver;
2 support set absolute time but no clk count, because;
clk src will change in different platform;
3 call this function in prepare_message but not in other API.
Signed-off-by: Mason Zhang <Mason.Zhang@mediatek.com>
---
drivers/spi/spi-mt65xx.c | 102 +++++++++++++++++++++------------------
1 file changed, 56 insertions(+), 46 deletions(-)
diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 6f2925118b98..7a34f5b1201d 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -208,6 +208,60 @@ static void mtk_spi_reset(struct mtk_spi *mdata)
writel(reg_val, mdata->base + SPI_CMD_REG);
}
+static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
+{
+ struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
+ struct spi_delay *cs_setup = &spi->cs_setup;
+ struct spi_delay *cs_hold = &spi->cs_hold;
+ struct spi_delay *cs_inactive = &spi->cs_inactive;
+ u16 setup, hold, inactive;
+ u32 reg_val;
+ int delay;
+
+ delay = spi_delay_to_ns(cs_setup, NULL);
+ if (delay < 0)
+ return delay;
+ setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ delay = spi_delay_to_ns(cs_hold, NULL);
+ if (delay < 0)
+ return delay;
+ hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ delay = spi_delay_to_ns(cs_inactive, NULL);
+ if (delay < 0)
+ return delay;
+ inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ setup = setup ? setup : 1;
+ hold = hold ? hold : 1;
+ inactive = inactive ? inactive : 1;
+
+ reg_val = readl(mdata->base + SPI_CFG0_REG);
+ if (mdata->dev_comp->enhance_timing) {
+ reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
+ reg_val |= (((hold - 1) & 0xffff)
+ << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
+ reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
+ reg_val |= (((setup - 1) & 0xffff)
+ << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
+ } else {
+ reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
+ reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
+ reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
+ reg_val |= (((setup - 1) & 0xff)
+ << SPI_CFG0_CS_SETUP_OFFSET);
+ }
+ writel(reg_val, mdata->base + SPI_CFG0_REG);
+
+ reg_val = readl(mdata->base + SPI_CFG1_REG);
+ reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
+ reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
+ writel(reg_val, mdata->base + SPI_CFG1_REG);
+
+ return 0;
+}
+
static int mtk_spi_prepare_message(struct spi_master *master,
struct spi_message *msg)
{
@@ -284,6 +338,8 @@ static int mtk_spi_prepare_message(struct spi_master *master,
<< SPI_CFG1_GET_TICK_DLY_OFFSET);
writel(reg_val, mdata->base + SPI_CFG1_REG);
+ /* set hw cs timing */
+ mtk_spi_set_hw_cs_timing(spi);
return 0;
}
@@ -528,52 +584,6 @@ static bool mtk_spi_can_dma(struct spi_master *master,
(unsigned long)xfer->rx_buf % 4 == 0);
}
-static int mtk_spi_set_hw_cs_timing(struct spi_device *spi,
- struct spi_delay *setup,
- struct spi_delay *hold,
- struct spi_delay *inactive)
-{
- struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
- u16 setup_dly, hold_dly, inactive_dly;
- u32 reg_val;
-
- if ((setup && setup->unit != SPI_DELAY_UNIT_SCK) ||
- (hold && hold->unit != SPI_DELAY_UNIT_SCK) ||
- (inactive && inactive->unit != SPI_DELAY_UNIT_SCK)) {
- dev_err(&spi->dev,
- "Invalid delay unit, should be SPI_DELAY_UNIT_SCK\n");
- return -EINVAL;
- }
-
- setup_dly = setup ? setup->value : 1;
- hold_dly = hold ? hold->value : 1;
- inactive_dly = inactive ? inactive->value : 1;
-
- reg_val = readl(mdata->base + SPI_CFG0_REG);
- if (mdata->dev_comp->enhance_timing) {
- reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
- reg_val |= (((hold_dly - 1) & 0xffff)
- << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
- reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
- reg_val |= (((setup_dly - 1) & 0xffff)
- << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
- } else {
- reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
- reg_val |= (((hold_dly - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
- reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
- reg_val |= (((setup_dly - 1) & 0xff)
- << SPI_CFG0_CS_SETUP_OFFSET);
- }
- writel(reg_val, mdata->base + SPI_CFG0_REG);
-
- reg_val = readl(mdata->base + SPI_CFG1_REG);
- reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
- reg_val |= (((inactive_dly - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
- writel(reg_val, mdata->base + SPI_CFG1_REG);
-
- return 0;
-}
-
static int mtk_spi_setup(struct spi_device *spi)
{
struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
--
2.18.0
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
@ 2021-08-03 10:24 ` Mason Zhang
0 siblings, 0 replies; 9+ messages in thread
From: Mason Zhang @ 2021-08-03 10:24 UTC (permalink / raw)
To: Mark Brown, Matthias Brugger
Cc: Laxman Dewangan, linux-spi, linux-kernel, linux-arm-kernel,
linux-mediatek, wsd_upstream, Mason Zhang
This patch modified set_cs_timing callback:
1 support spi_device set cs_timing in their driver;
2 support set absolute time but no clk count, because;
clk src will change in different platform;
3 call this function in prepare_message but not in other API.
Signed-off-by: Mason Zhang <Mason.Zhang@mediatek.com>
---
drivers/spi/spi-mt65xx.c | 102 +++++++++++++++++++++------------------
1 file changed, 56 insertions(+), 46 deletions(-)
diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
index 6f2925118b98..7a34f5b1201d 100644
--- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c
@@ -208,6 +208,60 @@ static void mtk_spi_reset(struct mtk_spi *mdata)
writel(reg_val, mdata->base + SPI_CMD_REG);
}
+static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
+{
+ struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
+ struct spi_delay *cs_setup = &spi->cs_setup;
+ struct spi_delay *cs_hold = &spi->cs_hold;
+ struct spi_delay *cs_inactive = &spi->cs_inactive;
+ u16 setup, hold, inactive;
+ u32 reg_val;
+ int delay;
+
+ delay = spi_delay_to_ns(cs_setup, NULL);
+ if (delay < 0)
+ return delay;
+ setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ delay = spi_delay_to_ns(cs_hold, NULL);
+ if (delay < 0)
+ return delay;
+ hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ delay = spi_delay_to_ns(cs_inactive, NULL);
+ if (delay < 0)
+ return delay;
+ inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
+
+ setup = setup ? setup : 1;
+ hold = hold ? hold : 1;
+ inactive = inactive ? inactive : 1;
+
+ reg_val = readl(mdata->base + SPI_CFG0_REG);
+ if (mdata->dev_comp->enhance_timing) {
+ reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
+ reg_val |= (((hold - 1) & 0xffff)
+ << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
+ reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
+ reg_val |= (((setup - 1) & 0xffff)
+ << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
+ } else {
+ reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
+ reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
+ reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
+ reg_val |= (((setup - 1) & 0xff)
+ << SPI_CFG0_CS_SETUP_OFFSET);
+ }
+ writel(reg_val, mdata->base + SPI_CFG0_REG);
+
+ reg_val = readl(mdata->base + SPI_CFG1_REG);
+ reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
+ reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
+ writel(reg_val, mdata->base + SPI_CFG1_REG);
+
+ return 0;
+}
+
static int mtk_spi_prepare_message(struct spi_master *master,
struct spi_message *msg)
{
@@ -284,6 +338,8 @@ static int mtk_spi_prepare_message(struct spi_master *master,
<< SPI_CFG1_GET_TICK_DLY_OFFSET);
writel(reg_val, mdata->base + SPI_CFG1_REG);
+ /* set hw cs timing */
+ mtk_spi_set_hw_cs_timing(spi);
return 0;
}
@@ -528,52 +584,6 @@ static bool mtk_spi_can_dma(struct spi_master *master,
(unsigned long)xfer->rx_buf % 4 == 0);
}
-static int mtk_spi_set_hw_cs_timing(struct spi_device *spi,
- struct spi_delay *setup,
- struct spi_delay *hold,
- struct spi_delay *inactive)
-{
- struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
- u16 setup_dly, hold_dly, inactive_dly;
- u32 reg_val;
-
- if ((setup && setup->unit != SPI_DELAY_UNIT_SCK) ||
- (hold && hold->unit != SPI_DELAY_UNIT_SCK) ||
- (inactive && inactive->unit != SPI_DELAY_UNIT_SCK)) {
- dev_err(&spi->dev,
- "Invalid delay unit, should be SPI_DELAY_UNIT_SCK\n");
- return -EINVAL;
- }
-
- setup_dly = setup ? setup->value : 1;
- hold_dly = hold ? hold->value : 1;
- inactive_dly = inactive ? inactive->value : 1;
-
- reg_val = readl(mdata->base + SPI_CFG0_REG);
- if (mdata->dev_comp->enhance_timing) {
- reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
- reg_val |= (((hold_dly - 1) & 0xffff)
- << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
- reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
- reg_val |= (((setup_dly - 1) & 0xffff)
- << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
- } else {
- reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
- reg_val |= (((hold_dly - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
- reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
- reg_val |= (((setup_dly - 1) & 0xff)
- << SPI_CFG0_CS_SETUP_OFFSET);
- }
- writel(reg_val, mdata->base + SPI_CFG0_REG);
-
- reg_val = readl(mdata->base + SPI_CFG1_REG);
- reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
- reg_val |= (((inactive_dly - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
- writel(reg_val, mdata->base + SPI_CFG1_REG);
-
- return 0;
-}
-
static int mtk_spi_setup(struct spi_device *spi)
{
struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
2021-08-03 10:24 ` Mason Zhang
(?)
@ 2021-08-03 18:20 ` Andy Shevchenko
-1 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-08-03 18:20 UTC (permalink / raw)
To: Mason Zhang
Cc: Mark Brown, Matthias Brugger, Laxman Dewangan, linux-spi,
Linux Kernel Mailing List, linux-arm Mailing List,
moderated list:ARM/Mediatek SoC support, Mediatek WSD Upstream
On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang <Mason.Zhang@mediatek.com> wrote:
>
> This patch modified set_cs_timing callback:
> 1 support spi_device set cs_timing in their driver;
> 2 support set absolute time but no clk count, because;
> clk src will change in different platform;
> 3 call this function in prepare_message but not in other API.
Perhaps it should be 3 patches?
...
> +static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
> +{
> + struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
> + struct spi_delay *cs_setup = &spi->cs_setup;
> + struct spi_delay *cs_hold = &spi->cs_hold;
> + struct spi_delay *cs_inactive = &spi->cs_inactive;
> + u16 setup, hold, inactive;
> + u32 reg_val;
> + int delay;
> +
> + delay = spi_delay_to_ns(cs_setup, NULL);
> + if (delay < 0)
> + return delay;
> + setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
1000 is NSEC_PER_USEC (here and below)?
> + delay = spi_delay_to_ns(cs_hold, NULL);
> + if (delay < 0)
> + return delay;
> + hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
> +
> + delay = spi_delay_to_ns(cs_inactive, NULL);
> + if (delay < 0)
> + return delay;
> + inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
> + setup = setup ? setup : 1;
> + hold = hold ? hold : 1;
> + inactive = inactive ? inactive : 1;
All of these can be simplified by using ?: (short ternary) form.
> + reg_val = readl(mdata->base + SPI_CFG0_REG);
> + if (mdata->dev_comp->enhance_timing) {
> + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> + reg_val |= (((hold - 1) & 0xffff)
> + << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> + reg_val |= (((setup - 1) & 0xffff)
> + << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> + } else {
> + reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
> + reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
> + reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
> + reg_val |= (((setup - 1) & 0xff)
> + << SPI_CFG0_CS_SETUP_OFFSET);
> + }
> + writel(reg_val, mdata->base + SPI_CFG0_REG);
> +
> + reg_val = readl(mdata->base + SPI_CFG1_REG);
> + reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
> + reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
> + writel(reg_val, mdata->base + SPI_CFG1_REG);
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
@ 2021-08-03 18:20 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-08-03 18:20 UTC (permalink / raw)
To: Mason Zhang
Cc: Mark Brown, Matthias Brugger, Laxman Dewangan, linux-spi,
Linux Kernel Mailing List, linux-arm Mailing List,
moderated list:ARM/Mediatek SoC support, Mediatek WSD Upstream
On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang <Mason.Zhang@mediatek.com> wrote:
>
> This patch modified set_cs_timing callback:
> 1 support spi_device set cs_timing in their driver;
> 2 support set absolute time but no clk count, because;
> clk src will change in different platform;
> 3 call this function in prepare_message but not in other API.
Perhaps it should be 3 patches?
...
> +static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
> +{
> + struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
> + struct spi_delay *cs_setup = &spi->cs_setup;
> + struct spi_delay *cs_hold = &spi->cs_hold;
> + struct spi_delay *cs_inactive = &spi->cs_inactive;
> + u16 setup, hold, inactive;
> + u32 reg_val;
> + int delay;
> +
> + delay = spi_delay_to_ns(cs_setup, NULL);
> + if (delay < 0)
> + return delay;
> + setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
1000 is NSEC_PER_USEC (here and below)?
> + delay = spi_delay_to_ns(cs_hold, NULL);
> + if (delay < 0)
> + return delay;
> + hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
> +
> + delay = spi_delay_to_ns(cs_inactive, NULL);
> + if (delay < 0)
> + return delay;
> + inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
> + setup = setup ? setup : 1;
> + hold = hold ? hold : 1;
> + inactive = inactive ? inactive : 1;
All of these can be simplified by using ?: (short ternary) form.
> + reg_val = readl(mdata->base + SPI_CFG0_REG);
> + if (mdata->dev_comp->enhance_timing) {
> + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> + reg_val |= (((hold - 1) & 0xffff)
> + << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> + reg_val |= (((setup - 1) & 0xffff)
> + << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> + } else {
> + reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
> + reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
> + reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
> + reg_val |= (((setup - 1) & 0xff)
> + << SPI_CFG0_CS_SETUP_OFFSET);
> + }
> + writel(reg_val, mdata->base + SPI_CFG0_REG);
> +
> + reg_val = readl(mdata->base + SPI_CFG1_REG);
> + reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
> + reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
> + writel(reg_val, mdata->base + SPI_CFG1_REG);
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
@ 2021-08-03 18:20 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2021-08-03 18:20 UTC (permalink / raw)
To: Mason Zhang
Cc: Mark Brown, Matthias Brugger, Laxman Dewangan, linux-spi,
Linux Kernel Mailing List, linux-arm Mailing List,
moderated list:ARM/Mediatek SoC support, Mediatek WSD Upstream
On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang <Mason.Zhang@mediatek.com> wrote:
>
> This patch modified set_cs_timing callback:
> 1 support spi_device set cs_timing in their driver;
> 2 support set absolute time but no clk count, because;
> clk src will change in different platform;
> 3 call this function in prepare_message but not in other API.
Perhaps it should be 3 patches?
...
> +static int mtk_spi_set_hw_cs_timing(struct spi_device *spi)
> +{
> + struct mtk_spi *mdata = spi_master_get_devdata(spi->master);
> + struct spi_delay *cs_setup = &spi->cs_setup;
> + struct spi_delay *cs_hold = &spi->cs_hold;
> + struct spi_delay *cs_inactive = &spi->cs_inactive;
> + u16 setup, hold, inactive;
> + u32 reg_val;
> + int delay;
> +
> + delay = spi_delay_to_ns(cs_setup, NULL);
> + if (delay < 0)
> + return delay;
> + setup = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
1000 is NSEC_PER_USEC (here and below)?
> + delay = spi_delay_to_ns(cs_hold, NULL);
> + if (delay < 0)
> + return delay;
> + hold = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
> +
> + delay = spi_delay_to_ns(cs_inactive, NULL);
> + if (delay < 0)
> + return delay;
> + inactive = (delay / 1000) * DIV_ROUND_UP(mdata->spi_clk_hz, 1000000);
> + setup = setup ? setup : 1;
> + hold = hold ? hold : 1;
> + inactive = inactive ? inactive : 1;
All of these can be simplified by using ?: (short ternary) form.
> + reg_val = readl(mdata->base + SPI_CFG0_REG);
> + if (mdata->dev_comp->enhance_timing) {
> + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> + reg_val |= (((hold - 1) & 0xffff)
> + << SPI_ADJUST_CFG0_CS_HOLD_OFFSET);
> + reg_val &= ~(0xffff << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> + reg_val |= (((setup - 1) & 0xffff)
> + << SPI_ADJUST_CFG0_CS_SETUP_OFFSET);
> + } else {
> + reg_val &= ~(0xff << SPI_CFG0_CS_HOLD_OFFSET);
> + reg_val |= (((hold - 1) & 0xff) << SPI_CFG0_CS_HOLD_OFFSET);
> + reg_val &= ~(0xff << SPI_CFG0_CS_SETUP_OFFSET);
> + reg_val |= (((setup - 1) & 0xff)
> + << SPI_CFG0_CS_SETUP_OFFSET);
> + }
> + writel(reg_val, mdata->base + SPI_CFG0_REG);
> +
> + reg_val = readl(mdata->base + SPI_CFG1_REG);
> + reg_val &= ~SPI_CFG1_CS_IDLE_MASK;
> + reg_val |= (((inactive - 1) & 0xff) << SPI_CFG1_CS_IDLE_OFFSET);
> + writel(reg_val, mdata->base + SPI_CFG1_REG);
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
2021-08-03 18:20 ` Andy Shevchenko
(?)
@ 2021-08-03 19:30 ` Mark Brown
-1 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2021-08-03 19:30 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Mason Zhang, Matthias Brugger, Laxman Dewangan, linux-spi,
Linux Kernel Mailing List, linux-arm Mailing List,
moderated list:ARM/Mediatek SoC support, Mediatek WSD Upstream
[-- Attachment #1: Type: text/plain, Size: 387 bytes --]
On Tue, Aug 03, 2021 at 09:20:19PM +0300, Andy Shevchenko wrote:
> On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang <Mason.Zhang@mediatek.com> wrote:
> > + inactive = inactive ? inactive : 1;
> All of these can be simplified by using ?: (short ternary) form.
Please don't, if anything just don't use the ternery operator at all for
things like this - it doesn't help with legibility.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
@ 2021-08-03 19:30 ` Mark Brown
0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2021-08-03 19:30 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Mason Zhang, Matthias Brugger, Laxman Dewangan, linux-spi,
Linux Kernel Mailing List, linux-arm Mailing List,
moderated list:ARM/Mediatek SoC support, Mediatek WSD Upstream
[-- Attachment #1.1: Type: text/plain, Size: 387 bytes --]
On Tue, Aug 03, 2021 at 09:20:19PM +0300, Andy Shevchenko wrote:
> On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang <Mason.Zhang@mediatek.com> wrote:
> > + inactive = inactive ? inactive : 1;
> All of these can be simplified by using ?: (short ternary) form.
Please don't, if anything just don't use the ternery operator at all for
things like this - it doesn't help with legibility.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 170 bytes --]
_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback
@ 2021-08-03 19:30 ` Mark Brown
0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2021-08-03 19:30 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Mason Zhang, Matthias Brugger, Laxman Dewangan, linux-spi,
Linux Kernel Mailing List, linux-arm Mailing List,
moderated list:ARM/Mediatek SoC support, Mediatek WSD Upstream
[-- Attachment #1.1: Type: text/plain, Size: 387 bytes --]
On Tue, Aug 03, 2021 at 09:20:19PM +0300, Andy Shevchenko wrote:
> On Tue, Aug 3, 2021 at 1:42 PM Mason Zhang <Mason.Zhang@mediatek.com> wrote:
> > + inactive = inactive ? inactive : 1;
> All of these can be simplified by using ?: (short ternary) form.
Please don't, if anything just don't use the ternery operator at all for
things like this - it doesn't help with legibility.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-08-03 19:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 10:24 [PATCH v2 3/4] spi: mediatek: modify set_cs_timing callback Mason Zhang
2021-08-03 10:24 ` Mason Zhang
2021-08-03 10:24 ` Mason Zhang
2021-08-03 18:20 ` Andy Shevchenko
2021-08-03 18:20 ` Andy Shevchenko
2021-08-03 18:20 ` Andy Shevchenko
2021-08-03 19:30 ` Mark Brown
2021-08-03 19:30 ` Mark Brown
2021-08-03 19:30 ` Mark Brown
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.