Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: single: Use generic parser and #pinctrl-cells for pinctrl-single,pins

We can now use generic parser. To support the legacy binding without
#pinctrl-cells, add pcs_quirk_missing_pinctrl_cells() and warn about
missing #pinctrl-cells.

Let's also update the documentation for struct pcs_soc_data while at it
as that seems to be out of date.

Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Tony Lindgren and committed by
Linus Walleij
4622215f 42124bc5

+93 -18
+93 -18
drivers/pinctrl/pinctrl-single.c
··· 31 31 #include <linux/platform_data/pinctrl-single.h> 32 32 33 33 #include "core.h" 34 + #include "devicetree.h" 34 35 #include "pinconf.h" 35 36 36 37 #define DRIVER_NAME "pinctrl-single" 37 - #define PCS_MUX_PINS_NAME "pinctrl-single,pins" 38 38 #define PCS_MUX_BITS_NAME "pinctrl-single,bits" 39 39 #define PCS_OFF_DISABLED ~0U 40 40 ··· 162 162 * @base: virtual address of the controller 163 163 * @size: size of the ioremapped area 164 164 * @dev: device entry 165 + * @np: device tree node 165 166 * @pctl: pin controller device 166 167 * @flags: mask of PCS_FEAT_xxx values 168 + * @missing_nr_pinctrl_cells: for legacy binding, may go away 169 + * @socdata: soc specific data 167 170 * @lock: spinlock for register access 168 171 * @mutex: mutex protecting the lists 169 172 * @width: bits per mux register ··· 174 171 * @fshift: function register shift 175 172 * @foff: value to turn mux off 176 173 * @fmax: max number of functions in fmask 177 - * @bits_per_pin:number of bits per pin 174 + * @bits_per_mux: number of bits per mux 175 + * @bits_per_pin: number of bits per pin 178 176 * @pins: physical pins on the SoC 179 177 * @pgtree: pingroup index radix tree 180 178 * @ftree: function index radix tree ··· 196 192 void __iomem *base; 197 193 unsigned size; 198 194 struct device *dev; 195 + struct device_node *np; 199 196 struct pinctrl_dev *pctl; 200 197 unsigned flags; 201 198 #define PCS_QUIRK_SHARED_IRQ (1 << 2) 202 199 #define PCS_FEAT_IRQ (1 << 1) 203 200 #define PCS_FEAT_PINCONF (1 << 0) 201 + struct property *missing_nr_pinctrl_cells; 204 202 struct pcs_soc_data socdata; 205 203 raw_spinlock_t lock; 206 204 struct mutex mutex; ··· 1128 1122 unsigned *num_maps, 1129 1123 const char **pgnames) 1130 1124 { 1125 + const char *name = "pinctrl-single,pins"; 1131 1126 struct pcs_func_vals *vals; 1132 - const __be32 *mux; 1133 - int size, rows, *pins, index = 0, found = 0, res = -ENOMEM; 1127 + int rows, *pins, found = 0, res = -ENOMEM, i; 1134 1128 struct pcs_function *function; 1135 1129 1136 - mux = of_get_property(np, PCS_MUX_PINS_NAME, &size); 1137 - if ((!mux) || (size < sizeof(*mux) * 2)) { 1138 - dev_err(pcs->dev, "bad data for mux %s\n", 1139 - np->name); 1140 - return -EINVAL; 1141 - } 1142 - 1143 - size /= sizeof(*mux); /* Number of elements in array */ 1144 - rows = size / 2; 1130 + rows = pinctrl_count_index_with_args(np, name); 1131 + if (rows == -EINVAL) 1132 + return rows; 1145 1133 1146 1134 vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows, GFP_KERNEL); 1147 1135 if (!vals) ··· 1145 1145 if (!pins) 1146 1146 goto free_vals; 1147 1147 1148 - while (index < size) { 1149 - unsigned offset, val; 1148 + for (i = 0; i < rows; i++) { 1149 + struct of_phandle_args pinctrl_spec; 1150 + unsigned int offset; 1150 1151 int pin; 1151 1152 1152 - offset = be32_to_cpup(mux + index++); 1153 - val = be32_to_cpup(mux + index++); 1153 + res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec); 1154 + if (res) 1155 + return res; 1156 + 1157 + if (pinctrl_spec.args_count < 2) { 1158 + dev_err(pcs->dev, "invalid args_count for spec: %i\n", 1159 + pinctrl_spec.args_count); 1160 + break; 1161 + } 1162 + 1163 + /* Index plus one value cell */ 1164 + offset = pinctrl_spec.args[0]; 1154 1165 vals[found].reg = pcs->base + offset; 1155 - vals[found].val = val; 1166 + vals[found].val = pinctrl_spec.args[1]; 1167 + 1168 + dev_dbg(pcs->dev, "%s index: 0x%x value: 0x%x\n", 1169 + pinctrl_spec.np->name, offset, pinctrl_spec.args[1]); 1156 1170 1157 1171 pin = pcs_get_pin_by_offset(pcs, offset); 1158 1172 if (pin < 0) { ··· 1484 1470 pinctrl_unregister(pcs->pctl); 1485 1471 pcs_free_funcs(pcs); 1486 1472 pcs_free_pingroups(pcs); 1473 + #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE) 1474 + if (pcs->missing_nr_pinctrl_cells) 1475 + of_remove_property(pcs->np, pcs->missing_nr_pinctrl_cells); 1476 + #endif 1487 1477 } 1488 1478 1489 1479 static const struct of_device_id pcs_of_match[]; ··· 1805 1787 } 1806 1788 #endif 1807 1789 1790 + /** 1791 + * pcs_quirk_missing_pinctrl_cells - handle legacy binding 1792 + * @pcs: pinctrl driver instance 1793 + * @np: device tree node 1794 + * @cells: number of cells 1795 + * 1796 + * Handle legacy binding with no #pinctrl-cells. This should be 1797 + * always two pinctrl-single,bit-per-mux and one for others. 1798 + * At some point we may want to consider removing this. 1799 + */ 1800 + static int pcs_quirk_missing_pinctrl_cells(struct pcs_device *pcs, 1801 + struct device_node *np, 1802 + int cells) 1803 + { 1804 + struct property *p; 1805 + const char *name = "#pinctrl-cells"; 1806 + int error; 1807 + u32 val; 1808 + 1809 + error = of_property_read_u32(np, name, &val); 1810 + if (!error) 1811 + return 0; 1812 + 1813 + dev_warn(pcs->dev, "please update dts to use %s = <%i>\n", 1814 + name, cells); 1815 + 1816 + p = devm_kzalloc(pcs->dev, sizeof(*p), GFP_KERNEL); 1817 + if (!p) 1818 + return -ENOMEM; 1819 + 1820 + p->length = sizeof(__be32); 1821 + p->value = devm_kzalloc(pcs->dev, sizeof(__be32), GFP_KERNEL); 1822 + if (!p->value) 1823 + return -ENOMEM; 1824 + *(__be32 *)p->value = cpu_to_be32(cells); 1825 + 1826 + p->name = devm_kstrdup(pcs->dev, name, GFP_KERNEL); 1827 + if (!p->name) 1828 + return -ENOMEM; 1829 + 1830 + pcs->missing_nr_pinctrl_cells = p; 1831 + 1832 + #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE) 1833 + error = of_add_property(np, pcs->missing_nr_pinctrl_cells); 1834 + #endif 1835 + 1836 + return error; 1837 + } 1838 + 1808 1839 static int pcs_probe(struct platform_device *pdev) 1809 1840 { 1810 1841 struct device_node *np = pdev->dev.of_node; ··· 1874 1807 return -ENOMEM; 1875 1808 } 1876 1809 pcs->dev = &pdev->dev; 1810 + pcs->np = np; 1877 1811 raw_spin_lock_init(&pcs->lock); 1878 1812 mutex_init(&pcs->mutex); 1879 1813 INIT_LIST_HEAD(&pcs->pingroups); ··· 1911 1843 1912 1844 pcs->bits_per_mux = of_property_read_bool(np, 1913 1845 "pinctrl-single,bit-per-mux"); 1846 + ret = pcs_quirk_missing_pinctrl_cells(pcs, np, 1847 + pcs->bits_per_mux ? 2 : 1); 1848 + if (ret) { 1849 + dev_err(&pdev->dev, "unable to patch #pinctrl-cells\n"); 1850 + 1851 + return ret; 1852 + } 1914 1853 1915 1854 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1916 1855 if (!res) {