[PATCH RFC v2 04/12] drm/components: add generic vga encoder driver

2015-04-01 Thread Heiko Stübner
Hi Russell,

Am Mittwoch, 1. April 2015, 11:27:51 schrieb Russell King - ARM Linux:
> On Wed, Apr 01, 2015 at 12:09:38PM +0200, Heiko Stuebner wrote:
> > This adds a driver for generic vga encoders like the Analog Devices
> > adv7123
> > and similar ics. These chips do not have any special configuration options
> > except a powersafe gpio.
> > 
> > An exception is added for the rcar-du driver which also implements support
> > for the adv7123 internally but is not yet converted to the component
> > framework.
> Why is this implemented as a master?  It's not the top level card device,
> it shouldn't be a master.  It should be a component.
> 
> I wonder if this is why you need your previous patches.  Componentised
> DRM works fine without needing to build lists of connectors and encoders.

It is a component to the upper drm driver (rockchip or whatever) but a master 
to the vga connector below, simply because the drm driver above (the lvds 
controller in this case) does not know and also probably shouldn't care what 
the structure below is.

So in this case the lvds knows there is either a panel or an encoder 
connected, but does not need to handle if this downstream component is some 
one-piece i2c component like a tv encoder or contains another component down 
below, like the vga-connector in this case.


Of course I may very well have overlooked some simpler method to achieve this, 
but got inspired to this by the similar way done in sti/sti_tvout.c


Heiko



[PATCH RFC v2 04/12] drm/components: add generic vga encoder driver

2015-04-01 Thread Heiko Stuebner
This adds a driver for generic vga encoders like the Analog Devices adv7123
and similar ics. These chips do not have any special configuration options
except a powersafe gpio.

An exception is added for the rcar-du driver which also implements support
for the adv7123 internally but is not yet converted to the component framework.

Signed-off-by: Heiko Stuebner 
---
 drivers/gpu/drm/components/Kconfig   |   5 +
 drivers/gpu/drm/components/Makefile  |   2 +
 drivers/gpu/drm/components/vga-encoder.c | 315 +++
 3 files changed, 322 insertions(+)
 create mode 100644 drivers/gpu/drm/components/vga-encoder.c

diff --git a/drivers/gpu/drm/components/Kconfig 
b/drivers/gpu/drm/components/Kconfig
index 9d5d462..647cea6 100644
--- a/drivers/gpu/drm/components/Kconfig
+++ b/drivers/gpu/drm/components/Kconfig
@@ -1,4 +1,9 @@
 menu "Standalone components for use with the component framework"
  depends on DRM && DRM_KMS_HELPER

+config DRM_COMPONENTS_VGA_ENCODER
+   tristate "Generic vga encoder"
+   help
+ Support for generic vga encoder chips without any special controls.
+
 endmenu
diff --git a/drivers/gpu/drm/components/Makefile 
b/drivers/gpu/drm/components/Makefile
index be16eca..719b1c9 100644
--- a/drivers/gpu/drm/components/Makefile
+++ b/drivers/gpu/drm/components/Makefile
@@ -1 +1,3 @@
 ccflags-y := -Iinclude/drm
+
+obj-$(CONFIG_DRM_COMPONENTS_VGA_ENCODER) += vga-encoder.o
diff --git a/drivers/gpu/drm/components/vga-encoder.c 
b/drivers/gpu/drm/components/vga-encoder.c
new file mode 100644
index 000..f559b5e
--- /dev/null
+++ b/drivers/gpu/drm/components/vga-encoder.c
@@ -0,0 +1,315 @@
+/*
+ * Simple vga encoder driver
+ *
+ * Copyright (C) 2014 Heiko Stuebner 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define encoder_to_vga_encoder(x) container_of(x, struct vga_encoder, encoder)
+
+struct vga_encoder {
+   struct drm_encoder encoder;
+   struct device *dev;
+   struct regulator *vaa_reg;
+   struct gpio_desc *psave_gpio;
+
+   struct mutex enable_lock;
+   bool enabled;
+};
+
+static void vga_encoder_destroy(struct drm_encoder *encoder)
+{
+   drm_encoder_cleanup(encoder);
+}
+
+static const struct drm_encoder_funcs vga_encoder_funcs = {
+   .destroy = vga_encoder_destroy,
+};
+
+static void vga_encoder_dpms(struct drm_encoder *encoder, int mode)
+{
+   struct vga_encoder *vga = encoder_to_vga_encoder(encoder);
+
+   mutex_lock(>enable_lock);
+
+   switch (mode) {
+   case DRM_MODE_DPMS_ON:
+   if (vga->enabled)
+   goto out;
+
+   if (!IS_ERR(vga->vaa_reg))
+   regulator_enable(vga->vaa_reg);
+
+   if (vga->psave_gpio)
+   gpiod_set_value(vga->psave_gpio, 1);
+
+   vga->enabled = true;
+   break;
+   case DRM_MODE_DPMS_STANDBY:
+   case DRM_MODE_DPMS_SUSPEND:
+   case DRM_MODE_DPMS_OFF:
+   if (!vga->enabled)
+   goto out;
+
+   if (vga->psave_gpio)
+   gpiod_set_value(vga->psave_gpio, 0);
+
+   if (!IS_ERR(vga->vaa_reg))
+   regulator_enable(vga->vaa_reg);
+
+   vga->enabled = false;
+   break;
+   default:
+   break;
+   }
+
+out:
+   mutex_unlock(>enable_lock);
+}
+
+static bool vga_encoder_mode_fixup(struct drm_encoder *encoder,
+ const struct drm_display_mode *mode,
+ struct drm_display_mode *adjusted_mode)
+{
+   return true;
+}
+
+static void vga_encoder_prepare(struct drm_encoder *encoder)
+{
+}
+
+static void vga_encoder_mode_set(struct drm_encoder *encoder,
+   struct drm_display_mode *mode,
+   struct drm_display_mode *adjusted_mode)
+{
+}
+
+static void vga_encoder_commit(struct drm_encoder *encoder)
+{
+   vga_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
+}
+
+static void vga_encoder_disable(struct drm_encoder *encoder)
+{
+   vga_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
+}
+
+static const struct drm_encoder_helper_funcs vga_encoder_helper_funcs = {
+   .dpms = vga_encoder_dpms,
+   .mode_fixup = vga_encoder_mode_fixup,
+   .prepare = vga_encoder_prepare,
+   .mode_set = vga_encoder_mode_set,
+   

[PATCH RFC v2 04/12] drm/components: add generic vga encoder driver

2015-04-01 Thread Russell King - ARM Linux
On Wed, Apr 01, 2015 at 12:09:38PM +0200, Heiko Stuebner wrote:
> This adds a driver for generic vga encoders like the Analog Devices adv7123
> and similar ics. These chips do not have any special configuration options
> except a powersafe gpio.
> 
> An exception is added for the rcar-du driver which also implements support
> for the adv7123 internally but is not yet converted to the component 
> framework.

Why is this implemented as a master?  It's not the top level card device,
it shouldn't be a master.  It should be a component.

I wonder if this is why you need your previous patches.  Componentised
DRM works fine without needing to build lists of connectors and encoders.

-- 
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.