.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Pin controller and GPIO driver for Amlogic Meson SoCs |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com> |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or |
---|
7 | | - * modify it under the terms of the GNU General Public License |
---|
8 | | - * version 2 as published by the Free Software Foundation. |
---|
9 | | - * |
---|
10 | | - * You should have received a copy of the GNU General Public License |
---|
11 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
12 | 6 | */ |
---|
13 | 7 | |
---|
14 | 8 | /* |
---|
.. | .. |
---|
31 | 25 | * In some cases the register ranges for pull enable and pull |
---|
32 | 26 | * direction are the same and thus there are only 3 register ranges. |
---|
33 | 27 | * |
---|
| 28 | + * Since Meson G12A SoC, the ao register ranges for gpio, pull enable |
---|
| 29 | + * and pull direction are the same, so there are only 2 register ranges. |
---|
| 30 | + * |
---|
34 | 31 | * For the pull and GPIO configuration every bank uses a contiguous |
---|
35 | 32 | * set of bits in the register sets described above; the same register |
---|
36 | 33 | * can be shared by more banks with different offsets. |
---|
.. | .. |
---|
41 | 38 | */ |
---|
42 | 39 | |
---|
43 | 40 | #include <linux/device.h> |
---|
44 | | -#include <linux/gpio.h> |
---|
| 41 | +#include <linux/gpio/driver.h> |
---|
45 | 42 | #include <linux/init.h> |
---|
46 | 43 | #include <linux/io.h> |
---|
47 | 44 | #include <linux/of.h> |
---|
.. | .. |
---|
58 | 55 | #include "../core.h" |
---|
59 | 56 | #include "../pinctrl-utils.h" |
---|
60 | 57 | #include "pinctrl-meson.h" |
---|
| 58 | + |
---|
| 59 | +static const unsigned int meson_bit_strides[] = { |
---|
| 60 | + 1, 1, 1, 1, 1, 2, 1 |
---|
| 61 | +}; |
---|
61 | 62 | |
---|
62 | 63 | /** |
---|
63 | 64 | * meson_get_bank() - find the bank containing a given pin |
---|
.. | .. |
---|
99 | 100 | { |
---|
100 | 101 | struct meson_reg_desc *desc = &bank->regs[reg_type]; |
---|
101 | 102 | |
---|
102 | | - *reg = desc->reg * 4; |
---|
103 | | - *bit = desc->bit + pin - bank->first; |
---|
| 103 | + *bit = (desc->bit + pin - bank->first) * meson_bit_strides[reg_type]; |
---|
| 104 | + *reg = (desc->reg + (*bit / 32)) * 4; |
---|
| 105 | + *bit &= 0x1f; |
---|
104 | 106 | } |
---|
105 | 107 | |
---|
106 | 108 | static int meson_get_groups_count(struct pinctrl_dev *pcdev) |
---|
.. | .. |
---|
150 | 152 | |
---|
151 | 153 | return pc->data->num_funcs; |
---|
152 | 154 | } |
---|
| 155 | +EXPORT_SYMBOL_GPL(meson_pmx_get_funcs_count); |
---|
153 | 156 | |
---|
154 | 157 | const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev, |
---|
155 | 158 | unsigned selector) |
---|
.. | .. |
---|
158 | 161 | |
---|
159 | 162 | return pc->data->funcs[selector].name; |
---|
160 | 163 | } |
---|
| 164 | +EXPORT_SYMBOL_GPL(meson_pmx_get_func_name); |
---|
161 | 165 | |
---|
162 | 166 | int meson_pmx_get_groups(struct pinctrl_dev *pcdev, unsigned selector, |
---|
163 | 167 | const char * const **groups, |
---|
.. | .. |
---|
170 | 174 | |
---|
171 | 175 | return 0; |
---|
172 | 176 | } |
---|
| 177 | +EXPORT_SYMBOL_GPL(meson_pmx_get_groups); |
---|
173 | 178 | |
---|
174 | | -static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin, |
---|
175 | | - unsigned long *configs, unsigned num_configs) |
---|
| 179 | +static int meson_pinconf_set_gpio_bit(struct meson_pinctrl *pc, |
---|
| 180 | + unsigned int pin, |
---|
| 181 | + unsigned int reg_type, |
---|
| 182 | + bool arg) |
---|
176 | 183 | { |
---|
177 | | - struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); |
---|
178 | 184 | struct meson_bank *bank; |
---|
179 | | - enum pin_config_param param; |
---|
180 | 185 | unsigned int reg, bit; |
---|
181 | | - int i, ret; |
---|
| 186 | + int ret; |
---|
182 | 187 | |
---|
183 | 188 | ret = meson_get_bank(pc, pin, &bank); |
---|
184 | 189 | if (ret) |
---|
185 | 190 | return ret; |
---|
186 | 191 | |
---|
| 192 | + meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit); |
---|
| 193 | + return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), |
---|
| 194 | + arg ? BIT(bit) : 0); |
---|
| 195 | +} |
---|
| 196 | + |
---|
| 197 | +static int meson_pinconf_get_gpio_bit(struct meson_pinctrl *pc, |
---|
| 198 | + unsigned int pin, |
---|
| 199 | + unsigned int reg_type) |
---|
| 200 | +{ |
---|
| 201 | + struct meson_bank *bank; |
---|
| 202 | + unsigned int reg, bit, val; |
---|
| 203 | + int ret; |
---|
| 204 | + |
---|
| 205 | + ret = meson_get_bank(pc, pin, &bank); |
---|
| 206 | + if (ret) |
---|
| 207 | + return ret; |
---|
| 208 | + |
---|
| 209 | + meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit); |
---|
| 210 | + ret = regmap_read(pc->reg_gpio, reg, &val); |
---|
| 211 | + if (ret) |
---|
| 212 | + return ret; |
---|
| 213 | + |
---|
| 214 | + return BIT(bit) & val ? 1 : 0; |
---|
| 215 | +} |
---|
| 216 | + |
---|
| 217 | +static int meson_pinconf_set_output(struct meson_pinctrl *pc, |
---|
| 218 | + unsigned int pin, |
---|
| 219 | + bool out) |
---|
| 220 | +{ |
---|
| 221 | + return meson_pinconf_set_gpio_bit(pc, pin, REG_DIR, !out); |
---|
| 222 | +} |
---|
| 223 | + |
---|
| 224 | +static int meson_pinconf_get_output(struct meson_pinctrl *pc, |
---|
| 225 | + unsigned int pin) |
---|
| 226 | +{ |
---|
| 227 | + int ret = meson_pinconf_get_gpio_bit(pc, pin, REG_DIR); |
---|
| 228 | + |
---|
| 229 | + if (ret < 0) |
---|
| 230 | + return ret; |
---|
| 231 | + |
---|
| 232 | + return !ret; |
---|
| 233 | +} |
---|
| 234 | + |
---|
| 235 | +static int meson_pinconf_set_drive(struct meson_pinctrl *pc, |
---|
| 236 | + unsigned int pin, |
---|
| 237 | + bool high) |
---|
| 238 | +{ |
---|
| 239 | + return meson_pinconf_set_gpio_bit(pc, pin, REG_OUT, high); |
---|
| 240 | +} |
---|
| 241 | + |
---|
| 242 | +static int meson_pinconf_get_drive(struct meson_pinctrl *pc, |
---|
| 243 | + unsigned int pin) |
---|
| 244 | +{ |
---|
| 245 | + return meson_pinconf_get_gpio_bit(pc, pin, REG_OUT); |
---|
| 246 | +} |
---|
| 247 | + |
---|
| 248 | +static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc, |
---|
| 249 | + unsigned int pin, |
---|
| 250 | + bool high) |
---|
| 251 | +{ |
---|
| 252 | + int ret; |
---|
| 253 | + |
---|
| 254 | + ret = meson_pinconf_set_output(pc, pin, true); |
---|
| 255 | + if (ret) |
---|
| 256 | + return ret; |
---|
| 257 | + |
---|
| 258 | + return meson_pinconf_set_drive(pc, pin, high); |
---|
| 259 | +} |
---|
| 260 | + |
---|
| 261 | +static int meson_pinconf_disable_bias(struct meson_pinctrl *pc, |
---|
| 262 | + unsigned int pin) |
---|
| 263 | +{ |
---|
| 264 | + struct meson_bank *bank; |
---|
| 265 | + unsigned int reg, bit = 0; |
---|
| 266 | + int ret; |
---|
| 267 | + |
---|
| 268 | + ret = meson_get_bank(pc, pin, &bank); |
---|
| 269 | + if (ret) |
---|
| 270 | + return ret; |
---|
| 271 | + |
---|
| 272 | + meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); |
---|
| 273 | + ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0); |
---|
| 274 | + if (ret) |
---|
| 275 | + return ret; |
---|
| 276 | + |
---|
| 277 | + return 0; |
---|
| 278 | +} |
---|
| 279 | + |
---|
| 280 | +static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin, |
---|
| 281 | + bool pull_up) |
---|
| 282 | +{ |
---|
| 283 | + struct meson_bank *bank; |
---|
| 284 | + unsigned int reg, bit, val = 0; |
---|
| 285 | + int ret; |
---|
| 286 | + |
---|
| 287 | + ret = meson_get_bank(pc, pin, &bank); |
---|
| 288 | + if (ret) |
---|
| 289 | + return ret; |
---|
| 290 | + |
---|
| 291 | + meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); |
---|
| 292 | + if (pull_up) |
---|
| 293 | + val = BIT(bit); |
---|
| 294 | + |
---|
| 295 | + ret = regmap_update_bits(pc->reg_pull, reg, BIT(bit), val); |
---|
| 296 | + if (ret) |
---|
| 297 | + return ret; |
---|
| 298 | + |
---|
| 299 | + meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); |
---|
| 300 | + ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), BIT(bit)); |
---|
| 301 | + if (ret) |
---|
| 302 | + return ret; |
---|
| 303 | + |
---|
| 304 | + return 0; |
---|
| 305 | +} |
---|
| 306 | + |
---|
| 307 | +static int meson_pinconf_set_drive_strength(struct meson_pinctrl *pc, |
---|
| 308 | + unsigned int pin, |
---|
| 309 | + u16 drive_strength_ua) |
---|
| 310 | +{ |
---|
| 311 | + struct meson_bank *bank; |
---|
| 312 | + unsigned int reg, bit, ds_val; |
---|
| 313 | + int ret; |
---|
| 314 | + |
---|
| 315 | + if (!pc->reg_ds) { |
---|
| 316 | + dev_err(pc->dev, "drive-strength not supported\n"); |
---|
| 317 | + return -ENOTSUPP; |
---|
| 318 | + } |
---|
| 319 | + |
---|
| 320 | + ret = meson_get_bank(pc, pin, &bank); |
---|
| 321 | + if (ret) |
---|
| 322 | + return ret; |
---|
| 323 | + |
---|
| 324 | + meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit); |
---|
| 325 | + |
---|
| 326 | + if (drive_strength_ua <= 500) { |
---|
| 327 | + ds_val = MESON_PINCONF_DRV_500UA; |
---|
| 328 | + } else if (drive_strength_ua <= 2500) { |
---|
| 329 | + ds_val = MESON_PINCONF_DRV_2500UA; |
---|
| 330 | + } else if (drive_strength_ua <= 3000) { |
---|
| 331 | + ds_val = MESON_PINCONF_DRV_3000UA; |
---|
| 332 | + } else if (drive_strength_ua <= 4000) { |
---|
| 333 | + ds_val = MESON_PINCONF_DRV_4000UA; |
---|
| 334 | + } else { |
---|
| 335 | + dev_warn_once(pc->dev, |
---|
| 336 | + "pin %u: invalid drive-strength : %d , default to 4mA\n", |
---|
| 337 | + pin, drive_strength_ua); |
---|
| 338 | + ds_val = MESON_PINCONF_DRV_4000UA; |
---|
| 339 | + } |
---|
| 340 | + |
---|
| 341 | + ret = regmap_update_bits(pc->reg_ds, reg, 0x3 << bit, ds_val << bit); |
---|
| 342 | + if (ret) |
---|
| 343 | + return ret; |
---|
| 344 | + |
---|
| 345 | + return 0; |
---|
| 346 | +} |
---|
| 347 | + |
---|
| 348 | +static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin, |
---|
| 349 | + unsigned long *configs, unsigned num_configs) |
---|
| 350 | +{ |
---|
| 351 | + struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); |
---|
| 352 | + enum pin_config_param param; |
---|
| 353 | + unsigned int arg = 0; |
---|
| 354 | + int i, ret; |
---|
| 355 | + |
---|
187 | 356 | for (i = 0; i < num_configs; i++) { |
---|
188 | 357 | param = pinconf_to_config_param(configs[i]); |
---|
189 | 358 | |
---|
190 | 359 | switch (param) { |
---|
191 | | - case PIN_CONFIG_BIAS_DISABLE: |
---|
192 | | - dev_dbg(pc->dev, "pin %u: disable bias\n", pin); |
---|
| 360 | + case PIN_CONFIG_DRIVE_STRENGTH_UA: |
---|
| 361 | + case PIN_CONFIG_OUTPUT_ENABLE: |
---|
| 362 | + case PIN_CONFIG_OUTPUT: |
---|
| 363 | + arg = pinconf_to_config_argument(configs[i]); |
---|
| 364 | + break; |
---|
193 | 365 | |
---|
194 | | - meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, |
---|
195 | | - &bit); |
---|
196 | | - ret = regmap_update_bits(pc->reg_pullen, reg, |
---|
197 | | - BIT(bit), 0); |
---|
198 | | - if (ret) |
---|
199 | | - return ret; |
---|
| 366 | + default: |
---|
| 367 | + break; |
---|
| 368 | + } |
---|
| 369 | + |
---|
| 370 | + switch (param) { |
---|
| 371 | + case PIN_CONFIG_BIAS_DISABLE: |
---|
| 372 | + ret = meson_pinconf_disable_bias(pc, pin); |
---|
200 | 373 | break; |
---|
201 | 374 | case PIN_CONFIG_BIAS_PULL_UP: |
---|
202 | | - dev_dbg(pc->dev, "pin %u: enable pull-up\n", pin); |
---|
203 | | - |
---|
204 | | - meson_calc_reg_and_bit(bank, pin, REG_PULLEN, |
---|
205 | | - ®, &bit); |
---|
206 | | - ret = regmap_update_bits(pc->reg_pullen, reg, |
---|
207 | | - BIT(bit), BIT(bit)); |
---|
208 | | - if (ret) |
---|
209 | | - return ret; |
---|
210 | | - |
---|
211 | | - meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); |
---|
212 | | - ret = regmap_update_bits(pc->reg_pull, reg, |
---|
213 | | - BIT(bit), BIT(bit)); |
---|
214 | | - if (ret) |
---|
215 | | - return ret; |
---|
| 375 | + ret = meson_pinconf_enable_bias(pc, pin, true); |
---|
216 | 376 | break; |
---|
217 | 377 | case PIN_CONFIG_BIAS_PULL_DOWN: |
---|
218 | | - dev_dbg(pc->dev, "pin %u: enable pull-down\n", pin); |
---|
219 | | - |
---|
220 | | - meson_calc_reg_and_bit(bank, pin, REG_PULLEN, |
---|
221 | | - ®, &bit); |
---|
222 | | - ret = regmap_update_bits(pc->reg_pullen, reg, |
---|
223 | | - BIT(bit), BIT(bit)); |
---|
224 | | - if (ret) |
---|
225 | | - return ret; |
---|
226 | | - |
---|
227 | | - meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); |
---|
228 | | - ret = regmap_update_bits(pc->reg_pull, reg, |
---|
229 | | - BIT(bit), 0); |
---|
230 | | - if (ret) |
---|
231 | | - return ret; |
---|
| 378 | + ret = meson_pinconf_enable_bias(pc, pin, false); |
---|
| 379 | + break; |
---|
| 380 | + case PIN_CONFIG_DRIVE_STRENGTH_UA: |
---|
| 381 | + ret = meson_pinconf_set_drive_strength(pc, pin, arg); |
---|
| 382 | + break; |
---|
| 383 | + case PIN_CONFIG_OUTPUT_ENABLE: |
---|
| 384 | + ret = meson_pinconf_set_output(pc, pin, arg); |
---|
| 385 | + break; |
---|
| 386 | + case PIN_CONFIG_OUTPUT: |
---|
| 387 | + ret = meson_pinconf_set_output_drive(pc, pin, arg); |
---|
232 | 388 | break; |
---|
233 | 389 | default: |
---|
234 | | - return -ENOTSUPP; |
---|
| 390 | + ret = -ENOTSUPP; |
---|
235 | 391 | } |
---|
| 392 | + |
---|
| 393 | + if (ret) |
---|
| 394 | + return ret; |
---|
236 | 395 | } |
---|
237 | 396 | |
---|
238 | 397 | return 0; |
---|
.. | .. |
---|
272 | 431 | return conf; |
---|
273 | 432 | } |
---|
274 | 433 | |
---|
| 434 | +static int meson_pinconf_get_drive_strength(struct meson_pinctrl *pc, |
---|
| 435 | + unsigned int pin, |
---|
| 436 | + u16 *drive_strength_ua) |
---|
| 437 | +{ |
---|
| 438 | + struct meson_bank *bank; |
---|
| 439 | + unsigned int reg, bit; |
---|
| 440 | + unsigned int val; |
---|
| 441 | + int ret; |
---|
| 442 | + |
---|
| 443 | + if (!pc->reg_ds) |
---|
| 444 | + return -ENOTSUPP; |
---|
| 445 | + |
---|
| 446 | + ret = meson_get_bank(pc, pin, &bank); |
---|
| 447 | + if (ret) |
---|
| 448 | + return ret; |
---|
| 449 | + |
---|
| 450 | + meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit); |
---|
| 451 | + |
---|
| 452 | + ret = regmap_read(pc->reg_ds, reg, &val); |
---|
| 453 | + if (ret) |
---|
| 454 | + return ret; |
---|
| 455 | + |
---|
| 456 | + switch ((val >> bit) & 0x3) { |
---|
| 457 | + case MESON_PINCONF_DRV_500UA: |
---|
| 458 | + *drive_strength_ua = 500; |
---|
| 459 | + break; |
---|
| 460 | + case MESON_PINCONF_DRV_2500UA: |
---|
| 461 | + *drive_strength_ua = 2500; |
---|
| 462 | + break; |
---|
| 463 | + case MESON_PINCONF_DRV_3000UA: |
---|
| 464 | + *drive_strength_ua = 3000; |
---|
| 465 | + break; |
---|
| 466 | + case MESON_PINCONF_DRV_4000UA: |
---|
| 467 | + *drive_strength_ua = 4000; |
---|
| 468 | + break; |
---|
| 469 | + default: |
---|
| 470 | + return -EINVAL; |
---|
| 471 | + } |
---|
| 472 | + |
---|
| 473 | + return 0; |
---|
| 474 | +} |
---|
| 475 | + |
---|
275 | 476 | static int meson_pinconf_get(struct pinctrl_dev *pcdev, unsigned int pin, |
---|
276 | 477 | unsigned long *config) |
---|
277 | 478 | { |
---|
278 | 479 | struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); |
---|
279 | 480 | enum pin_config_param param = pinconf_to_config_param(*config); |
---|
280 | 481 | u16 arg; |
---|
| 482 | + int ret; |
---|
281 | 483 | |
---|
282 | 484 | switch (param) { |
---|
283 | 485 | case PIN_CONFIG_BIAS_DISABLE: |
---|
.. | .. |
---|
288 | 490 | else |
---|
289 | 491 | return -EINVAL; |
---|
290 | 492 | break; |
---|
| 493 | + case PIN_CONFIG_DRIVE_STRENGTH_UA: |
---|
| 494 | + ret = meson_pinconf_get_drive_strength(pc, pin, &arg); |
---|
| 495 | + if (ret) |
---|
| 496 | + return ret; |
---|
| 497 | + break; |
---|
| 498 | + case PIN_CONFIG_OUTPUT_ENABLE: |
---|
| 499 | + ret = meson_pinconf_get_output(pc, pin); |
---|
| 500 | + if (ret <= 0) |
---|
| 501 | + return -EINVAL; |
---|
| 502 | + arg = 1; |
---|
| 503 | + break; |
---|
| 504 | + case PIN_CONFIG_OUTPUT: |
---|
| 505 | + ret = meson_pinconf_get_output(pc, pin); |
---|
| 506 | + if (ret <= 0) |
---|
| 507 | + return -EINVAL; |
---|
| 508 | + |
---|
| 509 | + ret = meson_pinconf_get_drive(pc, pin); |
---|
| 510 | + if (ret < 0) |
---|
| 511 | + return -EINVAL; |
---|
| 512 | + |
---|
| 513 | + arg = ret; |
---|
| 514 | + break; |
---|
| 515 | + |
---|
291 | 516 | default: |
---|
292 | 517 | return -ENOTSUPP; |
---|
293 | 518 | } |
---|
.. | .. |
---|
330 | 555 | .is_generic = true, |
---|
331 | 556 | }; |
---|
332 | 557 | |
---|
333 | | -static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
---|
| 558 | +static int meson_gpio_get_direction(struct gpio_chip *chip, unsigned gpio) |
---|
334 | 559 | { |
---|
335 | 560 | struct meson_pinctrl *pc = gpiochip_get_data(chip); |
---|
336 | | - unsigned int reg, bit; |
---|
337 | | - struct meson_bank *bank; |
---|
338 | 561 | int ret; |
---|
339 | 562 | |
---|
340 | | - ret = meson_get_bank(pc, gpio, &bank); |
---|
341 | | - if (ret) |
---|
| 563 | + ret = meson_pinconf_get_output(pc, gpio); |
---|
| 564 | + if (ret < 0) |
---|
342 | 565 | return ret; |
---|
343 | 566 | |
---|
344 | | - meson_calc_reg_and_bit(bank, gpio, REG_DIR, ®, &bit); |
---|
| 567 | + return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN; |
---|
| 568 | +} |
---|
345 | 569 | |
---|
346 | | - return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), BIT(bit)); |
---|
| 570 | +static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) |
---|
| 571 | +{ |
---|
| 572 | + return meson_pinconf_set_output(gpiochip_get_data(chip), gpio, false); |
---|
347 | 573 | } |
---|
348 | 574 | |
---|
349 | 575 | static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, |
---|
350 | 576 | int value) |
---|
351 | 577 | { |
---|
352 | | - struct meson_pinctrl *pc = gpiochip_get_data(chip); |
---|
353 | | - unsigned int reg, bit; |
---|
354 | | - struct meson_bank *bank; |
---|
355 | | - int ret; |
---|
356 | | - |
---|
357 | | - ret = meson_get_bank(pc, gpio, &bank); |
---|
358 | | - if (ret) |
---|
359 | | - return ret; |
---|
360 | | - |
---|
361 | | - meson_calc_reg_and_bit(bank, gpio, REG_DIR, ®, &bit); |
---|
362 | | - ret = regmap_update_bits(pc->reg_gpio, reg, BIT(bit), 0); |
---|
363 | | - if (ret) |
---|
364 | | - return ret; |
---|
365 | | - |
---|
366 | | - meson_calc_reg_and_bit(bank, gpio, REG_OUT, ®, &bit); |
---|
367 | | - return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), |
---|
368 | | - value ? BIT(bit) : 0); |
---|
| 578 | + return meson_pinconf_set_output_drive(gpiochip_get_data(chip), |
---|
| 579 | + gpio, value); |
---|
369 | 580 | } |
---|
370 | 581 | |
---|
371 | 582 | static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) |
---|
372 | 583 | { |
---|
373 | | - struct meson_pinctrl *pc = gpiochip_get_data(chip); |
---|
374 | | - unsigned int reg, bit; |
---|
375 | | - struct meson_bank *bank; |
---|
376 | | - int ret; |
---|
377 | | - |
---|
378 | | - ret = meson_get_bank(pc, gpio, &bank); |
---|
379 | | - if (ret) |
---|
380 | | - return; |
---|
381 | | - |
---|
382 | | - meson_calc_reg_and_bit(bank, gpio, REG_OUT, ®, &bit); |
---|
383 | | - regmap_update_bits(pc->reg_gpio, reg, BIT(bit), |
---|
384 | | - value ? BIT(bit) : 0); |
---|
| 584 | + meson_pinconf_set_drive(gpiochip_get_data(chip), gpio, value); |
---|
385 | 585 | } |
---|
386 | 586 | |
---|
387 | 587 | static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio) |
---|
.. | .. |
---|
409 | 609 | pc->chip.parent = pc->dev; |
---|
410 | 610 | pc->chip.request = gpiochip_generic_request; |
---|
411 | 611 | pc->chip.free = gpiochip_generic_free; |
---|
| 612 | + pc->chip.set_config = gpiochip_generic_config; |
---|
| 613 | + pc->chip.get_direction = meson_gpio_get_direction; |
---|
412 | 614 | pc->chip.direction_input = meson_gpio_direction_input; |
---|
413 | 615 | pc->chip.direction_output = meson_gpio_direction_output; |
---|
414 | 616 | pc->chip.get = meson_gpio_get; |
---|
.. | .. |
---|
444 | 646 | |
---|
445 | 647 | i = of_property_match_string(node, "reg-names", name); |
---|
446 | 648 | if (of_address_to_resource(node, i, &res)) |
---|
447 | | - return ERR_PTR(-ENOENT); |
---|
| 649 | + return NULL; |
---|
448 | 650 | |
---|
449 | 651 | base = devm_ioremap_resource(pc->dev, &res); |
---|
450 | 652 | if (IS_ERR(base)) |
---|
.. | .. |
---|
452 | 654 | |
---|
453 | 655 | meson_regmap_config.max_register = resource_size(&res) - 4; |
---|
454 | 656 | meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL, |
---|
455 | | - "%s-%s", node->name, |
---|
| 657 | + "%pOFn-%s", node, |
---|
456 | 658 | name); |
---|
457 | 659 | if (!meson_regmap_config.name) |
---|
458 | 660 | return ERR_PTR(-ENOMEM); |
---|
.. | .. |
---|
470 | 672 | continue; |
---|
471 | 673 | if (gpio_np) { |
---|
472 | 674 | dev_err(pc->dev, "multiple gpio nodes\n"); |
---|
| 675 | + of_node_put(np); |
---|
473 | 676 | return -EINVAL; |
---|
474 | 677 | } |
---|
475 | 678 | gpio_np = np; |
---|
.. | .. |
---|
483 | 686 | pc->of_node = gpio_np; |
---|
484 | 687 | |
---|
485 | 688 | pc->reg_mux = meson_map_resource(pc, gpio_np, "mux"); |
---|
486 | | - if (IS_ERR(pc->reg_mux)) { |
---|
| 689 | + if (IS_ERR_OR_NULL(pc->reg_mux)) { |
---|
487 | 690 | dev_err(pc->dev, "mux registers not found\n"); |
---|
488 | | - return PTR_ERR(pc->reg_mux); |
---|
| 691 | + return pc->reg_mux ? PTR_ERR(pc->reg_mux) : -ENOENT; |
---|
| 692 | + } |
---|
| 693 | + |
---|
| 694 | + pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio"); |
---|
| 695 | + if (IS_ERR_OR_NULL(pc->reg_gpio)) { |
---|
| 696 | + dev_err(pc->dev, "gpio registers not found\n"); |
---|
| 697 | + return pc->reg_gpio ? PTR_ERR(pc->reg_gpio) : -ENOENT; |
---|
489 | 698 | } |
---|
490 | 699 | |
---|
491 | 700 | pc->reg_pull = meson_map_resource(pc, gpio_np, "pull"); |
---|
492 | | - if (IS_ERR(pc->reg_pull)) { |
---|
493 | | - dev_err(pc->dev, "pull registers not found\n"); |
---|
494 | | - return PTR_ERR(pc->reg_pull); |
---|
495 | | - } |
---|
| 701 | + if (IS_ERR(pc->reg_pull)) |
---|
| 702 | + pc->reg_pull = NULL; |
---|
496 | 703 | |
---|
497 | 704 | pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable"); |
---|
498 | | - /* Use pull region if pull-enable one is not present */ |
---|
499 | 705 | if (IS_ERR(pc->reg_pullen)) |
---|
500 | | - pc->reg_pullen = pc->reg_pull; |
---|
| 706 | + pc->reg_pullen = NULL; |
---|
501 | 707 | |
---|
502 | | - pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio"); |
---|
503 | | - if (IS_ERR(pc->reg_gpio)) { |
---|
504 | | - dev_err(pc->dev, "gpio registers not found\n"); |
---|
505 | | - return PTR_ERR(pc->reg_gpio); |
---|
| 708 | + pc->reg_ds = meson_map_resource(pc, gpio_np, "ds"); |
---|
| 709 | + if (IS_ERR(pc->reg_ds)) { |
---|
| 710 | + dev_dbg(pc->dev, "ds registers not found - skipping\n"); |
---|
| 711 | + pc->reg_ds = NULL; |
---|
506 | 712 | } |
---|
| 713 | + |
---|
| 714 | + if (pc->data->parse_dt) |
---|
| 715 | + return pc->data->parse_dt(pc); |
---|
507 | 716 | |
---|
508 | 717 | return 0; |
---|
509 | 718 | } |
---|
| 719 | + |
---|
| 720 | +int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc) |
---|
| 721 | +{ |
---|
| 722 | + if (!pc->reg_pull) |
---|
| 723 | + return -EINVAL; |
---|
| 724 | + |
---|
| 725 | + pc->reg_pullen = pc->reg_pull; |
---|
| 726 | + |
---|
| 727 | + return 0; |
---|
| 728 | +} |
---|
| 729 | +EXPORT_SYMBOL_GPL(meson8_aobus_parse_dt_extra); |
---|
| 730 | + |
---|
| 731 | +int meson_a1_parse_dt_extra(struct meson_pinctrl *pc) |
---|
| 732 | +{ |
---|
| 733 | + pc->reg_pull = pc->reg_gpio; |
---|
| 734 | + pc->reg_pullen = pc->reg_gpio; |
---|
| 735 | + pc->reg_ds = pc->reg_gpio; |
---|
| 736 | + |
---|
| 737 | + return 0; |
---|
| 738 | +} |
---|
| 739 | +EXPORT_SYMBOL_GPL(meson_a1_parse_dt_extra); |
---|
510 | 740 | |
---|
511 | 741 | int meson_pinctrl_probe(struct platform_device *pdev) |
---|
512 | 742 | { |
---|
.. | .. |
---|
541 | 771 | |
---|
542 | 772 | return meson_gpiolib_register(pc); |
---|
543 | 773 | } |
---|
| 774 | +EXPORT_SYMBOL_GPL(meson_pinctrl_probe); |
---|
| 775 | + |
---|
| 776 | +MODULE_LICENSE("GPL v2"); |
---|