Skip to content

Commit 7f790a5

Browse files
author
Jon Lin
committed
spi: rockchip-sfc: Add rockchip,rk3506-fspi compatible
Change-Id: I61f67209b25e1917e656c1c8faa6241df58478b2 Signed-off-by: Jon Lin <[email protected]>
1 parent 89b9a1c commit 7f790a5

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

drivers/spi/spi-rockchip-sfc.c

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
#include <linux/dma-mapping.h>
1616
#include <linux/iopoll.h>
1717
#include <linux/interrupt.h>
18+
#include <linux/mfd/syscon.h>
1819
#include <linux/mm.h>
1920
#include <linux/module.h>
2021
#include <linux/of.h>
2122
#include <linux/pinctrl/consumer.h>
2223
#include <linux/platform_device.h>
2324
#include <linux/pm_runtime.h>
25+
#include <linux/regmap.h>
2426
#include <linux/slab.h>
2527
#include <linux/spi/spi-mem.h>
2628
#include <linux/of_gpio.h>
@@ -197,6 +199,16 @@
197199

198200
#define ROCKCHIP_AUTOSUSPEND_DELAY 2000
199201

202+
struct rockchip_sfc_powergood {
203+
bool valid;
204+
u32 grf_offset;
205+
u8 bits_mask;
206+
};
207+
208+
struct rockchip_sfc_data {
209+
struct rockchip_sfc_powergood powergood;
210+
};
211+
200212
struct rockchip_sfc {
201213
struct device *dev;
202214
void __iomem *regbase;
@@ -218,6 +230,8 @@ struct rockchip_sfc {
218230
struct gpio_desc *rst_gpio;
219231
struct gpio_desc **cs_gpiods;
220232
struct spi_master *master;
233+
struct regmap *grf;
234+
struct rockchip_sfc_data *data;
221235
};
222236

223237
static int rockchip_sfc_reset(struct rockchip_sfc *sfc)
@@ -392,6 +406,7 @@ static int rockchip_sfc_xfer_setup(struct rockchip_sfc *sfc,
392406
{
393407
u32 ctrl = 0, cmd = 0, cmd_ext = 0, dummy_ext = 0;
394408
u8 cs = mem->spi->chip_select;
409+
u32 voltage;
395410

396411
/* set CMD */
397412
if (op->cmd.nbytes == 2) {
@@ -461,6 +476,15 @@ static int rockchip_sfc_xfer_setup(struct rockchip_sfc *sfc,
461476
dev_dbg(sfc->dev, "sfc ctrl=%x cmd=%x cmd_ext=%x addr=%llx dummy_ext=%x len=%x cs=%d\n",
462477
ctrl, cmd, cmd_ext, op->addr.val, cmd_ext, len, cs);
463478

479+
if (sfc->data && sfc->data->powergood.valid) {
480+
if (regmap_read_poll_timeout(sfc->grf, sfc->data->powergood.grf_offset,
481+
voltage, voltage & sfc->data->powergood.bits_mask,
482+
1000, jiffies_to_usecs(HZ))) {
483+
dev_err(sfc->dev, "wait for powergood failed\n");
484+
return -EIO;
485+
}
486+
}
487+
464488
if (cmd_ext)
465489
writel(cmd_ext, sfc->regbase + SFC_CMD_EXT);
466490
if (sfc->version >= SFC_VER_8)
@@ -900,6 +924,22 @@ static int rockchip_sfc_get_gpio_descs(struct spi_controller *ctlr, struct rockc
900924
return 0;
901925
}
902926

927+
static const struct rockchip_sfc_data rk3506_fspi_data = {
928+
.powergood = {
929+
.valid = true,
930+
.grf_offset = 0x100,
931+
.bits_mask = BIT(0),
932+
},
933+
};
934+
935+
static const struct of_device_id rockchip_sfc_dt_ids[] = {
936+
{ .compatible = "rockchip,fspi",},
937+
{ .compatible = "rockchip,rk3506-fspi", .data = &rk3506_fspi_data},
938+
{ .compatible = "rockchip,sfc"},
939+
{ /* sentinel */ }
940+
};
941+
MODULE_DEVICE_TABLE(of, rockchip_sfc_dt_ids);
942+
903943
static int rockchip_sfc_probe(struct platform_device *pdev)
904944
{
905945
struct device *dev = &pdev->dev;
@@ -992,6 +1032,17 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
9921032
goto err_irq;
9931033
}
9941034

1035+
sfc->data = (struct rockchip_sfc_data *)device_get_match_data(&pdev->dev);
1036+
if (sfc->data) {
1037+
sfc->grf = syscon_regmap_lookup_by_phandle_optional(dev->of_node, "rockchip,grf");
1038+
if (IS_ERR_OR_NULL(sfc->grf)) {
1039+
ret = -EINVAL;
1040+
dev_err(dev, "Failed to find grf\n");
1041+
1042+
goto err_irq;
1043+
}
1044+
}
1045+
9951046
platform_set_drvdata(pdev, sfc);
9961047

9971048
if (IS_ENABLED(CONFIG_ROCKCHIP_THUNDER_BOOT)) {
@@ -1149,13 +1200,6 @@ static const struct dev_pm_ops rockchip_sfc_pm_ops = {
11491200
SET_SYSTEM_SLEEP_PM_OPS(rockchip_sfc_suspend, rockchip_sfc_resume)
11501201
};
11511202

1152-
static const struct of_device_id rockchip_sfc_dt_ids[] = {
1153-
{ .compatible = "rockchip,fspi"},
1154-
{ .compatible = "rockchip,sfc"},
1155-
{ /* sentinel */ }
1156-
};
1157-
MODULE_DEVICE_TABLE(of, rockchip_sfc_dt_ids);
1158-
11591203
static struct platform_driver rockchip_sfc_driver = {
11601204
.driver = {
11611205
.name = "rockchip-sfc",

0 commit comments

Comments
 (0)