Meenakshi Aggarwal | bbd3318 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2018 NXP. |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <i2c.h> |
| 11 | #include <asm/io.h> |
| 12 | |
| 13 | #include "emc2305.h" |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | void set_fan_speed(u8 data) |
| 18 | { |
| 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++) { |
Chuanhua Han | 37c2c5e | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 27 | #ifndef CONFIG_DM_I2C |
Meenakshi Aggarwal | bbd3318 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 28 | if (i2c_write(I2C_EMC2305_ADDR, Fan[index], 1, &data, 1) != 0) { |
| 29 | printf("Error: failed to change fan speed @%x\n", |
| 30 | Fan[index]); |
| 31 | } |
Chuanhua Han | 37c2c5e | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 32 | #else |
| 33 | struct udevice *dev; |
| 34 | |
| 35 | if (i2c_get_chip_for_busnum(0, I2C_EMC2305_ADDR, 1, &dev)) |
| 36 | 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 Aggarwal | bbd3318 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | void emc2305_init(void) |
| 47 | { |
| 48 | u8 data; |
| 49 | |
| 50 | data = I2C_EMC2305_CMD; |
Chuanhua Han | 37c2c5e | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 51 | #ifndef CONFIG_DM_I2C |
Meenakshi Aggarwal | bbd3318 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 52 | if (i2c_write(I2C_EMC2305_ADDR, I2C_EMC2305_CONF, 1, &data, 1) != 0) |
| 53 | printf("Error: failed to configure EMC2305\n"); |
Chuanhua Han | 37c2c5e | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 54 | #else |
| 55 | struct udevice *dev; |
| 56 | |
| 57 | if (!i2c_get_chip_for_busnum(0, I2C_EMC2305_ADDR, 1, &dev)) |
| 58 | if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1)) |
| 59 | printf("Error: failed to configure EMC2305\n"); |
| 60 | #endif |
| 61 | |
Meenakshi Aggarwal | bbd3318 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 62 | } |