aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video
diff options
context:
space:
mode:
authorGuennadi Liakhovetski <g.liakhovetski@gmx.de>2010-09-03 03:20:39 -0400
committerPaul Mundt <lethal@linux-sh.org>2010-09-14 04:23:39 -0400
commitafe417c0355154c8b2547619771d6053b3c0aad7 (patch)
tree39c2a88283848450c0a9eee36acd71c09f918ccf /drivers/video
parent9289c475823b6eee1f68af2a71243d0cff126948 (diff)
fbdev: sh_mobile_hdmi: support hot-plugging of different HDMI / DVI displays
With this patch hot-plugging of an HDMI or a DVI monitor can select a different video mode and reconfigure the LCDC and HDMI controllers accordingly. Due to a lack of a standard API to inform framebuffer users of a changed video mode, the framebuffer configuration is preserved regardless of a specific mode, selected for the monitor. As described in a previous patch, this leads to smaller framebuffers being displayed on larger monitors or a part of a larger framebuffer being displayed on a smaller resolution monitor. Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/sh_mobile_hdmi.c203
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c31
2 files changed, 170 insertions, 64 deletions
diff --git a/drivers/video/sh_mobile_hdmi.c b/drivers/video/sh_mobile_hdmi.c
index 2260fd7edd95..4d6ab86e9518 100644
--- a/drivers/video/sh_mobile_hdmi.c
+++ b/drivers/video/sh_mobile_hdmi.c
@@ -214,6 +214,7 @@ struct sh_hdmi {
214 struct mutex mutex; /* Protect the info pointer */ 214 struct mutex mutex; /* Protect the info pointer */
215 struct delayed_work edid_work; 215 struct delayed_work edid_work;
216 struct fb_var_screeninfo var; 216 struct fb_var_screeninfo var;
217 struct fb_monspecs monspec;
217}; 218};
218 219
219static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg) 220static void hdmi_write(struct sh_hdmi *hdmi, u8 data, u8 reg)
@@ -610,11 +611,12 @@ static void sh_hdmi_configure(struct sh_hdmi *hdmi)
610 hdmi_write(hdmi, 0x40, HDMI_SYSTEM_CTRL); 611 hdmi_write(hdmi, 0x40, HDMI_SYSTEM_CTRL);
611} 612}
612 613
613static void sh_hdmi_read_edid(struct sh_hdmi *hdmi) 614static int sh_hdmi_read_edid(struct sh_hdmi *hdmi)
614{ 615{
615 struct fb_var_screeninfo tmpvar; 616 struct fb_var_screeninfo tmpvar;
616 /* TODO: When we are ready to use EDID, use this to fill &hdmi->var */ 617 /* TODO: When we are ready to use EDID, use this to fill &hdmi->var */
617 struct fb_var_screeninfo *var = &tmpvar; 618 struct fb_var_screeninfo *var = &tmpvar;
619 const struct fb_videomode *mode, *found = NULL;
618 int i; 620 int i;
619 u8 edid[128]; 621 u8 edid[128];
620 622
@@ -634,20 +636,84 @@ static void sh_hdmi_read_edid(struct sh_hdmi *hdmi)
634#ifdef DEBUG 636#ifdef DEBUG
635 printk(KERN_CONT "\n"); 637 printk(KERN_CONT "\n");
636#endif 638#endif
637 fb_parse_edid(edid, var); 639
638 dev_dbg(hdmi->dev, "%u-%u-%u-%u x %u-%u-%u-%u @ %lu kHz monitor detected\n", 640 fb_edid_to_monspecs(edid, &hdmi->monspec);
639 var->left_margin, var->xres, var->right_margin, var->hsync_len, 641
640 var->upper_margin, var->yres, var->lower_margin, var->vsync_len, 642 /* First look for an exact match */
641 PICOS2KHZ(var->pixclock)); 643 for (i = 0, mode = hdmi->monspec.modedb; i < hdmi->monspec.modedb_len;
642 644 i++, mode++) {
643 if ((hdmi->var.xres == 720 && hdmi->var.yres == 480) || 645 dev_dbg(hdmi->dev, "%u-%u-%u-%u x %u-%u-%u-%u @ %lu kHz monitor detected\n",
644 (hdmi->var.xres == 1280 && hdmi->var.yres == 720) || 646 mode->left_margin, mode->xres,
645 (hdmi->var.xres == 1920 && hdmi->var.yres == 1080)) 647 mode->right_margin, mode->hsync_len,
648 mode->upper_margin, mode->yres,
649 mode->lower_margin, mode->vsync_len,
650 PICOS2KHZ(mode->pixclock));
651 if (!found && hdmi->info) {
652 fb_videomode_to_var(var, mode);
653 found = fb_match_mode(var, &hdmi->info->modelist);
654 /*
655 * If an exact match found, we're good to bail out, but
656 * continue to print out all modes
657 */
658 }
659 }
660
661 /*
662 * The monitor might also work with a mode, that is smaller, than one of
663 * its modes, use the first (default) one for this
664 */
665 if (!found && hdmi->info && hdmi->monspec.modedb_len) {
666 struct fb_modelist *modelist;
667 unsigned int min_err = UINT_MAX, err;
668 const struct fb_videomode *mon_mode = hdmi->monspec.modedb;
669
670 list_for_each_entry(modelist, &hdmi->info->modelist, list) {
671 mode = &modelist->mode;
672 dev_dbg(hdmi->dev, "matching %ux%u to %ux%u\n", mode->xres, mode->yres,
673 mon_mode->xres, mon_mode->yres);
674 if (mode->xres <= mon_mode->xres && mode->yres <= mon_mode->yres) {
675 err = mon_mode->xres - mode->xres + mon_mode->yres - mode->yres;
676 if (!err) {
677 found = mode;
678 break;
679 }
680 if (err < min_err) {
681 found = mode;
682 min_err = err;
683 }
684 }
685 }
686 }
687
688 /* Nothing suitable specified by the platform: use monitor's first mode */
689 if (!found && hdmi->monspec.modedb_len)
690 found = hdmi->monspec.modedb;
691
692 /* No valid timing info in EDID - last resort: use platform default mode */
693 if (!found && hdmi->info) {
694 struct fb_modelist *modelist = list_entry(hdmi->info->modelist.next,
695 struct fb_modelist, list);
696 found = &modelist->mode;
697 }
698
699 /* No cookie today */
700 if (!found)
701 return -ENXIO;
702
703 dev_dbg(hdmi->dev, "best \"%s\" %ux%u@%ups\n", found->name,
704 found->xres, found->yres, found->pixclock);
705
706 if ((found->xres == 720 && found->yres == 480) ||
707 (found->xres == 1280 && found->yres == 720) ||
708 (found->xres == 1920 && found->yres == 1080))
646 hdmi->preprogrammed_mode = true; 709 hdmi->preprogrammed_mode = true;
647 else 710 else
648 hdmi->preprogrammed_mode = false; 711 hdmi->preprogrammed_mode = false;
649 712
713 fb_videomode_to_var(&hdmi->var, found);
650 sh_hdmi_external_video_param(hdmi); 714 sh_hdmi_external_video_param(hdmi);
715
716 return 0;
651} 717}
652 718
653static irqreturn_t sh_hdmi_hotplug(int irq, void *dev_id) 719static irqreturn_t sh_hdmi_hotplug(int irq, void *dev_id)
@@ -770,12 +836,73 @@ static void sh_hdmi_display_off(void *arg)
770 hdmi_write(hdmi, 0x10, HDMI_SYSTEM_CTRL); 836 hdmi_write(hdmi, 0x10, HDMI_SYSTEM_CTRL);
771} 837}
772 838
839static bool sh_hdmi_must_reconfigure(struct sh_hdmi *hdmi)
840{
841 struct fb_info *info = hdmi->info;
842 struct sh_mobile_lcdc_chan *ch = info->par;
843 struct fb_var_screeninfo *new_var = &hdmi->var, *old_var = &ch->display_var;
844 struct fb_videomode mode1, mode2;
845
846 fb_var_to_videomode(&mode1, old_var);
847 fb_var_to_videomode(&mode2, new_var);
848
849 dev_dbg(info->dev, "Old %ux%u, new %ux%u\n",
850 mode1.xres, mode1.yres, mode2.xres, mode2.yres);
851
852 if (fb_mode_is_equal(&mode1, &mode2))
853 return false;
854
855 dev_dbg(info->dev, "Switching %u -> %u lines\n",
856 mode1.yres, mode2.yres);
857 *old_var = *new_var;
858
859 return true;
860}
861
862/**
863 * sh_hdmi_clk_configure() - set HDMI clock frequency and enable the clock
864 * @hdmi: driver context
865 * @pixclock: pixel clock period in picoseconds
866 * return: configured positive rate if successful
867 * 0 if couldn't set the rate, but managed to enable the clock
868 * negative error, if couldn't enable the clock
869 */
870static long sh_hdmi_clk_configure(struct sh_hdmi *hdmi, unsigned long pixclock)
871{
872 long rate;
873 int ret;
874
875 rate = PICOS2KHZ(pixclock) * 1000;
876 rate = clk_round_rate(hdmi->hdmi_clk, rate);
877 if (rate > 0) {
878 ret = clk_set_rate(hdmi->hdmi_clk, rate);
879 if (ret < 0) {
880 dev_warn(hdmi->dev, "Cannot set rate %ld: %d\n", rate, ret);
881 rate = 0;
882 } else {
883 dev_dbg(hdmi->dev, "HDMI set frequency %lu\n", rate);
884 }
885 } else {
886 rate = 0;
887 dev_warn(hdmi->dev, "Cannot get suitable rate: %ld\n", rate);
888 }
889
890 ret = clk_enable(hdmi->hdmi_clk);
891 if (ret < 0) {
892 dev_err(hdmi->dev, "Cannot enable clock: %d\n", ret);
893 return ret;
894 }
895
896 return rate;
897}
898
773/* Hotplug interrupt occurred, read EDID */ 899/* Hotplug interrupt occurred, read EDID */
774static void sh_hdmi_edid_work_fn(struct work_struct *work) 900static void sh_hdmi_edid_work_fn(struct work_struct *work)
775{ 901{
776 struct sh_hdmi *hdmi = container_of(work, struct sh_hdmi, edid_work.work); 902 struct sh_hdmi *hdmi = container_of(work, struct sh_hdmi, edid_work.work);
777 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data; 903 struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data;
778 struct sh_mobile_lcdc_chan *ch; 904 struct sh_mobile_lcdc_chan *ch;
905 int ret;
779 906
780 dev_dbg(hdmi->dev, "%s(%p): begin, hotplug status %d\n", __func__, 907 dev_dbg(hdmi->dev, "%s(%p): begin, hotplug status %d\n", __func__,
781 pdata->lcd_dev, hdmi->hp_state); 908 pdata->lcd_dev, hdmi->hp_state);
@@ -786,9 +913,19 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
786 mutex_lock(&hdmi->mutex); 913 mutex_lock(&hdmi->mutex);
787 914
788 if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) { 915 if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) {
789 pm_runtime_get_sync(hdmi->dev);
790 /* A device has been plugged in */ 916 /* A device has been plugged in */
791 sh_hdmi_read_edid(hdmi); 917 pm_runtime_get_sync(hdmi->dev);
918
919 ret = sh_hdmi_read_edid(hdmi);
920 if (ret < 0)
921 goto out;
922
923 /* Reconfigure the clock */
924 clk_disable(hdmi->hdmi_clk);
925 ret = sh_hdmi_clk_configure(hdmi, hdmi->var.pixclock);
926 if (ret < 0)
927 goto out;
928
792 msleep(10); 929 msleep(10);
793 sh_hdmi_configure(hdmi); 930 sh_hdmi_configure(hdmi);
794 /* Switched to another (d) power-save mode */ 931 /* Switched to another (d) power-save mode */
@@ -802,18 +939,24 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
802 acquire_console_sem(); 939 acquire_console_sem();
803 940
804 /* HDMI plug in */ 941 /* HDMI plug in */
805 ch->display_var = hdmi->var; 942 if (!sh_hdmi_must_reconfigure(hdmi) &&
806 if (hdmi->info->state != FBINFO_STATE_RUNNING) { 943 hdmi->info->state == FBINFO_STATE_RUNNING) {
807 fb_set_suspend(hdmi->info, 0); 944 /*
808 } else { 945 * First activation with the default monitor - just turn
946 * on, if we run a resume here, the logo disappears
947 */
809 if (lock_fb_info(hdmi->info)) { 948 if (lock_fb_info(hdmi->info)) {
810 sh_hdmi_display_on(hdmi, hdmi->info); 949 sh_hdmi_display_on(hdmi, hdmi->info);
811 unlock_fb_info(hdmi->info); 950 unlock_fb_info(hdmi->info);
812 } 951 }
952 } else {
953 /* New monitor or have to wake up */
954 fb_set_suspend(hdmi->info, 0);
813 } 955 }
814 956
815 release_console_sem(); 957 release_console_sem();
816 } else { 958 } else {
959 ret = 0;
817 if (!hdmi->info) 960 if (!hdmi->info)
818 goto out; 961 goto out;
819 962
@@ -824,9 +967,12 @@ static void sh_hdmi_edid_work_fn(struct work_struct *work)
824 967
825 release_console_sem(); 968 release_console_sem();
826 pm_runtime_put(hdmi->dev); 969 pm_runtime_put(hdmi->dev);
970 fb_destroy_modedb(hdmi->monspec.modedb);
827 } 971 }
828 972
829out: 973out:
974 if (ret < 0)
975 hdmi->hp_state = HDMI_HOTPLUG_DISCONNECTED;
830 mutex_unlock(&hdmi->mutex); 976 mutex_unlock(&hdmi->mutex);
831 977
832 dev_dbg(hdmi->dev, "%s(%p): end\n", __func__, pdata->lcd_dev); 978 dev_dbg(hdmi->dev, "%s(%p): end\n", __func__, pdata->lcd_dev);
@@ -905,31 +1051,13 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
905 goto egetclk; 1051 goto egetclk;
906 } 1052 }
907 1053
908 /* TODO: reconfigure the clock on monitor plug in */ 1054 rate = sh_hdmi_clk_configure(hdmi, pdata->lcd_chan->lcd_cfg[0].pixclock);
909 rate = PICOS2KHZ(pdata->lcd_chan->lcd_cfg[0].pixclock) * 1000;
910
911 rate = clk_round_rate(hdmi->hdmi_clk, rate);
912 if (rate < 0) { 1055 if (rate < 0) {
913 ret = rate; 1056 ret = rate;
914 dev_err(&pdev->dev, "Cannot get suitable rate: %ld\n", rate);
915 goto erate;
916 }
917
918 ret = clk_set_rate(hdmi->hdmi_clk, rate);
919 if (ret < 0) {
920 dev_err(&pdev->dev, "Cannot set rate %ld: %d\n", rate, ret);
921 goto erate; 1057 goto erate;
922 } 1058 }
923 1059
924 dev_dbg(hdmi->dev, "HDMI set frequency %lu\n", rate); 1060 dev_dbg(&pdev->dev, "Enabled HDMI clock at %luHz\n", rate);
925
926 ret = clk_enable(hdmi->hdmi_clk);
927 if (ret < 0) {
928 dev_err(&pdev->dev, "Cannot enable clock: %d\n", ret);
929 goto eclkenable;
930 }
931
932 dev_info(&pdev->dev, "Enabled HDMI clock at %luHz\n", rate);
933 1061
934 if (!request_mem_region(res->start, resource_size(res), dev_name(&pdev->dev))) { 1062 if (!request_mem_region(res->start, resource_size(res), dev_name(&pdev->dev))) {
935 dev_err(&pdev->dev, "HDMI register region already claimed\n"); 1063 dev_err(&pdev->dev, "HDMI register region already claimed\n");
@@ -946,11 +1074,9 @@ static int __init sh_hdmi_probe(struct platform_device *pdev)
946 1074
947 platform_set_drvdata(pdev, hdmi); 1075 platform_set_drvdata(pdev, hdmi);
948 1076
949#if 1
950 /* Product and revision IDs are 0 in sh-mobile version */ 1077 /* Product and revision IDs are 0 in sh-mobile version */
951 dev_info(&pdev->dev, "Detected HDMI controller 0x%x:0x%x\n", 1078 dev_info(&pdev->dev, "Detected HDMI controller 0x%x:0x%x\n",
952 hdmi_read(hdmi, HDMI_PRODUCT_ID), hdmi_read(hdmi, HDMI_REVISION_ID)); 1079 hdmi_read(hdmi, HDMI_PRODUCT_ID), hdmi_read(hdmi, HDMI_REVISION_ID));
953#endif
954 1080
955 /* Set up LCDC callbacks */ 1081 /* Set up LCDC callbacks */
956 board_cfg = &pdata->lcd_chan->board_cfg; 1082 board_cfg = &pdata->lcd_chan->board_cfg;
@@ -980,7 +1106,6 @@ emap:
980 release_mem_region(res->start, resource_size(res)); 1106 release_mem_region(res->start, resource_size(res));
981ereqreg: 1107ereqreg:
982 clk_disable(hdmi->hdmi_clk); 1108 clk_disable(hdmi->hdmi_clk);
983eclkenable:
984erate: 1109erate:
985 clk_put(hdmi->hdmi_clk); 1110 clk_put(hdmi->hdmi_clk);
986egetclk: 1111egetclk:
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index 946a810801af..b4a878624510 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -944,6 +944,7 @@ static int sh_mobile_lcdc_notify(struct notifier_block *nb,
944 struct sh_mobile_lcdc_chan *ch = info->par; 944 struct sh_mobile_lcdc_chan *ch = info->par;
945 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg; 945 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
946 struct fb_var_screeninfo *var; 946 struct fb_var_screeninfo *var;
947 int ret;
947 948
948 if (&ch->lcdc->notifier != nb) 949 if (&ch->lcdc->notifier != nb)
949 return NOTIFY_DONE; 950 return NOTIFY_DONE;
@@ -958,6 +959,7 @@ static int sh_mobile_lcdc_notify(struct notifier_block *nb,
958 module_put(board_cfg->owner); 959 module_put(board_cfg->owner);
959 } 960 }
960 pm_runtime_put(info->device); 961 pm_runtime_put(info->device);
962 sh_mobile_lcdc_stop(ch->lcdc);
961 break; 963 break;
962 case FB_EVENT_RESUME: 964 case FB_EVENT_RESUME:
963 var = &info->var; 965 var = &info->var;
@@ -968,31 +970,9 @@ static int sh_mobile_lcdc_notify(struct notifier_block *nb,
968 module_put(board_cfg->owner); 970 module_put(board_cfg->owner);
969 } 971 }
970 972
971 /* Check if the new display is not in our modelist */ 973 ret = sh_mobile_lcdc_start(ch->lcdc);
972 if (ch->info->modelist.next && 974 if (!ret)
973 !fb_match_mode(var, &ch->info->modelist)) { 975 pm_runtime_get_sync(info->device);
974 struct fb_videomode mode;
975 int ret;
976
977 /* Can we handle this display? */
978 if (var->xres > ch->cfg.lcd_cfg[0].xres ||
979 var->yres > ch->cfg.lcd_cfg[0].yres)
980 /*
981 * LCDC resume failed, no need to continue with
982 * the notifier chain
983 */
984 return notifier_from_errno(-ENOMEM);
985
986 /* Add to the modelist */
987 fb_var_to_videomode(&mode, var);
988 ret = fb_add_videomode(&mode, &ch->info->modelist);
989 if (ret < 0)
990 return notifier_from_errno(ret);
991 }
992
993 pm_runtime_get_sync(info->device);
994
995 sh_mobile_lcdc_geometry(ch);
996 } 976 }
997 977
998 return NOTIFY_OK; 978 return NOTIFY_OK;
@@ -1181,6 +1161,7 @@ static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1181 } 1161 }
1182 } 1162 }
1183 1163
1164 fb_videomode_to_modelist(ch->cfg.lcd_cfg, ch->cfg.num_cfg, &info->modelist);
1184 error = register_framebuffer(info); 1165 error = register_framebuffer(info);
1185 if (error < 0) 1166 if (error < 0)
1186 goto err1; 1167 goto err1;