1/* 2 * drivers/media/platform/s5p-mfc/s5p_mfc_opr.c 3 * 4 * Samsung MFC (Multi Function Codec - FIMV) driver 5 * This file contains hw related functions. 6 * 7 * Kamil Debski, Copyright (c) 2012 Samsung Electronics Co., Ltd. 8 * http://www.samsung.com/ 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License version 2 as 12 * published by the Free Software Foundation. 13 */ 14 15#include "s5p_mfc_debug.h" 16#include "s5p_mfc_opr.h" 17#include "s5p_mfc_opr_v5.h" 18#include "s5p_mfc_opr_v6.h" 19 20static struct s5p_mfc_hw_ops *s5p_mfc_ops; 21 22void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev) 23{ 24 if (IS_MFCV6_PLUS(dev)) { 25 s5p_mfc_ops = s5p_mfc_init_hw_ops_v6(); 26 dev->warn_start = S5P_FIMV_ERR_WARNINGS_START_V6; 27 } else { 28 s5p_mfc_ops = s5p_mfc_init_hw_ops_v5(); 29 dev->warn_start = S5P_FIMV_ERR_WARNINGS_START; 30 } 31 dev->mfc_ops = s5p_mfc_ops; 32} 33 34void s5p_mfc_init_regs(struct s5p_mfc_dev *dev) 35{ 36 if (IS_MFCV6_PLUS(dev)) 37 dev->mfc_regs = s5p_mfc_init_regs_v6_plus(dev); 38} 39 40int s5p_mfc_alloc_priv_buf(struct device *dev, dma_addr_t base, 41 struct s5p_mfc_priv_buf *b) 42{ 43 mfc_debug(3, "Allocating priv: %zu\n", b->size); 44 45 b->virt = dma_alloc_coherent(dev, b->size, &b->dma, GFP_KERNEL); 46 47 if (!b->virt) { 48 mfc_err("Allocating private buffer failed\n"); 49 return -ENOMEM; 50 } 51 52 if (b->dma < base) { 53 mfc_err("Invaling memory configuration!\n"); 54 mfc_err("Allocated buffer (%pad) is lower than memory base address (%pad)\n", 55 &b->dma, &base); 56 dma_free_coherent(dev, b->size, b->virt, b->dma); 57 return -ENOMEM; 58 } 59 60 mfc_debug(3, "Allocated addr %p %pad\n", b->virt, &b->dma); 61 return 0; 62} 63 64void s5p_mfc_release_priv_buf(struct device *dev, 65 struct s5p_mfc_priv_buf *b) 66{ 67 if (b->virt) { 68 dma_free_coherent(dev, b->size, b->virt, b->dma); 69 b->virt = NULL; 70 b->dma = 0; 71 b->size = 0; 72 } 73} 74 75