|
8 | 8 | * Vinayak Holikatti <h.vinayak@samsung.com> |
9 | 9 | */ |
10 | 10 |
|
| 11 | +#include <linux/clk.h> |
11 | 12 | #include <linux/module.h> |
12 | 13 | #include <linux/platform_device.h> |
13 | 14 | #include <linux/pm_opp.h> |
@@ -208,6 +209,55 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba) |
208 | 209 | } |
209 | 210 | } |
210 | 211 |
|
| 212 | +/** |
| 213 | + * ufshcd_parse_clock_min_max_freq - Parse MIN and MAX clocks freq |
| 214 | + * @hba: per adapter instance |
| 215 | + * |
| 216 | + * This function parses MIN and MAX frequencies of all clocks required |
| 217 | + * by the host drivers. |
| 218 | + * |
| 219 | + * Returns 0 for success and non-zero for failure |
| 220 | + */ |
| 221 | +static int ufshcd_parse_clock_min_max_freq(struct ufs_hba *hba) |
| 222 | +{ |
| 223 | + struct list_head *head = &hba->clk_list_head; |
| 224 | + struct ufs_clk_info *clki; |
| 225 | + struct dev_pm_opp *opp; |
| 226 | + unsigned long freq; |
| 227 | + u8 idx = 0; |
| 228 | + |
| 229 | + list_for_each_entry(clki, head, list) { |
| 230 | + if (!clki->name) |
| 231 | + continue; |
| 232 | + |
| 233 | + clki->clk = devm_clk_get(hba->dev, clki->name); |
| 234 | + if (IS_ERR(clki->clk)) |
| 235 | + continue; |
| 236 | + |
| 237 | + /* Find Max Freq */ |
| 238 | + freq = ULONG_MAX; |
| 239 | + opp = dev_pm_opp_find_freq_floor_indexed(hba->dev, &freq, idx); |
| 240 | + if (IS_ERR(opp)) { |
| 241 | + dev_err(hba->dev, "Failed to find OPP for MAX frequency\n"); |
| 242 | + return PTR_ERR(opp); |
| 243 | + } |
| 244 | + clki->max_freq = dev_pm_opp_get_freq_indexed(opp, idx); |
| 245 | + dev_pm_opp_put(opp); |
| 246 | + |
| 247 | + /* Find Min Freq */ |
| 248 | + freq = 0; |
| 249 | + opp = dev_pm_opp_find_freq_ceil_indexed(hba->dev, &freq, idx); |
| 250 | + if (IS_ERR(opp)) { |
| 251 | + dev_err(hba->dev, "Failed to find OPP for MIN frequency\n"); |
| 252 | + return PTR_ERR(opp); |
| 253 | + } |
| 254 | + clki->min_freq = dev_pm_opp_get_freq_indexed(opp, idx++); |
| 255 | + dev_pm_opp_put(opp); |
| 256 | + } |
| 257 | + |
| 258 | + return 0; |
| 259 | +} |
| 260 | + |
211 | 261 | static int ufshcd_parse_operating_points(struct ufs_hba *hba) |
212 | 262 | { |
213 | 263 | struct device *dev = hba->dev; |
@@ -274,6 +324,10 @@ static int ufshcd_parse_operating_points(struct ufs_hba *hba) |
274 | 324 | return ret; |
275 | 325 | } |
276 | 326 |
|
| 327 | + ret = ufshcd_parse_clock_min_max_freq(hba); |
| 328 | + if (ret) |
| 329 | + return ret; |
| 330 | + |
277 | 331 | hba->use_pm_opp = true; |
278 | 332 |
|
279 | 333 | return 0; |
|
0 commit comments