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) */ 12 enum { 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 */ 20 enum { 21 pmac_i2c_read = 0x01, 22 pmac_i2c_write = 0x00 23 }; 24 25 /* i2c bus type */ 26 enum { 27 pmac_i2c_bus_keywest = 0, 28 pmac_i2c_bus_pmu = 1, 29 pmac_i2c_bus_smu = 2, 30 }; 31 32 /* i2c bus features */ 33 enum { 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 */ 44 struct pmac_i2c_bus; 45 struct i2c_adapter; 46 47 /* Init, called early during boot */ 48 extern 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 */ 55 extern 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 */ 61 extern u8 pmac_i2c_get_dev_addr(struct device_node *device); 62 63 /* Get infos about a bus */ 64 extern struct device_node *pmac_i2c_get_controller(struct pmac_i2c_bus *bus); 65 extern struct device_node *pmac_i2c_get_bus_node(struct pmac_i2c_bus *bus); 66 extern int pmac_i2c_get_type(struct pmac_i2c_bus *bus); 67 extern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus); 68 extern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus); 69 70 /* i2c layer adapter helpers */ 71 extern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus); 72 extern 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 */ 78 extern int pmac_i2c_match_adapter(struct device_node *dev, 79 struct i2c_adapter *adapter); 80 81 82 /* (legacy) Locking functions exposed to i2c-keywest */ 83 extern int pmac_low_i2c_lock(struct device_node *np); 84 extern int pmac_low_i2c_unlock(struct device_node *np); 85 86 /* Access functions for platform code */ 87 extern int pmac_i2c_open(struct pmac_i2c_bus *bus, int polled); 88 extern void pmac_i2c_close(struct pmac_i2c_bus *bus); 89 extern int pmac_i2c_setmode(struct pmac_i2c_bus *bus, int mode); 90 extern 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 */ 94 extern void pmac_pfunc_i2c_suspend(void); 95 extern void pmac_pfunc_i2c_resume(void); 96 97 #endif /* __KERNEL__ */ 98 #endif /* __PMAC_LOW_I2C_H__ */ 99