Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Wasim Khan | c63edbc | 2020-08-27 19:13:34 +0530 | [diff] [blame] | 3 | * Copyright 2018-2020 NXP. |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 4 | * |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 7 | #include <command.h> |
| 8 | #include <i2c.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 10 | #include <asm/io.h> |
| 11 | |
| 12 | #include "emc2305.h" |
| 13 | |
| 14 | DECLARE_GLOBAL_DATA_PTR; |
| 15 | |
Wasim Khan | c63edbc | 2020-08-27 19:13:34 +0530 | [diff] [blame] | 16 | void set_fan_speed(u8 data, int chip_addr) |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 17 | { |
| 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 Opaniuk | 2147a16 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 26 | #if !CONFIG_IS_ENABLED(DM_I2C) |
Wasim Khan | c63edbc | 2020-08-27 19:13:34 +0530 | [diff] [blame] | 27 | if (i2c_write(chip_addr, Fan[index], 1, &data, 1) != 0) { |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 28 | printf("Error: failed to change fan speed @%x\n", |
| 29 | Fan[index]); |
| 30 | } |
Chuanhua Han | 0eba65d | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 31 | #else |
| 32 | struct udevice *dev; |
| 33 | |
Wasim Khan | c63edbc | 2020-08-27 19:13:34 +0530 | [diff] [blame] | 34 | if (i2c_get_chip_for_busnum(0, chip_addr, 1, &dev)) |
Chuanhua Han | 0eba65d | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 35 | 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 Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | |
Wasim Khan | c63edbc | 2020-08-27 19:13:34 +0530 | [diff] [blame] | 45 | void emc2305_init(int chip_addr) |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 46 | { |
| 47 | u8 data; |
| 48 | |
| 49 | data = I2C_EMC2305_CMD; |
Igor Opaniuk | 2147a16 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 50 | #if !CONFIG_IS_ENABLED(DM_I2C) |
Wasim Khan | c63edbc | 2020-08-27 19:13:34 +0530 | [diff] [blame] | 51 | if (i2c_write(chip_addr, I2C_EMC2305_CONF, 1, &data, 1) != 0) |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 52 | printf("Error: failed to configure EMC2305\n"); |
Chuanhua Han | 0eba65d | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 53 | #else |
| 54 | struct udevice *dev; |
| 55 | |
Wasim Khan | c63edbc | 2020-08-27 19:13:34 +0530 | [diff] [blame] | 56 | if (!i2c_get_chip_for_busnum(0, chip_addr, 1, &dev)) |
Chuanhua Han | 0eba65d | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 57 | if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1)) |
| 58 | printf("Error: failed to configure EMC2305\n"); |
| 59 | #endif |
| 60 | |
Meenakshi Aggarwal | e088e58 | 2018-11-30 22:32:11 +0530 | [diff] [blame] | 61 | } |