1b8b572e1SStephen Rothwell /*
2b8b572e1SStephen Rothwell  *  include/asm-ppc/pmac_low_i2c.h
3b8b572e1SStephen Rothwell  *
4b8b572e1SStephen Rothwell  *  Copyright (C) 2003 Ben. Herrenschmidt (benh@kernel.crashing.org)
5b8b572e1SStephen Rothwell  *
6b8b572e1SStephen Rothwell  *  This program is free software; you can redistribute it and/or
7b8b572e1SStephen Rothwell  *  modify it under the terms of the GNU General Public License
8b8b572e1SStephen Rothwell  *  as published by the Free Software Foundation; either version
9b8b572e1SStephen Rothwell  *  2 of the License, or (at your option) any later version.
10b8b572e1SStephen Rothwell  *
11b8b572e1SStephen Rothwell  */
12b8b572e1SStephen Rothwell #ifndef __PMAC_LOW_I2C_H__
13b8b572e1SStephen Rothwell #define __PMAC_LOW_I2C_H__
14b8b572e1SStephen Rothwell #ifdef __KERNEL__
15b8b572e1SStephen Rothwell 
16b8b572e1SStephen Rothwell /* i2c mode (based on the platform functions format) */
17b8b572e1SStephen Rothwell enum {
18b8b572e1SStephen Rothwell 	pmac_i2c_mode_dumb	= 1,
19b8b572e1SStephen Rothwell 	pmac_i2c_mode_std	= 2,
20b8b572e1SStephen Rothwell 	pmac_i2c_mode_stdsub	= 3,
21b8b572e1SStephen Rothwell 	pmac_i2c_mode_combined	= 4,
22b8b572e1SStephen Rothwell };
23b8b572e1SStephen Rothwell 
24b8b572e1SStephen Rothwell /* RW bit in address */
25b8b572e1SStephen Rothwell enum {
26b8b572e1SStephen Rothwell 	pmac_i2c_read		= 0x01,
27b8b572e1SStephen Rothwell 	pmac_i2c_write		= 0x00
28b8b572e1SStephen Rothwell };
29b8b572e1SStephen Rothwell 
30b8b572e1SStephen Rothwell /* i2c bus type */
31b8b572e1SStephen Rothwell enum {
32b8b572e1SStephen Rothwell 	pmac_i2c_bus_keywest	= 0,
33b8b572e1SStephen Rothwell 	pmac_i2c_bus_pmu	= 1,
34b8b572e1SStephen Rothwell 	pmac_i2c_bus_smu	= 2,
35b8b572e1SStephen Rothwell };
36b8b572e1SStephen Rothwell 
37b8b572e1SStephen Rothwell /* i2c bus features */
38b8b572e1SStephen Rothwell enum {
39b8b572e1SStephen Rothwell 	/* can_largesub : supports >1 byte subaddresses (SMU only) */
40b8b572e1SStephen Rothwell 	pmac_i2c_can_largesub	= 0x00000001u,
41b8b572e1SStephen Rothwell 
42b8b572e1SStephen Rothwell 	/* multibus : device node holds multiple busses, bus number is
43b8b572e1SStephen Rothwell 	 * encoded in bits 0xff00 of "reg" of a given device
44b8b572e1SStephen Rothwell 	 */
45b8b572e1SStephen Rothwell 	pmac_i2c_multibus	= 0x00000002u,
46b8b572e1SStephen Rothwell };
47b8b572e1SStephen Rothwell 
48b8b572e1SStephen Rothwell /* i2c busses in the system */
49b8b572e1SStephen Rothwell struct pmac_i2c_bus;
50b8b572e1SStephen Rothwell struct i2c_adapter;
51b8b572e1SStephen Rothwell 
52b8b572e1SStephen Rothwell /* Init, called early during boot */
53b8b572e1SStephen Rothwell extern int pmac_i2c_init(void);
54b8b572e1SStephen Rothwell 
55b8b572e1SStephen Rothwell /* Lookup an i2c bus for a device-node. The node can be either the bus
56b8b572e1SStephen Rothwell  * node itself or a device below it. In the case of a multibus, the bus
57b8b572e1SStephen Rothwell  * node itself is the controller node, else, it's a child of the controller
58b8b572e1SStephen Rothwell  * node
59b8b572e1SStephen Rothwell  */
60b8b572e1SStephen Rothwell extern struct pmac_i2c_bus *pmac_i2c_find_bus(struct device_node *node);
61b8b572e1SStephen Rothwell 
62b8b572e1SStephen Rothwell /* Get the address for an i2c device. This strips the bus number if
63b8b572e1SStephen Rothwell  * necessary. The 7 bits address is returned 1 bit right shifted so that the
64b8b572e1SStephen Rothwell  * direction can be directly ored in
65b8b572e1SStephen Rothwell  */
66b8b572e1SStephen Rothwell extern u8 pmac_i2c_get_dev_addr(struct device_node *device);
67b8b572e1SStephen Rothwell 
68b8b572e1SStephen Rothwell /* Get infos about a bus */
69b8b572e1SStephen Rothwell extern struct device_node *pmac_i2c_get_controller(struct pmac_i2c_bus *bus);
70b8b572e1SStephen Rothwell extern struct device_node *pmac_i2c_get_bus_node(struct pmac_i2c_bus *bus);
71b8b572e1SStephen Rothwell extern int pmac_i2c_get_type(struct pmac_i2c_bus *bus);
72b8b572e1SStephen Rothwell extern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus);
73b8b572e1SStephen Rothwell extern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus);
74b8b572e1SStephen Rothwell 
75b8b572e1SStephen Rothwell /* i2c layer adapter attach/detach */
76b8b572e1SStephen Rothwell extern void pmac_i2c_attach_adapter(struct pmac_i2c_bus *bus,
77b8b572e1SStephen Rothwell 				    struct i2c_adapter *adapter);
78b8b572e1SStephen Rothwell extern void pmac_i2c_detach_adapter(struct pmac_i2c_bus *bus,
79b8b572e1SStephen Rothwell 				    struct i2c_adapter *adapter);
80b8b572e1SStephen Rothwell extern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus);
81b8b572e1SStephen Rothwell extern struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter);
82b8b572e1SStephen Rothwell 
83b8b572e1SStephen Rothwell /* March a device or bus with an i2c adapter structure, to be used by drivers
84b8b572e1SStephen Rothwell  * to match device-tree nodes with i2c adapters during adapter discovery
85b8b572e1SStephen Rothwell  * callbacks
86b8b572e1SStephen Rothwell  */
87b8b572e1SStephen Rothwell extern int pmac_i2c_match_adapter(struct device_node *dev,
88b8b572e1SStephen Rothwell 				  struct i2c_adapter *adapter);
89b8b572e1SStephen Rothwell 
90b8b572e1SStephen Rothwell 
91b8b572e1SStephen Rothwell /* (legacy) Locking functions exposed to i2c-keywest */
92b8b572e1SStephen Rothwell extern int pmac_low_i2c_lock(struct device_node *np);
93b8b572e1SStephen Rothwell extern int pmac_low_i2c_unlock(struct device_node *np);
94b8b572e1SStephen Rothwell 
95b8b572e1SStephen Rothwell /* Access functions for platform code */
96b8b572e1SStephen Rothwell extern int pmac_i2c_open(struct pmac_i2c_bus *bus, int polled);
97b8b572e1SStephen Rothwell extern void pmac_i2c_close(struct pmac_i2c_bus *bus);
98b8b572e1SStephen Rothwell extern int pmac_i2c_setmode(struct pmac_i2c_bus *bus, int mode);
99b8b572e1SStephen Rothwell extern int pmac_i2c_xfer(struct pmac_i2c_bus *bus, u8 addrdir, int subsize,
100b8b572e1SStephen Rothwell 			 u32 subaddr, u8 *data,  int len);
101b8b572e1SStephen Rothwell 
102b8b572e1SStephen Rothwell /* Suspend/resume code called by via-pmu directly for now */
103b8b572e1SStephen Rothwell extern void pmac_pfunc_i2c_suspend(void);
104b8b572e1SStephen Rothwell extern void pmac_pfunc_i2c_resume(void);
105b8b572e1SStephen Rothwell 
106b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
107b8b572e1SStephen Rothwell #endif /* __PMAC_LOW_I2C_H__ */
108