drm/i915: base gmbus pin validity check on the gmbus pin map array
authorJani Nikula <jani.nikula@intel.com>
Thu, 26 Mar 2015 22:20:22 +0000 (00:20 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 1 Apr 2015 12:11:56 +0000 (14:11 +0200)
This will be helpful for adding future platforms. It is better to keep
the information in the single point of truth (the table) instead of
duplicating it into the validity function.

While at it, add dev_priv parameter to the function, also to prepare for
adding future platform support.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/intel_bios.c
drivers/gpu/drm/i915/intel_dvo.c
drivers/gpu/drm/i915/intel_i2c.c
drivers/gpu/drm/i915/intel_lvds.c
drivers/gpu/drm/i915/intel_sdvo.c

index 0ad11d9c123fc8bc00e28ccc6e9cfde57f492413..d63997bc80e4a7a1a7b087abb0e8c8d019a03572 100644 (file)
@@ -3064,10 +3064,8 @@ void i915_teardown_sysfs(struct drm_device *dev_priv);
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
-static inline bool intel_gmbus_is_valid_pin(unsigned int pin)
-{
-       return (pin >= GMBUS_PIN_SSC && pin <= GMBUS_PIN_DPD);
-}
+extern bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv,
+                                    unsigned int pin);
 
 extern struct i2c_adapter *
 intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, unsigned int pin);
index 333f4079343528d81ce34d06b774f6d0a6faadcc..ad2f3b0d922f11e66918b4c54ca34eb4fc63e319 100644 (file)
@@ -438,7 +438,7 @@ parse_general_definitions(struct drm_i915_private *dev_priv,
                if (block_size >= sizeof(*general)) {
                        int bus_pin = general->crt_ddc_gmbus_pin;
                        DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
-                       if (intel_gmbus_is_valid_pin(bus_pin))
+                       if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
                                dev_priv->vbt.crt_ddc_pin = bus_pin;
                } else {
                        DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
index bfedea3826d76322d308a3756cb9736123fcd3c1..9a27ec7100efa0a7902b6c9e52ae2f955db14949 100644 (file)
@@ -502,7 +502,7 @@ void intel_dvo_init(struct drm_device *dev)
                 * special cases, but otherwise default to what's defined
                 * in the spec.
                 */
-               if (intel_gmbus_is_valid_pin(dvo->gpio))
+               if (intel_gmbus_is_valid_pin(dev_priv, dvo->gpio))
                        gpio = dvo->gpio;
                else if (dvo->type == INTEL_DVO_CHIP_LVDS)
                        gpio = GMBUS_PIN_SSC;
index ff47a8fdcb6d9a3562b42d99a7ec537774419c72..ec9cc8cf642e623e82ee21bd83f13176eb7be8d5 100644 (file)
@@ -49,6 +49,12 @@ static const struct gmbus_pin gmbus_pins[] = {
        [GMBUS_PIN_DPD] = { "dpd", GPIOF },
 };
 
+bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv,
+                             unsigned int pin)
+{
+       return pin < ARRAY_SIZE(gmbus_pins) && gmbus_pins[pin].reg;
+}
+
 /* Intel GPIO access functions */
 
 #define I2C_RISEFALL_TIME 10
@@ -534,7 +540,7 @@ int intel_setup_gmbus(struct drm_device *dev)
        init_waitqueue_head(&dev_priv->gmbus_wait_queue);
 
        for (pin = 0; pin < ARRAY_SIZE(dev_priv->gmbus); pin++) {
-               if (!intel_gmbus_is_valid_pin(pin))
+               if (!intel_gmbus_is_valid_pin(dev_priv, pin))
                        continue;
 
                bus = &dev_priv->gmbus[pin];
@@ -571,7 +577,7 @@ int intel_setup_gmbus(struct drm_device *dev)
 
 err:
        while (--pin) {
-               if (!intel_gmbus_is_valid_pin(pin))
+               if (!intel_gmbus_is_valid_pin(dev_priv, pin))
                        continue;
 
                bus = &dev_priv->gmbus[pin];
@@ -583,7 +589,7 @@ err:
 struct i2c_adapter *intel_gmbus_get_adapter(struct drm_i915_private *dev_priv,
                                            unsigned int pin)
 {
-       if (WARN_ON(!intel_gmbus_is_valid_pin(pin)))
+       if (WARN_ON(!intel_gmbus_is_valid_pin(dev_priv, pin)))
                return NULL;
 
        return &dev_priv->gmbus[pin].adapter;
@@ -613,7 +619,7 @@ void intel_teardown_gmbus(struct drm_device *dev)
        unsigned int pin;
 
        for (pin = 0; pin < ARRAY_SIZE(dev_priv->gmbus); pin++) {
-               if (!intel_gmbus_is_valid_pin(pin))
+               if (!intel_gmbus_is_valid_pin(dev_priv, pin))
                        continue;
 
                bus = &dev_priv->gmbus[pin];
index d61aa78ed7e3bc35b6b61ac1b3b0710d3be00ea4..314a5d56ace25cd727b5f90214390974a3268095 100644 (file)
@@ -781,7 +781,7 @@ static bool lvds_is_present_in_vbt(struct drm_device *dev,
                    child->device_type != DEVICE_TYPE_LFP)
                        continue;
 
-               if (intel_gmbus_is_valid_pin(child->i2c_pin))
+               if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
                        *i2c_pin = child->i2c_pin;
 
                /* However, we cannot trust the BIOS writers to populate
index 124992e48abd395f276c1ddc671efde67a7dc8cb..b121796c86aa91e9ad1439a95f12cbbaff091ae9 100644 (file)
@@ -2291,7 +2291,8 @@ intel_sdvo_select_i2c_bus(struct drm_i915_private *dev_priv,
        else
                mapping = &dev_priv->sdvo_mappings[1];
 
-       if (mapping->initialized && intel_gmbus_is_valid_pin(mapping->i2c_pin))
+       if (mapping->initialized &&
+           intel_gmbus_is_valid_pin(dev_priv, mapping->i2c_pin))
                pin = mapping->i2c_pin;
        else
                pin = GMBUS_PIN_DPB;