Skip to content

Commit 3a01f04

Browse files
ffainellibroonie
authored andcommitted
spi: bcm-qspi: Handle lack of MSPI_REV offset
Older MIPS chips have a QSPI/MSPI controller that does not have the MSPI_REV offset, reading from that offset will cause a bus error. Match their compatible string and do not perform a read from that register in that case. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Kamal Dasu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 66eb228 commit 3a01f04

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

drivers/spi/spi-bcm-qspi.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#define MSPI_MSPI_STATUS 0x020
9292
#define MSPI_CPTQP 0x024
9393
#define MSPI_SPCR3 0x028
94+
#define MSPI_REV 0x02c
9495
#define MSPI_TXRAM 0x040
9596
#define MSPI_RXRAM 0x0c0
9697
#define MSPI_CDRAM 0x140
@@ -217,6 +218,8 @@ struct bcm_qspi {
217218
struct bcm_qspi_dev_id *dev_ids;
218219
struct completion mspi_done;
219220
struct completion bspi_done;
221+
u8 mspi_maj_rev;
222+
u8 mspi_min_rev;
220223
};
221224

222225
static inline bool has_bspi(struct bcm_qspi *qspi)
@@ -1190,31 +1193,64 @@ static const struct spi_controller_mem_ops bcm_qspi_mem_ops = {
11901193
.exec_op = bcm_qspi_exec_mem_op,
11911194
};
11921195

1196+
struct bcm_qspi_data {
1197+
bool has_mspi_rev;
1198+
};
1199+
1200+
static const struct bcm_qspi_data bcm_qspi_no_rev_data = {
1201+
.has_mspi_rev = false,
1202+
};
1203+
1204+
static const struct bcm_qspi_data bcm_qspi_rev_data = {
1205+
.has_mspi_rev = true,
1206+
};
1207+
11931208
static const struct of_device_id bcm_qspi_of_match[] = {
1194-
{ .compatible = "brcm,spi-bcm-qspi" },
1209+
{
1210+
.compatible = "brcm,spi-bcm7425-qspi",
1211+
.data = &bcm_qspi_no_rev_data,
1212+
},
1213+
{
1214+
.compatible = "brcm,spi-bcm7429-qspi",
1215+
.data = &bcm_qspi_no_rev_data,
1216+
},
1217+
{
1218+
.compatible = "brcm,spi-bcm7435-qspi",
1219+
.data = &bcm_qspi_no_rev_data,
1220+
},
1221+
{
1222+
.compatible = "brcm,spi-bcm-qspi",
1223+
.data = &bcm_qspi_rev_data,
1224+
},
11951225
{},
11961226
};
11971227
MODULE_DEVICE_TABLE(of, bcm_qspi_of_match);
11981228

11991229
int bcm_qspi_probe(struct platform_device *pdev,
12001230
struct bcm_qspi_soc_intc *soc_intc)
12011231
{
1232+
const struct of_device_id *of_id = NULL;
1233+
const struct bcm_qspi_data *data;
12021234
struct device *dev = &pdev->dev;
12031235
struct bcm_qspi *qspi;
12041236
struct spi_master *master;
12051237
struct resource *res;
12061238
int irq, ret = 0, num_ints = 0;
12071239
u32 val;
1240+
u32 rev = 0;
12081241
const char *name = NULL;
12091242
int num_irqs = ARRAY_SIZE(qspi_irq_tab);
12101243

12111244
/* We only support device-tree instantiation */
12121245
if (!dev->of_node)
12131246
return -ENODEV;
12141247

1215-
if (!of_match_node(bcm_qspi_of_match, dev->of_node))
1248+
of_id = of_match_node(bcm_qspi_of_match, dev->of_node);
1249+
if (!of_id)
12161250
return -ENODEV;
12171251

1252+
data = of_id->data;
1253+
12181254
master = spi_alloc_master(dev, sizeof(struct bcm_qspi));
12191255
if (!master) {
12201256
dev_err(dev, "error allocating spi_master\n");
@@ -1351,6 +1387,16 @@ int bcm_qspi_probe(struct platform_device *pdev,
13511387
qspi->base_clk = clk_get_rate(qspi->clk);
13521388
qspi->max_speed_hz = qspi->base_clk / (QSPI_SPBR_MIN * 2);
13531389

1390+
if (data->has_mspi_rev) {
1391+
rev = bcm_qspi_read(qspi, MSPI, MSPI_REV);
1392+
/* some older revs do not have a MSPI_REV register */
1393+
if ((rev & 0xff) == 0xff)
1394+
rev = 0;
1395+
}
1396+
1397+
qspi->mspi_maj_rev = (rev >> 4) & 0xf;
1398+
qspi->mspi_min_rev = rev & 0xf;
1399+
13541400
bcm_qspi_hw_init(qspi);
13551401
init_completion(&qspi->mspi_done);
13561402
init_completion(&qspi->bspi_done);

0 commit comments

Comments
 (0)