Skip to content

Commit 783bf5d

Browse files
NXP-CarlosSongbroonie
authored andcommitted
spi: spi-fsl-lpspi: limit PRESCALE bit in TCR register
Referring to the errata ERR051608 of I.MX93, LPSPI TCR[PRESCALE] can only be configured to be 0 or 1, other values are not valid and will cause LPSPI to not work. Add the prescale limitation for LPSPI in I.MX93. Other platforms are not affected. Signed-off-by: Carlos Song <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 57d5af2 commit 783bf5d

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

drivers/spi/spi-fsl-lpspi.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
#define TCR_RXMSK BIT(19)
8383
#define TCR_TXMSK BIT(18)
8484

85+
struct fsl_lpspi_devtype_data {
86+
u8 prescale_max;
87+
};
88+
8589
struct lpspi_config {
8690
u8 bpw;
8791
u8 chip_select;
@@ -119,10 +123,25 @@ struct fsl_lpspi_data {
119123
bool usedma;
120124
struct completion dma_rx_completion;
121125
struct completion dma_tx_completion;
126+
127+
const struct fsl_lpspi_devtype_data *devtype_data;
128+
};
129+
130+
/*
131+
* ERR051608 fixed or not:
132+
* https://www.nxp.com/docs/en/errata/i.MX93_1P87f.pdf
133+
*/
134+
static struct fsl_lpspi_devtype_data imx93_lpspi_devtype_data = {
135+
.prescale_max = 1,
136+
};
137+
138+
static struct fsl_lpspi_devtype_data imx7ulp_lpspi_devtype_data = {
139+
.prescale_max = 8,
122140
};
123141

124142
static const struct of_device_id fsl_lpspi_dt_ids[] = {
125-
{ .compatible = "fsl,imx7ulp-spi", },
143+
{ .compatible = "fsl,imx7ulp-spi", .data = &imx7ulp_lpspi_devtype_data,},
144+
{ .compatible = "fsl,imx93-spi", .data = &imx93_lpspi_devtype_data,},
126145
{ /* sentinel */ }
127146
};
128147
MODULE_DEVICE_TABLE(of, fsl_lpspi_dt_ids);
@@ -297,9 +316,11 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
297316
{
298317
struct lpspi_config config = fsl_lpspi->config;
299318
unsigned int perclk_rate, scldiv, div;
319+
u8 prescale_max;
300320
u8 prescale;
301321

302322
perclk_rate = clk_get_rate(fsl_lpspi->clk_per);
323+
prescale_max = fsl_lpspi->devtype_data->prescale_max;
303324

304325
if (!config.speed_hz) {
305326
dev_err(fsl_lpspi->dev,
@@ -315,7 +336,7 @@ static int fsl_lpspi_set_bitrate(struct fsl_lpspi_data *fsl_lpspi)
315336

316337
div = DIV_ROUND_UP(perclk_rate, config.speed_hz);
317338

318-
for (prescale = 0; prescale < 8; prescale++) {
339+
for (prescale = 0; prescale < prescale_max; prescale++) {
319340
scldiv = div / (1 << prescale) - 2;
320341
if (scldiv < 256) {
321342
fsl_lpspi->config.prescale = prescale;
@@ -822,6 +843,7 @@ static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi)
822843

823844
static int fsl_lpspi_probe(struct platform_device *pdev)
824845
{
846+
const struct fsl_lpspi_devtype_data *devtype_data;
825847
struct fsl_lpspi_data *fsl_lpspi;
826848
struct spi_controller *controller;
827849
struct resource *res;
@@ -830,6 +852,10 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
830852
u32 temp;
831853
bool is_target;
832854

855+
devtype_data = of_device_get_match_data(&pdev->dev);
856+
if (!devtype_data)
857+
return -ENODEV;
858+
833859
is_target = of_property_read_bool((&pdev->dev)->of_node, "spi-slave");
834860
if (is_target)
835861
controller = devm_spi_alloc_target(&pdev->dev,
@@ -848,6 +874,7 @@ static int fsl_lpspi_probe(struct platform_device *pdev)
848874
fsl_lpspi->is_target = is_target;
849875
fsl_lpspi->is_only_cs1 = of_property_read_bool((&pdev->dev)->of_node,
850876
"fsl,spi-only-use-cs1-sel");
877+
fsl_lpspi->devtype_data = devtype_data;
851878

852879
init_completion(&fsl_lpspi->xfer_done);
853880

0 commit comments

Comments
 (0)