unsigned int dfs_set_rate_switch(unsigned int rate_from, unsigned int rate_to, struct dfs_table *table) { unsigned int rate_max; int i; rate_max = (rate_from > rate_to) ? rate_from : rate_to; for (i = 0; i < table->num_of_switches; i++) { if (rate_max >= table->switches[i].switch_rate) { if (is_div(table->switch_src_div)) if (pwrcal_div_set_ratio( table->switch_src_div, table->switches[i].div_value + 1)) goto errorout; if (is_mux(table->switch_src_mux)) if (pwrcal_mux_set_src( table->switch_src_mux, table->switches[i].mux_value)) goto errorout; return table->switches[i].switch_rate; } } return table->switches[table->num_of_switches - 1].switch_rate; errorout: return 0; }
int dfs_trans_div(int lv_from, int lv_to, struct dfs_table *table, int opt) { unsigned int from; unsigned int to; int trans; int i; struct pwrcal_clk *clk; for (i = 1; i < table->num_of_members; i++) { clk = table->members[i]; if (is_div(clk)) { if (lv_from >= 0) from = get_value(table, lv_from, i); else from = pwrcal_div_get_ratio(clk) - 1; to = get_value(table, lv_to, i); trans = 0; switch (opt) { case TRANS_HIGH: if (from < to) trans = 1; break; case TRANS_LOW: if (from > to) trans = 1; break; case TRANS_DIFF: if (from != to) trans = 1; break; case TRANS_FORCE: trans = 1; break; default: break; } if (trans == 0) continue; if (pwrcal_div_set_ratio(clk, to + 1)) goto errorout; } } return 0; errorout: pr_err("%s %s %d\n", __func__, clk->name, to + 1); return -1; }
int div_sum(int x) { if (x == 0) { return 0; } x = (x < 0) ? -x : x; int sum = x + 1; for (int i = 2; i < x; ++i) { if (is_div(x, i)) { sum += i; } } return sum; }
int div_num(int x) { if (x == 0) { return 0; } x = (x < 0) ? -x : x; int result = 2; for (int i = 2; i < x; ++i) { if (is_div(x, i)) { ++result; } } return result; }
int dfs_disable_switch(struct dfs_table *table) { if (is_mux(table->switch_src_usermux)) if (pwrcal_mux_set_src(table->switch_src_usermux, 0)) return -1; if (is_div(table->switch_src_div)) if (pwrcal_div_set_ratio(table->switch_src_div, 1)) return -1; if (is_gate(table->switch_src_gate)) if (pwrcal_gate_disable(table->switch_src_gate)) return -1; return 0; }
static unsigned int get_rate(struct dfs_table *table) { int l, m; unsigned int cur[128] = {0, }; unsigned long long rate; struct pwrcal_clk *clk; for (m = 1; m < table->num_of_members; m++) { clk = table->members[m]; if (is_pll(clk)) { rate = pwrcal_pll_get_rate(clk); do_div(rate, 1000); cur[m] = (unsigned int)rate; } if (is_mux(clk)) cur[m] = pwrcal_mux_get_src(clk); if (is_div(clk)) cur[m] = pwrcal_div_get_ratio(clk) - 1; if (is_gate(clk)) cur[m] = pwrcal_gate_is_enabled(clk); } for (l = 0; l < table->num_of_lv; l++) { for (m = 1; m < table->num_of_members; m++) if (cur[m] != get_value(table, l, m)) break; if (m == table->num_of_members) return get_value(table, l, 0); } if (is_pll(table->members[1])) { for (l = 0; l < table->num_of_lv; l++) if (cur[1] == get_value(table, l, 1)) return get_value(table, l, 0); } for (m = 1; m < table->num_of_members; m++) { clk = table->members[m]; pr_err("dfs_get_rate mid : %s : %d\n", clk->name, cur[m]); } return 0; }
int set_config(struct pwrcal_clk_set *table, int config) { int lidx; int max; unsigned long long rate; int to; struct pwrcal_clk *cur; for (lidx = 0; table[lidx].clk != CLK_NONE; lidx++) { cur = table[lidx].clk; if (is_gate(cur)) { to = config ? table[lidx].config1 : table[lidx].config0; if (to != 1) continue; pwrcal_gate_enable(cur); } } for (lidx = 0; table[lidx].clk != CLK_NONE; lidx++) { cur = table[lidx].clk; if (is_div(cur)) { to = config ? table[lidx].config1 : table[lidx].config0; if (to == -1) continue; if (pwrcal_div_get_ratio(cur) < to + 1) if (pwrcal_div_set_ratio(cur, to + 1)) return -1; } } for (lidx = 0; table[lidx].clk != CLK_NONE; lidx++) { cur = table[lidx].clk; if (is_pll(cur)) { to = config ? table[lidx].config1 : table[lidx].config0; if (to == -1) continue; if (to == 0) { if (pwrcal_pll_disable(cur) != 0) return -1; continue; } rate = ((unsigned long long)to) * 1000; if (pwrcal_pll_get_rate(cur) > rate) { if (pwrcal_pll_set_rate(cur, rate)) return -1; if (pwrcal_pll_is_enabled(cur) == 0) if (pwrcal_pll_enable(cur)) return -1; } } } for (lidx = 0; table[lidx].clk != CLK_NONE; lidx++) { cur = table[lidx].clk; if (is_mux(cur)) { to = config ? table[lidx].config1 : table[lidx].config0; if (to == -1) continue; if (pwrcal_mux_get_src(cur) != to) if (pwrcal_mux_set_src(cur, to)) return -1; } } max = lidx; for (lidx = max - 1; lidx >= 0; lidx--) { cur = table[lidx].clk; if (is_pll(cur)) { to = config ? table[lidx].config1 : table[lidx].config0; if (to == -1) continue; if (to == 0) { if (pwrcal_pll_disable(cur)) return -1; continue; } rate = ((unsigned long long)to) * 1000; if (pwrcal_pll_get_rate(cur) < rate) { if (pwrcal_pll_set_rate(cur, rate)) return -1; if (pwrcal_pll_is_enabled(cur) == 0) if (pwrcal_pll_enable(cur)) return -1; } } } for (lidx = max - 1; lidx >= 0; lidx--) { cur = table[lidx].clk; if (is_div(cur)) { to = config ? table[lidx].config1 : table[lidx].config0; if (to == -1) continue; if (pwrcal_div_get_ratio(cur) > to + 1) if (pwrcal_div_set_ratio(cur, to + 1)) return -1; } } for (lidx = max - 1; lidx >= 0; lidx--) { cur = table[lidx].clk; if (is_gate(cur)) { to = config ? table[lidx].config1 : table[lidx].config0; if (to != 0) continue; pwrcal_gate_disable(cur); } } return 0; }
char *get_token(char *lexeme , int mode){ char *token=(char*)calloc(strlen(lexeme)+50,sizeof(char)); //printf("Getting token\n"); if(is_long(lexeme)){ sprintf(token,"%d",LONG); } else if(is_static(lexeme)){ sprintf(token,"%d",STATIC); } else if(is_union(lexeme)){ sprintf(token,"%d",UNION); } else if(is_default(lexeme)){ sprintf(token,"%d",DEFAULT); } else if(is_break(lexeme)){ sprintf(token,"%d",BREAK); } else if(is_case(lexeme)){ sprintf(token,"%d",CASE); } else if(is_continue(lexeme)){ sprintf(token,"%d",CONTINUE); } else if(is_goto(lexeme)){ sprintf(token,"%d",GOTO); } else if(is_struct(lexeme)){ sprintf(token,"%d",STRUCT); } else if(is_const(lexeme)){ sprintf(token,"%d",CONST); } else if(is_void(lexeme)){ sprintf(token,"%d",VOID); } else if(is_switch(lexeme)){ sprintf(token,"%d",SWITCH); } else if(is_for(lexeme)){ sprintf(token,"%d",FOR); } else if(is_while(lexeme)){ sprintf(token,"%d",WHILE); } else if(is_do(lexeme)){ sprintf(token,"%d",DO); } else if(is_return(lexeme)){ sprintf(token,"%d",RETURN); } else if(is_bool(lexeme)){ sprintf(token,"%d",BOOL); } else if(is_char(lexeme)){ sprintf(token,"%d",CHAR); } else if(is_signed(lexeme)){ sprintf(token,"%d",SIGNED); } else if(is_unsigned(lexeme)){ sprintf(token,"%d",UNSIGNED); } else if(is_short(lexeme)){ sprintf(token,"%d",SHORT); } else if(is_int(lexeme)){ sprintf(token,"%d",INT); } else if(is_float(lexeme)){ sprintf(token,"%d",FLOAT); } else if(is_double(lexeme)){ sprintf(token,"%d",DOUBLE); } else if(is_l_square(lexeme)){ sprintf(token,"%d",L_SQUARE); } else if(is_r_square(lexeme)){ sprintf(token,"%d",R_SQUARE); } else if(is_l_paraen(lexeme)){ sprintf(token,"%d",L_PARAEN); } else if(is_r_paraen(lexeme)){ sprintf(token,"%d",R_PARAEN); } else if(is_l_cbrace(lexeme)){ sprintf(token,"%d",L_CBRACE); } else if(is_r_cbrace(lexeme)){ sprintf(token,"%d",R_CBRACE); } else if(is_comma(lexeme)){ sprintf(token,"%d",COMMA); } else if(is_semicol(lexeme)){ sprintf(token,"%d",SEMICOL); } else if(is_eq_eq(lexeme)){ sprintf(token,"%d",EQ_EQ); } else if(is_lesser(lexeme)){ sprintf(token,"%d",LESSER); } else if(is_less_eq(lexeme)){ sprintf(token,"%d",LESS_EQ); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_greater(lexeme)){ sprintf(token,"%d",GREATER); } else if(is_great_eq(lexeme)){ sprintf(token,"%d",GREAT_EQ); } else if(is_plus_eq(lexeme)){ sprintf(token,"%d",PLUS_EQ); } else if(is_minus_eq(lexeme)){ sprintf(token,"%d",MINUS_EQ); } else if(is_div_eq(lexeme)){ sprintf(token,"%d",DIV_EQ); } else if(is_mult_eq(lexeme)){ sprintf(token,"%d",MULT_EQ); } else if(is_minus_minus(lexeme)){ sprintf(token,"%d",MINUS_MINUS); } else if(is_plus_plus(lexeme)){ sprintf(token,"%d",PLUS_PLUS); } else if(is_percent(lexeme)){ sprintf(token,"%d",PERCENT); } else if(is_div(lexeme)){ sprintf(token,"%d",DIV); } else if(is_mult(lexeme)){ sprintf(token,"%d",MULT); } else if(is_minus(lexeme)){ sprintf(token,"%d",MINUS); } else if(is_plus(lexeme)){ sprintf(token,"%d",PLUS); } else if(is_int_const(lexeme)){ printf("int"); sprintf(token,"%d\t%s",INT_CONST,lexeme); } else if(is_flo_const(lexeme)){ printf("float"); sprintf(token,"%d\t%s",FLO_CONST,lexeme); } else if(is_comment_start(lexeme)){ sprintf(token,"$start"); } else if(is_comment_end(lexeme)){ sprintf(token,"$end"); } else if(is_identifier(lexeme)){ printf("Identifier"); if(mode==1) ht_set( symboltable, lexeme, "1"); sprintf(token,"%d\t%s",IDNTIFIER,lexeme); } else sprintf(token,"%d",NOTOK); return token; }