1b886d83cSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
23764e82eSJohannes Thumshirn /*
33764e82eSJohannes Thumshirn * MEN Chameleon Bus.
43764e82eSJohannes Thumshirn *
53764e82eSJohannes Thumshirn * Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
63764e82eSJohannes Thumshirn * Author: Johannes Thumshirn <[email protected]>
73764e82eSJohannes Thumshirn */
83764e82eSJohannes Thumshirn #ifndef _LINUX_MCB_H
93764e82eSJohannes Thumshirn #define _LINUX_MCB_H
103764e82eSJohannes Thumshirn
113764e82eSJohannes Thumshirn #include <linux/mod_devicetable.h>
123764e82eSJohannes Thumshirn #include <linux/device.h>
133764e82eSJohannes Thumshirn #include <linux/irqreturn.h>
143764e82eSJohannes Thumshirn
15803f1ca6SJohannes Thumshirn #define CHAMELEON_FILENAME_LEN 12
16803f1ca6SJohannes Thumshirn
173764e82eSJohannes Thumshirn struct mcb_driver;
184ec65b77SJohannes Thumshirn struct mcb_device;
193764e82eSJohannes Thumshirn
203764e82eSJohannes Thumshirn /**
213764e82eSJohannes Thumshirn * struct mcb_bus - MEN Chameleon Bus
223764e82eSJohannes Thumshirn *
2318d28819SJohannes Thumshirn * @dev: bus device
2418d28819SJohannes Thumshirn * @carrier: pointer to carrier device
253764e82eSJohannes Thumshirn * @bus_nr: mcb bus number
264ec65b77SJohannes Thumshirn * @get_irq: callback to get IRQ number
27803f1ca6SJohannes Thumshirn * @revision: the FPGA's revision number
28803f1ca6SJohannes Thumshirn * @model: the FPGA's model number
29803f1ca6SJohannes Thumshirn * @filename: the FPGA's name
303764e82eSJohannes Thumshirn */
313764e82eSJohannes Thumshirn struct mcb_bus {
323764e82eSJohannes Thumshirn struct device dev;
334ec65b77SJohannes Thumshirn struct device *carrier;
343764e82eSJohannes Thumshirn int bus_nr;
35803f1ca6SJohannes Thumshirn u8 revision;
36803f1ca6SJohannes Thumshirn char model;
37803f1ca6SJohannes Thumshirn u8 minor;
38803f1ca6SJohannes Thumshirn char name[CHAMELEON_FILENAME_LEN + 1];
394ec65b77SJohannes Thumshirn int (*get_irq)(struct mcb_device *dev);
403764e82eSJohannes Thumshirn };
4168d9671aSJohannes Thumshirn
to_mcb_bus(struct device * dev)4268d9671aSJohannes Thumshirn static inline struct mcb_bus *to_mcb_bus(struct device *dev)
4368d9671aSJohannes Thumshirn {
4468d9671aSJohannes Thumshirn return container_of(dev, struct mcb_bus, dev);
4568d9671aSJohannes Thumshirn }
463764e82eSJohannes Thumshirn
473764e82eSJohannes Thumshirn /**
483764e82eSJohannes Thumshirn * struct mcb_device - MEN Chameleon Bus device
493764e82eSJohannes Thumshirn *
503764e82eSJohannes Thumshirn * @dev: device in kernel representation
513764e82eSJohannes Thumshirn * @bus: mcb bus the device is plugged to
523764e82eSJohannes Thumshirn * @is_added: flag to check if device is added to bus
533764e82eSJohannes Thumshirn * @driver: associated mcb_driver
543764e82eSJohannes Thumshirn * @id: mcb device id
553764e82eSJohannes Thumshirn * @inst: instance in Chameleon table
563764e82eSJohannes Thumshirn * @group: group in Chameleon table
573764e82eSJohannes Thumshirn * @var: variant in Chameleon table
583764e82eSJohannes Thumshirn * @bar: BAR in Chameleon table
593764e82eSJohannes Thumshirn * @rev: revision in Chameleon table
603764e82eSJohannes Thumshirn * @irq: IRQ resource
613764e82eSJohannes Thumshirn * @memory: memory resource
623764e82eSJohannes Thumshirn */
633764e82eSJohannes Thumshirn struct mcb_device {
643764e82eSJohannes Thumshirn struct device dev;
653764e82eSJohannes Thumshirn struct mcb_bus *bus;
663764e82eSJohannes Thumshirn struct mcb_driver *driver;
673764e82eSJohannes Thumshirn u16 id;
683764e82eSJohannes Thumshirn int inst;
693764e82eSJohannes Thumshirn int group;
703764e82eSJohannes Thumshirn int var;
713764e82eSJohannes Thumshirn int bar;
723764e82eSJohannes Thumshirn int rev;
733764e82eSJohannes Thumshirn struct resource irq;
743764e82eSJohannes Thumshirn struct resource mem;
752d8784dfSMichael Moese struct device *dma_dev;
763764e82eSJohannes Thumshirn };
7768d9671aSJohannes Thumshirn
78deaf8b21SGreg Kroah-Hartman #define to_mcb_device(__dev) container_of_const(__dev, struct mcb_device, dev)
793764e82eSJohannes Thumshirn
803764e82eSJohannes Thumshirn /**
813764e82eSJohannes Thumshirn * struct mcb_driver - MEN Chameleon Bus device driver
823764e82eSJohannes Thumshirn *
833764e82eSJohannes Thumshirn * @driver: device_driver
843764e82eSJohannes Thumshirn * @id_table: mcb id table
853764e82eSJohannes Thumshirn * @probe: probe callback
863764e82eSJohannes Thumshirn * @remove: remove callback
873764e82eSJohannes Thumshirn * @shutdown: shutdown callback
883764e82eSJohannes Thumshirn */
893764e82eSJohannes Thumshirn struct mcb_driver {
903764e82eSJohannes Thumshirn struct device_driver driver;
913764e82eSJohannes Thumshirn const struct mcb_device_id *id_table;
923764e82eSJohannes Thumshirn int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id);
933764e82eSJohannes Thumshirn void (*remove)(struct mcb_device *mdev);
943764e82eSJohannes Thumshirn void (*shutdown)(struct mcb_device *mdev);
953764e82eSJohannes Thumshirn };
9668d9671aSJohannes Thumshirn
97*d69d8048SGreg Kroah-Hartman #define to_mcb_driver(__drv) container_of_const(__drv, struct mcb_driver, driver)
983764e82eSJohannes Thumshirn
mcb_get_drvdata(struct mcb_device * dev)993764e82eSJohannes Thumshirn static inline void *mcb_get_drvdata(struct mcb_device *dev)
1003764e82eSJohannes Thumshirn {
1013764e82eSJohannes Thumshirn return dev_get_drvdata(&dev->dev);
1023764e82eSJohannes Thumshirn }
1033764e82eSJohannes Thumshirn
mcb_set_drvdata(struct mcb_device * dev,void * data)1043764e82eSJohannes Thumshirn static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
1053764e82eSJohannes Thumshirn {
1063764e82eSJohannes Thumshirn dev_set_drvdata(&dev->dev, data);
1073764e82eSJohannes Thumshirn }
1083764e82eSJohannes Thumshirn
1093764e82eSJohannes Thumshirn extern int __must_check __mcb_register_driver(struct mcb_driver *drv,
1103764e82eSJohannes Thumshirn struct module *owner,
1113764e82eSJohannes Thumshirn const char *mod_name);
1123764e82eSJohannes Thumshirn #define mcb_register_driver(driver) \
1133764e82eSJohannes Thumshirn __mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
1143764e82eSJohannes Thumshirn extern void mcb_unregister_driver(struct mcb_driver *driver);
1153764e82eSJohannes Thumshirn #define module_mcb_driver(__mcb_driver) \
11660f86b9aSHuilong Deng module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver)
1173764e82eSJohannes Thumshirn extern void mcb_bus_add_devices(const struct mcb_bus *bus);
1183764e82eSJohannes Thumshirn extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
1194ec65b77SJohannes Thumshirn extern struct mcb_bus *mcb_alloc_bus(struct device *carrier);
1203764e82eSJohannes Thumshirn extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
1213764e82eSJohannes Thumshirn extern void mcb_bus_put(struct mcb_bus *bus);
1223764e82eSJohannes Thumshirn extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
1233764e82eSJohannes Thumshirn extern void mcb_free_dev(struct mcb_device *dev);
1243764e82eSJohannes Thumshirn extern void mcb_release_bus(struct mcb_bus *bus);
1253764e82eSJohannes Thumshirn extern struct resource *mcb_request_mem(struct mcb_device *dev,
1263764e82eSJohannes Thumshirn const char *name);
1273764e82eSJohannes Thumshirn extern void mcb_release_mem(struct resource *mem);
1283764e82eSJohannes Thumshirn extern int mcb_get_irq(struct mcb_device *dev);
1292ce80087SJohannes Thumshirn extern struct resource *mcb_get_resource(struct mcb_device *dev,
1302ce80087SJohannes Thumshirn unsigned int type);
1313764e82eSJohannes Thumshirn
1323764e82eSJohannes Thumshirn #endif /* _LINUX_MCB_H */
133