Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/video/arcfb.c -- FB driver for Arc monochrome LCD board |
| 3 | * |
| 4 | * Copyright (C) 2005, Jaya Kumar <jayalk@intworks.biz> |
| 5 | * http://www.intworks.biz/arclcd |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file COPYING in the main directory of this archive for |
| 9 | * more details. |
| 10 | * |
| 11 | * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven. |
| 12 | * |
| 13 | * This driver was written to be used with the Arc LCD board. Arc uses a |
| 14 | * set of KS108 chips that control individual 64x64 LCD matrices. The board |
| 15 | * can be paneled in a variety of setups such as 2x1=128x64, 4x4=256x256 and |
| 16 | * so on. The interface between the board and the host is TTL based GPIO. The |
| 17 | * GPIO requirements are 8 writable data lines and 4+n lines for control. On a |
| 18 | * GPIO-less system, the board can be tested by connecting the respective sigs |
| 19 | * up to a parallel port connector. The driver requires the IO addresses for |
| 20 | * data and control GPIO at load time. It is unable to probe for the |
| 21 | * existence of the LCD so it must be told at load time whether it should |
| 22 | * be enabled or not. |
| 23 | * |
| 24 | * Todo: |
| 25 | * - testing with 4x4 |
| 26 | * - testing with interrupt hw |
| 27 | * |
| 28 | * General notes: |
| 29 | * - User must set tuhold. It's in microseconds. According to the 108 spec, |
| 30 | * the hold time is supposed to be at least 1 microsecond. |
| 31 | * - User must set num_cols=x num_rows=y, eg: x=2 means 128 |
| 32 | * - User must set arcfb_enable=1 to enable it |
| 33 | * - User must set dio_addr=0xIOADDR cio_addr=0xIOADDR |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/kernel.h> |
| 39 | #include <linux/errno.h> |
| 40 | #include <linux/string.h> |
| 41 | #include <linux/mm.h> |
| 42 | #include <linux/tty.h> |
| 43 | #include <linux/slab.h> |
| 44 | #include <linux/vmalloc.h> |
| 45 | #include <linux/delay.h> |
| 46 | #include <linux/interrupt.h> |
| 47 | #include <linux/fb.h> |
| 48 | #include <linux/init.h> |
| 49 | #include <linux/arcfb.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 50 | #include <linux/platform_device.h> |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 51 | |
| 52 | #include <asm/uaccess.h> |
| 53 | |
| 54 | #define floor8(a) (a&(~0x07)) |
| 55 | #define floorXres(a,xres) (a&(~(xres - 1))) |
| 56 | #define iceil8(a) (((int)((a+7)/8))*8) |
| 57 | #define ceil64(a) (a|0x3F) |
| 58 | #define ceilXres(a,xres) (a|(xres - 1)) |
| 59 | |
| 60 | /* ks108 chipset specific defines and code */ |
| 61 | |
| 62 | #define KS_SET_DPY_START_LINE 0xC0 |
| 63 | #define KS_SET_PAGE_NUM 0xB8 |
| 64 | #define KS_SET_X 0x40 |
| 65 | #define KS_CEHI 0x01 |
| 66 | #define KS_CELO 0x00 |
| 67 | #define KS_SEL_CMD 0x08 |
| 68 | #define KS_SEL_DATA 0x00 |
| 69 | #define KS_DPY_ON 0x3F |
| 70 | #define KS_DPY_OFF 0x3E |
| 71 | #define KS_INTACK 0x40 |
| 72 | #define KS_CLRINT 0x02 |
| 73 | |
| 74 | struct arcfb_par { |
| 75 | unsigned long dio_addr; |
| 76 | unsigned long cio_addr; |
| 77 | unsigned long c2io_addr; |
| 78 | atomic_t ref_count; |
| 79 | unsigned char cslut[9]; |
| 80 | struct fb_info *info; |
| 81 | unsigned int irq; |
| 82 | spinlock_t lock; |
| 83 | }; |
| 84 | |
| 85 | static struct fb_fix_screeninfo arcfb_fix __initdata = { |
| 86 | .id = "arcfb", |
| 87 | .type = FB_TYPE_PACKED_PIXELS, |
| 88 | .visual = FB_VISUAL_MONO01, |
| 89 | .xpanstep = 0, |
| 90 | .ypanstep = 1, |
| 91 | .ywrapstep = 0, |
| 92 | .accel = FB_ACCEL_NONE, |
| 93 | }; |
| 94 | |
| 95 | static struct fb_var_screeninfo arcfb_var __initdata = { |
| 96 | .xres = 128, |
| 97 | .yres = 64, |
| 98 | .xres_virtual = 128, |
| 99 | .yres_virtual = 64, |
| 100 | .bits_per_pixel = 1, |
| 101 | .nonstd = 1, |
| 102 | }; |
| 103 | |
| 104 | static unsigned long num_cols; |
| 105 | static unsigned long num_rows; |
| 106 | static unsigned long dio_addr; |
| 107 | static unsigned long cio_addr; |
| 108 | static unsigned long c2io_addr; |
| 109 | static unsigned long splashval; |
| 110 | static unsigned long tuhold; |
| 111 | static unsigned int nosplash; |
| 112 | static unsigned int arcfb_enable; |
| 113 | static unsigned int irq; |
| 114 | |
| 115 | static DECLARE_WAIT_QUEUE_HEAD(arcfb_waitq); |
| 116 | |
| 117 | static void ks108_writeb_ctl(struct arcfb_par *par, |
| 118 | unsigned int chipindex, unsigned char value) |
| 119 | { |
| 120 | unsigned char chipselval = par->cslut[chipindex]; |
| 121 | |
| 122 | outb(chipselval|KS_CEHI|KS_SEL_CMD, par->cio_addr); |
| 123 | outb(value, par->dio_addr); |
| 124 | udelay(tuhold); |
| 125 | outb(chipselval|KS_CELO|KS_SEL_CMD, par->cio_addr); |
| 126 | } |
| 127 | |
| 128 | static void ks108_writeb_mainctl(struct arcfb_par *par, unsigned char value) |
| 129 | { |
| 130 | |
| 131 | outb(value, par->cio_addr); |
| 132 | udelay(tuhold); |
| 133 | } |
| 134 | |
| 135 | static unsigned char ks108_readb_ctl2(struct arcfb_par *par) |
| 136 | { |
| 137 | return inb(par->c2io_addr); |
| 138 | } |
| 139 | |
| 140 | static void ks108_writeb_data(struct arcfb_par *par, |
| 141 | unsigned int chipindex, unsigned char value) |
| 142 | { |
| 143 | unsigned char chipselval = par->cslut[chipindex]; |
| 144 | |
| 145 | outb(chipselval|KS_CEHI|KS_SEL_DATA, par->cio_addr); |
| 146 | outb(value, par->dio_addr); |
| 147 | udelay(tuhold); |
| 148 | outb(chipselval|KS_CELO|KS_SEL_DATA, par->cio_addr); |
| 149 | } |
| 150 | |
| 151 | static void ks108_set_start_line(struct arcfb_par *par, |
| 152 | unsigned int chipindex, unsigned char y) |
| 153 | { |
| 154 | ks108_writeb_ctl(par, chipindex, KS_SET_DPY_START_LINE|y); |
| 155 | } |
| 156 | |
| 157 | static void ks108_set_yaddr(struct arcfb_par *par, |
| 158 | unsigned int chipindex, unsigned char y) |
| 159 | { |
| 160 | ks108_writeb_ctl(par, chipindex, KS_SET_PAGE_NUM|y); |
| 161 | } |
| 162 | |
| 163 | static void ks108_set_xaddr(struct arcfb_par *par, |
| 164 | unsigned int chipindex, unsigned char x) |
| 165 | { |
| 166 | ks108_writeb_ctl(par, chipindex, KS_SET_X|x); |
| 167 | } |
| 168 | |
| 169 | static void ks108_clear_lcd(struct arcfb_par *par, unsigned int chipindex) |
| 170 | { |
| 171 | int i,j; |
| 172 | |
| 173 | for (i = 0; i <= 8; i++) { |
| 174 | ks108_set_yaddr(par, chipindex, i); |
| 175 | ks108_set_xaddr(par, chipindex, 0); |
| 176 | for (j = 0; j < 64; j++) { |
| 177 | ks108_writeb_data(par, chipindex, |
| 178 | (unsigned char) splashval); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /* main arcfb functions */ |
| 184 | |
| 185 | static int arcfb_open(struct fb_info *info, int user) |
| 186 | { |
| 187 | struct arcfb_par *par = info->par; |
| 188 | |
| 189 | atomic_inc(&par->ref_count); |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int arcfb_release(struct fb_info *info, int user) |
| 194 | { |
| 195 | struct arcfb_par *par = info->par; |
| 196 | int count = atomic_read(&par->ref_count); |
| 197 | |
| 198 | if (!count) |
| 199 | return -EINVAL; |
| 200 | atomic_dec(&par->ref_count); |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | static int arcfb_pan_display(struct fb_var_screeninfo *var, |
| 205 | struct fb_info *info) |
| 206 | { |
| 207 | int i; |
| 208 | struct arcfb_par *par = info->par; |
| 209 | |
| 210 | if ((var->vmode & FB_VMODE_YWRAP) && (var->yoffset < 64) |
| 211 | && (info->var.yres <= 64)) { |
| 212 | for (i = 0; i < num_cols; i++) { |
| 213 | ks108_set_start_line(par, i, var->yoffset); |
| 214 | } |
| 215 | info->var.yoffset = var->yoffset; |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | return -EINVAL; |
| 220 | } |
| 221 | |
| 222 | static irqreturn_t arcfb_interrupt(int vec, void *dev_instance, |
| 223 | struct pt_regs *regs) |
| 224 | { |
| 225 | struct fb_info *info = dev_instance; |
| 226 | unsigned char ctl2status; |
| 227 | struct arcfb_par *par = info->par; |
| 228 | |
| 229 | ctl2status = ks108_readb_ctl2(par); |
| 230 | |
| 231 | if (!(ctl2status & KS_INTACK)) /* not arc generated interrupt */ |
| 232 | return IRQ_NONE; |
| 233 | |
| 234 | ks108_writeb_mainctl(par, KS_CLRINT); |
| 235 | |
| 236 | spin_lock(&par->lock); |
| 237 | if (waitqueue_active(&arcfb_waitq)) { |
| 238 | wake_up(&arcfb_waitq); |
| 239 | } |
| 240 | spin_unlock(&par->lock); |
| 241 | |
| 242 | return IRQ_HANDLED; |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * here we handle a specific page on the lcd. the complexity comes from |
| 247 | * the fact that the fb is laidout in 8xX vertical columns. we extract |
| 248 | * each write of 8 vertical pixels. then we shift out as we move along |
| 249 | * X. That's what rightshift does. bitmask selects the desired input bit. |
| 250 | */ |
| 251 | static void arcfb_lcd_update_page(struct arcfb_par *par, unsigned int upper, |
| 252 | unsigned int left, unsigned int right, unsigned int distance) |
| 253 | { |
| 254 | unsigned char *src; |
| 255 | unsigned int xindex, yindex, chipindex, linesize; |
Antonino A. Daplas | 604cc99 | 2006-03-11 03:27:21 -0800 | [diff] [blame] | 256 | int i; |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 257 | unsigned char val; |
| 258 | unsigned char bitmask, rightshift; |
| 259 | |
| 260 | xindex = left >> 6; |
| 261 | yindex = upper >> 6; |
| 262 | chipindex = (xindex + (yindex*num_cols)); |
| 263 | |
| 264 | ks108_set_yaddr(par, chipindex, upper/8); |
| 265 | |
| 266 | linesize = par->info->var.xres/8; |
| 267 | src = par->info->screen_base + (left/8) + (upper * linesize); |
| 268 | ks108_set_xaddr(par, chipindex, left); |
| 269 | |
| 270 | bitmask=1; |
| 271 | rightshift=0; |
| 272 | while (left <= right) { |
| 273 | val = 0; |
| 274 | for (i = 0; i < 8; i++) { |
| 275 | if ( i > rightshift) { |
| 276 | val |= (*(src + (i*linesize)) & bitmask) |
| 277 | << (i - rightshift); |
| 278 | } else { |
| 279 | val |= (*(src + (i*linesize)) & bitmask) |
| 280 | >> (rightshift - i); |
| 281 | } |
| 282 | } |
| 283 | ks108_writeb_data(par, chipindex, val); |
| 284 | left++; |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 285 | if (bitmask == 0x80) { |
| 286 | bitmask = 1; |
| 287 | src++; |
| 288 | rightshift=0; |
| 289 | } else { |
| 290 | bitmask <<= 1; |
| 291 | rightshift++; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | * here we handle the entire vertical page of the update. we write across |
| 298 | * lcd chips. update_page uses the upper/left values to decide which |
| 299 | * chip to select for the right. upper is needed for setting the page |
| 300 | * desired for the write. |
| 301 | */ |
| 302 | static void arcfb_lcd_update_vert(struct arcfb_par *par, unsigned int top, |
| 303 | unsigned int bottom, unsigned int left, unsigned int right) |
| 304 | { |
| 305 | unsigned int distance, upper, lower; |
| 306 | |
| 307 | distance = (bottom - top) + 1; |
| 308 | upper = top; |
| 309 | lower = top + 7; |
| 310 | |
| 311 | while (distance > 0) { |
| 312 | distance -= 8; |
| 313 | arcfb_lcd_update_page(par, upper, left, right, 8); |
| 314 | upper = lower + 1; |
| 315 | lower = upper + 7; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * here we handle horizontal blocks for the update. update_vert will |
| 321 | * handle spaning multiple pages. we break out each horizontal |
| 322 | * block in to individual blocks no taller than 64 pixels. |
| 323 | */ |
| 324 | static void arcfb_lcd_update_horiz(struct arcfb_par *par, unsigned int left, |
| 325 | unsigned int right, unsigned int top, unsigned int h) |
| 326 | { |
| 327 | unsigned int distance, upper, lower; |
| 328 | |
| 329 | distance = h; |
| 330 | upper = floor8(top); |
| 331 | lower = min(upper + distance - 1, ceil64(upper)); |
| 332 | |
| 333 | while (distance > 0) { |
| 334 | distance -= ((lower - upper) + 1 ); |
| 335 | arcfb_lcd_update_vert(par, upper, lower, left, right); |
| 336 | upper = lower + 1; |
| 337 | lower = min(upper + distance - 1, ceil64(upper)); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | * here we start the process of spliting out the fb update into |
| 343 | * individual blocks of pixels. we end up spliting into 64x64 blocks |
| 344 | * and finally down to 64x8 pages. |
| 345 | */ |
| 346 | static void arcfb_lcd_update(struct arcfb_par *par, unsigned int dx, |
| 347 | unsigned int dy, unsigned int w, unsigned int h) |
| 348 | { |
| 349 | unsigned int left, right, distance, y; |
| 350 | |
| 351 | /* align the request first */ |
| 352 | y = floor8(dy); |
| 353 | h += dy - y; |
| 354 | h = iceil8(h); |
| 355 | |
| 356 | distance = w; |
| 357 | left = dx; |
| 358 | right = min(left + w - 1, ceil64(left)); |
| 359 | |
| 360 | while (distance > 0) { |
| 361 | arcfb_lcd_update_horiz(par, left, right, y, h); |
| 362 | distance -= ((right - left) + 1); |
| 363 | left = right + 1; |
| 364 | right = min(left + distance - 1, ceil64(left)); |
| 365 | } |
| 366 | } |
| 367 | |
Adrian Bunk | a0aa7d0 | 2006-01-09 20:54:04 -0800 | [diff] [blame] | 368 | static void arcfb_fillrect(struct fb_info *info, |
| 369 | const struct fb_fillrect *rect) |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 370 | { |
| 371 | struct arcfb_par *par = info->par; |
| 372 | |
| 373 | cfb_fillrect(info, rect); |
| 374 | |
| 375 | /* update the physical lcd */ |
| 376 | arcfb_lcd_update(par, rect->dx, rect->dy, rect->width, rect->height); |
| 377 | } |
| 378 | |
Adrian Bunk | a0aa7d0 | 2006-01-09 20:54:04 -0800 | [diff] [blame] | 379 | static void arcfb_copyarea(struct fb_info *info, |
| 380 | const struct fb_copyarea *area) |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 381 | { |
| 382 | struct arcfb_par *par = info->par; |
| 383 | |
| 384 | cfb_copyarea(info, area); |
| 385 | |
| 386 | /* update the physical lcd */ |
| 387 | arcfb_lcd_update(par, area->dx, area->dy, area->width, area->height); |
| 388 | } |
| 389 | |
Adrian Bunk | a0aa7d0 | 2006-01-09 20:54:04 -0800 | [diff] [blame] | 390 | static void arcfb_imageblit(struct fb_info *info, const struct fb_image *image) |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 391 | { |
| 392 | struct arcfb_par *par = info->par; |
| 393 | |
| 394 | cfb_imageblit(info, image); |
| 395 | |
| 396 | /* update the physical lcd */ |
| 397 | arcfb_lcd_update(par, image->dx, image->dy, image->width, |
| 398 | image->height); |
| 399 | } |
| 400 | |
Christoph Hellwig | 67a6680 | 2006-01-14 13:21:25 -0800 | [diff] [blame] | 401 | static int arcfb_ioctl(struct fb_info *info, |
| 402 | unsigned int cmd, unsigned long arg) |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 403 | { |
| 404 | void __user *argp = (void __user *)arg; |
| 405 | struct arcfb_par *par = info->par; |
| 406 | unsigned long flags; |
| 407 | |
| 408 | switch (cmd) { |
| 409 | case FBIO_WAITEVENT: |
| 410 | { |
| 411 | DEFINE_WAIT(wait); |
| 412 | /* illegal to wait on arc if no irq will occur */ |
| 413 | if (!par->irq) |
| 414 | return -EINVAL; |
| 415 | |
| 416 | /* wait until the Arc has generated an interrupt |
| 417 | * which will wake us up */ |
| 418 | spin_lock_irqsave(&par->lock, flags); |
| 419 | prepare_to_wait(&arcfb_waitq, &wait, |
| 420 | TASK_INTERRUPTIBLE); |
| 421 | spin_unlock_irqrestore(&par->lock, flags); |
| 422 | schedule(); |
| 423 | finish_wait(&arcfb_waitq, &wait); |
| 424 | } |
| 425 | case FBIO_GETCONTROL2: |
| 426 | { |
| 427 | unsigned char ctl2; |
| 428 | |
| 429 | ctl2 = ks108_readb_ctl2(info->par); |
| 430 | if (copy_to_user(argp, &ctl2, sizeof(ctl2))) |
| 431 | return -EFAULT; |
| 432 | return 0; |
| 433 | } |
| 434 | default: |
| 435 | return -EINVAL; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * this is the access path from userspace. they can seek and write to |
| 441 | * the fb. it's inefficient for them to do anything less than 64*8 |
| 442 | * writes since we update the lcd in each write() anyway. |
| 443 | */ |
Al Viro | d220439 | 2005-12-15 09:18:15 +0000 | [diff] [blame] | 444 | static ssize_t arcfb_write(struct file *file, const char __user *buf, size_t count, |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 445 | loff_t *ppos) |
| 446 | { |
| 447 | /* modded from epson 1355 */ |
| 448 | |
| 449 | struct inode *inode; |
| 450 | int fbidx; |
| 451 | struct fb_info *info; |
| 452 | unsigned long p; |
| 453 | int err=-EINVAL; |
| 454 | unsigned int fbmemlength,x,y,w,h, bitppos, startpos, endpos, bitcount; |
| 455 | struct arcfb_par *par; |
| 456 | unsigned int xres; |
| 457 | |
| 458 | p = *ppos; |
| 459 | inode = file->f_dentry->d_inode; |
| 460 | fbidx = iminor(inode); |
| 461 | info = registered_fb[fbidx]; |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 462 | |
| 463 | if (!info || !info->screen_base) |
| 464 | return -ENODEV; |
| 465 | |
Antonino A. Daplas | 939205b | 2006-03-11 03:27:23 -0800 | [diff] [blame] | 466 | par = info->par; |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 467 | xres = info->var.xres; |
| 468 | fbmemlength = (xres * info->var.yres)/8; |
| 469 | |
| 470 | if (p > fbmemlength) |
| 471 | return -ENOSPC; |
| 472 | |
| 473 | err = 0; |
| 474 | if ((count + p) > fbmemlength) { |
| 475 | count = fbmemlength - p; |
| 476 | err = -ENOSPC; |
| 477 | } |
| 478 | |
| 479 | if (count) { |
| 480 | char *base_addr; |
| 481 | |
| 482 | base_addr = info->screen_base; |
| 483 | count -= copy_from_user(base_addr + p, buf, count); |
| 484 | *ppos += count; |
| 485 | err = -EFAULT; |
| 486 | } |
| 487 | |
| 488 | |
| 489 | bitppos = p*8; |
| 490 | startpos = floorXres(bitppos, xres); |
| 491 | endpos = ceilXres((bitppos + (count*8)), xres); |
| 492 | bitcount = endpos - startpos; |
| 493 | |
| 494 | x = startpos % xres; |
| 495 | y = startpos / xres; |
| 496 | w = xres; |
| 497 | h = bitcount / xres; |
| 498 | arcfb_lcd_update(par, x, y, w, h); |
| 499 | |
| 500 | if (count) |
| 501 | return count; |
| 502 | return err; |
| 503 | } |
| 504 | |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 505 | static struct fb_ops arcfb_ops = { |
| 506 | .owner = THIS_MODULE, |
| 507 | .fb_open = arcfb_open, |
| 508 | .fb_write = arcfb_write, |
| 509 | .fb_release = arcfb_release, |
| 510 | .fb_pan_display = arcfb_pan_display, |
| 511 | .fb_fillrect = arcfb_fillrect, |
| 512 | .fb_copyarea = arcfb_copyarea, |
| 513 | .fb_imageblit = arcfb_imageblit, |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 514 | .fb_ioctl = arcfb_ioctl, |
| 515 | }; |
| 516 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 517 | static int __init arcfb_probe(struct platform_device *dev) |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 518 | { |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 519 | struct fb_info *info; |
| 520 | int retval = -ENOMEM; |
| 521 | int videomemorysize; |
| 522 | unsigned char *videomemory; |
| 523 | struct arcfb_par *par; |
| 524 | int i; |
| 525 | |
| 526 | videomemorysize = (((64*64)*num_cols)*num_rows)/8; |
| 527 | |
| 528 | /* We need a flat backing store for the Arc's |
| 529 | less-flat actual paged framebuffer */ |
| 530 | if (!(videomemory = vmalloc(videomemorysize))) |
| 531 | return retval; |
| 532 | |
| 533 | memset(videomemory, 0, videomemorysize); |
| 534 | |
| 535 | info = framebuffer_alloc(sizeof(struct arcfb_par), &dev->dev); |
| 536 | if (!info) |
| 537 | goto err; |
| 538 | |
| 539 | info->screen_base = (char __iomem *)videomemory; |
| 540 | info->fbops = &arcfb_ops; |
| 541 | |
| 542 | info->var = arcfb_var; |
| 543 | info->fix = arcfb_fix; |
| 544 | par = info->par; |
| 545 | par->info = info; |
| 546 | |
| 547 | if (!dio_addr || !cio_addr || !c2io_addr) { |
| 548 | printk(KERN_WARNING "no IO addresses supplied\n"); |
| 549 | goto err1; |
| 550 | } |
| 551 | par->dio_addr = dio_addr; |
| 552 | par->cio_addr = cio_addr; |
| 553 | par->c2io_addr = c2io_addr; |
| 554 | par->cslut[0] = 0x00; |
| 555 | par->cslut[1] = 0x06; |
| 556 | info->flags = FBINFO_FLAG_DEFAULT; |
| 557 | spin_lock_init(&par->lock); |
| 558 | retval = register_framebuffer(info); |
| 559 | if (retval < 0) |
| 560 | goto err1; |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 561 | platform_set_drvdata(dev, info); |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 562 | if (irq) { |
| 563 | par->irq = irq; |
| 564 | if (request_irq(par->irq, &arcfb_interrupt, SA_SHIRQ, |
| 565 | "arcfb", info)) { |
| 566 | printk(KERN_INFO |
| 567 | "arcfb: Failed req IRQ %d\n", par->irq); |
| 568 | goto err1; |
| 569 | } |
| 570 | } |
| 571 | printk(KERN_INFO |
| 572 | "fb%d: Arc frame buffer device, using %dK of video memory\n", |
| 573 | info->node, videomemorysize >> 10); |
| 574 | |
| 575 | /* this inits the lcd but doesn't clear dirty pixels */ |
| 576 | for (i = 0; i < num_cols * num_rows; i++) { |
| 577 | ks108_writeb_ctl(par, i, KS_DPY_OFF); |
| 578 | ks108_set_start_line(par, i, 0); |
| 579 | ks108_set_yaddr(par, i, 0); |
| 580 | ks108_set_xaddr(par, i, 0); |
| 581 | ks108_writeb_ctl(par, i, KS_DPY_ON); |
| 582 | } |
| 583 | |
| 584 | /* if we were told to splash the screen, we just clear it */ |
| 585 | if (!nosplash) { |
| 586 | for (i = 0; i < num_cols * num_rows; i++) { |
| 587 | printk(KERN_INFO "fb%d: splashing lcd %d\n", |
| 588 | info->node, i); |
| 589 | ks108_set_start_line(par, i, 0); |
| 590 | ks108_clear_lcd(par, i); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | return 0; |
| 595 | err1: |
| 596 | framebuffer_release(info); |
| 597 | err: |
| 598 | vfree(videomemory); |
| 599 | return retval; |
| 600 | } |
| 601 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 602 | static int arcfb_remove(struct platform_device *dev) |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 603 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 604 | struct fb_info *info = platform_get_drvdata(dev); |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 605 | |
| 606 | if (info) { |
| 607 | unregister_framebuffer(info); |
| 608 | vfree(info->screen_base); |
| 609 | framebuffer_release(info); |
| 610 | } |
| 611 | return 0; |
| 612 | } |
| 613 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 614 | static struct platform_driver arcfb_driver = { |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 615 | .probe = arcfb_probe, |
| 616 | .remove = arcfb_remove, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 617 | .driver = { |
| 618 | .name = "arcfb", |
| 619 | }, |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 620 | }; |
| 621 | |
Russell King | 8d972a9 | 2005-11-05 21:21:38 +0000 | [diff] [blame] | 622 | static struct platform_device *arcfb_device; |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 623 | |
| 624 | static int __init arcfb_init(void) |
| 625 | { |
| 626 | int ret; |
| 627 | |
| 628 | if (!arcfb_enable) |
| 629 | return -ENXIO; |
| 630 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 631 | ret = platform_driver_register(&arcfb_driver); |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 632 | if (!ret) { |
Russell King | 8d972a9 | 2005-11-05 21:21:38 +0000 | [diff] [blame] | 633 | arcfb_device = platform_device_alloc("arcfb", 0); |
| 634 | if (arcfb_device) { |
| 635 | ret = platform_device_add(arcfb_device); |
| 636 | } else { |
| 637 | ret = -ENOMEM; |
| 638 | } |
| 639 | if (ret) { |
| 640 | platform_device_put(arcfb_device); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 641 | platform_driver_unregister(&arcfb_driver); |
Russell King | 8d972a9 | 2005-11-05 21:21:38 +0000 | [diff] [blame] | 642 | } |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 643 | } |
| 644 | return ret; |
| 645 | |
| 646 | } |
| 647 | |
| 648 | static void __exit arcfb_exit(void) |
| 649 | { |
Russell King | 8d972a9 | 2005-11-05 21:21:38 +0000 | [diff] [blame] | 650 | platform_device_unregister(arcfb_device); |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 651 | platform_driver_unregister(&arcfb_driver); |
Jaya Kumar | 1154ea7 | 2005-06-21 17:17:04 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | module_param(num_cols, ulong, 0); |
| 655 | MODULE_PARM_DESC(num_cols, "Num horiz panels, eg: 2 = 128 bit wide"); |
| 656 | module_param(num_rows, ulong, 0); |
| 657 | MODULE_PARM_DESC(num_rows, "Num vert panels, eg: 1 = 64 bit high"); |
| 658 | module_param(nosplash, uint, 0); |
| 659 | MODULE_PARM_DESC(nosplash, "Disable doing the splash screen"); |
| 660 | module_param(arcfb_enable, uint, 0); |
| 661 | MODULE_PARM_DESC(arcfb_enable, "Enable communication with Arc board"); |
| 662 | module_param(dio_addr, ulong, 0); |
| 663 | MODULE_PARM_DESC(dio_addr, "IO address for data, eg: 0x480"); |
| 664 | module_param(cio_addr, ulong, 0); |
| 665 | MODULE_PARM_DESC(cio_addr, "IO address for control, eg: 0x400"); |
| 666 | module_param(c2io_addr, ulong, 0); |
| 667 | MODULE_PARM_DESC(c2io_addr, "IO address for secondary control, eg: 0x408"); |
| 668 | module_param(splashval, ulong, 0); |
| 669 | MODULE_PARM_DESC(splashval, "Splash pattern: 0xFF is black, 0x00 is green"); |
| 670 | module_param(tuhold, ulong, 0); |
| 671 | MODULE_PARM_DESC(tuhold, "Time to hold between strobing data to Arc board"); |
| 672 | module_param(irq, uint, 0); |
| 673 | MODULE_PARM_DESC(irq, "IRQ for the Arc board"); |
| 674 | |
| 675 | module_init(arcfb_init); |
| 676 | module_exit(arcfb_exit); |
| 677 | |
| 678 | MODULE_DESCRIPTION("fbdev driver for Arc monochrome LCD board"); |
| 679 | MODULE_AUTHOR("Jaya Kumar"); |
| 680 | MODULE_LICENSE("GPL"); |
| 681 | |