2929#define AXP20X_PEK_STARTUP_MASK (0xc0)
3030#define AXP20X_PEK_SHUTDOWN_MASK (0x03)
3131
32+ struct axp20x_info {
33+ const struct axp20x_time * startup_time ;
34+ unsigned int startup_mask ;
35+ const struct axp20x_time * shutdown_time ;
36+ unsigned int shutdown_mask ;
37+ };
38+
3239struct axp20x_pek {
3340 struct axp20x_dev * axp20x ;
3441 struct input_dev * input ;
42+ struct axp20x_info * info ;
3543 int irq_dbr ;
3644 int irq_dbf ;
3745};
@@ -55,54 +63,61 @@ static const struct axp20x_time shutdown_time[] = {
5563 { .time = 10000 , .idx = 3 },
5664};
5765
58- struct axp20x_pek_ext_attr {
59- const struct axp20x_time * p_time ;
60- unsigned int mask ;
61- };
62-
63- static struct axp20x_pek_ext_attr axp20x_pek_startup_ext_attr = {
64- .p_time = startup_time ,
65- .mask = AXP20X_PEK_STARTUP_MASK ,
66- };
67-
68- static struct axp20x_pek_ext_attr axp20x_pek_shutdown_ext_attr = {
69- .p_time = shutdown_time ,
70- .mask = AXP20X_PEK_SHUTDOWN_MASK ,
66+ static const struct axp20x_info axp20x_info = {
67+ .startup_time = startup_time ,
68+ .startup_mask = AXP20X_PEK_STARTUP_MASK ,
69+ .shutdown_time = shutdown_time ,
70+ .shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK ,
7171};
7272
73- static struct axp20x_pek_ext_attr * get_axp_ext_attr (struct device_attribute * attr )
74- {
75- return container_of (attr , struct dev_ext_attribute , attr )-> var ;
76- }
77-
78- static ssize_t axp20x_show_ext_attr (struct device * dev ,
79- struct device_attribute * attr , char * buf )
73+ static ssize_t axp20x_show_attr (struct device * dev ,
74+ const struct axp20x_time * time ,
75+ unsigned int mask , char * buf )
8076{
8177 struct axp20x_pek * axp20x_pek = dev_get_drvdata (dev );
82- struct axp20x_pek_ext_attr * axp20x_ea = get_axp_ext_attr (attr );
8378 unsigned int val ;
8479 int ret , i ;
8580
8681 ret = regmap_read (axp20x_pek -> axp20x -> regmap , AXP20X_PEK_KEY , & val );
8782 if (ret != 0 )
8883 return ret ;
8984
90- val &= axp20x_ea -> mask ;
91- val >>= ffs (axp20x_ea -> mask ) - 1 ;
85+ val &= mask ;
86+ val >>= ffs (mask ) - 1 ;
9287
9388 for (i = 0 ; i < 4 ; i ++ )
94- if (val == axp20x_ea -> p_time [i ].idx )
95- val = axp20x_ea -> p_time [i ].time ;
89+ if (val == time [i ].idx )
90+ val = time [i ].time ;
9691
9792 return sprintf (buf , "%u\n" , val );
9893}
9994
100- static ssize_t axp20x_store_ext_attr (struct device * dev ,
101- struct device_attribute * attr ,
102- const char * buf , size_t count )
95+ static ssize_t axp20x_show_attr_startup (struct device * dev ,
96+ struct device_attribute * attr ,
97+ char * buf )
98+ {
99+ struct axp20x_pek * axp20x_pek = dev_get_drvdata (dev );
100+
101+ return axp20x_show_attr (dev , axp20x_pek -> info -> startup_time ,
102+ axp20x_pek -> info -> startup_mask , buf );
103+ }
104+
105+ static ssize_t axp20x_show_attr_shutdown (struct device * dev ,
106+ struct device_attribute * attr ,
107+ char * buf )
108+ {
109+ struct axp20x_pek * axp20x_pek = dev_get_drvdata (dev );
110+
111+ return axp20x_show_attr (dev , axp20x_pek -> info -> shutdown_time ,
112+ axp20x_pek -> info -> shutdown_mask , buf );
113+ }
114+
115+ static ssize_t axp20x_store_attr (struct device * dev ,
116+ const struct axp20x_time * time ,
117+ unsigned int mask , const char * buf ,
118+ size_t count )
103119{
104120 struct axp20x_pek * axp20x_pek = dev_get_drvdata (dev );
105- struct axp20x_pek_ext_attr * axp20x_ea = get_axp_ext_attr (attr );
106121 char val_str [20 ];
107122 size_t len ;
108123 int ret , i ;
@@ -123,39 +138,52 @@ static ssize_t axp20x_store_ext_attr(struct device *dev,
123138 for (i = 3 ; i >= 0 ; i -- ) {
124139 unsigned int err ;
125140
126- err = abs (axp20x_ea -> p_time [i ].time - val );
141+ err = abs (time [i ].time - val );
127142 if (err < best_err ) {
128143 best_err = err ;
129- idx = axp20x_ea -> p_time [i ].idx ;
144+ idx = time [i ].idx ;
130145 }
131146
132147 if (!err )
133148 break ;
134149 }
135150
136- idx <<= ffs (axp20x_ea -> mask ) - 1 ;
137- ret = regmap_update_bits (axp20x_pek -> axp20x -> regmap ,
138- AXP20X_PEK_KEY ,
139- axp20x_ea -> mask , idx );
151+ idx <<= ffs (mask ) - 1 ;
152+ ret = regmap_update_bits (axp20x_pek -> axp20x -> regmap , AXP20X_PEK_KEY ,
153+ mask , idx );
140154 if (ret != 0 )
141155 return - EINVAL ;
142156
143157 return count ;
144158}
145159
146- static struct dev_ext_attribute axp20x_dev_attr_startup = {
147- .attr = __ATTR (startup , 0644 , axp20x_show_ext_attr , axp20x_store_ext_attr ),
148- .var = & axp20x_pek_startup_ext_attr ,
149- };
160+ static ssize_t axp20x_store_attr_startup (struct device * dev ,
161+ struct device_attribute * attr ,
162+ const char * buf , size_t count )
163+ {
164+ struct axp20x_pek * axp20x_pek = dev_get_drvdata (dev );
150165
151- static struct dev_ext_attribute axp20x_dev_attr_shutdown = {
152- .attr = __ATTR (shutdown , 0644 , axp20x_show_ext_attr , axp20x_store_ext_attr ),
153- .var = & axp20x_pek_shutdown_ext_attr ,
154- };
166+ return axp20x_store_attr (dev , axp20x_pek -> info -> startup_time ,
167+ axp20x_pek -> info -> startup_mask , buf , count );
168+ }
169+
170+ static ssize_t axp20x_store_attr_shutdown (struct device * dev ,
171+ struct device_attribute * attr ,
172+ const char * buf , size_t count )
173+ {
174+ struct axp20x_pek * axp20x_pek = dev_get_drvdata (dev );
175+
176+ return axp20x_store_attr (dev , axp20x_pek -> info -> shutdown_time ,
177+ axp20x_pek -> info -> shutdown_mask , buf , count );
178+ }
179+
180+ DEVICE_ATTR (startup , 0644 , axp20x_show_attr_startup , axp20x_store_attr_startup );
181+ DEVICE_ATTR (shutdown , 0644 , axp20x_show_attr_shutdown ,
182+ axp20x_store_attr_shutdown );
155183
156184static struct attribute * axp20x_attributes [] = {
157- & axp20x_dev_attr_startup . attr .attr ,
158- & axp20x_dev_attr_shutdown . attr .attr ,
185+ & dev_attr_startup .attr ,
186+ & dev_attr_shutdown .attr ,
159187 NULL ,
160188};
161189
@@ -291,8 +319,14 @@ static bool axp20x_pek_should_register_input(struct axp20x_pek *axp20x_pek,
291319static int axp20x_pek_probe (struct platform_device * pdev )
292320{
293321 struct axp20x_pek * axp20x_pek ;
322+ const struct platform_device_id * match = platform_get_device_id (pdev );
294323 int error ;
295324
325+ if (!match ) {
326+ dev_err (& pdev -> dev , "Failed to get platform_device_id\n" );
327+ return - EINVAL ;
328+ }
329+
296330 axp20x_pek = devm_kzalloc (& pdev -> dev , sizeof (struct axp20x_pek ),
297331 GFP_KERNEL );
298332 if (!axp20x_pek )
@@ -306,6 +340,8 @@ static int axp20x_pek_probe(struct platform_device *pdev)
306340 return error ;
307341 }
308342
343+ axp20x_pek -> info = (struct axp20x_info * )match -> driver_data ;
344+
309345 error = devm_device_add_group (& pdev -> dev , & axp20x_attribute_group );
310346 if (error ) {
311347 dev_err (& pdev -> dev , "Failed to create sysfs attributes: %d\n" ,
@@ -342,8 +378,17 @@ static const struct dev_pm_ops axp20x_pek_pm_ops = {
342378#endif
343379};
344380
381+ static const struct platform_device_id axp_pek_id_match [] = {
382+ {
383+ .name = "axp20x-pek" ,
384+ .driver_data = (kernel_ulong_t )& axp20x_info ,
385+ },
386+ { /* sentinel */ }
387+ };
388+
345389static struct platform_driver axp20x_pek_driver = {
346390 .probe = axp20x_pek_probe ,
391+ .id_table = axp_pek_id_match ,
347392 .driver = {
348393 .name = "axp20x-pek" ,
349394 .pm = & axp20x_pek_pm_ops ,
0 commit comments