Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * I2C multiplexer using GPIO API |
| 3 | * |
| 4 | * Peter Korsgaard <peter.korsgaard@barco.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/i2c.h> |
| 12 | #include <linux/i2c-mux.h> |
Wolfram Sang | 62ea22c | 2018-04-19 22:00:08 +0200 | [diff] [blame] | 13 | #include <linux/platform_data/i2c-mux-gpio.h> |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/gpio.h> |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 18 | #include "../../gpio/gpiolib.h" |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 19 | #include <linux/of_gpio.h> |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 20 | |
| 21 | struct gpiomux { |
Jean Delvare | e7065e2 | 2012-04-28 15:32:06 +0200 | [diff] [blame] | 22 | struct i2c_mux_gpio_platform_data data; |
Jean Delvare | e7ee514 | 2012-10-05 22:23:54 +0200 | [diff] [blame] | 23 | unsigned gpio_base; |
Peter Rosin | feff5c0 | 2016-11-24 19:19:28 +0100 | [diff] [blame] | 24 | struct gpio_desc **gpios; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 25 | }; |
| 26 | |
Jean Delvare | e7065e2 | 2012-04-28 15:32:06 +0200 | [diff] [blame] | 27 | static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val) |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 28 | { |
Janusz Krzysztofik | b9762be | 2018-09-05 23:50:05 +0200 | [diff] [blame^] | 29 | DECLARE_BITMAP(values, BITS_PER_TYPE(val)); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 30 | |
Janusz Krzysztofik | b9762be | 2018-09-05 23:50:05 +0200 | [diff] [blame^] | 31 | values[0] = val; |
Peter Rosin | feff5c0 | 2016-11-24 19:19:28 +0100 | [diff] [blame] | 32 | |
Janusz Krzysztofik | b9762be | 2018-09-05 23:50:05 +0200 | [diff] [blame^] | 33 | gpiod_set_array_value_cansleep(mux->data.n_gpios, mux->gpios, values); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 34 | } |
| 35 | |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 36 | static int i2c_mux_gpio_select(struct i2c_mux_core *muxc, u32 chan) |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 37 | { |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 38 | struct gpiomux *mux = i2c_mux_priv(muxc); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 39 | |
Ionut Nicu | 8c0ec25 | 2013-10-11 12:09:57 +0200 | [diff] [blame] | 40 | i2c_mux_gpio_set(mux, chan); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 45 | static int i2c_mux_gpio_deselect(struct i2c_mux_core *muxc, u32 chan) |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 46 | { |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 47 | struct gpiomux *mux = i2c_mux_priv(muxc); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 48 | |
Jean Delvare | e7065e2 | 2012-04-28 15:32:06 +0200 | [diff] [blame] | 49 | i2c_mux_gpio_set(mux, mux->data.idle); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 54 | static int match_gpio_chip_by_label(struct gpio_chip *chip, |
Jean Delvare | e7ee514 | 2012-10-05 22:23:54 +0200 | [diff] [blame] | 55 | void *data) |
| 56 | { |
| 57 | return !strcmp(chip->label, data); |
| 58 | } |
| 59 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 60 | #ifdef CONFIG_OF |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 61 | static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 62 | struct platform_device *pdev) |
| 63 | { |
| 64 | struct device_node *np = pdev->dev.of_node; |
| 65 | struct device_node *adapter_np, *child; |
| 66 | struct i2c_adapter *adapter; |
| 67 | unsigned *values, *gpios; |
Ionut Nicu | 492ed77 | 2013-10-08 15:51:53 +0200 | [diff] [blame] | 68 | int i = 0, ret; |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 69 | |
| 70 | if (!np) |
| 71 | return -ENODEV; |
| 72 | |
| 73 | adapter_np = of_parse_phandle(np, "i2c-parent", 0); |
| 74 | if (!adapter_np) { |
| 75 | dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); |
| 76 | return -ENODEV; |
| 77 | } |
| 78 | adapter = of_find_i2c_adapter_by_node(adapter_np); |
Vladimir Zapolskiy | bdbf4a2 | 2015-08-26 23:59:33 +0300 | [diff] [blame] | 79 | of_node_put(adapter_np); |
Ioan Nicu | 623e4ec | 2015-03-30 15:03:38 +0200 | [diff] [blame] | 80 | if (!adapter) |
Ionut Nicu | 9937b8d | 2013-10-09 11:50:45 +0200 | [diff] [blame] | 81 | return -EPROBE_DEFER; |
Ioan Nicu | 623e4ec | 2015-03-30 15:03:38 +0200 | [diff] [blame] | 82 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 83 | mux->data.parent = i2c_adapter_id(adapter); |
| 84 | put_device(&adapter->dev); |
| 85 | |
| 86 | mux->data.n_values = of_get_child_count(np); |
| 87 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 88 | values = devm_kcalloc(&pdev->dev, |
| 89 | mux->data.n_values, sizeof(*mux->data.values), |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 90 | GFP_KERNEL); |
| 91 | if (!values) { |
| 92 | dev_err(&pdev->dev, "Cannot allocate values array"); |
| 93 | return -ENOMEM; |
| 94 | } |
| 95 | |
| 96 | for_each_child_of_node(np, child) { |
| 97 | of_property_read_u32(child, "reg", values + i); |
| 98 | i++; |
| 99 | } |
| 100 | mux->data.values = values; |
| 101 | |
| 102 | if (of_property_read_u32(np, "idle-state", &mux->data.idle)) |
| 103 | mux->data.idle = I2C_MUX_GPIO_NO_IDLE; |
| 104 | |
| 105 | mux->data.n_gpios = of_gpio_named_count(np, "mux-gpios"); |
| 106 | if (mux->data.n_gpios < 0) { |
| 107 | dev_err(&pdev->dev, "Missing mux-gpios property in the DT.\n"); |
| 108 | return -EINVAL; |
| 109 | } |
| 110 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 111 | gpios = devm_kcalloc(&pdev->dev, |
| 112 | mux->data.n_gpios, sizeof(*mux->data.gpios), |
| 113 | GFP_KERNEL); |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 114 | if (!gpios) { |
| 115 | dev_err(&pdev->dev, "Cannot allocate gpios array"); |
| 116 | return -ENOMEM; |
| 117 | } |
| 118 | |
Ionut Nicu | 492ed77 | 2013-10-08 15:51:53 +0200 | [diff] [blame] | 119 | for (i = 0; i < mux->data.n_gpios; i++) { |
| 120 | ret = of_get_named_gpio(np, "mux-gpios", i); |
| 121 | if (ret < 0) |
| 122 | return ret; |
| 123 | gpios[i] = ret; |
| 124 | } |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 125 | |
| 126 | mux->data.gpios = gpios; |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | #else |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 131 | static int i2c_mux_gpio_probe_dt(struct gpiomux *mux, |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 132 | struct platform_device *pdev) |
| 133 | { |
| 134 | return 0; |
| 135 | } |
| 136 | #endif |
| 137 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 138 | static int i2c_mux_gpio_probe(struct platform_device *pdev) |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 139 | { |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 140 | struct i2c_mux_core *muxc; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 141 | struct gpiomux *mux; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 142 | struct i2c_adapter *parent; |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 143 | struct i2c_adapter *root; |
Jean Delvare | e7ee514 | 2012-10-05 22:23:54 +0200 | [diff] [blame] | 144 | unsigned initial_state, gpio_base; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 145 | int i, ret; |
| 146 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 147 | mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 148 | if (!mux) |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 149 | return -ENOMEM; |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 150 | |
Jingoo Han | 6d4028c | 2013-07-30 16:59:33 +0900 | [diff] [blame] | 151 | if (!dev_get_platdata(&pdev->dev)) { |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 152 | ret = i2c_mux_gpio_probe_dt(mux, pdev); |
| 153 | if (ret < 0) |
| 154 | return ret; |
Jingoo Han | 6d4028c | 2013-07-30 16:59:33 +0900 | [diff] [blame] | 155 | } else { |
| 156 | memcpy(&mux->data, dev_get_platdata(&pdev->dev), |
| 157 | sizeof(mux->data)); |
| 158 | } |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 159 | |
Jean Delvare | e7ee514 | 2012-10-05 22:23:54 +0200 | [diff] [blame] | 160 | /* |
| 161 | * If a GPIO chip name is provided, the GPIO pin numbers provided are |
| 162 | * relative to its base GPIO number. Otherwise they are absolute. |
| 163 | */ |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 164 | if (mux->data.gpio_chip) { |
Jean Delvare | e7ee514 | 2012-10-05 22:23:54 +0200 | [diff] [blame] | 165 | struct gpio_chip *gpio; |
| 166 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 167 | gpio = gpiochip_find(mux->data.gpio_chip, |
Jean Delvare | e7ee514 | 2012-10-05 22:23:54 +0200 | [diff] [blame] | 168 | match_gpio_chip_by_label); |
| 169 | if (!gpio) |
| 170 | return -EPROBE_DEFER; |
| 171 | |
| 172 | gpio_base = gpio->base; |
| 173 | } else { |
| 174 | gpio_base = 0; |
| 175 | } |
| 176 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 177 | parent = i2c_get_adapter(mux->data.parent); |
Ioan Nicu | 623e4ec | 2015-03-30 15:03:38 +0200 | [diff] [blame] | 178 | if (!parent) |
Ionut Nicu | 9937b8d | 2013-10-09 11:50:45 +0200 | [diff] [blame] | 179 | return -EPROBE_DEFER; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 180 | |
Peter Rosin | feff5c0 | 2016-11-24 19:19:28 +0100 | [diff] [blame] | 181 | muxc = i2c_mux_alloc(parent, &pdev->dev, mux->data.n_values, |
Janusz Krzysztofik | b9762be | 2018-09-05 23:50:05 +0200 | [diff] [blame^] | 182 | mux->data.n_gpios * sizeof(*mux->gpios), 0, |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 183 | i2c_mux_gpio_select, NULL); |
| 184 | if (!muxc) { |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 185 | ret = -ENOMEM; |
Maxime Ripard | 2614a85 | 2012-10-05 22:23:53 +0200 | [diff] [blame] | 186 | goto alloc_failed; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 187 | } |
Peter Rosin | feff5c0 | 2016-11-24 19:19:28 +0100 | [diff] [blame] | 188 | mux->gpios = muxc->priv; |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 189 | muxc->priv = mux; |
| 190 | |
| 191 | platform_set_drvdata(pdev, muxc); |
| 192 | |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 193 | root = i2c_root_adapter(&parent->dev); |
| 194 | |
| 195 | muxc->mux_locked = true; |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 196 | mux->gpio_base = gpio_base; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 197 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 198 | if (mux->data.idle != I2C_MUX_GPIO_NO_IDLE) { |
| 199 | initial_state = mux->data.idle; |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 200 | muxc->deselect = i2c_mux_gpio_deselect; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 201 | } else { |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 202 | initial_state = mux->data.values[0]; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 205 | for (i = 0; i < mux->data.n_gpios; i++) { |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 206 | struct device *gpio_dev; |
| 207 | struct gpio_desc *gpio_desc; |
| 208 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 209 | ret = gpio_request(gpio_base + mux->data.gpios[i], "i2c-mux-gpio"); |
Jean Delvare | 7fafae6 | 2013-03-06 22:35:53 +0000 | [diff] [blame] | 210 | if (ret) { |
| 211 | dev_err(&pdev->dev, "Failed to request GPIO %d\n", |
| 212 | mux->data.gpios[i]); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 213 | goto err_request_gpio; |
Jean Delvare | 7fafae6 | 2013-03-06 22:35:53 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | ret = gpio_direction_output(gpio_base + mux->data.gpios[i], |
| 217 | initial_state & (1 << i)); |
| 218 | if (ret) { |
| 219 | dev_err(&pdev->dev, |
| 220 | "Failed to set direction of GPIO %d to output\n", |
| 221 | mux->data.gpios[i]); |
| 222 | i++; /* gpio_request above succeeded, so must free */ |
| 223 | goto err_request_gpio; |
| 224 | } |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 225 | |
Peter Rosin | feff5c0 | 2016-11-24 19:19:28 +0100 | [diff] [blame] | 226 | gpio_desc = gpio_to_desc(gpio_base + mux->data.gpios[i]); |
| 227 | mux->gpios[i] = gpio_desc; |
| 228 | |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 229 | if (!muxc->mux_locked) |
| 230 | continue; |
| 231 | |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 232 | gpio_dev = &gpio_desc->gdev->dev; |
| 233 | muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Peter Rosin | 6ef91fc | 2016-05-04 22:15:29 +0200 | [diff] [blame] | 236 | if (muxc->mux_locked) |
| 237 | dev_info(&pdev->dev, "mux-locked i2c mux\n"); |
| 238 | |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 239 | for (i = 0; i < mux->data.n_values; i++) { |
| 240 | u32 nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; |
| 241 | unsigned int class = mux->data.classes ? mux->data.classes[i] : 0; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 242 | |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 243 | ret = i2c_mux_add_adapter(muxc, nr, mux->data.values[i], class); |
Peter Rosin | 1b00900 | 2017-04-03 10:14:11 +0200 | [diff] [blame] | 244 | if (ret) |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 245 | goto add_adapter_failed; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | dev_info(&pdev->dev, "%d port mux on %s adapter\n", |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 249 | mux->data.n_values, parent->name); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | |
| 253 | add_adapter_failed: |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 254 | i2c_mux_del_adapters(muxc); |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 255 | i = mux->data.n_gpios; |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 256 | err_request_gpio: |
| 257 | for (; i > 0; i--) |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 258 | gpio_free(gpio_base + mux->data.gpios[i - 1]); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 259 | alloc_failed: |
| 260 | i2c_put_adapter(parent); |
| 261 | |
| 262 | return ret; |
| 263 | } |
| 264 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 265 | static int i2c_mux_gpio_remove(struct platform_device *pdev) |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 266 | { |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 267 | struct i2c_mux_core *muxc = platform_get_drvdata(pdev); |
| 268 | struct gpiomux *mux = i2c_mux_priv(muxc); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 269 | int i; |
| 270 | |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 271 | i2c_mux_del_adapters(muxc); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 272 | |
| 273 | for (i = 0; i < mux->data.n_gpios; i++) |
Jean Delvare | e7ee514 | 2012-10-05 22:23:54 +0200 | [diff] [blame] | 274 | gpio_free(mux->gpio_base + mux->data.gpios[i]); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 275 | |
Peter Rosin | bb44814 | 2016-04-20 08:39:05 +0200 | [diff] [blame] | 276 | i2c_put_adapter(muxc->parent); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 281 | static const struct of_device_id i2c_mux_gpio_of_match[] = { |
Maxime Ripard | 9b7a0c4 | 2012-10-25 18:23:53 +0200 | [diff] [blame] | 282 | { .compatible = "i2c-mux-gpio", }, |
| 283 | {}, |
| 284 | }; |
| 285 | MODULE_DEVICE_TABLE(of, i2c_mux_gpio_of_match); |
| 286 | |
Jean Delvare | e7065e2 | 2012-04-28 15:32:06 +0200 | [diff] [blame] | 287 | static struct platform_driver i2c_mux_gpio_driver = { |
| 288 | .probe = i2c_mux_gpio_probe, |
Bill Pemberton | 0b255e9 | 2012-11-27 15:59:38 -0500 | [diff] [blame] | 289 | .remove = i2c_mux_gpio_remove, |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 290 | .driver = { |
Jean Delvare | e7065e2 | 2012-04-28 15:32:06 +0200 | [diff] [blame] | 291 | .name = "i2c-mux-gpio", |
Sachin Kamat | 4e90532 | 2013-09-30 09:04:25 +0530 | [diff] [blame] | 292 | .of_match_table = i2c_mux_gpio_of_match, |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 293 | }, |
| 294 | }; |
| 295 | |
Jean Delvare | e7065e2 | 2012-04-28 15:32:06 +0200 | [diff] [blame] | 296 | module_platform_driver(i2c_mux_gpio_driver); |
Peter Korsgaard | 92ed1a7 | 2011-01-10 22:11:23 +0100 | [diff] [blame] | 297 | |
| 298 | MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver"); |
| 299 | MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>"); |
| 300 | MODULE_LICENSE("GPL"); |
Jean Delvare | e7065e2 | 2012-04-28 15:32:06 +0200 | [diff] [blame] | 301 | MODULE_ALIAS("platform:i2c-mux-gpio"); |