Skip to content

Commit a9277a8

Browse files
committed
spi: airoha: add support of en7523 SoC (for 6.19)
Merge series from Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>: Airoha EN7523 snfi controller almost identical to AN7581 one, so the same driver can be used. The only known difference appears in the very specific boot conditions, when attached serial console force EN7523 SoC boots in undocumented (reserved) mode. In this mode dma reading of the flash works incorrectly. This patch series: * add support of EN7523 SoC * add spinand node to en7523 dts (so spinand flash finally becomes usable) * updates dt-bindings to mark driver as compatible with en7523 * disable dma usage to prevent possible data damage if booting in reserved mode was detected.
2 parents 625f43b + de59a8a commit a9277a8

4 files changed

Lines changed: 74 additions & 29 deletions

File tree

Documentation/devicetree/bindings/spi/airoha,en7581-snand.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ allOf:
1414

1515
properties:
1616
compatible:
17-
const: airoha,en7581-snand
17+
oneOf:
18+
- const: airoha,en7581-snand
19+
- items:
20+
- enum:
21+
- airoha,en7523-snand
22+
- const: airoha,en7581-snand
1823

1924
reg:
2025
items:

drivers/spi/spi-airoha-snfi.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,11 @@ static const struct spi_controller_mem_ops airoha_snand_mem_ops = {
10131013
.dirmap_write = airoha_snand_dirmap_write,
10141014
};
10151015

1016+
static const struct spi_controller_mem_ops airoha_snand_nodma_mem_ops = {
1017+
.supports_op = airoha_snand_supports_op,
1018+
.exec_op = airoha_snand_exec_op,
1019+
};
1020+
10161021
static int airoha_snand_setup(struct spi_device *spi)
10171022
{
10181023
struct airoha_snand_ctrl *as_ctrl;
@@ -1057,7 +1062,9 @@ static int airoha_snand_probe(struct platform_device *pdev)
10571062
struct airoha_snand_ctrl *as_ctrl;
10581063
struct device *dev = &pdev->dev;
10591064
struct spi_controller *ctrl;
1065+
bool dma_enable = true;
10601066
void __iomem *base;
1067+
u32 sfc_strap;
10611068
int err;
10621069

10631070
ctrl = devm_spi_alloc_host(dev, sizeof(*as_ctrl));
@@ -1092,12 +1099,28 @@ static int airoha_snand_probe(struct platform_device *pdev)
10921099
return dev_err_probe(dev, PTR_ERR(as_ctrl->spi_clk),
10931100
"unable to get spi clk\n");
10941101

1102+
if (device_is_compatible(dev, "airoha,en7523-snand")) {
1103+
err = regmap_read(as_ctrl->regmap_ctrl,
1104+
REG_SPI_CTRL_SFC_STRAP, &sfc_strap);
1105+
if (err)
1106+
return err;
1107+
1108+
if (!(sfc_strap & 0x04)) {
1109+
dma_enable = false;
1110+
dev_warn(dev, "Detected booting in RESERVED mode (UART_TXD was short to GND).\n");
1111+
dev_warn(dev, "This mode is known for incorrect DMA reading of some flashes.\n");
1112+
dev_warn(dev, "Much slower PIO mode will be used to prevent flash data damage.\n");
1113+
dev_warn(dev, "Unplug UART cable and power cycle board to get full performance.\n");
1114+
}
1115+
}
1116+
10951117
err = dma_set_mask(as_ctrl->dev, DMA_BIT_MASK(32));
10961118
if (err)
10971119
return err;
10981120

10991121
ctrl->num_chipselect = 2;
1100-
ctrl->mem_ops = &airoha_snand_mem_ops;
1122+
ctrl->mem_ops = dma_enable ? &airoha_snand_mem_ops
1123+
: &airoha_snand_nodma_mem_ops;
11011124
ctrl->bits_per_word_mask = SPI_BPW_MASK(8);
11021125
ctrl->mode_bits = SPI_RX_DUAL;
11031126
ctrl->setup = airoha_snand_setup;

sound/soc/stm/stm32_sai.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,30 +138,24 @@ static int stm32_sai_set_sync(struct stm32_sai_data *sai_client,
138138
if (!pdev) {
139139
dev_err(&sai_client->pdev->dev,
140140
"Device not found for node %pOFn\n", np_provider);
141-
of_node_put(np_provider);
142141
return -ENODEV;
143142
}
144143

145144
sai_provider = platform_get_drvdata(pdev);
145+
put_device(&pdev->dev);
146146
if (!sai_provider) {
147147
dev_err(&sai_client->pdev->dev,
148148
"SAI sync provider data not found\n");
149-
ret = -EINVAL;
150-
goto error;
149+
return -EINVAL;
151150
}
152151

153152
/* Configure sync client */
154153
ret = stm32_sai_sync_conf_client(sai_client, synci);
155154
if (ret < 0)
156-
goto error;
155+
return ret;
157156

158157
/* Configure sync provider */
159-
ret = stm32_sai_sync_conf_provider(sai_provider, synco);
160-
161-
error:
162-
put_device(&pdev->dev);
163-
of_node_put(np_provider);
164-
return ret;
158+
return stm32_sai_sync_conf_provider(sai_provider, synco);
165159
}
166160

167161
static int stm32_sai_get_parent_clk(struct stm32_sai_data *sai)

sound/soc/stm/stm32_sai_sub.c

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,8 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev,
15861586
dev_err(&pdev->dev,
15871587
"External synchro not supported\n");
15881588
of_node_put(args.np);
1589-
return -EINVAL;
1589+
ret = -EINVAL;
1590+
goto err_put_sync_provider;
15901591
}
15911592
sai->sync = SAI_SYNC_EXTERNAL;
15921593

@@ -1595,7 +1596,8 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev,
15951596
(sai->synci > (SAI_GCR_SYNCIN_MAX + 1))) {
15961597
dev_err(&pdev->dev, "Wrong SAI index\n");
15971598
of_node_put(args.np);
1598-
return -EINVAL;
1599+
ret = -EINVAL;
1600+
goto err_put_sync_provider;
15991601
}
16001602

16011603
if (of_property_match_string(args.np, "compatible",
@@ -1609,7 +1611,8 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev,
16091611
if (!sai->synco) {
16101612
dev_err(&pdev->dev, "Unknown SAI sub-block\n");
16111613
of_node_put(args.np);
1612-
return -EINVAL;
1614+
ret = -EINVAL;
1615+
goto err_put_sync_provider;
16131616
}
16141617
}
16151618

@@ -1619,13 +1622,15 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev,
16191622

16201623
of_node_put(args.np);
16211624
sai->sai_ck = devm_clk_get(&pdev->dev, "sai_ck");
1622-
if (IS_ERR(sai->sai_ck))
1623-
return dev_err_probe(&pdev->dev, PTR_ERR(sai->sai_ck),
1624-
"Missing kernel clock sai_ck\n");
1625+
if (IS_ERR(sai->sai_ck)) {
1626+
ret = dev_err_probe(&pdev->dev, PTR_ERR(sai->sai_ck),
1627+
"Missing kernel clock sai_ck\n");
1628+
goto err_put_sync_provider;
1629+
}
16251630

16261631
ret = clk_prepare(sai->pdata->pclk);
16271632
if (ret < 0)
1628-
return ret;
1633+
goto err_put_sync_provider;
16291634

16301635
if (STM_SAI_IS_F4(sai->pdata))
16311636
return 0;
@@ -1634,14 +1639,23 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev,
16341639
if (of_property_present(np, "#clock-cells")) {
16351640
ret = stm32_sai_add_mclk_provider(sai);
16361641
if (ret < 0)
1637-
return ret;
1642+
goto err_unprepare_pclk;
16381643
} else {
16391644
sai->sai_mclk = devm_clk_get_optional(&pdev->dev, "MCLK");
1640-
if (IS_ERR(sai->sai_mclk))
1641-
return PTR_ERR(sai->sai_mclk);
1645+
if (IS_ERR(sai->sai_mclk)) {
1646+
ret = PTR_ERR(sai->sai_mclk);
1647+
goto err_unprepare_pclk;
1648+
}
16421649
}
16431650

16441651
return 0;
1652+
1653+
err_unprepare_pclk:
1654+
clk_unprepare(sai->pdata->pclk);
1655+
err_put_sync_provider:
1656+
of_node_put(sai->np_sync_provider);
1657+
1658+
return ret;
16451659
}
16461660

16471661
static int stm32_sai_sub_probe(struct platform_device *pdev)
@@ -1688,26 +1702,34 @@ static int stm32_sai_sub_probe(struct platform_device *pdev)
16881702
IRQF_SHARED, dev_name(&pdev->dev), sai);
16891703
if (ret) {
16901704
dev_err(&pdev->dev, "IRQ request returned %d\n", ret);
1691-
return ret;
1705+
goto err_unprepare_pclk;
16921706
}
16931707

16941708
if (STM_SAI_PROTOCOL_IS_SPDIF(sai))
16951709
conf = &stm32_sai_pcm_config_spdif;
16961710

16971711
ret = snd_dmaengine_pcm_register(&pdev->dev, conf, 0);
1698-
if (ret)
1699-
return dev_err_probe(&pdev->dev, ret, "Could not register pcm dma\n");
1712+
if (ret) {
1713+
ret = dev_err_probe(&pdev->dev, ret, "Could not register pcm dma\n");
1714+
goto err_unprepare_pclk;
1715+
}
17001716

17011717
ret = snd_soc_register_component(&pdev->dev, &stm32_component,
17021718
&sai->cpu_dai_drv, 1);
1703-
if (ret) {
1704-
snd_dmaengine_pcm_unregister(&pdev->dev);
1705-
return ret;
1706-
}
1719+
if (ret)
1720+
goto err_deregister_pcm_dma;
17071721

17081722
pm_runtime_enable(&pdev->dev);
17091723

17101724
return 0;
1725+
1726+
err_deregister_pcm_dma:
1727+
snd_dmaengine_pcm_unregister(&pdev->dev);
1728+
err_unprepare_pclk:
1729+
clk_unprepare(sai->pdata->pclk);
1730+
of_node_put(sai->np_sync_provider);
1731+
1732+
return ret;
17111733
}
17121734

17131735
static void stm32_sai_sub_remove(struct platform_device *pdev)
@@ -1718,6 +1740,7 @@ static void stm32_sai_sub_remove(struct platform_device *pdev)
17181740
snd_dmaengine_pcm_unregister(&pdev->dev);
17191741
snd_soc_unregister_component(&pdev->dev);
17201742
pm_runtime_disable(&pdev->dev);
1743+
of_node_put(sai->np_sync_provider);
17211744
}
17221745

17231746
static int stm32_sai_sub_suspend(struct device *dev)

0 commit comments

Comments
 (0)