|
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>
|
@@ -213,6 +214,55 @@ static void ufshcd_init_lanes_per_dir(struct ufs_hba *hba)
|
213 | 214 | }
|
214 | 215 | }
|
215 | 216 |
|
| 217 | +/** |
| 218 | + * ufshcd_parse_clock_min_max_freq - Parse MIN and MAX clocks freq |
| 219 | + * @hba: per adapter instance |
| 220 | + * |
| 221 | + * This function parses MIN and MAX frequencies of all clocks required |
| 222 | + * by the host drivers. |
| 223 | + * |
| 224 | + * Returns 0 for success and non-zero for failure |
| 225 | + */ |
| 226 | +static int ufshcd_parse_clock_min_max_freq(struct ufs_hba *hba) |
| 227 | +{ |
| 228 | + struct list_head *head = &hba->clk_list_head; |
| 229 | + struct ufs_clk_info *clki; |
| 230 | + struct dev_pm_opp *opp; |
| 231 | + unsigned long freq; |
| 232 | + u8 idx = 0; |
| 233 | + |
| 234 | + list_for_each_entry(clki, head, list) { |
| 235 | + if (!clki->name) |
| 236 | + continue; |
| 237 | + |
| 238 | + clki->clk = devm_clk_get(hba->dev, clki->name); |
| 239 | + if (IS_ERR(clki->clk)) |
| 240 | + continue; |
| 241 | + |
| 242 | + /* Find Max Freq */ |
| 243 | + freq = ULONG_MAX; |
| 244 | + opp = dev_pm_opp_find_freq_floor_indexed(hba->dev, &freq, idx); |
| 245 | + if (IS_ERR(opp)) { |
| 246 | + dev_err(hba->dev, "Failed to find OPP for MAX frequency\n"); |
| 247 | + return PTR_ERR(opp); |
| 248 | + } |
| 249 | + clki->max_freq = dev_pm_opp_get_freq_indexed(opp, idx); |
| 250 | + dev_pm_opp_put(opp); |
| 251 | + |
| 252 | + /* Find Min Freq */ |
| 253 | + freq = 0; |
| 254 | + opp = dev_pm_opp_find_freq_ceil_indexed(hba->dev, &freq, idx); |
| 255 | + if (IS_ERR(opp)) { |
| 256 | + dev_err(hba->dev, "Failed to find OPP for MIN frequency\n"); |
| 257 | + return PTR_ERR(opp); |
| 258 | + } |
| 259 | + clki->min_freq = dev_pm_opp_get_freq_indexed(opp, idx++); |
| 260 | + dev_pm_opp_put(opp); |
| 261 | + } |
| 262 | + |
| 263 | + return 0; |
| 264 | +} |
| 265 | + |
216 | 266 | static int ufshcd_parse_operating_points(struct ufs_hba *hba)
|
217 | 267 | {
|
218 | 268 | struct device *dev = hba->dev;
|
@@ -279,6 +329,10 @@ static int ufshcd_parse_operating_points(struct ufs_hba *hba)
|
279 | 329 | return ret;
|
280 | 330 | }
|
281 | 331 |
|
| 332 | + ret = ufshcd_parse_clock_min_max_freq(hba); |
| 333 | + if (ret) |
| 334 | + return ret; |
| 335 | + |
282 | 336 | hba->use_pm_opp = true;
|
283 | 337 |
|
284 | 338 | return 0;
|
|
0 commit comments