#define xgpio_writereg(offset, val) __raw_writel(val, offset)
struct xgpio_instance {
-#ifdef CONFIG_OF
struct of_mm_gpio_chip mmchip;
-#else
- struct gpio_chip gc;
- void __iomem *regs;
-#endif
u32 gpio_state; /* GPIO state shadow register */
u32 gpio_dir; /* GPIO direction shadow register */
u32 offset;
*/
static int xgpio_get(struct gpio_chip *gc, unsigned int gpio)
{
-#ifdef CONFIG_OF
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
struct xgpio_instance *chip =
container_of(mm_gc, struct xgpio_instance, mmchip);
void __iomem *regs = mm_gc->regs + chip->offset;
-#else
- struct xgpio_instance *chip = container_of(gc, struct xgpio_instance,
- gc);
- void __iomem *regs = chip->regs;
-#endif
+
return (xgpio_readreg(regs + XGPIO_DATA_OFFSET) >> gpio) & 1;
}
static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
{
unsigned long flags;
-#ifdef CONFIG_OF
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
struct xgpio_instance *chip =
container_of(mm_gc, struct xgpio_instance, mmchip);
void __iomem *regs = mm_gc->regs;
-#else
- struct xgpio_instance *chip = container_of(gc, struct xgpio_instance,
- gc);
- void __iomem *regs = chip->regs;
-#endif
spin_lock_irqsave(&chip->gpio_lock, flags);
static int xgpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
{
unsigned long flags;
-#ifdef CONFIG_OF
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
struct xgpio_instance *chip =
container_of(mm_gc, struct xgpio_instance, mmchip);
void __iomem *regs = mm_gc->regs;
-#else
- struct xgpio_instance *chip = container_of(gc, struct xgpio_instance,
- gc);
- void __iomem *regs = chip->regs;
-#endif
spin_lock_irqsave(&chip->gpio_lock, flags);
static int xgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
{
unsigned long flags;
-#ifdef CONFIG_OF
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
struct xgpio_instance *chip =
container_of(mm_gc, struct xgpio_instance, mmchip);
void __iomem *regs = mm_gc->regs;
-#else
- struct xgpio_instance *chip = container_of(gc, struct xgpio_instance,
- gc);
- void __iomem *regs = chip->regs;
-#endif
spin_lock_irqsave(&chip->gpio_lock, flags);
return 0;
}
-#ifdef CONFIG_OF
/**
* xgpio_save_regs - Set initial values of GPIO pins
* @mm_gc: pointer to memory mapped GPIO chip structure
{ /* end of list */ },
};
-#else
-
-/**
- * xgpio_probe - Probe method for the GPIO device
- * @pdev: platform device instance
- *
- * This function allocates memory resources for the xgpio device and initializes
- * the driver structures.
- *
- * Return: 0 on success, negative error otherwise.
- */
-static int __init xgpio_probe(struct platform_device *pdev)
-{
- int ret;
- struct xgpio_instance *chip;
- struct gpio_chip *gc;
- struct resource *mem_res = NULL;
- struct xgpio_platform_data *pdata;
-
- chip = kzalloc(sizeof(struct xgpio_instance), GFP_KERNEL);
- if (!chip) {
- dev_err(&pdev->dev, "couldn't allocate memory for gpio private "
- "data\n");
- return -ENOMEM;
- }
-
- platform_set_drvdata(pdev, chip);
-
- mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!mem_res) {
- dev_err(&pdev->dev, "No memory resource\n");
- ret = -ENODEV;
- goto err_free_gpio;
- }
-
- if (!request_mem_region(mem_res->start, resource_size(mem_res),
- pdev->name)) {
- dev_err(&pdev->dev, "Cannot request IO\n");
- ret = -ENXIO;
- goto err_free_gpio;
- }
-
- pdata = pdev->dev.platform_data;
- if (pdata == NULL) {
- dev_err(&pdev->dev, "Cannot find platform data\n");
- return -ENODEV;
- }
-
- chip->regs = ioremap(mem_res->start, resource_size(mem_res));
- if (chip->regs == NULL) {
- dev_err(&pdev->dev, "Couldn't ioremap memory at 0x%08lx\n",
- (unsigned long)mem_res->start);
- ret = -ENOMEM;
- goto err_release_region;
- }
-
- chip->gpio_state = pdata->state;
- chip->gpio_dir = pdata->dir;
-
- xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET, chip->gpio_state);
- xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET, chip->gpio_dir);
-
- /* configure the gpio chip */
- gc = &chip->gc;
- gc->label = "xgpio";
- gc->owner = THIS_MODULE;
- gc->dev = &pdev->dev;
- gc->get = xgpio_get;
- gc->set = xgpio_set;
- gc->direction_input = xgpio_dir_in;
- gc->direction_output = xgpio_dir_out;
- gc->dbg_show = NULL;
- gc->base = 0; /* default pin base */
- gc->ngpio = pdata->width;
- gc->can_sleep = 0;
-
- ret = gpiochip_add(gc);
- if (ret < 0) {
- dev_err(&pdev->dev, "gpio gc registration failed\n");
- goto err_iounmap;
- } else
- dev_info(&pdev->dev, "gpio at 0x%08lx mapped to 0x%08lx\n",
- (unsigned long)mem_res->start,
- (unsigned long)chip->regs);
-
- return 0;
-
-err_iounmap:
- iounmap(chip->regs);
-err_release_region:
- release_mem_region(mem_res->start, resource_size(mem_res));
-err_free_gpio:
- platform_set_drvdata(pdev, NULL);
- kfree(chip);
-
- return ret;
-}
-
-static struct platform_driver xgpio_driver = {
- .driver = {
- .name = "xilinx_gpio",
- .owner = THIS_MODULE,
- },
- .probe = xgpio_probe,
-};
-
-#endif /* CONFIG_OF */
-
static int __init xgpio_init(void)
{
-#ifdef CONFIG_OF
struct device_node *np;
for_each_matching_node(np, xgpio_of_match)
xgpio_of_probe(np);
return 0;
-#else
- return platform_driver_register(&xgpio_driver);
-#endif
}
/* Make sure we get initialized before anyone else tries to use us */