hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/memory/emif.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * EMIF driver
34 *
....@@ -5,10 +6,6 @@
56 *
67 * Aneesh V <aneesh@ti.com>
78 * 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.
129 */
1310 #include <linux/err.h>
1411 #include <linux/kernel.h>
....@@ -26,8 +23,9 @@
2623 #include <linux/list.h>
2724 #include <linux/spinlock.h>
2825 #include <linux/pm.h>
29
-#include <memory/jedec_ddr.h>
26
+
3027 #include "emif.h"
28
+#include "jedec_ddr.h"
3129 #include "of_memory.h"
3230
3331 /**
....@@ -133,16 +131,7 @@
133131 return 0;
134132 }
135133
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);
146135
147136 static int emif_mr4_show(struct seq_file *s, void *unused)
148137 {
....@@ -152,16 +141,7 @@
152141 return 0;
153142 }
154143
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);
165145
166146 static int __init_or_module emif_debugfs_init(struct emif_data *emif)
167147 {
....@@ -261,10 +241,9 @@
261241 * the EMIF_PWR_MGMT_CTRL[10:8] REG_LP_MODE bit field to 0x4.
262242 */
263243 if ((emif->plat_data->ip_rev == EMIF_4D) &&
264
- (EMIF_LP_MODE_PWR_DN == lpmode)) {
244
+ (lpmode == EMIF_LP_MODE_PWR_DN)) {
265245 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");
268247 /* rollback LP_MODE to Self-refresh mode */
269248 lpmode = EMIF_LP_MODE_SELF_REFRESH;
270249 }
....@@ -693,7 +672,7 @@
693672 u32 fifo_we_slave_ratio;
694673
695674 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);
697676
698677 return fifo_we_slave_ratio | fifo_we_slave_ratio << 11 |
699678 fifo_we_slave_ratio << 22;
....@@ -704,7 +683,7 @@
704683 u32 fifo_we_slave_ratio;
705684
706685 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);
708687
709688 return fifo_we_slave_ratio >> 10 | fifo_we_slave_ratio << 1 |
710689 fifo_we_slave_ratio << 12 | fifo_we_slave_ratio << 23;
....@@ -715,7 +694,7 @@
715694 u32 fifo_we_slave_ratio;
716695
717696 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);
719698
720699 return fifo_we_slave_ratio >> 9 | fifo_we_slave_ratio << 2 |
721700 fifo_we_slave_ratio << 13;
....@@ -954,8 +933,7 @@
954933 EMIF_CUSTOM_CONFIG_EXTENDED_TEMP_PART)) {
955934 if (emif->temperature_level >= SDRAM_TEMP_HIGH_DERATE_REFRESH) {
956935 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",
959937 __func__, emif->temperature_level);
960938 /*
961939 * Temperature far too high - do kernel_power_off()
....@@ -1297,9 +1275,9 @@
12971275 if (of_find_property(np_emif, "cal-resistor-per-cs", &len))
12981276 dev_info->cal_resistors_per_cs = true;
12991277
1300
- if (of_device_is_compatible(np_ddr , "jedec,lpddr2-s4"))
1278
+ if (of_device_is_compatible(np_ddr, "jedec,lpddr2-s4"))
13011279 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"))
13031281 dev_info->type = DDR_TYPE_LPDDR2_S2;
13041282
13051283 of_property_read_u32(np_ddr, "density", &density);
....@@ -1425,7 +1403,7 @@
14251403 temp = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
14261404 dev_info = devm_kzalloc(dev, sizeof(*dev_info), GFP_KERNEL);
14271405
1428
- if (!emif || !pd || !dev_info) {
1406
+ if (!emif || !temp || !dev_info) {
14291407 dev_err(dev, "%s:%d: allocation error\n", __func__, __LINE__);
14301408 goto error;
14311409 }
....@@ -1517,7 +1495,7 @@
15171495 {
15181496 struct emif_data *emif;
15191497 struct resource *res;
1520
- int irq;
1498
+ int irq, ret;
15211499
15221500 if (pdev->dev.of_node)
15231501 emif = of_get_memory_device_details(pdev->dev.of_node, &pdev->dev);
....@@ -1542,16 +1520,15 @@
15421520 goto error;
15431521
15441522 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)
15481524 goto error;
1549
- }
15501525
15511526 emif_onetime_settings(emif);
15521527 emif_debugfs_init(emif);
15531528 disable_and_clear_all_interrupts(emif);
1554
- setup_interrupts(emif, irq);
1529
+ ret = setup_interrupts(emif, irq);
1530
+ if (ret)
1531
+ goto error;
15551532
15561533 /* One-time actions taken on probing the first device */
15571534 if (!emif1) {
....@@ -1592,7 +1569,7 @@
15921569 static int get_emif_reg_values(struct emif_data *emif, u32 freq,
15931570 struct emif_regs *regs)
15941571 {
1595
- u32 cs1_used, ip_rev, phy_type;
1572
+ u32 ip_rev, phy_type;
15961573 u32 cl, type;
15971574 const struct lpddr2_timings *timings;
15981575 const struct lpddr2_min_tck *min_tck;
....@@ -1600,7 +1577,6 @@
16001577 const struct lpddr2_addressing *addressing;
16011578 struct emif_data *emif_for_calc;
16021579 struct device *dev;
1603
- const struct emif_custom_configs *custom_configs;
16041580
16051581 dev = emif->dev;
16061582 /*
....@@ -1618,12 +1594,10 @@
16181594
16191595 device_info = emif_for_calc->plat_data->device_info;
16201596 type = device_info->type;
1621
- cs1_used = device_info->cs1_used;
16221597 ip_rev = emif_for_calc->plat_data->ip_rev;
16231598 phy_type = emif_for_calc->plat_data->phy_type;
16241599
16251600 min_tck = emif_for_calc->plat_data->min_tck;
1626
- custom_configs = emif_for_calc->plat_data->custom_configs;
16271601
16281602 set_ddr_clk_period(freq);
16291603