devices/ccat/gpio.c
author Edouard Tisserant <edouard.tisserant@gmail.com>
Wed, 12 Sep 2018 21:22:46 +0200
branchstable-1.5
changeset 2708 742c70a97622
parent 2638 5995331a55fe
permissions -rw-r--r--
Fix C/C++ linking problem in tool/ethercat
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     1
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     2
    Network Driver for Beckhoff CCAT communication controller
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     3
    Copyright (C) 2014  Beckhoff Automation GmbH
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     4
    Author: Patrick Bruenn <p.bruenn@beckhoff.com>
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     5
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     6
    This program is free software; you can redistribute it and/or modify
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     7
    it under the terms of the GNU General Public License as published by
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     8
    the Free Software Foundation; either version 2 of the License, or
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
     9
    (at your option) any later version.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    10
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    11
    This program is distributed in the hope that it will be useful,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    14
    GNU General Public License for more details.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    15
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    16
    You should have received a copy of the GNU General Public License along
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    17
    with this program; if not, write to the Free Software Foundation, Inc.,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    18
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    19
*/
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    20
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    21
#include <linux/kernel.h>
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    22
#include <linux/module.h>
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    23
#include <linux/gpio.h>
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    24
#include <linux/version.h>
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    25
#include "module.h"
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    26
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    27
/**
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    28
 * struct ccat_gpio - CCAT GPIO function
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    29
 * @ioaddr: PCI base address of the CCAT Update function
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    30
 * @info: holds a copy of the CCAT Update function information block (read from PCI config space)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    31
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    32
struct ccat_gpio {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    33
	struct gpio_chip chip;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    34
	void __iomem *ioaddr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    35
	struct mutex lock;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    36
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    37
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    38
/** TODO implement in LED driver
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    39
	#define TC_RED 0x01
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    40
	#define TC_GREEN 0x02
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    41
	#define TC_BLUE 0x04
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    42
	#define FB1_RED 0x08
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    43
	#define FB1_GREEN 0x10
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    44
	#define FB1_BLUE 0x20
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    45
	#define FB2_RED 0x40
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    46
	#define FB2_GREEN 0x80
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    47
	#define FB2_BLUE 0x100
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    48
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    49
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    50
static int set_bit_in_register(struct mutex *lock, void __iomem * ioaddr,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    51
			       unsigned nr, int val)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    52
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    53
	volatile unsigned long old;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    54
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    55
	mutex_lock(lock);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    56
	old = ioread32(ioaddr);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    57
	val ? set_bit(nr, &old) : clear_bit(nr, &old);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    58
	if (val)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    59
		set_bit(nr, &old);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    60
	else
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    61
		clear_bit(nr, &old);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    62
	iowrite32(old, ioaddr);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    63
	mutex_unlock(lock);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    64
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    65
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    66
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    67
static int ccat_gpio_get_direction(struct gpio_chip *chip, unsigned nr)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    68
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    69
	struct ccat_gpio *gdev = container_of(chip, struct ccat_gpio, chip);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    70
	const size_t byte_offset = 4 * (nr / 32) + 0x8;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    71
	const u32 mask = 1 << (nr % 32);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    72
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    73
	return !(mask & ioread32(gdev->ioaddr + byte_offset));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    74
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    75
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    76
static int ccat_gpio_direction_input(struct gpio_chip *chip, unsigned nr)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    77
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    78
	struct ccat_gpio *gdev = container_of(chip, struct ccat_gpio, chip);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    79
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    80
	return set_bit_in_register(&gdev->lock, gdev->ioaddr + 0x8, nr, 0);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    81
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    82
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    83
static int ccat_gpio_direction_output(struct gpio_chip *chip, unsigned nr,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    84
				      int val)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    85
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    86
	struct ccat_gpio *gdev = container_of(chip, struct ccat_gpio, chip);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    87
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    88
	return set_bit_in_register(&gdev->lock, gdev->ioaddr + 0x8, nr, 1);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    89
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    90
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    91
static int ccat_gpio_get(struct gpio_chip *chip, unsigned nr)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    92
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    93
	struct ccat_gpio *gdev = container_of(chip, struct ccat_gpio, chip);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    94
	const size_t byte_off = 4 * (nr / 32);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    95
	const int mask = 1 << (nr % 32);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    96
	int dir_off;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    97
	int value;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    98
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
    99
	/** omit direction changes before value was read */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   100
	mutex_lock(&gdev->lock);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   101
	dir_off = 0x10 * ccat_gpio_get_direction(chip, nr);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   102
	value = !(mask & ioread32(gdev->ioaddr + byte_off + dir_off));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   103
	mutex_unlock(&gdev->lock);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   104
	return value;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   105
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   106
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   107
static void ccat_gpio_set(struct gpio_chip *chip, unsigned nr, int val)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   108
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   109
	struct ccat_gpio *gdev = container_of(chip, struct ccat_gpio, chip);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   110
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   111
	set_bit_in_register(&gdev->lock, gdev->ioaddr, nr, val);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   112
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   113
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   114
static const struct gpio_chip ccat_gpio_chip = {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   115
	.label = KBUILD_MODNAME,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   116
	.owner = THIS_MODULE,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   117
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,12,0))
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   118
	.get_direction = ccat_gpio_get_direction,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   119
#endif
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   120
	.direction_input = ccat_gpio_direction_input,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   121
	.get = ccat_gpio_get,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   122
	.direction_output = ccat_gpio_direction_output,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   123
	.set = ccat_gpio_set,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   124
	.dbg_show = NULL,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   125
	.base = -1,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   126
	.can_sleep = false
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   127
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   128
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   129
static int ccat_gpio_probe(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   130
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   131
	struct ccat_gpio *const gpio = kzalloc(sizeof(*gpio), GFP_KERNEL);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   132
	int ret;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   133
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   134
	if (!gpio)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   135
		return -ENOMEM;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   136
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   137
	gpio->ioaddr = func->ccat->bar_0 + func->info.addr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   138
	memcpy(&gpio->chip, &ccat_gpio_chip, sizeof(gpio->chip));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   139
	gpio->chip.ngpio = func->info.num_gpios;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   140
	mutex_init(&gpio->lock);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   141
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   142
	ret = gpiochip_add(&gpio->chip);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   143
	if (ret) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   144
		kfree(gpio);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   145
		return ret;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   146
	}
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   147
	pr_info("registered %s as gpiochip%d with #%d GPIOs.\n",
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   148
		gpio->chip.label, gpio->chip.base, gpio->chip.ngpio);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   149
	func->private_data = gpio;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   150
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   151
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   152
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   153
static void ccat_gpio_remove(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   154
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   155
	struct ccat_gpio *const gpio = func->private_data;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   156
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   157
	gpiochip_remove(&gpio->chip);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   158
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   159
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2636
diff changeset
   160
const struct ccat_driver gpio_driver = {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   161
	.type = CCATINFO_GPIO,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   162
	.probe = ccat_gpio_probe,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   163
	.remove = ccat_gpio_remove,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents:
diff changeset
   164
};