aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-02-06 04:58:17 -0500
committerDave Airlie <airlied@redhat.com>2012-02-09 05:15:18 -0500
commit4a67d39190315558631d944b1cea4466ed4c86d8 (patch)
tree1d90ec7e35c2f6048bf38ba3dfcb838d9df52a16 /drivers/gpu
parent198ceac091049003ffcc4b7cda76785510fc3b59 (diff)
drm: add convenience function to create an enum property
Creating an enum 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>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/drm_crtc.c100
-rw-r--r--drivers/gpu/drm/i915/intel_modes.c28
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_display.c10
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c43
4 files changed, 72 insertions, 109 deletions
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 322bc7b13004..3fe99c456a19 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -38,11 +38,6 @@
38#include "drm_edid.h" 38#include "drm_edid.h"
39#include "drm_fourcc.h" 39#include "drm_fourcc.h"
40 40
41struct drm_prop_enum_list {
42 int type;
43 char *name;
44};
45
46/* Avoid boilerplate. I'm tired of typing. */ 41/* Avoid boilerplate. I'm tired of typing. */
47#define DRM_ENUM_NAME_FN(fnname, list) \ 42#define DRM_ENUM_NAME_FN(fnname, list) \
48 char *fnname(int val) \ 43 char *fnname(int val) \
@@ -658,7 +653,6 @@ static int drm_mode_create_standard_connector_properties(struct drm_device *dev)
658{ 653{
659 struct drm_property *edid; 654 struct drm_property *edid;
660 struct drm_property *dpms; 655 struct drm_property *dpms;
661 int i;
662 656
663 /* 657 /*
664 * Standard properties (apply to all connectors) 658 * Standard properties (apply to all connectors)
@@ -668,11 +662,9 @@ static int drm_mode_create_standard_connector_properties(struct drm_device *dev)
668 "EDID", 0); 662 "EDID", 0);
669 dev->mode_config.edid_property = edid; 663 dev->mode_config.edid_property = edid;
670 664
671 dpms = drm_property_create(dev, DRM_MODE_PROP_ENUM, 665 dpms = drm_property_create_enum(dev, 0,
672 "DPMS", ARRAY_SIZE(drm_dpms_enum_list)); 666 "DPMS", drm_dpms_enum_list,
673 for (i = 0; i < ARRAY_SIZE(drm_dpms_enum_list); i++) 667 ARRAY_SIZE(drm_dpms_enum_list));
674 drm_property_add_enum(dpms, i, drm_dpms_enum_list[i].type,
675 drm_dpms_enum_list[i].name);
676 dev->mode_config.dpms_property = dpms; 668 dev->mode_config.dpms_property = dpms;
677 669
678 return 0; 670 return 0;
@@ -688,30 +680,21 @@ int drm_mode_create_dvi_i_properties(struct drm_device *dev)
688{ 680{
689 struct drm_property *dvi_i_selector; 681 struct drm_property *dvi_i_selector;
690 struct drm_property *dvi_i_subconnector; 682 struct drm_property *dvi_i_subconnector;
691 int i;
692 683
693 if (dev->mode_config.dvi_i_select_subconnector_property) 684 if (dev->mode_config.dvi_i_select_subconnector_property)
694 return 0; 685 return 0;
695 686
696 dvi_i_selector = 687 dvi_i_selector =
697 drm_property_create(dev, DRM_MODE_PROP_ENUM, 688 drm_property_create_enum(dev, 0,
698 "select subconnector", 689 "select subconnector",
690 drm_dvi_i_select_enum_list,
699 ARRAY_SIZE(drm_dvi_i_select_enum_list)); 691 ARRAY_SIZE(drm_dvi_i_select_enum_list));
700 for (i = 0; i < ARRAY_SIZE(drm_dvi_i_select_enum_list); i++)
701 drm_property_add_enum(dvi_i_selector, i,
702 drm_dvi_i_select_enum_list[i].type,
703 drm_dvi_i_select_enum_list[i].name);
704 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; 692 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
705 693
706 dvi_i_subconnector = 694 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
707 drm_property_create(dev, DRM_MODE_PROP_ENUM |
708 DRM_MODE_PROP_IMMUTABLE,
709 "subconnector", 695 "subconnector",
696 drm_dvi_i_subconnector_enum_list,
710 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); 697 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
711 for (i = 0; i < ARRAY_SIZE(drm_dvi_i_subconnector_enum_list); i++)
712 drm_property_add_enum(dvi_i_subconnector, i,
713 drm_dvi_i_subconnector_enum_list[i].type,
714 drm_dvi_i_subconnector_enum_list[i].name);
715 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; 698 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
716 699
717 return 0; 700 return 0;
@@ -742,23 +725,17 @@ int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
742 /* 725 /*
743 * Basic connector properties 726 * Basic connector properties
744 */ 727 */
745 tv_selector = drm_property_create(dev, DRM_MODE_PROP_ENUM, 728 tv_selector = drm_property_create_enum(dev, 0,
746 "select subconnector", 729 "select subconnector",
730 drm_tv_select_enum_list,
747 ARRAY_SIZE(drm_tv_select_enum_list)); 731 ARRAY_SIZE(drm_tv_select_enum_list));
748 for (i = 0; i < ARRAY_SIZE(drm_tv_select_enum_list); i++)
749 drm_property_add_enum(tv_selector, i,
750 drm_tv_select_enum_list[i].type,
751 drm_tv_select_enum_list[i].name);
752 dev->mode_config.tv_select_subconnector_property = tv_selector; 732 dev->mode_config.tv_select_subconnector_property = tv_selector;
753 733
754 tv_subconnector = 734 tv_subconnector =
755 drm_property_create(dev, DRM_MODE_PROP_ENUM | 735 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
756 DRM_MODE_PROP_IMMUTABLE, "subconnector", 736 "subconnector",
737 drm_tv_subconnector_enum_list,
757 ARRAY_SIZE(drm_tv_subconnector_enum_list)); 738 ARRAY_SIZE(drm_tv_subconnector_enum_list));
758 for (i = 0; i < ARRAY_SIZE(drm_tv_subconnector_enum_list); i++)
759 drm_property_add_enum(tv_subconnector, i,
760 drm_tv_subconnector_enum_list[i].type,
761 drm_tv_subconnector_enum_list[i].name);
762 dev->mode_config.tv_subconnector_property = tv_subconnector; 739 dev->mode_config.tv_subconnector_property = tv_subconnector;
763 740
764 /* 741 /*
@@ -845,18 +822,14 @@ EXPORT_SYMBOL(drm_mode_create_tv_properties);
845int drm_mode_create_scaling_mode_property(struct drm_device *dev) 822int drm_mode_create_scaling_mode_property(struct drm_device *dev)
846{ 823{
847 struct drm_property *scaling_mode; 824 struct drm_property *scaling_mode;
848 int i;
849 825
850 if (dev->mode_config.scaling_mode_property) 826 if (dev->mode_config.scaling_mode_property)
851 return 0; 827 return 0;
852 828
853 scaling_mode = 829 scaling_mode =
854 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode", 830 drm_property_create_enum(dev, 0, "scaling mode",
831 drm_scaling_mode_enum_list,
855 ARRAY_SIZE(drm_scaling_mode_enum_list)); 832 ARRAY_SIZE(drm_scaling_mode_enum_list));
856 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++)
857 drm_property_add_enum(scaling_mode, i,
858 drm_scaling_mode_enum_list[i].type,
859 drm_scaling_mode_enum_list[i].name);
860 833
861 dev->mode_config.scaling_mode_property = scaling_mode; 834 dev->mode_config.scaling_mode_property = scaling_mode;
862 835
@@ -874,18 +847,14 @@ EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
874int drm_mode_create_dithering_property(struct drm_device *dev) 847int drm_mode_create_dithering_property(struct drm_device *dev)
875{ 848{
876 struct drm_property *dithering_mode; 849 struct drm_property *dithering_mode;
877 int i;
878 850
879 if (dev->mode_config.dithering_mode_property) 851 if (dev->mode_config.dithering_mode_property)
880 return 0; 852 return 0;
881 853
882 dithering_mode = 854 dithering_mode =
883 drm_property_create(dev, DRM_MODE_PROP_ENUM, "dithering", 855 drm_property_create_enum(dev, 0, "dithering",
856 drm_dithering_mode_enum_list,
884 ARRAY_SIZE(drm_dithering_mode_enum_list)); 857 ARRAY_SIZE(drm_dithering_mode_enum_list));
885 for (i = 0; i < ARRAY_SIZE(drm_dithering_mode_enum_list); i++)
886 drm_property_add_enum(dithering_mode, i,
887 drm_dithering_mode_enum_list[i].type,
888 drm_dithering_mode_enum_list[i].name);
889 dev->mode_config.dithering_mode_property = dithering_mode; 858 dev->mode_config.dithering_mode_property = dithering_mode;
890 859
891 return 0; 860 return 0;
@@ -902,20 +871,15 @@ EXPORT_SYMBOL(drm_mode_create_dithering_property);
902int drm_mode_create_dirty_info_property(struct drm_device *dev) 871int drm_mode_create_dirty_info_property(struct drm_device *dev)
903{ 872{
904 struct drm_property *dirty_info; 873 struct drm_property *dirty_info;
905 int i;
906 874
907 if (dev->mode_config.dirty_info_property) 875 if (dev->mode_config.dirty_info_property)
908 return 0; 876 return 0;
909 877
910 dirty_info = 878 dirty_info =
911 drm_property_create(dev, DRM_MODE_PROP_ENUM | 879 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
912 DRM_MODE_PROP_IMMUTABLE,
913 "dirty", 880 "dirty",
881 drm_dirty_info_enum_list,
914 ARRAY_SIZE(drm_dirty_info_enum_list)); 882 ARRAY_SIZE(drm_dirty_info_enum_list));
915 for (i = 0; i < ARRAY_SIZE(drm_dirty_info_enum_list); i++)
916 drm_property_add_enum(dirty_info, i,
917 drm_dirty_info_enum_list[i].type,
918 drm_dirty_info_enum_list[i].name);
919 dev->mode_config.dirty_info_property = dirty_info; 883 dev->mode_config.dirty_info_property = dirty_info;
920 884
921 return 0; 885 return 0;
@@ -2629,6 +2593,34 @@ fail:
2629} 2593}
2630EXPORT_SYMBOL(drm_property_create); 2594EXPORT_SYMBOL(drm_property_create);
2631 2595
2596struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2597 const char *name,
2598 const struct drm_prop_enum_list *props,
2599 int num_values)
2600{
2601 struct drm_property *property;
2602 int i, ret;
2603
2604 flags |= DRM_MODE_PROP_ENUM;
2605
2606 property = drm_property_create(dev, flags, name, num_values);
2607 if (!property)
2608 return NULL;
2609
2610 for (i = 0; i < num_values; i++) {
2611 ret = drm_property_add_enum(property, i,
2612 props[i].type,
2613 props[i].name);
2614 if (ret) {
2615 drm_property_destroy(dev, property);
2616 return NULL;
2617 }
2618 }
2619
2620 return property;
2621}
2622EXPORT_SYMBOL(drm_property_create_enum);
2623
2632int drm_property_add_enum(struct drm_property *property, int index, 2624int drm_property_add_enum(struct drm_property *property, int index,
2633 uint64_t value, const char *name) 2625 uint64_t value, const char *name)
2634{ 2626{
diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c
index be2c6fe07d12..961f75dbeae1 100644
--- a/drivers/gpu/drm/i915/intel_modes.c
+++ b/drivers/gpu/drm/i915/intel_modes.c
@@ -83,10 +83,10 @@ int intel_ddc_get_modes(struct drm_connector *connector,
83 return ret; 83 return ret;
84} 84}
85 85
86static const char *force_audio_names[] = { 86static const struct drm_prop_enum_list force_audio_names[] = {
87 "off", 87 { -1, "off" },
88 "auto", 88 { 0, "auto" },
89 "on", 89 { 1, "on" },
90}; 90};
91 91
92void 92void
@@ -95,27 +95,24 @@ intel_attach_force_audio_property(struct drm_connector *connector)
95 struct drm_device *dev = connector->dev; 95 struct drm_device *dev = connector->dev;
96 struct drm_i915_private *dev_priv = dev->dev_private; 96 struct drm_i915_private *dev_priv = dev->dev_private;
97 struct drm_property *prop; 97 struct drm_property *prop;
98 int i;
99 98
100 prop = dev_priv->force_audio_property; 99 prop = dev_priv->force_audio_property;
101 if (prop == NULL) { 100 if (prop == NULL) {
102 prop = drm_property_create(dev, DRM_MODE_PROP_ENUM, 101 prop = drm_property_create_enum(dev, 0,
103 "audio", 102 "audio",
103 force_audio_names,
104 ARRAY_SIZE(force_audio_names)); 104 ARRAY_SIZE(force_audio_names));
105 if (prop == NULL) 105 if (prop == NULL)
106 return; 106 return;
107 107
108 for (i = 0; i < ARRAY_SIZE(force_audio_names); i++)
109 drm_property_add_enum(prop, i, i-1, force_audio_names[i]);
110
111 dev_priv->force_audio_property = prop; 108 dev_priv->force_audio_property = prop;
112 } 109 }
113 drm_connector_attach_property(connector, prop, 0); 110 drm_connector_attach_property(connector, prop, 0);
114} 111}
115 112
116static const char *broadcast_rgb_names[] = { 113static const struct drm_prop_enum_list broadcast_rgb_names[] = {
117 "Full", 114 { 0, "Full" },
118 "Limited 16:235", 115 { 1, "Limited 16:235" },
119}; 116};
120 117
121void 118void
@@ -124,19 +121,16 @@ intel_attach_broadcast_rgb_property(struct drm_connector *connector)
124 struct drm_device *dev = connector->dev; 121 struct drm_device *dev = connector->dev;
125 struct drm_i915_private *dev_priv = dev->dev_private; 122 struct drm_i915_private *dev_priv = dev->dev_private;
126 struct drm_property *prop; 123 struct drm_property *prop;
127 int i;
128 124
129 prop = dev_priv->broadcast_rgb_property; 125 prop = dev_priv->broadcast_rgb_property;
130 if (prop == NULL) { 126 if (prop == NULL) {
131 prop = drm_property_create(dev, DRM_MODE_PROP_ENUM, 127 prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
132 "Broadcast RGB", 128 "Broadcast RGB",
129 broadcast_rgb_names,
133 ARRAY_SIZE(broadcast_rgb_names)); 130 ARRAY_SIZE(broadcast_rgb_names));
134 if (prop == NULL) 131 if (prop == NULL)
135 return; 132 return;
136 133
137 for (i = 0; i < ARRAY_SIZE(broadcast_rgb_names); i++)
138 drm_property_add_enum(prop, i, i, broadcast_rgb_names[i]);
139
140 dev_priv->broadcast_rgb_property = prop; 134 dev_priv->broadcast_rgb_property = prop;
141 } 135 }
142 136
diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c
index 795a9e3c990a..cc94f3cbd5af 100644
--- a/drivers/gpu/drm/nouveau/nouveau_display.c
+++ b/drivers/gpu/drm/nouveau/nouveau_display.c
@@ -155,20 +155,20 @@ static const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
155}; 155};
156 156
157 157
158struct drm_prop_enum_list { 158struct nouveau_drm_prop_enum_list {
159 u8 gen_mask; 159 u8 gen_mask;
160 int type; 160 int type;
161 char *name; 161 char *name;
162}; 162};
163 163
164static struct drm_prop_enum_list underscan[] = { 164static struct nouveau_drm_prop_enum_list underscan[] = {
165 { 6, UNDERSCAN_AUTO, "auto" }, 165 { 6, UNDERSCAN_AUTO, "auto" },
166 { 6, UNDERSCAN_OFF, "off" }, 166 { 6, UNDERSCAN_OFF, "off" },
167 { 6, UNDERSCAN_ON, "on" }, 167 { 6, UNDERSCAN_ON, "on" },
168 {} 168 {}
169}; 169};
170 170
171static struct drm_prop_enum_list dither_mode[] = { 171static struct nouveau_drm_prop_enum_list dither_mode[] = {
172 { 7, DITHERING_MODE_AUTO, "auto" }, 172 { 7, DITHERING_MODE_AUTO, "auto" },
173 { 7, DITHERING_MODE_OFF, "off" }, 173 { 7, DITHERING_MODE_OFF, "off" },
174 { 1, DITHERING_MODE_ON, "on" }, 174 { 1, DITHERING_MODE_ON, "on" },
@@ -178,7 +178,7 @@ static struct drm_prop_enum_list dither_mode[] = {
178 {} 178 {}
179}; 179};
180 180
181static struct drm_prop_enum_list dither_depth[] = { 181static struct nouveau_drm_prop_enum_list dither_depth[] = {
182 { 6, DITHERING_DEPTH_AUTO, "auto" }, 182 { 6, DITHERING_DEPTH_AUTO, "auto" },
183 { 6, DITHERING_DEPTH_6BPC, "6 bpc" }, 183 { 6, DITHERING_DEPTH_6BPC, "6 bpc" },
184 { 6, DITHERING_DEPTH_8BPC, "8 bpc" }, 184 { 6, DITHERING_DEPTH_8BPC, "8 bpc" },
@@ -186,7 +186,7 @@ static struct drm_prop_enum_list dither_depth[] = {
186}; 186};
187 187
188#define PROP_ENUM(p,gen,n,list) do { \ 188#define PROP_ENUM(p,gen,n,list) do { \
189 struct drm_prop_enum_list *l = (list); \ 189 struct nouveau_drm_prop_enum_list *l = (list); \
190 int c = 0; \ 190 int c = 0; \
191 while (l->gen_mask) { \ 191 while (l->gen_mask) { \
192 if (l->gen_mask & (1 << (gen))) \ 192 if (l->gen_mask & (1 << (gen))) \
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 8c49fef1ce78..54629faf2846 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -1124,11 +1124,6 @@ static const struct drm_mode_config_funcs radeon_mode_funcs = {
1124 .output_poll_changed = radeon_output_poll_changed 1124 .output_poll_changed = radeon_output_poll_changed
1125}; 1125};
1126 1126
1127struct drm_prop_enum_list {
1128 int type;
1129 char *name;
1130};
1131
1132static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] = 1127static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] =
1133{ { 0, "driver" }, 1128{ { 0, "driver" },
1134 { 1, "bios" }, 1129 { 1, "bios" },
@@ -1153,7 +1148,7 @@ static struct drm_prop_enum_list radeon_underscan_enum_list[] =
1153 1148
1154static int radeon_modeset_create_props(struct radeon_device *rdev) 1149static int radeon_modeset_create_props(struct radeon_device *rdev)
1155{ 1150{
1156 int i, sz; 1151 int sz;
1157 1152
1158 if (rdev->is_atom_bios) { 1153 if (rdev->is_atom_bios) {
1159 rdev->mode_info.coherent_mode_property = 1154 rdev->mode_info.coherent_mode_property =
@@ -1170,15 +1165,9 @@ static int radeon_modeset_create_props(struct radeon_device *rdev)
1170 if (!ASIC_IS_AVIVO(rdev)) { 1165 if (!ASIC_IS_AVIVO(rdev)) {
1171 sz = ARRAY_SIZE(radeon_tmds_pll_enum_list); 1166 sz = ARRAY_SIZE(radeon_tmds_pll_enum_list);
1172 rdev->mode_info.tmds_pll_property = 1167 rdev->mode_info.tmds_pll_property =
1173 drm_property_create(rdev->ddev, 1168 drm_property_create_enum(rdev->ddev, 0,
1174 DRM_MODE_PROP_ENUM, 1169 "tmds_pll",
1175 "tmds_pll", sz); 1170 radeon_tmds_pll_enum_list, sz);
1176 for (i = 0; i < sz; i++) {
1177 drm_property_add_enum(rdev->mode_info.tmds_pll_property,
1178 i,
1179 radeon_tmds_pll_enum_list[i].type,
1180 radeon_tmds_pll_enum_list[i].name);
1181 }
1182 } 1171 }
1183 1172
1184 rdev->mode_info.load_detect_property = 1173 rdev->mode_info.load_detect_property =
@@ -1194,27 +1183,15 @@ static int radeon_modeset_create_props(struct radeon_device *rdev)
1194 1183
1195 sz = ARRAY_SIZE(radeon_tv_std_enum_list); 1184 sz = ARRAY_SIZE(radeon_tv_std_enum_list);
1196 rdev->mode_info.tv_std_property = 1185 rdev->mode_info.tv_std_property =
1197 drm_property_create(rdev->ddev, 1186 drm_property_create_enum(rdev->ddev, 0,
1198 DRM_MODE_PROP_ENUM, 1187 "tv standard",
1199 "tv standard", sz); 1188 radeon_tv_std_enum_list, sz);
1200 for (i = 0; i < sz; i++) {
1201 drm_property_add_enum(rdev->mode_info.tv_std_property,
1202 i,
1203 radeon_tv_std_enum_list[i].type,
1204 radeon_tv_std_enum_list[i].name);
1205 }
1206 1189
1207 sz = ARRAY_SIZE(radeon_underscan_enum_list); 1190 sz = ARRAY_SIZE(radeon_underscan_enum_list);
1208 rdev->mode_info.underscan_property = 1191 rdev->mode_info.underscan_property =
1209 drm_property_create(rdev->ddev, 1192 drm_property_create_enum(rdev->ddev, 0,
1210 DRM_MODE_PROP_ENUM, 1193 "underscan",
1211 "underscan", sz); 1194 radeon_underscan_enum_list, sz);
1212 for (i = 0; i < sz; i++) {
1213 drm_property_add_enum(rdev->mode_info.underscan_property,
1214 i,
1215 radeon_underscan_enum_list[i].type,
1216 radeon_underscan_enum_list[i].name);
1217 }
1218 1195
1219 rdev->mode_info.underscan_hborder_property = 1196 rdev->mode_info.underscan_hborder_property =
1220 drm_property_create(rdev->ddev, 1197 drm_property_create(rdev->ddev,