QE pin multiplexing API
Subsystems (2)
cover QE pin multiplexing API
Hi all,
The API is eveloved from the approach where I tried to put the qe_set_dedicated() function into the GPIO LIB framework, which wasn't good idea after all (see http://lkml.org/lkml/2008/9/24/289).
So here is the new version. Since the patchset touches driver/of/ I need Acks from the OF guys for the first patch. Then I hope Kumar would merge the patchset to the powerpc-next. And after that I could ask Greg KH to merge the FHCI driver itself...
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
PATCH 1/2 OF: new helper: of_parse_phandles_with_args()
The helper is factored out of of_get_gpio(). Will be used by the QE pin multiplexing functions (they need to parse the gpios = <> too).
--- drivers/of/base.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/of/gpio.c | 77 +++++++---------------------------- include/linux/of.h | 3 + 3 files changed, 130 insertions(+), 61 deletions(-)
drivers/of/base.c +111 -0
@@ -473,3 +473,114 @@ int of_modalias_node(struct device_node *node, char *modalias, int len) }EXPORT_SYMBOL_GPL (of_modalias_node); +/** +* of_parse_phandles_with_args - Find a node pointed by phandle in a list +* @np: pointer to a device tree node containing a list +* @list_name: property name that contains a list +* @cells_name: property name that specifies phandles' arguments count +* @index: index of a phandle to parse out +* @out_node: pointer to device_node struct pointer (will be filled) +* @out_args: pointer to arguments pointer (will be filled) +* +* This function is useful to parse lists of phandles and their arguments. +* Returns 0 on success and fills out_node and out_args, on error returns +* appropriate errno value. +* +* Example: +* +* phandle1: node1 { +* #list-cells = <2>; +* } +* +* phandle2: node2 { +* #list-cells = <1>; +* } +* +* node3 { +* list = <&phandle1 1 2 &phandle2 3>; +* } +* +* To get a device_node of the `node2' node you may call this: +* of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args); +*/ +int of_parse_phandles_with_args (struct device_node *np,const char *list_name, +const char *cells_name,int index, +struct device_node **out_node, +const void **out_args) +{ +int ret = -EINVAL ; +const u32 *list; +u32 list_cells; +int size; +int i; +int cur_index =0 ; +struct device_node *node =NULL ; +const void *args; + + list =of_get_property (np, list_name, &size); +if (!list) { + ret = -ENOENT ; + goto err0; + } + list_cells = size /sizeof (u32); + +for (i =0 ; i < list_cells; cur_index++) { +const u32 *cells; +const phandle *phandle; + + phandle = list + i; + args = phandle +1 ; + +/* one cell hole in the list = <>; */ +if (!*phandle) { +if (cur_index == index) +return -ENOENT ; + i++; +continue ; + } + + node =of_find_node_by_phandle (*phandle); +if (!node) { +pr_debug ("%s: could not find phandle\n" , + np->full_name); + goto err0; + } + + cells =of_get_property (node, cells_name, &size); +if (!cells || size !=sizeof (*cells)) { +pr_debug ("%s: could not get %s for %s\n" , + np->full_name, cells_name, node->full_name); + goto err1; + } + +/* Next phandle is at phandle cells + #cells */ + i +=sizeof (*phandle) /sizeof (u32) + *cells; +if (i >= list_cells +1 ) { +pr_debug ("%s: insufficient arguments length\n" , + np->full_name); + goto err1; + } + +if (cur_index == index) +break ; + + node =NULL ; +of_node_put (node); + } + +if (!node) { + ret = -ENOENT ; + goto err0; + } + + *out_node = node; + *out_args = args; + +return 0 ; +err1: +of_node_put (node); +err0: +pr_debug ("%s failed with status %d\n" , __func__, ret); +return ret; +} +EXPORT_SYMBOL (of_parse_phandles_with_args);
drivers/of/gpio.c +17 -62
95 lines not on this page · raw message
include/linux/of.h +3 -0
@@ -71,5 +71,8 @@ extern int of_n_size_cells(struct device_node *np);extern const struct of_device_id *of_match_node (const struct of_device_id *matches,const struct device_node *node);extern int of_modalias_node (struct device_node *node,char *modalias,int len); +extern int of_parse_phandles_with_args (struct device_node *np, +const char *list_name,const char *cells_name,int index, +struct device_node **out_node,const void **out_args);#endif /* _LINUX_OF_H */
Signature · 1 line
1.5.6.3
PATCH 2/2 powerpc/QE: implement QE Pin Multiplexing API
In reply to Anton VorontsovWith this API we're able to set a QE pin to the GPIO mode or a dedicated peripheral function.
The API relies on the fact that QE gpio controllers are registered. If they aren't, the API won't work (gracefully though).
There is one caveat though: if anybody occupied the node->data before us, or overwrote it, then bad things will happen. Luckily this is all in the platform code that we fully control, so this should never happen.
I could implement more checks (for example we could create a list of successfully registered QE controllers, and compare the node->data in the qe_pin_request()), but this is unneeded if nobody is going to do silly things behind our back.
--- arch/powerpc/include/asm/qe.h | 9 ++ arch/powerpc/sysdev/qe_lib/gpio.c | 195 +++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+), 0 deletions(-)
arch/powerpc/include/asm/qe.h +9 -0
@@ -112,6 +112,15 @@ extern int par_io_config_pin(u8 port, u8 pin, int dir, int open_drain, int assignment, int has_irq);extern int par_io_data_set (u8 port,u8 pin,u8 val); +/* +* Pin multiplexing functions. +*/ +struct qe_pin ; +extern struct qe_pin *qe_pin_request (struct device_node *np,int index); +extern void qe_pin_free (struct qe_pin *qe_pin); +extern void qe_pin_set_gpio (struct qe_pin *qe_pin); +extern void qe_pin_set_dedicated (struct qe_pin *pin); +/* QE internal API */ int qe_issue_cmd (u32 cmd,u32 device,u8 mcn_protocol,u32 cmd_input);enum qe_clock qe_clock_source (const char *source);
arch/powerpc/sysdev/qe_lib/gpio.c +195 -0
221 lines not on this page · raw message
Signature · 1 line
1.5.6.3