Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp709234ybl; Wed, 11 Dec 2019 06:22:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwnHc/ZPpkUV++7QE0QwA4D6Gz8YCyUASTd27i/8drQhmrqAhsrZTNoxe/xq1VwjlKOCGE9 X-Received: by 2002:a54:4f14:: with SMTP id e20mr2887000oiy.84.1576074130042; Wed, 11 Dec 2019 06:22:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576074130; cv=none; d=google.com; s=arc-20160816; b=pRYle7GtCugfqaDaARgYAtJZq/zzEOf7Bc00X6QfetGIWD5kNpNaViv9O/kuYoGtOI 8vxsniGGMOARPNmjjybQTySFFtjR8kJkbA0wYHnxk4IRH8CRI0+EdUOhXf22lxaoFDmZ FrEPvl7tSGZQt5kUskRjQZPIRhIi9PKwQCiqgYqcXG9kEsI5dI91huyIH4ocff5g509/ jtEbWbq9HERpRjal9frLp3imiCPGwr3ZJ0TozgYh7oqYgba4jgte9dfJOxH6hOc4kafd HCHNxjB2uR/H06zQynKpqWEXuh40Nk/WmZ34pO9YfvjgYpQ1DaMznNAaJ7dM55kQVABh +NrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Jaum9cgn8qiro55SDe7p1j21J37TFAfoAVP6EH0C/t0=; b=Gl98LKvbIv4MVRvWWtRnm8yo4J071LVpTHrq4M14dgbyw8D4JY51bleo1qBD2GoqBU Zw6veHm+//zjm5djsLAzTMjYqr5DzfELP6hUm5MWeZK38NfDBv72Br86KBRrK/ZFhpqx lFNiQdl84m/Gqsrv9SlvhNv5Y5bf/Gr5lhexqw0Ea7c06MMGRBI8mWDWLwJrFyY/Z7gk 4YSwELtEXL9XRhleMyn8Br7yCfgeuZ2TGboRHcVQmLXPiGL9zhH1U0yx1zbPfAJvhw91 TOAyhOMPzDduO2n2X1Zdy+ZtLmvfC8FNduZm3UuyB8iFCeE4qq/yEuCWMc/zcGjNtDbb 6obQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MUW5j7VJ; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13si1188767otk.9.2019.12.11.06.21.57; Wed, 11 Dec 2019 06:22:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MUW5j7VJ; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729769AbfLKOVy (ORCPT + 99 others); Wed, 11 Dec 2019 09:21:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:58134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729671AbfLKOVx (ORCPT ); Wed, 11 Dec 2019 09:21:53 -0500 Received: from localhost.localdomain (unknown [151.66.51.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7447420836; Wed, 11 Dec 2019 14:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576074113; bh=oS1HX2Zz3pkj+fcsDVFQhTLyKHsA0rs2aYnadytMw7Q=; h=From:To:Cc:Subject:Date:From; b=MUW5j7VJmFxui5Fq0Ex4iyV4ZPicB3cXx5zfYnt5SNsYOHYC6u0WPifFcvKYVA+JW KEFiIXFYycWMlboKckAKSUyQNn8ZXpfFDCzcXJouirSHyW0B8wqL1ZfMvdn895vxv3 OARXOvTQvlRVhwEmkYzO8jDVwfsAl134GyI4pc2w= From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, lorenzo.bianconi@redhat.com, ryder.lee@mediatek.com Subject: [PATCH] mt76: mt7615: introduce LED support Date: Wed, 11 Dec 2019 15:21:41 +0100 Message-Id: <378747af00fdd3e64e9f5d7724f1b84759f95e8f.1576074028.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Initialize brightness_set and blink_set callbacks to mt7615_led_set_brightness and mt7615_led_set_blink in order to enable LED support in mt7615 driver Tested-by: Deng Qingfang Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt7615/init.c | 58 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt7615/regs.h | 27 +++++++++ 2 files changed, 85 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/init.c b/drivers/net/wireless/mediatek/mt76/mt7615/init.c index eb7c6b9e3d4d..c25ba5fc3cdc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/init.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/init.c @@ -196,6 +196,58 @@ static const struct ieee80211_iface_combination if_comb[] = { } }; +static void +mt7615_led_set_config(struct led_classdev *led_cdev, + u8 delay_on, u8 delay_off) +{ + struct mt7615_dev *dev; + struct mt76_dev *mt76; + u32 val, addr; + + mt76 = container_of(led_cdev, struct mt76_dev, led_cdev); + dev = container_of(mt76, struct mt7615_dev, mt76); + val = MT_LED_STATUS_DURATION(0xffff) | + MT_LED_STATUS_OFF(delay_off) | + MT_LED_STATUS_ON(delay_on); + + addr = mt7615_reg_map(dev, MT_LED_STATUS_0(mt76->led_pin)); + mt76_wr(dev, addr, val); + addr = mt7615_reg_map(dev, MT_LED_STATUS_1(mt76->led_pin)); + mt76_wr(dev, addr, val); + + val = MT_LED_CTRL_REPLAY(mt76->led_pin) | + MT_LED_CTRL_KICK(mt76->led_pin); + if (mt76->led_al) + val |= MT_LED_CTRL_POLARITY(mt76->led_pin); + addr = mt7615_reg_map(dev, MT_LED_CTRL); + mt76_wr(dev, addr, val); +} + +static int +mt7615_led_set_blink(struct led_classdev *led_cdev, + unsigned long *delay_on, + unsigned long *delay_off) +{ + u8 delta_on, delta_off; + + delta_off = max_t(u8, *delay_off / 10, 1); + delta_on = max_t(u8, *delay_on / 10, 1); + + mt7615_led_set_config(led_cdev, delta_on, delta_off); + + return 0; +} + +static void +mt7615_led_set_brightness(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ + if (!brightness) + mt7615_led_set_config(led_cdev, 0, 0xff); + else + mt7615_led_set_config(led_cdev, 0xff, 0); +} + static void mt7615_init_txpower(struct mt7615_dev *dev, struct ieee80211_supported_band *sband) @@ -383,6 +435,12 @@ int mt7615_register_device(struct mt7615_dev *dev) mt7615_cap_dbdc_disable(dev); dev->phy.dfs_state = -1; + /* init led callbacks */ + if (IS_ENABLED(CONFIG_MT76_LEDS)) { + dev->mt76.led_cdev.brightness_set = mt7615_led_set_brightness; + dev->mt76.led_cdev.blink_set = mt7615_led_set_blink; + } + ret = mt76_register_device(&dev->mt76, true, mt7615_rates, ARRAY_SIZE(mt7615_rates)); if (ret) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/regs.h b/drivers/net/wireless/mediatek/mt76/mt7615/regs.h index 26d121646787..3234ae0761b8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/regs.h +++ b/drivers/net/wireless/mediatek/mt76/mt7615/regs.h @@ -345,6 +345,33 @@ #define MT_TX_AGG_CNT(n) MT_WF_MIB(0xa8 + ((n) << 2)) +#define MT_LED_BASE_PHYS 0x80024000 +#define MT_LED_PHYS(_n) (MT_LED_BASE_PHYS + (_n)) + +#define MT_LED_CTRL MT_LED_PHYS(0x00) + +#define MT_LED_CTRL_REPLAY(_n) BIT(0 + (8 * (_n))) +#define MT_LED_CTRL_POLARITY(_n) BIT(1 + (8 * (_n))) +#define MT_LED_CTRL_TX_BLINK_MODE(_n) BIT(2 + (8 * (_n))) +#define MT_LED_CTRL_TX_MANUAL_BLINK(_n) BIT(3 + (8 * (_n))) +#define MT_LED_CTRL_TX_OVER_BLINK(_n) BIT(5 + (8 * (_n))) +#define MT_LED_CTRL_KICK(_n) BIT(7 + (8 * (_n))) + +#define MT_LED_STATUS_0(_n) MT_LED_PHYS(0x10 + ((_n) * 8)) +#define MT_LED_STATUS_1(_n) MT_LED_PHYS(0x14 + ((_n) * 8)) +#define MT_LED_STATUS_OFF_MASK GENMASK(31, 24) +#define MT_LED_STATUS_OFF(_v) (((_v) << \ + __ffs(MT_LED_STATUS_OFF_MASK)) & \ + MT_LED_STATUS_OFF_MASK) +#define MT_LED_STATUS_ON_MASK GENMASK(23, 16) +#define MT_LED_STATUS_ON(_v) (((_v) << \ + __ffs(MT_LED_STATUS_ON_MASK)) & \ + MT_LED_STATUS_ON_MASK) +#define MT_LED_STATUS_DURATION_MASK GENMASK(15, 0) +#define MT_LED_STATUS_DURATION(_v) (((_v) << \ + __ffs(MT_LED_STATUS_DURATION_MASK)) &\ + MT_LED_STATUS_DURATION_MASK) + #define MT_EFUSE_BASE 0x81070000 #define MT_EFUSE_BASE_CTRL 0x000 #define MT_EFUSE_BASE_CTRL_EMPTY BIT(30) -- 2.21.0