From patchwork Fri Oct 29 14:31:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Nikula X-Patchwork-Id: 290322 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9TEUalY004025 for ; Fri, 29 Oct 2010 14:30:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755635Ab0J2Oae (ORCPT ); Fri, 29 Oct 2010 10:30:34 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:63518 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755179Ab0J2Oad (ORCPT ); Fri, 29 Oct 2010 10:30:33 -0400 Received: by ewy7 with SMTP id 7so2252000ewy.19 for ; Fri, 29 Oct 2010 07:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=x0hh/ylkxc4y2gFz1V7YBuJ1kQ38qL/PYNz7iTJjoLg=; b=M66TrSMHSX8Wcqu6CKOE4rTEQiGfMrKVEgDmpG0m6avw2iMfp1TYRP8MQ6YSmf6Cqn 4rfFDXcdnwfKUagYmggZ8X2BHpy8hK22B64U/OEU5Fweudp3mtet5N8qH/sjHPxkAEzi pvTDXveqLFmYqbcCkbi8jZo7/9l+SneqZpVXA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=S+fxlK8do48LZ0wDebF4A8EZsqzPf8WooveMj2ZVgLS9JC+8icM6Fz3ClRNR7QhON7 gIJjYSfWVj3iBCu/XRu8MDLqfl0wH60AOxLSAGX35xMLTMxgygzwsdPcA5kCVFshFhwL wcIuF/faLcKbeSEl9E/CamJS0g64mAYxfIOw8= Received: by 10.213.35.143 with SMTP id p15mr1167439ebd.47.1288362632108; Fri, 29 Oct 2010 07:30:32 -0700 (PDT) Received: from localhost (host-94-101-4-66.igua.fi [94.101.4.66]) by mx.google.com with ESMTPS id w20sm1747986eeh.18.2010.10.29.07.30.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 29 Oct 2010 07:30:31 -0700 (PDT) From: Jarkko Nikula To: linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , Jarkko Nikula , Eduardo Valentin Subject: [PATCH] V4L/DVB: radio-si4713: Add regulator framework support Date: Fri, 29 Oct 2010 17:31:39 +0300 Message-Id: <1288362699-23862-1-git-send-email-jhnikula@gmail.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <20101029172601.fdf7ed07.jhnikula@gmail.com> References: <20101029172601.fdf7ed07.jhnikula@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Fri, 29 Oct 2010 14:30:39 +0000 (UTC) diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c index a6e6f19..0fab6f8 100644 --- a/drivers/media/radio/si4713-i2c.c +++ b/drivers/media/radio/si4713-i2c.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include #include @@ -43,6 +45,11 @@ MODULE_AUTHOR("Eduardo Valentin "); MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter"); MODULE_VERSION("0.0.1"); +static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = { + "vio", + "vdd", +}; + #define DEFAULT_RDS_PI 0x00 #define DEFAULT_RDS_PTY 0x00 #define DEFAULT_RDS_PS_NAME "" @@ -369,7 +376,17 @@ static int si4713_powerup(struct si4713_device *sdev) if (sdev->power_state) return 0; - sdev->platform_data->set_power(1); + err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies), + sdev->supplies); + if (err) { + v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err); + return err; + } + if (gpio_is_valid(sdev->gpio_reset)) { + udelay(50); + gpio_set_value(sdev->gpio_reset, 1); + } + err = si4713_send_command(sdev, SI4713_CMD_POWER_UP, args, ARRAY_SIZE(args), resp, ARRAY_SIZE(resp), @@ -384,7 +401,13 @@ static int si4713_powerup(struct si4713_device *sdev) err = si4713_write_property(sdev, SI4713_GPO_IEN, SI4713_STC_INT | SI4713_CTS); } else { - sdev->platform_data->set_power(0); + if (gpio_is_valid(sdev->gpio_reset)) + gpio_set_value(sdev->gpio_reset, 0); + err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies), + sdev->supplies); + if (err) + v4l2_err(&sdev->sd, + "Failed to disable supplies: %d\n", err); } return err; @@ -411,7 +434,13 @@ static int si4713_powerdown(struct si4713_device *sdev) v4l2_dbg(1, debug, &sdev->sd, "Power down response: 0x%02x\n", resp[0]); v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n"); - sdev->platform_data->set_power(0); + if (gpio_is_valid(sdev->gpio_reset)) + gpio_set_value(sdev->gpio_reset, 0); + err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies), + sdev->supplies); + if (err) + v4l2_err(&sdev->sd, + "Failed to disable supplies: %d\n", err); sdev->power_state = POWER_OFF; } @@ -1967,7 +1996,8 @@ static int si4713_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct si4713_device *sdev; - int rval; + struct si4713_platform_data *pdata = client->dev.platform_data; + int rval, i; sdev = kzalloc(sizeof *sdev, GFP_KERNEL); if (!sdev) { @@ -1976,11 +2006,26 @@ static int si4713_probe(struct i2c_client *client, goto exit; } - sdev->platform_data = client->dev.platform_data; - if (!sdev->platform_data) { - v4l2_err(&sdev->sd, "No platform data registered.\n"); - rval = -ENODEV; - goto free_sdev; + sdev->gpio_reset = -1; + if (pdata && gpio_is_valid(pdata->gpio_reset)) { + rval = gpio_request(pdata->gpio_reset, "si4713 reset"); + if (rval) { + dev_err(&client->dev, + "Failed to request gpio: %d\n", rval); + goto free_sdev; + } + sdev->gpio_reset = pdata->gpio_reset; + gpio_direction_output(sdev->gpio_reset, 0); + } + + for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++) + sdev->supplies[i].supply = si4713_supply_names[i]; + + rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies), + sdev->supplies); + if (rval) { + dev_err(&client->dev, "Cannot get regulators: %d\n", rval); + goto free_gpio; } v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); @@ -1994,7 +2039,7 @@ static int si4713_probe(struct i2c_client *client, client->name, sdev); if (rval < 0) { v4l2_err(&sdev->sd, "Could not request IRQ\n"); - goto free_sdev; + goto put_reg; } v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n"); } else { @@ -2012,6 +2057,11 @@ static int si4713_probe(struct i2c_client *client, free_irq: if (client->irq) free_irq(client->irq, sdev); +put_reg: + regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies); +free_gpio: + if (gpio_is_valid(sdev->gpio_reset)) + gpio_free(sdev->gpio_reset); free_sdev: kfree(sdev); exit: @@ -2031,7 +2081,9 @@ static int si4713_remove(struct i2c_client *client) free_irq(client->irq, sdev); v4l2_device_unregister_subdev(sd); - + regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies); + if (gpio_is_valid(sdev->gpio_reset)) + gpio_free(sdev->gpio_reset); kfree(sdev); return 0; diff --git a/drivers/media/radio/si4713-i2c.h b/drivers/media/radio/si4713-i2c.h index faf8cff..c6dfa7f 100644 --- a/drivers/media/radio/si4713-i2c.h +++ b/drivers/media/radio/si4713-i2c.h @@ -211,6 +211,8 @@ struct acomp_info { u32 enabled; }; +#define SI4713_NUM_SUPPLIES 2 + /* * si4713_device - private data */ @@ -220,11 +222,12 @@ struct si4713_device { /* private data structures */ struct mutex mutex; struct completion work; - struct si4713_platform_data *platform_data; struct rds_info rds_info; struct limiter_info limiter_info; struct pilot_info pilot_info; struct acomp_info acomp_info; + struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES]; + int gpio_reset; u32 frequency; u32 preemphasis; u32 mute; diff --git a/include/media/si4713.h b/include/media/si4713.h index 99850a5..ed7353e 100644 --- a/include/media/si4713.h +++ b/include/media/si4713.h @@ -23,8 +23,7 @@ * Platform dependent definition */ struct si4713_platform_data { - /* Set power state, zero is off, non-zero is on. */ - int (*set_power)(int power); + int gpio_reset; /* < 0 if not used */ }; /*