int cycx_setup(cycxhw_t *hw, void *cfm, u32 len) { unsigned long dpmbase = hw->dpmbase; int err; /* Verify IRQ configuration options */ if (!get_option_index(cycx_2x_irq_options, hw->irq)) { printk(KERN_ERR "%s: IRQ %d is illegal!\n", modname, hw->irq); return -EINVAL; } /* Setup adapter dual-port memory window and test memory */ if (!hw->dpmbase) { printk(KERN_ERR "%s: you must specify the dpm address!\n", modname); return -EINVAL; } else if (!get_option_index(cyc2x_dpmbase_options, hw->dpmbase)) { printk(KERN_ERR "%s: memory address 0x%lX is illegal!\n", modname, dpmbase); return -EINVAL; } hw->dpmbase = (u32)ioremap(dpmbase, CYCX_WINDOWSIZE); hw->dpmsize = CYCX_WINDOWSIZE; if (!detect_cyc2x(hw->dpmbase)) { printk(KERN_ERR "%s: adapter Cyclom 2X not found at " "address 0x%lX!\n", modname, dpmbase); return -EINVAL; } printk(KERN_INFO "%s: found Cyclom 2X card at address 0x%lX.\n", modname, dpmbase); /* Load firmware. If loader fails then shut down adapter */ err = load_cyc2x(hw, cfm, len); if (err) cycx_down(hw); /* shutdown adapter */ return err; }
int cycx_setup(struct cycx_hw *hw, void *cfm, u32 len, unsigned long dpmbase) { int err; /* Verify IRQ configuration options */ if (!get_option_index(cycx_2x_irq_options, hw->irq)) { pr_err("IRQ %d is invalid!\n", hw->irq); return -EINVAL; } /* Setup adapter dual-port memory window and test memory */ if (!dpmbase) { pr_err("you must specify the dpm address!\n"); return -EINVAL; } else if (!get_option_index(cyc2x_dpmbase_options, dpmbase)) { pr_err("memory address 0x%lX is invalid!\n", dpmbase); return -EINVAL; } hw->dpmbase = ioremap(dpmbase, CYCX_WINDOWSIZE); hw->dpmsize = CYCX_WINDOWSIZE; if (!detect_cyc2x(hw->dpmbase)) { pr_err("adapter Cyclom 2X not found at address 0x%lX!\n", dpmbase); return -EINVAL; } pr_info("found Cyclom 2X card at address 0x%lX\n", dpmbase); /* Load firmware. If loader fails then shut down adapter */ err = load_cyc2x(hw, cfm, len); if (err) cycx_down(hw); /* shutdown adapter */ return err; }
static int setup_user_parameters(struct isp_node *upipe, struct options *cl, unsigned cl_items_count) { /* Read input image parameters */ int opt_idx = get_option_index("-iw", cl, cl_items_count); int in_hsize = cl[opt_idx].o_dflt.v_word; printf(" optindex %d hsize %d \n", opt_idx, in_hsize); opt_idx = get_option_index("-ih", cl, cl_items_count); int in_vsize = cl[opt_idx].o_dflt.v_word; printf(" optindex %d vsize %d \n", opt_idx, in_vsize); if (in_hsize <= 0 || in_vsize <= 0) { error(-1, ECANCELED, "Input size out of range."); return -1; } /* Read output image parameters */ opt_idx = get_option_index("-ow", cl, cl_items_count); int out_hsize = cl[opt_idx].o_dflt.v_word; opt_idx = get_option_index("-oh", cl, cl_items_count); int out_vsize = cl[opt_idx].o_dflt.v_word; if (in_hsize <= 0 || in_vsize <= 0) { error(-1, ECANCELED, "Output size out of range."); return -1; } /* clear parameters */ memset(upipe, 0, sizeof(struct isp_node)); /* determining 16 bit or 8 bit data */ upipe->in.image.pixelformat = V4L2_PIX_FMT_YUYV; /* input frame horizontal/vertical size */ upipe->in.image.width = in_hsize; upipe->in.image.height = in_vsize; /* input crop horizontal size */ opt_idx = get_option_index("-icw", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->in.crop.width = cl[opt_idx].o_dflt.v_word; else upipe->in.crop.width = upipe->in.image.width; /* input crop horizontal offset */ opt_idx = get_option_index("-icl", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->in.crop.left = cl[opt_idx].o_dflt.v_word; else upipe->in.crop.left = 0; /* input crop vertical size */ opt_idx = get_option_index("-ich", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->in.crop.height = cl[opt_idx].o_dflt.v_word; else upipe->in.crop.height = upipe->in.image.height; /* input crop vertical offset */ opt_idx = get_option_index("-ict", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->in.crop.top = cl[opt_idx].o_dflt.v_word; else upipe->in.crop.top = 0; /* output frame horizontal/verticals size */ upipe->out.image.width = out_hsize; upipe->out.image.height = out_vsize; /* output crop horizontal size */ opt_idx = get_option_index("-ocw", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->out.crop.width = cl[opt_idx].o_dflt.v_word; else upipe->out.crop.width = upipe->out.image.width; /* output crop horizontal offset */ opt_idx = get_option_index("-ocl", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->out.crop.left = cl[opt_idx].o_dflt.v_word; else upipe->out.crop.left = 0; /* output crop vertical size */ opt_idx = get_option_index("-och", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->out.crop.height = cl[opt_idx].o_dflt.v_word; else upipe->out.crop.height = upipe->out.image.height; /* output crop vertical offset */ opt_idx = get_option_index("-oct", cl, cl_items_count); if (cl[opt_idx].o_dflt.v_word) upipe->out.crop.top = cl[opt_idx].o_dflt.v_word; else upipe->out.crop.top = 0; #if defined(DEBUG) print_options(cl, cl_items_count); #endif return 0; }
int main(int argc, char *argv[]) { /* user parameters */ static struct isp_node upipe; /* command line argument index */ int opt_idx; if (argc == 1 || (argc == 2 && (!strcmp(argv[1], "?") || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) { fprintf(stderr, "\nUSAGE: command <options>"); opt_idx = get_option_index("-ifile", cmd_line, COUNT_OF(cmd_line)); fprintf(stderr, " %s<input file>", cmd_line[opt_idx].o_symb); opt_idx = get_option_index("-ofile", cmd_line, COUNT_OF(cmd_line)); fprintf(stderr, " %s<output file>\n", cmd_line[opt_idx].o_symb); print_options(cmd_line, COUNT_OF(cmd_line)); /* Print additional help */ printf("\nExamples:\n"); printf("\nResize image: \n "); printf("reszhq -iw [in width] -ih [in height] "\ "-ifile [input file] "\ "-ow [out width] -oh [out height] "\ "-ofile [output file]\n"); exit(EXIT_FAILURE); } if (parse_prepare(argc, argv, cmd_line, COUNT_OF(cmd_line))) exit(errno); if (setup_user_parameters(&upipe, cmd_line, COUNT_OF(cmd_line))) exit(errno); /* index of input file name argument */ opt_idx = get_option_index("-ifile", cmd_line, COUNT_OF(cmd_line)); if (!cmd_line[opt_idx].o_dflt.v_char) { error(-1, ECANCELED, "Input file parameter missing."); exit(errno); } /* index of output file name argument */ opt_idx = get_option_index("-ofile", cmd_line, COUNT_OF(cmd_line)); if (!cmd_line[opt_idx].o_dflt.v_char) { error(-1, ECANCELED, "Output file parameter missing."); exit(errno); } int rz_fd; /* index of device name */ opt_idx = get_option_index("-dev", cmd_line, COUNT_OF(cmd_line)); rz_fd = open(cmd_line[opt_idx].o_dflt.v_char, O_RDWR); if (rz_fd < 0) { error(-1, ECANCELED, "Can't open device."); exit(errno); } printf(" Before RSZ_S_PARAM : "); printf("%dx%d->", upipe.in.image.width, upipe.in.image.height); printf("%dx%d \n ", upipe.out.image.width, upipe.out.image.height); if (ioctl(rz_fd, RSZ_S_PARAM, &upipe) == -1) { error(-1, ECANCELED, "Invalid config parameters."); exit(errno); } printf(" After RSZ_S_PARAM : "); printf("%dx%d->", upipe.in.image.width, upipe.in.image.height); printf("%dx%d \n ", upipe.out.image.width, upipe.out.image.height); /* V4L2 Buffer */ struct v4l2_requestbuffers v4l2_req; /* user buffer source pointer */ struct v4l2_buffer src_ubuf; struct v4l2_buffer dst_ubuf; /* clear buffers */ memset(&v4l2_req, 0, sizeof(v4l2_req)); memset(&src_ubuf, 0, sizeof(src_ubuf)); memset(&dst_ubuf, 0, sizeof(dst_ubuf)); void * inBuf; void * outBuf; /* V4L2 Memory map type */ v4l2_req.memory = V4L2_MEMORY_USERPTR; /* V4L2 The number of buffers requested */ v4l2_req.count = 1; /* V4L2 Buffer type */ v4l2_req.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; if (ioctl(rz_fd, RSZ_REQBUF, &v4l2_req)) { error(-1, ECANCELED, "input: REQBUF failed."); exit(errno); } /* setup input buffer parameters */ src_ubuf.index = 0; src_ubuf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; src_ubuf.memory = v4l2_req.memory; /* calculate input buffer length */ src_ubuf.length = ALIGN(upipe.in.image.bytesperline * upipe.in.image.height, PAGE_SIZE); /* V4L2 - Query input buffer */ if (ioctl(rz_fd, RSZ_QUERYBUF, &src_ubuf)) { error(-1, ECANCELED, "RSZ_QUERYBUF failed."); exit(errno); } /* allocate input data buffer */ inBuf = malloc(src_ubuf.length + PAGE_SIZE); if (inBuf == NULL ) { perror("input: Can't allocate memory"); exit(errno); } src_ubuf.m.userptr = (unsigned long)(ALIGN(inBuf, PAGE_SIZE)); if (!src_ubuf.m.userptr) { perror("input: Can't allocate memory"); exit(errno); } /* V4L2 - Setup input buffer in queue */ if (ioctl(rz_fd, RSZ_QUEUEBUF, &src_ubuf)) { error(-1, ECANCELED, "RSZ_QUEUEBUF failed."); exit(errno); } /* index of options for input file name */ opt_idx = get_option_index("-ifile", cmd_line, COUNT_OF(cmd_line)); /* load data buffer */ if (Load_Image(cmd_line[opt_idx].o_dflt.v_char, (char *)src_ubuf.m.userptr, src_ubuf.length)) { error(-1, ECANCELED, "File load error."); exit(errno); } /* V4L2 Memory map type */ v4l2_req.memory = V4L2_MEMORY_USERPTR; /* V4L2 The number of buffers requested */ v4l2_req.count = 1; /* V4L2 Buffer type */ v4l2_req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (ioctl(rz_fd, RSZ_REQBUF, &v4l2_req)) { error(-1, ECANCELED, "RSZ_REQBUF failed."); exit(errno); } /* setup output buffer parameters */ dst_ubuf.index = 0; dst_ubuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; dst_ubuf.memory = v4l2_req.memory; /* calculate buffer/buffers length */ dst_ubuf.length = ALIGN(upipe.out.image.bytesperline * upipe.out.image.height, PAGE_SIZE); /* V4L2 - Query output buffer */ if (ioctl(rz_fd, RSZ_QUERYBUF, &dst_ubuf)) { error(-1, ECANCELED, "RSZ_QUERYBUF failed."); exit(errno); } #if 0 /* allocate output buffer */ dst_ubuf.maddr = malloc(dst_ubuf.length); if (dst_ubuf.maddr == 0) { error(-1, ECANCELED, "Buffer allocation failed."); exit(errno); } /* align and setup ouput pointer */ dst_ubuf.m.userptr = (unsigned long) (ALIGN(dst_ubuf.maddr, PAGE_SIZE)); #else /* allocate input data buffer */ outBuf = malloc(dst_ubuf.length + PAGE_SIZE); if (outBuf == NULL ) { perror("input: Can't allocate memory"); exit(errno); } dst_ubuf.m.userptr = (unsigned long)(ALIGN(outBuf, PAGE_SIZE)); if (!dst_ubuf.m.userptr) { perror("input: Can't allocate memory"); exit(errno); } #endif /* V4L2 - Setup output buffer in queue */ if (ioctl(rz_fd, RSZ_QUEUEBUF, &dst_ubuf)) { error(-1, ECANCELED, "RSZ_QUEUEBUF failed."); exit(errno); } #if !defined(NDEBUG) /* initialize start time */ struct timeval beg_tv; gettimeofday(&beg_tv, NULL); #endif /* * Execute operation */ if (ioctl(rz_fd, RSZ_RESIZE, &upipe) == -1) { error(-1, ECANCELED, "RSZ_RESIZE error\n"); exit(errno); } #if !defined(NDEBUG) /* initialize end time */ struct timeval end_tv; gettimeofday(&end_tv, NULL); fprintf(stderr, "\nOperation finished: %ld (usec)\n", (end_tv.tv_sec - beg_tv.tv_sec) * 1000000 + (end_tv.tv_usec - beg_tv.tv_usec) ); #endif /* index of options for output file name */ opt_idx = get_option_index("-ofile", cmd_line, COUNT_OF(cmd_line)); /* save image */ if (Save_Image(cmd_line[opt_idx].o_dflt.v_char, (char *)dst_ubuf.m.userptr, upipe.out.image.bytesperline * upipe.out.image.height)) { error(-1, ECANCELED, "File save error"); exit(errno); } /* release allocated buffers */ if (src_ubuf.m.userptr) free(inBuf); if (dst_ubuf.m.userptr) free(outBuf); if (rz_fd) close(rz_fd); parse_release(cmd_line, COUNT_OF(cmd_line)); return 0; }
int sdla_setup (sdlahw_t* hw, void* sfm, unsigned len) { unsigned* irq_opt = NULL; /* IRQ options */ unsigned* dpmbase_opt = NULL; /* DPM window base options */ unsigned* pclk_opt = NULL; /* CPU clock rate options */ int err; if (sdla_detect(hw)) { printk(KERN_ERR "%s: adapter S%04u not found at port 0x%X!\n", modname, hw->type, hw->port) ; return -EINVAL; } printk(KERN_INFO "%s: found S%04u card at port 0x%X.\n", modname, hw->type, hw->port) ; hw->dpmsize = SDLA_WINDOWSIZE; switch (hw->type) { case SDLA_S502A: hw->io_range = S502A_IORANGE; irq_opt = s502a_irq_options; dpmbase_opt = s502a_dpmbase_options; pclk_opt = s502a_pclk_options; break; case SDLA_S502E: hw->io_range = S502E_IORANGE; irq_opt = s502e_irq_options; dpmbase_opt = s508_dpmbase_options; pclk_opt = s502e_pclk_options; break; case SDLA_S503: hw->io_range = S503_IORANGE; irq_opt = s503_irq_options; dpmbase_opt = s508_dpmbase_options; pclk_opt = s503_pclk_options; break; case SDLA_S507: hw->io_range = S507_IORANGE; irq_opt = s508_irq_options; dpmbase_opt = s507_dpmbase_options; pclk_opt = s507_pclk_options; break; case SDLA_S508: hw->io_range = S508_IORANGE; irq_opt = s508_irq_options; dpmbase_opt = s508_dpmbase_options; pclk_opt = s508_pclk_options; break; } /* Verify IRQ configuration options */ if (!get_option_index(irq_opt, hw->irq)) { printk(KERN_ERR "%s: IRQ %d is illegal!\n", modname, hw->irq) ; return -EINVAL; } /* Verify CPU clock rate configuration options */ if (hw->pclk == 0) hw->pclk = pclk_opt[1] /* use default */ ; else if (!get_option_index(pclk_opt, hw->pclk)) { printk(KERN_ERR "%s: CPU clock %u is illegal!\n", modname, hw->pclk) ; return -EINVAL; } printk(KERN_INFO "%s: assuming CPU clock rate of %u kHz.\n", modname, hw->pclk) ; /* Setup adapter dual-port memory window and test memory */ if (hw->dpmbase == 0) { err = sdla_autodpm(hw); if (err) { printk(KERN_ERR "%s: can't find available memory region!\n", modname) ; return err; } } else if (!get_option_index(dpmbase_opt, virt_to_phys(hw->dpmbase))) { printk(KERN_ERR "%s: memory address 0x%lX is illegal!\n", modname, virt_to_phys(hw->dpmbase)) ; return -EINVAL; } else if (sdla_setdpm(hw)) { printk(KERN_ERR "%s: 8K memory region at 0x%lX is not available!\n", modname, virt_to_phys(hw->dpmbase)); return -EINVAL; } printk(KERN_INFO "%s: dual-port memory window is set at 0x%lX.\n", modname, virt_to_phys(hw->dpmbase)); printk(KERN_INFO "%s: found %luK bytes of on-board memory.\n", modname, hw->memory / 1024); /* Load firmware. If loader fails then shut down adapter */ err = sdla_load(hw, sfm, len); if (err) sdla_down(hw); /* shutdown adapter */ return err; }