int fimg2d_clk_setup(struct fimg2d_control *ctrl) { struct fimg2d_platdata *pdata; struct clk *parent, *sclk; int ret = 0; sclk = parent = NULL; pdata = to_fimg2d_plat(ctrl->dev); if (ip_is_g2d_5g() || ip_is_g2d_5a()) { fimg2d_info("aclk_acp(%lu) pclk_acp(%lu)\n", clk_get_rate(clk_get(NULL, "aclk_acp")), clk_get_rate(clk_get(NULL, "pclk_acp"))); } else { sclk = clk_get(ctrl->dev, pdata->clkname); if (IS_ERR(sclk)) { fimg2d_err("failed to get fimg2d clk\n"); ret = -ENOENT; goto err_clk1; } fimg2d_info("fimg2d clk name: %s clkrate: %ld\n", pdata->clkname, clk_get_rate(sclk)); } /* clock for gating */ ctrl->clock = clk_get(ctrl->dev, pdata->gate_clkname); if (IS_ERR(ctrl->clock)) { fimg2d_err("failed to get gate clk\n"); ret = -ENOENT; goto err_clk2; } fimg2d_info("gate clk: %s\n", pdata->gate_clkname); return ret; err_clk2: if (sclk) clk_put(sclk); err_clk1: return ret; }
static int fimg2d_resume(struct device *dev) { unsigned long flags; g2d_lock(&ctrl->drvlock); g2d_spin_lock(&ctrl->bltlock, flags); atomic_set(&ctrl->suspended, 0); g2d_spin_unlock(&ctrl->bltlock, flags); g2d_unlock(&ctrl->drvlock); fimg2d_info("resume... done\n"); return 0; }
static int fimg2d_resume(struct device *dev) { unsigned long flags; g2d_lock(&ctrl->drvlock); g2d_spin_lock(&ctrl->bltlock, flags); atomic_set(&ctrl->suspended, 0); g2d_spin_unlock(&ctrl->bltlock, flags); g2d_unlock(&ctrl->drvlock); /* G2D clk gating mask */ if (ip_is_g2d_5ar2()) { fimg2d_clk_on(ctrl); fimg2d_clk_off(ctrl); } fimg2d_info("resume... done\n"); return 0; }
static int fimg2d_suspend(struct device *dev) { unsigned long flags; int retry = POLL_RETRY; g2d_lock(&ctrl->drvlock); g2d_spin_lock(&ctrl->bltlock, flags); atomic_set(&ctrl->suspended, 1); g2d_spin_unlock(&ctrl->bltlock, flags); while (retry--) { if (fimg2d_queue_is_empty(&ctrl->cmd_q)) break; mdelay(POLL_TIMEOUT); } g2d_unlock(&ctrl->drvlock); fimg2d_info("suspend... done\n"); return 0; }
static int fimg2d_suspend(struct device *dev) { unsigned long flags; int retry = POLL_RETRY; g2d_spin_lock(&ctrl->bltlock, flags); atomic_set(&ctrl->suspended, 1); g2d_spin_unlock(&ctrl->bltlock, flags); while (retry--) { if (fimg2d_queue_is_empty(&ctrl->cmd_q)) break; mdelay(POLL_TIMEOUT); } if (ip_is_g2d_5h() || ip_is_g2d_5hp()) exynos5433_fimg2d_clk_set_osc(ctrl); fimg2d_info("suspend... done\n"); return 0; }
static int fimg2d_resume(struct device *dev) { unsigned long flags; int ret = 0; g2d_spin_lock(&ctrl->bltlock, flags); atomic_set(&ctrl->suspended, 0); g2d_spin_unlock(&ctrl->bltlock, flags); /* G2D clk gating mask */ if (ip_is_g2d_5ar2()) { fimg2d_clk_on(ctrl); fimg2d_clk_off(ctrl); } else if (ip_is_g2d_5hp()) { ret = exynos5430_fimg2d_clk_set(ctrl); if (ret) { fimg2d_err("failed to exynos5430_fimg2d_clk_set()\n"); return -ENOENT; } } fimg2d_info("resume... done\n"); return ret; }
static int parse_g2d_qos_platdata(struct device_node *np, char *node_name, struct fimg2d_qos *pdata) { int ret = 0; struct device_node *np_qos; np_qos = of_find_node_by_name(np, node_name); if (!np_qos) { pr_err("%s: could not find fimg2d qos platdata node\n", node_name); return -EINVAL; } of_property_read_u32(np_qos, "freq_int", &pdata->freq_int); of_property_read_u32(np_qos, "freq_mif", &pdata->freq_mif); of_property_read_u32(np_qos, "freq_cpu", &pdata->freq_cpu); of_property_read_u32(np_qos, "freq_kfc", &pdata->freq_kfc); fimg2d_info("cpu_min:%d, kfc_min:%d, mif_min:%d, int_min:%d\n" , pdata->freq_cpu, pdata->freq_kfc , pdata->freq_mif, pdata->freq_int); return ret; }
static int fimg2d_probe(struct platform_device *pdev) { int ret = 0; struct resource *res; if (!to_fimg2d_plat(&pdev->dev)) { fimg2d_err("failed to get platform data\n"); return -ENOMEM; } /* global structure */ ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); if (!ctrl) { fimg2d_err("failed to allocate memory for controller\n"); return -ENOMEM; } /* setup global ctrl */ ret = fimg2d_setup_controller(ctrl); if (ret) { fimg2d_err("failed to setup controller\n"); goto drv_free; } ctrl->dev = &pdev->dev; /* memory region */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { fimg2d_err("failed to get resource\n"); ret = -ENOENT; goto drv_free; } ctrl->mem = request_mem_region(res->start, resource_size(res), pdev->name); if (!ctrl->mem) { fimg2d_err("failed to request memory region\n"); ret = -ENOMEM; goto res_free; } /* ioremap */ ctrl->regs = ioremap(res->start, resource_size(res)); if (!ctrl->regs) { fimg2d_err("failed to ioremap for SFR\n"); ret = -ENOENT; goto mem_free; } fimg2d_info("base address: 0x%lx\n", (unsigned long)res->start); /* irq */ ctrl->irq = platform_get_irq(pdev, 0); if (!ctrl->irq) { fimg2d_err("failed to get irq resource\n"); ret = -ENOENT; goto reg_unmap; } fimg2d_info("irq: %d\n", ctrl->irq); ret = request_irq(ctrl->irq, fimg2d_irq, IRQF_DISABLED, pdev->name, ctrl); if (ret) { fimg2d_err("failed to request irq\n"); ret = -ENOENT; goto reg_unmap; } ret = fimg2d_clk_setup(ctrl); if (ret) { fimg2d_err("failed to setup clk\n"); ret = -ENOENT; goto irq_free; } #ifdef CONFIG_PM_RUNTIME pm_runtime_enable(ctrl->dev); fimg2d_info("enable runtime pm\n"); pm_runtime_get_sync(ctrl->dev); #else fimg2d_clk_on(ctrl); #endif exynos_sysmmu_set_fault_handler(ctrl->dev, fimg2d_sysmmu_fault_handler); fimg2d_info("register sysmmu page fault handler\n"); /* misc register */ ret = misc_register(&fimg2d_dev); if (ret) { fimg2d_err("failed to register misc driver\n"); goto clk_release; } #ifdef CONFIG_ARM_EXYNOS_IKS_CPUFREQ pm_qos_add_request(&exynos5_g2d_cpu_qos, PM_QOS_CPU_FREQ_MIN, 0); pm_qos_add_request(&exynos5_g2d_mif_qos, PM_QOS_BUS_THROUGHPUT, 0); #endif return 0; clk_release: #ifdef CONFIG_PM_RUNTIME pm_runtime_disable(ctrl->dev); #else fimg2d_clk_off(ctrl); #endif fimg2d_clk_release(ctrl); irq_free: free_irq(ctrl->irq, NULL); reg_unmap: iounmap(ctrl->regs); mem_free: kfree(ctrl->mem); res_free: release_resource(ctrl->mem); drv_free: #ifdef BLIT_WORKQUE if (ctrl->work_q) destroy_workqueue(ctrl->work_q); #endif mutex_destroy(&ctrl->drvlock); kfree(ctrl); return ret; }
static long fimg2d_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int ret = 0; struct fimg2d_context *ctx; struct mm_struct *mm; ctx = file->private_data; switch (cmd) { case FIMG2D_BITBLT_BLIT: mm = get_task_mm(current); if(!mm) { fimg2d_err("no mm for ctx\n"); return -ENXIO; } fimg2d_clk_on(ctrl); g2d_lock(&ctrl->drvlock); ctx->mm = mm; if (atomic_read(&ctrl->drvact) || atomic_read(&ctrl->suspended)) { fimg2d_err("driver is unavailable, do sw fallback\n"); g2d_unlock(&ctrl->drvlock); fimg2d_clk_off(ctrl); mmput(mm); return -EPERM; } ret = fimg2d_add_command(ctrl, ctx, (struct fimg2d_blit __user *)arg); if (ret) { fimg2d_err("add command not allowed.\n"); g2d_unlock(&ctrl->drvlock); fimg2d_clk_off(ctrl); mmput(mm); return ret; } ret = fimg2d_request_bitblt(ctrl, ctx); if (ret) { fimg2d_err("request bitblit not allowed.\n"); g2d_unlock(&ctrl->drvlock); fimg2d_clk_off(ctrl); mmput(mm); return -EBUSY; } g2d_unlock(&ctrl->drvlock); fimg2d_clk_off(ctrl); mmput(mm); break; case FIMG2D_BITBLT_VERSION: { struct fimg2d_version ver; struct fimg2d_platdata *pdata; pdata = to_fimg2d_plat(ctrl->dev); ver.hw = pdata->hw_ver; ver.sw = 0; fimg2d_info("version info. hw(0x%x), sw(0x%x)\n", ver.hw, ver.sw); if (copy_to_user((void *)arg, &ver, sizeof(ver))) return -EFAULT; break; } case FIMG2D_BITBLT_ACTIVATE: { enum driver_act act; if (copy_from_user(&act, (void *)arg, sizeof(act))) return -EFAULT; g2d_lock(&ctrl->drvlock); atomic_set(&ctrl->drvact, act); if (act == DRV_ACT) fimg2d_info("fimg2d driver is activated\n"); else fimg2d_info("fimg2d driver is deactivated\n"); g2d_unlock(&ctrl->drvlock); break; } default: fimg2d_err("unknown ioctl\n"); ret = -EFAULT; break; } return ret; }
static int fimg2d_probe(struct platform_device *pdev) { int ret = 0; struct resource *res; struct fimg2d_platdata *pdata; #ifdef CONFIG_OF struct device *dev = &pdev->dev; int id = 0; #else pdata = to_fimg2d_plat(&pdev->dev); #endif dev_info(&pdev->dev, "++%s\n", __func__); #ifdef CONFIG_OF if (dev->of_node) { id = of_alias_get_id(pdev->dev.of_node, "fimg2d"); } else { id = pdev->id; pdata = dev->platform_data; if (!pdata) { dev_err(&pdev->dev, "no platform data\n"); return -EINVAL; } } #else if (!to_fimg2d_plat(&pdev->dev)) { fimg2d_err("failed to get platform data\n"); return -ENOMEM; } #endif /* global structure */ ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); if (!ctrl) { fimg2d_err("failed to allocate memory for controller\n"); return -ENOMEM; } #ifdef CONFIG_OF pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); if (!pdata) { fimg2d_err("failed to allocate memory for controller\n"); kfree(ctrl); return -ENOMEM; } ctrl->pdata = pdata; g2d_parse_dt(dev->of_node, ctrl->pdata); #endif /* setup global ctrl */ ret = fimg2d_setup_controller(ctrl); if (ret) { fimg2d_err("failed to setup controller\n"); goto drv_free; } ctrl->dev = &pdev->dev; /* memory region */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { fimg2d_err("failed to get resource\n"); ret = -ENOENT; goto drv_free; } ctrl->mem = request_mem_region(res->start, resource_size(res), pdev->name); if (!ctrl->mem) { fimg2d_err("failed to request memory region\n"); ret = -ENOMEM; goto drv_free; } /* ioremap */ ctrl->regs = ioremap(res->start, resource_size(res)); if (!ctrl->regs) { fimg2d_err("failed to ioremap for SFR\n"); ret = -ENOENT; goto mem_free; } fimg2d_debug("base address: 0x%lx\n", (unsigned long)res->start); /* irq */ ctrl->irq = platform_get_irq(pdev, 0); if (!ctrl->irq) { fimg2d_err("failed to get irq resource\n"); ret = -ENOENT; goto reg_unmap; } fimg2d_debug("irq: %d\n", ctrl->irq); ret = request_irq(ctrl->irq, fimg2d_irq, IRQF_DISABLED, pdev->name, ctrl); if (ret) { fimg2d_err("failed to request irq\n"); ret = -ENOENT; goto reg_unmap; } ret = fimg2d_clk_setup(ctrl); if (ret) { fimg2d_err("failed to setup clk\n"); ret = -ENOENT; goto irq_free; } spin_lock_init(&ctrl->qoslock); #ifdef CONFIG_PM_RUNTIME pm_runtime_enable(ctrl->dev); fimg2d_info("enable runtime pm\n"); #else fimg2d_clk_on(ctrl); #endif #ifdef FIMG2D_IOVMM_PAGETABLE exynos_create_iovmm(dev, 3, 3); #endif iovmm_set_fault_handler(dev, fimg2d_sysmmu_fault_handler, ctrl); fimg2d_debug("register sysmmu page fault handler\n"); /* misc register */ ret = misc_register(&fimg2d_dev); if (ret) { fimg2d_err("failed to register misc driver\n"); goto clk_release; } fimg2d_pm_qos_add(ctrl); dev_info(&pdev->dev, "fimg2d registered successfully\n"); return 0; clk_release: #ifdef CONFIG_PM_RUNTIME pm_runtime_disable(ctrl->dev); #else fimg2d_clk_off(ctrl); #endif fimg2d_clk_release(ctrl); irq_free: free_irq(ctrl->irq, NULL); reg_unmap: iounmap(ctrl->regs); mem_free: release_mem_region(res->start, resource_size(res)); drv_free: #ifdef BLIT_WORKQUE if (ctrl->work_q) destroy_workqueue(ctrl->work_q); #endif mutex_destroy(&ctrl->drvlock); #ifdef CONFIG_OF kfree(pdata); #endif kfree(ctrl); return ret; }
static long fimg2d_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int ret = 0; struct fimg2d_context *ctx; struct mm_struct *mm; struct fimg2d_dma *usr_dst; ctx = file->private_data; switch (cmd) { case FIMG2D_BITBLT_BLIT: mm = get_task_mm(current); if (!mm) { fimg2d_err("no mm for ctx\n"); return -ENXIO; } g2d_lock(&ctrl->drvlock); ctx->mm = mm; if (atomic_read(&ctrl->drvact) || atomic_read(&ctrl->suspended)) { fimg2d_err("driver is unavailable, do sw fallback\n"); g2d_unlock(&ctrl->drvlock); mmput(mm); return -EPERM; } ret = fimg2d_add_command(ctrl, ctx, (struct fimg2d_blit __user *)arg); if (ret) { fimg2d_err("add command not allowed.\n"); g2d_unlock(&ctrl->drvlock); mmput(mm); return ret; } fimg2d_pm_qos_update(ctrl, FIMG2D_QOS_ON); usr_dst = kzalloc(sizeof(struct fimg2d_dma), GFP_KERNEL); if (!usr_dst) { fimg2d_err("failed to allocate memory for fimg2d_dma\n"); g2d_unlock(&ctrl->drvlock); mmput(mm); return -ENOMEM; } ret = store_user_dst((struct fimg2d_blit __user *)arg, usr_dst); if (ret) { fimg2d_err("store_user_dst() not allowed.\n"); g2d_unlock(&ctrl->drvlock); kfree(usr_dst); mmput(mm); return ret; } ret = fimg2d_request_bitblt(ctrl, ctx); if (ret) { fimg2d_info("request bitblit not allowed, " "so passing to s/w fallback.\n"); g2d_unlock(&ctrl->drvlock); kfree(usr_dst); mmput(mm); return -EBUSY; } g2d_unlock(&ctrl->drvlock); fimg2d_debug("addr : %p, size : %zd\n", (void *)usr_dst->addr, usr_dst->size); #ifndef CCI_SNOOP fimg2d_dma_unsync_inner(usr_dst->addr, usr_dst->size, DMA_FROM_DEVICE); #endif kfree(usr_dst); mmput(mm); break; case FIMG2D_BITBLT_VERSION: { struct fimg2d_version ver; struct fimg2d_platdata *pdata; #ifdef CONFIG_OF pdata = ctrl->pdata; #else pdata = to_fimg2d_plat(ctrl->dev); #endif ver.hw = pdata->hw_ver; ver.sw = 0; fimg2d_info("version info. hw(0x%x), sw(0x%x)\n", ver.hw, ver.sw); if (copy_to_user((void *)arg, &ver, sizeof(ver))) return -EFAULT; break; } case FIMG2D_BITBLT_ACTIVATE: { enum driver_act act; if (copy_from_user(&act, (void *)arg, sizeof(act))) return -EFAULT; g2d_lock(&ctrl->drvlock); atomic_set(&ctrl->drvact, act); if (act == DRV_ACT) { fimg2d_power_control(ctrl, FIMG2D_PW_OFF); fimg2d_info("fimg2d driver is activated\n"); } else { fimg2d_power_control(ctrl, FIMG2D_PW_ON); fimg2d_info("fimg2d driver is deactivated\n"); } g2d_unlock(&ctrl->drvlock); break; } default: fimg2d_err("unknown ioctl\n"); ret = -EFAULT; break; } return ret; }