Skip to content

Commit 10e7120

Browse files
embed-3dmchehab
authored andcommitted
media: rc: update sunxi-ir driver to get base clock frequency from devicetree
This patch updates the sunxi-ir driver to set the base clock frequency from devicetree. This is necessary since there are different ir receivers on the market, that operate with different frequencies. So this value could be set if the attached ir receiver needs a different base clock frequency, than the default 8 MHz. Signed-off-by: Philipp Rossak <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Sean Young <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 3f127ce commit 10e7120

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/media/rc/sunxi-cir.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@
7272
/* CIR_REG register idle threshold */
7373
#define REG_CIR_ITHR(val) (((val) << 8) & (GENMASK(15, 8)))
7474

75-
/* Required frequency for IR0 or IR1 clock in CIR mode */
75+
/* Required frequency for IR0 or IR1 clock in CIR mode (default) */
7676
#define SUNXI_IR_BASE_CLK 8000000
77-
/* Frequency after IR internal divider */
78-
#define SUNXI_IR_CLK (SUNXI_IR_BASE_CLK / 64)
79-
/* Sample period in ns */
80-
#define SUNXI_IR_SAMPLE (1000000000ul / SUNXI_IR_CLK)
8177
/* Noise threshold in samples */
8278
#define SUNXI_IR_RXNOISE 1
8379
/* Idle Threshold in samples */
@@ -122,7 +118,8 @@ static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
122118
/* for each bit in fifo */
123119
dt = readb(ir->base + SUNXI_IR_RXFIFO_REG);
124120
rawir.pulse = (dt & 0x80) != 0;
125-
rawir.duration = ((dt & 0x7f) + 1) * SUNXI_IR_SAMPLE;
121+
rawir.duration = ((dt & 0x7f) + 1) *
122+
ir->rc->rx_resolution;
126123
ir_raw_event_store_with_filter(ir->rc, &rawir);
127124
}
128125
}
@@ -148,6 +145,7 @@ static int sunxi_ir_probe(struct platform_device *pdev)
148145
struct device_node *dn = dev->of_node;
149146
struct resource *res;
150147
struct sunxi_ir *ir;
148+
u32 b_clk_freq = SUNXI_IR_BASE_CLK;
151149

152150
ir = devm_kzalloc(dev, sizeof(struct sunxi_ir), GFP_KERNEL);
153151
if (!ir)
@@ -172,6 +170,9 @@ static int sunxi_ir_probe(struct platform_device *pdev)
172170
return PTR_ERR(ir->clk);
173171
}
174172

173+
/* Base clock frequency (optional) */
174+
of_property_read_u32(dn, "clock-frequency", &b_clk_freq);
175+
175176
/* Reset (optional) */
176177
ir->rst = devm_reset_control_get_optional_exclusive(dev, NULL);
177178
if (IS_ERR(ir->rst))
@@ -180,11 +181,12 @@ static int sunxi_ir_probe(struct platform_device *pdev)
180181
if (ret)
181182
return ret;
182183

183-
ret = clk_set_rate(ir->clk, SUNXI_IR_BASE_CLK);
184+
ret = clk_set_rate(ir->clk, b_clk_freq);
184185
if (ret) {
185186
dev_err(dev, "set ir base clock failed!\n");
186187
goto exit_reset_assert;
187188
}
189+
dev_dbg(dev, "set base clock frequency to %d Hz.\n", b_clk_freq);
188190

189191
if (clk_prepare_enable(ir->apb_clk)) {
190192
dev_err(dev, "try to enable apb_ir_clk failed\n");
@@ -225,7 +227,8 @@ static int sunxi_ir_probe(struct platform_device *pdev)
225227
ir->rc->map_name = ir->map_name ?: RC_MAP_EMPTY;
226228
ir->rc->dev.parent = dev;
227229
ir->rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
228-
ir->rc->rx_resolution = SUNXI_IR_SAMPLE;
230+
/* Frequency after IR internal divider with sample period in ns */
231+
ir->rc->rx_resolution = (1000000000ul / (b_clk_freq / 64));
229232
ir->rc->timeout = MS_TO_NS(SUNXI_IR_TIMEOUT);
230233
ir->rc->driver_name = SUNXI_IR_DEV;
231234

0 commit comments

Comments
 (0)