1 /* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/time.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/spinlock.h>
25 #include <linux/delay.h>
26 #include <mach/hardware.h>
29 #include <asm/system.h>
30 #include <asm/mach-types.h>
31 #include <linux/semaphore.h>
32 #include <linux/uaccess.h>
33 #include <linux/clk.h>
34 #include <linux/platform_device.h>
35 #include <linux/pm_qos_params.h>
41 static int tvenc_probe(struct platform_device
*pdev
);
42 static int tvenc_remove(struct platform_device
*pdev
);
44 static int tvenc_off(struct platform_device
*pdev
);
45 static int tvenc_on(struct platform_device
*pdev
);
47 static struct platform_device
*pdev_list
[MSM_FB_MAX_DEV_LIST
];
48 static int pdev_list_cnt
;
50 static struct clk
*tvenc_clk
;
51 static struct clk
*tvdac_clk
;
53 static struct platform_driver tvenc_driver
= {
55 .remove
= tvenc_remove
,
57 // .suspend_late = NULL,
58 // .resume_early = NULL,
66 static struct tvenc_platform_data
*tvenc_pdata
;
68 static int tvenc_off(struct platform_device
*pdev
)
72 ret
= panel_next_off(pdev
);
74 clk_disable(tvenc_clk
);
75 clk_disable(tvdac_clk
);
77 if (tvenc_pdata
&& tvenc_pdata
->pm_vid_en
)
78 ret
= tvenc_pdata
->pm_vid_en(0);
80 //pm_qos_update_requirement(PM_QOS_SYSTEM_BUS_FREQ , "tvenc",
81 // PM_QOS_DEFAULT_VALUE);
84 printk(KERN_ERR
"%s: pm_vid_en(off) failed! %d\n",
90 static int tvenc_on(struct platform_device
*pdev
)
94 // pm_qos_update_requirement(PM_QOS_SYSTEM_BUS_FREQ , "tvenc",
96 if (tvenc_pdata
&& tvenc_pdata
->pm_vid_en
)
97 ret
= tvenc_pdata
->pm_vid_en(1);
100 printk(KERN_ERR
"%s: pm_vid_en(on) failed! %d\n",
105 clk_enable(tvenc_clk
);
106 clk_enable(tvdac_clk
);
108 ret
= panel_next_on(pdev
);
113 void tvenc_gen_test_pattern(struct msm_fb_data_type
*mfd
)
117 reg
= readl(MSM_TV_ENC_CTL
);
118 reg
|= TVENC_CTL_TEST_PATT_EN
;
120 for (i
= 0; i
< 3; i
++) {
121 TV_OUT(TV_ENC_CTL
, 0); /* disable TV encoder */
125 * TV Encoder - Color Bar Test Pattern
128 reg
|= TVENC_CTL_TPG_CLRBAR
;
131 * TV Encoder - Red Frame Test Pattern
134 reg
|= TVENC_CTL_TPG_REDCLR
;
137 * TV Encoder - Modulated Ramp Test Pattern
140 reg
|= TVENC_CTL_TPG_MODRAMP
;
144 TV_OUT(TV_ENC_CTL
, reg
);
149 * TV Encoder - Color Bar Test Pattern
152 reg
&= ~TVENC_CTL_TPG_CLRBAR
;
155 * TV Encoder - Red Frame Test Pattern
158 reg
&= ~TVENC_CTL_TPG_REDCLR
;
161 * TV Encoder - Modulated Ramp Test Pattern
164 reg
&= ~TVENC_CTL_TPG_MODRAMP
;
170 static int tvenc_resource_initialized
;
172 static int tvenc_probe(struct platform_device
*pdev
)
174 struct msm_fb_data_type
*mfd
;
175 struct platform_device
*mdp_dev
= NULL
;
176 struct msm_fb_panel_data
*pdata
= NULL
;
180 tvenc_base
= ioremap(pdev
->resource
[0].start
,
181 pdev
->resource
[0].end
-
182 pdev
->resource
[0].start
+ 1);
185 "tvenc_base ioremap failed!\n");
188 tvenc_pdata
= pdev
->dev
.platform_data
;
189 tvenc_resource_initialized
= 1;
193 if (!tvenc_resource_initialized
)
196 mfd
= platform_get_drvdata(pdev
);
201 if (mfd
->key
!= MFD_KEY
)
204 if (pdev_list_cnt
>= MSM_FB_MAX_DEV_LIST
)
207 if (tvenc_base
== NULL
)
210 mdp_dev
= platform_device_alloc("mdp", pdev
->id
);
215 * link to the latest pdev
218 mfd
->dest
= DISPLAY_TV
;
221 * alloc panel device data
223 if (platform_device_add_data
224 (mdp_dev
, pdev
->dev
.platform_data
,
225 sizeof(struct msm_fb_panel_data
))) {
226 printk(KERN_ERR
"tvenc_probe: platform_device_add_data failed!\n");
227 platform_device_put(mdp_dev
);
233 pdata
= mdp_dev
->dev
.platform_data
;
234 pdata
->on
= tvenc_on
;
235 pdata
->off
= tvenc_off
;
239 * get/set panel specific fb info
241 mfd
->panel_info
= pdata
->panel_info
;
242 mfd
->fb_imgType
= MDP_YCRYCB_H2V1
;
247 platform_set_drvdata(mdp_dev
, mfd
);
250 * register in mdp driver
252 rc
= platform_device_add(mdp_dev
);
254 goto tvenc_probe_err
;
256 pdev_list
[pdev_list_cnt
++] = pdev
;
260 platform_device_put(mdp_dev
);
264 static int tvenc_remove(struct platform_device
*pdev
)
266 // pm_qos_remove_requirement(PM_QOS_SYSTEM_BUS_FREQ , "tvenc");
270 static int tvenc_register_driver(void)
272 return platform_driver_register(&tvenc_driver
);
275 static int __init
tvenc_driver_init(void)
277 tvenc_clk
= clk_get(NULL
, "tv_enc_clk");
278 tvdac_clk
= clk_get(NULL
, "tv_dac_clk");
280 if (IS_ERR(tvenc_clk
)) {
281 printk(KERN_ERR
"error: can't get tvenc_clk!\n");
282 return PTR_ERR(tvenc_clk
);
285 if (IS_ERR(tvdac_clk
)) {
286 printk(KERN_ERR
"error: can't get tvdac_clk!\n");
288 return PTR_ERR(tvdac_clk
);
291 // pm_qos_add_requirement(PM_QOS_SYSTEM_BUS_FREQ , "tvenc",
292 // PM_QOS_DEFAULT_VALUE);
293 return tvenc_register_driver();
296 module_init(tvenc_driver_init
);