Jeremy Kerr | 0508ad1 | 2017-02-01 10:53:41 -0600 | [diff] [blame] | 1 | /* FSI device & driver interfaces |
| 2 | * |
| 3 | * Copyright (C) IBM Corporation 2016 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef LINUX_FSI_H |
| 16 | #define LINUX_FSI_H |
| 17 | |
| 18 | #include <linux/device.h> |
| 19 | |
Jeremy Kerr | fda07a6 | 2017-02-01 10:53:42 -0600 | [diff] [blame] | 20 | struct fsi_device { |
Jeremy Kerr | dd37eed | 2017-02-01 10:53:43 -0600 | [diff] [blame] | 21 | struct device dev; |
| 22 | u8 engine_type; |
| 23 | u8 version; |
Jeremy Kerr | f7ade2a | 2017-06-06 16:08:44 -0500 | [diff] [blame] | 24 | u8 unit; |
| 25 | struct fsi_slave *slave; |
| 26 | uint32_t addr; |
| 27 | uint32_t size; |
Jeremy Kerr | fda07a6 | 2017-02-01 10:53:42 -0600 | [diff] [blame] | 28 | }; |
| 29 | |
Jeremy Kerr | 4efe37f | 2017-06-06 16:08:45 -0500 | [diff] [blame] | 30 | extern int fsi_device_read(struct fsi_device *dev, uint32_t addr, |
| 31 | void *val, size_t size); |
| 32 | extern int fsi_device_write(struct fsi_device *dev, uint32_t addr, |
| 33 | const void *val, size_t size); |
| 34 | extern int fsi_device_peek(struct fsi_device *dev, void *val); |
| 35 | |
Jeremy Kerr | dd37eed | 2017-02-01 10:53:43 -0600 | [diff] [blame] | 36 | struct fsi_device_id { |
| 37 | u8 engine_type; |
| 38 | u8 version; |
| 39 | }; |
| 40 | |
| 41 | #define FSI_VERSION_ANY 0 |
| 42 | |
| 43 | #define FSI_DEVICE(t) \ |
| 44 | .engine_type = (t), .version = FSI_VERSION_ANY, |
| 45 | |
| 46 | #define FSI_DEVICE_VERSIONED(t, v) \ |
| 47 | .engine_type = (t), .version = (v), |
| 48 | |
Jeremy Kerr | fda07a6 | 2017-02-01 10:53:42 -0600 | [diff] [blame] | 49 | struct fsi_driver { |
Jeremy Kerr | dd37eed | 2017-02-01 10:53:43 -0600 | [diff] [blame] | 50 | struct device_driver drv; |
| 51 | const struct fsi_device_id *id_table; |
Jeremy Kerr | fda07a6 | 2017-02-01 10:53:42 -0600 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | #define to_fsi_dev(devp) container_of(devp, struct fsi_device, dev) |
| 55 | #define to_fsi_drv(drvp) container_of(drvp, struct fsi_driver, drv) |
| 56 | |
Christopher Bostic | 356d800 | 2017-06-06 16:08:48 -0500 | [diff] [blame] | 57 | extern int fsi_driver_register(struct fsi_driver *fsi_drv); |
| 58 | extern void fsi_driver_unregister(struct fsi_driver *fsi_drv); |
| 59 | |
| 60 | /* module_fsi_driver() - Helper macro for drivers that don't do |
| 61 | * anything special in module init/exit. This eliminates a lot of |
| 62 | * boilerplate. Each module may only use this macro once, and |
| 63 | * calling it replaces module_init() and module_exit() |
| 64 | */ |
| 65 | #define module_fsi_driver(__fsi_driver) \ |
| 66 | module_driver(__fsi_driver, fsi_driver_register, \ |
| 67 | fsi_driver_unregister) |
| 68 | |
Jeremy Kerr | da36cad | 2017-06-06 16:08:50 -0500 | [diff] [blame] | 69 | /* direct slave API */ |
| 70 | extern int fsi_slave_claim_range(struct fsi_slave *slave, |
| 71 | uint32_t addr, uint32_t size); |
| 72 | extern void fsi_slave_release_range(struct fsi_slave *slave, |
| 73 | uint32_t addr, uint32_t size); |
| 74 | extern int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, |
| 75 | void *val, size_t size); |
| 76 | extern int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, |
| 77 | const void *val, size_t size); |
| 78 | |
| 79 | |
| 80 | |
Jeremy Kerr | 0508ad1 | 2017-02-01 10:53:41 -0600 | [diff] [blame] | 81 | extern struct bus_type fsi_bus_type; |
| 82 | |
| 83 | #endif /* LINUX_FSI_H */ |