2019-06-01 08:08:55 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2014-02-26 16:29:05 +00:00
|
|
|
/*
|
|
|
|
* MEN Chameleon Bus.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 MEN Mikroelektronik GmbH (www.men.de)
|
|
|
|
* Author: Johannes Thumshirn <johannes.thumshirn@men.de>
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_MCB_H
|
|
|
|
#define _LINUX_MCB_H
|
|
|
|
|
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/irqreturn.h>
|
|
|
|
|
2016-05-03 07:46:23 +00:00
|
|
|
#define CHAMELEON_FILENAME_LEN 12
|
|
|
|
|
2014-02-26 16:29:05 +00:00
|
|
|
struct mcb_driver;
|
2014-04-24 12:35:25 +00:00
|
|
|
struct mcb_device;
|
2014-02-26 16:29:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mcb_bus - MEN Chameleon Bus
|
|
|
|
*
|
2016-05-03 07:46:22 +00:00
|
|
|
* @dev: bus device
|
|
|
|
* @carrier: pointer to carrier device
|
2014-02-26 16:29:05 +00:00
|
|
|
* @bus_nr: mcb bus number
|
2014-04-24 12:35:25 +00:00
|
|
|
* @get_irq: callback to get IRQ number
|
2016-05-03 07:46:23 +00:00
|
|
|
* @revision: the FPGA's revision number
|
|
|
|
* @model: the FPGA's model number
|
|
|
|
* @filename: the FPGA's name
|
2014-02-26 16:29:05 +00:00
|
|
|
*/
|
|
|
|
struct mcb_bus {
|
|
|
|
struct device dev;
|
2014-04-24 12:35:25 +00:00
|
|
|
struct device *carrier;
|
2014-02-26 16:29:05 +00:00
|
|
|
int bus_nr;
|
2016-05-03 07:46:23 +00:00
|
|
|
u8 revision;
|
|
|
|
char model;
|
|
|
|
u8 minor;
|
|
|
|
char name[CHAMELEON_FILENAME_LEN + 1];
|
2014-04-24 12:35:25 +00:00
|
|
|
int (*get_irq)(struct mcb_device *dev);
|
2014-02-26 16:29:05 +00:00
|
|
|
};
|
2016-08-26 07:34:59 +00:00
|
|
|
|
|
|
|
static inline struct mcb_bus *to_mcb_bus(struct device *dev)
|
|
|
|
{
|
|
|
|
return container_of(dev, struct mcb_bus, dev);
|
|
|
|
}
|
2014-02-26 16:29:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mcb_device - MEN Chameleon Bus device
|
|
|
|
*
|
|
|
|
* @dev: device in kernel representation
|
|
|
|
* @bus: mcb bus the device is plugged to
|
|
|
|
* @is_added: flag to check if device is added to bus
|
|
|
|
* @driver: associated mcb_driver
|
|
|
|
* @id: mcb device id
|
|
|
|
* @inst: instance in Chameleon table
|
|
|
|
* @group: group in Chameleon table
|
|
|
|
* @var: variant in Chameleon table
|
|
|
|
* @bar: BAR in Chameleon table
|
|
|
|
* @rev: revision in Chameleon table
|
|
|
|
* @irq: IRQ resource
|
|
|
|
* @memory: memory resource
|
|
|
|
*/
|
|
|
|
struct mcb_device {
|
|
|
|
struct device dev;
|
|
|
|
struct mcb_bus *bus;
|
|
|
|
struct mcb_driver *driver;
|
|
|
|
u16 id;
|
|
|
|
int inst;
|
|
|
|
int group;
|
|
|
|
int var;
|
|
|
|
int bar;
|
|
|
|
int rev;
|
|
|
|
struct resource irq;
|
|
|
|
struct resource mem;
|
2016-09-14 10:05:24 +00:00
|
|
|
struct device *dma_dev;
|
2014-02-26 16:29:05 +00:00
|
|
|
};
|
2016-08-26 07:34:59 +00:00
|
|
|
|
2023-01-11 11:30:15 +00:00
|
|
|
#define to_mcb_device(__dev) container_of_const(__dev, struct mcb_device, dev)
|
2014-02-26 16:29:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mcb_driver - MEN Chameleon Bus device driver
|
|
|
|
*
|
|
|
|
* @driver: device_driver
|
|
|
|
* @id_table: mcb id table
|
|
|
|
* @probe: probe callback
|
|
|
|
* @remove: remove callback
|
|
|
|
* @shutdown: shutdown callback
|
|
|
|
*/
|
|
|
|
struct mcb_driver {
|
|
|
|
struct device_driver driver;
|
|
|
|
const struct mcb_device_id *id_table;
|
|
|
|
int (*probe)(struct mcb_device *mdev, const struct mcb_device_id *id);
|
|
|
|
void (*remove)(struct mcb_device *mdev);
|
|
|
|
void (*shutdown)(struct mcb_device *mdev);
|
|
|
|
};
|
2016-08-26 07:34:59 +00:00
|
|
|
|
2024-07-01 12:07:37 +00:00
|
|
|
#define to_mcb_driver(__drv) container_of_const(__drv, struct mcb_driver, driver)
|
2014-02-26 16:29:05 +00:00
|
|
|
|
|
|
|
static inline void *mcb_get_drvdata(struct mcb_device *dev)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(&dev->dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mcb_set_drvdata(struct mcb_device *dev, void *data)
|
|
|
|
{
|
|
|
|
dev_set_drvdata(&dev->dev, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int __must_check __mcb_register_driver(struct mcb_driver *drv,
|
|
|
|
struct module *owner,
|
|
|
|
const char *mod_name);
|
|
|
|
#define mcb_register_driver(driver) \
|
|
|
|
__mcb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
|
|
|
|
extern void mcb_unregister_driver(struct mcb_driver *driver);
|
|
|
|
#define module_mcb_driver(__mcb_driver) \
|
2021-06-15 14:55:30 +00:00
|
|
|
module_driver(__mcb_driver, mcb_register_driver, mcb_unregister_driver)
|
2014-02-26 16:29:05 +00:00
|
|
|
extern void mcb_bus_add_devices(const struct mcb_bus *bus);
|
|
|
|
extern int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev);
|
2014-04-24 12:35:25 +00:00
|
|
|
extern struct mcb_bus *mcb_alloc_bus(struct device *carrier);
|
2014-02-26 16:29:05 +00:00
|
|
|
extern struct mcb_bus *mcb_bus_get(struct mcb_bus *bus);
|
|
|
|
extern void mcb_bus_put(struct mcb_bus *bus);
|
|
|
|
extern struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus);
|
|
|
|
extern void mcb_free_dev(struct mcb_device *dev);
|
|
|
|
extern void mcb_release_bus(struct mcb_bus *bus);
|
|
|
|
extern struct resource *mcb_request_mem(struct mcb_device *dev,
|
|
|
|
const char *name);
|
|
|
|
extern void mcb_release_mem(struct resource *mem);
|
|
|
|
extern int mcb_get_irq(struct mcb_device *dev);
|
2017-08-02 07:58:52 +00:00
|
|
|
extern struct resource *mcb_get_resource(struct mcb_device *dev,
|
|
|
|
unsigned int type);
|
2014-02-26 16:29:05 +00:00
|
|
|
|
|
|
|
#endif /* _LINUX_MCB_H */
|