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

pinctrl: pinctrl-single: enhance to configure multiple pins of different modules

Add support to configure multiple pins in each register, existing
implementation added by [1] does not support full fledge multiple pin
configuration in single register, reports a pin clash when different
modules configure different bits of same register. The issue reported
and discussed here
http://www.spinics.net/lists/arm-kernel/msg235213.html

With pinctrl-single,bits-per-mux property specified, use function-mask
property to find out number pins to configure. Allocate and register
pin control functions based sub mask.

Tested on da850/omap-l138 EVM.
does not support variable submask for pins.
does not support pinconf.

[1] "pinctrl: pinctrl-single: Add pinctrl-single,bits type of mux"
(9e605cb68a21d5704839a192a46ebcf387773704),

Signed-off-by: Manjunathappa, Prakash <prakash.pm@ti.com>
Reported-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Tested-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Acked-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Manjunathappa, Prakash and committed by
Linus Walleij
4e7e8017 ac844b62

+167 -34
+2 -1
Documentation/devicetree/bindings/pinctrl/pinctrl-single.txt
··· 18 18 pin functions is ignored 19 19 20 20 - pinctrl-single,bit-per-mux : boolean to indicate that one register controls 21 - more than one pin 21 + more than one pin, for which "pinctrl-single,function-mask" property specifies 22 + position mask of pin. 22 23 23 24 - pinctrl-single,drive-strength : array of value that are used to configure 24 25 drive strength in the pinmux register. They're value of drive strength
+165 -33
drivers/pinctrl/pinctrl-single.c
··· 163 163 * @foff: value to turn mux off 164 164 * @fmax: max number of functions in fmask 165 165 * @is_pinconf: whether supports pinconf 166 + * @bits_per_pin:number of bits per pin 166 167 * @names: array of register names for pins 167 168 * @pins: physical pins on the SoC 168 169 * @pgtree: pingroup index radix tree ··· 191 190 unsigned fmax; 192 191 bool bits_per_mux; 193 192 bool is_pinconf; 193 + unsigned bits_per_pin; 194 194 struct pcs_name *names; 195 195 struct pcs_data pins; 196 196 struct radix_tree_root pgtree; ··· 433 431 434 432 vals = &func->vals[i]; 435 433 val = pcs->read(vals->reg); 436 - if (!vals->mask) 437 - mask = pcs->fmask; 434 + 435 + if (pcs->bits_per_mux) 436 + mask = vals->mask; 438 437 else 439 - mask = pcs->fmask & vals->mask; 438 + mask = pcs->fmask; 440 439 441 440 val &= ~mask; 442 441 val |= (vals->val & mask); ··· 782 779 int mux_bytes, nr_pins, i; 783 780 784 781 mux_bytes = pcs->width / BITS_PER_BYTE; 785 - nr_pins = pcs->size / mux_bytes; 782 + 783 + if (pcs->bits_per_mux) { 784 + pcs->bits_per_pin = fls(pcs->fmask); 785 + nr_pins = (pcs->size * BITS_PER_BYTE) / pcs->bits_per_pin; 786 + } else { 787 + nr_pins = pcs->size / mux_bytes; 788 + } 786 789 787 790 dev_dbg(pcs->dev, "allocating %i pins\n", nr_pins); 788 791 pcs->pins.pa = devm_kzalloc(pcs->dev, ··· 809 800 for (i = 0; i < pcs->desc.npins; i++) { 810 801 unsigned offset; 811 802 int res; 803 + int byte_num; 812 804 813 - offset = i * mux_bytes; 805 + if (pcs->bits_per_mux) { 806 + byte_num = (pcs->bits_per_pin * i) / BITS_PER_BYTE; 807 + offset = (byte_num / mux_bytes) * mux_bytes; 808 + } else { 809 + offset = i * mux_bytes; 810 + } 814 811 res = pcs_add_pin(pcs, offset); 815 812 if (res < 0) { 816 813 dev_err(pcs->dev, "error adding pins: %i\n", res); ··· 934 919 return -EINVAL; 935 920 } 936 921 937 - index = offset / (pcs->width / BITS_PER_BYTE); 922 + if (pcs->bits_per_mux) 923 + index = (offset * BITS_PER_BYTE) / pcs->bits_per_pin; 924 + else 925 + index = offset / (pcs->width / BITS_PER_BYTE); 938 926 939 927 return index; 940 928 } ··· 1115 1097 { 1116 1098 struct pcs_func_vals *vals; 1117 1099 const __be32 *mux; 1118 - int size, params, rows, *pins, index = 0, found = 0, res = -ENOMEM; 1100 + int size, rows, *pins, index = 0, found = 0, res = -ENOMEM; 1119 1101 struct pcs_function *function; 1120 1102 1121 - if (pcs->bits_per_mux) { 1122 - params = 3; 1123 - mux = of_get_property(np, PCS_MUX_BITS_NAME, &size); 1124 - } else { 1125 - params = 2; 1126 - mux = of_get_property(np, PCS_MUX_PINS_NAME, &size); 1127 - } 1128 - 1129 - if (!mux) { 1130 - dev_err(pcs->dev, "no valid property for %s\n", np->name); 1131 - return -EINVAL; 1132 - } 1133 - 1134 - if (size < (sizeof(*mux) * params)) { 1135 - dev_err(pcs->dev, "bad data for %s\n", np->name); 1103 + mux = of_get_property(np, PCS_MUX_PINS_NAME, &size); 1104 + if ((!mux) || (size < sizeof(*mux) * 2)) { 1105 + dev_err(pcs->dev, "bad data for mux %s\n", 1106 + np->name); 1136 1107 return -EINVAL; 1137 1108 } 1138 1109 1139 1110 size /= sizeof(*mux); /* Number of elements in array */ 1140 - rows = size / params; 1111 + rows = size / 2; 1141 1112 1142 1113 vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows, GFP_KERNEL); 1143 1114 if (!vals) ··· 1144 1137 val = be32_to_cpup(mux + index++); 1145 1138 vals[found].reg = pcs->base + offset; 1146 1139 vals[found].val = val; 1147 - if (params == 3) { 1148 - val = be32_to_cpup(mux + index++); 1149 - vals[found].mask = val; 1150 - } 1151 1140 1152 1141 pin = pcs_get_pin_by_offset(pcs, offset); 1153 1142 if (pin < 0) { ··· 1192 1189 1193 1190 return res; 1194 1191 } 1192 + 1193 + #define PARAMS_FOR_BITS_PER_MUX 3 1194 + 1195 + static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs, 1196 + struct device_node *np, 1197 + struct pinctrl_map **map, 1198 + unsigned *num_maps, 1199 + const char **pgnames) 1200 + { 1201 + struct pcs_func_vals *vals; 1202 + const __be32 *mux; 1203 + int size, rows, *pins, index = 0, found = 0, res = -ENOMEM; 1204 + int npins_in_row; 1205 + struct pcs_function *function; 1206 + 1207 + mux = of_get_property(np, PCS_MUX_BITS_NAME, &size); 1208 + 1209 + if (!mux) { 1210 + dev_err(pcs->dev, "no valid property for %s\n", np->name); 1211 + return -EINVAL; 1212 + } 1213 + 1214 + if (size < (sizeof(*mux) * PARAMS_FOR_BITS_PER_MUX)) { 1215 + dev_err(pcs->dev, "bad data for %s\n", np->name); 1216 + return -EINVAL; 1217 + } 1218 + 1219 + /* Number of elements in array */ 1220 + size /= sizeof(*mux); 1221 + 1222 + rows = size / PARAMS_FOR_BITS_PER_MUX; 1223 + npins_in_row = pcs->width / pcs->bits_per_pin; 1224 + 1225 + vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows * npins_in_row, 1226 + GFP_KERNEL); 1227 + if (!vals) 1228 + return -ENOMEM; 1229 + 1230 + pins = devm_kzalloc(pcs->dev, sizeof(*pins) * rows * npins_in_row, 1231 + GFP_KERNEL); 1232 + if (!pins) 1233 + goto free_vals; 1234 + 1235 + while (index < size) { 1236 + unsigned offset, val; 1237 + unsigned mask, bit_pos, val_pos, mask_pos, submask; 1238 + unsigned pin_num_from_lsb; 1239 + int pin; 1240 + 1241 + offset = be32_to_cpup(mux + index++); 1242 + val = be32_to_cpup(mux + index++); 1243 + mask = be32_to_cpup(mux + index++); 1244 + 1245 + /* Parse pins in each row from LSB */ 1246 + while (mask) { 1247 + bit_pos = ffs(mask); 1248 + pin_num_from_lsb = bit_pos / pcs->bits_per_pin; 1249 + mask_pos = ((pcs->fmask) << (bit_pos - 1)); 1250 + val_pos = val & mask_pos; 1251 + submask = mask & mask_pos; 1252 + mask &= ~mask_pos; 1253 + 1254 + if (submask != mask_pos) { 1255 + dev_warn(pcs->dev, 1256 + "Invalid submask 0x%x for %s at 0x%x\n", 1257 + submask, np->name, offset); 1258 + continue; 1259 + } 1260 + 1261 + vals[found].mask = submask; 1262 + vals[found].reg = pcs->base + offset; 1263 + vals[found].val = val_pos; 1264 + 1265 + pin = pcs_get_pin_by_offset(pcs, offset); 1266 + if (pin < 0) { 1267 + dev_err(pcs->dev, 1268 + "could not add functions for %s %ux\n", 1269 + np->name, offset); 1270 + break; 1271 + } 1272 + pins[found++] = pin + pin_num_from_lsb; 1273 + } 1274 + } 1275 + 1276 + pgnames[0] = np->name; 1277 + function = pcs_add_function(pcs, np, np->name, vals, found, pgnames, 1); 1278 + if (!function) 1279 + goto free_pins; 1280 + 1281 + res = pcs_add_pingroup(pcs, np, np->name, pins, found); 1282 + if (res < 0) 1283 + goto free_function; 1284 + 1285 + (*map)->type = PIN_MAP_TYPE_MUX_GROUP; 1286 + (*map)->data.mux.group = np->name; 1287 + (*map)->data.mux.function = np->name; 1288 + 1289 + if (pcs->is_pinconf) { 1290 + dev_err(pcs->dev, "pinconf not supported\n"); 1291 + goto free_pingroups; 1292 + } 1293 + 1294 + *num_maps = 1; 1295 + return 0; 1296 + 1297 + free_pingroups: 1298 + pcs_free_pingroups(pcs); 1299 + *num_maps = 1; 1300 + free_function: 1301 + pcs_remove_function(pcs, function); 1302 + 1303 + free_pins: 1304 + devm_kfree(pcs->dev, pins); 1305 + 1306 + free_vals: 1307 + devm_kfree(pcs->dev, vals); 1308 + 1309 + return res; 1310 + } 1195 1311 /** 1196 1312 * pcs_dt_node_to_map() - allocates and parses pinctrl maps 1197 1313 * @pctldev: pinctrl instance ··· 1341 1219 goto free_map; 1342 1220 } 1343 1221 1344 - ret = pcs_parse_one_pinctrl_entry(pcs, np_config, map, num_maps, 1345 - pgnames); 1346 - if (ret < 0) { 1347 - dev_err(pcs->dev, "no pins entries for %s\n", 1348 - np_config->name); 1349 - goto free_pgnames; 1222 + if (pcs->bits_per_mux) { 1223 + ret = pcs_parse_bits_in_pinctrl_entry(pcs, np_config, map, 1224 + num_maps, pgnames); 1225 + if (ret < 0) { 1226 + dev_err(pcs->dev, "no pins entries for %s\n", 1227 + np_config->name); 1228 + goto free_pgnames; 1229 + } 1230 + } else { 1231 + ret = pcs_parse_one_pinctrl_entry(pcs, np_config, map, 1232 + num_maps, pgnames); 1233 + if (ret < 0) { 1234 + dev_err(pcs->dev, "no pins entries for %s\n", 1235 + np_config->name); 1236 + goto free_pgnames; 1237 + } 1350 1238 } 1351 1239 1352 1240 return 0;