18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2015-2017 Pengutronix, Uwe Kleine-König <kernel@pengutronix.de> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci#include <linux/kernel.h> 68c2ecf20Sopenharmony_ci#include <linux/kthread.h> 78c2ecf20Sopenharmony_ci#include <linux/siox.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define to_siox_master(_dev) container_of((_dev), struct siox_master, dev) 108c2ecf20Sopenharmony_cistruct siox_master { 118c2ecf20Sopenharmony_ci /* these fields should be initialized by the driver */ 128c2ecf20Sopenharmony_ci int busno; 138c2ecf20Sopenharmony_ci int (*pushpull)(struct siox_master *smaster, 148c2ecf20Sopenharmony_ci size_t setbuf_len, const u8 setbuf[], 158c2ecf20Sopenharmony_ci size_t getbuf_len, u8 getbuf[]); 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci /* might be initialized by the driver, if 0 it is set to HZ / 40 */ 188c2ecf20Sopenharmony_ci unsigned long poll_interval; /* in jiffies */ 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci /* framework private stuff */ 218c2ecf20Sopenharmony_ci struct mutex lock; 228c2ecf20Sopenharmony_ci bool active; 238c2ecf20Sopenharmony_ci struct module *owner; 248c2ecf20Sopenharmony_ci struct device dev; 258c2ecf20Sopenharmony_ci unsigned int num_devices; 268c2ecf20Sopenharmony_ci struct list_head devices; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci size_t setbuf_len, getbuf_len; 298c2ecf20Sopenharmony_ci size_t buf_len; 308c2ecf20Sopenharmony_ci u8 *buf; 318c2ecf20Sopenharmony_ci u8 status; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci unsigned long last_poll; 348c2ecf20Sopenharmony_ci struct task_struct *poll_thread; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline void *siox_master_get_devdata(struct siox_master *smaster) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci return dev_get_drvdata(&smaster->dev); 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistruct siox_master *siox_master_alloc(struct device *dev, size_t size); 438c2ecf20Sopenharmony_cistatic inline void siox_master_put(struct siox_master *smaster) 448c2ecf20Sopenharmony_ci{ 458c2ecf20Sopenharmony_ci put_device(&smaster->dev); 468c2ecf20Sopenharmony_ci} 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ciint siox_master_register(struct siox_master *smaster); 498c2ecf20Sopenharmony_civoid siox_master_unregister(struct siox_master *smaster); 50