diff options
| author | Wolfram Sang <wsa@the-dreams.de> | 2017-11-01 18:44:52 -0400 |
|---|---|---|
| committer | Wolfram Sang <wsa@the-dreams.de> | 2017-11-01 18:45:46 -0400 |
| commit | 4ee045f4e9b73c4635ceedbb1ee40e0b3ecbdbcc (patch) | |
| tree | f75e20907a3dc01e780ca75b1696f7d30c179944 /drivers | |
| parent | 93367bfca98f36cece57c01dbce6ea1b4ac58245 (diff) | |
| parent | 05c74778858d7d9907d607172fcc9646b70b6364 (diff) | |
Merge branch 'for-wolfram' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio into i2c/for-4.15
Refactor i2c-gpio and its users to use gpiod. Done by GPIO maintainer
LinusW.
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/gpio/gpiolib.c | 13 | ||||
| -rw-r--r-- | drivers/i2c/busses/i2c-gpio.c | 212 | ||||
| -rw-r--r-- | drivers/mfd/sm501.c | 49 |
3 files changed, 144 insertions, 130 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index eb80dac4e26a..c952ef1b2f46 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
| @@ -3264,8 +3264,21 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, | |||
| 3264 | 3264 | ||
| 3265 | if (lflags & GPIO_ACTIVE_LOW) | 3265 | if (lflags & GPIO_ACTIVE_LOW) |
| 3266 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); | 3266 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); |
| 3267 | |||
| 3267 | if (lflags & GPIO_OPEN_DRAIN) | 3268 | if (lflags & GPIO_OPEN_DRAIN) |
| 3268 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | 3269 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); |
| 3270 | else if (dflags & GPIOD_FLAGS_BIT_OPEN_DRAIN) { | ||
| 3271 | /* | ||
| 3272 | * This enforces open drain mode from the consumer side. | ||
| 3273 | * This is necessary for some busses like I2C, but the lookup | ||
| 3274 | * should *REALLY* have specified them as open drain in the | ||
| 3275 | * first place, so print a little warning here. | ||
| 3276 | */ | ||
| 3277 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | ||
| 3278 | gpiod_warn(desc, | ||
| 3279 | "enforced open drain please flag it properly in DT/ACPI DSDT/board file\n"); | ||
| 3280 | } | ||
| 3281 | |||
| 3269 | if (lflags & GPIO_OPEN_SOURCE) | 3282 | if (lflags & GPIO_OPEN_SOURCE) |
| 3270 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); | 3283 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); |
| 3271 | if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE) | 3284 | if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE) |
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 0ef8fcc6ac3a..d80ea6ce91bb 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c | |||
| @@ -14,27 +14,17 @@ | |||
| 14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 15 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
| 16 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/gpio.h> | 17 | #include <linux/gpio/consumer.h> |
| 18 | #include <linux/of.h> | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_gpio.h> | ||
| 20 | 19 | ||
| 21 | struct i2c_gpio_private_data { | 20 | struct i2c_gpio_private_data { |
| 21 | struct gpio_desc *sda; | ||
| 22 | struct gpio_desc *scl; | ||
| 22 | struct i2c_adapter adap; | 23 | struct i2c_adapter adap; |
| 23 | struct i2c_algo_bit_data bit_data; | 24 | struct i2c_algo_bit_data bit_data; |
| 24 | struct i2c_gpio_platform_data pdata; | 25 | struct i2c_gpio_platform_data pdata; |
| 25 | }; | 26 | }; |
| 26 | 27 | ||
| 27 | /* Toggle SDA by changing the direction of the pin */ | ||
| 28 | static void i2c_gpio_setsda_dir(void *data, int state) | ||
| 29 | { | ||
| 30 | struct i2c_gpio_platform_data *pdata = data; | ||
| 31 | |||
| 32 | if (state) | ||
| 33 | gpio_direction_input(pdata->sda_pin); | ||
| 34 | else | ||
| 35 | gpio_direction_output(pdata->sda_pin, 0); | ||
| 36 | } | ||
| 37 | |||
| 38 | /* | 28 | /* |
| 39 | * Toggle SDA by changing the output value of the pin. This is only | 29 | * Toggle SDA by changing the output value of the pin. This is only |
| 40 | * valid for pins configured as open drain (i.e. setting the value | 30 | * valid for pins configured as open drain (i.e. setting the value |
| @@ -42,20 +32,9 @@ static void i2c_gpio_setsda_dir(void *data, int state) | |||
| 42 | */ | 32 | */ |
| 43 | static void i2c_gpio_setsda_val(void *data, int state) | 33 | static void i2c_gpio_setsda_val(void *data, int state) |
| 44 | { | 34 | { |
| 45 | struct i2c_gpio_platform_data *pdata = data; | 35 | struct i2c_gpio_private_data *priv = data; |
| 46 | |||
| 47 | gpio_set_value(pdata->sda_pin, state); | ||
| 48 | } | ||
| 49 | |||
| 50 | /* Toggle SCL by changing the direction of the pin. */ | ||
| 51 | static void i2c_gpio_setscl_dir(void *data, int state) | ||
| 52 | { | ||
| 53 | struct i2c_gpio_platform_data *pdata = data; | ||
| 54 | 36 | ||
| 55 | if (state) | 37 | gpiod_set_value(priv->sda, state); |
| 56 | gpio_direction_input(pdata->scl_pin); | ||
| 57 | else | ||
| 58 | gpio_direction_output(pdata->scl_pin, 0); | ||
| 59 | } | 38 | } |
| 60 | 39 | ||
| 61 | /* | 40 | /* |
| @@ -66,44 +45,23 @@ static void i2c_gpio_setscl_dir(void *data, int state) | |||
| 66 | */ | 45 | */ |
| 67 | static void i2c_gpio_setscl_val(void *data, int state) | 46 | static void i2c_gpio_setscl_val(void *data, int state) |
| 68 | { | 47 | { |
| 69 | struct i2c_gpio_platform_data *pdata = data; | 48 | struct i2c_gpio_private_data *priv = data; |
| 70 | 49 | ||
| 71 | gpio_set_value(pdata->scl_pin, state); | 50 | gpiod_set_value(priv->scl, state); |
| 72 | } | 51 | } |
| 73 | 52 | ||
| 74 | static int i2c_gpio_getsda(void *data) | 53 | static int i2c_gpio_getsda(void *data) |
| 75 | { | 54 | { |
| 76 | struct i2c_gpio_platform_data *pdata = data; | 55 | struct i2c_gpio_private_data *priv = data; |
| 77 | 56 | ||
| 78 | return gpio_get_value(pdata->sda_pin); | 57 | return gpiod_get_value(priv->sda); |
| 79 | } | 58 | } |
| 80 | 59 | ||
| 81 | static int i2c_gpio_getscl(void *data) | 60 | static int i2c_gpio_getscl(void *data) |
| 82 | { | 61 | { |
| 83 | struct i2c_gpio_platform_data *pdata = data; | 62 | struct i2c_gpio_private_data *priv = data; |
| 84 | |||
| 85 | return gpio_get_value(pdata->scl_pin); | ||
| 86 | } | ||
| 87 | |||
| 88 | static int of_i2c_gpio_get_pins(struct device_node *np, | ||
| 89 | unsigned int *sda_pin, unsigned int *scl_pin) | ||
| 90 | { | ||
| 91 | if (of_gpio_count(np) < 2) | ||
| 92 | return -ENODEV; | ||
| 93 | |||
| 94 | *sda_pin = of_get_gpio(np, 0); | ||
| 95 | *scl_pin = of_get_gpio(np, 1); | ||
| 96 | |||
| 97 | if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER) | ||
| 98 | return -EPROBE_DEFER; | ||
| 99 | |||
| 100 | if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) { | ||
| 101 | pr_err("%pOF: invalid GPIO pins, sda=%d/scl=%d\n", | ||
| 102 | np, *sda_pin, *scl_pin); | ||
| 103 | return -ENODEV; | ||
| 104 | } | ||
| 105 | 63 | ||
| 106 | return 0; | 64 | return gpiod_get_value(priv->scl); |
| 107 | } | 65 | } |
| 108 | 66 | ||
| 109 | static void of_i2c_gpio_get_props(struct device_node *np, | 67 | static void of_i2c_gpio_get_props(struct device_node *np, |
| @@ -124,72 +82,105 @@ static void of_i2c_gpio_get_props(struct device_node *np, | |||
| 124 | of_property_read_bool(np, "i2c-gpio,scl-output-only"); | 82 | of_property_read_bool(np, "i2c-gpio,scl-output-only"); |
| 125 | } | 83 | } |
| 126 | 84 | ||
| 85 | static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, | ||
| 86 | const char *con_id, | ||
| 87 | unsigned int index, | ||
| 88 | enum gpiod_flags gflags) | ||
| 89 | { | ||
| 90 | struct gpio_desc *retdesc; | ||
| 91 | int ret; | ||
| 92 | |||
| 93 | retdesc = devm_gpiod_get(dev, con_id, gflags); | ||
| 94 | if (!IS_ERR(retdesc)) { | ||
| 95 | dev_dbg(dev, "got GPIO from name %s\n", con_id); | ||
| 96 | return retdesc; | ||
| 97 | } | ||
| 98 | |||
| 99 | retdesc = devm_gpiod_get_index(dev, NULL, index, gflags); | ||
| 100 | if (!IS_ERR(retdesc)) { | ||
| 101 | dev_dbg(dev, "got GPIO from index %u\n", index); | ||
| 102 | return retdesc; | ||
| 103 | } | ||
| 104 | |||
| 105 | ret = PTR_ERR(retdesc); | ||
| 106 | |||
| 107 | /* FIXME: hack in the old code, is this really necessary? */ | ||
| 108 | if (ret == -EINVAL) | ||
| 109 | retdesc = ERR_PTR(-EPROBE_DEFER); | ||
| 110 | |||
| 111 | /* This happens if the GPIO driver is not yet probed, let's defer */ | ||
| 112 | if (ret == -ENOENT) | ||
| 113 | retdesc = ERR_PTR(-EPROBE_DEFER); | ||
| 114 | |||
| 115 | if (ret != -EPROBE_DEFER) | ||
| 116 | dev_err(dev, "error trying to get descriptor: %d\n", ret); | ||
| 117 | |||
| 118 | return retdesc; | ||
| 119 | } | ||
| 120 | |||
| 127 | static int i2c_gpio_probe(struct platform_device *pdev) | 121 | static int i2c_gpio_probe(struct platform_device *pdev) |
| 128 | { | 122 | { |
| 129 | struct i2c_gpio_private_data *priv; | 123 | struct i2c_gpio_private_data *priv; |
| 130 | struct i2c_gpio_platform_data *pdata; | 124 | struct i2c_gpio_platform_data *pdata; |
| 131 | struct i2c_algo_bit_data *bit_data; | 125 | struct i2c_algo_bit_data *bit_data; |
| 132 | struct i2c_adapter *adap; | 126 | struct i2c_adapter *adap; |
| 133 | unsigned int sda_pin, scl_pin; | 127 | struct device *dev = &pdev->dev; |
| 128 | struct device_node *np = dev->of_node; | ||
| 129 | enum gpiod_flags gflags; | ||
| 134 | int ret; | 130 | int ret; |
| 135 | 131 | ||
| 136 | /* First get the GPIO pins; if it fails, we'll defer the probe. */ | 132 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 137 | if (pdev->dev.of_node) { | ||
| 138 | ret = of_i2c_gpio_get_pins(pdev->dev.of_node, | ||
| 139 | &sda_pin, &scl_pin); | ||
| 140 | if (ret) | ||
| 141 | return ret; | ||
| 142 | } else { | ||
| 143 | if (!dev_get_platdata(&pdev->dev)) | ||
| 144 | return -ENXIO; | ||
| 145 | pdata = dev_get_platdata(&pdev->dev); | ||
| 146 | sda_pin = pdata->sda_pin; | ||
| 147 | scl_pin = pdata->scl_pin; | ||
| 148 | } | ||
| 149 | |||
| 150 | ret = devm_gpio_request(&pdev->dev, sda_pin, "sda"); | ||
| 151 | if (ret) { | ||
| 152 | if (ret == -EINVAL) | ||
| 153 | ret = -EPROBE_DEFER; /* Try again later */ | ||
| 154 | return ret; | ||
| 155 | } | ||
| 156 | ret = devm_gpio_request(&pdev->dev, scl_pin, "scl"); | ||
| 157 | if (ret) { | ||
| 158 | if (ret == -EINVAL) | ||
| 159 | ret = -EPROBE_DEFER; /* Try again later */ | ||
| 160 | return ret; | ||
| 161 | } | ||
| 162 | |||
| 163 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
| 164 | if (!priv) | 133 | if (!priv) |
| 165 | return -ENOMEM; | 134 | return -ENOMEM; |
| 135 | |||
| 166 | adap = &priv->adap; | 136 | adap = &priv->adap; |
| 167 | bit_data = &priv->bit_data; | 137 | bit_data = &priv->bit_data; |
| 168 | pdata = &priv->pdata; | 138 | pdata = &priv->pdata; |
| 169 | 139 | ||
| 170 | if (pdev->dev.of_node) { | 140 | if (np) { |
| 171 | pdata->sda_pin = sda_pin; | 141 | of_i2c_gpio_get_props(np, pdata); |
| 172 | pdata->scl_pin = scl_pin; | ||
| 173 | of_i2c_gpio_get_props(pdev->dev.of_node, pdata); | ||
| 174 | } else { | 142 | } else { |
| 175 | memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata)); | 143 | /* |
| 144 | * If all platform data settings are zero it is OK | ||
| 145 | * to not provide any platform data from the board. | ||
| 146 | */ | ||
| 147 | if (dev_get_platdata(dev)) | ||
| 148 | memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata)); | ||
| 176 | } | 149 | } |
| 177 | 150 | ||
| 178 | if (pdata->sda_is_open_drain) { | 151 | /* |
| 179 | gpio_direction_output(pdata->sda_pin, 1); | 152 | * First get the GPIO pins; if it fails, we'll defer the probe. |
| 180 | bit_data->setsda = i2c_gpio_setsda_val; | 153 | * If the SDA line is marked from platform data or device tree as |
| 181 | } else { | 154 | * "open drain" it means something outside of our control is making |
| 182 | gpio_direction_input(pdata->sda_pin); | 155 | * this line being handled as open drain, and we should just handle |
| 183 | bit_data->setsda = i2c_gpio_setsda_dir; | 156 | * it as any other output. Else we enforce open drain as this is |
| 184 | } | 157 | * required for an I2C bus. |
| 158 | */ | ||
| 159 | if (pdata->sda_is_open_drain) | ||
| 160 | gflags = GPIOD_OUT_HIGH; | ||
| 161 | else | ||
| 162 | gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; | ||
| 163 | priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags); | ||
| 164 | if (IS_ERR(priv->sda)) | ||
| 165 | return PTR_ERR(priv->sda); | ||
| 166 | |||
| 167 | /* | ||
| 168 | * If the SCL line is marked from platform data or device tree as | ||
| 169 | * "open drain" it means something outside of our control is making | ||
| 170 | * this line being handled as open drain, and we should just handle | ||
| 171 | * it as any other output. Else we enforce open drain as this is | ||
| 172 | * required for an I2C bus. | ||
| 173 | */ | ||
| 174 | if (pdata->scl_is_open_drain) | ||
| 175 | gflags = GPIOD_OUT_LOW; | ||
| 176 | else | ||
| 177 | gflags = GPIOD_OUT_LOW_OPEN_DRAIN; | ||
| 178 | priv->scl = i2c_gpio_get_desc(dev, "scl", 1, gflags); | ||
| 179 | if (IS_ERR(priv->scl)) | ||
| 180 | return PTR_ERR(priv->scl); | ||
| 185 | 181 | ||
| 186 | if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { | 182 | bit_data->setsda = i2c_gpio_setsda_val; |
| 187 | gpio_direction_output(pdata->scl_pin, 1); | 183 | bit_data->setscl = i2c_gpio_setscl_val; |
| 188 | bit_data->setscl = i2c_gpio_setscl_val; | ||
| 189 | } else { | ||
| 190 | gpio_direction_input(pdata->scl_pin); | ||
| 191 | bit_data->setscl = i2c_gpio_setscl_dir; | ||
| 192 | } | ||
| 193 | 184 | ||
| 194 | if (!pdata->scl_is_output_only) | 185 | if (!pdata->scl_is_output_only) |
| 195 | bit_data->getscl = i2c_gpio_getscl; | 186 | bit_data->getscl = i2c_gpio_getscl; |
| @@ -207,18 +198,18 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
| 207 | else | 198 | else |
| 208 | bit_data->timeout = HZ / 10; /* 100 ms */ | 199 | bit_data->timeout = HZ / 10; /* 100 ms */ |
| 209 | 200 | ||
| 210 | bit_data->data = pdata; | 201 | bit_data->data = priv; |
| 211 | 202 | ||
| 212 | adap->owner = THIS_MODULE; | 203 | adap->owner = THIS_MODULE; |
| 213 | if (pdev->dev.of_node) | 204 | if (np) |
| 214 | strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); | 205 | strlcpy(adap->name, dev_name(dev), sizeof(adap->name)); |
| 215 | else | 206 | else |
| 216 | snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); | 207 | snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); |
| 217 | 208 | ||
| 218 | adap->algo_data = bit_data; | 209 | adap->algo_data = bit_data; |
| 219 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | 210 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
| 220 | adap->dev.parent = &pdev->dev; | 211 | adap->dev.parent = dev; |
| 221 | adap->dev.of_node = pdev->dev.of_node; | 212 | adap->dev.of_node = np; |
| 222 | 213 | ||
| 223 | adap->nr = pdev->id; | 214 | adap->nr = pdev->id; |
| 224 | ret = i2c_bit_add_numbered_bus(adap); | 215 | ret = i2c_bit_add_numbered_bus(adap); |
| @@ -227,8 +218,13 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
| 227 | 218 | ||
| 228 | platform_set_drvdata(pdev, priv); | 219 | platform_set_drvdata(pdev, priv); |
| 229 | 220 | ||
| 230 | dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", | 221 | /* |
| 231 | pdata->sda_pin, pdata->scl_pin, | 222 | * FIXME: using global GPIO numbers is not helpful. If/when we |
| 223 | * get accessors to get the actual name of the GPIO line, | ||
| 224 | * from the descriptor, then provide that instead. | ||
| 225 | */ | ||
| 226 | dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n", | ||
| 227 | desc_to_gpio(priv->sda), desc_to_gpio(priv->scl), | ||
| 232 | pdata->scl_is_output_only | 228 | pdata->scl_is_output_only |
| 233 | ? ", no clock stretching" : ""); | 229 | ? ", no clock stretching" : ""); |
| 234 | 230 | ||
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c index 40534352e574..ad774161a22d 100644 --- a/drivers/mfd/sm501.c +++ b/drivers/mfd/sm501.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/pci.h> | 21 | #include <linux/pci.h> |
| 22 | #include <linux/i2c-gpio.h> | 22 | #include <linux/i2c-gpio.h> |
| 23 | #include <linux/gpio/machine.h> | ||
| 23 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
| 24 | 25 | ||
| 25 | #include <linux/sm501.h> | 26 | #include <linux/sm501.h> |
| @@ -1107,14 +1108,6 @@ static void sm501_gpio_remove(struct sm501_devdata *sm) | |||
| 1107 | kfree(gpio->regs_res); | 1108 | kfree(gpio->regs_res); |
| 1108 | } | 1109 | } |
| 1109 | 1110 | ||
| 1110 | static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin) | ||
| 1111 | { | ||
| 1112 | struct sm501_gpio *gpio = &sm->gpio; | ||
| 1113 | int base = (pin < 32) ? gpio->low.gpio.base : gpio->high.gpio.base; | ||
| 1114 | |||
| 1115 | return (pin % 32) + base; | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) | 1111 | static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) |
| 1119 | { | 1112 | { |
| 1120 | return sm->gpio.registered; | 1113 | return sm->gpio.registered; |
| @@ -1129,11 +1122,6 @@ static inline void sm501_gpio_remove(struct sm501_devdata *sm) | |||
| 1129 | { | 1122 | { |
| 1130 | } | 1123 | } |
| 1131 | 1124 | ||
| 1132 | static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin) | ||
| 1133 | { | ||
| 1134 | return -1; | ||
| 1135 | } | ||
| 1136 | |||
| 1137 | static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) | 1125 | static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) |
| 1138 | { | 1126 | { |
| 1139 | return 0; | 1127 | return 0; |
| @@ -1145,20 +1133,37 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm, | |||
| 1145 | { | 1133 | { |
| 1146 | struct i2c_gpio_platform_data *icd; | 1134 | struct i2c_gpio_platform_data *icd; |
| 1147 | struct platform_device *pdev; | 1135 | struct platform_device *pdev; |
| 1136 | struct gpiod_lookup_table *lookup; | ||
| 1148 | 1137 | ||
| 1149 | pdev = sm501_create_subdev(sm, "i2c-gpio", 0, | 1138 | pdev = sm501_create_subdev(sm, "i2c-gpio", 0, |
| 1150 | sizeof(struct i2c_gpio_platform_data)); | 1139 | sizeof(struct i2c_gpio_platform_data)); |
| 1151 | if (!pdev) | 1140 | if (!pdev) |
| 1152 | return -ENOMEM; | 1141 | return -ENOMEM; |
| 1153 | 1142 | ||
| 1154 | icd = dev_get_platdata(&pdev->dev); | 1143 | /* Create a gpiod lookup using gpiochip-local offsets */ |
| 1155 | 1144 | lookup = devm_kzalloc(&pdev->dev, | |
| 1156 | /* We keep the pin_sda and pin_scl fields relative in case the | 1145 | sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup), |
| 1157 | * same platform data is passed to >1 SM501. | 1146 | GFP_KERNEL); |
| 1158 | */ | 1147 | lookup->dev_id = "i2c-gpio"; |
| 1148 | if (iic->pin_sda < 32) | ||
| 1149 | lookup->table[0].chip_label = "SM501-LOW"; | ||
| 1150 | else | ||
| 1151 | lookup->table[0].chip_label = "SM501-HIGH"; | ||
| 1152 | lookup->table[0].chip_hwnum = iic->pin_sda % 32; | ||
| 1153 | lookup->table[0].con_id = NULL; | ||
| 1154 | lookup->table[0].idx = 0; | ||
| 1155 | lookup->table[0].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; | ||
| 1156 | if (iic->pin_scl < 32) | ||
| 1157 | lookup->table[1].chip_label = "SM501-LOW"; | ||
| 1158 | else | ||
| 1159 | lookup->table[1].chip_label = "SM501-HIGH"; | ||
| 1160 | lookup->table[1].chip_hwnum = iic->pin_scl % 32; | ||
| 1161 | lookup->table[1].con_id = NULL; | ||
| 1162 | lookup->table[1].idx = 1; | ||
| 1163 | lookup->table[1].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; | ||
| 1164 | gpiod_add_lookup_table(lookup); | ||
| 1159 | 1165 | ||
| 1160 | icd->sda_pin = sm501_gpio_pin2nr(sm, iic->pin_sda); | 1166 | icd = dev_get_platdata(&pdev->dev); |
| 1161 | icd->scl_pin = sm501_gpio_pin2nr(sm, iic->pin_scl); | ||
| 1162 | icd->timeout = iic->timeout; | 1167 | icd->timeout = iic->timeout; |
| 1163 | icd->udelay = iic->udelay; | 1168 | icd->udelay = iic->udelay; |
| 1164 | 1169 | ||
| @@ -1170,9 +1175,9 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm, | |||
| 1170 | 1175 | ||
| 1171 | pdev->id = iic->bus_num; | 1176 | pdev->id = iic->bus_num; |
| 1172 | 1177 | ||
| 1173 | dev_info(sm->dev, "registering i2c-%d: sda=%d (%d), scl=%d (%d)\n", | 1178 | dev_info(sm->dev, "registering i2c-%d: sda=%d, scl=%d\n", |
| 1174 | iic->bus_num, | 1179 | iic->bus_num, |
| 1175 | icd->sda_pin, iic->pin_sda, icd->scl_pin, iic->pin_scl); | 1180 | iic->pin_sda, iic->pin_scl); |
| 1176 | 1181 | ||
| 1177 | return sm501_register_device(sm, pdev); | 1182 | return sm501_register_device(sm, pdev); |
| 1178 | } | 1183 | } |
