2 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
6 * The code contained herein is licensed under the GNU General Public
7 * License. You may obtain a copy of the GNU General Public License
8 * Version 2 or later at the following locations:
10 * http://www.opensource.org/licenses/gpl-license.html
11 * http://www.gnu.org/copyleft/gpl.html
14 #include <linux/init.h>
15 #include <linux/ipu.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/mxcfb.h>
19 #include <linux/of_device.h>
20 #include <linux/pinctrl/consumer.h>
21 #include <linux/platform_device.h>
22 #include <video/of_display_timing.h>
23 #include <video/of_videomode.h>
24 #include <video/videomode.h>
26 #include "mxc_dispdrv.h"
28 struct mxc_lcd_platform_data {
32 enum display_flags disp_flags;
35 struct mxc_lcdif_data {
37 struct mxc_dispdrv_handle *disp_lcdif;
40 #define DISPDRV_LCD "lcd"
42 static struct fb_videomode lcdif_modedb[] = {
44 /* 800x480 @ 57 Hz , pixel clk @ 27MHz */
45 "CLAA-WVGA", 57, 800, 480, 37037, 40, 60, 10, 10, 20, 10,
47 FB_VMODE_NONINTERLACED,
51 /* 800x480 @ 60 Hz , pixel clk @ 32MHz */
52 "SEIKO-WVGA", 60, 800, 480, 29850, 89, 164, 23, 10, 10, 10,
54 FB_VMODE_NONINTERLACED,
59 .pixclock = KHZ2PICOS(25200),
71 .pixclock = KHZ2PICOS(25200),
83 .pixclock = KHZ2PICOS(6413760 / 1000),
95 .pixclock = KHZ2PICOS(9009),
104 .sync = FB_SYNC_CLK_LAT_FALL,
108 .pixclock = KHZ2PICOS(33264),
119 .name = "ET0700", /* same as ET0500 */
120 .pixclock = KHZ2PICOS(33264),
132 .pixclock = KHZ2PICOS(6596040 / 1000),
143 static int lcdif_modedb_sz = ARRAY_SIZE(lcdif_modedb);
145 static int lcdif_init(struct mxc_dispdrv_handle *disp,
146 struct mxc_dispdrv_setting *setting)
149 struct mxc_lcdif_data *lcdif = mxc_dispdrv_getdata(disp);
150 struct mxc_lcd_platform_data *plat_data = lcdif->dev->platform_data;
151 struct fb_videomode *modedb = lcdif_modedb;
152 int modedb_sz = lcdif_modedb_sz;
154 /* use platform defined ipu/di */
155 setting->dev_id = plat_data->ipu_id;
156 setting->disp_id = plat_data->disp_id;
157 setting->disp_flags = plat_data->disp_flags;
159 printk(KERN_DEBUG "%s: disp_flags=%08x\n", __func__, setting->disp_flags);
160 ret = fb_find_mode(&setting->fbi->var, setting->fbi, setting->dft_mode_str,
161 modedb, modedb_sz, NULL, setting->default_bpp);
163 fb_videomode_to_var(&setting->fbi->var, &modedb[0]);
164 setting->if_fmt = plat_data->default_ifmt;
167 INIT_LIST_HEAD(&setting->fbi->modelist);
168 for (i = 0; i < modedb_sz; i++) {
169 struct fb_videomode m;
170 fb_var_to_videomode(&m, &setting->fbi->var);
171 if (fb_mode_is_equal(&m, &modedb[i])) {
172 fb_add_videomode(&modedb[i],
173 &setting->fbi->modelist);
181 void lcdif_deinit(struct mxc_dispdrv_handle *disp)
186 static struct mxc_dispdrv_driver lcdif_drv = {
189 .deinit = lcdif_deinit,
192 static int lcd_get_of_property(struct device *dev,
193 struct mxc_lcd_platform_data *plat_data)
195 struct device_node *np = dev->of_node;
198 const char *default_ifmt;
200 err = of_property_read_string(np, "default_ifmt", &default_ifmt);
202 dev_err(dev, "get of property default_ifmt fail\n");
205 err = of_property_read_u32(np, "ipu_id", &ipu_id);
207 dev_err(dev, "get of property ipu_id fail\n");
210 err = of_property_read_u32(np, "disp_id", &disp_id);
212 dev_err(dev, "get of property disp_id fail\n");
217 struct videomode vm = { };
219 err = of_get_videomode(np, &vm, OF_USE_NATIVE_MODE);
221 dev_dbg(dev, "Copying videomode from display-timings\n");
222 fb_videomode_from_videomode(&vm, &lcdif_modedb[0]);
223 plat_data->disp_flags = vm.flags;
228 plat_data->ipu_id = ipu_id;
229 plat_data->disp_id = disp_id;
230 if (!strncmp(default_ifmt, "RGB24", 5))
231 plat_data->default_ifmt = IPU_PIX_FMT_RGB24;
232 else if (!strncmp(default_ifmt, "BGR24", 5))
233 plat_data->default_ifmt = IPU_PIX_FMT_BGR24;
234 else if (!strncmp(default_ifmt, "GBR24", 5))
235 plat_data->default_ifmt = IPU_PIX_FMT_GBR24;
236 else if (!strncmp(default_ifmt, "RGB565", 6))
237 plat_data->default_ifmt = IPU_PIX_FMT_RGB565;
238 else if (!strncmp(default_ifmt, "RGB666", 6))
239 plat_data->default_ifmt = IPU_PIX_FMT_RGB666;
240 else if (!strncmp(default_ifmt, "YUV444", 6))
241 plat_data->default_ifmt = IPU_PIX_FMT_YUV444;
242 else if (!strncmp(default_ifmt, "LVDS666", 7))
243 plat_data->default_ifmt = IPU_PIX_FMT_LVDS666;
244 else if (!strncmp(default_ifmt, "YUYV16", 6))
245 plat_data->default_ifmt = IPU_PIX_FMT_YUYV;
246 else if (!strncmp(default_ifmt, "UYVY16", 6))
247 plat_data->default_ifmt = IPU_PIX_FMT_UYVY;
248 else if (!strncmp(default_ifmt, "YVYU16", 6))
249 plat_data->default_ifmt = IPU_PIX_FMT_YVYU;
250 else if (!strncmp(default_ifmt, "VYUY16", 6))
251 plat_data->default_ifmt = IPU_PIX_FMT_VYUY;
253 dev_err(dev, "err default_ifmt!\n");
260 static int mxc_lcdif_probe(struct platform_device *pdev)
263 struct pinctrl *pinctrl;
264 struct mxc_lcdif_data *lcdif;
265 struct mxc_lcd_platform_data *plat_data;
267 dev_dbg(&pdev->dev, "%s enter\n", __func__);
268 lcdif = devm_kzalloc(&pdev->dev, sizeof(struct mxc_lcdif_data),
272 plat_data = devm_kzalloc(&pdev->dev,
273 sizeof(struct mxc_lcd_platform_data),
277 pdev->dev.platform_data = plat_data;
279 ret = lcd_get_of_property(&pdev->dev, plat_data);
281 dev_err(&pdev->dev, "get lcd of property fail\n");
285 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
286 if (IS_ERR(pinctrl)) {
287 dev_err(&pdev->dev, "can't get/select pinctrl\n");
288 return PTR_ERR(pinctrl);
291 lcdif->dev = &pdev->dev;
292 lcdif->disp_lcdif = mxc_dispdrv_register(&lcdif_drv);
293 mxc_dispdrv_setdata(lcdif->disp_lcdif, lcdif);
295 dev_set_drvdata(&pdev->dev, lcdif);
296 dev_dbg(&pdev->dev, "%s exit\n", __func__);
301 static int mxc_lcdif_remove(struct platform_device *pdev)
303 struct mxc_lcdif_data *lcdif = platform_get_drvdata(pdev);
305 mxc_dispdrv_puthandle(lcdif->disp_lcdif);
306 mxc_dispdrv_unregister(lcdif->disp_lcdif);
311 static const struct of_device_id imx_lcd_dt_ids[] = {
312 { .compatible = "fsl,lcd"},
315 static struct platform_driver mxc_lcdif_driver = {
318 .of_match_table = imx_lcd_dt_ids,
320 .probe = mxc_lcdif_probe,
321 .remove = mxc_lcdif_remove,
324 static int __init mxc_lcdif_init(void)
326 return platform_driver_register(&mxc_lcdif_driver);
329 static void __exit mxc_lcdif_exit(void)
331 platform_driver_unregister(&mxc_lcdif_driver);
334 module_init(mxc_lcdif_init);
335 module_exit(mxc_lcdif_exit);
337 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
338 MODULE_DESCRIPTION("i.MX ipuv3 LCD extern port driver");
339 MODULE_LICENSE("GPL");