board: freescale: emc2305: Pass chip_addr to set_fan_speed

emc2305 is a common driver. It should not use platform specific
i2c address for slave device.
Pass chip_addr as agrument to emc2305_init() and set_fan_speed()
so that emc2305 driver can be used with different platforms.

Signed-off-by: Wasim Khan <wasim.khan@nxp.com>
Reviewed-by: Priyanka Jain <priyanka.jain@nxp.com>
This commit is contained in:
Wasim Khan 2020-08-27 19:13:34 +05:30 committed by Priyanka Jain
parent ada19fd2d2
commit c63edbc750
3 changed files with 12 additions and 14 deletions

View file

@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0+ // SPDX-License-Identifier: GPL-2.0+
/* /*
* Copyright 2018 NXP. * Copyright 2018-2020 NXP.
* *
* SPDX-License-Identifier: GPL-2.0+
*/ */
#include <common.h> #include <common.h>
@ -14,7 +13,7 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
void set_fan_speed(u8 data) void set_fan_speed(u8 data, int chip_addr)
{ {
u8 index; u8 index;
u8 Fan[NUM_OF_FANS] = {I2C_EMC2305_FAN1, u8 Fan[NUM_OF_FANS] = {I2C_EMC2305_FAN1,
@ -25,14 +24,14 @@ void set_fan_speed(u8 data)
for (index = 0; index < NUM_OF_FANS; index++) { for (index = 0; index < NUM_OF_FANS; index++) {
#ifndef CONFIG_DM_I2C #ifndef CONFIG_DM_I2C
if (i2c_write(I2C_EMC2305_ADDR, Fan[index], 1, &data, 1) != 0) { if (i2c_write(chip_addr, Fan[index], 1, &data, 1) != 0) {
printf("Error: failed to change fan speed @%x\n", printf("Error: failed to change fan speed @%x\n",
Fan[index]); Fan[index]);
} }
#else #else
struct udevice *dev; struct udevice *dev;
if (i2c_get_chip_for_busnum(0, I2C_EMC2305_ADDR, 1, &dev)) if (i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
continue; continue;
if (dm_i2c_write(dev, Fan[index], &data, 1) != 0) { if (dm_i2c_write(dev, Fan[index], &data, 1) != 0) {
@ -43,18 +42,18 @@ void set_fan_speed(u8 data)
} }
} }
void emc2305_init(void) void emc2305_init(int chip_addr)
{ {
u8 data; u8 data;
data = I2C_EMC2305_CMD; data = I2C_EMC2305_CMD;
#ifndef CONFIG_DM_I2C #ifndef CONFIG_DM_I2C
if (i2c_write(I2C_EMC2305_ADDR, I2C_EMC2305_CONF, 1, &data, 1) != 0) if (i2c_write(chip_addr, I2C_EMC2305_CONF, 1, &data, 1) != 0)
printf("Error: failed to configure EMC2305\n"); printf("Error: failed to configure EMC2305\n");
#else #else
struct udevice *dev; struct udevice *dev;
if (!i2c_get_chip_for_busnum(0, I2C_EMC2305_ADDR, 1, &dev)) if (!i2c_get_chip_for_busnum(0, chip_addr, 1, &dev))
if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1)) if (dm_i2c_write(dev, I2C_EMC2305_CONF, &data, 1))
printf("Error: failed to configure EMC2305\n"); printf("Error: failed to configure EMC2305\n");
#endif #endif

View file

@ -1,8 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0+ */ /* SPDX-License-Identifier: GPL-2.0+ */
/* /*
* Copyright 2018 NXP * Copyright 2018-2020 NXP
* *
* SPDX-License-Identifier: GPL-2.0+
*/ */
#ifndef __EMC2305_H_ #ifndef __EMC2305_H_
@ -17,7 +16,7 @@
#define NUM_OF_FANS 5 #define NUM_OF_FANS 5
void emc2305_init(void); void emc2305_init(int chip_addr);
void set_fan_speed(u8 data); void set_fan_speed(u8 data, int chip_addr);
#endif /* __EMC2305_H_ */ #endif /* __EMC2305_H_ */

View file

@ -114,8 +114,8 @@ int board_early_init_f(void)
#ifdef CONFIG_EMC2305 #ifdef CONFIG_EMC2305
select_i2c_ch_pca9547(I2C_MUX_CH_EMC2305); select_i2c_ch_pca9547(I2C_MUX_CH_EMC2305);
emc2305_init(); emc2305_init(I2C_EMC2305_ADDR);
set_fan_speed(I2C_EMC2305_PWM); set_fan_speed(I2C_EMC2305_PWM, I2C_EMC2305_ADDR);
select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
#endif #endif