From 3892569aed0cb65d18b56afe21d963c636581b05 Mon Sep 17 00:00:00 2001 From: Robert Marklund Date: Thu, 12 May 2011 22:40:35 +0200 Subject: cg2900: Add regulator support Add regulator support needed on snowball HW. ST-Ericsson Linux next: 340135 ST-Ericsson ID: 340139 ST-Ericsson FOSS-OUT ID: Trivial Signed-off-by: Robert Marklund Change-Id: Ic7b5d4559fa44fb13b788002f321898fba3d5843 Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/24086 Reviewed-by: Philippe LANGLAIS Reviewed-by: Par-Gunnar HJALMDAHL --- drivers/staging/cg2900/board-mop500-cg2900.c | 1 + drivers/staging/cg2900/devices-cg2900.c | 35 ++++++++++++++++++++++++++-- drivers/staging/cg2900/include/cg2900.h | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/staging/cg2900/board-mop500-cg2900.c b/drivers/staging/cg2900/board-mop500-cg2900.c index d112b36cc9f..99c1c937391 100644 --- a/drivers/staging/cg2900/board-mop500-cg2900.c +++ b/drivers/staging/cg2900/board-mop500-cg2900.c @@ -133,6 +133,7 @@ static struct cg2900_platform_data cg2900_uart_platform_data = { .uart_enabled = cg2900_uart_enabled, .uart_disabled = cg2900_uart_disabled, }, + .regulator_id = "vdd", }; static struct platform_device ux500_cg2900_uart_device = { diff --git a/drivers/staging/cg2900/devices-cg2900.c b/drivers/staging/cg2900/devices-cg2900.c index aaa07b734ef..f1bf3d48113 100644 --- a/drivers/staging/cg2900/devices-cg2900.c +++ b/drivers/staging/cg2900/devices-cg2900.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "cg2900.h" #include "devices-cg2900.h" @@ -70,6 +71,7 @@ struct dcg2900_info { u8 gpio_8_15_pull_down; u8 gpio_16_20_pull_down; spinlock_t pdb_toggle_lock; + struct regulator *regulator_wlan; }; static void dcg2900_enable_chip(struct cg2900_chip_dev *dev) @@ -198,6 +200,7 @@ static int dcg2900_init(struct cg2900_chip_dev *dev) struct resource *resource; const char *gbf_name; const char *bt_name = NULL; + struct cg2900_platform_data *pdata = dev_get_platdata(dev->dev); /* First retrieve and save the resources */ info = kzalloc(sizeof(*info), GFP_KERNEL); @@ -270,12 +273,35 @@ static int dcg2900_init(struct cg2900_chip_dev *dev) */ if (machine_is_snowball()) { /* Take the regulator */ + if (pdata->regulator_id) { + info->regulator_wlan = regulator_get(dev->dev, + pdata->regulator_id); + if (IS_ERR(info->regulator_wlan)) { + err = PTR_ERR(info->regulator_wlan); + dev_warn(dev->dev, + "%s: Failed to get regulator '%s'\n", + __func__, pdata->regulator_id); + info->regulator_wlan = NULL; + goto err_handling_free_gpio_bt; + } + /* Enable it also */ + err = regulator_enable(info->regulator_wlan); + if (err < 0) { + dev_warn(dev->dev, "%s: regulator_enable failed\n", + __func__); + goto err_handling_put_reg; + } + } else { + dev_warn(dev->dev, "%s: no regulator defined for snowball.\n", + __func__); + } } finished: dev->b_data = info; return 0; - +err_handling_put_reg: + regulator_put(info->regulator_wlan); err_handling_free_gpio_bt: gpio_free(info->bt_gpio); err_handling_free_gpio_gbf: @@ -290,8 +316,13 @@ static void dcg2900_exit(struct cg2900_chip_dev *dev) struct dcg2900_info *info = dev->b_data; if (machine_is_snowball()) { - /* Put the regulator */ + /* Turn off power if we have any */ + if (info->regulator_wlan) { + regulator_disable(info->regulator_wlan); + regulator_put(info->regulator_wlan); + } } + dcg2900_disable_chip(dev); if (info->bt_gpio != -1) gpio_free(info->bt_gpio); diff --git a/drivers/staging/cg2900/include/cg2900.h b/drivers/staging/cg2900/include/cg2900.h index 476ce158e4d..bd165c0048b 100644 --- a/drivers/staging/cg2900/include/cg2900.h +++ b/drivers/staging/cg2900/include/cg2900.h @@ -150,6 +150,7 @@ struct cg2900_chip_dev { * @get_power_switch_off_cmd: Callback called to retrieve * HCI VS_Power_Switch_Off command (command * HCI requires platform specific GPIO data). + * @regulator_id: Id of the regulator that powers on the chip * @bus: Transport used, see @include/net/bluetooth/hci.h. * @gpio_sleep: Array of GPIO sleep settings. * @enable_uart: Callback called when switching from UART GPIO to @@ -173,6 +174,7 @@ struct cg2900_platform_data { struct sk_buff* (*get_power_switch_off_cmd)(struct cg2900_chip_dev *dev, u16 *op_code); + char *regulator_id; __u8 bus; enum cg2900_gpio_pull_sleep *gpio_sleep; -- cgit v1.2.3