1d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez/*
2d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez * Industry-pack bus.
3d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
476859725ad31ac480d55bf176e5bbe0f9ab6e6cbSamuel Iglesias Gonsalvez * Copyright (C) 2011-2012 CERN (www.cern.ch)
576859725ad31ac480d55bf176e5bbe0f9ab6e6cbSamuel Iglesias Gonsalvez * Author: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
6d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
7d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez * This program is free software; you can redistribute it and/or modify it
8d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez * under the terms of the GNU General Public License as published by the Free
9416289b14a8ab1a0fea7b7ee03724c4820578427Samuel Iglesias Gonsalvez * Software Foundation; version 2 of the License.
10d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
11d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
12849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge#include <linux/mod_devicetable.h>
13d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#include <linux/device.h>
14faa75c406e7396a952c3ebedfc2b1d6f1b8d2648Jens Taprogge#include <linux/interrupt.h>
15d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
16d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_I			0x01
17d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_P			0x03
18d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_A			0x05
19d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_C			0x07
20d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_MANUFACTURER_ID	0x09
21d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_MODEL		0x0B
22d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_REVISION		0x0D
23d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_RESERVED		0x0F
24d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_DRIVER_ID_L		0x11
25d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_DRIVER_ID_H		0x13
26d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_NUM_BYTES		0x15
27d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez#define IPACK_IDPROM_OFFSET_CRC			0x17
28d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
2927cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez/*
3027cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez * IndustryPack Fromat, Vendor and Device IDs.
3127cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez */
3227cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez
3327cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez/* ID section format versions */
3427cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK_ID_VERSION_INVALID	0x00
3527cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK_ID_VERSION_1		0x01
3627cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK_ID_VERSION_2		0x02
3727cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez
3827cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez/* Vendors and devices. Sort key: vendor first, device next. */
3927cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_RESERVED1	0x00
4027cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_RESERVED2	0xFF
4127cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED01	0x01
4227cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED02	0x02
4327cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED03	0x03
4427cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED04	0x04
4527cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED05	0x05
4627cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED06	0x06
4727cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED07	0x07
4827cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED08	0x08
4927cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED09	0x09
5027cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED10	0x0A
5127cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED11	0x0B
5227cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED12	0x0C
5327cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED13	0x0D
5427cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED14	0x0E
5527cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_UNREGISTRED15	0x0F
5627cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez
5727cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_VENDOR_ID_SBS            0xF0
5827cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_DEVICE_ID_SBS_OCTAL_232  0x22
5927cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_DEVICE_ID_SBS_OCTAL_422  0x2A
6027cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez#define IPACK1_DEVICE_ID_SBS_OCTAL_485  0x48
6127cf2d1b873fc50a2c0388253ec666fa4c61bfd4Samuel Iglesias Gonsalvez
62d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezstruct ipack_bus_ops;
63d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezstruct ipack_driver;
64d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
65d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezenum ipack_space {
66d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	IPACK_IO_SPACE    = 0,
6784a08fa9eb330969b661305bd5a5fcae06d98cbaJens Taprogge	IPACK_ID_SPACE,
68e4af9497b65a8245ad7ef756d5f698e78db6e11cJens Taprogge	IPACK_INT_SPACE,
69fe4a3ed0d5ce09de5b61335ce51c74caa2a92911Jens Taprogge	IPACK_MEM8_SPACE,
7048a97352e18f6ec90355ce1ea70a3f750664adfcJens Taprogge	IPACK_MEM16_SPACE,
7184a08fa9eb330969b661305bd5a5fcae06d98cbaJens Taprogge	/* Dummy for counting the number of entries.  Must remain the last
7284a08fa9eb330969b661305bd5a5fcae06d98cbaJens Taprogge	 * entry */
7384a08fa9eb330969b661305bd5a5fcae06d98cbaJens Taprogge	IPACK_SPACE_COUNT,
74d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez};
75d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
76d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez/**
77bb29ab86d18da68e5c7f05814c07d5eb8bdb4652Jens Taprogge */
78bb29ab86d18da68e5c7f05814c07d5eb8bdb4652Jens Taproggestruct ipack_region {
79bb29ab86d18da68e5c7f05814c07d5eb8bdb4652Jens Taprogge	phys_addr_t start;
80bb29ab86d18da68e5c7f05814c07d5eb8bdb4652Jens Taprogge	size_t      size;
81bb29ab86d18da68e5c7f05814c07d5eb8bdb4652Jens Taprogge};
82bb29ab86d18da68e5c7f05814c07d5eb8bdb4652Jens Taprogge
83bb29ab86d18da68e5c7f05814c07d5eb8bdb4652Jens Taprogge/**
84d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	struct ipack_device
85d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
86d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@slot: Slot where the device is plugged in the carrier board
87ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez *	@bus: ipack_bus_device where the device is plugged to.
88d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@id_space: Virtual address to ID space.
89d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@io_space: Virtual address to IO space.
90d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@mem_space: Virtual address to MEM space.
91d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@dev: device in kernel representation.
92d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
93d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez * Warning: Direct access to mapped memory is possible but the endianness
94d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez * is not the same with PCI carrier or VME carrier. The endianness is managed
95ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * by the carrier board throught bus->ops.
96d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
97d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezstruct ipack_device {
98d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	unsigned int slot;
99ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez	struct ipack_bus_device *bus;
100d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	struct device dev;
1011e91795c8cea4287b155862793271fe6a7737d20Jens Taprogge	void (*release) (struct ipack_device *dev);
102a19ad7d08744bd3ea6efeccbcddcc4a992bc6ac9Jens Taprogge	struct ipack_region      region[IPACK_SPACE_COUNT];
103e8ed3276c24238adb7e676d56a82bc9c7f4fe912Jens Taprogge	u8                      *id;
104187e4782401329663bda870f432fdbeb8154fe3fJens Taprogge	size_t			 id_avail;
105e8ed3276c24238adb7e676d56a82bc9c7f4fe912Jens Taprogge	u32			 id_vendor;
106e8ed3276c24238adb7e676d56a82bc9c7f4fe912Jens Taprogge	u32			 id_device;
107187e4782401329663bda870f432fdbeb8154fe3fJens Taprogge	u8			 id_format;
108a92caeb8e1189f190ac13bb5e745446b25b09ae5Jens Taprogge	unsigned int		 id_crc_correct:1;
1090b0f3a1bee7f321b92ffc37d8b32d1ce412a285cJens Taprogge	unsigned int		 speed_8mhz:1;
1100b0f3a1bee7f321b92ffc37d8b32d1ce412a285cJens Taprogge	unsigned int		 speed_32mhz:1;
111d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez};
112d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
113ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez/**
11426c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge * struct ipack_driver_ops -- Callbacks to IPack device driver
115d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
11626c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge * @probe:  Probe function
11726c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge * @remove: Prepare imminent removal of the device.  Services provided by the
11826c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge *          device should be revoked.
119d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
120d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
121d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezstruct ipack_driver_ops {
122d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	int (*probe) (struct ipack_device *dev);
123d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	void (*remove) (struct ipack_device *dev);
124d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez};
125d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
126d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez/**
12726c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge * struct ipack_driver -- Specific data to each ipack device driver
128d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
12926c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge * @driver: Device driver kernel representation
13026c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge * @ops:    Callbacks provided by the IPack device driver
131d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
132d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezstruct ipack_driver {
133d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	struct device_driver driver;
134849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge	const struct ipack_device_id *id_table;
135e80111354ac95cd0453e12caf9044938b7a78137Jens Taprogge	const struct ipack_driver_ops *ops;
136d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez};
137d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
138d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez/**
139d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	struct ipack_bus_ops - available operations on a bridge module
140d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
141d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@map_space: map IP address space
142d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@unmap_space: unmap IP address space
143d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@request_irq: request IRQ
144d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@free_irq: free IRQ
1457b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *	@get_clockrate: Returns the clockrate the carrier is currently
1467b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *		communicating with the device at.
1477b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *	@set_clockrate: Sets the clock-rate for carrier / module communication.
1487b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *		Should return -EINVAL if the requested speed is not supported.
1497b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *	@get_error: Returns the error state for the slot the device is attached
1507b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *		to.
1517b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *	@get_timeout: Returns 1 if the communication with the device has
1527b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *		previously timed out.
1537b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge *	@reset_timeout: Resets the state returned by get_timeout.
154d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
155d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezstruct ipack_bus_ops {
156c6e2dfaa5251f584a05df74911685775dd750e2dJens Taprogge	int (*request_irq) (struct ipack_device *dev,
157faa75c406e7396a952c3ebedfc2b1d6f1b8d2648Jens Taprogge			    irqreturn_t (*handler)(void *), void *arg);
158d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	int (*free_irq) (struct ipack_device *dev);
1597b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge	int (*get_clockrate) (struct ipack_device *dev);
1607b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge	int (*set_clockrate) (struct ipack_device *dev, int mherz);
1617b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge	int (*get_error) (struct ipack_device *dev);
1627b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge	int (*get_timeout) (struct ipack_device *dev);
1637b6ab33c28980ae26de09654a0d5db6080c76921Jens Taprogge	int (*reset_timeout) (struct ipack_device *dev);
164d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez};
165d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
166d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez/**
167d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	struct ipack_bus_device
168d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
169d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@dev: pointer to carrier device
170d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@slots: number of slots available
171d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	@bus_nr: ipack bus number
172ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez *	@ops: bus operations for the mezzanine drivers
173d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
174d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezstruct ipack_bus_device {
17536c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga	struct module *owner;
176ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez	struct device *parent;
177d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	int slots;
178d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez	int bus_nr;
1799869a937d3a93c75c1d32e61df29149ce78ec3f9Stephen Hemminger	const struct ipack_bus_ops *ops;
180d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez};
181d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
182d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez/**
183d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	ipack_bus_register -- register a new ipack bus
184d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *
185ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * @parent: pointer to the parent device, if any.
186ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * @slots: number of slots available in the bus device.
187ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * @ops: bus operations for the mezzanine drivers.
188ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez *
189ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * The carrier board device should call this function to register itself as
190ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * available bus device in ipack.
191d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
192ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvezstruct ipack_bus_device *ipack_bus_register(struct device *parent, int slots,
19336c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga					    const struct ipack_bus_ops *ops,
19436c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga					    struct module *owner);
195d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez
196d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez/**
197d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez *	ipack_bus_unregister -- unregister an ipack bus
198d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvez */
199d3465872c5b38613fb5ad10a9756db9372630b22Samuel Iglesias Gonsalvezint ipack_bus_unregister(struct ipack_bus_device *bus);
200ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez
201ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez/**
20226c295cb4bd2a18f943a9962c6f954c8daee90f7Jens Taprogge * ipack_driver_register -- Register a new ipack device driver
203ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez *
204ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * Called by a ipack driver to register itself as a driver
205ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez * that can manage ipack devices.
206ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez */
2079869a937d3a93c75c1d32e61df29149ce78ec3f9Stephen Hemmingerint ipack_driver_register(struct ipack_driver *edrv, struct module *owner,
2089869a937d3a93c75c1d32e61df29149ce78ec3f9Stephen Hemminger			  const char *name);
209ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvezvoid ipack_driver_unregister(struct ipack_driver *edrv);
210ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez
211ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez/**
212e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez *	ipack_device_init -- initialize an IPack device
213e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * @dev: the new device to initialize.
214ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez *
215e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * Initialize a new IPack device ("module" in IndustryPack jargon). The call
216e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * is done by the carrier driver.  The carrier should populate the fields
217e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * bus and slot as well as the region array of @dev prior to calling this
218e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * function.  The rest of the fields will be allocated and populated
219e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * during initalization.
220ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez *
221e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * Return zero on success or error code on failure.
222e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez *
223e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * NOTE: _Never_ directly free @dev after calling this function, even
224e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * if it returned an error! Always use ipack_put_device() to give up the
225e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * reference initialized in this function instead.
226e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez */
227e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvezint ipack_device_init(struct ipack_device *dev);
228e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez
229e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez/**
230e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez *	ipack_device_add -- Add an IPack device
231e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * @dev: the new device to add.
232e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez *
233e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * Add a new IPack device. The call is done by the carrier driver
234e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * after calling ipack_device_init().
235e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez *
236e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * Return zero on success or error code on failure.
237e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez *
238e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * NOTE: _Never_ directly free @dev after calling this function, even
239e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * if it returned an error! Always use ipack_put_device() to give up the
240e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvez * reference initialized in this function instead.
241ec440335b1e360ab82ef4ce169b682ab4b9dcd2aSamuel Iglesias Gonsalvez */
242e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvezint ipack_device_add(struct ipack_device *dev);
243e926301b39a07f587ff8c66354a2e2ee4c29162cSamuel Iglesias Gonsalvezvoid ipack_device_del(struct ipack_device *dev);
244849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge
245fa882867ae5f8543eb304a1667563f1c99514475Samuel Iglesias Gonsalvezvoid ipack_get_device(struct ipack_device *dev);
246fa882867ae5f8543eb304a1667563f1c99514475Samuel Iglesias Gonsalvezvoid ipack_put_device(struct ipack_device *dev);
247fa882867ae5f8543eb304a1667563f1c99514475Samuel Iglesias Gonsalvez
248849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge/**
249849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * DEFINE_IPACK_DEVICE_TABLE - macro used to describe a IndustryPack table
250849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * @_table: device table name
251849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge *
252849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * This macro is used to create a struct ipack_device_id array (a device table)
253849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * in a generic manner.
254849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge */
255849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge#define DEFINE_IPACK_DEVICE_TABLE(_table) \
256d79251f0fc2fdb7587c99617aae0bf52ff6c5510Bill Pemberton	const struct ipack_device_id _table[]
257849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge/**
258849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * IPACK_DEVICE - macro used to describe a specific IndustryPack device
259849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * @_format: the format version (currently either 1 or 2, 8 bit value)
260849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * @vend:    the 8 or 24 bit IndustryPack Vendor ID
261849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * @dev:     the 8 or 16  bit IndustryPack Device ID
262849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge *
263849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * This macro is used to create a struct ipack_device_id that matches a specific
264849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge * device.
265849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge */
266849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge#define IPACK_DEVICE(_format, vend, dev) \
267849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge	 .format = (_format), \
268849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge	 .vendor = (vend), \
269849e0ad257d259b8443c63d74e3bcc32ebf336afJens Taprogge	 .device = (dev)
27036c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga
27136c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga/**
27236c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga * ipack_get_carrier - it increase the carrier ref. counter of
27336c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga *                     the carrier module
27436c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga * @dev: mezzanine device which wants to get the carrier
27536c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga */
27636c53b3cc3fac6952af68f43609b15ae050c9318Federico Vagastatic inline int ipack_get_carrier(struct ipack_device *dev)
27736c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga{
27836c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga	return try_module_get(dev->bus->owner);
27936c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga}
28036c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga
28136c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga/**
28236c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga * ipack_get_carrier - it decrease the carrier ref. counter of
28336c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga *                     the carrier module
28436c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga * @dev: mezzanine device which wants to get the carrier
28536c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga */
28636c53b3cc3fac6952af68f43609b15ae050c9318Federico Vagastatic inline void ipack_put_carrier(struct ipack_device *dev)
28736c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga{
28836c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga	module_put(dev->bus->owner);
28936c53b3cc3fac6952af68f43609b15ae050c9318Federico Vaga}
290