Skip to content

Commit

Permalink
auxdisplay: ht16k33: Define a few helper macros
Browse files Browse the repository at this point in the history
Define a few helper macros — wrappers on container_of() — for easier
maintenance in the future. While at it, include missing container_of.h.

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
  • Loading branch information
Andy Shevchenko committed Feb 26, 2024
1 parent 5a805a7 commit 0ee6eb8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions drivers/auxdisplay/ht16k33.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/property.h>
#include <linux/fb.h>
#include <linux/backlight.h>
#include <linux/container_of.h>
#include <linux/input.h>
#include <linux/input/matrix_keypad.h>
#include <linux/leds.h>
Expand Down Expand Up @@ -107,6 +108,15 @@ struct ht16k33_priv {
uint8_t blink;
};

#define ht16k33_work_to_priv(p) \
container_of(p, struct ht16k33_priv, work.work)

#define ht16k33_led_to_priv(p) \
container_of(p, struct ht16k33_priv, led)

#define ht16k33_linedisp_to_priv(p) \
container_of(p, struct ht16k33_priv, seg.linedisp)

static const struct fb_fix_screeninfo ht16k33_fb_fix = {
.id = DRIVER_NAME,
.type = FB_TYPE_PACKED_PIXELS,
Expand Down Expand Up @@ -194,17 +204,15 @@ static int ht16k33_brightness_set(struct ht16k33_priv *priv,
static int ht16k33_brightness_set_blocking(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct ht16k33_priv *priv = container_of(led_cdev, struct ht16k33_priv,
led);
struct ht16k33_priv *priv = ht16k33_led_to_priv(led_cdev);

return ht16k33_brightness_set(priv, brightness);
}

static int ht16k33_blink_set(struct led_classdev *led_cdev,
unsigned long *delay_on, unsigned long *delay_off)
{
struct ht16k33_priv *priv = container_of(led_cdev, struct ht16k33_priv,
led);
struct ht16k33_priv *priv = ht16k33_led_to_priv(led_cdev);
unsigned int delay;
uint8_t blink;
int err;
Expand Down Expand Up @@ -246,8 +254,7 @@ static void ht16k33_fb_queue(struct ht16k33_priv *priv)
*/
static void ht16k33_fb_update(struct work_struct *work)
{
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
work.work);
struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
struct ht16k33_fbdev *fbdev = &priv->fbdev;

uint8_t *p1, *p2;
Expand Down Expand Up @@ -441,8 +448,7 @@ static void ht16k33_keypad_stop(struct input_dev *dev)

static void ht16k33_seg7_update(struct work_struct *work)
{
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
work.work);
struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
struct ht16k33_seg *seg = &priv->seg;
char *s = seg->linedisp.buf;
uint8_t buf[9];
Expand All @@ -462,8 +468,7 @@ static void ht16k33_seg7_update(struct work_struct *work)

static void ht16k33_seg14_update(struct work_struct *work)
{
struct ht16k33_priv *priv = container_of(work, struct ht16k33_priv,
work.work);
struct ht16k33_priv *priv = ht16k33_work_to_priv(work);
struct ht16k33_seg *seg = &priv->seg;
char *s = seg->linedisp.buf;
uint8_t buf[8];
Expand All @@ -478,8 +483,7 @@ static void ht16k33_seg14_update(struct work_struct *work)

static void ht16k33_linedisp_update(struct linedisp *linedisp)
{
struct ht16k33_priv *priv = container_of(linedisp, struct ht16k33_priv,
seg.linedisp);
struct ht16k33_priv *priv = ht16k33_linedisp_to_priv(linedisp);

schedule_delayed_work(&priv->work, 0);
}
Expand Down

0 comments on commit 0ee6eb8

Please sign in to comment.