blob: bd0ce2fccd03ffa800945a1728102f73883d78db [file] [log] [blame]
Evan McClain97f044c2012-09-12 00:33:53 -04001/* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
2 *
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.
6 *
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.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/sched.h>
17#include <linux/time.h>
18#include <linux/init.h>
19#include <linux/interrupt.h>
20#include <linux/spinlock.h>
21#include <linux/delay.h>
22#include <linux/io.h>
23#include <linux/semaphore.h>
24#include <linux/uaccess.h>
25#include <linux/clk.h>
26#include <linux/platform_device.h>
27#include <asm/system.h>
28#include <asm/mach-types.h>
29#include <mach/hardware.h>
30#include <linux/pm_runtime.h>
31#include <mach/clk.h>
32
33#include "msm_fb.h"
34#include "mdp4.h"
35
36static int dtv_probe(struct platform_device *pdev);
37static int dtv_remove(struct platform_device *pdev);
38
39static int dtv_off(struct platform_device *pdev);
40static int dtv_on(struct platform_device *pdev);
41
42static struct platform_device *pdev_list[MSM_FB_MAX_DEV_LIST];
43static int pdev_list_cnt;
44
45static struct clk *tv_src_clk;
46static struct clk *hdmi_clk;
47static struct clk *mdp_tv_clk;
48
49
50static int mdp4_dtv_runtime_suspend(struct device *dev)
51{
52 dev_dbg(dev, "pm_runtime: suspending...\n");
53 return 0;
54}
55
56static int mdp4_dtv_runtime_resume(struct device *dev)
57{
58 dev_dbg(dev, "pm_runtime: resuming...\n");
59 return 0;
60}
61
62static const struct dev_pm_ops mdp4_dtv_dev_pm_ops = {
63 .runtime_suspend = mdp4_dtv_runtime_suspend,
64 .runtime_resume = mdp4_dtv_runtime_resume,
65};
66
67static struct platform_driver dtv_driver = {
68 .probe = dtv_probe,
69 .remove = dtv_remove,
70 .suspend = NULL,
71 .resume = NULL,
72 .shutdown = NULL,
73 .driver = {
74 .name = "dtv",
75 .pm = &mdp4_dtv_dev_pm_ops,
76 },
77};
78
79static struct lcdc_platform_data *dtv_pdata;
80#ifdef CONFIG_MSM_BUS_SCALING
81static uint32_t dtv_bus_scale_handle;
82#else
83static struct clk *ebi1_clk;
84#endif
85
86static int dtv_off(struct platform_device *pdev)
87{
88 int ret = 0;
89
90 ret = panel_next_off(pdev);
91
92 pr_info("%s\n", __func__);
93
94 clk_disable_unprepare(hdmi_clk);
95 if (mdp_tv_clk)
96 clk_disable_unprepare(mdp_tv_clk);
97
98 if (dtv_pdata && dtv_pdata->lcdc_power_save)
99 dtv_pdata->lcdc_power_save(0);
100
101 if (dtv_pdata && dtv_pdata->lcdc_gpio_config)
102 ret = dtv_pdata->lcdc_gpio_config(0);
103#ifdef CONFIG_MSM_BUS_SCALING
104 if (dtv_bus_scale_handle > 0)
105 msm_bus_scale_client_update_request(dtv_bus_scale_handle,
106 0);
107#else
108 if (ebi1_clk)
109 clk_disable_unprepare(ebi1_clk);
110#endif
111 mdp4_extn_disp = 0;
112 return ret;
113}
114
115static int dtv_on(struct platform_device *pdev)
116{
117 int ret = 0;
118 struct msm_fb_data_type *mfd;
119 unsigned long panel_pixclock_freq , pm_qos_rate;
120
121 mfd = platform_get_drvdata(pdev);
122 panel_pixclock_freq = mfd->fbi->var.pixclock;
123
124 if (panel_pixclock_freq > 58000000)
125 /* pm_qos_rate should be in Khz */
126 pm_qos_rate = panel_pixclock_freq / 1000 ;
127 else
128 pm_qos_rate = 58000;
129 mdp4_extn_disp = 1;
130#ifdef CONFIG_MSM_BUS_SCALING
131 if (dtv_bus_scale_handle > 0)
132 msm_bus_scale_client_update_request(dtv_bus_scale_handle,
133 1);
134#else
135 if (ebi1_clk) {
136 clk_set_rate(ebi1_clk, pm_qos_rate * 1000);
137 clk_prepare_enable(ebi1_clk);
138 }
139#endif
140
141 if (dtv_pdata && dtv_pdata->lcdc_power_save)
142 dtv_pdata->lcdc_power_save(1);
143 if (dtv_pdata && dtv_pdata->lcdc_gpio_config)
144 ret = dtv_pdata->lcdc_gpio_config(1);
145
146 mfd = platform_get_drvdata(pdev);
147
148 ret = clk_set_rate(tv_src_clk, mfd->fbi->var.pixclock);
149 if (ret) {
150 pr_info("%s: clk_set_rate(%d) failed\n", __func__,
151 mfd->fbi->var.pixclock);
152 if (mfd->fbi->var.pixclock == 27030000)
153 mfd->fbi->var.pixclock = 27000000;
154 ret = clk_set_rate(tv_src_clk, mfd->fbi->var.pixclock);
155 }
156 pr_info("%s: tv_src_clk=%dkHz, pm_qos_rate=%ldkHz, [%d]\n", __func__,
157 mfd->fbi->var.pixclock/1000, pm_qos_rate, ret);
158 mfd->panel_info.clk_rate = mfd->fbi->var.pixclock;
159 clk_prepare_enable(hdmi_clk);
160 clk_reset(hdmi_clk, CLK_RESET_ASSERT);
161 udelay(20);
162 clk_reset(hdmi_clk, CLK_RESET_DEASSERT);
163
164 if (mdp_tv_clk)
165 clk_prepare_enable(mdp_tv_clk);
166
167 ret = panel_next_on(pdev);
168 return ret;
169}
170
171static int dtv_probe(struct platform_device *pdev)
172{
173 struct msm_fb_data_type *mfd;
174 struct fb_info *fbi;
175 struct platform_device *mdp_dev = NULL;
176 struct msm_fb_panel_data *pdata = NULL;
177 int rc;
178
179 if (pdev->id == 0) {
180 dtv_pdata = pdev->dev.platform_data;
181#ifdef CONFIG_MSM_BUS_SCALING
182 if (!dtv_bus_scale_handle && dtv_pdata &&
183 dtv_pdata->bus_scale_table) {
184 dtv_bus_scale_handle =
185 msm_bus_scale_register_client(
186 dtv_pdata->bus_scale_table);
187 if (!dtv_bus_scale_handle) {
188 pr_err("%s not able to get bus scale\n",
189 __func__);
190 }
191 }
192#else
193 ebi1_clk = clk_get(&pdev->dev, "mem_clk");
194 if (IS_ERR(ebi1_clk)) {
195 ebi1_clk = NULL;
196 pr_warning("%s: Couldn't get ebi1 clock\n", __func__);
197 }
198#endif
199 tv_src_clk = clk_get(&pdev->dev, "src_clk");
200 if (IS_ERR(tv_src_clk)) {
201 pr_err("error: can't get tv_src_clk!\n");
202 return IS_ERR(tv_src_clk);
203 }
204
205 hdmi_clk = clk_get(&pdev->dev, "hdmi_clk");
206 if (IS_ERR(hdmi_clk)) {
207 pr_err("error: can't get hdmi_clk!\n");
208 return IS_ERR(hdmi_clk);
209 }
210
211 mdp_tv_clk = clk_get(&pdev->dev, "mdp_clk");
212 if (IS_ERR(mdp_tv_clk))
213 mdp_tv_clk = NULL;
214
215 return 0;
216 }
217
218 mfd = platform_get_drvdata(pdev);
219
220 if (!mfd)
221 return -ENODEV;
222
223 if (mfd->key != MFD_KEY)
224 return -EINVAL;
225
226 if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST)
227 return -ENOMEM;
228
229 mdp_dev = platform_device_alloc("mdp", pdev->id);
230 if (!mdp_dev)
231 return -ENOMEM;
232
233 /*
234 * link to the latest pdev
235 */
236 mfd->pdev = mdp_dev;
237 mfd->dest = DISPLAY_LCDC;
238
239 /*
240 * alloc panel device data
241 */
242 if (platform_device_add_data
243 (mdp_dev, pdev->dev.platform_data,
244 sizeof(struct msm_fb_panel_data))) {
245 pr_err("dtv_probe: platform_device_add_data failed!\n");
246 platform_device_put(mdp_dev);
247 return -ENOMEM;
248 }
249 /*
250 * data chain
251 */
252 pdata = (struct msm_fb_panel_data *)mdp_dev->dev.platform_data;
253 pdata->on = dtv_on;
254 pdata->off = dtv_off;
255 pdata->next = pdev;
256
257 /*
258 * get/set panel specific fb info
259 */
260 mfd->panel_info = pdata->panel_info;
261 if (hdmi_prim_display)
262 mfd->fb_imgType = MSMFB_DEFAULT_TYPE;
263 else
264 mfd->fb_imgType = MDP_RGB_565;
265
266 fbi = mfd->fbi;
267 fbi->var.pixclock = mfd->panel_info.clk_rate;
268 fbi->var.left_margin = mfd->panel_info.lcdc.h_back_porch;
269 fbi->var.right_margin = mfd->panel_info.lcdc.h_front_porch;
270 fbi->var.upper_margin = mfd->panel_info.lcdc.v_back_porch;
271 fbi->var.lower_margin = mfd->panel_info.lcdc.v_front_porch;
272 fbi->var.hsync_len = mfd->panel_info.lcdc.h_pulse_width;
273 fbi->var.vsync_len = mfd->panel_info.lcdc.v_pulse_width;
274
275 /*
276 * set driver data
277 */
278 platform_set_drvdata(mdp_dev, mfd);
279
280 /*
281 * register in mdp driver
282 */
283 rc = platform_device_add(mdp_dev);
284 if (rc)
285 goto dtv_probe_err;
286
287 pm_runtime_set_active(&pdev->dev);
288 pm_runtime_enable(&pdev->dev);
289
290 pdev_list[pdev_list_cnt++] = pdev;
291 return 0;
292
293dtv_probe_err:
294#ifdef CONFIG_MSM_BUS_SCALING
295 if (dtv_pdata && dtv_pdata->bus_scale_table &&
296 dtv_bus_scale_handle > 0)
297 msm_bus_scale_unregister_client(dtv_bus_scale_handle);
298#endif
299 platform_device_put(mdp_dev);
300 return rc;
301}
302
303static int dtv_remove(struct platform_device *pdev)
304{
305#ifdef CONFIG_MSM_BUS_SCALING
306 if (dtv_pdata && dtv_pdata->bus_scale_table &&
307 dtv_bus_scale_handle > 0)
308 msm_bus_scale_unregister_client(dtv_bus_scale_handle);
309#else
310 if (ebi1_clk)
311 clk_put(ebi1_clk);
312#endif
313 pm_runtime_disable(&pdev->dev);
314 return 0;
315}
316
317static int dtv_register_driver(void)
318{
319 return platform_driver_register(&dtv_driver);
320}
321
322static int __init dtv_driver_init(void)
323{
324 return dtv_register_driver();
325}
326
327module_init(dtv_driver_init);