Lines Matching full:cs
207 /* Structure to save gpmc cs context */
278 void gpmc_cs_write_reg(int cs, int idx, u32 val) in gpmc_cs_write_reg() argument
282 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; in gpmc_cs_write_reg()
286 static u32 gpmc_cs_read_reg(int cs, int idx) in gpmc_cs_read_reg() argument
290 reg_addr = gpmc_base + GPMC_CS0_OFFSET + (cs * GPMC_CS_SIZE) + idx; in gpmc_cs_read_reg()
307 * @cs: Chip Select Region.
310 * GPMC_CS_CONFIG1 GPMCFCLKDIVIDER for cs has to be setup
313 static unsigned long gpmc_get_clk_period(int cs, enum gpmc_clk_domain cd) in gpmc_get_clk_period() argument
322 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); in gpmc_get_clk_period()
335 static unsigned int gpmc_ns_to_clk_ticks(unsigned int time_ns, int cs, in gpmc_ns_to_clk_ticks() argument
341 tick_ps = gpmc_get_clk_period(cs, cd); in gpmc_ns_to_clk_ticks()
348 return gpmc_ns_to_clk_ticks(time_ns, /* any CS */ 0, GPMC_CD_FCLK); in gpmc_ns_to_ticks()
361 static unsigned int gpmc_clk_ticks_to_ns(unsigned int ticks, int cs, in gpmc_clk_ticks_to_ns() argument
364 return ticks * gpmc_get_clk_period(cs, cd) / 1000; in gpmc_clk_ticks_to_ns()
369 return gpmc_clk_ticks_to_ns(ticks, /* any CS */ 0, GPMC_CD_FCLK); in gpmc_ticks_to_ns()
384 static inline void gpmc_cs_modify_reg(int cs, int reg, u32 mask, bool value) in gpmc_cs_modify_reg() argument
388 l = gpmc_cs_read_reg(cs, reg); in gpmc_cs_modify_reg()
393 gpmc_cs_write_reg(cs, reg, l); in gpmc_cs_modify_reg()
396 static void gpmc_cs_bool_timings(int cs, const struct gpmc_bool_timings *p) in gpmc_cs_bool_timings() argument
398 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG1, in gpmc_cs_bool_timings()
401 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG2, in gpmc_cs_bool_timings()
403 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG3, in gpmc_cs_bool_timings()
405 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4, in gpmc_cs_bool_timings()
407 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG4, in gpmc_cs_bool_timings()
409 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6, in gpmc_cs_bool_timings()
412 gpmc_cs_modify_reg(cs, GPMC_CS_CONFIG6, in gpmc_cs_bool_timings()
420 * @cs: Chip Select Region
440 int cs, int reg, int st_bit, int end_bit, int max, in get_gpmc_timing_reg() argument
452 l = gpmc_cs_read_reg(cs, reg); in get_gpmc_timing_reg()
469 time_ns_min = gpmc_clk_ticks_to_ns(l - 1, cs, cd) + 1; in get_gpmc_timing_reg()
470 time_ns = gpmc_clk_ticks_to_ns(l, cs, cd); in get_gpmc_timing_reg()
483 #define GPMC_PRINT_CONFIG(cs, config) \ argument
484 pr_info("cs%i %s: 0x%08x\n", cs, #config, \
485 gpmc_cs_read_reg(cs, config))
487 get_gpmc_timing_reg(cs, (reg), (st), (end), 0, field, GPMC_CD_FCLK, 0, 1, 0)
489 get_gpmc_timing_reg(cs, (reg), (st), (end), (max), field, GPMC_CD_FCLK, 0, 1, 0)
491 get_gpmc_timing_reg(cs, (reg), (st), (end), 0, field, GPMC_CD_FCLK, 0, 1, 1)
493 get_gpmc_timing_reg(cs, (reg), (st), (end), (max), field, GPMC_CD_FCLK, (shift), 1, 1)
495 get_gpmc_timing_reg(cs, (reg), (st), (end), 0, field, GPMC_CD_FCLK, 0, 0, 0)
497 get_gpmc_timing_reg(cs, (reg), (st), (end), 0, field, (cd), 0, 0, 0)
499 get_gpmc_timing_reg(cs, (reg), (st), (end), (max), field, (cd), 0, 0, 0)
501 static void gpmc_show_regs(int cs, const char *desc) in gpmc_show_regs() argument
503 pr_info("gpmc cs%i %s:\n", cs, desc); in gpmc_show_regs()
504 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG1); in gpmc_show_regs()
505 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG2); in gpmc_show_regs()
506 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG3); in gpmc_show_regs()
507 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG4); in gpmc_show_regs()
508 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG5); in gpmc_show_regs()
509 GPMC_PRINT_CONFIG(cs, GPMC_CS_CONFIG6); in gpmc_show_regs()
516 static void gpmc_cs_show_timings(int cs, const char *desc) in gpmc_cs_show_timings() argument
518 gpmc_show_regs(cs, desc); in gpmc_cs_show_timings()
520 pr_info("gpmc cs%i access configuration:\n", cs); in gpmc_cs_show_timings()
537 GPMC_GET_RAW_BOOL(GPMC_CS_CONFIG2, 7, 7, "cs-extra-delay"); in gpmc_cs_show_timings()
547 pr_info("gpmc cs%i timings configuration:\n", cs); in gpmc_cs_show_timings()
548 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 0, 3, "cs-on-ns"); in gpmc_cs_show_timings()
549 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 8, 12, "cs-rd-off-ns"); in gpmc_cs_show_timings()
550 GPMC_GET_TICKS(GPMC_CS_CONFIG2, 16, 20, "cs-wr-off-ns"); in gpmc_cs_show_timings()
592 static inline void gpmc_cs_show_timings(int cs, const char *desc) in gpmc_cs_show_timings() argument
602 * @cs: Chip Select Region.
613 static int set_gpmc_timing_reg(int cs, int reg, int st_bit, int end_bit, int max, in set_gpmc_timing_reg() argument
622 ticks = gpmc_ns_to_clk_ticks(time, cs, cd); in set_gpmc_timing_reg()
630 pr_err("%s: GPMC CS%d: %s %d ns, %d ticks > %d ticks\n", in set_gpmc_timing_reg()
631 __func__, cs, name, time, ticks, max); in set_gpmc_timing_reg()
636 l = gpmc_cs_read_reg(cs, reg); in set_gpmc_timing_reg()
638 pr_info("GPMC CS%d: %-17s: %3d ticks, %3lu ns (was %3i ticks) %3d ns\n", in set_gpmc_timing_reg()
639 cs, name, ticks, gpmc_get_clk_period(cs, cd) * ticks / 1000, in set_gpmc_timing_reg()
644 gpmc_cs_write_reg(cs, reg, l); in set_gpmc_timing_reg()
699 * @cs: Chip Select Region.
704 int gpmc_cs_set_timings(int cs, const struct gpmc_timings *t, in gpmc_cs_set_timings() argument
741 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 0, 3, 0, t->cs_on, in gpmc_cs_set_timings()
743 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 8, 12, 0, t->cs_rd_off, in gpmc_cs_set_timings()
745 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG2, 16, 20, 0, t->cs_wr_off, in gpmc_cs_set_timings()
750 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 0, 3, 0, t->adv_on, in gpmc_cs_set_timings()
752 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 8, 12, 0, t->adv_rd_off, in gpmc_cs_set_timings()
754 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 16, 20, 0, t->adv_wr_off, in gpmc_cs_set_timings()
760 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 4, 6, 0, in gpmc_cs_set_timings()
763 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 24, 26, 0, in gpmc_cs_set_timings()
766 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG3, 28, 30, 0, in gpmc_cs_set_timings()
773 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 0, 3, 0, t->oe_on, in gpmc_cs_set_timings()
775 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 8, 12, 0, t->oe_off, in gpmc_cs_set_timings()
778 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 4, 6, 0, in gpmc_cs_set_timings()
781 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 13, 15, 0, in gpmc_cs_set_timings()
785 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 16, 19, 0, t->we_on, in gpmc_cs_set_timings()
787 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG4, 24, 28, 0, t->we_off, in gpmc_cs_set_timings()
792 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 0, 4, 0, t->rd_cycle, in gpmc_cs_set_timings()
794 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 8, 12, 0, t->wr_cycle, in gpmc_cs_set_timings()
796 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 16, 20, 0, t->access, in gpmc_cs_set_timings()
798 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG5, 24, 27, 0, in gpmc_cs_set_timings()
804 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 0, 3, 0, in gpmc_cs_set_timings()
807 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 8, 11, 0, in gpmc_cs_set_timings()
814 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 16, 19, 0, in gpmc_cs_set_timings()
821 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG6, 24, 28, 0, in gpmc_cs_set_timings()
828 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG1); in gpmc_cs_set_timings()
831 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, l); in gpmc_cs_set_timings()
834 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG1, 18, 19, in gpmc_cs_set_timings()
838 ret |= set_gpmc_timing_reg(cs, GPMC_CS_CONFIG1, 25, 26, in gpmc_cs_set_timings()
846 pr_info("GPMC CS%d CLK period is %lu ns (div %d)\n", in gpmc_cs_set_timings()
847 cs, (div * gpmc_get_fclk_period()) / 1000, div); in gpmc_cs_set_timings()
850 gpmc_cs_bool_timings(cs, &t->bool_timings); in gpmc_cs_set_timings()
851 gpmc_cs_show_timings(cs, "after gpmc_cs_set_timings"); in gpmc_cs_set_timings()
856 static int gpmc_cs_set_memconf(int cs, u32 base, u32 size) in gpmc_cs_set_memconf() argument
873 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); in gpmc_cs_set_memconf()
878 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); in gpmc_cs_set_memconf()
883 static void gpmc_cs_enable_mem(int cs) in gpmc_cs_enable_mem() argument
887 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); in gpmc_cs_enable_mem()
889 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); in gpmc_cs_enable_mem()
892 static void gpmc_cs_disable_mem(int cs) in gpmc_cs_disable_mem() argument
896 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); in gpmc_cs_disable_mem()
898 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG7, l); in gpmc_cs_disable_mem()
901 static void gpmc_cs_get_memconf(int cs, u32 *base, u32 *size) in gpmc_cs_get_memconf() argument
906 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); in gpmc_cs_get_memconf()
912 static int gpmc_cs_mem_enabled(int cs) in gpmc_cs_mem_enabled() argument
916 l = gpmc_cs_read_reg(cs, GPMC_CS_CONFIG7); in gpmc_cs_mem_enabled()
920 static void gpmc_cs_set_reserved(int cs, int reserved) in gpmc_cs_set_reserved() argument
922 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_set_reserved()
927 static bool gpmc_cs_reserved(int cs) in gpmc_cs_reserved() argument
929 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_reserved()
948 static int gpmc_cs_insert_mem(int cs, unsigned long base, unsigned long size) in gpmc_cs_insert_mem() argument
950 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_insert_mem()
964 static int gpmc_cs_delete_mem(int cs) in gpmc_cs_delete_mem() argument
966 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_delete_mem()
979 int gpmc_cs_request(int cs, unsigned long size, unsigned long *base) in gpmc_cs_request() argument
981 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_request()
985 if (cs >= gpmc_cs_num) { in gpmc_cs_request()
995 if (gpmc_cs_reserved(cs)) in gpmc_cs_request()
998 if (gpmc_cs_mem_enabled(cs)) in gpmc_cs_request()
1006 /* Disable CS while changing base address and size mask */ in gpmc_cs_request()
1007 gpmc_cs_disable_mem(cs); in gpmc_cs_request()
1009 r = gpmc_cs_set_memconf(cs, res->start, resource_size(res)); in gpmc_cs_request()
1015 /* Enable CS */ in gpmc_cs_request()
1016 gpmc_cs_enable_mem(cs); in gpmc_cs_request()
1018 gpmc_cs_set_reserved(cs, 1); in gpmc_cs_request()
1024 void gpmc_cs_free(int cs) in gpmc_cs_free() argument
1030 if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) { in gpmc_cs_free()
1031 WARN(1, "Trying to free non-reserved GPMC CS%d\n", cs); in gpmc_cs_free()
1034 gpmc = &gpmc_cs[cs]; in gpmc_cs_free()
1037 gpmc_cs_disable_mem(cs); in gpmc_cs_free()
1040 gpmc_cs_set_reserved(cs, 0); in gpmc_cs_free()
1144 * @cs: GPMC chip select number on which the NAND sits. The
1147 * Returns NULL on error e.g. invalid cs.
1149 struct gpmc_nand_ops *gpmc_omap_get_nand_ops(struct gpmc_nand_regs *reg, int cs) in gpmc_omap_get_nand_ops() argument
1153 if (cs >= gpmc_cs_num) in gpmc_omap_get_nand_ops()
1157 GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs; in gpmc_omap_get_nand_ops()
1159 GPMC_CS_NAND_ADDRESS + GPMC_CS_SIZE * cs; in gpmc_omap_get_nand_ops()
1161 GPMC_CS_NAND_DATA + GPMC_CS_SIZE * cs; in gpmc_omap_get_nand_ops()
1271 int gpmc_omap_onenand_set_timings(struct device *dev, int cs, int freq, in gpmc_omap_onenand_set_timings() argument
1290 ret = gpmc_cs_program_settings(cs, &gpmc_s); in gpmc_omap_onenand_set_timings()
1294 return gpmc_cs_set_timings(cs, &gpmc_t, &gpmc_s); in gpmc_omap_onenand_set_timings()
1514 int cs; in gpmc_mem_exit() local
1516 for (cs = 0; cs < gpmc_cs_num; cs++) { in gpmc_mem_exit()
1517 if (!gpmc_cs_mem_enabled(cs)) in gpmc_mem_exit()
1519 gpmc_cs_delete_mem(cs); in gpmc_mem_exit()
1525 int cs; in gpmc_mem_init() local
1537 for (cs = 0; cs < gpmc_cs_num; cs++) { in gpmc_mem_init()
1540 if (!gpmc_cs_mem_enabled(cs)) in gpmc_mem_init()
1542 gpmc_cs_get_memconf(cs, &base, &size); in gpmc_mem_init()
1543 if (gpmc_cs_insert_mem(cs, base, size)) { in gpmc_mem_init()
1544 pr_warn("%s: disabling cs %d mapped at 0x%x-0x%x\n", in gpmc_mem_init()
1545 __func__, cs, base, base + size); in gpmc_mem_init()
1546 gpmc_cs_disable_mem(cs); in gpmc_mem_init()
1873 * @cs: GPMC chip-select to program
1883 int gpmc_cs_program_settings(int cs, struct gpmc_settings *p) in gpmc_cs_program_settings() argument
1950 gpmc_cs_write_reg(cs, GPMC_CS_CONFIG1, config1); in gpmc_cs_program_settings()
1967 static void gpmc_cs_set_name(int cs, const char *name) in gpmc_cs_set_name() argument
1969 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_set_name()
1974 static const char *gpmc_cs_get_name(int cs) in gpmc_cs_get_name() argument
1976 struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; in gpmc_cs_get_name()
1983 * @cs: chip-select to remap
1990 static int gpmc_cs_remap(int cs, u32 base) in gpmc_cs_remap() argument
1995 if (cs >= gpmc_cs_num) { in gpmc_cs_remap()
2007 gpmc_cs_get_memconf(cs, &old_base, &size); in gpmc_cs_remap()
2011 ret = gpmc_cs_delete_mem(cs); in gpmc_cs_remap()
2015 ret = gpmc_cs_insert_mem(cs, base, size); in gpmc_cs_remap()
2019 ret = gpmc_cs_set_memconf(cs, base, size); in gpmc_cs_remap()
2095 of_property_read_u32(np, "gpmc,cs-on-ns", &gpmc_t->cs_on); in gpmc_read_timings_dt()
2096 of_property_read_u32(np, "gpmc,cs-rd-off-ns", &gpmc_t->cs_rd_off); in gpmc_read_timings_dt()
2097 of_property_read_u32(np, "gpmc,cs-wr-off-ns", &gpmc_t->cs_wr_off); in gpmc_read_timings_dt()
2152 p->cs_extra_delay = of_property_read_bool(np, "gpmc,cs-extra-delay"); in gpmc_read_timings_dt()
2173 int ret, cs; in gpmc_probe_generic_child() local
2177 if (of_property_read_u32(child, "reg", &cs) < 0) { in gpmc_probe_generic_child()
2194 name = gpmc_cs_get_name(cs); in gpmc_probe_generic_child()
2198 ret = gpmc_cs_request(cs, resource_size(&res), &base); in gpmc_probe_generic_child()
2200 dev_err(&pdev->dev, "cannot request GPMC CS %d\n", cs); in gpmc_probe_generic_child()
2203 gpmc_cs_set_name(cs, child->full_name); in gpmc_probe_generic_child()
2214 WARN(1, "enable GPMC debug to configure .dts timings for CS%i\n", in gpmc_probe_generic_child()
2215 cs); in gpmc_probe_generic_child()
2216 gpmc_cs_show_timings(cs, in gpmc_probe_generic_child()
2221 /* CS must be disabled while making changes to gpmc configuration */ in gpmc_probe_generic_child()
2222 gpmc_cs_disable_mem(cs); in gpmc_probe_generic_child()
2225 * FIXME: gpmc_cs_request() will map the CS to an arbitrary in gpmc_probe_generic_child()
2229 * CS to this location. Once DT migration is complete should in gpmc_probe_generic_child()
2232 ret = gpmc_cs_remap(cs, res.start); in gpmc_probe_generic_child()
2234 dev_err(&pdev->dev, "cannot remap GPMC CS %d to %pa\n", in gpmc_probe_generic_child()
2235 cs, &res.start); in gpmc_probe_generic_child()
2238 "GPMC CS %d start cannot be lesser than 0x%x\n", in gpmc_probe_generic_child()
2239 cs, GPMC_MEM_START); in gpmc_probe_generic_child()
2242 "GPMC CS %d end cannot be greater than 0x%x\n", in gpmc_probe_generic_child()
2243 cs, GPMC_MEM_END); in gpmc_probe_generic_child()
2307 gpmc_cs_show_timings(cs, "before gpmc_cs_program_settings"); in gpmc_probe_generic_child()
2309 ret = gpmc_cs_program_settings(cs, &gpmc_s); in gpmc_probe_generic_child()
2313 ret = gpmc_cs_set_timings(cs, &gpmc_t, &gpmc_s); in gpmc_probe_generic_child()
2325 /* Enable CS region */ in gpmc_probe_generic_child()
2326 gpmc_cs_enable_mem(cs); in gpmc_probe_generic_child()
2348 gpmc_cs_free(cs); in gpmc_probe_generic_child()
2364 ret = of_property_read_u32(pdev->dev.of_node, "gpmc,num-cs", in gpmc_probe_dt()