windfarm_max6690_sensor.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Windfarm PowerMac thermal control. MAX6690 sensor.
  3. *
  4. * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
  5. *
  6. * Use and redistribute under the terms of the GNU GPL v2.
  7. */
  8. #include <linux/types.h>
  9. #include <linux/errno.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/slab.h>
  13. #include <linux/i2c.h>
  14. #include <asm/prom.h>
  15. #include <asm/pmac_low_i2c.h>
  16. #include "windfarm.h"
  17. #define VERSION "1.0"
  18. /* This currently only exports the external temperature sensor,
  19. since that's all the control loops need. */
  20. /* Some MAX6690 register numbers */
  21. #define MAX6690_INTERNAL_TEMP 0
  22. #define MAX6690_EXTERNAL_TEMP 1
  23. struct wf_6690_sensor {
  24. struct i2c_client *i2c;
  25. struct wf_sensor sens;
  26. };
  27. #define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens)
  28. static int wf_max6690_get(struct wf_sensor *sr, s32 *value)
  29. {
  30. struct wf_6690_sensor *max = wf_to_6690(sr);
  31. s32 data;
  32. if (max->i2c == NULL)
  33. return -ENODEV;
  34. /* chip gets initialized by firmware */
  35. data = i2c_smbus_read_byte_data(max->i2c, MAX6690_EXTERNAL_TEMP);
  36. if (data < 0)
  37. return data;
  38. *value = data << 16;
  39. return 0;
  40. }
  41. static void wf_max6690_release(struct wf_sensor *sr)
  42. {
  43. struct wf_6690_sensor *max = wf_to_6690(sr);
  44. kfree(max);
  45. }
  46. static struct wf_sensor_ops wf_max6690_ops = {
  47. .get_value = wf_max6690_get,
  48. .release = wf_max6690_release,
  49. .owner = THIS_MODULE,
  50. };
  51. static int wf_max6690_probe(struct i2c_client *client,
  52. const struct i2c_device_id *id)
  53. {
  54. const char *name, *loc;
  55. struct wf_6690_sensor *max;
  56. int rc;
  57. loc = of_get_property(client->dev.of_node, "hwsensor-location", NULL);
  58. if (!loc) {
  59. dev_warn(&client->dev, "Missing hwsensor-location property!\n");
  60. return -ENXIO;
  61. }
  62. /*
  63. * We only expose the external temperature register for
  64. * now as this is all we need for our control loops
  65. */
  66. if (!strcmp(loc, "BACKSIDE") || !strcmp(loc, "SYS CTRLR AMBIENT"))
  67. name = "backside-temp";
  68. else if (!strcmp(loc, "NB Ambient"))
  69. name = "north-bridge-temp";
  70. else if (!strcmp(loc, "GPU Ambient"))
  71. name = "gpu-temp";
  72. else
  73. return -ENXIO;
  74. max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
  75. if (max == NULL) {
  76. printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: "
  77. "no memory\n");
  78. return -ENOMEM;
  79. }
  80. max->i2c = client;
  81. max->sens.name = name;
  82. max->sens.ops = &wf_max6690_ops;
  83. i2c_set_clientdata(client, max);
  84. rc = wf_register_sensor(&max->sens);
  85. if (rc)
  86. kfree(max);
  87. return rc;
  88. }
  89. static int wf_max6690_remove(struct i2c_client *client)
  90. {
  91. struct wf_6690_sensor *max = i2c_get_clientdata(client);
  92. max->i2c = NULL;
  93. wf_unregister_sensor(&max->sens);
  94. return 0;
  95. }
  96. static const struct i2c_device_id wf_max6690_id[] = {
  97. { "MAC,max6690", 0 },
  98. { }
  99. };
  100. MODULE_DEVICE_TABLE(i2c, wf_max6690_id);
  101. static struct i2c_driver wf_max6690_driver = {
  102. .driver = {
  103. .name = "wf_max6690",
  104. },
  105. .probe = wf_max6690_probe,
  106. .remove = wf_max6690_remove,
  107. .id_table = wf_max6690_id,
  108. };
  109. module_i2c_driver(wf_max6690_driver);
  110. MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
  111. MODULE_DESCRIPTION("MAX6690 sensor objects for PowerMac thermal control");
  112. MODULE_LICENSE("GPL");