From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 18/21] mfd: htc-pasic3: Prepare driver for leds-pasic3
Date: Tue, 18 Aug 2015 07:52:07 +0100 [thread overview]
Message-ID: <20150818065207.GC6180@x1> (raw)
In-Reply-To: <55D25ABC.1000405@tul.cz>
On Tue, 18 Aug 2015, Petr Cvek wrote:
> Fix register definitions and prepare structures for new leds-pasic3
> driver.
>
> Signed-off-by: Petr Cvek <petr.cvek@tul.cz>
> ---
> drivers/mfd/htc-pasic3.c | 54 ++++++++++++++++-----------
> include/linux/mfd/htc-pasic3.h | 85 +++++++++++++++++++++++++++++++-----------
> 2 files changed, 97 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/mfd/htc-pasic3.c b/drivers/mfd/htc-pasic3.c
> index e88d4f6..16e156d 100644
> --- a/drivers/mfd/htc-pasic3.c
> +++ b/drivers/mfd/htc-pasic3.c
> @@ -3,6 +3,9 @@
> *
> * Copyright (C) 2006 Philipp Zabel <philipp.zabel@gmail.com>
> *
> + * 2015: Added registers for LED and RESET, see htc-pasic3.h
> + * -- Petr Cvek
> + *
This is pretty unconventional.
Please look to see what others have done.
> * This program is free software; you can redistribute it and/or modify
> * it under the terms of the GNU General Public License as published by
> * the Free Software Foundation; version 2 of the License.
> @@ -21,15 +24,10 @@
> #include <linux/mfd/htc-pasic3.h>
> #include <linux/slab.h>
>
> -struct pasic3_data {
> - void __iomem *mapping;
> - unsigned int bus_shift;
> -};
> -
> #define REG_ADDR 5
> #define REG_DATA 6
>
> -#define READ_MODE 0x80
> +#define READ_MODE BIT(7)
>
> /*
> * write to a secondary register on the PASIC3
> @@ -76,24 +74,36 @@ static struct mfd_cell led_cell __initdata = {
> static int ds1wm_enable(struct platform_device *pdev)
> {
> struct device *dev = pdev->dev.parent;
> - int c;
> + struct pasic3_data *asic = platform_get_drvdata(pdev);
> + unsigned long flags;
> + u8 c;
> +
> + spin_lock_irqsave(&asic->lock, flags);
> +
> + c = pasic3_read_register(dev, PASIC3_GPIO);
> + pasic3_write_register(dev, PASIC3_GPIO, c & ~DS1WM_NEN);
>
> - c = pasic3_read_register(dev, 0x28);
> - pasic3_write_register(dev, 0x28, c & 0x7f);
> + spin_unlock_irqrestore(&asic->lock, flags);
>
> - dev_dbg(dev, "DS1WM OWM_EN low (active) %02x\n", c & 0x7f);
> + dev_dbg(dev, "DS1WM OWM_EN low (active) %02lx\n", c & ~DS1WM_NEN);
> return 0;
> }
>
> static int ds1wm_disable(struct platform_device *pdev)
> {
> struct device *dev = pdev->dev.parent;
> - int c;
> + struct pasic3_data *asic = platform_get_drvdata(pdev);
> + unsigned long flags;
> + u8 c;
> +
> + spin_lock_irqsave(&asic->lock, flags);
> +
> + c = pasic3_read_register(dev, PASIC3_GPIO);
> + pasic3_write_register(dev, PASIC3_GPIO, c | DS1WM_NEN);
>
> - c = pasic3_read_register(dev, 0x28);
> - pasic3_write_register(dev, 0x28, c | 0x80);
> + spin_unlock_irqrestore(&asic->lock, flags);
>
> - dev_dbg(dev, "DS1WM OWM_EN high (inactive) %02x\n", c | 0x80);
> + dev_dbg(dev, "DS1WM OWM_EN high (inactive) %02lx\n", c | DS1WM_NEN);
> return 0;
> }
>
> @@ -130,6 +140,7 @@ static int __init pasic3_probe(struct platform_device *pdev)
> struct device *dev = &pdev->dev;
> struct pasic3_data *asic;
> struct resource *r;
> + struct pasic3_leds_pdata *leds_pdata;
> int ret;
> int irq = 0;
>
> @@ -162,6 +173,8 @@ static int __init pasic3_probe(struct platform_device *pdev)
> /* calculate bus shift from mem resource */
> asic->bus_shift = (resource_size(r) - 5) >> 3;
>
> + spin_lock_init(&asic->lock);
> +
> if (pdata && pdata->clock_rate) {
> ds1wm_pdata.clock_rate = pdata->clock_rate;
> /* the first 5 PASIC3 registers control the DS1WM */
> @@ -172,13 +185,12 @@ static int __init pasic3_probe(struct platform_device *pdev)
> dev_warn(dev, "failed to register DS1WM\n");
> }
>
> - if (pdata && pdata->led_pdata) {
> - led_cell.platform_data = pdata->led_pdata;
> - led_cell.pdata_size = sizeof(struct pasic3_leds_machinfo);
> - ret = mfd_add_devices(&pdev->dev, pdev->id, &led_cell, 1, r,
> - 0, NULL);
> - if (ret < 0)
> - dev_warn(dev, "failed to register LED device\n");
> + if (pdata && pdata->pasic3_leds) {
> + leds_pdata = dev_get_platdata(&pdata->pasic3_leds->dev);
Whoa! You're passing a pointer to a device through pdata?
I don't like that at all. Please explain.
> + if (leds_pdata) {
> + leds_pdata->mfd_dev = dev;
> + platform_device_register(pdata->pasic3_leds);
What's the idea here?
> + }
> }
>
> return 0;
> diff --git a/include/linux/mfd/htc-pasic3.h b/include/linux/mfd/htc-pasic3.h
> index 3d3ed67..91a27b6 100644
> --- a/include/linux/mfd/htc-pasic3.h
> +++ b/include/linux/mfd/htc-pasic3.h
> @@ -2,6 +2,7 @@
> * HTC PASIC3 driver - LEDs and DS1WM
> *
> * Copyright (c) 2007 Philipp Zabel <philipp.zabel@gmail.com>
> + * Copyright (c) 2015 Petr Cvek <petr.cvek@tul.cz>
> *
> * This file is subject to the terms and conditions of the GNU General Public
> * License. See the file COPYING in the main directory of this archive for
> @@ -18,37 +19,79 @@
> extern void pasic3_write_register(struct device *dev, u32 reg, u8 val);
> extern u8 pasic3_read_register(struct device *dev, u32 reg);
>
> -/*
> - * mask for registers 0x20,0x21,0x22
> - */
> -#define PASIC3_MASK_LED0 0x04
> -#define PASIC3_MASK_LED1 0x08
> -#define PASIC3_MASK_LED2 0x40
> +#define PASIC3_CH0_DELAY_ON 0x00
> +#define PASIC3_CH0_DELAY_OFF 0x01
> +#define PASIC3_CH1_DELAY_ON 0x02
> +#define PASIC3_CH1_DELAY_OFF 0x03
> +#define PASIC3_CH2_DELAY_ON 0x04
> +#define PASIC3_CH2_DELAY_OFF 0x05
> +#define PASIC3_DELAY_MASK 0x7f
> +
> +#define PASIC3_CH_CONTROL 0x06
> +#define R06_CH0_EN BIT(0)
> +#define R06_CH1_EN BIT(1)
> +#define R06_CH2_EN BIT(2)
> +#define R06_CH0_FORCE_ON BIT(3)
> +#define R06_CH1_FORCE_ON BIT(4)
> +#define R06_CH2_FORCE_ON BIT(5)
>
> /*
> - * bits in register 0x06
> + * pwm_ch0_out | force_on | (bit0 & bit1 & bit2)
> + * pwm_ch1_out | force_on | (bit0 & bit1 & bit2)
> + * pwm_ch2_out | force_on | (bit2?bit0:(bit0 & ! bit1))
Please space this out properly.
> */
> -#define PASIC3_BIT2_LED0 0x08
> -#define PASIC3_BIT2_LED1 0x10
> -#define PASIC3_BIT2_LED2 0x20
> +
> +#define PASIC3_MASK_A 0x20
> +#define PASIC3_MASK_B 0x21
> +#define PASIC3_MASK_C 0x22
> +#define MASK_CH0 BIT(2)
> +#define MASK_CH1 BIT(3)
> +#define MASK_CH2 BIT(6)
> +#define PASIC3_GPIO 0x28
> +#define DS1WM_NEN BIT(7)
> +#define PASIC3_SYS 0x2a
> +
> +/* NORMAL_RST, CAM_PWR_RST and UNKNOWN will autoclear, set STATUS */
> +#define NORMAL_RST BIT(0)
> +#define CAM_PWR_RST BIT(1)
> +#define UNKNOWN BIT(2)
> +#define STATUS_NORMAL_RST BIT(4)
> +#define STATUS_CAM_PWR_RST BIT(5)
> +#define STATUS_UNKNOWN BIT(6)
> +
> +/* FIXME/TODO reset sources */
> +#define PASIC3_RST_EN 0x2c
> +#define EN_NORMAL_RST 0x40
> +#define EN_DOOR_RST 0x42
>
> struct pasic3_led {
> - struct led_classdev led;
> - unsigned int hw_num;
> - unsigned int bit2;
> - unsigned int mask;
> - struct pasic3_leds_machinfo *pdata;
> + char name[24];
> + char default_trigger[80];
> + int hw_num;
> + u8 bit_blink_en;
> + u8 bit_force_on;
> + u8 bit_mask;
> + u8 reg_delay_on;
> + u8 reg_delay_off;
> };
>
> -struct pasic3_leds_machinfo {
> - unsigned int num_leds;
> - unsigned int power_gpio;
> +struct pasic3_leds_pdata {
> struct pasic3_led *leds;
> + int num_leds;
> + int power_gpio;
> + int power_gpio_users;
> + struct device *mfd_dev;
> };
>
> -struct pasic3_platform_data {
> - struct pasic3_leds_machinfo *led_pdata;
> - unsigned int clock_rate;
> +struct pasic3_data {
> + void __iomem *mapping;
> + unsigned int bus_shift;
> + spinlock_t lock;
> };
>
> +struct pasic3_platform_data {
> + unsigned int clock_rate;
> + struct pasic3_led *leds;
> + struct platform_device *pasic3_leds;
> +};
If you can separate these with a TAB like the rest of the file, that
would be preferred.
> #endif
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org ? Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
next prev parent reply other threads:[~2015-08-18 6:52 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1439843482.git.petr.cvek@tul.cz>
2015-08-17 21:56 ` [PATCH v2 01/21] ARM: pxa: magician: Fix Kconfig for magician to always include htc-egpio Petr Cvek
2015-08-18 18:31 ` Robert Jarzmik
2015-08-18 20:02 ` Petr Cvek
2015-08-19 7:29 ` Philipp Zabel
2015-08-24 3:39 ` Petr Cvek
2015-08-17 21:56 ` [PATCH v2 02/21] ARM: pxa: magician: Fix indentation and whitespaces Petr Cvek
2015-08-18 18:32 ` Robert Jarzmik
2015-08-19 7:42 ` Philipp Zabel
2015-08-17 21:57 ` [PATCH v2 03/21] ARM: pxa: magician: Fix comments, debug functions and print strings Petr Cvek
2015-08-18 18:39 ` Robert Jarzmik
2015-08-18 23:09 ` Petr Cvek
2015-08-19 7:57 ` Philipp Zabel
2015-08-17 21:58 ` [PATCH v2 04/21] ARM: pxa: magician: Add, fix and init (new) GPIOs Petr Cvek
2015-08-18 19:01 ` Robert Jarzmik
2015-08-18 22:46 ` Petr Cvek
2015-08-17 21:58 ` [PATCH v2 05/21] ARM: pxa: magician: Add support for ADS7846 touchscreen Petr Cvek
2015-08-19 18:41 ` Robert Jarzmik
2015-08-17 21:59 ` [PATCH v2 06/21] ARM: pxa: magician: Add normal and power I2C definition Petr Cvek
2015-08-19 8:02 ` Philipp Zabel
2015-08-19 18:41 ` Robert Jarzmik
2015-08-17 21:59 ` [PATCH v2 07/21] ARM: pxa: magician: Fix IrDA pdata and redundant GPIO request Petr Cvek
2015-08-19 18:41 ` Robert Jarzmik
2015-08-17 22:00 ` [PATCH v2 08/21] ARM: pxa: magician: Add StrataFlash Vpp GPIO and alternative driver Petr Cvek
2015-08-17 22:01 ` [PATCH v2 09/21] ARM: pxa: magician: Add OV9640 camera support Petr Cvek
2015-08-20 19:48 ` Robert Jarzmik
2015-08-20 20:26 ` Arnd Bergmann
2015-08-20 22:39 ` Petr Cvek
2015-08-21 13:45 ` Arnd Bergmann
2015-08-21 17:36 ` Robert Jarzmik
2015-08-21 22:09 ` Petr Cvek
2015-08-22 12:41 ` Robert Jarzmik
2015-08-24 6:53 ` Lee Jones
2015-08-17 22:01 ` [PATCH v2 10/21] ARM: pxa: magician: Add UDA1380 sound support Petr Cvek
2015-08-20 19:51 ` Robert Jarzmik
2015-08-20 23:01 ` Petr Cvek
2015-08-28 8:48 ` Robert Jarzmik
2015-08-17 22:01 ` [PATCH v2 11/21] ARM: pxa: magician: Add MAX1586 Vcore regulator support Petr Cvek
2015-08-20 19:32 ` Robert Jarzmik
2015-08-20 22:33 ` Petr Cvek
2015-08-28 8:49 ` Robert Jarzmik
2015-08-17 22:02 ` [PATCH v2 12/21] ARM: pxa: magician: Add PXA27x UDC support Petr Cvek
2015-08-20 17:23 ` Robert Jarzmik
2015-08-20 22:21 ` Petr Cvek
2015-08-28 9:58 ` Robert Jarzmik
2015-08-17 22:03 ` [PATCH v2 13/21] ARM: pxa: magician: Fix charging source and add NiCd backup charging Petr Cvek
2015-08-17 22:18 ` Petr Cvek
2015-08-17 22:03 ` [PATCH v2 14/21] ARM: pxa: magician: Fix PXA USB OHCI port enable flags Petr Cvek
2015-08-17 22:03 ` [PATCH v2 15/21] ARM: pxa: magician: Fix PWM backlight regulator Petr Cvek
2015-08-20 19:58 ` Robert Jarzmik
2015-08-17 22:04 ` [PATCH v2 16/21] ARM: pxa: magician: Add support for alternative LCD backlight Petr Cvek
2015-08-20 20:01 ` Robert Jarzmik
2015-08-23 20:55 ` Petr Cvek
2015-08-24 8:25 ` Robert Jarzmik
2015-08-17 22:04 ` [PATCH v2 17/21] ARM: pxa: magician: Remove (temporarily) pasic3 LED support Petr Cvek
2015-08-22 16:25 ` Robert Jarzmik
2015-08-17 22:05 ` [PATCH v2 18/21] mfd: htc-pasic3: Prepare driver for leds-pasic3 Petr Cvek
2015-08-18 6:52 ` Lee Jones [this message]
2015-08-18 21:01 ` Petr Cvek
2015-08-19 6:58 ` Lee Jones
2015-08-17 22:06 ` [PATCH v2 19/21] leds: leds-pasic3: Add support for PASIC3 LED controller Petr Cvek
2015-08-17 22:14 ` Petr Cvek
2015-08-18 10:27 ` Jacek Anaszewski
2015-08-18 21:48 ` Petr Cvek
2015-08-19 8:09 ` Philipp Zabel
2015-08-19 8:49 ` Jacek Anaszewski
2015-08-17 22:06 ` [PATCH v2 20/21] ARM: pxa: magician: Re-add pdata for new leds-pasic3 driver Petr Cvek
2015-08-17 22:07 ` [PATCH v2 21/21] ARM: pxa: magician: Move platform_add_devices() to the end of magician_init() Petr Cvek
2015-08-22 16:27 ` Robert Jarzmik
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=20150818065207.GC6180@x1 \
--to=lee.jones@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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).