blob: 77dea015ff69a7524261296ea91ed33975b338a9 [file] [log] [blame]
Andrei Konovalov147394c2007-05-08 00:40:18 -07001/*
John Linndac4ccf2009-06-06 10:43:16 -06002 * Xilinx TFT frame buffer driver
Andrei Konovalov147394c2007-05-08 00:40:18 -07003 *
4 * Author: MontaVista Software, Inc.
5 * source@mvista.com
6 *
Grant Likely31e8d462007-10-04 10:48:37 -06007 * 2002-2007 (c) MontaVista Software, Inc.
8 * 2007 (c) Secret Lab Technologies, Ltd.
John Linndac4ccf2009-06-06 10:43:16 -06009 * 2009 (c) Xilinx Inc.
Grant Likely31e8d462007-10-04 10:48:37 -060010 *
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of any
13 * kind, whether express or implied.
Andrei Konovalov147394c2007-05-08 00:40:18 -070014 */
15
16/*
17 * This driver was based on au1100fb.c by MontaVista rewritten for 2.6
18 * by Embedded Alley Solutions <source@embeddedalley.com>, which in turn
19 * was based on skeletonfb.c, Skeleton for a frame buffer device by
20 * Geert Uytterhoeven.
21 */
22
Grant Likely3cb3ec22007-10-04 10:48:36 -060023#include <linux/device.h>
Andrei Konovalov147394c2007-05-08 00:40:18 -070024#include <linux/module.h>
25#include <linux/kernel.h>
John Linndac4ccf2009-06-06 10:43:16 -060026#include <linux/version.h>
Andrei Konovalov147394c2007-05-08 00:40:18 -070027#include <linux/errno.h>
28#include <linux/string.h>
29#include <linux/mm.h>
30#include <linux/fb.h>
31#include <linux/init.h>
32#include <linux/dma-mapping.h>
Grant Likely31e8d462007-10-04 10:48:37 -060033#include <linux/of_device.h>
34#include <linux/of_platform.h>
Michal Simeka1dfe9c2010-10-07 17:39:03 +100035#include <linux/of_address.h>
John Linndac4ccf2009-06-06 10:43:16 -060036#include <linux/io.h>
Grant Likelydc8afdc2007-10-01 07:47:00 +100037#include <linux/xilinxfb.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Michal Simeka1dfe9c2010-10-07 17:39:03 +100039
40#ifdef CONFIG_PPC_DCR
John Linndac4ccf2009-06-06 10:43:16 -060041#include <asm/dcr.h>
Michal Simeka1dfe9c2010-10-07 17:39:03 +100042#endif
Andrei Konovalov147394c2007-05-08 00:40:18 -070043
44#define DRIVER_NAME "xilinxfb"
John Linndac4ccf2009-06-06 10:43:16 -060045
Andrei Konovalov147394c2007-05-08 00:40:18 -070046
47/*
48 * Xilinx calls it "PLB TFT LCD Controller" though it can also be used for
John Linndac4ccf2009-06-06 10:43:16 -060049 * the VGA port on the Xilinx ML40x board. This is a hardware display
50 * controller for a 640x480 resolution TFT or VGA screen.
Andrei Konovalov147394c2007-05-08 00:40:18 -070051 *
52 * The interface to the framebuffer is nice and simple. There are two
53 * control registers. The first tells the LCD interface where in memory
54 * the frame buffer is (only the 11 most significant bits are used, so
55 * don't start thinking about scrolling). The second allows the LCD to
56 * be turned on or off as well as rotated 180 degrees.
John Linndac4ccf2009-06-06 10:43:16 -060057 *
58 * In case of direct PLB access the second control register will be at
59 * an offset of 4 as compared to the DCR access where the offset is 1
60 * i.e. REG_CTRL. So this is taken care in the function
61 * xilinx_fb_out_be32 where it left shifts the offset 2 times in case of
62 * direct PLB access.
Andrei Konovalov147394c2007-05-08 00:40:18 -070063 */
64#define NUM_REGS 2
65#define REG_FB_ADDR 0
66#define REG_CTRL 1
67#define REG_CTRL_ENABLE 0x0001
68#define REG_CTRL_ROTATE 0x0002
69
70/*
71 * The hardware only handles a single mode: 640x480 24 bit true
72 * color. Each pixel gets a word (32 bits) of memory. Within each word,
73 * the 8 most significant bits are ignored, the next 8 bits are the red
74 * level, the next 8 bits are the green level and the 8 least
75 * significant bits are the blue level. Each row of the LCD uses 1024
76 * words, but only the first 640 pixels are displayed with the other 384
77 * words being ignored. There are 480 rows.
78 */
79#define BYTES_PER_PIXEL 4
80#define BITS_PER_PIXEL (BYTES_PER_PIXEL * 8)
Andrei Konovalov147394c2007-05-08 00:40:18 -070081
82#define RED_SHIFT 16
83#define GREEN_SHIFT 8
84#define BLUE_SHIFT 0
85
86#define PALETTE_ENTRIES_NO 16 /* passed to fb_alloc_cmap() */
87
88/*
Grant Likely01ba1e92007-10-11 04:31:46 +100089 * Default xilinxfb configuration
90 */
91static struct xilinxfb_platform_data xilinx_fb_default_pdata = {
Grant Likelyb4d6a722007-10-11 04:31:51 +100092 .xres = 640,
93 .yres = 480,
94 .xvirt = 1024,
Grant Likely86a22492007-10-13 22:13:32 -060095 .yvirt = 480,
Grant Likely01ba1e92007-10-11 04:31:46 +100096};
97
98/*
Andrei Konovalov147394c2007-05-08 00:40:18 -070099 * Here are the default fb_fix_screeninfo and fb_var_screeninfo structures
100 */
Grant Likely3f5b85d2007-07-31 00:37:38 -0700101static struct fb_fix_screeninfo xilinx_fb_fix = {
Andrei Konovalov147394c2007-05-08 00:40:18 -0700102 .id = "Xilinx",
103 .type = FB_TYPE_PACKED_PIXELS,
104 .visual = FB_VISUAL_TRUECOLOR,
Andrei Konovalov147394c2007-05-08 00:40:18 -0700105 .accel = FB_ACCEL_NONE
106};
107
Grant Likely3f5b85d2007-07-31 00:37:38 -0700108static struct fb_var_screeninfo xilinx_fb_var = {
Andrei Konovalov147394c2007-05-08 00:40:18 -0700109 .bits_per_pixel = BITS_PER_PIXEL,
110
111 .red = { RED_SHIFT, 8, 0 },
112 .green = { GREEN_SHIFT, 8, 0 },
113 .blue = { BLUE_SHIFT, 8, 0 },
114 .transp = { 0, 0, 0 },
115
116 .activate = FB_ACTIVATE_NOW
117};
118
John Linndac4ccf2009-06-06 10:43:16 -0600119
120#define PLB_ACCESS_FLAG 0x1 /* 1 = PLB, 0 = DCR */
121
Andrei Konovalov147394c2007-05-08 00:40:18 -0700122struct xilinxfb_drvdata {
123
124 struct fb_info info; /* FB driver info record */
125
John Linndac4ccf2009-06-06 10:43:16 -0600126 phys_addr_t regs_phys; /* phys. address of the control
127 registers */
128 void __iomem *regs; /* virt. address of the control
129 registers */
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000130#ifdef CONFIG_PPC_DCR
John Linndac4ccf2009-06-06 10:43:16 -0600131 dcr_host_t dcr_host;
John Linndac4ccf2009-06-06 10:43:16 -0600132 unsigned int dcr_len;
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000133#endif
Grant Likelyb9a22792007-10-04 10:48:37 -0600134 void *fb_virt; /* virt. address of the frame buffer */
Andrei Konovalov147394c2007-05-08 00:40:18 -0700135 dma_addr_t fb_phys; /* phys. address of the frame buffer */
Grant Likely287e5d62007-10-11 04:31:56 +1000136 int fb_alloced; /* Flag, was the fb memory alloced? */
Andrei Konovalov147394c2007-05-08 00:40:18 -0700137
John Linndac4ccf2009-06-06 10:43:16 -0600138 u8 flags; /* features of the driver */
139
Andrei Konovalov147394c2007-05-08 00:40:18 -0700140 u32 reg_ctrl_default;
141
142 u32 pseudo_palette[PALETTE_ENTRIES_NO];
143 /* Fake palette of 16 colors */
144};
145
146#define to_xilinxfb_drvdata(_info) \
147 container_of(_info, struct xilinxfb_drvdata, info)
148
149/*
John Linndac4ccf2009-06-06 10:43:16 -0600150 * The XPS TFT Controller can be accessed through PLB or DCR interface.
151 * To perform the read/write on the registers we need to check on
152 * which bus its connected and call the appropriate write API.
Andrei Konovalov147394c2007-05-08 00:40:18 -0700153 */
John Linndac4ccf2009-06-06 10:43:16 -0600154static void xilinx_fb_out_be32(struct xilinxfb_drvdata *drvdata, u32 offset,
155 u32 val)
156{
157 if (drvdata->flags & PLB_ACCESS_FLAG)
158 out_be32(drvdata->regs + (offset << 2), val);
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000159#ifdef CONFIG_PPC_DCR
John Linndac4ccf2009-06-06 10:43:16 -0600160 else
161 dcr_write(drvdata->dcr_host, offset, val);
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000162#endif
John Linndac4ccf2009-06-06 10:43:16 -0600163}
Andrei Konovalov147394c2007-05-08 00:40:18 -0700164
165static int
166xilinx_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
167 unsigned transp, struct fb_info *fbi)
168{
169 u32 *palette = fbi->pseudo_palette;
170
171 if (regno >= PALETTE_ENTRIES_NO)
172 return -EINVAL;
173
174 if (fbi->var.grayscale) {
175 /* Convert color to grayscale.
176 * grayscale = 0.30*R + 0.59*G + 0.11*B */
177 red = green = blue =
178 (red * 77 + green * 151 + blue * 28 + 127) >> 8;
179 }
180
181 /* fbi->fix.visual is always FB_VISUAL_TRUECOLOR */
182
183 /* We only handle 8 bits of each color. */
184 red >>= 8;
185 green >>= 8;
186 blue >>= 8;
187 palette[regno] = (red << RED_SHIFT) | (green << GREEN_SHIFT) |
188 (blue << BLUE_SHIFT);
189
190 return 0;
191}
192
193static int
194xilinx_fb_blank(int blank_mode, struct fb_info *fbi)
195{
196 struct xilinxfb_drvdata *drvdata = to_xilinxfb_drvdata(fbi);
197
198 switch (blank_mode) {
199 case FB_BLANK_UNBLANK:
200 /* turn on panel */
201 xilinx_fb_out_be32(drvdata, REG_CTRL, drvdata->reg_ctrl_default);
202 break;
203
204 case FB_BLANK_NORMAL:
205 case FB_BLANK_VSYNC_SUSPEND:
206 case FB_BLANK_HSYNC_SUSPEND:
207 case FB_BLANK_POWERDOWN:
208 /* turn off panel */
209 xilinx_fb_out_be32(drvdata, REG_CTRL, 0);
210 default:
211 break;
212
213 }
214 return 0; /* success */
215}
216
217static struct fb_ops xilinxfb_ops =
218{
219 .owner = THIS_MODULE,
220 .fb_setcolreg = xilinx_fb_setcolreg,
221 .fb_blank = xilinx_fb_blank,
222 .fb_fillrect = cfb_fillrect,
223 .fb_copyarea = cfb_copyarea,
224 .fb_imageblit = cfb_imageblit,
225};
226
Grant Likely26477622007-10-04 10:48:37 -0600227/* ---------------------------------------------------------------------
228 * Bus independent setup/teardown
229 */
Andrei Konovalov147394c2007-05-08 00:40:18 -0700230
John Linndac4ccf2009-06-06 10:43:16 -0600231static int xilinxfb_assign(struct device *dev,
232 struct xilinxfb_drvdata *drvdata,
233 unsigned long physaddr,
Grant Likely01ba1e92007-10-11 04:31:46 +1000234 struct xilinxfb_platform_data *pdata)
Andrei Konovalov147394c2007-05-08 00:40:18 -0700235{
Grant Likely26477622007-10-04 10:48:37 -0600236 int rc;
Grant Likelyb4d6a722007-10-11 04:31:51 +1000237 int fbsize = pdata->xvirt * pdata->yvirt * BYTES_PER_PIXEL;
Andrei Konovalov147394c2007-05-08 00:40:18 -0700238
John Linndac4ccf2009-06-06 10:43:16 -0600239 if (drvdata->flags & PLB_ACCESS_FLAG) {
240 /*
241 * Map the control registers in if the controller
242 * is on direct PLB interface.
243 */
244 if (!request_mem_region(physaddr, 8, DRIVER_NAME)) {
245 dev_err(dev, "Couldn't lock memory region at 0x%08lX\n",
246 physaddr);
247 rc = -ENODEV;
248 goto err_region;
249 }
Andrei Konovalov147394c2007-05-08 00:40:18 -0700250
John Linndac4ccf2009-06-06 10:43:16 -0600251 drvdata->regs_phys = physaddr;
252 drvdata->regs = ioremap(physaddr, 8);
253 if (!drvdata->regs) {
254 dev_err(dev, "Couldn't lock memory region at 0x%08lX\n",
255 physaddr);
256 rc = -ENODEV;
257 goto err_map;
258 }
Andrei Konovalov147394c2007-05-08 00:40:18 -0700259 }
Andrei Konovalov147394c2007-05-08 00:40:18 -0700260
261 /* Allocate the framebuffer memory */
Grant Likely287e5d62007-10-11 04:31:56 +1000262 if (pdata->fb_phys) {
263 drvdata->fb_phys = pdata->fb_phys;
264 drvdata->fb_virt = ioremap(pdata->fb_phys, fbsize);
265 } else {
266 drvdata->fb_alloced = 1;
267 drvdata->fb_virt = dma_alloc_coherent(dev, PAGE_ALIGN(fbsize),
268 &drvdata->fb_phys, GFP_KERNEL);
269 }
270
Andrei Konovalov147394c2007-05-08 00:40:18 -0700271 if (!drvdata->fb_virt) {
Grant Likely3cb3ec22007-10-04 10:48:36 -0600272 dev_err(dev, "Could not allocate frame buffer memory\n");
Grant Likely26477622007-10-04 10:48:37 -0600273 rc = -ENOMEM;
John Linndac4ccf2009-06-06 10:43:16 -0600274 if (drvdata->flags & PLB_ACCESS_FLAG)
275 goto err_fbmem;
276 else
277 goto err_region;
Andrei Konovalov147394c2007-05-08 00:40:18 -0700278 }
279
280 /* Clear (turn to black) the framebuffer */
Grant Likelyb4d6a722007-10-11 04:31:51 +1000281 memset_io((void __iomem *)drvdata->fb_virt, 0, fbsize);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700282
283 /* Tell the hardware where the frame buffer is */
284 xilinx_fb_out_be32(drvdata, REG_FB_ADDR, drvdata->fb_phys);
285
286 /* Turn on the display */
Grant Likelyf53161d2007-07-31 00:37:39 -0700287 drvdata->reg_ctrl_default = REG_CTRL_ENABLE;
Grant Likely01ba1e92007-10-11 04:31:46 +1000288 if (pdata->rotate_screen)
Grant Likelyf53161d2007-07-31 00:37:39 -0700289 drvdata->reg_ctrl_default |= REG_CTRL_ROTATE;
John Linndac4ccf2009-06-06 10:43:16 -0600290 xilinx_fb_out_be32(drvdata, REG_CTRL,
291 drvdata->reg_ctrl_default);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700292
293 /* Fill struct fb_info */
294 drvdata->info.device = dev;
Grant Likelyb9a22792007-10-04 10:48:37 -0600295 drvdata->info.screen_base = (void __iomem *)drvdata->fb_virt;
Andrei Konovalov147394c2007-05-08 00:40:18 -0700296 drvdata->info.fbops = &xilinxfb_ops;
297 drvdata->info.fix = xilinx_fb_fix;
298 drvdata->info.fix.smem_start = drvdata->fb_phys;
Grant Likelyb4d6a722007-10-11 04:31:51 +1000299 drvdata->info.fix.smem_len = fbsize;
300 drvdata->info.fix.line_length = pdata->xvirt * BYTES_PER_PIXEL;
301
Andrei Konovalov147394c2007-05-08 00:40:18 -0700302 drvdata->info.pseudo_palette = drvdata->pseudo_palette;
Grant Likely26477622007-10-04 10:48:37 -0600303 drvdata->info.flags = FBINFO_DEFAULT;
304 drvdata->info.var = xilinx_fb_var;
Grant Likelyb4d6a722007-10-11 04:31:51 +1000305 drvdata->info.var.height = pdata->screen_height_mm;
306 drvdata->info.var.width = pdata->screen_width_mm;
307 drvdata->info.var.xres = pdata->xres;
308 drvdata->info.var.yres = pdata->yres;
309 drvdata->info.var.xres_virtual = pdata->xvirt;
310 drvdata->info.var.yres_virtual = pdata->yvirt;
Grant Likely26477622007-10-04 10:48:37 -0600311
312 /* Allocate a colour map */
313 rc = fb_alloc_cmap(&drvdata->info.cmap, PALETTE_ENTRIES_NO, 0);
314 if (rc) {
Grant Likely3cb3ec22007-10-04 10:48:36 -0600315 dev_err(dev, "Fail to allocate colormap (%d entries)\n",
Andrei Konovalov147394c2007-05-08 00:40:18 -0700316 PALETTE_ENTRIES_NO);
Grant Likely3fb99ce2007-10-04 10:48:37 -0600317 goto err_cmap;
Andrei Konovalov147394c2007-05-08 00:40:18 -0700318 }
319
Andrei Konovalov147394c2007-05-08 00:40:18 -0700320 /* Register new frame buffer */
Grant Likely26477622007-10-04 10:48:37 -0600321 rc = register_framebuffer(&drvdata->info);
322 if (rc) {
Grant Likely3cb3ec22007-10-04 10:48:36 -0600323 dev_err(dev, "Could not register frame buffer\n");
Grant Likely3fb99ce2007-10-04 10:48:37 -0600324 goto err_regfb;
Andrei Konovalov147394c2007-05-08 00:40:18 -0700325 }
326
John Linndac4ccf2009-06-06 10:43:16 -0600327 if (drvdata->flags & PLB_ACCESS_FLAG) {
328 /* Put a banner in the log (for DEBUG) */
329 dev_dbg(dev, "regs: phys=%lx, virt=%p\n", physaddr,
330 drvdata->regs);
331 }
Grant Likely258de4b2007-10-04 10:48:36 -0600332 /* Put a banner in the log (for DEBUG) */
Grant Likelyaa296a82009-06-17 00:30:02 -0600333 dev_dbg(dev, "fb: phys=%llx, virt=%p, size=%x\n",
334 (unsigned long long)drvdata->fb_phys, drvdata->fb_virt, fbsize);
Grant Likelyb4d6a722007-10-11 04:31:51 +1000335
Andrei Konovalov147394c2007-05-08 00:40:18 -0700336 return 0; /* success */
337
Grant Likely3fb99ce2007-10-04 10:48:37 -0600338err_regfb:
Andrei Konovalov147394c2007-05-08 00:40:18 -0700339 fb_dealloc_cmap(&drvdata->info.cmap);
340
Grant Likely3fb99ce2007-10-04 10:48:37 -0600341err_cmap:
Grant Likely287e5d62007-10-11 04:31:56 +1000342 if (drvdata->fb_alloced)
343 dma_free_coherent(dev, PAGE_ALIGN(fbsize), drvdata->fb_virt,
344 drvdata->fb_phys);
John Linndac4ccf2009-06-06 10:43:16 -0600345 else
346 iounmap(drvdata->fb_virt);
347
Andrei Konovalov147394c2007-05-08 00:40:18 -0700348 /* Turn off the display */
349 xilinx_fb_out_be32(drvdata, REG_CTRL, 0);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700350
Grant Likely3fb99ce2007-10-04 10:48:37 -0600351err_fbmem:
John Linndac4ccf2009-06-06 10:43:16 -0600352 if (drvdata->flags & PLB_ACCESS_FLAG)
353 iounmap(drvdata->regs);
Grant Likely26477622007-10-04 10:48:37 -0600354
355err_map:
John Linndac4ccf2009-06-06 10:43:16 -0600356 if (drvdata->flags & PLB_ACCESS_FLAG)
357 release_mem_region(physaddr, 8);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700358
Grant Likely3fb99ce2007-10-04 10:48:37 -0600359err_region:
Andrei Konovalov147394c2007-05-08 00:40:18 -0700360 kfree(drvdata);
361 dev_set_drvdata(dev, NULL);
362
Grant Likely26477622007-10-04 10:48:37 -0600363 return rc;
Andrei Konovalov147394c2007-05-08 00:40:18 -0700364}
365
Grant Likely26477622007-10-04 10:48:37 -0600366static int xilinxfb_release(struct device *dev)
Andrei Konovalov147394c2007-05-08 00:40:18 -0700367{
Grant Likely26477622007-10-04 10:48:37 -0600368 struct xilinxfb_drvdata *drvdata = dev_get_drvdata(dev);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700369
370#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
371 xilinx_fb_blank(VESA_POWERDOWN, &drvdata->info);
372#endif
373
374 unregister_framebuffer(&drvdata->info);
375
376 fb_dealloc_cmap(&drvdata->info.cmap);
377
Grant Likely287e5d62007-10-11 04:31:56 +1000378 if (drvdata->fb_alloced)
379 dma_free_coherent(dev, PAGE_ALIGN(drvdata->info.fix.smem_len),
380 drvdata->fb_virt, drvdata->fb_phys);
John Linndac4ccf2009-06-06 10:43:16 -0600381 else
382 iounmap(drvdata->fb_virt);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700383
384 /* Turn off the display */
385 xilinx_fb_out_be32(drvdata, REG_CTRL, 0);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700386
John Linndac4ccf2009-06-06 10:43:16 -0600387 /* Release the resources, as allocated based on interface */
388 if (drvdata->flags & PLB_ACCESS_FLAG) {
389 iounmap(drvdata->regs);
390 release_mem_region(drvdata->regs_phys, 8);
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000391 }
392#ifdef CONFIG_PPC_DCR
393 else
John Linndac4ccf2009-06-06 10:43:16 -0600394 dcr_unmap(drvdata->dcr_host, drvdata->dcr_len);
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000395#endif
Andrei Konovalov147394c2007-05-08 00:40:18 -0700396
397 kfree(drvdata);
398 dev_set_drvdata(dev, NULL);
399
400 return 0;
401}
402
Grant Likely26477622007-10-04 10:48:37 -0600403/* ---------------------------------------------------------------------
Grant Likely31e8d462007-10-04 10:48:37 -0600404 * OF bus binding
405 */
406
Grant Likely28541d02011-02-22 21:07:43 -0700407static int __devinit xilinxfb_of_probe(struct platform_device *op)
Grant Likely31e8d462007-10-04 10:48:37 -0600408{
Grant Likely31e8d462007-10-04 10:48:37 -0600409 const u32 *prop;
John Linndac4ccf2009-06-06 10:43:16 -0600410 u32 *p;
411 u32 tft_access;
Grant Likely01ba1e92007-10-11 04:31:46 +1000412 struct xilinxfb_platform_data pdata;
John Linndac4ccf2009-06-06 10:43:16 -0600413 struct resource res;
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000414 int size, rc;
John Linndac4ccf2009-06-06 10:43:16 -0600415 struct xilinxfb_drvdata *drvdata;
Grant Likely31e8d462007-10-04 10:48:37 -0600416
Grant Likely01ba1e92007-10-11 04:31:46 +1000417 /* Copy with the default pdata (not a ptr reference!) */
418 pdata = xilinx_fb_default_pdata;
419
Grant Likelyaa296a82009-06-17 00:30:02 -0600420 /* Allocate the driver data region */
421 drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
422 if (!drvdata) {
423 dev_err(&op->dev, "Couldn't allocate device private record\n");
424 return -ENOMEM;
425 }
426
John Linndac4ccf2009-06-06 10:43:16 -0600427 /*
428 * To check whether the core is connected directly to DCR or PLB
429 * interface and initialize the tft_access accordingly.
430 */
Grant Likely61c7a082010-04-13 16:12:29 -0700431 p = (u32 *)of_get_property(op->dev.of_node, "xlnx,dcr-splb-slave-if", NULL);
Grant Likelyaa296a82009-06-17 00:30:02 -0600432 tft_access = p ? *p : 0;
John Linndac4ccf2009-06-06 10:43:16 -0600433
434 /*
435 * Fill the resource structure if its direct PLB interface
436 * otherwise fill the dcr_host structure.
437 */
438 if (tft_access) {
Grant Likelyaa296a82009-06-17 00:30:02 -0600439 drvdata->flags |= PLB_ACCESS_FLAG;
Grant Likely61c7a082010-04-13 16:12:29 -0700440 rc = of_address_to_resource(op->dev.of_node, 0, &res);
John Linndac4ccf2009-06-06 10:43:16 -0600441 if (rc) {
442 dev_err(&op->dev, "invalid address\n");
Grant Likelyaa296a82009-06-17 00:30:02 -0600443 goto err;
John Linndac4ccf2009-06-06 10:43:16 -0600444 }
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000445 }
446#ifdef CONFIG_PPC_DCR
447 else {
448 int start;
Grant Likelyaa296a82009-06-17 00:30:02 -0600449 res.start = 0;
Grant Likely61c7a082010-04-13 16:12:29 -0700450 start = dcr_resource_start(op->dev.of_node, 0);
451 drvdata->dcr_len = dcr_resource_len(op->dev.of_node, 0);
452 drvdata->dcr_host = dcr_map(op->dev.of_node, start, drvdata->dcr_len);
Grant Likelyaa296a82009-06-17 00:30:02 -0600453 if (!DCR_MAP_OK(drvdata->dcr_host)) {
454 dev_err(&op->dev, "invalid DCR address\n");
455 goto err;
John Linndac4ccf2009-06-06 10:43:16 -0600456 }
Grant Likely31e8d462007-10-04 10:48:37 -0600457 }
Michal Simeka1dfe9c2010-10-07 17:39:03 +1000458#endif
Grant Likely31e8d462007-10-04 10:48:37 -0600459
Grant Likely61c7a082010-04-13 16:12:29 -0700460 prop = of_get_property(op->dev.of_node, "phys-size", &size);
Grant Likely31e8d462007-10-04 10:48:37 -0600461 if ((prop) && (size >= sizeof(u32)*2)) {
Grant Likely01ba1e92007-10-11 04:31:46 +1000462 pdata.screen_width_mm = prop[0];
463 pdata.screen_height_mm = prop[1];
Grant Likely31e8d462007-10-04 10:48:37 -0600464 }
465
Grant Likely61c7a082010-04-13 16:12:29 -0700466 prop = of_get_property(op->dev.of_node, "resolution", &size);
Grant Likelyb4d6a722007-10-11 04:31:51 +1000467 if ((prop) && (size >= sizeof(u32)*2)) {
468 pdata.xres = prop[0];
469 pdata.yres = prop[1];
470 }
471
Grant Likely61c7a082010-04-13 16:12:29 -0700472 prop = of_get_property(op->dev.of_node, "virtual-resolution", &size);
Grant Likelyb4d6a722007-10-11 04:31:51 +1000473 if ((prop) && (size >= sizeof(u32)*2)) {
474 pdata.xvirt = prop[0];
475 pdata.yvirt = prop[1];
476 }
477
Grant Likely61c7a082010-04-13 16:12:29 -0700478 if (of_find_property(op->dev.of_node, "rotate-display", NULL))
Grant Likely01ba1e92007-10-11 04:31:46 +1000479 pdata.rotate_screen = 1;
Grant Likely31e8d462007-10-04 10:48:37 -0600480
John Linndac4ccf2009-06-06 10:43:16 -0600481 dev_set_drvdata(&op->dev, drvdata);
Grant Likelyaa296a82009-06-17 00:30:02 -0600482 return xilinxfb_assign(&op->dev, drvdata, res.start, &pdata);
John Linndac4ccf2009-06-06 10:43:16 -0600483
Grant Likelyaa296a82009-06-17 00:30:02 -0600484 err:
485 kfree(drvdata);
486 return -ENODEV;
Grant Likely31e8d462007-10-04 10:48:37 -0600487}
488
Grant Likely2dc11582010-08-06 09:25:50 -0600489static int __devexit xilinxfb_of_remove(struct platform_device *op)
Grant Likely31e8d462007-10-04 10:48:37 -0600490{
491 return xilinxfb_release(&op->dev);
492}
493
494/* Match table for of_platform binding */
Grant Likely911a3172008-02-06 10:23:12 -0700495static struct of_device_id xilinxfb_of_match[] __devinitdata = {
John Linndac4ccf2009-06-06 10:43:16 -0600496 { .compatible = "xlnx,xps-tft-1.00.a", },
Adrian Alonso652078b2010-07-27 11:24:13 +0000497 { .compatible = "xlnx,xps-tft-2.00.a", },
498 { .compatible = "xlnx,xps-tft-2.01.a", },
Stephen Neuendorffer0e349b02008-01-09 06:35:05 +1100499 { .compatible = "xlnx,plb-tft-cntlr-ref-1.00.a", },
John Linndac4ccf2009-06-06 10:43:16 -0600500 { .compatible = "xlnx,plb-dvi-cntlr-ref-1.00.c", },
Grant Likely31e8d462007-10-04 10:48:37 -0600501 {},
502};
503MODULE_DEVICE_TABLE(of, xilinxfb_of_match);
504
Grant Likely28541d02011-02-22 21:07:43 -0700505static struct platform_driver xilinxfb_of_driver = {
Grant Likely31e8d462007-10-04 10:48:37 -0600506 .probe = xilinxfb_of_probe,
507 .remove = __devexit_p(xilinxfb_of_remove),
508 .driver = {
509 .name = DRIVER_NAME,
Grant Likely40182942010-04-13 16:13:02 -0700510 .owner = THIS_MODULE,
511 .of_match_table = xilinxfb_of_match,
Grant Likely31e8d462007-10-04 10:48:37 -0600512 },
513};
514
Grant Likely31e8d462007-10-04 10:48:37 -0600515
516/* ---------------------------------------------------------------------
517 * Module setup and teardown
518 */
519
Andrei Konovalov147394c2007-05-08 00:40:18 -0700520static int __init
521xilinxfb_init(void)
522{
Grant Likely28541d02011-02-22 21:07:43 -0700523 return platform_driver_register(&xilinxfb_of_driver);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700524}
525
526static void __exit
527xilinxfb_cleanup(void)
528{
Grant Likely28541d02011-02-22 21:07:43 -0700529 platform_driver_unregister(&xilinxfb_of_driver);
Andrei Konovalov147394c2007-05-08 00:40:18 -0700530}
531
532module_init(xilinxfb_init);
533module_exit(xilinxfb_cleanup);
534
535MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
John Linndac4ccf2009-06-06 10:43:16 -0600536MODULE_DESCRIPTION("Xilinx TFT frame buffer driver");
Andrei Konovalov147394c2007-05-08 00:40:18 -0700537MODULE_LICENSE("GPL");