1d7af6a48SSimon Glass /* 2d7af6a48SSimon Glass * Copyright (c) 2014 Google, Inc 3d7af6a48SSimon Glass * 4d7af6a48SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 5d7af6a48SSimon Glass */ 6d7af6a48SSimon Glass 7d7af6a48SSimon Glass #include <common.h> 8d7af6a48SSimon Glass #include <dm.h> 9d7af6a48SSimon Glass #include <errno.h> 10d7af6a48SSimon Glass #include <fdtdec.h> 11d7af6a48SSimon Glass #include <malloc.h> 12d7af6a48SSimon Glass #include <spi.h> 13d7af6a48SSimon Glass #include <dm/device-internal.h> 14d7af6a48SSimon Glass #include <dm/uclass-internal.h> 15d7af6a48SSimon Glass #include <dm/lists.h> 16d7af6a48SSimon Glass #include <dm/util.h> 17d7af6a48SSimon Glass 18d7af6a48SSimon Glass DECLARE_GLOBAL_DATA_PTR; 19d7af6a48SSimon Glass 20d7af6a48SSimon Glass static int spi_set_speed_mode(struct udevice *bus, int speed, int mode) 21d7af6a48SSimon Glass { 22d7af6a48SSimon Glass struct dm_spi_ops *ops; 23d7af6a48SSimon Glass int ret; 24d7af6a48SSimon Glass 25d7af6a48SSimon Glass ops = spi_get_ops(bus); 26d7af6a48SSimon Glass if (ops->set_speed) 27d7af6a48SSimon Glass ret = ops->set_speed(bus, speed); 28d7af6a48SSimon Glass else 29d7af6a48SSimon Glass ret = -EINVAL; 30d7af6a48SSimon Glass if (ret) { 31d7af6a48SSimon Glass printf("Cannot set speed (err=%d)\n", ret); 32d7af6a48SSimon Glass return ret; 33d7af6a48SSimon Glass } 34d7af6a48SSimon Glass 35d7af6a48SSimon Glass if (ops->set_mode) 36d7af6a48SSimon Glass ret = ops->set_mode(bus, mode); 37d7af6a48SSimon Glass else 38d7af6a48SSimon Glass ret = -EINVAL; 39d7af6a48SSimon Glass if (ret) { 40d7af6a48SSimon Glass printf("Cannot set mode (err=%d)\n", ret); 41d7af6a48SSimon Glass return ret; 42d7af6a48SSimon Glass } 43d7af6a48SSimon Glass 44d7af6a48SSimon Glass return 0; 45d7af6a48SSimon Glass } 46d7af6a48SSimon Glass 477a3eff4cSPeng Fan int dm_spi_claim_bus(struct udevice *dev) 48d7af6a48SSimon Glass { 49d7af6a48SSimon Glass struct udevice *bus = dev->parent; 50d7af6a48SSimon Glass struct dm_spi_ops *ops = spi_get_ops(bus); 51e564f054SSimon Glass struct dm_spi_bus *spi = dev_get_uclass_priv(bus); 527a3eff4cSPeng Fan struct spi_slave *slave = dev_get_parent_priv(dev); 53d7af6a48SSimon Glass int speed; 54d7af6a48SSimon Glass int ret; 55d7af6a48SSimon Glass 56d7af6a48SSimon Glass speed = slave->max_hz; 57d7af6a48SSimon Glass if (spi->max_hz) { 58d7af6a48SSimon Glass if (speed) 59b4141195SMasahiro Yamada speed = min(speed, (int)spi->max_hz); 60d7af6a48SSimon Glass else 61d7af6a48SSimon Glass speed = spi->max_hz; 62d7af6a48SSimon Glass } 63d7af6a48SSimon Glass if (!speed) 64d7af6a48SSimon Glass speed = 100000; 6560e2809aSSimon Glass if (speed != slave->speed) { 66d7af6a48SSimon Glass ret = spi_set_speed_mode(bus, speed, slave->mode); 67d7af6a48SSimon Glass if (ret) 68d7af6a48SSimon Glass return ret; 6960e2809aSSimon Glass slave->speed = speed; 7060e2809aSSimon Glass } 71d7af6a48SSimon Glass 729694b724SSimon Glass return ops->claim_bus ? ops->claim_bus(dev) : 0; 73d7af6a48SSimon Glass } 74d7af6a48SSimon Glass 757a3eff4cSPeng Fan void dm_spi_release_bus(struct udevice *dev) 76d7af6a48SSimon Glass { 77d7af6a48SSimon Glass struct udevice *bus = dev->parent; 78d7af6a48SSimon Glass struct dm_spi_ops *ops = spi_get_ops(bus); 79d7af6a48SSimon Glass 80d7af6a48SSimon Glass if (ops->release_bus) 819694b724SSimon Glass ops->release_bus(dev); 82d7af6a48SSimon Glass } 83d7af6a48SSimon Glass 847a3eff4cSPeng Fan int dm_spi_xfer(struct udevice *dev, unsigned int bitlen, 85d7af6a48SSimon Glass const void *dout, void *din, unsigned long flags) 86d7af6a48SSimon Glass { 87d7af6a48SSimon Glass struct udevice *bus = dev->parent; 88d7af6a48SSimon Glass 89d7af6a48SSimon Glass if (bus->uclass->uc_drv->id != UCLASS_SPI) 90d7af6a48SSimon Glass return -EOPNOTSUPP; 91d7af6a48SSimon Glass 92d7af6a48SSimon Glass return spi_get_ops(bus)->xfer(dev, bitlen, dout, din, flags); 93d7af6a48SSimon Glass } 94d7af6a48SSimon Glass 957a3eff4cSPeng Fan int spi_claim_bus(struct spi_slave *slave) 967a3eff4cSPeng Fan { 977a3eff4cSPeng Fan return dm_spi_claim_bus(slave->dev); 987a3eff4cSPeng Fan } 997a3eff4cSPeng Fan 1007a3eff4cSPeng Fan void spi_release_bus(struct spi_slave *slave) 1017a3eff4cSPeng Fan { 1027a3eff4cSPeng Fan dm_spi_release_bus(slave->dev); 1037a3eff4cSPeng Fan } 1047a3eff4cSPeng Fan 1057a3eff4cSPeng Fan int spi_xfer(struct spi_slave *slave, unsigned int bitlen, 1067a3eff4cSPeng Fan const void *dout, void *din, unsigned long flags) 1077a3eff4cSPeng Fan { 1087a3eff4cSPeng Fan return dm_spi_xfer(slave->dev, bitlen, dout, din, flags); 1097a3eff4cSPeng Fan } 1107a3eff4cSPeng Fan 1116f849c30SSimon Glass static int spi_child_post_bind(struct udevice *dev) 112d7af6a48SSimon Glass { 113d0cff03eSSimon Glass struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev); 114d7af6a48SSimon Glass 115d0cff03eSSimon Glass if (dev->of_offset == -1) 116d0cff03eSSimon Glass return 0; 117d0cff03eSSimon Glass 118d0cff03eSSimon Glass return spi_slave_ofdata_to_platdata(gd->fdt_blob, dev->of_offset, plat); 119d0cff03eSSimon Glass } 120d0cff03eSSimon Glass 1216f849c30SSimon Glass static int spi_post_probe(struct udevice *bus) 122d0cff03eSSimon Glass { 123e564f054SSimon Glass struct dm_spi_bus *spi = dev_get_uclass_priv(bus); 124d0cff03eSSimon Glass 125d0cff03eSSimon Glass spi->max_hz = fdtdec_get_int(gd->fdt_blob, bus->of_offset, 126d7af6a48SSimon Glass "spi-max-frequency", 0); 127d7af6a48SSimon Glass 128281f1566SMichal Simek #if defined(CONFIG_NEEDS_MANUAL_RELOC) 129281f1566SMichal Simek struct dm_spi_ops *ops = spi_get_ops(bus); 130281f1566SMichal Simek 131281f1566SMichal Simek 132281f1566SMichal Simek if (ops->claim_bus) 133281f1566SMichal Simek ops->claim_bus += gd->reloc_off; 134281f1566SMichal Simek if (ops->release_bus) 135281f1566SMichal Simek ops->release_bus += gd->reloc_off; 136281f1566SMichal Simek if (ops->set_wordlen) 137281f1566SMichal Simek ops->set_wordlen += gd->reloc_off; 138281f1566SMichal Simek if (ops->xfer) 139281f1566SMichal Simek ops->xfer += gd->reloc_off; 140281f1566SMichal Simek if (ops->set_speed) 141281f1566SMichal Simek ops->set_speed += gd->reloc_off; 142281f1566SMichal Simek if (ops->set_mode) 143281f1566SMichal Simek ops->set_mode += gd->reloc_off; 144281f1566SMichal Simek if (ops->cs_info) 145281f1566SMichal Simek ops->cs_info += gd->reloc_off; 146281f1566SMichal Simek #endif 147281f1566SMichal Simek 148d7af6a48SSimon Glass return 0; 149d7af6a48SSimon Glass } 150d7af6a48SSimon Glass 1516f849c30SSimon Glass static int spi_child_pre_probe(struct udevice *dev) 152440714eeSSimon Glass { 153d0cff03eSSimon Glass struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev); 154bcbe3d15SSimon Glass struct spi_slave *slave = dev_get_parent_priv(dev); 155440714eeSSimon Glass 156d0cff03eSSimon Glass /* 157d0cff03eSSimon Glass * This is needed because we pass struct spi_slave around the place 158d0cff03eSSimon Glass * instead slave->dev (a struct udevice). So we have to have some 159d0cff03eSSimon Glass * way to access the slave udevice given struct spi_slave. Once we 160d0cff03eSSimon Glass * change the SPI API to use udevice instead of spi_slave, we can 161d0cff03eSSimon Glass * drop this. 162d0cff03eSSimon Glass */ 163440714eeSSimon Glass slave->dev = dev; 164440714eeSSimon Glass 165d0cff03eSSimon Glass slave->max_hz = plat->max_hz; 166d0cff03eSSimon Glass slave->mode = plat->mode; 167674f3609SChristophe Ricard slave->wordlen = SPI_DEFAULT_WORDLEN; 168d0cff03eSSimon Glass 169440714eeSSimon Glass return 0; 170440714eeSSimon Glass } 171440714eeSSimon Glass 172d7af6a48SSimon Glass int spi_chip_select(struct udevice *dev) 173d7af6a48SSimon Glass { 174d0cff03eSSimon Glass struct dm_spi_slave_platdata *plat = dev_get_parent_platdata(dev); 175d7af6a48SSimon Glass 176d0cff03eSSimon Glass return plat ? plat->cs : -ENOENT; 177d7af6a48SSimon Glass } 178d7af6a48SSimon Glass 179ff56bba2SSimon Glass int spi_find_chip_select(struct udevice *bus, int cs, struct udevice **devp) 180d7af6a48SSimon Glass { 181d7af6a48SSimon Glass struct udevice *dev; 182d7af6a48SSimon Glass 183d7af6a48SSimon Glass for (device_find_first_child(bus, &dev); dev; 184d7af6a48SSimon Glass device_find_next_child(&dev)) { 185d0cff03eSSimon Glass struct dm_spi_slave_platdata *plat; 186d7af6a48SSimon Glass 187d0cff03eSSimon Glass plat = dev_get_parent_platdata(dev); 188d0cff03eSSimon Glass debug("%s: plat=%p, cs=%d\n", __func__, plat, plat->cs); 189d0cff03eSSimon Glass if (plat->cs == cs) { 190d7af6a48SSimon Glass *devp = dev; 191d7af6a48SSimon Glass return 0; 192d7af6a48SSimon Glass } 193d7af6a48SSimon Glass } 194d7af6a48SSimon Glass 195d7af6a48SSimon Glass return -ENODEV; 196d7af6a48SSimon Glass } 197d7af6a48SSimon Glass 198d7af6a48SSimon Glass int spi_cs_is_valid(unsigned int busnum, unsigned int cs) 199d7af6a48SSimon Glass { 200d7af6a48SSimon Glass struct spi_cs_info info; 201d7af6a48SSimon Glass struct udevice *bus; 202d7af6a48SSimon Glass int ret; 203d7af6a48SSimon Glass 204d7af6a48SSimon Glass ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, false, &bus); 205d7af6a48SSimon Glass if (ret) { 206d7af6a48SSimon Glass debug("%s: No bus %d\n", __func__, busnum); 207d7af6a48SSimon Glass return ret; 208d7af6a48SSimon Glass } 209d7af6a48SSimon Glass 210d7af6a48SSimon Glass return spi_cs_info(bus, cs, &info); 211d7af6a48SSimon Glass } 212d7af6a48SSimon Glass 213d7af6a48SSimon Glass int spi_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info) 214d7af6a48SSimon Glass { 215d7af6a48SSimon Glass struct spi_cs_info local_info; 216d7af6a48SSimon Glass struct dm_spi_ops *ops; 217d7af6a48SSimon Glass int ret; 218d7af6a48SSimon Glass 219d7af6a48SSimon Glass if (!info) 220d7af6a48SSimon Glass info = &local_info; 221d7af6a48SSimon Glass 222d7af6a48SSimon Glass /* If there is a device attached, return it */ 223d7af6a48SSimon Glass info->dev = NULL; 224d7af6a48SSimon Glass ret = spi_find_chip_select(bus, cs, &info->dev); 225d7af6a48SSimon Glass if (!ret) 226d7af6a48SSimon Glass return 0; 227d7af6a48SSimon Glass 228d7af6a48SSimon Glass /* 229d7af6a48SSimon Glass * Otherwise ask the driver. For the moment we don't have CS info. 230d7af6a48SSimon Glass * When we do we could provide the driver with a helper function 231d7af6a48SSimon Glass * to figure out what chip selects are valid, or just handle the 232d7af6a48SSimon Glass * request. 233d7af6a48SSimon Glass */ 234d7af6a48SSimon Glass ops = spi_get_ops(bus); 235d7af6a48SSimon Glass if (ops->cs_info) 236d7af6a48SSimon Glass return ops->cs_info(bus, cs, info); 237d7af6a48SSimon Glass 238d7af6a48SSimon Glass /* 239d7af6a48SSimon Glass * We could assume there is at least one valid chip select, but best 240d7af6a48SSimon Glass * to be sure and return an error in this case. The driver didn't 241d7af6a48SSimon Glass * care enough to tell us. 242d7af6a48SSimon Glass */ 243d7af6a48SSimon Glass return -ENODEV; 244d7af6a48SSimon Glass } 245d7af6a48SSimon Glass 246d7af6a48SSimon Glass int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, 247d7af6a48SSimon Glass struct udevice **devp) 248d7af6a48SSimon Glass { 249d7af6a48SSimon Glass struct udevice *bus, *dev; 250d7af6a48SSimon Glass int ret; 251d7af6a48SSimon Glass 252d7af6a48SSimon Glass ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, false, &bus); 253d7af6a48SSimon Glass if (ret) { 254d7af6a48SSimon Glass debug("%s: No bus %d\n", __func__, busnum); 255d7af6a48SSimon Glass return ret; 256d7af6a48SSimon Glass } 257d7af6a48SSimon Glass ret = spi_find_chip_select(bus, cs, &dev); 258d7af6a48SSimon Glass if (ret) { 259d7af6a48SSimon Glass debug("%s: No cs %d\n", __func__, cs); 260d7af6a48SSimon Glass return ret; 261d7af6a48SSimon Glass } 262d7af6a48SSimon Glass *busp = bus; 263d7af6a48SSimon Glass *devp = dev; 264d7af6a48SSimon Glass 265d7af6a48SSimon Glass return ret; 266d7af6a48SSimon Glass } 267d7af6a48SSimon Glass 268d7af6a48SSimon Glass int spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, 269d7af6a48SSimon Glass const char *drv_name, const char *dev_name, 270d7af6a48SSimon Glass struct udevice **busp, struct spi_slave **devp) 271d7af6a48SSimon Glass { 272d7af6a48SSimon Glass struct udevice *bus, *dev; 27396907c0fSVignesh R struct dm_spi_slave_platdata *plat; 274d7af6a48SSimon Glass bool created = false; 275d7af6a48SSimon Glass int ret; 276d7af6a48SSimon Glass 277d7af6a48SSimon Glass ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus); 278d7af6a48SSimon Glass if (ret) { 279d7af6a48SSimon Glass printf("Invalid bus %d (err=%d)\n", busnum, ret); 280d7af6a48SSimon Glass return ret; 281d7af6a48SSimon Glass } 282d7af6a48SSimon Glass ret = spi_find_chip_select(bus, cs, &dev); 283d7af6a48SSimon Glass 284d7af6a48SSimon Glass /* 285d7af6a48SSimon Glass * If there is no such device, create one automatically. This means 286d7af6a48SSimon Glass * that we don't need a device tree node or platform data for the 287d7af6a48SSimon Glass * SPI flash chip - we will bind to the correct driver. 288d7af6a48SSimon Glass */ 289d7af6a48SSimon Glass if (ret == -ENODEV && drv_name) { 290d7af6a48SSimon Glass debug("%s: Binding new device '%s', busnum=%d, cs=%d, driver=%s\n", 291d7af6a48SSimon Glass __func__, dev_name, busnum, cs, drv_name); 2926b18656aSSimon Glass ret = device_bind_driver(bus, drv_name, dev_name, &dev); 293d7af6a48SSimon Glass if (ret) 294d7af6a48SSimon Glass return ret; 295d0cff03eSSimon Glass plat = dev_get_parent_platdata(dev); 296d0cff03eSSimon Glass plat->cs = cs; 297d0cff03eSSimon Glass plat->max_hz = speed; 298d0cff03eSSimon Glass plat->mode = mode; 299d7af6a48SSimon Glass created = true; 300d7af6a48SSimon Glass } else if (ret) { 301d7af6a48SSimon Glass printf("Invalid chip select %d:%d (err=%d)\n", busnum, cs, 302d7af6a48SSimon Glass ret); 303d7af6a48SSimon Glass return ret; 304d7af6a48SSimon Glass } 305d7af6a48SSimon Glass 306d7af6a48SSimon Glass if (!device_active(dev)) { 307d0cff03eSSimon Glass struct spi_slave *slave; 308d7af6a48SSimon Glass 309d0cff03eSSimon Glass ret = device_probe(dev); 310d7af6a48SSimon Glass if (ret) 311d7af6a48SSimon Glass goto err; 312bcbe3d15SSimon Glass slave = dev_get_parent_priv(dev); 313d7af6a48SSimon Glass slave->dev = dev; 314d7af6a48SSimon Glass } 315d7af6a48SSimon Glass 31696907c0fSVignesh R plat = dev_get_parent_platdata(dev); 31796907c0fSVignesh R if (!speed) { 31896907c0fSVignesh R speed = plat->max_hz; 31996907c0fSVignesh R mode = plat->mode; 32096907c0fSVignesh R } 321d7af6a48SSimon Glass ret = spi_set_speed_mode(bus, speed, mode); 322d7af6a48SSimon Glass if (ret) 323d7af6a48SSimon Glass goto err; 324d7af6a48SSimon Glass 325d7af6a48SSimon Glass *busp = bus; 326bcbe3d15SSimon Glass *devp = dev_get_parent_priv(dev); 327d7af6a48SSimon Glass debug("%s: bus=%p, slave=%p\n", __func__, bus, *devp); 328d7af6a48SSimon Glass 329d7af6a48SSimon Glass return 0; 330d7af6a48SSimon Glass 331d7af6a48SSimon Glass err: 332c8864d72SAnatolij Gustschin debug("%s: Error path, created=%d, device '%s'\n", __func__, 333d0cff03eSSimon Glass created, dev->name); 334d7af6a48SSimon Glass if (created) { 335d7af6a48SSimon Glass device_remove(dev); 336d7af6a48SSimon Glass device_unbind(dev); 337d7af6a48SSimon Glass } 338d7af6a48SSimon Glass 339d7af6a48SSimon Glass return ret; 340d7af6a48SSimon Glass } 341d7af6a48SSimon Glass 342d7af6a48SSimon Glass /* Compatibility function - to be removed */ 343d7af6a48SSimon Glass struct spi_slave *spi_setup_slave_fdt(const void *blob, int node, 344d7af6a48SSimon Glass int bus_node) 345d7af6a48SSimon Glass { 346d7af6a48SSimon Glass struct udevice *bus, *dev; 347d7af6a48SSimon Glass int ret; 348d7af6a48SSimon Glass 349d7af6a48SSimon Glass ret = uclass_get_device_by_of_offset(UCLASS_SPI, bus_node, &bus); 350d7af6a48SSimon Glass if (ret) 351d7af6a48SSimon Glass return NULL; 352d7af6a48SSimon Glass ret = device_get_child_by_of_offset(bus, node, &dev); 353d7af6a48SSimon Glass if (ret) 354d7af6a48SSimon Glass return NULL; 355bcbe3d15SSimon Glass return dev_get_parent_priv(dev); 356d7af6a48SSimon Glass } 357d7af6a48SSimon Glass 358d7af6a48SSimon Glass /* Compatibility function - to be removed */ 359d7af6a48SSimon Glass struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs, 360d7af6a48SSimon Glass unsigned int speed, unsigned int mode) 361d7af6a48SSimon Glass { 362d7af6a48SSimon Glass struct spi_slave *slave; 363d7af6a48SSimon Glass struct udevice *dev; 364d7af6a48SSimon Glass int ret; 365d7af6a48SSimon Glass 366d7af6a48SSimon Glass ret = spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev, 367d7af6a48SSimon Glass &slave); 368d7af6a48SSimon Glass if (ret) 369d7af6a48SSimon Glass return NULL; 370d7af6a48SSimon Glass 371d7af6a48SSimon Glass return slave; 372d7af6a48SSimon Glass } 373d7af6a48SSimon Glass 374d7af6a48SSimon Glass void spi_free_slave(struct spi_slave *slave) 375d7af6a48SSimon Glass { 376d7af6a48SSimon Glass device_remove(slave->dev); 377d7af6a48SSimon Glass slave->dev = NULL; 378d7af6a48SSimon Glass } 379d7af6a48SSimon Glass 380d0cff03eSSimon Glass int spi_slave_ofdata_to_platdata(const void *blob, int node, 381d0cff03eSSimon Glass struct dm_spi_slave_platdata *plat) 382d7af6a48SSimon Glass { 383*08fe9c29SJagan Teki int mode = 0; 384f8e2f92dSMugunthan V N int value; 385d7af6a48SSimon Glass 386d0cff03eSSimon Glass plat->cs = fdtdec_get_int(blob, node, "reg", -1); 387d0cff03eSSimon Glass plat->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency", 0); 388d7af6a48SSimon Glass if (fdtdec_get_bool(blob, node, "spi-cpol")) 389d7af6a48SSimon Glass mode |= SPI_CPOL; 390d7af6a48SSimon Glass if (fdtdec_get_bool(blob, node, "spi-cpha")) 391d7af6a48SSimon Glass mode |= SPI_CPHA; 392d7af6a48SSimon Glass if (fdtdec_get_bool(blob, node, "spi-cs-high")) 393d7af6a48SSimon Glass mode |= SPI_CS_HIGH; 394379b49d8SJagan Teki if (fdtdec_get_bool(blob, node, "spi-3wire")) 395379b49d8SJagan Teki mode |= SPI_3WIRE; 396d7af6a48SSimon Glass if (fdtdec_get_bool(blob, node, "spi-half-duplex")) 397d7af6a48SSimon Glass mode |= SPI_PREAMBLE; 398f8e2f92dSMugunthan V N 399f8e2f92dSMugunthan V N /* Device DUAL/QUAD mode */ 400f8e2f92dSMugunthan V N value = fdtdec_get_uint(blob, node, "spi-tx-bus-width", 1); 401f8e2f92dSMugunthan V N switch (value) { 402f8e2f92dSMugunthan V N case 1: 403f8e2f92dSMugunthan V N break; 404f8e2f92dSMugunthan V N case 2: 405f8e2f92dSMugunthan V N mode |= SPI_TX_DUAL; 406f8e2f92dSMugunthan V N break; 407f8e2f92dSMugunthan V N case 4: 408f8e2f92dSMugunthan V N mode |= SPI_TX_QUAD; 409f8e2f92dSMugunthan V N break; 410f8e2f92dSMugunthan V N default: 411f8e2f92dSMugunthan V N error("spi-tx-bus-width %d not supported\n", value); 412f8e2f92dSMugunthan V N break; 413f8e2f92dSMugunthan V N } 414f8e2f92dSMugunthan V N 415f8e2f92dSMugunthan V N value = fdtdec_get_uint(blob, node, "spi-rx-bus-width", 1); 416f8e2f92dSMugunthan V N switch (value) { 417f8e2f92dSMugunthan V N case 1: 418f8e2f92dSMugunthan V N break; 419f8e2f92dSMugunthan V N case 2: 420*08fe9c29SJagan Teki mode |= SPI_RX_DUAL; 421f8e2f92dSMugunthan V N break; 422f8e2f92dSMugunthan V N case 4: 423*08fe9c29SJagan Teki mode |= SPI_RX_QUAD; 424f8e2f92dSMugunthan V N break; 425f8e2f92dSMugunthan V N default: 426f8e2f92dSMugunthan V N error("spi-rx-bus-width %d not supported\n", value); 427f8e2f92dSMugunthan V N break; 428f8e2f92dSMugunthan V N } 429f8e2f92dSMugunthan V N 430*08fe9c29SJagan Teki plat->mode = mode; 431f8e2f92dSMugunthan V N 432d7af6a48SSimon Glass return 0; 433d7af6a48SSimon Glass } 434d7af6a48SSimon Glass 435d7af6a48SSimon Glass UCLASS_DRIVER(spi) = { 436d7af6a48SSimon Glass .id = UCLASS_SPI, 437d7af6a48SSimon Glass .name = "spi", 4389cc36a2bSSimon Glass .flags = DM_UC_FLAG_SEQ_ALIAS, 43991195485SSimon Glass .post_bind = dm_scan_fdt_dev, 440d7af6a48SSimon Glass .post_probe = spi_post_probe, 441440714eeSSimon Glass .child_pre_probe = spi_child_pre_probe, 442d7af6a48SSimon Glass .per_device_auto_alloc_size = sizeof(struct dm_spi_bus), 44319a25f67SSimon Glass .per_child_auto_alloc_size = sizeof(struct spi_slave), 444d0cff03eSSimon Glass .per_child_platdata_auto_alloc_size = 445d0cff03eSSimon Glass sizeof(struct dm_spi_slave_platdata), 446d0cff03eSSimon Glass .child_post_bind = spi_child_post_bind, 447d7af6a48SSimon Glass }; 448d7af6a48SSimon Glass 449d7af6a48SSimon Glass UCLASS_DRIVER(spi_generic) = { 450d7af6a48SSimon Glass .id = UCLASS_SPI_GENERIC, 451d7af6a48SSimon Glass .name = "spi_generic", 452d7af6a48SSimon Glass }; 453d7af6a48SSimon Glass 454d7af6a48SSimon Glass U_BOOT_DRIVER(spi_generic_drv) = { 455d7af6a48SSimon Glass .name = "spi_generic_drv", 456d7af6a48SSimon Glass .id = UCLASS_SPI_GENERIC, 457d7af6a48SSimon Glass }; 458