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) |
| 73 | #define XRES 640 |
| 74 | #define YRES 480 |
| 75 | #define XRES_VIRTUAL 1024 |
| 76 | #define YRES_VIRTUAL YRES |
| 77 | #define LINE_LENGTH (XRES_VIRTUAL * BYTES_PER_PIXEL) |
| 78 | #define FB_SIZE (YRES_VIRTUAL * LINE_LENGTH) |
| 79 | |
| 80 | #define RED_SHIFT 16 |
| 81 | #define GREEN_SHIFT 8 |
| 82 | #define BLUE_SHIFT 0 |
| 83 | |
| 84 | #define PALETTE_ENTRIES_NO 16 /* passed to fb_alloc_cmap() */ |
| 85 | |
| 86 | /* |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 87 | * Default xilinxfb configuration |
| 88 | */ |
| 89 | static struct xilinxfb_platform_data xilinx_fb_default_pdata = { |
| 90 | }; |
| 91 | |
| 92 | /* |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 93 | * Here are the default fb_fix_screeninfo and fb_var_screeninfo structures |
| 94 | */ |
Grant Likely | 3f5b85d | 2007-07-31 00:37:38 -0700 | [diff] [blame] | 95 | static struct fb_fix_screeninfo xilinx_fb_fix = { |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 96 | .id = "Xilinx", |
| 97 | .type = FB_TYPE_PACKED_PIXELS, |
| 98 | .visual = FB_VISUAL_TRUECOLOR, |
| 99 | .smem_len = FB_SIZE, |
| 100 | .line_length = LINE_LENGTH, |
| 101 | .accel = FB_ACCEL_NONE |
| 102 | }; |
| 103 | |
Grant Likely | 3f5b85d | 2007-07-31 00:37:38 -0700 | [diff] [blame] | 104 | static struct fb_var_screeninfo xilinx_fb_var = { |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 105 | .xres = XRES, |
| 106 | .yres = YRES, |
| 107 | .xres_virtual = XRES_VIRTUAL, |
| 108 | .yres_virtual = YRES_VIRTUAL, |
| 109 | |
| 110 | .bits_per_pixel = BITS_PER_PIXEL, |
| 111 | |
| 112 | .red = { RED_SHIFT, 8, 0 }, |
| 113 | .green = { GREEN_SHIFT, 8, 0 }, |
| 114 | .blue = { BLUE_SHIFT, 8, 0 }, |
| 115 | .transp = { 0, 0, 0 }, |
| 116 | |
| 117 | .activate = FB_ACTIVATE_NOW |
| 118 | }; |
| 119 | |
| 120 | struct xilinxfb_drvdata { |
| 121 | |
| 122 | struct fb_info info; /* FB driver info record */ |
| 123 | |
| 124 | u32 regs_phys; /* phys. address of the control registers */ |
| 125 | u32 __iomem *regs; /* virt. address of the control registers */ |
| 126 | |
Grant Likely | b9a2279 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 127 | void *fb_virt; /* virt. address of the frame buffer */ |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 128 | dma_addr_t fb_phys; /* phys. address of the frame buffer */ |
| 129 | |
| 130 | u32 reg_ctrl_default; |
| 131 | |
| 132 | u32 pseudo_palette[PALETTE_ENTRIES_NO]; |
| 133 | /* Fake palette of 16 colors */ |
| 134 | }; |
| 135 | |
| 136 | #define to_xilinxfb_drvdata(_info) \ |
| 137 | container_of(_info, struct xilinxfb_drvdata, info) |
| 138 | |
| 139 | /* |
| 140 | * The LCD controller has DCR interface to its registers, but all |
| 141 | * the boards and configurations the driver has been tested with |
| 142 | * use opb2dcr bridge. So the registers are seen as memory mapped. |
| 143 | * This macro is to make it simple to add the direct DCR access |
| 144 | * when it's needed. |
| 145 | */ |
| 146 | #define xilinx_fb_out_be32(driverdata, offset, val) \ |
| 147 | out_be32(driverdata->regs + offset, val) |
| 148 | |
| 149 | static int |
| 150 | xilinx_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, |
| 151 | unsigned transp, struct fb_info *fbi) |
| 152 | { |
| 153 | u32 *palette = fbi->pseudo_palette; |
| 154 | |
| 155 | if (regno >= PALETTE_ENTRIES_NO) |
| 156 | return -EINVAL; |
| 157 | |
| 158 | if (fbi->var.grayscale) { |
| 159 | /* Convert color to grayscale. |
| 160 | * grayscale = 0.30*R + 0.59*G + 0.11*B */ |
| 161 | red = green = blue = |
| 162 | (red * 77 + green * 151 + blue * 28 + 127) >> 8; |
| 163 | } |
| 164 | |
| 165 | /* fbi->fix.visual is always FB_VISUAL_TRUECOLOR */ |
| 166 | |
| 167 | /* We only handle 8 bits of each color. */ |
| 168 | red >>= 8; |
| 169 | green >>= 8; |
| 170 | blue >>= 8; |
| 171 | palette[regno] = (red << RED_SHIFT) | (green << GREEN_SHIFT) | |
| 172 | (blue << BLUE_SHIFT); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static int |
| 178 | xilinx_fb_blank(int blank_mode, struct fb_info *fbi) |
| 179 | { |
| 180 | struct xilinxfb_drvdata *drvdata = to_xilinxfb_drvdata(fbi); |
| 181 | |
| 182 | switch (blank_mode) { |
| 183 | case FB_BLANK_UNBLANK: |
| 184 | /* turn on panel */ |
| 185 | xilinx_fb_out_be32(drvdata, REG_CTRL, drvdata->reg_ctrl_default); |
| 186 | break; |
| 187 | |
| 188 | case FB_BLANK_NORMAL: |
| 189 | case FB_BLANK_VSYNC_SUSPEND: |
| 190 | case FB_BLANK_HSYNC_SUSPEND: |
| 191 | case FB_BLANK_POWERDOWN: |
| 192 | /* turn off panel */ |
| 193 | xilinx_fb_out_be32(drvdata, REG_CTRL, 0); |
| 194 | default: |
| 195 | break; |
| 196 | |
| 197 | } |
| 198 | return 0; /* success */ |
| 199 | } |
| 200 | |
| 201 | static struct fb_ops xilinxfb_ops = |
| 202 | { |
| 203 | .owner = THIS_MODULE, |
| 204 | .fb_setcolreg = xilinx_fb_setcolreg, |
| 205 | .fb_blank = xilinx_fb_blank, |
| 206 | .fb_fillrect = cfb_fillrect, |
| 207 | .fb_copyarea = cfb_copyarea, |
| 208 | .fb_imageblit = cfb_imageblit, |
| 209 | }; |
| 210 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 211 | /* --------------------------------------------------------------------- |
| 212 | * Bus independent setup/teardown |
| 213 | */ |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 214 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 215 | static int xilinxfb_assign(struct device *dev, unsigned long physaddr, |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 216 | struct xilinxfb_platform_data *pdata) |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 217 | { |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 218 | struct xilinxfb_drvdata *drvdata; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 219 | int rc; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 220 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 221 | /* Allocate the driver data region */ |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 222 | drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); |
| 223 | if (!drvdata) { |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 224 | dev_err(dev, "Couldn't allocate device private record\n"); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 225 | return -ENOMEM; |
| 226 | } |
| 227 | dev_set_drvdata(dev, drvdata); |
| 228 | |
| 229 | /* Map the control registers in */ |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 230 | if (!request_mem_region(physaddr, 8, DRIVER_NAME)) { |
| 231 | dev_err(dev, "Couldn't lock memory region at 0x%08lX\n", |
| 232 | physaddr); |
| 233 | rc = -ENODEV; |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 234 | goto err_region; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 235 | } |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 236 | drvdata->regs_phys = physaddr; |
| 237 | drvdata->regs = ioremap(physaddr, 8); |
| 238 | if (!drvdata->regs) { |
| 239 | dev_err(dev, "Couldn't lock memory region at 0x%08lX\n", |
| 240 | physaddr); |
| 241 | rc = -ENODEV; |
| 242 | goto err_map; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 243 | } |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 244 | |
| 245 | /* Allocate the framebuffer memory */ |
| 246 | drvdata->fb_virt = dma_alloc_coherent(dev, PAGE_ALIGN(FB_SIZE), |
| 247 | &drvdata->fb_phys, GFP_KERNEL); |
| 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 | b9a2279 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 255 | memset_io((void __iomem *)drvdata->fb_virt, 0, FB_SIZE); |
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; |
| 272 | drvdata->info.pseudo_palette = drvdata->pseudo_palette; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 273 | drvdata->info.flags = FBINFO_DEFAULT; |
| 274 | drvdata->info.var = xilinx_fb_var; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 275 | |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 276 | xilinx_fb_var.height = pdata->screen_height_mm; |
| 277 | xilinx_fb_var.width = pdata->screen_width_mm; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 278 | |
| 279 | /* Allocate a colour map */ |
| 280 | rc = fb_alloc_cmap(&drvdata->info.cmap, PALETTE_ENTRIES_NO, 0); |
| 281 | if (rc) { |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 282 | dev_err(dev, "Fail to allocate colormap (%d entries)\n", |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 283 | PALETTE_ENTRIES_NO); |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 284 | goto err_cmap; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 287 | /* Register new frame buffer */ |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 288 | rc = register_framebuffer(&drvdata->info); |
| 289 | if (rc) { |
Grant Likely | 3cb3ec2 | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 290 | dev_err(dev, "Could not register frame buffer\n"); |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 291 | goto err_regfb; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Grant Likely | 258de4b | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 294 | /* Put a banner in the log (for DEBUG) */ |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 295 | dev_dbg(dev, "regs: phys=%lx, virt=%p\n", physaddr, drvdata->regs); |
Grant Likely | 258de4b | 2007-10-04 10:48:36 -0600 | [diff] [blame] | 296 | dev_dbg(dev, "fb: phys=%p, virt=%p, size=%x\n", |
| 297 | (void*)drvdata->fb_phys, drvdata->fb_virt, FB_SIZE); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 298 | return 0; /* success */ |
| 299 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 300 | err_regfb: |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 301 | fb_dealloc_cmap(&drvdata->info.cmap); |
| 302 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 303 | err_cmap: |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 304 | dma_free_coherent(dev, PAGE_ALIGN(FB_SIZE), drvdata->fb_virt, |
| 305 | drvdata->fb_phys); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 306 | /* Turn off the display */ |
| 307 | xilinx_fb_out_be32(drvdata, REG_CTRL, 0); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 308 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 309 | err_fbmem: |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 310 | iounmap(drvdata->regs); |
| 311 | |
| 312 | err_map: |
| 313 | release_mem_region(physaddr, 8); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 314 | |
Grant Likely | 3fb99ce | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 315 | err_region: |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 316 | kfree(drvdata); |
| 317 | dev_set_drvdata(dev, NULL); |
| 318 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 319 | return rc; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 322 | static int xilinxfb_release(struct device *dev) |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 323 | { |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 324 | struct xilinxfb_drvdata *drvdata = dev_get_drvdata(dev); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 325 | |
| 326 | #if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO) |
| 327 | xilinx_fb_blank(VESA_POWERDOWN, &drvdata->info); |
| 328 | #endif |
| 329 | |
| 330 | unregister_framebuffer(&drvdata->info); |
| 331 | |
| 332 | fb_dealloc_cmap(&drvdata->info.cmap); |
| 333 | |
| 334 | dma_free_coherent(dev, PAGE_ALIGN(FB_SIZE), drvdata->fb_virt, |
| 335 | drvdata->fb_phys); |
| 336 | |
| 337 | /* Turn off the display */ |
| 338 | xilinx_fb_out_be32(drvdata, REG_CTRL, 0); |
| 339 | iounmap(drvdata->regs); |
| 340 | |
| 341 | release_mem_region(drvdata->regs_phys, 8); |
| 342 | |
| 343 | kfree(drvdata); |
| 344 | dev_set_drvdata(dev, NULL); |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 349 | /* --------------------------------------------------------------------- |
| 350 | * Platform bus binding |
| 351 | */ |
| 352 | |
| 353 | static int |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 354 | xilinxfb_platform_probe(struct platform_device *pdev) |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 355 | { |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 356 | struct xilinxfb_platform_data *pdata; |
| 357 | struct resource *res; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 358 | |
| 359 | /* Find the registers address */ |
| 360 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 361 | if (!res) { |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 362 | dev_err(&pdev->dev, "Couldn't get registers resource\n"); |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 363 | return -ENODEV; |
| 364 | } |
| 365 | |
Grant Likely | e3cec00 | 2007-10-04 15:44:52 -0600 | [diff] [blame] | 366 | /* If a pdata structure is provided, then extract the parameters */ |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 367 | if (pdev->dev.platform_data) |
| 368 | pdata = pdev->dev.platform_data; |
| 369 | else |
| 370 | pdata = &xilinx_fb_default_pdata; |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 371 | |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 372 | return xilinxfb_assign(&pdev->dev, res->start, pdata); |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static int |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 376 | xilinxfb_platform_remove(struct platform_device *pdev) |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 377 | { |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 378 | return xilinxfb_release(&pdev->dev); |
Grant Likely | 2647762 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 379 | } |
| 380 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 381 | |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 382 | static struct platform_driver xilinxfb_platform_driver = { |
| 383 | .probe = xilinxfb_platform_probe, |
| 384 | .remove = xilinxfb_platform_remove, |
| 385 | .driver = { |
| 386 | .owner = THIS_MODULE, |
| 387 | .name = DRIVER_NAME, |
| 388 | }, |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 389 | }; |
| 390 | |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 391 | /* --------------------------------------------------------------------- |
| 392 | * OF bus binding |
| 393 | */ |
| 394 | |
| 395 | #if defined(CONFIG_OF) |
| 396 | static int __devinit |
| 397 | xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match) |
| 398 | { |
| 399 | struct resource res; |
| 400 | const u32 *prop; |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 401 | struct xilinxfb_platform_data pdata; |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 402 | int size, rc; |
| 403 | |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 404 | /* Copy with the default pdata (not a ptr reference!) */ |
| 405 | pdata = xilinx_fb_default_pdata; |
| 406 | |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 407 | dev_dbg(&op->dev, "xilinxfb_of_probe(%p, %p)\n", op, match); |
| 408 | |
| 409 | rc = of_address_to_resource(op->node, 0, &res); |
| 410 | if (rc) { |
| 411 | dev_err(&op->dev, "invalid address\n"); |
| 412 | return rc; |
| 413 | } |
| 414 | |
| 415 | prop = of_get_property(op->node, "display-number", &size); |
| 416 | if ((prop) && (size >= sizeof(u32)*2)) { |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 417 | pdata.screen_width_mm = prop[0]; |
| 418 | pdata.screen_height_mm = prop[1]; |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | if (of_find_property(op->node, "rotate-display", NULL)) |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 422 | pdata.rotate_screen = 1; |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 423 | |
Grant Likely | 01ba1e9 | 2007-10-11 04:31:46 +1000 | [diff] [blame^] | 424 | return xilinxfb_assign(&op->dev, res.start, &pdata); |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | static int __devexit xilinxfb_of_remove(struct of_device *op) |
| 428 | { |
| 429 | return xilinxfb_release(&op->dev); |
| 430 | } |
| 431 | |
| 432 | /* Match table for of_platform binding */ |
| 433 | static struct of_device_id __devinit xilinxfb_of_match[] = { |
| 434 | { .compatible = "xilinx,ml300-fb", }, |
| 435 | {}, |
| 436 | }; |
| 437 | MODULE_DEVICE_TABLE(of, xilinxfb_of_match); |
| 438 | |
| 439 | static struct of_platform_driver xilinxfb_of_driver = { |
| 440 | .owner = THIS_MODULE, |
| 441 | .name = DRIVER_NAME, |
| 442 | .match_table = xilinxfb_of_match, |
| 443 | .probe = xilinxfb_of_probe, |
| 444 | .remove = __devexit_p(xilinxfb_of_remove), |
| 445 | .driver = { |
| 446 | .name = DRIVER_NAME, |
| 447 | }, |
| 448 | }; |
| 449 | |
| 450 | /* Registration helpers to keep the number of #ifdefs to a minimum */ |
| 451 | static inline int __init xilinxfb_of_register(void) |
| 452 | { |
| 453 | pr_debug("xilinxfb: calling of_register_platform_driver()\n"); |
| 454 | return of_register_platform_driver(&xilinxfb_of_driver); |
| 455 | } |
| 456 | |
| 457 | static inline void __exit xilinxfb_of_unregister(void) |
| 458 | { |
| 459 | of_unregister_platform_driver(&xilinxfb_of_driver); |
| 460 | } |
| 461 | #else /* CONFIG_OF */ |
| 462 | /* CONFIG_OF not enabled; do nothing helpers */ |
| 463 | static inline int __init xilinxfb_of_register(void) { return 0; } |
| 464 | static inline void __exit xilinxfb_of_unregister(void) { } |
| 465 | #endif /* CONFIG_OF */ |
| 466 | |
| 467 | /* --------------------------------------------------------------------- |
| 468 | * Module setup and teardown |
| 469 | */ |
| 470 | |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 471 | static int __init |
| 472 | xilinxfb_init(void) |
| 473 | { |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 474 | int rc; |
| 475 | rc = xilinxfb_of_register(); |
| 476 | if (rc) |
| 477 | return rc; |
| 478 | |
| 479 | rc = platform_driver_register(&xilinxfb_platform_driver); |
| 480 | if (rc) |
| 481 | xilinxfb_of_unregister(); |
| 482 | |
| 483 | return rc; |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static void __exit |
| 487 | xilinxfb_cleanup(void) |
| 488 | { |
Grant Likely | 47473e3 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 489 | platform_driver_unregister(&xilinxfb_platform_driver); |
Grant Likely | 31e8d46 | 2007-10-04 10:48:37 -0600 | [diff] [blame] | 490 | xilinxfb_of_unregister(); |
Andrei Konovalov | 147394c | 2007-05-08 00:40:18 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | module_init(xilinxfb_init); |
| 494 | module_exit(xilinxfb_cleanup); |
| 495 | |
| 496 | MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>"); |
| 497 | MODULE_DESCRIPTION(DRIVER_DESCRIPTION); |
| 498 | MODULE_LICENSE("GPL"); |