cregit-Linux how code gets into the kernel

Release 4.17 drivers/gpu/drm/sun4i/sun4i_hdmi_ddc_clk.c

/*
 * Copyright (C) 2016 Free Electrons
 * Copyright (C) 2016 NextThing Co
 *
 * Maxime Ripard <maxime.ripard@free-electrons.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */

#include <linux/clk-provider.h>
#include <linux/regmap.h>

#include "sun4i_hdmi.h"


struct sun4i_ddc {
	
struct clk_hw		hw;
	
struct sun4i_hdmi	*hdmi;
	
struct regmap_field	*reg;
	
u8			pre_div;
	
u8			m_offset;
};


static inline struct sun4i_ddc *hw_to_ddc(struct clk_hw *hw) { return container_of(hw, struct sun4i_ddc, hw); }

Contributors

PersonTokensPropCommitsCommitProp
Maxime Ripard25100.00%1100.00%
Total25100.00%1100.00%


static unsigned long sun4i_ddc_calc_divider(unsigned long rate, unsigned long parent_rate, const u8 pre_div, const u8 m_offset, u8 *m, u8 *n) { unsigned long best_rate = 0; u8 best_m = 0, best_n = 0, _m, _n; for (_m = 0; _m < 8; _m++) { for (_n = 0; _n < 8; _n++) { unsigned long tmp_rate; tmp_rate = (((parent_rate / pre_div) / 10) >> _n) / (_m + m_offset); if (tmp_rate > rate) continue; if (abs(rate - tmp_rate) < abs(rate - best_rate)) { best_rate = tmp_rate; best_m = _m; best_n = _n; } } } if (m && n) { *m = best_m; *n = best_n; } return best_rate; }

Contributors

PersonTokensPropCommitsCommitProp
Maxime Ripard15493.90%150.00%
Chen-Yu Tsai106.10%150.00%
Total164100.00%2100.00%


static long sun4i_ddc_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *prate) { struct sun4i_ddc *ddc = hw_to_ddc(hw); return sun4i_ddc_calc_divider(rate, *prate, ddc->pre_div, ddc->m_offset, NULL, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Maxime Ripard3364.71%150.00%
Chen-Yu Tsai1835.29%150.00%
Total51100.00%2100.00%


static unsigned long sun4i_ddc_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct sun4i_ddc *ddc = hw_to_ddc(hw); unsigned int reg; u8 m, n; regmap_field_read(ddc->reg, &reg); m = (reg >> 3) & 0xf; n = reg & 0x7; return (((parent_rate / ddc->pre_div) / 10) >> n) / (m + ddc->m_offset); }

Contributors

PersonTokensPropCommitsCommitProp
Maxime Ripard7283.72%150.00%
Chen-Yu Tsai1416.28%150.00%
Total86100.00%2100.00%


static int sun4i_ddc_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct sun4i_ddc *ddc = hw_to_ddc(hw); u8 div_m, div_n; sun4i_ddc_calc_divider(rate, parent_rate, ddc->pre_div, ddc->m_offset, &div_m, &div_n); regmap_field_write(ddc->reg, SUN4I_HDMI_DDC_CLK_M(div_m) | SUN4I_HDMI_DDC_CLK_N(div_n)); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Maxime Ripard6282.67%150.00%
Chen-Yu Tsai1317.33%150.00%
Total75100.00%2100.00%

static const struct clk_ops sun4i_ddc_ops = { .recalc_rate = sun4i_ddc_recalc_rate, .round_rate = sun4i_ddc_round_rate, .set_rate = sun4i_ddc_set_rate, };
int sun4i_ddc_create(struct sun4i_hdmi *hdmi, struct clk *parent) { struct clk_init_data init; struct sun4i_ddc *ddc; const char *parent_name; parent_name = __clk_get_name(parent); if (!parent_name) return -ENODEV; ddc = devm_kzalloc(hdmi->dev, sizeof(*ddc), GFP_KERNEL); if (!ddc) return -ENOMEM; ddc->reg = devm_regmap_field_alloc(hdmi->dev, hdmi->regmap, hdmi->variant->ddc_clk_reg); if (IS_ERR(ddc->reg)) return PTR_ERR(ddc->reg); init.name = "hdmi-ddc"; init.ops = &sun4i_ddc_ops; init.parent_names = &parent_name; init.num_parents = 1; ddc->hdmi = hdmi; ddc->hw.init = &init; ddc->pre_div = hdmi->variant->ddc_clk_pre_divider; ddc->m_offset = hdmi->variant->ddc_clk_m_offset; hdmi->ddc_clk = devm_clk_register(hdmi->dev, &ddc->hw); if (IS_ERR(hdmi->ddc_clk)) return PTR_ERR(hdmi->ddc_clk); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Maxime Ripard14871.84%150.00%
Chen-Yu Tsai5828.16%150.00%
Total206100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Maxime Ripard53880.90%150.00%
Chen-Yu Tsai12719.10%150.00%
Total665100.00%2100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.