From 23be3ef2350803daa2803607f6ddffea8bba420c Mon Sep 17 00:00:00 2001 From: luowei Date: Mon, 28 Feb 2011 09:23:40 +0800 Subject: [PATCH] add wm831x support for in board-rk29-phonesdk.c --- arch/arm/mach-rk29/board-rk29-phonesdk.c | 751 +++++++++++++++++++++++ arch/arm/mach-rk29/include/mach/gpio.h | 188 +++++- drivers/input/keyboard/Kconfig | 15 + drivers/input/keyboard/Makefile | 1 + drivers/mfd/Kconfig | 27 +- drivers/mfd/Makefile | 2 + drivers/mfd/wm831x-core.c | 2 + drivers/power/Kconfig | 6 + drivers/power/Makefile | 1 + 9 files changed, 985 insertions(+), 8 deletions(-) mode change 100644 => 100755 drivers/mfd/Kconfig mode change 100644 => 100755 drivers/mfd/Makefile mode change 100644 => 100755 drivers/power/Kconfig mode change 100644 => 100755 drivers/power/Makefile diff --git a/arch/arm/mach-rk29/board-rk29-phonesdk.c b/arch/arm/mach-rk29/board-rk29-phonesdk.c index c1a6e597f519..78f3d67b9c05 100755 --- a/arch/arm/mach-rk29/board-rk29-phonesdk.c +++ b/arch/arm/mach-rk29/board-rk29-phonesdk.c @@ -46,6 +46,9 @@ #include #include +#include +#include +#include #include #include @@ -403,6 +406,754 @@ static struct mma8452_platform_data mma8452_info = { }; #endif +#if defined(CONFIG_GPIO_WM831X) +struct rk2818_gpio_expander_info wm831x_gpio_settinginfo[] = { + { + .gpio_num =WM831X_P01,// tp3 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + + { + .gpio_num =WM831X_P02,//tp4 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P03,//tp2 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P04,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P05,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P06,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P07,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P08,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P09,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P10,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P11,//tp1 + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, + { + .gpio_num =WM831X_P12, + .pin_type = GPIO_OUT, + .pin_value =GPIO_HIGH, + }, +}; + +#endif + + + +#if defined(CONFIG_MFD_WM831X) + +int wm831x_pre_init(struct wm831x *parm) +{ + int ret; + printk("%s\n", __FUNCTION__); + + //ILIM = 900ma + ret = wm831x_reg_read(parm, WM831X_POWER_STATE) & 0xffff; + wm831x_reg_write(parm, WM831X_POWER_STATE, (ret&0xfff8) | 0x04); +#if 0 + wm831x_set_bits(parm, WM831X_LDO_ENABLE, (1 << 3), 0); + wm831x_set_bits(parm, WM831X_LDO_ENABLE, (1 << 7), 0); + printk("%s:disable ldo4 and ldo8 because they are enabled in uboot\n",__FUNCTION__); +#endif + return 0; +} +int wm831x_post_init(struct wm831x *parm) +{ + struct regulator *dcdc; + struct regulator *ldo; + + //dcdc init + dcdc = regulator_get(NULL, "dcdc1"); + regulator_set_voltage(dcdc,1800000,1800000); + regulator_enable(dcdc); + printk("%s set dcdc1=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc)); + regulator_put(dcdc); + + dcdc = regulator_get(NULL, "dcdc2"); + regulator_set_voltage(dcdc,1300000,1300000); + regulator_enable(dcdc); + printk("%s set dcdc2=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc)); + regulator_put(dcdc); + + dcdc = regulator_get(NULL, "dcdc3"); + regulator_set_voltage(dcdc,3000000,3000000); + regulator_enable(dcdc); + printk("%s set dcdc3=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc)); + regulator_put(dcdc); + + dcdc = regulator_get(NULL, "dcdc4"); + regulator_set_voltage(dcdc,20000000,20000000); + regulator_enable(dcdc); + printk("%s set dcdc4=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc)); + regulator_put(dcdc); + + //ldo init + ldo = regulator_get(NULL, "ldo1"); + regulator_set_voltage(ldo,1800000,1800000); + regulator_enable(ldo); + printk("%s set ldo1=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo2"); + regulator_set_voltage(ldo,1800000,1800000); + regulator_enable(ldo); + printk("%s set ldo2=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo3"); + regulator_set_voltage(ldo,1800000,1800000); + regulator_enable(ldo); + printk("%s set ldo3=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo4"); + regulator_set_voltage(ldo,2800000,2800000); + //regulator_enable(ldo); + //printk("%s set ldo4=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo5"); + regulator_set_voltage(ldo,2800000,2800000); + regulator_enable(ldo); + printk("%s set ldo5=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo6"); + regulator_set_voltage(ldo,3000000,3000000); + regulator_enable(ldo); + printk("%s set ldo6=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo7"); + regulator_set_voltage(ldo,3300000,3300000); + regulator_enable(ldo); + printk("%s set ldo7=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo8"); + regulator_set_voltage(ldo,1200000,1200000); + //regulator_enable(ldo); + //printk("%s set ldo8=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo9"); + regulator_set_voltage(ldo,3000000,3000000); + regulator_enable(ldo); + printk("%s set ldo9=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo10"); + regulator_set_voltage(ldo,3000000,3000000); + regulator_enable(ldo); + printk("%s set ldo10=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + ldo = regulator_get(NULL, "ldo11"); + //regulator_enable(ldo); + printk("%s set ldo11=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo)); + regulator_put(ldo); + + + return 0; +} + +extern void wm831x_enter_sleep(void); +extern void wm831x_exit_sleep(void); + +void pmu_wm831x_set_suspend_voltage(void) +{ + +} +EXPORT_SYMBOL_GPL(pmu_wm831x_set_suspend_voltage); + +void pmu_wm831x_set_resume_voltage(void) +{ + +} +EXPORT_SYMBOL_GPL(pmu_wm831x_set_resume_voltage); + +int wm831x_last_deinit(struct wm831x *parm) +{ + printk("%s\n", __FUNCTION__); + + return 0; +} + +struct wm831x_backlight_pdata wm831x_backlight_platdata = { + .isink = 1, /** ISINK to use, 1 or 2 */ + .max_uA = 5000, /** Maximum current to allow */ +}; + +struct wm831x_backup_pdata wm831x_backup_platdata = { + .charger_enable = 1, + .no_constant_voltage = 0, /** Disable constant voltage charging */ + .vlim = 3100, /** Voltage limit in milivolts */ + .ilim = 300, /** Current limit in microamps */ +}; + +struct wm831x_battery_pdata wm831x_battery_platdata = { + .enable = 1, /** Enable charging */ + .fast_enable = 1, /** Enable fast charging */ + .off_mask = 1, /** Mask OFF while charging */ + .trickle_ilim = 200, /** Trickle charge current limit, in mA */ + .vsel = 4200, /** Target voltage, in mV */ + .eoc_iterm = 90, /** End of trickle charge current, in mA */ + .fast_ilim = 1000, /** Fast charge current limit, in mA */ + .timeout = 180, /** Charge cycle timeout, in minutes */ + .syslo = 3300, /* syslo threshold, in mV*/ + .sysok = 3500, /* sysko threshold, in mV*/ +}; + +struct wm831x_status_pdata wm831x_status_platdata[WM831X_MAX_STATUS] = { + { + .default_src = WM831X_STATUS_OTP, + .name = "wm831x_status0", + .default_trigger = "wm831x_otp", + }, + { + .default_src = WM831X_STATUS_POWER, + .name = "wm831x_status1", + .default_trigger = "wm831x_power", + }, +}; + + +static struct regulator_consumer_supply dcdc1_consumers[] = { + { + .supply = "dcdc1", + } +}; +static struct regulator_consumer_supply dcdc2_consumers[] = { + { + .supply = "dcdc2", + } +}; +static struct regulator_consumer_supply dcdc3_consumers[] = { + { + .supply = "dcdc3", + } +}; +static struct regulator_consumer_supply dcdc4_consumers[] = { + { + .supply = "dcdc4", + } +}; +static struct regulator_consumer_supply epe1_consumers[] = { + { + .supply = "epe1", + } +}; +static struct regulator_consumer_supply epe2_consumers[] = { + { + .supply = "epe2", + } +}; +static struct regulator_consumer_supply ldo1_consumers[] = { + { + .supply = "ldo1", + } +}; +static struct regulator_consumer_supply ldo2_consumers[] = { + { + .supply = "ldo2", + } +}; +static struct regulator_consumer_supply ldo3_consumers[] = { + { + .supply = "ldo3", + } +}; +static struct regulator_consumer_supply ldo4_consumers[] = { + { + .supply = "ldo4", + } +}; +static struct regulator_consumer_supply ldo5_consumers[] = { + { + .supply = "ldo5", + } +}; +static struct regulator_consumer_supply ldo6_consumers[] = { + { + .supply = "ldo6", + } +}; +static struct regulator_consumer_supply ldo7_consumers[] = { + { + .supply = "ldo7", + } +}; +static struct regulator_consumer_supply ldo8_consumers[] = { + { + .supply = "ldo8", + } +}; +static struct regulator_consumer_supply ldo9_consumers[] = { + { + .supply = "ldo9", + } +}; +static struct regulator_consumer_supply ldo10_consumers[] = { + { + .supply = "ldo10", + } +}; +static struct regulator_consumer_supply ldo11_consumers[] = { + { + .supply = "ldo11", + } +}; +static struct regulator_consumer_supply isink1_consumers[] = { + { + .supply = "isink1", + } +}; +static struct regulator_consumer_supply isink2_consumers[] = { + { + .supply = "isink2", + } +}; + +struct regulator_init_data wm831x_regulator_init_dcdc[WM831X_MAX_DCDC] = { + { + .constraints = { + .name = "DCDC1", + .min_uV = 600000, + .max_uV = 1800000,//0.6-1.8V + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(dcdc1_consumers), + .consumer_supplies = dcdc1_consumers, + }, + { + .constraints = { + .name = "DCDC2", + .min_uV = 600000, + .max_uV = 1800000,//0.6-1.8V + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(dcdc2_consumers), + .consumer_supplies = dcdc2_consumers, + }, + { + .constraints = { + .name = "DCDC3", + .min_uV = 850000, + .max_uV = 3400000,//0.85-3.4V + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(dcdc3_consumers), + .consumer_supplies = dcdc3_consumers, + }, + { + .constraints = { + .name = "DCDC4", + .min_uV = 00000000, + .max_uV = 30000000,//30V/40mA + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(dcdc4_consumers), + .consumer_supplies = dcdc4_consumers, + }, + +}; +struct regulator_init_data wm831x_regulator_init_epe[WM831X_MAX_EPE] = { + { + .constraints = { + .name = "EPE1", + .min_uV = 1200000, + .max_uV = 3000000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(epe1_consumers), + .consumer_supplies = epe1_consumers, + }, + { + .constraints = { + .name = "EPE2", + .min_uV = 1200000, + .max_uV = 3000000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(epe2_consumers), + .consumer_supplies = epe2_consumers, + }, +}; + +struct regulator_init_data wm831x_regulator_init_ldo[WM831X_MAX_LDO] = { + { + .constraints = { + .name = "LDO1", + .min_uV = 900000, + .max_uV = 3300000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo1_consumers), + .consumer_supplies = ldo1_consumers, + }, + { + .constraints = { + .name = "LDO2", + .min_uV = 900000, + .max_uV = 3300000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo2_consumers), + .consumer_supplies = ldo2_consumers, + }, + { + .constraints = { + .name = "LDO3", + .min_uV = 900000, + .max_uV = 3300000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo3_consumers), + .consumer_supplies = ldo3_consumers, + }, + { + .constraints = { + .name = "LDO4", + .min_uV = 900000, + .max_uV = 3300000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers), + .consumer_supplies = ldo4_consumers, + }, + { + .constraints = { + .name = "LDO5", + .min_uV = 900000, + .max_uV = 3300000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers), + .consumer_supplies = ldo5_consumers, + }, + { + .constraints = { + .name = "LDO6", + .min_uV = 900000, + .max_uV = 3300000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo6_consumers), + .consumer_supplies = ldo6_consumers, + }, + { + .constraints = { + .name = "LDO7", + .min_uV = 1000000, + .max_uV = 3500000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo7_consumers), + .consumer_supplies = ldo7_consumers, + }, + { + .constraints = { + .name = "LDO8", + .min_uV = 1000000, + .max_uV = 3500000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo8_consumers), + .consumer_supplies = ldo8_consumers, + }, + { + .constraints = { + .name = "LDO9", + .min_uV = 1000000, + .max_uV = 3500000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo9_consumers), + .consumer_supplies = ldo9_consumers, + }, + { + .constraints = { + .name = "LDO10", + .min_uV = 1000000, + .max_uV = 3500000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo10_consumers), + .consumer_supplies = ldo10_consumers, + }, + { + .constraints = { + .name = "LDO11", + .min_uV = 1200000, + .max_uV = 3000000, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE, + }, + .num_consumer_supplies = ARRAY_SIZE(ldo11_consumers), + .consumer_supplies = ldo11_consumers, + }, +}; + +struct regulator_init_data wm831x_regulator_init_isink[WM831X_MAX_ISINK] = { + { + .constraints = { + .name = "ISINK1", + .min_uA = 00000, + .max_uA = 40000, + .always_on = true, + .apply_uV = true, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT, + }, + .num_consumer_supplies = ARRAY_SIZE(isink1_consumers), + .consumer_supplies = isink1_consumers, + }, + { + .constraints = { + .name = "ISINK2", + .min_uA = 0000000, + .max_uA = 0000000, + .apply_uV = false, + .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT, + }, + .num_consumer_supplies = ARRAY_SIZE(isink2_consumers), + .consumer_supplies = isink2_consumers, + }, +}; + +static int wm831x_checkrange(int start,int num,int val) +{ + if((val<(start+num))&&(val>=start)) + return 0; + else + return -1; +} + +static int wm831x_init_pin_type(struct wm831x *wm831x) +{ +#if 0 + struct wm831x_pdata *pdata = wm831x->dev->platform_data; + struct rk2818_gpio_expander_info *wm831x_gpio_settinginfo; + uint16_t offset = 0; + uint16_t wm831x_settingpin_num = 0; + uint16_t ret = 0; + int i = 0; + + if(wm831x) + { + wm831x_gpio_settinginfo=pdata->settinginfo; + if(wm831x_gpio_settinginfo) + { + wm831x_settingpin_num = pdata->settinginfolen; + for(i=0;igpio_base,pdata->gpio_pin_num,wm831x_gpio_settinginfo[i].gpio_num)) + { + offset = wm831x_gpio_settinginfo[i].gpio_num - pdata->gpio_base; + + if(wm831x_gpio_settinginfo[i].pin_type==GPIO_IN) + { + wm831x_set_bits(wm831x,(WM831X_GPIO1_CONTROL+offset), WM831X_GPN_DIR_MASK|WM831X_GPN_TRI_MASK, 1<gpio_pin_num;i++) + { + wm831x_set_bits(wm831x,(WM831X_GPIO1_CONTROL+i), + WM831X_GPN_PULL_MASK|WM831X_GPN_POL_MASK|WM831X_GPN_OD_MASK|WM831X_GPN_TRI_MASK, + 1<