clk-uniphier-fixed-factor.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2016 Socionext Inc.
  3. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/clk-provider.h>
  16. #include <linux/device.h>
  17. #include "clk-uniphier.h"
  18. struct clk_hw *uniphier_clk_register_fixed_factor(struct device *dev,
  19. const char *name,
  20. const struct uniphier_clk_fixed_factor_data *data)
  21. {
  22. struct clk_fixed_factor *fix;
  23. struct clk_init_data init;
  24. int ret;
  25. fix = devm_kzalloc(dev, sizeof(*fix), GFP_KERNEL);
  26. if (!fix)
  27. return ERR_PTR(-ENOMEM);
  28. init.name = name;
  29. init.ops = &clk_fixed_factor_ops;
  30. init.flags = data->parent_name ? CLK_SET_RATE_PARENT : 0;
  31. init.parent_names = data->parent_name ? &data->parent_name : NULL;
  32. init.num_parents = data->parent_name ? 1 : 0;
  33. fix->mult = data->mult;
  34. fix->div = data->div;
  35. fix->hw.init = &init;
  36. ret = devm_clk_hw_register(dev, &fix->hw);
  37. if (ret)
  38. return ERR_PTR(ret);
  39. return &fix->hw;
  40. }