1515#include <linux/property.h>
1616#include <linux/fb.h>
1717#include <linux/backlight.h>
18+ #include <linux/container_of.h>
1819#include <linux/input.h>
1920#include <linux/input/matrix_keypad.h>
2021#include <linux/leds.h>
@@ -107,6 +108,15 @@ struct ht16k33_priv {
107108 uint8_t blink ;
108109};
109110
111+ #define ht16k33_work_to_priv (p ) \
112+ container_of(p, struct ht16k33_priv, work.work)
113+
114+ #define ht16k33_led_to_priv (p ) \
115+ container_of(p, struct ht16k33_priv, led)
116+
117+ #define ht16k33_linedisp_to_priv (p ) \
118+ container_of(p, struct ht16k33_priv, seg.linedisp)
119+
110120static const struct fb_fix_screeninfo ht16k33_fb_fix = {
111121 .id = DRIVER_NAME ,
112122 .type = FB_TYPE_PACKED_PIXELS ,
@@ -194,17 +204,15 @@ static int ht16k33_brightness_set(struct ht16k33_priv *priv,
194204static int ht16k33_brightness_set_blocking (struct led_classdev * led_cdev ,
195205 enum led_brightness brightness )
196206{
197- struct ht16k33_priv * priv = container_of (led_cdev , struct ht16k33_priv ,
198- led );
207+ struct ht16k33_priv * priv = ht16k33_led_to_priv (led_cdev );
199208
200209 return ht16k33_brightness_set (priv , brightness );
201210}
202211
203212static int ht16k33_blink_set (struct led_classdev * led_cdev ,
204213 unsigned long * delay_on , unsigned long * delay_off )
205214{
206- struct ht16k33_priv * priv = container_of (led_cdev , struct ht16k33_priv ,
207- led );
215+ struct ht16k33_priv * priv = ht16k33_led_to_priv (led_cdev );
208216 unsigned int delay ;
209217 uint8_t blink ;
210218 int err ;
@@ -246,8 +254,7 @@ static void ht16k33_fb_queue(struct ht16k33_priv *priv)
246254 */
247255static void ht16k33_fb_update (struct work_struct * work )
248256{
249- struct ht16k33_priv * priv = container_of (work , struct ht16k33_priv ,
250- work .work );
257+ struct ht16k33_priv * priv = ht16k33_work_to_priv (work );
251258 struct ht16k33_fbdev * fbdev = & priv -> fbdev ;
252259
253260 uint8_t * p1 , * p2 ;
@@ -441,8 +448,7 @@ static void ht16k33_keypad_stop(struct input_dev *dev)
441448
442449static void ht16k33_seg7_update (struct work_struct * work )
443450{
444- struct ht16k33_priv * priv = container_of (work , struct ht16k33_priv ,
445- work .work );
451+ struct ht16k33_priv * priv = ht16k33_work_to_priv (work );
446452 struct ht16k33_seg * seg = & priv -> seg ;
447453 char * s = seg -> linedisp .buf ;
448454 uint8_t buf [9 ];
@@ -462,8 +468,7 @@ static void ht16k33_seg7_update(struct work_struct *work)
462468
463469static void ht16k33_seg14_update (struct work_struct * work )
464470{
465- struct ht16k33_priv * priv = container_of (work , struct ht16k33_priv ,
466- work .work );
471+ struct ht16k33_priv * priv = ht16k33_work_to_priv (work );
467472 struct ht16k33_seg * seg = & priv -> seg ;
468473 char * s = seg -> linedisp .buf ;
469474 uint8_t buf [8 ];
@@ -478,8 +483,7 @@ static void ht16k33_seg14_update(struct work_struct *work)
478483
479484static void ht16k33_linedisp_update (struct linedisp * linedisp )
480485{
481- struct ht16k33_priv * priv = container_of (linedisp , struct ht16k33_priv ,
482- seg .linedisp );
486+ struct ht16k33_priv * priv = ht16k33_linedisp_to_priv (linedisp );
483487
484488 schedule_delayed_work (& priv -> work , 0 );
485489}
0 commit comments