Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2451157imu; Sat, 10 Nov 2018 15:21:55 -0800 (PST) X-Google-Smtp-Source: AJdET5caBvpdSwyXxapoNnFQfvriITK/euelVKE5URrzdeUEeti+DMVDP+QDOVpoXCqi6huSVfEX X-Received: by 2002:a17:902:4523:: with SMTP id m32-v6mr13485076pld.276.1541892115549; Sat, 10 Nov 2018 15:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541892115; cv=none; d=google.com; s=arc-20160816; b=S20pmqPinJ4+NWrgUUnGO3LQy2oLP2ezP7eN1IC0r7F6Nfb3MstEkooi52U10rIBK0 MOH6FMBwvI2nCN5bd4IftSceHnQslqUq9yhSi1v3ZM/eJ1GBeEAV96KoVRcP5t1OZvt3 Lsb+sVn0/uFCyTljJm+PwXSpYQ9Nq0+XAgphx7vz7ovPIKNns46OaYUb3GHUKU4/r2S5 B6LwU2YlSPKG5hZpe8HwQiK2neAA0ROlr4Uj6W3sJ6YjqW3W2ggT4z8mk7y/0CRa9EO6 dbsEStxuWN8wea/N1sljQXV57aiYkm2jRNMdA92EQHaNTvGDDh+eg5yd7MwjHrKa3hEh KcFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=kjVFlkSgk0BDTgQVRpr/2/qyl7ykVo0DO2kAtXSunjo=; b=Ch618Lc9Cput/2uON68Xtrd1Zw0SOML+65o9bn9OAH6ydm/55kIRWXXQTWeczjkAxF tkt0iEuOlSG+/zuLPJh1TH/woGPG+NiDSRyJvggptBIYQFdPD/HDarIskD7W5g8aoBc0 xYCloFgdJWAzEfkw6OIxT5peTc6xKSD/kS0zJN1qDTOrsGmOzAXsJV6Z+fVaS1M/tAV4 GBhnjgqCH8I1w52+2Ba0c/wRtdE4FdiOMtKgmM0ndxKpd71OxT1lVy1LD9ioBSEi6IiP oVfNRd4BB3uR3GF+Ngrdu+pbSaYh34rdzEoEd4l5wvvLSdhJVHkIfADRj75vYOjPMedO YPBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=HIf4o9S0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11-v6si12308641plo.199.2018.11.10.15.21.24; Sat, 10 Nov 2018 15:21:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=HIf4o9S0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbeKKJHc (ORCPT + 99 others); Sun, 11 Nov 2018 04:07:32 -0500 Received: from mail.andi.de1.cc ([85.214.239.24]:55612 "EHLO h2641619.stratoserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725859AbeKKJHc (ORCPT ); Sun, 11 Nov 2018 04:07:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=kjVFlkSgk0BDTgQVRpr/2/qyl7ykVo0DO2kAtXSunjo=; b=HIf4o9S0jhybQUpDBlhogfd2Pn NZtHe/0Sk2p+xwG6WvabrRAX1RVQf9GDRtxEjdA4yd/z33BQtOulYqZz8yqUby80/wW5vGZ8ESfGZ aQivKC4uSw5OCpx22oklzpddC1UkCBu4P0KD1dOHxxJAe9zndI2YrIrOLc0DuxsLiCWs=; Received: from p200300ccfbcefb001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:fbce:fb00:1a3d:a2ff:febf:d33a] helo=aktux) by h2641619.stratoserver.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLcYZ-0002U6-Ia; Sun, 11 Nov 2018 00:20:47 +0100 Received: from andi by aktux with local (Exim 4.89) (envelope-from ) id 1gLcYZ-0004rX-23; Sun, 11 Nov 2018 00:20:47 +0100 From: Andreas Kemnade To: marcel@holtmann.org, johan.hedberg@gmail.com, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, letux-kernel@openphoenux.org Cc: Andreas Kemnade Subject: [PATCH RFC] bluetooth: add uart h4 devices via serdev/devicetree Date: Sun, 11 Nov 2018 00:20:34 +0100 Message-Id: <20181110232034.17277-1-andreas@kemnade.info> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a first try to be able to use h4 devices specified in the devicetree, so you do not need to call hciattach and it can be automatically probed. Of course, proper devicetree bindings documentation is missing. And also you would extend that by regulator/ enable gpio settings. But before proceeding further it should be checked if the general way of doing things is right. Signed-off-by: Andreas Kemnade --- drivers/bluetooth/hci_h4.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c index fb97a3bf069b..8df0611d976c 100644 --- a/drivers/bluetooth/hci_h4.c +++ b/drivers/bluetooth/hci_h4.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include @@ -47,6 +49,11 @@ #include "hci_uart.h" +struct h4_device { + struct hci_uart hu; + bool flow; +}; + struct h4_struct { struct sk_buff *rx_skb; struct sk_buff_head txq; @@ -146,9 +153,76 @@ static struct sk_buff *h4_dequeue(struct hci_uart *hu) return skb_dequeue(&h4->txq); } +#if IS_ENABLED(CONFIG_SERIAL_DEV_BUS) +static int h4_setup(struct hci_uart *hu) +{ + struct h4_device *h4dev; + struct serdev_device *serdev = hu->serdev; + + if (!serdev) + return 0; + + h4dev = serdev_device_get_drvdata(serdev); + + serdev_device_set_flow_control(serdev, h4dev->flow); + + return 0; +} + +static const struct hci_uart_proto h4p; + +static int hci_h4_probe(struct serdev_device *serdev) +{ + struct hci_uart *hu; + struct h4_device *h4dev; + u32 speed = 3000000; + + h4dev = devm_kzalloc(&serdev->dev, sizeof(struct h4_device), + GFP_KERNEL); + if (!h4dev) + return -ENOMEM; + hu = &h4dev->hu; + + serdev_device_set_drvdata(serdev, h4dev); + hu->serdev = serdev; + + h4dev->flow = of_property_read_bool(serdev->dev.of_node, "flow"); + + of_property_read_u32(serdev->dev.of_node, "speed", &speed); + hci_uart_set_speeds(hu, speed, speed); + + return hci_uart_register_device(hu, &h4p); +} + +static void hci_h4_remove(struct serdev_device *serdev) +{ + struct h4_device *h4dev = serdev_device_get_drvdata(serdev); + + hci_uart_unregister_device(&h4dev->hu); +} + +static const struct of_device_id hci_h4_of_match[] = { + { .compatible = "wi2wi,w2cbw003-bluetooth"}, + {}, +}; +MODULE_DEVICE_TABLE(of, hci_h4_of_match); + +static struct serdev_device_driver hci_h4_drv = { + .driver = { + .name = "hci-h4", + .of_match_table = of_match_ptr(hci_h4_of_match), + }, + .probe = hci_h4_probe, + .remove = hci_h4_remove +}; +#else +#define h4_setup NULL +#endif + static const struct hci_uart_proto h4p = { .id = HCI_UART_H4, .name = "H4", + .setup = h4_setup, .open = h4_open, .close = h4_close, .recv = h4_recv, @@ -159,11 +233,15 @@ static const struct hci_uart_proto h4p = { int __init h4_init(void) { + serdev_device_driver_register(&hci_h4_drv); + return hci_uart_register_proto(&h4p); } int __exit h4_deinit(void) { + serdev_device_driver_unregister(&hci_h4_drv); + return hci_uart_unregister_proto(&h4p); } -- 2.11.0