From patchwork Mon Aug 2 15:29:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cory Maccarrone X-Patchwork-Id: 116545 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o72FUOx9014464 for ; Mon, 2 Aug 2010 15:30:47 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752967Ab0HBPaq (ORCPT ); Mon, 2 Aug 2010 11:30:46 -0400 Received: from mail-gw0-f46.google.com ([74.125.83.46]:52436 "EHLO mail-gw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752371Ab0HBPaq (ORCPT ); Mon, 2 Aug 2010 11:30:46 -0400 Received: by gwb20 with SMTP id 20so1307981gwb.19 for ; Mon, 02 Aug 2010 08:30:45 -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=lDZ2++tS0DGEB6rnE4f8lOLgJwRZ4Psk6Dq4de+CCzo=; b=LgdKqmYhkI3RoHN5R6lwhFuGoTK86TVpbCoUlfv+tQjbakzRddj2YZyPql/gANf6Hg cmAQ+DPQDcNFelr8FcD27R2+jm9/K6rsEq/Qf/2KTM0GEl0ppIbbdK6MpIycCsrJrn9L T53NTzJtV+j2S+iJlpowgIrv4zI+tGXtZmg30= 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=LXHT8BSefF6GjgdzhJPN5RBGCtzFkqMrD3amLrVob4mdGhS27yFhw1FejhSR7c60sn tjodsDCGcpX438tMz5svkl8CyDyta2paEmin391j/cs8sBptVIBJ7b3VBaYWXd00rshU du3qENbTOeJ0gbuQQsReIMjLJbfb600oc4qXA= Received: by 10.150.162.3 with SMTP id k3mr7300577ybe.97.1280763045284; Mon, 02 Aug 2010 08:30:45 -0700 (PDT) Received: from localhost (97-126-99-222.tukw.qwest.net [97.126.99.222]) by mx.google.com with ESMTPS id h8sm5581363ibk.15.2010.08.02.08.30.40 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 02 Aug 2010 08:30:42 -0700 (PDT) From: Cory Maccarrone To: linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Cory Maccarrone Subject: [PATCH 4/5] [omap1] Bluetooth device code common to HTC smartphones Date: Mon, 2 Aug 2010 08:29:35 -0700 Message-Id: <1280762976-17284-5-git-send-email-darkstar6262@gmail.com> X-Mailer: git-send-email 1.6.0.4 In-Reply-To: <1280762976-17284-1-git-send-email-darkstar6262@gmail.com> References: <1280762976-17284-1-git-send-email-darkstar6262@gmail.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 02 Aug 2010 15:30:47 +0000 (UTC) diff --git a/arch/arm/mach-omap1/htc-bt.c b/arch/arm/mach-omap1/htc-bt.c new file mode 100644 index 0000000..aca7b97 --- /dev/null +++ b/arch/arm/mach-omap1/htc-bt.c @@ -0,0 +1,183 @@ +/* + * Bluetooth built-in chip control + * + * Copyright (c) 2010 Cory Maccarrone + * Based on tosa-bt.c copyright (c) 2008 Dmitry Baryshkov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +static struct clk *uart_ck; + +static void htc_bt_on(struct htc_bt_data *data) +{ + gpio_set_value(data->gpio_pwr, 1); + + if (uart_ck) + clk_enable(uart_ck); + + msleep(1000); + + if (data->gpio_enable) + gpio_set_value(data->gpio_enable, 1); +} + +static void htc_bt_off(struct htc_bt_data *data) +{ + gpio_set_value(data->gpio_pwr, 0); + + if (uart_ck) + clk_disable(uart_ck); + + msleep(1000); + + if (data->gpio_enable) + gpio_set_value(data->gpio_enable, 0); +} + +static int htc_bt_set_block(void *data, bool blocked) +{ + if (!blocked) + htc_bt_on(data); + else + htc_bt_off(data); + + return 0; +} + +static const struct rfkill_ops htc_bt_rfkill_ops = { + .set_block = htc_bt_set_block, +}; + +static int htc_bt_probe(struct platform_device *dev) +{ + int rc; + struct rfkill *rfk; + + struct htc_bt_data *data = dev->dev.platform_data; + + /* Configure the GPIOs */ + if (data->gpio_enable) { + rc = gpio_request(data->gpio_enable, "Bluetooth enable"); + if (rc) + goto err_enable; + rc = gpio_direction_output(data->gpio_enable, 0); + if (rc) + goto err_enable_dir; + } + + rc = gpio_request(data->gpio_pwr, "Bluetooth power"); + if (rc) + goto err_pwr; + rc = gpio_direction_output(data->gpio_pwr, 0); + if (rc) + goto err_pwr_dir; + + /* Get the clocks */ + if (data->uart_clock != NULL) { + uart_ck = clk_get(NULL, data->uart_clock); + if (IS_ERR(uart_ck)) { + pr_warn("htc-bt: Could not get uart clock\n"); + uart_ck = NULL; + } else + clk_disable(uart_ck); + } else + uart_ck = NULL; + + /* MUX pins for UART */ + omap_cfg_reg(UART_7XX_1); + omap_cfg_reg(UART_7XX_2); + + /* Configure RFKill */ + rfk = rfkill_alloc("htc-bt", &dev->dev, RFKILL_TYPE_BLUETOOTH, + &htc_bt_rfkill_ops, data); + if (!rfk) { + rc = -ENOMEM; + goto err_rfk_alloc; + } + + rfkill_set_led_trigger_name(rfk, "htc-bt"); + + rc = rfkill_register(rfk); + if (rc) + goto err_rfkill; + + platform_set_drvdata(dev, rfk); + + return 0; + +err_rfkill: + rfkill_destroy(rfk); +err_rfk_alloc: + htc_bt_off(data); +err_pwr_dir: + gpio_free(data->gpio_pwr); +err_pwr: +err_enable_dir: + if (data->gpio_enable) + gpio_free(data->gpio_enable); +err_enable: + return rc; +} + +static int __devexit htc_bt_remove(struct platform_device *dev) +{ + struct htc_bt_data *data = dev->dev.platform_data; + struct rfkill *rfk = platform_get_drvdata(dev); + + platform_set_drvdata(dev, NULL); + + if (rfk) { + rfkill_unregister(rfk); + rfkill_destroy(rfk); + } + rfk = NULL; + + htc_bt_off(data); + + gpio_free(data->gpio_pwr); + if (data->gpio_enable) + gpio_free(data->gpio_enable); + + return 0; +} + +static struct platform_driver htc_bt_driver = { + .probe = htc_bt_probe, + .remove = __devexit_p(htc_bt_remove), + + .driver = { + .name = "htc-bt", + .owner = THIS_MODULE, + }, +}; + + +static int __init htc_bt_init(void) +{ + return platform_driver_register(&htc_bt_driver); +} + +static void __exit htc_bt_exit(void) +{ + platform_driver_unregister(&htc_bt_driver); +} + +late_initcall(htc_bt_init); +module_exit(htc_bt_exit); + diff --git a/arch/arm/mach-omap1/include/mach/htc-bt.h b/arch/arm/mach-omap1/include/mach/htc-bt.h new file mode 100644 index 0000000..843ec45 --- /dev/null +++ b/arch/arm/mach-omap1/include/mach/htc-bt.h @@ -0,0 +1,22 @@ +/* + * HTC bluetooth built-in chip control. + * + * Copyright (C) 2010 Cory Maccarrone + * Based on tosa_bt.h copyright (c) 2008 Dmitry Baryshkov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ +#ifndef HTC_BT_H +#define HTC_BT_H + +struct htc_bt_data { + const char *uart_clock; + int gpio_pwr; + int gpio_enable; +}; + +#endif +