X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/251aec23e81a06411a0f5f60568b97436aeda748..3b90e5b185bf3a85abf6117d4bd3be13dcf0dcd8:/target/linux/omap24xx/patches-2.6.37/900-n810-battery-management.patch?ds=sidebyside diff --git a/target/linux/omap24xx/patches-2.6.37/900-n810-battery-management.patch b/target/linux/omap24xx/patches-2.6.37/900-n810-battery-management.patch index c0e436082..0c2e8c2c2 100644 --- a/target/linux/omap24xx/patches-2.6.37/900-n810-battery-management.patch +++ b/target/linux/omap24xx/patches-2.6.37/900-n810-battery-management.patch @@ -41,8 +41,8 @@ Index: linux-2.6.37.1/drivers/cbus/Makefile Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ linux-2.6.37.1/drivers/cbus/n810bm_main.c 2011-02-20 15:11:55.764356685 +0100 -@@ -0,0 +1,1559 @@ ++++ linux-2.6.37.1/drivers/cbus/n810bm_main.c 2011-02-20 17:50:58.807801112 +0100 +@@ -0,0 +1,1583 @@ +/* + * Nokia n810 battery management + * @@ -131,22 +131,23 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + */ + + ++/* PMM block ADC IDs */ +enum n810bm_pmm_adc_id { -+ N810BM_PMM_ADC_0x01 = 0x01, -+ N810BM_PMM_ADC_0x02 = 0x02, -+ N810BM_PMM_ADC_0x03 = 0x03, -+ N810BM_PMM_ADC_0x04 = 0x04, -+ N810BM_PMM_ADC_BATTEMP = 0x05, -+ N810BM_PMM_ADC_0x06 = 0x06, -+ N810BM_PMM_ADC_0x07 = 0x07, -+ N810BM_PMM_ADC_0x08 = 0x08, -+ N810BM_PMM_ADC_0x0E = 0x0E, -+ N810BM_PMM_ADC_0x13 = 0x13, -+ N810BM_PMM_ADC_0x14 = 0x14, -+ N810BM_PMM_ADC_0x15 = 0x15, -+ N810BM_PMM_ADC_0x16 = 0x16, -+ N810BM_PMM_ADC_0x17 = 0x17, -+ N810BM_PMM_ADC_0xFE = 0xFE, ++ N810BM_PMM_ADC_BATVOLT = 0x01, /* Battery voltage */ ++ N810BM_PMM_ADC_CHGVOLT = 0x02, /* Charger voltage */ ++ N810BM_PMM_ADC_GND2 = 0x03, /* Ground 0V */ ++ N810BM_PMM_ADC_BSI = 0x04, /* Battery size indicator */ ++ N810BM_PMM_ADC_BATTEMP = 0x05, /* Battery temperature */ ++ N810BM_PMM_ADC_HEADSET = 0x06, /* Headset detection */ ++ N810BM_PMM_ADC_HOOKDET = 0x07, /* Hook detection */ ++ N810BM_PMM_ADC_LIGHTSENS = 0x08, /* Light sensor */ ++ N810BM_PMM_ADC_BATCURR = 0x0E, /* Battery current */ ++ N810BM_PMM_ADC_BKUPVOLT = 0x13, /* Backup battery voltage */ ++ N810BM_PMM_ADC_LIGHTTEMP = 0x14, /* Light sensor temperature */ ++ N810BM_PMM_ADC_RFGP = 0x15, /* RF GP */ ++ N810BM_PMM_ADC_WBTX = 0x16, /* Wideband TX detection */ ++ N810BM_PMM_ADC_RETUTEMP = 0x17, /* RETU chip temperature */ ++ N810BM_PMM_ADC_0xFE = 0xFE, +}; + +struct n810bm_adc_calib { @@ -347,6 +348,23 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + return value; +} + ++static struct n810bm_adc_calib * n810bm_get_adc_calib(struct n810bm *bm, ++ enum n810bm_pmm_adc_id id) ++{ ++ unsigned int index = 0; ++ struct n810bm_adc_calib *cal; ++ ++ if (id != N810BM_PMM_ADC_0xFE) ++ index = (unsigned int)id + 1; ++ if (index >= ARRAY_SIZE(bm->calib.adc)) ++ return NULL; ++ ++ cal = &bm->calib.adc[index]; ++ WARN_ON(cal->id && cal->id != id); ++ ++ return cal; ++} ++ +static int pmm_record_get(struct n810bm *bm, + const struct firmware *pmm_block, + void *buffer, size_t length, @@ -391,10 +409,10 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + __le32 field2; +} __packed; + -+static void extract_group1_elem(struct n810bm *bm, -+ const struct firmware *pmm_block, -+ const u8 *pmm_adc_ids, size_t nr_pmm_adc_ids, -+ u32 field1_mask, u32 field2_mask) ++static int extract_group1_elem(struct n810bm *bm, ++ const struct firmware *pmm_block, ++ const enum n810bm_pmm_adc_id *pmm_adc_ids, size_t nr_pmm_adc_ids, ++ u32 field1_mask, u32 field2_mask) +{ + struct group1_element elem; + int err; @@ -402,39 +420,51 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + struct n810bm_adc_calib *adc_calib; + + for (i = 0; i < nr_pmm_adc_ids; i++) { -+ element_nr = pmm_adc_ids[i] + 3; ++ element_nr = (unsigned int)(pmm_adc_ids[i]) + 3; + + err = pmm_record_get(bm, pmm_block, &elem, sizeof(elem), + 1, element_nr, 0); + if (err) + continue; -+ WARN_ON(element_nr - 3 + 1 >= ARRAY_SIZE(bm->calib.adc)); -+ adc_calib = &bm->calib.adc[element_nr - 3 + 1]; ++ adc_calib = n810bm_get_adc_calib(bm, elem.id); ++ if (!adc_calib) { ++ dev_err(&bm->pdev->dev, "extract_group1_elem: " ++ "Could not get calib element for 0x%02X", ++ elem.id); ++ return -EINVAL; ++ } + + if (adc_calib->flags == elem.flags) { -+ WARN_ON(adc_calib->id != elem.id); + adc_calib->field1 = le32_to_cpu(elem.field1) & field1_mask; + adc_calib->field2 = le32_to_cpu(elem.field2) & field2_mask; ++ } else { ++ dev_dbg(&bm->pdev->dev, "extract_group1_elem: " ++ "Not extracting fields due to flags mismatch: " ++ "0x%02X vs 0x%02X", ++ adc_calib->flags, elem.flags); + } + } ++ ++ return 0; +} + +static int n810bm_parse_pmm_group1(struct n810bm *bm, + const struct firmware *pmm_block) +{ ++ struct n810bm_adc_calib *adc_calib; + struct group1_element elem; + int err; + -+ static const u8 pmm_adc_ids_0[] = { -+ N810BM_PMM_ADC_0x01, -+ N810BM_PMM_ADC_0x02, -+ N810BM_PMM_ADC_0x13, -+ N810BM_PMM_ADC_0x0E, ++ static const enum n810bm_pmm_adc_id pmm_adc_ids_1[] = { ++ N810BM_PMM_ADC_BATVOLT, ++ N810BM_PMM_ADC_CHGVOLT, ++ N810BM_PMM_ADC_BKUPVOLT, ++ N810BM_PMM_ADC_BATCURR, + }; -+ static const u8 pmm_adc_ids_1[] = { -+ N810BM_PMM_ADC_0x04, ++ static const enum n810bm_pmm_adc_id pmm_adc_ids_2[] = { ++ N810BM_PMM_ADC_BSI, + }; -+ static const u8 pmm_adc_ids_2[] = { ++ static const enum n810bm_pmm_adc_id pmm_adc_ids_3[] = { + N810BM_PMM_ADC_BATTEMP, + }; + @@ -447,21 +477,33 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + return err; + } + if (elem.id == N810BM_PMM_ADC_0xFE && elem.flags == 0x05) { -+ bm->calib.adc[0].id = elem.id; -+ bm->calib.adc[0].flags = elem.flags; -+ bm->calib.adc[0].field1 = le32_to_cpu(elem.field1); -+ bm->calib.adc[0].field2 = le32_to_cpu(elem.field2); ++ adc_calib = n810bm_get_adc_calib(bm, elem.id); ++ if (!adc_calib) { ++ dev_err(&bm->pdev->dev, ++ "calib extract: Failed to get 0xFE calib"); ++ return -EINVAL; ++ } ++ adc_calib->id = elem.id; ++ adc_calib->flags = elem.flags; ++ adc_calib->field1 = le32_to_cpu(elem.field1); ++ adc_calib->field2 = le32_to_cpu(elem.field2); + } + -+ extract_group1_elem(bm, pmm_block, -+ pmm_adc_ids_0, ARRAY_SIZE(pmm_adc_ids_0), -+ 0xFFFFFFFF, 0xFFFFFFFF); -+ extract_group1_elem(bm, pmm_block, -+ pmm_adc_ids_1, ARRAY_SIZE(pmm_adc_ids_1), -+ 0xFFFFFFFF, 0); -+ extract_group1_elem(bm, pmm_block, -+ pmm_adc_ids_2, ARRAY_SIZE(pmm_adc_ids_2), -+ 0xFFFFFFFF, 0x0000FFFF); ++ err = extract_group1_elem(bm, pmm_block, ++ pmm_adc_ids_1, ARRAY_SIZE(pmm_adc_ids_1), ++ 0xFFFFFFFF, 0xFFFFFFFF); ++ if (err) ++ return err; ++ err = extract_group1_elem(bm, pmm_block, ++ pmm_adc_ids_2, ARRAY_SIZE(pmm_adc_ids_2), ++ 0xFFFFFFFF, 0); ++ if (err) ++ return err; ++ err = extract_group1_elem(bm, pmm_block, ++ pmm_adc_ids_3, ARRAY_SIZE(pmm_adc_ids_3), ++ 0xFFFFFFFF, 0x0000FFFF); ++ if (err) ++ return err; + + return 0; +} @@ -476,37 +518,36 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c +static void n810bm_adc_calib_set_defaults(struct n810bm *bm) +{ + struct n810bm_adc_calib *adc_calib; -+ const struct n810bm_adc_calib *def; -+ unsigned int i, index; ++ unsigned int i; + + static const struct n810bm_adc_calib defaults[] = { + /* ADC group-nr 0 */ + { -+ .id = N810BM_PMM_ADC_0x06, ++ .id = N810BM_PMM_ADC_HEADSET, + .flags = 0x00, + .adc_groupnr = 0, + }, { -+ .id = N810BM_PMM_ADC_0x07, ++ .id = N810BM_PMM_ADC_HOOKDET, + .flags = 0x00, + .adc_groupnr = 0, + }, { -+ .id = N810BM_PMM_ADC_0x15, ++ .id = N810BM_PMM_ADC_RFGP, + .flags = 0x00, + .adc_groupnr = 0, + }, { -+ .id = N810BM_PMM_ADC_0x08, ++ .id = N810BM_PMM_ADC_LIGHTSENS, + .flags = 0x00, + .adc_groupnr = 0, + }, { -+ .id = N810BM_PMM_ADC_0x16, ++ .id = N810BM_PMM_ADC_WBTX, + .flags = 0x00, + .adc_groupnr = 0, + }, { -+ .id = N810BM_PMM_ADC_0x17, ++ .id = N810BM_PMM_ADC_RETUTEMP, + .flags = 0x00, + .adc_groupnr = 0, + }, { -+ .id = N810BM_PMM_ADC_0x03, ++ .id = N810BM_PMM_ADC_GND2, + .flags = 0x00, + .adc_groupnr = 0, + }, @@ -518,25 +559,25 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + .field1 = (u32)-2, + .field2 = 13189, + }, { -+ .id = N810BM_PMM_ADC_0x01, ++ .id = N810BM_PMM_ADC_BATVOLT, + .flags = 0x01, + .adc_groupnr = 1, + .field1 = 2527, + .field2 = 21373, + }, { -+ .id = N810BM_PMM_ADC_0x02, ++ .id = N810BM_PMM_ADC_CHGVOLT, + .flags = 0x01, + .adc_groupnr = 1, + .field1 = 0, + .field2 = 129848, + }, { -+ .id = N810BM_PMM_ADC_0x13, ++ .id = N810BM_PMM_ADC_BKUPVOLT, + .flags = 0x01, + .adc_groupnr = 1, + .field1 = 0, + .field2 = 20000, + }, { -+ .id = N810BM_PMM_ADC_0x0E, ++ .id = N810BM_PMM_ADC_BATCURR, + .flags = 0x06, + .adc_groupnr = 1, + .field1 = 0, @@ -544,7 +585,7 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + }, + /* ADC group-nr 2 */ + { -+ .id = N810BM_PMM_ADC_0x04, ++ .id = N810BM_PMM_ADC_BSI, + .flags = 0x02, + .adc_groupnr = 2, + .field1 = 1169, @@ -560,7 +601,7 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + }, + /* ADC group-nr 4 */ + { -+ .id = N810BM_PMM_ADC_0x14, ++ .id = N810BM_PMM_ADC_LIGHTTEMP, + .flags = 0x04, + .adc_groupnr = 4, + .field1 = 19533778, @@ -577,30 +618,13 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + + /* Copy the defaults */ + for (i = 0; i < ARRAY_SIZE(defaults); i++) { -+ def = &defaults[i]; -+ -+ index = 0; -+ if (def->id != N810BM_PMM_ADC_0xFE) -+ index = def->id + 1; -+ WARN_ON(index >= ARRAY_SIZE(bm->calib.adc)); -+ -+ adc_calib = &bm->calib.adc[index]; -+ *adc_calib = *def; ++ adc_calib = n810bm_get_adc_calib(bm, defaults[i].id); ++ if (WARN_ON(!adc_calib)) ++ continue; ++ *adc_calib = defaults[i]; + } +} + -+static const struct n810bm_adc_calib * n810bm_get_adc_calib(struct n810bm *bm, -+ enum n810bm_pmm_adc_id id) -+{ -+ unsigned int index = 0; -+ -+ if (id != N810BM_PMM_ADC_0xFE) -+ index = (unsigned int)id + 1; -+ WARN_ON(index >= ARRAY_SIZE(bm->calib.adc)); -+ -+ return &bm->calib.adc[index]; -+} -+ +static int n810bm_parse_pmm_block(struct n810bm *bm, + const struct firmware *pmm_block) +{ @@ -632,7 +656,7 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + if (adc_calib->flags == 0xFF) + continue; + switch (adc_calib->id) { -+ case N810BM_PMM_ADC_0x01: ++ case N810BM_PMM_ADC_BATVOLT: + if (adc_calib->field1 < 2400 || + adc_calib->field1 > 2700) + goto value_check_fail; @@ -641,13 +665,13 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + goto value_check_fail; + count++; + break; -+ case N810BM_PMM_ADC_0x04: ++ case N810BM_PMM_ADC_BSI: + if (adc_calib->field1 < 1100 || + adc_calib->field1 > 1300) + goto value_check_fail; + count++; + break; -+ case N810BM_PMM_ADC_0x0E: ++ case N810BM_PMM_ADC_BATCURR: + if (adc_calib->field2 < 7000 || + adc_calib->field2 > 12000) + goto value_check_fail; @@ -662,19 +686,19 @@ Index: linux-2.6.37.1/drivers/cbus/n810bm_main.c + goto value_check_fail; + count++; + break; -+ case N810BM_PMM_ADC_0x02: ++ case N810BM_PMM_ADC_CHGVOLT: + case N810BM_PMM_ADC_BATTEMP: -+ case N810BM_PMM_ADC_0x13: ++ case N810BM_PMM_ADC_BKUPVOLT: + count++; + break; -+ case N810BM_PMM_ADC_0x03: -+ case N810BM_PMM_ADC_0x07: -+ case N810BM_PMM_ADC_0x08: -+ case N810BM_PMM_ADC_0x06: -+ case N810BM_PMM_ADC_0x14: -+ case N810BM_PMM_ADC_0x15: -+ case N810BM_PMM_ADC_0x16: -+ case N810BM_PMM_ADC_0x17: ++ case N810BM_PMM_ADC_GND2: ++ case N810BM_PMM_ADC_HOOKDET: ++ case N810BM_PMM_ADC_LIGHTSENS: ++ case N810BM_PMM_ADC_HEADSET: ++ case N810BM_PMM_ADC_LIGHTTEMP: ++ case N810BM_PMM_ADC_RFGP: ++ case N810BM_PMM_ADC_WBTX: ++ case N810BM_PMM_ADC_RETUTEMP: + break; + } + dev_dbg(&bm->pdev->dev,