Re: [PATCH v17 2/7] video: add display_timing and videomode

2013-03-05 Thread Steffen Trumtrar
Hi!

On Wed, Feb 27, 2013 at 06:13:49PM +0200, Tomi Valkeinen wrote:
 On 2013-02-27 18:05, Steffen Trumtrar wrote:
  Ah, sorry. Forgot to answer this.
  
  On Wed, Feb 27, 2013 at 05:45:31PM +0200, Tomi Valkeinen wrote:
  Ping.
 
  On 2013-02-18 16:09, Tomi Valkeinen wrote:
  Hi Steffen,
 
  On 2013-01-25 11:01, Steffen Trumtrar wrote:
 
  +/* VESA display monitor timing parameters */
  +#define VESA_DMT_HSYNC_LOW  BIT(0)
  +#define VESA_DMT_HSYNC_HIGH BIT(1)
  +#define VESA_DMT_VSYNC_LOW  BIT(2)
  +#define VESA_DMT_VSYNC_HIGH BIT(3)
  +
  +/* display specific flags */
  +#define DISPLAY_FLAGS_DE_LOWBIT(0)  /* data enable flag */
  +#define DISPLAY_FLAGS_DE_HIGH   BIT(1)
  +#define DISPLAY_FLAGS_PIXDATA_POSEDGE   BIT(2)  /* drive data on pos. 
  edge */
  +#define DISPLAY_FLAGS_PIXDATA_NEGEDGE   BIT(3)  /* drive data on neg. 
  edge */
  +#define DISPLAY_FLAGS_INTERLACEDBIT(4)
  +#define DISPLAY_FLAGS_DOUBLESCANBIT(5)
 
  snip
 
  +unsigned int dmt_flags; /* VESA DMT flags */
  +unsigned int data_flags; /* video data flags */
 
  Why did you go for this approach? To be able to represent
  true/false/not-specified?
 
  
  We decided somewhere between v3 and v8 (I think), that those flags can be
  high/low/ignored.
 
 Okay. Why aren't they enums, though? That always makes more clear which
 defines are to be used with which fields.
 

Hm...

  Would it be simpler to just have flags field? What does it give us to
  have those two separately?
 
  
  I decided to split them, so it is clear that some flags are VESA defined and
  the others are invented for the display-timings framework and may be
  extended.
 
 Hmm... Okay. Is it relevant that they are VESA defined? It just feels to
 complicate handling the flags =).
 
  Should the above say raising edge/falling edge instead of positive
  edge/negative edge?
 
  
  Hm, I used posedge/negedge because it is shorter (and because of my Verilog 
  past
  pretty natural to me :-) ). I don't know what others are thinking though.
 
 I guess it's quite clear, but it's still different terms than used
 elsewhere, e.g. documentation for videomodes.
 
 Another thing I noticed while using the new videomode, display_timings.h
 has a few names that are quite short and generic. Like TE_MIN, which
 is now a global define. And timing_entry. Either name could be well
 used internally in some .c file, and could easily clash.
 

Yes. You are correct.
Everyone using this is welcome to send patches now :-)

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v17 2/7] video: add display_timing and videomode

2013-02-27 Thread Steffen Trumtrar
Ah, sorry. Forgot to answer this.

On Wed, Feb 27, 2013 at 05:45:31PM +0200, Tomi Valkeinen wrote:
 Ping.
 
 On 2013-02-18 16:09, Tomi Valkeinen wrote:
  Hi Steffen,
  
  On 2013-01-25 11:01, Steffen Trumtrar wrote:
  
  +/* VESA display monitor timing parameters */
  +#define VESA_DMT_HSYNC_LOWBIT(0)
  +#define VESA_DMT_HSYNC_HIGH   BIT(1)
  +#define VESA_DMT_VSYNC_LOWBIT(2)
  +#define VESA_DMT_VSYNC_HIGH   BIT(3)
  +
  +/* display specific flags */
  +#define DISPLAY_FLAGS_DE_LOW  BIT(0)  /* data enable flag */
  +#define DISPLAY_FLAGS_DE_HIGH BIT(1)
  +#define DISPLAY_FLAGS_PIXDATA_POSEDGE BIT(2)  /* drive data on pos. 
  edge */
  +#define DISPLAY_FLAGS_PIXDATA_NEGEDGE BIT(3)  /* drive data on neg. 
  edge */
  +#define DISPLAY_FLAGS_INTERLACED  BIT(4)
  +#define DISPLAY_FLAGS_DOUBLESCAN  BIT(5)
  
  snip
  
  +  unsigned int dmt_flags; /* VESA DMT flags */
  +  unsigned int data_flags; /* video data flags */
  
  Why did you go for this approach? To be able to represent
  true/false/not-specified?
  

We decided somewhere between v3 and v8 (I think), that those flags can be
high/low/ignored.

  Would it be simpler to just have flags field? What does it give us to
  have those two separately?
  

I decided to split them, so it is clear that some flags are VESA defined and
the others are invented for the display-timings framework and may be
extended.

  Should the above say raising edge/falling edge instead of positive
  edge/negative edge?
  

Hm, I used posedge/negedge because it is shorter (and because of my Verilog past
pretty natural to me :-) ). I don't know what others are thinking though.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v17 4/7] fbmon: add videomode helpers

2013-02-05 Thread Steffen Trumtrar
Hi!

On Fri, Feb 01, 2013 at 06:29:50PM +0900, Jingoo Han wrote:
 On Friday, January 25, 2013 6:02 PM, Steffen Trumtrar wrote
  
  +   fbmode-sync = 0;
  +   fbmode-vmode = 0;
  +   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
  +   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
  +   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
 
 Um, it seems to be a type. 'H'SYNC - 'V'SYNC
 Thus, it would be changed as below:
 
 VESA_DMT_HSYNC_HIGH - VESA_DMT_VSYNC_HIGH

Damn. You are right, that is a typo. But I guess some maintainer (Dave) really,
really wants to take the series now and this can wait for an -rc. No?!  ;-)

Thanks,
Steffen

 
  +   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
  +   if (vm-data_flags  DISPLAY_FLAGS_INTERLACED)
  +   fbmode-vmode |= FB_VMODE_INTERLACED;
  +   if (vm-data_flags  DISPLAY_FLAGS_DOUBLESCAN)
  +   fbmode-vmode |= FB_VMODE_DOUBLE;
  +   fbmode-flag = 0;
  +

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v16 RESEND 0/7] of: add display helper

2013-01-25 Thread Steffen Trumtrar
Hi Afzal,

On Thu, Jan 24, 2013 at 08:47:02AM +, Mohammed, Afzal wrote:
 Hi Steffen,
 
 On Thu, Jan 24, 2013 at 13:49:58, Steffen Trumtrar wrote:
 
  Thanks. I'll use that opportunity for a v17 that is rebased onto 3.8-rc4.
 
 As you are going to have a v17, if you can fold the diff[1]
 (that I mentioned earlier) into the patch,
 fbmon: add of_videomode helpers, it would be helpful. 
 

I thought about it and I will not include that patch. Sorry.
In one of the previous versions of the series I had something like that and
it was suggested to remove it. If I leave it like it is, one gets a compile
time error like you do. And that is correct, because you shouldn't use the
function if you do not have of_videomode enabled. You should use one of the
underlying functions that are non-DT and called by of_get_fb_videomode.

Regards,
Steffen

 Regards
 Afzal
 
 [1]
 
 diff --git a/include/linux/fb.h b/include/linux/fb.h
 index 58b9860..0ce30d1 100644
 --- a/include/linux/fb.h
 +++ b/include/linux/fb.h
 @@ -716,9 +716,19 @@ extern void fb_destroy_modedb(struct fb_videomode 
 *modedb);
  extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
  extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
  
 +#if defined(CONFIG_OF_VIDEOMODE)  defined(CONFIG_FB_MODE_HELPERS)
  extern int of_get_fb_videomode(struct device_node *np,
struct fb_videomode *fb,
int index);
 +#else
 +static inline int of_get_fb_videomode(struct device_node *np,
 + struct fb_videomode *fb,
 + int index)
 +{
 +   return -EINVAL;
 +}
 +#endif
 +
  extern int fb_videomode_from_videomode(const struct videomode *vm,
struct fb_videomode *fbmode);
 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v16 RESEND 0/7] of: add display helper

2013-01-24 Thread Steffen Trumtrar
On Thu, Jan 24, 2013 at 10:44:50AM +0530, Leela Krishna Amudala wrote:
 Steffen,
 
 You can add my tested-by for this series.. :)
 I have been using them for Exynos: smdk5250 board.
 

Thanks. I'll use that opportunity for a v17 that is rebased onto 3.8-rc4.

Regards,
Steffen

 On Wed, Jan 23, 2013 at 2:42 PM, Steffen Trumtrar
 s.trumt...@pengutronix.de wrote:
  On Tue, Jan 22, 2013 at 03:50:48PM -0600, Rob Clark wrote:
  On Mon, Jan 21, 2013 at 5:07 AM, Steffen Trumtrar
  s.trumt...@pengutronix.de wrote:
   Hi!
  
   There was still no maintainer, that commented, ack'd, nack'd, apply'd the
   series. So, this is just a resend.
   The patches were tested with:
  
   - v15 on Tegra by Thierry
   - sh-mobile-lcdcfb by Laurent
   - MX53QSB by Marek
   - Exynos: smdk5250 by Leela
   - AM335X EVM  AM335X EVM-SK by Afzal
   - imx6q: sabrelite, sabresd by Philipp and me
   - imx53: tqma53/mba53 by me
 
 
  btw, you can add my tested-by for this series..  I've been using them
  for the tilcdc lcd-panel output driver support.
 
 
  Thanks. The more drivers the merrier ;-)
 
  Steffen
 
  
  
   Changes since v15:
   - move include/linux/{videomode,display_timing}.h to 
   include/video
   - move include/linux/of_{videomode,display_timing}.h to 
   include/video
   - reimplement flags: add VESA flags and data flags
   - let pixelclock in struct videomode be unsigned long
   - rename of_display_timings_exists to of_display_timings_exist
   - revise logging/error messages: replace __func__ with 
   np-full_name
   - rename pixelclk-inverted to pixelclk-active
   - revise comments in code
  
   Changes since v14:
   - fix const struct * warning
   (reported by: Leela Krishna Amudala 
   l.kris...@samsung.com)
   - return -EINVAL when htotal or vtotal are zero
   - remove unreachable code in of_get_display_timings
   - include headers in .c files and not implicit in .h
   - sort includes alphabetically
   - fix lower/uppercase in binding documentation
   - rebase onto v3.7-rc7
  
   Changes since v13:
   - fix const struct * warning
   (reported by: Laurent Pinchart 
   laurent.pinch...@ideasonboard.com)
   - prevent division by zero in fb_videomode_from_videomode
  
   Changes since v12:
   - rename struct display_timing to via_display_timing in via 
   subsystem
   - fix refreshrate calculation
   - fix const struct * warnings
   (reported by: Manjunathappa, Prakash prakash...@ti.com)
   - some CodingStyle fixes
   - rewrite parts of commit messages and display-timings.txt
   - let display_timing_get_value get all values instead of just 
   typical
  
   Changes since v11:
   - make pointers const where applicable
   - add reviewed-by Laurent Pinchart
  
   Changes since v10:
   - fix function name (drm_)display_mode_from_videomode
   - add acked-by, reviewed-by, tested-by
  
   Changes since v9:
   - don't leak memory when previous timings were correct
   - CodingStyle fixes
   - move blank lines around
  
   Changes since v8:
   - fix memory leaks
   - change API to be more consistent (foo_from_bar(struct bar, 
   struct foo))
   - include headers were necessary
   - misc minor bugfixes
  
   Changes since v7:
   - move of_xxx to drivers/video
   - remove non-binding documentation from display-timings.txt
   - squash display_timings and videomode in one patch
   - misc minor fixes
  
   Changes since v6:
   - get rid of some empty lines etc.
   - move functions to their subsystems
   - split of_ from non-of_ functions
   - add at least some kerneldoc to some functions
  
   Changes since v5:
   - removed all display stuff and just describe timings
  
   Changes since v4:
   - refactored functions
  
   Changes since v3:
   - print error messages
   - free alloced memory
   - general cleanup
  
   Changes since v2:
   - use hardware-near property-names
   - provide a videomode structure
   - allow ranges for all properties (min,typ,max)
   - functions to get display_mode or fb_videomode
  
  
   Regards,
   Steffen
  
  
   Steffen Trumtrar (7):
 viafb: rename display_timing to via_display_timing
 video: add display_timing and videomode
 video: add of helper for display timings/videomode
 fbmon: add videomode helpers
 fbmon: add of_videomode helpers
 drm_modes: add videomode helpers
 drm_modes: add of_videomode helpers
  
.../devicetree/bindings/video/display-timing.txt   |  109 +
drivers/gpu/drm/drm_modes.c|   70 ++
drivers/video/Kconfig

[PATCH v16 RESEND 6/7] drm_modes: add videomode helpers

2013-01-21 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Tested-by: Afzal Mohammed af...@ti.com
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |5 +
 2 files changed, 42 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..184a22d 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include video/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(const struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else if (vm-dmt_flags  VESA_DMT_HSYNC_LOW)
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-dmt_flags  VESA_DMT_VSYNC_HIGH)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else if (vm-dmt_flags  VESA_DMT_VSYNC_LOW)
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-data_flags  DISPLAY_FLAGS_INTERLACED)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-data_flags  DISPLAY_FLAGS_DOUBLESCAN)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..5fbb0fe 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,8 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct videomode;
+
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1454,6 +1456,9 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+extern int drm_display_mode_from_videomode(const struct videomode *vm,
+  struct drm_display_mode *dmode);
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v16 RESEND 5/7] fbmon: add of_videomode helpers

2013-01-21 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Tested-by: Afzal Mohammed af...@ti.com
---
 drivers/video/fbmon.c |   42 ++
 include/linux/fb.h|4 
 2 files changed, 46 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 17ce135..94ad0f7 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include video/of_videomode.h
 #include video/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
@@ -1425,6 +1426,47 @@ int fb_videomode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(const struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+   int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_debug(%s: got %dx%d display mode from %s\n,
+   of_node_full_name(np), vm.hactive, vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 100a176..58b9860 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -20,6 +20,7 @@ struct fb_info;
 struct device;
 struct file;
 struct videomode;
+struct device_node;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -715,6 +716,9 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+extern int of_get_fb_videomode(struct device_node *np,
+  struct fb_videomode *fb,
+  int index);
 extern int fb_videomode_from_videomode(const struct videomode *vm,
   struct fb_videomode *fbmode);
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v16 RESEND 4/7] fbmon: add videomode helpers

2013-01-21 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Tested-by: Afzal Mohammed af...@ti.com
---
 drivers/video/fbmon.c |   52 +
 include/linux/fb.h|4 
 2 files changed, 56 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..17ce135 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include video/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,57 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   /* prevent division by zero in KHZ2PICOS macro */
+   fbmode-pixclock = vm-pixelclock ?
+   KHZ2PICOS(vm-pixelclock / 1000) : 0;
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-data_flags  DISPLAY_FLAGS_INTERLACED)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-data_flags  DISPLAY_FLAGS_DOUBLESCAN)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   /* prevent division by zero */
+   if (htotal  vtotal) {
+   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
+   /* a mode must have htotal and vtotal != 0 or it is invalid */
+   } else {
+   fbmode-refresh = 0;
+   return -EINVAL;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..100a176 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -19,6 +19,7 @@ struct vm_area_struct;
 struct fb_info;
 struct device;
 struct file;
+struct videomode;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -714,6 +715,9 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+extern int fb_videomode_from_videomode(const struct videomode *vm,
+  struct fb_videomode *fbmode);
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v16 RESEND 3/7] video: add of helper for display timings/videomode

2013-01-21 Thread Steffen Trumtrar
This adds support for reading display timings from DT into a struct
display_timings. The of_display_timing implementation supports multiple
subnodes. All children are read into an array, that can be queried.

If no native mode is specified, the first subnode will be used.

For cases where the graphics driver knows there can be only one
mode description or where the driver only supports one mode, a helper
function of_get_videomode is added, that gets a struct videomode from DT.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Tested-by: Afzal Mohammed af...@ti.com
---
 .../devicetree/bindings/video/display-timing.txt   |  109 +
 drivers/video/Kconfig  |   15 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  239 
 drivers/video/of_videomode.c   |   54 +
 include/video/of_display_timing.h  |   20 ++
 include/video/of_videomode.h   |   18 ++
 7 files changed, 457 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timing.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/video/of_display_timing.h
 create mode 100644 include/video/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timing.txt 
b/Documentation/devicetree/bindings/video/display-timing.txt
new file mode 100644
index 000..1500385
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timing.txt
@@ -0,0 +1,109 @@
+display-timing bindings
+===
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timing subnode
+--
+
+required properties:
+ - hactive, vactive: display resolution
+ - hfront-porch, hback-porch, hsync-len: horizontal display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: hsync pulse is active low/high/ignored
+ - vsync-active: vsync pulse is active low/high/ignored
+ - de-active: data-enable pulse is active low/high/ignored
+ - pixelclk-active: with
+   - active high = drive pixel data on rising edge/
+   sample data on falling edge
+   - active low  = drive pixel data on falling edge/
+   sample data on rising edge
+   - ignored = ignored
+ - interlaced (bool): boolean to enable interlaced mode
+ - doublescan (bool): boolean to enable doublescan mode
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The
+devicetree representation corresponds to the one commonly found in datasheets
+for displays. If a display supports multiple signal timings, the native-mode
+can be specified.
+
+The parameters are defined as:
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive

[PATCH v16 RESEND 0/7] of: add display helper

2013-01-21 Thread Steffen Trumtrar
Hi!

There was still no maintainer, that commented, ack'd, nack'd, apply'd the
series. So, this is just a resend.
The patches were tested with:

- v15 on Tegra by Thierry
- sh-mobile-lcdcfb by Laurent
- MX53QSB by Marek
- Exynos: smdk5250 by Leela
- AM335X EVM  AM335X EVM-SK by Afzal
- imx6q: sabrelite, sabresd by Philipp and me
- imx53: tqma53/mba53 by me


Changes since v15:
- move include/linux/{videomode,display_timing}.h to include/video
- move include/linux/of_{videomode,display_timing}.h to include/video
- reimplement flags: add VESA flags and data flags
- let pixelclock in struct videomode be unsigned long
- rename of_display_timings_exists to of_display_timings_exist
- revise logging/error messages: replace __func__ with np-full_name
- rename pixelclk-inverted to pixelclk-active
- revise comments in code

Changes since v14:
- fix const struct * warning
(reported by: Leela Krishna Amudala l.kris...@samsung.com)
- return -EINVAL when htotal or vtotal are zero
- remove unreachable code in of_get_display_timings
- include headers in .c files and not implicit in .h
- sort includes alphabetically
- fix lower/uppercase in binding documentation
- rebase onto v3.7-rc7

Changes since v13:
- fix const struct * warning
(reported by: Laurent Pinchart 
laurent.pinch...@ideasonboard.com)
- prevent division by zero in fb_videomode_from_videomode

Changes since v12:
- rename struct display_timing to via_display_timing in via subsystem
- fix refreshrate calculation
- fix const struct * warnings
(reported by: Manjunathappa, Prakash prakash...@ti.com)
- some CodingStyle fixes
- rewrite parts of commit messages and display-timings.txt
- let display_timing_get_value get all values instead of just typical

Changes since v11:
- make pointers const where applicable
- add reviewed-by Laurent Pinchart

Changes since v10:
- fix function name (drm_)display_mode_from_videomode
- add acked-by, reviewed-by, tested-by

Changes since v9:
- don't leak memory when previous timings were correct
- CodingStyle fixes
- move blank lines around

Changes since v8:
- fix memory leaks
- change API to be more consistent (foo_from_bar(struct bar, struct 
foo))
- include headers were necessary
- misc minor bugfixes

Changes since v7:
- move of_xxx to drivers/video
- remove non-binding documentation from display-timings.txt
- squash display_timings and videomode in one patch
- misc minor fixes

Changes since v6:
- get rid of some empty lines etc.
- move functions to their subsystems
- split of_ from non-of_ functions
- add at least some kerneldoc to some functions

Changes since v5:
- removed all display stuff and just describe timings

Changes since v4:
- refactored functions

Changes since v3:
- print error messages
- free alloced memory
- general cleanup

Changes since v2:
- use hardware-near property-names
- provide a videomode structure
- allow ranges for all properties (min,typ,max)
- functions to get display_mode or fb_videomode


Regards,
Steffen


Steffen Trumtrar (7):
  viafb: rename display_timing to via_display_timing
  video: add display_timing and videomode
  video: add of helper for display timings/videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timing.txt   |  109 +
 drivers/gpu/drm/drm_modes.c|   70 ++
 drivers/video/Kconfig  |   21 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 ++
 drivers/video/fbmon.c  |   94 
 drivers/video/of_display_timing.c  |  239 
 drivers/video/of_videomode.c   |   54 +
 drivers/video/via/hw.c |6 +-
 drivers/video/via/hw.h |2 +-
 drivers/video/via/lcd.c|2 +-
 drivers/video/via/share.h  |2 +-
 drivers/video/via/via_modesetting.c|8 +-
 drivers/video/via/via_modesetting.h|6 +-
 drivers/video/videomode.c  |   39 
 include/drm/drmP.h |9 +
 include/linux/fb.h |8 +
 include/video/display_timing.h |  124 ++
 include/video/of_display_timing.h

[PATCH v16 RESEND 2/7] video: add display_timing and videomode

2013-01-21 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Also, add helper functions to convert from display timings to a generic 
videomode
structure.

The struct display_timing specifies all needed parameters to describe the signal
properties of a display in one mode. This includes
- ranges for signals that may have min-, max- and typical values
- single integers for signals that can be on, off or are ignored
- booleans for signals that are either on or off

As a display may support multiple modes like this, a struct display_timings is
added, that holds all given struct display_timing pointers and declares the
native mode of the display.

Although a display may state that a signal can be in a range, it is driven with
fixed values that indicate a videomode. Therefore graphic drivers don't need all
the information of struct display_timing, but would generate a videomode from
the given set of supported signal timings and work with that.

The video subsystems all define their own structs that describe a mode and work
with that (e.g. fb_videomode or drm_display_mode). To slowly replace all those
various structures and allow code reuse across those subsystems, add struct
videomode as a generic description.

This patch only includes the most basic fields in struct videomode. All missing
fields that are needed to have a really generic video mode description can be
added at a later stage.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Tested-by: Afzal Mohammed af...@ti.com
---
 drivers/video/Kconfig  |6 ++
 drivers/video/Makefile |2 +
 drivers/video/display_timing.c |   24 
 drivers/video/videomode.c  |   39 +
 include/video/display_timing.h |  124 
 include/video/videomode.h  |   48 
 6 files changed, 243 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/video/display_timing.h
 create mode 100644 include/video/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..5e1822c
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/slab.h
+#include video/display_timing.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..21c47a2
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,39 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/errno.h
+#include linux/export.h
+#include video/display_timing.h
+#include video/videomode.h
+
+int videomode_from_timing(const struct display_timings *disp,
+ struct videomode *vm, unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, TE_TYP);
+   vm-hactive = display_timing_get_value(dt-hactive

[PATCH v16 RESEND 1/7] viafb: rename display_timing to via_display_timing

2013-01-21 Thread Steffen Trumtrar
The struct display_timing is specific to the via subsystem. The naming leads to
collisions with the new struct display_timing, which is supposed to be a shared
struct between different subsystems.
To clean this up, prepend the existing struct with the subsystem it is specific
to.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/via/hw.c  |6 +++---
 drivers/video/via/hw.h  |2 +-
 drivers/video/via/lcd.c |2 +-
 drivers/video/via/share.h   |2 +-
 drivers/video/via/via_modesetting.c |8 
 drivers/video/via/via_modesetting.h |6 +++---
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 898590d..5563c67 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,10 +1467,10 @@ void viafb_set_vclock(u32 clk, int set_iga)
via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres)
 {
-   struct display_timing timing;
+   struct via_display_timing timing;
u16 dx = (var-xres - cxres) / 2, dy = (var-yres - cyres) / 2;
 
timing.hor_addr = cxres;
@@ -1491,7 +1491,7 @@ struct display_timing var_to_timing(const struct 
fb_var_screeninfo *var,
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga)
 {
-   struct display_timing crt_reg = var_to_timing(var,
+   struct via_display_timing crt_reg = var_to_timing(var,
cxres ? cxres : var-xres, cyres ? cyres : var-yres);
 
if (iga == IGA1)
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 6be243c..c3f2572 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,7 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres);
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga);
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 1650379..022b0df 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -549,7 +549,7 @@ void viafb_lcd_set_mode(const struct fb_var_screeninfo 
*var, u16 cxres,
int panel_hres = plvds_setting_info-lcd_panel_hres;
int panel_vres = plvds_setting_info-lcd_panel_vres;
u32 clock;
-   struct display_timing timing;
+   struct via_display_timing timing;
struct fb_var_screeninfo panel_var;
const struct fb_videomode *mode_crt_table, *panel_crt_table;
 
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 3158dfc..65c65c6 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -319,7 +319,7 @@ struct crt_mode_table {
int refresh_rate;
int h_sync_polarity;
int v_sync_polarity;
-   struct display_timing crtc;
+   struct via_display_timing crtc;
 };
 
 struct io_reg {
diff --git a/drivers/video/via/via_modesetting.c 
b/drivers/video/via/via_modesetting.c
index 0e431ae..0b414b0 100644
--- a/drivers/video/via/via_modesetting.c
+++ b/drivers/video/via/via_modesetting.c
@@ -30,9 +30,9 @@
 #include debug.h
 
 
-void via_set_primary_timing(const struct display_timing *timing)
+void via_set_primary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total / 8 - 5;
raw.hor_addr = timing-hor_addr / 8 - 1;
@@ -88,9 +88,9 @@ void via_set_primary_timing(const struct display_timing 
*timing)
via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
 }
 
-void via_set_secondary_timing(const struct display_timing *timing)
+void via_set_secondary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total - 1;
raw.hor_addr = timing-hor_addr - 1;
diff --git a/drivers/video/via/via_modesetting.h 
b/drivers/video/via/via_modesetting.h
index 06e09fe..f6a6503 100644
--- a/drivers/video/via/via_modesetting.h
+++ b/drivers/video/via/via_modesetting.h
@@ -33,7 +33,7 @@
 #define VIA_PITCH_MAX  0x3FF8
 
 
-struct display_timing {
+struct via_display_timing {
u16 hor_total;
u16 hor_addr;
u16 hor_blank_start;
@@ -49,8 +49,8 @@ struct display_timing {
 };
 
 
-void via_set_primary_timing(const struct display_timing *timing);
-void via_set_secondary_timing(const struct display_timing *timing);
+void via_set_primary_timing(const struct via_display_timing *timing);
+void via_set_secondary_timing(const struct via_display_timing

[PATCH v16 RESEND 7/7] drm_modes: add of_videomode helpers

2013-01-21 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Tested-by: Afzal Mohammed af...@ti.com
---
 drivers/gpu/drm/drm_modes.c |   33 +
 include/drm/drmP.h  |4 
 2 files changed, 37 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 184a22d..fd53454 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include video/of_videomode.h
 #include video/videomode.h
 
 /**
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_debug(%s: got %dx%d display mode from %s\n,
+   of_node_full_name(np), vm.hactive, vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 5fbb0fe..e26ca59 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,7 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct device_node;
 struct videomode;
 
 #include drm/drm_os_linux.h
@@ -1458,6 +1459,9 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 
 extern int drm_display_mode_from_videomode(const struct videomode *vm,
   struct drm_display_mode *dmode);
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  int index);
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv16 0/7] of: add display helper

2013-01-09 Thread Steffen Trumtrar
Hi!

On Wed, Jan 09, 2013 at 08:12:01PM +0100, Marek Vasut wrote:
 Dear Steffen Trumtrar,
 
 I tested this on 3.8-rc1 (next 20130103) with the imx drm driver. After 
 adding 
 the following piece of code (quick hack), this works just fine. Thanks!
 
 diff --git a/drivers/staging/imx-drm/parallel-display.c b/drivers/staging/imx-
 drm/parallel-display.c
 index a8064fc..e45002a 100644
 --- a/drivers/staging/imx-drm/parallel-display.c
 +++ b/drivers/staging/imx-drm/parallel-display.c
 @@ -57,6 +57,7 @@ static void imx_pd_connector_destroy(struct drm_connector 
 *connector)
  static int imx_pd_connector_get_modes(struct drm_connector *connector)
  {
 struct imx_parallel_display *imxpd = con_to_imxpd(connector);
 +   struct device_node *np = imxpd-dev-of_node;
 int num_modes = 0;
  
 if (imxpd-edid) {
 @@ -72,6 +73,15 @@ static int imx_pd_connector_get_modes(struct drm_connector 
 *connector)
 num_modes++;
 }
  
 +   if (np) {
 +   struct drm_display_mode *mode = 
 drm_mode_create(connector-dev);
 +   of_get_drm_display_mode(np, imxpd-mode, 0);
 +   drm_mode_copy(mode, imxpd-mode);
 +   mode-type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
 +   drm_mode_probed_add(connector, mode);
 +   num_modes++;
 +   }
 +
 return num_modes;
  }
 

Nice! I haven't tried the parallel display, but I think Philipp Zabel might
already have a patch for it. If not, I will definitly keep your patch in my
topic branch.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv16 0/7] of: add display helper

2013-01-09 Thread Steffen Trumtrar
On Tue, Dec 18, 2012 at 06:04:09PM +0100, Steffen Trumtrar wrote:
 Hi!
 
 Finally, right in time before the end of the world on friday, v16 of the
 display helpers.
 

So, any more criticism on the series? Any takers for the series as is?
I guess it could be merged via the fbdev-tree if David Airlie can agree
to the DRM patches ?! Does that sound about right?

I think the series was tested at least with
- imx6q: sabrelite, sabresd
- imx53: tqma53/mba53
- omap: DA850 EVM, AM335x EVM, EVM-SK

I don't know what Laurent Pinchart, Marek Vasut and Leela Krishna Amudala
are using. Those are the people I know from the top of my head, that use
or at least did use the patches in one of its iterations. If I forgot
anyone, please speak up and possibly add your new HW to the list of tested
devices.

Thanks,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv16 5/7] fbmon: add of_videomode helpers

2013-01-07 Thread Steffen Trumtrar
Hi Afzal,

On Mon, Jan 07, 2013 at 06:10:13AM +, Mohammed, Afzal wrote:
 Hi Steffen,
 
 On Tue, Dec 18, 2012 at 22:34:14, Steffen Trumtrar wrote:
  Add helper to get fb_videomode from devicetree.
 
   drivers/video/fbmon.c |   42 ++
   include/linux/fb.h|4 
 
 This breaks DaVinci (da8xx_omapl_defconfig), following change was
 required to get it build if OF_VIDEOMODE or/and FB_MODE_HELPERS
 is not defined. There may be better solutions, following was the
 one that was used by me to test this series.
 
 ---8--
 
 diff --git a/include/linux/fb.h b/include/linux/fb.h
 index 58b9860..0ce30d1 100644
 --- a/include/linux/fb.h
 +++ b/include/linux/fb.h
 @@ -716,9 +716,19 @@ extern void fb_destroy_modedb(struct fb_videomode 
 *modedb);
  extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
  extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
 +#if defined(CONFIG_OF_VIDEOMODE)  defined(CONFIG_FB_MODE_HELPERS)
  extern int of_get_fb_videomode(struct device_node *np,
struct fb_videomode *fb,
int index);
 +#else
 +static inline int of_get_fb_videomode(struct device_node *np,
 + struct fb_videomode *fb,
 + int index)
 +{
 +   return -EINVAL;
 +}
 +#endif
 +
  extern int fb_videomode_from_videomode(const struct videomode *vm,
struct fb_videomode *fbmode);
 
 ---8--
 

I just did a quick make da8xx_omapl_defconfig  make and it builds just fine.
On what version did you apply the series?
At the moment I have the series sitting on 3.7. Didn't try any 3.8-rcx yet.
But fixing this shouldn't be a problem.

 
  +#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
 
 As _OF_VIDEOMODE is a bool type CONFIG, isn't,
 
 #ifdef CONFIG_OF_VIDEOMODE
 
 sufficient ?
 

Yes, that is right. But I think IS_ENABLED is the preferred way to do it, isn't 
it?

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv16 0/7] of: add display helper

2013-01-06 Thread Steffen Trumtrar
On Mon, Jan 07, 2013 at 06:23:54AM +, Mohammed, Afzal wrote:
 Hi Steffen,
 
 On Tue, Dec 18, 2012 at 22:34:09, Steffen Trumtrar wrote:
 
  Finally, right in time before the end of the world on friday, v16 of the
  display helpers.
 
 After another big bang, your series in the previous world was tried ;)
 
 This series has been tested on DA850 EVM, AM335x EVM, EVM-SK along
 with the fix mentioned in 5/7, there was a build breakage on default
 config on DaVinci boards with this series, fix as well as more
 details are mentioned as reply to 5/7.
 
 With those changes or equivalent to achieve the same,
 
 Tested-by: Afzal Mohammed af...@ti.com


Thanks.

Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 7/7] drm_modes: add of_videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   33 +
 include/drm/drmP.h  |4 
 2 files changed, 37 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 184a22d..fd53454 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include video/of_videomode.h
 #include video/videomode.h
 
 /**
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_debug(%s: got %dx%d display mode from %s\n,
+   of_node_full_name(np), vm.hactive, vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 5fbb0fe..e26ca59 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,7 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct device_node;
 struct videomode;
 
 #include drm/drm_os_linux.h
@@ -1458,6 +1459,9 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 
 extern int drm_display_mode_from_videomode(const struct videomode *vm,
   struct drm_display_mode *dmode);
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  int index);
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 4/7] fbmon: add videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   52 +
 include/linux/fb.h|4 
 2 files changed, 56 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..17ce135 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include video/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,57 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   /* prevent division by zero in KHZ2PICOS macro */
+   fbmode-pixclock = vm-pixelclock ?
+   KHZ2PICOS(vm-pixelclock / 1000) : 0;
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-data_flags  DISPLAY_FLAGS_INTERLACED)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-data_flags  DISPLAY_FLAGS_DOUBLESCAN)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   /* prevent division by zero */
+   if (htotal  vtotal) {
+   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
+   /* a mode must have htotal and vtotal != 0 or it is invalid */
+   } else {
+   fbmode-refresh = 0;
+   return -EINVAL;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..100a176 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -19,6 +19,7 @@ struct vm_area_struct;
 struct fb_info;
 struct device;
 struct file;
+struct videomode;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -714,6 +715,9 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+extern int fb_videomode_from_videomode(const struct videomode *vm,
+  struct fb_videomode *fbmode);
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 5/7] fbmon: add of_videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   42 ++
 include/linux/fb.h|4 
 2 files changed, 46 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 17ce135..94ad0f7 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include video/of_videomode.h
 #include video/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
@@ -1425,6 +1426,47 @@ int fb_videomode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(const struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+   int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_debug(%s: got %dx%d display mode from %s\n,
+   of_node_full_name(np), vm.hactive, vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 100a176..58b9860 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -20,6 +20,7 @@ struct fb_info;
 struct device;
 struct file;
 struct videomode;
+struct device_node;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -715,6 +716,9 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+extern int of_get_fb_videomode(struct device_node *np,
+  struct fb_videomode *fb,
+  int index);
 extern int fb_videomode_from_videomode(const struct videomode *vm,
   struct fb_videomode *fbmode);
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 1/7] viafb: rename display_timing to via_display_timing

2012-12-18 Thread Steffen Trumtrar
The struct display_timing is specific to the via subsystem. The naming leads to
collisions with the new struct display_timing, which is supposed to be a shared
struct between different subsystems.
To clean this up, prepend the existing struct with the subsystem it is specific
to.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/via/hw.c  |6 +++---
 drivers/video/via/hw.h  |2 +-
 drivers/video/via/lcd.c |2 +-
 drivers/video/via/share.h   |2 +-
 drivers/video/via/via_modesetting.c |8 
 drivers/video/via/via_modesetting.h |6 +++---
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 898590d..5563c67 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,10 +1467,10 @@ void viafb_set_vclock(u32 clk, int set_iga)
via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres)
 {
-   struct display_timing timing;
+   struct via_display_timing timing;
u16 dx = (var-xres - cxres) / 2, dy = (var-yres - cyres) / 2;
 
timing.hor_addr = cxres;
@@ -1491,7 +1491,7 @@ struct display_timing var_to_timing(const struct 
fb_var_screeninfo *var,
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga)
 {
-   struct display_timing crt_reg = var_to_timing(var,
+   struct via_display_timing crt_reg = var_to_timing(var,
cxres ? cxres : var-xres, cyres ? cyres : var-yres);
 
if (iga == IGA1)
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 6be243c..c3f2572 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,7 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres);
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga);
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 1650379..022b0df 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -549,7 +549,7 @@ void viafb_lcd_set_mode(const struct fb_var_screeninfo 
*var, u16 cxres,
int panel_hres = plvds_setting_info-lcd_panel_hres;
int panel_vres = plvds_setting_info-lcd_panel_vres;
u32 clock;
-   struct display_timing timing;
+   struct via_display_timing timing;
struct fb_var_screeninfo panel_var;
const struct fb_videomode *mode_crt_table, *panel_crt_table;
 
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 3158dfc..65c65c6 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -319,7 +319,7 @@ struct crt_mode_table {
int refresh_rate;
int h_sync_polarity;
int v_sync_polarity;
-   struct display_timing crtc;
+   struct via_display_timing crtc;
 };
 
 struct io_reg {
diff --git a/drivers/video/via/via_modesetting.c 
b/drivers/video/via/via_modesetting.c
index 0e431ae..0b414b0 100644
--- a/drivers/video/via/via_modesetting.c
+++ b/drivers/video/via/via_modesetting.c
@@ -30,9 +30,9 @@
 #include debug.h
 
 
-void via_set_primary_timing(const struct display_timing *timing)
+void via_set_primary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total / 8 - 5;
raw.hor_addr = timing-hor_addr / 8 - 1;
@@ -88,9 +88,9 @@ void via_set_primary_timing(const struct display_timing 
*timing)
via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
 }
 
-void via_set_secondary_timing(const struct display_timing *timing)
+void via_set_secondary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total - 1;
raw.hor_addr = timing-hor_addr - 1;
diff --git a/drivers/video/via/via_modesetting.h 
b/drivers/video/via/via_modesetting.h
index 06e09fe..f6a6503 100644
--- a/drivers/video/via/via_modesetting.h
+++ b/drivers/video/via/via_modesetting.h
@@ -33,7 +33,7 @@
 #define VIA_PITCH_MAX  0x3FF8
 
 
-struct display_timing {
+struct via_display_timing {
u16 hor_total;
u16 hor_addr;
u16 hor_blank_start;
@@ -49,8 +49,8 @@ struct display_timing {
 };
 
 
-void via_set_primary_timing(const struct display_timing *timing);
-void via_set_secondary_timing(const struct display_timing *timing);
+void via_set_primary_timing(const struct via_display_timing *timing);
+void via_set_secondary_timing(const struct via_display_timing

[PATCHv16 2/7] video: add display_timing and videomode

2012-12-18 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Also, add helper functions to convert from display timings to a generic 
videomode
structure.

The struct display_timing specifies all needed parameters to describe the signal
properties of a display in one mode. This includes
- ranges for signals that may have min-, max- and typical values
- single integers for signals that can be on, off or are ignored
- booleans for signals that are either on or off

As a display may support multiple modes like this, a struct display_timings is
added, that holds all given struct display_timing pointers and declares the
native mode of the display.

Although a display may state that a signal can be in a range, it is driven with
fixed values that indicate a videomode. Therefore graphic drivers don't need all
the information of struct display_timing, but would generate a videomode from
the given set of supported signal timings and work with that.

The video subsystems all define their own structs that describe a mode and work
with that (e.g. fb_videomode or drm_display_mode). To slowly replace all those
various structures and allow code reuse across those subsystems, add struct
videomode as a generic description.

This patch only includes the most basic fields in struct videomode. All missing
fields that are needed to have a really generic video mode description can be
added at a later stage.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/Kconfig  |6 ++
 drivers/video/Makefile |2 +
 drivers/video/display_timing.c |   24 
 drivers/video/videomode.c  |   39 +
 include/video/display_timing.h |  124 
 include/video/videomode.h  |   48 
 6 files changed, 243 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/video/display_timing.h
 create mode 100644 include/video/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..5e1822c
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/slab.h
+#include video/display_timing.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..21c47a2
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,39 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/errno.h
+#include linux/export.h
+#include video/display_timing.h
+#include video/videomode.h
+
+int videomode_from_timing(const struct display_timings *disp,
+ struct videomode *vm, unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, TE_TYP);
+   vm-hactive = display_timing_get_value(dt-hactive, TE_TYP);
+   vm-hfront_porch

[PATCHv16 0/7] of: add display helper

2012-12-18 Thread Steffen Trumtrar
Hi!

Finally, right in time before the end of the world on friday, v16 of the
display helpers.

Changes since v15:
- move include/linux/{videomode,display_timing}.h to include/video
- move include/linux/of_{videomode,display_timing}.h to include/video
- reimplement flags: add VESA flags and data flags
- let pixelclock in struct videomode be unsigned long
- rename of_display_timings_exists to of_display_timings_exist
- revise logging/error messages: replace __func__ with np-full_name
- rename pixelclk-inverted to pixelclk-active
- revise comments in code

Changes since v14:
- fix const struct * warning
(reported by: Leela Krishna Amudala l.kris...@samsung.com)
- return -EINVAL when htotal or vtotal are zero
- remove unreachable code in of_get_display_timings
- include headers in .c files and not implicit in .h
- sort includes alphabetically
- fix lower/uppercase in binding documentation
- rebase onto v3.7-rc7

Changes since v13:
- fix const struct * warning
(reported by: Laurent Pinchart 
laurent.pinch...@ideasonboard.com)
- prevent division by zero in fb_videomode_from_videomode

Changes since v12:
- rename struct display_timing to via_display_timing in via subsystem
- fix refreshrate calculation
- fix const struct * warnings
(reported by: Manjunathappa, Prakash prakash...@ti.com)
- some CodingStyle fixes
- rewrite parts of commit messages and display-timings.txt
- let display_timing_get_value get all values instead of just typical

Changes since v11:
- make pointers const where applicable
- add reviewed-by Laurent Pinchart

Changes since v10:
- fix function name (drm_)display_mode_from_videomode
- add acked-by, reviewed-by, tested-by

Changes since v9:
- don't leak memory when previous timings were correct
- CodingStyle fixes
- move blank lines around

Changes since v8:
- fix memory leaks
- change API to be more consistent (foo_from_bar(struct bar, struct 
foo))
- include headers were necessary
- misc minor bugfixes

Changes since v7:
- move of_xxx to drivers/video
- remove non-binding documentation from display-timings.txt
- squash display_timings and videomode in one patch
- misc minor fixes

Changes since v6:
- get rid of some empty lines etc.
- move functions to their subsystems
- split of_ from non-of_ functions
- add at least some kerneldoc to some functions

Changes since v5:
- removed all display stuff and just describe timings

Changes since v4:
- refactored functions

Changes since v3:
- print error messages
- free alloced memory
- general cleanup

Changes since v2:
- use hardware-near property-names
- provide a videomode structure
- allow ranges for all properties (min,typ,max)
- functions to get display_mode or fb_videomode


Regards,
Steffen


Steffen Trumtrar (7):
  viafb: rename display_timing to via_display_timing
  video: add display_timing and videomode
  video: add of helper for display timings/videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timing.txt   |  109 +
 drivers/gpu/drm/drm_modes.c|   70 ++
 drivers/video/Kconfig  |   21 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 ++
 drivers/video/fbmon.c  |   94 
 drivers/video/of_display_timing.c  |  239 
 drivers/video/of_videomode.c   |   54 +
 drivers/video/via/hw.c |6 +-
 drivers/video/via/hw.h |2 +-
 drivers/video/via/lcd.c|2 +-
 drivers/video/via/share.h  |2 +-
 drivers/video/via/via_modesetting.c|8 +-
 drivers/video/via/via_modesetting.h|6 +-
 drivers/video/videomode.c  |   39 
 include/drm/drmP.h |9 +
 include/linux/fb.h |8 +
 include/video/display_timing.h |  124 ++
 include/video/of_display_timing.h  |   20 ++
 include/video/of_videomode.h   |   18 ++
 include/video/videomode.h  |   48 
 21 files changed, 894 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/video/display-timing.txt
 create mode 100644 drivers/video

[PATCHv16 6/7] drm_modes: add videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |5 +
 2 files changed, 42 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..184a22d 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include video/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(const struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else if (vm-dmt_flags  VESA_DMT_HSYNC_LOW)
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-dmt_flags  VESA_DMT_VSYNC_HIGH)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else if (vm-dmt_flags  VESA_DMT_VSYNC_LOW)
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-data_flags  DISPLAY_FLAGS_INTERLACED)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-data_flags  DISPLAY_FLAGS_DOUBLESCAN)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..5fbb0fe 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,8 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct videomode;
+
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1454,6 +1456,9 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+extern int drm_display_mode_from_videomode(const struct videomode *vm,
+  struct drm_display_mode *dmode);
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 6/7] drm_modes: add videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |5 +
 2 files changed, 42 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..184a22d 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include video/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(const struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else if (vm-dmt_flags  VESA_DMT_HSYNC_LOW)
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-dmt_flags  VESA_DMT_VSYNC_HIGH)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else if (vm-dmt_flags  VESA_DMT_VSYNC_LOW)
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-data_flags  DISPLAY_FLAGS_INTERLACED)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-data_flags  DISPLAY_FLAGS_DOUBLESCAN)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..5fbb0fe 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,8 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct videomode;
+
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1454,6 +1456,9 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+extern int drm_display_mode_from_videomode(const struct videomode *vm,
+  struct drm_display_mode *dmode);
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 4/7] fbmon: add videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   52 +
 include/linux/fb.h|4 
 2 files changed, 56 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..17ce135 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include video/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,57 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   /* prevent division by zero in KHZ2PICOS macro */
+   fbmode-pixclock = vm-pixelclock ?
+   KHZ2PICOS(vm-pixelclock / 1000) : 0;
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-dmt_flags  VESA_DMT_HSYNC_HIGH)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-data_flags  DISPLAY_FLAGS_INTERLACED)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-data_flags  DISPLAY_FLAGS_DOUBLESCAN)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   /* prevent division by zero */
+   if (htotal  vtotal) {
+   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
+   /* a mode must have htotal and vtotal != 0 or it is invalid */
+   } else {
+   fbmode-refresh = 0;
+   return -EINVAL;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..100a176 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -19,6 +19,7 @@ struct vm_area_struct;
 struct fb_info;
 struct device;
 struct file;
+struct videomode;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -714,6 +715,9 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+extern int fb_videomode_from_videomode(const struct videomode *vm,
+  struct fb_videomode *fbmode);
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 3/7] video: add of helper for display timings/videomode

2012-12-18 Thread Steffen Trumtrar
This adds support for reading display timings from DT into a struct
display_timings. The of_display_timing implementation supports multiple
subnodes. All children are read into an array, that can be queried.

If no native mode is specified, the first subnode will be used.

For cases where the graphics driver knows there can be only one
mode description or where the driver only supports one mode, a helper
function of_get_videomode is added, that gets a struct videomode from DT.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 .../devicetree/bindings/video/display-timing.txt   |  109 +
 drivers/video/Kconfig  |   15 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  239 
 drivers/video/of_videomode.c   |   54 +
 include/video/of_display_timing.h  |   20 ++
 include/video/of_videomode.h   |   18 ++
 7 files changed, 457 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timing.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/video/of_display_timing.h
 create mode 100644 include/video/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timing.txt 
b/Documentation/devicetree/bindings/video/display-timing.txt
new file mode 100644
index 000..1500385
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timing.txt
@@ -0,0 +1,109 @@
+display-timing bindings
+===
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timing subnode
+--
+
+required properties:
+ - hactive, vactive: display resolution
+ - hfront-porch, hback-porch, hsync-len: horizontal display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: hsync pulse is active low/high/ignored
+ - vsync-active: vsync pulse is active low/high/ignored
+ - de-active: data-enable pulse is active low/high/ignored
+ - pixelclk-active: with
+   - active high = drive pixel data on rising edge/
+   sample data on falling edge
+   - active low  = drive pixel data on falling edge/
+   sample data on rising edge
+   - ignored = ignored
+ - interlaced (bool): boolean to enable interlaced mode
+ - doublescan (bool): boolean to enable doublescan mode
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The
+devicetree representation corresponds to the one commonly found in datasheets
+for displays. If a display supports multiple signal timings, the native-mode
+can be specified.
+
+The parameters are defined as:
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive #  |   |
+  |  #|#  |   |
+  |  #↓#  |   |
+  +--###--+---+
+  |  |↑|  |   |
+  |  ||vfront_porch

[PATCHv16 2/7] video: add display_timing and videomode

2012-12-18 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Also, add helper functions to convert from display timings to a generic 
videomode
structure.

The struct display_timing specifies all needed parameters to describe the signal
properties of a display in one mode. This includes
- ranges for signals that may have min-, max- and typical values
- single integers for signals that can be on, off or are ignored
- booleans for signals that are either on or off

As a display may support multiple modes like this, a struct display_timings is
added, that holds all given struct display_timing pointers and declares the
native mode of the display.

Although a display may state that a signal can be in a range, it is driven with
fixed values that indicate a videomode. Therefore graphic drivers don't need all
the information of struct display_timing, but would generate a videomode from
the given set of supported signal timings and work with that.

The video subsystems all define their own structs that describe a mode and work
with that (e.g. fb_videomode or drm_display_mode). To slowly replace all those
various structures and allow code reuse across those subsystems, add struct
videomode as a generic description.

This patch only includes the most basic fields in struct videomode. All missing
fields that are needed to have a really generic video mode description can be
added at a later stage.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/Kconfig  |6 ++
 drivers/video/Makefile |2 +
 drivers/video/display_timing.c |   24 
 drivers/video/videomode.c  |   39 +
 include/video/display_timing.h |  124 
 include/video/videomode.h  |   48 
 6 files changed, 243 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/video/display_timing.h
 create mode 100644 include/video/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..5e1822c
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/slab.h
+#include video/display_timing.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..21c47a2
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,39 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/errno.h
+#include linux/export.h
+#include video/display_timing.h
+#include video/videomode.h
+
+int videomode_from_timing(const struct display_timings *disp,
+ struct videomode *vm, unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, TE_TYP);
+   vm-hactive = display_timing_get_value(dt-hactive, TE_TYP);
+   vm-hfront_porch

[PATCHv16 7/7] drm_modes: add of_videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   33 +
 include/drm/drmP.h  |4 
 2 files changed, 37 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 184a22d..fd53454 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include video/of_videomode.h
 #include video/videomode.h
 
 /**
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_debug(%s: got %dx%d display mode from %s\n,
+   of_node_full_name(np), vm.hactive, vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 5fbb0fe..e26ca59 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,7 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct device_node;
 struct videomode;
 
 #include drm/drm_os_linux.h
@@ -1458,6 +1459,9 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 
 extern int drm_display_mode_from_videomode(const struct videomode *vm,
   struct drm_display_mode *dmode);
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  int index);
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 0/7] of: add display helper

2012-12-18 Thread Steffen Trumtrar
Hi!

Finally, right in time before the end of the world on friday, v16 of the
display helpers.

Changes since v15:
- move include/linux/{videomode,display_timing}.h to include/video
- move include/linux/of_{videomode,display_timing}.h to include/video
- reimplement flags: add VESA flags and data flags
- let pixelclock in struct videomode be unsigned long
- rename of_display_timings_exists to of_display_timings_exist
- revise logging/error messages: replace __func__ with np-full_name
- rename pixelclk-inverted to pixelclk-active
- revise comments in code

Changes since v14:
- fix const struct * warning
(reported by: Leela Krishna Amudala l.kris...@samsung.com)
- return -EINVAL when htotal or vtotal are zero
- remove unreachable code in of_get_display_timings
- include headers in .c files and not implicit in .h
- sort includes alphabetically
- fix lower/uppercase in binding documentation
- rebase onto v3.7-rc7

Changes since v13:
- fix const struct * warning
(reported by: Laurent Pinchart 
laurent.pinch...@ideasonboard.com)
- prevent division by zero in fb_videomode_from_videomode

Changes since v12:
- rename struct display_timing to via_display_timing in via subsystem
- fix refreshrate calculation
- fix const struct * warnings
(reported by: Manjunathappa, Prakash prakash...@ti.com)
- some CodingStyle fixes
- rewrite parts of commit messages and display-timings.txt
- let display_timing_get_value get all values instead of just typical

Changes since v11:
- make pointers const where applicable
- add reviewed-by Laurent Pinchart

Changes since v10:
- fix function name (drm_)display_mode_from_videomode
- add acked-by, reviewed-by, tested-by

Changes since v9:
- don't leak memory when previous timings were correct
- CodingStyle fixes
- move blank lines around

Changes since v8:
- fix memory leaks
- change API to be more consistent (foo_from_bar(struct bar, struct 
foo))
- include headers were necessary
- misc minor bugfixes

Changes since v7:
- move of_xxx to drivers/video
- remove non-binding documentation from display-timings.txt
- squash display_timings and videomode in one patch
- misc minor fixes

Changes since v6:
- get rid of some empty lines etc.
- move functions to their subsystems
- split of_ from non-of_ functions
- add at least some kerneldoc to some functions

Changes since v5:
- removed all display stuff and just describe timings

Changes since v4:
- refactored functions

Changes since v3:
- print error messages
- free alloced memory
- general cleanup

Changes since v2:
- use hardware-near property-names
- provide a videomode structure
- allow ranges for all properties (min,typ,max)
- functions to get display_mode or fb_videomode

Regards,
Steffen



Steffen Trumtrar (7):
  viafb: rename display_timing to via_display_timing
  video: add display_timing and videomode
  video: add of helper for display timings/videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timing.txt   |  109 +
 drivers/gpu/drm/drm_modes.c|   70 ++
 drivers/video/Kconfig  |   21 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 ++
 drivers/video/fbmon.c  |   94 
 drivers/video/of_display_timing.c  |  239 
 drivers/video/of_videomode.c   |   54 +
 drivers/video/via/hw.c |6 +-
 drivers/video/via/hw.h |2 +-
 drivers/video/via/lcd.c|2 +-
 drivers/video/via/share.h  |2 +-
 drivers/video/via/via_modesetting.c|8 +-
 drivers/video/via/via_modesetting.h|6 +-
 drivers/video/videomode.c  |   39 
 include/drm/drmP.h |9 +
 include/linux/fb.h |8 +
 include/video/display_timing.h |  124 ++
 include/video/of_display_timing.h  |   20 ++
 include/video/of_videomode.h   |   18 ++
 include/video/videomode.h  |   48 
 21 files changed, 894 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/video/display-timing.txt
 create mode 100644 drivers/video

[PATCHv16 5/7] fbmon: add of_videomode helpers

2012-12-18 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   42 ++
 include/linux/fb.h|4 
 2 files changed, 46 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 17ce135..94ad0f7 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include video/of_videomode.h
 #include video/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
@@ -1425,6 +1426,47 @@ int fb_videomode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(const struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+   int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_debug(%s: got %dx%d display mode from %s\n,
+   of_node_full_name(np), vm.hactive, vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 100a176..58b9860 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -20,6 +20,7 @@ struct fb_info;
 struct device;
 struct file;
 struct videomode;
+struct device_node;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -715,6 +716,9 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+extern int of_get_fb_videomode(struct device_node *np,
+  struct fb_videomode *fb,
+  int index);
 extern int fb_videomode_from_videomode(const struct videomode *vm,
   struct fb_videomode *fbmode);
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv16 1/7] viafb: rename display_timing to via_display_timing

2012-12-18 Thread Steffen Trumtrar
The struct display_timing is specific to the via subsystem. The naming leads to
collisions with the new struct display_timing, which is supposed to be a shared
struct between different subsystems.
To clean this up, prepend the existing struct with the subsystem it is specific
to.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/via/hw.c  |6 +++---
 drivers/video/via/hw.h  |2 +-
 drivers/video/via/lcd.c |2 +-
 drivers/video/via/share.h   |2 +-
 drivers/video/via/via_modesetting.c |8 
 drivers/video/via/via_modesetting.h |6 +++---
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 898590d..5563c67 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,10 +1467,10 @@ void viafb_set_vclock(u32 clk, int set_iga)
via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres)
 {
-   struct display_timing timing;
+   struct via_display_timing timing;
u16 dx = (var-xres - cxres) / 2, dy = (var-yres - cyres) / 2;
 
timing.hor_addr = cxres;
@@ -1491,7 +1491,7 @@ struct display_timing var_to_timing(const struct 
fb_var_screeninfo *var,
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga)
 {
-   struct display_timing crt_reg = var_to_timing(var,
+   struct via_display_timing crt_reg = var_to_timing(var,
cxres ? cxres : var-xres, cyres ? cyres : var-yres);
 
if (iga == IGA1)
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 6be243c..c3f2572 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,7 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres);
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga);
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 1650379..022b0df 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -549,7 +549,7 @@ void viafb_lcd_set_mode(const struct fb_var_screeninfo 
*var, u16 cxres,
int panel_hres = plvds_setting_info-lcd_panel_hres;
int panel_vres = plvds_setting_info-lcd_panel_vres;
u32 clock;
-   struct display_timing timing;
+   struct via_display_timing timing;
struct fb_var_screeninfo panel_var;
const struct fb_videomode *mode_crt_table, *panel_crt_table;
 
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 3158dfc..65c65c6 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -319,7 +319,7 @@ struct crt_mode_table {
int refresh_rate;
int h_sync_polarity;
int v_sync_polarity;
-   struct display_timing crtc;
+   struct via_display_timing crtc;
 };
 
 struct io_reg {
diff --git a/drivers/video/via/via_modesetting.c 
b/drivers/video/via/via_modesetting.c
index 0e431ae..0b414b0 100644
--- a/drivers/video/via/via_modesetting.c
+++ b/drivers/video/via/via_modesetting.c
@@ -30,9 +30,9 @@
 #include debug.h
 
 
-void via_set_primary_timing(const struct display_timing *timing)
+void via_set_primary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total / 8 - 5;
raw.hor_addr = timing-hor_addr / 8 - 1;
@@ -88,9 +88,9 @@ void via_set_primary_timing(const struct display_timing 
*timing)
via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
 }
 
-void via_set_secondary_timing(const struct display_timing *timing)
+void via_set_secondary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total - 1;
raw.hor_addr = timing-hor_addr - 1;
diff --git a/drivers/video/via/via_modesetting.h 
b/drivers/video/via/via_modesetting.h
index 06e09fe..f6a6503 100644
--- a/drivers/video/via/via_modesetting.h
+++ b/drivers/video/via/via_modesetting.h
@@ -33,7 +33,7 @@
 #define VIA_PITCH_MAX  0x3FF8
 
 
-struct display_timing {
+struct via_display_timing {
u16 hor_total;
u16 hor_addr;
u16 hor_blank_start;
@@ -49,8 +49,8 @@ struct display_timing {
 };
 
 
-void via_set_primary_timing(const struct display_timing *timing);
-void via_set_secondary_timing(const struct display_timing *timing);
+void via_set_primary_timing(const struct via_display_timing *timing);
+void via_set_secondary_timing(const struct via_display_timing

Re: [PATCHv15 3/7] video: add of helper for display timings/videomode

2012-12-10 Thread Steffen Trumtrar
Hi,

On Fri, Dec 07, 2012 at 03:12:48PM +0100, Philipp Zabel wrote:
 Hi,
 
 Am Montag, den 26.11.2012, 18:56 +0200 schrieb Tomi Valkeinen:
  On 2012-11-26 18:10, Steffen Trumtrar wrote:
   Hi,
   
   On Mon, Nov 26, 2012 at 04:38:36PM +0200, Tomi Valkeinen wrote:
  
   +optional properties:
   + - hsync-active: hsync pulse is active low/high/ignored
   + - vsync-active: vsync pulse is active low/high/ignored
   + - de-active: data-enable pulse is active low/high/ignored
   + - pixelclk-inverted: pixelclock is inverted (active on falling edge)/
   +   non-inverted (active on rising edge)/
   +ignored (ignore property)
  
   I think hsync-active and vsync-active are clear, and commonly used, and
   they are used for both drm and fb mode conversions in later patches.
  
   de-active is not used in drm and fb mode conversions, but I think it's
   also clear.
  
   pixelclk-inverted is not used in the mode conversions. It's also a bit
   unclear to me. What does it mean that pix clock is active on rising
   edge? The pixel data is driven on rising edge? How about the sync
   signals and DE, when are they driven? Does your HW have any settings
   related to those?
  
   
   Those are properties commonly found in display specs. That is why they 
   are here.
   If the GPU does not support the property it can be omitted.
  
  So what does the pixelclk-inverted mean? Normally the SoC drives pixel
  data on rising edge, and the panel samples it at falling edge? And
  vice-versa for inverted? Or the other way around?
 
  When is hsync/vsync set? On rising or falling edge of pclk?
 
  My point here is that the pixelclk-inverted is not crystal clear thing,
  like the hsync/vsync/de-active values are.
 
  And while thinking about this, I realized that the meaning of
  pixelclk-inverted depends on what component is it applied to. Presuming
  normal pixclk means pixel data on rising edge, the meaning of that
  depends on do we consider the SoC or the panel. The panel needs to
  sample the data on the other edge from the one the SoC uses to drive the
  data.
  
  Does the videomode describe the panel, or does it describe the settings
  programmed to the SoC?
 
 How about calling this property pixelclk-active, active high meaning
 driving pixel data on rising edges and sampling on falling edges (the
 pixel clock is high between driving and sampling the data), and active
 low meaning driving on falling edges and sampling on rising edges?
 It is the same from the SoC perspective and from the panel perspective,
 and it mirrors the usage of the other *-active properties.
 

I think, this would not be a bad idea. I would include Philipps description in 
the
display-timing.txt, as it makes the meaning pretty clear; at least to me.

What do the others think about this?

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv15 0/7] of: add display helper

2012-12-05 Thread Steffen Trumtrar
Hi Leela,

unfortunately, nothing new as of yet. I have to work on other stuff at the 
moment.

Regards,
Steffen


On Wed, Dec 05, 2012 at 01:25:30PM +0530, Leela Krishna Amudala wrote:
 Hello Steffen,
 
 Any update on version 16 ?
 
 Best Wishes,
 Leela Krishna Amudala.
 
 On Mon, Nov 26, 2012 at 2:37 PM, Steffen Trumtrar
 s.trumt...@pengutronix.de wrote:
  Hi!
 
  Changes since v14:
  - fix const struct * warning
  (reported by: Leela Krishna Amudala l.kris...@samsung.com)
  - return -EINVAL when htotal or vtotal are zero
  - remove unreachable code in of_get_display_timings
  - include headers in .c files and not implicit in .h
  - sort includes alphabetically
  - fix lower/uppercase in binding documentation
  - rebase onto v3.7-rc7
 
  Changes since v13:
  - fix const struct * warning
  (reported by: Laurent Pinchart 
  laurent.pinch...@ideasonboard.com)
  - prevent division by zero in fb_videomode_from_videomode
 
  Changes since v12:
  - rename struct display_timing to via_display_timing in via 
  subsystem
  - fix refreshrate calculation
  - fix const struct * warnings
  (reported by: Manjunathappa, Prakash prakash...@ti.com)
  - some CodingStyle fixes
  - rewrite parts of commit messages and display-timings.txt
  - let display_timing_get_value get all values instead of just 
  typical
 
  Changes since v11:
  - make pointers const where applicable
  - add reviewed-by Laurent Pinchart
 
  Changes since v10:
  - fix function name (drm_)display_mode_from_videomode
  - add acked-by, reviewed-by, tested-by
 
  Changes since v9:
  - don't leak memory when previous timings were correct
  - CodingStyle fixes
  - move blank lines around
 
  Changes since v8:
  - fix memory leaks
  - change API to be more consistent (foo_from_bar(struct bar, struct 
  foo))
  - include headers were necessary
  - misc minor bufixe
 
  Changes since v7:
  - move of_xxx to drivers/video
  - remove non-binding documentation from display-timings.txt
  - squash display_timings and videomode in one patch
  - misc minor fixes
 
  Changes since v6:
  - get rid of some empty lines etc.
  - move functions to their subsystems
  - split of_ from non-of_ functions
  - add at least some kerneldoc to some functions
 
  Changes since v5:
  - removed all display stuff and just describe timings
 
  Changes since v4:
  - refactored functions
 
  Changes since v3:
  - print error messages
  - free alloced memory
  - general cleanup
 
  Changes since v2:
  - use hardware-near property-names
  - provide a videomode structure
  - allow ranges for all properties (min,typ,max)
  - functions to get display_mode or fb_videomode
 
 
  Steffen Trumtrar (7):
viafb: rename display_timing to via_display_timing
video: add display_timing and videomode
video: add of helper for display timings/videomode
fbmon: add videomode helpers
fbmon: add of_videomode helpers
drm_modes: add videomode helpers
drm_modes: add of_videomode helpers
 
   .../devicetree/bindings/video/display-timing.txt   |  107 ++
   drivers/gpu/drm/drm_modes.c|   70 +++
   drivers/video/Kconfig  |   21 ++
   drivers/video/Makefile |4 +
   drivers/video/display_timing.c |   24 +++
   drivers/video/fbmon.c  |   93 +
   drivers/video/of_display_timing.c  |  219 
  
   drivers/video/of_videomode.c   |   54 +
   drivers/video/via/hw.c |6 +-
   drivers/video/via/hw.h |2 +-
   drivers/video/via/lcd.c|2 +-
   drivers/video/via/share.h  |2 +-
   drivers/video/via/via_modesetting.c|8 +-
   drivers/video/via/via_modesetting.h|6 +-
   drivers/video/videomode.c  |   44 
   include/drm/drmP.h |   13 ++
   include/linux/display_timing.h |  104 ++
   include/linux/fb.h |   12 ++
   include/linux/of_display_timing.h  |   20 ++
   include/linux/of_videomode.h   |   18 ++
   include/linux/videomode.h  |   54 +
   21 files changed, 870 insertions(+), 13 deletions(-)
   create mode 100644 
  Documentation/devicetree/bindings/video/display-timing.txt
   create mode 100644 drivers/video/display_timing.c
   create mode 100644 drivers/video

[PATCHv15 6/7] drm_modes: add videomode helpers

2012-11-26 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |7 +++
 2 files changed, 44 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..8263ea1 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -33,6 +33,7 @@
 #include linux/list.h
 #include linux/list_sort.h
 #include linux/export.h
+#include linux/videomode.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
 
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(const struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-hah)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-vah)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-interlaced)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-doublescan)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..2194e97 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,8 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct videomode;
+
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1454,6 +1456,11 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int drm_display_mode_from_videomode(const struct videomode *vm,
+  struct drm_display_mode *dmode);
+#endif
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv15 2/7] video: add display_timing and videomode

2012-11-26 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Also, add helper functions to convert from display timings to a generic 
videomode
structure.

The struct display_timing specifies all needed parameters to describe the signal
properties of a display in one mode. This includes
- ranges for signals that may have min-, max- and typical values
- single integers for signals that can be on, off or are ignored
- booleans for signals that are either on or off

As a display may support multiple modes like this, a struct display_timings is
added, that holds all given struct display_timing pointers and declares the
native mode of the display.

Although a display may state that a signal can be in a range, it is driven with
fixed values that indicate a videomode. Therefore graphic drivers don't need all
the information of struct display_timing, but would generate a videomode from
the given set of supported signal timings and work with that.

The video subsystems all define their own structs that describe a mode and work
with that (e.g. fb_videomode or drm_display_mode). To slowly replace all those
various structures and allow code reuse across those subsystems, add struct
videomode as a generic description.

This patch only includes the most basic fields in struct videomode. All missing
fields that are needed to have a really generic video mode description can be
added at a later stage.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/Kconfig  |6 +++
 drivers/video/Makefile |2 +
 drivers/video/display_timing.c |   24 ++
 drivers/video/videomode.c  |   44 +
 include/linux/display_timing.h |  104 
 include/linux/videomode.h  |   54 +
 6 files changed, 234 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..ac9bbbc
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/display_timing.h
+#include linux/export.h
+#include linux/slab.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..784eaad
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,44 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/display_timing.h
+#include linux/errno.h
+#include linux/export.h
+#include linux/videomode.h
+
+int videomode_from_timing(const struct display_timings *disp,
+ struct videomode *vm, unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, TE_TYP);
+   vm-hactive = display_timing_get_value(dt-hactive, TE_TYP

[PATCHv15 5/7] fbmon: add of_videomode helpers

2012-11-26 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/fbmon.c |   42 ++
 include/linux/fb.h|6 ++
 2 files changed, 48 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 733553b..4a8484d 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -28,6 +28,7 @@
  */
 #include linux/fb.h
 #include linux/module.h
+#include linux/of_videomode.h
 #include linux/pci.h
 #include linux/slab.h
 #include linux/videomode.h
@@ -1424,6 +1425,47 @@ int fb_videomode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(const struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+   int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 4404ec2..c2d933d 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -20,6 +20,7 @@ struct fb_info;
 struct device;
 struct file;
 struct videomode;
+struct device_node;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -715,6 +716,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_fb_videomode(struct device_node *np,
+  struct fb_videomode *fb,
+  int index);
+#endif
 #if IS_ENABLED(CONFIG_VIDEOMODE)
 extern int fb_videomode_from_videomode(const struct videomode *vm,
   struct fb_videomode *fbmode);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv15 4/7] fbmon: add videomode helpers

2012-11-26 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/fbmon.c |   51 +
 include/linux/fb.h|6 ++
 2 files changed, 57 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..733553b 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -30,6 +30,7 @@
 #include linux/module.h
 #include linux/pci.h
 #include linux/slab.h
+#include linux/videomode.h
 #include video/edid.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
@@ -1373,6 +1374,56 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   /* prevent division by zero in KHZ2PICOS macro */
+   fbmode-pixclock = vm-pixelclock ? KHZ2PICOS(vm-pixelclock / 1000) : 
0;
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-hah)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-vah)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-interlaced)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-doublescan)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   /* prevent division by zero */
+   if (htotal  vtotal)
+   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
+   /* a mode must have htotal and vtotal != 0 or it is invalid */
+   else {
+   fbmode-refresh = 0;
+   return -EINVAL;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..4404ec2 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -19,6 +19,7 @@ struct vm_area_struct;
 struct fb_info;
 struct device;
 struct file;
+struct videomode;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -714,6 +715,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int fb_videomode_from_videomode(const struct videomode *vm,
+  struct fb_videomode *fbmode);
+#endif
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv15 3/7] video: add of helper for display timings/videomode

2012-11-26 Thread Steffen Trumtrar
This adds support for reading display timings from DT into a struct
display_timings. The of_display_timing implementation supports multiple
subnodes. All children are read into an array, that can be queried.

If no native mode is specified, the first subnode will be used.

For cases where the graphics driver knows there can be only one
mode description or where the driver only supports one mode, a helper
function of_get_videomode is added, that gets a struct videomode from DT.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 .../devicetree/bindings/video/display-timing.txt   |  107 ++
 drivers/video/Kconfig  |   15 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  219 
 drivers/video/of_videomode.c   |   54 +
 include/linux/of_display_timing.h  |   20 ++
 include/linux/of_videomode.h   |   18 ++
 7 files changed, 435 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timing.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/linux/of_display_timing.h
 create mode 100644 include/linux/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timing.txt 
b/Documentation/devicetree/bindings/video/display-timing.txt
new file mode 100644
index 000..e238f27
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timing.txt
@@ -0,0 +1,107 @@
+display-timing bindings
+===
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timing subnode
+--
+
+required properties:
+ - hactive, vactive: display resolution
+ - hfront-porch, hback-porch, hsync-len: horizontal display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: hsync pulse is active low/high/ignored
+ - vsync-active: vsync pulse is active low/high/ignored
+ - de-active: data-enable pulse is active low/high/ignored
+ - pixelclk-inverted: pixelclock is inverted (active on falling edge)/
+   non-inverted (active on rising edge)/
+ignored (ignore property)
+ - interlaced (bool): boolean to enable interlaced mode
+ - doublescan (bool): boolean to enable doublescan mode
+ - doubleclk (bool)
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The 
devicetree
+representation corresponds to the one commonly found in datasheets for 
displays.
+If a display supports multiple signal timings, the native-mode can be 
specified.
+
+The parameters are defined as
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive #  |   |
+  |  #|#  |   |
+  |  #↓#  |   |
+  +--###--+---+
+  |  |↑|  |   |
+  |  ||vfront_porch

[PATCHv15 7/7] drm_modes: add of_videomode helpers

2012-11-26 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   33 +
 include/drm/drmP.h  |6 ++
 2 files changed, 39 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 8263ea1..3568f0a 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -33,6 +33,7 @@
 #include linux/list.h
 #include linux/list_sort.h
 #include linux/export.h
+#include linux/of_videomode.h
 #include linux/videomode.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 2194e97..1784e55 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,7 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct device_node;
 struct videomode;
 
 #include drm/drm_os_linux.h
@@ -1460,6 +1461,11 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 extern int drm_display_mode_from_videomode(const struct videomode *vm,
   struct drm_display_mode *dmode);
 #endif
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  int index);
+#endif
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv15 1/7] viafb: rename display_timing to via_display_timing

2012-11-26 Thread Steffen Trumtrar
The struct display_timing is specific to the via subsystem. The naming leads to
collisions with the new struct display_timing, that is supposed to be a shared
struct between different subsystems.
To clean this up, prepend the existing struct with the subsystem it is specific
to.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/via/hw.c  |6 +++---
 drivers/video/via/hw.h  |2 +-
 drivers/video/via/lcd.c |2 +-
 drivers/video/via/share.h   |2 +-
 drivers/video/via/via_modesetting.c |8 
 drivers/video/via/via_modesetting.h |6 +++---
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 898590d..5563c67 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,10 +1467,10 @@ void viafb_set_vclock(u32 clk, int set_iga)
via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres)
 {
-   struct display_timing timing;
+   struct via_display_timing timing;
u16 dx = (var-xres - cxres) / 2, dy = (var-yres - cyres) / 2;
 
timing.hor_addr = cxres;
@@ -1491,7 +1491,7 @@ struct display_timing var_to_timing(const struct 
fb_var_screeninfo *var,
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga)
 {
-   struct display_timing crt_reg = var_to_timing(var,
+   struct via_display_timing crt_reg = var_to_timing(var,
cxres ? cxres : var-xres, cyres ? cyres : var-yres);
 
if (iga == IGA1)
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 6be243c..c3f2572 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,7 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres);
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga);
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 1650379..022b0df 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -549,7 +549,7 @@ void viafb_lcd_set_mode(const struct fb_var_screeninfo 
*var, u16 cxres,
int panel_hres = plvds_setting_info-lcd_panel_hres;
int panel_vres = plvds_setting_info-lcd_panel_vres;
u32 clock;
-   struct display_timing timing;
+   struct via_display_timing timing;
struct fb_var_screeninfo panel_var;
const struct fb_videomode *mode_crt_table, *panel_crt_table;
 
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 3158dfc..65c65c6 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -319,7 +319,7 @@ struct crt_mode_table {
int refresh_rate;
int h_sync_polarity;
int v_sync_polarity;
-   struct display_timing crtc;
+   struct via_display_timing crtc;
 };
 
 struct io_reg {
diff --git a/drivers/video/via/via_modesetting.c 
b/drivers/video/via/via_modesetting.c
index 0e431ae..0b414b0 100644
--- a/drivers/video/via/via_modesetting.c
+++ b/drivers/video/via/via_modesetting.c
@@ -30,9 +30,9 @@
 #include debug.h
 
 
-void via_set_primary_timing(const struct display_timing *timing)
+void via_set_primary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total / 8 - 5;
raw.hor_addr = timing-hor_addr / 8 - 1;
@@ -88,9 +88,9 @@ void via_set_primary_timing(const struct display_timing 
*timing)
via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
 }
 
-void via_set_secondary_timing(const struct display_timing *timing)
+void via_set_secondary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total - 1;
raw.hor_addr = timing-hor_addr - 1;
diff --git a/drivers/video/via/via_modesetting.h 
b/drivers/video/via/via_modesetting.h
index 06e09fe..f6a6503 100644
--- a/drivers/video/via/via_modesetting.h
+++ b/drivers/video/via/via_modesetting.h
@@ -33,7 +33,7 @@
 #define VIA_PITCH_MAX  0x3FF8
 
 
-struct display_timing {
+struct via_display_timing {
u16 hor_total;
u16 hor_addr;
u16 hor_blank_start;
@@ -49,8 +49,8 @@ struct display_timing {
 };
 
 
-void via_set_primary_timing(const struct display_timing *timing);
-void via_set_secondary_timing(const struct display_timing *timing);
+void via_set_primary_timing(const struct via_display_timing *timing);
+void via_set_secondary_timing(const struct via_display_timing

[PATCHv15 0/7] of: add display helper

2012-11-26 Thread Steffen Trumtrar
Hi!

Changes since v14:
- fix const struct * warning
(reported by: Leela Krishna Amudala l.kris...@samsung.com)
- return -EINVAL when htotal or vtotal are zero
- remove unreachable code in of_get_display_timings
- include headers in .c files and not implicit in .h
- sort includes alphabetically
- fix lower/uppercase in binding documentation
- rebase onto v3.7-rc7

Changes since v13:
- fix const struct * warning
(reported by: Laurent Pinchart 
laurent.pinch...@ideasonboard.com)
- prevent division by zero in fb_videomode_from_videomode

Changes since v12:
- rename struct display_timing to via_display_timing in via subsystem
- fix refreshrate calculation
- fix const struct * warnings
(reported by: Manjunathappa, Prakash prakash...@ti.com)
- some CodingStyle fixes
- rewrite parts of commit messages and display-timings.txt
- let display_timing_get_value get all values instead of just typical

Changes since v11:
- make pointers const where applicable
- add reviewed-by Laurent Pinchart

Changes since v10:
- fix function name (drm_)display_mode_from_videomode
- add acked-by, reviewed-by, tested-by

Changes since v9:
- don't leak memory when previous timings were correct
- CodingStyle fixes
- move blank lines around

Changes since v8:
- fix memory leaks
- change API to be more consistent (foo_from_bar(struct bar, struct 
foo))
- include headers were necessary
- misc minor bufixe

Changes since v7:
- move of_xxx to drivers/video
- remove non-binding documentation from display-timings.txt
- squash display_timings and videomode in one patch
- misc minor fixes

Changes since v6:
- get rid of some empty lines etc.
- move functions to their subsystems
- split of_ from non-of_ functions
- add at least some kerneldoc to some functions

Changes since v5:
- removed all display stuff and just describe timings

Changes since v4:
- refactored functions

Changes since v3:
- print error messages
- free alloced memory
- general cleanup

Changes since v2:
- use hardware-near property-names
- provide a videomode structure
- allow ranges for all properties (min,typ,max)
- functions to get display_mode or fb_videomode


Steffen Trumtrar (7):
  viafb: rename display_timing to via_display_timing
  video: add display_timing and videomode
  video: add of helper for display timings/videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timing.txt   |  107 ++
 drivers/gpu/drm/drm_modes.c|   70 +++
 drivers/video/Kconfig  |   21 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 +++
 drivers/video/fbmon.c  |   93 +
 drivers/video/of_display_timing.c  |  219 
 drivers/video/of_videomode.c   |   54 +
 drivers/video/via/hw.c |6 +-
 drivers/video/via/hw.h |2 +-
 drivers/video/via/lcd.c|2 +-
 drivers/video/via/share.h  |2 +-
 drivers/video/via/via_modesetting.c|8 +-
 drivers/video/via/via_modesetting.h|6 +-
 drivers/video/videomode.c  |   44 
 include/drm/drmP.h |   13 ++
 include/linux/display_timing.h |  104 ++
 include/linux/fb.h |   12 ++
 include/linux/of_display_timing.h  |   20 ++
 include/linux/of_videomode.h   |   18 ++
 include/linux/videomode.h  |   54 +
 21 files changed, 870 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/video/display-timing.txt
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/of_display_timing.h
 create mode 100644 include/linux/of_videomode.h
 create mode 100644 include/linux/videomode.h

-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv15 2/7] video: add display_timing and videomode

2012-11-26 Thread Steffen Trumtrar
On Mon, Nov 26, 2012 at 02:37:26PM +0200, Tomi Valkeinen wrote:
 On 2012-11-26 11:07, Steffen Trumtrar wrote:
 
  +/*
  + * Subsystem independent description of a videomode.
  + * Can be generated from struct display_timing.
  + */
  +struct videomode {
  +   u32 pixelclock; /* pixelclock in Hz */
 
 I don't know if this is of any importance, but the linux clock framework
 manages clock rates with unsigned long. Would it be better to use the
 same type here?
 

Hm, I don't know. Anyone? u32 should be large enough for a pixelclock.

  +   u32 hactive;
  +   u32 hfront_porch;
  +   u32 hback_porch;
  +   u32 hsync_len;
  +
  +   u32 vactive;
  +   u32 vfront_porch;
  +   u32 vback_porch;
  +   u32 vsync_len;
  +
  +   u32 hah;/* hsync active high */
  +   u32 vah;/* vsync active high */
  +   u32 de; /* data enable */
  +   u32 pixelclk_pol;
 
 What values will these 4 have? Aren't these booleans?
 
 The data enable comment should be data enable active high.
 
 The next patch says in the devtree binding documentation that the values
 may be on/off/ignored. Is that represented here somehow, i.e. values are
 0/1/2 or so? If not, what does it mean if the value is left out from
 devtree data, meaning not used on hardware?


Hm, I think you might be right here. It is no problem in the DT part of the 
code.
The properties are optional, left out means not used on hardware.
But this does not propagate correctly to the videomode. I should set the fields
to -EINVAL in case they are omitted, than everything should work nicely.

 There's also a doubleclk value mentioned in the devtree bindings doc,
 but not shown here.
 

Argh. That slipped through. I have patches that add this property to all
structs and the devicetree binding. But it is not supposed to be in this
series, because I want to at least have the binding stable for now.

 I think this videomode struct is the one that display drivers are going
 to use (?), in addition to the display_timing, so it would be good to
 document it well.
 

Yes. Maybe I have to put more of the devicetree documentation in the code.

Regards,
Steffen


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv15 3/7] video: add of helper for display timings/videomode

2012-11-26 Thread Steffen Trumtrar
Hi,

On Mon, Nov 26, 2012 at 04:38:36PM +0200, Tomi Valkeinen wrote:
 Hi,
 
 On 2012-11-26 11:07, Steffen Trumtrar wrote:
  This adds support for reading display timings from DT into a struct
  display_timings. The of_display_timing implementation supports multiple
  subnodes. All children are read into an array, that can be queried.
  
  If no native mode is specified, the first subnode will be used.
  
  For cases where the graphics driver knows there can be only one
  mode description or where the driver only supports one mode, a helper
  function of_get_videomode is added, that gets a struct videomode from DT.
  
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  Signed-off-by: Philipp Zabel p.za...@pengutronix.de
  Acked-by: Stephen Warren swar...@nvidia.com
  Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
  Acked-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Philipp Zabel p.za...@pengutronix.de
  Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  ---
   .../devicetree/bindings/video/display-timing.txt   |  107 ++
   drivers/video/Kconfig  |   15 ++
   drivers/video/Makefile |2 +
   drivers/video/of_display_timing.c  |  219 
  
   drivers/video/of_videomode.c   |   54 +
   include/linux/of_display_timing.h  |   20 ++
   include/linux/of_videomode.h   |   18 ++
   7 files changed, 435 insertions(+)
   create mode 100644 
  Documentation/devicetree/bindings/video/display-timing.txt
   create mode 100644 drivers/video/of_display_timing.c
   create mode 100644 drivers/video/of_videomode.c
   create mode 100644 include/linux/of_display_timing.h
   create mode 100644 include/linux/of_videomode.h
  
  diff --git a/Documentation/devicetree/bindings/video/display-timing.txt 
  b/Documentation/devicetree/bindings/video/display-timing.txt
  new file mode 100644
  index 000..e238f27
  --- /dev/null
  +++ b/Documentation/devicetree/bindings/video/display-timing.txt
  @@ -0,0 +1,107 @@
  +display-timing bindings
  +===
  +
  +display-timings node
  +
  +
  +required properties:
  + - none
  +
  +optional properties:
  + - native-mode: The native mode for the display, in case multiple modes are
  +   provided. When omitted, assume the first node is the native.
  +
  +timing subnode
  +--
  +
  +required properties:
  + - hactive, vactive: display resolution
  + - hfront-porch, hback-porch, hsync-len: horizontal display timing 
  parameters
  +   in pixels
  +   vfront-porch, vback-porch, vsync-len: vertical display timing 
  parameters in
  +   lines
  + - clock-frequency: display clock in Hz
  +
  +optional properties:
  + - hsync-active: hsync pulse is active low/high/ignored
  + - vsync-active: vsync pulse is active low/high/ignored
  + - de-active: data-enable pulse is active low/high/ignored
  + - pixelclk-inverted: pixelclock is inverted (active on falling edge)/
  +   non-inverted (active on rising edge)/
  +ignored (ignore property)
 
 I think hsync-active and vsync-active are clear, and commonly used, and
 they are used for both drm and fb mode conversions in later patches.
 
 de-active is not used in drm and fb mode conversions, but I think it's
 also clear.
 
 pixelclk-inverted is not used in the mode conversions. It's also a bit
 unclear to me. What does it mean that pix clock is active on rising
 edge? The pixel data is driven on rising edge? How about the sync
 signals and DE, when are they driven? Does your HW have any settings
 related to those?
 

Those are properties commonly found in display specs. That is why they are here.
If the GPU does not support the property it can be omitted.

 OMAP has the invert pclk setting, but it also has a setting to define
 when the sync signals are driven. The options are:
 - syncs are driven on rising edge of pclk
 - syncs are driven on falling edge of pclk
 - syncs are driven on the opposite edge of pclk compared to the pixel data
 
 For DE there's no setting, except the active high/low.
 
 And if I'm not mistaken, if the optional properties are not defined,
 they are not ignored, but left to the default 0. Which means active low,
 or active on rising edge(?). I think it would be good to have a
 undefined value for the properties.
 

Yes. As mentioned in my other mail, the intention of the omitted properties do
not propagate properly. Omitted must be a value  0, so it is clear in a later
stage, that this property shall not be used. And isn't unintentionally 
considered
to be active low.

  + - interlaced (bool): boolean to enable interlaced mode
  + - doublescan (bool): boolean to enable doublescan mode

Re: [PATCHv13 4/7] fbmon: add videomode helpers

2012-11-23 Thread Steffen Trumtrar
On Fri, Nov 23, 2012 at 12:52:08AM +0100, Laurent Pinchart wrote:
 On Friday 23 November 2012 00:09:49 Steffen Trumtrar wrote:
  On Thu, Nov 22, 2012 at 07:31:39PM +0100, Laurent Pinchart wrote:
   On Thursday 22 November 2012 17:00:12 Steffen Trumtrar wrote:
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---

 drivers/video/fbmon.c |   44 ++
 include/linux/fb.h|6 ++
 2 files changed, 50 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..a6a564d 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@

 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h

+#include linux/videomode.h

 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h

@@ -1373,6 +1374,49 @@ int fb_get_mode(int flags, u32 val, struct
fb_var_screeninfo *var, struct fb_inf kfree(timings);

return err;
 
 }

+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   fbmode-pixclock = KHZ2PICOS(vm-pixelclock / 1000);
   
   This results in a division by 0 if vm-pixelclock is equal to zero. As the
   information is missing from many board files, what would you think about
   the following ?
   
 fbmode-pixclock = vm-pixelclock ? KHZ2PICOS(vm-pixelclock / 1000) : 
   0;
  
  Grrr...you are right. I will fix that...
 
 Thank you.
 

I have to thank you for bulletproofing my code o/\o

+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
+
  
  ...and obviously this, too.
 
 That one is less of an issue in my opinion. A mode with a zero htotal or 
 vtotal is clearly invalid, while we have modes with no pixel clock value.
 

Yes, you I are right. But while I'm on it, might as well prevent an error.

Regards,
Steffen
-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv14 7/7] drm_modes: add of_videomode helpers

2012-11-23 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   34 +-
 include/drm/drmP.h  |6 ++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 0073b27..2d6edfa 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,7 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
-#include linux/videomode.h
+#include linux/of_videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -541,6 +541,38 @@ int drm_display_mode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3d0ccaa..84ecabd 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -86,6 +86,7 @@ struct drm_file;
 struct drm_device;
 
 struct videomode;
+struct device_node;
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1459,6 +1460,11 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 extern int drm_display_mode_from_videomode(const struct videomode *vm,
   struct drm_display_mode *dmode);
 #endif
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  unsigned int index);
+#endif
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv14 5/7] fbmon: add of_videomode helpers

2012-11-23 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   42 +-
 include/linux/fb.h|6 ++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index bcbfe8f..287e66b 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,7 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
-#include linux/videomode.h
+#include linux/of_videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1421,6 +1421,46 @@ int fb_videomode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(const struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+   unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
 
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 4404ec2..7e1c8cf 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -20,6 +20,7 @@ struct fb_info;
 struct device;
 struct file;
 struct videomode;
+struct device_node;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -715,6 +716,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_fb_videomode(struct device_node *np,
+  struct fb_videomode *fb,
+  unsigned int index);
+#endif
 #if IS_ENABLED(CONFIG_VIDEOMODE)
 extern int fb_videomode_from_videomode(const struct videomode *vm,
   struct fb_videomode *fbmode);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv14 2/7] video: add display_timing and videomode

2012-11-23 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Also, add helper functions to convert from display timings to a generic 
videomode
structure.

The struct display_timing specifies all needed parameters to describe the signal
properties of a display in one mode. This includes
- ranges for signals that may have min-, max- and typical values
- single integers for signals that can be on, off or are ignored
- booleans for signals that are either on or off

As a display may support multiple modes like this, a struct display_timings is
added, that holds all given struct display_timing pointers and declares the
native mode of the display.

Although a display may state that a signal can be in a range, it is driven with
fixed values that indicate a videomode. Therefore graphic drivers don't need all
the information of struct display_timing, but would generate a videomode from
the given set of supported signal timings and work with that.

The video subsystems all define their own structs that describe a mode and work
with that (e.g. fb_videomode or drm_display_mode). To slowly replace all those
various structures and allow code reuse across those subsystems, add struct
videomode as a generic description.

This patch only includes the most basic fields in struct videomode. All missing
fields that are needed to have a really generic video mode description can be
added at a later stage.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/Kconfig  |6 +++
 drivers/video/Makefile |2 +
 drivers/video/display_timing.c |   24 ++
 drivers/video/videomode.c  |   45 +
 include/linux/display_timing.h |  104 
 include/linux/videomode.h  |   52 
 6 files changed, 233 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..ac9bbbc
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/display_timing.h
+#include linux/export.h
+#include linux/slab.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..86a8558
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,45 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/errno.h
+#include linux/display_timing.h
+#include linux/kernel.h
+#include linux/videomode.h
+
+int videomode_from_timing(const struct display_timings *disp,
+ struct videomode *vm, unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, TE_TYP);
+   vm-hactive = display_timing_get_value(dt

[PATCHv14 1/7] viafb: rename display_timing to via_display_timing

2012-11-23 Thread Steffen Trumtrar
The struct display_timing is specific to the via subsystem. The naming leads to
collisions with the new struct display_timing, that is supposed to be a shared
struct between different subsystems.
To clean this up, prepend the existing struct with the subsystem it is specific
to.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/via/hw.c  |6 +++---
 drivers/video/via/hw.h  |2 +-
 drivers/video/via/lcd.c |2 +-
 drivers/video/via/share.h   |2 +-
 drivers/video/via/via_modesetting.c |8 
 drivers/video/via/via_modesetting.h |6 +++---
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 898590d..5563c67 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,10 +1467,10 @@ void viafb_set_vclock(u32 clk, int set_iga)
via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres)
 {
-   struct display_timing timing;
+   struct via_display_timing timing;
u16 dx = (var-xres - cxres) / 2, dy = (var-yres - cyres) / 2;
 
timing.hor_addr = cxres;
@@ -1491,7 +1491,7 @@ struct display_timing var_to_timing(const struct 
fb_var_screeninfo *var,
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga)
 {
-   struct display_timing crt_reg = var_to_timing(var,
+   struct via_display_timing crt_reg = var_to_timing(var,
cxres ? cxres : var-xres, cyres ? cyres : var-yres);
 
if (iga == IGA1)
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 6be243c..c3f2572 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,7 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres);
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga);
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 1650379..022b0df 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -549,7 +549,7 @@ void viafb_lcd_set_mode(const struct fb_var_screeninfo 
*var, u16 cxres,
int panel_hres = plvds_setting_info-lcd_panel_hres;
int panel_vres = plvds_setting_info-lcd_panel_vres;
u32 clock;
-   struct display_timing timing;
+   struct via_display_timing timing;
struct fb_var_screeninfo panel_var;
const struct fb_videomode *mode_crt_table, *panel_crt_table;
 
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 3158dfc..65c65c6 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -319,7 +319,7 @@ struct crt_mode_table {
int refresh_rate;
int h_sync_polarity;
int v_sync_polarity;
-   struct display_timing crtc;
+   struct via_display_timing crtc;
 };
 
 struct io_reg {
diff --git a/drivers/video/via/via_modesetting.c 
b/drivers/video/via/via_modesetting.c
index 0e431ae..0b414b0 100644
--- a/drivers/video/via/via_modesetting.c
+++ b/drivers/video/via/via_modesetting.c
@@ -30,9 +30,9 @@
 #include debug.h
 
 
-void via_set_primary_timing(const struct display_timing *timing)
+void via_set_primary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total / 8 - 5;
raw.hor_addr = timing-hor_addr / 8 - 1;
@@ -88,9 +88,9 @@ void via_set_primary_timing(const struct display_timing 
*timing)
via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
 }
 
-void via_set_secondary_timing(const struct display_timing *timing)
+void via_set_secondary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total - 1;
raw.hor_addr = timing-hor_addr - 1;
diff --git a/drivers/video/via/via_modesetting.h 
b/drivers/video/via/via_modesetting.h
index 06e09fe..f6a6503 100644
--- a/drivers/video/via/via_modesetting.h
+++ b/drivers/video/via/via_modesetting.h
@@ -33,7 +33,7 @@
 #define VIA_PITCH_MAX  0x3FF8
 
 
-struct display_timing {
+struct via_display_timing {
u16 hor_total;
u16 hor_addr;
u16 hor_blank_start;
@@ -49,8 +49,8 @@ struct display_timing {
 };
 
 
-void via_set_primary_timing(const struct display_timing *timing);
-void via_set_secondary_timing(const struct display_timing *timing);
+void via_set_primary_timing(const struct via_display_timing *timing);
+void via_set_secondary_timing(const struct via_display_timing

[PATCHv14 4/7] fbmon: add videomode helpers

2012-11-23 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   49 +
 include/linux/fb.h|6 ++
 2 files changed, 55 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..bcbfe8f 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include linux/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,54 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   /* prevent division by zero in KHZ2PICOS macro */
+   fbmode-pixclock = vm-pixelclock ? KHZ2PICOS(vm-pixelclock / 1000) : 
0;
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-hah)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-vah)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-interlaced)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-doublescan)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   /* prevent division by zero */
+   if (htotal  vtotal)
+   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
+   else
+   fbmode-refresh = vm-pixelclock;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..4404ec2 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -19,6 +19,7 @@ struct vm_area_struct;
 struct fb_info;
 struct device;
 struct file;
+struct videomode;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -714,6 +715,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int fb_videomode_from_videomode(const struct videomode *vm,
+  struct fb_videomode *fbmode);
+#endif
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv14 0/7] of: add display helper

2012-11-23 Thread Steffen Trumtrar
Hi!

Changes since v13:
- fix const struct * warning
(reported by: Laurent Pinchart 
laurent.pinch...@ideasonboard.com)
- prevent division by zero in fb_videomode_from_videomode

Changes since v12:
- rename struct display_timing to via_display_timing in via subsystem
- fix refreshrate calculation
- fix const struct * warnings
(reported by: Manjunathappa, Prakash prakash...@ti.com)
- some CodingStyle fixes
- rewrite parts of commit messages and display-timings.txt
- let display_timing_get_value get all values instead of just typical

Changes since v11:
- make pointers const where applicable
- add reviewed-by Laurent Pinchart

Changes since v10:
- fix function name (drm_)display_mode_from_videomode
- add acked-by, reviewed-by, tested-by

Changes since v9:
- don't leak memory when previous timings were correct
- CodingStyle fixes
- move blank lines around

Changes since v8:
- fix memory leaks
- change API to be more consistent (foo_from_bar(struct bar, struct 
foo))
- include headers were necessary
- misc minor bufixe

Changes since v7:
- move of_xxx to drivers/video
- remove non-binding documentation from display-timings.txt
- squash display_timings and videomode in one patch
- misc minor fixes

Changes since v6:
- get rid of some empty lines etc.
- move functions to their subsystems
- split of_ from non-of_ functions
- add at least some kerneldoc to some functions

Changes since v5:
- removed all display stuff and just describe timings

Changes since v4:
- refactored functions

Changes since v3:
- print error messages
- free alloced memory
- general cleanup

Changes since v2:
- use hardware-near property-names
- provide a videomode structure
- allow ranges for all properties (min,typ,max)
- functions to get display_mode or fb_videomode


Steffen Trumtrar (7):
  viafb: rename display_timing to via_display_timing
  video: add display_timing and videomode
  video: add of helper for display timings/videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/gpu/drm/drm_modes.c|   69 ++
 drivers/video/Kconfig  |   21 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 +++
 drivers/video/fbmon.c  |   89 
 drivers/video/of_display_timing.c  |  223 
 drivers/video/of_videomode.c   |   48 +
 drivers/video/via/hw.c |6 +-
 drivers/video/via/hw.h |2 +-
 drivers/video/via/lcd.c|2 +-
 drivers/video/via/share.h  |2 +-
 drivers/video/via/via_modesetting.c|8 +-
 drivers/video/via/via_modesetting.h|6 +-
 drivers/video/videomode.c  |   45 
 include/drm/drmP.h |   12 ++
 include/linux/display_timing.h |  104 +
 include/linux/fb.h |   12 ++
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   18 ++
 include/linux/videomode.h  |   52 +
 21 files changed, 861 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h
 create mode 100644 include/linux/videomode.h

-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv14 6/7] drm_modes: add videomode helpers

2012-11-23 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |6 ++
 2 files changed, 43 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..0073b27 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include linux/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(const struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-hah)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-vah)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-interlaced)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-doublescan)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..3d0ccaa 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,7 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct videomode;
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1454,6 +1455,11 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int drm_display_mode_from_videomode(const struct videomode *vm,
+  struct drm_display_mode *dmode);
+#endif
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv14 3/7] video: add of helper for display timings/videomode

2012-11-23 Thread Steffen Trumtrar
This adds support for reading display timings from DT into a struct
display_timings. The of_display_timing implementation supports multiple
subnodes. All children are read into an array, that can be queried.

If no native mode is specified, the first subnode will be used.

For cases, where the graphics drivers knows, there can be only one
mode description or where the driver only supports one mode, a helper
function of_get_videomode is added, that gets a struct videomode from DT.
(As this function is implemented in an expensive fashion, it should only
be used in the aforementioned case).

This also demonstrates how of_display_timings may be utilized.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/video/Kconfig  |   15 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  223 
 drivers/video/of_videomode.c   |   48 +
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   18 ++
 7 files changed, 433 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timings.txt 
b/Documentation/devicetree/bindings/video/display-timings.txt
new file mode 100644
index 000..2b25d58
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timings.txt
@@ -0,0 +1,107 @@
+display-timings bindings
+
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timings subnode
+---
+
+required properties:
+ - hactive, vactive: Display resolution
+ - hfront-porch, hback-porch, hsync-len: Horizontal Display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: Vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: Hsync pulse is active low/high/ignored
+ - vsync-active: Vsync pulse is active low/high/ignored
+ - de-active: Data-Enable pulse is active low/high/ignored
+ - pixelclk-inverted: pixelclock is inverted (active on falling edge)/
+   non-inverted (active on rising edge)/
+ignored (ignore property)
+ - interlaced (bool): boolean to enable interlaced mode
+ - doublescan (bool): boolean to enable doublescan mode
+ - doubleclk (bool)
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The 
devicetree
+representation corresponds to the one commonly found in datasheets for 
displays.
+If a display supports multiple signal timings, the native-mode can be 
specified.
+
+The parameters are defined as
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive

Re: [PATCHv14 3/7] video: add of helper for display timings/videomode

2012-11-23 Thread Steffen Trumtrar
On Fri, Nov 23, 2012 at 03:49:37PM +0530, Leela Krishna Amudala wrote:
 Hello Steffen,
 
 On Fri, Nov 23, 2012 at 2:34 PM, Steffen Trumtrar
 s.trumt...@pengutronix.de wrote:
  This adds support for reading display timings from DT into a struct
  display_timings. The of_display_timing implementation supports multiple
  subnodes. All children are read into an array, that can be queried.
 
  If no native mode is specified, the first subnode will be used.
 
  For cases, where the graphics drivers knows, there can be only one
  mode description or where the driver only supports one mode, a helper
  function of_get_videomode is added, that gets a struct videomode from DT.
  (As this function is implemented in an expensive fashion, it should only
  be used in the aforementioned case).
 
  This also demonstrates how of_display_timings may be utilized.
 
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  Signed-off-by: Philipp Zabel p.za...@pengutronix.de
  Acked-by: Stephen Warren swar...@nvidia.com
  Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
  Acked-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Philipp Zabel p.za...@pengutronix.de
  Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  ---
   .../devicetree/bindings/video/display-timings.txt  |  107 ++
   drivers/video/Kconfig  |   15 ++
   drivers/video/Makefile |2 +
   drivers/video/of_display_timing.c  |  223 
  
   drivers/video/of_videomode.c   |   48 +
   include/linux/of_display_timings.h |   20 ++
   include/linux/of_videomode.h   |   18 ++
   7 files changed, 433 insertions(+)
   create mode 100644 
  Documentation/devicetree/bindings/video/display-timings.txt
   create mode 100644 drivers/video/of_display_timing.c
   create mode 100644 drivers/video/of_videomode.c
   create mode 100644 include/linux/of_display_timings.h
   create mode 100644 include/linux/of_videomode.h
 
 
 snip
 
  diff --git a/drivers/video/of_display_timing.c 
  b/drivers/video/of_display_timing.c
  new file mode 100644
  index 000..645f43d
  --- /dev/null
  +++ b/drivers/video/of_display_timing.c
  @@ -0,0 +1,223 @@
  +/*
  + * OF helpers for parsing display timings
  + *
  + * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, 
  Pengutronix
  + *
  + * based on of_videomode.c by Sascha Hauer s.ha...@pengutronix.de
  + *
  + * This file is released under the GPLv2
  + */
  +#include linux/of.h
  +#include linux/slab.h
  +#include linux/export.h
  +#include linux/of_display_timings.h
  +
  +/**
  + * parse_property - parse timing_entry from device_node
  + * @np: device_node with the property
  + * @name: name of the property
  + * @result: will be set to the return value
  + *
  + * DESCRIPTION:
  + * Every display_timing can be specified with either just the typical 
  value or
  + * a range consisting of min/typ/max. This function helps handling this
  + **/
  +static int parse_property(const struct device_node *np, const char *name,
  + struct timing_entry *result)
  +{
  +   struct property *prop;
  +   int length, cells, ret;
  +
  +   prop = of_find_property(np, name, length);
  +   if (!prop) {
  +   pr_err(%s: could not find property %s\n, __func__, name);
  +   return -EINVAL;
  +   }
  +
  +   cells = length / sizeof(u32);
  +   if (cells == 1) {
  +   ret = of_property_read_u32(np, name, result-typ);
  +   result-min = result-typ;
  +   result-max = result-typ;
  +   } else if (cells == 3) {
  +   ret = of_property_read_u32_array(np, name, result-min, 
  cells);
  +   } else {
  +   pr_err(%s: illegal timing specification in %s\n, __func__,
  +   name);
  +   return -EINVAL;
  +   }
  +
  +   return ret;
  +}
  +
  +/**
  + * of_get_display_timing - parse display_timing entry from device_node
  + * @np: device_node with the properties
  + **/
  +static struct display_timing *of_get_display_timing(const struct 
  device_node
  +   *np)
  +{
  +   struct display_timing *dt;
  +   int ret = 0;
  +
  +   dt = kzalloc(sizeof(*dt), GFP_KERNEL);
  +   if (!dt) {
  +   pr_err(%s: could not allocate display_timing struct\n,
  +   __func__);
  +   return NULL;
  +   }
  +
  +   ret |= parse_property(np, hback-porch, dt-hback_porch);
  +   ret |= parse_property(np, hfront-porch, dt-hfront_porch);
  +   ret |= parse_property(np, hactive, dt-hactive);
  +   ret |= parse_property(np, hsync-len, dt-hsync_len

Re: [PATCHv14 4/7] fbmon: add videomode helpers

2012-11-23 Thread Steffen Trumtrar
Hi Laurent,

On Fri, Nov 23, 2012 at 11:53:10AM +0100, Laurent Pinchart wrote:
 Hi Steffen,
 
 On Friday 23 November 2012 10:04:24 Steffen Trumtrar wrote:
  Add a function to convert from the generic videomode to a fb_videomode.
  
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
  Acked-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Philipp Zabel p.za...@pengutronix.de
  Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  ---
   drivers/video/fbmon.c |   49 ++
   include/linux/fb.h|6 ++
   2 files changed, 55 insertions(+)
  
  diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
  index cef6557..bcbfe8f 100644
  --- a/drivers/video/fbmon.c
  +++ b/drivers/video/fbmon.c
  @@ -31,6 +31,7 @@
   #include linux/pci.h
   #include linux/slab.h
   #include video/edid.h
  +#include linux/videomode.h
 
 You could move this one line up to keep headers sorted alphabetically 
 (assuming they are in the first place).
 

Because of the careless mistake below, I will do that.

   #ifdef CONFIG_PPC_OF
   #include asm/prom.h
   #include asm/pci-bridge.h
  @@ -1373,6 +1374,54 @@ int fb_get_mode(int flags, u32 val, struct
  fb_var_screeninfo *var, struct fb_inf kfree(timings);
  return err;
   }
  +
  +#if IS_ENABLED(CONFIG_VIDEOMODE)
  +int fb_videomode_from_videomode(const struct videomode *vm,
  +   struct fb_videomode *fbmode)
 
 This is inside the #if CONFIG_FB_MODE_HELPERS block, is that intentional ?
 

Yes. Intentional. It is a fb_mode helper, that is why ... oh, wait. I should
add a depends on to the Kconfig then.

  +{
  +   unsigned int htotal, vtotal;
  +
  +   fbmode-xres = vm-hactive;
  +   fbmode-left_margin = vm-hback_porch;
  +   fbmode-right_margin = vm-hfront_porch;
  +   fbmode-hsync_len = vm-hsync_len;
  +
  +   fbmode-yres = vm-vactive;
  +   fbmode-upper_margin = vm-vback_porch;
  +   fbmode-lower_margin = vm-vfront_porch;
  +   fbmode-vsync_len = vm-vsync_len;
  +
  +   /* prevent division by zero in KHZ2PICOS macro */
  +   fbmode-pixclock = vm-pixelclock ? KHZ2PICOS(vm-pixelclock / 1000) : 
  0;
  +
  +   fbmode-sync = 0;
  +   fbmode-vmode = 0;
  +   if (vm-hah)
  +   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
  +   if (vm-vah)
  +   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
  +   if (vm-interlaced)
  +   fbmode-vmode |= FB_VMODE_INTERLACED;
  +   if (vm-doublescan)
  +   fbmode-vmode |= FB_VMODE_DOUBLE;
  +   fbmode-flag = 0;
  +
  +   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
  +vm-hsync_len;
  +   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
  +vm-vsync_len;
  +   /* prevent division by zero */
  +   if (htotal  vtotal)
  +   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
  +   else
  +   fbmode-refresh = vm-pixelclock;
 
 What about returning an error if htotal * vtotal == 0 ? The input is clearly 
 invalid in that case. I would then set fbmode-refresh to 0, setting it to vm-
 pixelclock doesn't really make sense.
 

Yes, pixelclock makes no sense. It was supposed to be 0. I was careless here.

  +
  +   return 0;
  +}
  +EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
  +#endif
  +
  +
 
 A single blank line should be enough.
 

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv13 3/7] video: add of helper for display timings/videomode

2012-11-22 Thread Steffen Trumtrar
This adds support for reading display timings from DT into a struct
display_timings. The of_display_timing implementation supports multiple
subnodes. All children are read into an array, that can be queried.

If no native mode is specified, the first subnode will be used.

For cases, where the graphics drivers knows, there can be only one
mode description or where the driver only supports one mode, a helper
function of_get_videomode is added, that gets a struct videomode from DT.
(As this function is implemented in an expensive fashion, it should only
be used in the aforementioned case).

This also demonstrates how of_display_timings may be utilized.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/video/Kconfig  |   15 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  223 
 drivers/video/of_videomode.c   |   48 +
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   18 ++
 7 files changed, 433 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timings.txt 
b/Documentation/devicetree/bindings/video/display-timings.txt
new file mode 100644
index 000..2b25d58
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timings.txt
@@ -0,0 +1,107 @@
+display-timings bindings
+
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timings subnode
+---
+
+required properties:
+ - hactive, vactive: Display resolution
+ - hfront-porch, hback-porch, hsync-len: Horizontal Display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: Vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: Hsync pulse is active low/high/ignored
+ - vsync-active: Vsync pulse is active low/high/ignored
+ - de-active: Data-Enable pulse is active low/high/ignored
+ - pixelclk-inverted: pixelclock is inverted (active on falling edge)/
+   non-inverted (active on rising edge)/
+ignored (ignore property)
+ - interlaced (bool): boolean to enable interlaced mode
+ - doublescan (bool): boolean to enable doublescan mode
+ - doubleclk (bool)
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The 
devicetree
+representation corresponds to the one commonly found in datasheets for 
displays.
+If a display supports multiple signal timings, the native-mode can be 
specified.
+
+The parameters are defined as
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive

[PATCHv13 2/7] video: add display_timing and videomode

2012-11-22 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Also, add helper functions to convert from display timings to a generic 
videomode
structure.

The struct display_timing specifies all needed parameters to describe the signal
properties of a display in one mode. This includes
- ranges for signals that may have min-, max- and typical values
- single integers for signals that can be on, off or are ignored
- booleans for signals that are either on or off

As a display may support multiple modes like this, a struct display_timings is
added, that holds all given struct display_timing pointers and declares the
native mode of the display.

Although a display may state that a signal can be in a range, it is driven with
fixed values that indicate a videomode. Therefore graphic drivers don't need all
the information of struct display_timing, but would generate a videomode from
the given set of supported signal timings and work with that.

The video subsystems all define their own structs that describe a mode and work
with that (e.g. fb_videomode or drm_display_mode). To slowly replace all those
various structures and allow code reuse across those subsystems, add struct
videomode as a generic description.

This patch only includes the most basic fields in struct videomode. All missing
fields that are needed to have a really generic video mode description can be
added at a later stage.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/Kconfig  |6 +++
 drivers/video/Makefile |2 +
 drivers/video/display_timing.c |   24 ++
 drivers/video/videomode.c  |   45 +
 include/linux/display_timing.h |  104 
 include/linux/videomode.h  |   52 
 6 files changed, 233 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..ac9bbbc
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/display_timing.h
+#include linux/export.h
+#include linux/slab.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..86a8558
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,45 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/errno.h
+#include linux/display_timing.h
+#include linux/kernel.h
+#include linux/videomode.h
+
+int videomode_from_timing(const struct display_timings *disp,
+ struct videomode *vm, unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, TE_TYP);
+   vm-hactive = display_timing_get_value(dt

[PATCHv13 5/7] fbmon: add of_videomode helpers

2012-11-22 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   42 +-
 include/linux/fb.h|6 ++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index a6a564d..cd0a035 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,7 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
-#include linux/videomode.h
+#include linux/of_videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1416,6 +1416,46 @@ int fb_videomode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(const struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(const struct device_node *np, struct fb_videomode *fb,
+   unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
 
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 4404ec2..43a2f81 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -20,6 +20,7 @@ struct fb_info;
 struct device;
 struct file;
 struct videomode;
+struct device_node;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -715,6 +716,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_fb_videomode(const struct device_node *np,
+  struct fb_videomode *fb,
+  unsigned int index);
+#endif
 #if IS_ENABLED(CONFIG_VIDEOMODE)
 extern int fb_videomode_from_videomode(const struct videomode *vm,
   struct fb_videomode *fbmode);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv13 6/7] drm_modes: add videomode helpers

2012-11-22 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |6 ++
 2 files changed, 43 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..0073b27 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include linux/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(const struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-hah)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-vah)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-interlaced)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-doublescan)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..3d0ccaa 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -85,6 +85,7 @@ struct module;
 struct drm_file;
 struct drm_device;
 
+struct videomode;
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1454,6 +1455,11 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int drm_display_mode_from_videomode(const struct videomode *vm,
+  struct drm_display_mode *dmode);
+#endif
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v12 2/6] video: add of helper for videomode

2012-11-22 Thread Steffen Trumtrar
Hi!

On Wed, Nov 21, 2012 at 09:03:38AM -0600, Rob Herring wrote:
 On 11/21/2012 05:52 AM, Thierry Reding wrote:
  On Wed, Nov 21, 2012 at 12:48:43PM +0100, Steffen Trumtrar wrote:
  Hi!
 
  On Wed, Nov 21, 2012 at 10:12:43AM +, Manjunathappa, Prakash wrote:
  Hi Steffen,
 
  On Tue, Nov 20, 2012 at 21:24:52, Steffen Trumtrar wrote:
  +/**
  + * of_get_display_timings - parse all display_timing entries from a 
  device_node
  + * @np: device_node with the subnodes
  + **/
  +struct display_timings *of_get_display_timings(const struct device_node 
  *np)
  +{
  +struct device_node *timings_np;
  +struct device_node *entry;
  +struct device_node *native_mode;
  +struct display_timings *disp;
  +
  +if (!np) {
  +pr_err(%s: no devicenode given\n, __func__);
  +return NULL;
  +}
  +
  +timings_np = of_find_node_by_name(np, display-timings);
 
  I get below build warnings on this line
  drivers/video/of_display_timing.c: In function 'of_get_display_timings':
  drivers/video/of_display_timing.c:109:2: warning: passing argument 1 of 
  'of_find_node_by_name' discards qualifiers from pointer target type
  include/linux/of.h:167:28: note: expected 'struct device_node *' but 
  argument is of type 'const struct device_node *'
 
  + * of_display_timings_exists - check if a display-timings node is 
  provided
  + * @np: device_node with the timing
  + **/
  +int of_display_timings_exists(const struct device_node *np)
  +{
  +struct device_node *timings_np;
  +
  +if (!np)
  +return -EINVAL;
  +
  +timings_np = of_parse_phandle(np, display-timings, 0);
 
  Also here:
  drivers/video/of_display_timing.c: In function 
  'of_display_timings_exists':
  drivers/video/of_display_timing.c:209:2: warning: passing argument 1 of 
  'of_parse_phandle' discards qualifiers from pointer target type
  include/linux/of.h:258:28: note: expected 'struct device_node *' but 
  argument is of type 'const struct device_node *'
 
 
  The warnings are because the of-functions do not use const pointers where 
  they
  should. I had two options: don't use const pointers even if they should be 
  and
  have no warnings or use const pointers and have a correct API. (Third 
  option:
  send patches for of-functions). I chose the second option.
  
  Maybe a better approach would be a combination of 1 and 3: don't use
  const pointers for struct device_node for now and bring the issue up
  with the OF maintainers, possibly with patches attached that fix the
  problematic functions.
 
 Why does this need to be const? Since some DT functions increment
 refcount the node, I'm not sure that making struct device_node const in
 general is right thing to do. I do think it should be okay for
 of_parse_phandle.
 

Okay, that seems right. I went a little to far with const'ing.
I will send a patch for of_parse_phandle as this function does
not seem to change the pointer it is given, but returns a new one
on which the refcount gets incremented.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv13 4/7] fbmon: add videomode helpers

2012-11-22 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/fbmon.c |   44 
 include/linux/fb.h|6 ++
 2 files changed, 50 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..a6a564d 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include linux/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,49 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   fbmode-pixclock = KHZ2PICOS(vm-pixelclock / 1000);
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-hah)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-vah)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-interlaced)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-doublescan)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..4404ec2 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -19,6 +19,7 @@ struct vm_area_struct;
 struct fb_info;
 struct device;
 struct file;
+struct videomode;
 
 /* Definitions below are used in the parsed monitor specs */
 #define FB_DPMS_ACTIVE_OFF 1
@@ -714,6 +715,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int fb_videomode_from_videomode(const struct videomode *vm,
+  struct fb_videomode *fbmode);
+#endif
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v12 3/6] fbmon: add videomode helpers

2012-11-22 Thread Steffen Trumtrar
On Thu, Nov 22, 2012 at 10:07:07AM +0100, Laurent Pinchart wrote:
 On Thursday 22 November 2012 09:53:42 Sascha Hauer wrote:
  On Thu, Nov 22, 2012 at 09:50:10AM +0100, Laurent Pinchart wrote:
   On Thursday 22 November 2012 07:20:00 Sascha Hauer wrote:
On Wed, Nov 21, 2012 at 11:02:44PM +0100, Laurent Pinchart wrote:
 Hi Steffen,
 
  +
  +   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
  +vm-hsync_len;
  +   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
  +vm-vsync_len;
  +   fbmode-refresh = (vm-pixelclock * 1000) / (htotal * vtotal);
 
 This will fail if vm-pixelclock = ((1  32) / 1000). The easiest
 solution is probably to use 64-bit computation.

You have displays with a pixelclock  4GHz?
   
   vm-pixelclock is expressed in Hz. vm-pixelclock * 1000 will thus
   overflow if the clock frequency is = ~4.3 MHz. I have displays with a
   clock frequency higher than that :-)
  
  If vm-pixelclock is in Hz, then the * 1000 above is wrong.
 
 My bad, I though refresh was expressed in mHz. So yes, the above computation 
 is wrong.


Okay. I will fix that with the next version...

 BTW it seems that the refreshrate field in struct videomode isn't used. It 
 should then be removed.
 

...and remove this field.

 I've just realized that the struct videomode fields are not documented. 
 kerneldoc in include/linux/videomode.h would be a good addition.
 

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv13 7/7] drm_modes: add of_videomode helpers

2012-11-22 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   34 +-
 include/drm/drmP.h  |6 ++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 0073b27..2d6edfa 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,7 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
-#include linux/videomode.h
+#include linux/of_videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -541,6 +541,38 @@ int drm_display_mode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3d0ccaa..84ecabd 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -86,6 +86,7 @@ struct drm_file;
 struct drm_device;
 
 struct videomode;
+struct device_node;
 #include drm/drm_os_linux.h
 #include drm/drm_hashtab.h
 #include drm/drm_mm.h
@@ -1459,6 +1460,11 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 extern int drm_display_mode_from_videomode(const struct videomode *vm,
   struct drm_display_mode *dmode);
 #endif
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  unsigned int index);
+#endif
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv13 0/7] of: add display helper

2012-11-22 Thread Steffen Trumtrar
Hi!

Changes since v12:
- rename struct display_timing to via_display_timing in via subsystem
- fix refreshrate calculation
- fix const struct * warnings
(reported by: Manjunathappa, Prakash prakash...@ti.com)
- some CodingStyle fixes
- rewrite parts of commit messages and display-timings.txt
- let display_timing_get_value get all values instead of just typical

Regards,
Steffen

Steffen Trumtrar (7):
  viafb: rename display_timing to via_display_timing
  video: add display_timing and videomode
  video: add of helper for display timings/videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/gpu/drm/drm_modes.c|   69 ++
 drivers/video/Kconfig  |   21 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 +++
 drivers/video/fbmon.c  |   84 
 drivers/video/of_display_timing.c  |  223 
 drivers/video/of_videomode.c   |   48 +
 drivers/video/via/hw.c |6 +-
 drivers/video/via/hw.h |2 +-
 drivers/video/via/lcd.c|2 +-
 drivers/video/via/share.h  |2 +-
 drivers/video/via/via_modesetting.c|8 +-
 drivers/video/via/via_modesetting.h|6 +-
 drivers/video/videomode.c  |   45 
 include/drm/drmP.h |   12 ++
 include/linux/display_timing.h |  104 +
 include/linux/fb.h |   12 ++
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   18 ++
 include/linux/videomode.h  |   52 +
 21 files changed, 856 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h
 create mode 100644 include/linux/videomode.h

-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv13 1/7] viafb: rename display_timing to via_display_timing

2012-11-22 Thread Steffen Trumtrar
The struct display_timing is specific to the via subsystem. The naming leads to
collisions with the new struct display_timing, that is supposed to be a shared
struct between different subsystems.
To clean this up, prepend the existing struct with the subsystem it is specific
to.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/via/hw.c  |6 +++---
 drivers/video/via/hw.h  |2 +-
 drivers/video/via/lcd.c |2 +-
 drivers/video/via/share.h   |2 +-
 drivers/video/via/via_modesetting.c |8 
 drivers/video/via/via_modesetting.h |6 +++---
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
index 898590d..5563c67 100644
--- a/drivers/video/via/hw.c
+++ b/drivers/video/via/hw.c
@@ -1467,10 +1467,10 @@ void viafb_set_vclock(u32 clk, int set_iga)
via_write_misc_reg_mask(0x0C, 0x0C); /* select external clock */
 }
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres)
 {
-   struct display_timing timing;
+   struct via_display_timing timing;
u16 dx = (var-xres - cxres) / 2, dy = (var-yres - cyres) / 2;
 
timing.hor_addr = cxres;
@@ -1491,7 +1491,7 @@ struct display_timing var_to_timing(const struct 
fb_var_screeninfo *var,
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga)
 {
-   struct display_timing crt_reg = var_to_timing(var,
+   struct via_display_timing crt_reg = var_to_timing(var,
cxres ? cxres : var-xres, cyres ? cyres : var-yres);
 
if (iga == IGA1)
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
index 6be243c..c3f2572 100644
--- a/drivers/video/via/hw.h
+++ b/drivers/video/via/hw.h
@@ -637,7 +637,7 @@ extern int viafb_LCD_ON;
 extern int viafb_DVI_ON;
 extern int viafb_hotplug;
 
-struct display_timing var_to_timing(const struct fb_var_screeninfo *var,
+struct via_display_timing var_to_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres);
 void viafb_fill_crtc_timing(const struct fb_var_screeninfo *var,
u16 cxres, u16 cyres, int iga);
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
index 1650379..022b0df 100644
--- a/drivers/video/via/lcd.c
+++ b/drivers/video/via/lcd.c
@@ -549,7 +549,7 @@ void viafb_lcd_set_mode(const struct fb_var_screeninfo 
*var, u16 cxres,
int panel_hres = plvds_setting_info-lcd_panel_hres;
int panel_vres = plvds_setting_info-lcd_panel_vres;
u32 clock;
-   struct display_timing timing;
+   struct via_display_timing timing;
struct fb_var_screeninfo panel_var;
const struct fb_videomode *mode_crt_table, *panel_crt_table;
 
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
index 3158dfc..65c65c6 100644
--- a/drivers/video/via/share.h
+++ b/drivers/video/via/share.h
@@ -319,7 +319,7 @@ struct crt_mode_table {
int refresh_rate;
int h_sync_polarity;
int v_sync_polarity;
-   struct display_timing crtc;
+   struct via_display_timing crtc;
 };
 
 struct io_reg {
diff --git a/drivers/video/via/via_modesetting.c 
b/drivers/video/via/via_modesetting.c
index 0e431ae..0b414b0 100644
--- a/drivers/video/via/via_modesetting.c
+++ b/drivers/video/via/via_modesetting.c
@@ -30,9 +30,9 @@
 #include debug.h
 
 
-void via_set_primary_timing(const struct display_timing *timing)
+void via_set_primary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total / 8 - 5;
raw.hor_addr = timing-hor_addr / 8 - 1;
@@ -88,9 +88,9 @@ void via_set_primary_timing(const struct display_timing 
*timing)
via_write_reg_mask(VIACR, 0x17, 0x80, 0x80);
 }
 
-void via_set_secondary_timing(const struct display_timing *timing)
+void via_set_secondary_timing(const struct via_display_timing *timing)
 {
-   struct display_timing raw;
+   struct via_display_timing raw;
 
raw.hor_total = timing-hor_total - 1;
raw.hor_addr = timing-hor_addr - 1;
diff --git a/drivers/video/via/via_modesetting.h 
b/drivers/video/via/via_modesetting.h
index 06e09fe..f6a6503 100644
--- a/drivers/video/via/via_modesetting.h
+++ b/drivers/video/via/via_modesetting.h
@@ -33,7 +33,7 @@
 #define VIA_PITCH_MAX  0x3FF8
 
 
-struct display_timing {
+struct via_display_timing {
u16 hor_total;
u16 hor_addr;
u16 hor_blank_start;
@@ -49,8 +49,8 @@ struct display_timing {
 };
 
 
-void via_set_primary_timing(const struct display_timing *timing);
-void via_set_secondary_timing(const struct display_timing *timing);
+void via_set_primary_timing(const struct via_display_timing *timing);
+void via_set_secondary_timing(const struct via_display_timing

Re: [PATCHv13 4/7] fbmon: add videomode helpers

2012-11-22 Thread Steffen Trumtrar
On Thu, Nov 22, 2012 at 07:31:39PM +0100, Laurent Pinchart wrote:
 Hi Steffen,
 
 On Thursday 22 November 2012 17:00:12 Steffen Trumtrar wrote:
  Add a function to convert from the generic videomode to a fb_videomode.
  
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
  Acked-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Philipp Zabel p.za...@pengutronix.de
  Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  ---
   drivers/video/fbmon.c |   44 
   include/linux/fb.h|6 ++
   2 files changed, 50 insertions(+)
  
  diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
  index cef6557..a6a564d 100644
  --- a/drivers/video/fbmon.c
  +++ b/drivers/video/fbmon.c
  @@ -31,6 +31,7 @@
   #include linux/pci.h
   #include linux/slab.h
   #include video/edid.h
  +#include linux/videomode.h
   #ifdef CONFIG_PPC_OF
   #include asm/prom.h
   #include asm/pci-bridge.h
  @@ -1373,6 +1374,49 @@ int fb_get_mode(int flags, u32 val, struct
  fb_var_screeninfo *var, struct fb_inf kfree(timings);
  return err;
   }
  +
  +#if IS_ENABLED(CONFIG_VIDEOMODE)
  +int fb_videomode_from_videomode(const struct videomode *vm,
  +   struct fb_videomode *fbmode)
  +{
  +   unsigned int htotal, vtotal;
  +
  +   fbmode-xres = vm-hactive;
  +   fbmode-left_margin = vm-hback_porch;
  +   fbmode-right_margin = vm-hfront_porch;
  +   fbmode-hsync_len = vm-hsync_len;
  +
  +   fbmode-yres = vm-vactive;
  +   fbmode-upper_margin = vm-vback_porch;
  +   fbmode-lower_margin = vm-vfront_porch;
  +   fbmode-vsync_len = vm-vsync_len;
  +
  +   fbmode-pixclock = KHZ2PICOS(vm-pixelclock / 1000);
 
 This results in a division by 0 if vm-pixelclock is equal to zero. As the 
 information is missing from many board files, what would you think about the 
 following ?
 
   fbmode-pixclock = vm-pixelclock ? KHZ2PICOS(vm-pixelclock / 1000) : 
 0;
 

Grrr...you are right. I will fix that...

  +   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
  +vm-hsync_len;
  +   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
  +vm-vsync_len;
  +   fbmode-refresh = vm-pixelclock / (htotal * vtotal);
  +

...and obviously this, too.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv13 5/7] fbmon: add of_videomode helpers

2012-11-22 Thread Steffen Trumtrar
Hi Laurent,

On Thu, Nov 22, 2012 at 06:58:09PM +0100, Laurent Pinchart wrote:
 Hi Steffen,
 
 On Thursday 22 November 2012 17:00:13 Steffen Trumtrar wrote:
  Add helper to get fb_videomode from devicetree.
  
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
  Acked-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Philipp Zabel p.za...@pengutronix.de
  Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
 
 This patch results in the following build warning:
 
 drivers/video/fbmon.c: In function 'of_get_fb_videomode':
 drivers/video/fbmon.c:1445: warning: passing argument 1 of 'of_get_videomode' 
 discards qualifiers from pointer target type
 include/linux/of_videomode.h:15: note: expected 'struct device_node *' but 
 argument is of type 'const struct device_node *'
 

This I don't get. Well, looking at the code, the warning is correct. I fixed
that now. But, I do not get the warning. Just tried it again before fixing:
cleaned, cleaned and touching file, just make drivers/video/fbmon.o. Nothing.
Weird.

So, thanks for reporting it.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v12 0/6] of: add display helper

2012-11-21 Thread Steffen Trumtrar
On Tue, Nov 20, 2012 at 08:35:31PM +0100, Thierry Reding wrote:
 On Tue, Nov 20, 2012 at 07:11:29PM +0100, Robert Schwebel wrote:
  On Tue, Nov 20, 2012 at 05:13:19PM +0100, Laurent Pinchart wrote:
   On Tuesday 20 November 2012 16:54:50 Steffen Trumtrar wrote:
Hi!

Changes since v11:
- make pointers const where applicable
- add reviewed-by Laurent Pinchart
   
   Looks good to me.
   
   Acked-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
   
   Through which tree do you plan to push this ?
  
  We have no idea yet, and none of the people on Cc: have volunteered
  so far... what do you think?
 
 The customary approach would be to take the patches through separate
 trees, but I think this particular series is sufficiently interwoven to
 warrant taking them all through one tree. However the least that we
 should do is collect Acked-by's from the other tree maintainers.
 
 Given that most of the patches modify files in drivers/video, Florian's
 fbdev tree would be the most obvious candidate, right? If Florian agrees
 to take the patches, all we would need is David's Acked-by.
 
 How does that sound?
 
 Thierry

Hi!

That is exactly the way I thought this could happen.

Regards
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v12 2/6] video: add of helper for videomode

2012-11-21 Thread Steffen Trumtrar
Hi!

On Wed, Nov 21, 2012 at 10:12:43AM +, Manjunathappa, Prakash wrote:
 Hi Steffen,
 
 On Tue, Nov 20, 2012 at 21:24:52, Steffen Trumtrar wrote:
  +/**
  + * of_get_display_timings - parse all display_timing entries from a 
  device_node
  + * @np: device_node with the subnodes
  + **/
  +struct display_timings *of_get_display_timings(const struct device_node 
  *np)
  +{
  +   struct device_node *timings_np;
  +   struct device_node *entry;
  +   struct device_node *native_mode;
  +   struct display_timings *disp;
  +
  +   if (!np) {
  +   pr_err(%s: no devicenode given\n, __func__);
  +   return NULL;
  +   }
  +
  +   timings_np = of_find_node_by_name(np, display-timings);
 
 I get below build warnings on this line
 drivers/video/of_display_timing.c: In function 'of_get_display_timings':
 drivers/video/of_display_timing.c:109:2: warning: passing argument 1 of 
 'of_find_node_by_name' discards qualifiers from pointer target type
 include/linux/of.h:167:28: note: expected 'struct device_node *' but argument 
 is of type 'const struct device_node *'
 
  + * of_display_timings_exists - check if a display-timings node is provided
  + * @np: device_node with the timing
  + **/
  +int of_display_timings_exists(const struct device_node *np)
  +{
  +   struct device_node *timings_np;
  +
  +   if (!np)
  +   return -EINVAL;
  +
  +   timings_np = of_parse_phandle(np, display-timings, 0);
 
 Also here:
 drivers/video/of_display_timing.c: In function 'of_display_timings_exists':
 drivers/video/of_display_timing.c:209:2: warning: passing argument 1 of 
 'of_parse_phandle' discards qualifiers from pointer target type
 include/linux/of.h:258:28: note: expected 'struct device_node *' but argument 
 is of type 'const struct device_node *'
 

The warnings are because the of-functions do not use const pointers where they
should. I had two options: don't use const pointers even if they should be and
have no warnings or use const pointers and have a correct API. (Third option:
send patches for of-functions). I chose the second option.

Regards,
Steffen


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v12 3/6] fbmon: add videomode helpers

2012-11-21 Thread Steffen Trumtrar
Hi!

On Wed, Nov 21, 2012 at 04:39:01PM +0530, Leela Krishna Amudala wrote:
 Yes,
 Even I got the same build error.
 later I fixed it by including #include linux/mxsfb.h
 
 Best Wishes,
 Leela Krishna.
 
 On Wed, Nov 21, 2012 at 3:39 PM, Manjunathappa, Prakash
 prakash...@ti.com wrote:
  Hi Steffen,
 
  I am trying to add DT support for da8xx-fb driver on top of your patches.
  Encountered below build error. Sorry for reporting it late.
 
  On Tue, Nov 20, 2012 at 21:24:53, Steffen Trumtrar wrote:
  Add a function to convert from the generic videomode to a fb_videomode.
 
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
  Acked-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Philipp Zabel p.za...@pengutronix.de
  Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  ---
   drivers/video/fbmon.c |   46 
  ++
   include/linux/fb.h|6 ++
   2 files changed, 52 insertions(+)
 
  diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
  index cef6557..c1939a6 100644
  --- a/drivers/video/fbmon.c
  +++ b/drivers/video/fbmon.c
  @@ -31,6 +31,7 @@
   #include linux/pci.h
   #include linux/slab.h
   #include video/edid.h
  +#include linux/videomode.h
   #ifdef CONFIG_PPC_OF
   #include asm/prom.h
   #include asm/pci-bridge.h
  @@ -1373,6 +1374,51 @@ int fb_get_mode(int flags, u32 val, struct 
  fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
   }
  +
  +#if IS_ENABLED(CONFIG_VIDEOMODE)
  +int fb_videomode_from_videomode(const struct videomode *vm,
  + struct fb_videomode *fbmode)
  +{
  + unsigned int htotal, vtotal;
  +
  + fbmode-xres = vm-hactive;
  + fbmode-left_margin = vm-hback_porch;
  + fbmode-right_margin = vm-hfront_porch;
  + fbmode-hsync_len = vm-hsync_len;
  +
  + fbmode-yres = vm-vactive;
  + fbmode-upper_margin = vm-vback_porch;
  + fbmode-lower_margin = vm-vfront_porch;
  + fbmode-vsync_len = vm-vsync_len;
  +
  + fbmode-pixclock = KHZ2PICOS(vm-pixelclock / 1000);
  +
  + fbmode-sync = 0;
  + fbmode-vmode = 0;
  + if (vm-hah)
  + fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
  + if (vm-vah)
  + fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
  + if (vm-interlaced)
  + fbmode-vmode |= FB_VMODE_INTERLACED;
  + if (vm-doublescan)
  + fbmode-vmode |= FB_VMODE_DOUBLE;
  + if (vm-de)
  + fbmode-sync |= FB_SYNC_DATA_ENABLE_HIGH_ACT;
 
  FB_SYNC_DATA_ENABLE_HIGH_ACT seems to be mxsfb specific flag, I am getting
  build error on this. Please let me know if I am missing something.
 
  Thanks,
  Prakash
 

I compile-tested the series and didn't have that error. But obviously I should
have. As this is a mxsfs flag, I will throw it out.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v12 1/6] video: add display_timing and videomode

2012-11-21 Thread Steffen Trumtrar
Hi,

On Wed, Nov 21, 2012 at 01:37:08PM +0200, Tomi Valkeinen wrote:
 Hi,
 
 On 2012-11-20 17:54, Steffen Trumtrar wrote:
  Add display_timing structure and the according helper functions. This allows
  the description of a display via its supported timing parameters.
  
  Every timing parameter can be specified as a single value or a range
  min typ max.
  
  Also, add helper functions to convert from display timings to a generic 
  videomode
  structure. This videomode can then be converted to the corresponding 
  subsystem
  mode representation (e.g. fb_videomode).
 
 Sorry for reviewing this so late.
 
 One thing I'd like to see is some explanation of the structs involved.
 For example, in this patch you present structs videomode, display_timing
 and display_timings without giving any hint what they represent.
 
 I'm not asking for you to write a long documentation, but perhaps the
 header files could include a few lines of comments above the structs,
 explaining the idea.
 

Okay. Will do.

  +void display_timings_release(struct display_timings *disp)
  +{
  +   if (disp-timings) {
  +   unsigned int i;
  +
  +   for (i = 0; i  disp-num_timings; i++)
  +   kfree(disp-timings[i]);
  +   kfree(disp-timings);
  +   }
  +   kfree(disp);
  +}
  +EXPORT_SYMBOL_GPL(display_timings_release);
 
 Perhaps this will become clearer after reading the following patches,
 but it feels a bit odd to add a release function, without anything in
 this patch that would actually allocate the timings.
 

2/6 uses this function. And as this does not belong to the DT part, it
is added in this patch.

  diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
  new file mode 100644
  index 000..e24f879
  --- /dev/null
  +++ b/drivers/video/videomode.c
  @@ -0,0 +1,46 @@
  +/*
  + * generic display timing functions
  + *
  + * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, 
  Pengutronix
  + *
  + * This file is released under the GPLv2
  + */
  +
  +#include linux/export.h
  +#include linux/errno.h
  +#include linux/display_timing.h
  +#include linux/kernel.h
  +#include linux/videomode.h
  +
  +int videomode_from_timing(const struct display_timings *disp,
  + struct videomode *vm, unsigned int index)
  +{
  +   struct display_timing *dt;
  +
  +   dt = display_timings_get(disp, index);
  +   if (!dt)
  +   return -EINVAL;
  +
  +   vm-pixelclock = display_timing_get_value(dt-pixelclock, 0);
  +   vm-hactive = display_timing_get_value(dt-hactive, 0);
  +   vm-hfront_porch = display_timing_get_value(dt-hfront_porch, 0);
  +   vm-hback_porch = display_timing_get_value(dt-hback_porch, 0);
  +   vm-hsync_len = display_timing_get_value(dt-hsync_len, 0);
  +
  +   vm-vactive = display_timing_get_value(dt-vactive, 0);
  +   vm-vfront_porch = display_timing_get_value(dt-vfront_porch, 0);
  +   vm-vback_porch = display_timing_get_value(dt-vback_porch, 0);
  +   vm-vsync_len = display_timing_get_value(dt-vsync_len, 0);
 
 Shouldn't all these calls get the typical value, with index 1?
 

Yes. I omitted the indexing until now. So it didn't matter what value was used.
But I will integrate it in the next version.

  +
  +   vm-vah = dt-vsync_pol_active;
  +   vm-hah = dt-hsync_pol_active;
  +   vm-de = dt-de_pol_active;
  +   vm-pixelclk_pol = dt-pixelclk_pol;
  +
  +   vm-interlaced = dt-interlaced;
  +   vm-doublescan = dt-doublescan;
  +
  +   return 0;
  +}
  +
  +EXPORT_SYMBOL_GPL(videomode_from_timing);
  diff --git a/include/linux/display_timing.h b/include/linux/display_timing.h
  new file mode 100644
  index 000..d5bf03f
  --- /dev/null
  +++ b/include/linux/display_timing.h
  @@ -0,0 +1,70 @@
  +/*
  + * Copyright 2012 Steffen Trumtrar s.trumt...@pengutronix.de
  + *
  + * description of display timings
  + *
  + * This file is released under the GPLv2
  + */
  +
  +#ifndef __LINUX_DISPLAY_TIMINGS_H
  +#define __LINUX_DISPLAY_TIMINGS_H
  +
  +#include linux/types.h
 
 What is this needed for? u32? I don't see it defined in types.h
 

Yes, u32. What would be the right header for that if not types.h?

  +
  +struct timing_entry {
  +   u32 min;
  +   u32 typ;
  +   u32 max;
  +};
  +
  +struct display_timing {
  +   struct timing_entry pixelclock;
  +
  +   struct timing_entry hactive;
  +   struct timing_entry hfront_porch;
  +   struct timing_entry hback_porch;
  +   struct timing_entry hsync_len;
  +
  +   struct timing_entry vactive;
  +   struct timing_entry vfront_porch;
  +   struct timing_entry vback_porch;
  +   struct timing_entry vsync_len;
  +
  +   unsigned int vsync_pol_active;
  +   unsigned int hsync_pol_active;
  +   unsigned int de_pol_active;
  +   unsigned int pixelclk_pol;
  +   bool interlaced;
  +   bool doublescan;
  +};
  +
  +struct display_timings {
  +   unsigned int num_timings;
  +   unsigned int native_mode;
  +
  +   struct display_timing **timings;
  +};
  +
  +/*
  + * placeholder function until

Re: [PATCH v12 4/6] fbmon: add of_videomode helpers

2012-11-21 Thread Steffen Trumtrar
On Wed, Nov 21, 2012 at 02:49:30PM +0200, Tomi Valkeinen wrote:
 On 2012-11-20 17:54, Steffen Trumtrar wrote:
  Add helper to get fb_videomode from devicetree.
  
  Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
  Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
  Acked-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Thierry Reding thierry.red...@avionic-design.de
  Tested-by: Philipp Zabel p.za...@pengutronix.de
  Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
  ---
   drivers/video/fbmon.c |   42 +-
   include/linux/fb.h|7 +++
   2 files changed, 48 insertions(+), 1 deletion(-)
 
 
  diff --git a/include/linux/fb.h b/include/linux/fb.h
  index 920cbe3..41b5e49 100644
  --- a/include/linux/fb.h
  +++ b/include/linux/fb.h
  @@ -15,6 +15,8 @@
   #include linux/slab.h
   #include asm/io.h
   #include linux/videomode.h
  +#include linux/of.h
  +#include linux/of_videomode.h
 
 Guess what? =)
 
 To be honest, I don't know what the general opinion is about including
 header files from header files. But I always leave them out if they are
 not strictly needed.
 

Okay. Seems to fit with the rest of the file;

   struct vm_area_struct;
   struct fb_info;
  @@ -715,6 +717,11 @@ extern void fb_destroy_modedb(struct fb_videomode 
  *modedb);
   extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int 
  rb);
   extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
   
  +#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
  +extern int of_get_fb_videomode(const struct device_node *np,
  +  struct fb_videomode *fb,
  +  unsigned int index);
  +#endif
   #if IS_ENABLED(CONFIG_VIDEOMODE)
   extern int fb_videomode_from_videomode(const struct videomode *vm,
 struct fb_videomode *fbmode);
 
 Do you really need these #ifs in the header files? They do make it look
 a bit messy. If somebody uses the functions and CONFIG_VIDEOMODE is not
 enabled, he'll get a linker error anyway.
 

Well, I don't remember at the moment who requested this, but it was not my
idea to put them there. So, this is a matter of style I guess.
But maybe I understood that wrong.


Regards,
Steffen



-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v11 0/6] of: add display helper

2012-11-20 Thread Steffen Trumtrar
On Tue, Nov 20, 2012 at 11:52:06AM +0100, Laurent Pinchart wrote:
 Hi Steffen,
 
 On Tuesday 20 November 2012 11:39:18 Steffen Trumtrar wrote:
  On Thu, Nov 15, 2012 at 02:15:06PM +0100, Steffen Trumtrar wrote:
   Hi!
   
   Changes since v10:
 - fix function name (drm_)display_mode_from_videomode
 - add acked-by, reviewed-by, tested-by
   
   Regards,
   Steffen
   
   Steffen Trumtrar (6):
 video: add display_timing and videomode
 video: add of helper for videomode
 fbmon: add videomode helpers
 fbmon: add of_videomode helpers
 drm_modes: add videomode helpers
 drm_modes: add of_videomode helpers

.../devicetree/bindings/video/display-timings.txt  |  107 ++
drivers/gpu/drm/drm_modes.c|   70 +++
drivers/video/Kconfig  |   19 ++
drivers/video/Makefile |4 +
drivers/video/display_timing.c |   24 +++
drivers/video/fbmon.c  |   86 
drivers/video/of_display_timing.c  |  212 +++
drivers/video/of_videomode.c   |   47 +
drivers/video/videomode.c  |   45 +
include/drm/drmP.h |   12 ++
include/linux/display_timing.h |   69 +++
include/linux/fb.h |   12 ++
include/linux/of_display_timings.h |   20 ++
include/linux/of_videomode.h   |   17 ++
include/linux/videomode.h  |   40 
15 files changed, 784 insertions(+)
create mode 100644
Documentation/devicetree/bindings/video/display-timings.txt create mode
100644 drivers/video/display_timing.c
create mode 100644 drivers/video/of_display_timing.c
create mode 100644 drivers/video/of_videomode.c
create mode 100644 drivers/video/videomode.c
create mode 100644 include/linux/display_timing.h
create mode 100644 include/linux/of_display_timings.h
create mode 100644 include/linux/of_videomode.h
create mode 100644 include/linux/videomode.h
  
  Ping!
  
  Any comments or taker for v11? Errors are fixed, driver is tested and
  working, DT binding got two ACKs. So, the series is finished as far as I
  can tell.
 
 Just one last comment, sorry for not bringing this up earlier. Could you 
 constify pointer arguments to functions where applicable ? For instance
 
 int videomode_from_timing(struct display_timings *disp, struct videomode *vm,
   unsigned int index);
 
 The function shouldn't modify disp, so you can make it const. Same for most 
 of 
 the API functions.
 

Okay. Will do.

 You can then add my
 
 Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
 

Thanks.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 6/6] drm_modes: add of_videomode helpers

2012-11-20 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   35 ++-
 include/drm/drmP.h  |6 ++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 0073b27..04feef8 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,7 +35,8 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
-#include linux/videomode.h
+#include linux/of.h
+#include linux/of_videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(const struct device_node *np,
+   struct drm_display_mode *dmode, unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index de2f6cf..377280f 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -56,6 +56,7 @@
 #include linux/cdev.h
 #include linux/mutex.h
 #include linux/slab.h
+#include linux/of.h
 #include linux/videomode.h
 #if defined(__alpha__) || defined(__powerpc__)
 #include asm/pgtable.h   /* For pte_wrprotect */
@@ -1459,6 +1460,11 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 extern int drm_display_mode_from_videomode(const struct videomode *vm,
   struct drm_display_mode *dmode);
 #endif
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_drm_display_mode(const struct device_node *np,
+  struct drm_display_mode *dmode,
+  unsigned int index);
+#endif
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 3/6] fbmon: add videomode helpers

2012-11-20 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   46 ++
 include/linux/fb.h|6 ++
 2 files changed, 52 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..c1939a6 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include linux/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,51 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(const struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   fbmode-pixclock = KHZ2PICOS(vm-pixelclock / 1000);
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-hah)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-vah)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-interlaced)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-doublescan)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   if (vm-de)
+   fbmode-sync |= FB_SYNC_DATA_ENABLE_HIGH_ACT;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   fbmode-refresh = (vm-pixelclock * 1000) / (htotal * vtotal);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..920cbe3 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -14,6 +14,7 @@
 #include linux/backlight.h
 #include linux/slab.h
 #include asm/io.h
+#include linux/videomode.h
 
 struct vm_area_struct;
 struct fb_info;
@@ -714,6 +715,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int fb_videomode_from_videomode(const struct videomode *vm,
+  struct fb_videomode *fbmode);
+#endif
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 2/6] video: add of helper for videomode

2012-11-20 Thread Steffen Trumtrar
This adds support for reading display timings from DT or/and convert one of 
those
timings to a videomode.
The of_display_timing implementation supports multiple children where each
property can have up to 3 values. All children are read into an array, that
can be queried.
of_get_videomode converts exactly one of that timings to a struct videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/video/Kconfig  |   13 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  216 
 drivers/video/of_videomode.c   |   48 +
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   18 ++
 7 files changed, 424 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timings.txt 
b/Documentation/devicetree/bindings/video/display-timings.txt
new file mode 100644
index 000..a05cade
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timings.txt
@@ -0,0 +1,107 @@
+display-timings bindings
+
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timings subnode
+---
+
+required properties:
+ - hactive, vactive: Display resolution
+ - hfront-porch, hback-porch, hsync-len: Horizontal Display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: Vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: Hsync pulse is active low/high/ignored
+ - vsync-active: Vsync pulse is active low/high/ignored
+ - de-active: Data-Enable pulse is active low/high/ignored
+ - pixelclk-inverted: pixelclock is inverted/non-inverted/ignored
+ - interlaced (bool)
+ - doublescan (bool)
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The 
devicetree
+representation corresponds to the one commonly found in datasheets for 
displays.
+If a display supports multiple signal timings, the native-mode can be 
specified.
+
+The parameters are defined as
+
+struct display_timing
+=
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive #  |   |
+  |  #|#  |   |
+  |  #↓#  |   |
+  +--###--+---+
+  |  |↑|  |   |
+  |  ||vfront_porch|  |   |
+  |  |↓|  |   |
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vsync_len

[PATCH v12 1/6] video: add display_timing and videomode

2012-11-20 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Every timing parameter can be specified as a single value or a range
min typ max.

Also, add helper functions to convert from display timings to a generic 
videomode
structure. This videomode can then be converted to the corresponding subsystem
mode representation (e.g. fb_videomode).

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/Kconfig  |6 
 drivers/video/Makefile |2 ++
 drivers/video/display_timing.c |   24 ++
 drivers/video/videomode.c  |   46 ++
 include/linux/display_timing.h |   70 
 include/linux/videomode.h  |   40 +++
 6 files changed, 188 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..ac9bbbc
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/display_timing.h
+#include linux/export.h
+#include linux/slab.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..e24f879
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,46 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/errno.h
+#include linux/display_timing.h
+#include linux/kernel.h
+#include linux/videomode.h
+
+int videomode_from_timing(const struct display_timings *disp,
+ struct videomode *vm, unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, 0);
+   vm-hactive = display_timing_get_value(dt-hactive, 0);
+   vm-hfront_porch = display_timing_get_value(dt-hfront_porch, 0);
+   vm-hback_porch = display_timing_get_value(dt-hback_porch, 0);
+   vm-hsync_len = display_timing_get_value(dt-hsync_len, 0);
+
+   vm-vactive = display_timing_get_value(dt-vactive, 0);
+   vm-vfront_porch = display_timing_get_value(dt-vfront_porch, 0);
+   vm-vback_porch = display_timing_get_value(dt-vback_porch, 0);
+   vm-vsync_len = display_timing_get_value(dt-vsync_len, 0);
+
+   vm-vah = dt-vsync_pol_active;
+   vm-hah = dt-hsync_pol_active;
+   vm-de = dt-de_pol_active;
+   vm-pixelclk_pol = dt-pixelclk_pol;
+
+   vm-interlaced = dt-interlaced;
+   vm-doublescan = dt-doublescan;
+
+   return 0;
+}
+
+EXPORT_SYMBOL_GPL(videomode_from_timing);
diff --git a/include/linux/display_timing.h b/include/linux/display_timing.h
new file mode 100644
index 000..d5bf03f
--- /dev/null
+++ b/include/linux/display_timing.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2012 Steffen Trumtrar s.trumt...@pengutronix.de
+ *
+ * description of display timings
+ *
+ * This file is released under

[PATCH v12 5/6] drm_modes: add videomode helpers

2012-11-20 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |6 ++
 2 files changed, 43 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..0073b27 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include linux/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(const struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-hah)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-vah)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-interlaced)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-doublescan)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..de2f6cf 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -56,6 +56,7 @@
 #include linux/cdev.h
 #include linux/mutex.h
 #include linux/slab.h
+#include linux/videomode.h
 #if defined(__alpha__) || defined(__powerpc__)
 #include asm/pgtable.h   /* For pte_wrprotect */
 #endif
@@ -1454,6 +1455,11 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int drm_display_mode_from_videomode(const struct videomode *vm,
+  struct drm_display_mode *dmode);
+#endif
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 4/6] fbmon: add of_videomode helpers

2012-11-20 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
Reviewed-by: Laurent Pinchart laurent.pinch...@ideasonboard.com
---
 drivers/video/fbmon.c |   42 +-
 include/linux/fb.h|7 +++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index c1939a6..16c353c 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,7 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
-#include linux/videomode.h
+#include linux/of_videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1418,6 +1418,46 @@ int fb_videomode_from_videomode(const struct videomode 
*vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(const struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(const struct device_node *np, struct fb_videomode *fb,
+   unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
 
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 920cbe3..41b5e49 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -15,6 +15,8 @@
 #include linux/slab.h
 #include asm/io.h
 #include linux/videomode.h
+#include linux/of.h
+#include linux/of_videomode.h
 
 struct vm_area_struct;
 struct fb_info;
@@ -715,6 +717,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_fb_videomode(const struct device_node *np,
+  struct fb_videomode *fb,
+  unsigned int index);
+#endif
 #if IS_ENABLED(CONFIG_VIDEOMODE)
 extern int fb_videomode_from_videomode(const struct videomode *vm,
   struct fb_videomode *fbmode);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v12 0/6] of: add display helper

2012-11-20 Thread Steffen Trumtrar
Hi!

Changes since v11:
- make pointers const where applicable
- add reviewed-by Laurent Pinchart

Regards,
Steffen


Steffen Trumtrar (6):
  video: add display_timing and videomode
  video: add of helper for videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/gpu/drm/drm_modes.c|   70 +++
 drivers/video/Kconfig  |   19 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 +++
 drivers/video/fbmon.c  |   86 
 drivers/video/of_display_timing.c  |  216 
 drivers/video/of_videomode.c   |   48 +
 drivers/video/videomode.c  |   46 +
 include/drm/drmP.h |   12 ++
 include/linux/display_timing.h |   70 +++
 include/linux/fb.h |   13 ++
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   18 ++
 include/linux/videomode.h  |   40 
 15 files changed, 793 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h
 create mode 100644 include/linux/videomode.h

-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v10 1/6] video: add display_timing and videomode

2012-11-16 Thread Steffen Trumtrar
Hi Grant,

On Thu, Nov 15, 2012 at 06:03:59PM +, Grant Likely wrote:
 On Thu, 15 Nov 2012 17:00:57 +0100, Laurent Pinchart 
 laurent.pinch...@ideasonboard.com wrote:
  Hi Grant,
  
  On Thursday 15 November 2012 15:47:53 Grant Likely wrote:
   On Thu, 15 Nov 2012 10:23:52 +0100, Steffen Trumtrar wrote:
Add display_timing structure and the according helper functions. This
allows the description of a display via its supported timing parameters.

Every timing parameter can be specified as a single value or a range
min typ max.

Also, add helper functions to convert from display timings to a generic
videomode structure. This videomode can then be converted to the
corresponding subsystem mode representation (e.g. fb_videomode).

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
   
   Hmmm... here's my thoughts as an outside reviewer. Correct me if I'm
   making an incorrect assumption.
   
   It looks to me that the purpose of this entire series is to decode video
   timings from the device tree and (eventually) provide the data in the
   form 'struct videomode'. Correct?
   

For the time being it is straight from devicetree via struct videomode
to struct drm_display_mode or fb_videomode. Correct.

   If so, then it looks over engineered. Creating new infrastructure to
   allocate, maintain, and free a new 'struct display_timings' doesn't make
   any sense when it is an intermediary data format that will never be used
   by drivers.
   
   Can the DT parsing code instead return a table of struct videomode?
   

See below.

   But, wait... struct videomode is also a new structure. So it looks like
   this series creates two new intermediary data structures;
   display_timings and videomode. And at least as far as I can see in this
   series struct fb_videomode is the only user.

struct drm_display_mode is also a user in this series see 5/6 and 6/6.

  
  struct videomode is supposed to slowly replace the various video mode 
  structures we currently have in the kernel (struct drm_mode_modeinfo, 
  struct 
  fb_videomode and struct v4l2_bt_timings), at least where possible 
  (userspace 
  APIs can't be broken). This will make it possible to reuse code across the 
  DRM, FB and V4L2 subsystems, such as the EDID parser or HDMI encoder 
  drivers. 
  This rationale might not be clearly explained in the commit message, but 
  having a shared video mode structure is pretty important.


That.

 Okay that make sense. What about struct display_timings?
 

The reason for defining an intermediary step is because of the different things
that are described:
- struct display_timing describes the signal ranges a display supports
- struct display_timings describes all timing settings of a display
- struct videomode describes one single mode generated from that settings

It is possible to generate multiple struct videomodes from one
struct display_timing based on the circumstances. And that is a task for the
driver using the display_timing infos. This means drivers are supposed to use
struct display_timings if they need to generate a struct videomode from the
timing ranges of one entry.
This is just the first step in that direction.
I hope this makes the need for struct display_timings a little clearer.
The other solution would be the one Laurent suggested and pass multiple values
around. Which in my opinion doesn't make it better, more practical or cleaner.


Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 2/6] video: add of helper for videomode

2012-11-15 Thread Steffen Trumtrar
This adds support for reading display timings from DT or/and convert one of 
those
timings to a videomode.
The of_display_timing implementation supports multiple children where each
property can have up to 3 values. All children are read into an array, that
can be queried.
of_get_videomode converts exactly one of that timings to a struct videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
---
 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/video/Kconfig  |   13 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  212 
 drivers/video/of_videomode.c   |   47 +
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   17 ++
 7 files changed, 418 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timings.txt 
b/Documentation/devicetree/bindings/video/display-timings.txt
new file mode 100644
index 000..a05cade
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timings.txt
@@ -0,0 +1,107 @@
+display-timings bindings
+
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timings subnode
+---
+
+required properties:
+ - hactive, vactive: Display resolution
+ - hfront-porch, hback-porch, hsync-len: Horizontal Display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: Vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: Hsync pulse is active low/high/ignored
+ - vsync-active: Vsync pulse is active low/high/ignored
+ - de-active: Data-Enable pulse is active low/high/ignored
+ - pixelclk-inverted: pixelclock is inverted/non-inverted/ignored
+ - interlaced (bool)
+ - doublescan (bool)
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The 
devicetree
+representation corresponds to the one commonly found in datasheets for 
displays.
+If a display supports multiple signal timings, the native-mode can be 
specified.
+
+The parameters are defined as
+
+struct display_timing
+=
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive #  |   |
+  |  #|#  |   |
+  |  #↓#  |   |
+  +--###--+---+
+  |  |↑|  |   |
+  |  ||vfront_porch|  |   |
+  |  |↓|  |   |
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vsync_len   |  |   |
+  |  |↓|  |   |
+  +--+-+--+---+
+
+
+Example:
+
+   display-timings {
+   native-mode = timing0;
+   timing0: 1920p24

[PATCH v10 4/6] fbmon: add of_videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/fbmon.c |   42 +-
 include/linux/fb.h|6 ++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 247e079..9e8c5fa 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,7 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
-#include linux/videomode.h
+#include linux/of_videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1418,6 +1418,46 @@ int fb_videomode_from_videomode(struct videomode *vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+   unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
 
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 4024136..dc8f693 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -15,6 +15,8 @@
 #include linux/slab.h
 #include asm/io.h
 #include linux/videomode.h
+#include linux/of.h
+#include linux/of_videomode.h
 
 struct vm_area_struct;
 struct fb_info;
@@ -715,6 +717,10 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+  unsigned int index);
+#endif
 #if IS_ENABLED(CONFIG_VIDEOMODE)
 extern int fb_videomode_from_videomode(struct videomode *vm,
   struct fb_videomode *fbmode);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 1/6] video: add display_timing and videomode

2012-11-15 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Every timing parameter can be specified as a single value or a range
min typ max.

Also, add helper functions to convert from display timings to a generic 
videomode
structure. This videomode can then be converted to the corresponding subsystem
mode representation (e.g. fb_videomode).

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/Kconfig  |6 
 drivers/video/Makefile |2 ++
 drivers/video/display_timing.c |   24 ++
 drivers/video/videomode.c  |   45 ++
 include/linux/display_timing.h |   69 
 include/linux/videomode.h  |   40 +++
 6 files changed, 186 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..ac9bbbc
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/display_timing.h
+#include linux/export.h
+#include linux/slab.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..087374a
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,45 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/errno.h
+#include linux/display_timing.h
+#include linux/kernel.h
+#include linux/videomode.h
+
+int videomode_from_timing(struct display_timings *disp, struct videomode *vm,
+ unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, 0);
+   vm-hactive = display_timing_get_value(dt-hactive, 0);
+   vm-hfront_porch = display_timing_get_value(dt-hfront_porch, 0);
+   vm-hback_porch = display_timing_get_value(dt-hback_porch, 0);
+   vm-hsync_len = display_timing_get_value(dt-hsync_len, 0);
+
+   vm-vactive = display_timing_get_value(dt-vactive, 0);
+   vm-vfront_porch = display_timing_get_value(dt-vfront_porch, 0);
+   vm-vback_porch = display_timing_get_value(dt-vback_porch, 0);
+   vm-vsync_len = display_timing_get_value(dt-vsync_len, 0);
+
+   vm-vah = dt-vsync_pol_active;
+   vm-hah = dt-hsync_pol_active;
+   vm-de = dt-de_pol_active;
+   vm-pixelclk_pol = dt-pixelclk_pol;
+
+   vm-interlaced = dt-interlaced;
+   vm-doublescan = dt-doublescan;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(videomode_from_timing);
diff --git a/include/linux/display_timing.h b/include/linux/display_timing.h
new file mode 100644
index 000..caee2a8
--- /dev/null
+++ b/include/linux/display_timing.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 Steffen Trumtrar s.trumt...@pengutronix.de
+ *
+ * description of display timings
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_DISPLAY_TIMINGS_H
+#define __LINUX_DISPLAY_TIMINGS_H
+
+#include linux/types.h
+
+struct timing_entry {
+   u32 min;
+   u32 typ;
+   u32 max;
+};
+
+struct display_timing {
+   struct timing_entry pixelclock;
+
+   struct timing_entry hactive

[PATCH v10 5/6] drm_modes: add videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |6 ++
 2 files changed, 43 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..23d951a0 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include linux/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-hah)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-vah)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-interlaced)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-doublescan)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..341049c 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -56,6 +56,7 @@
 #include linux/cdev.h
 #include linux/mutex.h
 #include linux/slab.h
+#include linux/videomode.h
 #if defined(__alpha__) || defined(__powerpc__)
 #include asm/pgtable.h   /* For pte_wrprotect */
 #endif
@@ -1454,6 +1455,11 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int drm_display_mode_from_videomode(struct videomode *vm,
+  struct drm_display_mode *dmode);
+#endif
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 6/6] drm_modes: add of_videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/gpu/drm/drm_modes.c |   35 ++-
 include/drm/drmP.h  |6 ++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 23d951a0..810b534 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,7 +35,8 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
-#include linux/videomode.h
+#include linux/of.h
+#include linux/of_videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(struct videomode *vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   display_mode_from_videomode(vm, dmode);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 341049c..ae132be 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -56,6 +56,7 @@
 #include linux/cdev.h
 #include linux/mutex.h
 #include linux/slab.h
+#include linux/of.h
 #include linux/videomode.h
 #if defined(__alpha__) || defined(__powerpc__)
 #include asm/pgtable.h   /* For pte_wrprotect */
@@ -1459,6 +1460,11 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 extern int drm_display_mode_from_videomode(struct videomode *vm,
   struct drm_display_mode *dmode);
 #endif
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  unsigned int index);
+#endif
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 3/6] fbmon: add videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/video/fbmon.c |   46 ++
 include/linux/fb.h|6 ++
 2 files changed, 52 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..247e079 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include linux/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,51 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   fbmode-pixclock = KHZ2PICOS(vm-pixelclock / 1000);
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-hah)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-vah)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-interlaced)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-doublescan)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   if (vm-de)
+   fbmode-sync |= FB_SYNC_DATA_ENABLE_HIGH_ACT;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   fbmode-refresh = (vm-pixelclock * 1000) / (htotal * vtotal);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..4024136 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -14,6 +14,7 @@
 #include linux/backlight.h
 #include linux/slab.h
 #include asm/io.h
+#include linux/videomode.h
 
 struct vm_area_struct;
 struct fb_info;
@@ -714,6 +715,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int fb_videomode_from_videomode(struct videomode *vm,
+  struct fb_videomode *fbmode);
+#endif
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v10 0/6] of: add display helper

2012-11-15 Thread Steffen Trumtrar
Hi!

Changes since v9:
- don't leak memory when previous timings were correct
- CodingStyle fixes
- move blank lines around

Regards,
Steffen


Steffen Trumtrar (6):
  video: add display_timing and videomode
  video: add of helper for videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/gpu/drm/drm_modes.c|   70 +++
 drivers/video/Kconfig  |   19 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 +++
 drivers/video/fbmon.c  |   86 
 drivers/video/of_display_timing.c  |  212 
 drivers/video/of_videomode.c   |   47 +
 drivers/video/videomode.c  |   45 +
 include/drm/drmP.h |   12 ++
 include/linux/display_timing.h |   69 +++
 include/linux/fb.h |   12 ++
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   17 ++
 include/linux/videomode.h  |   40 
 15 files changed, 784 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h
 create mode 100644 include/linux/videomode.h

-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v10 6/6] drm_modes: add of_videomode helpers

2012-11-15 Thread Steffen Trumtrar
On Thu, Nov 15, 2012 at 10:58:49AM +0100, Thierry Reding wrote:
 On Thu, Nov 15, 2012 at 10:23:57AM +0100, Steffen Trumtrar wrote:
 [...]
  +int of_get_drm_display_mode(struct device_node *np,
  +   struct drm_display_mode *dmode, unsigned int index)
  +{
  +   struct videomode vm;
  +   int ret;
  +
  +   ret = of_get_videomode(np, vm, index);
  +   if (ret)
  +   return ret;
  +
  +   display_mode_from_videomode(vm, dmode);
 
 This function is now called drm_display_mode_from_videomode().
 
Well, can't argue with that. You are right.

Regards,
Steffen

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v10 0/6] of: add display helper

2012-11-15 Thread Steffen Trumtrar
On Thu, Nov 15, 2012 at 11:24:11AM +0100, Thierry Reding wrote:
 On Thu, Nov 15, 2012 at 10:23:51AM +0100, Steffen Trumtrar wrote:
  Hi!
  
  Changes since v9:
  - don't leak memory when previous timings were correct
  - CodingStyle fixes
  - move blank lines around
  
  Regards,
  Steffen
  
  
  Steffen Trumtrar (6):
video: add display_timing and videomode
video: add of helper for videomode
fbmon: add videomode helpers
fbmon: add of_videomode helpers
drm_modes: add videomode helpers
drm_modes: add of_videomode helpers
  
   .../devicetree/bindings/video/display-timings.txt  |  107 ++
   drivers/gpu/drm/drm_modes.c|   70 +++
   drivers/video/Kconfig  |   19 ++
   drivers/video/Makefile |4 +
   drivers/video/display_timing.c |   24 +++
   drivers/video/fbmon.c  |   86 
   drivers/video/of_display_timing.c  |  212 
  
   drivers/video/of_videomode.c   |   47 +
   drivers/video/videomode.c  |   45 +
   include/drm/drmP.h |   12 ++
   include/linux/display_timing.h |   69 +++
   include/linux/fb.h |   12 ++
   include/linux/of_display_timings.h |   20 ++
   include/linux/of_videomode.h   |   17 ++
   include/linux/videomode.h  |   40 
   15 files changed, 784 insertions(+)
   create mode 100644 
  Documentation/devicetree/bindings/video/display-timings.txt
   create mode 100644 drivers/video/display_timing.c
   create mode 100644 drivers/video/of_display_timing.c
   create mode 100644 drivers/video/of_videomode.c
   create mode 100644 drivers/video/videomode.c
   create mode 100644 include/linux/display_timing.h
   create mode 100644 include/linux/of_display_timings.h
   create mode 100644 include/linux/of_videomode.h
   create mode 100644 include/linux/videomode.h
 
 With the one change that I pointed out, the whole series:
 

Already fixed.

 Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
 Acked-by: Thierry Reding thierry.red...@avionic-design.de

\o/ Thanks


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 3/6] fbmon: add videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add a function to convert from the generic videomode to a fb_videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/video/fbmon.c |   46 ++
 include/linux/fb.h|6 ++
 2 files changed, 52 insertions(+)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index cef6557..247e079 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,6 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
+#include linux/videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1373,6 +1374,51 @@ int fb_get_mode(int flags, u32 val, struct 
fb_var_screeninfo *var, struct fb_inf
kfree(timings);
return err;
 }
+
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int fb_videomode_from_videomode(struct videomode *vm,
+   struct fb_videomode *fbmode)
+{
+   unsigned int htotal, vtotal;
+
+   fbmode-xres = vm-hactive;
+   fbmode-left_margin = vm-hback_porch;
+   fbmode-right_margin = vm-hfront_porch;
+   fbmode-hsync_len = vm-hsync_len;
+
+   fbmode-yres = vm-vactive;
+   fbmode-upper_margin = vm-vback_porch;
+   fbmode-lower_margin = vm-vfront_porch;
+   fbmode-vsync_len = vm-vsync_len;
+
+   fbmode-pixclock = KHZ2PICOS(vm-pixelclock / 1000);
+
+   fbmode-sync = 0;
+   fbmode-vmode = 0;
+   if (vm-hah)
+   fbmode-sync |= FB_SYNC_HOR_HIGH_ACT;
+   if (vm-vah)
+   fbmode-sync |= FB_SYNC_VERT_HIGH_ACT;
+   if (vm-interlaced)
+   fbmode-vmode |= FB_VMODE_INTERLACED;
+   if (vm-doublescan)
+   fbmode-vmode |= FB_VMODE_DOUBLE;
+   if (vm-de)
+   fbmode-sync |= FB_SYNC_DATA_ENABLE_HIGH_ACT;
+   fbmode-flag = 0;
+
+   htotal = vm-hactive + vm-hfront_porch + vm-hback_porch +
+vm-hsync_len;
+   vtotal = vm-vactive + vm-vfront_porch + vm-vback_porch +
+vm-vsync_len;
+   fbmode-refresh = (vm-pixelclock * 1000) / (htotal * vtotal);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
+#endif
+
+
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
 {
diff --git a/include/linux/fb.h b/include/linux/fb.h
index c7a9571..4024136 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -14,6 +14,7 @@
 #include linux/backlight.h
 #include linux/slab.h
 #include asm/io.h
+#include linux/videomode.h
 
 struct vm_area_struct;
 struct fb_info;
@@ -714,6 +715,11 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int fb_videomode_from_videomode(struct videomode *vm,
+  struct fb_videomode *fbmode);
+#endif
+
 /* drivers/video/modedb.c */
 #define VESA_MODEDB_SIZE 34
 extern void fb_var_to_videomode(struct fb_videomode *mode,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 5/6] drm_modes: add videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add conversion from videomode to drm_display_mode

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/gpu/drm/drm_modes.c |   37 +
 include/drm/drmP.h  |6 ++
 2 files changed, 43 insertions(+)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 59450f3..23d951a0 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,6 +35,7 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
+#include linux/videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +505,42 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int 
vdisplay, int vrefresh,
 }
 EXPORT_SYMBOL(drm_gtf_mode);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+int drm_display_mode_from_videomode(struct videomode *vm,
+   struct drm_display_mode *dmode)
+{
+   dmode-hdisplay = vm-hactive;
+   dmode-hsync_start = dmode-hdisplay + vm-hfront_porch;
+   dmode-hsync_end = dmode-hsync_start + vm-hsync_len;
+   dmode-htotal = dmode-hsync_end + vm-hback_porch;
+
+   dmode-vdisplay = vm-vactive;
+   dmode-vsync_start = dmode-vdisplay + vm-vfront_porch;
+   dmode-vsync_end = dmode-vsync_start + vm-vsync_len;
+   dmode-vtotal = dmode-vsync_end + vm-vback_porch;
+
+   dmode-clock = vm-pixelclock / 1000;
+
+   dmode-flags = 0;
+   if (vm-hah)
+   dmode-flags |= DRM_MODE_FLAG_PHSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NHSYNC;
+   if (vm-vah)
+   dmode-flags |= DRM_MODE_FLAG_PVSYNC;
+   else
+   dmode-flags |= DRM_MODE_FLAG_NVSYNC;
+   if (vm-interlaced)
+   dmode-flags |= DRM_MODE_FLAG_INTERLACE;
+   if (vm-doublescan)
+   dmode-flags |= DRM_MODE_FLAG_DBLSCAN;
+   drm_mode_set_name(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 3fd8280..341049c 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -56,6 +56,7 @@
 #include linux/cdev.h
 #include linux/mutex.h
 #include linux/slab.h
+#include linux/videomode.h
 #if defined(__alpha__) || defined(__powerpc__)
 #include asm/pgtable.h   /* For pte_wrprotect */
 #endif
@@ -1454,6 +1455,11 @@ extern struct drm_display_mode *
 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  struct drm_cmdline_mode *cmd);
 
+#if IS_ENABLED(CONFIG_VIDEOMODE)
+extern int drm_display_mode_from_videomode(struct videomode *vm,
+  struct drm_display_mode *dmode);
+#endif
+
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
 extern void drm_vblank_post_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 0/6] of: add display helper

2012-11-15 Thread Steffen Trumtrar
Hi!

Changes since v10:
- fix function name (drm_)display_mode_from_videomode
- add acked-by, reviewed-by, tested-by

Regards,
Steffen


Steffen Trumtrar (6):
  video: add display_timing and videomode
  video: add of helper for videomode
  fbmon: add videomode helpers
  fbmon: add of_videomode helpers
  drm_modes: add videomode helpers
  drm_modes: add of_videomode helpers

 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/gpu/drm/drm_modes.c|   70 +++
 drivers/video/Kconfig  |   19 ++
 drivers/video/Makefile |4 +
 drivers/video/display_timing.c |   24 +++
 drivers/video/fbmon.c  |   86 
 drivers/video/of_display_timing.c  |  212 
 drivers/video/of_videomode.c   |   47 +
 drivers/video/videomode.c  |   45 +
 include/drm/drmP.h |   12 ++
 include/linux/display_timing.h |   69 +++
 include/linux/fb.h |   12 ++
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   17 ++
 include/linux/videomode.h  |   40 
 15 files changed, 784 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h
 create mode 100644 include/linux/videomode.h

-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 1/6] video: add display_timing and videomode

2012-11-15 Thread Steffen Trumtrar
Add display_timing structure and the according helper functions. This allows
the description of a display via its supported timing parameters.

Every timing parameter can be specified as a single value or a range
min typ max.

Also, add helper functions to convert from display timings to a generic 
videomode
structure. This videomode can then be converted to the corresponding subsystem
mode representation (e.g. fb_videomode).

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/video/Kconfig  |6 
 drivers/video/Makefile |2 ++
 drivers/video/display_timing.c |   24 ++
 drivers/video/videomode.c  |   45 ++
 include/linux/display_timing.h |   69 
 include/linux/videomode.h  |   40 +++
 6 files changed, 186 insertions(+)
 create mode 100644 drivers/video/display_timing.c
 create mode 100644 drivers/video/videomode.c
 create mode 100644 include/linux/display_timing.h
 create mode 100644 include/linux/videomode.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index d08d799..2a23b18 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -33,6 +33,12 @@ config VIDEO_OUTPUT_CONTROL
  This framework adds support for low-level control of the video 
  output switch.
 
+config DISPLAY_TIMING
+   bool
+
+config VIDEOMODE
+   bool
+
 menuconfig FB
tristate Support for frame buffer devices
---help---
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 23e948e..fc30439 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -167,3 +167,5 @@ obj-$(CONFIG_FB_VIRTUAL)  += vfb.o
 
 #video output switch sysfs driver
 obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
+obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
+obj-$(CONFIG_VIDEOMODE) += videomode.o
diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
new file mode 100644
index 000..ac9bbbc
--- /dev/null
+++ b/drivers/video/display_timing.c
@@ -0,0 +1,24 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/display_timing.h
+#include linux/export.h
+#include linux/slab.h
+
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
+EXPORT_SYMBOL_GPL(display_timings_release);
diff --git a/drivers/video/videomode.c b/drivers/video/videomode.c
new file mode 100644
index 000..087374a
--- /dev/null
+++ b/drivers/video/videomode.c
@@ -0,0 +1,45 @@
+/*
+ * generic display timing functions
+ *
+ * Copyright (c) 2012 Steffen Trumtrar s.trumt...@pengutronix.de, Pengutronix
+ *
+ * This file is released under the GPLv2
+ */
+
+#include linux/export.h
+#include linux/errno.h
+#include linux/display_timing.h
+#include linux/kernel.h
+#include linux/videomode.h
+
+int videomode_from_timing(struct display_timings *disp, struct videomode *vm,
+ unsigned int index)
+{
+   struct display_timing *dt;
+
+   dt = display_timings_get(disp, index);
+   if (!dt)
+   return -EINVAL;
+
+   vm-pixelclock = display_timing_get_value(dt-pixelclock, 0);
+   vm-hactive = display_timing_get_value(dt-hactive, 0);
+   vm-hfront_porch = display_timing_get_value(dt-hfront_porch, 0);
+   vm-hback_porch = display_timing_get_value(dt-hback_porch, 0);
+   vm-hsync_len = display_timing_get_value(dt-hsync_len, 0);
+
+   vm-vactive = display_timing_get_value(dt-vactive, 0);
+   vm-vfront_porch = display_timing_get_value(dt-vfront_porch, 0);
+   vm-vback_porch = display_timing_get_value(dt-vback_porch, 0);
+   vm-vsync_len = display_timing_get_value(dt-vsync_len, 0);
+
+   vm-vah = dt-vsync_pol_active;
+   vm-hah = dt-hsync_pol_active;
+   vm-de = dt-de_pol_active;
+   vm-pixelclk_pol = dt-pixelclk_pol;
+
+   vm-interlaced = dt-interlaced;
+   vm-doublescan = dt-doublescan;
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(videomode_from_timing);
diff --git a/include/linux/display_timing.h b/include/linux/display_timing.h
new file mode 100644
index 000..caee2a8
--- /dev/null
+++ b/include/linux/display_timing.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012 Steffen Trumtrar s.trumt...@pengutronix.de
+ *
+ * description of display timings
+ *
+ * This file is released under the GPLv2
+ */
+
+#ifndef __LINUX_DISPLAY_TIMINGS_H
+#define

[PATCH v11 6/6] drm_modes: add of_videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/gpu/drm/drm_modes.c |   35 ++-
 include/drm/drmP.h  |6 ++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 23d951a0..5508037 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,7 +35,8 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
-#include linux/videomode.h
+#include linux/of.h
+#include linux/of_videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(struct videomode *vm,
 EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np,
+   struct drm_display_mode *dmode, unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   drm_display_mode_from_videomode(vm, dmode);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
+
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 341049c..ae132be 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -56,6 +56,7 @@
 #include linux/cdev.h
 #include linux/mutex.h
 #include linux/slab.h
+#include linux/of.h
 #include linux/videomode.h
 #if defined(__alpha__) || defined(__powerpc__)
 #include asm/pgtable.h   /* For pte_wrprotect */
@@ -1459,6 +1460,11 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 extern int drm_display_mode_from_videomode(struct videomode *vm,
   struct drm_display_mode *dmode);
 #endif
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  unsigned int index);
+#endif
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 4/6] fbmon: add of_videomode helpers

2012-11-15 Thread Steffen Trumtrar
Add helper to get fb_videomode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/video/fbmon.c |   42 +-
 include/linux/fb.h|6 ++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 247e079..9e8c5fa 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -31,7 +31,7 @@
 #include linux/pci.h
 #include linux/slab.h
 #include video/edid.h
-#include linux/videomode.h
+#include linux/of_videomode.h
 #ifdef CONFIG_PPC_OF
 #include asm/prom.h
 #include asm/pci-bridge.h
@@ -1418,6 +1418,46 @@ int fb_videomode_from_videomode(struct videomode *vm,
 EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+static inline void dump_fb_videomode(struct fb_videomode *m)
+{
+   pr_debug(fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u 
%u\n,
+m-xres, m-yres, m-refresh, m-pixclock, m-left_margin,
+m-right_margin, m-upper_margin, m-lower_margin,
+m-hsync_len, m-vsync_len, m-sync, m-vmode, m-flag);
+}
+
+/**
+ * of_get_fb_videomode - get a fb_videomode from devicetree
+ * @np: device_node with the timing specification
+ * @fb: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * DESCRIPTION:
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings ond
+ * work with that instead.
+ */
+int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+   unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   fb_videomode_from_videomode(vm, fb);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   dump_fb_videomode(fb);
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_fb_videomode);
+#endif
 
 #else
 int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 4024136..dc8f693 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -15,6 +15,8 @@
 #include linux/slab.h
 #include asm/io.h
 #include linux/videomode.h
+#include linux/of.h
+#include linux/of_videomode.h
 
 struct vm_area_struct;
 struct fb_info;
@@ -715,6 +717,10 @@ extern void fb_destroy_modedb(struct fb_videomode *modedb);
 extern int fb_find_mode_cvt(struct fb_videomode *mode, int margins, int rb);
 extern unsigned char *fb_ddc_read(struct i2c_adapter *adapter);
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
+  unsigned int index);
+#endif
 #if IS_ENABLED(CONFIG_VIDEOMODE)
 extern int fb_videomode_from_videomode(struct videomode *vm,
   struct fb_videomode *fbmode);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v11 2/6] video: add of helper for videomode

2012-11-15 Thread Steffen Trumtrar
This adds support for reading display timings from DT or/and convert one of 
those
timings to a videomode.
The of_display_timing implementation supports multiple children where each
property can have up to 3 values. All children are read into an array, that
can be queried.
of_get_videomode converts exactly one of that timings to a struct videomode.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
Signed-off-by: Philipp Zabel p.za...@pengutronix.de
Acked-by: Stephen Warren swar...@nvidia.com
Reviewed-by: Thierry Reding thierry.red...@avionic-design.de
Acked-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Thierry Reding thierry.red...@avionic-design.de
Tested-by: Philipp Zabel p.za...@pengutronix.de
---
 .../devicetree/bindings/video/display-timings.txt  |  107 ++
 drivers/video/Kconfig  |   13 ++
 drivers/video/Makefile |2 +
 drivers/video/of_display_timing.c  |  212 
 drivers/video/of_videomode.c   |   47 +
 include/linux/of_display_timings.h |   20 ++
 include/linux/of_videomode.h   |   17 ++
 7 files changed, 418 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/video/display-timings.txt
 create mode 100644 drivers/video/of_display_timing.c
 create mode 100644 drivers/video/of_videomode.c
 create mode 100644 include/linux/of_display_timings.h
 create mode 100644 include/linux/of_videomode.h

diff --git a/Documentation/devicetree/bindings/video/display-timings.txt 
b/Documentation/devicetree/bindings/video/display-timings.txt
new file mode 100644
index 000..a05cade
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/display-timings.txt
@@ -0,0 +1,107 @@
+display-timings bindings
+
+
+display-timings node
+
+
+required properties:
+ - none
+
+optional properties:
+ - native-mode: The native mode for the display, in case multiple modes are
+   provided. When omitted, assume the first node is the native.
+
+timings subnode
+---
+
+required properties:
+ - hactive, vactive: Display resolution
+ - hfront-porch, hback-porch, hsync-len: Horizontal Display timing parameters
+   in pixels
+   vfront-porch, vback-porch, vsync-len: Vertical display timing parameters in
+   lines
+ - clock-frequency: display clock in Hz
+
+optional properties:
+ - hsync-active: Hsync pulse is active low/high/ignored
+ - vsync-active: Vsync pulse is active low/high/ignored
+ - de-active: Data-Enable pulse is active low/high/ignored
+ - pixelclk-inverted: pixelclock is inverted/non-inverted/ignored
+ - interlaced (bool)
+ - doublescan (bool)
+
+All the optional properties that are not bool follow the following logic:
+1: high active
+0: low active
+omitted: not used on hardware
+
+There are different ways of describing the capabilities of a display. The 
devicetree
+representation corresponds to the one commonly found in datasheets for 
displays.
+If a display supports multiple signal timings, the native-mode can be 
specified.
+
+The parameters are defined as
+
+struct display_timing
+=
+
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vback_porch |  |   |
+  |  |↓|  |   |
+  +--###--+---+
+  |  #↑#  |   |
+  |  #|#  |   |
+  |  hback   #|#  hfront  | hsync |
+  |   porch  #|   hactive  #  porch   |  len  |
+  |#---+---#|-|
+  |  #|#  |   |
+  |  #|vactive #  |   |
+  |  #|#  |   |
+  |  #↓#  |   |
+  +--###--+---+
+  |  |↑|  |   |
+  |  ||vfront_porch|  |   |
+  |  |↓|  |   |
+  +--+-+--+---+
+  |  |↑|  |   |
+  |  ||vsync_len

Re: [PATCH v8 1/6] video: add display_timing and videomode

2012-11-14 Thread Steffen Trumtrar
On Wed, Nov 14, 2012 at 11:56:34AM +0100, Thierry Reding wrote:
 On Mon, Nov 12, 2012 at 04:37:01PM +0100, Steffen Trumtrar wrote:
 [...]
  diff --git a/drivers/video/display_timing.c b/drivers/video/display_timing.c
 [...]
  +void display_timings_release(struct display_timings *disp)
  +{
  +   if (disp-timings) {
  +   unsigned int i;
  +
  +   for (i = 0; i  disp-num_timings; i++)
  +   kfree(disp-timings[i]);
  +   kfree(disp-timings);
  +   }
  +   kfree(disp);
  +}
 
 I think this is still missing an EXPORT_SYMBOL_GPL. Otherwise it can't
 be used from modules.
 
 Thierry

Yes. Just in time. I was just starting to type the send-email command ;-)

Regards,
Steffen


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v8 1/6] video: add display_timing and videomode

2012-11-14 Thread Steffen Trumtrar
On Wed, Nov 14, 2012 at 12:02:15PM +0100, Thierry Reding wrote:
 On Wed, Nov 14, 2012 at 11:59:25AM +0100, Steffen Trumtrar wrote:
  On Wed, Nov 14, 2012 at 11:56:34AM +0100, Thierry Reding wrote:
   On Mon, Nov 12, 2012 at 04:37:01PM +0100, Steffen Trumtrar wrote:
   [...]
diff --git a/drivers/video/display_timing.c 
b/drivers/video/display_timing.c
   [...]
+void display_timings_release(struct display_timings *disp)
+{
+   if (disp-timings) {
+   unsigned int i;
+
+   for (i = 0; i  disp-num_timings; i++)
+   kfree(disp-timings[i]);
+   kfree(disp-timings);
+   }
+   kfree(disp);
+}
   
   I think this is still missing an EXPORT_SYMBOL_GPL. Otherwise it can't
   be used from modules.
   
   Thierry
  
  Yes. Just in time. I was just starting to type the send-email command ;-)
 
 Great! In that case don't forget to also look at my other email before
 sending. =)
 
Sure.


-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 6/6] drm_modes: add of_videomode helpers

2012-11-14 Thread Steffen Trumtrar
Add helper to get drm_display_mode from devicetree.

Signed-off-by: Steffen Trumtrar s.trumt...@pengutronix.de
---
 drivers/gpu/drm/drm_modes.c |   35 ++-
 include/drm/drmP.h  |6 ++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 42ea099..c3ae5d2 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -35,7 +35,8 @@
 #include linux/export.h
 #include drm/drmP.h
 #include drm/drm_crtc.h
-#include linux/videomode.h
+#include linux/of.h
+#include linux/of_videomode.h
 
 /**
  * drm_mode_debug_printmodeline - debug print a mode
@@ -540,6 +541,38 @@ int display_mode_from_videomode(struct videomode *vm, 
struct drm_display_mode *d
 EXPORT_SYMBOL_GPL(display_mode_from_videomode);
 #endif
 
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+/**
+ * of_get_drm_display_mode - get a drm_display_mode from devicetree
+ * @np: device_node with the timing specification
+ * @dmode: will be set to the return value
+ * @index: index into the list of display timings in devicetree
+ *
+ * This function is expensive and should only be used, if only one mode is to 
be
+ * read from DT. To get multiple modes start with of_get_display_timings and
+ * work with that instead.
+ */
+int of_get_drm_display_mode(struct device_node *np, struct drm_display_mode 
*dmode,
+   unsigned int index)
+{
+   struct videomode vm;
+   int ret;
+
+   ret = of_get_videomode(np, vm, index);
+   if (ret)
+   return ret;
+
+   display_mode_from_videomode(vm, dmode);
+
+   pr_info(%s: got %dx%d display mode from %s\n, __func__, vm.hactive,
+   vm.vactive, np-name);
+   drm_mode_debug_printmodeline(dmode);
+
+   return 0;
+
+}
+EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
+#endif
 /**
  * drm_mode_set_name - set the name on a mode
  * @mode: name will be set in this mode
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 1e0d846..e8f46a1 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -56,6 +56,7 @@
 #include linux/cdev.h
 #include linux/mutex.h
 #include linux/slab.h
+#include linux/of.h
 #include linux/videomode.h
 #if defined(__alpha__) || defined(__powerpc__)
 #include asm/pgtable.h   /* For pte_wrprotect */
@@ -1459,6 +1460,11 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
 extern int display_mode_from_videomode(struct videomode *vm,
   struct drm_display_mode *dmode);
 #endif
+#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
+extern int of_get_drm_display_mode(struct device_node *np,
+  struct drm_display_mode *dmode,
+  unsigned int index);
+#endif
 
 /* Modesetting support */
 extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   >