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

clkdev: Add clk_hw based registration APIs

Now that we have a clk registration API that doesn't return
struct clks, we need to have some way to hand out struct clks via
the clk_get() APIs that doesn't involve associating struct clk
pointers with a struct clk_lookup. Luckily, clkdev already
operates on struct clk_hw pointers, except for the registration
facing APIs where it converts struct clk pointers into struct
clk_hw pointers almost immediately.

Let's add clk_hw based registration APIs so that we can skip the
conversion step and provide a way for clk provider drivers to
operate exclusively on clk_hw structs. This way we clearly
split the API between consumers and providers.

Cc: Russell King <linux@arm.linux.org.uk>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

+70
+64
drivers/clk/clkdev.c
··· 301 301 } 302 302 EXPORT_SYMBOL(clkdev_alloc); 303 303 304 + struct clk_lookup * 305 + clkdev_hw_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt, ...) 306 + { 307 + struct clk_lookup *cl; 308 + va_list ap; 309 + 310 + va_start(ap, dev_fmt); 311 + cl = vclkdev_alloc(hw, con_id, dev_fmt, ap); 312 + va_end(ap); 313 + 314 + return cl; 315 + } 316 + EXPORT_SYMBOL(clkdev_hw_alloc); 317 + 304 318 /** 305 319 * clkdev_create - allocate and add a clkdev lookup structure 306 320 * @clk: struct clk to associate with all clk_lookups ··· 337 323 return cl; 338 324 } 339 325 EXPORT_SYMBOL_GPL(clkdev_create); 326 + 327 + /** 328 + * clkdev_hw_create - allocate and add a clkdev lookup structure 329 + * @hw: struct clk_hw to associate with all clk_lookups 330 + * @con_id: connection ID string on device 331 + * @dev_fmt: format string describing device name 332 + * 333 + * Returns a clk_lookup structure, which can be later unregistered and 334 + * freed. 335 + */ 336 + struct clk_lookup *clkdev_hw_create(struct clk_hw *hw, const char *con_id, 337 + const char *dev_fmt, ...) 338 + { 339 + struct clk_lookup *cl; 340 + va_list ap; 341 + 342 + va_start(ap, dev_fmt); 343 + cl = vclkdev_create(hw, con_id, dev_fmt, ap); 344 + va_end(ap); 345 + 346 + return cl; 347 + } 348 + EXPORT_SYMBOL_GPL(clkdev_hw_create); 340 349 341 350 int clk_add_alias(const char *alias, const char *alias_dev_name, 342 351 const char *con_id, struct device *dev) ··· 439 402 return cl ? 0 : -ENOMEM; 440 403 } 441 404 EXPORT_SYMBOL(clk_register_clkdev); 405 + 406 + /** 407 + * clk_hw_register_clkdev - register one clock lookup for a struct clk_hw 408 + * @hw: struct clk_hw to associate with all clk_lookups 409 + * @con_id: connection ID string on device 410 + * @dev_id: format string describing device name 411 + * 412 + * con_id or dev_id may be NULL as a wildcard, just as in the rest of 413 + * clkdev. 414 + */ 415 + int clk_hw_register_clkdev(struct clk_hw *hw, const char *con_id, 416 + const char *dev_id) 417 + { 418 + struct clk_lookup *cl; 419 + 420 + /* 421 + * Since dev_id can be NULL, and NULL is handled specially, we must 422 + * pass it as either a NULL format string, or with "%s". 423 + */ 424 + if (dev_id) 425 + cl = __clk_register_clkdev(hw, con_id, "%s", dev_id); 426 + else 427 + cl = __clk_register_clkdev(hw, con_id, NULL); 428 + 429 + return cl ? 0 : -ENOMEM; 430 + } 431 + EXPORT_SYMBOL(clk_hw_register_clkdev);
+6
include/linux/clkdev.h
··· 15 15 #include <asm/clkdev.h> 16 16 17 17 struct clk; 18 + struct clk_hw; 18 19 struct device; 19 20 20 21 struct clk_lookup { ··· 35 34 36 35 struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id, 37 36 const char *dev_fmt, ...) __printf(3, 4); 37 + struct clk_lookup *clkdev_hw_alloc(struct clk_hw *hw, const char *con_id, 38 + const char *dev_fmt, ...) __printf(3, 4); 38 39 39 40 void clkdev_add(struct clk_lookup *cl); 40 41 void clkdev_drop(struct clk_lookup *cl); 41 42 42 43 struct clk_lookup *clkdev_create(struct clk *clk, const char *con_id, 43 44 const char *dev_fmt, ...) __printf(3, 4); 45 + struct clk_lookup *clkdev_hw_create(struct clk_hw *hw, const char *con_id, 46 + const char *dev_fmt, ...) __printf(3, 4); 44 47 45 48 void clkdev_add_table(struct clk_lookup *, size_t); 46 49 int clk_add_alias(const char *, const char *, const char *, struct device *); 47 50 48 51 int clk_register_clkdev(struct clk *, const char *, const char *); 52 + int clk_hw_register_clkdev(struct clk_hw *, const char *, const char *); 49 53 50 54 #ifdef CONFIG_COMMON_CLK 51 55 int __clk_get(struct clk *clk);