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>
23 #include "mxc_dispdrv.h"
25 struct mxc_lcd_platform_data {
31 struct mxc_lcdif_data {
33 struct mxc_dispdrv_handle *disp_lcdif;
36 #define DISPDRV_LCD "lcd"
38 static struct fb_videomode lcdif_modedb[] = {
40 /* 800x480 @ 57 Hz , pixel clk @ 27MHz */
41 "CLAA-WVGA", 57, 800, 480, 37037, 40, 60, 10, 10, 20, 10,
43 FB_VMODE_NONINTERLACED,
47 /* 800x480 @ 60 Hz , pixel clk @ 32MHz */
48 "SEIKO-WVGA", 60, 800, 480, 29850, 89, 164, 23, 10, 10, 10,
50 FB_VMODE_NONINTERLACED,
55 .pixclock = KHZ2PICOS(25200),
67 .pixclock = KHZ2PICOS(25200),
79 .pixclock = KHZ2PICOS(6413760 / 1000),
91 .pixclock = KHZ2PICOS(9009),
100 .sync = FB_SYNC_CLK_LAT_FALL,
104 .pixclock = KHZ2PICOS(33264),
115 .name = "ET0700", /* same as ET0500 */
116 .pixclock = KHZ2PICOS(33264),
128 .pixclock = KHZ2PICOS(6596040 / 1000),
139 static int lcdif_modedb_sz = ARRAY_SIZE(lcdif_modedb);
141 static int lcdif_init(struct mxc_dispdrv_handle *disp,
142 struct mxc_dispdrv_setting *setting)
145 struct mxc_lcdif_data *lcdif = mxc_dispdrv_getdata(disp);
146 struct mxc_lcd_platform_data *plat_data = lcdif->dev->platform_data;
147 struct fb_videomode *modedb = lcdif_modedb;
148 int modedb_sz = lcdif_modedb_sz;
150 /* use platform defined ipu/di */
151 setting->dev_id = plat_data->ipu_id;
152 setting->disp_id = plat_data->disp_id;
154 ret = fb_find_mode(&setting->fbi->var, setting->fbi, setting->dft_mode_str,
155 modedb, modedb_sz, NULL, setting->default_bpp);
157 fb_videomode_to_var(&setting->fbi->var, &modedb[0]);
158 setting->if_fmt = plat_data->default_ifmt;
161 INIT_LIST_HEAD(&setting->fbi->modelist);
162 for (i = 0; i < modedb_sz; i++) {
163 struct fb_videomode m;
164 fb_var_to_videomode(&m, &setting->fbi->var);
165 if (fb_mode_is_equal(&m, &modedb[i])) {
166 fb_add_videomode(&modedb[i],
167 &setting->fbi->modelist);
175 void lcdif_deinit(struct mxc_dispdrv_handle *disp)
180 static struct mxc_dispdrv_driver lcdif_drv = {
183 .deinit = lcdif_deinit,
186 static int lcd_get_of_property(struct device *dev,
187 struct mxc_lcd_platform_data *plat_data)
189 struct device_node *np = dev->of_node;
192 const char *default_ifmt;
194 err = of_property_read_string(np, "default_ifmt", &default_ifmt);
196 dev_err(dev, "get of property default_ifmt fail\n");
199 err = of_property_read_u32(np, "ipu_id", &ipu_id);
201 dev_err(dev, "get of property ipu_id fail\n");
204 err = of_property_read_u32(np, "disp_id", &disp_id);
206 dev_err(dev, "get of property disp_id fail\n");
210 plat_data->ipu_id = ipu_id;
211 plat_data->disp_id = disp_id;
212 if (!strncmp(default_ifmt, "RGB24", 5))
213 plat_data->default_ifmt = IPU_PIX_FMT_RGB24;
214 else if (!strncmp(default_ifmt, "BGR24", 5))
215 plat_data->default_ifmt = IPU_PIX_FMT_BGR24;
216 else if (!strncmp(default_ifmt, "GBR24", 5))
217 plat_data->default_ifmt = IPU_PIX_FMT_GBR24;
218 else if (!strncmp(default_ifmt, "RGB565", 6))
219 plat_data->default_ifmt = IPU_PIX_FMT_RGB565;
220 else if (!strncmp(default_ifmt, "RGB666", 6))
221 plat_data->default_ifmt = IPU_PIX_FMT_RGB666;
222 else if (!strncmp(default_ifmt, "YUV444", 6))
223 plat_data->default_ifmt = IPU_PIX_FMT_YUV444;
224 else if (!strncmp(default_ifmt, "LVDS666", 7))
225 plat_data->default_ifmt = IPU_PIX_FMT_LVDS666;
226 else if (!strncmp(default_ifmt, "YUYV16", 6))
227 plat_data->default_ifmt = IPU_PIX_FMT_YUYV;
228 else if (!strncmp(default_ifmt, "UYVY16", 6))
229 plat_data->default_ifmt = IPU_PIX_FMT_UYVY;
230 else if (!strncmp(default_ifmt, "YVYU16", 6))
231 plat_data->default_ifmt = IPU_PIX_FMT_YVYU;
232 else if (!strncmp(default_ifmt, "VYUY16", 6))
233 plat_data->default_ifmt = IPU_PIX_FMT_VYUY;
235 dev_err(dev, "err default_ifmt!\n");
242 static int mxc_lcdif_probe(struct platform_device *pdev)
245 struct pinctrl *pinctrl;
246 struct mxc_lcdif_data *lcdif;
247 struct mxc_lcd_platform_data *plat_data;
249 dev_dbg(&pdev->dev, "%s enter\n", __func__);
250 lcdif = devm_kzalloc(&pdev->dev, sizeof(struct mxc_lcdif_data),
254 plat_data = devm_kzalloc(&pdev->dev,
255 sizeof(struct mxc_lcd_platform_data),
259 pdev->dev.platform_data = plat_data;
261 ret = lcd_get_of_property(&pdev->dev, plat_data);
263 dev_err(&pdev->dev, "get lcd of property fail\n");
267 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
268 if (IS_ERR(pinctrl)) {
269 dev_err(&pdev->dev, "can't get/select pinctrl\n");
270 return PTR_ERR(pinctrl);
273 lcdif->dev = &pdev->dev;
274 lcdif->disp_lcdif = mxc_dispdrv_register(&lcdif_drv);
275 mxc_dispdrv_setdata(lcdif->disp_lcdif, lcdif);
277 dev_set_drvdata(&pdev->dev, lcdif);
278 dev_dbg(&pdev->dev, "%s exit\n", __func__);
283 static int mxc_lcdif_remove(struct platform_device *pdev)
285 struct mxc_lcdif_data *lcdif = platform_get_drvdata(pdev);
287 mxc_dispdrv_puthandle(lcdif->disp_lcdif);
288 mxc_dispdrv_unregister(lcdif->disp_lcdif);
293 static const struct of_device_id imx_lcd_dt_ids[] = {
294 { .compatible = "fsl,lcd"},
297 static struct platform_driver mxc_lcdif_driver = {
300 .of_match_table = imx_lcd_dt_ids,
302 .probe = mxc_lcdif_probe,
303 .remove = mxc_lcdif_remove,
306 static int __init mxc_lcdif_init(void)
308 return platform_driver_register(&mxc_lcdif_driver);
311 static void __exit mxc_lcdif_exit(void)
313 platform_driver_unregister(&mxc_lcdif_driver);
316 module_init(mxc_lcdif_init);
317 module_exit(mxc_lcdif_exit);
319 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
320 MODULE_DESCRIPTION("i.MX ipuv3 LCD extern port driver");
321 MODULE_LICENSE("GPL");