drm: add convenience function to create an range property
authorSascha Hauer <s.hauer@pengutronix.de>
Mon, 6 Feb 2012 09:58:18 +0000 (10:58 +0100)
committerDave Airlie <airlied@redhat.com>
Thu, 9 Feb 2012 10:15:25 +0000 (10:15 +0000)
Creating a range property is a common pattern, so create
a convenience function for this and use it where appropriate.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/gma500/framebuffer.c
drivers/gpu/drm/gma500/psb_intel_sdvo.c
drivers/gpu/drm/i2c/ch7006_drv.c
drivers/gpu/drm/i915/intel_sdvo.c
drivers/gpu/drm/nouveau/nouveau_display.c
drivers/gpu/drm/radeon/radeon_display.c
include/drm/drm_crtc.h

index 3fe99c456a193be37bd626e49e0893a9e8a1bf0e..6fdaf6fe94eb57dfcc36c6c23a454c1ca8519d80 100644 (file)
@@ -742,28 +742,16 @@ int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
         * Other, TV specific properties: margins & TV modes.
         */
        dev->mode_config.tv_left_margin_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "left margin", 2);
-       dev->mode_config.tv_left_margin_property->values[0] = 0;
-       dev->mode_config.tv_left_margin_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "left margin", 0, 100);
 
        dev->mode_config.tv_right_margin_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "right margin", 2);
-       dev->mode_config.tv_right_margin_property->values[0] = 0;
-       dev->mode_config.tv_right_margin_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "right margin", 0, 100);
 
        dev->mode_config.tv_top_margin_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "top margin", 2);
-       dev->mode_config.tv_top_margin_property->values[0] = 0;
-       dev->mode_config.tv_top_margin_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "top margin", 0, 100);
 
        dev->mode_config.tv_bottom_margin_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "bottom margin", 2);
-       dev->mode_config.tv_bottom_margin_property->values[0] = 0;
-       dev->mode_config.tv_bottom_margin_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "bottom margin", 0, 100);
 
        dev->mode_config.tv_mode_property =
                drm_property_create(dev, DRM_MODE_PROP_ENUM,
@@ -773,40 +761,22 @@ int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
                                      i, modes[i]);
 
        dev->mode_config.tv_brightness_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "brightness", 2);
-       dev->mode_config.tv_brightness_property->values[0] = 0;
-       dev->mode_config.tv_brightness_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "brightness", 0, 100);
 
        dev->mode_config.tv_contrast_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "contrast", 2);
-       dev->mode_config.tv_contrast_property->values[0] = 0;
-       dev->mode_config.tv_contrast_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "contrast", 0, 100);
 
        dev->mode_config.tv_flicker_reduction_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "flicker reduction", 2);
-       dev->mode_config.tv_flicker_reduction_property->values[0] = 0;
-       dev->mode_config.tv_flicker_reduction_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
 
        dev->mode_config.tv_overscan_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "overscan", 2);
-       dev->mode_config.tv_overscan_property->values[0] = 0;
-       dev->mode_config.tv_overscan_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "overscan", 0, 100);
 
        dev->mode_config.tv_saturation_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "saturation", 2);
-       dev->mode_config.tv_saturation_property->values[0] = 0;
-       dev->mode_config.tv_saturation_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "saturation", 0, 100);
 
        dev->mode_config.tv_hue_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "hue", 2);
-       dev->mode_config.tv_hue_property->values[0] = 0;
-       dev->mode_config.tv_hue_property->values[1] = 100;
+               drm_property_create_range(dev, 0, "hue", 0, 100);
 
        return 0;
 }
@@ -2621,6 +2591,25 @@ struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
 }
 EXPORT_SYMBOL(drm_property_create_enum);
 
+struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
+                                        const char *name,
+                                        uint64_t min, uint64_t max)
+{
+       struct drm_property *property;
+
+       flags |= DRM_MODE_PROP_RANGE;
+
+       property = drm_property_create(dev, flags, name, 2);
+       if (!property)
+               return NULL;
+
+       property->values[0] = min;
+       property->values[1] = max;
+
+       return property;
+}
+EXPORT_SYMBOL(drm_property_create_range);
+
 int drm_property_add_enum(struct drm_property *property, int index,
                          uint64_t value, const char *name)
 {
index 830dfdd6bf154a473e15357654cf4d19be8d6b81..78733b5fd3fbc07d29b1302b82ab2a21db55bb68 100644 (file)
@@ -725,10 +725,7 @@ static int psb_create_backlight_property(struct drm_device *dev)
        if (dev_priv->backlight_property)
                return 0;
 
-       backlight = drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                                       "backlight", 2);
-       backlight->values[0] = 0;
-       backlight->values[1] = 100;
+       backlight = drm_property_create_range(dev, 0, "backlight", 0, 100);
 
        dev_priv->backlight_property = backlight;
 
index 88b42971c0fd07356155110581ea5c7e681a8408..41b55d7a7bf868714678572557393ffb81313739 100644 (file)
@@ -2312,10 +2312,8 @@ static bool psb_intel_sdvo_tv_create_property(struct psb_intel_sdvo *psb_intel_s
                psb_intel_sdvo_connector->max_##name = data_value[0]; \
                psb_intel_sdvo_connector->cur_##name = response; \
                psb_intel_sdvo_connector->name = \
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE, #name, 2); \
+                       drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
                if (!psb_intel_sdvo_connector->name) return false; \
-               psb_intel_sdvo_connector->name->values[0] = 0; \
-               psb_intel_sdvo_connector->name->values[1] = data_value[0]; \
                drm_connector_attach_property(connector, \
                                              psb_intel_sdvo_connector->name, \
                                              psb_intel_sdvo_connector->cur_##name); \
@@ -2349,25 +2347,19 @@ psb_intel_sdvo_create_enhance_property_tv(struct psb_intel_sdvo *psb_intel_sdvo,
                psb_intel_sdvo_connector->left_margin = data_value[0] - response;
                psb_intel_sdvo_connector->right_margin = psb_intel_sdvo_connector->left_margin;
                psb_intel_sdvo_connector->left =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "left_margin", 2);
+                       drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
                if (!psb_intel_sdvo_connector->left)
                        return false;
 
-               psb_intel_sdvo_connector->left->values[0] = 0;
-               psb_intel_sdvo_connector->left->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              psb_intel_sdvo_connector->left,
                                              psb_intel_sdvo_connector->left_margin);
 
                psb_intel_sdvo_connector->right =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "right_margin", 2);
+                       drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
                if (!psb_intel_sdvo_connector->right)
                        return false;
 
-               psb_intel_sdvo_connector->right->values[0] = 0;
-               psb_intel_sdvo_connector->right->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              psb_intel_sdvo_connector->right,
                                              psb_intel_sdvo_connector->right_margin);
@@ -2391,25 +2383,19 @@ psb_intel_sdvo_create_enhance_property_tv(struct psb_intel_sdvo *psb_intel_sdvo,
                psb_intel_sdvo_connector->top_margin = data_value[0] - response;
                psb_intel_sdvo_connector->bottom_margin = psb_intel_sdvo_connector->top_margin;
                psb_intel_sdvo_connector->top =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "top_margin", 2);
+                       drm_property_create_range(dev, 0, "top_margin", 0, data_value[0]);
                if (!psb_intel_sdvo_connector->top)
                        return false;
 
-               psb_intel_sdvo_connector->top->values[0] = 0;
-               psb_intel_sdvo_connector->top->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              psb_intel_sdvo_connector->top,
                                              psb_intel_sdvo_connector->top_margin);
 
                psb_intel_sdvo_connector->bottom =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "bottom_margin", 2);
+                       drm_property_create_range(dev, 0, "bottom_margin", 0, data_value[0]);
                if (!psb_intel_sdvo_connector->bottom)
                        return false;
 
-               psb_intel_sdvo_connector->bottom->values[0] = 0;
-               psb_intel_sdvo_connector->bottom->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              psb_intel_sdvo_connector->bottom,
                                              psb_intel_sdvo_connector->bottom_margin);
@@ -2438,12 +2424,10 @@ psb_intel_sdvo_create_enhance_property_tv(struct psb_intel_sdvo *psb_intel_sdvo,
                psb_intel_sdvo_connector->max_dot_crawl = 1;
                psb_intel_sdvo_connector->cur_dot_crawl = response & 0x1;
                psb_intel_sdvo_connector->dot_crawl =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE, "dot_crawl", 2);
+                       drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
                if (!psb_intel_sdvo_connector->dot_crawl)
                        return false;
 
-               psb_intel_sdvo_connector->dot_crawl->values[0] = 0;
-               psb_intel_sdvo_connector->dot_crawl->values[1] = 1;
                drm_connector_attach_property(connector,
                                              psb_intel_sdvo_connector->dot_crawl,
                                              psb_intel_sdvo_connector->cur_dot_crawl);
index 07d55df6623e2db921dc337003f9406af7e5e7c8..d3f2e87850107130e20561b2951bdf86e8aa35fc 100644 (file)
@@ -252,10 +252,7 @@ static int ch7006_encoder_create_resources(struct drm_encoder *encoder,
 
        drm_mode_create_tv_properties(dev, NUM_TV_NORMS, ch7006_tv_norm_names);
 
-       priv->scale_property = drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                                  "scale", 2);
-       priv->scale_property->values[0] = 0;
-       priv->scale_property->values[1] = 2;
+       priv->scale_property = drm_property_create_range(dev, 0, "scale", 0, 2);
 
        drm_connector_attach_property(connector, conf->tv_select_subconnector_property,
                                      priv->select_subconnector);
index e334ec33a47d4eb0cbd731c0c834de6c2102c458..80acc3f241efb997b1f785a81fa8054a25584fb1 100644 (file)
@@ -2277,10 +2277,8 @@ static bool intel_sdvo_tv_create_property(struct intel_sdvo *intel_sdvo,
                intel_sdvo_connector->max_##name = data_value[0]; \
                intel_sdvo_connector->cur_##name = response; \
                intel_sdvo_connector->name = \
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE, #name, 2); \
+                       drm_property_create_range(dev, 0, #name, 0, data_value[0]); \
                if (!intel_sdvo_connector->name) return false; \
-               intel_sdvo_connector->name->values[0] = 0; \
-               intel_sdvo_connector->name->values[1] = data_value[0]; \
                drm_connector_attach_property(connector, \
                                              intel_sdvo_connector->name, \
                                              intel_sdvo_connector->cur_##name); \
@@ -2314,25 +2312,19 @@ intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
                intel_sdvo_connector->left_margin = data_value[0] - response;
                intel_sdvo_connector->right_margin = intel_sdvo_connector->left_margin;
                intel_sdvo_connector->left =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "left_margin", 2);
+                       drm_property_create_range(dev, 0, "left_margin", 0, data_value[0]);
                if (!intel_sdvo_connector->left)
                        return false;
 
-               intel_sdvo_connector->left->values[0] = 0;
-               intel_sdvo_connector->left->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              intel_sdvo_connector->left,
                                              intel_sdvo_connector->left_margin);
 
                intel_sdvo_connector->right =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "right_margin", 2);
+                       drm_property_create_range(dev, 0, "right_margin", 0, data_value[0]);
                if (!intel_sdvo_connector->right)
                        return false;
 
-               intel_sdvo_connector->right->values[0] = 0;
-               intel_sdvo_connector->right->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              intel_sdvo_connector->right,
                                              intel_sdvo_connector->right_margin);
@@ -2356,25 +2348,21 @@ intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
                intel_sdvo_connector->top_margin = data_value[0] - response;
                intel_sdvo_connector->bottom_margin = intel_sdvo_connector->top_margin;
                intel_sdvo_connector->top =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "top_margin", 2);
+                       drm_property_create_range(dev, 0,
+                                           "top_margin", 0, data_value[0]);
                if (!intel_sdvo_connector->top)
                        return false;
 
-               intel_sdvo_connector->top->values[0] = 0;
-               intel_sdvo_connector->top->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              intel_sdvo_connector->top,
                                              intel_sdvo_connector->top_margin);
 
                intel_sdvo_connector->bottom =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                           "bottom_margin", 2);
+                       drm_property_create_range(dev, 0,
+                                           "bottom_margin", 0, data_value[0]);
                if (!intel_sdvo_connector->bottom)
                        return false;
 
-               intel_sdvo_connector->bottom->values[0] = 0;
-               intel_sdvo_connector->bottom->values[1] = data_value[0];
                drm_connector_attach_property(connector,
                                              intel_sdvo_connector->bottom,
                                              intel_sdvo_connector->bottom_margin);
@@ -2403,12 +2391,10 @@ intel_sdvo_create_enhance_property_tv(struct intel_sdvo *intel_sdvo,
                intel_sdvo_connector->max_dot_crawl = 1;
                intel_sdvo_connector->cur_dot_crawl = response & 0x1;
                intel_sdvo_connector->dot_crawl =
-                       drm_property_create(dev, DRM_MODE_PROP_RANGE, "dot_crawl", 2);
+                       drm_property_create_range(dev, 0, "dot_crawl", 0, 1);
                if (!intel_sdvo_connector->dot_crawl)
                        return false;
 
-               intel_sdvo_connector->dot_crawl->values[0] = 0;
-               intel_sdvo_connector->dot_crawl->values[1] = 1;
                drm_connector_attach_property(connector,
                                              intel_sdvo_connector->dot_crawl,
                                              intel_sdvo_connector->cur_dot_crawl);
index cc94f3cbd5af0b27b6021568c7d94b7e0b195077..5565e5056ba17cc53c3ed18dfd38b03ac0994a84 100644 (file)
@@ -281,16 +281,10 @@ nouveau_display_create(struct drm_device *dev)
        PROP_ENUM(disp->underscan_property, gen, "underscan", underscan);
 
        disp->underscan_hborder_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "underscan hborder", 2);
-       disp->underscan_hborder_property->values[0] = 0;
-       disp->underscan_hborder_property->values[1] = 128;
+               drm_property_create_range(dev, 0, "underscan hborder", 0, 128);
 
        disp->underscan_vborder_property =
-               drm_property_create(dev, DRM_MODE_PROP_RANGE,
-                                   "underscan vborder", 2);
-       disp->underscan_vborder_property->values[0] = 0;
-       disp->underscan_vborder_property->values[1] = 128;
+               drm_property_create_range(dev, 0, "underscan vborder", 0, 128);
 
        dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
        dev->mode_config.fb_base = pci_resource_start(dev->pdev, 1);
index 54629faf28468cdc5f2113a6584269ae31b6e1ba..5515f1054b29331324bdc15c2b27d4ea6c82fe0a 100644 (file)
@@ -1152,14 +1152,9 @@ static int radeon_modeset_create_props(struct radeon_device *rdev)
 
        if (rdev->is_atom_bios) {
                rdev->mode_info.coherent_mode_property =
-                       drm_property_create(rdev->ddev,
-                                           DRM_MODE_PROP_RANGE,
-                                           "coherent", 2);
+                       drm_property_create_range(rdev->ddev, 0 , "coherent", 0, 1);
                if (!rdev->mode_info.coherent_mode_property)
                        return -ENOMEM;
-
-               rdev->mode_info.coherent_mode_property->values[0] = 0;
-               rdev->mode_info.coherent_mode_property->values[1] = 1;
        }
 
        if (!ASIC_IS_AVIVO(rdev)) {
@@ -1171,13 +1166,9 @@ static int radeon_modeset_create_props(struct radeon_device *rdev)
        }
 
        rdev->mode_info.load_detect_property =
-               drm_property_create(rdev->ddev,
-                                   DRM_MODE_PROP_RANGE,
-                                   "load detection", 2);
+               drm_property_create_range(rdev->ddev, 0, "load detection", 0, 1);
        if (!rdev->mode_info.load_detect_property)
                return -ENOMEM;
-       rdev->mode_info.load_detect_property->values[0] = 0;
-       rdev->mode_info.load_detect_property->values[1] = 1;
 
        drm_mode_create_scaling_mode_property(rdev->ddev);
 
@@ -1194,22 +1185,16 @@ static int radeon_modeset_create_props(struct radeon_device *rdev)
                                    radeon_underscan_enum_list, sz);
 
        rdev->mode_info.underscan_hborder_property =
-               drm_property_create(rdev->ddev,
-                                       DRM_MODE_PROP_RANGE,
-                                       "underscan hborder", 2);
+               drm_property_create_range(rdev->ddev, 0,
+                                       "underscan hborder", 0, 128);
        if (!rdev->mode_info.underscan_hborder_property)
                return -ENOMEM;
-       rdev->mode_info.underscan_hborder_property->values[0] = 0;
-       rdev->mode_info.underscan_hborder_property->values[1] = 128;
 
        rdev->mode_info.underscan_vborder_property =
-               drm_property_create(rdev->ddev,
-                                       DRM_MODE_PROP_RANGE,
-                                       "underscan vborder", 2);
+               drm_property_create_range(rdev->ddev, 0,
+                                       "underscan vborder", 0, 128);
        if (!rdev->mode_info.underscan_vborder_property)
                return -ENOMEM;
-       rdev->mode_info.underscan_vborder_property->values[0] = 0;
-       rdev->mode_info.underscan_vborder_property->values[1] = 128;
 
        return 0;
 }
index 3b93cdccea498d646ba842fa9e3bb60151e6ba31..823531454799a3ea54bc81bb37cc45d8e5bf9906 100644 (file)
@@ -912,6 +912,9 @@ extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int
                                         const char *name,
                                         const struct drm_prop_enum_list *props,
                                         int num_values);
+struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
+                                        const char *name,
+                                        uint64_t min, uint64_t max);
 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
 extern int drm_property_add_enum(struct drm_property *property, int index,
                                 uint64_t value, const char *name);