Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* 
0003  *  include/asm-ppc/pmac_low_i2c.h
0004  *
0005  *  Copyright (C) 2003 Ben. Herrenschmidt (benh@kernel.crashing.org)
0006  */
0007 #ifndef __PMAC_LOW_I2C_H__
0008 #define __PMAC_LOW_I2C_H__
0009 #ifdef __KERNEL__
0010 
0011 /* i2c mode (based on the platform functions format) */
0012 enum {
0013     pmac_i2c_mode_dumb  = 1,
0014     pmac_i2c_mode_std   = 2,
0015     pmac_i2c_mode_stdsub    = 3,
0016     pmac_i2c_mode_combined  = 4,
0017 };
0018 
0019 /* RW bit in address */
0020 enum {
0021     pmac_i2c_read       = 0x01,
0022     pmac_i2c_write      = 0x00
0023 };
0024 
0025 /* i2c bus type */
0026 enum {
0027     pmac_i2c_bus_keywest    = 0,
0028     pmac_i2c_bus_pmu    = 1,
0029     pmac_i2c_bus_smu    = 2,
0030 };
0031 
0032 /* i2c bus features */
0033 enum {
0034     /* can_largesub : supports >1 byte subaddresses (SMU only) */
0035     pmac_i2c_can_largesub   = 0x00000001u,
0036 
0037     /* multibus : device node holds multiple busses, bus number is
0038      * encoded in bits 0xff00 of "reg" of a given device
0039      */
0040     pmac_i2c_multibus   = 0x00000002u,
0041 };
0042 
0043 /* i2c busses in the system */
0044 struct pmac_i2c_bus;
0045 struct i2c_adapter;
0046 
0047 /* Init, called early during boot */
0048 extern int pmac_i2c_init(void);
0049 
0050 /* Lookup an i2c bus for a device-node. The node can be either the bus
0051  * node itself or a device below it. In the case of a multibus, the bus
0052  * node itself is the controller node, else, it's a child of the controller
0053  * node
0054  */
0055 extern struct pmac_i2c_bus *pmac_i2c_find_bus(struct device_node *node);
0056 
0057 /* Get the address for an i2c device. This strips the bus number if
0058  * necessary. The 7 bits address is returned 1 bit right shifted so that the
0059  * direction can be directly ored in
0060  */
0061 extern u8 pmac_i2c_get_dev_addr(struct device_node *device);
0062 
0063 /* Get infos about a bus */
0064 extern struct device_node *pmac_i2c_get_controller(struct pmac_i2c_bus *bus);
0065 extern struct device_node *pmac_i2c_get_bus_node(struct pmac_i2c_bus *bus);
0066 extern int pmac_i2c_get_type(struct pmac_i2c_bus *bus);
0067 extern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus);
0068 extern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus);
0069 
0070 /* i2c layer adapter helpers */
0071 extern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus);
0072 extern struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter);
0073 
0074 /* March a device or bus with an i2c adapter structure, to be used by drivers
0075  * to match device-tree nodes with i2c adapters during adapter discovery
0076  * callbacks
0077  */
0078 extern int pmac_i2c_match_adapter(struct device_node *dev,
0079                   struct i2c_adapter *adapter);
0080 
0081 
0082 /* (legacy) Locking functions exposed to i2c-keywest */
0083 extern int pmac_low_i2c_lock(struct device_node *np);
0084 extern int pmac_low_i2c_unlock(struct device_node *np);
0085 
0086 /* Access functions for platform code */
0087 extern int pmac_i2c_open(struct pmac_i2c_bus *bus, int polled);
0088 extern void pmac_i2c_close(struct pmac_i2c_bus *bus);
0089 extern int pmac_i2c_setmode(struct pmac_i2c_bus *bus, int mode);
0090 extern int pmac_i2c_xfer(struct pmac_i2c_bus *bus, u8 addrdir, int subsize,
0091              u32 subaddr, u8 *data,  int len);
0092 
0093 /* Suspend/resume code called by via-pmu directly for now */
0094 extern void pmac_pfunc_i2c_suspend(void);
0095 extern void pmac_pfunc_i2c_resume(void);
0096 
0097 #endif /* __KERNEL__ */
0098 #endif /* __PMAC_LOW_I2C_H__ */