Skip to content

Commit dc567f3

Browse files
committed
Merge tag 'reset-gpio-for-v6.19' of https://git.pengutronix.de/git/pza/linux into soc/drivers-late
Reset/GPIO/swnode changes for v6.19 * Extend software node implementation, allowing its properties to reference existing firmware nodes. * Update the GPIO property interface to use reworked swnode macros. * Rework reset-gpio code to use GPIO lookup via swnode. * Fix spi-cs42l43 driver to work with swnode changes. * tag 'reset-gpio-for-v6.19' of https://git.pengutronix.de/git/pza/linux: reset: gpio: use software nodes to setup the GPIO lookup reset: gpio: convert the driver to using the auxiliary bus reset: make the provider of reset-gpios the parent of the reset device reset: order includes alphabetically in reset/core.c gpio: swnode: allow referencing GPIO chips by firmware nodes spi: cs42l43: Use actual ACPI firmware node for chip selects software node: allow referencing firmware nodes software node: increase the reference of the swnode by its fwnode software node: read the reference args via the fwnode API Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2 parents 6a23ae0 + 5fc4e4c commit dc567f3

7 files changed

Lines changed: 137 additions & 107 deletions

File tree

drivers/base/swnode.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,29 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
535535
ref_array = prop->pointer;
536536
ref = &ref_array[index];
537537

538-
refnode = software_node_fwnode(ref->node);
538+
/*
539+
* A software node can reference other software nodes or firmware
540+
* nodes (which are the abstraction layer sitting on top of them).
541+
* This is done to ensure we can create references to static software
542+
* nodes before they're registered with the firmware node framework.
543+
* At the time the reference is being resolved, we expect the swnodes
544+
* in question to already have been registered and to be backed by
545+
* a firmware node. This is why we use the fwnode API below to read the
546+
* relevant properties and bump the reference count.
547+
*/
548+
549+
if (ref->swnode)
550+
refnode = software_node_fwnode(ref->swnode);
551+
else if (ref->fwnode)
552+
refnode = ref->fwnode;
553+
else
554+
return -EINVAL;
555+
539556
if (!refnode)
540557
return -ENOENT;
541558

542559
if (nargs_prop) {
543-
error = property_entry_read_int_array(ref->node->properties,
544-
nargs_prop, sizeof(u32),
545-
&nargs_prop_val, 1);
560+
error = fwnode_property_read_u32(refnode, nargs_prop, &nargs_prop_val);
546561
if (error)
547562
return error;
548563

@@ -555,7 +570,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
555570
if (!args)
556571
return 0;
557572

558-
args->fwnode = software_node_get(refnode);
573+
args->fwnode = fwnode_handle_get(refnode);
559574
args->nargs = nargs;
560575

561576
for (i = 0; i < nargs; i++)
@@ -635,7 +650,10 @@ software_node_graph_get_remote_endpoint(const struct fwnode_handle *fwnode)
635650

636651
ref = prop->pointer;
637652

638-
return software_node_get(software_node_fwnode(ref[0].node));
653+
if (!ref->swnode)
654+
return NULL;
655+
656+
return software_node_get(software_node_fwnode(ref->swnode));
639657
}
640658

641659
static struct fwnode_handle *

drivers/gpio/gpiolib-swnode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
3131

3232
gdev_node = to_software_node(fwnode);
3333
if (!gdev_node || !gdev_node->name)
34-
return ERR_PTR(-EINVAL);
34+
goto fwnode_lookup;
3535

3636
/*
3737
* Check for a special node that identifies undefined GPIOs, this is
@@ -41,6 +41,7 @@ static struct gpio_device *swnode_get_gpio_device(struct fwnode_handle *fwnode)
4141
!strcmp(gdev_node->name, GPIOLIB_SWNODE_UNDEFINED_NAME))
4242
return ERR_PTR(-ENOENT);
4343

44+
fwnode_lookup:
4445
gdev = gpio_device_find_by_fwnode(fwnode);
4546
return gdev ?: ERR_PTR(-EPROBE_DEFER);
4647
}

drivers/reset/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ config RESET_EYEQ
8989
config RESET_GPIO
9090
tristate "GPIO reset controller"
9191
depends on GPIOLIB
92+
select AUXILIARY_BUS
9293
help
9394
This enables a generic reset controller for resets attached via
9495
GPIOs. Typically for OF platforms this driver expects "reset-gpios"

drivers/reset/core.c

Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
*
55
* Copyright 2013 Philipp Zabel, Pengutronix
66
*/
7+
8+
#include <linux/acpi.h>
79
#include <linux/atomic.h>
10+
#include <linux/auxiliary_bus.h>
811
#include <linux/cleanup.h>
912
#include <linux/device.h>
1013
#include <linux/err.h>
1114
#include <linux/export.h>
12-
#include <linux/kernel.h>
13-
#include <linux/kref.h>
1415
#include <linux/gpio/driver.h>
1516
#include <linux/gpio/machine.h>
17+
#include <linux/gpio/property.h>
1618
#include <linux/idr.h>
19+
#include <linux/kernel.h>
20+
#include <linux/kref.h>
1721
#include <linux/module.h>
1822
#include <linux/of.h>
19-
#include <linux/acpi.h>
20-
#include <linux/platform_device.h>
2123
#include <linux/reset.h>
2224
#include <linux/reset-controller.h>
2325
#include <linux/slab.h>
@@ -76,10 +78,12 @@ struct reset_control_array {
7678
/**
7779
* struct reset_gpio_lookup - lookup key for ad-hoc created reset-gpio devices
7880
* @of_args: phandle to the reset controller with all the args like GPIO number
81+
* @swnode: Software node containing the reference to the GPIO provider
7982
* @list: list entry for the reset_gpio_lookup_list
8083
*/
8184
struct reset_gpio_lookup {
8285
struct of_phandle_args of_args;
86+
struct fwnode_handle *swnode;
8387
struct list_head list;
8488
};
8589

@@ -848,65 +852,56 @@ static void __reset_control_put_internal(struct reset_control *rstc)
848852
kref_put(&rstc->refcnt, __reset_control_release);
849853
}
850854

851-
static int __reset_add_reset_gpio_lookup(int id, struct device_node *np,
852-
unsigned int gpio,
853-
unsigned int of_flags)
855+
static void reset_gpio_aux_device_release(struct device *dev)
854856
{
855-
const struct fwnode_handle *fwnode = of_fwnode_handle(np);
856-
unsigned int lookup_flags;
857-
const char *label_tmp;
857+
struct auxiliary_device *adev = to_auxiliary_dev(dev);
858858

859-
/*
860-
* Later we map GPIO flags between OF and Linux, however not all
861-
* constants from include/dt-bindings/gpio/gpio.h and
862-
* include/linux/gpio/machine.h match each other.
863-
*/
864-
if (of_flags > GPIO_ACTIVE_LOW) {
865-
pr_err("reset-gpio code does not support GPIO flags %u for GPIO %u\n",
866-
of_flags, gpio);
867-
return -EINVAL;
868-
}
869-
870-
struct gpio_device *gdev __free(gpio_device_put) = gpio_device_find_by_fwnode(fwnode);
871-
if (!gdev)
872-
return -EPROBE_DEFER;
873-
874-
label_tmp = gpio_device_get_label(gdev);
875-
if (!label_tmp)
876-
return -EINVAL;
859+
kfree(adev);
860+
}
877861

878-
char *label __free(kfree) = kstrdup(label_tmp, GFP_KERNEL);
879-
if (!label)
880-
return -ENOMEM;
862+
static int reset_add_gpio_aux_device(struct device *parent,
863+
struct fwnode_handle *swnode,
864+
int id, void *pdata)
865+
{
866+
struct auxiliary_device *adev;
867+
int ret;
881868

882-
/* Size: one lookup entry plus sentinel */
883-
struct gpiod_lookup_table *lookup __free(kfree) = kzalloc(struct_size(lookup, table, 2),
884-
GFP_KERNEL);
885-
if (!lookup)
869+
adev = kzalloc(sizeof(*adev), GFP_KERNEL);
870+
if (!adev)
886871
return -ENOMEM;
887872

888-
lookup->dev_id = kasprintf(GFP_KERNEL, "reset-gpio.%d", id);
889-
if (!lookup->dev_id)
890-
return -ENOMEM;
873+
adev->id = id;
874+
adev->name = "gpio";
875+
adev->dev.parent = parent;
876+
adev->dev.platform_data = pdata;
877+
adev->dev.release = reset_gpio_aux_device_release;
878+
device_set_node(&adev->dev, swnode);
891879

892-
lookup_flags = GPIO_PERSISTENT;
893-
lookup_flags |= of_flags & GPIO_ACTIVE_LOW;
894-
lookup->table[0] = GPIO_LOOKUP(no_free_ptr(label), gpio, "reset",
895-
lookup_flags);
880+
ret = auxiliary_device_init(adev);
881+
if (ret) {
882+
kfree(adev);
883+
return ret;
884+
}
896885

897-
/* Not freed on success, because it is persisent subsystem data. */
898-
gpiod_add_lookup_table(no_free_ptr(lookup));
886+
ret = __auxiliary_device_add(adev, "reset");
887+
if (ret) {
888+
auxiliary_device_uninit(adev);
889+
kfree(adev);
890+
return ret;
891+
}
899892

900-
return 0;
893+
return ret;
901894
}
902895

903896
/*
904897
* @args: phandle to the GPIO provider with all the args like GPIO number
905898
*/
906899
static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
907900
{
901+
struct property_entry properties[2] = { };
902+
unsigned int offset, of_flags, lflags;
908903
struct reset_gpio_lookup *rgpio_dev;
909-
struct platform_device *pdev;
904+
struct device *parent;
910905
int id, ret;
911906

912907
/*
@@ -925,6 +920,28 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
925920
*/
926921
lockdep_assert_not_held(&reset_list_mutex);
927922

923+
offset = args->args[0];
924+
of_flags = args->args[1];
925+
926+
/*
927+
* Later we map GPIO flags between OF and Linux, however not all
928+
* constants from include/dt-bindings/gpio/gpio.h and
929+
* include/linux/gpio/machine.h match each other.
930+
*
931+
* FIXME: Find a better way of translating OF flags to GPIO lookup
932+
* flags.
933+
*/
934+
if (of_flags > GPIO_ACTIVE_LOW) {
935+
pr_err("reset-gpio code does not support GPIO flags %u for GPIO %u\n",
936+
of_flags, offset);
937+
return -EINVAL;
938+
}
939+
940+
struct gpio_device *gdev __free(gpio_device_put) =
941+
gpio_device_find_by_fwnode(of_fwnode_handle(args->np));
942+
if (!gdev)
943+
return -EPROBE_DEFER;
944+
928945
guard(mutex)(&reset_gpio_lookup_mutex);
929946

930947
list_for_each_entry(rgpio_dev, &reset_gpio_lookup_list, list) {
@@ -934,6 +951,10 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
934951
}
935952
}
936953

954+
lflags = GPIO_PERSISTENT | (of_flags & GPIO_ACTIVE_LOW);
955+
parent = gpio_device_to_device(gdev);
956+
properties[0] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);
957+
937958
id = ida_alloc(&reset_gpio_ida, GFP_KERNEL);
938959
if (id < 0)
939960
return id;
@@ -945,32 +966,33 @@ static int __reset_add_reset_gpio_device(const struct of_phandle_args *args)
945966
goto err_ida_free;
946967
}
947968

948-
ret = __reset_add_reset_gpio_lookup(id, args->np, args->args[0],
949-
args->args[1]);
950-
if (ret < 0)
951-
goto err_kfree;
952-
953969
rgpio_dev->of_args = *args;
954970
/*
955971
* We keep the device_node reference, but of_args.np is put at the end
956972
* of __of_reset_control_get(), so get it one more time.
957973
* Hold reference as long as rgpio_dev memory is valid.
958974
*/
959975
of_node_get(rgpio_dev->of_args.np);
960-
pdev = platform_device_register_data(NULL, "reset-gpio", id,
961-
&rgpio_dev->of_args,
962-
sizeof(rgpio_dev->of_args));
963-
ret = PTR_ERR_OR_ZERO(pdev);
976+
977+
rgpio_dev->swnode = fwnode_create_software_node(properties, NULL);
978+
if (IS_ERR(rgpio_dev->swnode)) {
979+
ret = PTR_ERR(rgpio_dev->swnode);
980+
goto err_put_of_node;
981+
}
982+
983+
ret = reset_add_gpio_aux_device(parent, rgpio_dev->swnode, id,
984+
&rgpio_dev->of_args);
964985
if (ret)
965-
goto err_put;
986+
goto err_del_swnode;
966987

967988
list_add(&rgpio_dev->list, &reset_gpio_lookup_list);
968989

969990
return 0;
970991

971-
err_put:
992+
err_del_swnode:
993+
fwnode_remove_software_node(rgpio_dev->swnode);
994+
err_put_of_node:
972995
of_node_put(rgpio_dev->of_args.np);
973-
err_kfree:
974996
kfree(rgpio_dev);
975997
err_ida_free:
976998
ida_free(&reset_gpio_ida, id);

drivers/reset/reset-gpio.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
#include <linux/auxiliary_bus.h>
34
#include <linux/gpio/consumer.h>
45
#include <linux/mod_devicetable.h>
56
#include <linux/module.h>
67
#include <linux/of.h>
7-
#include <linux/platform_device.h>
88
#include <linux/reset-controller.h>
99

1010
struct reset_gpio_priv {
@@ -61,9 +61,10 @@ static void reset_gpio_of_node_put(void *data)
6161
of_node_put(data);
6262
}
6363

64-
static int reset_gpio_probe(struct platform_device *pdev)
64+
static int reset_gpio_probe(struct auxiliary_device *adev,
65+
const struct auxiliary_device_id *id)
6566
{
66-
struct device *dev = &pdev->dev;
67+
struct device *dev = &adev->dev;
6768
struct of_phandle_args *platdata = dev_get_platdata(dev);
6869
struct reset_gpio_priv *priv;
6970
int ret;
@@ -75,7 +76,7 @@ static int reset_gpio_probe(struct platform_device *pdev)
7576
if (!priv)
7677
return -ENOMEM;
7778

78-
platform_set_drvdata(pdev, &priv->rc);
79+
auxiliary_set_drvdata(adev, &priv->rc);
7980

8081
priv->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
8182
if (IS_ERR(priv->reset))
@@ -99,20 +100,20 @@ static int reset_gpio_probe(struct platform_device *pdev)
99100
return devm_reset_controller_register(dev, &priv->rc);
100101
}
101102

102-
static const struct platform_device_id reset_gpio_ids[] = {
103-
{ .name = "reset-gpio", },
103+
static const struct auxiliary_device_id reset_gpio_ids[] = {
104+
{ .name = "reset.gpio" },
104105
{}
105106
};
106-
MODULE_DEVICE_TABLE(platform, reset_gpio_ids);
107+
MODULE_DEVICE_TABLE(auxiliary, reset_gpio_ids);
107108

108-
static struct platform_driver reset_gpio_driver = {
109+
static struct auxiliary_driver reset_gpio_driver = {
109110
.probe = reset_gpio_probe,
110111
.id_table = reset_gpio_ids,
111112
.driver = {
112113
.name = "reset-gpio",
113114
},
114115
};
115-
module_platform_driver(reset_gpio_driver);
116+
module_auxiliary_driver(reset_gpio_driver);
116117

117118
MODULE_AUTHOR("Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>");
118119
MODULE_DESCRIPTION("Generic GPIO reset driver");

0 commit comments

Comments
 (0)