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