aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/asm-generic/gpio.h15
-rw-r--r--include/linux/of.h10
-rw-r--r--include/linux/of_address.h44
-rw-r--r--include/linux/of_device.h61
-rw-r--r--include/linux/of_gpio.h35
-rw-r--r--include/linux/of_i2c.h13
-rw-r--r--include/linux/of_irq.h70
-rw-r--r--include/linux/of_platform.h53
-rw-r--r--include/linux/of_spi.h11
9 files changed, 250 insertions, 62 deletions
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 4f3d75e1ad39..c7376bf80b06 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -31,6 +31,7 @@ static inline int gpio_is_valid(int number)
31struct device; 31struct device;
32struct seq_file; 32struct seq_file;
33struct module; 33struct module;
34struct device_node;
34 35
35/** 36/**
36 * struct gpio_chip - abstract a GPIO controller 37 * struct gpio_chip - abstract a GPIO controller
@@ -106,6 +107,17 @@ struct gpio_chip {
106 const char *const *names; 107 const char *const *names;
107 unsigned can_sleep:1; 108 unsigned can_sleep:1;
108 unsigned exported:1; 109 unsigned exported:1;
110
111#if defined(CONFIG_OF_GPIO)
112 /*
113 * If CONFIG_OF is enabled, then all GPIO controllers described in the
114 * device tree automatically may have an OF translation
115 */
116 struct device_node *of_node;
117 int of_gpio_n_cells;
118 int (*of_xlate)(struct gpio_chip *gc, struct device_node *np,
119 const void *gpio_spec, u32 *flags);
120#endif
109}; 121};
110 122
111extern const char *gpiochip_is_requested(struct gpio_chip *chip, 123extern const char *gpiochip_is_requested(struct gpio_chip *chip,
@@ -115,6 +127,9 @@ extern int __must_check gpiochip_reserve(int start, int ngpio);
115/* add/remove chips */ 127/* add/remove chips */
116extern int gpiochip_add(struct gpio_chip *chip); 128extern int gpiochip_add(struct gpio_chip *chip);
117extern int __must_check gpiochip_remove(struct gpio_chip *chip); 129extern int __must_check gpiochip_remove(struct gpio_chip *chip);
130extern struct gpio_chip *gpiochip_find(void *data,
131 int (*match)(struct gpio_chip *chip,
132 void *data));
118 133
119 134
120/* Always use the library code for GPIO management calls, 135/* Always use the library code for GPIO management calls,
diff --git a/include/linux/of.h b/include/linux/of.h
index a367e19bb3af..cad7cf0ab278 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -70,6 +70,11 @@ extern struct device_node *allnodes;
70extern struct device_node *of_chosen; 70extern struct device_node *of_chosen;
71extern rwlock_t devtree_lock; 71extern rwlock_t devtree_lock;
72 72
73static inline bool of_node_is_root(const struct device_node *node)
74{
75 return node && (node->parent == NULL);
76}
77
73static inline int of_node_check_flag(struct device_node *n, unsigned long flag) 78static inline int of_node_check_flag(struct device_node *n, unsigned long flag)
74{ 79{
75 return test_bit(flag, &n->_flags); 80 return test_bit(flag, &n->_flags);
@@ -141,6 +146,11 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size)
141 146
142#define OF_BAD_ADDR ((u64)-1) 147#define OF_BAD_ADDR ((u64)-1)
143 148
149#ifndef of_node_to_nid
150static inline int of_node_to_nid(struct device_node *np) { return -1; }
151#define of_node_to_nid of_node_to_nid
152#endif
153
144extern struct device_node *of_find_node_by_name(struct device_node *from, 154extern struct device_node *of_find_node_by_name(struct device_node *from,
145 const char *name); 155 const char *name);
146#define for_each_node_by_name(dn, name) \ 156#define for_each_node_by_name(dn, name) \
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
new file mode 100644
index 000000000000..8aea06f0564c
--- /dev/null
+++ b/include/linux/of_address.h
@@ -0,0 +1,44 @@
1#ifndef __OF_ADDRESS_H
2#define __OF_ADDRESS_H
3#include <linux/ioport.h>
4#include <linux/of.h>
5
6extern u64 of_translate_address(struct device_node *np, const u32 *addr);
7extern int of_address_to_resource(struct device_node *dev, int index,
8 struct resource *r);
9extern void __iomem *of_iomap(struct device_node *device, int index);
10
11/* Extract an address from a device, returns the region size and
12 * the address space flags too. The PCI version uses a BAR number
13 * instead of an absolute index
14 */
15extern const u32 *of_get_address(struct device_node *dev, int index,
16 u64 *size, unsigned int *flags);
17
18#ifndef pci_address_to_pio
19static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
20#define pci_address_to_pio pci_address_to_pio
21#endif
22
23#ifdef CONFIG_PCI
24extern const u32 *of_get_pci_address(struct device_node *dev, int bar_no,
25 u64 *size, unsigned int *flags);
26extern int of_pci_address_to_resource(struct device_node *dev, int bar,
27 struct resource *r);
28#else /* CONFIG_PCI */
29static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
30 struct resource *r)
31{
32 return -ENOSYS;
33}
34
35static inline const u32 *of_get_pci_address(struct device_node *dev,
36 int bar_no, u64 *size, unsigned int *flags)
37{
38 return NULL;
39}
40#endif /* CONFIG_PCI */
41
42
43#endif /* __OF_ADDRESS_H */
44
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 11651facc5f1..35aa44ad9f2c 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -1,32 +1,77 @@
1#ifndef _LINUX_OF_DEVICE_H 1#ifndef _LINUX_OF_DEVICE_H
2#define _LINUX_OF_DEVICE_H 2#define _LINUX_OF_DEVICE_H
3 3
4/*
5 * The of_device *was* a kind of "base class" that was a superset of
6 * struct device for use by devices attached to an OF node and probed
7 * using OF properties. However, the important bit of OF-style
8 * probing, namely the device node pointer, has been moved into the
9 * common struct device when CONFIG_OF is set to make OF-style probing
10 * available to all bus types. So now, just make of_device and
11 * platform_device equivalent so that current of_platform bus users
12 * can be transparently migrated over to using the platform bus.
13 *
14 * This line will go away once all references to of_device are removed
15 * from the kernel.
16 */
17#define of_device platform_device
18#include <linux/platform_device.h>
19#include <linux/of_platform.h> /* temporary until merge */
20
4#ifdef CONFIG_OF_DEVICE 21#ifdef CONFIG_OF_DEVICE
5#include <linux/device.h> 22#include <linux/device.h>
6#include <linux/of.h> 23#include <linux/of.h>
7#include <linux/mod_devicetable.h> 24#include <linux/mod_devicetable.h>
8 25
9#include <asm/of_device.h>
10
11#define to_of_device(d) container_of(d, struct of_device, dev) 26#define to_of_device(d) container_of(d, struct of_device, dev)
12 27
13extern const struct of_device_id *of_match_device( 28extern const struct of_device_id *of_match_device(
14 const struct of_device_id *matches, const struct device *dev); 29 const struct of_device_id *matches, const struct device *dev);
30extern void of_device_make_bus_id(struct device *dev);
31
32/**
33 * of_driver_match_device - Tell if a driver's of_match_table matches a device.
34 * @drv: the device_driver structure to test
35 * @dev: the device structure to match against
36 */
37static inline int of_driver_match_device(const struct device *dev,
38 const struct device_driver *drv)
39{
40 return of_match_device(drv->of_match_table, dev) != NULL;
41}
15 42
16extern struct of_device *of_dev_get(struct of_device *dev); 43extern struct platform_device *of_dev_get(struct platform_device *dev);
17extern void of_dev_put(struct of_device *dev); 44extern void of_dev_put(struct platform_device *dev);
18 45
19extern int of_device_register(struct of_device *ofdev); 46extern int of_device_register(struct platform_device *ofdev);
20extern void of_device_unregister(struct of_device *ofdev); 47extern void of_device_unregister(struct platform_device *ofdev);
21extern void of_release_dev(struct device *dev); 48extern void of_release_dev(struct device *dev);
22 49
23static inline void of_device_free(struct of_device *dev) 50static inline void of_device_free(struct platform_device *dev)
24{ 51{
25 of_release_dev(&dev->dev); 52 of_release_dev(&dev->dev);
26} 53}
27 54
28extern ssize_t of_device_get_modalias(struct of_device *ofdev, 55extern ssize_t of_device_get_modalias(struct device *dev,
29 char *str, ssize_t len); 56 char *str, ssize_t len);
57
58extern int of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
59
60
61#else /* CONFIG_OF_DEVICE */
62
63static inline int of_driver_match_device(struct device *dev,
64 struct device_driver *drv)
65{
66 return 0;
67}
68
69static inline int of_device_uevent(struct device *dev,
70 struct kobj_uevent_env *env)
71{
72 return -ENODEV;
73}
74
30#endif /* CONFIG_OF_DEVICE */ 75#endif /* CONFIG_OF_DEVICE */
31 76
32#endif /* _LINUX_OF_DEVICE_H */ 77#endif /* _LINUX_OF_DEVICE_H */
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index fc2472c3c254..6598c04dab01 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -33,34 +33,17 @@ enum of_gpio_flags {
33#ifdef CONFIG_OF_GPIO 33#ifdef CONFIG_OF_GPIO
34 34
35/* 35/*
36 * Generic OF GPIO chip
37 */
38struct of_gpio_chip {
39 struct gpio_chip gc;
40 int gpio_cells;
41 int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
42 const void *gpio_spec, enum of_gpio_flags *flags);
43};
44
45static inline struct of_gpio_chip *to_of_gpio_chip(struct gpio_chip *gc)
46{
47 return container_of(gc, struct of_gpio_chip, gc);
48}
49
50/*
51 * OF GPIO chip for memory mapped banks 36 * OF GPIO chip for memory mapped banks
52 */ 37 */
53struct of_mm_gpio_chip { 38struct of_mm_gpio_chip {
54 struct of_gpio_chip of_gc; 39 struct gpio_chip gc;
55 void (*save_regs)(struct of_mm_gpio_chip *mm_gc); 40 void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
56 void __iomem *regs; 41 void __iomem *regs;
57}; 42};
58 43
59static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) 44static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
60{ 45{
61 struct of_gpio_chip *of_gc = to_of_gpio_chip(gc); 46 return container_of(gc, struct of_mm_gpio_chip, gc);
62
63 return container_of(of_gc, struct of_mm_gpio_chip, of_gc);
64} 47}
65 48
66extern int of_get_gpio_flags(struct device_node *np, int index, 49extern int of_get_gpio_flags(struct device_node *np, int index,
@@ -69,11 +52,12 @@ extern unsigned int of_gpio_count(struct device_node *np);
69 52
70extern int of_mm_gpiochip_add(struct device_node *np, 53extern int of_mm_gpiochip_add(struct device_node *np,
71 struct of_mm_gpio_chip *mm_gc); 54 struct of_mm_gpio_chip *mm_gc);
72extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, 55
73 struct device_node *np, 56extern void of_gpiochip_add(struct gpio_chip *gc);
74 const void *gpio_spec, 57extern void of_gpiochip_remove(struct gpio_chip *gc);
75 enum of_gpio_flags *flags); 58extern struct gpio_chip *of_node_to_gpiochip(struct device_node *np);
76#else 59
60#else /* CONFIG_OF_GPIO */
77 61
78/* Drivers may not strictly depend on the GPIO support, so let them link. */ 62/* Drivers may not strictly depend on the GPIO support, so let them link. */
79static inline int of_get_gpio_flags(struct device_node *np, int index, 63static inline int of_get_gpio_flags(struct device_node *np, int index,
@@ -87,6 +71,9 @@ static inline unsigned int of_gpio_count(struct device_node *np)
87 return 0; 71 return 0;
88} 72}
89 73
74static inline void of_gpiochip_add(struct gpio_chip *gc) { }
75static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
76
90#endif /* CONFIG_OF_GPIO */ 77#endif /* CONFIG_OF_GPIO */
91 78
92/** 79/**
diff --git a/include/linux/of_i2c.h b/include/linux/of_i2c.h
index 34974b5a76f7..0efe8d465f55 100644
--- a/include/linux/of_i2c.h
+++ b/include/linux/of_i2c.h
@@ -12,12 +12,19 @@
12#ifndef __LINUX_OF_I2C_H 12#ifndef __LINUX_OF_I2C_H
13#define __LINUX_OF_I2C_H 13#define __LINUX_OF_I2C_H
14 14
15#if defined(CONFIG_OF_I2C) || defined(CONFIG_OF_I2C_MODULE)
15#include <linux/i2c.h> 16#include <linux/i2c.h>
16 17
17void of_register_i2c_devices(struct i2c_adapter *adap, 18extern void of_i2c_register_devices(struct i2c_adapter *adap);
18 struct device_node *adap_node);
19 19
20/* must call put_device() when done with returned i2c_client device */ 20/* must call put_device() when done with returned i2c_client device */
21struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); 21extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
22
23#else
24static inline void of_i2c_register_devices(struct i2c_adapter *adap)
25{
26 return;
27}
28#endif /* CONFIG_OF_I2C */
22 29
23#endif /* __LINUX_OF_I2C_H */ 30#endif /* __LINUX_OF_I2C_H */
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
new file mode 100644
index 000000000000..5929781c104d
--- /dev/null
+++ b/include/linux/of_irq.h
@@ -0,0 +1,70 @@
1#ifndef __OF_IRQ_H
2#define __OF_IRQ_H
3
4#if defined(CONFIG_OF)
5struct of_irq;
6#include <linux/types.h>
7#include <linux/errno.h>
8#include <linux/ioport.h>
9#include <linux/of.h>
10
11/*
12 * irq_of_parse_and_map() is used ba all OF enabled platforms; but SPARC
13 * implements it differently. However, the prototype is the same for all,
14 * so declare it here regardless of the CONFIG_OF_IRQ setting.
15 */
16extern unsigned int irq_of_parse_and_map(struct device_node *node, int index);
17
18#if defined(CONFIG_OF_IRQ)
19/**
20 * of_irq - container for device_node/irq_specifier pair for an irq controller
21 * @controller: pointer to interrupt controller device tree node
22 * @size: size of interrupt specifier
23 * @specifier: array of cells @size long specifing the specific interrupt
24 *
25 * This structure is returned when an interrupt is mapped. The controller
26 * field needs to be put() after use
27 */
28#define OF_MAX_IRQ_SPEC 4 /* We handle specifiers of at most 4 cells */
29struct of_irq {
30 struct device_node *controller; /* Interrupt controller node */
31 u32 size; /* Specifier size */
32 u32 specifier[OF_MAX_IRQ_SPEC]; /* Specifier copy */
33};
34
35/*
36 * Workarounds only applied to 32bit powermac machines
37 */
38#define OF_IMAP_OLDWORLD_MAC 0x00000001
39#define OF_IMAP_NO_PHANDLE 0x00000002
40
41#if defined(CONFIG_PPC32) && defined(CONFIG_PPC_PMAC)
42extern unsigned int of_irq_workarounds;
43extern struct device_node *of_irq_dflt_pic;
44extern int of_irq_map_oldworld(struct device_node *device, int index,
45 struct of_irq *out_irq);
46#else /* CONFIG_PPC32 && CONFIG_PPC_PMAC */
47#define of_irq_workarounds (0)
48#define of_irq_dflt_pic (NULL)
49static inline int of_irq_map_oldworld(struct device_node *device, int index,
50 struct of_irq *out_irq)
51{
52 return -EINVAL;
53}
54#endif /* CONFIG_PPC32 && CONFIG_PPC_PMAC */
55
56
57extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
58 u32 ointsize, const u32 *addr,
59 struct of_irq *out_irq);
60extern int of_irq_map_one(struct device_node *device, int index,
61 struct of_irq *out_irq);
62extern unsigned int irq_create_of_mapping(struct device_node *controller,
63 const u32 *intspec,
64 unsigned int intsize);
65extern int of_irq_to_resource(struct device_node *dev, int index,
66 struct resource *r);
67
68#endif /* CONFIG_OF_IRQ */
69#endif /* CONFIG_OF */
70#endif /* __OF_IRQ_H */
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 1643d3761eb4..4e6d989c06df 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -17,29 +17,24 @@
17#include <linux/mod_devicetable.h> 17#include <linux/mod_devicetable.h>
18#include <linux/pm.h> 18#include <linux/pm.h>
19#include <linux/of_device.h> 19#include <linux/of_device.h>
20 20#include <linux/platform_device.h>
21/*
22 * The of_platform_bus_type is a bus type used by drivers that do not
23 * attach to a macio or similar bus but still use OF probing
24 * mechanism
25 */
26extern struct bus_type of_platform_bus_type;
27 21
28/* 22/*
29 * An of_platform_driver driver is attached to a basic of_device on 23 * An of_platform_driver driver is attached to a basic of_device on
30 * the "platform bus" (of_platform_bus_type). 24 * the "platform bus" (platform_bus_type).
31 */ 25 */
32struct of_platform_driver 26struct of_platform_driver
33{ 27{
34 int (*probe)(struct of_device* dev, 28 int (*probe)(struct platform_device* dev,
35 const struct of_device_id *match); 29 const struct of_device_id *match);
36 int (*remove)(struct of_device* dev); 30 int (*remove)(struct platform_device* dev);
37 31
38 int (*suspend)(struct of_device* dev, pm_message_t state); 32 int (*suspend)(struct platform_device* dev, pm_message_t state);
39 int (*resume)(struct of_device* dev); 33 int (*resume)(struct platform_device* dev);
40 int (*shutdown)(struct of_device* dev); 34 int (*shutdown)(struct platform_device* dev);
41 35
42 struct device_driver driver; 36 struct device_driver driver;
37 struct platform_driver platform_driver;
43}; 38};
44#define to_of_platform_driver(drv) \ 39#define to_of_platform_driver(drv) \
45 container_of(drv,struct of_platform_driver, driver) 40 container_of(drv,struct of_platform_driver, driver)
@@ -49,20 +44,30 @@ extern int of_register_driver(struct of_platform_driver *drv,
49extern void of_unregister_driver(struct of_platform_driver *drv); 44extern void of_unregister_driver(struct of_platform_driver *drv);
50 45
51/* Platform drivers register/unregister */ 46/* Platform drivers register/unregister */
52static inline int of_register_platform_driver(struct of_platform_driver *drv) 47extern int of_register_platform_driver(struct of_platform_driver *drv);
53{ 48extern void of_unregister_platform_driver(struct of_platform_driver *drv);
54 return of_register_driver(drv, &of_platform_bus_type);
55}
56static inline void of_unregister_platform_driver(struct of_platform_driver *drv)
57{
58 of_unregister_driver(drv);
59}
60 49
61#include <asm/of_platform.h> 50extern struct platform_device *of_device_alloc(struct device_node *np,
62 51 const char *bus_id,
63extern struct of_device *of_find_device_by_node(struct device_node *np); 52 struct device *parent);
53extern struct platform_device *of_find_device_by_node(struct device_node *np);
64 54
65extern int of_bus_type_init(struct bus_type *bus, const char *name); 55extern int of_bus_type_init(struct bus_type *bus, const char *name);
56
57#if !defined(CONFIG_SPARC) /* SPARC has its own device registration method */
58/* Platform devices and busses creation */
59extern struct platform_device *of_platform_device_create(struct device_node *np,
60 const char *bus_id,
61 struct device *parent);
62
63/* pseudo "matches" value to not do deep probe */
64#define OF_NO_DEEP_PROBE ((struct of_device_id *)-1)
65
66extern int of_platform_bus_probe(struct device_node *root,
67 const struct of_device_id *matches,
68 struct device *parent);
69#endif /* !CONFIG_SPARC */
70
66#endif /* CONFIG_OF_DEVICE */ 71#endif /* CONFIG_OF_DEVICE */
67 72
68#endif /* _LINUX_OF_PLATFORM_H */ 73#endif /* _LINUX_OF_PLATFORM_H */
diff --git a/include/linux/of_spi.h b/include/linux/of_spi.h
index 5f71ee8c0868..9e3e70f78ae6 100644
--- a/include/linux/of_spi.h
+++ b/include/linux/of_spi.h
@@ -9,10 +9,15 @@
9#ifndef __LINUX_OF_SPI_H 9#ifndef __LINUX_OF_SPI_H
10#define __LINUX_OF_SPI_H 10#define __LINUX_OF_SPI_H
11 11
12#include <linux/of.h>
13#include <linux/spi/spi.h> 12#include <linux/spi/spi.h>
14 13
15extern void of_register_spi_devices(struct spi_master *master, 14#if defined(CONFIG_OF_SPI) || defined(CONFIG_OF_SPI_MODULE)
16 struct device_node *np); 15extern void of_register_spi_devices(struct spi_master *master);
16#else
17static inline void of_register_spi_devices(struct spi_master *master)
18{
19 return;
20}
21#endif /* CONFIG_OF_SPI */
17 22
18#endif /* __LINUX_OF_SPI */ 23#endif /* __LINUX_OF_SPI */