Masahiro Yamada | 734d82f | 2016-09-16 16:40:03 +0900 | [diff] [blame] | 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 | |
| 16 | #include <linux/clk-provider.h> |
| 17 | #include <linux/device.h> |
| 18 | |
| 19 | #include "clk-uniphier.h" |
| 20 | |
| 21 | struct clk_hw *uniphier_clk_register_fixed_factor(struct device *dev, |
| 22 | const char *name, |
| 23 | const struct uniphier_clk_fixed_factor_data *data) |
| 24 | { |
| 25 | struct clk_fixed_factor *fix; |
| 26 | struct clk_init_data init; |
| 27 | int ret; |
| 28 | |
| 29 | fix = devm_kzalloc(dev, sizeof(*fix), GFP_KERNEL); |
| 30 | if (!fix) |
| 31 | return ERR_PTR(-ENOMEM); |
| 32 | |
| 33 | init.name = name; |
| 34 | init.ops = &clk_fixed_factor_ops; |
| 35 | init.flags = data->parent_name ? CLK_SET_RATE_PARENT : 0; |
| 36 | init.parent_names = data->parent_name ? &data->parent_name : NULL; |
| 37 | init.num_parents = data->parent_name ? 1 : 0; |
| 38 | |
| 39 | fix->mult = data->mult; |
| 40 | fix->div = data->div; |
| 41 | fix->hw.init = &init; |
| 42 | |
| 43 | ret = devm_clk_hw_register(dev, &fix->hw); |
| 44 | if (ret) |
| 45 | return ERR_PTR(ret); |
| 46 | |
| 47 | return &fix->hw; |
| 48 | } |