]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/video/mxc/mxc_lcdif.c
7235f922aa2254a9d25ce47f42782a15260f9bdd
[karo-tx-linux.git] / drivers / video / mxc / mxc_lcdif.c
1 /*
2  * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved.
3  */
4
5 /*
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:
9  *
10  * http://www.opensource.org/licenses/gpl-license.html
11  * http://www.gnu.org/copyleft/gpl.html
12  */
13
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
23 #include "mxc_dispdrv.h"
24
25 struct mxc_lcd_platform_data {
26         u32 default_ifmt;
27         u32 ipu_id;
28         u32 disp_id;
29 };
30
31 struct mxc_lcdif_data {
32         struct platform_device *pdev;
33         struct mxc_dispdrv_handle *disp_lcdif;
34 };
35
36 #define DISPDRV_LCD     "lcd"
37
38 static struct fb_videomode lcdif_modedb[] = {
39         {
40         /* 800x480 @ 57 Hz , pixel clk @ 27MHz */
41         "CLAA-WVGA", 57, 800, 480, 37037, 40, 60, 10, 10, 20, 10,
42         FB_SYNC_CLK_LAT_FALL,
43         FB_VMODE_NONINTERLACED,
44         0,},
45         {
46         /* 800x480 @ 60 Hz , pixel clk @ 32MHz */
47         "SEIKO-WVGA", 60, 800, 480, 29850, 89, 164, 23, 10, 10, 10,
48         FB_SYNC_CLK_LAT_FALL,
49         FB_VMODE_NONINTERLACED,
50         0,},
51 };
52 static int lcdif_modedb_sz = ARRAY_SIZE(lcdif_modedb);
53
54 static int lcdif_init(struct mxc_dispdrv_handle *disp,
55         struct mxc_dispdrv_setting *setting)
56 {
57         int ret, i;
58         struct mxc_lcdif_data *lcdif = mxc_dispdrv_getdata(disp);
59         struct mxc_lcd_platform_data *plat_data
60                         = lcdif->pdev->dev.platform_data;
61         struct fb_videomode *modedb = lcdif_modedb;
62         int modedb_sz = lcdif_modedb_sz;
63
64         /* use platform defined ipu/di */
65         setting->dev_id = plat_data->ipu_id;
66         setting->disp_id = plat_data->disp_id;
67
68         ret = fb_find_mode(&setting->fbi->var, setting->fbi, setting->dft_mode_str,
69                                 modedb, modedb_sz, NULL, setting->default_bpp);
70         if (!ret) {
71                 fb_videomode_to_var(&setting->fbi->var, &modedb[0]);
72                 setting->if_fmt = plat_data->default_ifmt;
73         }
74
75         INIT_LIST_HEAD(&setting->fbi->modelist);
76         for (i = 0; i < modedb_sz; i++) {
77                 struct fb_videomode m;
78                 fb_var_to_videomode(&m, &setting->fbi->var);
79                 if (fb_mode_is_equal(&m, &modedb[i])) {
80                         fb_add_videomode(&modedb[i],
81                                         &setting->fbi->modelist);
82                         break;
83                 }
84         }
85
86         return ret;
87 }
88
89 void lcdif_deinit(struct mxc_dispdrv_handle *disp)
90 {
91         /*TODO*/
92 }
93
94 static struct mxc_dispdrv_driver lcdif_drv = {
95         .name   = DISPDRV_LCD,
96         .init   = lcdif_init,
97         .deinit = lcdif_deinit,
98 };
99
100 static int lcd_get_of_property(struct platform_device *pdev,
101                                 struct mxc_lcd_platform_data *plat_data)
102 {
103         struct device_node *np = pdev->dev.of_node;
104         int err;
105         u32 ipu_id, disp_id;
106         const char *default_ifmt;
107
108         err = of_property_read_string(np, "default_ifmt", &default_ifmt);
109         if (err) {
110                 dev_err(&pdev->dev, "get of property default_ifmt fail\n");
111                 return err;
112         }
113         err = of_property_read_u32(np, "ipu_id", &ipu_id);
114         if (err) {
115                 dev_err(&pdev->dev, "get of property ipu_id fail\n");
116                 return err;
117         }
118         err = of_property_read_u32(np, "disp_id", &disp_id);
119         if (err) {
120                 dev_err(&pdev->dev, "get of property disp_id fail\n");
121                 return err;
122         }
123
124         plat_data->ipu_id = ipu_id;
125         plat_data->disp_id = disp_id;
126         if (!strncmp(default_ifmt, "RGB24", 5))
127                 plat_data->default_ifmt = IPU_PIX_FMT_RGB24;
128         else if (!strncmp(default_ifmt, "BGR24", 5))
129                 plat_data->default_ifmt = IPU_PIX_FMT_BGR24;
130         else if (!strncmp(default_ifmt, "GBR24", 5))
131                 plat_data->default_ifmt = IPU_PIX_FMT_GBR24;
132         else if (!strncmp(default_ifmt, "RGB565", 6))
133                 plat_data->default_ifmt = IPU_PIX_FMT_RGB565;
134         else if (!strncmp(default_ifmt, "RGB666", 6))
135                 plat_data->default_ifmt = IPU_PIX_FMT_RGB666;
136         else if (!strncmp(default_ifmt, "YUV444", 6))
137                 plat_data->default_ifmt = IPU_PIX_FMT_YUV444;
138         else if (!strncmp(default_ifmt, "LVDS666", 7))
139                 plat_data->default_ifmt = IPU_PIX_FMT_LVDS666;
140         else if (!strncmp(default_ifmt, "YUYV16", 6))
141                 plat_data->default_ifmt = IPU_PIX_FMT_YUYV;
142         else if (!strncmp(default_ifmt, "UYVY16", 6))
143                 plat_data->default_ifmt = IPU_PIX_FMT_UYVY;
144         else if (!strncmp(default_ifmt, "YVYU16", 6))
145                 plat_data->default_ifmt = IPU_PIX_FMT_YVYU;
146         else if (!strncmp(default_ifmt, "VYUY16", 6))
147                                 plat_data->default_ifmt = IPU_PIX_FMT_VYUY;
148         else {
149                 dev_err(&pdev->dev, "err default_ifmt!\n");
150                 return -ENOENT;
151         }
152
153         return err;
154 }
155
156 static int mxc_lcdif_probe(struct platform_device *pdev)
157 {
158         int ret;
159         struct pinctrl *pinctrl;
160         struct mxc_lcdif_data *lcdif;
161         struct mxc_lcd_platform_data *plat_data;
162
163         dev_dbg(&pdev->dev, "%s enter\n", __func__);
164         lcdif = devm_kzalloc(&pdev->dev, sizeof(struct mxc_lcdif_data),
165                                 GFP_KERNEL);
166         if (!lcdif)
167                 return -ENOMEM;
168         plat_data = devm_kzalloc(&pdev->dev,
169                                 sizeof(struct mxc_lcd_platform_data),
170                                 GFP_KERNEL);
171         if (!plat_data)
172                 return -ENOMEM;
173         pdev->dev.platform_data = plat_data;
174
175         ret = lcd_get_of_property(pdev, plat_data);
176         if (ret < 0) {
177                 dev_err(&pdev->dev, "get lcd of property fail\n");
178                 return ret;
179         }
180
181         pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
182         if (IS_ERR(pinctrl)) {
183                 dev_err(&pdev->dev, "can't get/select pinctrl\n");
184                 return PTR_ERR(pinctrl);
185         }
186
187         lcdif->pdev = pdev;
188         lcdif->disp_lcdif = mxc_dispdrv_register(&lcdif_drv);
189         mxc_dispdrv_setdata(lcdif->disp_lcdif, lcdif);
190
191         dev_set_drvdata(&pdev->dev, lcdif);
192         dev_dbg(&pdev->dev, "%s exit\n", __func__);
193
194         return ret;
195 }
196
197 static int mxc_lcdif_remove(struct platform_device *pdev)
198 {
199         struct mxc_lcdif_data *lcdif = dev_get_drvdata(&pdev->dev);
200
201         mxc_dispdrv_puthandle(lcdif->disp_lcdif);
202         mxc_dispdrv_unregister(lcdif->disp_lcdif);
203         kfree(lcdif);
204         return 0;
205 }
206
207 static const struct of_device_id imx_lcd_dt_ids[] = {
208         { .compatible = "fsl,lcd"},
209         { /* sentinel */ }
210 };
211 static struct platform_driver mxc_lcdif_driver = {
212         .driver = {
213                 .name = "mxc_lcdif",
214                 .of_match_table = imx_lcd_dt_ids,
215         },
216         .probe = mxc_lcdif_probe,
217         .remove = mxc_lcdif_remove,
218 };
219
220 static int __init mxc_lcdif_init(void)
221 {
222         return platform_driver_register(&mxc_lcdif_driver);
223 }
224
225 static void __exit mxc_lcdif_exit(void)
226 {
227         platform_driver_unregister(&mxc_lcdif_driver);
228 }
229
230 module_init(mxc_lcdif_init);
231 module_exit(mxc_lcdif_exit);
232
233 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
234 MODULE_DESCRIPTION("i.MX ipuv3 LCD extern port driver");
235 MODULE_LICENSE("GPL");