11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef _BBC_I2C_H
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _BBC_I2C_H
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
4e21e245bcd9d5244735799387d14421789b20557David S. Miller#include <linux/of.h>
5e21e245bcd9d5244735799387d14421789b20557David S. Miller#include <linux/of_device.h>
6e21e245bcd9d5244735799387d14421789b20557David S. Miller#include <linux/list.h>
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
8e21e245bcd9d5244735799387d14421789b20557David S. Millerstruct bbc_i2c_client {
9e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct bbc_i2c_bus		*bp;
102dc11581376829303b98eadb2de253bee065a56aGrant Likely	struct platform_device		*op;
11e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				bus;
12e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				address;
13e21e245bcd9d5244735799387d14421789b20557David S. Miller};
14e21e245bcd9d5244735799387d14421789b20557David S. Miller
15e21e245bcd9d5244735799387d14421789b20557David S. Millerenum fan_action { FAN_SLOWER, FAN_SAME, FAN_FASTER, FAN_FULLBLAST, FAN_STATE_MAX };
16e21e245bcd9d5244735799387d14421789b20557David S. Miller
17e21e245bcd9d5244735799387d14421789b20557David S. Millerstruct bbc_cpu_temperature {
18e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct list_head		bp_list;
19e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct list_head		glob_list;
20e21e245bcd9d5244735799387d14421789b20557David S. Miller
21e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct bbc_i2c_client		*client;
22e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				index;
23e21e245bcd9d5244735799387d14421789b20557David S. Miller
24e21e245bcd9d5244735799387d14421789b20557David S. Miller	/* Current readings, and history. */
25e21e245bcd9d5244735799387d14421789b20557David S. Miller	s8				curr_cpu_temp;
26e21e245bcd9d5244735799387d14421789b20557David S. Miller	s8				curr_amb_temp;
27e21e245bcd9d5244735799387d14421789b20557David S. Miller	s8				prev_cpu_temp;
28e21e245bcd9d5244735799387d14421789b20557David S. Miller	s8				prev_amb_temp;
29e21e245bcd9d5244735799387d14421789b20557David S. Miller	s8				avg_cpu_temp;
30e21e245bcd9d5244735799387d14421789b20557David S. Miller	s8				avg_amb_temp;
31e21e245bcd9d5244735799387d14421789b20557David S. Miller
32e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				sample_tick;
33e21e245bcd9d5244735799387d14421789b20557David S. Miller
34e21e245bcd9d5244735799387d14421789b20557David S. Miller	enum fan_action			fan_todo[2];
35e21e245bcd9d5244735799387d14421789b20557David S. Miller#define FAN_AMBIENT	0
36e21e245bcd9d5244735799387d14421789b20557David S. Miller#define FAN_CPU		1
37e21e245bcd9d5244735799387d14421789b20557David S. Miller};
38e21e245bcd9d5244735799387d14421789b20557David S. Miller
39e21e245bcd9d5244735799387d14421789b20557David S. Millerstruct bbc_fan_control {
40e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct list_head		bp_list;
41e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct list_head		glob_list;
42e21e245bcd9d5244735799387d14421789b20557David S. Miller
43e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct bbc_i2c_client 		*client;
44e21e245bcd9d5244735799387d14421789b20557David S. Miller	int 				index;
45e21e245bcd9d5244735799387d14421789b20557David S. Miller
46e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				psupply_fan_on;
47e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				cpu_fan_speed;
48e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				system_fan_speed;
49e21e245bcd9d5244735799387d14421789b20557David S. Miller};
50e21e245bcd9d5244735799387d14421789b20557David S. Miller
51e21e245bcd9d5244735799387d14421789b20557David S. Miller#define NUM_CHILDREN	8
52e21e245bcd9d5244735799387d14421789b20557David S. Miller
53e21e245bcd9d5244735799387d14421789b20557David S. Millerstruct bbc_i2c_bus {
54e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct bbc_i2c_bus		*next;
55e21e245bcd9d5244735799387d14421789b20557David S. Miller	int				index;
56e21e245bcd9d5244735799387d14421789b20557David S. Miller	spinlock_t			lock;
57e21e245bcd9d5244735799387d14421789b20557David S. Miller	void				__iomem *i2c_bussel_reg;
58e21e245bcd9d5244735799387d14421789b20557David S. Miller	void				__iomem *i2c_control_regs;
59e21e245bcd9d5244735799387d14421789b20557David S. Miller	unsigned char			own, clock;
60e21e245bcd9d5244735799387d14421789b20557David S. Miller
61e21e245bcd9d5244735799387d14421789b20557David S. Miller	wait_queue_head_t		wq;
62e21e245bcd9d5244735799387d14421789b20557David S. Miller	volatile int			waiting;
63e21e245bcd9d5244735799387d14421789b20557David S. Miller
64e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct list_head		temps;
65e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct list_head		fans;
66e21e245bcd9d5244735799387d14421789b20557David S. Miller
672dc11581376829303b98eadb2de253bee065a56aGrant Likely	struct platform_device		*op;
68e21e245bcd9d5244735799387d14421789b20557David S. Miller	struct {
692dc11581376829303b98eadb2de253bee065a56aGrant Likely		struct platform_device	*device;
70e21e245bcd9d5244735799387d14421789b20557David S. Miller		int			client_claimed;
71e21e245bcd9d5244735799387d14421789b20557David S. Miller	} devs[NUM_CHILDREN];
72e21e245bcd9d5244735799387d14421789b20557David S. Miller};
731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Probing and attachment. */
752dc11581376829303b98eadb2de253bee065a56aGrant Likelyextern struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *, int);
762dc11581376829303b98eadb2de253bee065a56aGrant Likelyextern struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *);
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern void bbc_i2c_detach(struct bbc_i2c_client *);
781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* Register read/write.  NOTE: Blocking! */
801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int bbc_i2c_writeb(struct bbc_i2c_client *, unsigned char val, int off);
811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int bbc_i2c_readb(struct bbc_i2c_client *, unsigned char *byte, int off);
821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int bbc_i2c_write_buf(struct bbc_i2c_client *, char *buf, int len, int off);
831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsextern int bbc_i2c_read_buf(struct bbc_i2c_client *, char *buf, int len, int off);
841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* _BBC_I2C_H */
86