15
15
#include <linux/dma-mapping.h>
16
16
#include <linux/iopoll.h>
17
17
#include <linux/interrupt.h>
18
+ #include <linux/mfd/syscon.h>
18
19
#include <linux/mm.h>
19
20
#include <linux/module.h>
20
21
#include <linux/of.h>
21
22
#include <linux/pinctrl/consumer.h>
22
23
#include <linux/platform_device.h>
23
24
#include <linux/pm_runtime.h>
25
+ #include <linux/regmap.h>
24
26
#include <linux/slab.h>
25
27
#include <linux/spi/spi-mem.h>
26
28
#include <linux/of_gpio.h>
197
199
198
200
#define ROCKCHIP_AUTOSUSPEND_DELAY 2000
199
201
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
+
200
212
struct rockchip_sfc {
201
213
struct device * dev ;
202
214
void __iomem * regbase ;
@@ -218,6 +230,8 @@ struct rockchip_sfc {
218
230
struct gpio_desc * rst_gpio ;
219
231
struct gpio_desc * * cs_gpiods ;
220
232
struct spi_master * master ;
233
+ struct regmap * grf ;
234
+ struct rockchip_sfc_data * data ;
221
235
};
222
236
223
237
static int rockchip_sfc_reset (struct rockchip_sfc * sfc )
@@ -392,6 +406,7 @@ static int rockchip_sfc_xfer_setup(struct rockchip_sfc *sfc,
392
406
{
393
407
u32 ctrl = 0 , cmd = 0 , cmd_ext = 0 , dummy_ext = 0 ;
394
408
u8 cs = mem -> spi -> chip_select ;
409
+ u32 voltage ;
395
410
396
411
/* set CMD */
397
412
if (op -> cmd .nbytes == 2 ) {
@@ -461,6 +476,15 @@ static int rockchip_sfc_xfer_setup(struct rockchip_sfc *sfc,
461
476
dev_dbg (sfc -> dev , "sfc ctrl=%x cmd=%x cmd_ext=%x addr=%llx dummy_ext=%x len=%x cs=%d\n" ,
462
477
ctrl , cmd , cmd_ext , op -> addr .val , cmd_ext , len , cs );
463
478
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
+
464
488
if (cmd_ext )
465
489
writel (cmd_ext , sfc -> regbase + SFC_CMD_EXT );
466
490
if (sfc -> version >= SFC_VER_8 )
@@ -900,6 +924,22 @@ static int rockchip_sfc_get_gpio_descs(struct spi_controller *ctlr, struct rockc
900
924
return 0 ;
901
925
}
902
926
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
+
903
943
static int rockchip_sfc_probe (struct platform_device * pdev )
904
944
{
905
945
struct device * dev = & pdev -> dev ;
@@ -992,6 +1032,17 @@ static int rockchip_sfc_probe(struct platform_device *pdev)
992
1032
goto err_irq ;
993
1033
}
994
1034
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
+
995
1046
platform_set_drvdata (pdev , sfc );
996
1047
997
1048
if (IS_ENABLED (CONFIG_ROCKCHIP_THUNDER_BOOT )) {
@@ -1149,13 +1200,6 @@ static const struct dev_pm_ops rockchip_sfc_pm_ops = {
1149
1200
SET_SYSTEM_SLEEP_PM_OPS (rockchip_sfc_suspend , rockchip_sfc_resume )
1150
1201
};
1151
1202
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
-
1159
1203
static struct platform_driver rockchip_sfc_driver = {
1160
1204
.driver = {
1161
1205
.name = "rockchip-sfc" ,
0 commit comments