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