Skip to content

Commit a473810

Browse files
committed
Merge branch 'i2c/alert-for-acpi' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c material for 5.18 that is depended on by subsequent device properties changes. * 'i2c/alert-for-acpi' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: smbus: Use device_*() functions instead of of_*() docs: firmware-guide: ACPI: Add named interrupt doc device property: Add fwnode_irq_get_byname
2 parents 754e0b0 + a263a84 commit a473810

File tree

7 files changed

+82
-11
lines changed

7 files changed

+82
-11
lines changed

Documentation/firmware-guide/acpi/enumeration.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,45 @@ In robust cases the client unfortunately needs to call
143143
acpi_dma_request_slave_chan_by_index() directly and therefore choose the
144144
specific FixedDMA resource by its index.
145145

146+
Named Interrupts
147+
================
148+
149+
Drivers enumerated via ACPI can have names to interrupts in the ACPI table
150+
which can be used to get the IRQ number in the driver.
151+
152+
The interrupt name can be listed in _DSD as 'interrupt-names'. The names
153+
should be listed as an array of strings which will map to the Interrupt()
154+
resource in the ACPI table corresponding to its index.
155+
156+
The table below shows an example of its usage::
157+
158+
Device (DEV0) {
159+
...
160+
Name (_CRS, ResourceTemplate() {
161+
...
162+
Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) {
163+
0x20,
164+
0x24
165+
}
166+
})
167+
168+
Name (_DSD, Package () {
169+
ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
170+
Package () {
171+
Package () {"interrupt-names",
172+
Package (2) {"default", "alert"}},
173+
}
174+
...
175+
})
176+
}
177+
178+
The interrupt name 'default' will correspond to 0x20 in Interrupt()
179+
resource and 'alert' to 0x24. Note that only the Interrupt() resource
180+
is mapped and not GpioInt() or similar.
181+
182+
The driver can call the function - fwnode_irq_get_byname() with the fwnode
183+
and interrupt name as arguments to get the corresponding IRQ number.
184+
146185
SPI serial bus support
147186
======================
148187

drivers/base/property.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,35 @@ void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index)
935935
}
936936
EXPORT_SYMBOL(fwnode_iomap);
937937

938+
/**
939+
* fwnode_irq_get_byname - Get IRQ from a fwnode using its name
940+
* @fwnode: Pointer to the firmware node
941+
* @name: IRQ name
942+
*
943+
* Description:
944+
* Find a match to the string @name in the 'interrupt-names' string array
945+
* in _DSD for ACPI, or of_node for Device Tree. Then get the Linux IRQ
946+
* number of the IRQ resource corresponding to the index of the matched
947+
* string.
948+
*
949+
* Return:
950+
* Linux IRQ number on success, or negative errno otherwise.
951+
*/
952+
int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name)
953+
{
954+
int index;
955+
956+
if (!name)
957+
return -EINVAL;
958+
959+
index = fwnode_property_match_string(fwnode, "interrupt-names", name);
960+
if (index < 0)
961+
return index;
962+
963+
return fwnode_irq_get(fwnode, index);
964+
}
965+
EXPORT_SYMBOL(fwnode_irq_get_byname);
966+
938967
/**
939968
* fwnode_graph_get_next_endpoint - Get next endpoint firmware node
940969
* @fwnode: Pointer to the parent firmware node

drivers/i2c/i2c-core-base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
14791479
goto out_list;
14801480
}
14811481

1482-
res = of_i2c_setup_smbus_alert(adap);
1482+
res = i2c_setup_smbus_alert(adap);
14831483
if (res)
14841484
goto out_reg;
14851485

drivers/i2c/i2c-core-smbus.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/err.h>
1515
#include <linux/i2c.h>
1616
#include <linux/i2c-smbus.h>
17+
#include <linux/property.h>
1718
#include <linux/slab.h>
1819

1920
#include "i2c-core.h"
@@ -701,19 +702,19 @@ struct i2c_client *i2c_new_smbus_alert_device(struct i2c_adapter *adapter,
701702
}
702703
EXPORT_SYMBOL_GPL(i2c_new_smbus_alert_device);
703704

704-
#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF)
705-
int of_i2c_setup_smbus_alert(struct i2c_adapter *adapter)
705+
#if IS_ENABLED(CONFIG_I2C_SMBUS)
706+
int i2c_setup_smbus_alert(struct i2c_adapter *adapter)
706707
{
707708
int irq;
708709

709-
irq = of_property_match_string(adapter->dev.of_node, "interrupt-names",
710-
"smbus_alert");
710+
irq = device_property_match_string(adapter->dev.parent, "interrupt-names",
711+
"smbus_alert");
711712
if (irq == -EINVAL || irq == -ENODATA)
712713
return 0;
713714
else if (irq < 0)
714715
return irq;
715716

716717
return PTR_ERR_OR_ZERO(i2c_new_smbus_alert_device(adapter, NULL));
717718
}
718-
EXPORT_SYMBOL_GPL(of_i2c_setup_smbus_alert);
719+
EXPORT_SYMBOL_GPL(i2c_setup_smbus_alert);
719720
#endif

drivers/i2c/i2c-smbus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <linux/interrupt.h>
1414
#include <linux/kernel.h>
1515
#include <linux/module.h>
16-
#include <linux/of_irq.h>
16+
#include <linux/property.h>
1717
#include <linux/slab.h>
1818
#include <linux/workqueue.h>
1919

@@ -128,7 +128,8 @@ static int smbalert_probe(struct i2c_client *ara,
128128
if (setup) {
129129
irq = setup->irq;
130130
} else {
131-
irq = of_irq_get_byname(adapter->dev.of_node, "smbus_alert");
131+
irq = fwnode_irq_get_byname(dev_fwnode(adapter->dev.parent),
132+
"smbus_alert");
132133
if (irq <= 0)
133134
return irq;
134135
}

include/linux/i2c-smbus.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ struct i2c_client *i2c_new_smbus_alert_device(struct i2c_adapter *adapter,
3030
struct i2c_smbus_alert_setup *setup);
3131
int i2c_handle_smbus_alert(struct i2c_client *ara);
3232

33-
#if IS_ENABLED(CONFIG_I2C_SMBUS) && IS_ENABLED(CONFIG_OF)
34-
int of_i2c_setup_smbus_alert(struct i2c_adapter *adap);
33+
#if IS_ENABLED(CONFIG_I2C_SMBUS)
34+
int i2c_setup_smbus_alert(struct i2c_adapter *adap);
3535
#else
36-
static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap)
36+
static inline int i2c_setup_smbus_alert(struct i2c_adapter *adap)
3737
{
3838
return 0;
3939
}

include/linux/property.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
121121
void fwnode_handle_put(struct fwnode_handle *fwnode);
122122

123123
int fwnode_irq_get(const struct fwnode_handle *fwnode, unsigned int index);
124+
int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name);
124125

125126
void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);
126127

0 commit comments

Comments
 (0)