15 #include <linux/module.h>
16 #include <linux/export.h>
17 #include <linux/types.h>
26 #include <linux/list.h>
83 val |= 1 << (channel->
num % 32);
90 u32 bit = (wbs >> 8) % 160;
98 pr_debug(
"%s %d %d %d\n", __func__, word, bit , size);
100 val =
readl(&base->word[word].data[i]);
101 val &= ~(mask << ofs);
103 writel(val, &base->word[word].data[i]);
105 if ((bit + size - 1) / 32 > i) {
106 val =
readl(&base->word[word].data[i + 1]);
107 val &= ~(mask >> (ofs ? (32 - ofs) : 0));
108 val |= v >> (ofs ? (32 - ofs) : 0);
109 writel(val, &base->word[word].data[i + 1]);
116 u32 bit = (wbs >> 8) % 160;
124 pr_debug(
"%s %d %d %d\n", __func__, word, bit , size);
126 val = (
readl(&base->word[word].data[i]) >> ofs) & mask;
128 if ((bit + size - 1) / 32 >
i) {
130 tmp =
readl(&base->word[word].data[i + 1]);
131 tmp &= mask >> (ofs ? (32 - ofs) : 0);
132 val |= tmp << (ofs ? (32 - ofs) : 0);
231 switch (pixel_format) {
244 int u_offset, v_offset;
247 switch (pixel_format) {
249 uv_stride = stride / 2;
250 u_offset = stride *
height;
251 v_offset = u_offset + (uv_stride * height / 2);
259 static struct ipu_rgb def_rgb_32 = {
260 .red = { .offset = 16, .length = 8, },
261 .green = { .offset = 8, .length = 8, },
262 .blue = { .offset = 0, .length = 8, },
263 .transp = { .offset = 24, .length = 8, },
264 .bits_per_pixel = 32,
267 static struct ipu_rgb def_bgr_32 = {
268 .red = { .offset = 16, .length = 8, },
269 .green = { .offset = 8, .length = 8, },
270 .blue = { .offset = 0, .length = 8, },
271 .transp = { .offset = 24, .length = 8, },
272 .bits_per_pixel = 32,
275 static struct ipu_rgb def_rgb_24 = {
276 .red = { .offset = 0, .length = 8, },
277 .green = { .offset = 8, .length = 8, },
278 .blue = { .offset = 16, .length = 8, },
279 .transp = { .offset = 0, .length = 0, },
280 .bits_per_pixel = 24,
283 static struct ipu_rgb def_bgr_24 = {
284 .red = { .offset = 16, .length = 8, },
285 .green = { .offset = 8, .length = 8, },
286 .blue = { .offset = 0, .length = 8, },
287 .transp = { .offset = 0, .length = 0, },
288 .bits_per_pixel = 24,
291 static struct ipu_rgb def_rgb_16 = {
292 .red = { .offset = 11, .length = 5, },
293 .green = { .offset = 5, .length = 6, },
294 .blue = { .offset = 0, .length = 5, },
295 .transp = { .offset = 0, .length = 0, },
296 .bits_per_pixel = 16,
299 #define Y_OFFSET(pix, x, y) ((x) + pix->width * (y))
300 #define U_OFFSET(pix, x, y) ((pix->width * pix->height) + \
301 (pix->width * (y) / 4) + (x) / 2)
302 #define V_OFFSET(pix, x, y) ((pix->width * pix->height) + \
303 (pix->width * pix->height / 4) + \
304 (pix->width * (y) / 4) + (x) / 2)
308 switch (pixelformat) {
358 int y_offset, u_offset, v_offset;
360 pr_debug(
"%s: resolution: %dx%d stride: %d\n",
364 ipu_cpmem_set_resolution(cpmem, image->
rect.width,
374 image->
rect.top) - y_offset;
376 image->
rect.top) - y_offset;
380 ipu_cpmem_set_buffer(cpmem, 0, image->
phys + y_offset);
383 ipu_cpmem_set_buffer(cpmem, 0, image->
phys +
384 image->
rect.left * 2 +
385 image->
rect.top * image->
pix.bytesperline);
389 ipu_cpmem_set_buffer(cpmem, 0, image->
phys +
390 image->
rect.left * 4 +
391 image->
rect.top * image->
pix.bytesperline);
394 ipu_cpmem_set_buffer(cpmem, 0, image->
phys +
395 image->
rect.left * 2 +
396 image->
rect.top * image->
pix.bytesperline);
400 ipu_cpmem_set_buffer(cpmem, 0, image->
phys +
401 image->
rect.left * 3 +
402 image->
rect.top * image->
pix.bytesperline);
414 switch (pixelformat) {
445 channel = ERR_PTR(-
EBUSY);
473 #define idma_mask(ch) (1 << (ch & 0x1f))
491 spin_unlock_irqrestore(&ipu->
lock, flags);
515 spin_unlock_irqrestore(&ipu->
lock, lock_flags);
541 spin_unlock_irqrestore(&ipu->
lock, lock_flags);
550 unsigned int chno = channel->
num;
561 spin_unlock_irqrestore(&ipu->
lock, flags);
577 spin_unlock_irqrestore(&ipu->
lock, flags);
594 dev_warn(ipu->
dev,
"disabling busy idmac channel %d\n",
609 ipu_cm_write(ipu, 0xf0000000,
IPU_GPR);
623 ipu_cm_write(ipu, 0x0,
IPU_GPR);
630 spin_unlock_irqrestore(&ipu->
lock, flags);
643 while (ipu_cm_read(ipu,
IPU_MEM_RST) & 0x80000000) {
669 .cm_ofs = 0x1e000000,
670 .cpmem_ofs = 0x1f000000,
671 .srm_ofs = 0x1f040000,
672 .tpm_ofs = 0x1f060000,
673 .disp0_ofs = 0x1e040000,
674 .disp1_ofs = 0x1e048000,
675 .dc_tmpl_ofs = 0x1f080000,
676 .vdi_ofs = 0x1e068000,
682 .cm_ofs = 0x06000000,
683 .cpmem_ofs = 0x07000000,
684 .srm_ofs = 0x07040000,
685 .tpm_ofs = 0x07060000,
686 .disp0_ofs = 0x06040000,
687 .disp1_ofs = 0x06048000,
688 .dc_tmpl_ofs = 0x07080000,
689 .vdi_ofs = 0x06068000,
695 .cm_ofs = 0x00200000,
696 .cpmem_ofs = 0x00300000,
697 .srm_ofs = 0x00340000,
698 .tpm_ofs = 0x00360000,
699 .disp0_ofs = 0x00240000,
700 .disp1_ofs = 0x00248000,
701 .dc_tmpl_ofs = 0x00380000,
702 .vdi_ofs = 0x00268000,
707 { .compatible =
"fsl,imx51-ipu", .data = &ipu_type_imx51, },
708 { .compatible =
"fsl,imx53-ipu", .data = &ipu_type_imx53, },
709 { .compatible =
"fsl,imx6q-ipu", .data = &ipu_type_imx6q, },
714 static int ipu_submodules_init(
struct ipu_soc *ipu,
740 unit =
"dc_template";
768 dev_err(&pdev->
dev,
"init %s failed with %d\n", unit, ret);
772 static void ipu_irq_handle(
struct ipu_soc *ipu,
const int *
regs,
int num_regs)
775 int i,
bit, irq_base;
777 for (i = 0; i < num_regs; i++) {
790 struct ipu_soc *ipu = irq_desc_get_handler_data(desc);
791 const int int_reg[] = { 0, 1, 2, 3, 10, 11, 12, 13, 14};
794 chained_irq_enter(chip, desc);
796 ipu_irq_handle(ipu, int_reg,
ARRAY_SIZE(int_reg));
798 chained_irq_exit(chip, desc);
801 static void ipu_err_irq_handler(
unsigned int irq,
struct irq_desc *desc)
803 struct ipu_soc *ipu = irq_desc_get_handler_data(desc);
804 const int int_reg[] = { 4, 5, 8, 9};
805 struct irq_chip *chip = irq_get_chip(irq);
807 chained_irq_enter(chip, desc);
809 ipu_irq_handle(ipu, int_reg,
ARRAY_SIZE(int_reg));
811 chained_irq_exit(chip, desc);
814 static void ipu_ack_irq(
struct irq_data *
d)
816 struct ipu_soc *ipu = irq_data_get_irq_chip_data(d);
819 ipu_cm_write(ipu, 1 << (irq % 32),
IPU_INT_STAT(irq / 32));
822 static void ipu_unmask_irq(
struct irq_data *d)
824 struct ipu_soc *ipu = irq_data_get_irq_chip_data(d);
832 reg |= 1 << (irq % 32);
835 spin_unlock_irqrestore(&ipu->
lock, flags);
838 static void ipu_mask_irq(
struct irq_data *d)
840 struct ipu_soc *ipu = irq_data_get_irq_chip_data(d);
848 reg &= ~(1 << (irq % 32));
851 spin_unlock_irqrestore(&ipu->
lock, flags);
854 static struct irq_chip ipu_irq_chip = {
856 .irq_ack = ipu_ack_irq,
857 .irq_mask = ipu_mask_irq,
858 .irq_unmask = ipu_unmask_irq,
868 static void ipu_submodules_exit(
struct ipu_soc *ipu)
877 static int platform_remove_devices_fn(
struct device *dev,
void *
unused)
886 static void platform_device_unregister_children(
struct platform_device *pdev)
905 .name =
"imx-ipuv3-crtc",
914 .name =
"imx-ipuv3-crtc",
918 static int ipu_client_id;
920 static int ipu_add_subdevice_pdata(
struct device *dev,
925 pdev = platform_device_register_data(dev, reg->
name, ipu_client_id++,
928 return pdev ? 0 : -
EINVAL;
931 static int ipu_add_client_devices(
struct ipu_soc *ipu)
936 for (i = 0; i <
ARRAY_SIZE(client_reg); i++) {
938 ret = ipu_add_subdevice_pdata(ipu->
dev, reg);
951 static int ipu_irq_init(
struct ipu_soc *ipu)
965 irq_set_chained_handler(ipu->
irq_sync, ipu_irq_handler);
967 irq_set_chained_handler(ipu->
irq_err, ipu_err_irq_handler);
973 static void ipu_irq_exit(
struct ipu_soc *ipu)
997 unsigned long ipu_base;
998 int i,
ret, irq_sync, irq_err;
1001 devtype = of_id->
data;
1009 dev_info(&pdev->
dev,
"irq_sync: %d irq_err: %d\n",
1012 if (!res || irq_sync < 0 || irq_err < 0)
1015 ipu_base = res->
start;
1021 for (i = 0; i < 64; i++)
1030 ipu_base + devtype->
cm_ofs);
1062 goto failed_ioremap;
1066 if (IS_ERR(ipu->
clk)) {
1067 ret = PTR_ERR(ipu->
clk);
1068 dev_err(&pdev->
dev,
"clk_get failed with %d", ret);
1069 goto failed_clk_get;
1072 platform_set_drvdata(pdev, ipu);
1074 clk_prepare_enable(ipu->
clk);
1080 ret = ipu_irq_init(ipu);
1082 goto out_failed_irq;
1090 ret = ipu_submodules_init(ipu, pdev, ipu_base, ipu->
clk);
1092 goto failed_submodules_init;
1094 ret = ipu_add_client_devices(ipu);
1096 dev_err(&pdev->
dev,
"adding client devices failed with %d\n",
1098 goto failed_add_clients;
1104 ipu_submodules_exit(ipu);
1105 failed_submodules_init:
1108 clk_disable_unprepare(ipu->
clk);
1116 struct ipu_soc *ipu = platform_get_drvdata(pdev);
1121 platform_device_unregister_children(pdev);
1122 ipu_submodules_exit(ipu);
1125 clk_disable_unprepare(ipu->
clk);
1132 .name =
"imx-ipuv3",
1133 .of_match_table = imx_ipu_dt_ids,