.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * EMIF driver |
---|
3 | 4 | * |
---|
.. | .. |
---|
5 | 6 | * |
---|
6 | 7 | * Aneesh V <aneesh@ti.com> |
---|
7 | 8 | * Santosh Shilimkar <santosh.shilimkar@ti.com> |
---|
8 | | - * |
---|
9 | | - * This program is free software; you can redistribute it and/or modify |
---|
10 | | - * it under the terms of the GNU General Public License version 2 as |
---|
11 | | - * published by the Free Software Foundation. |
---|
12 | 9 | */ |
---|
13 | 10 | #include <linux/err.h> |
---|
14 | 11 | #include <linux/kernel.h> |
---|
.. | .. |
---|
26 | 23 | #include <linux/list.h> |
---|
27 | 24 | #include <linux/spinlock.h> |
---|
28 | 25 | #include <linux/pm.h> |
---|
29 | | -#include <memory/jedec_ddr.h> |
---|
| 26 | + |
---|
30 | 27 | #include "emif.h" |
---|
| 28 | +#include "jedec_ddr.h" |
---|
31 | 29 | #include "of_memory.h" |
---|
32 | 30 | |
---|
33 | 31 | /** |
---|
.. | .. |
---|
133 | 131 | return 0; |
---|
134 | 132 | } |
---|
135 | 133 | |
---|
136 | | -static int emif_regdump_open(struct inode *inode, struct file *file) |
---|
137 | | -{ |
---|
138 | | - return single_open(file, emif_regdump_show, inode->i_private); |
---|
139 | | -} |
---|
140 | | - |
---|
141 | | -static const struct file_operations emif_regdump_fops = { |
---|
142 | | - .open = emif_regdump_open, |
---|
143 | | - .read = seq_read, |
---|
144 | | - .release = single_release, |
---|
145 | | -}; |
---|
| 134 | +DEFINE_SHOW_ATTRIBUTE(emif_regdump); |
---|
146 | 135 | |
---|
147 | 136 | static int emif_mr4_show(struct seq_file *s, void *unused) |
---|
148 | 137 | { |
---|
.. | .. |
---|
152 | 141 | return 0; |
---|
153 | 142 | } |
---|
154 | 143 | |
---|
155 | | -static int emif_mr4_open(struct inode *inode, struct file *file) |
---|
156 | | -{ |
---|
157 | | - return single_open(file, emif_mr4_show, inode->i_private); |
---|
158 | | -} |
---|
159 | | - |
---|
160 | | -static const struct file_operations emif_mr4_fops = { |
---|
161 | | - .open = emif_mr4_open, |
---|
162 | | - .read = seq_read, |
---|
163 | | - .release = single_release, |
---|
164 | | -}; |
---|
| 144 | +DEFINE_SHOW_ATTRIBUTE(emif_mr4); |
---|
165 | 145 | |
---|
166 | 146 | static int __init_or_module emif_debugfs_init(struct emif_data *emif) |
---|
167 | 147 | { |
---|
.. | .. |
---|
261 | 241 | * the EMIF_PWR_MGMT_CTRL[10:8] REG_LP_MODE bit field to 0x4. |
---|
262 | 242 | */ |
---|
263 | 243 | if ((emif->plat_data->ip_rev == EMIF_4D) && |
---|
264 | | - (EMIF_LP_MODE_PWR_DN == lpmode)) { |
---|
| 244 | + (lpmode == EMIF_LP_MODE_PWR_DN)) { |
---|
265 | 245 | WARN_ONCE(1, |
---|
266 | | - "REG_LP_MODE = LP_MODE_PWR_DN(4) is prohibited by" |
---|
267 | | - "erratum i743 switch to LP_MODE_SELF_REFRESH(2)\n"); |
---|
| 246 | + "REG_LP_MODE = LP_MODE_PWR_DN(4) is prohibited by erratum i743 switch to LP_MODE_SELF_REFRESH(2)\n"); |
---|
268 | 247 | /* rollback LP_MODE to Self-refresh mode */ |
---|
269 | 248 | lpmode = EMIF_LP_MODE_SELF_REFRESH; |
---|
270 | 249 | } |
---|
.. | .. |
---|
693 | 672 | u32 fifo_we_slave_ratio; |
---|
694 | 673 | |
---|
695 | 674 | fifo_we_slave_ratio = DIV_ROUND_CLOSEST( |
---|
696 | | - EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256 , t_ck); |
---|
| 675 | + EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256, t_ck); |
---|
697 | 676 | |
---|
698 | 677 | return fifo_we_slave_ratio | fifo_we_slave_ratio << 11 | |
---|
699 | 678 | fifo_we_slave_ratio << 22; |
---|
.. | .. |
---|
704 | 683 | u32 fifo_we_slave_ratio; |
---|
705 | 684 | |
---|
706 | 685 | fifo_we_slave_ratio = DIV_ROUND_CLOSEST( |
---|
707 | | - EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256 , t_ck); |
---|
| 686 | + EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256, t_ck); |
---|
708 | 687 | |
---|
709 | 688 | return fifo_we_slave_ratio >> 10 | fifo_we_slave_ratio << 1 | |
---|
710 | 689 | fifo_we_slave_ratio << 12 | fifo_we_slave_ratio << 23; |
---|
.. | .. |
---|
715 | 694 | u32 fifo_we_slave_ratio; |
---|
716 | 695 | |
---|
717 | 696 | fifo_we_slave_ratio = DIV_ROUND_CLOSEST( |
---|
718 | | - EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256 , t_ck); |
---|
| 697 | + EMIF_INTELLI_PHY_DQS_GATE_OPENING_DELAY_PS * 256, t_ck); |
---|
719 | 698 | |
---|
720 | 699 | return fifo_we_slave_ratio >> 9 | fifo_we_slave_ratio << 2 | |
---|
721 | 700 | fifo_we_slave_ratio << 13; |
---|
.. | .. |
---|
954 | 933 | EMIF_CUSTOM_CONFIG_EXTENDED_TEMP_PART)) { |
---|
955 | 934 | if (emif->temperature_level >= SDRAM_TEMP_HIGH_DERATE_REFRESH) { |
---|
956 | 935 | dev_err(emif->dev, |
---|
957 | | - "%s:NOT Extended temperature capable memory." |
---|
958 | | - "Converting MR4=0x%02x as shutdown event\n", |
---|
| 936 | + "%s:NOT Extended temperature capable memory. Converting MR4=0x%02x as shutdown event\n", |
---|
959 | 937 | __func__, emif->temperature_level); |
---|
960 | 938 | /* |
---|
961 | 939 | * Temperature far too high - do kernel_power_off() |
---|
.. | .. |
---|
1297 | 1275 | if (of_find_property(np_emif, "cal-resistor-per-cs", &len)) |
---|
1298 | 1276 | dev_info->cal_resistors_per_cs = true; |
---|
1299 | 1277 | |
---|
1300 | | - if (of_device_is_compatible(np_ddr , "jedec,lpddr2-s4")) |
---|
| 1278 | + if (of_device_is_compatible(np_ddr, "jedec,lpddr2-s4")) |
---|
1301 | 1279 | dev_info->type = DDR_TYPE_LPDDR2_S4; |
---|
1302 | | - else if (of_device_is_compatible(np_ddr , "jedec,lpddr2-s2")) |
---|
| 1280 | + else if (of_device_is_compatible(np_ddr, "jedec,lpddr2-s2")) |
---|
1303 | 1281 | dev_info->type = DDR_TYPE_LPDDR2_S2; |
---|
1304 | 1282 | |
---|
1305 | 1283 | of_property_read_u32(np_ddr, "density", &density); |
---|
.. | .. |
---|
1425 | 1403 | temp = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); |
---|
1426 | 1404 | dev_info = devm_kzalloc(dev, sizeof(*dev_info), GFP_KERNEL); |
---|
1427 | 1405 | |
---|
1428 | | - if (!emif || !pd || !dev_info) { |
---|
| 1406 | + if (!emif || !temp || !dev_info) { |
---|
1429 | 1407 | dev_err(dev, "%s:%d: allocation error\n", __func__, __LINE__); |
---|
1430 | 1408 | goto error; |
---|
1431 | 1409 | } |
---|
.. | .. |
---|
1517 | 1495 | { |
---|
1518 | 1496 | struct emif_data *emif; |
---|
1519 | 1497 | struct resource *res; |
---|
1520 | | - int irq; |
---|
| 1498 | + int irq, ret; |
---|
1521 | 1499 | |
---|
1522 | 1500 | if (pdev->dev.of_node) |
---|
1523 | 1501 | emif = of_get_memory_device_details(pdev->dev.of_node, &pdev->dev); |
---|
.. | .. |
---|
1542 | 1520 | goto error; |
---|
1543 | 1521 | |
---|
1544 | 1522 | irq = platform_get_irq(pdev, 0); |
---|
1545 | | - if (irq < 0) { |
---|
1546 | | - dev_err(emif->dev, "%s: error getting IRQ resource - %d\n", |
---|
1547 | | - __func__, irq); |
---|
| 1523 | + if (irq < 0) |
---|
1548 | 1524 | goto error; |
---|
1549 | | - } |
---|
1550 | 1525 | |
---|
1551 | 1526 | emif_onetime_settings(emif); |
---|
1552 | 1527 | emif_debugfs_init(emif); |
---|
1553 | 1528 | disable_and_clear_all_interrupts(emif); |
---|
1554 | | - setup_interrupts(emif, irq); |
---|
| 1529 | + ret = setup_interrupts(emif, irq); |
---|
| 1530 | + if (ret) |
---|
| 1531 | + goto error; |
---|
1555 | 1532 | |
---|
1556 | 1533 | /* One-time actions taken on probing the first device */ |
---|
1557 | 1534 | if (!emif1) { |
---|
.. | .. |
---|
1592 | 1569 | static int get_emif_reg_values(struct emif_data *emif, u32 freq, |
---|
1593 | 1570 | struct emif_regs *regs) |
---|
1594 | 1571 | { |
---|
1595 | | - u32 cs1_used, ip_rev, phy_type; |
---|
| 1572 | + u32 ip_rev, phy_type; |
---|
1596 | 1573 | u32 cl, type; |
---|
1597 | 1574 | const struct lpddr2_timings *timings; |
---|
1598 | 1575 | const struct lpddr2_min_tck *min_tck; |
---|
.. | .. |
---|
1600 | 1577 | const struct lpddr2_addressing *addressing; |
---|
1601 | 1578 | struct emif_data *emif_for_calc; |
---|
1602 | 1579 | struct device *dev; |
---|
1603 | | - const struct emif_custom_configs *custom_configs; |
---|
1604 | 1580 | |
---|
1605 | 1581 | dev = emif->dev; |
---|
1606 | 1582 | /* |
---|
.. | .. |
---|
1618 | 1594 | |
---|
1619 | 1595 | device_info = emif_for_calc->plat_data->device_info; |
---|
1620 | 1596 | type = device_info->type; |
---|
1621 | | - cs1_used = device_info->cs1_used; |
---|
1622 | 1597 | ip_rev = emif_for_calc->plat_data->ip_rev; |
---|
1623 | 1598 | phy_type = emif_for_calc->plat_data->phy_type; |
---|
1624 | 1599 | |
---|
1625 | 1600 | min_tck = emif_for_calc->plat_data->min_tck; |
---|
1626 | | - custom_configs = emif_for_calc->plat_data->custom_configs; |
---|
1627 | 1601 | |
---|
1628 | 1602 | set_ddr_clk_period(freq); |
---|
1629 | 1603 | |
---|