5
5
6
6
#include <linux/err.h>
7
7
#include <linux/io.h>
8
+ #include <linux/mfd/syscon.h>
8
9
#include <linux/module.h>
9
10
#include <linux/of.h>
10
11
#include <linux/of_device.h>
11
12
#include <linux/pinctrl/pinconf-generic.h>
12
13
#include <linux/pinctrl/pinctrl.h>
13
14
#include <linux/pinctrl/pinmux.h>
14
15
#include <linux/platform_device.h>
16
+ #include <linux/regmap.h>
15
17
#include <linux/slab.h>
16
18
17
19
#define FLAG_BCM4708 BIT(1)
@@ -22,7 +24,8 @@ struct ns_pinctrl {
22
24
struct device * dev ;
23
25
unsigned int chipset_flag ;
24
26
struct pinctrl_dev * pctldev ;
25
- void __iomem * base ;
27
+ struct regmap * regmap ;
28
+ u32 offset ;
26
29
27
30
struct pinctrl_desc pctldesc ;
28
31
struct ns_pinctrl_group * groups ;
@@ -229,9 +232,9 @@ static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev,
229
232
unset |= BIT (pin_number );
230
233
}
231
234
232
- tmp = readl (ns_pinctrl -> base );
235
+ regmap_read (ns_pinctrl -> regmap , ns_pinctrl -> offset , & tmp );
233
236
tmp &= ~unset ;
234
- writel ( tmp , ns_pinctrl -> base );
237
+ regmap_write ( ns_pinctrl -> regmap , ns_pinctrl -> offset , tmp );
235
238
236
239
return 0 ;
237
240
}
@@ -263,13 +266,13 @@ static const struct of_device_id ns_pinctrl_of_match_table[] = {
263
266
static int ns_pinctrl_probe (struct platform_device * pdev )
264
267
{
265
268
struct device * dev = & pdev -> dev ;
269
+ struct device_node * np = dev -> of_node ;
266
270
const struct of_device_id * of_id ;
267
271
struct ns_pinctrl * ns_pinctrl ;
268
272
struct pinctrl_desc * pctldesc ;
269
273
struct pinctrl_pin_desc * pin ;
270
274
struct ns_pinctrl_group * group ;
271
275
struct ns_pinctrl_function * function ;
272
- struct resource * res ;
273
276
int i ;
274
277
275
278
ns_pinctrl = devm_kzalloc (dev , sizeof (* ns_pinctrl ), GFP_KERNEL );
@@ -287,12 +290,18 @@ static int ns_pinctrl_probe(struct platform_device *pdev)
287
290
return - EINVAL ;
288
291
ns_pinctrl -> chipset_flag = (uintptr_t )of_id -> data ;
289
292
290
- res = platform_get_resource_byname (pdev , IORESOURCE_MEM ,
291
- "cru_gpio_control" );
292
- ns_pinctrl -> base = devm_ioremap_resource (dev , res );
293
- if (IS_ERR (ns_pinctrl -> base )) {
294
- dev_err (dev , "Failed to map pinctrl regs\n" );
295
- return PTR_ERR (ns_pinctrl -> base );
293
+ ns_pinctrl -> regmap = syscon_node_to_regmap (of_get_parent (np ));
294
+ if (IS_ERR (ns_pinctrl -> regmap )) {
295
+ int err = PTR_ERR (ns_pinctrl -> regmap );
296
+
297
+ dev_err (dev , "Failed to map pinctrl regs: %d\n" , err );
298
+
299
+ return err ;
300
+ }
301
+
302
+ if (of_property_read_u32 (np , "offset" , & ns_pinctrl -> offset )) {
303
+ dev_err (dev , "Failed to get register offset\n" );
304
+ return - ENOENT ;
296
305
}
297
306
298
307
memcpy (pctldesc , & ns_pinctrl_desc , sizeof (* pctldesc ));
0 commit comments