Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * xilinxfb.c |
| 3 | * |
| 4 | * Xilinx TFT LCD frame buffer driver |
| 5 | * |
| 6 | * Author: MontaVista Software, Inc. |
| 7 | * source@mvista.com |
| 8 | * |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 9 | * 2002-2007 (c) MontaVista Software, Inc. |
| 10 | * 2007 (c) Secret Lab Technologies, Ltd. |
| 11 | * |
| 12 | * This file is licensed under the terms of the GNU General Public License |
| 13 | * version 2. This program is licensed "as is" without any warranty of any |
| 14 | * kind, whether express or implied. |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * This driver was based on au1100fb.c by MontaVista rewritten for 2.6 |
| 19 | * by Embedded Alley Solutions <source@embeddedalley.com>, which in turn |
| 20 | * was based on skeletonfb.c, Skeleton for a frame buffer device by |
| 21 | * Geert Uytterhoeven. |
| 22 | */ |
| 23 | |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 24 | #include <linux/device.h> |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/version.h> |
| 28 | #include <linux/errno.h> |
| 29 | #include <linux/string.h> |
| 30 | #include <linux/mm.h> |
| 31 | #include <linux/fb.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/dma-mapping.h> |
| 34 | #include <linux/platform_device.h> |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 35 | #if defined(CONFIG_OF) |
| 36 | #include <linux/of_device.h> |
| 37 | #include <linux/of_platform.h> |
| 38 | #endif |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 39 | #include <asm/io.h> |
Grant Likely | dc8afdc | 2007-10-01 07:47:00 +1000 | [diff] [blame] | 40 | #include <linux/xilinxfb.h> |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 41 | |
| 42 | #define DRIVER_NAME "xilinxfb" |
| 43 | #define DRIVER_DESCRIPTION "Xilinx TFT LCD frame buffer driver" |
| 44 | |
| 45 | /* |
| 46 | * Xilinx calls it "PLB TFT LCD Controller" though it can also be used for |
| 47 | * the VGA port on the Xilinx ML40x board. This is a hardware display controller |
| 48 | * for a 640x480 resolution TFT or VGA screen. |
| 49 | * |
| 50 | * The interface to the framebuffer is nice and simple. There are two |
| 51 | * control registers. The first tells the LCD interface where in memory |
| 52 | * the frame buffer is (only the 11 most significant bits are used, so |
| 53 | * don't start thinking about scrolling). The second allows the LCD to |
| 54 | * be turned on or off as well as rotated 180 degrees. |
| 55 | */ |
| 56 | #define NUM_REGS 2 |
| 57 | #define REG_FB_ADDR 0 |
| 58 | #define REG_CTRL 1 |
| 59 | #define REG_CTRL_ENABLE 0x0001 |
| 60 | #define REG_CTRL_ROTATE 0x0002 |
| 61 | |
| 62 | /* |
| 63 | * The hardware only handles a single mode: 640x480 24 bit true |
| 64 | * color. Each pixel gets a word (32 bits) of memory. Within each word, |
| 65 | * the 8 most significant bits are ignored, the next 8 bits are the red |
| 66 | * level, the next 8 bits are the green level and the 8 least |
| 67 | * significant bits are the blue level. Each row of the LCD uses 1024 |
| 68 | * words, but only the first 640 pixels are displayed with the other 384 |
| 69 | * words being ignored. There are 480 rows. |
| 70 | */ |
| 71 | #define BYTES_PER_PIXEL 4 |
| 72 | #define BITS_PER_PIXEL (BYTES_PER_PIXEL * 8) |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 73 | |
| 74 | #define RED_SHIFT 16 |
| 75 | #define GREEN_SHIFT 8 |
| 76 | #define BLUE_SHIFT 0 |
| 77 | |
| 78 | #define PALETTE_ENTRIES_NO 16 /* passed to fb_alloc_cmap() */ |
| 79 | |
| 80 | /* |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 81 | * Default xilinxfb configuration |
| 82 | */ |
| 83 | static struct xilinxfb_platform_data xilinx_fb_default_pdata = { |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 84 | .xres = 640, |
| 85 | .yres = 480, |
| 86 | .xvirt = 1024, |
Grant Likely | 86a2249 | 2007-10-13 22:13:32 -0600 | [diff] [blame] | 87 | .yvirt = 480, |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | /* |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 91 | * Here are the default fb_fix_screeninfo and fb_var_screeninfo structures |
| 92 | */ |
Grant Likely | 3f5b85d | 2007-07-31 00:37:38 -0700 | [diff] [blame] | 93 | static struct fb_fix_screeninfo xilinx_fb_fix = { |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 94 | .id = "Xilinx", |
| 95 | .type = FB_TYPE_PACKED_PIXELS, |
| 96 | .visual = FB_VISUAL_TRUECOLOR, |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 97 | .accel = FB_ACCEL_NONE |
| 98 | }; |
| 99 | |
Grant Likely | 3f5b85d | 2007-07-31 00:37:38 -0700 | [diff] [blame] | 100 | static struct fb_var_screeninfo xilinx_fb_var = { |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 101 | .bits_per_pixel = BITS_PER_PIXEL, |
| 102 | |
| 103 | .red = { RED_SHIFT, 8, 0 }, |
| 104 | .green = { GREEN_SHIFT, 8, 0 }, |
| 105 | .blue = { BLUE_SHIFT, 8, 0 }, |
| 106 | .transp = { 0, 0, 0 }, |
| 107 | |
| 108 | .activate = FB_ACTIVATE_NOW |
| 109 | }; |
| 110 | |
| 111 | struct xilinxfb_drvdata { |
| 112 | |
| 113 | struct fb_info info; /* FB driver info record */ |
| 114 | |
| 115 | u32 regs_phys; /* phys. address of the control registers */ |
| 116 | u32 __iomem *regs; /* virt. address of the control registers */ |
| 117 | |
Grant Likely | b9a2279 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 118 | void *fb_virt; /* virt. address of the frame buffer */ |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 119 | dma_addr_t fb_phys; /* phys. address of the frame buffer */ |
Grant Likely | 287e5d6 | 2007-10-11 04:31:56 +1000 | [diff] [blame] | 120 | int fb_alloced; /* Flag, was the fb memory alloced? */ |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 121 | |
| 122 | u32 reg_ctrl_default; |
| 123 | |
| 124 | u32 pseudo_palette[PALETTE_ENTRIES_NO]; |
| 125 | /* Fake palette of 16 colors */ |
| 126 | }; |
| 127 | |
| 128 | #define to_xilinxfb_drvdata(_info) \ |
| 129 | container_of(_info, struct xilinxfb_drvdata, info) |
| 130 | |
| 131 | /* |
| 132 | * The LCD controller has DCR interface to its registers, but all |
| 133 | * the boards and configurations the driver has been tested with |
| 134 | * use opb2dcr bridge. So the registers are seen as memory mapped. |
| 135 | * This macro is to make it simple to add the direct DCR access |
| 136 | * when it's needed. |
| 137 | */ |
| 138 | #define xilinx_fb_out_be32(driverdata, offset, val) \ |
| 139 | out_be32(driverdata->regs + offset, val) |
| 140 | |
| 141 | static int |
| 142 | xilinx_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, |
| 143 | unsigned transp, struct fb_info *fbi) |
| 144 | { |
| 145 | u32 *palette = fbi->pseudo_palette; |
| 146 | |
| 147 | if (regno >= PALETTE_ENTRIES_NO) |
| 148 | return -EINVAL; |
| 149 | |
| 150 | if (fbi->var.grayscale) { |
| 151 | /* Convert color to grayscale. |
| 152 | * grayscale = 0.30*R + 0.59*G + 0.11*B */ |
| 153 | red = green = blue = |
| 154 | (red * 77 + green * 151 + blue * 28 + 127) >> 8; |
| 155 | } |
| 156 | |
| 157 | /* fbi->fix.visual is always FB_VISUAL_TRUECOLOR */ |
| 158 | |
| 159 | /* We only handle 8 bits of each color. */ |
| 160 | red >>= 8; |
| 161 | green >>= 8; |
| 162 | blue >>= 8; |
| 163 | palette[regno] = (red << RED_SHIFT) | (green << GREEN_SHIFT) | |
| 164 | (blue << BLUE_SHIFT); |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int |
| 170 | xilinx_fb_blank(int blank_mode, struct fb_info *fbi) |
| 171 | { |
| 172 | struct xilinxfb_drvdata *drvdata = to_xilinxfb_drvdata(fbi); |
| 173 | |
| 174 | switch (blank_mode) { |
| 175 | case FB_BLANK_UNBLANK: |
| 176 | /* turn on panel */ |
| 177 | xilinx_fb_out_be32(drvdata, REG_CTRL, drvdata->reg_ctrl_default); |
| 178 | break; |
| 179 | |
| 180 | case FB_BLANK_NORMAL: |
| 181 | case FB_BLANK_VSYNC_SUSPEND: |
| 182 | case FB_BLANK_HSYNC_SUSPEND: |
| 183 | case FB_BLANK_POWERDOWN: |
| 184 | /* turn off panel */ |
| 185 | xilinx_fb_out_be32(drvdata, REG_CTRL, 0); |
| 186 | default: |
| 187 | break; |
| 188 | |
| 189 | } |
| 190 | return 0; /* success */ |
| 191 | } |
| 192 | |
| 193 | static struct fb_ops xilinxfb_ops = |
| 194 | { |
| 195 | .owner = THIS_MODULE, |
| 196 | .fb_setcolreg = xilinx_fb_setcolreg, |
| 197 | .fb_blank = xilinx_fb_blank, |
| 198 | .fb_fillrect = cfb_fillrect, |
| 199 | .fb_copyarea = cfb_copyarea, |
| 200 | .fb_imageblit = cfb_imageblit, |
| 201 | }; |
| 202 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 203 | /* --------------------------------------------------------------------- |
| 204 | * Bus independent setup/teardown |
| 205 | */ |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 206 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 207 | static int xilinxfb_assign(struct device *dev, unsigned long physaddr, |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 208 | struct xilinxfb_platform_data *pdata) |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 209 | { |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 210 | struct xilinxfb_drvdata *drvdata; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 211 | int rc; |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 212 | int fbsize = pdata->xvirt * pdata->yvirt * BYTES_PER_PIXEL; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 213 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 214 | /* Allocate the driver data region */ |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 215 | drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); |
| 216 | if (!drvdata) { |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 217 | dev_err(dev, "Couldn't allocate device private record\n"); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 218 | return -ENOMEM; |
| 219 | } |
| 220 | dev_set_drvdata(dev, drvdata); |
| 221 | |
| 222 | /* Map the control registers in */ |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 223 | if (!request_mem_region(physaddr, 8, DRIVER_NAME)) { |
| 224 | dev_err(dev, "Couldn't lock memory region at 0x%08lX\n", |
| 225 | physaddr); |
| 226 | rc = -ENODEV; |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 227 | goto err_region; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 228 | } |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 229 | drvdata->regs_phys = physaddr; |
| 230 | drvdata->regs = ioremap(physaddr, 8); |
| 231 | if (!drvdata->regs) { |
| 232 | dev_err(dev, "Couldn't lock memory region at 0x%08lX\n", |
| 233 | physaddr); |
| 234 | rc = -ENODEV; |
| 235 | goto err_map; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 236 | } |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 237 | |
| 238 | /* Allocate the framebuffer memory */ |
Grant Likely | 287e5d6 | 2007-10-11 04:31:56 +1000 | [diff] [blame] | 239 | if (pdata->fb_phys) { |
| 240 | drvdata->fb_phys = pdata->fb_phys; |
| 241 | drvdata->fb_virt = ioremap(pdata->fb_phys, fbsize); |
| 242 | } else { |
| 243 | drvdata->fb_alloced = 1; |
| 244 | drvdata->fb_virt = dma_alloc_coherent(dev, PAGE_ALIGN(fbsize), |
| 245 | &drvdata->fb_phys, GFP_KERNEL); |
| 246 | } |
| 247 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 248 | if (!drvdata->fb_virt) { |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 249 | dev_err(dev, "Could not allocate frame buffer memory\n"); |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 250 | rc = -ENOMEM; |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 251 | goto err_fbmem; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | /* Clear (turn to black) the framebuffer */ |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 255 | memset_io((void __iomem *)drvdata->fb_virt, 0, fbsize); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 256 | |
| 257 | /* Tell the hardware where the frame buffer is */ |
| 258 | xilinx_fb_out_be32(drvdata, REG_FB_ADDR, drvdata->fb_phys); |
| 259 | |
| 260 | /* Turn on the display */ |
Grant Likely | f53161d | 2007-07-31 00:37:39 -0700 | [diff] [blame] | 261 | drvdata->reg_ctrl_default = REG_CTRL_ENABLE; |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 262 | if (pdata->rotate_screen) |
Grant Likely | f53161d | 2007-07-31 00:37:39 -0700 | [diff] [blame] | 263 | drvdata->reg_ctrl_default |= REG_CTRL_ROTATE; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 264 | xilinx_fb_out_be32(drvdata, REG_CTRL, drvdata->reg_ctrl_default); |
| 265 | |
| 266 | /* Fill struct fb_info */ |
| 267 | drvdata->info.device = dev; |
Grant Likely | b9a2279 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 268 | drvdata->info.screen_base = (void __iomem *)drvdata->fb_virt; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 269 | drvdata->info.fbops = &xilinxfb_ops; |
| 270 | drvdata->info.fix = xilinx_fb_fix; |
| 271 | drvdata->info.fix.smem_start = drvdata->fb_phys; |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 272 | drvdata->info.fix.smem_len = fbsize; |
| 273 | drvdata->info.fix.line_length = pdata->xvirt * BYTES_PER_PIXEL; |
| 274 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 275 | drvdata->info.pseudo_palette = drvdata->pseudo_palette; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 276 | drvdata->info.flags = FBINFO_DEFAULT; |
| 277 | drvdata->info.var = xilinx_fb_var; |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 278 | drvdata->info.var.height = pdata->screen_height_mm; |
| 279 | drvdata->info.var.width = pdata->screen_width_mm; |
| 280 | drvdata->info.var.xres = pdata->xres; |
| 281 | drvdata->info.var.yres = pdata->yres; |
| 282 | drvdata->info.var.xres_virtual = pdata->xvirt; |
| 283 | drvdata->info.var.yres_virtual = pdata->yvirt; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 284 | |
| 285 | /* Allocate a colour map */ |
| 286 | rc = fb_alloc_cmap(&drvdata->info.cmap, PALETTE_ENTRIES_NO, 0); |
| 287 | if (rc) { |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 288 | dev_err(dev, "Fail to allocate colormap (%d entries)\n", |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 289 | PALETTE_ENTRIES_NO); |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 290 | goto err_cmap; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 293 | /* Register new frame buffer */ |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 294 | rc = register_framebuffer(&drvdata->info); |
| 295 | if (rc) { |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 296 | dev_err(dev, "Could not register frame buffer\n"); |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 297 | goto err_regfb; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Grant Likely | 258de4b | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 300 | /* Put a banner in the log (for DEBUG) */ |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 301 | dev_dbg(dev, "regs: phys=%lx, virt=%p\n", physaddr, drvdata->regs); |
Grant Likely | 258de4b | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 302 | dev_dbg(dev, "fb: phys=%p, virt=%p, size=%x\n", |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 303 | (void*)drvdata->fb_phys, drvdata->fb_virt, fbsize); |
| 304 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 305 | return 0; /* success */ |
| 306 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 307 | err_regfb: |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 308 | fb_dealloc_cmap(&drvdata->info.cmap); |
| 309 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 310 | err_cmap: |
Grant Likely | 287e5d6 | 2007-10-11 04:31:56 +1000 | [diff] [blame] | 311 | if (drvdata->fb_alloced) |
| 312 | dma_free_coherent(dev, PAGE_ALIGN(fbsize), drvdata->fb_virt, |
| 313 | drvdata->fb_phys); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 314 | /* Turn off the display */ |
| 315 | xilinx_fb_out_be32(drvdata, REG_CTRL, 0); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 316 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 317 | err_fbmem: |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 318 | iounmap(drvdata->regs); |
| 319 | |
| 320 | err_map: |
| 321 | release_mem_region(physaddr, 8); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 322 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 323 | err_region: |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 324 | kfree(drvdata); |
| 325 | dev_set_drvdata(dev, NULL); |
| 326 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 327 | return rc; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 330 | static int xilinxfb_release(struct device *dev) |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 331 | { |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 332 | struct xilinxfb_drvdata *drvdata = dev_get_drvdata(dev); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 333 | |
| 334 | #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO) |
| 335 | xilinx_fb_blank(VESA_POWERDOWN, &drvdata->info); |
| 336 | #endif |
| 337 | |
| 338 | unregister_framebuffer(&drvdata->info); |
| 339 | |
| 340 | fb_dealloc_cmap(&drvdata->info.cmap); |
| 341 | |
Grant Likely | 287e5d6 | 2007-10-11 04:31:56 +1000 | [diff] [blame] | 342 | if (drvdata->fb_alloced) |
| 343 | dma_free_coherent(dev, PAGE_ALIGN(drvdata->info.fix.smem_len), |
| 344 | drvdata->fb_virt, drvdata->fb_phys); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 345 | |
| 346 | /* Turn off the display */ |
| 347 | xilinx_fb_out_be32(drvdata, REG_CTRL, 0); |
| 348 | iounmap(drvdata->regs); |
| 349 | |
| 350 | release_mem_region(drvdata->regs_phys, 8); |
| 351 | |
| 352 | kfree(drvdata); |
| 353 | dev_set_drvdata(dev, NULL); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 358 | /* --------------------------------------------------------------------- |
| 359 | * Platform bus binding |
| 360 | */ |
| 361 | |
| 362 | static int |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 363 | xilinxfb_platform_probe(struct platform_device *pdev) |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 364 | { |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 365 | struct xilinxfb_platform_data *pdata; |
| 366 | struct resource *res; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 367 | |
| 368 | /* Find the registers address */ |
| 369 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 370 | if (!res) { |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 371 | dev_err(&pdev->dev, "Couldn't get registers resource\n"); |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 372 | return -ENODEV; |
| 373 | } |
| 374 | |
Grant Likely | e3cec00 | 2007-10-04 15:44:52 -0600 | [diff] [blame] | 375 | /* If a pdata structure is provided, then extract the parameters */ |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 376 | pdata = &xilinx_fb_default_pdata; |
| 377 | if (pdev->dev.platform_data) { |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 378 | pdata = pdev->dev.platform_data; |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 379 | if (!pdata->xres) |
| 380 | pdata->xres = xilinx_fb_default_pdata.xres; |
| 381 | if (!pdata->yres) |
| 382 | pdata->yres = xilinx_fb_default_pdata.yres; |
| 383 | if (!pdata->xvirt) |
| 384 | pdata->xvirt = xilinx_fb_default_pdata.xvirt; |
| 385 | if (!pdata->yvirt) |
| 386 | pdata->yvirt = xilinx_fb_default_pdata.yvirt; |
| 387 | } |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 388 | |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 389 | return xilinxfb_assign(&pdev->dev, res->start, pdata); |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static int |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 393 | xilinxfb_platform_remove(struct platform_device *pdev) |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 394 | { |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 395 | return xilinxfb_release(&pdev->dev); |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 396 | } |
| 397 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 398 | |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 399 | static struct platform_driver xilinxfb_platform_driver = { |
| 400 | .probe = xilinxfb_platform_probe, |
| 401 | .remove = xilinxfb_platform_remove, |
| 402 | .driver = { |
| 403 | .owner = THIS_MODULE, |
| 404 | .name = DRIVER_NAME, |
| 405 | }, |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 406 | }; |
| 407 | |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 408 | /* --------------------------------------------------------------------- |
| 409 | * OF bus binding |
| 410 | */ |
| 411 | |
| 412 | #if defined(CONFIG_OF) |
| 413 | static int __devinit |
| 414 | xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match) |
| 415 | { |
| 416 | struct resource res; |
| 417 | const u32 *prop; |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 418 | struct xilinxfb_platform_data pdata; |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 419 | int size, rc; |
| 420 | |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 421 | /* Copy with the default pdata (not a ptr reference!) */ |
| 422 | pdata = xilinx_fb_default_pdata; |
| 423 | |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 424 | dev_dbg(&op->dev, "xilinxfb_of_probe(%p, %p)\n", op, match); |
| 425 | |
| 426 | rc = of_address_to_resource(op->node, 0, &res); |
| 427 | if (rc) { |
| 428 | dev_err(&op->dev, "invalid address\n"); |
| 429 | return rc; |
| 430 | } |
| 431 | |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 432 | prop = of_get_property(op->node, "phys-size", &size); |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 433 | if ((prop) && (size >= sizeof(u32)*2)) { |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 434 | pdata.screen_width_mm = prop[0]; |
| 435 | pdata.screen_height_mm = prop[1]; |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 436 | } |
| 437 | |
Grant Likely | b4d6a72 | 2007-10-11 04:31:51 +1000 | [diff] [blame] | 438 | prop = of_get_property(op->node, "resolution", &size); |
| 439 | if ((prop) && (size >= sizeof(u32)*2)) { |
| 440 | pdata.xres = prop[0]; |
| 441 | pdata.yres = prop[1]; |
| 442 | } |
| 443 | |
| 444 | prop = of_get_property(op->node, "virtual-resolution", &size); |
| 445 | if ((prop) && (size >= sizeof(u32)*2)) { |
| 446 | pdata.xvirt = prop[0]; |
| 447 | pdata.yvirt = prop[1]; |
| 448 | } |
| 449 | |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 450 | if (of_find_property(op->node, "rotate-display", NULL)) |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 451 | pdata.rotate_screen = 1; |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 452 | |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame] | 453 | return xilinxfb_assign(&op->dev, res.start, &pdata); |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static int __devexit xilinxfb_of_remove(struct of_device *op) |
| 457 | { |
| 458 | return xilinxfb_release(&op->dev); |
| 459 | } |
| 460 | |
| 461 | /* Match table for of_platform binding */ |
| 462 | static struct of_device_id __devinit xilinxfb_of_match[] = { |
| 463 | { .compatible = "xilinx,ml300-fb", }, |
| 464 | {}, |
| 465 | }; |
| 466 | MODULE_DEVICE_TABLE(of, xilinxfb_of_match); |
| 467 | |
| 468 | static struct of_platform_driver xilinxfb_of_driver = { |
| 469 | .owner = THIS_MODULE, |
| 470 | .name = DRIVER_NAME, |
| 471 | .match_table = xilinxfb_of_match, |
| 472 | .probe = xilinxfb_of_probe, |
| 473 | .remove = __devexit_p(xilinxfb_of_remove), |
| 474 | .driver = { |
| 475 | .name = DRIVER_NAME, |
| 476 | }, |
| 477 | }; |
| 478 | |
| 479 | /* Registration helpers to keep the number of #ifdefs to a minimum */ |
| 480 | static inline int __init xilinxfb_of_register(void) |
| 481 | { |
| 482 | pr_debug("xilinxfb: calling of_register_platform_driver()\n"); |
| 483 | return of_register_platform_driver(&xilinxfb_of_driver); |
| 484 | } |
| 485 | |
| 486 | static inline void __exit xilinxfb_of_unregister(void) |
| 487 | { |
| 488 | of_unregister_platform_driver(&xilinxfb_of_driver); |
| 489 | } |
| 490 | #else /* CONFIG_OF */ |
| 491 | /* CONFIG_OF not enabled; do nothing helpers */ |
| 492 | static inline int __init xilinxfb_of_register(void) { return 0; } |
| 493 | static inline void __exit xilinxfb_of_unregister(void) { } |
| 494 | #endif /* CONFIG_OF */ |
| 495 | |
| 496 | /* --------------------------------------------------------------------- |
| 497 | * Module setup and teardown |
| 498 | */ |
| 499 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 500 | static int __init |
| 501 | xilinxfb_init(void) |
| 502 | { |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 503 | int rc; |
| 504 | rc = xilinxfb_of_register(); |
| 505 | if (rc) |
| 506 | return rc; |
| 507 | |
| 508 | rc = platform_driver_register(&xilinxfb_platform_driver); |
| 509 | if (rc) |
| 510 | xilinxfb_of_unregister(); |
| 511 | |
| 512 | return rc; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static void __exit |
| 516 | xilinxfb_cleanup(void) |
| 517 | { |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 518 | platform_driver_unregister(&xilinxfb_platform_driver); |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 519 | xilinxfb_of_unregister(); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | module_init(xilinxfb_init); |
| 523 | module_exit(xilinxfb_cleanup); |
| 524 | |
| 525 | MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>"); |
| 526 | MODULE_DESCRIPTION(DRIVER_DESCRIPTION); |
| 527 | MODULE_LICENSE("GPL"); |