18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * include/asm-ppc/pmac_low_i2c.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2003 Ben. Herrenschmidt (benh@kernel.crashing.org) 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#ifndef __PMAC_LOW_I2C_H__ 88c2ecf20Sopenharmony_ci#define __PMAC_LOW_I2C_H__ 98c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci/* i2c mode (based on the platform functions format) */ 128c2ecf20Sopenharmony_cienum { 138c2ecf20Sopenharmony_ci pmac_i2c_mode_dumb = 1, 148c2ecf20Sopenharmony_ci pmac_i2c_mode_std = 2, 158c2ecf20Sopenharmony_ci pmac_i2c_mode_stdsub = 3, 168c2ecf20Sopenharmony_ci pmac_i2c_mode_combined = 4, 178c2ecf20Sopenharmony_ci}; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* RW bit in address */ 208c2ecf20Sopenharmony_cienum { 218c2ecf20Sopenharmony_ci pmac_i2c_read = 0x01, 228c2ecf20Sopenharmony_ci pmac_i2c_write = 0x00 238c2ecf20Sopenharmony_ci}; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* i2c bus type */ 268c2ecf20Sopenharmony_cienum { 278c2ecf20Sopenharmony_ci pmac_i2c_bus_keywest = 0, 288c2ecf20Sopenharmony_ci pmac_i2c_bus_pmu = 1, 298c2ecf20Sopenharmony_ci pmac_i2c_bus_smu = 2, 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci/* i2c bus features */ 338c2ecf20Sopenharmony_cienum { 348c2ecf20Sopenharmony_ci /* can_largesub : supports >1 byte subaddresses (SMU only) */ 358c2ecf20Sopenharmony_ci pmac_i2c_can_largesub = 0x00000001u, 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci /* multibus : device node holds multiple busses, bus number is 388c2ecf20Sopenharmony_ci * encoded in bits 0xff00 of "reg" of a given device 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci pmac_i2c_multibus = 0x00000002u, 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* i2c busses in the system */ 448c2ecf20Sopenharmony_cistruct pmac_i2c_bus; 458c2ecf20Sopenharmony_cistruct i2c_adapter; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* Init, called early during boot */ 488c2ecf20Sopenharmony_ciextern int pmac_i2c_init(void); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* Lookup an i2c bus for a device-node. The node can be either the bus 518c2ecf20Sopenharmony_ci * node itself or a device below it. In the case of a multibus, the bus 528c2ecf20Sopenharmony_ci * node itself is the controller node, else, it's a child of the controller 538c2ecf20Sopenharmony_ci * node 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_ciextern struct pmac_i2c_bus *pmac_i2c_find_bus(struct device_node *node); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* Get the address for an i2c device. This strips the bus number if 588c2ecf20Sopenharmony_ci * necessary. The 7 bits address is returned 1 bit right shifted so that the 598c2ecf20Sopenharmony_ci * direction can be directly ored in 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ciextern u8 pmac_i2c_get_dev_addr(struct device_node *device); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* Get infos about a bus */ 648c2ecf20Sopenharmony_ciextern struct device_node *pmac_i2c_get_controller(struct pmac_i2c_bus *bus); 658c2ecf20Sopenharmony_ciextern struct device_node *pmac_i2c_get_bus_node(struct pmac_i2c_bus *bus); 668c2ecf20Sopenharmony_ciextern int pmac_i2c_get_type(struct pmac_i2c_bus *bus); 678c2ecf20Sopenharmony_ciextern int pmac_i2c_get_flags(struct pmac_i2c_bus *bus); 688c2ecf20Sopenharmony_ciextern int pmac_i2c_get_channel(struct pmac_i2c_bus *bus); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* i2c layer adapter helpers */ 718c2ecf20Sopenharmony_ciextern struct i2c_adapter *pmac_i2c_get_adapter(struct pmac_i2c_bus *bus); 728c2ecf20Sopenharmony_ciextern struct pmac_i2c_bus *pmac_i2c_adapter_to_bus(struct i2c_adapter *adapter); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* March a device or bus with an i2c adapter structure, to be used by drivers 758c2ecf20Sopenharmony_ci * to match device-tree nodes with i2c adapters during adapter discovery 768c2ecf20Sopenharmony_ci * callbacks 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_ciextern int pmac_i2c_match_adapter(struct device_node *dev, 798c2ecf20Sopenharmony_ci struct i2c_adapter *adapter); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* (legacy) Locking functions exposed to i2c-keywest */ 838c2ecf20Sopenharmony_ciextern int pmac_low_i2c_lock(struct device_node *np); 848c2ecf20Sopenharmony_ciextern int pmac_low_i2c_unlock(struct device_node *np); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* Access functions for platform code */ 878c2ecf20Sopenharmony_ciextern int pmac_i2c_open(struct pmac_i2c_bus *bus, int polled); 888c2ecf20Sopenharmony_ciextern void pmac_i2c_close(struct pmac_i2c_bus *bus); 898c2ecf20Sopenharmony_ciextern int pmac_i2c_setmode(struct pmac_i2c_bus *bus, int mode); 908c2ecf20Sopenharmony_ciextern int pmac_i2c_xfer(struct pmac_i2c_bus *bus, u8 addrdir, int subsize, 918c2ecf20Sopenharmony_ci u32 subaddr, u8 *data, int len); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* Suspend/resume code called by via-pmu directly for now */ 948c2ecf20Sopenharmony_ciextern void pmac_pfunc_i2c_suspend(void); 958c2ecf20Sopenharmony_ciextern void pmac_pfunc_i2c_resume(void); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */ 988c2ecf20Sopenharmony_ci#endif /* __PMAC_LOW_I2C_H__ */ 99