From: Dan Carpenter <dan.carpenter@oracle.com>
To: Eduardo Valentin <eduardo.valentin@ti.com>
Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org,
linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org
Subject: Re: [PATCH 07/50] staging: omap-thermal: introduce RMW_BITS macro
Date: Sat, 16 Mar 2013 00:09:46 +0300 [thread overview]
Message-ID: <20130315210946.GK9138@mwanda> (raw)
In-Reply-To: <1363352438-15935-8-git-send-email-eduardo.valentin@ti.com>
On Fri, Mar 15, 2013 at 08:59:55AM -0400, Eduardo Valentin wrote:
> This patch introduce a macro to read, update, write bitfields.
> It will be specific to bandgap data structures.
>
> Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>
> ---
> drivers/staging/omap-thermal/omap-bandgap.c | 178 +++++++--------------------
> 1 files changed, 46 insertions(+), 132 deletions(-)
>
> diff --git a/drivers/staging/omap-thermal/omap-bandgap.c b/drivers/staging/omap-thermal/omap-bandgap.c
> index 9f2d7cc..1c1b905 100644
> --- a/drivers/staging/omap-thermal/omap-bandgap.c
> +++ b/drivers/staging/omap-thermal/omap-bandgap.c
> @@ -52,25 +52,29 @@ static void omap_bandgap_writel(struct omap_bandgap *bg_ptr, u32 val, u32 reg)
> writel(val, bg_ptr->base + reg);
> }
>
> +/* update bits, value will be shifted */
> +#define RMW_BITS(bg_ptr, id, reg, mask, val) \
> +do { \
> + struct temp_sensor_registers *t; \
> + u32 r; \
> + \
> + t = bg_ptr->conf->sensors[(id)].registers; \
> + r = omap_bandgap_readl(bg_ptr, t->reg); \
> + r &= ~t->mask; \
> + r |= (val) << __ffs(t->mask); \
> + omap_bandgap_writel(bg_ptr, r, t->reg); \
> +} while (0)
> +
> static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on)
> {
> - struct temp_sensor_registers *tsr;
> int i;
> - u32 ctrl;
>
> if (!OMAP_BANDGAP_HAS(bg_ptr, POWER_SWITCH))
> return 0;
>
> - for (i = 0; i < bg_ptr->conf->sensor_count; i++) {
> - tsr = bg_ptr->conf->sensors[i].registers;
> - ctrl = omap_bandgap_readl(bg_ptr, tsr->temp_sensor_ctrl);
> - ctrl &= ~tsr->bgap_tempsoff_mask;
> + for (i = 0; i < bg_ptr->conf->sensor_count; i++)
> /* active on 0 */
> - ctrl |= !on << __ffs(tsr->bgap_tempsoff_mask);
> -
> - /* write BGAP_TEMPSOFF should be reset to 0 */
> - omap_bandgap_writel(bg_ptr, ctrl, tsr->temp_sensor_ctrl);
> - }
> + RMW_BITS(bg_ptr, i, temp_sensor_ctrl, bgap_tempsoff_mask, !on);
>
> return 0;
> }
> @@ -78,15 +82,13 @@ static int omap_bandgap_power(struct omap_bandgap *bg_ptr, bool on)
> static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id)
> {
This patch is fine and it makes it cleaner than before.
But that said, I don't care for the RMW_BITS() very much as a long
term thing. If we just used pointers instead of passing the offset
into the bg_ptr->conf->sensors[] array then everything would be a
lot cleaner.
In other words, instead of this:
static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr, int id)
We would have:
static u32 omap_bandgap_read_temp(struct omap_bandgap *bg_ptr,
struct temp_sensor_registers *tsr)
If you have the pointer then it's easy write RMW_BITS() as a
function.
static void rmw_bits(struct omap_bandgap *bg_ptr, u32 reg, u32 mask, u32 val)
{
u32 r;
r = omap_bandgap_readl(bg_ptr, reg);
r &= ~mask;
r |= val << __ffs(mask);
omap_bandgap_writel(bg_ptr, r, reg);
}
It's called like:
rmw_bits(bg_ptr, tsr->bgap_mask_ctrl, tsr->mask_freeze_mask, 1);
regards,
dan carpenter
next prev parent reply other threads:[~2013-03-15 21:09 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 12:59 [PATCH 00/50] staging: omap-thermal: several code refactoring Eduardo Valentin
2013-03-15 12:59 ` [PATCH 01/50] staging: omap-thermal: use BIT() macro Eduardo Valentin
2013-03-15 12:59 ` [PATCH 02/50] staging: omap-thermal: remove unused _SHIFT macros Eduardo Valentin
2013-03-15 12:59 ` [PATCH 03/50] staging: omap-thermal: create header for register, bitfields and definitions Eduardo Valentin
2013-03-15 12:59 ` [PATCH 04/50] staging: omap-thermal: update documentation of omap-bandgap.h Eduardo Valentin
2013-03-15 12:59 ` [PATCH 05/50] staging: omap-thermal: style cleanup on omap-bandgap.c Eduardo Valentin
2013-03-15 12:59 ` [PATCH 06/50] staging: omap-thermal: fix error checking Eduardo Valentin
2013-03-15 12:59 ` [PATCH 07/50] staging: omap-thermal: introduce RMW_BITS macro Eduardo Valentin
2013-03-15 21:09 ` Dan Carpenter [this message]
2013-03-16 12:36 ` Eduardo Valentin
2013-03-16 14:00 ` Dan Carpenter
2013-03-15 12:59 ` [PATCH 08/50] staging: omap-thermal: add documentation for register access functions Eduardo Valentin
2013-03-15 12:59 ` [PATCH 09/50] staging: omap-thermal: make a omap_bandgap_power with only one exit point Eduardo Valentin
2013-03-15 21:22 ` Dan Carpenter
2013-03-16 12:39 ` Eduardo Valentin
2013-03-16 13:56 ` Dan Carpenter
2013-03-15 12:59 ` [PATCH 10/50] staging: omap-thermal: add documentation for omap_bandgap_power Eduardo Valentin
2013-03-15 12:59 ` [PATCH 11/50] staging: omap-thermal: add documentation for omap_bandgap_read_temp Eduardo Valentin
2013-03-15 13:00 ` [PATCH 12/50] staging: omap-thermal: rename talert handler Eduardo Valentin
2013-03-15 13:00 ` [PATCH 13/50] staging: omap-thermal: update documentation for talert irq handler Eduardo Valentin
2013-03-15 13:00 ` [PATCH 14/50] staging: omap-thermal: update tshut IRQ handler documentation Eduardo Valentin
2013-03-15 13:00 ` [PATCH 15/50] staging: omap-thermal: remove duplicated code Eduardo Valentin
2013-03-15 13:00 ` [PATCH 16/50] staging: omap-thermal: read status only once inside alert IRQ Eduardo Valentin
2013-03-15 13:00 ` [PATCH 17/50] staging: omap-thermal: add a section of register manipulation Eduardo Valentin
2013-03-15 13:00 ` [PATCH 18/50] staging: omap-thermal: section of basic helpers Eduardo Valentin
2013-03-15 13:00 ` [PATCH 19/50] staging: omap-thermal: IRQ handler section Eduardo Valentin
2013-03-15 13:00 ` [PATCH 20/50] staging: omap-thermal: ADC section Eduardo Valentin
2013-03-15 13:00 ` [PATCH 21/50] staging: omap-thermal: name adc_to_temp_conversion in a better way Eduardo Valentin
2013-03-15 13:00 ` [PATCH 22/50] staging: omap-thermal: rewrite omap_bandgap_adc_to_mcelsius on kernel coding style Eduardo Valentin
2013-03-16 8:27 ` Dan Carpenter
2013-03-15 13:00 ` [PATCH 23/50] staging: omap-thermal: add documentation for omap_bandgap_adc_to_mcelsius Eduardo Valentin
2013-03-15 13:00 ` [PATCH 24/50] staging: omap-thermal: name temp_to_adc_conversion in a better way Eduardo Valentin
2013-03-15 13:00 ` [PATCH 25/50] staging: omap-thermal: rewrite omap_bandgap_mcelsius_to_adc on kernel coding style Eduardo Valentin
2013-03-16 8:33 ` Dan Carpenter
2013-03-15 13:00 ` [PATCH 26/50] staging: omap-thermal: move conv table limits out of sensor data Eduardo Valentin
2013-03-15 13:00 ` [PATCH 27/50] staging: omap-thermal: add documentation for omap_bandgap_mcelsius_to_adc Eduardo Valentin
2013-03-15 13:00 ` [PATCH 28/50] staging: omap-thermal: rename add_hyst to omap_bandgap_add_hyst Eduardo Valentin
2013-03-15 13:00 ` [PATCH 29/50] staging: omap-thermal: document omap_bandgap_add_hyst function Eduardo Valentin
2013-03-15 13:00 ` [PATCH 30/50] staging: omap-thermal: threshold manipulation section Eduardo Valentin
2013-03-15 13:00 ` [PATCH 31/50] staging: omap-thermal: refactor temp_sensor_unmask_interrupts Eduardo Valentin
2013-03-15 13:00 ` [PATCH 32/50] staging: omap-thermal: update omap_bandgap_unmask_interrupts documentation Eduardo Valentin
2013-03-15 13:00 ` [PATCH 33/50] staging: omap-thermal: refactor APIs handling threshold values Eduardo Valentin
2013-03-16 8:39 ` Dan Carpenter
2013-03-16 12:49 ` Eduardo Valentin
2013-03-16 13:58 ` Dan Carpenter
2013-03-15 13:00 ` [PATCH 34/50] staging: omap-thermal: device initialization section Eduardo Valentin
2013-03-15 13:00 ` [PATCH 35/50] staging: omap-thermal: section of device driver callbacks Eduardo Valentin
2013-03-15 13:00 ` [PATCH 36/50] staging: omap-thermal: rename enable_continuous_mode Eduardo Valentin
2013-03-15 13:00 ` [PATCH 37/50] staging: omap-thermal: update omap_bandgap_set_continous_mode documentation Eduardo Valentin
2013-03-15 13:00 ` [PATCH 38/50] staging: omap-thermal: document omap_bandgap_force_single_read Eduardo Valentin
2013-03-15 13:00 ` [PATCH 39/50] staging: omap-thermal: document omap_bandgap_update_alert_threshold function Eduardo Valentin
2013-03-15 13:00 ` [PATCH 40/50] staging: omap-thermal: document _omap_bandgap_write_threshold function Eduardo Valentin
2013-03-15 13:00 ` [PATCH 41/50] staging: omap-thermal: document _omap_bandgap_read_threshold function Eduardo Valentin
2013-03-15 13:00 ` [PATCH 42/50] staging: omap-thermal: document omap_bandgap_tshut_init function Eduardo Valentin
2013-03-15 13:00 ` [PATCH 43/50] staging: omap-thermal: document omap_bandgap_alert_init function Eduardo Valentin
2013-03-15 13:00 ` [PATCH 44/50] staging: omap-thermal: document omap_bandgap_build function Eduardo Valentin
2013-03-15 13:00 ` [PATCH 45/50] staging: omap-thermal: change Kconfig dependency method Eduardo Valentin
2013-03-15 13:00 ` [PATCH 46/50] staging: Add a MAINTAINERS entry for TI bandgap and thermal driver Eduardo Valentin
2013-03-15 13:00 ` [PATCH 47/50] staging: omap-thermal: switch mutex to spinlock inside omap-bandgap Eduardo Valentin
2013-03-16 8:59 ` Dan Carpenter
2013-03-16 12:41 ` Eduardo Valentin
2013-03-16 14:22 ` Dan Carpenter
2013-03-15 13:00 ` [PATCH 48/50] staging: omap-thermal: remove TODO entry suggesting regmap usage Eduardo Valentin
2013-03-15 13:00 ` [PATCH 49/50] staging: omap-thermal: remove TODO entry for exposed APIs Eduardo Valentin
2013-03-15 13:00 ` [PATCH 50/50] staging: omap-thermal: add documentation for omap_bandgap_validate Eduardo Valentin
2013-03-16 9:05 ` [PATCH 00/50] staging: omap-thermal: several code refactoring Dan Carpenter
2013-03-16 12:46 ` Eduardo Valentin
2013-03-16 16:16 ` Greg KH
2013-03-18 14:44 ` Eduardo Valentin
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=20130315210946.GK9138@mwanda \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=eduardo.valentin@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.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).