Lines Matching +full:memcpy +full:- +full:bus +full:- +full:width
1 // SPDX-License-Identifier: GPL-2.0-only
33 * struct emif_data - Per device static data for driver's use
38 * to this EMIF - read from MR4 register. If there
43 * @base: base address of memory-mapped IO registers.
47 * frequencies, to avoid re-calculating them on
77 u32 type = emif->plat_data->device_info->type; in do_emif_regdump_show()
78 u32 ip_rev = emif->plat_data->ip_rev; in do_emif_regdump_show()
81 regs->freq/1000000); in do_emif_regdump_show()
83 seq_printf(s, "ref_ctrl_shdw\t: 0x%08x\n", regs->ref_ctrl_shdw); in do_emif_regdump_show()
84 seq_printf(s, "sdram_tim1_shdw\t: 0x%08x\n", regs->sdram_tim1_shdw); in do_emif_regdump_show()
85 seq_printf(s, "sdram_tim2_shdw\t: 0x%08x\n", regs->sdram_tim2_shdw); in do_emif_regdump_show()
86 seq_printf(s, "sdram_tim3_shdw\t: 0x%08x\n", regs->sdram_tim3_shdw); in do_emif_regdump_show()
90 regs->read_idle_ctrl_shdw_normal); in do_emif_regdump_show()
92 regs->read_idle_ctrl_shdw_volt_ramp); in do_emif_regdump_show()
95 regs->dll_calib_ctrl_shdw_normal); in do_emif_regdump_show()
97 regs->dll_calib_ctrl_shdw_volt_ramp); in do_emif_regdump_show()
102 regs->ref_ctrl_shdw_derated); in do_emif_regdump_show()
104 regs->sdram_tim1_shdw_derated); in do_emif_regdump_show()
106 regs->sdram_tim3_shdw_derated); in do_emif_regdump_show()
112 struct emif_data *emif = s->private; in emif_regdump_show()
116 if (emif->duplicate) in emif_regdump_show()
117 regs_cache = emif1->regs_cache; in emif_regdump_show()
119 regs_cache = emif->regs_cache; in emif_regdump_show()
133 struct emif_data *emif = s->private; in emif_mr4_show()
135 seq_printf(s, "MR4=%d\n", emif->temperature_level); in emif_mr4_show()
144 emif->debugfs_root = debugfs_create_dir(dev_name(emif->dev), NULL); in emif_debugfs_init()
145 debugfs_create_file("regcache_dump", S_IRUGO, emif->debugfs_root, emif, in emif_debugfs_init()
147 debugfs_create_file("mr4", S_IRUGO, emif->debugfs_root, emif, in emif_debugfs_init()
155 debugfs_remove_recursive(emif->debugfs_root); in emif_debugfs_exit()
156 emif->debugfs_root = NULL; in emif_debugfs_exit()
161 * Get bus width used by EMIF. Note that this may be different from the
162 * bus width of the DDR devices used. For instance two 16-bit DDR devices
163 * may be connected to a given CS of EMIF. In this case bus width as far
164 * as EMIF is concerned is 32, where as the DDR bus width is 16 bits.
168 u32 width; in get_emif_bus_width() local
169 void __iomem *base = emif->base; in get_emif_bus_width()
171 width = (readl(base + EMIF_SDRAM_CONFIG) & NARROW_MODE_MASK) in get_emif_bus_width()
173 width = width == 0 ? 32 : 16; in get_emif_bus_width()
175 return width; in get_emif_bus_width()
181 void __iomem *base = emif->base; in set_lpmode()
184 * Workaround for errata i743 - LPDDR2 Power-Down State is Not in set_lpmode()
188 * The EMIF supports power-down state for low power. The EMIF in set_lpmode()
189 * automatically puts the SDRAM into power-down after the memory is in set_lpmode()
194 * power-down and precharge power-down modes. The EMIF waits and in set_lpmode()
197 * exit of power-down mode. Due to very short periods of power-down in set_lpmode()
200 * issuing ZQ calibration long commands when exiting self-refresh is in set_lpmode()
204 * Because there is no power consumption benefit of the power-down due in set_lpmode()
206 * is to not allow power-down state and, therefore, to not have set in set_lpmode()
209 if ((emif->plat_data->ip_rev == EMIF_4D) && in set_lpmode()
213 /* rollback LP_MODE to Self-refresh mode */ in set_lpmode()
231 * The EMIF automatically puts the SDRAM into self-refresh mode in do_freq_update()
237 * - The SR_TIMING counter expires in do_freq_update()
238 * - And frequency change is requested in do_freq_update()
239 * - And OCP access is requested in do_freq_update()
244 * is to disable the self-refresh when requesting a frequency in do_freq_update()
251 if (emif->lpmode == EMIF_LP_MODE_SELF_REFRESH) in do_freq_update()
262 if (emif->lpmode == EMIF_LP_MODE_SELF_REFRESH) in do_freq_update()
273 type = device_info->type; in get_addressing_table()
274 density = device_info->density; in get_addressing_table()
278 index = density - 1; in get_addressing_table()
287 index = density - 1; in get_addressing_table()
302 val = EMIF_ZQCS_INTERVAL_US * 1000 / addressing->tREFI_ns; in get_zq_config_reg()
305 val = DIV_ROUND_UP(T_ZQCL_DEFAULT_NS, T_ZQCS_DEFAULT_NS) - 1; in get_zq_config_reg()
308 val = DIV_ROUND_UP(T_ZQINIT_DEFAULT_NS, T_ZQCL_DEFAULT_NS) - 1; in get_zq_config_reg()
332 if (custom_configs && (custom_configs->mask & in get_temp_alert_config()
334 interval = custom_configs->temp_alert_poll_interval_ms; in get_temp_alert_config()
339 interval /= addressing->tREFI_ns; /* Convert to refresh cycles */ in get_temp_alert_config()
343 * sdram_io_width is in 'log2(x) - 1' form. Convert emif_bus_width in get_temp_alert_config()
347 emif_bus_width = __fls(emif_bus_width) - 1; in get_temp_alert_config()
348 devcnt = emif_bus_width - sdram_io_width; in get_temp_alert_config()
351 /* DEVWDT is in 'log2(x) - 3' form */ in get_temp_alert_config()
352 alert |= (sdram_io_width - 2) << TA_DEVWDT_SHIFT; in get_temp_alert_config()
371 struct emif_custom_configs *cust_cfgs = emif->plat_data->custom_configs; in get_pwr_mgmt_ctrl()
373 if (cust_cfgs && (cust_cfgs->mask & EMIF_CUSTOM_CONFIG_LPMODE)) { in get_pwr_mgmt_ctrl()
374 lpmode = cust_cfgs->lpmode; in get_pwr_mgmt_ctrl()
375 timeout_perf = cust_cfgs->lpmode_timeout_performance; in get_pwr_mgmt_ctrl()
376 timeout_pwr = cust_cfgs->lpmode_timeout_power; in get_pwr_mgmt_ctrl()
377 freq_threshold = cust_cfgs->lpmode_freq_threshold; in get_pwr_mgmt_ctrl()
384 * The value to be set in register is "log2(timeout) - 3" in get_pwr_mgmt_ctrl()
391 if (timeout & (timeout - 1)) in get_pwr_mgmt_ctrl()
393 timeout = __fls(timeout) - 3; in get_pwr_mgmt_ctrl()
421 pr_err("TIMEOUT Overflow - lpmode=%d perf=%d pwr=%d freq=%d\n", in get_pwr_mgmt_ctrl()
457 base = emif->base; in get_temperature_level()
465 if (emif->plat_data->device_info->cs1_used) { in get_temperature_level()
479 emif->temperature_level = temperature_level; in get_temperature_level()
483 * setup_temperature_sensitive_regs() - set the timings for temperature
494 void __iomem *base = emif->base; in setup_temperature_sensitive_regs()
497 type = emif->plat_data->device_info->type; in setup_temperature_sensitive_regs()
499 tim1 = regs->sdram_tim1_shdw; in setup_temperature_sensitive_regs()
500 tim3 = regs->sdram_tim3_shdw; in setup_temperature_sensitive_regs()
501 ref_ctrl = regs->ref_ctrl_shdw; in setup_temperature_sensitive_regs()
503 /* No de-rating for non-lpddr2 devices */ in setup_temperature_sensitive_regs()
507 temperature = emif->temperature_level; in setup_temperature_sensitive_regs()
509 ref_ctrl = regs->ref_ctrl_shdw_derated; in setup_temperature_sensitive_regs()
511 tim1 = regs->sdram_tim1_shdw_derated; in setup_temperature_sensitive_regs()
512 tim3 = regs->sdram_tim3_shdw_derated; in setup_temperature_sensitive_regs()
513 ref_ctrl = regs->ref_ctrl_shdw_derated; in setup_temperature_sensitive_regs()
529 old_temp_level = emif->temperature_level; in handle_temp_alert()
532 if (unlikely(emif->temperature_level == old_temp_level)) { in handle_temp_alert()
534 } else if (!emif->curr_regs) { in handle_temp_alert()
535 dev_err(emif->dev, "temperature alert before registers are calculated, not de-rating timings\n"); in handle_temp_alert()
539 custom_configs = emif->plat_data->custom_configs; in handle_temp_alert()
545 if (custom_configs && !(custom_configs->mask & in handle_temp_alert()
547 if (emif->temperature_level >= SDRAM_TEMP_HIGH_DERATE_REFRESH) { in handle_temp_alert()
548 dev_err(emif->dev, in handle_temp_alert()
550 __func__, emif->temperature_level); in handle_temp_alert()
552 * Temperature far too high - do kernel_power_off() in handle_temp_alert()
555 emif->temperature_level = SDRAM_TEMP_VERY_HIGH_SHUTDOWN; in handle_temp_alert()
560 if (emif->temperature_level < old_temp_level || in handle_temp_alert()
561 emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) { in handle_temp_alert()
563 * Temperature coming down - defer handling to thread OR in handle_temp_alert()
564 * Temperature far too high - do kernel_power_off() from in handle_temp_alert()
569 /* Temperature is going up - handle immediately */ in handle_temp_alert()
570 setup_temperature_sensitive_regs(emif, emif->curr_regs); in handle_temp_alert()
582 void __iomem *base = emif->base; in emif_interrupt_handler()
583 struct device *dev = emif->dev; in emif_interrupt_handler()
599 dev_err(dev, "Access error from SYS port - %x\n", interrupts); in emif_interrupt_handler()
601 if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE) { in emif_interrupt_handler()
607 dev_err(dev, "Access error from LL port - %x\n", in emif_interrupt_handler()
619 if (emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) { in emif_threaded_isr()
620 dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n"); in emif_threaded_isr()
627 kernel_restart("SDRAM Over-temp Emergency restart"); in emif_threaded_isr()
634 if (emif->curr_regs) { in emif_threaded_isr()
635 setup_temperature_sensitive_regs(emif, emif->curr_regs); in emif_threaded_isr()
638 dev_err(emif->dev, "temperature alert before registers are calculated, not de-rating timings\n"); in emif_threaded_isr()
648 void __iomem *base = emif->base; in clear_all_interrupts()
652 if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE) in clear_all_interrupts()
659 void __iomem *base = emif->base; in disable_and_clear_all_interrupts()
664 if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE) in disable_and_clear_all_interrupts()
675 void __iomem *base = emif->base; in setup_interrupts()
677 type = emif->plat_data->device_info->type; in setup_interrupts()
688 if (emif->plat_data->hw_caps & EMIF_HW_CAPS_LL_INTERFACE) { in setup_interrupts()
695 return devm_request_threaded_irq(emif->dev, irq, in setup_interrupts()
698 0, dev_name(emif->dev), in setup_interrupts()
706 void __iomem *base = emif->base; in emif_onetime_settings()
710 device_info = emif->plat_data->device_info; in emif_onetime_settings()
719 emif->plat_data->ip_rev); in emif_onetime_settings()
720 emif->lpmode = (pwr_mgmt_ctrl & LP_MODE_MASK) >> LP_MODE_SHIFT; in emif_onetime_settings()
724 zq = get_zq_config_reg(addressing, device_info->cs1_used, in emif_onetime_settings()
725 device_info->cal_resistors_per_cs); in emif_onetime_settings()
730 if (emif->temperature_level == SDRAM_TEMP_VERY_HIGH_SHUTDOWN) in emif_onetime_settings()
731 dev_emerg(emif->dev, "SDRAM temperature exceeds operating limit.. Needs shut down!!!\n"); in emif_onetime_settings()
735 emif->plat_data->custom_configs, device_info->cs1_used, in emif_onetime_settings()
736 device_info->io_width, get_emif_bus_width(emif)); in emif_onetime_settings()
743 if (emif->plat_data->phy_type != EMIF_PHY_TYPE_INTELLIPHY) in emif_onetime_settings()
770 struct emif_platform_data *pd = emif->plat_data; in get_default_timings()
772 pd->timings = lpddr2_jedec_timings; in get_default_timings()
773 pd->timings_arr_size = ARRAY_SIZE(lpddr2_jedec_timings); in get_default_timings()
775 dev_warn(emif->dev, "%s: using default timings\n", __func__); in get_default_timings()
812 if ((cust_cfgs->mask & EMIF_CUSTOM_CONFIG_LPMODE) && in is_custom_config_valid()
813 (cust_cfgs->lpmode != EMIF_LP_MODE_DISABLE)) in is_custom_config_valid()
814 valid = cust_cfgs->lpmode_freq_threshold && in is_custom_config_valid()
815 cust_cfgs->lpmode_timeout_performance && in is_custom_config_valid()
816 cust_cfgs->lpmode_timeout_power; in is_custom_config_valid()
818 if (cust_cfgs->mask & EMIF_CUSTOM_CONFIG_TEMP_ALERT_POLL_INTERVAL) in is_custom_config_valid()
819 valid = valid && cust_cfgs->temp_alert_poll_interval_ms; in is_custom_config_valid()
834 lpmode = of_get_property(np_emif, "low-power-mode", &len); in of_get_custom_configs()
835 poll_intvl = of_get_property(np_emif, "temp-alert-poll-interval", &len); in of_get_custom_configs()
838 cust_cfgs = devm_kzalloc(emif->dev, sizeof(*cust_cfgs), in of_get_custom_configs()
845 cust_cfgs->mask |= EMIF_CUSTOM_CONFIG_LPMODE; in of_get_custom_configs()
846 cust_cfgs->lpmode = be32_to_cpup(lpmode); in of_get_custom_configs()
848 "low-power-mode-timeout-performance", in of_get_custom_configs()
849 &cust_cfgs->lpmode_timeout_performance); in of_get_custom_configs()
851 "low-power-mode-timeout-power", in of_get_custom_configs()
852 &cust_cfgs->lpmode_timeout_power); in of_get_custom_configs()
854 "low-power-mode-freq-threshold", in of_get_custom_configs()
855 &cust_cfgs->lpmode_freq_threshold); in of_get_custom_configs()
859 cust_cfgs->mask |= in of_get_custom_configs()
861 cust_cfgs->temp_alert_poll_interval_ms = in of_get_custom_configs()
865 if (of_property_read_bool(np_emif, "extended-temp-part")) in of_get_custom_configs()
866 cust_cfgs->mask |= EMIF_CUSTOM_CONFIG_EXTENDED_TEMP_PART; in of_get_custom_configs()
868 if (!is_custom_config_valid(cust_cfgs, emif->dev)) { in of_get_custom_configs()
869 devm_kfree(emif->dev, cust_cfgs); in of_get_custom_configs()
873 emif->plat_data->custom_configs = cust_cfgs; in of_get_custom_configs()
882 dev_info->cs1_used = of_property_read_bool(np_emif, "cs1-used"); in of_get_ddr_info()
883 dev_info->cal_resistors_per_cs = of_property_read_bool(np_emif, "cal-resistor-per-cs"); in of_get_ddr_info()
885 if (of_device_is_compatible(np_ddr, "jedec,lpddr2-s4")) in of_get_ddr_info()
886 dev_info->type = DDR_TYPE_LPDDR2_S4; in of_get_ddr_info()
887 else if (of_device_is_compatible(np_ddr, "jedec,lpddr2-s2")) in of_get_ddr_info()
888 dev_info->type = DDR_TYPE_LPDDR2_S2; in of_get_ddr_info()
891 of_property_read_u32(np_ddr, "io-width", &io_width); in of_get_ddr_info()
894 if (density & (density - 1)) in of_get_ddr_info()
895 dev_info->density = 0; in of_get_ddr_info()
897 dev_info->density = __fls(density) - 5; in of_get_ddr_info()
900 if (io_width & (io_width - 1)) in of_get_ddr_info()
901 dev_info->io_width = 0; in of_get_ddr_info()
903 dev_info->io_width = __fls(io_width) - 1; in of_get_ddr_info()
914 np_ddr = of_parse_phandle(np_emif, "device-handle", 0); in of_get_memory_device_details()
927 emif->plat_data = pd; in of_get_memory_device_details()
928 pd->device_info = dev_info; in of_get_memory_device_details()
929 emif->dev = dev; in of_get_memory_device_details()
930 emif->np_ddr = np_ddr; in of_get_memory_device_details()
931 emif->temperature_level = SDRAM_TEMP_NOMINAL; in of_get_memory_device_details()
933 if (of_device_is_compatible(np_emif, "ti,emif-4d")) in of_get_memory_device_details()
934 emif->plat_data->ip_rev = EMIF_4D; in of_get_memory_device_details()
935 else if (of_device_is_compatible(np_emif, "ti,emif-4d5")) in of_get_memory_device_details()
936 emif->plat_data->ip_rev = EMIF_4D5; in of_get_memory_device_details()
938 of_property_read_u32(np_emif, "phy-type", &pd->phy_type); in of_get_memory_device_details()
940 if (of_property_read_bool(np_emif, "hw-caps-ll-interface")) in of_get_memory_device_details()
941 pd->hw_caps |= EMIF_HW_CAPS_LL_INTERFACE; in of_get_memory_device_details()
944 if (!is_dev_data_valid(pd->device_info->type, pd->device_info->density, in of_get_memory_device_details()
945 pd->device_info->io_width, pd->phy_type, pd->ip_rev, in of_get_memory_device_details()
946 emif->dev)) { in of_get_memory_device_details()
956 if (emif1 && emif1->np_ddr == np_ddr) { in of_get_memory_device_details()
957 emif->duplicate = true; in of_get_memory_device_details()
960 dev_warn(emif->dev, "%s: Non-symmetric DDR geometry\n", in of_get_memory_device_details()
965 emif->plat_data->timings = of_get_ddr_timings(np_ddr, emif->dev, in of_get_memory_device_details()
966 emif->plat_data->device_info->type, in of_get_memory_device_details()
967 &emif->plat_data->timings_arr_size); in of_get_memory_device_details()
969 emif->plat_data->min_tck = of_get_min_tck(np_ddr, emif->dev); in of_get_memory_device_details()
989 pd = pdev->dev.platform_data; in get_device_details()
990 dev = &pdev->dev; in get_device_details()
992 if (!(pd && pd->device_info && is_dev_data_valid(pd->device_info->type, in get_device_details()
993 pd->device_info->density, pd->device_info->io_width, in get_device_details()
994 pd->phy_type, pd->ip_rev, dev))) { in get_device_details()
1006 memcpy(temp, pd, sizeof(*pd)); in get_device_details()
1008 memcpy(dev_info, pd->device_info, sizeof(*dev_info)); in get_device_details()
1010 pd->device_info = dev_info; in get_device_details()
1011 emif->plat_data = pd; in get_device_details()
1012 emif->dev = dev; in get_device_details()
1013 emif->temperature_level = SDRAM_TEMP_NOMINAL; in get_device_details()
1021 emif->duplicate = emif1 && (memcmp(dev_info, in get_device_details()
1022 emif1->plat_data->device_info, in get_device_details()
1025 if (emif->duplicate) { in get_device_details()
1026 pd->timings = NULL; in get_device_details()
1027 pd->min_tck = NULL; in get_device_details()
1030 dev_warn(emif->dev, "%s: Non-symmetric DDR geometry\n", in get_device_details()
1035 * Copy custom configs - ignore allocation error, if any, as in get_device_details()
1038 cust_cfgs = pd->custom_configs; in get_device_details()
1042 memcpy(temp, cust_cfgs, sizeof(*cust_cfgs)); in get_device_details()
1043 pd->custom_configs = temp; in get_device_details()
1047 * Copy timings and min-tck values from platform data. If it is not in get_device_details()
1050 size = sizeof(struct lpddr2_timings) * pd->timings_arr_size; in get_device_details()
1051 if (pd->timings) { in get_device_details()
1054 memcpy(temp, pd->timings, size); in get_device_details()
1055 pd->timings = temp; in get_device_details()
1063 if (pd->min_tck) { in get_device_details()
1064 temp = devm_kzalloc(dev, sizeof(*pd->min_tck), GFP_KERNEL); in get_device_details()
1066 memcpy(temp, pd->min_tck, sizeof(*pd->min_tck)); in get_device_details()
1067 pd->min_tck = temp; in get_device_details()
1069 pd->min_tck = &lpddr2_jedec_min_tck; in get_device_details()
1072 pd->min_tck = &lpddr2_jedec_min_tck; in get_device_details()
1087 if (pdev->dev.of_node) in emif_probe()
1088 emif = of_get_memory_device_details(pdev->dev.of_node, &pdev->dev); in emif_probe()
1097 list_add(&emif->node, &device_list); in emif_probe()
1100 emif->dev = &pdev->dev; in emif_probe()
1103 emif->base = devm_platform_ioremap_resource(pdev, 0); in emif_probe()
1104 if (IS_ERR(emif->base)) in emif_probe()
1118 /* One-time actions taken on probing the first device */ in emif_probe()
1129 dev_info(&pdev->dev, "%s: device configured with addr = %p and IRQ%d\n", in emif_probe()
1130 __func__, emif->base, irq); in emif_probe()
1134 return -ENODEV; in emif_probe()
1153 { .compatible = "ti,emif-4d" },
1154 { .compatible = "ti,emif-4d5" },