blob: 9a75c5a09dd17749a84cbca6e240c91198f71fe0 [file] [log] [blame]
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
Wasim Khan14241982020-08-27 19:13:34 +05303 * Copyright 2018-2020 NXP.
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +05304 *
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +05305 */
6
7#include <common.h>
8#include <command.h>
9#include <i2c.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053011#include <asm/io.h>
12
13#include "emc2305.h"
14
15DECLARE_GLOBAL_DATA_PTR;
16
Wasim Khan14241982020-08-27 19:13:34 +053017void set_fan_speed(u8 data, int chip_addr)
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053018{
19 u8 index;
20 u8 Fan[NUM_OF_FANS] = {I2C_EMC2305_FAN1,
21 I2C_EMC2305_FAN2,
22 I2C_EMC2305_FAN3,
23 I2C_EMC2305_FAN4,
24 I2C_EMC2305_FAN5};
25
26 for (index = 0; index < NUM_OF_FANS; index++) {
Igor Opaniukf7c91762021-02-09 13:52:45 +020027#if !CONFIG_IS_ENABLED(DM_I2C)
Wasim Khan14241982020-08-27 19:13:34 +053028 if (i2c_write(chip_addr, Fan[index], 1, &data, 1) != 0) {
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053029 printf("Error: failed to change fan speed @%x\n",
30 Fan[index]);
31 }
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080032#else
33 struct udevice *dev;
34
Wasim Khan14241982020-08-27 19:13:34 +053035 if (i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080036 continue;
37
38 if (dm_i2c_write(dev, Fan[index], &data, 1) != 0) {
39 printf("Error: failed to change fan speed @%x\n",
40 Fan[index]);
41 }
42#endif
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053043 }
44}
45
Wasim Khan14241982020-08-27 19:13:34 +053046void emc2305_init(int chip_addr)
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053047{
48 u8 data;
49
50 data = I2C_EMC2305_CMD;
Igor Opaniukf7c91762021-02-09 13:52:45 +020051#if !CONFIG_IS_ENABLED(DM_I2C)
Wasim Khan14241982020-08-27 19:13:34 +053052 if (i2c_write(chip_addr, I2C_EMC2305_CONF, 1, &data, 1) != 0)
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053053 printf("Error: failed to configure EMC2305\n");
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080054#else
55 struct udevice *dev;
56
Wasim Khan14241982020-08-27 19:13:34 +053057 if (!i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080058 if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1))
59 printf("Error: failed to configure EMC2305\n");
60#endif
61
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053062}