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

clk: qcom: Add a regmap type clock struct

Add a clock type that associates a regmap pointer and some
enable/disable bits with a clk_hw struct. This will be the struct
that a hw specific implementation wraps if it wants to use the
regmap helper functions.

Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Mike Turquette <mturquette@linaro.org>

authored by

Stephen Boyd and committed by
Mike Turquette
085d7a45 3fa2252b

+170
+2
drivers/clk/Kconfig
··· 107 107 Supports clock drivers for Keystone based SOCs. These SOCs have local 108 108 a power sleep control module that gate the clock to the IPs and PLLs. 109 109 110 + source "drivers/clk/qcom/Kconfig" 111 + 110 112 endmenu 111 113 112 114 source "drivers/clk/mvebu/Kconfig"
+1
drivers/clk/Makefile
··· 21 21 obj-$(CONFIG_PLAT_SPEAR) += spear/ 22 22 obj-$(CONFIG_ARCH_U300) += clk-u300.o 23 23 obj-$(CONFIG_COMMON_CLK_VERSATILE) += versatile/ 24 + obj-$(CONFIG_COMMON_CLK_QCOM) += qcom/ 24 25 obj-$(CONFIG_PLAT_ORION) += mvebu/ 25 26 ifeq ($(CONFIG_COMMON_CLK), y) 26 27 obj-$(CONFIG_ARCH_MMP) += mmp/
+5
drivers/clk/qcom/Kconfig
··· 1 + config COMMON_CLK_QCOM 2 + tristate "Support for Qualcomm's clock controllers" 3 + depends on OF 4 + select REGMAP_MMIO 5 +
+3
drivers/clk/qcom/Makefile
··· 1 + obj-$(CONFIG_COMMON_CLK_QCOM) += clk-qcom.o 2 + 3 + clk-qcom-$(CONFIG_COMMON_CLK_QCOM) += clk-regmap.o
+114
drivers/clk/qcom/clk-regmap.c
··· 1 + /* 2 + * Copyright (c) 2014, The Linux Foundation. All rights reserved. 3 + * 4 + * This software is licensed under the terms of the GNU General Public 5 + * License version 2, as published by the Free Software Foundation, and 6 + * may be copied, distributed, and modified under those terms. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #include <linux/device.h> 15 + #include <linux/clk-provider.h> 16 + #include <linux/regmap.h> 17 + #include <linux/export.h> 18 + 19 + #include "clk-regmap.h" 20 + 21 + /** 22 + * clk_is_enabled_regmap - standard is_enabled() for regmap users 23 + * 24 + * @hw: clk to operate on 25 + * 26 + * Clocks that use regmap for their register I/O can set the 27 + * enable_reg and enable_mask fields in their struct clk_regmap and then use 28 + * this as their is_enabled operation, saving some code. 29 + */ 30 + int clk_is_enabled_regmap(struct clk_hw *hw) 31 + { 32 + struct clk_regmap *rclk = to_clk_regmap(hw); 33 + unsigned int val; 34 + int ret; 35 + 36 + ret = regmap_read(rclk->regmap, rclk->enable_reg, &val); 37 + if (ret != 0) 38 + return ret; 39 + 40 + if (rclk->enable_is_inverted) 41 + return (val & rclk->enable_mask) == 0; 42 + else 43 + return (val & rclk->enable_mask) != 0; 44 + } 45 + EXPORT_SYMBOL_GPL(clk_is_enabled_regmap); 46 + 47 + /** 48 + * clk_enable_regmap - standard enable() for regmap users 49 + * 50 + * @hw: clk to operate on 51 + * 52 + * Clocks that use regmap for their register I/O can set the 53 + * enable_reg and enable_mask fields in their struct clk_regmap and then use 54 + * this as their enable() operation, saving some code. 55 + */ 56 + int clk_enable_regmap(struct clk_hw *hw) 57 + { 58 + struct clk_regmap *rclk = to_clk_regmap(hw); 59 + unsigned int val; 60 + 61 + if (rclk->enable_is_inverted) 62 + val = 0; 63 + else 64 + val = rclk->enable_mask; 65 + 66 + return regmap_update_bits(rclk->regmap, rclk->enable_reg, 67 + rclk->enable_mask, val); 68 + } 69 + EXPORT_SYMBOL_GPL(clk_enable_regmap); 70 + 71 + /** 72 + * clk_disable_regmap - standard disable() for regmap users 73 + * 74 + * @hw: clk to operate on 75 + * 76 + * Clocks that use regmap for their register I/O can set the 77 + * enable_reg and enable_mask fields in their struct clk_regmap and then use 78 + * this as their disable() operation, saving some code. 79 + */ 80 + void clk_disable_regmap(struct clk_hw *hw) 81 + { 82 + struct clk_regmap *rclk = to_clk_regmap(hw); 83 + unsigned int val; 84 + 85 + if (rclk->enable_is_inverted) 86 + val = rclk->enable_mask; 87 + else 88 + val = 0; 89 + 90 + regmap_update_bits(rclk->regmap, rclk->enable_reg, rclk->enable_mask, 91 + val); 92 + } 93 + EXPORT_SYMBOL_GPL(clk_disable_regmap); 94 + 95 + /** 96 + * devm_clk_register_regmap - register a clk_regmap clock 97 + * 98 + * @rclk: clk to operate on 99 + * 100 + * Clocks that use regmap for their register I/O should register their 101 + * clk_regmap struct via this function so that the regmap is initialized 102 + * and so that the clock is registered with the common clock framework. 103 + */ 104 + struct clk *devm_clk_register_regmap(struct device *dev, 105 + struct clk_regmap *rclk) 106 + { 107 + if (dev && dev_get_regmap(dev, NULL)) 108 + rclk->regmap = dev_get_regmap(dev, NULL); 109 + else if (dev && dev->parent) 110 + rclk->regmap = dev_get_regmap(dev->parent, NULL); 111 + 112 + return devm_clk_register(dev, &rclk->hw); 113 + } 114 + EXPORT_SYMBOL_GPL(devm_clk_register_regmap);
+45
drivers/clk/qcom/clk-regmap.h
··· 1 + /* 2 + * Copyright (c) 2014, The Linux Foundation. All rights reserved. 3 + * 4 + * This software is licensed under the terms of the GNU General Public 5 + * License version 2, as published by the Free Software Foundation, and 6 + * may be copied, distributed, and modified under those terms. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #ifndef __QCOM_CLK_REGMAP_H__ 15 + #define __QCOM_CLK_REGMAP_H__ 16 + 17 + #include <linux/clk-provider.h> 18 + 19 + struct regmap; 20 + 21 + /** 22 + * struct clk_regmap - regmap supporting clock 23 + * @hw: handle between common and hardware-specific interfaces 24 + * @regmap: regmap to use for regmap helpers and/or by providers 25 + * @enable_reg: register when using regmap enable/disable ops 26 + * @enable_mask: mask when using regmap enable/disable ops 27 + * @enable_is_inverted: flag to indicate set enable_mask bits to disable 28 + * when using clock_enable_regmap and friends APIs. 29 + */ 30 + struct clk_regmap { 31 + struct clk_hw hw; 32 + struct regmap *regmap; 33 + unsigned int enable_reg; 34 + unsigned int enable_mask; 35 + bool enable_is_inverted; 36 + }; 37 + #define to_clk_regmap(_hw) container_of(_hw, struct clk_regmap, hw) 38 + 39 + int clk_is_enabled_regmap(struct clk_hw *hw); 40 + int clk_enable_regmap(struct clk_hw *hw); 41 + void clk_disable_regmap(struct clk_hw *hw); 42 + struct clk * 43 + devm_clk_register_regmap(struct device *dev, struct clk_regmap *rclk); 44 + 45 + #endif