Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 1 | diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 2 | index 8b94aa8f5971..2723e6143aa9 100644 |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 3 | --- a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt |
| 4 | +++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt |
| 5 | @@ -144,3 +144,38 @@ gpio21: gpio@21 { |
| 6 | bias-pull-up; |
| 7 | }; |
| 8 | }; |
| 9 | + |
| 10 | +Line naming |
| 11 | +=========== |
| 12 | + |
| 13 | +Because several gpio_chip instances are hidden below a single device tree |
| 14 | +node, it is necessary to split the names into several child nodes. Ensure |
| 15 | +that the configured addresses match those in the microchip,spi-present-mask: |
| 16 | + |
| 17 | +gpio@0 { |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 18 | + compatible = "microchip,mcp23s17"; |
| 19 | + gpio-controller; |
| 20 | + #gpio-cells = <2>; |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 21 | + /* this bitmask has bits #0 (0x01) and #2 (0x04) set */ |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 22 | + spi-present-mask = <0x05>; |
| 23 | + reg = <0>; |
| 24 | + spi-max-frequency = <1000000>; |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 25 | + |
| 26 | + gpio-bank@1 { |
| 27 | + address = <0>; |
| 28 | + gpio-line-names = |
| 29 | + "GPA0", |
| 30 | + "GPA1", |
| 31 | + ... |
| 32 | + "GPA7", |
| 33 | + "GPB0", |
| 34 | + "GPB1", |
| 35 | + ... |
| 36 | + "GPB7"; |
| 37 | + }; |
| 38 | + |
| 39 | + gpio-bank@2 { |
| 40 | + address = <2>; |
| 41 | + gpio-line-names = ... |
| 42 | + }; |
| 43 | +}; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 44 | diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c |
| 45 | index 80137c1b3cdc..8d1c49a289eb 100644 |
| 46 | --- a/drivers/gpio/gpiolib.c |
| 47 | +++ b/drivers/gpio/gpiolib.c |
| 48 | @@ -1727,11 +1727,6 @@ static inline void gpiochip_irqchip_free_valid_mask(struct gpio_chip *gc) |
| 49 | */ |
| 50 | int gpiochip_generic_request(struct gpio_chip *gc, unsigned offset) |
| 51 | { |
| 52 | -#ifdef CONFIG_PINCTRL |
| 53 | - if (list_empty(&gc->gpiodev->pin_ranges)) |
| 54 | - return 0; |
| 55 | -#endif |
| 56 | - |
| 57 | return pinctrl_gpio_request(gc->gpiodev->base + offset); |
| 58 | } |
| 59 | EXPORT_SYMBOL_GPL(gpiochip_generic_request); |
| 60 | diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h |
| 61 | index 18e06fc6c53f..5c0f429ed7ad 100644 |
| 62 | --- a/drivers/hwmon/pmbus/pmbus.h |
| 63 | +++ b/drivers/hwmon/pmbus/pmbus.h |
| 64 | @@ -361,7 +361,7 @@ enum pmbus_sensor_classes { |
| 65 | PSC_NUM_CLASSES /* Number of power sensor classes */ |
| 66 | }; |
| 67 | |
| 68 | -#define PMBUS_PAGES 32 /* Per PMBus specification */ |
| 69 | +#define PMBUS_PAGES 255 /* Per PMBus specification */ |
| 70 | #define PMBUS_PHASES 8 /* Maximum number of phases per page */ |
| 71 | |
| 72 | /* Functionality bit mask */ |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 73 | diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 74 | index 0929f1275814..710c56cba818 100644 |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 75 | --- a/drivers/leds/leds-tlc591xx.c |
| 76 | +++ b/drivers/leds/leds-tlc591xx.c |
Jan Kundrát | f97c81d | 2020-02-06 00:33:19 +0100 | [diff] [blame] | 77 | @@ -40,6 +40,9 @@ |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 78 | |
| 79 | #define ldev_to_led(c) container_of(c, struct tlc591xx_led, ldev) |
| 80 | |
| 81 | +#define TLC591XX_RESET_BYTE_0 0xa5 |
| 82 | +#define TLC591XX_RESET_BYTE_1 0x5a |
| 83 | + |
| 84 | struct tlc591xx_led { |
| 85 | bool active; |
| 86 | unsigned int led_no; |
Jan Kundrát | f97c81d | 2020-02-06 00:33:19 +0100 | [diff] [blame] | 87 | @@ -51,21 +54,25 @@ struct tlc591xx_priv { |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 88 | struct tlc591xx_led leds[TLC591XX_MAX_LEDS]; |
| 89 | struct regmap *regmap; |
| 90 | unsigned int reg_ledout_offset; |
| 91 | + struct i2c_client *swrst_client; |
| 92 | }; |
| 93 | |
| 94 | struct tlc591xx { |
| 95 | unsigned int max_leds; |
| 96 | unsigned int reg_ledout_offset; |
| 97 | + u8 swrst_addr; |
| 98 | }; |
| 99 | |
| 100 | static const struct tlc591xx tlc59116 = { |
| 101 | .max_leds = 16, |
| 102 | .reg_ledout_offset = 0x14, |
| 103 | + .swrst_addr = 0x6b, |
| 104 | }; |
| 105 | |
| 106 | static const struct tlc591xx tlc59108 = { |
| 107 | .max_leds = 8, |
| 108 | .reg_ledout_offset = 0x0c, |
| 109 | + .swrst_addr = 0x4b, |
| 110 | }; |
| 111 | |
| 112 | static int |
Jan Kundrát | 31bf7ae | 2020-02-14 17:03:53 +0100 | [diff] [blame] | 113 | @@ -181,6 +188,18 @@ tlc591xx_probe(struct i2c_client *client, |
| 114 | |
| 115 | i2c_set_clientdata(client, priv); |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 116 | |
Jan Kundrát | f97c81d | 2020-02-06 00:33:19 +0100 | [diff] [blame] | 117 | + priv->swrst_client = devm_i2c_new_dummy_device(dev, client->adapter, tlc591xx->swrst_addr); |
Jan Kundrát | 89b682a | 2020-03-08 13:03:33 -0700 | [diff] [blame] | 118 | + if (IS_ERR(priv->swrst_client)) { |
| 119 | + dev_info(dev, "Skipping reset: address %02x already used\n", |
| 120 | + tlc591xx->swrst_addr); |
| 121 | + } else { |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 122 | + err = i2c_smbus_write_byte_data(priv->swrst_client, |
| 123 | + TLC591XX_RESET_BYTE_0, TLC591XX_RESET_BYTE_1); |
| 124 | + if (err) { |
| 125 | + dev_warn(dev, "SW reset failed\n"); |
| 126 | + } |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 127 | + } |
| 128 | + |
Jan Kundrát | 31bf7ae | 2020-02-14 17:03:53 +0100 | [diff] [blame] | 129 | err = tlc591xx_set_mode(priv->regmap, MODE2_DIM); |
| 130 | if (err < 0) |
| 131 | return err; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 132 | diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c |
| 133 | index c39978b750ec..653c0b3d2912 100644 |
| 134 | --- a/drivers/pci/controller/pci-mvebu.c |
| 135 | +++ b/drivers/pci/controller/pci-mvebu.c |
| 136 | @@ -960,25 +960,16 @@ static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port) |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | - * We can't use devm_of_pci_get_host_bridge_resources() because we |
| 141 | - * need to parse our special DT properties encoding the MEM and IO |
| 142 | - * apertures. |
| 143 | + * devm_of_pci_get_host_bridge_resources() only sets up translateable resources, |
| 144 | + * so we need extra resource setup parsing our special DT properties encoding |
| 145 | + * the MEM and IO apertures. |
| 146 | */ |
| 147 | static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie) |
| 148 | { |
| 149 | struct device *dev = &pcie->pdev->dev; |
| 150 | - struct device_node *np = dev->of_node; |
| 151 | struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); |
| 152 | int ret; |
| 153 | |
| 154 | - /* Get the bus range */ |
| 155 | - ret = of_pci_parse_bus_range(np, &pcie->busn); |
| 156 | - if (ret) { |
| 157 | - dev_err(dev, "failed to parse bus-range property: %d\n", ret); |
| 158 | - return ret; |
| 159 | - } |
| 160 | - pci_add_resource(&bridge->windows, &pcie->busn); |
| 161 | - |
| 162 | /* Get the PCIe memory aperture */ |
| 163 | mvebu_mbus_get_pcie_mem_aperture(&pcie->mem); |
| 164 | if (resource_size(&pcie->mem) == 0) { |
| 165 | @@ -988,6 +979,9 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie) |
| 166 | |
| 167 | pcie->mem.name = "PCI MEM"; |
| 168 | pci_add_resource(&bridge->windows, &pcie->mem); |
| 169 | + ret = devm_request_resource(dev, &iomem_resource, &pcie->mem); |
| 170 | + if (ret) |
| 171 | + return ret; |
| 172 | |
| 173 | /* Get the PCIe IO aperture */ |
| 174 | mvebu_mbus_get_pcie_io_aperture(&pcie->io); |
| 175 | @@ -1001,9 +995,12 @@ static int mvebu_pcie_parse_request_resources(struct mvebu_pcie *pcie) |
| 176 | pcie->realio.name = "PCI I/O"; |
| 177 | |
| 178 | pci_add_resource(&bridge->windows, &pcie->realio); |
| 179 | + ret = devm_request_resource(dev, &ioport_resource, &pcie->realio); |
| 180 | + if (ret) |
| 181 | + return ret; |
| 182 | } |
| 183 | |
| 184 | - return devm_request_pci_bus_resources(dev, &bridge->windows); |
| 185 | + return 0; |
| 186 | } |
| 187 | |
| 188 | /* |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 189 | diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 190 | index 42b12ea14d6b..ce2d8014b7e0 100644 |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 191 | --- a/drivers/pinctrl/pinctrl-mcp23s08.c |
| 192 | +++ b/drivers/pinctrl/pinctrl-mcp23s08.c |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 193 | @@ -87,7 +87,7 @@ const struct regmap_config mcp23x08_regmap = { |
| 194 | }; |
| 195 | EXPORT_SYMBOL_GPL(mcp23x08_regmap); |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 196 | |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 197 | -static const struct reg_default mcp23x16_defaults[] = { |
| 198 | +static const struct reg_default mcp23x17_defaults[] = { |
| 199 | {.reg = MCP_IODIR << 1, .def = 0xffff}, |
| 200 | {.reg = MCP_IPOL << 1, .def = 0x0000}, |
| 201 | {.reg = MCP_GPINTEN << 1, .def = 0x0000}, |
| 202 | @@ -98,23 +98,23 @@ static const struct reg_default mcp23x16_defaults[] = { |
| 203 | {.reg = MCP_OLAT << 1, .def = 0x0000}, |
| 204 | }; |
| 205 | |
| 206 | -static const struct regmap_range mcp23x16_volatile_range = { |
| 207 | +static const struct regmap_range mcp23x17_volatile_range = { |
| 208 | .range_min = MCP_INTF << 1, |
| 209 | .range_max = MCP_GPIO << 1, |
| 210 | }; |
| 211 | |
| 212 | -static const struct regmap_access_table mcp23x16_volatile_table = { |
| 213 | - .yes_ranges = &mcp23x16_volatile_range, |
| 214 | +static const struct regmap_access_table mcp23x17_volatile_table = { |
| 215 | + .yes_ranges = &mcp23x17_volatile_range, |
| 216 | .n_yes_ranges = 1, |
| 217 | }; |
| 218 | |
| 219 | -static const struct regmap_range mcp23x16_precious_range = { |
| 220 | - .range_min = MCP_GPIO << 1, |
| 221 | +static const struct regmap_range mcp23x17_precious_range = { |
| 222 | + .range_min = MCP_INTCAP << 1, |
| 223 | .range_max = MCP_GPIO << 1, |
| 224 | }; |
| 225 | |
| 226 | -static const struct regmap_access_table mcp23x16_precious_table = { |
| 227 | - .yes_ranges = &mcp23x16_precious_range, |
| 228 | +static const struct regmap_access_table mcp23x17_precious_table = { |
| 229 | + .yes_ranges = &mcp23x17_precious_range, |
| 230 | .n_yes_ranges = 1, |
| 231 | }; |
| 232 | |
| 233 | @@ -124,10 +124,10 @@ const struct regmap_config mcp23x17_regmap = { |
| 234 | |
| 235 | .reg_stride = 2, |
| 236 | .max_register = MCP_OLAT << 1, |
| 237 | - .volatile_table = &mcp23x16_volatile_table, |
| 238 | - .precious_table = &mcp23x16_precious_table, |
| 239 | - .reg_defaults = mcp23x16_defaults, |
| 240 | - .num_reg_defaults = ARRAY_SIZE(mcp23x16_defaults), |
| 241 | + .volatile_table = &mcp23x17_volatile_table, |
| 242 | + .precious_table = &mcp23x17_precious_table, |
| 243 | + .reg_defaults = mcp23x17_defaults, |
| 244 | + .num_reg_defaults = ARRAY_SIZE(mcp23x17_defaults), |
| 245 | .cache_type = REGCACHE_FLAT, |
| 246 | .val_format_endian = REGMAP_ENDIAN_LITTLE, |
| 247 | }; |
| 248 | @@ -564,7 +564,7 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, |
| 249 | |
| 250 | ret = mcp_read(mcp, MCP_IOCON, &status); |
| 251 | if (ret < 0) |
| 252 | - goto fail; |
| 253 | + return dev_err_probe(dev, ret, "can't identify chip %d\n", addr); |
| 254 | |
| 255 | mcp->irq_controller = |
| 256 | device_property_read_bool(dev, "interrupt-controller"); |
| 257 | @@ -598,7 +598,7 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, |
| 258 | |
| 259 | ret = mcp_write(mcp, MCP_IOCON, status); |
| 260 | if (ret < 0) |
| 261 | - goto fail; |
| 262 | + return dev_err_probe(dev, ret, "can't write IOCON %d\n", addr); |
| 263 | } |
| 264 | |
| 265 | if (mcp->irq && mcp->irq_controller) { |
| 266 | @@ -616,7 +616,7 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, |
| 267 | |
| 268 | ret = devm_gpiochip_add_data(dev, &mcp->chip, mcp); |
| 269 | if (ret < 0) |
| 270 | - goto fail; |
| 271 | + return dev_err_probe(dev, ret, "can't add GPIO chip\n"); |
| 272 | |
| 273 | mcp->pinctrl_desc.pctlops = &mcp_pinctrl_ops; |
| 274 | mcp->pinctrl_desc.confops = &mcp_pinconf_ops; |
| 275 | @@ -628,18 +628,17 @@ int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev, |
| 276 | mcp->pinctrl_desc.owner = THIS_MODULE; |
| 277 | |
| 278 | mcp->pctldev = devm_pinctrl_register(dev, &mcp->pinctrl_desc, mcp); |
| 279 | - if (IS_ERR(mcp->pctldev)) { |
| 280 | - ret = PTR_ERR(mcp->pctldev); |
| 281 | - goto fail; |
| 282 | - } |
| 283 | + if (IS_ERR(mcp->pctldev)) |
| 284 | + return dev_err_probe(dev, PTR_ERR(mcp->pctldev), "can't register controller\n"); |
| 285 | |
| 286 | - if (mcp->irq) |
| 287 | + if (mcp->irq) { |
| 288 | ret = mcp23s08_irq_setup(mcp); |
| 289 | + if (ret) |
| 290 | + return dev_err_probe(dev, ret, "can't setup IRQ\n"); |
| 291 | + } |
| 292 | |
| 293 | -fail: |
| 294 | - if (ret < 0) |
| 295 | - dev_dbg(dev, "can't setup chip %d, --> %d\n", addr, ret); |
| 296 | - return ret; |
| 297 | + return 0; |
| 298 | } |
| 299 | EXPORT_SYMBOL_GPL(mcp23s08_probe_one); |
| 300 | + |
| 301 | MODULE_LICENSE("GPL"); |
| 302 | diff --git a/drivers/pinctrl/pinctrl-mcp23s08_spi.c b/drivers/pinctrl/pinctrl-mcp23s08_spi.c |
| 303 | index 1f47a661b0a7..3271e304c985 100644 |
| 304 | --- a/drivers/pinctrl/pinctrl-mcp23s08_spi.c |
| 305 | +++ b/drivers/pinctrl/pinctrl-mcp23s08_spi.c |
| 306 | @@ -119,13 +119,15 @@ static int mcp23s08_spi_regmap_init(struct mcp23s08 *mcp, struct device *dev, |
| 307 | return -EINVAL; |
| 308 | } |
| 309 | |
| 310 | - copy = devm_kmemdup(dev, &config, sizeof(config), GFP_KERNEL); |
| 311 | + copy = devm_kmemdup(dev, config, sizeof(*config), GFP_KERNEL); |
| 312 | if (!copy) |
| 313 | return -ENOMEM; |
| 314 | |
| 315 | copy->name = name; |
| 316 | |
| 317 | mcp->regmap = devm_regmap_init(dev, &mcp23sxx_spi_regmap, mcp, copy); |
| 318 | + if (IS_ERR(mcp->regmap)) |
| 319 | + dev_err(dev, "regmap init failed for %s\n", mcp->chip.label); |
| 320 | return PTR_ERR_OR_ZERO(mcp->regmap); |
| 321 | } |
| 322 | |
| 323 | @@ -141,6 +143,7 @@ static int mcp23s08_probe(struct spi_device *spi) |
| 324 | int type; |
| 325 | int ret; |
| 326 | u32 v; |
| 327 | + struct device_node *np; |
| 328 | |
| 329 | match = device_get_match_data(dev); |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 330 | if (match) |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 331 | @@ -190,6 +193,16 @@ static int mcp23s08_probe(struct spi_device *spi) |
| 332 | return ret; |
| 333 | |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 334 | ngpio += data->mcp[addr]->chip.ngpio; |
| 335 | + |
| 336 | + for_each_available_child_of_node(spi->dev.of_node, np) { |
| 337 | + u32 chip_addr; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 338 | + ret = of_property_read_u32(np, "address", &chip_addr); |
| 339 | + if (ret) |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 340 | + continue; |
| 341 | + if (chip_addr != addr) |
| 342 | + continue; |
| 343 | + devprop_gpiochip_set_names(&data->mcp[addr]->chip, of_fwnode_handle(np)); |
| 344 | + } |
| 345 | } |
| 346 | data->ngpio = ngpio; |
| 347 | |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 348 | diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 349 | index b57b8b3cc26e..5dc323643522 100644 |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 350 | --- a/drivers/spi/spi-orion.c |
| 351 | +++ b/drivers/spi/spi-orion.c |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 352 | @@ -17,8 +17,10 @@ |
| 353 | #include <linux/of.h> |
| 354 | #include <linux/of_address.h> |
| 355 | #include <linux/of_device.h> |
| 356 | +#include <linux/of_gpio.h> |
| 357 | #include <linux/clk.h> |
| 358 | #include <linux/sizes.h> |
| 359 | +#include <linux/gpio.h> |
| 360 | #include <asm/unaligned.h> |
| 361 | |
| 362 | #define DRIVER_NAME "orion_spi" |
| 363 | @@ -86,18 +88,15 @@ struct orion_direct_acc { |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 364 | u32 size; |
| 365 | }; |
| 366 | |
| 367 | -struct orion_child_options { |
| 368 | - struct orion_direct_acc direct_access; |
| 369 | -}; |
| 370 | - |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 371 | struct orion_spi { |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 372 | struct spi_master *master; |
| 373 | void __iomem *base; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 374 | struct clk *clk; |
| 375 | struct clk *axi_clk; |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 376 | const struct orion_spi_dev *devdata; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 377 | + int unused_hw_gpio; |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 378 | |
| 379 | - struct orion_child_options child[ORION_NUM_CHIPSELECTS]; |
| 380 | + struct orion_direct_acc direct_access[ORION_NUM_CHIPSELECTS]; |
| 381 | }; |
| 382 | |
| 383 | static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg) |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 384 | @@ -322,27 +321,20 @@ orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) |
| 385 | static void orion_spi_set_cs(struct spi_device *spi, bool enable) |
| 386 | { |
| 387 | struct orion_spi *orion_spi; |
| 388 | + int cs; |
| 389 | |
| 390 | orion_spi = spi_master_get_devdata(spi->master); |
| 391 | |
| 392 | - /* |
| 393 | - * If this line is using a GPIO to control chip select, this internal |
| 394 | - * .set_cs() function will still be called, so we clear any previous |
| 395 | - * chip select. The CS we activate will not have any elecrical effect, |
| 396 | - * as it is handled by a GPIO, but that doesn't matter. What we need |
| 397 | - * is to deassert the old chip select and assert some other chip select. |
| 398 | - */ |
| 399 | + if (gpio_is_valid(spi->cs_gpio)) |
| 400 | + cs = orion_spi->unused_hw_gpio; |
| 401 | + else |
| 402 | + cs = spi->chip_select; |
| 403 | + |
| 404 | orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS_MASK); |
| 405 | orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, |
| 406 | - ORION_SPI_CS(spi->chip_select)); |
| 407 | + ORION_SPI_CS(cs)); |
| 408 | |
| 409 | - /* |
| 410 | - * Chip select logic is inverted from spi_set_cs(). For lines using a |
| 411 | - * GPIO to do chip select SPI_CS_HIGH is enforced and inversion happens |
| 412 | - * in the GPIO library, but we don't care about that, because in those |
| 413 | - * cases we are dealing with an unused native CS anyways so the polarity |
| 414 | - * doesn't matter. |
| 415 | - */ |
| 416 | + /* Chip select logic is inverted from spi_set_cs */ |
| 417 | if (!enable) |
| 418 | orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1); |
| 419 | else |
| 420 | @@ -434,7 +426,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 421 | int cs = spi->chip_select; |
Jan Kundrát | 549db87 | 2019-03-05 12:23:25 +0100 | [diff] [blame] | 422 | void __iomem *vaddr; |
Jan Kundrát | 2501643 | 2019-03-04 21:40:58 +0100 | [diff] [blame] | 423 | |
| 424 | - word_len = spi->bits_per_word; |
| 425 | + word_len = xfer->bits_per_word; |
| 426 | count = xfer->len; |
| 427 | |
| 428 | orion_spi = spi_master_get_devdata(spi->master); |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 429 | @@ -443,7 +435,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 430 | * Use SPI direct write mode if base address is available. Otherwise |
| 431 | * fall back to PIO mode for this transfer. |
| 432 | */ |
| 433 | - vaddr = orion_spi->child[cs].direct_access.vaddr; |
| 434 | + vaddr = orion_spi->direct_access[cs].vaddr; |
| 435 | |
| 436 | if (vaddr && xfer->tx_buf && word_len == 8) { |
| 437 | unsigned int cnt = count / 4; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 438 | @@ -507,6 +499,9 @@ static int orion_spi_transfer_one(struct spi_master *master, |
| 439 | |
| 440 | static int orion_spi_setup(struct spi_device *spi) |
| 441 | { |
| 442 | + if (gpio_is_valid(spi->cs_gpio)) { |
| 443 | + gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); |
| 444 | + } |
| 445 | return orion_spi_setup_transfer(spi, NULL); |
| 446 | } |
| 447 | |
| 448 | @@ -623,13 +618,13 @@ static int orion_spi_probe(struct platform_device *pdev) |
| 449 | master->setup = orion_spi_setup; |
| 450 | master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); |
| 451 | master->auto_runtime_pm = true; |
| 452 | - master->use_gpio_descriptors = true; |
| 453 | master->flags = SPI_MASTER_GPIO_SS; |
| 454 | |
| 455 | platform_set_drvdata(pdev, master); |
| 456 | |
| 457 | spi = spi_master_get_devdata(master); |
| 458 | spi->master = master; |
| 459 | + spi->unused_hw_gpio = -1; |
| 460 | |
| 461 | of_id = of_match_device(orion_spi_of_match_table, &pdev->dev); |
| 462 | devdata = (of_id) ? of_id->data : &orion_spi_dev_data; |
| 463 | @@ -682,8 +677,8 @@ static int orion_spi_probe(struct platform_device *pdev) |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | for_each_available_child_of_node(pdev->dev.of_node, np) { |
| 467 | - struct orion_direct_acc *dir_acc; |
| 468 | u32 cs; |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 469 | + int cs_gpio; |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 470 | |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 471 | /* Get chip-select number from the "reg" property */ |
| 472 | status = of_property_read_u32(np, "reg", &cs); |
| 473 | @@ -694,6 +689,44 @@ static int orion_spi_probe(struct platform_device *pdev) |
| 474 | continue; |
| 475 | } |
| 476 | |
| 477 | + /* |
| 478 | + * Initialize the CS GPIO: |
| 479 | + * - properly request the actual GPIO signal |
| 480 | + * - de-assert the logical signal so that all GPIO CS lines |
| 481 | + * are inactive when probing for slaves |
| 482 | + * - find an unused physical CS which will be driven for any |
| 483 | + * slave which uses a CS GPIO |
| 484 | + */ |
| 485 | + cs_gpio = of_get_named_gpio(pdev->dev.of_node, "cs-gpios", cs); |
| 486 | + if (cs_gpio > 0) { |
| 487 | + char *gpio_name; |
| 488 | + int cs_flags; |
| 489 | + |
| 490 | + if (spi->unused_hw_gpio == -1) { |
| 491 | + dev_info(&pdev->dev, |
| 492 | + "Selected unused HW CS#%d for any GPIO CSes\n", |
| 493 | + cs); |
| 494 | + spi->unused_hw_gpio = cs; |
| 495 | + } |
| 496 | + |
| 497 | + gpio_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, |
| 498 | + "%s-CS%d", dev_name(&pdev->dev), cs); |
| 499 | + if (!gpio_name) { |
| 500 | + status = -ENOMEM; |
| 501 | + goto out_rel_axi_clk; |
| 502 | + } |
| 503 | + |
| 504 | + cs_flags = of_property_read_bool(np, "spi-cs-high") ? |
| 505 | + GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH; |
| 506 | + status = devm_gpio_request_one(&pdev->dev, cs_gpio, |
| 507 | + cs_flags, gpio_name); |
| 508 | + if (status) { |
| 509 | + dev_err(&pdev->dev, |
| 510 | + "Can't request GPIO for CS %d\n", cs); |
| 511 | + goto out_rel_axi_clk; |
| 512 | + } |
| 513 | + } |
| 514 | + |
| 515 | /* |
| 516 | * Check if an address is configured for this SPI device. If |
| 517 | * not, the MBus mapping via the 'ranges' property in the 'soc' |
| 518 | @@ -711,13 +744,14 @@ static int orion_spi_probe(struct platform_device *pdev) |
| 519 | * This needs to get extended for the direct SPI NOR / SPI NAND |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 520 | * support, once this gets implemented. |
| 521 | */ |
| 522 | - dir_acc = &spi->child[cs].direct_access; |
| 523 | - dir_acc->vaddr = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE); |
| 524 | - if (!dir_acc->vaddr) { |
| 525 | + spi->direct_access[cs].vaddr = devm_ioremap(&pdev->dev, |
| 526 | + r->start, |
| 527 | + PAGE_SIZE); |
| 528 | + if (!spi->direct_access[cs].vaddr) { |
| 529 | status = -ENOMEM; |
| 530 | goto out_rel_axi_clk; |
| 531 | } |
| 532 | - dir_acc->size = PAGE_SIZE; |
| 533 | + spi->direct_access[cs].size = PAGE_SIZE; |
| 534 | |
| 535 | dev_info(&pdev->dev, "CS%d configured for direct access\n", cs); |
| 536 | } |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 537 | diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 538 | index 8434bd5a8ec7..7db66392fcd5 100644 |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 539 | --- a/drivers/tty/serial/max310x.c |
| 540 | +++ b/drivers/tty/serial/max310x.c |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 541 | @@ -235,6 +235,10 @@ |
| 542 | #define MAX310x_REV_MASK (0xf8) |
| 543 | #define MAX310X_WRITE_BIT 0x80 |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 544 | |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 545 | +/* Timeout for external crystal stability */ |
| 546 | +#define MAX310X_XTAL_WAIT_RETRIES 20 |
| 547 | +#define MAX310X_XTAL_WAIT_DELAY_MS 10 |
| 548 | + |
| 549 | /* MAX3107 specific */ |
| 550 | #define MAX3107_REV_ID (0xa0) |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 551 | |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 552 | @@ -610,11 +614,14 @@ static int max310x_set_ref_clk(struct device *dev, struct max310x_port *s, |
| 553 | |
| 554 | /* Wait for crystal */ |
| 555 | if (xtal) { |
| 556 | - unsigned int val; |
| 557 | - msleep(10); |
| 558 | - regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); |
| 559 | + unsigned int val = 0, i; |
| 560 | + for (i = 0; i < MAX310X_XTAL_WAIT_RETRIES && !(val & MAX310X_STS_CLKREADY_BIT); ++i) { |
| 561 | + msleep(MAX310X_XTAL_WAIT_DELAY_MS); |
| 562 | + regmap_read(s->regmap, MAX310X_STS_IRQSTS_REG, &val); |
| 563 | + } |
| 564 | if (!(val & MAX310X_STS_CLKREADY_BIT)) { |
| 565 | - dev_warn(dev, "clock is not stable yet\n"); |
| 566 | + dev_err(dev, "clock is not stable\n"); |
| 567 | + return -EAGAIN; |
| 568 | } |
| 569 | } |
| 570 | |
Jan Kundrát | 0341eea | 2020-10-16 18:06:38 +0200 | [diff] [blame] | 571 | @@ -1056,9 +1063,9 @@ static int max310x_startup(struct uart_port *port) |
| 572 | max310x_port_update(port, MAX310X_MODE1_REG, |
| 573 | MAX310X_MODE1_TRNSCVCTRL_BIT, 0); |
| 574 | |
| 575 | - /* Configure MODE2 register & Reset FIFOs*/ |
| 576 | - val = MAX310X_MODE2_RXEMPTINV_BIT | MAX310X_MODE2_FIFORST_BIT; |
| 577 | - max310x_port_write(port, MAX310X_MODE2_REG, val); |
| 578 | + /* Reset FIFOs */ |
| 579 | + max310x_port_write(port, MAX310X_MODE2_REG, |
| 580 | + MAX310X_MODE2_FIFORST_BIT); |
| 581 | max310x_port_update(port, MAX310X_MODE2_REG, |
| 582 | MAX310X_MODE2_FIFORST_BIT, 0); |
| 583 | |
| 584 | @@ -1086,8 +1093,27 @@ static int max310x_startup(struct uart_port *port) |
| 585 | /* Clear IRQ status register */ |
| 586 | max310x_port_read(port, MAX310X_IRQSTS_REG); |
| 587 | |
| 588 | - /* Enable RX, TX, CTS change interrupts */ |
| 589 | - val = MAX310X_IRQ_RXEMPTY_BIT | MAX310X_IRQ_TXEMPTY_BIT; |
| 590 | + /* |
| 591 | + * Let's ask for an interrupt after a timeout equivalent to |
| 592 | + * the receiving time of 4 characters after the last character |
| 593 | + * has been received. |
| 594 | + */ |
| 595 | + max310x_port_write(port, MAX310X_RXTO_REG, 4); |
| 596 | + |
| 597 | + /* |
| 598 | + * Make sure we also get RX interrupts when the RX FIFO is |
| 599 | + * filling up quickly, so get an interrupt when half of the RX |
| 600 | + * FIFO has been filled in. |
| 601 | + */ |
| 602 | + max310x_port_write(port, MAX310X_FIFOTRIGLVL_REG, |
| 603 | + MAX310X_FIFOTRIGLVL_RX(MAX310X_FIFO_SIZE / 2)); |
| 604 | + |
| 605 | + /* Enable RX timeout interrupt in LSR */ |
| 606 | + max310x_port_write(port, MAX310X_LSR_IRQEN_REG, |
| 607 | + MAX310X_LSR_RXTO_BIT); |
| 608 | + |
| 609 | + /* Enable LSR, RX FIFO trigger, CTS change interrupts */ |
| 610 | + val = MAX310X_IRQ_LSR_BIT | MAX310X_IRQ_RXFIFO_BIT | MAX310X_IRQ_TXEMPTY_BIT; |
| 611 | max310x_port_write(port, MAX310X_IRQEN_REG, val | MAX310X_IRQ_CTS_BIT); |
| 612 | |
| 613 | return 0; |
| 614 | @@ -1327,6 +1353,10 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype, |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | uartclk = max310x_set_ref_clk(dev, s, freq, xtal); |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 618 | + if (uartclk < 0) { |
| 619 | + ret = uartclk; |
| 620 | + goto out_uart; |
| 621 | + } |
| 622 | dev_dbg(dev, "Reference clock set to %i Hz\n", uartclk); |
Jan Kundrát | e7d2162 | 2019-03-28 22:52:38 +0100 | [diff] [blame] | 623 | |
Jan Kundrát | 2bfe9ee | 2019-12-04 13:42:07 +0100 | [diff] [blame] | 624 | for (i = 0; i < devtype->nr; i++) { |