sched: Remove double_rq_lock() from __migrate_task()
[linux/fpc-iii.git] / drivers / media / rc / img-ir / img-ir-core.c
blob6b7834834fb873ded34b2d75790c47d233dc0b50
1 /*
2 * ImgTec IR Decoder found in PowerDown Controller.
4 * Copyright 2010-2014 Imagination Technologies Ltd.
6 * This contains core img-ir code for setting up the driver. The two interfaces
7 * (raw and hardware decode) are handled separately.
8 */
10 #include <linux/clk.h>
11 #include <linux/init.h>
12 #include <linux/interrupt.h>
13 #include <linux/io.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <linux/spinlock.h>
18 #include "img-ir.h"
20 static irqreturn_t img_ir_isr(int irq, void *dev_id)
22 struct img_ir_priv *priv = dev_id;
23 u32 irq_status;
25 spin_lock(&priv->lock);
26 /* we have to clear irqs before reading */
27 irq_status = img_ir_read(priv, IMG_IR_IRQ_STATUS);
28 img_ir_write(priv, IMG_IR_IRQ_CLEAR, irq_status);
30 /* don't handle valid data irqs if we're only interested in matches */
31 irq_status &= img_ir_read(priv, IMG_IR_IRQ_ENABLE);
33 /* hand off edge interrupts to raw decode handler */
34 if (irq_status & IMG_IR_IRQ_EDGE && img_ir_raw_enabled(&priv->raw))
35 img_ir_isr_raw(priv, irq_status);
37 /* hand off hardware match interrupts to hardware decode handler */
38 if (irq_status & (IMG_IR_IRQ_DATA_MATCH |
39 IMG_IR_IRQ_DATA_VALID |
40 IMG_IR_IRQ_DATA2_VALID) &&
41 img_ir_hw_enabled(&priv->hw))
42 img_ir_isr_hw(priv, irq_status);
44 spin_unlock(&priv->lock);
45 return IRQ_HANDLED;
48 static void img_ir_setup(struct img_ir_priv *priv)
50 /* start off with interrupts disabled */
51 img_ir_write(priv, IMG_IR_IRQ_ENABLE, 0);
53 img_ir_setup_raw(priv);
54 img_ir_setup_hw(priv);
56 if (!IS_ERR(priv->clk))
57 clk_prepare_enable(priv->clk);
60 static void img_ir_ident(struct img_ir_priv *priv)
62 u32 core_rev = img_ir_read(priv, IMG_IR_CORE_REV);
64 dev_info(priv->dev,
65 "IMG IR Decoder (%d.%d.%d.%d) probed successfully\n",
66 (core_rev & IMG_IR_DESIGNER) >> IMG_IR_DESIGNER_SHIFT,
67 (core_rev & IMG_IR_MAJOR_REV) >> IMG_IR_MAJOR_REV_SHIFT,
68 (core_rev & IMG_IR_MINOR_REV) >> IMG_IR_MINOR_REV_SHIFT,
69 (core_rev & IMG_IR_MAINT_REV) >> IMG_IR_MAINT_REV_SHIFT);
70 dev_info(priv->dev, "Modes:%s%s\n",
71 img_ir_hw_enabled(&priv->hw) ? " hardware" : "",
72 img_ir_raw_enabled(&priv->raw) ? " raw" : "");
75 static int img_ir_probe(struct platform_device *pdev)
77 struct img_ir_priv *priv;
78 struct resource *res_regs;
79 int irq, error, error2;
81 /* Get resources from platform device */
82 irq = platform_get_irq(pdev, 0);
83 if (irq < 0) {
84 dev_err(&pdev->dev, "cannot find IRQ resource\n");
85 return irq;
88 /* Private driver data */
89 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
90 if (!priv) {
91 dev_err(&pdev->dev, "cannot allocate device data\n");
92 return -ENOMEM;
94 platform_set_drvdata(pdev, priv);
95 priv->dev = &pdev->dev;
96 spin_lock_init(&priv->lock);
98 /* Ioremap the registers */
99 res_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
100 priv->reg_base = devm_ioremap_resource(&pdev->dev, res_regs);
101 if (IS_ERR(priv->reg_base))
102 return PTR_ERR(priv->reg_base);
104 /* Get core clock */
105 priv->clk = devm_clk_get(&pdev->dev, "core");
106 if (IS_ERR(priv->clk))
107 dev_warn(&pdev->dev, "cannot get core clock resource\n");
109 * The driver doesn't need to know about the system ("sys") or power
110 * modulation ("mod") clocks yet
113 /* Set up raw & hw decoder */
114 error = img_ir_probe_raw(priv);
115 error2 = img_ir_probe_hw(priv);
116 if (error && error2)
117 return (error == -ENODEV) ? error2 : error;
119 /* Get the IRQ */
120 priv->irq = irq;
121 error = request_irq(priv->irq, img_ir_isr, 0, "img-ir", priv);
122 if (error) {
123 dev_err(&pdev->dev, "cannot register IRQ %u\n",
124 priv->irq);
125 error = -EIO;
126 goto err_irq;
129 img_ir_ident(priv);
130 img_ir_setup(priv);
132 return 0;
134 err_irq:
135 img_ir_remove_hw(priv);
136 img_ir_remove_raw(priv);
137 return error;
140 static int img_ir_remove(struct platform_device *pdev)
142 struct img_ir_priv *priv = platform_get_drvdata(pdev);
144 free_irq(priv->irq, img_ir_isr);
145 img_ir_remove_hw(priv);
146 img_ir_remove_raw(priv);
148 if (!IS_ERR(priv->clk))
149 clk_disable_unprepare(priv->clk);
150 return 0;
153 static SIMPLE_DEV_PM_OPS(img_ir_pmops, img_ir_suspend, img_ir_resume);
155 static const struct of_device_id img_ir_match[] = {
156 { .compatible = "img,ir-rev1" },
159 MODULE_DEVICE_TABLE(of, img_ir_match);
161 static struct platform_driver img_ir_driver = {
162 .driver = {
163 .name = "img-ir",
164 .owner = THIS_MODULE,
165 .of_match_table = img_ir_match,
166 .pm = &img_ir_pmops,
168 .probe = img_ir_probe,
169 .remove = img_ir_remove,
172 module_platform_driver(img_ir_driver);
174 MODULE_AUTHOR("Imagination Technologies Ltd.");
175 MODULE_DESCRIPTION("ImgTec IR");
176 MODULE_LICENSE("GPL");