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