Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756959AbcJTH4K (ORCPT ); Thu, 20 Oct 2016 03:56:10 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:29487 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756127AbcJTH4I (ORCPT ); Thu, 20 Oct 2016 03:56:08 -0400 Subject: Re: [PATCH v2 4/6] clk: stm32f4: Add RTC clock To: Stephen Boyd References: <1476436699-21879-1-git-send-email-gabriel.fernandez@st.com> <1476436699-21879-5-git-send-email-gabriel.fernandez@st.com> <20161019204537.GD8871@codeaurora.org> CC: Rob Herring , Mark Rutland , Russell King , Maxime Coquelin , Alexandre Torgue , Michael Turquette , Nicolas Pitre , Arnd Bergmann , , , , , , , , From: Gabriel Fernandez Message-ID: Date: Thu, 20 Oct 2016 09:55:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20161019204537.GD8871@codeaurora.org> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.48.1.80] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-20_03:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3019 Lines: 124 Hi Stephen, On 10/19/2016 10:45 PM, Stephen Boyd wrote: > On 10/14, gabriel.fernandez@st.com wrote: >> @@ -310,6 +310,15 @@ static inline void enable_power_domain_write_protection(void) >> regmap_update_bits(pdrm, 0x00, (1 << 8), (0 << 8)); >> } >> >> +static inline void sofware_reset_backup_domain(void) >> +{ >> + unsigned long val; >> + >> + val = readl(base + STM32F4_RCC_BDCR); >> + writel(val |= (1 << 16), base + STM32F4_RCC_BDCR); > Interesting C style here! Why set the bit in val that will then > be cleared in the next function call? Please just don't do it. It > would be better to do writel(val | BIT(16), ...) To reset the backup domain, i have to generate a pulse on this bit. BR Gabriel. > >> + writel(val & ~(1 << 16), base + STM32F4_RCC_BDCR); >> +} >> + >> struct stm32_rgate { >> struct clk_hw hw; >> struct clk_gate gate; >> @@ -396,6 +405,113 @@ static struct clk_hw *clk_register_rgate(struct device *dev, const char *name, >> return hw; >> } >> >> +static int cclk_gate_enable(struct clk_hw *hw) >> +{ >> + int ret; >> + >> + disable_power_domain_write_protection(); >> + >> + ret = clk_gate_ops.enable(hw); >> + >> + enable_power_domain_write_protection(); >> + >> + return ret; >> +} >> + >> +static void cclk_gate_disable(struct clk_hw *hw) >> +{ >> + disable_power_domain_write_protection(); >> + >> + clk_gate_ops.disable(hw); >> + >> + enable_power_domain_write_protection(); >> +} >> + >> +static int cclk_gate_is_enabled(struct clk_hw *hw) >> +{ >> + return clk_gate_ops.is_enabled(hw); >> +} >> + >> +static const struct clk_ops cclk_gate_ops = { >> + .enable = cclk_gate_enable, >> + .disable = cclk_gate_disable, >> + .is_enabled = cclk_gate_is_enabled, >> +}; >> + >> +static u8 cclk_mux_get_parent(struct clk_hw *hw) >> +{ >> + return clk_mux_ops.get_parent(hw); >> +} >> + >> + > Weird double newline here. Please remove one. > >> +static int cclk_mux_set_parent(struct clk_hw *hw, u8 index) >> +{ >> + int ret; >> + >> + disable_power_domain_write_protection(); >> + >> + sofware_reset_backup_domain(); >> + >> + ret = clk_mux_ops.set_parent(hw, index); >> + >> + enable_power_domain_write_protection(); >> + >> + return ret; >> +} >> + >> + > Same. > >> +static const struct clk_ops cclk_mux_ops = { >> + .get_parent = cclk_mux_get_parent, >> + .set_parent = cclk_mux_set_parent, >> +}; >> + >> +static struct clk_hw *stm32_register_cclk(struct device *dev, const char *name, >> + const char * const *parent_names, int num_parents, >> + void __iomem *reg, u8 bit_idx, u8 shift, unsigned long flags, >> + spinlock_t *lock) >> +{ >> + struct clk_hw *hw; >> + struct clk_gate *gate; >> + struct clk_mux *mux; >> + >> + gate = kzalloc(sizeof(struct clk_gate), GFP_KERNEL); > sizeof(*gate) please. > >> + if (!gate) { >> + hw = ERR_PTR(-EINVAL); >> + goto fail; >> + } >> + >> + mux = kzalloc(sizeof(struct clk_mux), GFP_KERNEL); > sizeof(*mux) please. > >> + if (!mux) { >> + kfree(gate); >> + hw = ERR_PTR(-EINVAL); >> + goto fail; >> + } >> +