ipu-smfc.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * The code contained herein is licensed under the GNU General Public
  5. * License. You may obtain a copy of the GNU General Public License
  6. * Version 2 or later at the following locations:
  7. *
  8. * http://www.opensource.org/licenses/gpl-license.html
  9. * http://www.gnu.org/copyleft/gpl.html
  10. */
  11. #define DEBUG
  12. #include <linux/export.h>
  13. #include <linux/types.h>
  14. #include <linux/init.h>
  15. #include <linux/io.h>
  16. #include <linux/errno.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/delay.h>
  19. #include <linux/clk.h>
  20. #include <video/imx-ipu-v3.h>
  21. #include "ipu-prv.h"
  22. struct ipu_smfc_priv {
  23. void __iomem *base;
  24. spinlock_t lock;
  25. };
  26. /*SMFC Registers */
  27. #define SMFC_MAP 0x0000
  28. #define SMFC_WMC 0x0004
  29. #define SMFC_BS 0x0008
  30. int ipu_smfc_set_burstsize(struct ipu_soc *ipu, int channel, int burstsize)
  31. {
  32. struct ipu_smfc_priv *smfc = ipu->smfc_priv;
  33. unsigned long flags;
  34. u32 val, shift;
  35. spin_lock_irqsave(&smfc->lock, flags);
  36. shift = channel * 4;
  37. val = readl(smfc->base + SMFC_BS);
  38. val &= ~(0xf << shift);
  39. val |= burstsize << shift;
  40. writel(val, smfc->base + SMFC_BS);
  41. spin_unlock_irqrestore(&smfc->lock, flags);
  42. return 0;
  43. }
  44. EXPORT_SYMBOL_GPL(ipu_smfc_set_burstsize);
  45. int ipu_smfc_map_channel(struct ipu_soc *ipu, int channel, int csi_id, int mipi_id)
  46. {
  47. struct ipu_smfc_priv *smfc = ipu->smfc_priv;
  48. unsigned long flags;
  49. u32 val, shift;
  50. spin_lock_irqsave(&smfc->lock, flags);
  51. shift = channel * 3;
  52. val = readl(smfc->base + SMFC_MAP);
  53. val &= ~(0x7 << shift);
  54. val |= ((csi_id << 2) | mipi_id) << shift;
  55. writel(val, smfc->base + SMFC_MAP);
  56. spin_unlock_irqrestore(&smfc->lock, flags);
  57. return 0;
  58. }
  59. EXPORT_SYMBOL_GPL(ipu_smfc_map_channel);
  60. int ipu_smfc_init(struct ipu_soc *ipu, struct device *dev,
  61. unsigned long base)
  62. {
  63. struct ipu_smfc_priv *smfc;
  64. smfc = devm_kzalloc(dev, sizeof(*smfc), GFP_KERNEL);
  65. if (!smfc)
  66. return -ENOMEM;
  67. ipu->smfc_priv = smfc;
  68. spin_lock_init(&smfc->lock);
  69. smfc->base = devm_ioremap(dev, base, PAGE_SIZE);
  70. if (!smfc->base)
  71. return -ENOMEM;
  72. pr_debug("%s: ioremap 0x%08lx -> %p\n", __func__, base, smfc->base);
  73. return 0;
  74. }
  75. void ipu_smfc_exit(struct ipu_soc *ipu)
  76. {
  77. }