anybuss-client.h (2701B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * Anybus-S client adapter definitions 4 * 5 * Copyright 2018 Arcx Inc 6 */ 7 8#ifndef __LINUX_ANYBUSS_CLIENT_H__ 9#define __LINUX_ANYBUSS_CLIENT_H__ 10 11#include <linux/device.h> 12#include <linux/types.h> 13#include <linux/poll.h> 14 15/* move to <linux/fieldbus_dev.h> when taking this out of staging */ 16#include "../fieldbus_dev.h" 17 18struct anybuss_host; 19 20struct anybuss_client { 21 struct device dev; 22 struct anybuss_host *host; 23 __be16 anybus_id; 24 /* 25 * these can be optionally set by the client to receive event 26 * notifications from the host. 27 */ 28 void (*on_area_updated)(struct anybuss_client *client); 29 void (*on_online_changed)(struct anybuss_client *client, bool online); 30}; 31 32struct anybuss_client_driver { 33 struct device_driver driver; 34 int (*probe)(struct anybuss_client *adev); 35 void (*remove)(struct anybuss_client *adev); 36 u16 anybus_id; 37}; 38 39int anybuss_client_driver_register(struct anybuss_client_driver *drv); 40void anybuss_client_driver_unregister(struct anybuss_client_driver *drv); 41 42static inline struct anybuss_client *to_anybuss_client(struct device *dev) 43{ 44 return container_of(dev, struct anybuss_client, dev); 45} 46 47static inline struct anybuss_client_driver * 48to_anybuss_client_driver(struct device_driver *drv) 49{ 50 return container_of(drv, struct anybuss_client_driver, driver); 51} 52 53static inline void * 54anybuss_get_drvdata(const struct anybuss_client *client) 55{ 56 return dev_get_drvdata(&client->dev); 57} 58 59static inline void 60anybuss_set_drvdata(struct anybuss_client *client, void *data) 61{ 62 dev_set_drvdata(&client->dev, data); 63} 64 65int anybuss_set_power(struct anybuss_client *client, bool power_on); 66 67struct anybuss_memcfg { 68 u16 input_io; 69 u16 input_dpram; 70 u16 input_total; 71 72 u16 output_io; 73 u16 output_dpram; 74 u16 output_total; 75 76 enum fieldbus_dev_offl_mode offl_mode; 77}; 78 79int anybuss_start_init(struct anybuss_client *client, 80 const struct anybuss_memcfg *cfg); 81int anybuss_finish_init(struct anybuss_client *client); 82int anybuss_read_fbctrl(struct anybuss_client *client, u16 addr, 83 void *buf, size_t count); 84int anybuss_send_msg(struct anybuss_client *client, u16 cmd_num, 85 const void *buf, size_t count); 86int anybuss_send_ext(struct anybuss_client *client, u16 cmd_num, 87 const void *buf, size_t count); 88int anybuss_recv_msg(struct anybuss_client *client, u16 cmd_num, 89 void *buf, size_t count); 90 91/* these help clients make a struct file_operations */ 92int anybuss_write_input(struct anybuss_client *client, 93 const char __user *buf, size_t size, 94 loff_t *offset); 95int anybuss_read_output(struct anybuss_client *client, 96 char __user *buf, size_t size, 97 loff_t *offset); 98 99#endif /* __LINUX_ANYBUSS_CLIENT_H__ */