2018-11-30 17:02:11 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
2020-08-27 13:43:34 +00:00
|
|
|
* Copyright 2018-2020 NXP.
|
2018-11-30 17:02:11 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
|
|
|
#include <i2c.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-11-30 17:02:11 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#include "emc2305.h"
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-08-27 13:43:34 +00:00
|
|
|
void set_fan_speed(u8 data, int chip_addr)
|
2018-11-30 17:02:11 +00:00
|
|
|
{
|
|
|
|
u8 index;
|
|
|
|
u8 Fan[NUM_OF_FANS] = {I2C_EMC2305_FAN1,
|
|
|
|
I2C_EMC2305_FAN2,
|
|
|
|
I2C_EMC2305_FAN3,
|
|
|
|
I2C_EMC2305_FAN4,
|
|
|
|
I2C_EMC2305_FAN5};
|
|
|
|
|
|
|
|
for (index = 0; index < NUM_OF_FANS; index++) {
|
2019-07-10 13:00:20 +00:00
|
|
|
#ifndef CONFIG_DM_I2C
|
2020-08-27 13:43:34 +00:00
|
|
|
if (i2c_write(chip_addr, Fan[index], 1, &data, 1) != 0) {
|
2018-11-30 17:02:11 +00:00
|
|
|
printf("Error: failed to change fan speed @%x\n",
|
|
|
|
Fan[index]);
|
|
|
|
}
|
2019-07-10 13:00:20 +00:00
|
|
|
#else
|
|
|
|
struct udevice *dev;
|
|
|
|
|
2020-08-27 13:43:34 +00:00
|
|
|
if (i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
|
2019-07-10 13:00:20 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dm_i2c_write(dev, Fan[index], &data, 1) != 0) {
|
|
|
|
printf("Error: failed to change fan speed @%x\n",
|
|
|
|
Fan[index]);
|
|
|
|
}
|
|
|
|
#endif
|
2018-11-30 17:02:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 13:43:34 +00:00
|
|
|
void emc2305_init(int chip_addr)
|
2018-11-30 17:02:11 +00:00
|
|
|
{
|
|
|
|
u8 data;
|
|
|
|
|
|
|
|
data = I2C_EMC2305_CMD;
|
2019-07-10 13:00:20 +00:00
|
|
|
#ifndef CONFIG_DM_I2C
|
2020-08-27 13:43:34 +00:00
|
|
|
if (i2c_write(chip_addr, I2C_EMC2305_CONF, 1, &data, 1) != 0)
|
2018-11-30 17:02:11 +00:00
|
|
|
printf("Error: failed to configure EMC2305\n");
|
2019-07-10 13:00:20 +00:00
|
|
|
#else
|
|
|
|
struct udevice *dev;
|
|
|
|
|
2020-08-27 13:43:34 +00:00
|
|
|
if (!i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
|
2019-07-10 13:00:20 +00:00
|
|
|
if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1))
|
|
|
|
printf("Error: failed to configure EMC2305\n");
|
|
|
|
#endif
|
|
|
|
|
2018-11-30 17:02:11 +00:00
|
|
|
}
|