Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ufs: Add freq-table-hz property for UFS device

Add freq-table-hz propery for UFS device to keep track of
<min max> frequencies supported by UFS clocks.

Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
Signed-off-by: Dolev Raviv <draviv@codeaurora.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Sahitya Tummala and committed by
Christoph Hellwig
4cff6d99 1ab27c9c

+43 -19
+6 -6
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt
··· 26 26 - clocks : List of phandle and clock specifier pairs 27 27 - clock-names : List of clock input name strings sorted in the same 28 28 order as the clocks property. 29 - - max-clock-frequency-hz : List of maximum operating frequency stored in the same 30 - order as the clocks property. If this property is not 31 - defined or a value in the array is "0" then it is assumed 32 - that the frequency is set by the parent clock or a 33 - fixed rate clock source. 29 + - freq-table-hz : Array of <min max> operating frequencies stored in the same 30 + order as the clocks property. If this property is not 31 + defined or a value in the array is "0" then it is assumed 32 + that the frequency is set by the parent clock or a 33 + fixed rate clock source. 34 34 35 35 Note: If above properties are not defined it can be assumed that the supply 36 36 regulators or clocks are always on. ··· 53 53 54 54 clocks = <&core 0>, <&ref 0>, <&iface 0>; 55 55 clock-names = "core_clk", "ref_clk", "iface_clk"; 56 - max-clock-frequency-hz = <100000000 19200000 0>; 56 + freq-table-hz = <100000000 200000000>, <0 0>, <0 0>; 57 57 };
+35 -13
drivers/scsi/ufs/ufshcd-pltfrm.c
··· 63 63 char *name; 64 64 u32 *clkfreq = NULL; 65 65 struct ufs_clk_info *clki; 66 + int len = 0; 67 + size_t sz = 0; 66 68 67 69 if (!np) 68 70 goto out; ··· 84 82 if (cnt <= 0) 85 83 goto out; 86 84 87 - clkfreq = kzalloc(cnt * sizeof(*clkfreq), GFP_KERNEL); 85 + if (!of_get_property(np, "freq-table-hz", &len)) { 86 + dev_info(dev, "freq-table-hz property not specified\n"); 87 + goto out; 88 + } 89 + 90 + if (len <= 0) 91 + goto out; 92 + 93 + sz = len / sizeof(*clkfreq); 94 + if (sz != 2 * cnt) { 95 + dev_err(dev, "%s len mismatch\n", "freq-table-hz"); 96 + ret = -EINVAL; 97 + goto out; 98 + } 99 + 100 + clkfreq = devm_kzalloc(dev, sz * sizeof(*clkfreq), 101 + GFP_KERNEL); 88 102 if (!clkfreq) { 103 + dev_err(dev, "%s: no memory\n", "freq-table-hz"); 89 104 ret = -ENOMEM; 90 - dev_err(dev, "%s: memory alloc failed\n", __func__); 91 105 goto out; 92 106 } 93 107 94 - ret = of_property_read_u32_array(np, 95 - "max-clock-frequency-hz", clkfreq, cnt); 108 + ret = of_property_read_u32_array(np, "freq-table-hz", 109 + clkfreq, sz); 96 110 if (ret && (ret != -EINVAL)) { 97 - dev_err(dev, "%s: invalid max-clock-frequency-hz property, %d\n", 98 - __func__, ret); 99 - goto out; 111 + dev_err(dev, "%s: error reading array %d\n", 112 + "freq-table-hz", ret); 113 + goto free_clkfreq; 100 114 } 101 115 102 - for (i = 0; i < cnt; i++) { 116 + for (i = 0; i < sz; i += 2) { 103 117 ret = of_property_read_string_index(np, 104 - "clock-names", i, (const char **)&name); 118 + "clock-names", i/2, (const char **)&name); 105 119 if (ret) 106 - goto out; 120 + goto free_clkfreq; 107 121 108 122 clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL); 109 123 if (!clki) { 110 124 ret = -ENOMEM; 111 - goto out; 125 + goto free_clkfreq; 112 126 } 113 127 114 - clki->max_freq = clkfreq[i]; 128 + clki->min_freq = clkfreq[i]; 129 + clki->max_freq = clkfreq[i+1]; 115 130 clki->name = kstrdup(name, GFP_KERNEL); 131 + dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz", 132 + clki->min_freq, clki->max_freq, clki->name); 116 133 list_add_tail(&clki->list, &hba->clk_list_head); 117 134 } 118 - out: 135 + free_clkfreq: 119 136 kfree(clkfreq); 137 + out: 120 138 return ret; 121 139 } 122 140
+2
drivers/scsi/ufs/ufshcd.h
··· 209 209 * @clk: clock node 210 210 * @name: clock name 211 211 * @max_freq: maximum frequency supported by the clock 212 + * @min_freq: min frequency that can be used for clock scaling 212 213 * @enabled: variable to check against multiple enable/disable 213 214 */ 214 215 struct ufs_clk_info { ··· 217 216 struct clk *clk; 218 217 const char *name; 219 218 u32 max_freq; 219 + u32 min_freq; 220 220 bool enabled; 221 221 }; 222 222