Lines Matching +full:fmc2 +full:- +full:ebi +full:- +full:cs +full:- +full:data +full:- +full:setup +full:- +full:ns
1 // SPDX-License-Identifier: GPL-2.0
18 /* FMC2 Controller Registers */
185 int (*nwait_used_by_ctrls)(struct stm32_fmc2_ebi *ebi);
186 void (*set_setup)(struct stm32_fmc2_ebi *ebi);
187 int (*save_setup)(struct stm32_fmc2_ebi *ebi);
188 int (*check_rif)(struct stm32_fmc2_ebi *ebi, u32 resource);
189 void (*put_sems)(struct stm32_fmc2_ebi *ebi);
190 void (*get_sems)(struct stm32_fmc2_ebi *ebi);
197 const struct stm32_fmc2_ebi_data *data; member
210 * struct stm32_fmc2_prop - STM32 FMC2 EBI property
233 int (*check)(struct stm32_fmc2_ebi *ebi,
234 const struct stm32_fmc2_prop *prop, int cs);
235 u32 (*calculate)(struct stm32_fmc2_ebi *ebi, int cs, u32 setup);
236 int (*set)(struct stm32_fmc2_ebi *ebi,
238 int cs, u32 setup);
241 static int stm32_fmc2_ebi_check_mux(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_mux() argument
243 int cs) in stm32_fmc2_ebi_check_mux() argument
248 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_check_mux()
255 return -EINVAL; in stm32_fmc2_ebi_check_mux()
258 static int stm32_fmc2_ebi_check_waitcfg(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_waitcfg() argument
260 int cs) in stm32_fmc2_ebi_check_waitcfg() argument
265 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_check_waitcfg()
272 return -EINVAL; in stm32_fmc2_ebi_check_waitcfg()
275 static int stm32_fmc2_ebi_check_sync_trans(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_sync_trans() argument
277 int cs) in stm32_fmc2_ebi_check_sync_trans() argument
282 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_check_sync_trans()
289 return -EINVAL; in stm32_fmc2_ebi_check_sync_trans()
292 static int stm32_fmc2_ebi_mp25_check_cclk(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_mp25_check_cclk() argument
294 int cs) in stm32_fmc2_ebi_mp25_check_cclk() argument
296 if (!ebi->access_granted) in stm32_fmc2_ebi_mp25_check_cclk()
297 return -EACCES; in stm32_fmc2_ebi_mp25_check_cclk()
299 return stm32_fmc2_ebi_check_sync_trans(ebi, prop, cs); in stm32_fmc2_ebi_mp25_check_cclk()
302 static int stm32_fmc2_ebi_mp25_check_clk_period(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_mp25_check_clk_period() argument
304 int cs) in stm32_fmc2_ebi_mp25_check_clk_period() argument
309 ret = regmap_read(ebi->regmap, FMC2_CFGR, &cfgr); in stm32_fmc2_ebi_mp25_check_clk_period()
313 if (cfgr & FMC2_CFGR_CCLKEN && !ebi->access_granted) in stm32_fmc2_ebi_mp25_check_clk_period()
314 return -EACCES; in stm32_fmc2_ebi_mp25_check_clk_period()
316 return stm32_fmc2_ebi_check_sync_trans(ebi, prop, cs); in stm32_fmc2_ebi_mp25_check_clk_period()
319 static int stm32_fmc2_ebi_check_async_trans(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_async_trans() argument
321 int cs) in stm32_fmc2_ebi_check_async_trans() argument
326 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_check_async_trans()
333 return -EINVAL; in stm32_fmc2_ebi_check_async_trans()
336 static int stm32_fmc2_ebi_check_cpsize(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_cpsize() argument
338 int cs) in stm32_fmc2_ebi_check_cpsize() argument
343 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_check_cpsize()
350 return -EINVAL; in stm32_fmc2_ebi_check_cpsize()
353 static int stm32_fmc2_ebi_check_address_hold(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_address_hold() argument
355 int cs) in stm32_fmc2_ebi_check_address_hold() argument
360 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_check_address_hold()
364 if (prop->reg_type == FMC2_REG_BWTR) in stm32_fmc2_ebi_check_address_hold()
365 ret = regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr); in stm32_fmc2_ebi_check_address_hold()
367 ret = regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr); in stm32_fmc2_ebi_check_address_hold()
375 return -EINVAL; in stm32_fmc2_ebi_check_address_hold()
378 static int stm32_fmc2_ebi_check_clk_period(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_clk_period() argument
380 int cs) in stm32_fmc2_ebi_check_clk_period() argument
385 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_check_clk_period()
389 if (cs) { in stm32_fmc2_ebi_check_clk_period()
390 ret = regmap_read(ebi->regmap, FMC2_BCR1, &bcr1); in stm32_fmc2_ebi_check_clk_period()
397 if (bcr & FMC2_BCR_BURSTEN && (!cs || !(bcr1 & FMC2_BCR1_CCLKEN))) in stm32_fmc2_ebi_check_clk_period()
400 return -EINVAL; in stm32_fmc2_ebi_check_clk_period()
403 static int stm32_fmc2_ebi_check_cclk(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_check_cclk() argument
405 int cs) in stm32_fmc2_ebi_check_cclk() argument
407 if (cs) in stm32_fmc2_ebi_check_cclk()
408 return -EINVAL; in stm32_fmc2_ebi_check_cclk()
410 return stm32_fmc2_ebi_check_sync_trans(ebi, prop, cs); in stm32_fmc2_ebi_check_cclk()
413 static u32 stm32_fmc2_ebi_ns_to_clock_cycles(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_ns_to_clock_cycles() argument
414 int cs, u32 setup) in stm32_fmc2_ebi_ns_to_clock_cycles() argument
416 unsigned long hclk = clk_get_rate(ebi->clk); in stm32_fmc2_ebi_ns_to_clock_cycles()
419 return DIV_ROUND_UP(setup * 1000, hclkp); in stm32_fmc2_ebi_ns_to_clock_cycles()
422 static u32 stm32_fmc2_ebi_ns_to_clk_period(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_ns_to_clk_period() argument
423 int cs, u32 setup) in stm32_fmc2_ebi_ns_to_clk_period() argument
425 u32 nb_clk_cycles = stm32_fmc2_ebi_ns_to_clock_cycles(ebi, cs, setup); in stm32_fmc2_ebi_ns_to_clk_period()
429 ret = regmap_read(ebi->regmap, FMC2_BCR1, &bcr); in stm32_fmc2_ebi_ns_to_clk_period()
433 if (bcr & FMC2_BCR1_CCLKEN || !cs) in stm32_fmc2_ebi_ns_to_clk_period()
434 ret = regmap_read(ebi->regmap, FMC2_BTR1, &btr); in stm32_fmc2_ebi_ns_to_clk_period()
436 ret = regmap_read(ebi->regmap, FMC2_BTR(cs), &btr); in stm32_fmc2_ebi_ns_to_clk_period()
445 static u32 stm32_fmc2_ebi_mp25_ns_to_clk_period(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_mp25_ns_to_clk_period() argument
446 int cs, u32 setup) in stm32_fmc2_ebi_mp25_ns_to_clk_period() argument
448 u32 nb_clk_cycles = stm32_fmc2_ebi_ns_to_clock_cycles(ebi, cs, setup); in stm32_fmc2_ebi_mp25_ns_to_clk_period()
452 ret = regmap_read(ebi->regmap, FMC2_CFGR, &cfgr); in stm32_fmc2_ebi_mp25_ns_to_clk_period()
459 ret = regmap_read(ebi->regmap, FMC2_BTR(cs), &btr); in stm32_fmc2_ebi_mp25_ns_to_clk_period()
469 static int stm32_fmc2_ebi_get_reg(int reg_type, int cs, u32 *reg) in stm32_fmc2_ebi_get_reg() argument
473 *reg = FMC2_BCR(cs); in stm32_fmc2_ebi_get_reg()
476 *reg = FMC2_BTR(cs); in stm32_fmc2_ebi_get_reg()
479 *reg = FMC2_BWTR(cs); in stm32_fmc2_ebi_get_reg()
488 return -EINVAL; in stm32_fmc2_ebi_get_reg()
494 static int stm32_fmc2_ebi_set_bit_field(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_bit_field() argument
496 int cs, u32 setup) in stm32_fmc2_ebi_set_bit_field() argument
501 ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, ®); in stm32_fmc2_ebi_set_bit_field()
505 regmap_update_bits(ebi->regmap, reg, prop->reg_mask, in stm32_fmc2_ebi_set_bit_field()
506 setup ? prop->reg_mask : 0); in stm32_fmc2_ebi_set_bit_field()
511 static int stm32_fmc2_ebi_set_trans_type(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_trans_type() argument
513 int cs, u32 setup) in stm32_fmc2_ebi_set_trans_type() argument
525 switch (setup) { in stm32_fmc2_ebi_set_trans_type()
632 return -EINVAL; in stm32_fmc2_ebi_set_trans_type()
636 regmap_update_bits(ebi->regmap, FMC2_BWTR(cs), in stm32_fmc2_ebi_set_trans_type()
638 regmap_update_bits(ebi->regmap, FMC2_BTR(cs), btr_mask, btr); in stm32_fmc2_ebi_set_trans_type()
639 regmap_update_bits(ebi->regmap, FMC2_BCR(cs), bcr_mask, bcr); in stm32_fmc2_ebi_set_trans_type()
644 static int stm32_fmc2_ebi_set_buswidth(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_buswidth() argument
646 int cs, u32 setup) in stm32_fmc2_ebi_set_buswidth() argument
650 switch (setup) { in stm32_fmc2_ebi_set_buswidth()
659 return -EINVAL; in stm32_fmc2_ebi_set_buswidth()
662 regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_MWID, val); in stm32_fmc2_ebi_set_buswidth()
667 static int stm32_fmc2_ebi_set_cpsize(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_cpsize() argument
669 int cs, u32 setup) in stm32_fmc2_ebi_set_cpsize() argument
673 switch (setup) { in stm32_fmc2_ebi_set_cpsize()
691 return -EINVAL; in stm32_fmc2_ebi_set_cpsize()
694 regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_CPSIZE, val); in stm32_fmc2_ebi_set_cpsize()
699 static int stm32_fmc2_ebi_set_bl_setup(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_bl_setup() argument
701 int cs, u32 setup) in stm32_fmc2_ebi_set_bl_setup() argument
705 val = min_t(u32, setup, FMC2_BCR_NBLSET_MAX); in stm32_fmc2_ebi_set_bl_setup()
707 regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_NBLSET, val); in stm32_fmc2_ebi_set_bl_setup()
712 static int stm32_fmc2_ebi_set_address_setup(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_address_setup() argument
714 int cs, u32 setup) in stm32_fmc2_ebi_set_address_setup() argument
720 ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, ®); in stm32_fmc2_ebi_set_address_setup()
724 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_set_address_setup()
728 if (prop->reg_type == FMC2_REG_BWTR) in stm32_fmc2_ebi_set_address_setup()
729 ret = regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr); in stm32_fmc2_ebi_set_address_setup()
731 ret = regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr); in stm32_fmc2_ebi_set_address_setup()
736 val = clamp_val(setup, 1, FMC2_BXTR_ADDSET_MAX); in stm32_fmc2_ebi_set_address_setup()
738 val = min_t(u32, setup, FMC2_BXTR_ADDSET_MAX); in stm32_fmc2_ebi_set_address_setup()
740 regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_ADDSET, val); in stm32_fmc2_ebi_set_address_setup()
745 static int stm32_fmc2_ebi_set_address_hold(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_address_hold() argument
747 int cs, u32 setup) in stm32_fmc2_ebi_set_address_hold() argument
752 ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, ®); in stm32_fmc2_ebi_set_address_hold()
756 val = clamp_val(setup, 1, FMC2_BXTR_ADDHLD_MAX); in stm32_fmc2_ebi_set_address_hold()
758 regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_ADDHLD, val); in stm32_fmc2_ebi_set_address_hold()
763 static int stm32_fmc2_ebi_set_data_setup(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_data_setup() argument
765 int cs, u32 setup) in stm32_fmc2_ebi_set_data_setup() argument
770 ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, ®); in stm32_fmc2_ebi_set_data_setup()
774 val = clamp_val(setup, 1, FMC2_BXTR_DATAST_MAX); in stm32_fmc2_ebi_set_data_setup()
776 regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_DATAST, val); in stm32_fmc2_ebi_set_data_setup()
781 static int stm32_fmc2_ebi_set_bus_turnaround(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_bus_turnaround() argument
783 int cs, u32 setup) in stm32_fmc2_ebi_set_bus_turnaround() argument
788 ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, ®); in stm32_fmc2_ebi_set_bus_turnaround()
792 val = setup ? min_t(u32, setup - 1, FMC2_BXTR_BUSTURN_MAX) : 0; in stm32_fmc2_ebi_set_bus_turnaround()
794 regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_BUSTURN, val); in stm32_fmc2_ebi_set_bus_turnaround()
799 static int stm32_fmc2_ebi_set_data_hold(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_data_hold() argument
801 int cs, u32 setup) in stm32_fmc2_ebi_set_data_hold() argument
806 ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, ®); in stm32_fmc2_ebi_set_data_hold()
810 if (prop->reg_type == FMC2_REG_BWTR) in stm32_fmc2_ebi_set_data_hold()
811 val = setup ? min_t(u32, setup - 1, FMC2_BXTR_DATAHLD_MAX) : 0; in stm32_fmc2_ebi_set_data_hold()
813 val = min_t(u32, setup, FMC2_BXTR_DATAHLD_MAX); in stm32_fmc2_ebi_set_data_hold()
815 regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_DATAHLD, val); in stm32_fmc2_ebi_set_data_hold()
820 static int stm32_fmc2_ebi_set_clk_period(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_clk_period() argument
822 int cs, u32 setup) in stm32_fmc2_ebi_set_clk_period() argument
826 val = setup ? clamp_val(setup - 1, 1, FMC2_BTR_CLKDIV_MAX) : 1; in stm32_fmc2_ebi_set_clk_period()
828 regmap_update_bits(ebi->regmap, FMC2_BTR(cs), FMC2_BTR_CLKDIV, val); in stm32_fmc2_ebi_set_clk_period()
833 static int stm32_fmc2_ebi_mp25_set_clk_period(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_mp25_set_clk_period() argument
835 int cs, u32 setup) in stm32_fmc2_ebi_mp25_set_clk_period() argument
840 ret = regmap_read(ebi->regmap, FMC2_CFGR, &cfgr); in stm32_fmc2_ebi_mp25_set_clk_period()
845 val = setup ? clamp_val(setup - 1, 1, FMC2_CFGR_CLKDIV_MAX) : 1; in stm32_fmc2_ebi_mp25_set_clk_period()
847 regmap_update_bits(ebi->regmap, FMC2_CFGR, FMC2_CFGR_CLKDIV, val); in stm32_fmc2_ebi_mp25_set_clk_period()
849 val = setup ? clamp_val(setup - 1, 1, FMC2_BTR_CLKDIV_MAX) : 1; in stm32_fmc2_ebi_mp25_set_clk_period()
851 regmap_update_bits(ebi->regmap, FMC2_BTR(cs), FMC2_BTR_CLKDIV, val); in stm32_fmc2_ebi_mp25_set_clk_period()
857 static int stm32_fmc2_ebi_set_data_latency(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_data_latency() argument
859 int cs, u32 setup) in stm32_fmc2_ebi_set_data_latency() argument
863 val = setup > 1 ? min_t(u32, setup - 2, FMC2_BTR_DATLAT_MAX) : 0; in stm32_fmc2_ebi_set_data_latency()
865 regmap_update_bits(ebi->regmap, FMC2_BTR(cs), FMC2_BTR_DATLAT, val); in stm32_fmc2_ebi_set_data_latency()
870 static int stm32_fmc2_ebi_set_max_low_pulse(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_set_max_low_pulse() argument
872 int cs, u32 setup) in stm32_fmc2_ebi_set_max_low_pulse() argument
877 if (setup < 1) in stm32_fmc2_ebi_set_max_low_pulse()
880 ret = regmap_read(ebi->regmap, FMC2_PCSCNTR, &pcscntr); in stm32_fmc2_ebi_set_max_low_pulse()
885 regmap_update_bits(ebi->regmap, FMC2_PCSCNTR, in stm32_fmc2_ebi_set_max_low_pulse()
886 FMC2_PCSCNTR_CNTBEN(cs), in stm32_fmc2_ebi_set_max_low_pulse()
887 FMC2_PCSCNTR_CNTBEN(cs)); in stm32_fmc2_ebi_set_max_low_pulse()
889 new_val = min_t(u32, setup - 1, FMC2_PCSCNTR_CSCOUNT_MAX); in stm32_fmc2_ebi_set_max_low_pulse()
896 regmap_update_bits(ebi->regmap, FMC2_PCSCNTR, in stm32_fmc2_ebi_set_max_low_pulse()
902 static int stm32_fmc2_ebi_mp25_set_max_low_pulse(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_mp25_set_max_low_pulse() argument
904 int cs, u32 setup) in stm32_fmc2_ebi_mp25_set_max_low_pulse() argument
908 if (setup == FMC2_CSCOUNT_0) in stm32_fmc2_ebi_mp25_set_max_low_pulse()
910 else if (setup == FMC2_CSCOUNT_1) in stm32_fmc2_ebi_mp25_set_max_low_pulse()
912 else if (setup <= FMC2_CSCOUNT_64) in stm32_fmc2_ebi_mp25_set_max_low_pulse()
917 regmap_update_bits(ebi->regmap, FMC2_BCR(cs), in stm32_fmc2_ebi_mp25_set_max_low_pulse()
924 /* st,fmc2-ebi-cs-trans-type must be the first property */
926 .name = "st,fmc2-ebi-cs-transaction-type",
931 .name = "st,fmc2-ebi-cs-cclk-enable",
939 .name = "st,fmc2-ebi-cs-mux-enable",
947 .name = "st,fmc2-ebi-cs-buswidth",
952 .name = "st,fmc2-ebi-cs-waitpol-high",
959 .name = "st,fmc2-ebi-cs-waitcfg-enable",
967 .name = "st,fmc2-ebi-cs-wait-enable",
975 .name = "st,fmc2-ebi-cs-asyncwait-enable",
983 .name = "st,fmc2-ebi-cs-cpsize",
988 .name = "st,fmc2-ebi-cs-byte-lane-setup-ns",
993 .name = "st,fmc2-ebi-cs-address-setup-ns",
1001 .name = "st,fmc2-ebi-cs-address-hold-ns",
1009 .name = "st,fmc2-ebi-cs-data-setup-ns",
1017 .name = "st,fmc2-ebi-cs-bus-turnaround-ns",
1024 .name = "st,fmc2-ebi-cs-data-hold-ns",
1031 .name = "st,fmc2-ebi-cs-clk-period-ns",
1038 .name = "st,fmc2-ebi-cs-data-latency-ns",
1044 .name = "st,fmc2-ebi-cs-write-address-setup-ns",
1052 .name = "st,fmc2-ebi-cs-write-address-hold-ns",
1060 .name = "st,fmc2-ebi-cs-write-data-setup-ns",
1068 .name = "st,fmc2-ebi-cs-write-bus-turnaround-ns",
1075 .name = "st,fmc2-ebi-cs-write-data-hold-ns",
1082 .name = "st,fmc2-ebi-cs-max-low-pulse-ns",
1089 /* st,fmc2-ebi-cs-trans-type must be the first property */
1091 .name = "st,fmc2-ebi-cs-transaction-type",
1096 .name = "st,fmc2-ebi-cs-cclk-enable",
1104 .name = "st,fmc2-ebi-cs-mux-enable",
1112 .name = "st,fmc2-ebi-cs-buswidth",
1117 .name = "st,fmc2-ebi-cs-waitpol-high",
1124 .name = "st,fmc2-ebi-cs-waitcfg-enable",
1132 .name = "st,fmc2-ebi-cs-wait-enable",
1140 .name = "st,fmc2-ebi-cs-asyncwait-enable",
1148 .name = "st,fmc2-ebi-cs-cpsize",
1153 .name = "st,fmc2-ebi-cs-byte-lane-setup-ns",
1158 .name = "st,fmc2-ebi-cs-address-setup-ns",
1166 .name = "st,fmc2-ebi-cs-address-hold-ns",
1174 .name = "st,fmc2-ebi-cs-data-setup-ns",
1182 .name = "st,fmc2-ebi-cs-bus-turnaround-ns",
1189 .name = "st,fmc2-ebi-cs-data-hold-ns",
1196 .name = "st,fmc2-ebi-cs-clk-period-ns",
1203 .name = "st,fmc2-ebi-cs-data-latency-ns",
1209 .name = "st,fmc2-ebi-cs-write-address-setup-ns",
1217 .name = "st,fmc2-ebi-cs-write-address-hold-ns",
1225 .name = "st,fmc2-ebi-cs-write-data-setup-ns",
1233 .name = "st,fmc2-ebi-cs-write-bus-turnaround-ns",
1240 .name = "st,fmc2-ebi-cs-write-data-hold-ns",
1247 .name = "st,fmc2-ebi-cs-max-low-pulse-ns",
1253 static int stm32_fmc2_ebi_mp25_check_rif(struct stm32_fmc2_ebi *ebi, u32 resource) in stm32_fmc2_ebi_mp25_check_rif() argument
1259 return -EINVAL; in stm32_fmc2_ebi_mp25_check_rif()
1261 ret = regmap_read(ebi->regmap, FMC2_SECCFGR, &seccfgr); in stm32_fmc2_ebi_mp25_check_rif()
1267 dev_err(ebi->dev, "resource %d is configured as secure\n", in stm32_fmc2_ebi_mp25_check_rif()
1270 return -EACCES; in stm32_fmc2_ebi_mp25_check_rif()
1273 ret = regmap_read(ebi->regmap, FMC2_CIDCFGR(resource), &cidcfgr); in stm32_fmc2_ebi_mp25_check_rif()
1286 dev_err(ebi->dev, "static CID%d set for resource %d\n", in stm32_fmc2_ebi_mp25_check_rif()
1289 return -EACCES; in stm32_fmc2_ebi_mp25_check_rif()
1295 /* Pass-list with semaphore mode */ in stm32_fmc2_ebi_mp25_check_rif()
1298 dev_err(ebi->dev, "CID1 is block-listed for resource %d\n", in stm32_fmc2_ebi_mp25_check_rif()
1301 return -EACCES; in stm32_fmc2_ebi_mp25_check_rif()
1304 ret = regmap_read(ebi->regmap, FMC2_SEMCR(resource), &semcr); in stm32_fmc2_ebi_mp25_check_rif()
1309 regmap_update_bits(ebi->regmap, FMC2_SEMCR(resource), in stm32_fmc2_ebi_mp25_check_rif()
1312 ret = regmap_read(ebi->regmap, FMC2_SEMCR(resource), &semcr); in stm32_fmc2_ebi_mp25_check_rif()
1320 dev_err(ebi->dev, "resource %d is already used by CID%d\n", in stm32_fmc2_ebi_mp25_check_rif()
1323 return -EACCES; in stm32_fmc2_ebi_mp25_check_rif()
1326 ebi->sem_taken |= BIT(resource); in stm32_fmc2_ebi_mp25_check_rif()
1331 static void stm32_fmc2_ebi_mp25_put_sems(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_mp25_put_sems() argument
1336 if (!(ebi->sem_taken & BIT(resource))) in stm32_fmc2_ebi_mp25_put_sems()
1339 regmap_update_bits(ebi->regmap, FMC2_SEMCR(resource), in stm32_fmc2_ebi_mp25_put_sems()
1344 static void stm32_fmc2_ebi_mp25_get_sems(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_mp25_get_sems() argument
1349 if (!(ebi->sem_taken & BIT(resource))) in stm32_fmc2_ebi_mp25_get_sems()
1352 regmap_update_bits(ebi->regmap, FMC2_SEMCR(resource), in stm32_fmc2_ebi_mp25_get_sems()
1357 static int stm32_fmc2_ebi_parse_prop(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_parse_prop() argument
1360 int cs) in stm32_fmc2_ebi_parse_prop() argument
1362 struct device *dev = ebi->dev; in stm32_fmc2_ebi_parse_prop()
1363 u32 setup = 0; in stm32_fmc2_ebi_parse_prop() local
1365 if (!prop->set) { in stm32_fmc2_ebi_parse_prop()
1366 dev_err(dev, "property %s is not well defined\n", prop->name); in stm32_fmc2_ebi_parse_prop()
1367 return -EINVAL; in stm32_fmc2_ebi_parse_prop()
1370 if (prop->check && prop->check(ebi, prop, cs)) in stm32_fmc2_ebi_parse_prop()
1374 if (prop->bprop) { in stm32_fmc2_ebi_parse_prop()
1377 bprop = of_property_read_bool(dev_node, prop->name); in stm32_fmc2_ebi_parse_prop()
1378 if (prop->mprop && !bprop) { in stm32_fmc2_ebi_parse_prop()
1380 prop->name); in stm32_fmc2_ebi_parse_prop()
1381 return -EINVAL; in stm32_fmc2_ebi_parse_prop()
1385 setup = 1; in stm32_fmc2_ebi_parse_prop()
1390 ret = of_property_read_u32(dev_node, prop->name, &val); in stm32_fmc2_ebi_parse_prop()
1391 if (prop->mprop && ret) { in stm32_fmc2_ebi_parse_prop()
1393 prop->name); in stm32_fmc2_ebi_parse_prop()
1398 setup = prop->reset_val; in stm32_fmc2_ebi_parse_prop()
1399 else if (prop->calculate) in stm32_fmc2_ebi_parse_prop()
1400 setup = prop->calculate(ebi, cs, val); in stm32_fmc2_ebi_parse_prop()
1402 setup = val; in stm32_fmc2_ebi_parse_prop()
1405 return prop->set(ebi, prop, cs, setup); in stm32_fmc2_ebi_parse_prop()
1408 static void stm32_fmc2_ebi_enable_bank(struct stm32_fmc2_ebi *ebi, int cs) in stm32_fmc2_ebi_enable_bank() argument
1410 regmap_update_bits(ebi->regmap, FMC2_BCR(cs), in stm32_fmc2_ebi_enable_bank()
1414 static void stm32_fmc2_ebi_disable_bank(struct stm32_fmc2_ebi *ebi, int cs) in stm32_fmc2_ebi_disable_bank() argument
1416 regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_MBKEN, 0); in stm32_fmc2_ebi_disable_bank()
1419 static int stm32_fmc2_ebi_save_setup(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_save_setup() argument
1421 unsigned int cs; in stm32_fmc2_ebi_save_setup() local
1424 for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { in stm32_fmc2_ebi_save_setup()
1425 if (!(ebi->bank_assigned & BIT(cs))) in stm32_fmc2_ebi_save_setup()
1428 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &ebi->bcr[cs]); in stm32_fmc2_ebi_save_setup()
1429 ret |= regmap_read(ebi->regmap, FMC2_BTR(cs), &ebi->btr[cs]); in stm32_fmc2_ebi_save_setup()
1430 ret |= regmap_read(ebi->regmap, FMC2_BWTR(cs), &ebi->bwtr[cs]); in stm32_fmc2_ebi_save_setup()
1438 static int stm32_fmc2_ebi_mp1_save_setup(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_mp1_save_setup() argument
1442 ret = stm32_fmc2_ebi_save_setup(ebi); in stm32_fmc2_ebi_mp1_save_setup()
1446 return regmap_read(ebi->regmap, FMC2_PCSCNTR, &ebi->pcscntr); in stm32_fmc2_ebi_mp1_save_setup()
1449 static int stm32_fmc2_ebi_mp25_save_setup(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_mp25_save_setup() argument
1453 ret = stm32_fmc2_ebi_save_setup(ebi); in stm32_fmc2_ebi_mp25_save_setup()
1457 if (ebi->access_granted) in stm32_fmc2_ebi_mp25_save_setup()
1458 ret = regmap_read(ebi->regmap, FMC2_CFGR, &ebi->cfgr); in stm32_fmc2_ebi_mp25_save_setup()
1463 static void stm32_fmc2_ebi_set_setup(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_set_setup() argument
1465 unsigned int cs; in stm32_fmc2_ebi_set_setup() local
1467 for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { in stm32_fmc2_ebi_set_setup()
1468 if (!(ebi->bank_assigned & BIT(cs))) in stm32_fmc2_ebi_set_setup()
1471 regmap_write(ebi->regmap, FMC2_BCR(cs), ebi->bcr[cs]); in stm32_fmc2_ebi_set_setup()
1472 regmap_write(ebi->regmap, FMC2_BTR(cs), ebi->btr[cs]); in stm32_fmc2_ebi_set_setup()
1473 regmap_write(ebi->regmap, FMC2_BWTR(cs), ebi->bwtr[cs]); in stm32_fmc2_ebi_set_setup()
1477 static void stm32_fmc2_ebi_mp1_set_setup(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_mp1_set_setup() argument
1479 stm32_fmc2_ebi_set_setup(ebi); in stm32_fmc2_ebi_mp1_set_setup()
1480 regmap_write(ebi->regmap, FMC2_PCSCNTR, ebi->pcscntr); in stm32_fmc2_ebi_mp1_set_setup()
1483 static void stm32_fmc2_ebi_mp25_set_setup(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_mp25_set_setup() argument
1485 stm32_fmc2_ebi_set_setup(ebi); in stm32_fmc2_ebi_mp25_set_setup()
1487 if (ebi->access_granted) in stm32_fmc2_ebi_mp25_set_setup()
1488 regmap_write(ebi->regmap, FMC2_CFGR, ebi->cfgr); in stm32_fmc2_ebi_mp25_set_setup()
1491 static void stm32_fmc2_ebi_disable_banks(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_disable_banks() argument
1493 unsigned int cs; in stm32_fmc2_ebi_disable_banks() local
1495 for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { in stm32_fmc2_ebi_disable_banks()
1496 if (!(ebi->bank_assigned & BIT(cs))) in stm32_fmc2_ebi_disable_banks()
1499 stm32_fmc2_ebi_disable_bank(ebi, cs); in stm32_fmc2_ebi_disable_banks()
1503 /* NWAIT signal can not be connected to EBI controller and NAND controller */
1504 static int stm32_fmc2_ebi_nwait_used_by_ctrls(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_nwait_used_by_ctrls() argument
1506 struct device *dev = ebi->dev; in stm32_fmc2_ebi_nwait_used_by_ctrls()
1507 unsigned int cs; in stm32_fmc2_ebi_nwait_used_by_ctrls() local
1511 for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { in stm32_fmc2_ebi_nwait_used_by_ctrls()
1512 if (!(ebi->bank_assigned & BIT(cs))) in stm32_fmc2_ebi_nwait_used_by_ctrls()
1515 ret = regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); in stm32_fmc2_ebi_nwait_used_by_ctrls()
1520 ebi->bank_assigned & BIT(FMC2_NAND)) { in stm32_fmc2_ebi_nwait_used_by_ctrls()
1521 dev_err(dev, "NWAIT signal connected to EBI and NAND controllers\n"); in stm32_fmc2_ebi_nwait_used_by_ctrls()
1522 return -EINVAL; in stm32_fmc2_ebi_nwait_used_by_ctrls()
1529 static void stm32_fmc2_ebi_enable(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_enable() argument
1531 if (!ebi->access_granted) in stm32_fmc2_ebi_enable()
1534 regmap_update_bits(ebi->regmap, ebi->data->fmc2_enable_reg, in stm32_fmc2_ebi_enable()
1535 ebi->data->fmc2_enable_bit, in stm32_fmc2_ebi_enable()
1536 ebi->data->fmc2_enable_bit); in stm32_fmc2_ebi_enable()
1539 static void stm32_fmc2_ebi_disable(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_disable() argument
1541 if (!ebi->access_granted) in stm32_fmc2_ebi_disable()
1544 regmap_update_bits(ebi->regmap, ebi->data->fmc2_enable_reg, in stm32_fmc2_ebi_disable()
1545 ebi->data->fmc2_enable_bit, 0); in stm32_fmc2_ebi_disable()
1548 static int stm32_fmc2_ebi_setup_cs(struct stm32_fmc2_ebi *ebi, in stm32_fmc2_ebi_setup_cs() argument
1550 u32 cs) in stm32_fmc2_ebi_setup_cs() argument
1555 stm32_fmc2_ebi_disable_bank(ebi, cs); in stm32_fmc2_ebi_setup_cs()
1557 for (i = 0; i < ebi->data->nb_child_props; i++) { in stm32_fmc2_ebi_setup_cs()
1558 const struct stm32_fmc2_prop *p = &ebi->data->child_props[i]; in stm32_fmc2_ebi_setup_cs()
1560 ret = stm32_fmc2_ebi_parse_prop(ebi, dev_node, p, cs); in stm32_fmc2_ebi_setup_cs()
1562 dev_err(ebi->dev, "property %s could not be set: %d\n", in stm32_fmc2_ebi_setup_cs()
1563 p->name, ret); in stm32_fmc2_ebi_setup_cs()
1568 stm32_fmc2_ebi_enable_bank(ebi, cs); in stm32_fmc2_ebi_setup_cs()
1573 static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi) in stm32_fmc2_ebi_parse_dt() argument
1575 struct device *dev = ebi->dev; in stm32_fmc2_ebi_parse_dt()
1580 for_each_available_child_of_node_scoped(dev->of_node, child) { in stm32_fmc2_ebi_parse_dt()
1587 return -EINVAL; in stm32_fmc2_ebi_parse_dt()
1590 if (ebi->bank_assigned & BIT(bank)) { in stm32_fmc2_ebi_parse_dt()
1592 return -EINVAL; in stm32_fmc2_ebi_parse_dt()
1595 if (ebi->data->check_rif) { in stm32_fmc2_ebi_parse_dt()
1596 ret = ebi->data->check_rif(ebi, bank + 1); in stm32_fmc2_ebi_parse_dt()
1604 ret = stm32_fmc2_ebi_setup_cs(ebi, child, bank); in stm32_fmc2_ebi_parse_dt()
1607 "setup chip select %d failed\n", bank); in stm32_fmc2_ebi_parse_dt()
1610 ebi->bank_assigned |= BIT(bank); in stm32_fmc2_ebi_parse_dt()
1616 return -ENODEV; in stm32_fmc2_ebi_parse_dt()
1619 if (ebi->data->nwait_used_by_ctrls) { in stm32_fmc2_ebi_parse_dt()
1620 ret = ebi->data->nwait_used_by_ctrls(ebi); in stm32_fmc2_ebi_parse_dt()
1625 stm32_fmc2_ebi_enable(ebi); in stm32_fmc2_ebi_parse_dt()
1627 return of_platform_populate(dev->of_node, NULL, NULL, dev); in stm32_fmc2_ebi_parse_dt()
1632 struct device *dev = &pdev->dev; in stm32_fmc2_ebi_probe()
1633 struct stm32_fmc2_ebi *ebi; in stm32_fmc2_ebi_probe() local
1637 ebi = devm_kzalloc(&pdev->dev, sizeof(*ebi), GFP_KERNEL); in stm32_fmc2_ebi_probe()
1638 if (!ebi) in stm32_fmc2_ebi_probe()
1639 return -ENOMEM; in stm32_fmc2_ebi_probe()
1641 ebi->dev = dev; in stm32_fmc2_ebi_probe()
1642 platform_set_drvdata(pdev, ebi); in stm32_fmc2_ebi_probe()
1644 ebi->data = of_device_get_match_data(dev); in stm32_fmc2_ebi_probe()
1645 if (!ebi->data) in stm32_fmc2_ebi_probe()
1646 return -EINVAL; in stm32_fmc2_ebi_probe()
1648 ebi->regmap = device_node_to_regmap(dev->of_node); in stm32_fmc2_ebi_probe()
1649 if (IS_ERR(ebi->regmap)) in stm32_fmc2_ebi_probe()
1650 return PTR_ERR(ebi->regmap); in stm32_fmc2_ebi_probe()
1652 ebi->clk = devm_clk_get(dev, NULL); in stm32_fmc2_ebi_probe()
1653 if (IS_ERR(ebi->clk)) in stm32_fmc2_ebi_probe()
1654 return PTR_ERR(ebi->clk); in stm32_fmc2_ebi_probe()
1657 if (PTR_ERR(rstc) == -EPROBE_DEFER) in stm32_fmc2_ebi_probe()
1658 return -EPROBE_DEFER; in stm32_fmc2_ebi_probe()
1674 ebi->access_granted = true; in stm32_fmc2_ebi_probe()
1675 if (ebi->data->check_rif) { in stm32_fmc2_ebi_probe()
1676 ret = ebi->data->check_rif(ebi, 0); in stm32_fmc2_ebi_probe()
1680 ebi->access_granted = false; in stm32_fmc2_ebi_probe()
1682 ret = regmap_read(ebi->regmap, FMC2_SR, &sr); in stm32_fmc2_ebi_probe()
1686 /* In case of CFGR is secure, just check that the FMC2 is enabled */ in stm32_fmc2_ebi_probe()
1688 dev_err(dev, "FMC2 is not ready to be used.\n"); in stm32_fmc2_ebi_probe()
1689 ret = -EACCES; in stm32_fmc2_ebi_probe()
1695 ret = stm32_fmc2_ebi_parse_dt(ebi); in stm32_fmc2_ebi_probe()
1699 ret = ebi->data->save_setup(ebi); in stm32_fmc2_ebi_probe()
1706 stm32_fmc2_ebi_disable_banks(ebi); in stm32_fmc2_ebi_probe()
1707 stm32_fmc2_ebi_disable(ebi); in stm32_fmc2_ebi_probe()
1708 if (ebi->data->put_sems) in stm32_fmc2_ebi_probe()
1709 ebi->data->put_sems(ebi); in stm32_fmc2_ebi_probe()
1717 struct stm32_fmc2_ebi *ebi = platform_get_drvdata(pdev); in stm32_fmc2_ebi_remove() local
1719 of_platform_depopulate(&pdev->dev); in stm32_fmc2_ebi_remove()
1720 stm32_fmc2_ebi_disable_banks(ebi); in stm32_fmc2_ebi_remove()
1721 stm32_fmc2_ebi_disable(ebi); in stm32_fmc2_ebi_remove()
1722 if (ebi->data->put_sems) in stm32_fmc2_ebi_remove()
1723 ebi->data->put_sems(ebi); in stm32_fmc2_ebi_remove()
1724 pm_runtime_put_sync_suspend(&pdev->dev); in stm32_fmc2_ebi_remove()
1729 struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev); in stm32_fmc2_ebi_runtime_suspend() local
1731 clk_disable_unprepare(ebi->clk); in stm32_fmc2_ebi_runtime_suspend()
1738 struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev); in stm32_fmc2_ebi_runtime_resume() local
1740 return clk_prepare_enable(ebi->clk); in stm32_fmc2_ebi_runtime_resume()
1745 struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev); in stm32_fmc2_ebi_suspend() local
1747 stm32_fmc2_ebi_disable(ebi); in stm32_fmc2_ebi_suspend()
1748 if (ebi->data->put_sems) in stm32_fmc2_ebi_suspend()
1749 ebi->data->put_sems(ebi); in stm32_fmc2_ebi_suspend()
1758 struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev); in stm32_fmc2_ebi_resume() local
1767 if (ebi->data->get_sems) in stm32_fmc2_ebi_resume()
1768 ebi->data->get_sems(ebi); in stm32_fmc2_ebi_resume()
1769 ebi->data->set_setup(ebi); in stm32_fmc2_ebi_resume()
1770 stm32_fmc2_ebi_enable(ebi); in stm32_fmc2_ebi_resume()
1805 .compatible = "st,stm32mp1-fmc2-ebi",
1806 .data = &stm32_fmc2_ebi_mp1_data,
1809 .compatible = "st,stm32mp25-fmc2-ebi",
1810 .data = &stm32_fmc2_ebi_mp25_data,
1829 MODULE_DESCRIPTION("STMicroelectronics STM32 FMC2 ebi driver");