diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-24 17:05:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-24 17:05:46 -0400 |
commit | 914311c9fb9bc01a215de9d848b72b5449c0e342 (patch) | |
tree | e130f41c9c721bae03d6e293ffe0039d1a9018ea /drivers/pinctrl | |
parent | 5dedb9f3bd5bcb186313ea0c0cff8f2c525d4122 (diff) | |
parent | 8b8b091bf07fa7ef7f13c1ac40b30bcf74050b60 (diff) |
Merge tag 'pinctrl-for-v3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl
Pull pin control changes from Linus Walleij:
"These are the accumulated pin control patches for v3.6:
- Various cleanups to the U300 driver
- Refactor the pin control core to automatically remove any GPIO
ranges when the drivers are removed, instead of having the drivers
do this explicitly.
- Add a function for registering a batch of GPIO ranges.
- Fix a number of incorrect but non-regressive error checks.
- Incremental improvements to the COH901, i.MX and Nomadik drivers
- Add a one-register-per-pin entirely Device Tree-based pin control
driver from Tony Lindgren."
* tag 'pinctrl-for-v3.6' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl:
pinctrl: Add one-register-per-pin type device tree based pinctrl driver
pinctrl/nomadik: add spi2_oc1_2 pin group
pinctrl/nomadik: kerneldoc fix
pinctrl/nomadik: use devm_* allocators for gpio probe
pinctrl/nomadik: add pin group to mco function
pinctrl/nomadik: add hsit_a_2 pin group
pinctrl/nomadik: add pin group smcs1 and smps0
pinctrl/nomadik: fix hsir_a_1_pins pin list
pinctrl: pinctrl-imx: fix map setting problem if NO_PAD_CTL is set
pinctrl/coh901: use clk_prepare_[en|dis]able()
pinctrl/pinctrl-tegra: remove IS_ERR checking of pmx->pctl
pinctrl/pinctrl-spear: remove IS_ERR checking of pmx->pctl
pinctrl/u300: drop unused variable
pinctrl: select the proper symbol
pinctrl: add pinctrl_add_gpio_ranges function
pinctrl: remove pinctrl_remove_gpio_range
pinctrl/pinctrl-core: cleanup pinctrl_register
pinctrl/u300: delete pointless debug print
pinctrl/pinctrl-u300: remove devm_kfree at driver unload
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r-- | drivers/pinctrl/Kconfig | 10 | ||||
-rw-r--r-- | drivers/pinctrl/Makefile | 1 | ||||
-rw-r--r-- | drivers/pinctrl/core.c | 41 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-coh901.c | 6 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-imx.c | 13 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-nomadik-db8500.c | 33 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-nomadik.c | 37 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-single.c | 987 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-tegra.c | 5 | ||||
-rw-r--r-- | drivers/pinctrl/pinctrl-u300.c | 6 | ||||
-rw-r--r-- | drivers/pinctrl/spear/pinctrl-spear.c | 4 |
11 files changed, 1064 insertions, 79 deletions
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index c6e6ae0aa3b1..54e3588bef62 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig | |||
@@ -102,6 +102,14 @@ config PINCTRL_PXA910 | |||
102 | select PINCTRL_PXA3xx | 102 | select PINCTRL_PXA3xx |
103 | select PINCONF | 103 | select PINCONF |
104 | 104 | ||
105 | config PINCTRL_SINGLE | ||
106 | tristate "One-register-per-pin type device tree based pinctrl driver" | ||
107 | depends on OF | ||
108 | select PINMUX | ||
109 | select PINCONF | ||
110 | help | ||
111 | This selects the device tree based generic pinctrl driver. | ||
112 | |||
105 | config PINCTRL_SIRF | 113 | config PINCTRL_SIRF |
106 | bool "CSR SiRFprimaII pin controller driver" | 114 | bool "CSR SiRFprimaII pin controller driver" |
107 | depends on ARCH_PRIMA2 | 115 | depends on ARCH_PRIMA2 |
@@ -130,7 +138,7 @@ config PINCTRL_U300 | |||
130 | 138 | ||
131 | config PINCTRL_COH901 | 139 | config PINCTRL_COH901 |
132 | bool "ST-Ericsson U300 COH 901 335/571 GPIO" | 140 | bool "ST-Ericsson U300 COH 901 335/571 GPIO" |
133 | depends on GPIOLIB && ARCH_U300 && PINMUX_U300 | 141 | depends on GPIOLIB && ARCH_U300 && PINCTRL_U300 |
134 | help | 142 | help |
135 | Say yes here to support GPIO interface on ST-Ericsson U300. | 143 | Say yes here to support GPIO interface on ST-Ericsson U300. |
136 | The names of the two IP block variants supported are | 144 | The names of the two IP block variants supported are |
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index 8c074376cdea..f40b1f81ff2c 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile | |||
@@ -22,6 +22,7 @@ obj-$(CONFIG_PINCTRL_NOMADIK) += pinctrl-nomadik.o | |||
22 | obj-$(CONFIG_PINCTRL_DB8500) += pinctrl-nomadik-db8500.o | 22 | obj-$(CONFIG_PINCTRL_DB8500) += pinctrl-nomadik-db8500.o |
23 | obj-$(CONFIG_PINCTRL_PXA168) += pinctrl-pxa168.o | 23 | obj-$(CONFIG_PINCTRL_PXA168) += pinctrl-pxa168.o |
24 | obj-$(CONFIG_PINCTRL_PXA910) += pinctrl-pxa910.o | 24 | obj-$(CONFIG_PINCTRL_PXA910) += pinctrl-pxa910.o |
25 | obj-$(CONFIG_PINCTRL_SINGLE) += pinctrl-single.o | ||
25 | obj-$(CONFIG_PINCTRL_SIRF) += pinctrl-sirf.o | 26 | obj-$(CONFIG_PINCTRL_SIRF) += pinctrl-sirf.o |
26 | obj-$(CONFIG_PINCTRL_TEGRA) += pinctrl-tegra.o | 27 | obj-$(CONFIG_PINCTRL_TEGRA) += pinctrl-tegra.o |
27 | obj-$(CONFIG_PINCTRL_TEGRA20) += pinctrl-tegra20.o | 28 | obj-$(CONFIG_PINCTRL_TEGRA20) += pinctrl-tegra20.o |
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 0cc053af70bd..fb7f3bebdc69 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c | |||
@@ -332,19 +332,16 @@ void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, | |||
332 | } | 332 | } |
333 | EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range); | 333 | EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range); |
334 | 334 | ||
335 | /** | 335 | void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev, |
336 | * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller | 336 | struct pinctrl_gpio_range *ranges, |
337 | * @pctldev: pin controller device to remove the range from | 337 | unsigned nranges) |
338 | * @range: the GPIO range to remove | ||
339 | */ | ||
340 | void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, | ||
341 | struct pinctrl_gpio_range *range) | ||
342 | { | 338 | { |
343 | mutex_lock(&pinctrl_mutex); | 339 | int i; |
344 | list_del(&range->node); | 340 | |
345 | mutex_unlock(&pinctrl_mutex); | 341 | for (i = 0; i < nranges; i++) |
342 | pinctrl_add_gpio_range(pctldev, &ranges[i]); | ||
346 | } | 343 | } |
347 | EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range); | 344 | EXPORT_SYMBOL_GPL(pinctrl_add_gpio_ranges); |
348 | 345 | ||
349 | /** | 346 | /** |
350 | * pinctrl_get_group_selector() - returns the group selector for a group | 347 | * pinctrl_get_group_selector() - returns the group selector for a group |
@@ -1395,9 +1392,9 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, | |||
1395 | struct pinctrl_dev *pctldev; | 1392 | struct pinctrl_dev *pctldev; |
1396 | int ret; | 1393 | int ret; |
1397 | 1394 | ||
1398 | if (pctldesc == NULL) | 1395 | if (!pctldesc) |
1399 | return NULL; | 1396 | return NULL; |
1400 | if (pctldesc->name == NULL) | 1397 | if (!pctldesc->name) |
1401 | return NULL; | 1398 | return NULL; |
1402 | 1399 | ||
1403 | pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL); | 1400 | pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL); |
@@ -1415,23 +1412,20 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, | |||
1415 | pctldev->dev = dev; | 1412 | pctldev->dev = dev; |
1416 | 1413 | ||
1417 | /* check core ops for sanity */ | 1414 | /* check core ops for sanity */ |
1418 | ret = pinctrl_check_ops(pctldev); | 1415 | if (pinctrl_check_ops(pctldev)) { |
1419 | if (ret) { | ||
1420 | dev_err(dev, "pinctrl ops lacks necessary functions\n"); | 1416 | dev_err(dev, "pinctrl ops lacks necessary functions\n"); |
1421 | goto out_err; | 1417 | goto out_err; |
1422 | } | 1418 | } |
1423 | 1419 | ||
1424 | /* If we're implementing pinmuxing, check the ops for sanity */ | 1420 | /* If we're implementing pinmuxing, check the ops for sanity */ |
1425 | if (pctldesc->pmxops) { | 1421 | if (pctldesc->pmxops) { |
1426 | ret = pinmux_check_ops(pctldev); | 1422 | if (pinmux_check_ops(pctldev)) |
1427 | if (ret) | ||
1428 | goto out_err; | 1423 | goto out_err; |
1429 | } | 1424 | } |
1430 | 1425 | ||
1431 | /* If we're implementing pinconfig, check the ops for sanity */ | 1426 | /* If we're implementing pinconfig, check the ops for sanity */ |
1432 | if (pctldesc->confops) { | 1427 | if (pctldesc->confops) { |
1433 | ret = pinconf_check_ops(pctldev); | 1428 | if (pinconf_check_ops(pctldev)) |
1434 | if (ret) | ||
1435 | goto out_err; | 1429 | goto out_err; |
1436 | } | 1430 | } |
1437 | 1431 | ||
@@ -1457,11 +1451,9 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, | |||
1457 | if (IS_ERR(s)) { | 1451 | if (IS_ERR(s)) { |
1458 | dev_dbg(dev, "failed to lookup the default state\n"); | 1452 | dev_dbg(dev, "failed to lookup the default state\n"); |
1459 | } else { | 1453 | } else { |
1460 | ret = pinctrl_select_state_locked(pctldev->p, s); | 1454 | if (pinctrl_select_state_locked(pctldev->p, s)) |
1461 | if (ret) { | ||
1462 | dev_err(dev, | 1455 | dev_err(dev, |
1463 | "failed to select default state\n"); | 1456 | "failed to select default state\n"); |
1464 | } | ||
1465 | } | 1457 | } |
1466 | } | 1458 | } |
1467 | 1459 | ||
@@ -1485,6 +1477,7 @@ EXPORT_SYMBOL_GPL(pinctrl_register); | |||
1485 | */ | 1477 | */ |
1486 | void pinctrl_unregister(struct pinctrl_dev *pctldev) | 1478 | void pinctrl_unregister(struct pinctrl_dev *pctldev) |
1487 | { | 1479 | { |
1480 | struct pinctrl_gpio_range *range, *n; | ||
1488 | if (pctldev == NULL) | 1481 | if (pctldev == NULL) |
1489 | return; | 1482 | return; |
1490 | 1483 | ||
@@ -1500,6 +1493,10 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev) | |||
1500 | /* Destroy descriptor tree */ | 1493 | /* Destroy descriptor tree */ |
1501 | pinctrl_free_pindescs(pctldev, pctldev->desc->pins, | 1494 | pinctrl_free_pindescs(pctldev, pctldev->desc->pins, |
1502 | pctldev->desc->npins); | 1495 | pctldev->desc->npins); |
1496 | /* remove gpio ranges map */ | ||
1497 | list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node) | ||
1498 | list_del(&range->node); | ||
1499 | |||
1503 | kfree(pctldev); | 1500 | kfree(pctldev); |
1504 | 1501 | ||
1505 | mutex_unlock(&pinctrl_mutex); | 1502 | mutex_unlock(&pinctrl_mutex); |
diff --git a/drivers/pinctrl/pinctrl-coh901.c b/drivers/pinctrl/pinctrl-coh901.c index 55697a5d7482..cc0f00d73d15 100644 --- a/drivers/pinctrl/pinctrl-coh901.c +++ b/drivers/pinctrl/pinctrl-coh901.c | |||
@@ -770,7 +770,7 @@ static int __init u300_gpio_probe(struct platform_device *pdev) | |||
770 | dev_err(gpio->dev, "could not get GPIO clock\n"); | 770 | dev_err(gpio->dev, "could not get GPIO clock\n"); |
771 | goto err_no_clk; | 771 | goto err_no_clk; |
772 | } | 772 | } |
773 | err = clk_enable(gpio->clk); | 773 | err = clk_prepare_enable(gpio->clk); |
774 | if (err) { | 774 | if (err) { |
775 | dev_err(gpio->dev, "could not enable GPIO clock\n"); | 775 | dev_err(gpio->dev, "could not enable GPIO clock\n"); |
776 | goto err_no_clk_enable; | 776 | goto err_no_clk_enable; |
@@ -912,7 +912,7 @@ err_no_ioremap: | |||
912 | release_mem_region(gpio->memres->start, resource_size(gpio->memres)); | 912 | release_mem_region(gpio->memres->start, resource_size(gpio->memres)); |
913 | err_no_ioregion: | 913 | err_no_ioregion: |
914 | err_no_resource: | 914 | err_no_resource: |
915 | clk_disable(gpio->clk); | 915 | clk_disable_unprepare(gpio->clk); |
916 | err_no_clk_enable: | 916 | err_no_clk_enable: |
917 | clk_put(gpio->clk); | 917 | clk_put(gpio->clk); |
918 | err_no_clk: | 918 | err_no_clk: |
@@ -943,7 +943,7 @@ static int __exit u300_gpio_remove(struct platform_device *pdev) | |||
943 | iounmap(gpio->base); | 943 | iounmap(gpio->base); |
944 | release_mem_region(gpio->memres->start, | 944 | release_mem_region(gpio->memres->start, |
945 | resource_size(gpio->memres)); | 945 | resource_size(gpio->memres)); |
946 | clk_disable(gpio->clk); | 946 | clk_disable_unprepare(gpio->clk); |
947 | clk_put(gpio->clk); | 947 | clk_put(gpio->clk); |
948 | platform_set_drvdata(pdev, NULL); | 948 | platform_set_drvdata(pdev, NULL); |
949 | kfree(gpio); | 949 | kfree(gpio); |
diff --git a/drivers/pinctrl/pinctrl-imx.c b/drivers/pinctrl/pinctrl-imx.c index 90c837f469a6..44e97265cd7d 100644 --- a/drivers/pinctrl/pinctrl-imx.c +++ b/drivers/pinctrl/pinctrl-imx.c | |||
@@ -146,7 +146,7 @@ static int imx_dt_node_to_map(struct pinctrl_dev *pctldev, | |||
146 | struct pinctrl_map *new_map; | 146 | struct pinctrl_map *new_map; |
147 | struct device_node *parent; | 147 | struct device_node *parent; |
148 | int map_num = 1; | 148 | int map_num = 1; |
149 | int i; | 149 | int i, j; |
150 | 150 | ||
151 | /* | 151 | /* |
152 | * first find the group of this node and check if we need create | 152 | * first find the group of this node and check if we need create |
@@ -184,13 +184,14 @@ static int imx_dt_node_to_map(struct pinctrl_dev *pctldev, | |||
184 | 184 | ||
185 | /* create config map */ | 185 | /* create config map */ |
186 | new_map++; | 186 | new_map++; |
187 | for (i = 0; i < grp->npins; i++) { | 187 | for (i = j = 0; i < grp->npins; i++) { |
188 | if (!(grp->configs[i] & IMX_NO_PAD_CTL)) { | 188 | if (!(grp->configs[i] & IMX_NO_PAD_CTL)) { |
189 | new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN; | 189 | new_map[j].type = PIN_MAP_TYPE_CONFIGS_PIN; |
190 | new_map[i].data.configs.group_or_pin = | 190 | new_map[j].data.configs.group_or_pin = |
191 | pin_get_name(pctldev, grp->pins[i]); | 191 | pin_get_name(pctldev, grp->pins[i]); |
192 | new_map[i].data.configs.configs = &grp->configs[i]; | 192 | new_map[j].data.configs.configs = &grp->configs[i]; |
193 | new_map[i].data.configs.num_configs = 1; | 193 | new_map[j].data.configs.num_configs = 1; |
194 | j++; | ||
194 | } | 195 | } |
195 | } | 196 | } |
196 | 197 | ||
diff --git a/drivers/pinctrl/pinctrl-nomadik-db8500.c b/drivers/pinctrl/pinctrl-nomadik-db8500.c index 8b2022276f71..6f99769c6733 100644 --- a/drivers/pinctrl/pinctrl-nomadik-db8500.c +++ b/drivers/pinctrl/pinctrl-nomadik-db8500.c | |||
@@ -467,9 +467,12 @@ static const unsigned mc1_a_1_pins[] = { DB8500_PIN_AH16, DB8500_PIN_AG15, | |||
467 | DB8500_PIN_AH15 }; | 467 | DB8500_PIN_AH15 }; |
468 | static const unsigned mc1dir_a_1_pins[] = { DB8500_PIN_AH13, DB8500_PIN_AG12, | 468 | static const unsigned mc1dir_a_1_pins[] = { DB8500_PIN_AH13, DB8500_PIN_AG12, |
469 | DB8500_PIN_AH12, DB8500_PIN_AH11 }; | 469 | DB8500_PIN_AH12, DB8500_PIN_AH11 }; |
470 | static const unsigned hsir_a_1_pins[] = { DB8500_PIN_AG10, DB8500_PIN_AH10 }; | 470 | static const unsigned hsir_a_1_pins[] = { DB8500_PIN_AG10, DB8500_PIN_AH10, |
471 | static const unsigned hsit_a_1_pins[] = { DB8500_PIN_AJ11, DB8500_PIN_AJ9, | 471 | DB8500_PIN_AJ11 }; |
472 | DB8500_PIN_AH9, DB8500_PIN_AG9, DB8500_PIN_AG8, DB8500_PIN_AF8 }; | 472 | static const unsigned hsit_a_1_pins[] = { DB8500_PIN_AJ9, DB8500_PIN_AH9, |
473 | DB8500_PIN_AG9, DB8500_PIN_AG8, DB8500_PIN_AF8 }; | ||
474 | static const unsigned hsit_a_2_pins[] = { DB8500_PIN_AJ9, DB8500_PIN_AH9, | ||
475 | DB8500_PIN_AG9, DB8500_PIN_AG8 }; | ||
473 | static const unsigned clkout_a_1_pins[] = { DB8500_PIN_AH7, DB8500_PIN_AJ6 }; | 476 | static const unsigned clkout_a_1_pins[] = { DB8500_PIN_AH7, DB8500_PIN_AJ6 }; |
474 | static const unsigned clkout_a_2_pins[] = { DB8500_PIN_AG7, DB8500_PIN_AF7 }; | 477 | static const unsigned clkout_a_2_pins[] = { DB8500_PIN_AG7, DB8500_PIN_AF7 }; |
475 | static const unsigned usb_a_1_pins[] = { DB8500_PIN_AF28, DB8500_PIN_AE29, | 478 | static const unsigned usb_a_1_pins[] = { DB8500_PIN_AF28, DB8500_PIN_AE29, |
@@ -508,9 +511,11 @@ static const unsigned sm_b_1_pins[] = { DB8500_PIN_C6, DB8500_PIN_B3, | |||
508 | DB8500_PIN_D9, DB8500_PIN_A5, DB8500_PIN_B4, DB8500_PIN_C8, | 511 | DB8500_PIN_D9, DB8500_PIN_A5, DB8500_PIN_B4, DB8500_PIN_C8, |
509 | DB8500_PIN_A12, DB8500_PIN_C10, DB8500_PIN_B10, DB8500_PIN_B9, | 512 | DB8500_PIN_A12, DB8500_PIN_C10, DB8500_PIN_B10, DB8500_PIN_B9, |
510 | DB8500_PIN_A9, DB8500_PIN_C7, DB8500_PIN_A7, DB8500_PIN_C5, | 513 | DB8500_PIN_A9, DB8500_PIN_C7, DB8500_PIN_A7, DB8500_PIN_C5, |
511 | DB8500_PIN_C9, DB8500_PIN_B14 }; | 514 | DB8500_PIN_C9 }; |
512 | /* This chip select pin can be "ps0" in alt B so have it separately */ | 515 | /* This chip select pin can be "ps0" in alt C so have it separately */ |
513 | static const unsigned smcs0_b_1_pins[] = { DB8500_PIN_E8 }; | 516 | static const unsigned smcs0_b_1_pins[] = { DB8500_PIN_E8 }; |
517 | /* This chip select pin can be "ps1" in alt C so have it separately */ | ||
518 | static const unsigned smcs1_b_1_pins[] = { DB8500_PIN_B14 }; | ||
514 | static const unsigned ipgpio7_b_1_pins[] = { DB8500_PIN_B11 }; | 519 | static const unsigned ipgpio7_b_1_pins[] = { DB8500_PIN_B11 }; |
515 | static const unsigned ipgpio2_b_1_pins[] = { DB8500_PIN_C12 }; | 520 | static const unsigned ipgpio2_b_1_pins[] = { DB8500_PIN_C12 }; |
516 | static const unsigned ipgpio3_b_1_pins[] = { DB8500_PIN_C11 }; | 521 | static const unsigned ipgpio3_b_1_pins[] = { DB8500_PIN_C11 }; |
@@ -572,6 +577,7 @@ static const unsigned mc2rstn_c_1_pins[] = { DB8500_PIN_C8 }; | |||
572 | static const unsigned kp_c_1_pins[] = { DB8500_PIN_C9, DB8500_PIN_B11, | 577 | static const unsigned kp_c_1_pins[] = { DB8500_PIN_C9, DB8500_PIN_B11, |
573 | DB8500_PIN_C12, DB8500_PIN_C11, DB8500_PIN_D17, DB8500_PIN_D16, | 578 | DB8500_PIN_C12, DB8500_PIN_C11, DB8500_PIN_D17, DB8500_PIN_D16, |
574 | DB8500_PIN_C23, DB8500_PIN_D23 }; | 579 | DB8500_PIN_C23, DB8500_PIN_D23 }; |
580 | static const unsigned smps0_c_1_pins[] = { DB8500_PIN_E8 }; | ||
575 | static const unsigned smps1_c_1_pins[] = { DB8500_PIN_B14 }; | 581 | static const unsigned smps1_c_1_pins[] = { DB8500_PIN_B14 }; |
576 | static const unsigned u2rxtx_c_3_pins[] = { DB8500_PIN_B17, DB8500_PIN_C16 }; | 582 | static const unsigned u2rxtx_c_3_pins[] = { DB8500_PIN_B17, DB8500_PIN_C16 }; |
577 | static const unsigned stmape_c_2_pins[] = { DB8500_PIN_C19, DB8500_PIN_C17, | 583 | static const unsigned stmape_c_2_pins[] = { DB8500_PIN_C19, DB8500_PIN_C17, |
@@ -595,6 +601,8 @@ static const unsigned kp_oc1_1_pins[] = { DB8500_PIN_C6, DB8500_PIN_B3, | |||
595 | DB8500_PIN_D6, DB8500_PIN_B7 }; | 601 | DB8500_PIN_D6, DB8500_PIN_B7 }; |
596 | static const unsigned spi2_oc1_1_pins[] = { DB8500_PIN_AH13, DB8500_PIN_AG12, | 602 | static const unsigned spi2_oc1_1_pins[] = { DB8500_PIN_AH13, DB8500_PIN_AG12, |
597 | DB8500_PIN_AH12, DB8500_PIN_AH11 }; | 603 | DB8500_PIN_AH12, DB8500_PIN_AH11 }; |
604 | static const unsigned spi2_oc1_2_pins[] = { DB8500_PIN_AH13, DB8500_PIN_AH12, | ||
605 | DB8500_PIN_AH11 }; | ||
598 | 606 | ||
599 | #define DB8500_PIN_GROUP(a,b) { .name = #a, .pins = a##_pins, \ | 607 | #define DB8500_PIN_GROUP(a,b) { .name = #a, .pins = a##_pins, \ |
600 | .npins = ARRAY_SIZE(a##_pins), .altsetting = b } | 608 | .npins = ARRAY_SIZE(a##_pins), .altsetting = b } |
@@ -610,6 +618,8 @@ static const struct nmk_pingroup nmk_db8500_groups[] = { | |||
610 | DB8500_PIN_GROUP(msp0tfstck_a_1, NMK_GPIO_ALT_A), | 618 | DB8500_PIN_GROUP(msp0tfstck_a_1, NMK_GPIO_ALT_A), |
611 | DB8500_PIN_GROUP(msp0rfsrck_a_1, NMK_GPIO_ALT_A), | 619 | DB8500_PIN_GROUP(msp0rfsrck_a_1, NMK_GPIO_ALT_A), |
612 | DB8500_PIN_GROUP(mc0_a_1, NMK_GPIO_ALT_A), | 620 | DB8500_PIN_GROUP(mc0_a_1, NMK_GPIO_ALT_A), |
621 | DB8500_PIN_GROUP(mc0_dat47_a_1, NMK_GPIO_ALT_A), | ||
622 | DB8500_PIN_GROUP(mc0dat31dir_a_1, NMK_GPIO_ALT_A), | ||
613 | DB8500_PIN_GROUP(msp1txrx_a_1, NMK_GPIO_ALT_A), | 623 | DB8500_PIN_GROUP(msp1txrx_a_1, NMK_GPIO_ALT_A), |
614 | DB8500_PIN_GROUP(msp1_a_1, NMK_GPIO_ALT_A), | 624 | DB8500_PIN_GROUP(msp1_a_1, NMK_GPIO_ALT_A), |
615 | DB8500_PIN_GROUP(lcdb_a_1, NMK_GPIO_ALT_A), | 625 | DB8500_PIN_GROUP(lcdb_a_1, NMK_GPIO_ALT_A), |
@@ -631,6 +641,7 @@ static const struct nmk_pingroup nmk_db8500_groups[] = { | |||
631 | DB8500_PIN_GROUP(mc1_a_1, NMK_GPIO_ALT_A), | 641 | DB8500_PIN_GROUP(mc1_a_1, NMK_GPIO_ALT_A), |
632 | DB8500_PIN_GROUP(hsir_a_1, NMK_GPIO_ALT_A), | 642 | DB8500_PIN_GROUP(hsir_a_1, NMK_GPIO_ALT_A), |
633 | DB8500_PIN_GROUP(hsit_a_1, NMK_GPIO_ALT_A), | 643 | DB8500_PIN_GROUP(hsit_a_1, NMK_GPIO_ALT_A), |
644 | DB8500_PIN_GROUP(hsit_a_2, NMK_GPIO_ALT_A), | ||
634 | DB8500_PIN_GROUP(clkout_a_1, NMK_GPIO_ALT_A), | 645 | DB8500_PIN_GROUP(clkout_a_1, NMK_GPIO_ALT_A), |
635 | DB8500_PIN_GROUP(clkout_a_2, NMK_GPIO_ALT_A), | 646 | DB8500_PIN_GROUP(clkout_a_2, NMK_GPIO_ALT_A), |
636 | DB8500_PIN_GROUP(usb_a_1, NMK_GPIO_ALT_A), | 647 | DB8500_PIN_GROUP(usb_a_1, NMK_GPIO_ALT_A), |
@@ -653,6 +664,7 @@ static const struct nmk_pingroup nmk_db8500_groups[] = { | |||
653 | DB8500_PIN_GROUP(kp_b_1, NMK_GPIO_ALT_B), | 664 | DB8500_PIN_GROUP(kp_b_1, NMK_GPIO_ALT_B), |
654 | DB8500_PIN_GROUP(sm_b_1, NMK_GPIO_ALT_B), | 665 | DB8500_PIN_GROUP(sm_b_1, NMK_GPIO_ALT_B), |
655 | DB8500_PIN_GROUP(smcs0_b_1, NMK_GPIO_ALT_B), | 666 | DB8500_PIN_GROUP(smcs0_b_1, NMK_GPIO_ALT_B), |
667 | DB8500_PIN_GROUP(smcs1_b_1, NMK_GPIO_ALT_B), | ||
656 | DB8500_PIN_GROUP(ipgpio7_b_1, NMK_GPIO_ALT_B), | 668 | DB8500_PIN_GROUP(ipgpio7_b_1, NMK_GPIO_ALT_B), |
657 | DB8500_PIN_GROUP(ipgpio2_b_1, NMK_GPIO_ALT_B), | 669 | DB8500_PIN_GROUP(ipgpio2_b_1, NMK_GPIO_ALT_B), |
658 | DB8500_PIN_GROUP(ipgpio3_b_1, NMK_GPIO_ALT_B), | 670 | DB8500_PIN_GROUP(ipgpio3_b_1, NMK_GPIO_ALT_B), |
@@ -693,6 +705,7 @@ static const struct nmk_pingroup nmk_db8500_groups[] = { | |||
693 | DB8500_PIN_GROUP(mc5_c_1, NMK_GPIO_ALT_C), | 705 | DB8500_PIN_GROUP(mc5_c_1, NMK_GPIO_ALT_C), |
694 | DB8500_PIN_GROUP(mc2rstn_c_1, NMK_GPIO_ALT_C), | 706 | DB8500_PIN_GROUP(mc2rstn_c_1, NMK_GPIO_ALT_C), |
695 | DB8500_PIN_GROUP(kp_c_1, NMK_GPIO_ALT_C), | 707 | DB8500_PIN_GROUP(kp_c_1, NMK_GPIO_ALT_C), |
708 | DB8500_PIN_GROUP(smps0_c_1, NMK_GPIO_ALT_C), | ||
696 | DB8500_PIN_GROUP(smps1_c_1, NMK_GPIO_ALT_C), | 709 | DB8500_PIN_GROUP(smps1_c_1, NMK_GPIO_ALT_C), |
697 | DB8500_PIN_GROUP(u2rxtx_c_3, NMK_GPIO_ALT_C), | 710 | DB8500_PIN_GROUP(u2rxtx_c_3, NMK_GPIO_ALT_C), |
698 | DB8500_PIN_GROUP(stmape_c_2, NMK_GPIO_ALT_C), | 711 | DB8500_PIN_GROUP(stmape_c_2, NMK_GPIO_ALT_C), |
@@ -709,6 +722,7 @@ static const struct nmk_pingroup nmk_db8500_groups[] = { | |||
709 | /* Other alt C1 column, these are still configured as alt C */ | 722 | /* Other alt C1 column, these are still configured as alt C */ |
710 | DB8500_PIN_GROUP(kp_oc1_1, NMK_GPIO_ALT_C), | 723 | DB8500_PIN_GROUP(kp_oc1_1, NMK_GPIO_ALT_C), |
711 | DB8500_PIN_GROUP(spi2_oc1_1, NMK_GPIO_ALT_C), | 724 | DB8500_PIN_GROUP(spi2_oc1_1, NMK_GPIO_ALT_C), |
725 | DB8500_PIN_GROUP(spi2_oc1_2, NMK_GPIO_ALT_C), | ||
712 | }; | 726 | }; |
713 | 727 | ||
714 | /* We use this macro to define the groups applicable to a function */ | 728 | /* We use this macro to define the groups applicable to a function */ |
@@ -731,7 +745,7 @@ DB8500_FUNC_GROUPS(ipi2c, "ipi2c_a_1", "ipi2c_a_2"); | |||
731 | */ | 745 | */ |
732 | DB8500_FUNC_GROUPS(msp0, "msp0txrx_a_1", "msp0tfstck_a_1", "msp0rfstck_a_1", | 746 | DB8500_FUNC_GROUPS(msp0, "msp0txrx_a_1", "msp0tfstck_a_1", "msp0rfstck_a_1", |
733 | "msp0txrx_b_1", "msp0sck_b_1"); | 747 | "msp0txrx_b_1", "msp0sck_b_1"); |
734 | DB8500_FUNC_GROUPS(mc0, "mc0_a_1"); | 748 | DB8500_FUNC_GROUPS(mc0, "mc0_a_1", "mc0_dat47_a_1", "mc0dat31dir_a_1"); |
735 | /* MSP0 can swap RX/TX like MSP0 but has no SCK pin available */ | 749 | /* MSP0 can swap RX/TX like MSP0 but has no SCK pin available */ |
736 | DB8500_FUNC_GROUPS(msp1, "msp1txrx_a_1", "msp1_a_1", "msp1txrx_b_1"); | 750 | DB8500_FUNC_GROUPS(msp1, "msp1txrx_a_1", "msp1_a_1", "msp1txrx_b_1"); |
737 | DB8500_FUNC_GROUPS(lcdb, "lcdb_a_1"); | 751 | DB8500_FUNC_GROUPS(lcdb, "lcdb_a_1"); |
@@ -752,7 +766,7 @@ DB8500_FUNC_GROUPS(ipgpio, "ipgpio0_a_1", "ipgpio1_a_1", "ipgpio7_b_1", | |||
752 | DB8500_FUNC_GROUPS(msp2, "msp2sck_a_1", "msp2_a_1"); | 766 | DB8500_FUNC_GROUPS(msp2, "msp2sck_a_1", "msp2_a_1"); |
753 | DB8500_FUNC_GROUPS(mc4, "mc4_a_1", "mc4rstn_c_1"); | 767 | DB8500_FUNC_GROUPS(mc4, "mc4_a_1", "mc4rstn_c_1"); |
754 | DB8500_FUNC_GROUPS(mc1, "mc1_a_1", "mc1dir_a_1"); | 768 | DB8500_FUNC_GROUPS(mc1, "mc1_a_1", "mc1dir_a_1"); |
755 | DB8500_FUNC_GROUPS(hsi, "hsir1_a_1", "hsit1_a_1"); | 769 | DB8500_FUNC_GROUPS(hsi, "hsir1_a_1", "hsit1_a_1", "hsit_a_2"); |
756 | DB8500_FUNC_GROUPS(clkout, "clkout_a_1", "clkout_a_2", "clkout_c_1"); | 770 | DB8500_FUNC_GROUPS(clkout, "clkout_a_1", "clkout_a_2", "clkout_c_1"); |
757 | DB8500_FUNC_GROUPS(usb, "usb_a_1"); | 771 | DB8500_FUNC_GROUPS(usb, "usb_a_1"); |
758 | DB8500_FUNC_GROUPS(trig, "trig_b_1"); | 772 | DB8500_FUNC_GROUPS(trig, "trig_b_1"); |
@@ -768,7 +782,8 @@ DB8500_FUNC_GROUPS(uartmod, "uartmodtx_b_1", "uartmodrx_b_1", "uartmodrx_b_2", | |||
768 | DB8500_FUNC_GROUPS(stmmod, "stmmod_b_1", "stmmod_c_1"); | 782 | DB8500_FUNC_GROUPS(stmmod, "stmmod_b_1", "stmmod_c_1"); |
769 | DB8500_FUNC_GROUPS(spi3, "spi3_b_1"); | 783 | DB8500_FUNC_GROUPS(spi3, "spi3_b_1"); |
770 | /* Select between CS0 on alt B or PS1 on alt C */ | 784 | /* Select between CS0 on alt B or PS1 on alt C */ |
771 | DB8500_FUNC_GROUPS(sm, "sm_b_1", "smcs0_b_1", "smcleale_c_1", "smps1_c_1"); | 785 | DB8500_FUNC_GROUPS(sm, "sm_b_1", "smcs0_b_1", "smcs1_b_1", "smcleale_c_1", |
786 | "smps0_c_1", "smps1_c_1"); | ||
772 | DB8500_FUNC_GROUPS(lcda, "lcdaclk_b_1", "lcda_b_1"); | 787 | DB8500_FUNC_GROUPS(lcda, "lcdaclk_b_1", "lcda_b_1"); |
773 | DB8500_FUNC_GROUPS(ddrtrig, "ddrtrig_b_1"); | 788 | DB8500_FUNC_GROUPS(ddrtrig, "ddrtrig_b_1"); |
774 | DB8500_FUNC_GROUPS(pwl, "pwl_b_1", "pwl_b_2", "pwl_b_3", "pwl_b_4"); | 789 | DB8500_FUNC_GROUPS(pwl, "pwl_b_1", "pwl_b_2", "pwl_b_3", "pwl_b_4"); |
@@ -783,7 +798,7 @@ DB8500_FUNC_GROUPS(mc5, "mc5_c_1"); | |||
783 | DB8500_FUNC_GROUPS(usbsim, "usbsim_c_1", "usbsim_c_2"); | 798 | DB8500_FUNC_GROUPS(usbsim, "usbsim_c_1", "usbsim_c_2"); |
784 | DB8500_FUNC_GROUPS(i2c3, "i2c3_c_1", "i2c3_c_2"); | 799 | DB8500_FUNC_GROUPS(i2c3, "i2c3_c_1", "i2c3_c_2"); |
785 | DB8500_FUNC_GROUPS(spi0, "spi0_c_1"); | 800 | DB8500_FUNC_GROUPS(spi0, "spi0_c_1"); |
786 | DB8500_FUNC_GROUPS(spi2, "spi2_oc1_1"); | 801 | DB8500_FUNC_GROUPS(spi2, "spi2_oc1_1", "spi2_oc1_2"); |
787 | 802 | ||
788 | #define FUNCTION(fname) \ | 803 | #define FUNCTION(fname) \ |
789 | { \ | 804 | { \ |
diff --git a/drivers/pinctrl/pinctrl-nomadik.c b/drivers/pinctrl/pinctrl-nomadik.c index dd9e6f26416d..53b0d49a7a1c 100644 --- a/drivers/pinctrl/pinctrl-nomadik.c +++ b/drivers/pinctrl/pinctrl-nomadik.c | |||
@@ -434,7 +434,7 @@ static int __nmk_config_pins(pin_cfg_t *cfgs, int num, bool sleep) | |||
434 | /** | 434 | /** |
435 | * nmk_config_pin - configure a pin's mux attributes | 435 | * nmk_config_pin - configure a pin's mux attributes |
436 | * @cfg: pin confguration | 436 | * @cfg: pin confguration |
437 | * | 437 | * @sleep: Non-zero to apply the sleep mode configuration |
438 | * Configures a pin's mode (alternate function or GPIO), its pull up status, | 438 | * Configures a pin's mode (alternate function or GPIO), its pull up status, |
439 | * and its sleep mode based on the specified configuration. The @cfg is | 439 | * and its sleep mode based on the specified configuration. The @cfg is |
440 | * usually one of the SoC specific macros defined in mach/<soc>-pins.h. These | 440 | * usually one of the SoC specific macros defined in mach/<soc>-pins.h. These |
@@ -1194,7 +1194,7 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev) | |||
1194 | } | 1194 | } |
1195 | 1195 | ||
1196 | if (np) { | 1196 | if (np) { |
1197 | pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); | 1197 | pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL); |
1198 | if (!pdata) | 1198 | if (!pdata) |
1199 | return -ENOMEM; | 1199 | return -ENOMEM; |
1200 | 1200 | ||
@@ -1229,29 +1229,23 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev) | |||
1229 | goto out; | 1229 | goto out; |
1230 | } | 1230 | } |
1231 | 1231 | ||
1232 | if (request_mem_region(res->start, resource_size(res), | 1232 | base = devm_request_and_ioremap(&dev->dev, res); |
1233 | dev_name(&dev->dev)) == NULL) { | ||
1234 | ret = -EBUSY; | ||
1235 | goto out; | ||
1236 | } | ||
1237 | |||
1238 | base = ioremap(res->start, resource_size(res)); | ||
1239 | if (!base) { | 1233 | if (!base) { |
1240 | ret = -ENOMEM; | 1234 | ret = -ENOMEM; |
1241 | goto out_release; | 1235 | goto out; |
1242 | } | 1236 | } |
1243 | 1237 | ||
1244 | clk = clk_get(&dev->dev, NULL); | 1238 | clk = devm_clk_get(&dev->dev, NULL); |
1245 | if (IS_ERR(clk)) { | 1239 | if (IS_ERR(clk)) { |
1246 | ret = PTR_ERR(clk); | 1240 | ret = PTR_ERR(clk); |
1247 | goto out_unmap; | 1241 | goto out; |
1248 | } | 1242 | } |
1249 | clk_prepare(clk); | 1243 | clk_prepare(clk); |
1250 | 1244 | ||
1251 | nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL); | 1245 | nmk_chip = devm_kzalloc(&dev->dev, sizeof(*nmk_chip), GFP_KERNEL); |
1252 | if (!nmk_chip) { | 1246 | if (!nmk_chip) { |
1253 | ret = -ENOMEM; | 1247 | ret = -ENOMEM; |
1254 | goto out_clk; | 1248 | goto out; |
1255 | } | 1249 | } |
1256 | 1250 | ||
1257 | /* | 1251 | /* |
@@ -1286,7 +1280,7 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev) | |||
1286 | 1280 | ||
1287 | ret = gpiochip_add(&nmk_chip->chip); | 1281 | ret = gpiochip_add(&nmk_chip->chip); |
1288 | if (ret) | 1282 | if (ret) |
1289 | goto out_free; | 1283 | goto out; |
1290 | 1284 | ||
1291 | BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips)); | 1285 | BUG_ON(nmk_chip->bank >= ARRAY_SIZE(nmk_gpio_chips)); |
1292 | 1286 | ||
@@ -1300,7 +1294,7 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev) | |||
1300 | if (!nmk_chip->domain) { | 1294 | if (!nmk_chip->domain) { |
1301 | pr_err("%s: Failed to create irqdomain\n", np->full_name); | 1295 | pr_err("%s: Failed to create irqdomain\n", np->full_name); |
1302 | ret = -ENOSYS; | 1296 | ret = -ENOSYS; |
1303 | goto out_free; | 1297 | goto out; |
1304 | } | 1298 | } |
1305 | 1299 | ||
1306 | nmk_gpio_init_irq(nmk_chip); | 1300 | nmk_gpio_init_irq(nmk_chip); |
@@ -1309,20 +1303,9 @@ static int __devinit nmk_gpio_probe(struct platform_device *dev) | |||
1309 | 1303 | ||
1310 | return 0; | 1304 | return 0; |
1311 | 1305 | ||
1312 | out_free: | ||
1313 | kfree(nmk_chip); | ||
1314 | out_clk: | ||
1315 | clk_disable(clk); | ||
1316 | clk_put(clk); | ||
1317 | out_unmap: | ||
1318 | iounmap(base); | ||
1319 | out_release: | ||
1320 | release_mem_region(res->start, resource_size(res)); | ||
1321 | out: | 1306 | out: |
1322 | dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret, | 1307 | dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret, |
1323 | pdata->first_gpio, pdata->first_gpio+31); | 1308 | pdata->first_gpio, pdata->first_gpio+31); |
1324 | if (np) | ||
1325 | kfree(pdata); | ||
1326 | 1309 | ||
1327 | return ret; | 1310 | return ret; |
1328 | } | 1311 | } |
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c new file mode 100644 index 000000000000..76a4260f20f3 --- /dev/null +++ b/drivers/pinctrl/pinctrl-single.c | |||
@@ -0,0 +1,987 @@ | |||
1 | /* | ||
2 | * Generic device tree based pinctrl driver for one register per pin | ||
3 | * type pinmux controllers | ||
4 | * | ||
5 | * Copyright (C) 2012 Texas Instruments, Inc. | ||
6 | * | ||
7 | * This file is licensed under the terms of the GNU General Public | ||
8 | * License version 2. This program is licensed "as is" without any | ||
9 | * warranty of any kind, whether express or implied. | ||
10 | */ | ||
11 | |||
12 | #include <linux/init.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/io.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/list.h> | ||
18 | |||
19 | #include <linux/of.h> | ||
20 | #include <linux/of_device.h> | ||
21 | #include <linux/of_address.h> | ||
22 | |||
23 | #include <linux/pinctrl/pinctrl.h> | ||
24 | #include <linux/pinctrl/pinmux.h> | ||
25 | |||
26 | #include "core.h" | ||
27 | |||
28 | #define DRIVER_NAME "pinctrl-single" | ||
29 | #define PCS_MUX_NAME "pinctrl-single,pins" | ||
30 | #define PCS_REG_NAME_LEN ((sizeof(unsigned long) * 2) + 1) | ||
31 | #define PCS_OFF_DISABLED ~0U | ||
32 | |||
33 | /** | ||
34 | * struct pcs_pingroup - pingroups for a function | ||
35 | * @np: pingroup device node pointer | ||
36 | * @name: pingroup name | ||
37 | * @gpins: array of the pins in the group | ||
38 | * @ngpins: number of pins in the group | ||
39 | * @node: list node | ||
40 | */ | ||
41 | struct pcs_pingroup { | ||
42 | struct device_node *np; | ||
43 | const char *name; | ||
44 | int *gpins; | ||
45 | int ngpins; | ||
46 | struct list_head node; | ||
47 | }; | ||
48 | |||
49 | /** | ||
50 | * struct pcs_func_vals - mux function register offset and value pair | ||
51 | * @reg: register virtual address | ||
52 | * @val: register value | ||
53 | */ | ||
54 | struct pcs_func_vals { | ||
55 | void __iomem *reg; | ||
56 | unsigned val; | ||
57 | }; | ||
58 | |||
59 | /** | ||
60 | * struct pcs_function - pinctrl function | ||
61 | * @name: pinctrl function name | ||
62 | * @vals: register and vals array | ||
63 | * @nvals: number of entries in vals array | ||
64 | * @pgnames: array of pingroup names the function uses | ||
65 | * @npgnames: number of pingroup names the function uses | ||
66 | * @node: list node | ||
67 | */ | ||
68 | struct pcs_function { | ||
69 | const char *name; | ||
70 | struct pcs_func_vals *vals; | ||
71 | unsigned nvals; | ||
72 | const char **pgnames; | ||
73 | int npgnames; | ||
74 | struct list_head node; | ||
75 | }; | ||
76 | |||
77 | /** | ||
78 | * struct pcs_data - wrapper for data needed by pinctrl framework | ||
79 | * @pa: pindesc array | ||
80 | * @cur: index to current element | ||
81 | * | ||
82 | * REVISIT: We should be able to drop this eventually by adding | ||
83 | * support for registering pins individually in the pinctrl | ||
84 | * framework for those drivers that don't need a static array. | ||
85 | */ | ||
86 | struct pcs_data { | ||
87 | struct pinctrl_pin_desc *pa; | ||
88 | int cur; | ||
89 | }; | ||
90 | |||
91 | /** | ||
92 | * struct pcs_name - register name for a pin | ||
93 | * @name: name of the pinctrl register | ||
94 | * | ||
95 | * REVISIT: We may want to make names optional in the pinctrl | ||
96 | * framework as some drivers may not care about pin names to | ||
97 | * avoid kernel bloat. The pin names can be deciphered by user | ||
98 | * space tools using debugfs based on the register address and | ||
99 | * SoC packaging information. | ||
100 | */ | ||
101 | struct pcs_name { | ||
102 | char name[PCS_REG_NAME_LEN]; | ||
103 | }; | ||
104 | |||
105 | /** | ||
106 | * struct pcs_device - pinctrl device instance | ||
107 | * @res: resources | ||
108 | * @base: virtual address of the controller | ||
109 | * @size: size of the ioremapped area | ||
110 | * @dev: device entry | ||
111 | * @pctl: pin controller device | ||
112 | * @mutex: mutex protecting the lists | ||
113 | * @width: bits per mux register | ||
114 | * @fmask: function register mask | ||
115 | * @fshift: function register shift | ||
116 | * @foff: value to turn mux off | ||
117 | * @fmax: max number of functions in fmask | ||
118 | * @names: array of register names for pins | ||
119 | * @pins: physical pins on the SoC | ||
120 | * @pgtree: pingroup index radix tree | ||
121 | * @ftree: function index radix tree | ||
122 | * @pingroups: list of pingroups | ||
123 | * @functions: list of functions | ||
124 | * @ngroups: number of pingroups | ||
125 | * @nfuncs: number of functions | ||
126 | * @desc: pin controller descriptor | ||
127 | * @read: register read function to use | ||
128 | * @write: register write function to use | ||
129 | */ | ||
130 | struct pcs_device { | ||
131 | struct resource *res; | ||
132 | void __iomem *base; | ||
133 | unsigned size; | ||
134 | struct device *dev; | ||
135 | struct pinctrl_dev *pctl; | ||
136 | struct mutex mutex; | ||
137 | unsigned width; | ||
138 | unsigned fmask; | ||
139 | unsigned fshift; | ||
140 | unsigned foff; | ||
141 | unsigned fmax; | ||
142 | struct pcs_name *names; | ||
143 | struct pcs_data pins; | ||
144 | struct radix_tree_root pgtree; | ||
145 | struct radix_tree_root ftree; | ||
146 | struct list_head pingroups; | ||
147 | struct list_head functions; | ||
148 | unsigned ngroups; | ||
149 | unsigned nfuncs; | ||
150 | struct pinctrl_desc desc; | ||
151 | unsigned (*read)(void __iomem *reg); | ||
152 | void (*write)(unsigned val, void __iomem *reg); | ||
153 | }; | ||
154 | |||
155 | /* | ||
156 | * REVISIT: Reads and writes could eventually use regmap or something | ||
157 | * generic. But at least on omaps, some mux registers are performance | ||
158 | * critical as they may need to be remuxed every time before and after | ||
159 | * idle. Adding tests for register access width for every read and | ||
160 | * write like regmap is doing is not desired, and caching the registers | ||
161 | * does not help in this case. | ||
162 | */ | ||
163 | |||
164 | static unsigned __maybe_unused pcs_readb(void __iomem *reg) | ||
165 | { | ||
166 | return readb(reg); | ||
167 | } | ||
168 | |||
169 | static unsigned __maybe_unused pcs_readw(void __iomem *reg) | ||
170 | { | ||
171 | return readw(reg); | ||
172 | } | ||
173 | |||
174 | static unsigned __maybe_unused pcs_readl(void __iomem *reg) | ||
175 | { | ||
176 | return readl(reg); | ||
177 | } | ||
178 | |||
179 | static void __maybe_unused pcs_writeb(unsigned val, void __iomem *reg) | ||
180 | { | ||
181 | writeb(val, reg); | ||
182 | } | ||
183 | |||
184 | static void __maybe_unused pcs_writew(unsigned val, void __iomem *reg) | ||
185 | { | ||
186 | writew(val, reg); | ||
187 | } | ||
188 | |||
189 | static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg) | ||
190 | { | ||
191 | writel(val, reg); | ||
192 | } | ||
193 | |||
194 | static int pcs_get_groups_count(struct pinctrl_dev *pctldev) | ||
195 | { | ||
196 | struct pcs_device *pcs; | ||
197 | |||
198 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
199 | |||
200 | return pcs->ngroups; | ||
201 | } | ||
202 | |||
203 | static const char *pcs_get_group_name(struct pinctrl_dev *pctldev, | ||
204 | unsigned gselector) | ||
205 | { | ||
206 | struct pcs_device *pcs; | ||
207 | struct pcs_pingroup *group; | ||
208 | |||
209 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
210 | group = radix_tree_lookup(&pcs->pgtree, gselector); | ||
211 | if (!group) { | ||
212 | dev_err(pcs->dev, "%s could not find pingroup%i\n", | ||
213 | __func__, gselector); | ||
214 | return NULL; | ||
215 | } | ||
216 | |||
217 | return group->name; | ||
218 | } | ||
219 | |||
220 | static int pcs_get_group_pins(struct pinctrl_dev *pctldev, | ||
221 | unsigned gselector, | ||
222 | const unsigned **pins, | ||
223 | unsigned *npins) | ||
224 | { | ||
225 | struct pcs_device *pcs; | ||
226 | struct pcs_pingroup *group; | ||
227 | |||
228 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
229 | group = radix_tree_lookup(&pcs->pgtree, gselector); | ||
230 | if (!group) { | ||
231 | dev_err(pcs->dev, "%s could not find pingroup%i\n", | ||
232 | __func__, gselector); | ||
233 | return -EINVAL; | ||
234 | } | ||
235 | |||
236 | *pins = group->gpins; | ||
237 | *npins = group->ngpins; | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev, | ||
243 | struct seq_file *s, | ||
244 | unsigned offset) | ||
245 | { | ||
246 | seq_printf(s, " " DRIVER_NAME); | ||
247 | } | ||
248 | |||
249 | static void pcs_dt_free_map(struct pinctrl_dev *pctldev, | ||
250 | struct pinctrl_map *map, unsigned num_maps) | ||
251 | { | ||
252 | struct pcs_device *pcs; | ||
253 | |||
254 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
255 | devm_kfree(pcs->dev, map); | ||
256 | } | ||
257 | |||
258 | static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev, | ||
259 | struct device_node *np_config, | ||
260 | struct pinctrl_map **map, unsigned *num_maps); | ||
261 | |||
262 | static struct pinctrl_ops pcs_pinctrl_ops = { | ||
263 | .get_groups_count = pcs_get_groups_count, | ||
264 | .get_group_name = pcs_get_group_name, | ||
265 | .get_group_pins = pcs_get_group_pins, | ||
266 | .pin_dbg_show = pcs_pin_dbg_show, | ||
267 | .dt_node_to_map = pcs_dt_node_to_map, | ||
268 | .dt_free_map = pcs_dt_free_map, | ||
269 | }; | ||
270 | |||
271 | static int pcs_get_functions_count(struct pinctrl_dev *pctldev) | ||
272 | { | ||
273 | struct pcs_device *pcs; | ||
274 | |||
275 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
276 | |||
277 | return pcs->nfuncs; | ||
278 | } | ||
279 | |||
280 | static const char *pcs_get_function_name(struct pinctrl_dev *pctldev, | ||
281 | unsigned fselector) | ||
282 | { | ||
283 | struct pcs_device *pcs; | ||
284 | struct pcs_function *func; | ||
285 | |||
286 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
287 | func = radix_tree_lookup(&pcs->ftree, fselector); | ||
288 | if (!func) { | ||
289 | dev_err(pcs->dev, "%s could not find function%i\n", | ||
290 | __func__, fselector); | ||
291 | return NULL; | ||
292 | } | ||
293 | |||
294 | return func->name; | ||
295 | } | ||
296 | |||
297 | static int pcs_get_function_groups(struct pinctrl_dev *pctldev, | ||
298 | unsigned fselector, | ||
299 | const char * const **groups, | ||
300 | unsigned * const ngroups) | ||
301 | { | ||
302 | struct pcs_device *pcs; | ||
303 | struct pcs_function *func; | ||
304 | |||
305 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
306 | func = radix_tree_lookup(&pcs->ftree, fselector); | ||
307 | if (!func) { | ||
308 | dev_err(pcs->dev, "%s could not find function%i\n", | ||
309 | __func__, fselector); | ||
310 | return -EINVAL; | ||
311 | } | ||
312 | *groups = func->pgnames; | ||
313 | *ngroups = func->npgnames; | ||
314 | |||
315 | return 0; | ||
316 | } | ||
317 | |||
318 | static int pcs_enable(struct pinctrl_dev *pctldev, unsigned fselector, | ||
319 | unsigned group) | ||
320 | { | ||
321 | struct pcs_device *pcs; | ||
322 | struct pcs_function *func; | ||
323 | int i; | ||
324 | |||
325 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
326 | func = radix_tree_lookup(&pcs->ftree, fselector); | ||
327 | if (!func) | ||
328 | return -EINVAL; | ||
329 | |||
330 | dev_dbg(pcs->dev, "enabling %s function%i\n", | ||
331 | func->name, fselector); | ||
332 | |||
333 | for (i = 0; i < func->nvals; i++) { | ||
334 | struct pcs_func_vals *vals; | ||
335 | unsigned val; | ||
336 | |||
337 | vals = &func->vals[i]; | ||
338 | val = pcs->read(vals->reg); | ||
339 | val &= ~pcs->fmask; | ||
340 | val |= vals->val; | ||
341 | pcs->write(val, vals->reg); | ||
342 | } | ||
343 | |||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | static void pcs_disable(struct pinctrl_dev *pctldev, unsigned fselector, | ||
348 | unsigned group) | ||
349 | { | ||
350 | struct pcs_device *pcs; | ||
351 | struct pcs_function *func; | ||
352 | int i; | ||
353 | |||
354 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
355 | func = radix_tree_lookup(&pcs->ftree, fselector); | ||
356 | if (!func) { | ||
357 | dev_err(pcs->dev, "%s could not find function%i\n", | ||
358 | __func__, fselector); | ||
359 | return; | ||
360 | } | ||
361 | |||
362 | /* | ||
363 | * Ignore disable if function-off is not specified. Some hardware | ||
364 | * does not have clearly defined disable function. For pin specific | ||
365 | * off modes, you can use alternate named states as described in | ||
366 | * pinctrl-bindings.txt. | ||
367 | */ | ||
368 | if (pcs->foff == PCS_OFF_DISABLED) { | ||
369 | dev_dbg(pcs->dev, "ignoring disable for %s function%i\n", | ||
370 | func->name, fselector); | ||
371 | return; | ||
372 | } | ||
373 | |||
374 | dev_dbg(pcs->dev, "disabling function%i %s\n", | ||
375 | fselector, func->name); | ||
376 | |||
377 | for (i = 0; i < func->nvals; i++) { | ||
378 | struct pcs_func_vals *vals; | ||
379 | unsigned val; | ||
380 | |||
381 | vals = &func->vals[i]; | ||
382 | val = pcs->read(vals->reg); | ||
383 | val &= ~pcs->fmask; | ||
384 | val |= pcs->foff << pcs->fshift; | ||
385 | pcs->write(val, vals->reg); | ||
386 | } | ||
387 | } | ||
388 | |||
389 | static int pcs_request_gpio(struct pinctrl_dev *pctldev, | ||
390 | struct pinctrl_gpio_range *range, unsigned offset) | ||
391 | { | ||
392 | return -ENOTSUPP; | ||
393 | } | ||
394 | |||
395 | static struct pinmux_ops pcs_pinmux_ops = { | ||
396 | .get_functions_count = pcs_get_functions_count, | ||
397 | .get_function_name = pcs_get_function_name, | ||
398 | .get_function_groups = pcs_get_function_groups, | ||
399 | .enable = pcs_enable, | ||
400 | .disable = pcs_disable, | ||
401 | .gpio_request_enable = pcs_request_gpio, | ||
402 | }; | ||
403 | |||
404 | static int pcs_pinconf_get(struct pinctrl_dev *pctldev, | ||
405 | unsigned pin, unsigned long *config) | ||
406 | { | ||
407 | return -ENOTSUPP; | ||
408 | } | ||
409 | |||
410 | static int pcs_pinconf_set(struct pinctrl_dev *pctldev, | ||
411 | unsigned pin, unsigned long config) | ||
412 | { | ||
413 | return -ENOTSUPP; | ||
414 | } | ||
415 | |||
416 | static int pcs_pinconf_group_get(struct pinctrl_dev *pctldev, | ||
417 | unsigned group, unsigned long *config) | ||
418 | { | ||
419 | return -ENOTSUPP; | ||
420 | } | ||
421 | |||
422 | static int pcs_pinconf_group_set(struct pinctrl_dev *pctldev, | ||
423 | unsigned group, unsigned long config) | ||
424 | { | ||
425 | return -ENOTSUPP; | ||
426 | } | ||
427 | |||
428 | static void pcs_pinconf_dbg_show(struct pinctrl_dev *pctldev, | ||
429 | struct seq_file *s, unsigned offset) | ||
430 | { | ||
431 | } | ||
432 | |||
433 | static void pcs_pinconf_group_dbg_show(struct pinctrl_dev *pctldev, | ||
434 | struct seq_file *s, unsigned selector) | ||
435 | { | ||
436 | } | ||
437 | |||
438 | static struct pinconf_ops pcs_pinconf_ops = { | ||
439 | .pin_config_get = pcs_pinconf_get, | ||
440 | .pin_config_set = pcs_pinconf_set, | ||
441 | .pin_config_group_get = pcs_pinconf_group_get, | ||
442 | .pin_config_group_set = pcs_pinconf_group_set, | ||
443 | .pin_config_dbg_show = pcs_pinconf_dbg_show, | ||
444 | .pin_config_group_dbg_show = pcs_pinconf_group_dbg_show, | ||
445 | }; | ||
446 | |||
447 | /** | ||
448 | * pcs_add_pin() - add a pin to the static per controller pin array | ||
449 | * @pcs: pcs driver instance | ||
450 | * @offset: register offset from base | ||
451 | */ | ||
452 | static int __devinit pcs_add_pin(struct pcs_device *pcs, unsigned offset) | ||
453 | { | ||
454 | struct pinctrl_pin_desc *pin; | ||
455 | struct pcs_name *pn; | ||
456 | int i; | ||
457 | |||
458 | i = pcs->pins.cur; | ||
459 | if (i >= pcs->desc.npins) { | ||
460 | dev_err(pcs->dev, "too many pins, max %i\n", | ||
461 | pcs->desc.npins); | ||
462 | return -ENOMEM; | ||
463 | } | ||
464 | |||
465 | pin = &pcs->pins.pa[i]; | ||
466 | pn = &pcs->names[i]; | ||
467 | sprintf(pn->name, "%lx", | ||
468 | (unsigned long)pcs->res->start + offset); | ||
469 | pin->name = pn->name; | ||
470 | pin->number = i; | ||
471 | pcs->pins.cur++; | ||
472 | |||
473 | return i; | ||
474 | } | ||
475 | |||
476 | /** | ||
477 | * pcs_allocate_pin_table() - adds all the pins for the pinctrl driver | ||
478 | * @pcs: pcs driver instance | ||
479 | * | ||
480 | * In case of errors, resources are freed in pcs_free_resources. | ||
481 | * | ||
482 | * If your hardware needs holes in the address space, then just set | ||
483 | * up multiple driver instances. | ||
484 | */ | ||
485 | static int __devinit pcs_allocate_pin_table(struct pcs_device *pcs) | ||
486 | { | ||
487 | int mux_bytes, nr_pins, i; | ||
488 | |||
489 | mux_bytes = pcs->width / BITS_PER_BYTE; | ||
490 | nr_pins = pcs->size / mux_bytes; | ||
491 | |||
492 | dev_dbg(pcs->dev, "allocating %i pins\n", nr_pins); | ||
493 | pcs->pins.pa = devm_kzalloc(pcs->dev, | ||
494 | sizeof(*pcs->pins.pa) * nr_pins, | ||
495 | GFP_KERNEL); | ||
496 | if (!pcs->pins.pa) | ||
497 | return -ENOMEM; | ||
498 | |||
499 | pcs->names = devm_kzalloc(pcs->dev, | ||
500 | sizeof(struct pcs_name) * nr_pins, | ||
501 | GFP_KERNEL); | ||
502 | if (!pcs->names) | ||
503 | return -ENOMEM; | ||
504 | |||
505 | pcs->desc.pins = pcs->pins.pa; | ||
506 | pcs->desc.npins = nr_pins; | ||
507 | |||
508 | for (i = 0; i < pcs->desc.npins; i++) { | ||
509 | unsigned offset; | ||
510 | int res; | ||
511 | |||
512 | offset = i * mux_bytes; | ||
513 | res = pcs_add_pin(pcs, offset); | ||
514 | if (res < 0) { | ||
515 | dev_err(pcs->dev, "error adding pins: %i\n", res); | ||
516 | return res; | ||
517 | } | ||
518 | } | ||
519 | |||
520 | return 0; | ||
521 | } | ||
522 | |||
523 | /** | ||
524 | * pcs_add_function() - adds a new function to the function list | ||
525 | * @pcs: pcs driver instance | ||
526 | * @np: device node of the mux entry | ||
527 | * @name: name of the function | ||
528 | * @vals: array of mux register value pairs used by the function | ||
529 | * @nvals: number of mux register value pairs | ||
530 | * @pgnames: array of pingroup names for the function | ||
531 | * @npgnames: number of pingroup names | ||
532 | */ | ||
533 | static struct pcs_function *pcs_add_function(struct pcs_device *pcs, | ||
534 | struct device_node *np, | ||
535 | const char *name, | ||
536 | struct pcs_func_vals *vals, | ||
537 | unsigned nvals, | ||
538 | const char **pgnames, | ||
539 | unsigned npgnames) | ||
540 | { | ||
541 | struct pcs_function *function; | ||
542 | |||
543 | function = devm_kzalloc(pcs->dev, sizeof(*function), GFP_KERNEL); | ||
544 | if (!function) | ||
545 | return NULL; | ||
546 | |||
547 | function->name = name; | ||
548 | function->vals = vals; | ||
549 | function->nvals = nvals; | ||
550 | function->pgnames = pgnames; | ||
551 | function->npgnames = npgnames; | ||
552 | |||
553 | mutex_lock(&pcs->mutex); | ||
554 | list_add_tail(&function->node, &pcs->functions); | ||
555 | radix_tree_insert(&pcs->ftree, pcs->nfuncs, function); | ||
556 | pcs->nfuncs++; | ||
557 | mutex_unlock(&pcs->mutex); | ||
558 | |||
559 | return function; | ||
560 | } | ||
561 | |||
562 | static void pcs_remove_function(struct pcs_device *pcs, | ||
563 | struct pcs_function *function) | ||
564 | { | ||
565 | int i; | ||
566 | |||
567 | mutex_lock(&pcs->mutex); | ||
568 | for (i = 0; i < pcs->nfuncs; i++) { | ||
569 | struct pcs_function *found; | ||
570 | |||
571 | found = radix_tree_lookup(&pcs->ftree, i); | ||
572 | if (found == function) | ||
573 | radix_tree_delete(&pcs->ftree, i); | ||
574 | } | ||
575 | list_del(&function->node); | ||
576 | mutex_unlock(&pcs->mutex); | ||
577 | } | ||
578 | |||
579 | /** | ||
580 | * pcs_add_pingroup() - add a pingroup to the pingroup list | ||
581 | * @pcs: pcs driver instance | ||
582 | * @np: device node of the mux entry | ||
583 | * @name: name of the pingroup | ||
584 | * @gpins: array of the pins that belong to the group | ||
585 | * @ngpins: number of pins in the group | ||
586 | */ | ||
587 | static int pcs_add_pingroup(struct pcs_device *pcs, | ||
588 | struct device_node *np, | ||
589 | const char *name, | ||
590 | int *gpins, | ||
591 | int ngpins) | ||
592 | { | ||
593 | struct pcs_pingroup *pingroup; | ||
594 | |||
595 | pingroup = devm_kzalloc(pcs->dev, sizeof(*pingroup), GFP_KERNEL); | ||
596 | if (!pingroup) | ||
597 | return -ENOMEM; | ||
598 | |||
599 | pingroup->name = name; | ||
600 | pingroup->np = np; | ||
601 | pingroup->gpins = gpins; | ||
602 | pingroup->ngpins = ngpins; | ||
603 | |||
604 | mutex_lock(&pcs->mutex); | ||
605 | list_add_tail(&pingroup->node, &pcs->pingroups); | ||
606 | radix_tree_insert(&pcs->pgtree, pcs->ngroups, pingroup); | ||
607 | pcs->ngroups++; | ||
608 | mutex_unlock(&pcs->mutex); | ||
609 | |||
610 | return 0; | ||
611 | } | ||
612 | |||
613 | /** | ||
614 | * pcs_get_pin_by_offset() - get a pin index based on the register offset | ||
615 | * @pcs: pcs driver instance | ||
616 | * @offset: register offset from the base | ||
617 | * | ||
618 | * Note that this is OK as long as the pins are in a static array. | ||
619 | */ | ||
620 | static int pcs_get_pin_by_offset(struct pcs_device *pcs, unsigned offset) | ||
621 | { | ||
622 | unsigned index; | ||
623 | |||
624 | if (offset >= pcs->size) { | ||
625 | dev_err(pcs->dev, "mux offset out of range: 0x%x (0x%x)\n", | ||
626 | offset, pcs->size); | ||
627 | return -EINVAL; | ||
628 | } | ||
629 | |||
630 | index = offset / (pcs->width / BITS_PER_BYTE); | ||
631 | |||
632 | return index; | ||
633 | } | ||
634 | |||
635 | /** | ||
636 | * smux_parse_one_pinctrl_entry() - parses a device tree mux entry | ||
637 | * @pcs: pinctrl driver instance | ||
638 | * @np: device node of the mux entry | ||
639 | * @map: map entry | ||
640 | * @pgnames: pingroup names | ||
641 | * | ||
642 | * Note that this binding currently supports only sets of one register + value. | ||
643 | * | ||
644 | * Also note that this driver tries to avoid understanding pin and function | ||
645 | * names because of the extra bloat they would cause especially in the case of | ||
646 | * a large number of pins. This driver just sets what is specified for the board | ||
647 | * in the .dts file. Further user space debugging tools can be developed to | ||
648 | * decipher the pin and function names using debugfs. | ||
649 | * | ||
650 | * If you are concerned about the boot time, set up the static pins in | ||
651 | * the bootloader, and only set up selected pins as device tree entries. | ||
652 | */ | ||
653 | static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs, | ||
654 | struct device_node *np, | ||
655 | struct pinctrl_map **map, | ||
656 | const char **pgnames) | ||
657 | { | ||
658 | struct pcs_func_vals *vals; | ||
659 | const __be32 *mux; | ||
660 | int size, rows, *pins, index = 0, found = 0, res = -ENOMEM; | ||
661 | struct pcs_function *function; | ||
662 | |||
663 | mux = of_get_property(np, PCS_MUX_NAME, &size); | ||
664 | if ((!mux) || (size < sizeof(*mux) * 2)) { | ||
665 | dev_err(pcs->dev, "bad data for mux %s\n", | ||
666 | np->name); | ||
667 | return -EINVAL; | ||
668 | } | ||
669 | |||
670 | size /= sizeof(*mux); /* Number of elements in array */ | ||
671 | rows = size / 2; /* Each row is a key value pair */ | ||
672 | |||
673 | vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows, GFP_KERNEL); | ||
674 | if (!vals) | ||
675 | return -ENOMEM; | ||
676 | |||
677 | pins = devm_kzalloc(pcs->dev, sizeof(*pins) * rows, GFP_KERNEL); | ||
678 | if (!pins) | ||
679 | goto free_vals; | ||
680 | |||
681 | while (index < size) { | ||
682 | unsigned offset, val; | ||
683 | int pin; | ||
684 | |||
685 | offset = be32_to_cpup(mux + index++); | ||
686 | val = be32_to_cpup(mux + index++); | ||
687 | vals[found].reg = pcs->base + offset; | ||
688 | vals[found].val = val; | ||
689 | |||
690 | pin = pcs_get_pin_by_offset(pcs, offset); | ||
691 | if (pin < 0) { | ||
692 | dev_err(pcs->dev, | ||
693 | "could not add functions for %s %ux\n", | ||
694 | np->name, offset); | ||
695 | break; | ||
696 | } | ||
697 | pins[found++] = pin; | ||
698 | } | ||
699 | |||
700 | pgnames[0] = np->name; | ||
701 | function = pcs_add_function(pcs, np, np->name, vals, found, pgnames, 1); | ||
702 | if (!function) | ||
703 | goto free_pins; | ||
704 | |||
705 | res = pcs_add_pingroup(pcs, np, np->name, pins, found); | ||
706 | if (res < 0) | ||
707 | goto free_function; | ||
708 | |||
709 | (*map)->type = PIN_MAP_TYPE_MUX_GROUP; | ||
710 | (*map)->data.mux.group = np->name; | ||
711 | (*map)->data.mux.function = np->name; | ||
712 | |||
713 | return 0; | ||
714 | |||
715 | free_function: | ||
716 | pcs_remove_function(pcs, function); | ||
717 | |||
718 | free_pins: | ||
719 | devm_kfree(pcs->dev, pins); | ||
720 | |||
721 | free_vals: | ||
722 | devm_kfree(pcs->dev, vals); | ||
723 | |||
724 | return res; | ||
725 | } | ||
726 | /** | ||
727 | * pcs_dt_node_to_map() - allocates and parses pinctrl maps | ||
728 | * @pctldev: pinctrl instance | ||
729 | * @np_config: device tree pinmux entry | ||
730 | * @map: array of map entries | ||
731 | * @num_maps: number of maps | ||
732 | */ | ||
733 | static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev, | ||
734 | struct device_node *np_config, | ||
735 | struct pinctrl_map **map, unsigned *num_maps) | ||
736 | { | ||
737 | struct pcs_device *pcs; | ||
738 | const char **pgnames; | ||
739 | int ret; | ||
740 | |||
741 | pcs = pinctrl_dev_get_drvdata(pctldev); | ||
742 | |||
743 | *map = devm_kzalloc(pcs->dev, sizeof(**map), GFP_KERNEL); | ||
744 | if (!map) | ||
745 | return -ENOMEM; | ||
746 | |||
747 | *num_maps = 0; | ||
748 | |||
749 | pgnames = devm_kzalloc(pcs->dev, sizeof(*pgnames), GFP_KERNEL); | ||
750 | if (!pgnames) { | ||
751 | ret = -ENOMEM; | ||
752 | goto free_map; | ||
753 | } | ||
754 | |||
755 | ret = pcs_parse_one_pinctrl_entry(pcs, np_config, map, pgnames); | ||
756 | if (ret < 0) { | ||
757 | dev_err(pcs->dev, "no pins entries for %s\n", | ||
758 | np_config->name); | ||
759 | goto free_pgnames; | ||
760 | } | ||
761 | *num_maps = 1; | ||
762 | |||
763 | return 0; | ||
764 | |||
765 | free_pgnames: | ||
766 | devm_kfree(pcs->dev, pgnames); | ||
767 | free_map: | ||
768 | devm_kfree(pcs->dev, *map); | ||
769 | |||
770 | return ret; | ||
771 | } | ||
772 | |||
773 | /** | ||
774 | * pcs_free_funcs() - free memory used by functions | ||
775 | * @pcs: pcs driver instance | ||
776 | */ | ||
777 | static void pcs_free_funcs(struct pcs_device *pcs) | ||
778 | { | ||
779 | struct list_head *pos, *tmp; | ||
780 | int i; | ||
781 | |||
782 | mutex_lock(&pcs->mutex); | ||
783 | for (i = 0; i < pcs->nfuncs; i++) { | ||
784 | struct pcs_function *func; | ||
785 | |||
786 | func = radix_tree_lookup(&pcs->ftree, i); | ||
787 | if (!func) | ||
788 | continue; | ||
789 | radix_tree_delete(&pcs->ftree, i); | ||
790 | } | ||
791 | list_for_each_safe(pos, tmp, &pcs->functions) { | ||
792 | struct pcs_function *function; | ||
793 | |||
794 | function = list_entry(pos, struct pcs_function, node); | ||
795 | list_del(&function->node); | ||
796 | } | ||
797 | mutex_unlock(&pcs->mutex); | ||
798 | } | ||
799 | |||
800 | /** | ||
801 | * pcs_free_pingroups() - free memory used by pingroups | ||
802 | * @pcs: pcs driver instance | ||
803 | */ | ||
804 | static void pcs_free_pingroups(struct pcs_device *pcs) | ||
805 | { | ||
806 | struct list_head *pos, *tmp; | ||
807 | int i; | ||
808 | |||
809 | mutex_lock(&pcs->mutex); | ||
810 | for (i = 0; i < pcs->ngroups; i++) { | ||
811 | struct pcs_pingroup *pingroup; | ||
812 | |||
813 | pingroup = radix_tree_lookup(&pcs->pgtree, i); | ||
814 | if (!pingroup) | ||
815 | continue; | ||
816 | radix_tree_delete(&pcs->pgtree, i); | ||
817 | } | ||
818 | list_for_each_safe(pos, tmp, &pcs->pingroups) { | ||
819 | struct pcs_pingroup *pingroup; | ||
820 | |||
821 | pingroup = list_entry(pos, struct pcs_pingroup, node); | ||
822 | list_del(&pingroup->node); | ||
823 | } | ||
824 | mutex_unlock(&pcs->mutex); | ||
825 | } | ||
826 | |||
827 | /** | ||
828 | * pcs_free_resources() - free memory used by this driver | ||
829 | * @pcs: pcs driver instance | ||
830 | */ | ||
831 | static void pcs_free_resources(struct pcs_device *pcs) | ||
832 | { | ||
833 | if (pcs->pctl) | ||
834 | pinctrl_unregister(pcs->pctl); | ||
835 | |||
836 | pcs_free_funcs(pcs); | ||
837 | pcs_free_pingroups(pcs); | ||
838 | } | ||
839 | |||
840 | #define PCS_GET_PROP_U32(name, reg, err) \ | ||
841 | do { \ | ||
842 | ret = of_property_read_u32(np, name, reg); \ | ||
843 | if (ret) { \ | ||
844 | dev_err(pcs->dev, err); \ | ||
845 | return ret; \ | ||
846 | } \ | ||
847 | } while (0); | ||
848 | |||
849 | static struct of_device_id pcs_of_match[]; | ||
850 | |||
851 | static int __devinit pcs_probe(struct platform_device *pdev) | ||
852 | { | ||
853 | struct device_node *np = pdev->dev.of_node; | ||
854 | const struct of_device_id *match; | ||
855 | struct resource *res; | ||
856 | struct pcs_device *pcs; | ||
857 | int ret; | ||
858 | |||
859 | match = of_match_device(pcs_of_match, &pdev->dev); | ||
860 | if (!match) | ||
861 | return -EINVAL; | ||
862 | |||
863 | pcs = devm_kzalloc(&pdev->dev, sizeof(*pcs), GFP_KERNEL); | ||
864 | if (!pcs) { | ||
865 | dev_err(&pdev->dev, "could not allocate\n"); | ||
866 | return -ENOMEM; | ||
867 | } | ||
868 | pcs->dev = &pdev->dev; | ||
869 | mutex_init(&pcs->mutex); | ||
870 | INIT_LIST_HEAD(&pcs->pingroups); | ||
871 | INIT_LIST_HEAD(&pcs->functions); | ||
872 | |||
873 | PCS_GET_PROP_U32("pinctrl-single,register-width", &pcs->width, | ||
874 | "register width not specified\n"); | ||
875 | |||
876 | PCS_GET_PROP_U32("pinctrl-single,function-mask", &pcs->fmask, | ||
877 | "function register mask not specified\n"); | ||
878 | pcs->fshift = ffs(pcs->fmask) - 1; | ||
879 | pcs->fmax = pcs->fmask >> pcs->fshift; | ||
880 | |||
881 | ret = of_property_read_u32(np, "pinctrl-single,function-off", | ||
882 | &pcs->foff); | ||
883 | if (ret) | ||
884 | pcs->foff = PCS_OFF_DISABLED; | ||
885 | |||
886 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
887 | if (!res) { | ||
888 | dev_err(pcs->dev, "could not get resource\n"); | ||
889 | return -ENODEV; | ||
890 | } | ||
891 | |||
892 | pcs->res = devm_request_mem_region(pcs->dev, res->start, | ||
893 | resource_size(res), DRIVER_NAME); | ||
894 | if (!pcs->res) { | ||
895 | dev_err(pcs->dev, "could not get mem_region\n"); | ||
896 | return -EBUSY; | ||
897 | } | ||
898 | |||
899 | pcs->size = resource_size(pcs->res); | ||
900 | pcs->base = devm_ioremap(pcs->dev, pcs->res->start, pcs->size); | ||
901 | if (!pcs->base) { | ||
902 | dev_err(pcs->dev, "could not ioremap\n"); | ||
903 | return -ENODEV; | ||
904 | } | ||
905 | |||
906 | INIT_RADIX_TREE(&pcs->pgtree, GFP_KERNEL); | ||
907 | INIT_RADIX_TREE(&pcs->ftree, GFP_KERNEL); | ||
908 | platform_set_drvdata(pdev, pcs); | ||
909 | |||
910 | switch (pcs->width) { | ||
911 | case 8: | ||
912 | pcs->read = pcs_readb; | ||
913 | pcs->write = pcs_writeb; | ||
914 | break; | ||
915 | case 16: | ||
916 | pcs->read = pcs_readw; | ||
917 | pcs->write = pcs_writew; | ||
918 | break; | ||
919 | case 32: | ||
920 | pcs->read = pcs_readl; | ||
921 | pcs->write = pcs_writel; | ||
922 | break; | ||
923 | default: | ||
924 | break; | ||
925 | } | ||
926 | |||
927 | pcs->desc.name = DRIVER_NAME; | ||
928 | pcs->desc.pctlops = &pcs_pinctrl_ops; | ||
929 | pcs->desc.pmxops = &pcs_pinmux_ops; | ||
930 | pcs->desc.confops = &pcs_pinconf_ops; | ||
931 | pcs->desc.owner = THIS_MODULE; | ||
932 | |||
933 | ret = pcs_allocate_pin_table(pcs); | ||
934 | if (ret < 0) | ||
935 | goto free; | ||
936 | |||
937 | pcs->pctl = pinctrl_register(&pcs->desc, pcs->dev, pcs); | ||
938 | if (!pcs->pctl) { | ||
939 | dev_err(pcs->dev, "could not register single pinctrl driver\n"); | ||
940 | ret = -EINVAL; | ||
941 | goto free; | ||
942 | } | ||
943 | |||
944 | dev_info(pcs->dev, "%i pins at pa %p size %u\n", | ||
945 | pcs->desc.npins, pcs->base, pcs->size); | ||
946 | |||
947 | return 0; | ||
948 | |||
949 | free: | ||
950 | pcs_free_resources(pcs); | ||
951 | |||
952 | return ret; | ||
953 | } | ||
954 | |||
955 | static int __devexit pcs_remove(struct platform_device *pdev) | ||
956 | { | ||
957 | struct pcs_device *pcs = platform_get_drvdata(pdev); | ||
958 | |||
959 | if (!pcs) | ||
960 | return 0; | ||
961 | |||
962 | pcs_free_resources(pcs); | ||
963 | |||
964 | return 0; | ||
965 | } | ||
966 | |||
967 | static struct of_device_id pcs_of_match[] __devinitdata = { | ||
968 | { .compatible = DRIVER_NAME, }, | ||
969 | { }, | ||
970 | }; | ||
971 | MODULE_DEVICE_TABLE(of, pcs_of_match); | ||
972 | |||
973 | static struct platform_driver pcs_driver = { | ||
974 | .probe = pcs_probe, | ||
975 | .remove = __devexit_p(pcs_remove), | ||
976 | .driver = { | ||
977 | .owner = THIS_MODULE, | ||
978 | .name = DRIVER_NAME, | ||
979 | .of_match_table = pcs_of_match, | ||
980 | }, | ||
981 | }; | ||
982 | |||
983 | module_platform_driver(pcs_driver); | ||
984 | |||
985 | MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>"); | ||
986 | MODULE_DESCRIPTION("One-register-per-pin type device tree based pinctrl driver"); | ||
987 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/pinctrl/pinctrl-tegra.c b/drivers/pinctrl/pinctrl-tegra.c index b6934867d8d3..ae52e4e5d098 100644 --- a/drivers/pinctrl/pinctrl-tegra.c +++ b/drivers/pinctrl/pinctrl-tegra.c | |||
@@ -745,9 +745,9 @@ int __devinit tegra_pinctrl_probe(struct platform_device *pdev, | |||
745 | } | 745 | } |
746 | 746 | ||
747 | pmx->pctl = pinctrl_register(&tegra_pinctrl_desc, &pdev->dev, pmx); | 747 | pmx->pctl = pinctrl_register(&tegra_pinctrl_desc, &pdev->dev, pmx); |
748 | if (IS_ERR(pmx->pctl)) { | 748 | if (!pmx->pctl) { |
749 | dev_err(&pdev->dev, "Couldn't register pinctrl driver\n"); | 749 | dev_err(&pdev->dev, "Couldn't register pinctrl driver\n"); |
750 | return PTR_ERR(pmx->pctl); | 750 | return -ENODEV; |
751 | } | 751 | } |
752 | 752 | ||
753 | pinctrl_add_gpio_range(pmx->pctl, &tegra_pinctrl_gpio_range); | 753 | pinctrl_add_gpio_range(pmx->pctl, &tegra_pinctrl_gpio_range); |
@@ -764,7 +764,6 @@ int __devexit tegra_pinctrl_remove(struct platform_device *pdev) | |||
764 | { | 764 | { |
765 | struct tegra_pmx *pmx = platform_get_drvdata(pdev); | 765 | struct tegra_pmx *pmx = platform_get_drvdata(pdev); |
766 | 766 | ||
767 | pinctrl_remove_gpio_range(pmx->pctl, &tegra_pinctrl_gpio_range); | ||
768 | pinctrl_unregister(pmx->pctl); | 767 | pinctrl_unregister(pmx->pctl); |
769 | 768 | ||
770 | return 0; | 769 | return 0; |
diff --git a/drivers/pinctrl/pinctrl-u300.c b/drivers/pinctrl/pinctrl-u300.c index 05d029911be6..a7ad8c112d91 100644 --- a/drivers/pinctrl/pinctrl-u300.c +++ b/drivers/pinctrl/pinctrl-u300.c | |||
@@ -1113,8 +1113,6 @@ static int __devinit u300_pmx_probe(struct platform_device *pdev) | |||
1113 | int ret; | 1113 | int ret; |
1114 | int i; | 1114 | int i; |
1115 | 1115 | ||
1116 | pr_err("U300 PMX PROBE\n"); | ||
1117 | |||
1118 | /* Create state holders etc for this driver */ | 1116 | /* Create state holders etc for this driver */ |
1119 | upmx = devm_kzalloc(&pdev->dev, sizeof(*upmx), GFP_KERNEL); | 1117 | upmx = devm_kzalloc(&pdev->dev, sizeof(*upmx), GFP_KERNEL); |
1120 | if (!upmx) | 1118 | if (!upmx) |
@@ -1175,15 +1173,11 @@ out_no_resource: | |||
1175 | static int __devexit u300_pmx_remove(struct platform_device *pdev) | 1173 | static int __devexit u300_pmx_remove(struct platform_device *pdev) |
1176 | { | 1174 | { |
1177 | struct u300_pmx *upmx = platform_get_drvdata(pdev); | 1175 | struct u300_pmx *upmx = platform_get_drvdata(pdev); |
1178 | int i; | ||
1179 | 1176 | ||
1180 | for (i = 0; i < ARRAY_SIZE(u300_gpio_ranges); i++) | ||
1181 | pinctrl_remove_gpio_range(upmx->pctl, &u300_gpio_ranges[i]); | ||
1182 | pinctrl_unregister(upmx->pctl); | 1177 | pinctrl_unregister(upmx->pctl); |
1183 | iounmap(upmx->virtbase); | 1178 | iounmap(upmx->virtbase); |
1184 | release_mem_region(upmx->phybase, upmx->physize); | 1179 | release_mem_region(upmx->phybase, upmx->physize); |
1185 | platform_set_drvdata(pdev, NULL); | 1180 | platform_set_drvdata(pdev, NULL); |
1186 | devm_kfree(&pdev->dev, upmx); | ||
1187 | 1181 | ||
1188 | return 0; | 1182 | return 0; |
1189 | } | 1183 | } |
diff --git a/drivers/pinctrl/spear/pinctrl-spear.c b/drivers/pinctrl/spear/pinctrl-spear.c index b3f6b2873fdd..5d4f44f462f0 100644 --- a/drivers/pinctrl/spear/pinctrl-spear.c +++ b/drivers/pinctrl/spear/pinctrl-spear.c | |||
@@ -336,9 +336,9 @@ int __devinit spear_pinctrl_probe(struct platform_device *pdev, | |||
336 | spear_pinctrl_desc.npins = machdata->npins; | 336 | spear_pinctrl_desc.npins = machdata->npins; |
337 | 337 | ||
338 | pmx->pctl = pinctrl_register(&spear_pinctrl_desc, &pdev->dev, pmx); | 338 | pmx->pctl = pinctrl_register(&spear_pinctrl_desc, &pdev->dev, pmx); |
339 | if (IS_ERR(pmx->pctl)) { | 339 | if (!pmx->pctl) { |
340 | dev_err(&pdev->dev, "Couldn't register pinctrl driver\n"); | 340 | dev_err(&pdev->dev, "Couldn't register pinctrl driver\n"); |
341 | return PTR_ERR(pmx->pctl); | 341 | return -ENODEV; |
342 | } | 342 | } |
343 | 343 | ||
344 | return 0; | 344 | return 0; |