linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <florian.fainelli@broadcom.com>
To: "Rafał Miłecki" <zajec5@gmail.com>, "Pavel Machek" <pavel@ucw.cz>,
	"Rob Herring" <robh+dt@kernel.org>
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	linux-arm-kernel@lists.infradead.org,
	bcm-kernel-feedback-list@broadcom.com,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: Re: [PATCH 2/2] leds: bcm63xxx: add support for BCM63xxx controller
Date: Mon, 22 Nov 2021 14:04:10 -0800	[thread overview]
Message-ID: <02a2dbb7-6ae0-af28-e852-ee66bb3d66f1@broadcom.com> (raw)
In-Reply-To: <20211115091107.11737-2-zajec5@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3532 bytes --]

On 11/15/21 1:11 AM, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
> 
> It's a new controller used on BCM4908, some BCM68xx and some BCM63xxx
> SoCs.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

Same comment as the binding, please s/bcm63xxx/bcm63xx/ for matchign
existing drivers/patterns.

[snip]

> +
> +#define BCM63XXX_MAX_LEDS			32> +
> +#define BCM63XXX_GLB_CTRL			0x00
> +#define BCM63XXX_MASK				0x04

This define appears unused.

> +#define BCM63XXX_HW_LED_EN			0x08
> +#define BCM63XXX_SERIAL_LED_SHIFT_SEL		0x0c
> +#define BCM63XXX_FLASH_RATE_CTRL1		0x10
> +#define BCM63XXX_FLASH_RATE_CTRL2		0x14
> +#define BCM63XXX_FLASH_RATE_CTRL3		0x18
> +#define BCM63XXX_FLASH_RATE_CTRL4		0x1c
> +#define BCM63XXX_BRIGHT_CTRL1			0x20
> +#define BCM63XXX_BRIGHT_CTRL2			0x24
> +#define BCM63XXX_BRIGHT_CTRL3			0x28
> +#define BCM63XXX_BRIGHT_CTRL4			0x2c
> +#define BCM63XXX_POWER_LED_CFG			0x30
> +#define BCM63XXX_HW_POLARITY			0xb4
> +#define BCM63XXX_SW_DATA			0xb8

This is called SW_LED_IP in the register but I guess this name is a bit
clearer.

> +#define BCM63XXX_SW_POLARITY			0xbc
> +#define BCM63XXX_PARALLEL_LED_POLARITY		0xc0
> +#define BCM63XXX_SERIAL_LED_POLARITY		0xc4
> +#define BCM63XXX_HW_LED_STATUS			0xc8
> +#define BCM63XXX_FLASH_CTRL_STATUS		0xcc
> +#define BCM63XXX_FLASH_BRT_CTRL			0xd0
> +#define BCM63XXX_FLASH_P_LED_OUT_STATUS		0xd4
> +#define BCM63XXX_FLASH_S_LED_OUT_STATUS		0xd8
> +
> +struct bcm63xxx_leds {
> +	struct device *dev;
> +	void __iomem *base;
> +	spinlock_t lock;
> +};
> +
> +struct bcm63xxx_led {
> +	struct bcm63xxx_leds *leds;
> +	struct led_classdev cdev;
> +	u32 pin;
> +	bool active_low;
> +};
> +
> +/*
> + * I/O access
> + */
> +
> +static void bcm63xxx_leds_write(struct bcm63xxx_leds *leds, unsigned int reg,
> +				u32 data)
> +{
> +	writel(data, leds->base + reg);
> +}
> +
> +static unsigned long bcm63xxx_leds_read(struct bcm63xxx_leds *leds,
> +					unsigned int reg)
> +{
> +	return readl(leds->base + reg);
> +}
> +
> +static void bcm63xxx_leds_update_bits(struct bcm63xxx_leds *leds,
> +				      unsigned int reg, u32 mask, u32 val)
> +{
> +	WARN_ON(val & ~mask);
> +
> +	bcm63xxx_leds_write(leds, reg, (bcm63xxx_leds_read(leds, reg) & ~mask) | (val & mask));
> +}
> +
> +/*
> + * Helpers
> + */
> +
> +static void bcm63xxx_leds_set_flash_rate(struct bcm63xxx_leds *leds,
> +					 struct bcm63xxx_led *led,
> +					 u8 value)
> +{
> +	int reg_offset = (led->pin >> 3) * 4;

Maybe add some definitions here, like LEDS_PER_WORD and LED_SHIFT and
LED_MASK?

[snip]

> +static int bcm63xxx_leds_create_led(struct bcm63xxx_leds *leds, struct device_node *np)
> +{

You are not checking the return value of this function, make it void?

[snip]

> +static int bcm63xxx_leds_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = dev_of_node(&pdev->dev);
> +	struct device *dev = &pdev->dev;
> +	struct bcm63xxx_leds *leds;
> +	struct device_node *child;
> +
> +	leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL);
> +	if (!leds)
> +		return -ENOMEM;
> +
> +	leds->dev = dev;
> +
> +	leds->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(leds->base))
> +		return PTR_ERR(leds->base);
> +
> +	spin_lock_init(&leds->lock);
> +
> +	bcm63xxx_leds_write(leds, BCM63XXX_GLB_CTRL, 0xa);

We would need a define for that:

0x2 -> SERIAL_LED_DATA_PPOL
0x8 -> SERIAL_LED_EN_POL

> +	bcm63xxx_leds_write(leds, BCM63XXX_BRIGHT_CTRL1, 0x88888888);

Cannot we let the LED subsystem change the default brightness?
-- 
Florian

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4221 bytes --]

  reply	other threads:[~2021-11-22 22:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15  9:11 [PATCH 1/2] dt-bindings: leds: add Broadcom's BCM63xxx controller Rafał Miłecki
2021-11-15  9:11 ` [PATCH 2/2] leds: bcm63xxx: add support for " Rafał Miłecki
2021-11-22 22:04   ` Florian Fainelli [this message]
2021-11-24  8:11     ` Rafał Miłecki
2021-11-22 21:51 ` [PATCH 1/2] dt-bindings: leds: add Broadcom's " Florian Fainelli
2021-11-22 22:00   ` Rafał Miłecki
2021-11-23 22:17     ` Florian Fainelli
2021-11-23 22:19       ` Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=02a2dbb7-6ae0-af28-e852-ee66bb3d66f1@broadcom.com \
    --to=florian.fainelli@broadcom.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=rafal@milecki.pl \
    --cc=robh+dt@kernel.org \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).