xref: /dflybsd-src/sys/dev/drm/include/linux/i2c.h (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
1bdab7f26SFrançois Tigeot /*
2*3f2dd94aSFrançois Tigeot  * Copyright (c) 2013-2020 François Tigeot <ftigeot@wolfpond.org>
3bdab7f26SFrançois Tigeot  * All rights reserved.
4bdab7f26SFrançois Tigeot  *
5bdab7f26SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
6bdab7f26SFrançois Tigeot  * modification, are permitted provided that the following conditions
7bdab7f26SFrançois Tigeot  * are met:
8bdab7f26SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
9bdab7f26SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
10bdab7f26SFrançois Tigeot  *    disclaimer.
11bdab7f26SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
12bdab7f26SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
13bdab7f26SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
14bdab7f26SFrançois Tigeot  *
15bdab7f26SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16bdab7f26SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17bdab7f26SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18bdab7f26SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19bdab7f26SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20bdab7f26SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21bdab7f26SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22bdab7f26SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23bdab7f26SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24bdab7f26SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25bdab7f26SFrançois Tigeot  */
26bdab7f26SFrançois Tigeot 
27bdab7f26SFrançois Tigeot #ifndef _LINUX_I2C_H_
28bdab7f26SFrançois Tigeot #define _LINUX_I2C_H_
29bdab7f26SFrançois Tigeot 
30fb572d17SFrançois Tigeot #include <linux/mod_devicetable.h>
31fb572d17SFrançois Tigeot #include <linux/device.h>	/* for struct device */
32fb572d17SFrançois Tigeot #include <linux/sched.h>	/* for completion */
33fb572d17SFrançois Tigeot #include <linux/mutex.h>
341dedbd3bSFrançois Tigeot #include <linux/of.h>		/* for struct device_node */
3583b4b9b9SFrançois Tigeot #include <uapi/linux/i2c.h>
368c49d0deSFrançois Tigeot 
37ba55f2f5SFrançois Tigeot #include <bus/iicbus/iic.h>
38ba55f2f5SFrançois Tigeot 
396e29dde8SFrançois Tigeot #define I2C_M_RD	IIC_M_RD
40ba55f2f5SFrançois Tigeot #define I2C_M_NOSTART	IIC_M_NOSTART
41ba55f2f5SFrançois Tigeot 
421dedbd3bSFrançois Tigeot struct i2c_lock_operations;
431dedbd3bSFrançois Tigeot 
449f4ca867SFrançois Tigeot struct i2c_adapter {
459f4ca867SFrançois Tigeot 	const struct i2c_algorithm *algo;
469f4ca867SFrançois Tigeot 	void *algo_data;
479f4ca867SFrançois Tigeot 
489f4ca867SFrançois Tigeot 	int timeout;
499f4ca867SFrançois Tigeot 	int retries;
509f4ca867SFrançois Tigeot 	struct device dev;
51d182fd93SFrançois Tigeot 	void *private_data;
529f4ca867SFrançois Tigeot 
539f4ca867SFrançois Tigeot 	char name[48];
541dedbd3bSFrançois Tigeot 
551dedbd3bSFrançois Tigeot 	const struct i2c_lock_operations *lock_ops;
569f4ca867SFrançois Tigeot };
579f4ca867SFrançois Tigeot 
587d061d0fSFrançois Tigeot struct i2c_client {
597d061d0fSFrançois Tigeot 	unsigned short flags;
607d061d0fSFrançois Tigeot 	unsigned short addr;
617d061d0fSFrançois Tigeot 	char name[I2C_NAME_SIZE];
627d061d0fSFrançois Tigeot 	struct i2c_adapter *adapter;
637d061d0fSFrançois Tigeot };
647d061d0fSFrançois Tigeot 
65*3f2dd94aSFrançois Tigeot int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
66*3f2dd94aSFrançois Tigeot int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
679f4ca867SFrançois Tigeot 
689f4ca867SFrançois Tigeot struct i2c_algorithm {
699f4ca867SFrançois Tigeot 	int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
709f4ca867SFrançois Tigeot 			   int num);
719f4ca867SFrançois Tigeot 
729f4ca867SFrançois Tigeot 	u32 (*functionality) (struct i2c_adapter *);
739f4ca867SFrançois Tigeot };
749f4ca867SFrançois Tigeot 
759f4ca867SFrançois Tigeot extern int i2c_add_adapter(struct i2c_adapter *);
769f4ca867SFrançois Tigeot extern void i2c_del_adapter(struct i2c_adapter *);
776e29dde8SFrançois Tigeot 
78d182fd93SFrançois Tigeot static inline void
i2c_set_adapdata(struct i2c_adapter * dev,void * data)79d182fd93SFrançois Tigeot i2c_set_adapdata(struct i2c_adapter *dev, void *data)
80d182fd93SFrançois Tigeot {
81d182fd93SFrançois Tigeot 	dev->private_data = data;
82d182fd93SFrançois Tigeot }
83d182fd93SFrançois Tigeot 
84d182fd93SFrançois Tigeot static inline void *
i2c_get_adapdata(const struct i2c_adapter * dev)85d182fd93SFrançois Tigeot i2c_get_adapdata(const struct i2c_adapter *dev)
86d182fd93SFrançois Tigeot {
87d182fd93SFrançois Tigeot 	return dev->private_data;
88d182fd93SFrançois Tigeot }
89d182fd93SFrançois Tigeot 
907d061d0fSFrançois Tigeot struct i2c_board_info {
917d061d0fSFrançois Tigeot 	char		type[I2C_NAME_SIZE];
927d061d0fSFrançois Tigeot 	unsigned short	addr;
937d061d0fSFrançois Tigeot };
947d061d0fSFrançois Tigeot 
957d061d0fSFrançois Tigeot struct i2c_client *
967d061d0fSFrançois Tigeot i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
977d061d0fSFrançois Tigeot 
981dedbd3bSFrançois Tigeot #define I2C_LOCK_SEGMENT      BIT(1)
991dedbd3bSFrançois Tigeot 
1001dedbd3bSFrançois Tigeot struct i2c_lock_operations {
1011dedbd3bSFrançois Tigeot 	void (*lock_bus)(struct i2c_adapter *, unsigned int flags);
1021dedbd3bSFrançois Tigeot 	int (*trylock_bus)(struct i2c_adapter *, unsigned int flags);
1031dedbd3bSFrançois Tigeot 	void (*unlock_bus)(struct i2c_adapter *, unsigned int flags);
1041dedbd3bSFrançois Tigeot };
1051dedbd3bSFrançois Tigeot 
106bdab7f26SFrançois Tigeot #endif	/* _LINUX_I2C_H_ */
107