linux/drivers/i2c/i2c-dev.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
    i2c-dev.c - i2c-bus driver, char device interface

    Copyright (C) 1995-97 Simon G. Vogl
    Copyright (C) 1998-99 Frodo Looijaard <[email protected]>
    Copyright (C) 2003 Greg Kroah-Hartman <[email protected]>

*/

/* Note that this is a complete rewrite of Simon Vogl's i2c-dev module.
   But I have used so much of his original code and ideas that it seems
   only fair to recognize him as co-author -- Frodo */

/* The I2C_RDWR ioctl code is written by Kolja Waschk <[email protected]> */

#define pr_fmt(fmt)

#include <linux/cdev.h>
#include <linux/compat.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/notifier.h>
#include <linux/slab.h>
#include <linux/uaccess.h>

/*
 * An i2c_dev represents an i2c_adapter ... an I2C or SMBus master, not a
 * slave (i2c_client) with which messages will be exchanged.  It's coupled
 * with a character special file which is accessed by user mode drivers.
 *
 * The list of i2c_dev structures is parallel to the i2c_adapter lists
 * maintained by the driver model, and is updated using bus notifications.
 */
struct i2c_dev {};

#define I2C_MINORS
static LIST_HEAD(i2c_dev_list);
static DEFINE_SPINLOCK(i2c_dev_list_lock);

static struct i2c_dev *i2c_dev_get_by_minor(unsigned index)
{}

static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
{}

static void put_i2c_dev(struct i2c_dev *i2c_dev, bool del_cdev)
{}

static ssize_t name_show(struct device *dev,
			 struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR_RO(name);

static struct attribute *i2c_attrs[] =;
ATTRIBUTE_GROUPS();

/* ------------------------------------------------------------------------- */

/*
 * After opening an instance of this character special file, a file
 * descriptor starts out associated only with an i2c_adapter (and bus).
 *
 * Using the I2C_RDWR ioctl(), you can then *immediately* issue i2c_msg
 * traffic to any devices on the bus used by that adapter.  That's because
 * the i2c_msg vectors embed all the addressing information they need, and
 * are submitted directly to an i2c_adapter.  However, SMBus-only adapters
 * don't support that interface.
 *
 * To use read()/write() system calls on that file descriptor, or to use
 * SMBus interfaces (and work with SMBus-only hosts!), you must first issue
 * an I2C_SLAVE (or I2C_SLAVE_FORCE) ioctl.  That configures an anonymous
 * (never registered) i2c_client so it holds the addressing information
 * needed by those system calls and by this SMBus interface.
 */

static ssize_t i2cdev_read(struct file *file, char __user *buf, size_t count,
		loff_t *offset)
{}

static ssize_t i2cdev_write(struct file *file, const char __user *buf,
		size_t count, loff_t *offset)
{}

static int i2cdev_check(struct device *dev, void *addrp)
{}

/* walk up mux tree */
static int i2cdev_check_mux_parents(struct i2c_adapter *adapter, int addr)
{}

/* recurse down mux tree */
static int i2cdev_check_mux_children(struct device *dev, void *addrp)
{}

/* This address checking function differs from the one in i2c-core
   in that it considers an address with a registered device, but no
   driver bound to it, as NOT busy. */
static int i2cdev_check_addr(struct i2c_adapter *adapter, unsigned int addr)
{}

static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client,
		unsigned nmsgs, struct i2c_msg *msgs)
{}

static noinline int i2cdev_ioctl_smbus(struct i2c_client *client,
		u8 read_write, u8 command, u32 size,
		union i2c_smbus_data __user *data)
{}

static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{}

#ifdef CONFIG_COMPAT

struct i2c_smbus_ioctl_data32 {};

struct i2c_msg32 {};

struct i2c_rdwr_ioctl_data32 {};

static long compat_i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{}
#else
#define compat_i2cdev_ioctl
#endif

static int i2cdev_open(struct inode *inode, struct file *file)
{}

static int i2cdev_release(struct inode *inode, struct file *file)
{}

static const struct file_operations i2cdev_fops =;

/* ------------------------------------------------------------------------- */

static const struct class i2c_dev_class =;

static void i2cdev_dev_release(struct device *dev)
{}

static int i2cdev_attach_adapter(struct device *dev)
{}

static int i2cdev_detach_adapter(struct device *dev)
{}

static int i2cdev_notifier_call(struct notifier_block *nb, unsigned long action,
			 void *data)
{}

static struct notifier_block i2cdev_notifier =;

/* ------------------------------------------------------------------------- */

static int __init i2c_dev_attach_adapter(struct device *dev, void *dummy)
{}

static int __exit i2c_dev_detach_adapter(struct device *dev, void *dummy)
{}

/*
 * module load/unload record keeping
 */

static int __init i2c_dev_init(void)
{}

static void __exit i2c_dev_exit(void)
{}

MODULE_AUTHOR();
MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();

module_init();
module_exit(i2c_dev_exit);