fsi.h 2.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* FSI device & driver interfaces
 *
 * Copyright (C) IBM Corporation 2016
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef LINUX_FSI_H
#define LINUX_FSI_H

#include <linux/device.h>

20
struct fsi_device {
21 22 23
	struct device		dev;
	u8			engine_type;
	u8			version;
24 25 26 27
	u8			unit;
	struct fsi_slave	*slave;
	uint32_t		addr;
	uint32_t		size;
28 29
};

30 31 32 33 34 35
extern int fsi_device_read(struct fsi_device *dev, uint32_t addr,
		void *val, size_t size);
extern int fsi_device_write(struct fsi_device *dev, uint32_t addr,
		const void *val, size_t size);
extern int fsi_device_peek(struct fsi_device *dev, void *val);

36 37 38 39 40 41 42 43 44 45 46 47 48
struct fsi_device_id {
	u8	engine_type;
	u8	version;
};

#define FSI_VERSION_ANY		0

#define FSI_DEVICE(t) \
	.engine_type = (t), .version = FSI_VERSION_ANY,

#define FSI_DEVICE_VERSIONED(t, v) \
	.engine_type = (t), .version = (v),

49
struct fsi_driver {
50 51
	struct device_driver		drv;
	const struct fsi_device_id	*id_table;
52 53 54 55 56
};

#define to_fsi_dev(devp) container_of(devp, struct fsi_device, dev)
#define to_fsi_drv(drvp) container_of(drvp, struct fsi_driver, drv)

57 58 59 60 61 62 63 64 65 66 67 68
extern int fsi_driver_register(struct fsi_driver *fsi_drv);
extern void fsi_driver_unregister(struct fsi_driver *fsi_drv);

/* module_fsi_driver() - Helper macro for drivers that don't do
 * anything special in module init/exit.  This eliminates a lot of
 * boilerplate.  Each module may only use this macro once, and
 * calling it replaces module_init() and module_exit()
 */
#define module_fsi_driver(__fsi_driver) \
		module_driver(__fsi_driver, fsi_driver_register, \
				fsi_driver_unregister)

69 70 71 72 73 74 75 76 77 78
/* direct slave API */
extern int fsi_slave_claim_range(struct fsi_slave *slave,
		uint32_t addr, uint32_t size);
extern void fsi_slave_release_range(struct fsi_slave *slave,
		uint32_t addr, uint32_t size);
extern int fsi_slave_read(struct fsi_slave *slave, uint32_t addr,
		void *val, size_t size);
extern int fsi_slave_write(struct fsi_slave *slave, uint32_t addr,
		const void *val, size_t size);

79 80
extern struct bus_type fsi_bus_type;
extern const struct device_type fsi_cdev_type;
81

82 83 84 85 86 87
enum fsi_dev_type {
	fsi_dev_cfam,
	fsi_dev_sbefifo,
	fsi_dev_scom,
	fsi_dev_occ
};
88

89 90 91
extern int fsi_get_new_minor(struct fsi_device *fdev, enum fsi_dev_type type,
			     dev_t *out_dev, int *out_index);
extern void fsi_free_minor(dev_t dev);
92 93

#endif /* LINUX_FSI_H */