diff options
author | Jean Delvare <khali@linux-fr.org> | 2012-10-05 16:23:54 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2012-10-05 16:23:54 -0400 |
commit | f82b86267a7a7cc2fc9779fa2957467c242395d8 (patch) | |
tree | 3c25536f8e63fdfd8532ec9b82245d0d44e4bcef | |
parent | 600a711cfeb10769e386c4ce7d39e9f0cc4b471a (diff) |
i2c-i801: Let i2c-mux-gpio find the GPIO chip
Now that i2c-mux-gpio is able to find the GPIO chip by itself, we can
delegate this task. The great thing here is that i2c-mux-gpio can
defer device probing until the gpio chip is available, so we no longer
depend on the module loading order.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r-- | drivers/i2c/busses/i2c-i801.c | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c index bb1d7291cf21..37793156bd93 100644 --- a/drivers/i2c/busses/i2c-i801.c +++ b/drivers/i2c/busses/i2c-i801.c | |||
@@ -194,7 +194,6 @@ struct i801_priv { | |||
194 | 194 | ||
195 | #if defined CONFIG_I2C_MUX || defined CONFIG_I2C_MUX_MODULE | 195 | #if defined CONFIG_I2C_MUX || defined CONFIG_I2C_MUX_MODULE |
196 | const struct i801_mux_config *mux_drvdata; | 196 | const struct i801_mux_config *mux_drvdata; |
197 | unsigned mux_priv[2]; | ||
198 | struct platform_device *mux_pdev; | 197 | struct platform_device *mux_pdev; |
199 | #endif | 198 | #endif |
200 | }; | 199 | }; |
@@ -1008,60 +1007,32 @@ static struct dmi_system_id __devinitdata mux_dmi_table[] = { | |||
1008 | { } | 1007 | { } |
1009 | }; | 1008 | }; |
1010 | 1009 | ||
1011 | static int __devinit match_gpio_chip_by_label(struct gpio_chip *chip, | ||
1012 | void *data) | ||
1013 | { | ||
1014 | return !strcmp(chip->label, data); | ||
1015 | } | ||
1016 | |||
1017 | /* Setup multiplexing if needed */ | 1010 | /* Setup multiplexing if needed */ |
1018 | static int __devinit i801_add_mux(struct i801_priv *priv) | 1011 | static int __devinit i801_add_mux(struct i801_priv *priv) |
1019 | { | 1012 | { |
1020 | struct device *dev = &priv->adapter.dev; | 1013 | struct device *dev = &priv->adapter.dev; |
1021 | const struct i801_mux_config *mux_config; | 1014 | const struct i801_mux_config *mux_config; |
1022 | struct gpio_chip *gpio; | ||
1023 | struct i2c_mux_gpio_platform_data gpio_data; | 1015 | struct i2c_mux_gpio_platform_data gpio_data; |
1024 | int i, err; | 1016 | int err; |
1025 | 1017 | ||
1026 | if (!priv->mux_drvdata) | 1018 | if (!priv->mux_drvdata) |
1027 | return 0; | 1019 | return 0; |
1028 | mux_config = priv->mux_drvdata; | 1020 | mux_config = priv->mux_drvdata; |
1029 | 1021 | ||
1030 | /* Find GPIO chip */ | ||
1031 | gpio = gpiochip_find(mux_config->gpio_chip, match_gpio_chip_by_label); | ||
1032 | if (gpio) { | ||
1033 | dev_info(dev, | ||
1034 | "GPIO chip %s found, SMBus multiplexing enabled\n", | ||
1035 | mux_config->gpio_chip); | ||
1036 | } else { | ||
1037 | dev_err(dev, | ||
1038 | "GPIO chip %s not found, SMBus multiplexing disabled\n", | ||
1039 | mux_config->gpio_chip); | ||
1040 | return -ENODEV; | ||
1041 | } | ||
1042 | |||
1043 | /* Find absolute GPIO pin numbers */ | ||
1044 | if (ARRAY_SIZE(priv->mux_priv) < mux_config->n_gpios) { | ||
1045 | dev_err(dev, "i801_priv.mux_priv too small (%zu, need %d)\n", | ||
1046 | ARRAY_SIZE(priv->mux_priv), mux_config->n_gpios); | ||
1047 | return -ENODEV; | ||
1048 | } | ||
1049 | for (i = 0; i < mux_config->n_gpios; i++) | ||
1050 | priv->mux_priv[i] = gpio->base + mux_config->gpios[i]; | ||
1051 | |||
1052 | /* Prepare the platform data */ | 1022 | /* Prepare the platform data */ |
1053 | memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data)); | 1023 | memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data)); |
1054 | gpio_data.parent = priv->adapter.nr; | 1024 | gpio_data.parent = priv->adapter.nr; |
1055 | gpio_data.values = mux_config->values; | 1025 | gpio_data.values = mux_config->values; |
1056 | gpio_data.n_values = mux_config->n_values; | 1026 | gpio_data.n_values = mux_config->n_values; |
1057 | gpio_data.classes = mux_config->classes; | 1027 | gpio_data.classes = mux_config->classes; |
1058 | gpio_data.gpios = priv->mux_priv; | 1028 | gpio_data.gpio_chip = mux_config->gpio_chip; |
1029 | gpio_data.gpios = mux_config->gpios; | ||
1059 | gpio_data.n_gpios = mux_config->n_gpios; | 1030 | gpio_data.n_gpios = mux_config->n_gpios; |
1060 | gpio_data.idle = I2C_MUX_GPIO_NO_IDLE; | 1031 | gpio_data.idle = I2C_MUX_GPIO_NO_IDLE; |
1061 | 1032 | ||
1062 | /* Register the mux device */ | 1033 | /* Register the mux device */ |
1063 | priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio", | 1034 | priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio", |
1064 | priv->mux_priv[0], &gpio_data, | 1035 | PLATFORM_DEVID_AUTO, &gpio_data, |
1065 | sizeof(struct i2c_mux_gpio_platform_data)); | 1036 | sizeof(struct i2c_mux_gpio_platform_data)); |
1066 | if (IS_ERR(priv->mux_pdev)) { | 1037 | if (IS_ERR(priv->mux_pdev)) { |
1067 | err = PTR_ERR(priv->mux_pdev); | 1038 | err = PTR_ERR(priv->mux_pdev); |