···11+* SPEAr ARM Timer22+33+** Timer node required properties:44+55+- compatible : Should be:66+ "st,spear-timer"77+- reg: Address range of the timer registers88+- interrupt-parent: Should be the phandle for the interrupt controller99+ that services interrupts for this device1010+- interrupt: Should contain the timer interrupt number1111+1212+Example:1313+1414+ timer@f0000000 {1515+ compatible = "st,spear-timer";1616+ reg = <0xf0000000 0x400>;1717+ interrupts = <2>;1818+ };
+18
Documentation/devicetree/bindings/arm/spear.txt
···66Required root node property:7788compatible = "st,spear600";99+1010+Boards with the ST SPEAr300 SoC shall have the following properties:1111+1212+Required root node property:1313+1414+compatible = "st,spear300";1515+1616+Boards with the ST SPEAr310 SoC shall have the following properties:1717+1818+Required root node property:1919+2020+compatible = "st,spear310";2121+2222+Boards with the ST SPEAr320 SoC shall have the following properties:2323+2424+Required root node property:2525+2626+compatible = "st,spear320";
···11+* Freescale IOMUX Controller (IOMUXC) for i.MX22+33+The IOMUX Controller (IOMUXC), together with the IOMUX, enables the IC44+to share one PAD to several functional blocks. The sharing is done by55+multiplexing the PAD input/output signals. For each PAD there are up to66+8 muxing options (called ALT modes). Since different modules require77+different PAD settings (like pull up, keeper, etc) the IOMUXC controls88+also the PAD settings parameters.99+1010+Please refer to pinctrl-bindings.txt in this directory for details of the1111+common pinctrl bindings used by client devices, including the meaning of the1212+phrase "pin configuration node".1313+1414+Freescale IMX pin configuration node is a node of a group of pins which can be1515+used for a specific device or function. This node represents both mux and config1616+of the pins in that group. The 'mux' selects the function mode(also named mux1717+mode) this pin can work on and the 'config' configures various pad settings1818+such as pull-up, open drain, drive strength, etc.1919+2020+Required properties for iomux controller:2121+- compatible: "fsl,<soc>-iomuxc"2222+ Please refer to each fsl,<soc>-pinctrl.txt binding doc for supported SoCs.2323+2424+Required properties for pin configuration node:2525+- fsl,pins: two integers array, represents a group of pins mux and config2626+ setting. The format is fsl,pins = <PIN_FUNC_ID CONFIG>, PIN_FUNC_ID is a2727+ pin working on a specific function, CONFIG is the pad setting value like2828+ pull-up on this pin. Please refer to fsl,<soc>-pinctrl.txt for the valid2929+ pins and functions of each SoC.3030+3131+Bits used for CONFIG:3232+NO_PAD_CTL(1 << 31): indicate this pin does not need config.3333+3434+SION(1 << 30): Software Input On Field.3535+Force the selected mux mode input path no matter of MUX_MODE functionality.3636+By default the input path is determined by functionality of the selected3737+mux mode (regular).3838+3939+Other bits are used for PAD setting.4040+Please refer to each fsl,<soc>-pinctrl,txt binding doc for SoC specific part4141+of bits definitions.4242+4343+NOTE:4444+Some requirements for using fsl,imx-pinctrl binding:4545+1. We have pin function node defined under iomux controller node to represent4646+ what pinmux functions this SoC supports.4747+2. The pin configuration node intends to work on a specific function should4848+ to be defined under that specific function node.4949+ The function node's name should represent well about what function5050+ this group of pins in this pin configuration node are working on.5151+3. The driver can use the function node's name and pin configuration node's5252+ name describe the pin function and group hierarchy.5353+ For example, Linux IMX pinctrl driver takes the function node's name5454+ as the function name and pin configuration node's name as group name to5555+ create the map table.5656+4. Each pin configuration node should have a phandle, devices can set pins5757+ configurations by referring to the phandle of that pin configuration node.5858+5959+Examples:6060+usdhc@0219c000 { /* uSDHC4 */6161+ fsl,card-wired;6262+ vmmc-supply = <®_3p3v>;6363+ status = "okay";6464+ pinctrl-names = "default";6565+ pinctrl-0 = <&pinctrl_usdhc4_1>;6666+};6767+6868+iomuxc@020e0000 {6969+ compatible = "fsl,imx6q-iomuxc";7070+ reg = <0x020e0000 0x4000>;7171+7272+ /* shared pinctrl settings */7373+ usdhc4 {7474+ pinctrl_usdhc4_1: usdhc4grp-1 {7575+ fsl,pins = <1386 0x17059 /* MX6Q_PAD_SD4_CMD__USDHC4_CMD */7676+ 1392 0x10059 /* MX6Q_PAD_SD4_CLK__USDHC4_CLK */7777+ 1462 0x17059 /* MX6Q_PAD_SD4_DAT0__USDHC4_DAT0 */7878+ 1470 0x17059 /* MX6Q_PAD_SD4_DAT1__USDHC4_DAT1 */7979+ 1478 0x17059 /* MX6Q_PAD_SD4_DAT2__USDHC4_DAT2 */8080+ 1486 0x17059 /* MX6Q_PAD_SD4_DAT3__USDHC4_DAT3 */8181+ 1493 0x17059 /* MX6Q_PAD_SD4_DAT4__USDHC4_DAT4 */8282+ 1501 0x17059 /* MX6Q_PAD_SD4_DAT5__USDHC4_DAT5 */8383+ 1509 0x17059 /* MX6Q_PAD_SD4_DAT6__USDHC4_DAT6 */8484+ 1517 0x17059>; /* MX6Q_PAD_SD4_DAT7__USDHC4_DAT7 */8585+ };8686+ };8787+ ....8888+};8989+Refer to the IOMUXC controller chapter in imx6q datasheet,9090+0x17059 means enable hysteresis, 47KOhm Pull Up, 50Mhz speed,9191+80Ohm driver strength and Fast Slew Rate.9292+User should refer to each SoC spec to set the correct value.9393+9494+TODO: when dtc macro support is available, we can change above raw data9595+to dt macro which can get better readability in dts file.
···11+NVIDIA Tegra20 pinmux controller22+33+Required properties:44+- compatible: "nvidia,tegra20-pinmux"55+- reg: Should contain the register physical address and length for each of66+ the tri-state, mux, pull-up/down, and pad control register sets.77+88+Please refer to pinctrl-bindings.txt in this directory for details of the99+common pinctrl bindings used by client devices, including the meaning of the1010+phrase "pin configuration node".1111+1212+Tegra's pin configuration nodes act as a container for an abitrary number of1313+subnodes. Each of these subnodes represents some desired configuration for a1414+pin, a group, or a list of pins or groups. This configuration can include the1515+mux function to select on those pin(s)/group(s), and various pin configuration1616+parameters, such as pull-up, tristate, drive strength, etc.1717+1818+The name of each subnode is not important; all subnodes should be enumerated1919+and processed purely based on their content.2020+2121+Each subnode only affects those parameters that are explicitly listed. In2222+other words, a subnode that lists a mux function but no pin configuration2323+parameters implies no information about any pin configuration parameters.2424+Similarly, a pin subnode that describes a pullup parameter implies no2525+information about e.g. the mux function or tristate parameter. For this2626+reason, even seemingly boolean values are actually tristates in this binding:2727+unspecified, off, or on. Unspecified is represented as an absent property,2828+and off/on are represented as integer values 0 and 1.2929+3030+Required subnode-properties:3131+- nvidia,pins : An array of strings. Each string contains the name of a pin or3232+ group. Valid values for these names are listed below.3333+3434+Optional subnode-properties:3535+- nvidia,function: A string containing the name of the function to mux to the3636+ pin or group. Valid values for function names are listed below. See the Tegra3737+ TRM to determine which are valid for each pin or group.3838+- nvidia,pull: Integer, representing the pull-down/up to apply to the pin.3939+ 0: none, 1: down, 2: up.4040+- nvidia,tristate: Integer.4141+ 0: drive, 1: tristate.4242+- nvidia,high-speed-mode: Integer. Enable high speed mode the pins.4343+ 0: no, 1: yes.4444+- nvidia,schmitt: Integer. Enables Schmitt Trigger on the input.4545+ 0: no, 1: yes.4646+- nvidia,low-power-mode: Integer. Valid values 0-3. 0 is least power, 3 is4747+ most power. Controls the drive power or current. See "Low Power Mode"4848+ or "LPMD1" and "LPMD0" in the Tegra TRM.4949+- nvidia,pull-down-strength: Integer. Controls drive strength. 0 is weakest.5050+ The range of valid values depends on the pingroup. See "CAL_DRVDN" in the5151+ Tegra TRM.5252+- nvidia,pull-up-strength: Integer. Controls drive strength. 0 is weakest.5353+ The range of valid values depends on the pingroup. See "CAL_DRVUP" in the5454+ Tegra TRM.5555+- nvidia,slew-rate-rising: Integer. Controls rising signal slew rate. 0 is5656+ fastest. The range of valid values depends on the pingroup. See5757+ "DRVDN_SLWR" in the Tegra TRM.5858+- nvidia,slew-rate-falling: Integer. Controls falling signal slew rate. 0 is5959+ fastest. The range of valid values depends on the pingroup. See6060+ "DRVUP_SLWF" in the Tegra TRM.6161+6262+Note that many of these properties are only valid for certain specific pins6363+or groups. See the Tegra TRM and various pinmux spreadsheets for complete6464+details regarding which groups support which functionality. The Linux pinctrl6565+driver may also be a useful reference, since it consolidates, disambiguates,6666+and corrects data from all those sources.6767+6868+Valid values for pin and group names are:6969+7070+ mux groups:7171+7272+ These all support nvidia,function, nvidia,tristate, and many support7373+ nvidia,pull.7474+7575+ ata, atb, atc, atd, ate, cdev1, cdev2, crtp, csus, dap1, dap2, dap3, dap4,7676+ ddc, dta, dtb, dtc, dtd, dte, dtf, gma, gmb, gmc, gmd, gme, gpu, gpu7,7777+ gpv, hdint, i2cp, irrx, irtx, kbca, kbcb, kbcc, kbcd, kbce, kbcf, lcsn,7878+ ld0, ld1, ld2, ld3, ld4, ld5, ld6, ld7, ld8, ld9, ld10, ld11, ld12, ld13,7979+ ld14, ld15, ld16, ld17, ldc, ldi, lhp0, lhp1, lhp2, lhs, lm0, lm1, lpp,8080+ lpw0, lpw1, lpw2, lsc0, lsc1, lsck, lsda, lsdi, lspi, lvp0, lvp1, lvs,8181+ owc, pmc, pta, rm, sdb, sdc, sdd, sdio1, slxa, slxc, slxd, slxk, spdi,8282+ spdo, spia, spib, spic, spid, spie, spif, spig, spih, uaa, uab, uac, uad,8383+ uca, ucb, uda.8484+8585+ tristate groups:8686+8787+ These only support nvidia,pull.8888+8989+ ck32, ddrc, pmca, pmcb, pmcc, pmcd, pmce, xm2c, xm2d, ls, lc, ld17_0,9090+ ld19_18, ld21_20, ld23_22.9191+9292+ drive groups:9393+9494+ With some exceptions, these support nvidia,high-speed-mode,9595+ nvidia,schmitt, nvidia,low-power-mode, nvidia,pull-down-strength,9696+ nvidia,pull-up-strength, nvidia,slew_rate-rising, nvidia,slew_rate-falling.9797+9898+ drive_ao1, drive_ao2, drive_at1, drive_at2, drive_cdev1, drive_cdev2,9999+ drive_csus, drive_dap1, drive_dap2, drive_dap3, drive_dap4, drive_dbg,100100+ drive_lcd1, drive_lcd2, drive_sdmmc2, drive_sdmmc3, drive_spi, drive_uaa,101101+ drive_uab, drive_uart2, drive_uart3, drive_vi1, drive_vi2, drive_xm2a,102102+ drive_xm2c, drive_xm2d, drive_xm2clk, drive_sdio1, drive_crt, drive_ddc,103103+ drive_gma, drive_gmb, drive_gmc, drive_gmd, drive_gme, drive_owr,104104+ drive_uda.105105+106106+Example:107107+108108+ pinctrl@70000000 {109109+ compatible = "nvidia,tegra20-pinmux";110110+ reg = < 0x70000014 0x10 /* Tri-state registers */111111+ 0x70000080 0x20 /* Mux registers */112112+ 0x700000a0 0x14 /* Pull-up/down registers */113113+ 0x70000868 0xa8 >; /* Pad control registers */114114+ };115115+116116+Example board file extract:117117+118118+ pinctrl@70000000 {119119+ sdio4_default: sdio4_default {120120+ atb {121121+ nvidia,pins = "atb", "gma", "gme";122122+ nvidia,function = "sdio4";123123+ nvidia,pull = <0>;124124+ nvidia,tristate = <0>;125125+ };126126+ };127127+ };128128+129129+ sdhci@c8000600 {130130+ pinctrl-names = "default";131131+ pinctrl-0 = <&sdio4_default>;132132+ };
···11+== Introduction ==22+33+Hardware modules that control pin multiplexing or configuration parameters44+such as pull-up/down, tri-state, drive-strength etc are designated as pin55+controllers. Each pin controller must be represented as a node in device tree,66+just like any other hardware module.77+88+Hardware modules whose signals are affected by pin configuration are99+designated client devices. Again, each client device must be represented as a1010+node in device tree, just like any other hardware module.1111+1212+For a client device to operate correctly, certain pin controllers must1313+set up certain specific pin configurations. Some client devices need a1414+single static pin configuration, e.g. set up during initialization. Others1515+need to reconfigure pins at run-time, for example to tri-state pins when the1616+device is inactive. Hence, each client device can define a set of named1717+states. The number and names of those states is defined by the client device's1818+own binding.1919+2020+The common pinctrl bindings defined in this file provide an infrastructure2121+for client device device tree nodes to map those state names to the pin2222+configuration used by those states.2323+2424+Note that pin controllers themselves may also be client devices of themselves.2525+For example, a pin controller may set up its own "active" state when the2626+driver loads. This would allow representing a board's static pin configuration2727+in a single place, rather than splitting it across multiple client device2828+nodes. The decision to do this or not somewhat rests with the author of2929+individual board device tree files, and any requirements imposed by the3030+bindings for the individual client devices in use by that board, i.e. whether3131+they require certain specific named states for dynamic pin configuration.3232+3333+== Pinctrl client devices ==3434+3535+For each client device individually, every pin state is assigned an integer3636+ID. These numbers start at 0, and are contiguous. For each state ID, a unique3737+property exists to define the pin configuration. Each state may also be3838+assigned a name. When names are used, another property exists to map from3939+those names to the integer IDs.4040+4141+Each client device's own binding determines the set of states the must be4242+defined in its device tree node, and whether to define the set of state4343+IDs that must be provided, or whether to define the set of state names that4444+must be provided.4545+4646+Required properties:4747+pinctrl-0: List of phandles, each pointing at a pin configuration4848+ node. These referenced pin configuration nodes must be child4949+ nodes of the pin controller that they configure. Multiple5050+ entries may exist in this list so that multiple pin5151+ controllers may be configured, or so that a state may be built5252+ from multiple nodes for a single pin controller, each5353+ contributing part of the overall configuration. See the next5454+ section of this document for details of the format of these5555+ pin configuration nodes.5656+5757+ In some cases, it may be useful to define a state, but for it5858+ to be empty. This may be required when a common IP block is5959+ used in an SoC either without a pin controller, or where the6060+ pin controller does not affect the HW module in question. If6161+ the binding for that IP block requires certain pin states to6262+ exist, they must still be defined, but may be left empty.6363+6464+Optional properties:6565+pinctrl-1: List of phandles, each pointing at a pin configuration6666+ node within a pin controller.6767+...6868+pinctrl-n: List of phandles, each pointing at a pin configuration6969+ node within a pin controller.7070+pinctrl-names: The list of names to assign states. List entry 0 defines the7171+ name for integer state ID 0, list entry 1 for state ID 1, and7272+ so on.7373+7474+For example:7575+7676+ /* For a client device requiring named states */7777+ device {7878+ pinctrl-names = "active", "idle";7979+ pinctrl-0 = <&state_0_node_a>;8080+ pinctrl-1 = <&state_1_node_a &state_1_node_b>;8181+ };8282+8383+ /* For the same device if using state IDs */8484+ device {8585+ pinctrl-0 = <&state_0_node_a>;8686+ pinctrl-1 = <&state_1_node_a &state_1_node_b>;8787+ };8888+8989+ /*9090+ * For an IP block whose binding supports pin configuration,9191+ * but in use on an SoC that doesn't have any pin control hardware9292+ */9393+ device {9494+ pinctrl-names = "active", "idle";9595+ pinctrl-0 = <>;9696+ pinctrl-1 = <>;9797+ };9898+9999+== Pin controller devices ==100100+101101+Pin controller devices should contain the pin configuration nodes that client102102+devices reference.103103+104104+For example:105105+106106+ pincontroller {107107+ ... /* Standard DT properties for the device itself elided */108108+109109+ state_0_node_a {110110+ ...111111+ };112112+ state_1_node_a {113113+ ...114114+ };115115+ state_1_node_b {116116+ ...117117+ };118118+ }119119+120120+The contents of each of those pin configuration child nodes is defined121121+entirely by the binding for the individual pin controller device. There122122+exists no common standard for this content.123123+124124+The pin configuration nodes need not be direct children of the pin controller125125+device; they may be grandchildren, for example. Whether this is legal, and126126+whether there is any interaction between the child and intermediate parent127127+nodes, is again defined entirely by the binding for the individual pin128128+controller device.
···152152};153153154154155155-static int foo_list_groups(struct pinctrl_dev *pctldev, unsigned selector)155155+static int foo_get_groups_count(struct pinctrl_dev *pctldev)156156{157157- if (selector >= ARRAY_SIZE(foo_groups))158158- return -EINVAL;159159- return 0;157157+ return ARRAY_SIZE(foo_groups);160158}161159162160static const char *foo_get_group_name(struct pinctrl_dev *pctldev,···173175}174176175177static struct pinctrl_ops foo_pctrl_ops = {176176- .list_groups = foo_list_groups,178178+ .get_groups_count = foo_get_groups_count,177179 .get_group_name = foo_get_group_name,178180 .get_group_pins = foo_get_group_pins,179181};···184186 .pctlops = &foo_pctrl_ops,185187};186188187187-The pin control subsystem will call the .list_groups() function repeatedly188188-beginning on 0 until it returns non-zero to determine legal selectors, then189189-it will call the other functions to retrieve the name and pins of the group.190190-Maintaining the data structure of the groups is up to the driver, this is191191-just a simple example - in practice you may need more entries in your group192192-structure, for example specific register ranges associated with each group193193-and so on.189189+The pin control subsystem will call the .get_groups_count() function to190190+determine total number of legal selectors, then it will call the other functions191191+to retrieve the name and pins of the group. Maintaining the data structure of192192+the groups is up to the driver, this is just a simple example - in practice you193193+may need more entries in your group structure, for example specific register194194+ranges associated with each group and so on.194195195196196197Pin configuration···603606};604607605608606606-static int foo_list_groups(struct pinctrl_dev *pctldev, unsigned selector)609609+static int foo_get_groups_count(struct pinctrl_dev *pctldev)607610{608608- if (selector >= ARRAY_SIZE(foo_groups))609609- return -EINVAL;610610- return 0;611611+ return ARRAY_SIZE(foo_groups);611612}612613613614static const char *foo_get_group_name(struct pinctrl_dev *pctldev,···624629}625630626631static struct pinctrl_ops foo_pctrl_ops = {627627- .list_groups = foo_list_groups,632632+ .get_groups_count = foo_get_groups_count,628633 .get_group_name = foo_get_group_name,629634 .get_group_pins = foo_get_group_pins,630635};···635640 const unsigned num_groups;636641};637642638638-static const char * const spi0_groups[] = { "spi0_1_grp" };643643+static const char * const spi0_groups[] = { "spi0_0_grp", "spi0_1_grp" };639644static const char * const i2c0_groups[] = { "i2c0_grp" };640645static const char * const mmc0_groups[] = { "mmc0_1_grp", "mmc0_2_grp",641646 "mmc0_3_grp" };···658663 },659664};660665661661-int foo_list_funcs(struct pinctrl_dev *pctldev, unsigned selector)666666+int foo_get_functions_count(struct pinctrl_dev *pctldev)662667{663663- if (selector >= ARRAY_SIZE(foo_functions))664664- return -EINVAL;665665- return 0;668668+ return ARRAY_SIZE(foo_functions);666669}667670668671const char *foo_get_fname(struct pinctrl_dev *pctldev, unsigned selector)···696703}697704698705struct pinmux_ops foo_pmxops = {699699- .list_functions = foo_list_funcs,706706+ .get_functions_count = foo_get_functions_count,700707 .get_function_name = foo_get_fname,701708 .get_function_groups = foo_get_groups,702709 .enable = foo_enable,···779786780787#include <linux/pinctrl/machine.h>781788782782-static const struct pinctrl_map __initdata mapping[] = {789789+static const struct pinctrl_map mapping[] __initconst = {783790 {784791 .dev_name = "foo-spi.0",785792 .name = PINCTRL_STATE_DEFAULT,···945952The result of grabbing this mapping from the device with something like946953this (see next paragraph):947954948948- p = pinctrl_get(dev);955955+ p = devm_pinctrl_get(dev);949956 s = pinctrl_lookup_state(p, "8bit");950957 ret = pinctrl_select_state(p, s);951958952959or more simply:953960954954- p = pinctrl_get_select(dev, "8bit");961961+ p = devm_pinctrl_get_select(dev, "8bit");955962956963Will be that you activate all the three bottom records in the mapping at957964once. Since they share the same name, pin controller device, function and···985992 /* Allocate a state holder named "foo" etc */986993 struct foo_state *foo = ...;987994988988- foo->p = pinctrl_get(&device);995995+ foo->p = devm_pinctrl_get(&device);989996 if (IS_ERR(foo->p)) {990997 /* FIXME: clean up "foo" here */991998 return PTR_ERR(foo->p);···99310009941001 foo->s = pinctrl_lookup_state(foo->p, PINCTRL_STATE_DEFAULT);9951002 if (IS_ERR(foo->s)) {996996- pinctrl_put(foo->p);9971003 /* FIXME: clean up "foo" here */9981004 return PTR_ERR(s);9991005 }1000100610011007 ret = pinctrl_select_state(foo->s);10021008 if (ret < 0) {10031003- pinctrl_put(foo->p);10041009 /* FIXME: clean up "foo" here */10051010 return ret;10061011 }10071007-}10081008-10091009-foo_remove()10101010-{10111011- pinctrl_put(state->p);10121012}1013101310141014This get/lookup/select/put sequence can just as well be handled by bus drivers···10151029 kernel memory to hold the pinmux state. All mapping table parsing or similar10161030 slow operations take place within this API.1017103110321032+- devm_pinctrl_get() is a variant of pinctrl_get() that causes pinctrl_put()10331033+ to be called automatically on the retrieved pointer when the associated10341034+ device is removed. It is recommended to use this function over plain10351035+ pinctrl_get().10361036+10181037- pinctrl_lookup_state() is called in process context to obtain a handle to a10191038 specific state for a the client device. This operation may be slow too.10201039···1032104110331042- pinctrl_put() frees all information associated with a pinctrl handle.1034104310441044+- devm_pinctrl_put() is a variant of pinctrl_put() that may be used to10451045+ explicitly destroy a pinctrl object returned by devm_pinctrl_get().10461046+ However, use of this function will be rare, due to the automatic cleanup10471047+ that will occur even without calling it.10481048+10491049+ pinctrl_get() must be paired with a plain pinctrl_put().10501050+ pinctrl_get() may not be paired with devm_pinctrl_put().10511051+ devm_pinctrl_get() can optionally be paired with devm_pinctrl_put().10521052+ devm_pinctrl_get() may not be paired with plain pinctrl_put().10531053+10351054Usually the pin control core handled the get/put pair and call out to the10361055device drivers bookkeeping operations, like checking available functions and10371056the associated pins, whereas the enable/disable pass on to the pin controller10381057driver which takes care of activating and/or deactivating the mux setting by10391058quickly poking some registers.1040105910411041-The pins are allocated for your device when you issue the pinctrl_get() call,10421042-after this you should be able to see this in the debugfs listing of all pins.10601060+The pins are allocated for your device when you issue the devm_pinctrl_get()10611061+call, after this you should be able to see this in the debugfs listing of all10621062+pins.10631063+10641064+NOTE: the pinctrl system will return -EPROBE_DEFER if it cannot find the10651065+requested pinctrl handles, for example if the pinctrl driver has not yet10661066+registered. Thus make sure that the error path in your driver gracefully10671067+cleans up and is ready to retry the probing later in the startup process.104310681044106910451070System pin control hogging···1101109411021095#include <linux/pinctrl/consumer.h>1103109611041104-foo_switch()11051105-{11061106- struct pinctrl *p;11071107- struct pinctrl_state *s1, *s2;10971097+struct pinctrl *p;10981098+struct pinctrl_state *s1, *s2;1108109911001100+foo_probe()11011101+{11091102 /* Setup */11101110- p = pinctrl_get(&device);11031103+ p = devm_pinctrl_get(&device);11111104 if (IS_ERR(p))11121105 ...11131106···11181111 s2 = pinctrl_lookup_state(foo->p, "pos-B");11191112 if (IS_ERR(s2))11201113 ...11141114+}1121111511161116+foo_switch()11171117+{11221118 /* Enable on position A */11231119 ret = pinctrl_select_state(s1);11241120 if (ret < 0)···11351125 ...1136112611371127 ...11381138-11391139- pinctrl_put(p);11401128}1141112911421130The above has to be done from process context.
+8-15
MAINTAINERS
···52425242S: Maintained52435243F: drivers/pinctrl/5244524452455245+PIN CONTROLLER - ST SPEAR52465246+M: Viresh Kumar <viresh.kumar@st.com>52475247+L: spear-devel@list.st.com52485248+L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)52495249+W: http://www.st.com/spear52505250+S: Maintained52515251+F: driver/pinctrl/spear/52525252+52455253PKTCDVD DRIVER52465254M: Peter Osterlund <petero2@telia.com>52475255S: Maintained···63436335W: http://www.st.com/spear63446336S: Maintained63456337F: drivers/clk/spear/63466346-63476347-SPEAR PAD MULTIPLEXING SUPPORT63486348-M: Viresh Kumar <viresh.kumar@st.com>63496349-L: spear-devel@list.st.com63506350-L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)63516351-W: http://www.st.com/spear63526352-S: Maintained63536353-F: arch/arm/plat-spear/include/plat/padmux.h63546354-F: arch/arm/plat-spear/padmux.c63556355-F: arch/arm/mach-spear*/spear*xx.c63566356-F: arch/arm/mach-spear*/include/mach/generic.h63576357-F: arch/arm/mach-spear3xx/spear3*0.c63586358-F: arch/arm/mach-spear3xx/spear3*0_evb.c63596359-F: arch/arm/mach-spear6xx/spear600.c63606360-F: arch/arm/mach-spear6xx/spear600_evb.c6361633863626339SPI SUBSYSTEM63636340M: Grant Likely <grant.likely@secretlab.ca>
+1
arch/arm/Kconfig
···470470 select CLKSRC_MMIO471471 select COMMON_CLK472472 select HAVE_CLK_PREPARE473473+ select PINCTRL473474 help474475 Support for Freescale MXS-based family of processors475476
···22CONFIG_SYSVIPC=y33CONFIG_BSD_PROCESS_ACCT=y44CONFIG_BLK_DEV_INITRD=y55-CONFIG_KALLSYMS_EXTRA_PASS=y65CONFIG_MODULES=y76CONFIG_MODULE_UNLOAD=y87CONFIG_MODVERSIONS=y88+CONFIG_PARTITION_ADVANCED=y99CONFIG_PLAT_SPEAR=y1010-CONFIG_BOARD_SPEAR300_EVB=y1111-CONFIG_BOARD_SPEAR310_EVB=y1212-CONFIG_BOARD_SPEAR320_EVB=y1010+CONFIG_MACH_SPEAR300=y1111+CONFIG_MACH_SPEAR310=y1212+CONFIG_MACH_SPEAR320=y1313CONFIG_BINFMT_MISC=y1414+CONFIG_NET=y1415CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"1616+CONFIG_MTD=y1717+CONFIG_MTD_OF_PARTS=y1818+CONFIG_MTD_CHAR=y1919+CONFIG_MTD_BLOCK=y2020+CONFIG_MTD_NAND=y2121+CONFIG_MTD_NAND_FSMC=y1522CONFIG_BLK_DEV_RAM=y1623CONFIG_BLK_DEV_RAM_SIZE=163842424+CONFIG_NETDEVICES=y2525+# CONFIG_NET_VENDOR_BROADCOM is not set2626+# CONFIG_NET_VENDOR_CIRRUS is not set2727+# CONFIG_NET_VENDOR_FARADAY is not set2828+# CONFIG_NET_VENDOR_INTEL is not set2929+# CONFIG_NET_VENDOR_MICREL is not set3030+# CONFIG_NET_VENDOR_NATSEMI is not set3131+# CONFIG_NET_VENDOR_SEEQ is not set3232+# CONFIG_NET_VENDOR_SMSC is not set3333+CONFIG_STMMAC_ETH=y3434+# CONFIG_WLAN is not set1735CONFIG_INPUT_FF_MEMLESS=y1836# CONFIG_INPUT_MOUSEDEV_PSAUX is not set1919-# CONFIG_INPUT_KEYBOARD is not set3737+# CONFIG_KEYBOARD_ATKBD is not set3838+CONFIG_KEYBOARD_SPEAR=y2039# CONFIG_INPUT_MOUSE is not set4040+# CONFIG_LEGACY_PTYS is not set2141CONFIG_SERIAL_AMBA_PL011=y2242CONFIG_SERIAL_AMBA_PL011_CONSOLE=y2323-# CONFIG_LEGACY_PTYS is not set2443# CONFIG_HW_RANDOM is not set2544CONFIG_RAW_DRIVER=y2645CONFIG_MAX_RAW_DEVS=81924646+CONFIG_I2C=y4747+CONFIG_I2C_DESIGNWARE_PLATFORM=y4848+CONFIG_SPI=y4949+CONFIG_SPI_PL022=y2750CONFIG_GPIO_SYSFS=y2851CONFIG_GPIO_PL061=y2952# CONFIG_HWMON is not set5353+CONFIG_WATCHDOG=y5454+CONFIG_ARM_SP805_WATCHDOG=y5555+CONFIG_FB=y5656+CONFIG_FB_ARMCLCD=y3057# CONFIG_HID_SUPPORT is not set3131-# CONFIG_USB_SUPPORT is not set5858+CONFIG_USB=y5959+# CONFIG_USB_DEVICE_CLASS is not set6060+CONFIG_USB_EHCI_HCD=y6161+CONFIG_USB_OHCI_HCD=y6262+CONFIG_MMC=y6363+CONFIG_MMC_SDHCI=y6464+CONFIG_MMC_SDHCI_SPEAR=y6565+CONFIG_RTC_CLASS=y6666+CONFIG_DMADEVICES=y6767+CONFIG_AMBA_PL08X=y6868+CONFIG_DMATEST=m3269CONFIG_EXT2_FS=y3370CONFIG_EXT2_FS_XATTR=y3471CONFIG_EXT2_FS_SECURITY=y···7639CONFIG_VFAT_FS=m7740CONFIG_FAT_DEFAULT_IOCHARSET="ascii"7841CONFIG_TMPFS=y7979-CONFIG_PARTITION_ADVANCED=y8080-CONFIG_NLS=y4242+CONFIG_JFFS2_FS=y8143CONFIG_NLS_DEFAULT="utf8"8244CONFIG_NLS_CODEPAGE_437=y8345CONFIG_NLS_ASCII=m···8448CONFIG_DEBUG_FS=y8549CONFIG_DEBUG_KERNEL=y8650CONFIG_DEBUG_SPINLOCK=y8787-CONFIG_DEBUG_SPINLOCK_SLEEP=y8851CONFIG_DEBUG_INFO=y8989-# CONFIG_CRC32 is not set
+36-8
arch/arm/configs/spear6xx_defconfig
···22CONFIG_SYSVIPC=y33CONFIG_BSD_PROCESS_ACCT=y44CONFIG_BLK_DEV_INITRD=y55-CONFIG_KALLSYMS_EXTRA_PASS=y65CONFIG_MODULES=y76CONFIG_MODULE_UNLOAD=y87CONFIG_MODVERSIONS=y88+CONFIG_PARTITION_ADVANCED=y99CONFIG_PLAT_SPEAR=y1010CONFIG_ARCH_SPEAR6XX=y1111-CONFIG_BOARD_SPEAR600_EVB=y1211CONFIG_BINFMT_MISC=y1212+CONFIG_NET=y1313CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"1414+CONFIG_MTD=y1515+CONFIG_MTD_OF_PARTS=y1616+CONFIG_MTD_CHAR=y1717+CONFIG_MTD_BLOCK=y1818+CONFIG_MTD_NAND=y1919+CONFIG_MTD_NAND_FSMC=y1420CONFIG_BLK_DEV_RAM=y1521CONFIG_BLK_DEV_RAM_SIZE=163842222+CONFIG_NETDEVICES=y2323+# CONFIG_NET_VENDOR_BROADCOM is not set2424+# CONFIG_NET_VENDOR_CIRRUS is not set2525+# CONFIG_NET_VENDOR_FARADAY is not set2626+# CONFIG_NET_VENDOR_INTEL is not set2727+# CONFIG_NET_VENDOR_MICREL is not set2828+# CONFIG_NET_VENDOR_NATSEMI is not set2929+# CONFIG_NET_VENDOR_SEEQ is not set3030+# CONFIG_NET_VENDOR_SMSC is not set3131+CONFIG_STMMAC_ETH=y3232+# CONFIG_WLAN is not set1633CONFIG_INPUT_FF_MEMLESS=y1734# CONFIG_INPUT_MOUSEDEV_PSAUX is not set3535+# CONFIG_INPUT_KEYBOARD is not set3636+# CONFIG_INPUT_MOUSE is not set3737+# CONFIG_LEGACY_PTYS is not set1838CONFIG_SERIAL_AMBA_PL011=y1939CONFIG_SERIAL_AMBA_PL011_CONSOLE=y2020-# CONFIG_LEGACY_PTYS is not set2140CONFIG_RAW_DRIVER=y2241CONFIG_MAX_RAW_DEVS=81924242+CONFIG_I2C=y4343+CONFIG_I2C_DESIGNWARE_PLATFORM=y4444+CONFIG_SPI=y4545+CONFIG_SPI_PL022=y2346CONFIG_GPIO_SYSFS=y2447CONFIG_GPIO_PL061=y2548# CONFIG_HWMON is not set4949+CONFIG_WATCHDOG=y5050+CONFIG_ARM_SP805_WATCHDOG=y2651# CONFIG_HID_SUPPORT is not set2727-# CONFIG_USB_SUPPORT is not set5252+CONFIG_USB=y5353+CONFIG_USB_EHCI_HCD=y5454+CONFIG_USB_OHCI_HCD=y5555+CONFIG_RTC_CLASS=y5656+CONFIG_DMADEVICES=y5757+CONFIG_AMBA_PL08X=y5858+CONFIG_DMATEST=m2859CONFIG_EXT2_FS=y2960CONFIG_EXT2_FS_XATTR=y3061CONFIG_EXT2_FS_SECURITY=y···6635CONFIG_VFAT_FS=m6736CONFIG_FAT_DEFAULT_IOCHARSET="ascii"6837CONFIG_TMPFS=y6969-CONFIG_PARTITION_ADVANCED=y7070-CONFIG_NLS=y3838+CONFIG_JFFS2_FS=y7139CONFIG_NLS_DEFAULT="utf8"7240CONFIG_NLS_CODEPAGE_437=y7341CONFIG_NLS_ASCII=m···7444CONFIG_DEBUG_FS=y7545CONFIG_DEBUG_KERNEL=y7646CONFIG_DEBUG_SPINLOCK=y7777-CONFIG_DEBUG_SPINLOCK_SLEEP=y7847CONFIG_DEBUG_INFO=y7979-# CONFIG_CRC32 is not set
···1919#include <linux/of_address.h>2020#include <linux/of_irq.h>2121#include <linux/of_platform.h>2222+#include <linux/pinctrl/machine.h>2223#include <linux/phy.h>2324#include <linux/micrel_phy.h>2425#include <asm/smp_twd.h>···78777978static void __init imx6q_init_machine(void)8079{8080+ /*8181+ * This should be removed when all imx6q boards have pinctrl8282+ * states for devices defined in device tree.8383+ */8484+ pinctrl_provide_dummies();8585+8186 if (of_machine_is_compatible("fsl,imx6q-sabrelite"))8287 phy_register_fixup_for_uid(PHY_ID_KSZ9021, MICREL_PHY_ID_MASK,8388 ksz9021rn_phy_fixup);
···1717extern void mxs_restart(char, const char *);1818extern int mxs_saif_clkmux_select(unsigned int clkmux);19192020+extern void mx23_soc_init(void);2021extern int mx23_register_gpios(void);2122extern int mx23_clocks_init(void);2223extern void mx23_map_io(void);2324extern void mx23_init_irq(void);24252626+extern void mx28_soc_init(void);2527extern int mx28_register_gpios(void);2628extern int mx28_clocks_init(void);2729extern void mx28_map_io(void);
···11-/*22- * arch/arm/mach-spear3xx/include/mach/hardware.h33- *44- * Hardware definitions for SPEAr3xx machine family55- *66- * Copyright (C) 2009 ST Microelectronics77- * Viresh Kumar<viresh.kumar@st.com>88- *99- * This file is licensed under the terms of the GNU General Public1010- * License version 2. This program is licensed "as is" without any1111- * warranty of any kind, whether express or implied.1212- */1313-1414-#ifndef __MACH_HARDWARE_H1515-#define __MACH_HARDWARE_H1616-1717-#include <plat/hardware.h>1818-#include <mach/spear.h>1919-2020-/* Vitual to physical translation of statically mapped space */2121-#define IO_ADDRESS(x) (x | 0xF0000000)2222-2323-#endif /* __MACH_HARDWARE_H */11+/* empty */
···1515#define __MACH_GENERIC_H16161717#include <linux/init.h>1818-#include <linux/platform_device.h>1919-#include <linux/amba/bus.h>2020-#include <asm/mach/time.h>2121-#include <asm/mach/map.h>22182323-/*2424- * Each GPT has 2 timer channels2525- * Following GPT channels will be used as clock source and clockevent2626- */2727-#define SPEAR_GPT0_BASE SPEAR6XX_CPU_TMR_BASE2828-#define SPEAR_GPT0_CHAN0_IRQ IRQ_CPU_GPT1_12929-#define SPEAR_GPT0_CHAN1_IRQ IRQ_CPU_GPT1_23030-3131-/* Add spear6xx family device structure declarations here */3232-extern struct amba_device gpio_device[];3333-extern struct amba_device uart_device[];3434-extern struct sys_timer spear6xx_timer;3535-3636-/* Add spear6xx family function declarations here */3737-void __init spear_setup_timer(void);3838-void __init spear6xx_map_io(void);3939-void __init spear6xx_init_irq(void);4040-void __init spear6xx_init(void);4141-void __init spear600_init(void);4242-void __init spear6xx_clk_init(void);4343-1919+void __init spear_setup_of_timer(void);4420void spear_restart(char, const char *);4545-4646-/* Add spear600 machine device structure declarations here */2121+void __init spear6xx_clk_init(void);47224823#endif /* __MACH_GENERIC_H */
+1-23
arch/arm/mach-spear6xx/include/mach/hardware.h
···11-/*22- * arch/arm/mach-spear6xx/include/mach/hardware.h33- *44- * Hardware definitions for SPEAr6xx machine family55- *66- * Copyright (C) 2009 ST Microelectronics77- * Rajeev Kumar<rajeev-dlh.kumar@st.com>88- *99- * This file is licensed under the terms of the GNU General Public1010- * License version 2. This program is licensed "as is" without any1111- * warranty of any kind, whether express or implied.1212- */1313-1414-#ifndef __MACH_HARDWARE_H1515-#define __MACH_HARDWARE_H1616-1717-#include <plat/hardware.h>1818-#include <mach/spear.h>1919-2020-/* Vitual to physical translation of statically mapped space */2121-#define IO_ADDRESS(x) (x | 0xF0000000)2222-2323-#endif /* __MACH_HARDWARE_H */11+/* empty */
···11-/*22- * arch/arm/mach-spear66xx/include/mach/spear600.h33- *44- * SPEAr600 Machine specific definition55- *66- * Copyright (C) 2009 ST Microelectronics77- * Viresh Kumar<viresh.kumar@st.com>88- *99- * This file is licensed under the terms of the GNU General Public1010- * License version 2. This program is licensed "as is" without any1111- * warranty of any kind, whether express or implied.1212- */1313-1414-#ifdef CONFIG_MACH_SPEAR6001515-1616-#ifndef __MACH_SPEAR600_H1717-#define __MACH_SPEAR600_H1818-1919-#endif /* __MACH_SPEAR600_H */2020-2121-#endif /* CONFIG_MACH_SPEAR600 */
···11-/*22- * arch/arm/plat-spear/include/plat/hardware.h33- *44- * Hardware definitions for SPEAr55- *66- * Copyright (C) 2010 ST Microelectronics77- * Viresh Kumar<viresh.kumar@st.com>88- *99- * This file is licensed under the terms of the GNU General Public1010- * License version 2. This program is licensed "as is" without any1111- * warranty of any kind, whether express or implied.1212- */1313-1414-#ifndef __PLAT_HARDWARE_H1515-#define __PLAT_HARDWARE_H1616-1717-#endif /* __PLAT_HARDWARE_H */
-92
arch/arm/plat-spear/include/plat/padmux.h
···11-/*22- * arch/arm/plat-spear/include/plat/padmux.h33- *44- * SPEAr platform specific gpio pads muxing file55- *66- * Copyright (C) 2009 ST Microelectronics77- * Viresh Kumar<viresh.kumar@st.com>88- *99- * This file is licensed under the terms of the GNU General Public1010- * License version 2. This program is licensed "as is" without any1111- * warranty of any kind, whether express or implied.1212- */1313-1414-#ifndef __PLAT_PADMUX_H1515-#define __PLAT_PADMUX_H1616-1717-#include <linux/types.h>1818-1919-/*2020- * struct pmx_reg: configuration structure for mode reg and mux reg2121- *2222- * offset: offset of mode reg2323- * mask: mask of mode reg2424- */2525-struct pmx_reg {2626- u32 offset;2727- u32 mask;2828-};2929-3030-/*3131- * struct pmx_dev_mode: configuration structure every group of modes of a device3232- *3333- * ids: all modes for this configuration3434- * mask: mask for supported mode3535- */3636-struct pmx_dev_mode {3737- u32 ids;3838- u32 mask;3939-};4040-4141-/*4242- * struct pmx_mode: mode definition structure4343- *4444- * name: mode name4545- * mask: mode mask4646- */4747-struct pmx_mode {4848- char *name;4949- u32 id;5050- u32 mask;5151-};5252-5353-/*5454- * struct pmx_dev: device definition structure5555- *5656- * name: device name5757- * modes: device configuration array for different modes supported5858- * mode_count: size of modes array5959- * is_active: is peripheral active/enabled6060- * enb_on_reset: if 1, mask bits to be cleared in reg otherwise to be set in reg6161- */6262-struct pmx_dev {6363- char *name;6464- struct pmx_dev_mode *modes;6565- u8 mode_count;6666- bool is_active;6767- bool enb_on_reset;6868-};6969-7070-/*7171- * struct pmx_driver: driver definition structure7272- *7373- * mode: mode to be set7474- * devs: array of pointer to pmx devices7575- * devs_count: ARRAY_SIZE of devs7676- * base: base address of soc config registers7777- * mode_reg: structure of mode config register7878- * mux_reg: structure of device mux config register7979- */8080-struct pmx_driver {8181- struct pmx_mode *mode;8282- struct pmx_dev **devs;8383- u8 devs_count;8484- u32 *base;8585- struct pmx_reg mode_reg;8686- struct pmx_reg mux_reg;8787-};8888-8989-/* pmx functions */9090-int pmx_register(struct pmx_driver *driver);9191-9292-#endif /* __PLAT_PADMUX_H */
+21
arch/arm/plat-spear/include/plat/pl080.h
···11+/*22+ * arch/arm/plat-spear/include/plat/pl080.h33+ *44+ * DMAC pl080 definitions for SPEAr platform55+ *66+ * Copyright (C) 2012 ST Microelectronics77+ * Viresh Kumar <viresh.kumar@st.com>88+ *99+ * This file is licensed under the terms of the GNU General Public1010+ * License version 2. This program is licensed "as is" without any1111+ * warranty of any kind, whether express or implied.1212+ */1313+1414+#ifndef __PLAT_PL080_H1515+#define __PLAT_PL080_H1616+1717+struct pl08x_dma_chan;1818+int pl080_get_signal(struct pl08x_dma_chan *ch);1919+void pl080_put_signal(struct pl08x_dma_chan *ch);2020+2121+#endif /* __PLAT_PL080_H */
···11-/*22- * arch/arm/plat-spear/include/plat/padmux.c33- *44- * SPEAr platform specific gpio pads muxing source file55- *66- * Copyright (C) 2009 ST Microelectronics77- * Viresh Kumar<viresh.kumar@st.com>88- *99- * This file is licensed under the terms of the GNU General Public1010- * License version 2. This program is licensed "as is" without any1111- * warranty of any kind, whether express or implied.1212- */1313-1414-#include <linux/err.h>1515-#include <linux/io.h>1616-#include <linux/slab.h>1717-#include <plat/padmux.h>1818-1919-/*2020- * struct pmx: pmx definition structure2121- *2222- * base: base address of configuration registers2323- * mode_reg: mode configurations2424- * mux_reg: muxing configurations2525- * active_mode: pointer to current active mode2626- */2727-struct pmx {2828- u32 base;2929- struct pmx_reg mode_reg;3030- struct pmx_reg mux_reg;3131- struct pmx_mode *active_mode;3232-};3333-3434-static struct pmx *pmx;3535-3636-/**3737- * pmx_mode_set - Enables an multiplexing mode3838- * @mode - pointer to pmx mode3939- *4040- * It will set mode of operation in hardware.4141- * Returns -ve on Err otherwise 04242- */4343-static int pmx_mode_set(struct pmx_mode *mode)4444-{4545- u32 val;4646-4747- if (!mode->name)4848- return -EFAULT;4949-5050- pmx->active_mode = mode;5151-5252- val = readl(pmx->base + pmx->mode_reg.offset);5353- val &= ~pmx->mode_reg.mask;5454- val |= mode->mask & pmx->mode_reg.mask;5555- writel(val, pmx->base + pmx->mode_reg.offset);5656-5757- return 0;5858-}5959-6060-/**6161- * pmx_devs_enable - Enables list of devices6262- * @devs - pointer to pmx device array6363- * @count - number of devices to enable6464- *6565- * It will enable pads for all required peripherals once and only once.6666- * If peripheral is not supported by current mode then request is rejected.6767- * Conflicts between peripherals are not handled and peripherals will be6868- * enabled in the order they are present in pmx_dev array.6969- * In case of conflicts last peripheral enabled will be present.7070- * Returns -ve on Err otherwise 07171- */7272-static int pmx_devs_enable(struct pmx_dev **devs, u8 count)7373-{7474- u32 val, i, mask;7575-7676- if (!count)7777- return -EINVAL;7878-7979- val = readl(pmx->base + pmx->mux_reg.offset);8080- for (i = 0; i < count; i++) {8181- u8 j = 0;8282-8383- if (!devs[i]->name || !devs[i]->modes) {8484- printk(KERN_ERR "padmux: dev name or modes is null\n");8585- continue;8686- }8787- /* check if peripheral exists in active mode */8888- if (pmx->active_mode) {8989- bool found = false;9090- for (j = 0; j < devs[i]->mode_count; j++) {9191- if (devs[i]->modes[j].ids &9292- pmx->active_mode->id) {9393- found = true;9494- break;9595- }9696- }9797- if (found == false) {9898- printk(KERN_ERR "%s device not available in %s"\9999- "mode\n", devs[i]->name,100100- pmx->active_mode->name);101101- continue;102102- }103103- }104104-105105- /* enable peripheral */106106- mask = devs[i]->modes[j].mask & pmx->mux_reg.mask;107107- if (devs[i]->enb_on_reset)108108- val &= ~mask;109109- else110110- val |= mask;111111-112112- devs[i]->is_active = true;113113- }114114- writel(val, pmx->base + pmx->mux_reg.offset);115115- kfree(pmx);116116-117117- /* this will ensure that multiplexing can't be changed now */118118- pmx = (struct pmx *)-1;119119-120120- return 0;121121-}122122-123123-/**124124- * pmx_register - registers a platform requesting pad mux feature125125- * @driver - pointer to driver structure containing driver specific parameters126126- *127127- * Also this must be called only once. This will allocate memory for pmx128128- * structure, will call pmx_mode_set, will call pmx_devs_enable.129129- * Returns -ve on Err otherwise 0130130- */131131-int pmx_register(struct pmx_driver *driver)132132-{133133- int ret = 0;134134-135135- if (pmx)136136- return -EPERM;137137- if (!driver->base || !driver->devs)138138- return -EFAULT;139139-140140- pmx = kzalloc(sizeof(*pmx), GFP_KERNEL);141141- if (!pmx)142142- return -ENOMEM;143143-144144- pmx->base = (u32)driver->base;145145- pmx->mode_reg.offset = driver->mode_reg.offset;146146- pmx->mode_reg.mask = driver->mode_reg.mask;147147- pmx->mux_reg.offset = driver->mux_reg.offset;148148- pmx->mux_reg.mask = driver->mux_reg.mask;149149-150150- /* choose mode to enable */151151- if (driver->mode) {152152- ret = pmx_mode_set(driver->mode);153153- if (ret)154154- goto pmx_fail;155155- }156156- ret = pmx_devs_enable(driver->devs, driver->devs_count);157157- if (ret)158158- goto pmx_fail;159159-160160- return 0;161161-162162-pmx_fail:163163- return ret;164164-}
+80
arch/arm/plat-spear/pl080.c
···11+/*22+ * arch/arm/plat-spear/pl080.c33+ *44+ * DMAC pl080 definitions for SPEAr platform55+ *66+ * Copyright (C) 2012 ST Microelectronics77+ * Viresh Kumar <viresh.kumar@st.com>88+ *99+ * This file is licensed under the terms of the GNU General Public1010+ * License version 2. This program is licensed "as is" without any1111+ * warranty of any kind, whether express or implied.1212+ */1313+1414+#include <linux/amba/pl08x.h>1515+#include <linux/amba/bus.h>1616+#include <linux/bug.h>1717+#include <linux/err.h>1818+#include <linux/io.h>1919+#include <linux/spinlock_types.h>2020+#include <mach/spear.h>2121+#include <mach/misc_regs.h>2222+2323+static spinlock_t lock = __SPIN_LOCK_UNLOCKED(x);2424+2525+struct {2626+ unsigned char busy;2727+ unsigned char val;2828+} signals[16] = {{0, 0}, };2929+3030+int pl080_get_signal(struct pl08x_dma_chan *ch)3131+{3232+ const struct pl08x_channel_data *cd = ch->cd;3333+ unsigned int signal = cd->min_signal, val;3434+ unsigned long flags;3535+3636+ spin_lock_irqsave(&lock, flags);3737+3838+ /* Return if signal is already acquired by somebody else */3939+ if (signals[signal].busy &&4040+ (signals[signal].val != cd->muxval)) {4141+ spin_unlock_irqrestore(&lock, flags);4242+ return -EBUSY;4343+ }4444+4545+ /* If acquiring for the first time, configure it */4646+ if (!signals[signal].busy) {4747+ val = readl(DMA_CHN_CFG);4848+4949+ /*5050+ * Each request line has two bits in DMA_CHN_CFG register. To5151+ * goto the bits of current request line, do left shift of5252+ * value by 2 * signal number.5353+ */5454+ val &= ~(0x3 << (signal * 2));5555+ val |= cd->muxval << (signal * 2);5656+ writel(val, DMA_CHN_CFG);5757+ }5858+5959+ signals[signal].busy++;6060+ signals[signal].val = cd->muxval;6161+ spin_unlock_irqrestore(&lock, flags);6262+6363+ return signal;6464+}6565+6666+void pl080_put_signal(struct pl08x_dma_chan *ch)6767+{6868+ const struct pl08x_channel_data *cd = ch->cd;6969+ unsigned long flags;7070+7171+ spin_lock_irqsave(&lock, flags);7272+7373+ /* if signal is not used */7474+ if (!signals[cd->min_signal].busy)7575+ BUG();7676+7777+ signals[cd->min_signal].busy--;7878+7979+ spin_unlock_irqrestore(&lock, flags);8080+}
···4455config PINCTRL66 bool77- depends on EXPERIMENTAL8798if PINCTRL109···2627 help2728 Say Y here to add some extra checks and diagnostics to PINCTRL calls.28293030+config PINCTRL_IMX3131+ bool3232+ select PINMUX3333+ select PINCONF3434+3535+config PINCTRL_IMX6Q3636+ bool "IMX6Q pinctrl driver"3737+ depends on OF3838+ depends on SOC_IMX6Q3939+ select PINCTRL_IMX4040+ help4141+ Say Y here to enable the imx6q pinctrl driver4242+2943config PINCTRL_PXA3xx3044 bool3145 select PINMUX···4836 depends on ARCH_MMP4937 select PINCTRL_PXA3xx5038 select PINCONF3939+4040+config PINCTRL_MXS4141+ bool4242+4343+config PINCTRL_IMX234444+ bool4545+ select PINMUX4646+ select PINCONF4747+ select PINCTRL_MXS4848+4949+config PINCTRL_IMX285050+ bool5151+ select PINMUX5252+ select PINCONF5353+ select PINCTRL_MXS51545255config PINCTRL_PXA1685356 bool "PXA168 pin controller driver"···11083 The names of the two IP block variants supported are11184 COH 901 335 and COH 901 571/3. They contain 3, 5 or 711285 ports of 8 GPIO pins each.8686+8787+source "drivers/pinctrl/spear/Kconfig"1138811489endmenu11590
···2323#include <linux/sysfs.h>2424#include <linux/debugfs.h>2525#include <linux/seq_file.h>2626+#include <linux/pinctrl/consumer.h>2627#include <linux/pinctrl/pinctrl.h>2728#include <linux/pinctrl/machine.h>2829#include "core.h"3030+#include "devicetree.h"2931#include "pinmux.h"3032#include "pinconf.h"3133···4341 unsigned num_maps;4442};45434444+static bool pinctrl_dummy_state;4545+4646/* Mutex taken by all entry points */4747DEFINE_MUTEX(pinctrl_mutex);48484949/* Global list of pin control devices (struct pinctrl_dev) */5050-static LIST_HEAD(pinctrldev_list);5050+LIST_HEAD(pinctrldev_list);51515252/* List of pin controller handles (struct pinctrl) */5353static LIST_HEAD(pinctrl_list);···6258 for (_i_ = 0, _map_ = &_maps_node_->maps[_i_]; \6359 _i_ < _maps_node_->num_maps; \6460 i++, _map_ = &_maps_node_->maps[_i_])6161+6262+/**6363+ * pinctrl_provide_dummies() - indicate if pinctrl provides dummy state support6464+ *6565+ * Usually this function is called by platforms without pinctrl driver support6666+ * but run with some shared drivers using pinctrl APIs.6767+ * After calling this function, the pinctrl core will return successfully6868+ * with creating a dummy state for the driver to keep going smoothly.6969+ */7070+void pinctrl_provide_dummies(void)7171+{7272+ pinctrl_dummy_state = true;7373+}65746675const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev)6776{···138121 }139122140123 return -EINVAL;124124+}125125+126126+/**127127+ * pin_get_name_from_id() - look up a pin name from a pin id128128+ * @pctldev: the pin control device to lookup the pin on129129+ * @name: the name of the pin to look up130130+ */131131+const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin)132132+{133133+ const struct pin_desc *desc;134134+135135+ desc = pin_desc_get(pctldev, pin);136136+ if (desc == NULL) {137137+ dev_err(pctldev->dev, "failed to get pin(%d) name\n",138138+ pin);139139+ return NULL;140140+ }141141+142142+ return desc->name;141143}142144143145/**···291255 *292256 * Find the pin controller handling a certain GPIO pin from the pinspace of293257 * the GPIO subsystem, return the device and the matching GPIO range. Returns294294- * negative if the GPIO range could not be found in any device.258258+ * -EPROBE_DEFER if the GPIO range could not be found in any device since it259259+ * may still have not been registered.295260 */296261static int pinctrl_get_device_gpio_range(unsigned gpio,297262 struct pinctrl_dev **outdev,···312275 }313276 }314277315315- return -EINVAL;278278+ return -EPROBE_DEFER;316279}317280318281/**···355318 const char *pin_group)356319{357320 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;321321+ unsigned ngroups = pctlops->get_groups_count(pctldev);358322 unsigned group_selector = 0;359323360360- while (pctlops->list_groups(pctldev, group_selector) >= 0) {324324+ while (group_selector < ngroups) {361325 const char *gname = pctlops->get_group_name(pctldev,362326 group_selector);363327 if (!strcmp(gname, pin_group)) {···398360 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);399361 if (ret) {400362 mutex_unlock(&pinctrl_mutex);401401- return -EINVAL;363363+ return ret;402364 }403365404366 /* Convert to the pin controllers number space */···554516555517 setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);556518 if (setting->pctldev == NULL) {557557- dev_err(p->dev, "unknown pinctrl device %s in map entry",519519+ dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe",558520 map->ctrl_dev_name);559521 kfree(setting);560560- /* Eventually, this should trigger deferred probe */561561- return -ENODEV;522522+ /*523523+ * OK let us guess that the driver is not there yet, and524524+ * let's defer obtaining this pinctrl handle to later...525525+ */526526+ return -EPROBE_DEFER;562527 }563528564529 switch (map->type) {···620579 }621580 p->dev = dev;622581 INIT_LIST_HEAD(&p->states);582582+ INIT_LIST_HEAD(&p->dt_maps);583583+584584+ ret = pinctrl_dt_to_map(p);585585+ if (ret < 0) {586586+ kfree(p);587587+ return ERR_PTR(ret);588588+ }623589624590 devname = dev_name(dev);625591···710662 kfree(state);711663 }712664665665+ pinctrl_dt_free_maps(p);666666+713667 if (inlist)714668 list_del(&p->node);715669 kfree(p);···735685 struct pinctrl_state *state;736686737687 state = find_state(p, name);738738- if (!state)739739- return ERR_PTR(-ENODEV);688688+ if (!state) {689689+ if (pinctrl_dummy_state) {690690+ /* create dummy state */691691+ dev_dbg(p->dev, "using pinctrl dummy state (%s)\n",692692+ name);693693+ state = create_state(p, name);694694+ if (IS_ERR(state))695695+ return state;696696+ } else {697697+ return ERR_PTR(-ENODEV);698698+ }699699+ }740700741701 return state;742702}···847787}848788EXPORT_SYMBOL_GPL(pinctrl_select_state);849789790790+static void devm_pinctrl_release(struct device *dev, void *res)791791+{792792+ pinctrl_put(*(struct pinctrl **)res);793793+}794794+850795/**851851- * pinctrl_register_mappings() - register a set of pin controller mappings852852- * @maps: the pincontrol mappings table to register. This should probably be853853- * marked with __initdata so it can be discarded after boot. This854854- * function will perform a shallow copy for the mapping entries.855855- * @num_maps: the number of maps in the mapping table796796+ * struct devm_pinctrl_get() - Resource managed pinctrl_get()797797+ * @dev: the device to obtain the handle for798798+ *799799+ * If there is a need to explicitly destroy the returned struct pinctrl,800800+ * devm_pinctrl_put() should be used, rather than plain pinctrl_put().856801 */857857-int pinctrl_register_mappings(struct pinctrl_map const *maps,858858- unsigned num_maps)802802+struct pinctrl *devm_pinctrl_get(struct device *dev)803803+{804804+ struct pinctrl **ptr, *p;805805+806806+ ptr = devres_alloc(devm_pinctrl_release, sizeof(*ptr), GFP_KERNEL);807807+ if (!ptr)808808+ return ERR_PTR(-ENOMEM);809809+810810+ p = pinctrl_get(dev);811811+ if (!IS_ERR(p)) {812812+ *ptr = p;813813+ devres_add(dev, ptr);814814+ } else {815815+ devres_free(ptr);816816+ }817817+818818+ return p;819819+}820820+EXPORT_SYMBOL_GPL(devm_pinctrl_get);821821+822822+static int devm_pinctrl_match(struct device *dev, void *res, void *data)823823+{824824+ struct pinctrl **p = res;825825+826826+ return *p == data;827827+}828828+829829+/**830830+ * devm_pinctrl_put() - Resource managed pinctrl_put()831831+ * @p: the pinctrl handle to release832832+ *833833+ * Deallocate a struct pinctrl obtained via devm_pinctrl_get(). Normally834834+ * this function will not need to be called and the resource management835835+ * code will ensure that the resource is freed.836836+ */837837+void devm_pinctrl_put(struct pinctrl *p)838838+{839839+ WARN_ON(devres_destroy(p->dev, devm_pinctrl_release,840840+ devm_pinctrl_match, p));841841+ pinctrl_put(p);842842+}843843+EXPORT_SYMBOL_GPL(devm_pinctrl_put);844844+845845+int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,846846+ bool dup, bool locked)859847{860848 int i, ret;861849 struct pinctrl_maps *maps_node;···937829 case PIN_MAP_TYPE_MUX_GROUP:938830 ret = pinmux_validate_map(&maps[i], i);939831 if (ret < 0)940940- return 0;832832+ return ret;941833 break;942834 case PIN_MAP_TYPE_CONFIGS_PIN:943835 case PIN_MAP_TYPE_CONFIGS_GROUP:944836 ret = pinconf_validate_map(&maps[i], i);945837 if (ret < 0)946946- return 0;838838+ return ret;947839 break;948840 default:949841 pr_err("failed to register map %s (%d): invalid type given\n",···959851 }960852961853 maps_node->num_maps = num_maps;962962- maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, GFP_KERNEL);963963- if (!maps_node->maps) {964964- pr_err("failed to duplicate mapping table\n");965965- kfree(maps_node);966966- return -ENOMEM;854854+ if (dup) {855855+ maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps,856856+ GFP_KERNEL);857857+ if (!maps_node->maps) {858858+ pr_err("failed to duplicate mapping table\n");859859+ kfree(maps_node);860860+ return -ENOMEM;861861+ }862862+ } else {863863+ maps_node->maps = maps;967864 }968865969969- mutex_lock(&pinctrl_mutex);866866+ if (!locked)867867+ mutex_lock(&pinctrl_mutex);970868 list_add_tail(&maps_node->node, &pinctrl_maps);971971- mutex_unlock(&pinctrl_mutex);869869+ if (!locked)870870+ mutex_unlock(&pinctrl_mutex);972871973872 return 0;873873+}874874+875875+/**876876+ * pinctrl_register_mappings() - register a set of pin controller mappings877877+ * @maps: the pincontrol mappings table to register. This should probably be878878+ * marked with __initdata so it can be discarded after boot. This879879+ * function will perform a shallow copy for the mapping entries.880880+ * @num_maps: the number of maps in the mapping table881881+ */882882+int pinctrl_register_mappings(struct pinctrl_map const *maps,883883+ unsigned num_maps)884884+{885885+ return pinctrl_register_map(maps, num_maps, true, false);886886+}887887+888888+void pinctrl_unregister_map(struct pinctrl_map const *map)889889+{890890+ struct pinctrl_maps *maps_node;891891+892892+ list_for_each_entry(maps_node, &pinctrl_maps, node) {893893+ if (maps_node->maps == map) {894894+ list_del(&maps_node->node);895895+ return;896896+ }897897+ }974898}975899976900#ifdef CONFIG_DEBUG_FS···1046906{1047907 struct pinctrl_dev *pctldev = s->private;1048908 const struct pinctrl_ops *ops = pctldev->desc->pctlops;10491049- unsigned selector = 0;909909+ unsigned ngroups, selector = 0;1050910911911+ ngroups = ops->get_groups_count(pctldev);1051912 mutex_lock(&pinctrl_mutex);10529131053914 seq_puts(s, "registered pin groups:\n");10541054- while (ops->list_groups(pctldev, selector) >= 0) {915915+ while (selector < ngroups) {1055916 const unsigned *pins;1056917 unsigned num_pins;1057918 const char *gname = ops->get_group_name(pctldev, selector);919919+ const char *pname;1058920 int ret;1059921 int i;1060922···1066924 seq_printf(s, "%s [ERROR GETTING PINS]\n",1067925 gname);1068926 else {10691069- seq_printf(s, "group: %s, pins = [ ", gname);10701070- for (i = 0; i < num_pins; i++)10711071- seq_printf(s, "%d ", pins[i]);10721072- seq_puts(s, "]\n");927927+ seq_printf(s, "group: %s\n", gname);928928+ for (i = 0; i < num_pins; i++) {929929+ pname = pin_get_name(pctldev, pins[i]);930930+ if (WARN_ON(!pname))931931+ return -EINVAL;932932+ seq_printf(s, "pin %d (%s)\n", pins[i], pname);933933+ }934934+ seq_puts(s, "\n");1073935 }1074936 selector++;1075937 }···13721226 const struct pinctrl_ops *ops = pctldev->desc->pctlops;1373122713741228 if (!ops ||13751375- !ops->list_groups ||12291229+ !ops->get_groups_count ||13761230 !ops->get_group_name ||13771231 !ops->get_group_pins)12321232+ return -EINVAL;12331233+12341234+ if (ops->dt_node_to_map && !ops->dt_free_map)13781235 return -EINVAL;1379123613801237 return 0;···14171268 /* check core ops for sanity */14181269 ret = pinctrl_check_ops(pctldev);14191270 if (ret) {14201420- pr_err("%s pinctrl ops lacks necessary functions\n",14211421- pctldesc->name);12711271+ dev_err(dev, "pinctrl ops lacks necessary functions\n");14221272 goto out_err;14231273 }1424127414251275 /* If we're implementing pinmuxing, check the ops for sanity */14261276 if (pctldesc->pmxops) {14271277 ret = pinmux_check_ops(pctldev);14281428- if (ret) {14291429- pr_err("%s pinmux ops lacks necessary functions\n",14301430- pctldesc->name);12781278+ if (ret)14311279 goto out_err;14321432- }14331280 }1434128114351282 /* If we're implementing pinconfig, check the ops for sanity */14361283 if (pctldesc->confops) {14371284 ret = pinconf_check_ops(pctldev);14381438- if (ret) {14391439- pr_err("%s pin config ops lacks necessary functions\n",14401440- pctldesc->name);12851285+ if (ret)14411286 goto out_err;14421442- }14431287 }1444128814451289 /* Register all the pins */14461446- pr_debug("try to register %d pins on %s...\n",14471447- pctldesc->npins, pctldesc->name);12901290+ dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins);14481291 ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins);14491292 if (ret) {14501450- pr_err("error during pin registration\n");12931293+ dev_err(dev, "error during pin registration\n");14511294 pinctrl_free_pindescs(pctldev, pctldesc->pins,14521295 pctldesc->npins);14531296 goto out_err;···14541313 struct pinctrl_state *s =14551314 pinctrl_lookup_state_locked(pctldev->p,14561315 PINCTRL_STATE_DEFAULT);14571457- if (!IS_ERR(s))14581458- pinctrl_select_state_locked(pctldev->p, s);13161316+ if (IS_ERR(s)) {13171317+ dev_dbg(dev, "failed to lookup the default state\n");13181318+ } else {13191319+ ret = pinctrl_select_state_locked(pctldev->p, s);13201320+ if (ret) {13211321+ dev_err(dev,13221322+ "failed to select default state\n");13231323+ }13241324+ }14591325 }1460132614611327 mutex_unlock(&pinctrl_mutex);
+11-1
drivers/pinctrl/core.h
···5252 * @dev: the device using this pin control handle5353 * @states: a list of states for this device5454 * @state: the current state5555+ * @dt_maps: the mapping table chunks dynamically parsed from device tree for5656+ * this device, if any5557 */5658struct pinctrl {5759 struct list_head node;5860 struct device *dev;5961 struct list_head states;6062 struct pinctrl_state *state;6363+ struct list_head dt_maps;6164};62656366/**···103100 * struct pinctrl_setting - an individual mux or config setting104101 * @node: list node for struct pinctrl_settings's @settings field105102 * @type: the type of setting106106- * @pctldev: pin control device handling to be programmed103103+ * @pctldev: pin control device handling to be programmed. Not used for104104+ * PIN_MAP_TYPE_DUMMY_STATE.107105 * @data: Data specific to the setting type108106 */109107struct pinctrl_setting {···148144149145struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);150146int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);147147+const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin);151148int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,152149 const char *pin_group);153150···158153 return radix_tree_lookup(&pctldev->pin_desc_tree, pin);159154}160155156156+int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,157157+ bool dup, bool locked);158158+void pinctrl_unregister_map(struct pinctrl_map const *map);159159+161160extern struct mutex pinctrl_mutex;161161+extern struct list_head pinctrldev_list;
+249
drivers/pinctrl/devicetree.c
···11+/*22+ * Device tree integration for the pin control subsystem33+ *44+ * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.55+ *66+ * This program is free software; you can redistribute it and/or modify it77+ * under the terms and conditions of the GNU General Public License,88+ * version 2, as published by the Free Software Foundation.99+ *1010+ * This program is distributed in the hope it will be useful, but WITHOUT1111+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1212+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1313+ * more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1717+ */1818+1919+#include <linux/device.h>2020+#include <linux/of.h>2121+#include <linux/pinctrl/pinctrl.h>2222+#include <linux/slab.h>2323+2424+#include "core.h"2525+#include "devicetree.h"2626+2727+/**2828+ * struct pinctrl_dt_map - mapping table chunk parsed from device tree2929+ * @node: list node for struct pinctrl's @dt_maps field3030+ * @pctldev: the pin controller that allocated this struct, and will free it3131+ * @maps: the mapping table entries3232+ */3333+struct pinctrl_dt_map {3434+ struct list_head node;3535+ struct pinctrl_dev *pctldev;3636+ struct pinctrl_map *map;3737+ unsigned num_maps;3838+};3939+4040+static void dt_free_map(struct pinctrl_dev *pctldev,4141+ struct pinctrl_map *map, unsigned num_maps)4242+{4343+ if (pctldev) {4444+ struct pinctrl_ops *ops = pctldev->desc->pctlops;4545+ ops->dt_free_map(pctldev, map, num_maps);4646+ } else {4747+ /* There is no pctldev for PIN_MAP_TYPE_DUMMY_STATE */4848+ kfree(map);4949+ }5050+}5151+5252+void pinctrl_dt_free_maps(struct pinctrl *p)5353+{5454+ struct pinctrl_dt_map *dt_map, *n1;5555+5656+ list_for_each_entry_safe(dt_map, n1, &p->dt_maps, node) {5757+ pinctrl_unregister_map(dt_map->map);5858+ list_del(&dt_map->node);5959+ dt_free_map(dt_map->pctldev, dt_map->map,6060+ dt_map->num_maps);6161+ kfree(dt_map);6262+ }6363+6464+ of_node_put(p->dev->of_node);6565+}6666+6767+static int dt_remember_or_free_map(struct pinctrl *p, const char *statename,6868+ struct pinctrl_dev *pctldev,6969+ struct pinctrl_map *map, unsigned num_maps)7070+{7171+ int i;7272+ struct pinctrl_dt_map *dt_map;7373+7474+ /* Initialize common mapping table entry fields */7575+ for (i = 0; i < num_maps; i++) {7676+ map[i].dev_name = dev_name(p->dev);7777+ map[i].name = statename;7878+ if (pctldev)7979+ map[i].ctrl_dev_name = dev_name(pctldev->dev);8080+ }8181+8282+ /* Remember the converted mapping table entries */8383+ dt_map = kzalloc(sizeof(*dt_map), GFP_KERNEL);8484+ if (!dt_map) {8585+ dev_err(p->dev, "failed to alloc struct pinctrl_dt_map\n");8686+ dt_free_map(pctldev, map, num_maps);8787+ return -ENOMEM;8888+ }8989+9090+ dt_map->pctldev = pctldev;9191+ dt_map->map = map;9292+ dt_map->num_maps = num_maps;9393+ list_add_tail(&dt_map->node, &p->dt_maps);9494+9595+ return pinctrl_register_map(map, num_maps, false, true);9696+}9797+9898+static struct pinctrl_dev *find_pinctrl_by_of_node(struct device_node *np)9999+{100100+ struct pinctrl_dev *pctldev;101101+102102+ list_for_each_entry(pctldev, &pinctrldev_list, node)103103+ if (pctldev->dev->of_node == np)104104+ return pctldev;105105+106106+ return NULL;107107+}108108+109109+static int dt_to_map_one_config(struct pinctrl *p, const char *statename,110110+ struct device_node *np_config)111111+{112112+ struct device_node *np_pctldev;113113+ struct pinctrl_dev *pctldev;114114+ struct pinctrl_ops *ops;115115+ int ret;116116+ struct pinctrl_map *map;117117+ unsigned num_maps;118118+119119+ /* Find the pin controller containing np_config */120120+ np_pctldev = of_node_get(np_config);121121+ for (;;) {122122+ np_pctldev = of_get_next_parent(np_pctldev);123123+ if (!np_pctldev || of_node_is_root(np_pctldev)) {124124+ dev_info(p->dev, "could not find pctldev for node %s, deferring probe\n",125125+ np_config->full_name);126126+ of_node_put(np_pctldev);127127+ /* OK let's just assume this will appear later then */128128+ return -EPROBE_DEFER;129129+ }130130+ pctldev = find_pinctrl_by_of_node(np_pctldev);131131+ if (pctldev)132132+ break;133133+ }134134+ of_node_put(np_pctldev);135135+136136+ /*137137+ * Call pinctrl driver to parse device tree node, and138138+ * generate mapping table entries139139+ */140140+ ops = pctldev->desc->pctlops;141141+ if (!ops->dt_node_to_map) {142142+ dev_err(p->dev, "pctldev %s doesn't support DT\n",143143+ dev_name(pctldev->dev));144144+ return -ENODEV;145145+ }146146+ ret = ops->dt_node_to_map(pctldev, np_config, &map, &num_maps);147147+ if (ret < 0)148148+ return ret;149149+150150+ /* Stash the mapping table chunk away for later use */151151+ return dt_remember_or_free_map(p, statename, pctldev, map, num_maps);152152+}153153+154154+static int dt_remember_dummy_state(struct pinctrl *p, const char *statename)155155+{156156+ struct pinctrl_map *map;157157+158158+ map = kzalloc(sizeof(*map), GFP_KERNEL);159159+ if (!map) {160160+ dev_err(p->dev, "failed to alloc struct pinctrl_map\n");161161+ return -ENOMEM;162162+ }163163+164164+ /* There is no pctldev for PIN_MAP_TYPE_DUMMY_STATE */165165+ map->type = PIN_MAP_TYPE_DUMMY_STATE;166166+167167+ return dt_remember_or_free_map(p, statename, NULL, map, 1);168168+}169169+170170+int pinctrl_dt_to_map(struct pinctrl *p)171171+{172172+ struct device_node *np = p->dev->of_node;173173+ int state, ret;174174+ char *propname;175175+ struct property *prop;176176+ const char *statename;177177+ const __be32 *list;178178+ int size, config;179179+ phandle phandle;180180+ struct device_node *np_config;181181+182182+ /* CONFIG_OF enabled, p->dev not instantiated from DT */183183+ if (!np) {184184+ dev_dbg(p->dev, "no of_node; not parsing pinctrl DT\n");185185+ return 0;186186+ }187187+188188+ /* We may store pointers to property names within the node */189189+ of_node_get(np);190190+191191+ /* For each defined state ID */192192+ for (state = 0; ; state++) {193193+ /* Retrieve the pinctrl-* property */194194+ propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);195195+ prop = of_find_property(np, propname, &size);196196+ kfree(propname);197197+ if (!prop)198198+ break;199199+ list = prop->value;200200+ size /= sizeof(*list);201201+202202+ /* Determine whether pinctrl-names property names the state */203203+ ret = of_property_read_string_index(np, "pinctrl-names",204204+ state, &statename);205205+ /*206206+ * If not, statename is just the integer state ID. But rather207207+ * than dynamically allocate it and have to free it later,208208+ * just point part way into the property name for the string.209209+ */210210+ if (ret < 0) {211211+ /* strlen("pinctrl-") == 8 */212212+ statename = prop->name + 8;213213+ }214214+215215+ /* For every referenced pin configuration node in it */216216+ for (config = 0; config < size; config++) {217217+ phandle = be32_to_cpup(list++);218218+219219+ /* Look up the pin configuration node */220220+ np_config = of_find_node_by_phandle(phandle);221221+ if (!np_config) {222222+ dev_err(p->dev,223223+ "prop %s index %i invalid phandle\n",224224+ prop->name, config);225225+ ret = -EINVAL;226226+ goto err;227227+ }228228+229229+ /* Parse the node */230230+ ret = dt_to_map_one_config(p, statename, np_config);231231+ of_node_put(np_config);232232+ if (ret < 0)233233+ goto err;234234+ }235235+236236+ /* No entries in DT? Generate a dummy state table entry */237237+ if (!size) {238238+ ret = dt_remember_dummy_state(p, statename);239239+ if (ret < 0)240240+ goto err;241241+ }242242+ }243243+244244+ return 0;245245+246246+err:247247+ pinctrl_dt_free_maps(p);248248+ return ret;249249+}
+35
drivers/pinctrl/devicetree.h
···11+/*22+ * Internal interface to pinctrl device tree integration33+ *44+ * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.55+ *66+ * This program is free software; you can redistribute it and/or modify it77+ * under the terms and conditions of the GNU General Public License,88+ * version 2, as published by the Free Software Foundation.99+ *1010+ * This program is distributed in the hope it will be useful, but WITHOUT1111+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1212+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1313+ * more details.1414+ *1515+ * You should have received a copy of the GNU General Public License1616+ * along with this program. If not, see <http://www.gnu.org/licenses/>.1717+ */1818+1919+#ifdef CONFIG_OF2020+2121+void pinctrl_dt_free_maps(struct pinctrl *p);2222+int pinctrl_dt_to_map(struct pinctrl *p);2323+2424+#else2525+2626+static inline int pinctrl_dt_to_map(struct pinctrl *p)2727+{2828+ return 0;2929+}3030+3131+static inline void pinctrl_dt_free_maps(struct pinctrl *p)3232+{3333+}3434+3535+#endif
+43-9
drivers/pinctrl/pinconf.c
···2828 const struct pinconf_ops *ops = pctldev->desc->confops;29293030 /* We must be able to read out pin status */3131- if (!ops->pin_config_get && !ops->pin_config_group_get)3131+ if (!ops->pin_config_get && !ops->pin_config_group_get) {3232+ dev_err(pctldev->dev,3333+ "pinconf must be able to read out pin status\n");3234 return -EINVAL;3535+ }3336 /* We have to be able to config the pins in SOME way */3434- if (!ops->pin_config_set && !ops->pin_config_group_set)3737+ if (!ops->pin_config_set && !ops->pin_config_group_set) {3838+ dev_err(pctldev->dev,3939+ "pinconf has to be able to set a pins config\n");3540 return -EINVAL;4141+ }3642 return 0;3743}3844···385379386380void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map)387381{382382+ struct pinctrl_dev *pctldev;383383+ const struct pinconf_ops *confops;388384 int i;385385+386386+ pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);387387+ if (pctldev)388388+ confops = pctldev->desc->confops;389389+ else390390+ confops = NULL;389391390392 switch (map->type) {391393 case PIN_MAP_TYPE_CONFIGS_PIN:···408394409395 seq_printf(s, "%s\n", map->data.configs.group_or_pin);410396411411- for (i = 0; i < map->data.configs.num_configs; i++)412412- seq_printf(s, "config %08lx\n", map->data.configs.configs[i]);397397+ for (i = 0; i < map->data.configs.num_configs; i++) {398398+ seq_printf(s, "config ");399399+ if (confops && confops->pin_config_config_dbg_show)400400+ confops->pin_config_config_dbg_show(pctldev, s,401401+ map->data.configs.configs[i]);402402+ else403403+ seq_printf(s, "%08lx", map->data.configs.configs[i]);404404+ seq_printf(s, "\n");405405+ }413406}414407415408void pinconf_show_setting(struct seq_file *s,···424403{425404 struct pinctrl_dev *pctldev = setting->pctldev;426405 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;406406+ const struct pinconf_ops *confops = pctldev->desc->confops;427407 struct pin_desc *desc;428408 int i;429409···450428 * FIXME: We should really get the pin controler to dump the config451429 * values, so they can be decoded to something meaningful.452430 */453453- for (i = 0; i < setting->data.configs.num_configs; i++)454454- seq_printf(s, " %08lx", setting->data.configs.configs[i]);431431+ for (i = 0; i < setting->data.configs.num_configs; i++) {432432+ seq_printf(s, " ");433433+ if (confops && confops->pin_config_config_dbg_show)434434+ confops->pin_config_config_dbg_show(pctldev, s,435435+ setting->data.configs.configs[i]);436436+ else437437+ seq_printf(s, "%08lx",438438+ setting->data.configs.configs[i]);439439+ }455440456441 seq_printf(s, "\n");457442}···477448static int pinconf_pins_show(struct seq_file *s, void *what)478449{479450 struct pinctrl_dev *pctldev = s->private;451451+ const struct pinconf_ops *ops = pctldev->desc->confops;480452 unsigned i, pin;481453454454+ if (!ops || !ops->pin_config_get)455455+ return 0;456456+482457 seq_puts(s, "Pin config settings per pin\n");483483- seq_puts(s, "Format: pin (name): pinmux setting array\n");458458+ seq_puts(s, "Format: pin (name): configs\n");484459485460 mutex_lock(&pinctrl_mutex);486461···528495 struct pinctrl_dev *pctldev = s->private;529496 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;530497 const struct pinconf_ops *ops = pctldev->desc->confops;498498+ unsigned ngroups = pctlops->get_groups_count(pctldev);531499 unsigned selector = 0;532500533501 if (!ops || !ops->pin_config_group_get)534502 return 0;535503536504 seq_puts(s, "Pin config settings per pin group\n");537537- seq_puts(s, "Format: group (name): pinmux setting array\n");505505+ seq_puts(s, "Format: group (name): configs\n");538506539507 mutex_lock(&pinctrl_mutex);540508541541- while (pctlops->list_groups(pctldev, selector) >= 0) {509509+ while (selector < ngroups) {542510 const char *gname = pctlops->get_group_name(pctldev, selector);543511544512 seq_printf(s, "%u (%s):", selector, gname);
+12-5
drivers/pinctrl/pinconf.h
···1919 struct pinctrl_setting *setting);2020void pinconf_free_setting(struct pinctrl_setting const *setting);2121int pinconf_apply_setting(struct pinctrl_setting const *setting);2222-void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map);2323-void pinconf_show_setting(struct seq_file *s,2424- struct pinctrl_setting const *setting);2525-void pinconf_init_device_debugfs(struct dentry *devroot,2626- struct pinctrl_dev *pctldev);27222823/*2924 * You will only be interested in these if you're using PINCONF···5560{5661 return 0;5762}6363+6464+#endif6565+6666+#if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS)6767+6868+void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map);6969+void pinconf_show_setting(struct seq_file *s,7070+ struct pinctrl_setting const *setting);7171+void pinconf_init_device_debugfs(struct dentry *devroot,7272+ struct pinctrl_dev *pctldev);7373+7474+#else58755976static inline void pinconf_show_map(struct seq_file *s,6077 struct pinctrl_map const *map)
···11+/*22+ * Core driver for the imx pin controller33+ *44+ * Copyright (C) 2012 Freescale Semiconductor, Inc.55+ * Copyright (C) 2012 Linaro Ltd.66+ *77+ * Author: Dong Aisheng <dong.aisheng@linaro.org>88+ *99+ * This program is free software; you can redistribute it and/or modify1010+ * it under the terms of the GNU General Public License as published by1111+ * the Free Software Foundation; either version 2 of the License, or1212+ * (at your option) any later version.1313+ */1414+1515+#include <linux/err.h>1616+#include <linux/init.h>1717+#include <linux/io.h>1818+#include <linux/module.h>1919+#include <linux/of.h>2020+#include <linux/of_device.h>2121+#include <linux/pinctrl/machine.h>2222+#include <linux/pinctrl/pinconf.h>2323+#include <linux/pinctrl/pinctrl.h>2424+#include <linux/pinctrl/pinmux.h>2525+#include <linux/slab.h>2626+2727+#include "core.h"2828+#include "pinctrl-imx.h"2929+3030+#define IMX_PMX_DUMP(info, p, m, c, n) \3131+{ \3232+ int i, j; \3333+ printk("Format: Pin Mux Config\n"); \3434+ for (i = 0; i < n; i++) { \3535+ j = p[i]; \3636+ printk("%s %d 0x%lx\n", \3737+ info->pins[j].name, \3838+ m[i], c[i]); \3939+ } \4040+}4141+4242+/* The bits in CONFIG cell defined in binding doc*/4343+#define IMX_NO_PAD_CTL 0x80000000 /* no pin config need */4444+#define IMX_PAD_SION 0x40000000 /* set SION */4545+4646+/**4747+ * @dev: a pointer back to containing device4848+ * @base: the offset to the controller in virtual memory4949+ */5050+struct imx_pinctrl {5151+ struct device *dev;5252+ struct pinctrl_dev *pctl;5353+ void __iomem *base;5454+ const struct imx_pinctrl_soc_info *info;5555+};5656+5757+static const struct imx_pin_reg *imx_find_pin_reg(5858+ const struct imx_pinctrl_soc_info *info,5959+ unsigned pin, bool is_mux, unsigned mux)6060+{6161+ const struct imx_pin_reg *pin_reg = NULL;6262+ int i;6363+6464+ for (i = 0; i < info->npin_regs; i++) {6565+ pin_reg = &info->pin_regs[i];6666+ if (pin_reg->pid != pin)6767+ continue;6868+ if (!is_mux)6969+ break;7070+ else if (pin_reg->mux_mode == (mux & IMX_MUX_MASK))7171+ break;7272+ }7373+7474+ if (!pin_reg) {7575+ dev_err(info->dev, "Pin(%s): unable to find pin reg map\n",7676+ info->pins[pin].name);7777+ return NULL;7878+ }7979+8080+ return pin_reg;8181+}8282+8383+static const inline struct imx_pin_group *imx_pinctrl_find_group_by_name(8484+ const struct imx_pinctrl_soc_info *info,8585+ const char *name)8686+{8787+ const struct imx_pin_group *grp = NULL;8888+ int i;8989+9090+ for (i = 0; i < info->ngroups; i++) {9191+ if (!strcmp(info->groups[i].name, name)) {9292+ grp = &info->groups[i];9393+ break;9494+ }9595+ }9696+9797+ return grp;9898+}9999+100100+static int imx_get_groups_count(struct pinctrl_dev *pctldev)101101+{102102+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);103103+ const struct imx_pinctrl_soc_info *info = ipctl->info;104104+105105+ return info->ngroups;106106+}107107+108108+static const char *imx_get_group_name(struct pinctrl_dev *pctldev,109109+ unsigned selector)110110+{111111+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);112112+ const struct imx_pinctrl_soc_info *info = ipctl->info;113113+114114+ return info->groups[selector].name;115115+}116116+117117+static int imx_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,118118+ const unsigned **pins,119119+ unsigned *npins)120120+{121121+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);122122+ const struct imx_pinctrl_soc_info *info = ipctl->info;123123+124124+ if (selector >= info->ngroups)125125+ return -EINVAL;126126+127127+ *pins = info->groups[selector].pins;128128+ *npins = info->groups[selector].npins;129129+130130+ return 0;131131+}132132+133133+static void imx_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,134134+ unsigned offset)135135+{136136+ seq_printf(s, "%s", dev_name(pctldev->dev));137137+}138138+139139+static int imx_dt_node_to_map(struct pinctrl_dev *pctldev,140140+ struct device_node *np,141141+ struct pinctrl_map **map, unsigned *num_maps)142142+{143143+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);144144+ const struct imx_pinctrl_soc_info *info = ipctl->info;145145+ const struct imx_pin_group *grp;146146+ struct pinctrl_map *new_map;147147+ struct device_node *parent;148148+ int map_num = 1;149149+ int i;150150+151151+ /*152152+ * first find the group of this node and check if we need create153153+ * config maps for pins154154+ */155155+ grp = imx_pinctrl_find_group_by_name(info, np->name);156156+ if (!grp) {157157+ dev_err(info->dev, "unable to find group for node %s\n",158158+ np->name);159159+ return -EINVAL;160160+ }161161+162162+ for (i = 0; i < grp->npins; i++) {163163+ if (!(grp->configs[i] & IMX_NO_PAD_CTL))164164+ map_num++;165165+ }166166+167167+ new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL);168168+ if (!new_map)169169+ return -ENOMEM;170170+171171+ *map = new_map;172172+ *num_maps = map_num;173173+174174+ /* create mux map */175175+ parent = of_get_parent(np);176176+ if (!parent)177177+ return -EINVAL;178178+ new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;179179+ new_map[0].data.mux.function = parent->name;180180+ new_map[0].data.mux.group = np->name;181181+ of_node_put(parent);182182+183183+ /* create config map */184184+ new_map++;185185+ for (i = 0; i < grp->npins; i++) {186186+ if (!(grp->configs[i] & IMX_NO_PAD_CTL)) {187187+ new_map[i].type = PIN_MAP_TYPE_CONFIGS_PIN;188188+ new_map[i].data.configs.group_or_pin =189189+ pin_get_name(pctldev, grp->pins[i]);190190+ new_map[i].data.configs.configs = &grp->configs[i];191191+ new_map[i].data.configs.num_configs = 1;192192+ }193193+ }194194+195195+ dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",196196+ new_map->data.mux.function, new_map->data.mux.group, map_num);197197+198198+ return 0;199199+}200200+201201+static void imx_dt_free_map(struct pinctrl_dev *pctldev,202202+ struct pinctrl_map *map, unsigned num_maps)203203+{204204+ int i;205205+206206+ for (i = 0; i < num_maps; i++)207207+ kfree(map);208208+}209209+210210+static struct pinctrl_ops imx_pctrl_ops = {211211+ .get_groups_count = imx_get_groups_count,212212+ .get_group_name = imx_get_group_name,213213+ .get_group_pins = imx_get_group_pins,214214+ .pin_dbg_show = imx_pin_dbg_show,215215+ .dt_node_to_map = imx_dt_node_to_map,216216+ .dt_free_map = imx_dt_free_map,217217+218218+};219219+220220+static int imx_pmx_enable(struct pinctrl_dev *pctldev, unsigned selector,221221+ unsigned group)222222+{223223+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);224224+ const struct imx_pinctrl_soc_info *info = ipctl->info;225225+ const struct imx_pin_reg *pin_reg;226226+ const unsigned *pins, *mux;227227+ unsigned int npins, pin_id;228228+ int i;229229+230230+ /*231231+ * Configure the mux mode for each pin in the group for a specific232232+ * function.233233+ */234234+ pins = info->groups[group].pins;235235+ npins = info->groups[group].npins;236236+ mux = info->groups[group].mux_mode;237237+238238+ WARN_ON(!pins || !npins || !mux);239239+240240+ dev_dbg(ipctl->dev, "enable function %s group %s\n",241241+ info->functions[selector].name, info->groups[group].name);242242+243243+ for (i = 0; i < npins; i++) {244244+ pin_id = pins[i];245245+246246+ pin_reg = imx_find_pin_reg(info, pin_id, 1, mux[i]);247247+ if (!pin_reg)248248+ return -EINVAL;249249+250250+ if (!pin_reg->mux_reg) {251251+ dev_err(ipctl->dev, "Pin(%s) does not support mux function\n",252252+ info->pins[pin_id].name);253253+ return -EINVAL;254254+ }255255+256256+ writel(mux[i], ipctl->base + pin_reg->mux_reg);257257+ dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%x\n",258258+ pin_reg->mux_reg, mux[i]);259259+260260+ /* some pins also need select input setting, set it if found */261261+ if (pin_reg->input_reg) {262262+ writel(pin_reg->input_val, ipctl->base + pin_reg->input_reg);263263+ dev_dbg(ipctl->dev,264264+ "==>select_input: offset 0x%x val 0x%x\n",265265+ pin_reg->input_reg, pin_reg->input_val);266266+ }267267+ }268268+269269+ return 0;270270+}271271+272272+static void imx_pmx_disable(struct pinctrl_dev *pctldev, unsigned func_selector,273273+ unsigned group_selector)274274+{275275+ /* nothing to do here */276276+}277277+278278+static int imx_pmx_get_funcs_count(struct pinctrl_dev *pctldev)279279+{280280+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);281281+ const struct imx_pinctrl_soc_info *info = ipctl->info;282282+283283+ return info->nfunctions;284284+}285285+286286+static const char *imx_pmx_get_func_name(struct pinctrl_dev *pctldev,287287+ unsigned selector)288288+{289289+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);290290+ const struct imx_pinctrl_soc_info *info = ipctl->info;291291+292292+ return info->functions[selector].name;293293+}294294+295295+static int imx_pmx_get_groups(struct pinctrl_dev *pctldev, unsigned selector,296296+ const char * const **groups,297297+ unsigned * const num_groups)298298+{299299+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);300300+ const struct imx_pinctrl_soc_info *info = ipctl->info;301301+302302+ *groups = info->functions[selector].groups;303303+ *num_groups = info->functions[selector].num_groups;304304+305305+ return 0;306306+}307307+308308+static struct pinmux_ops imx_pmx_ops = {309309+ .get_functions_count = imx_pmx_get_funcs_count,310310+ .get_function_name = imx_pmx_get_func_name,311311+ .get_function_groups = imx_pmx_get_groups,312312+ .enable = imx_pmx_enable,313313+ .disable = imx_pmx_disable,314314+};315315+316316+static int imx_pinconf_get(struct pinctrl_dev *pctldev,317317+ unsigned pin_id, unsigned long *config)318318+{319319+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);320320+ const struct imx_pinctrl_soc_info *info = ipctl->info;321321+ const struct imx_pin_reg *pin_reg;322322+323323+ pin_reg = imx_find_pin_reg(info, pin_id, 0, 0);324324+ if (!pin_reg)325325+ return -EINVAL;326326+327327+ if (!pin_reg->conf_reg) {328328+ dev_err(info->dev, "Pin(%s) does not support config function\n",329329+ info->pins[pin_id].name);330330+ return -EINVAL;331331+ }332332+333333+ *config = readl(ipctl->base + pin_reg->conf_reg);334334+335335+ return 0;336336+}337337+338338+static int imx_pinconf_set(struct pinctrl_dev *pctldev,339339+ unsigned pin_id, unsigned long config)340340+{341341+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);342342+ const struct imx_pinctrl_soc_info *info = ipctl->info;343343+ const struct imx_pin_reg *pin_reg;344344+345345+ pin_reg = imx_find_pin_reg(info, pin_id, 0, 0);346346+ if (!pin_reg)347347+ return -EINVAL;348348+349349+ if (!pin_reg->conf_reg) {350350+ dev_err(info->dev, "Pin(%s) does not support config function\n",351351+ info->pins[pin_id].name);352352+ return -EINVAL;353353+ }354354+355355+ dev_dbg(ipctl->dev, "pinconf set pin %s\n",356356+ info->pins[pin_id].name);357357+358358+ writel(config, ipctl->base + pin_reg->conf_reg);359359+ dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%lx\n",360360+ pin_reg->conf_reg, config);361361+362362+ return 0;363363+}364364+365365+static void imx_pinconf_dbg_show(struct pinctrl_dev *pctldev,366366+ struct seq_file *s, unsigned pin_id)367367+{368368+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);369369+ const struct imx_pinctrl_soc_info *info = ipctl->info;370370+ const struct imx_pin_reg *pin_reg;371371+ unsigned long config;372372+373373+ pin_reg = imx_find_pin_reg(info, pin_id, 0, 0);374374+ if (!pin_reg || !pin_reg->conf_reg) {375375+ seq_printf(s, "N/A");376376+ return;377377+ }378378+379379+ config = readl(ipctl->base + pin_reg->conf_reg);380380+ seq_printf(s, "0x%lx", config);381381+}382382+383383+static void imx_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,384384+ struct seq_file *s, unsigned group)385385+{386386+ struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);387387+ const struct imx_pinctrl_soc_info *info = ipctl->info;388388+ struct imx_pin_group *grp;389389+ unsigned long config;390390+ const char *name;391391+ int i, ret;392392+393393+ if (group > info->ngroups)394394+ return;395395+396396+ seq_printf(s, "\n");397397+ grp = &info->groups[group];398398+ for (i = 0; i < grp->npins; i++) {399399+ name = pin_get_name(pctldev, grp->pins[i]);400400+ ret = imx_pinconf_get(pctldev, grp->pins[i], &config);401401+ if (ret)402402+ return;403403+ seq_printf(s, "%s: 0x%lx", name, config);404404+ }405405+}406406+407407+struct pinconf_ops imx_pinconf_ops = {408408+ .pin_config_get = imx_pinconf_get,409409+ .pin_config_set = imx_pinconf_set,410410+ .pin_config_dbg_show = imx_pinconf_dbg_show,411411+ .pin_config_group_dbg_show = imx_pinconf_group_dbg_show,412412+};413413+414414+static struct pinctrl_desc imx_pinctrl_desc = {415415+ .pctlops = &imx_pctrl_ops,416416+ .pmxops = &imx_pmx_ops,417417+ .confops = &imx_pinconf_ops,418418+ .owner = THIS_MODULE,419419+};420420+421421+/* decode pin id and mux from pin function id got from device tree*/422422+static int imx_pinctrl_get_pin_id_and_mux(const struct imx_pinctrl_soc_info *info,423423+ unsigned int pin_func_id, unsigned int *pin_id,424424+ unsigned int *mux)425425+{426426+ if (pin_func_id > info->npin_regs)427427+ return -EINVAL;428428+429429+ *pin_id = info->pin_regs[pin_func_id].pid;430430+ *mux = info->pin_regs[pin_func_id].mux_mode;431431+432432+ return 0;433433+}434434+435435+static int __devinit imx_pinctrl_parse_groups(struct device_node *np,436436+ struct imx_pin_group *grp,437437+ struct imx_pinctrl_soc_info *info,438438+ u32 index)439439+{440440+ unsigned int pin_func_id;441441+ int ret, size;442442+ const const __be32 *list;443443+ int i, j;444444+ u32 config;445445+446446+ dev_dbg(info->dev, "group(%d): %s\n", index, np->name);447447+448448+ /* Initialise group */449449+ grp->name = np->name;450450+451451+ /*452452+ * the binding format is fsl,pins = <PIN_FUNC_ID CONFIG ...>,453453+ * do sanity check and calculate pins number454454+ */455455+ list = of_get_property(np, "fsl,pins", &size);456456+ /* we do not check return since it's safe node passed down */457457+ size /= sizeof(*list);458458+ if (!size || size % 2) {459459+ dev_err(info->dev, "wrong pins number or pins and configs should be pairs\n");460460+ return -EINVAL;461461+ }462462+463463+ grp->npins = size / 2;464464+ grp->pins = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned int),465465+ GFP_KERNEL);466466+ grp->mux_mode = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned int),467467+ GFP_KERNEL);468468+ grp->configs = devm_kzalloc(info->dev, grp->npins * sizeof(unsigned long),469469+ GFP_KERNEL);470470+ for (i = 0, j = 0; i < size; i += 2, j++) {471471+ pin_func_id = be32_to_cpu(*list++);472472+ ret = imx_pinctrl_get_pin_id_and_mux(info, pin_func_id,473473+ &grp->pins[j], &grp->mux_mode[j]);474474+ if (ret) {475475+ dev_err(info->dev, "get invalid pin function id\n");476476+ return -EINVAL;477477+ }478478+ /* SION bit is in mux register */479479+ config = be32_to_cpu(*list++);480480+ if (config & IMX_PAD_SION)481481+ grp->mux_mode[j] |= IOMUXC_CONFIG_SION;482482+ grp->configs[j] = config & ~IMX_PAD_SION;483483+ }484484+485485+#ifdef DEBUG486486+ IMX_PMX_DUMP(info, grp->pins, grp->mux_mode, grp->configs, grp->npins);487487+#endif488488+ return 0;489489+}490490+491491+static int __devinit imx_pinctrl_parse_functions(struct device_node *np,492492+ struct imx_pinctrl_soc_info *info, u32 index)493493+{494494+ struct device_node *child;495495+ struct imx_pmx_func *func;496496+ struct imx_pin_group *grp;497497+ int ret;498498+ static u32 grp_index;499499+ u32 i = 0;500500+501501+ dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name);502502+503503+ func = &info->functions[index];504504+505505+ /* Initialise function */506506+ func->name = np->name;507507+ func->num_groups = of_get_child_count(np);508508+ if (func->num_groups <= 0) {509509+ dev_err(info->dev, "no groups defined\n");510510+ return -EINVAL;511511+ }512512+ func->groups = devm_kzalloc(info->dev,513513+ func->num_groups * sizeof(char *), GFP_KERNEL);514514+515515+ for_each_child_of_node(np, child) {516516+ func->groups[i] = child->name;517517+ grp = &info->groups[grp_index++];518518+ ret = imx_pinctrl_parse_groups(child, grp, info, i++);519519+ if (ret)520520+ return ret;521521+ }522522+523523+ return 0;524524+}525525+526526+static int __devinit imx_pinctrl_probe_dt(struct platform_device *pdev,527527+ struct imx_pinctrl_soc_info *info)528528+{529529+ struct device_node *np = pdev->dev.of_node;530530+ struct device_node *child;531531+ int ret;532532+ u32 nfuncs = 0;533533+ u32 i = 0;534534+535535+ if (!np)536536+ return -ENODEV;537537+538538+ nfuncs = of_get_child_count(np);539539+ if (nfuncs <= 0) {540540+ dev_err(&pdev->dev, "no functions defined\n");541541+ return -EINVAL;542542+ }543543+544544+ info->nfunctions = nfuncs;545545+ info->functions = devm_kzalloc(&pdev->dev, nfuncs * sizeof(struct imx_pmx_func),546546+ GFP_KERNEL);547547+ if (!info->functions)548548+ return -ENOMEM;549549+550550+ info->ngroups = 0;551551+ for_each_child_of_node(np, child)552552+ info->ngroups += of_get_child_count(child);553553+ info->groups = devm_kzalloc(&pdev->dev, info->ngroups * sizeof(struct imx_pin_group),554554+ GFP_KERNEL);555555+ if (!info->groups)556556+ return -ENOMEM;557557+558558+ for_each_child_of_node(np, child) {559559+ ret = imx_pinctrl_parse_functions(child, info, i++);560560+ if (ret) {561561+ dev_err(&pdev->dev, "failed to parse function\n");562562+ return ret;563563+ }564564+ }565565+566566+ return 0;567567+}568568+569569+int __devinit imx_pinctrl_probe(struct platform_device *pdev,570570+ struct imx_pinctrl_soc_info *info)571571+{572572+ struct imx_pinctrl *ipctl;573573+ struct resource *res;574574+ int ret;575575+576576+ if (!info || !info->pins || !info->npins577577+ || !info->pin_regs || !info->npin_regs) {578578+ dev_err(&pdev->dev, "wrong pinctrl info\n");579579+ return -EINVAL;580580+ }581581+ info->dev = &pdev->dev;582582+583583+ /* Create state holders etc for this driver */584584+ ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL);585585+ if (!ipctl)586586+ return -ENOMEM;587587+588588+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);589589+ if (!res)590590+ return -ENOENT;591591+592592+ ipctl->base = devm_request_and_ioremap(&pdev->dev, res);593593+ if (!ipctl->base)594594+ return -EBUSY;595595+596596+ imx_pinctrl_desc.name = dev_name(&pdev->dev);597597+ imx_pinctrl_desc.pins = info->pins;598598+ imx_pinctrl_desc.npins = info->npins;599599+600600+ ret = imx_pinctrl_probe_dt(pdev, info);601601+ if (ret) {602602+ dev_err(&pdev->dev, "fail to probe dt properties\n");603603+ return ret;604604+ }605605+606606+ ipctl->info = info;607607+ ipctl->dev = info->dev;608608+ platform_set_drvdata(pdev, ipctl);609609+ ipctl->pctl = pinctrl_register(&imx_pinctrl_desc, &pdev->dev, ipctl);610610+ if (!ipctl->pctl) {611611+ dev_err(&pdev->dev, "could not register IMX pinctrl driver\n");612612+ return -EINVAL;613613+ }614614+615615+ dev_info(&pdev->dev, "initialized IMX pinctrl driver\n");616616+617617+ return 0;618618+}619619+620620+int __devexit imx_pinctrl_remove(struct platform_device *pdev)621621+{622622+ struct imx_pinctrl *ipctl = platform_get_drvdata(pdev);623623+624624+ pinctrl_unregister(ipctl->pctl);625625+626626+ return 0;627627+}
+106
drivers/pinctrl/pinctrl-imx.h
···11+/*22+ * IMX pinmux core definitions33+ *44+ * Copyright (C) 2012 Freescale Semiconductor, Inc.55+ * Copyright (C) 2012 Linaro Ltd.66+ *77+ * Author: Dong Aisheng <dong.aisheng@linaro.org>88+ *99+ * This program is free software; you can redistribute it and/or modify1010+ * it under the terms of the GNU General Public License as published by1111+ * the Free Software Foundation; either version 2 of the License, or1212+ * (at your option) any later version.1313+ */1414+1515+#ifndef __DRIVERS_PINCTRL_IMX_H1616+#define __DRIVERS_PINCTRL_IMX_H1717+1818+struct platform_device;1919+2020+/**2121+ * struct imx_pin_group - describes an IMX pin group2222+ * @name: the name of this specific pin group2323+ * @pins: an array of discrete physical pins used in this group, taken2424+ * from the driver-local pin enumeration space2525+ * @npins: the number of pins in this group array, i.e. the number of2626+ * elements in .pins so we can iterate over that array2727+ * @mux_mode: the mux mode for each pin in this group. The size of this2828+ * array is the same as pins.2929+ * @configs: the config for each pin in this group. The size of this3030+ * array is the same as pins.3131+ */3232+struct imx_pin_group {3333+ const char *name;3434+ unsigned int *pins;3535+ unsigned npins;3636+ unsigned int *mux_mode;3737+ unsigned long *configs;3838+};3939+4040+/**4141+ * struct imx_pmx_func - describes IMX pinmux functions4242+ * @name: the name of this specific function4343+ * @groups: corresponding pin groups4444+ * @num_groups: the number of groups4545+ */4646+struct imx_pmx_func {4747+ const char *name;4848+ const char **groups;4949+ unsigned num_groups;5050+};5151+5252+/**5353+ * struct imx_pin_reg - describe a pin reg map5454+ * The last 3 members are used for select input setting5555+ * @pid: pin id5656+ * @mux_reg: mux register offset5757+ * @conf_reg: config register offset5858+ * @mux_mode: mux mode5959+ * @input_reg: select input register offset for this mux if any6060+ * 0 if no select input setting needed.6161+ * @input_val: the value set to select input register6262+ */6363+struct imx_pin_reg {6464+ u16 pid;6565+ u16 mux_reg;6666+ u16 conf_reg;6767+ u8 mux_mode;6868+ u16 input_reg;6969+ u8 input_val;7070+};7171+7272+struct imx_pinctrl_soc_info {7373+ struct device *dev;7474+ const struct pinctrl_pin_desc *pins;7575+ unsigned int npins;7676+ const struct imx_pin_reg *pin_regs;7777+ unsigned int npin_regs;7878+ struct imx_pin_group *groups;7979+ unsigned int ngroups;8080+ struct imx_pmx_func *functions;8181+ unsigned int nfunctions;8282+};8383+8484+#define NO_MUX 0x08585+#define NO_PAD 0x08686+8787+#define IMX_PIN_REG(id, conf, mux, mode, input, val) \8888+ { \8989+ .pid = id, \9090+ .conf_reg = conf, \9191+ .mux_reg = mux, \9292+ .mux_mode = mode, \9393+ .input_reg = input, \9494+ .input_val = val, \9595+ }9696+9797+#define IMX_PINCTRL_PIN(pin) PINCTRL_PIN(pin, #pin)9898+9999+#define PAD_CTL_MASK(len) ((1 << len) - 1)100100+#define IMX_MUX_MASK 0x7101101+#define IOMUXC_CONFIG_SION (0x1 << 4)102102+103103+int imx_pinctrl_probe(struct platform_device *pdev,104104+ struct imx_pinctrl_soc_info *info);105105+int imx_pinctrl_remove(struct platform_device *pdev);106106+#endif /* __DRIVERS_PINCTRL_IMX_H */
···11+/*22+ * Driver for the ST Microelectronics SPEAr pinmux33+ *44+ * Copyright (C) 2012 ST Microelectronics55+ * Viresh Kumar <viresh.kumar@st.com>66+ *77+ * Inspired from:88+ * - U300 Pinctl drivers99+ * - Tegra Pinctl drivers1010+ *1111+ * This file is licensed under the terms of the GNU General Public1212+ * License version 2. This program is licensed "as is" without any1313+ * warranty of any kind, whether express or implied.1414+ */1515+1616+#include <linux/err.h>1717+#include <linux/io.h>1818+#include <linux/module.h>1919+#include <linux/of.h>2020+#include <linux/of_address.h>2121+#include <linux/pinctrl/machine.h>2222+#include <linux/pinctrl/pinctrl.h>2323+#include <linux/pinctrl/pinmux.h>2424+#include <linux/platform_device.h>2525+#include <linux/slab.h>2626+2727+#include "pinctrl-spear.h"2828+2929+#define DRIVER_NAME "spear-pinmux"3030+3131+static inline u32 pmx_readl(struct spear_pmx *pmx, u32 reg)3232+{3333+ return readl_relaxed(pmx->vbase + reg);3434+}3535+3636+static inline void pmx_writel(struct spear_pmx *pmx, u32 val, u32 reg)3737+{3838+ writel_relaxed(val, pmx->vbase + reg);3939+}4040+4141+static int set_mode(struct spear_pmx *pmx, int mode)4242+{4343+ struct spear_pmx_mode *pmx_mode = NULL;4444+ int i;4545+ u32 val;4646+4747+ if (!pmx->machdata->pmx_modes || !pmx->machdata->npmx_modes)4848+ return -EINVAL;4949+5050+ for (i = 0; i < pmx->machdata->npmx_modes; i++) {5151+ if (pmx->machdata->pmx_modes[i]->mode == (1 << mode)) {5252+ pmx_mode = pmx->machdata->pmx_modes[i];5353+ break;5454+ }5555+ }5656+5757+ if (!pmx_mode)5858+ return -EINVAL;5959+6060+ val = pmx_readl(pmx, pmx_mode->reg);6161+ val &= ~pmx_mode->mask;6262+ val |= pmx_mode->val;6363+ pmx_writel(pmx, val, pmx_mode->reg);6464+6565+ pmx->machdata->mode = pmx_mode->mode;6666+ dev_info(pmx->dev, "Configured Mode: %s with id: %x\n\n",6767+ pmx_mode->name ? pmx_mode->name : "no_name",6868+ pmx_mode->reg);6969+7070+ return 0;7171+}7272+7373+void __devinit pmx_init_addr(struct spear_pinctrl_machdata *machdata, u16 reg)7474+{7575+ struct spear_pingroup *pgroup;7676+ struct spear_modemux *modemux;7777+ int i, j, group;7878+7979+ for (group = 0; group < machdata->ngroups; group++) {8080+ pgroup = machdata->groups[group];8181+8282+ for (i = 0; i < pgroup->nmodemuxs; i++) {8383+ modemux = &pgroup->modemuxs[i];8484+8585+ for (j = 0; j < modemux->nmuxregs; j++)8686+ if (modemux->muxregs[j].reg == 0xFFFF)8787+ modemux->muxregs[j].reg = reg;8888+ }8989+ }9090+}9191+9292+static int spear_pinctrl_get_groups_cnt(struct pinctrl_dev *pctldev)9393+{9494+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);9595+9696+ return pmx->machdata->ngroups;9797+}9898+9999+static const char *spear_pinctrl_get_group_name(struct pinctrl_dev *pctldev,100100+ unsigned group)101101+{102102+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);103103+104104+ return pmx->machdata->groups[group]->name;105105+}106106+107107+static int spear_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,108108+ unsigned group, const unsigned **pins, unsigned *num_pins)109109+{110110+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);111111+112112+ *pins = pmx->machdata->groups[group]->pins;113113+ *num_pins = pmx->machdata->groups[group]->npins;114114+115115+ return 0;116116+}117117+118118+static void spear_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,119119+ struct seq_file *s, unsigned offset)120120+{121121+ seq_printf(s, " " DRIVER_NAME);122122+}123123+124124+int spear_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,125125+ struct device_node *np_config,126126+ struct pinctrl_map **map, unsigned *num_maps)127127+{128128+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);129129+ struct device_node *np;130130+ struct property *prop;131131+ const char *function, *group;132132+ int ret, index = 0, count = 0;133133+134134+ /* calculate number of maps required */135135+ for_each_child_of_node(np_config, np) {136136+ ret = of_property_read_string(np, "st,function", &function);137137+ if (ret < 0)138138+ return ret;139139+140140+ ret = of_property_count_strings(np, "st,pins");141141+ if (ret < 0)142142+ return ret;143143+144144+ count += ret;145145+ }146146+147147+ if (!count) {148148+ dev_err(pmx->dev, "No child nodes passed via DT\n");149149+ return -ENODEV;150150+ }151151+152152+ *map = kzalloc(sizeof(**map) * count, GFP_KERNEL);153153+ if (!*map)154154+ return -ENOMEM;155155+156156+ for_each_child_of_node(np_config, np) {157157+ of_property_read_string(np, "st,function", &function);158158+ of_property_for_each_string(np, "st,pins", prop, group) {159159+ (*map)[index].type = PIN_MAP_TYPE_MUX_GROUP;160160+ (*map)[index].data.mux.group = group;161161+ (*map)[index].data.mux.function = function;162162+ index++;163163+ }164164+ }165165+166166+ *num_maps = count;167167+168168+ return 0;169169+}170170+171171+void spear_pinctrl_dt_free_map(struct pinctrl_dev *pctldev,172172+ struct pinctrl_map *map, unsigned num_maps)173173+{174174+ kfree(map);175175+}176176+177177+static struct pinctrl_ops spear_pinctrl_ops = {178178+ .get_groups_count = spear_pinctrl_get_groups_cnt,179179+ .get_group_name = spear_pinctrl_get_group_name,180180+ .get_group_pins = spear_pinctrl_get_group_pins,181181+ .pin_dbg_show = spear_pinctrl_pin_dbg_show,182182+ .dt_node_to_map = spear_pinctrl_dt_node_to_map,183183+ .dt_free_map = spear_pinctrl_dt_free_map,184184+};185185+186186+static int spear_pinctrl_get_funcs_count(struct pinctrl_dev *pctldev)187187+{188188+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);189189+190190+ return pmx->machdata->nfunctions;191191+}192192+193193+static const char *spear_pinctrl_get_func_name(struct pinctrl_dev *pctldev,194194+ unsigned function)195195+{196196+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);197197+198198+ return pmx->machdata->functions[function]->name;199199+}200200+201201+static int spear_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,202202+ unsigned function, const char *const **groups,203203+ unsigned * const ngroups)204204+{205205+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);206206+207207+ *groups = pmx->machdata->functions[function]->groups;208208+ *ngroups = pmx->machdata->functions[function]->ngroups;209209+210210+ return 0;211211+}212212+213213+static int spear_pinctrl_endisable(struct pinctrl_dev *pctldev,214214+ unsigned function, unsigned group, bool enable)215215+{216216+ struct spear_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);217217+ const struct spear_pingroup *pgroup;218218+ const struct spear_modemux *modemux;219219+ struct spear_muxreg *muxreg;220220+ u32 val, temp;221221+ int i, j;222222+ bool found = false;223223+224224+ pgroup = pmx->machdata->groups[group];225225+226226+ for (i = 0; i < pgroup->nmodemuxs; i++) {227227+ modemux = &pgroup->modemuxs[i];228228+229229+ /* SoC have any modes */230230+ if (pmx->machdata->modes_supported) {231231+ if (!(pmx->machdata->mode & modemux->modes))232232+ continue;233233+ }234234+235235+ found = true;236236+ for (j = 0; j < modemux->nmuxregs; j++) {237237+ muxreg = &modemux->muxregs[j];238238+239239+ val = pmx_readl(pmx, muxreg->reg);240240+ val &= ~muxreg->mask;241241+242242+ if (enable)243243+ temp = muxreg->val;244244+ else245245+ temp = ~muxreg->val;246246+247247+ val |= temp;248248+ pmx_writel(pmx, val, muxreg->reg);249249+ }250250+ }251251+252252+ if (!found) {253253+ dev_err(pmx->dev, "pinmux group: %s not supported\n",254254+ pgroup->name);255255+ return -ENODEV;256256+ }257257+258258+ return 0;259259+}260260+261261+static int spear_pinctrl_enable(struct pinctrl_dev *pctldev, unsigned function,262262+ unsigned group)263263+{264264+ return spear_pinctrl_endisable(pctldev, function, group, true);265265+}266266+267267+static void spear_pinctrl_disable(struct pinctrl_dev *pctldev,268268+ unsigned function, unsigned group)269269+{270270+ spear_pinctrl_endisable(pctldev, function, group, false);271271+}272272+273273+static struct pinmux_ops spear_pinmux_ops = {274274+ .get_functions_count = spear_pinctrl_get_funcs_count,275275+ .get_function_name = spear_pinctrl_get_func_name,276276+ .get_function_groups = spear_pinctrl_get_func_groups,277277+ .enable = spear_pinctrl_enable,278278+ .disable = spear_pinctrl_disable,279279+};280280+281281+static struct pinctrl_desc spear_pinctrl_desc = {282282+ .name = DRIVER_NAME,283283+ .pctlops = &spear_pinctrl_ops,284284+ .pmxops = &spear_pinmux_ops,285285+ .owner = THIS_MODULE,286286+};287287+288288+int __devinit spear_pinctrl_probe(struct platform_device *pdev,289289+ struct spear_pinctrl_machdata *machdata)290290+{291291+ struct device_node *np = pdev->dev.of_node;292292+ struct resource *res;293293+ struct spear_pmx *pmx;294294+295295+ if (!machdata)296296+ return -ENODEV;297297+298298+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);299299+ if (!res)300300+ return -EINVAL;301301+302302+ pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL);303303+ if (!pmx) {304304+ dev_err(&pdev->dev, "Can't alloc spear_pmx\n");305305+ return -ENOMEM;306306+ }307307+308308+ pmx->vbase = devm_ioremap(&pdev->dev, res->start, resource_size(res));309309+ if (!pmx->vbase) {310310+ dev_err(&pdev->dev, "Couldn't ioremap at index 0\n");311311+ return -ENODEV;312312+ }313313+314314+ pmx->dev = &pdev->dev;315315+ pmx->machdata = machdata;316316+317317+ /* configure mode, if supported by SoC */318318+ if (machdata->modes_supported) {319319+ int mode = 0;320320+321321+ if (of_property_read_u32(np, "st,pinmux-mode", &mode)) {322322+ dev_err(&pdev->dev, "OF: pinmux mode not passed\n");323323+ return -EINVAL;324324+ }325325+326326+ if (set_mode(pmx, mode)) {327327+ dev_err(&pdev->dev, "OF: Couldn't configure mode: %x\n",328328+ mode);329329+ return -EINVAL;330330+ }331331+ }332332+333333+ platform_set_drvdata(pdev, pmx);334334+335335+ spear_pinctrl_desc.pins = machdata->pins;336336+ spear_pinctrl_desc.npins = machdata->npins;337337+338338+ pmx->pctl = pinctrl_register(&spear_pinctrl_desc, &pdev->dev, pmx);339339+ if (IS_ERR(pmx->pctl)) {340340+ dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");341341+ return PTR_ERR(pmx->pctl);342342+ }343343+344344+ return 0;345345+}346346+347347+int __devexit spear_pinctrl_remove(struct platform_device *pdev)348348+{349349+ struct spear_pmx *pmx = platform_get_drvdata(pdev);350350+351351+ pinctrl_unregister(pmx->pctl);352352+353353+ return 0;354354+}
+142
drivers/pinctrl/spear/pinctrl-spear.h
···11+/*22+ * Driver header file for the ST Microelectronics SPEAr pinmux33+ *44+ * Copyright (C) 2012 ST Microelectronics55+ * Viresh Kumar <viresh.kumar@st.com>66+ *77+ * This file is licensed under the terms of the GNU General Public88+ * License version 2. This program is licensed "as is" without any99+ * warranty of any kind, whether express or implied.1010+ */1111+1212+#ifndef __PINMUX_SPEAR_H__1313+#define __PINMUX_SPEAR_H__1414+1515+#include <linux/pinctrl/pinctrl.h>1616+#include <linux/types.h>1717+1818+struct platform_device;1919+struct device;2020+2121+/**2222+ * struct spear_pmx_mode - SPEAr pmx mode2323+ * @name: name of pmx mode2424+ * @mode: mode id2525+ * @reg: register for configuring this mode2626+ * @mask: mask of this mode in reg2727+ * @val: val to be configured at reg after doing (val & mask)2828+ */2929+struct spear_pmx_mode {3030+ const char *const name;3131+ u16 mode;3232+ u16 reg;3333+ u16 mask;3434+ u32 val;3535+};3636+3737+/**3838+ * struct spear_muxreg - SPEAr mux reg configuration3939+ * @reg: register offset4040+ * @mask: mask bits4141+ * @val: val to be written on mask bits4242+ */4343+struct spear_muxreg {4444+ u16 reg;4545+ u32 mask;4646+ u32 val;4747+};4848+4949+/**5050+ * struct spear_modemux - SPEAr mode mux configuration5151+ * @modes: mode ids supported by this group of muxregs5252+ * @nmuxregs: number of muxreg configurations to be done for modes5353+ * @muxregs: array of muxreg configurations to be done for modes5454+ */5555+struct spear_modemux {5656+ u16 modes;5757+ u8 nmuxregs;5858+ struct spear_muxreg *muxregs;5959+};6060+6161+/**6262+ * struct spear_pingroup - SPEAr pin group configurations6363+ * @name: name of pin group6464+ * @pins: array containing pin numbers6565+ * @npins: size of pins array6666+ * @modemuxs: array of modemux configurations for this pin group6767+ * @nmodemuxs: size of array modemuxs6868+ *6969+ * A representation of a group of pins in the SPEAr pin controller. Each group7070+ * allows some parameter or parameters to be configured.7171+ */7272+struct spear_pingroup {7373+ const char *name;7474+ const unsigned *pins;7575+ unsigned npins;7676+ struct spear_modemux *modemuxs;7777+ unsigned nmodemuxs;7878+};7979+8080+/**8181+ * struct spear_function - SPEAr pinctrl mux function8282+ * @name: The name of the function, exported to pinctrl core.8383+ * @groups: An array of pin groups that may select this function.8484+ * @ngroups: The number of entries in @groups.8585+ */8686+struct spear_function {8787+ const char *name;8888+ const char *const *groups;8989+ unsigned ngroups;9090+};9191+9292+/**9393+ * struct spear_pinctrl_machdata - SPEAr pin controller machine driver9494+ * configuration9595+ * @pins: An array describing all pins the pin controller affects.9696+ * All pins which are also GPIOs must be listed first within the *array,9797+ * and be numbered identically to the GPIO controller's *numbering.9898+ * @npins: The numbmer of entries in @pins.9999+ * @functions: An array describing all mux functions the SoC supports.100100+ * @nfunctions: The numbmer of entries in @functions.101101+ * @groups: An array describing all pin groups the pin SoC supports.102102+ * @ngroups: The numbmer of entries in @groups.103103+ *104104+ * @modes_supported: Does SoC support modes105105+ * @mode: mode configured from probe106106+ * @pmx_modes: array of modes supported by SoC107107+ * @npmx_modes: number of entries in pmx_modes.108108+ */109109+struct spear_pinctrl_machdata {110110+ const struct pinctrl_pin_desc *pins;111111+ unsigned npins;112112+ struct spear_function **functions;113113+ unsigned nfunctions;114114+ struct spear_pingroup **groups;115115+ unsigned ngroups;116116+117117+ bool modes_supported;118118+ u16 mode;119119+ struct spear_pmx_mode **pmx_modes;120120+ unsigned npmx_modes;121121+};122122+123123+/**124124+ * struct spear_pmx - SPEAr pinctrl mux125125+ * @dev: pointer to struct dev of platform_device registered126126+ * @pctl: pointer to struct pinctrl_dev127127+ * @machdata: pointer to SoC or machine specific structure128128+ * @vbase: virtual base address of pinmux controller129129+ */130130+struct spear_pmx {131131+ struct device *dev;132132+ struct pinctrl_dev *pctl;133133+ struct spear_pinctrl_machdata *machdata;134134+ void __iomem *vbase;135135+};136136+137137+/* exported routines */138138+void __devinit pmx_init_addr(struct spear_pinctrl_machdata *machdata, u16 reg);139139+int __devinit spear_pinctrl_probe(struct platform_device *pdev,140140+ struct spear_pinctrl_machdata *machdata);141141+int __devexit spear_pinctrl_remove(struct platform_device *pdev);142142+#endif /* __PINMUX_SPEAR_H__ */
···2525 * @pin_config_get: get the config of a certain pin, if the requested config2626 * is not available on this controller this should return -ENOTSUPP2727 * and if it is available but disabled it should return -EINVAL2828- * @pin_config_get: get the config of a certain pin2928 * @pin_config_set: configure an individual pin3029 * @pin_config_group_get: get configurations for an entire pin group3130 * @pin_config_group_set: configure all pins in a group···3233 * per-device info for a certain pin in debugfs3334 * @pin_config_group_dbg_show: optional debugfs display hook that will provide3435 * per-device info for a certain group in debugfs3636+ * @pin_config_config_dbg_show: optional debugfs display hook that will decode3737+ * and display a driver's pin configuration parameter3538 */3639struct pinconf_ops {3740#ifdef CONFIG_GENERIC_PINCONF···5756 void (*pin_config_group_dbg_show) (struct pinctrl_dev *pctldev,5857 struct seq_file *s,5958 unsigned selector);5959+ void (*pin_config_config_dbg_show) (struct pinctrl_dev *pctldev,6060+ struct seq_file *s,6161+ unsigned long config);6062};61636264#endif
+18-4
include/linux/pinctrl/pinctrl.h
···21212222struct device;2323struct pinctrl_dev;2424+struct pinctrl_map;2425struct pinmux_ops;2526struct pinconf_ops;2627struct gpio_chip;2828+struct device_node;27292830/**2931 * struct pinctrl_pin_desc - boards/machines provide information on their···6664/**6765 * struct pinctrl_ops - global pin control operations, to be implemented by6866 * pin controller drivers.6969- * @list_groups: list the number of selectable named groups available7070- * in this pinmux driver, the core will begin on 0 and call this7171- * repeatedly as long as it returns >= 0 to enumerate the groups6767+ * @get_groups_count: Returns the count of total number of groups registered.7268 * @get_group_name: return the group name of the pin group7369 * @get_group_pins: return an array of pins corresponding to a certain7470 * group selector @pins, and the size of the array in @num_pins7571 * @pin_dbg_show: optional debugfs display hook that will provide per-device7672 * info for a certain pin in debugfs7373+ * @dt_node_to_map: parse a device tree "pin configuration node", and create7474+ * mapping table entries for it. These are returned through the @map and7575+ * @num_maps output parameters. This function is optional, and may be7676+ * omitted for pinctrl drivers that do not support device tree.7777+ * @dt_free_map: free mapping table entries created via @dt_node_to_map. The7878+ * top-level @map pointer must be freed, along with any dynamically7979+ * allocated members of the mapping table entries themselves. This8080+ * function is optional, and may be omitted for pinctrl drivers that do8181+ * not support device tree.7782 */7883struct pinctrl_ops {7979- int (*list_groups) (struct pinctrl_dev *pctldev, unsigned selector);8484+ int (*get_groups_count) (struct pinctrl_dev *pctldev);8085 const char *(*get_group_name) (struct pinctrl_dev *pctldev,8186 unsigned selector);8287 int (*get_group_pins) (struct pinctrl_dev *pctldev,···9283 unsigned *num_pins);9384 void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,9485 unsigned offset);8686+ int (*dt_node_to_map) (struct pinctrl_dev *pctldev,8787+ struct device_node *np_config,8888+ struct pinctrl_map **map, unsigned *num_maps);8989+ void (*dt_free_map) (struct pinctrl_dev *pctldev,9090+ struct pinctrl_map *map, unsigned num_maps);9591};96929793/**
+4-5
include/linux/pinctrl/pinmux.h
···2323/**2424 * struct pinmux_ops - pinmux operations, to be implemented by pin controller2525 * drivers that support pinmuxing2626- * @request: called by the core to see if a certain pin can be made available2626+ * @request: called by the core to see if a certain pin can be made2727 * available for muxing. This is called by the core to acquire the pins2828 * before selecting any actual mux setting across a function. The driver2929 * is allowed to answer "no" by returning a negative error code3030 * @free: the reverse function of the request() callback, frees a pin after3131 * being requested3232- * @list_functions: list the number of selectable named functions available3333- * in this pinmux driver, the core will begin on 0 and call this3434- * repeatedly as long as it returns >= 0 to enumerate mux settings3232+ * @get_functions_count: returns number of selectable named functions available3333+ * in this pinmux driver3534 * @get_function_name: return the function name of the muxing selector,3635 * called by the core to figure out which mux setting it shall map a3736 * certain device to···6162struct pinmux_ops {6263 int (*request) (struct pinctrl_dev *pctldev, unsigned offset);6364 int (*free) (struct pinctrl_dev *pctldev, unsigned offset);6464- int (*list_functions) (struct pinctrl_dev *pctldev, unsigned selector);6565+ int (*get_functions_count) (struct pinctrl_dev *pctldev);6566 const char *(*get_function_name) (struct pinctrl_dev *pctldev,6667 unsigned selector);6768 int (*get_function_groups) (struct pinctrl_dev *pctldev,