Generalize OF gpio support code
Subsystems (8)
v2 cover Generalize OF gpio support code
This series makes all gpio drivers usable from the OF support apis by automatically registering a default OF translator when the of_node pointer is assigned. These patches are heavily based on the work that Anton did earlier, but I didn't add the notifiers infrastructure and the OF data now lives directly inside the core gpio_chip structure so that fewer gymnastics are needed to get at it.
These patches are currently sitting in the following branch:
git://git.secretlab.ca/git/linux-2.6 next-devicetree
---
Anton Vorontsov (3):
gpiolib: cosmetic improvements for error handling in gpiochip_add() of/gpio: Kill of_gpio_chip and add members directly to gpio_chip of/gpio: add default of_xlate function if device has a node pointer
Grant Likely (2):
of/gpio: stop using device_node data pointer to find gpio_chip of/device: Add OF style matching helper function
arch/microblaze/kernel/reset.c | 12 ++- arch/powerpc/platforms/52xx/mpc52xx_gpio.c | 30 ++++---- arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 29 ++++---- arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 34 ++------- arch/powerpc/platforms/86xx/gef_gpio.c | 24 +++---- arch/powerpc/sysdev/cpm1.c | 10 +-- arch/powerpc/sysdev/cpm_common.c | 5 - arch/powerpc/sysdev/mpc8xxx_gpio.c | 5 - arch/powerpc/sysdev/ppc4xx_gpio.c | 5 - arch/powerpc/sysdev/qe_lib/gpio.c | 31 ++++----- arch/powerpc/sysdev/simple_gpio.c | 5 - drivers/gpio/gpiolib.c | 55 ++++++++++++++- drivers/gpio/xilinx_gpio.c | 15 ++-- drivers/of/device.c | 2 - drivers/of/gpio.c | 86 +++++++++++++++--------- include/asm-generic/gpio.h | 15 ++++ include/linux/of_device.h | 19 +++++ include/linux/of_gpio.h | 35 +++------- 18 files changed, 226 insertions(+), 191 deletions(-)
PATCH v2 1/5 gpiolib: cosmetic improvements for error handling in gpiochip_add()
From: Anton Vorontsov <[email protected]>
Hopefully it makes the code look nicer and makes it easier to extend this function.
--- drivers/gpio/gpiolib.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-)
drivers/gpio/gpiolib.c +12 -6
@@ -1101,14 +1101,20 @@ int gpiochip_add(struct gpio_chip *chip) unlock:spin_unlock_irqrestore (&gpio_lock, flags); -if (status ==0 ) - status =gpiochip_export (chip); + +if (status) + goto fail; + + status =gpiochip_export (chip); +if (status) + goto fail; + +return 0 ; fail:/* failures here can mean systems won't boot... */ -if (status) -pr_err ("gpiochip_add: gpios %d..%d (%s) failed to register\n" , - chip->base, chip->base + chip->ngpio -1 , - chip->label ? :"generic" ); +pr_err ("gpiochip_add: gpios %d..%d (%s) failed to register\n" , + chip->base, chip->base + chip->ngpio -1 , + chip->label ? :"generic" );return status; }EXPORT_SYMBOL_GPL (gpiochip_add);
PATCH v2 2/5 of/gpio: Kill of_gpio_chip and add members directly to gpio_chip
In reply to Grant LikelyFrom: Anton Vorontsov <[email protected]>
The OF gpio infrastructure is great for describing GPIO connections within the device tree. However, using a GPIO binding still requires changes to the gpio controller just to add an of_gpio structure. In most cases, the gpio controller doesn't actually need any special support and the simple OF gpio mapping function is more than sufficient. Additional, the current scheme of using of_gpio_chip requires a convoluted scheme to maintain 1:1 mappings between of_gpio_chip and gpio_chip instances.
If the struct of_gpio_chip data members were moved into struct gpio_chip, then it would simplify the processing of OF gpio bindings, and it would make it trivial to use device tree OF connections on existing gpiolib controller drivers.
This patch eliminates the of_gpio_chip structure and moves the relevant fields into struct gpio_chip (conditional on CONFIG_OF_GPIO). This move simplifies the existing code and prepares for adding automatic device tree support to existing drivers.
--- arch/microblaze/kernel/reset.c | 12 +++--- arch/powerpc/platforms/52xx/mpc52xx_gpio.c | 32 ++++++++------- arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 29 +++++++------- arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 15 +++---- arch/powerpc/platforms/86xx/gef_gpio.c | 24 ++++++------ arch/powerpc/sysdev/cpm1.c | 12 ++---- arch/powerpc/sysdev/cpm_common.c | 6 +-- arch/powerpc/sysdev/mpc8xxx_gpio.c | 6 +-- arch/powerpc/sysdev/ppc4xx_gpio.c | 6 +-- arch/powerpc/sysdev/qe_lib/gpio.c | 32 +++++++-------- arch/powerpc/sysdev/simple_gpio.c | 6 +-- drivers/gpio/xilinx_gpio.c | 16 +++----- drivers/of/gpio.c | 50 ++++++++++++------------ include/asm-generic/gpio.h | 12 ++++++ include/linux/of_gpio.h | 29 ++------------ 15 files changed, 129 insertions(+), 158 deletions(-)
arch/microblaze/kernel/reset.c +6 -6
@@ -24,8 +24,8 @@ static int of_reset_gpio_handle(void)int ret;/* variable which stored handle reset gpio pin */ struct device_node *root;/* root node */ struct device_node *gpio;/* gpio node */ -struct of_gpio_chip *of_gc =NULL ; -enum of_gpio_flags flags ; +struct gpio_chip *gc; +u32 flags;const void *gpio_spec;/* find out root node */
@@ -39,19 +39,19 @@ static int of_reset_gpio_handle(void) goto err0; } - of_gc = gpio->data; -if (!of_gc) { + gc = gpio->data; +if (!gc) {pr_debug ("%s: gpio controller %s isn't registered\n" , root->full_name, gpio->full_name); ret = -ENODEV ; goto err1; } - ret = of_gc->xlate (of_gc, root, gpio_spec, &flags); + ret = gc->of_xlate (gc, root, gpio_spec, &flags);if (ret <0 ) goto err1; - ret += of_gc->gc.base; + ret += gc->base; err1:of_node_put (gpio); err0:
arch/powerpc/platforms/52xx/mpc52xx_gpio.c +16 -16
@@ -152,21 +152,21 @@ static int __devinit mpc52xx_wkup_gpiochip_probe(struct of_device *ofdev, {struct mpc52xx_gpiochip *chip;struct mpc52xx_gpio_wkup __iomem *regs; -struct of_gpio_chip *ofchip; +struct gpio_chip *gc;int ret; chip =kzalloc (sizeof (*chip),GFP_KERNEL );if (!chip)return -ENOMEM ; - ofchip = &chip->mmchip.of_gc; + gc = &chip->mmchip.gc; - ofchip->gpio_cells =2 ; - ofchip->gc.ngpio =8 ; - ofchip->gc.direction_input = mpc52xx_wkup_gpio_dir_in; - ofchip->gc.direction_output = mpc52xx_wkup_gpio_dir_out; - ofchip->gc.get = mpc52xx_wkup_gpio_get; - ofchip->gc.set = mpc52xx_wkup_gpio_set; + gc->of_gpio_n_cells =2 ; + gc->ngpio =8 ; + gc->direction_input = mpc52xx_wkup_gpio_dir_in; + gc->direction_output = mpc52xx_wkup_gpio_dir_out; + gc->get = mpc52xx_wkup_gpio_get; + gc->set = mpc52xx_wkup_gpio_set; ret =of_mm_gpiochip_add (ofdev->dev.of_node, &chip->mmchip);if (ret)
@@ -315,7 +315,7 @@ static int __devinit mpc52xx_simple_gpiochip_probe(struct of_device *ofdev, const struct of_device_id *match) {struct mpc52xx_gpiochip *chip; -struct of_gpio_chip *ofchip; +struct gpio_chip *gc;struct mpc52xx_gpio __iomem *regs;int ret;
@@ -323,14 +323,14 @@ static int __devinit mpc52xx_simple_gpiochip_probe(struct of_device *ofdev,if (!chip)return -ENOMEM ; - ofchip = &chip->mmchip.of_gc; + gc = &chip->mmchip.gc; - ofchip->gpio_cells =2 ; - ofchip->gc.ngpio =32 ; - ofchip->gc.direction_input = mpc52xx_simple_gpio_dir_in; - ofchip->gc.direction_output = mpc52xx_simple_gpio_dir_out; - ofchip->gc.get = mpc52xx_simple_gpio_get; - ofchip->gc.set = mpc52xx_simple_gpio_set; + gc->of_gpio_n_cells =2 ; + gc->ngpio =32 ; + gc->direction_input = mpc52xx_simple_gpio_dir_in; + gc->direction_output = mpc52xx_simple_gpio_dir_out; + gc->get = mpc52xx_simple_gpio_get; + gc->set = mpc52xx_simple_gpio_set; ret =of_mm_gpiochip_add (ofdev->dev.of_node, &chip->mmchip);if (ret)
arch/powerpc/platforms/52xx/mpc52xx_gpt.c +14 -15
@@ -78,7 +78,7 @@ MODULE_LICENSE("GPL");* @dev: pointer to device structure * @regs: virtual address of GPT registers * @lock: spinlock to coordinate between different functions. -* @of_gc: of_gpio_chip instance structure; used when GPIO is enabled +* @gc: gpio_chip instance structure; used when GPIO is enabled * @irqhost: Pointer to irq_host instance; used when IRQ mode is supported * @wdt_mode: only relevant for gpt0: bit 0 (MPC52xx_GPT_CAN_WDT) indicates * if the gpt may be used as wdt, bit 1 (MPC52xx_GPT_IS_WDT) indicates
@@ -94,7 +94,7 @@ struct mpc52xx_gpt_priv {u8 wdt_mode;#if defined(CONFIG_GPIOLIB ) -struct of_gpio_chip of_gc; +struct gpio_chip gc;#endif };
@@ -280,7 +280,7 @@ mpc52xx_gpt_irq_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node)#if defined(CONFIG_GPIOLIB )static inline struct mpc52xx_gpt_priv *gc_to_mpc52xx_gpt (struct gpio_chip *gc) { - return container_of(to_of_gpio_chip(gc), struct mpc52xx_gpt_priv,of_gc); + return container_of(gc, struct mpc52xx_gpt_priv, gc); }static int mpc52xx_gpt_gpio_get (struct gpio_chip *gc,unsigned int gpio)
@@ -336,28 +336,27 @@ mpc52xx_gpt_gpio_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node)if (!of_find_property (node,"gpio-controller" ,NULL ))return ; - gpt->of_gc.gc.label =kstrdup (node->full_name,GFP_KERNEL ); -if (!gpt->of_gc.gc.label) { + gpt->gc.label =kstrdup (node->full_name,GFP_KERNEL ); +if (!gpt->gc.label) {dev_err (gpt->dev,"out of memory\n" );return ; } - gpt->of_gc.gpio_cells =2 ; - gpt->of_gc.gc.ngpio =1 ; - gpt->of_gc.gc.direction_input = mpc52xx_gpt_gpio_dir_in; - gpt->of_gc.gc.direction_output = mpc52xx_gpt_gpio_dir_out; - gpt->of_gc.gc.get = mpc52xx_gpt_gpio_get; - gpt->of_gc.gc.set = mpc52xx_gpt_gpio_set; - gpt->of_gc.gc.base =-1 ; - gpt->of_gc.xlate = of_gpio_simple_xlate; - node->data = &gpt->of_gc; + gpt->gc.ngpio =1 ; + gpt->gc.direction_input = mpc52xx_gpt_gpio_dir_in; + gpt->gc.direction_output = mpc52xx_gpt_gpio_dir_out; + gpt->gc.get = mpc52xx_gpt_gpio_get; + gpt->gc.set = mpc52xx_gpt_gpio_set; + gpt->gc.base =-1 ; + gpt->gc.of_gpio_n_cells =2 ; + gpt->gc.of_xlate = of_gpio_simple_xlate;of_node_get (node);/* Setup external pin in GPIO mode */ clrsetbits_be32 (&gpt->regs->mode, MPC52xx_GPT_MODE_MS_MASK, MPC52xx_GPT_MODE_MS_GPIO); - rc =gpiochip_add (&gpt->of_gc.gc); + rc =gpiochip_add (&gpt->gc);if (rc)dev_err (gpt->dev,"gpiochip_add() failed; rc=%i\n" , rc);
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +6 -9
@@ -37,7 +37,7 @@ struct mcu {struct mutex lock;struct device_node *np;struct i2c_client *client; -struct of_gpio_chip of_gc; +struct gpio_chip gc;u8 reg_ctrl; };
@@ -56,8 +56,7 @@ static void mcu_power_off(void)static void mcu_gpio_set (struct gpio_chip *gc,unsigned int gpio,int val) { -struct of_gpio_chip *of_gc =to_of_gpio_chip (gc); - struct mcu *mcu = container_of(of_gc, struct mcu, of_gc); + struct mcu *mcu = container_of(gc, struct mcu, gc);u8 bit =1 << (4 + gpio);mutex_lock (&mcu->lock);
@@ -79,8 +78,7 @@ static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)static int mcu_gpiochip_add (struct mcu *mcu) {struct device_node *np; -struct of_gpio_chip *of_gc = &mcu->of_gc; -struct gpio_chip *gc = &of_gc->gc; +struct gpio_chip *gc = &mcu->gc;int ret; np =of_find_compatible_node (NULL ,NULL ,"fsl,mcu-mpc8349emitx" );
@@ -94,10 +92,9 @@ static int mcu_gpiochip_add(struct mcu *mcu) gc->base =-1 ; gc->set = mcu_gpio_set; gc->direction_output = mcu_gpio_dir_out; - of_gc->gpio_cells =2 ; - of_gc->xlate = of_gpio_simple_xlate; + gc->of_gpio_n_cells =2 ; + gc->of_xlate = of_gpio_simple_xlate; - np->data = of_gc; mcu->np = np;/*
@@ -114,7 +111,7 @@ static int mcu_gpiochip_remove(struct mcu *mcu) {int ret; - ret =gpiochip_remove (&mcu->of_gc.gc); + ret =gpiochip_remove (&mcu->gc);if (ret)return ret;of_node_put (mcu->np);
arch/powerpc/platforms/86xx/gef_gpio.c +12 -12
@@ -118,12 +118,12 @@ static int __init gef_gpio_init(void) }/* Setup pointers to chip functions */ - gef_gpio_chip->of_gc.gpio_cells =2 ; - gef_gpio_chip->of_gc.gc.ngpio =19 ; - gef_gpio_chip->of_gc.gc.direction_input = gef_gpio_dir_in; - gef_gpio_chip->of_gc.gc.direction_output = gef_gpio_dir_out; - gef_gpio_chip->of_gc.gc.get = gef_gpio_get; - gef_gpio_chip->of_gc.gc.set = gef_gpio_set; + gef_gpio_chip->gc.of_gpio_n_cells =2 ; + gef_gpio_chip->gc.ngpio =19 ; + gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; + gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; + gef_gpio_chip->gc.get = gef_gpio_get; + gef_gpio_chip->gc.set = gef_gpio_set;/* This function adds a memory mapped GPIO chip */ retval =of_mm_gpiochip_add (np, gef_gpio_chip);
@@ -146,12 +146,12 @@ static int __init gef_gpio_init(void) }/* Setup pointers to chip functions */ - gef_gpio_chip->of_gc.gpio_cells =2 ; - gef_gpio_chip->of_gc.gc.ngpio =6 ; - gef_gpio_chip->of_gc.gc.direction_input = gef_gpio_dir_in; - gef_gpio_chip->of_gc.gc.direction_output = gef_gpio_dir_out; - gef_gpio_chip->of_gc.gc.get = gef_gpio_get; - gef_gpio_chip->of_gc.gc.set = gef_gpio_set; + gef_gpio_chip->gc.of_gpio_n_cells =2 ; + gef_gpio_chip->gc.ngpio =6 ; + gef_gpio_chip->gc.direction_input = gef_gpio_dir_in; + gef_gpio_chip->gc.direction_output = gef_gpio_dir_out; + gef_gpio_chip->gc.get = gef_gpio_get; + gef_gpio_chip->gc.set = gef_gpio_set;/* This function adds a memory mapped GPIO chip */ retval =of_mm_gpiochip_add (np, gef_gpio_chip);
arch/powerpc/sysdev/cpm1.c +4 -8
@@ -621,7 +621,6 @@ int cpm1_gpiochip_add16(struct device_node *np) {struct cpm1_gpio16_chip *cpm1_gc;struct of_mm_gpio_chip *mm_gc; -struct of_gpio_chip *of_gc;struct gpio_chip *gc; cpm1_gc =kzalloc (sizeof (*cpm1_gc),GFP_KERNEL );
@@ -631,11 +630,10 @@ int cpm1_gpiochip_add16(struct device_node *np)spin_lock_init (&cpm1_gc->lock); mm_gc = &cpm1_gc->mm_gc; - of_gc = &mm_gc->of_gc; - gc = &of_gc->gc; + gc = &mm_gc->gc; mm_gc->save_regs = cpm1_gpio16_save_regs; - of_gc->gpio_cells =2 ; + gc->of_gpio_n_cells =2 ; gc->ngpio =16 ; gc->direction_input = cpm1_gpio16_dir_in; gc->direction_output = cpm1_gpio16_dir_out;
@@ -745,7 +743,6 @@ int cpm1_gpiochip_add32(struct device_node *np) {struct cpm1_gpio32_chip *cpm1_gc;struct of_mm_gpio_chip *mm_gc; -struct of_gpio_chip *of_gc;struct gpio_chip *gc; cpm1_gc =kzalloc (sizeof (*cpm1_gc),GFP_KERNEL );
@@ -755,11 +752,10 @@ int cpm1_gpiochip_add32(struct device_node *np)spin_lock_init (&cpm1_gc->lock); mm_gc = &cpm1_gc->mm_gc; - of_gc = &mm_gc->of_gc; - gc = &of_gc->gc; + gc = &mm_gc->gc; mm_gc->save_regs = cpm1_gpio32_save_regs; - of_gc->gpio_cells =2 ; + gc->of_gpio_n_cells =2 ; gc->ngpio =32 ; gc->direction_input = cpm1_gpio32_dir_in; gc->direction_output = cpm1_gpio32_dir_out;
arch/powerpc/sysdev/cpm_common.c +2 -4
@@ -325,7 +325,6 @@ int cpm2_gpiochip_add32(struct device_node *np) {struct cpm2_gpio32_chip *cpm2_gc;struct of_mm_gpio_chip *mm_gc; -struct of_gpio_chip *of_gc;struct gpio_chip *gc; cpm2_gc =kzalloc (sizeof (*cpm2_gc),GFP_KERNEL );
@@ -335,11 +334,10 @@ int cpm2_gpiochip_add32(struct device_node *np)spin_lock_init (&cpm2_gc->lock); mm_gc = &cpm2_gc->mm_gc; - of_gc = &mm_gc->of_gc; - gc = &of_gc->gc; + gc = &mm_gc->gc; mm_gc->save_regs = cpm2_gpio32_save_regs; - of_gc->gpio_cells =2 ; + gc->of_gpio_n_cells =2 ; gc->ngpio =32 ; gc->direction_input = cpm2_gpio32_dir_in; gc->direction_output = cpm2_gpio32_dir_out;
arch/powerpc/sysdev/mpc8xxx_gpio.c +2 -4
@@ -257,7 +257,6 @@ static void __init mpc8xxx_add_controller(struct device_node *np) {struct mpc8xxx_gpio_chip *mpc8xxx_gc;struct of_mm_gpio_chip *mm_gc; -struct of_gpio_chip *of_gc;struct gpio_chip *gc;unsigned hwirq;int ret;
@@ -271,11 +270,10 @@ static void __init mpc8xxx_add_controller(struct device_node *np)spin_lock_init (&mpc8xxx_gc->lock); mm_gc = &mpc8xxx_gc->mm_gc; - of_gc = &mm_gc->of_gc; - gc = &of_gc->gc; + gc = &mm_gc->gc; mm_gc->save_regs = mpc8xxx_gpio_save_regs; - of_gc->gpio_cells =2 ; + gc->of_gpio_n_cells =2 ; gc->ngpio =MPC8XXX_GPIO_PINS ; gc->direction_input = mpc8xxx_gpio_dir_in; gc->direction_output = mpc8xxx_gpio_dir_out;
arch/powerpc/sysdev/ppc4xx_gpio.c +2 -4
@@ -181,7 +181,6 @@ static int __init ppc4xx_add_gpiochips(void)int ret;struct ppc4xx_gpio_chip *ppc4xx_gc;struct of_mm_gpio_chip *mm_gc; -struct of_gpio_chip *of_gc;struct gpio_chip *gc; ppc4xx_gc =kzalloc (sizeof (*ppc4xx_gc),GFP_KERNEL );
@@ -193,10 +192,9 @@ static int __init ppc4xx_add_gpiochips(void)spin_lock_init (&ppc4xx_gc->lock); mm_gc = &ppc4xx_gc->mm_gc; - of_gc = &mm_gc->of_gc; - gc = &of_gc->gc; + gc = &mm_gc->gc; - of_gc->gpio_cells =2 ; + gc->of_gpio_n_cells =2 ; gc->ngpio =32 ; gc->direction_input = ppc4xx_gpio_dir_in; gc->direction_output = ppc4xx_gpio_dir_out;
arch/powerpc/sysdev/qe_lib/gpio.c +15 -17
@@ -138,8 +138,8 @@ struct qe_pin {struct qe_pin *qe_pin_request (struct device_node *np,int index) {struct qe_pin *qe_pin; -struct device_node *gc; -struct of_gpio_chip *of_gc =NULL ; +struct device_node *gpio_np; +struct gpio_chip *gc;struct of_mm_gpio_chip *mm_gc;struct qe_gpio_chip *qe_gc;int err;
@@ -155,40 +155,40 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index) } err =of_parse_phandles_with_args (np,"gpios" ,"#gpio-cells" , index, - &gc, &gpio_spec); + &gpio_np, &gpio_spec);if (err) {pr_debug ("%s: can't parse gpios property\n" , __func__); goto err0; } -if (!of_device_is_compatible (gc,"fsl,mpc8323-qe-pario-bank" )) { +if (!of_device_is_compatible (gpio_np,"fsl,mpc8323-qe-pario-bank" )) {pr_debug ("%s: tried to get a non-qe pin\n" , __func__); err = -EINVAL ; goto err1; } - of_gc = gc->data; -if (!of_gc) { + gc = gpio_np->data; +if (!gc) {pr_debug ("%s: gpio controller %s isn't registered\n" , - np->full_name, gc->full_name); + np->full_name, gpio_np->full_name); err = -ENODEV ; goto err1; } - gpio_cells =of_get_property (gc,"#gpio-cells" , &size); + gpio_cells =of_get_property (gpio_np,"#gpio-cells" , &size);if (!gpio_cells || size !=sizeof (*gpio_cells) || - *gpio_cells != of_gc->gpio_cells) { + *gpio_cells != gc->of_gpio_n_cells) {pr_debug ("%s: wrong #gpio-cells for %s\n" , - np->full_name, gc->full_name); + np->full_name, gpio_np->full_name); err = -EINVAL ; goto err1; } - err = of_gc->xlate (of_gc, np, gpio_spec,NULL ); + err = gc->of_xlate (gc, np, gpio_spec,NULL );if (err <0 ) goto err1; - mm_gc =to_of_mm_gpio_chip (&of_gc->gc); + mm_gc =to_of_mm_gpio_chip (gc); qe_gc =to_qe_gpio_chip (mm_gc);spin_lock_irqsave (&qe_gc->lock, flags);
@@ -206,7 +206,7 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)if (!err)return qe_pin; err1: -of_node_put (gc); +of_node_put (gpio_np); err0:kfree (qe_pin);pr_debug ("%s failed with status %d\n" , __func__, err);
@@ -307,7 +307,6 @@ static int __init qe_add_gpiochips(void)int ret;struct qe_gpio_chip *qe_gc;struct of_mm_gpio_chip *mm_gc; -struct of_gpio_chip *of_gc;struct gpio_chip *gc; qe_gc =kzalloc (sizeof (*qe_gc),GFP_KERNEL );
@@ -319,11 +318,10 @@ static int __init qe_add_gpiochips(void)spin_lock_init (&qe_gc->lock); mm_gc = &qe_gc->mm_gc; - of_gc = &mm_gc->of_gc; - gc = &of_gc->gc; + gc = &mm_gc->gc; mm_gc->save_regs = qe_gpio_save_regs; - of_gc->gpio_cells =2 ; + gc->of_gpio_n_cells =2 ; gc->ngpio =QE_PIO_PINS ; gc->direction_input = qe_gpio_dir_in; gc->direction_output = qe_gpio_dir_out;
arch/powerpc/sysdev/simple_gpio.c +2 -4
@@ -91,7 +91,6 @@ static int __init u8_simple_gpiochip_add(struct device_node *np)int ret;struct u8_gpio_chip *u8_gc;struct of_mm_gpio_chip *mm_gc; -struct of_gpio_chip *of_gc;struct gpio_chip *gc; u8_gc =kzalloc (sizeof (*u8_gc),GFP_KERNEL );
@@ -101,11 +100,10 @@ static int __init u8_simple_gpiochip_add(struct device_node *np)spin_lock_init (&u8_gc->lock); mm_gc = &u8_gc->mm_gc; - of_gc = &mm_gc->of_gc; - gc = &of_gc->gc; + gc = &mm_gc->gc; mm_gc->save_regs = u8_gpio_save_regs; - of_gc->gpio_cells =2 ; + gc->of_gpio_n_cells =2 ; gc->ngpio =8 ; gc->direction_input = u8_gpio_dir_in; gc->direction_output = u8_gpio_dir_out;
drivers/gpio/xilinx_gpio.c +7 -9
@@ -161,14 +161,12 @@ static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc)static int __devinit xgpio_of_probe (struct device_node *np) {struct xgpio_instance *chip; -struct of_gpio_chip *ofchip;int status =0 ;const u32 *tree_info; chip =kzalloc (sizeof (*chip),GFP_KERNEL );if (!chip)return -ENOMEM ; - ofchip = &chip->mmchip.of_gc;/* Update GPIO state shadow register with default value */ tree_info =of_get_property (np,"xlnx,dout-default" ,NULL );
@@ -182,21 +180,21 @@ static int __devinit xgpio_of_probe(struct device_node *np) chip->gpio_dir = *tree_info;/* Check device node and parent device node for device width */ - ofchip->gc.ngpio =32 ;/* By default assume full GPIO controller */ + chip->mmchip.gc.ngpio =32 ;/* By default assume full GPIO controller */ tree_info =of_get_property (np,"xlnx,gpio-width" ,NULL );if (!tree_info) tree_info =of_get_property (np->parent,"xlnx,gpio-width" ,NULL );if (tree_info) - ofchip->gc.ngpio = *tree_info; + chip->mmchip.gc.ngpio = *tree_info;spin_lock_init (&chip->gpio_lock); - ofchip->gpio_cells =2 ; - ofchip->gc.direction_input = xgpio_dir_in; - ofchip->gc.direction_output = xgpio_dir_out; - ofchip->gc.get = xgpio_get; - ofchip->gc.set = xgpio_set; + chip->mmchip.gc.of_gpio_n_cells =2 ; + chip->mmchip.gc.direction_input = xgpio_dir_in; + chip->mmchip.gc.direction_output = xgpio_dir_out; + chip->mmchip.gc.get = xgpio_get; + chip->mmchip.gc.set = xgpio_set; chip->mmchip.save_regs = xgpio_save_regs;
drivers/of/gpio.c +24 -26
127 lines not on this page · raw message
include/asm-generic/gpio.h +12 -0
@@ -31,6 +31,7 @@ static inline int gpio_is_valid(int number)struct device ;struct seq_file ;struct module ; +struct device_node ;/** * struct gpio_chip - abstract a GPIO controller
@@ -106,6 +107,17 @@ struct gpio_chip {const char *const *names; unsigned can_sleep:1; unsigned exported:1; + +#if defined(CONFIG_OF_GPIO ) +/* +* If CONFIG_OF is enabled, then all GPIO controllers described in the +* device tree automatically may have an OF translation +*/ +struct device_node *of_node; +int of_gpio_n_cells; +int (*of_xlate)(struct gpio_chip *gc,struct device_node *np, +const void *gpio_spec,u32 *flags); +#endif }; extern const char *gpiochip_is_requested(struct gpio_chip *chip,
include/linux/of_gpio.h +5 -24
@@ -33,34 +33,17 @@ enum of_gpio_flags {#ifdef CONFIG_OF_GPIO /* -* Generic OF GPIO chip -*/ -struct of_gpio_chip { -struct gpio_chip gc; -int gpio_cells; -int (*xlate)(struct of_gpio_chip *of_gc,struct device_node *np, -const void *gpio_spec,enum of_gpio_flags *flags); -}; - -static inline struct of_gpio_chip *to_of_gpio_chip (struct gpio_chip *gc) -{ - return container_of(gc, struct of_gpio_chip, gc); -} - -/* * OF GPIO chip for memory mapped banks */ struct of_mm_gpio_chip { -struct of_gpio_chip of_gc; +struct gpio_chip gc;void (*save_regs)(struct of_mm_gpio_chip *mm_gc);void __iomem *regs; };static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip (struct gpio_chip *gc) { -struct of_gpio_chip *of_gc =to_of_gpio_chip (gc); - - return container_of(of_gc, struct of_mm_gpio_chip, of_gc); + return container_of(gc, struct of_mm_gpio_chip, gc); } extern int of_get_gpio_flags(struct device_node *np, int index,
@@ -69,11 +52,9 @@ extern unsigned int of_gpio_count(struct device_node *np);extern int of_mm_gpiochip_add (struct device_node *np,struct of_mm_gpio_chip *mm_gc); -extern int of_gpio_simple_xlate (struct of_gpio_chip *of_gc, -struct device_node *np, -const void *gpio_spec, -enum of_gpio_flags *flags); -#else +extern int of_gpio_simple_xlate (struct gpio_chip *gc,struct device_node *np, +const void *gpio_spec,u32 *flags); +#else /* CONFIG_OF_GPIO */ /* Drivers may not strictly depend on the GPIO support, so let them link. */ static inline int of_get_gpio_flags(struct device_node *np, int index,
PATCH v2 3/5 of/gpio: stop using device_node data pointer to find gpio_chip
In reply to Grant LikelyCurrently the kernel uses the struct device_node.data pointer to resolve a struct gpio_chip pointer from a device tree node. However, the .data member doesn't provide any type checking and there aren't any rules enforced on what it should be used for. There's no guarantee that the data stored in it actually points to an gpio_chip pointer.
Instead of relying on the .data pointer, this patch modifies the code to add a lookup function which scans through the registered gpio_chips and returns the gpio_chip that has a pointer to the specified device_node.
--- arch/microblaze/kernel/reset.c | 2 +- arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 1 + arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 23 ++--------------- arch/powerpc/sysdev/qe_lib/gpio.c | 2 +- drivers/gpio/gpiolib.c | 32 ++++++++++++++++++++++++ drivers/of/gpio.c | 15 +++++++++-- include/asm-generic/gpio.h | 3 ++ include/linux/of_gpio.h | 3 ++ 8 files changed, 56 insertions(+), 25 deletions(-)
arch/microblaze/kernel/reset.c +1 -1
@@ -39,7 +39,7 @@ static int of_reset_gpio_handle(void) goto err0; } - gc = gpio->data; + gc =of_node_to_gpiochip (gpio);if (!gc) {pr_debug ("%s: gpio controller %s isn't registered\n" , root->full_name, gpio->full_name);
arch/powerpc/platforms/52xx/mpc52xx_gpt.c +1 -0
@@ -350,6 +350,7 @@ mpc52xx_gpt_gpio_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node) gpt->gc.base =-1 ; gpt->gc.of_gpio_n_cells =2 ; gpt->gc.of_xlate = of_gpio_simple_xlate; + gpt->gc.of_node = node;of_node_get (node);/* Setup external pin in GPIO mode */
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +3 -20
@@ -35,7 +35,6 @@struct mcu {struct mutex lock; -struct device_node *np;struct i2c_client *client;struct gpio_chip gc;u8 reg_ctrl;
@@ -79,7 +78,6 @@ static int mcu_gpiochip_add(struct mcu *mcu) {struct device_node *np;struct gpio_chip *gc = &mcu->gc; -int ret; np =of_find_compatible_node (NULL ,NULL ,"fsl,mcu-mpc8349emitx" );if (!np)
@@ -94,29 +92,14 @@ static int mcu_gpiochip_add(struct mcu *mcu) gc->direction_output = mcu_gpio_dir_out; gc->of_gpio_n_cells =2 ; gc->of_xlate = of_gpio_simple_xlate; + gc->of_node = np; - mcu->np = np; - -/* -* We don't want to lose the node, its ->data and ->full_name... -* So, if succeeded, we don't put the node here. -*/ - ret =gpiochip_add (gc); -if (ret) -of_node_put (np); -return ret; +return gpiochip_add (gc); }static int mcu_gpiochip_remove (struct mcu *mcu) { -int ret; - - ret =gpiochip_remove (&mcu->gc); -if (ret) -return ret; -of_node_put (mcu->np); - -return 0 ; +return gpiochip_remove (&mcu->gc); } static int __devinit mcu_probe(struct i2c_client *client,
arch/powerpc/sysdev/qe_lib/gpio.c +1 -1
@@ -167,7 +167,7 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index) goto err1; } - gc = gpio_np->data; + gc =of_node_to_gpiochip (gpio_np);if (!gc) {pr_debug ("%s: gpio controller %s isn't registered\n" , np->full_name, gpio_np->full_name);
drivers/gpio/gpiolib.c +32 -0
@@ -1153,6 +1153,38 @@ int gpiochip_remove(struct gpio_chip *chip) }EXPORT_SYMBOL_GPL (gpiochip_remove); +/** +* gpiochip_find() - iterator for locating a specific gpio_chip +* @data: data to pass to match function +* @callback: Callback function to check gpio_chip +* +* Similar to bus_find_device. It returns a reference to a gpio_chip as +* determined by a user supplied @match callback. The callback should return +* 0 if the device doesn't match and non-zero if it does. If the callback is +* non-zero, this function will return to the caller and not iterate over any +* more gpio_chips. +*/ +struct gpio_chip *gpiochip_find (void *data, +int (*match)(struct gpio_chip *chip,void *data)) +{ +struct gpio_chip *chip =NULL ; +unsigned long flags; +int i; + +spin_lock_irqsave (&gpio_lock, flags); +for (i =0 ; i <ARCH_NR_GPIOS ; i++) { +if (!gpio_desc[i].chip) +continue ; + +if (match (gpio_desc[i].chip, data)) { + chip = gpio_desc[i].chip; +break ; + } + } +spin_unlock_irqrestore (&gpio_lock, flags); + +return chip; +}/* These "optional" allocation calls help prevent drivers from stomping * on each other, and help provide better diagnostics in debugfs.
drivers/of/gpio.c +12 -3
@@ -46,7 +46,7 @@ int of_get_gpio_flags(struct device_node *np, int index, goto err0; } - gc = gpio_np->data; + gc =of_node_to_gpiochip (gpio_np);if (!gc) {pr_debug ("%s: gpio controller %s isn't registered\n" , np->full_name, gpio_np->full_name);
@@ -193,7 +193,6 @@ int of_mm_gpiochip_add(struct device_node *np,if (mm_gc->save_regs) mm_gc->save_regs (mm_gc); - np->data = &mm_gc->gc; mm_gc->gc.of_node = np; ret =gpiochip_add (gc);
@@ -207,7 +206,6 @@ int of_mm_gpiochip_add(struct device_node *np, np->full_name, gc->base);return 0 ; err2: - np->data =NULL ;iounmap (mm_gc->regs); err1:kfree (gc->label);
@@ -217,3 +215,14 @@ err0:return ret; }EXPORT_SYMBOL (of_mm_gpiochip_add); + +/* Private function for resolving node pointer to gpio_chip */ +static int of_gpiochip_is_match (struct gpio_chip *chip,void *data) +{ +return chip->of_node == data; +} + +struct gpio_chip *of_node_to_gpiochip (struct device_node *np) +{ +return gpiochip_find (np, of_gpiochip_is_match); +}
include/asm-generic/gpio.h +3 -0
@@ -127,6 +127,9 @@ extern int __must_check gpiochip_reserve(int start, int ngpio);/* add/remove chips */ extern int gpiochip_add (struct gpio_chip *chip);extern int __must_check gpiochip_remove (struct gpio_chip *chip); +extern struct gpio_chip *gpiochip_find (void *data, +int (*match)(struct gpio_chip *chip, +void *data));/* Always use the library code for GPIO management calls,
include/linux/of_gpio.h +3 -0
@@ -54,6 +54,9 @@ extern int of_mm_gpiochip_add(struct device_node *np, struct of_mm_gpio_chip *mm_gc);extern int of_gpio_simple_xlate (struct gpio_chip *gc,struct device_node *np,const void *gpio_spec,u32 *flags); + +extern struct gpio_chip *of_node_to_gpiochip (struct device_node *np); +#else /* CONFIG_OF_GPIO */ /* Drivers may not strictly depend on the GPIO support, so let them link. */
PATCH v2 4/5 of/gpio: add default of_xlate function if device has a node pointer
In reply to Grant LikelyFrom: Anton Vorontsov <[email protected]>
Implement generic OF gpio hooks and thus make device-enabled GPIO chips (i.e. the ones that have gpio_chip->dev specified) automatically attach to the OpenFirmware subsystem. Which means that now we can handle I2C and SPI GPIO chips almost* transparently.
* "Almost" because some chips still require platform data, and for these chips OF-glue is still needed, though with this change the glue will be much smaller.
--- arch/powerpc/platforms/52xx/mpc52xx_gpio.c | 2 - arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 3 -- arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 2 - arch/powerpc/sysdev/cpm1.c | 2 - arch/powerpc/sysdev/cpm_common.c | 1 - arch/powerpc/sysdev/mpc8xxx_gpio.c | 1 - arch/powerpc/sysdev/ppc4xx_gpio.c | 1 - arch/powerpc/sysdev/qe_lib/gpio.c | 1 - arch/powerpc/sysdev/simple_gpio.c | 1 - drivers/gpio/gpiolib.c | 5 ++++ drivers/gpio/xilinx_gpio.c | 1 - drivers/of/gpio.c | 33 +++++++++++++++++------- include/linux/of_gpio.h | 7 ++++- 13 files changed, 34 insertions(+), 26 deletions(-)
arch/powerpc/platforms/52xx/mpc52xx_gpio.c +0 -2
@@ -161,7 +161,6 @@ static int __devinit mpc52xx_wkup_gpiochip_probe(struct of_device *ofdev, gc = &chip->mmchip.gc; - gc->of_gpio_n_cells =2 ; gc->ngpio =8 ; gc->direction_input = mpc52xx_wkup_gpio_dir_in; gc->direction_output = mpc52xx_wkup_gpio_dir_out;
@@ -325,7 +324,6 @@ static int __devinit mpc52xx_simple_gpiochip_probe(struct of_device *ofdev, gc = &chip->mmchip.gc; - gc->of_gpio_n_cells =2 ; gc->ngpio =32 ; gc->direction_input = mpc52xx_simple_gpio_dir_in; gc->direction_output = mpc52xx_simple_gpio_dir_out;
arch/powerpc/platforms/52xx/mpc52xx_gpt.c +0 -3
@@ -348,10 +348,7 @@ mpc52xx_gpt_gpio_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node) gpt->gc.get = mpc52xx_gpt_gpio_get; gpt->gc.set = mpc52xx_gpt_gpio_set; gpt->gc.base =-1 ; - gpt->gc.of_gpio_n_cells =2 ; - gpt->gc.of_xlate = of_gpio_simple_xlate; gpt->gc.of_node = node; -of_node_get (node);/* Setup external pin in GPIO mode */ clrsetbits_be32(&gpt->regs->mode, MPC52xx_GPT_MODE_MS_MASK,
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +0 -2
@@ -90,8 +90,6 @@ static int mcu_gpiochip_add(struct mcu *mcu) gc->base =-1 ; gc->set = mcu_gpio_set; gc->direction_output = mcu_gpio_dir_out; - gc->of_gpio_n_cells =2 ; - gc->of_xlate = of_gpio_simple_xlate; gc->of_node = np;return gpiochip_add (gc);
arch/powerpc/sysdev/cpm1.c +0 -2
@@ -633,7 +633,6 @@ int cpm1_gpiochip_add16(struct device_node *np) gc = &mm_gc->gc; mm_gc->save_regs = cpm1_gpio16_save_regs; - gc->of_gpio_n_cells =2 ; gc->ngpio =16 ; gc->direction_input = cpm1_gpio16_dir_in; gc->direction_output = cpm1_gpio16_dir_out;
@@ -755,7 +754,6 @@ int cpm1_gpiochip_add32(struct device_node *np) gc = &mm_gc->gc; mm_gc->save_regs = cpm1_gpio32_save_regs; - gc->of_gpio_n_cells =2 ; gc->ngpio =32 ; gc->direction_input = cpm1_gpio32_dir_in; gc->direction_output = cpm1_gpio32_dir_out;
arch/powerpc/sysdev/cpm_common.c +0 -1
@@ -337,7 +337,6 @@ int cpm2_gpiochip_add32(struct device_node *np) gc = &mm_gc->gc; mm_gc->save_regs = cpm2_gpio32_save_regs; - gc->of_gpio_n_cells =2 ; gc->ngpio =32 ; gc->direction_input = cpm2_gpio32_dir_in; gc->direction_output = cpm2_gpio32_dir_out;
arch/powerpc/sysdev/mpc8xxx_gpio.c +0 -1
@@ -273,7 +273,6 @@ static void __init mpc8xxx_add_controller(struct device_node *np) gc = &mm_gc->gc; mm_gc->save_regs = mpc8xxx_gpio_save_regs; - gc->of_gpio_n_cells =2 ; gc->ngpio =MPC8XXX_GPIO_PINS ; gc->direction_input = mpc8xxx_gpio_dir_in; gc->direction_output = mpc8xxx_gpio_dir_out;
arch/powerpc/sysdev/ppc4xx_gpio.c +0 -1
@@ -194,7 +194,6 @@ static int __init ppc4xx_add_gpiochips(void) mm_gc = &ppc4xx_gc->mm_gc; gc = &mm_gc->gc; - gc->of_gpio_n_cells =2 ; gc->ngpio =32 ; gc->direction_input = ppc4xx_gpio_dir_in; gc->direction_output = ppc4xx_gpio_dir_out;
arch/powerpc/sysdev/qe_lib/gpio.c +0 -1
@@ -321,7 +321,6 @@ static int __init qe_add_gpiochips(void) gc = &mm_gc->gc; mm_gc->save_regs = qe_gpio_save_regs; - gc->of_gpio_n_cells =2 ; gc->ngpio =QE_PIO_PINS ; gc->direction_input = qe_gpio_dir_in; gc->direction_output = qe_gpio_dir_out;
arch/powerpc/sysdev/simple_gpio.c +0 -1
@@ -103,7 +103,6 @@ static int __init u8_simple_gpiochip_add(struct device_node *np) gc = &mm_gc->gc; mm_gc->save_regs = u8_gpio_save_regs; - gc->of_gpio_n_cells =2 ; gc->ngpio =8 ; gc->direction_input = u8_gpio_dir_in; gc->direction_output = u8_gpio_dir_out;
drivers/gpio/gpiolib.c +5 -0
@@ -8,6 +8,7 @@#include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/gpio.h> +#include <linux/of_gpio.h> #include <linux/idr.h> #include <linux/slab.h>
@@ -1099,6 +1100,8 @@ int gpiochip_add(struct gpio_chip *chip) } } +of_gpiochip_add (chip); + unlock:spin_unlock_irqrestore (&gpio_lock, flags);
@@ -1133,6 +1136,8 @@ int gpiochip_remove(struct gpio_chip *chip)spin_lock_irqsave (&gpio_lock, flags); +of_gpiochip_remove (chip); +for (id = chip->base; id < chip->base + chip->ngpio; id++) {if (test_bit (FLAG_REQUESTED , &gpio_desc[id].flags)) { status = -EBUSY ;
drivers/gpio/xilinx_gpio.c +0 -1
@@ -190,7 +190,6 @@ static int __devinit xgpio_of_probe(struct device_node *np)spin_lock_init (&chip->gpio_lock); - chip->mmchip.gc.of_gpio_n_cells =2 ; chip->mmchip.gc.direction_input = xgpio_dir_in; chip->mmchip.gc.direction_output = xgpio_dir_out; chip->mmchip.gc.get = xgpio_get;
drivers/of/gpio.c +24 -9
@@ -125,8 +125,8 @@ EXPORT_SYMBOL(of_gpio_count);* gpio chips. This function performs only one sanity check: whether gpio * is less than ngpios (that is specified in the gpio_chip). */ -int of_gpio_simple_xlate (struct gpio_chip *gc,struct device_node *np, -const void *gpio_spec,u32 *flags) +static int of_gpio_simple_xlate (struct gpio_chip *gc,struct device_node *np, +const void *gpio_spec,u32 *flags) {const __be32 *gpio = gpio_spec;const u32 n =be32_to_cpup (gpio);
@@ -150,7 +150,6 @@ int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np,return n; } -EXPORT_SYMBOL (of_gpio_simple_xlate);/** * of_mm_gpiochip_add - Add memory mapped GPIO chip (bank)
@@ -187,9 +186,6 @@ int of_mm_gpiochip_add(struct device_node *np, gc->base =-1 ; -if (!gc->of_xlate) - gc->of_xlate = of_gpio_simple_xlate; -if (mm_gc->save_regs) mm_gc->save_regs (mm_gc);
@@ -199,9 +195,6 @@ int of_mm_gpiochip_add(struct device_node *np,if (ret) goto err2; -/* We don't want to lose the node and its ->data */ -of_node_get (np); -pr_debug ("%s: registered as generic GPIO chip, base is %d\n" , np->full_name, gc->base);return 0 ;
@@ -216,6 +209,28 @@ err0: }EXPORT_SYMBOL (of_mm_gpiochip_add); +void of_gpiochip_add (struct gpio_chip *chip) +{ +if ((!chip->of_node) && (chip->dev)) + chip->of_node = chip->dev->of_node; + +if (!chip->of_node) +return ; + +if (!chip->of_xlate) { + chip->of_gpio_n_cells =2 ; + chip->of_xlate = of_gpio_simple_xlate; + } + +of_node_get (chip->of_node); +} + +void of_gpiochip_remove (struct gpio_chip *chip) +{ +if (chip->of_node) +of_node_put (chip->of_node); +} +/* Private function for resolving node pointer to gpio_chip */ static int of_gpiochip_is_match (struct gpio_chip *chip,void *data) {
include/linux/of_gpio.h +5 -2
@@ -52,9 +52,9 @@ extern unsigned int of_gpio_count(struct device_node *np);extern int of_mm_gpiochip_add (struct device_node *np,struct of_mm_gpio_chip *mm_gc); -extern int of_gpio_simple_xlate (struct gpio_chip *gc,struct device_node *np, -const void *gpio_spec,u32 *flags); +extern void of_gpiochip_add (struct gpio_chip *gc); +extern void of_gpiochip_remove (struct gpio_chip *gc);extern struct gpio_chip *of_node_to_gpiochip (struct device_node *np);#else /* CONFIG_OF_GPIO */
@@ -71,6 +71,9 @@ static inline unsigned int of_gpio_count(struct device_node *np) return 0; } +static inline void of_gpiochip_add (struct gpio_chip *gc) { } +static inline void of_gpiochip_remove (struct gpio_chip *gc) { } +#endif /* CONFIG_OF_GPIO */ /**
PATCH v2 5/5 of/device: Add OF style matching helper function
In reply to Grant LikelyAdd of_driver_match_device() helper function. This function can be used by bus types to determine if a driver works with a device when using OF style matching. If CONFIG_OF is unselected, then it is a nop.
--- drivers/of/device.c | 2 +- include/linux/of_device.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletions(-)
drivers/of/device.c +1 -1
@@ -20,7 +20,7 @@const struct of_device_id *of_match_device (const struct of_device_id *matches,const struct device *dev) { -if (!dev->of_node) +if ((!matches) || (!dev->of_node))return NULL ;return of_match_node (matches, dev->of_node); }
include/linux/of_device.h +19 -0
@@ -30,6 +30,17 @@extern const struct of_device_id *of_match_device (const struct of_device_id *matches,const struct device *dev); +/** +* of_driver_match_device - Tell if a driver's of_match_table matches a device. +* @drv: the device_driver structure to test +* @dev: the device structure to match against +*/ +static inline int of_driver_match_device (const struct device *dev, +const struct device_driver *drv) +{ +return of_match_device (drv->of_match_table, dev) !=NULL ; +} +extern struct of_device *of_dev_get (struct of_device *dev);extern void of_dev_put (struct of_device *dev);
@@ -48,6 +59,14 @@ extern ssize_t of_device_get_modalias(struct device *dev,extern int of_device_uevent (struct device *dev,struct kobj_uevent_env *env); +#else /* CONFIG_OF_DEVICE */ + +static inline int of_driver_match_device (struct device *dev, +struct device_driver *drv) +{ +return 0 ; +} +#endif /* CONFIG_OF_DEVICE */ #endif /* _LINUX_OF_DEVICE_H */