blob: 68590afd04a4bdc2d1638f79a4b45d0b6a69f0db [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2008-2009, 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/moduleparam.h>
16#include <linux/kernel.h>
17#include <linux/slab.h>
18#include <linux/delay.h>
19#include <linux/mm.h>
20#include <linux/fb.h>
21#include <linux/init.h>
22#include <linux/ioport.h>
23#include <linux/device.h>
24#include <linux/dma-mapping.h>
25#include <linux/uaccess.h>
26#include <linux/workqueue.h>
27#include <linux/string.h>
28#include <linux/version.h>
29#include <linux/proc_fs.h>
30#include <linux/vmalloc.h>
31#include <linux/debugfs.h>
32
33#include "msm_fb.h"
34
35static int ebi2_lcd_probe(struct platform_device *pdev);
36static int ebi2_lcd_remove(struct platform_device *pdev);
37
38static int ebi2_lcd_runtime_suspend(struct device *dev)
39{
40 dev_dbg(dev, "pm_runtime: suspending...\n");
41 return 0;
42}
43
44static int ebi2_lcd_runtime_resume(struct device *dev)
45{
46 dev_dbg(dev, "pm_runtime: resuming...\n");
47 return 0;
48}
49
50static struct dev_pm_ops ebi2_lcd_dev_pm_ops = {
51 .runtime_suspend = ebi2_lcd_runtime_suspend,
52 .runtime_resume = ebi2_lcd_runtime_resume,
53};
54
55static struct platform_driver ebi2_lcd_driver = {
56 .probe = ebi2_lcd_probe,
57 .remove = ebi2_lcd_remove,
58 .suspend = NULL,
59 .suspend_late = NULL,
60 .resume_early = NULL,
61 .resume = NULL,
62 .shutdown = NULL,
63 .driver = {
64 .name = "ebi2_lcd",
65 .pm = &ebi2_lcd_dev_pm_ops,
66 },
67};
68
69static void *ebi2_base;
70static void *ebi2_lcd_cfg0;
71static void *ebi2_lcd_cfg1;
72static void __iomem *lcd01_base;
73static void __iomem *lcd02_base;
74static int ebi2_lcd_resource_initialized;
75
76static struct platform_device *pdev_list[MSM_FB_MAX_DEV_LIST];
77static int pdev_list_cnt;
78
79static int ebi2_lcd_probe(struct platform_device *pdev)
80{
81 struct msm_fb_data_type *mfd;
82 struct platform_device *mdp_dev = NULL;
83 struct msm_fb_panel_data *pdata = NULL;
84 int rc, i;
85
86 if (pdev->id == 0) {
87 for (i = 0; i < pdev->num_resources; i++) {
88 if (!strncmp(pdev->resource[i].name, "base", 4)) {
89 ebi2_base = ioremap(pdev->resource[i].start,
90 pdev->resource[i].end -
91 pdev->resource[i].start + 1);
92 if (!ebi2_base) {
93 printk(KERN_ERR
94 "ebi2_base ioremap failed!\n");
95 return -ENOMEM;
96 }
97 ebi2_lcd_cfg0 = (void *)(ebi2_base + 0x20);
98 ebi2_lcd_cfg1 = (void *)(ebi2_base + 0x24);
99 } else if (!strncmp(pdev->resource[i].name,
100 "lcd01", 5)) {
101 lcd01_base = ioremap(pdev->resource[i].start,
102 pdev->resource[i].end -
103 pdev->resource[i].start + 1);
104 if (!lcd01_base) {
105 printk(KERN_ERR
106 "lcd01_base ioremap failed!\n");
107 return -ENOMEM;
108 }
109 } else if (!strncmp(pdev->resource[i].name,
110 "lcd02", 5)) {
111 lcd02_base = ioremap(pdev->resource[i].start,
112 pdev->resource[i].end -
113 pdev->resource[i].start + 1);
114 if (!lcd02_base) {
115 printk(KERN_ERR
116 "lcd02_base ioremap failed!\n");
117 return -ENOMEM;
118 }
119 }
120 }
121 ebi2_lcd_resource_initialized = 1;
122 return 0;
123 }
124
125 if (!ebi2_lcd_resource_initialized)
126 return -EPERM;
127
128 mfd = platform_get_drvdata(pdev);
129
130 if (!mfd)
131 return -ENODEV;
132
133 if (mfd->key != MFD_KEY)
134 return -EINVAL;
135
136 if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST)
137 return -ENOMEM;
138
139 if (ebi2_base == NULL)
140 return -ENOMEM;
141
142 mdp_dev = platform_device_alloc("mdp", pdev->id);
143 if (!mdp_dev)
144 return -ENOMEM;
145
146 /* link to the latest pdev */
147 mfd->pdev = mdp_dev;
148 mfd->dest = DISPLAY_LCD;
149
150 /* add panel data */
151 if (platform_device_add_data
152 (mdp_dev, pdev->dev.platform_data,
153 sizeof(struct msm_fb_panel_data))) {
154 printk(KERN_ERR "ebi2_lcd_probe: platform_device_add_data failed!\n");
155 platform_device_put(mdp_dev);
156 return -ENOMEM;
157 }
158
159 /* data chain */
160 pdata = mdp_dev->dev.platform_data;
161 pdata->on = panel_next_on;
162 pdata->off = panel_next_off;
163 pdata->next = pdev;
164
165 /* get/set panel specific fb info */
166 mfd->panel_info = pdata->panel_info;
167
168 if (mfd->panel_info.bpp == 24)
169 mfd->fb_imgType = MDP_RGB_888;
170 else
171 mfd->fb_imgType = MDP_RGB_565;
172
173 /* config msm ebi2 lcd register */
174 if (mfd->panel_info.pdest == DISPLAY_1) {
175 outp32(ebi2_base,
176 (inp32(ebi2_base) & (~(EBI2_PRIM_LCD_CLR))) |
177 EBI2_PRIM_LCD_SEL);
178 /*
179 * current design has one set of cfg0/1 register to control
180 * both EBI2 channels. so, we're using the PRIM channel to
181 * configure both.
182 */
183 outp32(ebi2_lcd_cfg0, mfd->panel_info.wait_cycle);
184 if (mfd->panel_info.bpp == 18)
185 outp32(ebi2_lcd_cfg1, 0x01000000);
186 else
187 outp32(ebi2_lcd_cfg1, 0x0);
188 } else {
189#ifdef DEBUG_EBI2_LCD
190 /*
191 * confliting with QCOM SURF FPGA CS.
192 * OEM should enable below for their CS mapping
193 */
194 outp32(ebi2_base, (inp32(ebi2_base)&(~(EBI2_SECD_LCD_CLR)))
195 |EBI2_SECD_LCD_SEL);
196#endif
197 }
198
199 /*
200 * map cs (chip select) address
201 */
202 if (mfd->panel_info.pdest == DISPLAY_1) {
203 mfd->cmd_port = lcd01_base;
204 mfd->data_port =
205 (void *)((uint32) mfd->cmd_port + EBI2_PRIM_LCD_RS_PIN);
206 mfd->data_port_phys =
207 (void *)(LCD_PRIM_BASE_PHYS + EBI2_PRIM_LCD_RS_PIN);
208 } else {
209 mfd->cmd_port = lcd01_base;
210 mfd->data_port =
211 (void *)((uint32) mfd->cmd_port + EBI2_SECD_LCD_RS_PIN);
212 mfd->data_port_phys =
213 (void *)(LCD_SECD_BASE_PHYS + EBI2_SECD_LCD_RS_PIN);
214 }
215
216 /*
217 * set driver data
218 */
219 platform_set_drvdata(mdp_dev, mfd);
220
221 /*
222 * register in mdp driver
223 */
224 rc = platform_device_add(mdp_dev);
225 if (rc) {
226 goto ebi2_lcd_probe_err;
227 }
228
229 pm_runtime_set_active(&pdev->dev);
230 pm_runtime_enable(&pdev->dev);
231
232
233 pdev_list[pdev_list_cnt++] = pdev;
234 return 0;
235
236 ebi2_lcd_probe_err:
237 platform_device_put(mdp_dev);
238 return rc;
239}
240
241static int ebi2_lcd_remove(struct platform_device *pdev)
242{
243 struct msm_fb_data_type *mfd;
244
245 mfd = (struct msm_fb_data_type *)platform_get_drvdata(pdev);
246
247 if (!mfd)
248 return 0;
249
250 if (mfd->key != MFD_KEY)
251 return 0;
252
253 iounmap(mfd->cmd_port);
254 pm_runtime_disable(&pdev->dev);
255 return 0;
256}
257
258static int ebi2_lcd_register_driver(void)
259{
260 return platform_driver_register(&ebi2_lcd_driver);
261}
262
263static int __init ebi2_lcd_driver_init(void)
264{
265 return ebi2_lcd_register_driver();
266}
267
268module_init(ebi2_lcd_driver_init);