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

clk: Loongson1: Refactor Loongson1 clock

Factor out the common functions into loongson1/clk.c
to support both Loongson1B and Loongson1C. And, put
the rest into loongson1/clk-loongson1b.c.

Signed-off-by: Kelvin Cheung <keguang.zhang@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Kelvin Cheung and committed by
Stephen Boyd
a8e3ced4 5963f19c

+69 -48
+1 -1
drivers/clk/Makefile
··· 26 26 obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.o 27 27 obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o 28 28 obj-$(CONFIG_ARCH_HIGHBANK) += clk-highbank.o 29 - obj-$(CONFIG_MACH_LOONGSON32) += clk-ls1x.o 30 29 obj-$(CONFIG_COMMON_CLK_MAX77686) += clk-max77686.o 31 30 obj-$(CONFIG_ARCH_MB86S7X) += clk-mb86s7x.o 32 31 obj-$(CONFIG_ARCH_MOXART) += clk-moxart.o ··· 60 61 obj-$(CONFIG_ARCH_MXC) += imx/ 61 62 obj-$(CONFIG_MACH_INGENIC) += ingenic/ 62 63 obj-$(CONFIG_COMMON_CLK_KEYSTONE) += keystone/ 64 + obj-$(CONFIG_MACH_LOONGSON32) += loongson1/ 63 65 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ 64 66 obj-$(CONFIG_COMMON_CLK_AMLOGIC) += meson/ 65 67 obj-$(CONFIG_MACH_PIC32) += microchip/
+4 -47
drivers/clk/clk-ls1x.c drivers/clk/loongson1/clk-loongson1b.c
··· 1 1 /* 2 - * Copyright (c) 2012 Zhang, Keguang <keguang.zhang@gmail.com> 2 + * Copyright (c) 2012-2016 Zhang, Keguang <keguang.zhang@gmail.com> 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify it 5 5 * under the terms of the GNU General Public License as published by the ··· 10 10 #include <linux/clkdev.h> 11 11 #include <linux/clk-provider.h> 12 12 #include <linux/io.h> 13 - #include <linux/slab.h> 14 13 #include <linux/err.h> 15 14 16 15 #include <loongson1.h> 16 + #include "clk.h" 17 17 18 18 #define OSC (33 * 1000000) 19 19 #define DIV_APB 2 20 20 21 21 static DEFINE_SPINLOCK(_lock); 22 - 23 - static int ls1x_pll_clk_enable(struct clk_hw *hw) 24 - { 25 - return 0; 26 - } 27 - 28 - static void ls1x_pll_clk_disable(struct clk_hw *hw) 29 - { 30 - } 31 22 32 23 static unsigned long ls1x_pll_recalc_rate(struct clk_hw *hw, 33 24 unsigned long parent_rate) ··· 34 43 } 35 44 36 45 static const struct clk_ops ls1x_pll_clk_ops = { 37 - .enable = ls1x_pll_clk_enable, 38 - .disable = ls1x_pll_clk_disable, 39 46 .recalc_rate = ls1x_pll_recalc_rate, 40 47 }; 41 - 42 - static struct clk_hw *__init clk_hw_register_pll(struct device *dev, 43 - const char *name, 44 - const char *parent_name, 45 - unsigned long flags) 46 - { 47 - int ret; 48 - struct clk_hw *hw; 49 - struct clk_init_data init; 50 - 51 - /* allocate the divider */ 52 - hw = kzalloc(sizeof(struct clk_hw), GFP_KERNEL); 53 - if (!hw) { 54 - pr_err("%s: could not allocate clk_hw\n", __func__); 55 - return ERR_PTR(-ENOMEM); 56 - } 57 - 58 - init.name = name; 59 - init.ops = &ls1x_pll_clk_ops; 60 - init.flags = flags | CLK_IS_BASIC; 61 - init.parent_names = (parent_name ? &parent_name : NULL); 62 - init.num_parents = (parent_name ? 1 : 0); 63 - hw->init = &init; 64 - 65 - /* register the clock */ 66 - ret = clk_hw_register(dev, hw); 67 - if (ret) { 68 - kfree(hw); 69 - hw = ERR_PTR(ret); 70 - } 71 - 72 - return hw; 73 - } 74 48 75 49 static const char * const cpu_parents[] = { "cpu_clk_div", "osc_33m_clk", }; 76 50 static const char * const ahb_parents[] = { "ahb_clk_div", "osc_33m_clk", }; ··· 49 93 clk_hw_register_clkdev(hw, "osc_33m_clk", NULL); 50 94 51 95 /* clock derived from 33 MHz OSC clk */ 52 - hw = clk_hw_register_pll(NULL, "pll_clk", "osc_33m_clk", 0); 96 + hw = clk_hw_register_pll(NULL, "pll_clk", "osc_33m_clk", 97 + &ls1x_pll_clk_ops, 0); 53 98 clk_hw_register_clkdev(hw, "pll_clk", NULL); 54 99 55 100 /* clock derived from PLL clk */
+2
drivers/clk/loongson1/Makefile
··· 1 + obj-y += clk.o 2 + obj-$(CONFIG_LOONGSON1_LS1B) += clk-loongson1b.o
+43
drivers/clk/loongson1/clk.c
··· 1 + /* 2 + * Copyright (c) 2012-2016 Zhang, Keguang <keguang.zhang@gmail.com> 3 + * 4 + * This program is free software; you can redistribute it and/or modify it 5 + * under the terms of the GNU General Public License as published by the 6 + * Free Software Foundation; either version 2 of the License, or (at your 7 + * option) any later version. 8 + */ 9 + 10 + #include <linux/clk-provider.h> 11 + #include <linux/slab.h> 12 + 13 + struct clk_hw *__init clk_hw_register_pll(struct device *dev, 14 + const char *name, 15 + const char *parent_name, 16 + const struct clk_ops *ops, 17 + unsigned long flags) 18 + { 19 + int ret; 20 + struct clk_hw *hw; 21 + struct clk_init_data init; 22 + 23 + /* allocate the divider */ 24 + hw = kzalloc(sizeof(*hw), GFP_KERNEL); 25 + if (!hw) 26 + return ERR_PTR(-ENOMEM); 27 + 28 + init.name = name; 29 + init.ops = ops; 30 + init.flags = flags | CLK_IS_BASIC; 31 + init.parent_names = (parent_name ? &parent_name : NULL); 32 + init.num_parents = (parent_name ? 1 : 0); 33 + hw->init = &init; 34 + 35 + /* register the clock */ 36 + ret = clk_hw_register(dev, hw); 37 + if (ret) { 38 + kfree(hw); 39 + hw = ERR_PTR(ret); 40 + } 41 + 42 + return hw; 43 + }
+19
drivers/clk/loongson1/clk.h
··· 1 + /* 2 + * Copyright (c) 2012-2016 Zhang, Keguang <keguang.zhang@gmail.com> 3 + * 4 + * This program is free software; you can redistribute it and/or modify it 5 + * under the terms of the GNU General Public License as published by the 6 + * Free Software Foundation; either version 2 of the License, or (at your 7 + * option) any later version. 8 + */ 9 + 10 + #ifndef __LOONGSON1_CLK_H 11 + #define __LOONGSON1_CLK_H 12 + 13 + struct clk_hw *clk_hw_register_pll(struct device *dev, 14 + const char *name, 15 + const char *parent_name, 16 + const struct clk_ops *ops, 17 + unsigned long flags); 18 + 19 + #endif /* __LOONGSON1_CLK_H */