bbc_i2c.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _BBC_I2C_H
  3. #define _BBC_I2C_H
  4. #include <linux/of.h>
  5. #include <linux/of_device.h>
  6. #include <linux/list.h>
  7. struct bbc_i2c_client {
  8. struct bbc_i2c_bus *bp;
  9. struct platform_device *op;
  10. int bus;
  11. int address;
  12. };
  13. enum fan_action { FAN_SLOWER, FAN_SAME, FAN_FASTER, FAN_FULLBLAST, FAN_STATE_MAX };
  14. struct bbc_cpu_temperature {
  15. struct list_head bp_list;
  16. struct list_head glob_list;
  17. struct bbc_i2c_client *client;
  18. int index;
  19. /* Current readings, and history. */
  20. s8 curr_cpu_temp;
  21. s8 curr_amb_temp;
  22. s8 prev_cpu_temp;
  23. s8 prev_amb_temp;
  24. s8 avg_cpu_temp;
  25. s8 avg_amb_temp;
  26. int sample_tick;
  27. enum fan_action fan_todo[2];
  28. #define FAN_AMBIENT 0
  29. #define FAN_CPU 1
  30. };
  31. struct bbc_fan_control {
  32. struct list_head bp_list;
  33. struct list_head glob_list;
  34. struct bbc_i2c_client *client;
  35. int index;
  36. int psupply_fan_on;
  37. int cpu_fan_speed;
  38. int system_fan_speed;
  39. };
  40. #define NUM_CHILDREN 8
  41. struct bbc_i2c_bus {
  42. struct bbc_i2c_bus *next;
  43. int index;
  44. spinlock_t lock;
  45. void __iomem *i2c_bussel_reg;
  46. void __iomem *i2c_control_regs;
  47. unsigned char own, clock;
  48. wait_queue_head_t wq;
  49. volatile int waiting;
  50. struct list_head temps;
  51. struct list_head fans;
  52. struct platform_device *op;
  53. struct {
  54. struct platform_device *device;
  55. int client_claimed;
  56. } devs[NUM_CHILDREN];
  57. };
  58. /* Probing and attachment. */
  59. extern struct platform_device *bbc_i2c_getdev(struct bbc_i2c_bus *, int);
  60. extern struct bbc_i2c_client *bbc_i2c_attach(struct bbc_i2c_bus *bp, struct platform_device *);
  61. extern void bbc_i2c_detach(struct bbc_i2c_client *);
  62. /* Register read/write. NOTE: Blocking! */
  63. extern int bbc_i2c_writeb(struct bbc_i2c_client *, unsigned char val, int off);
  64. extern int bbc_i2c_readb(struct bbc_i2c_client *, unsigned char *byte, int off);
  65. extern int bbc_i2c_write_buf(struct bbc_i2c_client *, char *buf, int len, int off);
  66. extern int bbc_i2c_read_buf(struct bbc_i2c_client *, char *buf, int len, int off);
  67. #endif /* _BBC_I2C_H */