blob: 50252bb5007f667bd53115922b9c8d06e76f7f61 [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
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +05307#include <command.h>
8#include <i2c.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053010#include <asm/io.h>
11
12#include "emc2305.h"
13
14DECLARE_GLOBAL_DATA_PTR;
15
Wasim Khan14241982020-08-27 19:13:34 +053016void set_fan_speed(u8 data, int chip_addr)
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053017{
18 u8 index;
19 u8 Fan[NUM_OF_FANS] = {I2C_EMC2305_FAN1,
20 I2C_EMC2305_FAN2,
21 I2C_EMC2305_FAN3,
22 I2C_EMC2305_FAN4,
23 I2C_EMC2305_FAN5};
24
25 for (index = 0; index < NUM_OF_FANS; index++) {
Igor Opaniukf7c91762021-02-09 13:52:45 +020026#if !CONFIG_IS_ENABLED(DM_I2C)
Wasim Khan14241982020-08-27 19:13:34 +053027 if (i2c_write(chip_addr, Fan[index], 1, &data, 1) != 0) {
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053028 printf("Error: failed to change fan speed @%x\n",
29 Fan[index]);
30 }
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080031#else
32 struct udevice *dev;
33
Wasim Khan14241982020-08-27 19:13:34 +053034 if (i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080035 continue;
36
37 if (dm_i2c_write(dev, Fan[index], &data, 1) != 0) {
38 printf("Error: failed to change fan speed @%x\n",
39 Fan[index]);
40 }
41#endif
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053042 }
43}
44
Wasim Khan14241982020-08-27 19:13:34 +053045void emc2305_init(int chip_addr)
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053046{
47 u8 data;
48
49 data = I2C_EMC2305_CMD;
Igor Opaniukf7c91762021-02-09 13:52:45 +020050#if !CONFIG_IS_ENABLED(DM_I2C)
Wasim Khan14241982020-08-27 19:13:34 +053051 if (i2c_write(chip_addr, I2C_EMC2305_CONF, 1, &data, 1) != 0)
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053052 printf("Error: failed to configure EMC2305\n");
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080053#else
54 struct udevice *dev;
55
Wasim Khan14241982020-08-27 19:13:34 +053056 if (!i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080057 if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1))
58 printf("Error: failed to configure EMC2305\n");
59#endif
60
Meenakshi Aggarwalbbd33182018-11-30 22:32:11 +053061}