Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jean Delvare and committed by
Jean Delvare
f82b8626 600a711c

+4 -33
+4 -33
drivers/i2c/busses/i2c-i801.c
··· 194 194 195 195 #if defined CONFIG_I2C_MUX || defined CONFIG_I2C_MUX_MODULE 196 196 const struct i801_mux_config *mux_drvdata; 197 - unsigned mux_priv[2]; 198 197 struct platform_device *mux_pdev; 199 198 #endif 200 199 }; ··· 1007 1008 { } 1008 1009 }; 1009 1010 1010 - static int __devinit match_gpio_chip_by_label(struct gpio_chip *chip, 1011 - void *data) 1012 - { 1013 - return !strcmp(chip->label, data); 1014 - } 1015 - 1016 1011 /* Setup multiplexing if needed */ 1017 1012 static int __devinit i801_add_mux(struct i801_priv *priv) 1018 1013 { 1019 1014 struct device *dev = &priv->adapter.dev; 1020 1015 const struct i801_mux_config *mux_config; 1021 - struct gpio_chip *gpio; 1022 1016 struct i2c_mux_gpio_platform_data gpio_data; 1023 - int i, err; 1017 + int err; 1024 1018 1025 1019 if (!priv->mux_drvdata) 1026 1020 return 0; 1027 1021 mux_config = priv->mux_drvdata; 1028 - 1029 - /* Find GPIO chip */ 1030 - gpio = gpiochip_find(mux_config->gpio_chip, match_gpio_chip_by_label); 1031 - if (gpio) { 1032 - dev_info(dev, 1033 - "GPIO chip %s found, SMBus multiplexing enabled\n", 1034 - mux_config->gpio_chip); 1035 - } else { 1036 - dev_err(dev, 1037 - "GPIO chip %s not found, SMBus multiplexing disabled\n", 1038 - mux_config->gpio_chip); 1039 - return -ENODEV; 1040 - } 1041 - 1042 - /* Find absolute GPIO pin numbers */ 1043 - if (ARRAY_SIZE(priv->mux_priv) < mux_config->n_gpios) { 1044 - dev_err(dev, "i801_priv.mux_priv too small (%zu, need %d)\n", 1045 - ARRAY_SIZE(priv->mux_priv), mux_config->n_gpios); 1046 - return -ENODEV; 1047 - } 1048 - for (i = 0; i < mux_config->n_gpios; i++) 1049 - priv->mux_priv[i] = gpio->base + mux_config->gpios[i]; 1050 1022 1051 1023 /* Prepare the platform data */ 1052 1024 memset(&gpio_data, 0, sizeof(struct i2c_mux_gpio_platform_data)); ··· 1025 1055 gpio_data.values = mux_config->values; 1026 1056 gpio_data.n_values = mux_config->n_values; 1027 1057 gpio_data.classes = mux_config->classes; 1028 - gpio_data.gpios = priv->mux_priv; 1058 + gpio_data.gpio_chip = mux_config->gpio_chip; 1059 + gpio_data.gpios = mux_config->gpios; 1029 1060 gpio_data.n_gpios = mux_config->n_gpios; 1030 1061 gpio_data.idle = I2C_MUX_GPIO_NO_IDLE; 1031 1062 1032 1063 /* Register the mux device */ 1033 1064 priv->mux_pdev = platform_device_register_data(dev, "i2c-mux-gpio", 1034 - priv->mux_priv[0], &gpio_data, 1065 + PLATFORM_DEVID_AUTO, &gpio_data, 1035 1066 sizeof(struct i2c_mux_gpio_platform_data)); 1036 1067 if (IS_ERR(priv->mux_pdev)) { 1037 1068 err = PTR_ERR(priv->mux_pdev);