os/linux-2.6-tag--devboard-R2_10-4/arch/cris/arch-v32/drivers/elphel/cxsdram353.c

Go to the documentation of this file.
00001 /*!***************************************************************************
00002 *! FILE NAME  : cxsdram353.c
00003 *! DESCRIPTION: TBD
00004 *! Copyright (C) 2002-2007 Elphel, Inc
00005 *! -----------------------------------------------------------------------------**
00006 *!
00007 *!  This program is free software: you can redistribute it and/or modify
00008 *!  it under the terms of the GNU General Public License as published by
00009 *!  the Free Software Foundation, either version 3 of the License, or
00010 *!  (at your option) any later version.
00011 *!
00012 *!  This program is distributed in the hope that it will be useful,
00013 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 *!  GNU General Public License for more details.
00016 *!
00017 *!  You should have received a copy of the GNU General Public License
00018 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 *! -----------------------------------------------------------------------------**
00020 *!  $Log: cxsdram353.c,v $
00021 *!  Revision 1.1.1.1  2007/08/17 10:23:18  elphel
00022 *!  This is a fresh tree based on elphel353-2.10
00023 *!
00024 *!  Revision 1.7  2007/08/17 10:23:18  spectr_rain
00025 *!  switch to GPL3 license
00026 *!
00027 *!  Revision 1.6  2007/07/20 10:17:45  spectr_rain
00028 *!  *** empty log message ***
00029 *!
00030 *!  Revision 1.1.1.1  2007/02/23 10:11:48  elphel
00031 *!  initial import into CVS
00032 *!
00033 *!  Revision 1.8  2006/09/19 16:22:14  spectr_rain
00034 *!  *** empty log message ***
00035 *!
00036 *!  Revision 1.7  2006/09/02 22:04:17  spectr_rain
00037 *!  *** empty log message ***
00038 *!
00039 *!  Revision 1.6  2006/09/02 00:19:49  spectr_rain
00040 *!  lock sensor while readrawimage
00041 *!
00042 *!  Revision 1.5  2006/09/01 21:36:59  spectr_rain
00043 *!  *** empty log message ***
00044 *!
00045 *!  Revision 1.4  2006/09/01 21:16:00  spectr_rain
00046 *!  *** empty log message ***
00047 *!
00048 *!  Revision 1.3  2006/09/01 21:02:00  spectr_rain
00049 *!  *** empty log message ***
00050 *!
00051 *!  Revision 1.2  2006/09/01 18:54:40  spectr_rain
00052 *!  some fixes for /dev/ccam_img (image.raw)
00053 *!
00054 *!  Revision 1.1.1.1  2006/07/11 19:14:59  spectr_rain
00055 *!  unwork with less than 5MPx Micron sensor, initial branch
00056 *!
00057 *!  Revision 1.2  2005/05/10 21:08:49  elphel
00058 *!  *** empty log message ***
00059 *!
00060 
00061 P_ACTUAL_WIDTH2 and P_ACTUAL_HEIGHT2 increased by 4 each to include 1
00062 */
00063 
00064 /****************** INCLUDE FILES SECTION ***********************************/
00065 #define P_ACTUAL_WIDTH2  ( get_imageParamsR(P_ACTUAL_WIDTH)+4 )
00066 #define P_ACTUAL_HEIGHT2 ( get_imageParamsR(P_ACTUAL_HEIGHT)+4 )
00067 
00068 #include <linux/module.h>
00069 #include <linux/sched.h>
00070 #include <linux/slab.h>
00071 #include <linux/errno.h>
00072 #include <linux/kernel.h>
00073 #include <linux/fs.h>
00074 #include <linux/string.h>
00075 #include <linux/init.h>
00076 #include <linux/autoconf.h>
00077 
00078 #include <asm/system.h>
00079 //#include <asm/svinto.h>
00080 #include <asm/io.h>
00081 
00082 #include <asm/irq.h>
00083 
00084 #include <asm/delay.h>
00085 #include <asm/uaccess.h>
00086 
00087 #include <asm/elphel/c313a.h>
00088 
00089 #include "fpgactrl.h"  // defines port_csp0_addr, port_csp4_addr 
00090 
00091 #include "x3x3.h"
00092 #include "cc3x3.h"
00093 #include "cxsdram.h"
00094 
00095 #define D(x)
00096 //#define MD3(x) printk("%s:%d:",__FILE__,__LINE__);x
00097 #define MD3(x)
00098 
00099 static int linebuf_fpn[4096];
00100 static int lineinbuf_fpn;               // should be -1 after frame acquisition, etc - program sensor
00101 static int linebufdirty_fpn = 0;
00102 static int linebuf_img[4096];
00103 static int lineinbuf_img;               // should be -1 after frame acquisition, etc - program sensor
00104 
00105 
00106 int *x313_fpn_readline(int line, int ignore) {  // read fpn line to buffer (returns buffer address). ignore - contents does not matter (to write over)
00107         int ntilex, padlen, sa, nw, n, i, li;   //nw - number of 32-bit words to read)
00108 
00109         if(line == lineinbuf_fpn)
00110                 return linebuf_fpn;             // cache hit
00111         if((port_csp0_addr[X313_WA_SD_MODE] & 3) != 3)
00112                 return NULL;                    // SDRAM was not enabled or refresh was not on
00113         if(linebufdirty_fpn) {
00114                 if (x313_fpn_writeline() < 0)
00115                         return NULL;            // failed to write buffer
00116         }
00117         if(ignore)
00118                 return linebuf_fpn;
00119         nw = ((P_ACTUAL_WIDTH2 + 1) >> 1);
00120         ntilex = ((nw + 3) >> 2);
00121 //      padlen = ((ntilex + 15) >> 4);
00122         padlen = ((ntilex + 31) >> 5);
00123 //      sa = X313_MAP_FPN + ((padlen * line) << 7);
00124         sa = X313_MAP_FPN + ((padlen * line) << 8);
00125 
00126 //      printk(" *%x*",sa);
00127         X313_INIT_SDCHAN(3, 0, 0, 0, sa, 0x3ff, 0xfff); // 4096 rows of 32x256 16-bit words each - 64MB > than memory
00128 //      enable channel if it was not already
00129         port_csp0_addr[X313_WA_SD_MODE] |= 0x23;        // channel3 enabled, refresh, sdram
00130         li = 0;
00131 //      n = nw;
00132         while (nw > 0) {
00133                 i = 1000;
00134                 D(printk("wait "));
00135                 while (((i--) > 0) && !X313_SR(PIORDY));
00136                 udelay(1);
00137                 D(printk("ready, i=%d\n", (int) i));
00138                 if (i == 0)
00139                         return NULL;            // page not ready
00140                 n = nw;
00141                 if (n > 128)
00142                         n = 128;
00143                 i = port_csp4_addr[X313_WA_SD_PIOWIN];  // will return garbage (because of latency), prepares to the next read, increments address
00144                 for (i = 0; i < n; i++)
00145                         linebuf_fpn[li++] = port_csp4_addr[X313_WA_SD_PIOWIN];
00146                 nw -= n;
00147                 if (nw > 0)
00148                         port_csp0_addr[X313_WA_SDPIO_NEXT] = 0; // next page (all but last)
00149         }
00150         lineinbuf_fpn = line;
00151         return linebuf_fpn;
00152 }
00153 
00154 int x313_fpn_writeline(void) {  // write current line of FPN data to SDRAM, clear "dirty" flag
00155         int ntilex, padlen, sa, nw, n, i, li;
00156 
00157         if(linebufdirty_fpn == 0)
00158                 return 0;
00159 //  if((lineinbuf_fpn >= 0) && (lineinbuf_fpn < 1024)) {
00160         if(lineinbuf_fpn >= 0) {
00161                 if((port_csp0_addr[X313_WA_SD_MODE] & 3) != 3)
00162                         return -1;                      // SDRAM was not enabled or refresh was not on
00163                 nw = ((P_ACTUAL_WIDTH2 + 1) >> 1);
00164                 ntilex = ((nw + 3) >> 2);
00165 //              padlen = ((ntilex + 15) >> 4);
00166                 padlen = ((ntilex + 31) >> 5);
00167 //              sa = X313_MAP_FPN + ((padlen * lineinbuf_fpn) << 7);
00168                 sa = X313_MAP_FPN + ((padlen * lineinbuf_fpn) << 8);
00169 //              X313_INIT_SDCHAN(3, 0, 1, 0, sa, 0xff, 0x7ff);   // 2048 rows of 16x128 16-bit words each
00170                 X313_INIT_SDCHAN(3, 0, 1, 0, sa, 0x3ff, 0xfff); // 4096 rows of 32x256 16-bit words each - 64MB > than memory
00171 
00172                 // enable channel if it was not already
00173                 port_csp0_addr[X313_WA_SD_MODE] |= 0x23;        // channel3 enabled, refresh, sdram
00174                 li = 0;
00175 //              n = nw;
00176                 while (nw > 0) {
00177 //              if(!(li & 0x3f)) { // wait SDRAM ready (here 0x3f, as li addresses 32-bit words)
00178                         i = 1000;
00179                         D(printk("wait "));
00180                         while (((i--) > 0) && !X313_SR(PIORDY));
00181                         udelay(1);
00182                         D(printk("ready, i=%d\n", (int) i));
00183                         if (i == 0)
00184                                 return -1;              // page not ready
00185 //                      }
00186                         n = nw;
00187                         if (n > 128)
00188                                 n = 128;
00189                         for (i = 0; i < n; i++)
00190                                 port_csp0_addr[X313_WA_SD_PIOWIN] = linebuf_fpn[li++];
00191                         nw -= n;
00192                         port_csp0_addr[X313_WA_SDPIO_NEXT] = 0; // skip 8x32 data (all but last)
00193                 }
00194                 // write the last page if it was partial
00195 //              while(li & 0x3f) {
00196 //                      port_csp0_addr[X313_WA_SDPIO_NEXT] = 0; // skip 8x32 data (all but last)
00197 //                      li += 8;
00198 //              }
00199                 // wait page is written
00200                 i = 1000;
00201                 while (((i--) > 0) && !X313_SR(PIOWEMPTY))
00202                         udelay(1);
00203                 if (i == 0)
00204                         return -EFAULT;         // page not ready
00205         }
00206         linebufdirty_fpn = 0;
00207         return 0;
00208 }
00209 
00210 
00211 ssize_t x313_fpn_read(struct file * file, char *buf, size_t count, loff_t * off) {
00212         unsigned long p, fsz, y, xb, xbl, left;
00213         char *bp = buf;
00214         char *mp;
00215 
00216         MD3(printk("x313_fpn_read, count=%x, off=%x\n", (int) count, (int) off));
00217 //      p = file->f_pos;
00218    p = *off;
00219 //      printk("x313_fpn_read (%x/%x) ", (int) p, (int) count);
00220         fsz = (P_ACTUAL_WIDTH2 * P_ACTUAL_HEIGHT2) << 1;
00221 //      if(p >= fsz)  return -EINVAL; // bigger than SDRAM
00222         if((p + count) > fsz) { // truncate count
00223                 count = fsz - p;
00224         }
00225         left = count;
00226         while(left > 0) {
00227                 // calculate start address, pointed by p;
00228 //              printk(":%x:",(int) p);
00229                 y = (p / P_ACTUAL_WIDTH2) >> 1;
00230 //              printk("+%x+",(int) y);
00231                 xb = p - y * (P_ACTUAL_WIDTH2 << 1);
00232                 xbl = (P_ACTUAL_WIDTH2 << 1) - xb;
00233                 if(xbl > left)
00234                         xbl = left;                     // xbl - number of bytes left in the same line
00235                 if(!(mp = (char *)x313_fpn_readline(y, 0)))
00236                         return -EFAULT;         // read SDRAM error
00237 //              copy data
00238                 mp += xb;
00239 //              D(printk("copytouser, ibp=%x, nb=%x\n", (int) ibp, (int) nb));
00240                 if(copy_to_user(bp, mp, xbl))
00241                         return -EFAULT;
00242                 left -= xbl;
00243                 p += xbl;
00244                 bp += xbl;
00245         }                                                       // while (left >0)
00246 //      file->f_pos += count;
00247    *off+=count;
00248         return count;
00249 }
00250 
00251 ssize_t x313_fpn_write(struct file * file, const char *buf, size_t count, loff_t * off) {
00252         unsigned long p, fsz, y, xb, xbl, left;
00253         const char *bp = buf;
00254         char *mp;
00255 
00256 //  MD3(printk("x313_fpn_write, count=%x, off=%x\n", (int) count, (int) off));
00257 //      p = file->f_pos;
00258    p=*off;
00259         fsz = (P_ACTUAL_WIDTH2 * P_ACTUAL_HEIGHT2) << 1;
00260         if (p >= fsz)
00261                 return -EINVAL;                 // bigger than SDRAM
00262         if ((p + count) > fsz) {        // truncate count
00263                 count = fsz - p;
00264         }
00265         left = count;
00266         while (left > 0) {
00267                 // calculate start address, pointed by p;
00268                 y = (p / P_ACTUAL_WIDTH2) >> 1;
00269                 xb = p - y * (P_ACTUAL_WIDTH2 << 1);
00270                 xbl = (P_ACTUAL_WIDTH2 << 1) - xb;
00271                 if (xbl > left)
00272                         xbl = left;                     // xbl - number of bytes left in the same line
00273                 // do we need to overwrite a whole line? ((xb==0) && (xbl==(P_ACTUAL_WIDTH2<<1)))
00274                 if (!(mp = (char *) x313_fpn_readline(y, ((xb == 0) && (xbl == (P_ACTUAL_WIDTH2 << 1))))))
00275                         return -EFAULT;         // read SDRAM error
00276                 // copy to line buffer
00277                 mp += xb;
00278                 if (copy_from_user(mp, bp, xbl))
00279                         return -EFAULT;
00280                 left -= xbl;
00281                 p += xbl;
00282                 bp += xbl;
00283                 linebufdirty_fpn = 1;   // mark as modified
00284         }                                                       // while (left >0)
00285 //      file->f_pos += count;
00286    *off+=count;
00287         return count;
00288 }
00289 
00290 
00291 loff_t x313_fpn_lseek(struct file * file, loff_t offset, int orig) {
00292 
00293         //  orig 0: position from begining
00294         //  orig 1: relative from current position
00295         //  orig 2: position from last address
00296 
00297 
00298         unsigned long fsz;
00299 
00300         fsz = (P_ACTUAL_WIDTH2 * P_ACTUAL_HEIGHT2) << 1;
00301 
00302         MD3(printk("fpn_lseek %x\n", (int) offset));
00303 
00304         D(printk("fsdram_lseek\n"));
00305 
00306         switch (orig) {
00307         case 0:
00308                 file->f_pos = offset;
00309                 break;
00310         case 1:
00311                 file->f_pos += offset;
00312                 break;
00313         case 2:
00314                 file->f_pos = fsz + offset;
00315                 break;
00316         default:
00317                 return -EINVAL;
00318         }
00319 
00320         // truncate position
00321         if (file->f_pos < 0) {
00322                 file->f_pos = 0;
00323                 return (-EOVERFLOW);
00324         }
00325 
00326         if (file->f_pos > fsz) {
00327                 file->f_pos = fsz;
00328                 return (-EOVERFLOW);
00329         }
00330         return (file->f_pos);
00331 }
00332 
00333 
00334 // ----------------------------------------
00335 int *x313_frame_readline(int line) {    // read image line to buffer (returns buffer address)- may be modified to use DMA. Also - cache multiple lines? (for color)
00336         int ntilex, padlen, sa, nw, n, i, li;
00337 
00338 //      int line2;
00339 //      int buf128[128];
00340 //      int d;
00341 //      int d, pw;
00342 //      unsigned char *cbuf128 = (unsigned char *) buf128;
00343 //      unsigned char *clinebuf = (unsigned char *) linebuf_img;
00344 //      unsigned short *sbuf128 = (unsigned short *) buf128;
00345 //      unsigned short *slinebuf = (unsigned short *) linebuf_img;
00346 
00347         if(line == lineinbuf_img)
00348                 return linebuf_img;             // cache hit
00349         if((port_csp0_addr[X313_WA_SD_MODE] & 3) != 3)
00350                 return NULL;                    // SDRAM was not enabled or refresh was not on
00351         lineinbuf_img = line;
00352         if((get_imageParamsR(P_BITS) == 8) && !get_imageParamsR(P_BGFRAME))     // n - number of 32-bit words to read 
00353                 nw = ((P_ACTUAL_WIDTH2 + 3) >> 2);
00354         else
00355                 nw = ((P_ACTUAL_WIDTH2 + 1) >> 1);
00356         ntilex = ((nw + 3) >> 2);
00357 //  padlen = ((ntilex + 15) >> 4);
00358         padlen = ((ntilex + 31) >> 5);
00359 
00360 // in external (or virtual) trigger mode always 2 frames acquired (exactly), so there is no need to find the boarder
00361 // just add 2 frames.
00362 // so read line into buffer in any case
00363 
00364         sa = X313_MAP_FRAME + ((padlen * line) << 8);
00365 
00366 //pw = P_ACTUAL_WIDTH2;
00367         X313_INIT_SDCHAN(3, 0, 0, 0, sa, 0x3ff, 0xfff); // 4096 rows of 32x256 16-bit words each - 64MB > than memory
00368 //printk("readline(): line1 == %d, sa == 0x%08X; nw == %d, padlen == %d, P_ACTUAL_WIDTH2 == %d\r\n", line, sa, nw, padlen, pw);
00369 
00370         // enable channel if it was not already
00371         port_csp0_addr[X313_WA_SD_MODE] |= 0x23;        // channel3 enabled, refresh, sdram
00372         li = 0;
00373         while(nw > 0) {
00374                 i = 1000;
00375                 D(printk("wait "));
00376                 while(((i--) > 0) && !X313_SR(PIORDY));
00377                 udelay(1);
00378                 D(printk("ready, i = %d\n", (int) i));
00379                 if(i == 0)
00380                         return NULL;            // page not ready
00381                 n = nw;
00382                 if(n > 128)
00383                         n = 128;
00384                 i = port_csp4_addr[X313_WA_SD_PIOWIN];  // will return garbage (because of latency), prepares to the next read, increments address
00385                 for(i = 0; i < n; i++)
00386 //                      linebuf_img[li++] = 0x13141516;
00387                         linebuf_img[li++] = port_csp4_addr[X313_WA_SD_PIOWIN];
00388                 nw -= n;
00389                 if(nw > 0)
00390                         port_csp0_addr[X313_WA_SDPIO_NEXT] = 0; // next page (all but last)
00391         }
00392 
00393         // now add line from the second frame if external (or virtual) trigger
00394 /*
00395         if(get_imageParamsR(P_TRIG) > 0) {      //(external)
00396                 line2 = line + P_ACTUAL_HEIGHT2;        // second frame
00397 //              sa = X313_MAP_FRAME + ((padlen * line2) << 7);
00398                 sa = X313_MAP_FRAME + ((padlen * line2) << 8);
00399 //              X313_INIT_SDCHAN(3, 0, 0, 0, sa, 0xff, 0x7ff);   // 2048 rows of 16x128 16-bit words each
00400                 X313_INIT_SDCHAN(3, 0, 0, 0, sa, 0x3ff, 0xfff); // 4096 rows of 32x256 16-bit words each - 64MB > than memory
00401 printk("readline(): line2 == %d, sa == 0x%08X\r\n", line, sa);
00402                 // enable channel if it was not already
00403                 port_csp0_addr[X313_WA_SD_MODE] |= 0x23;        // channel3 enabled, refresh, sdram
00404 
00405                 li = 0;
00406                 while(nw > 0) {
00407                         i = 1000;
00408                         while(((i--) > 0) && !X313_SR(PIORDY));
00409                         udelay(1);
00410                         if(i == 0)
00411                                 return NULL;    // page not ready
00412                         n = nw;
00413                         if(n > 128)
00414                                 n = 128;
00415 //                      i = port_csp4_addr[X313_WA_SD_PIOWIN];  // will return garbage (because of latency), prepares to the next read, increments address
00416                         for(i = 0; i < n; i++)
00417                                 buf128[i] = port_csp0_addr[X313_WA_SD_PIOWIN];
00418                         if((get_imageParamsR(P_BITS) == 8) && !get_imageParamsR(P_BGFRAME)) {
00419                                 for(i = 0; i < 512; i++) {
00420                                         d = clinebuf[li];
00421                                         d += cbuf128[i];
00422                                         d -= get_imageParamsR(P_FATZERO);
00423                                         if (d < 0)
00424                                                 d = 0;
00425                                         else if (d > 255)
00426                                                 d = 255;
00427                                         clinebuf[li++] = d;
00428                                 }
00429                         } else {
00430                                 for(i = 0; i < 256; i++) {
00431                                         d = slinebuf[li];
00432                                         d += sbuf128[i];
00433                                         d -= get_imageParamsR(P_FATZERO);
00434                                         if(d < 0)
00435                                                 d = 0;
00436                                         else if(d > 65535)
00437                                                 d = 65535;
00438                                         slinebuf[li++] = d;
00439                                 }
00440                         }
00441                         nw -= n;
00442                         if(nw > 0)
00443                                 port_csp0_addr[X313_WA_SDPIO_NEXT] = 0; // next page (all but last)
00444                 }
00445         }
00446 */
00447         return linebuf_img;
00448 }
00449 
00450 static int lock_flag = 0;
00451 
00452 int slock = 0;
00453 wait_queue_head_t vack_wait_queue;
00454 
00455 void ch0_lock(void) {
00456         unsigned long t = port_csp0_addr[0x27];
00457         t = t & ~(1 << 2);
00458         port_csp0_addr[0x27] = t;
00459 }
00460 
00461 void ch0_dis(void) {
00462 //      init_waitqueue_head(&vack_wait_queue);
00463         slock = 2;
00464         while(slock == 2)
00465                 yield();
00466 //              sched_yield();
00467 //      interruptible_sleep_on(&vack_wait_queue);
00468 }
00469 
00470 void ch0_en(void) {
00471         unsigned long t = port_csp0_addr[0x27];
00472         t |= 1 << 2;
00473         port_csp0_addr[0x27] = t;
00474         slock = 0;
00475 }
00476 
00477 ssize_t x313_frame_read(struct file * file, char *buf, size_t count, loff_t * off) {
00478         unsigned long p, fsz, y, xb, xbl, left;
00479         char *bp = buf;
00480         char *mp;
00481 
00482         if(lock_flag == 0) {
00483                 lock_flag = 1;
00484                 printk("frame read first time - lock sensor and wait it\r\n");
00485 //              if(get_imageParamsR(P_BITS) <= 8 || get_imageParamsR(P_BITS) > 16)
00486 //                      sensor_stop(1);
00487 //              else
00488 //              sensor_stop(0);
00489                 ch0_dis();
00490         }
00491 
00492 //      MD3(printk("x313_frame_read, count=%x, off=%x\n", (int)count, (int)off));
00493 //      p = file->f_pos;
00494    p=*off;
00495 //      printk("x313_frame_read, count == %x, off == %x, f_pos == %d\r\n", (int)count, (int)off, p);
00496         fsz = (P_ACTUAL_WIDTH2 * P_ACTUAL_HEIGHT2) << (((get_imageParamsR(P_BITS) == 8) && !get_imageParamsR(P_BGFRAME)) ? 0 : 1);
00497 //  if(p >= fsz)  return -EINVAL; // bigger than SDRAM
00498         if((p + count) > fsz) { // truncate count
00499                 count = fsz - p;
00500         }
00501         left = count;
00502         while(left > 0) {
00503                 // calculate start address, pointed by p;
00504                 if((get_imageParamsR(P_BITS) == 8) && !get_imageParamsR(P_BGFRAME)) {
00505                         y = p / P_ACTUAL_WIDTH2;
00506                         xb = p - y * P_ACTUAL_WIDTH2;
00507                         xbl = P_ACTUAL_WIDTH2 - xb;
00508                 } else {
00509                         y = (p / P_ACTUAL_WIDTH2) >> 1;
00510                         xb = p - y * (P_ACTUAL_WIDTH2 << 1);
00511                         xbl = (P_ACTUAL_WIDTH2 << 1) - xb;
00512                 }
00513                 if(xbl > left)
00514                         xbl = left;                     // xbl - number of bytes left in the same line
00515 //              if(!(mp = (char *)x313_frame_readline(y + ((P_ACTUAL_HEIGHT2 * get_imageParamsR(P_PAGE_READ)) << (get_imageParamsR(P_TRIG) ? 1 : 0))))) {
00516                 if(!(mp = (char *)x313_frame_readline(y + P_ACTUAL_HEIGHT2 * get_imageParamsR(P_PAGE_READ)))) {
00517 printk("read SDRAM error!\r\n");
00518                         return -EFAULT;         // read SDRAM error
00519                 }
00520 // copy data
00521                 mp += xb;
00522 //    D(printk ("copytouser, ibp=%x, nb=%x\n", (int) ibp, (int) nb));
00523                 if(copy_to_user(bp, mp, xbl)) {
00524 printk("copy_to_user error!\r\n");
00525                         return -EFAULT;
00526                 }
00527                 left -= xbl;
00528                 p += xbl;
00529                 bp += xbl;
00530         }                                                       // while (left >0)
00531 //      file->f_pos += count;
00532    *off+=count;
00533 //printk("count == %d\r\n", count);
00534         return count;
00535 }
00536 
00537 
00538 loff_t x313_frame_lseek(struct file * file, loff_t offset, int orig) {
00539 /*
00540  *  orig 0: position from begning of eeprom
00541  *  orig 1: relative from current position
00542  *  orig 2: position from last eeprom address
00543  */
00544 
00545         unsigned long fsz;
00546         fsz = (P_ACTUAL_WIDTH2 * P_ACTUAL_HEIGHT2) << (((get_imageParamsR(P_BITS) == 8) && !get_imageParamsR(P_BGFRAME)) ? 0 : 1);
00547 
00548 //      MD3(printk("frame_lseek %x\n", (int) offset));
00549 
00550         switch (orig) {
00551         case 0:
00552                 file->f_pos = offset;
00553                 break;
00554         case 1:
00555                 file->f_pos += offset;
00556                 break;
00557         case 2:
00558                 file->f_pos = fsz + offset;
00559                 break;
00560         default:
00561                 return -EINVAL;
00562         }
00563 
00564         /* truncate position */
00565         if (file->f_pos < 0) {
00566                 file->f_pos = 0;
00567                 return (-EOVERFLOW);
00568         }
00569 
00570         if (file->f_pos > fsz) {
00571                 file->f_pos = fsz;
00572                 return (-EOVERFLOW);
00573         }
00574         return (file->f_pos);
00575 }
00576 
00577 int x313_frame_open(struct inode *inode, struct file *filp) {   // set filesize
00578         inode->i_size = (P_ACTUAL_WIDTH2 * P_ACTUAL_HEIGHT2) << (((get_imageParamsR(P_BITS) == 8) && !get_imageParamsR(P_BGFRAME)) ? 0 : 1);
00579         linebufdirty_fpn = 0;
00580         lineinbuf_img = -1;
00581 //      MD3(printk("frame_open, size = %x\n", (int) inode->i_size));
00582 //      printk("frame_open, size = 0x%08X; %d\n", (int)inode->i_size, (int)inode->i_size);
00583         return 0;
00584 }
00585 
00586 void x313_frame_release(void) {
00587 
00588         if(lock_flag == 1) {
00589                 printk("frame release - release sensor\r\n");
00590 //              sensor_release();
00591                 ch0_en();
00592                 lock_flag = 0;
00593         }
00594 }
00595 
00596 int x313_fpn_open(struct inode *inode, struct file *filp) {     // set filesize
00597         inode->i_size = (P_ACTUAL_WIDTH2 * P_ACTUAL_HEIGHT2) << 1;
00598         linebufdirty_fpn = 0;
00599         lineinbuf_fpn = -1;
00600         MD3(printk("fpn_open, size = %x\n", (int) inode->i_size));
00601         return 0;
00602 }
00603 
00604 void x313_fpn_release(void) {
00605         if(linebufdirty_fpn)
00606                 x313_fpn_writeline();
00607         MD3(printk("fpn_release\n"));
00608 
00609 }
00610 
00611 void x313_f_invalidate(void) {  // to be called when page number is changed. Write should not be in progress
00612         linebufdirty_fpn = 0;
00613         lineinbuf_fpn = -1;
00614         lineinbuf_img = -1;
00615 }

Generated on Thu Aug 7 16:19:00 2008 for elphel by  doxygen 1.5.1