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

Merge branch 'clk-parent-rewrite-1' into clk-next

- Rewrite how clk parents can be specified to be DT/clkdev based instead
of just string based

* clk-parent-rewrite-1:
clk: Cache core in clk_fetch_parent_index() without names
clk: fixed-factor: Initialize clk_init_data on stack
clk: fixed-factor: Let clk framework find parent
clk: Allow parents to be specified via clkspec index
clk: Look for parents with clkdev based clk_lookups
clk: Allow parents to be specified without string names
clk: Add of_clk_hw_register() API for early clk drivers
driver core: Let dev_of_node() accept a NULL dev
clk: Prepare for clk registration API that uses DT nodes
clkdev: Move clk creation outside of 'clocks_mutex'

+348 -117
+34 -21
drivers/clk/clk-fixed-factor.c
··· 64 64 }; 65 65 EXPORT_SYMBOL_GPL(clk_fixed_factor_ops); 66 66 67 - struct clk_hw *clk_hw_register_fixed_factor(struct device *dev, 68 - const char *name, const char *parent_name, unsigned long flags, 69 - unsigned int mult, unsigned int div) 67 + static struct clk_hw * 68 + __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, 69 + const char *name, const char *parent_name, int index, 70 + unsigned long flags, unsigned int mult, unsigned int div) 70 71 { 71 72 struct clk_fixed_factor *fix; 72 - struct clk_init_data init; 73 + struct clk_init_data init = { }; 74 + struct clk_parent_data pdata = { .index = index }; 73 75 struct clk_hw *hw; 74 76 int ret; 75 77 ··· 87 85 init.name = name; 88 86 init.ops = &clk_fixed_factor_ops; 89 87 init.flags = flags; 90 - init.parent_names = &parent_name; 88 + if (parent_name) 89 + init.parent_names = &parent_name; 90 + else 91 + init.parent_data = &pdata; 91 92 init.num_parents = 1; 92 93 93 94 hw = &fix->hw; 94 - ret = clk_hw_register(dev, hw); 95 + if (dev) 96 + ret = clk_hw_register(dev, hw); 97 + else 98 + ret = of_clk_hw_register(np, hw); 95 99 if (ret) { 96 100 kfree(fix); 97 101 hw = ERR_PTR(ret); 98 102 } 99 103 100 104 return hw; 105 + } 106 + 107 + struct clk_hw *clk_hw_register_fixed_factor(struct device *dev, 108 + const char *name, const char *parent_name, unsigned long flags, 109 + unsigned int mult, unsigned int div) 110 + { 111 + return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, -1, 112 + flags, mult, div); 101 113 } 102 114 EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor); 103 115 ··· 159 143 { /* Sentinel */ }, 160 144 }; 161 145 162 - static struct clk *_of_fixed_factor_clk_setup(struct device_node *node) 146 + static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node) 163 147 { 164 - struct clk *clk; 148 + struct clk_hw *hw; 165 149 const char *clk_name = node->name; 166 - const char *parent_name; 167 150 unsigned long flags = 0; 168 151 u32 div, mult; 169 152 int ret; ··· 180 165 } 181 166 182 167 of_property_read_string(node, "clock-output-names", &clk_name); 183 - parent_name = of_clk_get_parent_name(node, 0); 184 168 185 169 if (of_match_node(set_rate_parent_matches, node)) 186 170 flags |= CLK_SET_RATE_PARENT; 187 171 188 - clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags, 189 - mult, div); 190 - if (IS_ERR(clk)) { 172 + hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, 0, 173 + flags, mult, div); 174 + if (IS_ERR(hw)) { 191 175 /* 192 - * If parent clock is not registered, registration would fail. 193 176 * Clear OF_POPULATED flag so that clock registration can be 194 177 * attempted again from probe function. 195 178 */ 196 179 of_node_clear_flag(node, OF_POPULATED); 197 - return clk; 180 + return ERR_CAST(hw); 198 181 } 199 182 200 - ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); 183 + ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw); 201 184 if (ret) { 202 - clk_unregister(clk); 185 + clk_hw_unregister_fixed_factor(hw); 203 186 return ERR_PTR(ret); 204 187 } 205 188 206 - return clk; 189 + return hw; 207 190 } 208 191 209 192 /** ··· 216 203 217 204 static int of_fixed_factor_clk_remove(struct platform_device *pdev) 218 205 { 219 - struct clk *clk = platform_get_drvdata(pdev); 206 + struct clk_hw *clk = platform_get_drvdata(pdev); 220 207 221 208 of_clk_del_provider(pdev->dev.of_node); 222 - clk_unregister_fixed_factor(clk); 209 + clk_hw_unregister_fixed_factor(clk); 223 210 224 211 return 0; 225 212 } 226 213 227 214 static int of_fixed_factor_clk_probe(struct platform_device *pdev) 228 215 { 229 - struct clk *clk; 216 + struct clk_hw *clk; 230 217 231 218 /* 232 219 * This function is not executed when of_fixed_factor_clk_setup
+273 -80
drivers/clk/clk.c
··· 39 39 40 40 /*** private data structures ***/ 41 41 42 + struct clk_parent_map { 43 + const struct clk_hw *hw; 44 + struct clk_core *core; 45 + const char *fw_name; 46 + const char *name; 47 + int index; 48 + }; 49 + 42 50 struct clk_core { 43 51 const char *name; 44 52 const struct clk_ops *ops; 45 53 struct clk_hw *hw; 46 54 struct module *owner; 47 55 struct device *dev; 56 + struct device_node *of_node; 48 57 struct clk_core *parent; 49 - const char **parent_names; 50 - struct clk_core **parents; 58 + struct clk_parent_map *parents; 51 59 u8 num_parents; 52 60 u8 new_parent_index; 53 61 unsigned long rate; ··· 324 316 return NULL; 325 317 } 326 318 319 + /** 320 + * clk_core_get - Find the clk_core parent of a clk 321 + * @core: clk to find parent of 322 + * @p_index: parent index to search for 323 + * 324 + * This is the preferred method for clk providers to find the parent of a 325 + * clk when that parent is external to the clk controller. The parent_names 326 + * array is indexed and treated as a local name matching a string in the device 327 + * node's 'clock-names' property or as the 'con_id' matching the device's 328 + * dev_name() in a clk_lookup. This allows clk providers to use their own 329 + * namespace instead of looking for a globally unique parent string. 330 + * 331 + * For example the following DT snippet would allow a clock registered by the 332 + * clock-controller@c001 that has a clk_init_data::parent_data array 333 + * with 'xtal' in the 'name' member to find the clock provided by the 334 + * clock-controller@f00abcd without needing to get the globally unique name of 335 + * the xtal clk. 336 + * 337 + * parent: clock-controller@f00abcd { 338 + * reg = <0xf00abcd 0xabcd>; 339 + * #clock-cells = <0>; 340 + * }; 341 + * 342 + * clock-controller@c001 { 343 + * reg = <0xc001 0xf00d>; 344 + * clocks = <&parent>; 345 + * clock-names = "xtal"; 346 + * #clock-cells = <1>; 347 + * }; 348 + * 349 + * Returns: -ENOENT when the provider can't be found or the clk doesn't 350 + * exist in the provider. -EINVAL when the name can't be found. NULL when the 351 + * provider knows about the clk but it isn't provided on this system. 352 + * A valid clk_core pointer when the clk can be found in the provider. 353 + */ 354 + static struct clk_core *clk_core_get(struct clk_core *core, u8 p_index) 355 + { 356 + const char *name = core->parents[p_index].fw_name; 357 + int index = core->parents[p_index].index; 358 + struct clk_hw *hw = ERR_PTR(-ENOENT); 359 + struct device *dev = core->dev; 360 + const char *dev_id = dev ? dev_name(dev) : NULL; 361 + struct device_node *np = core->of_node; 362 + 363 + if (np && index >= 0) 364 + hw = of_clk_get_hw(np, index, name); 365 + 366 + /* 367 + * If the DT search above couldn't find the provider or the provider 368 + * didn't know about this clk, fallback to looking up via clkdev based 369 + * clk_lookups 370 + */ 371 + if (PTR_ERR(hw) == -ENOENT && name) 372 + hw = clk_find_hw(dev_id, name); 373 + 374 + if (IS_ERR(hw)) 375 + return ERR_CAST(hw); 376 + 377 + return hw->core; 378 + } 379 + 380 + static void clk_core_fill_parent_index(struct clk_core *core, u8 index) 381 + { 382 + struct clk_parent_map *entry = &core->parents[index]; 383 + struct clk_core *parent = ERR_PTR(-ENOENT); 384 + 385 + if (entry->hw) { 386 + parent = entry->hw->core; 387 + /* 388 + * We have a direct reference but it isn't registered yet? 389 + * Orphan it and let clk_reparent() update the orphan status 390 + * when the parent is registered. 391 + */ 392 + if (!parent) 393 + parent = ERR_PTR(-EPROBE_DEFER); 394 + } else { 395 + parent = clk_core_get(core, index); 396 + if (IS_ERR(parent) && PTR_ERR(parent) == -ENOENT) 397 + parent = clk_core_lookup(entry->name); 398 + } 399 + 400 + /* Only cache it if it's not an error */ 401 + if (!IS_ERR(parent)) 402 + entry->core = parent; 403 + } 404 + 327 405 static struct clk_core *clk_core_get_parent_by_index(struct clk_core *core, 328 406 u8 index) 329 407 { 330 - if (!core || index >= core->num_parents) 408 + if (!core || index >= core->num_parents || !core->parents) 331 409 return NULL; 332 410 333 - if (!core->parents[index]) 334 - core->parents[index] = 335 - clk_core_lookup(core->parent_names[index]); 411 + if (!core->parents[index].core) 412 + clk_core_fill_parent_index(core, index); 336 413 337 - return core->parents[index]; 414 + return core->parents[index].core; 338 415 } 339 416 340 417 struct clk_hw * ··· 1613 1520 return -EINVAL; 1614 1521 1615 1522 for (i = 0; i < core->num_parents; i++) { 1616 - if (core->parents[i] == parent) 1523 + /* Found it first try! */ 1524 + if (core->parents[i].core == parent) 1617 1525 return i; 1618 1526 1619 - if (core->parents[i]) 1527 + /* Something else is here, so keep looking */ 1528 + if (core->parents[i].core) 1620 1529 continue; 1621 1530 1622 - /* Fallback to comparing globally unique names */ 1623 - if (!strcmp(parent->name, core->parent_names[i])) { 1624 - core->parents[i] = parent; 1625 - return i; 1531 + /* Maybe core hasn't been cached but the hw is all we know? */ 1532 + if (core->parents[i].hw) { 1533 + if (core->parents[i].hw == parent->hw) 1534 + break; 1535 + 1536 + /* Didn't match, but we're expecting a clk_hw */ 1537 + continue; 1626 1538 } 1539 + 1540 + /* Maybe it hasn't been cached (clk_set_parent() path) */ 1541 + if (parent == clk_core_get(core, i)) 1542 + break; 1543 + 1544 + /* Fallback to comparing globally unique names */ 1545 + if (!strcmp(parent->name, core->parents[i].name)) 1546 + break; 1627 1547 } 1628 1548 1629 - return -EINVAL; 1549 + if (i == core->num_parents) 1550 + return -EINVAL; 1551 + 1552 + core->parents[i].core = parent; 1553 + return i; 1630 1554 } 1631 1555 1632 1556 /* ··· 2404 2294 bool clk_has_parent(struct clk *clk, struct clk *parent) 2405 2295 { 2406 2296 struct clk_core *core, *parent_core; 2297 + int i; 2407 2298 2408 2299 /* NULL clocks should be nops, so return success if either is NULL. */ 2409 2300 if (!clk || !parent) ··· 2417 2306 if (core->parent == parent_core) 2418 2307 return true; 2419 2308 2420 - return match_string(core->parent_names, core->num_parents, 2421 - parent_core->name) >= 0; 2309 + for (i = 0; i < core->num_parents; i++) 2310 + if (!strcmp(core->parents[i].name, parent_core->name)) 2311 + return true; 2312 + 2313 + return false; 2422 2314 } 2423 2315 EXPORT_SYMBOL_GPL(clk_has_parent); 2424 2316 ··· 3003 2889 int i; 3004 2890 3005 2891 for (i = 0; i < core->num_parents - 1; i++) 3006 - seq_printf(s, "%s ", core->parent_names[i]); 2892 + seq_printf(s, "%s ", core->parents[i].name); 3007 2893 3008 - seq_printf(s, "%s\n", core->parent_names[i]); 2894 + seq_printf(s, "%s\n", core->parents[i].name); 3009 2895 3010 2896 return 0; 3011 2897 } ··· 3139 3025 */ 3140 3026 static int __clk_core_init(struct clk_core *core) 3141 3027 { 3142 - int i, ret; 3028 + int ret; 3143 3029 struct clk_core *orphan; 3144 3030 struct hlist_node *tmp2; 3145 3031 unsigned long rate; ··· 3192 3078 ret = -EINVAL; 3193 3079 goto out; 3194 3080 } 3195 - 3196 - /* throw a WARN if any entries in parent_names are NULL */ 3197 - for (i = 0; i < core->num_parents; i++) 3198 - WARN(!core->parent_names[i], 3199 - "%s: invalid NULL in %s's .parent_names\n", 3200 - __func__, core->name); 3201 3081 3202 3082 core->parent = __clk_init_parent(core); 3203 3083 ··· 3421 3313 return clk; 3422 3314 } 3423 3315 3424 - /** 3425 - * clk_register - allocate a new clock, register it and return an opaque cookie 3426 - * @dev: device that is registering this clock 3427 - * @hw: link to hardware-specific clock data 3428 - * 3429 - * clk_register is the *deprecated* interface for populating the clock tree with 3430 - * new clock nodes. Use clk_hw_register() instead. 3431 - * 3432 - * Returns: a pointer to the newly allocated struct clk which 3433 - * cannot be dereferenced by driver code but may be used in conjunction with the 3434 - * rest of the clock API. In the event of an error clk_register will return an 3435 - * error code; drivers must test for an error code after calling clk_register. 3436 - */ 3437 - struct clk *clk_register(struct device *dev, struct clk_hw *hw) 3316 + static int clk_cpy_name(const char **dst_p, const char *src, bool must_exist) 3438 3317 { 3439 - int i, ret; 3318 + const char *dst; 3319 + 3320 + if (!src) { 3321 + if (must_exist) 3322 + return -EINVAL; 3323 + return 0; 3324 + } 3325 + 3326 + *dst_p = dst = kstrdup_const(src, GFP_KERNEL); 3327 + if (!dst) 3328 + return -ENOMEM; 3329 + 3330 + return 0; 3331 + } 3332 + 3333 + static int clk_core_populate_parent_map(struct clk_core *core) 3334 + { 3335 + const struct clk_init_data *init = core->hw->init; 3336 + u8 num_parents = init->num_parents; 3337 + const char * const *parent_names = init->parent_names; 3338 + const struct clk_hw **parent_hws = init->parent_hws; 3339 + const struct clk_parent_data *parent_data = init->parent_data; 3340 + int i, ret = 0; 3341 + struct clk_parent_map *parents, *parent; 3342 + 3343 + if (!num_parents) 3344 + return 0; 3345 + 3346 + /* 3347 + * Avoid unnecessary string look-ups of clk_core's possible parents by 3348 + * having a cache of names/clk_hw pointers to clk_core pointers. 3349 + */ 3350 + parents = kcalloc(num_parents, sizeof(*parents), GFP_KERNEL); 3351 + core->parents = parents; 3352 + if (!parents) 3353 + return -ENOMEM; 3354 + 3355 + /* Copy everything over because it might be __initdata */ 3356 + for (i = 0, parent = parents; i < num_parents; i++, parent++) { 3357 + parent->index = -1; 3358 + if (parent_names) { 3359 + /* throw a WARN if any entries are NULL */ 3360 + WARN(!parent_names[i], 3361 + "%s: invalid NULL in %s's .parent_names\n", 3362 + __func__, core->name); 3363 + ret = clk_cpy_name(&parent->name, parent_names[i], 3364 + true); 3365 + } else if (parent_data) { 3366 + parent->hw = parent_data[i].hw; 3367 + parent->index = parent_data[i].index; 3368 + ret = clk_cpy_name(&parent->fw_name, 3369 + parent_data[i].fw_name, false); 3370 + if (!ret) 3371 + ret = clk_cpy_name(&parent->name, 3372 + parent_data[i].name, 3373 + false); 3374 + } else if (parent_hws) { 3375 + parent->hw = parent_hws[i]; 3376 + } else { 3377 + ret = -EINVAL; 3378 + WARN(1, "Must specify parents if num_parents > 0\n"); 3379 + } 3380 + 3381 + if (ret) { 3382 + do { 3383 + kfree_const(parents[i].name); 3384 + kfree_const(parents[i].fw_name); 3385 + } while (--i >= 0); 3386 + kfree(parents); 3387 + 3388 + return ret; 3389 + } 3390 + } 3391 + 3392 + return 0; 3393 + } 3394 + 3395 + static void clk_core_free_parent_map(struct clk_core *core) 3396 + { 3397 + int i = core->num_parents; 3398 + 3399 + if (!core->num_parents) 3400 + return; 3401 + 3402 + while (--i >= 0) { 3403 + kfree_const(core->parents[i].name); 3404 + kfree_const(core->parents[i].fw_name); 3405 + } 3406 + 3407 + kfree(core->parents); 3408 + } 3409 + 3410 + static struct clk * 3411 + __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw) 3412 + { 3413 + int ret; 3440 3414 struct clk_core *core; 3441 3415 3442 3416 core = kzalloc(sizeof(*core), GFP_KERNEL); ··· 3542 3352 if (dev && pm_runtime_enabled(dev)) 3543 3353 core->rpm_enabled = true; 3544 3354 core->dev = dev; 3355 + core->of_node = np; 3545 3356 if (dev && dev->driver) 3546 3357 core->owner = dev->driver->owner; 3547 3358 core->hw = hw; ··· 3552 3361 core->max_rate = ULONG_MAX; 3553 3362 hw->core = core; 3554 3363 3555 - /* allocate local copy in case parent_names is __initdata */ 3556 - core->parent_names = kcalloc(core->num_parents, sizeof(char *), 3557 - GFP_KERNEL); 3558 - 3559 - if (!core->parent_names) { 3560 - ret = -ENOMEM; 3561 - goto fail_parent_names; 3562 - } 3563 - 3564 - 3565 - /* copy each string name in case parent_names is __initdata */ 3566 - for (i = 0; i < core->num_parents; i++) { 3567 - core->parent_names[i] = kstrdup_const(hw->init->parent_names[i], 3568 - GFP_KERNEL); 3569 - if (!core->parent_names[i]) { 3570 - ret = -ENOMEM; 3571 - goto fail_parent_names_copy; 3572 - } 3573 - } 3574 - 3575 - /* avoid unnecessary string look-ups of clk_core's possible parents. */ 3576 - core->parents = kcalloc(core->num_parents, sizeof(*core->parents), 3577 - GFP_KERNEL); 3578 - if (!core->parents) { 3579 - ret = -ENOMEM; 3364 + ret = clk_core_populate_parent_map(core); 3365 + if (ret) 3580 3366 goto fail_parents; 3581 - }; 3582 3367 3583 3368 INIT_HLIST_HEAD(&core->clks); 3584 3369 ··· 3565 3398 hw->clk = alloc_clk(core, NULL, NULL); 3566 3399 if (IS_ERR(hw->clk)) { 3567 3400 ret = PTR_ERR(hw->clk); 3568 - goto fail_parents; 3401 + goto fail_create_clk; 3569 3402 } 3570 3403 3571 3404 clk_core_link_consumer(hw->core, hw->clk); ··· 3581 3414 free_clk(hw->clk); 3582 3415 hw->clk = NULL; 3583 3416 3417 + fail_create_clk: 3418 + clk_core_free_parent_map(core); 3584 3419 fail_parents: 3585 - kfree(core->parents); 3586 - fail_parent_names_copy: 3587 - while (--i >= 0) 3588 - kfree_const(core->parent_names[i]); 3589 - kfree(core->parent_names); 3590 - fail_parent_names: 3591 3420 fail_ops: 3592 3421 kfree_const(core->name); 3593 3422 fail_name: 3594 3423 kfree(core); 3595 3424 fail_out: 3596 3425 return ERR_PTR(ret); 3426 + } 3427 + 3428 + /** 3429 + * clk_register - allocate a new clock, register it and return an opaque cookie 3430 + * @dev: device that is registering this clock 3431 + * @hw: link to hardware-specific clock data 3432 + * 3433 + * clk_register is the *deprecated* interface for populating the clock tree with 3434 + * new clock nodes. Use clk_hw_register() instead. 3435 + * 3436 + * Returns: a pointer to the newly allocated struct clk which 3437 + * cannot be dereferenced by driver code but may be used in conjunction with the 3438 + * rest of the clock API. In the event of an error clk_register will return an 3439 + * error code; drivers must test for an error code after calling clk_register. 3440 + */ 3441 + struct clk *clk_register(struct device *dev, struct clk_hw *hw) 3442 + { 3443 + return __clk_register(dev, dev_of_node(dev), hw); 3597 3444 } 3598 3445 EXPORT_SYMBOL_GPL(clk_register); 3599 3446 ··· 3623 3442 */ 3624 3443 int clk_hw_register(struct device *dev, struct clk_hw *hw) 3625 3444 { 3626 - return PTR_ERR_OR_ZERO(clk_register(dev, hw)); 3445 + return PTR_ERR_OR_ZERO(__clk_register(dev, dev_of_node(dev), hw)); 3627 3446 } 3628 3447 EXPORT_SYMBOL_GPL(clk_hw_register); 3448 + 3449 + /* 3450 + * of_clk_hw_register - register a clk_hw and return an error code 3451 + * @node: device_node of device that is registering this clock 3452 + * @hw: link to hardware-specific clock data 3453 + * 3454 + * of_clk_hw_register() is the primary interface for populating the clock tree 3455 + * with new clock nodes when a struct device is not available, but a struct 3456 + * device_node is. It returns an integer equal to zero indicating success or 3457 + * less than zero indicating failure. Drivers must test for an error code after 3458 + * calling of_clk_hw_register(). 3459 + */ 3460 + int of_clk_hw_register(struct device_node *node, struct clk_hw *hw) 3461 + { 3462 + return PTR_ERR_OR_ZERO(__clk_register(NULL, node, hw)); 3463 + } 3464 + EXPORT_SYMBOL_GPL(of_clk_hw_register); 3629 3465 3630 3466 /* Free memory allocated for a clock. */ 3631 3467 static void __clk_release(struct kref *ref) 3632 3468 { 3633 3469 struct clk_core *core = container_of(ref, struct clk_core, ref); 3634 - int i = core->num_parents; 3635 3470 3636 3471 lockdep_assert_held(&prepare_lock); 3637 3472 3638 - kfree(core->parents); 3639 - while (--i >= 0) 3640 - kfree_const(core->parent_names[i]); 3641 - 3642 - kfree(core->parent_names); 3473 + clk_core_free_parent_map(core); 3643 3474 kfree_const(core->name); 3644 3475 kfree(core); 3645 3476 }
+2
drivers/clk/clk.h
··· 19 19 } 20 20 #endif 21 21 22 + struct clk_hw *clk_find_hw(const char *dev_id, const char *con_id); 23 + 22 24 #ifdef CONFIG_COMMON_CLK 23 25 struct clk *clk_hw_create_clk(struct device *dev, struct clk_hw *hw, 24 26 const char *dev_id, const char *con_id);
+16 -15
drivers/clk/clkdev.c
··· 72 72 return cl; 73 73 } 74 74 75 + struct clk_hw *clk_find_hw(const char *dev_id, const char *con_id) 76 + { 77 + struct clk_lookup *cl; 78 + struct clk_hw *hw = ERR_PTR(-ENOENT); 79 + 80 + mutex_lock(&clocks_mutex); 81 + cl = clk_find(dev_id, con_id); 82 + if (cl) 83 + hw = cl->clk_hw; 84 + mutex_unlock(&clocks_mutex); 85 + 86 + return hw; 87 + } 88 + 75 89 static struct clk *__clk_get_sys(struct device *dev, const char *dev_id, 76 90 const char *con_id) 77 91 { 78 - struct clk_lookup *cl; 79 - struct clk *clk = NULL; 92 + struct clk_hw *hw = clk_find_hw(dev_id, con_id); 80 93 81 - mutex_lock(&clocks_mutex); 82 - 83 - cl = clk_find(dev_id, con_id); 84 - if (!cl) 85 - goto out; 86 - 87 - clk = clk_hw_create_clk(dev, cl->clk_hw, dev_id, con_id); 88 - if (IS_ERR(clk)) 89 - cl = NULL; 90 - out: 91 - mutex_unlock(&clocks_mutex); 92 - 93 - return cl ? clk : ERR_PTR(-ENOENT); 94 + return clk_hw_create_clk(dev, hw, dev_id, con_id); 94 95 } 95 96 96 97 struct clk *clk_get_sys(const char *dev_id, const char *con_id)
+22
include/linux/clk-provider.h
··· 251 251 }; 252 252 253 253 /** 254 + * struct clk_parent_data - clk parent information 255 + * @hw: parent clk_hw pointer (used for clk providers with internal clks) 256 + * @fw_name: parent name local to provider registering clk 257 + * @name: globally unique parent name (used as a fallback) 258 + * @index: parent index local to provider registering clk (if @fw_name absent) 259 + */ 260 + struct clk_parent_data { 261 + const struct clk_hw *hw; 262 + const char *fw_name; 263 + const char *name; 264 + int index; 265 + }; 266 + 267 + /** 254 268 * struct clk_init_data - holds init data that's common to all clocks and is 255 269 * shared between the clock provider and the common clock framework. 256 270 * 257 271 * @name: clock name 258 272 * @ops: operations this clock supports 259 273 * @parent_names: array of string names for all possible parents 274 + * @parent_data: array of parent data for all possible parents (when some 275 + * parents are external to the clk controller) 276 + * @parent_hws: array of pointers to all possible parents (when all parents 277 + * are internal to the clk controller) 260 278 * @num_parents: number of possible parents 261 279 * @flags: framework-level hints and quirks 262 280 */ 263 281 struct clk_init_data { 264 282 const char *name; 265 283 const struct clk_ops *ops; 284 + /* Only one of the following three should be assigned */ 266 285 const char * const *parent_names; 286 + const struct clk_parent_data *parent_data; 287 + const struct clk_hw **parent_hws; 267 288 u8 num_parents; 268 289 unsigned long flags; 269 290 }; ··· 797 776 798 777 int __must_check clk_hw_register(struct device *dev, struct clk_hw *hw); 799 778 int __must_check devm_clk_hw_register(struct device *dev, struct clk_hw *hw); 779 + int __must_check of_clk_hw_register(struct device_node *node, struct clk_hw *hw); 800 780 801 781 void clk_unregister(struct clk *clk); 802 782 void devm_clk_unregister(struct device *dev, struct clk *clk);
+1 -1
include/linux/device.h
··· 1229 1229 1230 1230 static inline struct device_node *dev_of_node(struct device *dev) 1231 1231 { 1232 - if (!IS_ENABLED(CONFIG_OF)) 1232 + if (!IS_ENABLED(CONFIG_OF) || !dev) 1233 1233 return NULL; 1234 1234 return dev->of_node; 1235 1235 }