a19e3da5bc
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. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Anton Vorontsov <avorontsov@ru.mvista.com> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: David Brownell <dbrownell@users.sourceforge.net> Cc: Bill Gatliff <bgat@billgatliff.com> Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Jean Delvare <khali@linux-fr.org>
141 lines
2.8 KiB
C
141 lines
2.8 KiB
C
/*
|
|
* Copyright (C) 2009 Michal Simek <monstr@monstr.eu>
|
|
* Copyright (C) 2009 PetaLogix
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/of_platform.h>
|
|
#include <asm/prom.h>
|
|
|
|
/* Trigger specific functions */
|
|
#ifdef CONFIG_GPIOLIB
|
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
static int handle; /* reset pin handle */
|
|
static unsigned int reset_val;
|
|
|
|
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 gpio_chip *gc;
|
|
u32 flags;
|
|
const void *gpio_spec;
|
|
|
|
/* find out root node */
|
|
root = of_find_node_by_path("/");
|
|
|
|
/* give me handle for gpio node to be possible allocate pin */
|
|
ret = of_parse_phandles_with_args(root, "hard-reset-gpios",
|
|
"#gpio-cells", 0, &gpio, &gpio_spec);
|
|
if (ret) {
|
|
pr_debug("%s: can't parse gpios property\n", __func__);
|
|
goto err0;
|
|
}
|
|
|
|
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 = gc->of_xlate(gc, root, gpio_spec, &flags);
|
|
if (ret < 0)
|
|
goto err1;
|
|
|
|
ret += gc->base;
|
|
err1:
|
|
of_node_put(gpio);
|
|
err0:
|
|
pr_debug("%s exited with status %d\n", __func__, ret);
|
|
return ret;
|
|
}
|
|
|
|
void of_platform_reset_gpio_probe(void)
|
|
{
|
|
int ret;
|
|
handle = of_reset_gpio_handle();
|
|
|
|
if (!gpio_is_valid(handle)) {
|
|
printk(KERN_INFO "Skipping unavailable RESET gpio %d (%s)\n",
|
|
handle, "reset");
|
|
}
|
|
|
|
ret = gpio_request(handle, "reset");
|
|
if (ret < 0) {
|
|
printk(KERN_INFO "GPIO pin is already allocated\n");
|
|
return;
|
|
}
|
|
|
|
/* get current setup value */
|
|
reset_val = gpio_get_value(handle);
|
|
/* FIXME maybe worth to perform any action */
|
|
pr_debug("Reset: Gpio output state: 0x%x\n", reset_val);
|
|
|
|
/* Setup GPIO as output */
|
|
ret = gpio_direction_output(handle, 0);
|
|
if (ret < 0)
|
|
goto err;
|
|
|
|
/* Setup output direction */
|
|
gpio_set_value(handle, 0);
|
|
|
|
printk(KERN_INFO "RESET: Registered gpio device: %d, current val: %d\n",
|
|
handle, reset_val);
|
|
return;
|
|
err:
|
|
gpio_free(handle);
|
|
return;
|
|
}
|
|
|
|
|
|
static void gpio_system_reset(void)
|
|
{
|
|
gpio_set_value(handle, 1 - reset_val);
|
|
}
|
|
#else
|
|
#define gpio_system_reset() do {} while (0)
|
|
void of_platform_reset_gpio_probe(void)
|
|
{
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
void machine_restart(char *cmd)
|
|
{
|
|
printk(KERN_NOTICE "Machine restart...\n");
|
|
gpio_system_reset();
|
|
dump_stack();
|
|
while (1)
|
|
;
|
|
}
|
|
|
|
void machine_shutdown(void)
|
|
{
|
|
printk(KERN_NOTICE "Machine shutdown...\n");
|
|
while (1)
|
|
;
|
|
}
|
|
|
|
void machine_halt(void)
|
|
{
|
|
printk(KERN_NOTICE "Machine halt...\n");
|
|
while (1)
|
|
;
|
|
}
|
|
|
|
void machine_power_off(void)
|
|
{
|
|
printk(KERN_NOTICE "Machine power off...\n");
|
|
while (1)
|
|
;
|
|
}
|