Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * linux/drivers/video/omap2/dss/dpi.c
0004  *
0005  * Copyright (C) 2009 Nokia Corporation
0006  * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
0007  *
0008  * Some code and ideas taken from drivers/video/omap/ driver
0009  * by Imre Deak.
0010  */
0011 
0012 #define DSS_SUBSYS_NAME "DPI"
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/delay.h>
0016 #include <linux/export.h>
0017 #include <linux/err.h>
0018 #include <linux/errno.h>
0019 #include <linux/platform_device.h>
0020 #include <linux/regulator/consumer.h>
0021 #include <linux/string.h>
0022 #include <linux/of.h>
0023 #include <linux/clk.h>
0024 #include <linux/component.h>
0025 
0026 #include <video/omapfb_dss.h>
0027 
0028 #include "dss.h"
0029 #include "dss_features.h"
0030 
0031 #define HSDIV_DISPC 0
0032 
0033 struct dpi_data {
0034     struct platform_device *pdev;
0035 
0036     struct regulator *vdds_dsi_reg;
0037     struct dss_pll *pll;
0038 
0039     struct mutex lock;
0040 
0041     struct omap_video_timings timings;
0042     struct dss_lcd_mgr_config mgr_config;
0043     int data_lines;
0044 
0045     struct omap_dss_device output;
0046 
0047     bool port_initialized;
0048 };
0049 
0050 static struct dpi_data *dpi_get_data_from_dssdev(struct omap_dss_device *dssdev)
0051 {
0052     return container_of(dssdev, struct dpi_data, output);
0053 }
0054 
0055 /* only used in non-DT mode */
0056 static struct dpi_data *dpi_get_data_from_pdev(struct platform_device *pdev)
0057 {
0058     return platform_get_drvdata(pdev);
0059 }
0060 
0061 static struct dss_pll *dpi_get_pll(enum omap_channel channel)
0062 {
0063     /*
0064      * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL
0065      * would also be used for DISPC fclk. Meaning, when the DPI output is
0066      * disabled, DISPC clock will be disabled, and TV out will stop.
0067      */
0068     switch (omapdss_get_version()) {
0069     case OMAPDSS_VER_OMAP24xx:
0070     case OMAPDSS_VER_OMAP34xx_ES1:
0071     case OMAPDSS_VER_OMAP34xx_ES3:
0072     case OMAPDSS_VER_OMAP3630:
0073     case OMAPDSS_VER_AM35xx:
0074     case OMAPDSS_VER_AM43xx:
0075         return NULL;
0076 
0077     case OMAPDSS_VER_OMAP4430_ES1:
0078     case OMAPDSS_VER_OMAP4430_ES2:
0079     case OMAPDSS_VER_OMAP4:
0080         switch (channel) {
0081         case OMAP_DSS_CHANNEL_LCD:
0082             return dss_pll_find("dsi0");
0083         case OMAP_DSS_CHANNEL_LCD2:
0084             return dss_pll_find("dsi1");
0085         default:
0086             return NULL;
0087         }
0088 
0089     case OMAPDSS_VER_OMAP5:
0090         switch (channel) {
0091         case OMAP_DSS_CHANNEL_LCD:
0092             return dss_pll_find("dsi0");
0093         case OMAP_DSS_CHANNEL_LCD3:
0094             return dss_pll_find("dsi1");
0095         default:
0096             return NULL;
0097         }
0098 
0099     case OMAPDSS_VER_DRA7xx:
0100         switch (channel) {
0101         case OMAP_DSS_CHANNEL_LCD:
0102         case OMAP_DSS_CHANNEL_LCD2:
0103             return dss_pll_find("video0");
0104         case OMAP_DSS_CHANNEL_LCD3:
0105             return dss_pll_find("video1");
0106         default:
0107             return NULL;
0108         }
0109 
0110     default:
0111         return NULL;
0112     }
0113 }
0114 
0115 static enum omap_dss_clk_source dpi_get_alt_clk_src(enum omap_channel channel)
0116 {
0117     switch (channel) {
0118     case OMAP_DSS_CHANNEL_LCD:
0119         return OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC;
0120     case OMAP_DSS_CHANNEL_LCD2:
0121         return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
0122     case OMAP_DSS_CHANNEL_LCD3:
0123         return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
0124     default:
0125         /* this shouldn't happen */
0126         WARN_ON(1);
0127         return OMAP_DSS_CLK_SRC_FCK;
0128     }
0129 }
0130 
0131 struct dpi_clk_calc_ctx {
0132     struct dss_pll *pll;
0133 
0134     /* inputs */
0135 
0136     unsigned long pck_min, pck_max;
0137 
0138     /* outputs */
0139 
0140     struct dss_pll_clock_info dsi_cinfo;
0141     unsigned long fck;
0142     struct dispc_clock_info dispc_cinfo;
0143 };
0144 
0145 static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
0146         unsigned long pck, void *data)
0147 {
0148     struct dpi_clk_calc_ctx *ctx = data;
0149 
0150     /*
0151      * Odd dividers give us uneven duty cycle, causing problem when level
0152      * shifted. So skip all odd dividers when the pixel clock is on the
0153      * higher side.
0154      */
0155     if (ctx->pck_min >= 100000000) {
0156         if (lckd > 1 && lckd % 2 != 0)
0157             return false;
0158 
0159         if (pckd > 1 && pckd % 2 != 0)
0160             return false;
0161     }
0162 
0163     ctx->dispc_cinfo.lck_div = lckd;
0164     ctx->dispc_cinfo.pck_div = pckd;
0165     ctx->dispc_cinfo.lck = lck;
0166     ctx->dispc_cinfo.pck = pck;
0167 
0168     return true;
0169 }
0170 
0171 
0172 static bool dpi_calc_hsdiv_cb(int m_dispc, unsigned long dispc,
0173         void *data)
0174 {
0175     struct dpi_clk_calc_ctx *ctx = data;
0176 
0177     /*
0178      * Odd dividers give us uneven duty cycle, causing problem when level
0179      * shifted. So skip all odd dividers when the pixel clock is on the
0180      * higher side.
0181      */
0182     if (m_dispc > 1 && m_dispc % 2 != 0 && ctx->pck_min >= 100000000)
0183         return false;
0184 
0185     ctx->dsi_cinfo.mX[HSDIV_DISPC] = m_dispc;
0186     ctx->dsi_cinfo.clkout[HSDIV_DISPC] = dispc;
0187 
0188     return dispc_div_calc(dispc, ctx->pck_min, ctx->pck_max,
0189             dpi_calc_dispc_cb, ctx);
0190 }
0191 
0192 
0193 static bool dpi_calc_pll_cb(int n, int m, unsigned long fint,
0194         unsigned long clkdco,
0195         void *data)
0196 {
0197     struct dpi_clk_calc_ctx *ctx = data;
0198 
0199     ctx->dsi_cinfo.n = n;
0200     ctx->dsi_cinfo.m = m;
0201     ctx->dsi_cinfo.fint = fint;
0202     ctx->dsi_cinfo.clkdco = clkdco;
0203 
0204     return dss_pll_hsdiv_calc(ctx->pll, clkdco,
0205         ctx->pck_min, dss_feat_get_param_max(FEAT_PARAM_DSS_FCK),
0206         dpi_calc_hsdiv_cb, ctx);
0207 }
0208 
0209 static bool dpi_calc_dss_cb(unsigned long fck, void *data)
0210 {
0211     struct dpi_clk_calc_ctx *ctx = data;
0212 
0213     ctx->fck = fck;
0214 
0215     return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max,
0216             dpi_calc_dispc_cb, ctx);
0217 }
0218 
0219 static bool dpi_dsi_clk_calc(struct dpi_data *dpi, unsigned long pck,
0220         struct dpi_clk_calc_ctx *ctx)
0221 {
0222     unsigned long clkin;
0223     unsigned long pll_min, pll_max;
0224 
0225     memset(ctx, 0, sizeof(*ctx));
0226     ctx->pll = dpi->pll;
0227     ctx->pck_min = pck - 1000;
0228     ctx->pck_max = pck + 1000;
0229 
0230     pll_min = 0;
0231     pll_max = 0;
0232 
0233     clkin = clk_get_rate(ctx->pll->clkin);
0234 
0235     return dss_pll_calc(ctx->pll, clkin,
0236             pll_min, pll_max,
0237             dpi_calc_pll_cb, ctx);
0238 }
0239 
0240 static bool dpi_dss_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx)
0241 {
0242     int i;
0243 
0244     /*
0245      * DSS fck gives us very few possibilities, so finding a good pixel
0246      * clock may not be possible. We try multiple times to find the clock,
0247      * each time widening the pixel clock range we look for, up to
0248      * +/- ~15MHz.
0249      */
0250 
0251     for (i = 0; i < 25; ++i) {
0252         bool ok;
0253 
0254         memset(ctx, 0, sizeof(*ctx));
0255         if (pck > 1000 * i * i * i)
0256             ctx->pck_min = max(pck - 1000 * i * i * i, 0lu);
0257         else
0258             ctx->pck_min = 0;
0259         ctx->pck_max = pck + 1000 * i * i * i;
0260 
0261         ok = dss_div_calc(pck, ctx->pck_min, dpi_calc_dss_cb, ctx);
0262         if (ok)
0263             return ok;
0264     }
0265 
0266     return false;
0267 }
0268 
0269 
0270 
0271 static int dpi_set_dsi_clk(struct dpi_data *dpi, enum omap_channel channel,
0272         unsigned long pck_req, unsigned long *fck, int *lck_div,
0273         int *pck_div)
0274 {
0275     struct dpi_clk_calc_ctx ctx;
0276     int r;
0277     bool ok;
0278 
0279     ok = dpi_dsi_clk_calc(dpi, pck_req, &ctx);
0280     if (!ok)
0281         return -EINVAL;
0282 
0283     r = dss_pll_set_config(dpi->pll, &ctx.dsi_cinfo);
0284     if (r)
0285         return r;
0286 
0287     dss_select_lcd_clk_source(channel,
0288             dpi_get_alt_clk_src(channel));
0289 
0290     dpi->mgr_config.clock_info = ctx.dispc_cinfo;
0291 
0292     *fck = ctx.dsi_cinfo.clkout[HSDIV_DISPC];
0293     *lck_div = ctx.dispc_cinfo.lck_div;
0294     *pck_div = ctx.dispc_cinfo.pck_div;
0295 
0296     return 0;
0297 }
0298 
0299 static int dpi_set_dispc_clk(struct dpi_data *dpi, unsigned long pck_req,
0300         unsigned long *fck, int *lck_div, int *pck_div)
0301 {
0302     struct dpi_clk_calc_ctx ctx;
0303     int r;
0304     bool ok;
0305 
0306     ok = dpi_dss_clk_calc(pck_req, &ctx);
0307     if (!ok)
0308         return -EINVAL;
0309 
0310     r = dss_set_fck_rate(ctx.fck);
0311     if (r)
0312         return r;
0313 
0314     dpi->mgr_config.clock_info = ctx.dispc_cinfo;
0315 
0316     *fck = ctx.fck;
0317     *lck_div = ctx.dispc_cinfo.lck_div;
0318     *pck_div = ctx.dispc_cinfo.pck_div;
0319 
0320     return 0;
0321 }
0322 
0323 static int dpi_set_mode(struct dpi_data *dpi)
0324 {
0325     struct omap_dss_device *out = &dpi->output;
0326     struct omap_overlay_manager *mgr = out->manager;
0327     struct omap_video_timings *t = &dpi->timings;
0328     int lck_div = 0, pck_div = 0;
0329     unsigned long fck = 0;
0330     unsigned long pck;
0331     int r = 0;
0332 
0333     if (dpi->pll)
0334         r = dpi_set_dsi_clk(dpi, mgr->id, t->pixelclock, &fck,
0335                 &lck_div, &pck_div);
0336     else
0337         r = dpi_set_dispc_clk(dpi, t->pixelclock, &fck,
0338                 &lck_div, &pck_div);
0339     if (r)
0340         return r;
0341 
0342     pck = fck / lck_div / pck_div;
0343 
0344     if (pck != t->pixelclock) {
0345         DSSWARN("Could not find exact pixel clock. Requested %d Hz, got %lu Hz\n",
0346             t->pixelclock, pck);
0347 
0348         t->pixelclock = pck;
0349     }
0350 
0351     dss_mgr_set_timings(mgr, t);
0352 
0353     return 0;
0354 }
0355 
0356 static void dpi_config_lcd_manager(struct dpi_data *dpi)
0357 {
0358     struct omap_dss_device *out = &dpi->output;
0359     struct omap_overlay_manager *mgr = out->manager;
0360 
0361     dpi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
0362 
0363     dpi->mgr_config.stallmode = false;
0364     dpi->mgr_config.fifohandcheck = false;
0365 
0366     dpi->mgr_config.video_port_width = dpi->data_lines;
0367 
0368     dpi->mgr_config.lcden_sig_polarity = 0;
0369 
0370     dss_mgr_set_lcd_config(mgr, &dpi->mgr_config);
0371 }
0372 
0373 static int dpi_display_enable(struct omap_dss_device *dssdev)
0374 {
0375     struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
0376     struct omap_dss_device *out = &dpi->output;
0377     int r;
0378 
0379     mutex_lock(&dpi->lock);
0380 
0381     if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi->vdds_dsi_reg) {
0382         DSSERR("no VDSS_DSI regulator\n");
0383         r = -ENODEV;
0384         goto err_no_reg;
0385     }
0386 
0387     if (out->manager == NULL) {
0388         DSSERR("failed to enable display: no output/manager\n");
0389         r = -ENODEV;
0390         goto err_no_out_mgr;
0391     }
0392 
0393     if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) {
0394         r = regulator_enable(dpi->vdds_dsi_reg);
0395         if (r)
0396             goto err_reg_enable;
0397     }
0398 
0399     r = dispc_runtime_get();
0400     if (r)
0401         goto err_get_dispc;
0402 
0403     r = dss_dpi_select_source(out->port_num, out->manager->id);
0404     if (r)
0405         goto err_src_sel;
0406 
0407     if (dpi->pll) {
0408         r = dss_pll_enable(dpi->pll);
0409         if (r)
0410             goto err_dsi_pll_init;
0411     }
0412 
0413     r = dpi_set_mode(dpi);
0414     if (r)
0415         goto err_set_mode;
0416 
0417     dpi_config_lcd_manager(dpi);
0418 
0419     mdelay(2);
0420 
0421     r = dss_mgr_enable(out->manager);
0422     if (r)
0423         goto err_mgr_enable;
0424 
0425     mutex_unlock(&dpi->lock);
0426 
0427     return 0;
0428 
0429 err_mgr_enable:
0430 err_set_mode:
0431     if (dpi->pll)
0432         dss_pll_disable(dpi->pll);
0433 err_dsi_pll_init:
0434 err_src_sel:
0435     dispc_runtime_put();
0436 err_get_dispc:
0437     if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
0438         regulator_disable(dpi->vdds_dsi_reg);
0439 err_reg_enable:
0440 err_no_out_mgr:
0441 err_no_reg:
0442     mutex_unlock(&dpi->lock);
0443     return r;
0444 }
0445 
0446 static void dpi_display_disable(struct omap_dss_device *dssdev)
0447 {
0448     struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
0449     struct omap_overlay_manager *mgr = dpi->output.manager;
0450 
0451     mutex_lock(&dpi->lock);
0452 
0453     dss_mgr_disable(mgr);
0454 
0455     if (dpi->pll) {
0456         dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
0457         dss_pll_disable(dpi->pll);
0458     }
0459 
0460     dispc_runtime_put();
0461 
0462     if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
0463         regulator_disable(dpi->vdds_dsi_reg);
0464 
0465     mutex_unlock(&dpi->lock);
0466 }
0467 
0468 static void dpi_set_timings(struct omap_dss_device *dssdev,
0469         struct omap_video_timings *timings)
0470 {
0471     struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
0472 
0473     DSSDBG("dpi_set_timings\n");
0474 
0475     mutex_lock(&dpi->lock);
0476 
0477     dpi->timings = *timings;
0478 
0479     mutex_unlock(&dpi->lock);
0480 }
0481 
0482 static void dpi_get_timings(struct omap_dss_device *dssdev,
0483         struct omap_video_timings *timings)
0484 {
0485     struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
0486 
0487     mutex_lock(&dpi->lock);
0488 
0489     *timings = dpi->timings;
0490 
0491     mutex_unlock(&dpi->lock);
0492 }
0493 
0494 static int dpi_check_timings(struct omap_dss_device *dssdev,
0495             struct omap_video_timings *timings)
0496 {
0497     struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
0498     struct omap_overlay_manager *mgr = dpi->output.manager;
0499     int lck_div, pck_div;
0500     unsigned long fck;
0501     unsigned long pck;
0502     struct dpi_clk_calc_ctx ctx;
0503     bool ok;
0504 
0505     if (mgr && !dispc_mgr_timings_ok(mgr->id, timings))
0506         return -EINVAL;
0507 
0508     if (timings->pixelclock == 0)
0509         return -EINVAL;
0510 
0511     if (dpi->pll) {
0512         ok = dpi_dsi_clk_calc(dpi, timings->pixelclock, &ctx);
0513         if (!ok)
0514             return -EINVAL;
0515 
0516         fck = ctx.dsi_cinfo.clkout[HSDIV_DISPC];
0517     } else {
0518         ok = dpi_dss_clk_calc(timings->pixelclock, &ctx);
0519         if (!ok)
0520             return -EINVAL;
0521 
0522         fck = ctx.fck;
0523     }
0524 
0525     lck_div = ctx.dispc_cinfo.lck_div;
0526     pck_div = ctx.dispc_cinfo.pck_div;
0527 
0528     pck = fck / lck_div / pck_div;
0529 
0530     timings->pixelclock = pck;
0531 
0532     return 0;
0533 }
0534 
0535 static void dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines)
0536 {
0537     struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
0538 
0539     mutex_lock(&dpi->lock);
0540 
0541     dpi->data_lines = data_lines;
0542 
0543     mutex_unlock(&dpi->lock);
0544 }
0545 
0546 static int dpi_verify_dsi_pll(struct dss_pll *pll)
0547 {
0548     int r;
0549 
0550     /* do initial setup with the PLL to see if it is operational */
0551 
0552     r = dss_pll_enable(pll);
0553     if (r)
0554         return r;
0555 
0556     dss_pll_disable(pll);
0557 
0558     return 0;
0559 }
0560 
0561 static int dpi_init_regulator(struct dpi_data *dpi)
0562 {
0563     struct regulator *vdds_dsi;
0564 
0565     if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
0566         return 0;
0567 
0568     if (dpi->vdds_dsi_reg)
0569         return 0;
0570 
0571     vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
0572     if (IS_ERR(vdds_dsi)) {
0573         if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
0574             DSSERR("can't get VDDS_DSI regulator\n");
0575         return PTR_ERR(vdds_dsi);
0576     }
0577 
0578     dpi->vdds_dsi_reg = vdds_dsi;
0579 
0580     return 0;
0581 }
0582 
0583 static void dpi_init_pll(struct dpi_data *dpi)
0584 {
0585     struct dss_pll *pll;
0586 
0587     if (dpi->pll)
0588         return;
0589 
0590     pll = dpi_get_pll(dpi->output.dispc_channel);
0591     if (!pll)
0592         return;
0593 
0594     /* On DRA7 we need to set a mux to use the PLL */
0595     if (omapdss_get_version() == OMAPDSS_VER_DRA7xx)
0596         dss_ctrl_pll_set_control_mux(pll->id, dpi->output.dispc_channel);
0597 
0598     if (dpi_verify_dsi_pll(pll)) {
0599         DSSWARN("DSI PLL not operational\n");
0600         return;
0601     }
0602 
0603     dpi->pll = pll;
0604 }
0605 
0606 /*
0607  * Return a hardcoded channel for the DPI output. This should work for
0608  * current use cases, but this can be later expanded to either resolve
0609  * the channel in some more dynamic manner, or get the channel as a user
0610  * parameter.
0611  */
0612 static enum omap_channel dpi_get_channel(int port_num)
0613 {
0614     switch (omapdss_get_version()) {
0615     case OMAPDSS_VER_OMAP24xx:
0616     case OMAPDSS_VER_OMAP34xx_ES1:
0617     case OMAPDSS_VER_OMAP34xx_ES3:
0618     case OMAPDSS_VER_OMAP3630:
0619     case OMAPDSS_VER_AM35xx:
0620     case OMAPDSS_VER_AM43xx:
0621         return OMAP_DSS_CHANNEL_LCD;
0622 
0623     case OMAPDSS_VER_DRA7xx:
0624         switch (port_num) {
0625         case 2:
0626             return OMAP_DSS_CHANNEL_LCD3;
0627         case 1:
0628             return OMAP_DSS_CHANNEL_LCD2;
0629         case 0:
0630         default:
0631             return OMAP_DSS_CHANNEL_LCD;
0632         }
0633 
0634     case OMAPDSS_VER_OMAP4430_ES1:
0635     case OMAPDSS_VER_OMAP4430_ES2:
0636     case OMAPDSS_VER_OMAP4:
0637         return OMAP_DSS_CHANNEL_LCD2;
0638 
0639     case OMAPDSS_VER_OMAP5:
0640         return OMAP_DSS_CHANNEL_LCD3;
0641 
0642     default:
0643         DSSWARN("unsupported DSS version\n");
0644         return OMAP_DSS_CHANNEL_LCD;
0645     }
0646 }
0647 
0648 static int dpi_connect(struct omap_dss_device *dssdev,
0649         struct omap_dss_device *dst)
0650 {
0651     struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
0652     struct omap_overlay_manager *mgr;
0653     int r;
0654 
0655     r = dpi_init_regulator(dpi);
0656     if (r)
0657         return r;
0658 
0659     dpi_init_pll(dpi);
0660 
0661     mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
0662     if (!mgr)
0663         return -ENODEV;
0664 
0665     r = dss_mgr_connect(mgr, dssdev);
0666     if (r)
0667         return r;
0668 
0669     r = omapdss_output_set_device(dssdev, dst);
0670     if (r) {
0671         DSSERR("failed to connect output to new device: %s\n",
0672                 dst->name);
0673         dss_mgr_disconnect(mgr, dssdev);
0674         return r;
0675     }
0676 
0677     return 0;
0678 }
0679 
0680 static void dpi_disconnect(struct omap_dss_device *dssdev,
0681         struct omap_dss_device *dst)
0682 {
0683     WARN_ON(dst != dssdev->dst);
0684 
0685     if (dst != dssdev->dst)
0686         return;
0687 
0688     omapdss_output_unset_device(dssdev);
0689 
0690     if (dssdev->manager)
0691         dss_mgr_disconnect(dssdev->manager, dssdev);
0692 }
0693 
0694 static const struct omapdss_dpi_ops dpi_ops = {
0695     .connect = dpi_connect,
0696     .disconnect = dpi_disconnect,
0697 
0698     .enable = dpi_display_enable,
0699     .disable = dpi_display_disable,
0700 
0701     .check_timings = dpi_check_timings,
0702     .set_timings = dpi_set_timings,
0703     .get_timings = dpi_get_timings,
0704 
0705     .set_data_lines = dpi_set_data_lines,
0706 };
0707 
0708 static void dpi_init_output(struct platform_device *pdev)
0709 {
0710     struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
0711     struct omap_dss_device *out = &dpi->output;
0712 
0713     out->dev = &pdev->dev;
0714     out->id = OMAP_DSS_OUTPUT_DPI;
0715     out->output_type = OMAP_DISPLAY_TYPE_DPI;
0716     out->name = "dpi.0";
0717     out->dispc_channel = dpi_get_channel(0);
0718     out->ops.dpi = &dpi_ops;
0719     out->owner = THIS_MODULE;
0720 
0721     omapdss_register_output(out);
0722 }
0723 
0724 static void dpi_uninit_output(struct platform_device *pdev)
0725 {
0726     struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
0727     struct omap_dss_device *out = &dpi->output;
0728 
0729     omapdss_unregister_output(out);
0730 }
0731 
0732 static void dpi_init_output_port(struct platform_device *pdev,
0733     struct device_node *port)
0734 {
0735     struct dpi_data *dpi = port->data;
0736     struct omap_dss_device *out = &dpi->output;
0737     int r;
0738     u32 port_num;
0739 
0740     r = of_property_read_u32(port, "reg", &port_num);
0741     if (r)
0742         port_num = 0;
0743 
0744     switch (port_num) {
0745     case 2:
0746         out->name = "dpi.2";
0747         break;
0748     case 1:
0749         out->name = "dpi.1";
0750         break;
0751     case 0:
0752     default:
0753         out->name = "dpi.0";
0754         break;
0755     }
0756 
0757     out->dev = &pdev->dev;
0758     out->id = OMAP_DSS_OUTPUT_DPI;
0759     out->output_type = OMAP_DISPLAY_TYPE_DPI;
0760     out->dispc_channel = dpi_get_channel(port_num);
0761     out->port_num = port_num;
0762     out->ops.dpi = &dpi_ops;
0763     out->owner = THIS_MODULE;
0764 
0765     omapdss_register_output(out);
0766 }
0767 
0768 static void dpi_uninit_output_port(struct device_node *port)
0769 {
0770     struct dpi_data *dpi = port->data;
0771     struct omap_dss_device *out = &dpi->output;
0772 
0773     omapdss_unregister_output(out);
0774 }
0775 
0776 static int dpi_bind(struct device *dev, struct device *master, void *data)
0777 {
0778     struct platform_device *pdev = to_platform_device(dev);
0779     struct dpi_data *dpi;
0780 
0781     dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
0782     if (!dpi)
0783         return -ENOMEM;
0784 
0785     dpi->pdev = pdev;
0786 
0787     platform_set_drvdata(pdev, dpi);
0788 
0789     mutex_init(&dpi->lock);
0790 
0791     dpi_init_output(pdev);
0792 
0793     return 0;
0794 }
0795 
0796 static void dpi_unbind(struct device *dev, struct device *master, void *data)
0797 {
0798     struct platform_device *pdev = to_platform_device(dev);
0799 
0800     dpi_uninit_output(pdev);
0801 }
0802 
0803 static const struct component_ops dpi_component_ops = {
0804     .bind   = dpi_bind,
0805     .unbind = dpi_unbind,
0806 };
0807 
0808 static int dpi_probe(struct platform_device *pdev)
0809 {
0810     return component_add(&pdev->dev, &dpi_component_ops);
0811 }
0812 
0813 static int dpi_remove(struct platform_device *pdev)
0814 {
0815     component_del(&pdev->dev, &dpi_component_ops);
0816     return 0;
0817 }
0818 
0819 static struct platform_driver omap_dpi_driver = {
0820     .probe      = dpi_probe,
0821     .remove     = dpi_remove,
0822     .driver         = {
0823         .name   = "omapdss_dpi",
0824         .suppress_bind_attrs = true,
0825     },
0826 };
0827 
0828 int __init dpi_init_platform_driver(void)
0829 {
0830     return platform_driver_register(&omap_dpi_driver);
0831 }
0832 
0833 void dpi_uninit_platform_driver(void)
0834 {
0835     platform_driver_unregister(&omap_dpi_driver);
0836 }
0837 
0838 int dpi_init_port(struct platform_device *pdev, struct device_node *port)
0839 {
0840     struct dpi_data *dpi;
0841     struct device_node *ep;
0842     u32 datalines;
0843     int r;
0844 
0845     dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
0846     if (!dpi)
0847         return -ENOMEM;
0848 
0849     ep = omapdss_of_get_next_endpoint(port, NULL);
0850     if (!ep)
0851         return 0;
0852 
0853     r = of_property_read_u32(ep, "data-lines", &datalines);
0854     if (r) {
0855         DSSERR("failed to parse datalines\n");
0856         goto err_datalines;
0857     }
0858 
0859     dpi->data_lines = datalines;
0860 
0861     of_node_put(ep);
0862 
0863     dpi->pdev = pdev;
0864     port->data = dpi;
0865 
0866     mutex_init(&dpi->lock);
0867 
0868     dpi_init_output_port(pdev, port);
0869 
0870     dpi->port_initialized = true;
0871 
0872     return 0;
0873 
0874 err_datalines:
0875     of_node_put(ep);
0876 
0877     return r;
0878 }
0879 
0880 void dpi_uninit_port(struct device_node *port)
0881 {
0882     struct dpi_data *dpi = port->data;
0883 
0884     if (!dpi->port_initialized)
0885         return;
0886 
0887     dpi_uninit_output_port(port);
0888 }