emc2305.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2018-2020 NXP.
  4. *
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <i2c.h>
  9. #include <asm/global_data.h>
  10. #include <asm/io.h>
  11. #include "emc2305.h"
  12. DECLARE_GLOBAL_DATA_PTR;
  13. void set_fan_speed(u8 data, int chip_addr)
  14. {
  15. u8 index;
  16. u8 Fan[NUM_OF_FANS] = {I2C_EMC2305_FAN1,
  17. I2C_EMC2305_FAN2,
  18. I2C_EMC2305_FAN3,
  19. I2C_EMC2305_FAN4,
  20. I2C_EMC2305_FAN5};
  21. for (index = 0; index < NUM_OF_FANS; index++) {
  22. #if !CONFIG_IS_ENABLED(DM_I2C)
  23. if (i2c_write(chip_addr, Fan[index], 1, &data, 1) != 0) {
  24. printf("Error: failed to change fan speed @%x\n",
  25. Fan[index]);
  26. }
  27. #else
  28. struct udevice *dev;
  29. if (i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
  30. continue;
  31. if (dm_i2c_write(dev, Fan[index], &data, 1) != 0) {
  32. printf("Error: failed to change fan speed @%x\n",
  33. Fan[index]);
  34. }
  35. #endif
  36. }
  37. }
  38. void emc2305_init(int chip_addr)
  39. {
  40. u8 data;
  41. data = I2C_EMC2305_CMD;
  42. #if !CONFIG_IS_ENABLED(DM_I2C)
  43. if (i2c_write(chip_addr, I2C_EMC2305_CONF, 1, &data, 1) != 0)
  44. printf("Error: failed to configure EMC2305\n");
  45. #else
  46. struct udevice *dev;
  47. if (!i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
  48. if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1))
  49. printf("Error: failed to configure EMC2305\n");
  50. #endif
  51. }