Skip to content

Commit

Permalink
[xprj] pinctrl driver: add dt-node-to-map API
Browse files Browse the repository at this point in the history
  • Loading branch information
wowo committed Jul 14, 2017
1 parent 52d6b83 commit 7c7b7b9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
16 changes: 16 additions & 0 deletions arch/arm64/boot/dts/actions/s900-bubblegum.dts
Expand Up @@ -39,9 +39,25 @@
clock-frequency = <24000000>;
};

pinctrl@0xe01b0000 {
compatible = "actions,s900-pinctrl";
reg = <0 0xe01b0000 0 0x550>;

uart5_state_default: uart5_default {
pinmux {
function = "uart5";
group = "uart5_0_grp";
};
/* others, TODO */
};
};

serial5: serial@e012a000 {
compatible = "actions,s900-serial";
reg = <0 0xe012a000 0 0x2000>; /* UART5_BASE */
interrupts = <GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>;

pinctrl-names = "default";
pinctrl-0 = <&uart5_state_default>;
};
};
60 changes: 60 additions & 0 deletions drivers/pinctrl/pinctrl-owl.c
Expand Up @@ -19,6 +19,7 @@
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
#include <linux/slab.h>

#include <asm/io.h>

Expand Down Expand Up @@ -159,10 +160,69 @@ static int s900_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
return 0;
}

static int s900_dt_node_to_map(struct pinctrl_dev *pctldev,
struct device_node *np_config,
struct pinctrl_map **map,
unsigned *num_maps)
{
int ret, child_cnt;

const char *function;
const char *group;

struct device *dev = pctldev->dev;
struct device_node *np;

dev_dbg(dev, "%s\n", __func__);

*map = NULL;
*num_maps = 0;

child_cnt = of_get_child_count(np_config);
dev_dbg(dev, "child_cnt %d\n", child_cnt);

if (child_cnt == 0)
return 0;

*map = kzalloc(sizeof(struct pinctrl_map) * child_cnt, GFP_KERNEL);
if (*map == NULL) {
dev_dbg(dev, "malloc failed\n");
return -ENOMEM;
}

for_each_child_of_node(np_config, np) {
ret = of_property_read_string(np, "function", &function);
if (ret != 0)
continue;

ret = of_property_read_string(np, "group", &group);
if (ret != 0)
continue;

dev_dbg(dev, "got a pinmux entry: %s-%s\n", function, group);

(*map)[*num_maps].type = PIN_MAP_TYPE_MUX_GROUP;
(*map)[*num_maps].data.mux.function = function;
(*map)[*num_maps].data.mux.group = group;
(*num_maps)++;
}

return 0;
}
static void s900_dt_free_map(struct pinctrl_dev *pctldev,
struct pinctrl_map *map, unsigned num_maps)
{
/* others, TODO */

kfree(map);
}

static struct pinctrl_ops s900_pctrl_ops = {
.get_groups_count = s900_get_groups_count,
.get_group_name = s900_get_group_name,
.get_group_pins = s900_get_group_pins,
.dt_node_to_map = s900_dt_node_to_map,
.dt_free_map = s900_dt_free_map,
};
/*
* pin groups end
Expand Down

0 comments on commit 7c7b7b9

Please sign in to comment.