devices/ccat/module.c
author Florian Pose <fp@igh.de>
Thu, 12 Oct 2017 13:22:06 +0200
branchstable-1.5
changeset 2688 adcbb2ad12e3
parent 2684 56587a22d05c
permissions -rw-r--r--
Fixed statistics filter initialisation.
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     1
/**
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     2
    Network Driver for Beckhoff CCAT communication controller
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
     3
    Copyright (C) 2014-2015  Beckhoff Automation GmbH
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     4
    Author: Patrick Bruenn <p.bruenn@beckhoff.com>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     5
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     6
    This program is free software; you can redistribute it and/or modify
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     7
    it under the terms of the GNU General Public License as published by
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     8
    the Free Software Foundation; either version 2 of the License, or
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
     9
    (at your option) any later version.
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    10
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    11
    This program is distributed in the hope that it will be useful,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    14
    GNU General Public License for more details.
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    15
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    16
    You should have received a copy of the GNU General Public License along
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    17
    with this program; if not, write to the Free Software Foundation, Inc.,
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    18
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    19
*/
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    20
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    21
#include <linux/etherdevice.h>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    22
#include <linux/module.h>
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    23
#include <linux/netdevice.h>
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    24
#include <linux/platform_device.h>
2580
b0be16b7edae CCAT: Support kernels before 3.14 without dma_set_mask_and_coherent().
Florian Pose <fp@igh-essen.com>
parents: 2579
diff changeset
    25
#include <linux/version.h>
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    26
#include "module.h"
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    27
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    28
MODULE_DESCRIPTION(DRV_DESCRIPTION);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    29
MODULE_AUTHOR("Patrick Bruenn <p.bruenn@beckhoff.com>");
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    30
MODULE_LICENSE("GPL");
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    31
MODULE_VERSION(DRV_VERSION);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    32
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    33
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,12,27))
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    34
/*
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    35
 * Set both the DMA mask and the coherent DMA mask to the same thing.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    36
 * Note that we don't check the return value from dma_set_coherent_mask()
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    37
 * as the DMA API guarantees that the coherent DMA mask can be set to
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    38
 * the same or smaller than the streaming DMA mask.
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    39
 */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    40
static inline int dma_set_mask_and_coherent(struct device *dev, u64 mask)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    41
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    42
	int rc = dma_set_mask(dev, mask);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    43
	if (rc == 0)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    44
		dma_set_coherent_mask(dev, mask);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    45
	return rc;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    46
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    47
#endif
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    48
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    49
/**
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    50
 * configure the drivers capabilities here
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
    51
 */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    52
static const struct ccat_driver *const drivers[] = {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    53
#ifdef CONFIG_PCI
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    54
	&eth_dma_driver,	/* load Ethernet MAC/EtherCAT Master driver with DMA support from netdev.c */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    55
#endif
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    56
	&eth_eim_driver,	/* load Ethernet MAC/EtherCAT Master driver without DMA support from */
2684
56587a22d05c Do not build GPIO part of CCAT if GPIO is not configured in kernel.
Florian Pose <fp@igh.de>
parents: 2640
diff changeset
    57
#ifdef CONFIG_GPIO
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    58
	&gpio_driver,		/* load GPIO driver from gpio.c */
2684
56587a22d05c Do not build GPIO part of CCAT if GPIO is not configured in kernel.
Florian Pose <fp@igh.de>
parents: 2640
diff changeset
    59
#endif
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    60
	&sram_driver,		/* load SRAM driver from sram.c */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    61
	&update_driver,		/* load Update driver from update.c */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    62
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    63
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    64
static int __init ccat_class_init(struct ccat_class *base)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    65
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    66
	if (1 == atomic_inc_return(&base->instances)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    67
		if (alloc_chrdev_region
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    68
		    (&base->dev, 0, base->count, KBUILD_MODNAME)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    69
			pr_warn("alloc_chrdev_region() for '%s' failed\n",
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    70
				base->name);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    71
			return -1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    72
		}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    73
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    74
		base->class = class_create(THIS_MODULE, base->name);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    75
		if (!base->class) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    76
			pr_warn("Create device class '%s' failed\n",
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    77
				base->name);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    78
			unregister_chrdev_region(base->dev, base->count);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    79
			return -1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    80
		}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    81
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    82
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    83
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    84
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    85
static void ccat_class_exit(struct ccat_class *base)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    86
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    87
	if (!atomic_dec_return(&base->instances)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    88
		class_destroy(base->class);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    89
		unregister_chrdev_region(base->dev, base->count);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    90
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    91
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    92
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    93
static void free_ccat_cdev(struct ccat_cdev *ccdev)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    94
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    95
	ccat_class_exit(ccdev->class);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    96
	ccdev->dev = 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    97
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    98
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
    99
static struct ccat_cdev *alloc_ccat_cdev(struct ccat_class *base)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   100
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   101
	int i = 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   102
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   103
	ccat_class_init(base);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   104
	for (i = 0; i < base->count; ++i) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   105
		if (base->devices[i].dev == 0) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   106
			base->devices[i].dev = MKDEV(MAJOR(base->dev), i);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   107
			return &base->devices[i];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   108
		}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   109
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   110
	pr_warn("exceeding max. number of '%s' devices (%d)\n",
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   111
		base->class->name, base->count);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   112
	atomic_dec_return(&base->instances);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   113
	return NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   114
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   115
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   116
static int ccat_cdev_init(struct cdev *cdev, dev_t dev, struct class *class,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   117
			  struct file_operations *fops)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   118
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   119
	if (!device_create
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   120
	    (class, NULL, dev, NULL, "%s%d", class->name, MINOR(dev))) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   121
		pr_warn("device_create() failed\n");
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   122
		return -1;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   123
	}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   124
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   125
	cdev_init(cdev, fops);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   126
	cdev->owner = fops->owner;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   127
	if (cdev_add(cdev, dev, 1)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   128
		pr_warn("add update device failed\n");
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   129
		device_destroy(class, dev);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   130
		return -1;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   131
	}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   132
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   133
	pr_info("registered %s%d.\n", class->name, MINOR(dev));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   134
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   135
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   136
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   137
int ccat_cdev_open(struct inode *const i, struct file *const f)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   138
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   139
	struct ccat_cdev *ccdev =
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   140
	    container_of(i->i_cdev, struct ccat_cdev, cdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   141
	struct cdev_buffer *buf;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   142
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   143
	if (!atomic_dec_and_test(&ccdev->in_use)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   144
		atomic_inc(&ccdev->in_use);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   145
		return -EBUSY;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   146
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   147
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   148
	buf = kzalloc(sizeof(*buf) + ccdev->iosize, GFP_KERNEL);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   149
	if (!buf) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   150
		atomic_inc(&ccdev->in_use);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   151
		return -ENOMEM;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   152
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   153
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   154
	buf->ccdev = ccdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   155
	f->private_data = buf;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   156
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   157
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   158
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   159
int ccat_cdev_probe(struct ccat_function *func, struct ccat_class *cdev_class,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   160
		    size_t iosize)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   161
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   162
	struct ccat_cdev *const ccdev = alloc_ccat_cdev(cdev_class);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   163
	if (!ccdev) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   164
		return -ENOMEM;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   165
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   166
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   167
	ccdev->ioaddr = func->ccat->bar_0 + func->info.addr;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   168
	ccdev->iosize = iosize;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   169
	atomic_set(&ccdev->in_use, 1);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   170
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   171
	if (ccat_cdev_init
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   172
	    (&ccdev->cdev, ccdev->dev, cdev_class->class, &cdev_class->fops)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   173
		pr_warn("ccat_cdev_probe() failed\n");
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   174
		free_ccat_cdev(ccdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   175
		return -1;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   176
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   177
	ccdev->class = cdev_class;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   178
	func->private_data = ccdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   179
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   180
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   181
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   182
int ccat_cdev_release(struct inode *const i, struct file *const f)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   183
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   184
	const struct cdev_buffer *const buf = f->private_data;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   185
	struct ccat_cdev *const ccdev = buf->ccdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   186
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   187
	kfree(f->private_data);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   188
	atomic_inc(&ccdev->in_use);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   189
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   190
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   191
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   192
void ccat_cdev_remove(struct ccat_function *func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   193
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   194
	struct ccat_cdev *const ccdev = func->private_data;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   195
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   196
	cdev_del(&ccdev->cdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   197
	device_destroy(ccdev->class->class, ccdev->dev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   198
	free_ccat_cdev(ccdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   199
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   200
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   201
static const struct ccat_driver *ccat_function_connect(struct ccat_function
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   202
						       *const func)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   203
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   204
	int i;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   205
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   206
	for (i = 0; i < ARRAY_SIZE(drivers); ++i) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   207
		if (func->info.type == drivers[i]->type) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   208
			return drivers[i]->probe(func) ? NULL : drivers[i];
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   209
		}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   210
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   211
	return NULL;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   212
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   213
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   214
/**
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   215
 * Initialize all available CCAT functions.
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   216
 *
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   217
 * Return: count of failed functions
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   218
 */
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   219
static int ccat_functions_init(struct ccat_device *const ccatdev)
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   220
{
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2567
diff changeset
   221
	static const size_t block_size = sizeof(struct ccat_info_block);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   222
	struct ccat_function *next = kzalloc(sizeof(*next), GFP_KERNEL);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   223
	void __iomem *addr = ccatdev->bar_0; /** first block is the CCAT information block entry */
2569
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2567
diff changeset
   224
	const u8 num_func = ioread8(addr + 4); /** number of CCAT function blocks is at offset 0x4 */
720172a7563f make ccat driver more linux compliant
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2567
diff changeset
   225
	const void __iomem *end = addr + (block_size * num_func);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   226
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   227
	INIT_LIST_HEAD(&ccatdev->functions);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   228
	for (; addr < end && next; addr += block_size) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   229
		memcpy_fromio(&next->info, addr, sizeof(next->info));
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   230
		if (CCATINFO_NOTUSED != next->info.type) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   231
			next->ccat = ccatdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   232
			next->drv = ccat_function_connect(next);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   233
			if (next->drv) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   234
				list_add(&next->list, &ccatdev->functions);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   235
				next = kzalloc(sizeof(*next), GFP_KERNEL);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   236
			}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   237
		}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   238
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   239
	kfree(next);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   240
	return list_empty(&ccatdev->functions);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   241
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   242
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   243
/**
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   244
 * Destroy all previously initialized CCAT functions
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   245
 */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   246
static void ccat_functions_remove(struct ccat_device *const dev)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   247
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   248
	struct ccat_function *func;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   249
	struct ccat_function *tmp;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   250
	list_for_each_entry_safe(func, tmp, &dev->functions, list) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   251
		if (func->drv) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   252
			func->drv->remove(func);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   253
			func->drv = NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   254
		}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   255
		list_del(&func->list);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   256
		kfree(func);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   257
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   258
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   259
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   260
#ifdef CONFIG_PCI
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   261
static int ccat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   262
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   263
	struct ccat_device *ccatdev;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   264
	u8 rev;
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   265
	int status;
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   266
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   267
	ccatdev = devm_kzalloc(&pdev->dev, sizeof(*ccatdev), GFP_KERNEL);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   268
	if (!ccatdev) {
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   269
		pr_err("%s() out of memory.\n", __FUNCTION__);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   270
		return -ENOMEM;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   271
	}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   272
	ccatdev->pdev = pdev;
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   273
	pci_set_drvdata(pdev, ccatdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   274
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   275
	status = pci_enable_device_mem(pdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   276
	if (status) {
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   277
		pr_err("enable %s failed: %d\n", pdev->dev.kobj.name, status);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   278
		return status;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   279
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   280
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   281
	status = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   282
	if (status) {
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   283
		pr_err("read CCAT pci revision failed with %d\n", status);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   284
		goto disable_device;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   285
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   286
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   287
	status = pci_request_regions(pdev, KBUILD_MODNAME);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   288
	if (status) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   289
		pr_err("allocate mem_regions failed.\n");
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   290
		goto disable_device;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   291
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   292
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   293
	status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   294
	if (status) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   295
		status =
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   296
		    dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   297
		if (status) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   298
			pr_err("No suitable DMA available, pci rev: %u\n", rev);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   299
			goto release_regions;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   300
		}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   301
		pr_debug("32 bit DMA supported, pci rev: %u\n", rev);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   302
	} else {
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   303
		pr_debug("64 bit DMA supported, pci rev: %u\n", rev);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   304
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   305
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   306
	ccatdev->bar_0 = pci_iomap(pdev, 0, 0);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   307
	if (!ccatdev->bar_0) {
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   308
		pr_err("initialization of bar0 failed.\n");
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   309
		status = -EIO;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   310
		goto release_regions;
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   311
	}
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   312
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   313
	ccatdev->bar_2 = pci_iomap(pdev, 2, 0);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   314
	if (!ccatdev->bar_2) {
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   315
		pr_warn("initialization of optional bar2 failed.\n");
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   316
	}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   317
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   318
	pci_set_master(pdev);
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   319
	if (ccat_functions_init(ccatdev)) {
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   320
		pr_warn("some functions couldn't be initialized\n");
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   321
	}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   322
	return 0;
2638
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   323
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   324
release_regions:
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   325
	pci_release_regions(pdev);
5995331a55fe update ccat driver to v0.14
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2637
diff changeset
   326
disable_device:
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   327
	pci_disable_device(pdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   328
	return status;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   329
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   330
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   331
static void ccat_pci_remove(struct pci_dev *pdev)
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   332
{
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   333
	struct ccat_device *ccatdev = pci_get_drvdata(pdev);
2567
d70aad2f131f - use short kernel types, add empty lines after variable declaration to conform better with linux coding style
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2565
diff changeset
   334
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   335
	if (ccatdev) {
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   336
		ccat_functions_remove(ccatdev);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   337
		if (ccatdev->bar_2)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   338
			pci_iounmap(pdev, ccatdev->bar_2);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   339
		pci_iounmap(pdev, ccatdev->bar_0);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   340
		pci_release_regions(pdev);
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   341
		pci_disable_device(pdev);
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   342
	}
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   343
}
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   344
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   345
#define PCI_DEVICE_ID_BECKHOFF_CCAT 0x5000
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   346
#define PCI_VENDOR_ID_BECKHOFF 0x15EC
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   347
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   348
static const struct pci_device_id pci_ids[] = {
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   349
	{PCI_DEVICE(PCI_VENDOR_ID_BECKHOFF, PCI_DEVICE_ID_BECKHOFF_CCAT)},
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   350
	{0,},
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   351
};
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   352
2640
b11e1014edfe Prevent CCAT auto-loading.
Florian Pose <fp@igh-essen.com>
parents: 2638
diff changeset
   353
/* prevent auto-loading. */
b11e1014edfe Prevent CCAT auto-loading.
Florian Pose <fp@igh-essen.com>
parents: 2638
diff changeset
   354
/* MODULE_DEVICE_TABLE(pci, pci_ids); */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   355
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   356
static struct pci_driver ccat_pci_driver = {
2565
f7b06b264646 - restored examples/user/
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2553
diff changeset
   357
	.name = KBUILD_MODNAME,
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   358
	.id_table = pci_ids,
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   359
	.probe = ccat_pci_probe,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   360
	.remove = ccat_pci_remove,
2550
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   361
};
7e25950ea941 replace not working symlinks with real copies from the ccat main repository(git)
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2549
diff changeset
   362
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   363
module_pci_driver(ccat_pci_driver);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   364
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   365
#else /* #ifdef CONFIG_PCI */
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   366
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   367
static int ccat_eim_probe(struct platform_device *pdev)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   368
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   369
	struct ccat_device *ccatdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   370
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   371
	ccatdev = devm_kzalloc(&pdev->dev, sizeof(*ccatdev), GFP_KERNEL);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   372
	if (!ccatdev) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   373
		pr_err("%s() out of memory.\n", __FUNCTION__);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   374
		return -ENOMEM;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   375
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   376
	ccatdev->pdev = pdev;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   377
	platform_set_drvdata(pdev, ccatdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   378
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   379
	if (!request_mem_region(0xf0000000, 0x02000000, pdev->name)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   380
		pr_warn("request mem region failed.\n");
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   381
		return -EIO;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   382
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   383
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   384
	if (!(ccatdev->bar_0 = ioremap(0xf0000000, 0x02000000))) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   385
		pr_warn("initialization of bar0 failed.\n");
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   386
		return -EIO;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   387
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   388
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   389
	ccatdev->bar_2 = NULL;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   390
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   391
	if (ccat_functions_init(ccatdev)) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   392
		pr_warn("some functions couldn't be initialized\n");
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   393
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   394
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   395
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   396
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   397
static int ccat_eim_remove(struct platform_device *pdev)
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   398
{
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   399
	struct ccat_device *ccatdev = platform_get_drvdata(pdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   400
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   401
	if (ccatdev) {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   402
		ccat_functions_remove(ccatdev);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   403
		iounmap(ccatdev->bar_0);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   404
		release_mem_region(0xf0000000, 0x02000000);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   405
	}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   406
	return 0;
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   407
}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   408
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   409
static const struct of_device_id bhf_eim_ccat_ids[] = {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   410
	{.compatible = "bhf,emi-ccat",},
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   411
	{}
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   412
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   413
2640
b11e1014edfe Prevent CCAT auto-loading.
Florian Pose <fp@igh-essen.com>
parents: 2638
diff changeset
   414
/* prevent auto-loading. */
b11e1014edfe Prevent CCAT auto-loading.
Florian Pose <fp@igh-essen.com>
parents: 2638
diff changeset
   415
/* MODULE_DEVICE_TABLE(of, bhf_eim_ccat_ids); */
2636
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   416
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   417
static struct platform_driver ccat_eim_driver = {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   418
	.driver = {
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   419
		   .name = KBUILD_MODNAME,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   420
		   .of_match_table = bhf_eim_ccat_ids,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   421
		   },
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   422
	.probe = ccat_eim_probe,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   423
	.remove = ccat_eim_remove,
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   424
};
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   425
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   426
module_platform_driver(ccat_eim_driver);
0613017547fe update ccat driver to v0.13
Patrick Bruenn <p.bruenn@beckhoff.com>
parents: 2580
diff changeset
   427
#endif /* #ifdef CONFIG_PCI */