Skip to content

Commit 54196cc

Browse files
committed
of: consolidate linker section OF match table declarations
We now have several OF match tables using linker sections that are nearly the same definition. The only variation is the callback function prototype. Create a common define for creating linker section OF match table entries which each table declaration can use. Acked-by: Grant Likely <grant.likely@linaro.org> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent 826d895 commit 54196cc

File tree

6 files changed

+32
-38
lines changed

6 files changed

+32
-38
lines changed

drivers/clocksource/clksrc-of.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void __init clocksource_of_init(void)
2727
{
2828
struct device_node *np;
2929
const struct of_device_id *match;
30-
clocksource_of_init_fn init_func;
30+
of_init_fn_1 init_func;
3131
unsigned clocksources = 0;
3232

3333
for_each_matching_node_and_match(np, __clksrc_of_table, &match) {

drivers/irqchip/irqchip.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#ifndef _IRQCHIP_H
1212
#define _IRQCHIP_H
1313

14+
#include <linux/of.h>
15+
1416
/*
1517
* This macro must be used by the different irqchip drivers to declare
1618
* the association between their DT compatible string and their
@@ -21,9 +23,6 @@
2123
* @compstr: compatible string of the irqchip driver
2224
* @fn: initialization function
2325
*/
24-
#define IRQCHIP_DECLARE(name,compstr,fn) \
25-
static const struct of_device_id irqchip_of_match_##name \
26-
__used __section(__irqchip_of_table) \
27-
= { .compatible = compstr, .data = fn }
26+
#define IRQCHIP_DECLARE(name, compat, fn) OF_DECLARE_2(irqchip, name, compat, fn)
2827

2928
#endif

include/linux/clk-provider.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,7 @@ struct clk_onecell_data {
498498

499499
extern struct of_device_id __clk_of_table;
500500

501-
#define CLK_OF_DECLARE(name, compat, fn) \
502-
static const struct of_device_id __clk_of_table_##name \
503-
__used __section(__clk_of_table) \
504-
= { .compatible = compat, .data = fn };
501+
#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)
505502

506503
#ifdef CONFIG_OF
507504
int of_clk_add_provider(struct device_node *np,

include/linux/clocksource.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,23 +339,13 @@ extern int clocksource_mmio_init(void __iomem *, const char *,
339339

340340
extern int clocksource_i8253_init(void);
341341

342-
struct device_node;
343-
typedef void(*clocksource_of_init_fn)(struct device_node *);
342+
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
343+
OF_DECLARE_1(clksrc, name, compat, fn)
344+
344345
#ifdef CONFIG_CLKSRC_OF
345346
extern void clocksource_of_init(void);
346-
347-
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
348-
static const struct of_device_id __clksrc_of_table_##name \
349-
__used __section(__clksrc_of_table) \
350-
= { .compatible = compat, \
351-
.data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn }
352347
#else
353348
static inline void clocksource_of_init(void) {}
354-
#define CLOCKSOURCE_OF_DECLARE(name, compat, fn) \
355-
static const struct of_device_id __clksrc_of_table_##name \
356-
__attribute__((unused)) \
357-
= { .compatible = compat, \
358-
.data = (fn == (clocksource_of_init_fn)NULL) ? fn : fn }
359349
#endif
360350

361351
#endif /* _LINUX_CLOCKSOURCE_H */

include/linux/of.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,4 +757,26 @@ static inline int of_get_available_child_count(const struct device_node *np)
757757
return num;
758758
}
759759

760+
#ifdef CONFIG_OF
761+
#define _OF_DECLARE(table, name, compat, fn, fn_type) \
762+
static const struct of_device_id __of_table_##name \
763+
__used __section(__##table##_of_table) \
764+
= { .compatible = compat, \
765+
.data = (fn == (fn_type)NULL) ? fn : fn }
766+
#else
767+
#define _OF_DECLARE(table, name, compat, fn, fn_type) \
768+
static const struct of_device_id __of_table_##name \
769+
__attribute__((unused)) \
770+
= { .compatible = compat, \
771+
.data = (fn == (fn_type)NULL) ? fn : fn }
772+
#endif
773+
774+
typedef int (*of_init_fn_2)(struct device_node *, struct device_node *);
775+
typedef void (*of_init_fn_1)(struct device_node *);
776+
777+
#define OF_DECLARE_1(table, name, compat, fn) \
778+
_OF_DECLARE(table, name, compat, fn, of_init_fn_1)
779+
#define OF_DECLARE_2(table, name, compat, fn) \
780+
_OF_DECLARE(table, name, compat, fn, of_init_fn_2)
781+
760782
#endif /* _LINUX_OF_H */

include/linux/of_reserved_mem.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,17 @@ struct reserved_mem_ops {
2323

2424
typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
2525

26+
#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
27+
_OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
2628

2729
#ifdef CONFIG_OF_RESERVED_MEM
2830
void fdt_init_reserved_mem(void);
2931
void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
3032
phys_addr_t base, phys_addr_t size);
31-
32-
#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
33-
static const struct of_device_id __reservedmem_of_table_##name \
34-
__used __section(__reservedmem_of_table) \
35-
= { .compatible = compat, \
36-
.data = (init == (reservedmem_of_init_fn)NULL) ? \
37-
init : init }
38-
3933
#else
4034
static inline void fdt_init_reserved_mem(void) { }
4135
static inline void fdt_reserved_mem_save_node(unsigned long node,
4236
const char *uname, phys_addr_t base, phys_addr_t size) { }
43-
44-
#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
45-
static const struct of_device_id __reservedmem_of_table_##name \
46-
__attribute__((unused)) \
47-
= { .compatible = compat, \
48-
.data = (init == (reservedmem_of_init_fn)NULL) ? \
49-
init : init }
50-
5137
#endif
5238

5339
#endif /* __OF_RESERVED_MEM_H */

0 commit comments

Comments
 (0)