Skip to content

Commit

Permalink
[AS7326-56X] Fix led drv bug (#8541)
Browse files Browse the repository at this point in the history
CPLD offset in led drv is incorrect. 

#### How to verify it

echo 1  > brightness, show green on in DIAG led
echo 3  > brightness, show red on in DIAG led
echo 4  > brightness, show blue on in DIAG led
echo 5  > brightness, show green blinking in DIAG led

Signed-off-by: Jostar Yang <[email protected]>
  • Loading branch information
jostar-yang authored Aug 22, 2021
1 parent 51fce2a commit 753ea80
Showing 1 changed file with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct accton_as7326_56x_led_data {
struct mutex update_lock;
char valid; /* != 0 if registers are valid */
unsigned long last_updated; /* In jiffies */
u8 reg_val[1]; /* only 1 register*/
u8 reg_val[2];
};

static struct accton_as7326_56x_led_data *ledctl = NULL;
Expand All @@ -54,16 +54,24 @@ static struct accton_as7326_56x_led_data *ledctl = NULL;

#define LED_CNTRLER_I2C_ADDRESS (0x60)

#define LED_TYPE_DIAG_REG_MASK (0x3)
#define LED_MODE_DIAG_GREEN_VALUE (0x02)
#define LED_MODE_DIAG_RED_VALUE (0x01)
#define LED_MODE_DIAG_AMBER_VALUE (0x00) /*It's yellow actually. Green+Red=Yellow*/
#define LED_MODE_DIAG_OFF_VALUE (0x03)


#define LED_TYPE_LOC_REG_MASK (0x80)
#define LED_MODE_LOC_ON_VALUE (0)
#define LED_MODE_LOC_OFF_VALUE (0x80)
#define LED_TYPE_DIAG_REG_MASK (0x3f)
#define LED_MODE_DIAG_GREEN_VALUE (0x05)
#define LED_MODE_DIAG_RED_VALUE (0x06)
#define LED_MODE_DIAG_BLUE_VALUE (0x03)
#define LED_MODE_DIAG_GREEN_BLINK_VALUE (0x17)
#define LED_MODE_DIAG_RED_BLINK_VALUE (0x0d)
#define LED_MODE_DIAG_BLUE_BLINK_VALUE (0x27)

#define LED_MODE_DIAG_OFF_VALUE (0x07)

#define LED_TYPE_LOC_REG_MASK (0x3f)
#define LED_MODE_LOC_GREEN_VALUE (0x05)
#define LED_MODE_LOC_RED_VALUE (0x06)
#define LED_MODE_LOC_BLUE_VALUE (0x03)
#define LED_MODE_LOC_GREEN_BLINK_VALUE (0x17)
#define LED_MODE_LOC_RED_BLINK_VALUE (0x0d)
#define LED_MODE_LOC_BLUE_BLINK_VALUE (0x27)
#define LED_MODE_LOC_OFF_VALUE (0x07)

enum led_type {
LED_TYPE_DIAG,
Expand All @@ -79,7 +87,8 @@ struct led_reg {
};

static const struct led_reg led_reg_map[] = {
{(1<<LED_TYPE_LOC) | (1<<LED_TYPE_DIAG), 0x41},
{LED_TYPE_DIAG, 0x24},
{LED_TYPE_LOC, 0x25}
};


Expand All @@ -105,12 +114,22 @@ struct led_type_mode {
};

static struct led_type_mode led_type_mode_data[] = {
{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE},
{LED_TYPE_LOC, LED_MODE_AMBER, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_ON_VALUE},
{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE},
{LED_TYPE_LOC, LED_MODE_GREEN, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_GREEN_VALUE},
{LED_TYPE_LOC, LED_MODE_RED, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_RED_VALUE},
{LED_TYPE_LOC, LED_MODE_BLUE, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_BLUE_VALUE},
{LED_TYPE_LOC, LED_MODE_GREEN_BLINK, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_GREEN_BLINK_VALUE},
{LED_TYPE_LOC, LED_MODE_RED_BLINK, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_RED_BLINK_VALUE},
{LED_TYPE_LOC, LED_MODE_BLUE_BLINK, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_BLUE_BLINK_VALUE},

{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE},
{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE},
{LED_TYPE_DIAG, LED_MODE_RED, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_RED_VALUE},
{LED_TYPE_DIAG, LED_MODE_AMBER, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_AMBER_VALUE},
{LED_TYPE_DIAG, LED_MODE_BLUE, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_BLUE_VALUE},
{LED_TYPE_DIAG, LED_MODE_GREEN_BLINK, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_BLINK_VALUE},
{LED_TYPE_DIAG, LED_MODE_RED_BLINK, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_RED_BLINK_VALUE},
{LED_TYPE_DIAG, LED_MODE_BLUE_BLINK, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_BLUE_BLINK_VALUE},

};


Expand All @@ -125,8 +144,9 @@ static void accton_as7326_56x_led_set(struct led_classdev *led_cdev,
static int accton_getLedReg(enum led_type type, u8 *reg)
{
int i;

for (i = 0; i < ARRAY_SIZE(led_reg_map); i++) {
if(led_reg_map[i].types & (type<<1)) {
if(led_reg_map[i].types ==type)) {
*reg = led_reg_map[i].reg_addr;
return 0;
}
Expand Down Expand Up @@ -267,7 +287,7 @@ static void accton_as7326_56x_led_loc_set(struct led_classdev *led_cdev,
static enum led_brightness accton_as7326_56x_led_loc_get(struct led_classdev *cdev)
{
accton_as7326_56x_led_update();
return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]);
return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[1]);
}

static void accton_as7326_56x_led_auto_set(struct led_classdev *led_cdev,
Expand All @@ -287,15 +307,15 @@ static struct led_classdev accton_as7326_56x_leds[] = {
.brightness_set = accton_as7326_56x_led_diag_set,
.brightness_get = accton_as7326_56x_led_diag_get,
.flags = LED_CORE_SUSPENDRESUME,
.max_brightness = LED_MODE_RED,
.max_brightness = LED_MODE_BLUE_BLINK,
},
[LED_TYPE_LOC] = {
.name = "accton_as7326_56x_led::loc",
.default_trigger = "unused",
.brightness_set = accton_as7326_56x_led_loc_set,
.brightness_get = accton_as7326_56x_led_loc_get,
.flags = LED_CORE_SUSPENDRESUME,
.max_brightness = LED_MODE_BLUE,
.max_brightness = LED_MODE_BLUE_BLINK,
},
[LED_TYPE_FAN] = {
.name = "accton_as7326_56x_led::fan",
Expand Down

0 comments on commit 753ea80

Please sign in to comment.