Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_SPI |
| 7 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <errno.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 12 | #include <malloc.h> |
| 13 | #include <spi.h> |
T Karthik Reddy | 346df7d | 2021-03-17 12:31:30 +0100 | [diff] [blame] | 14 | #include <spi-mem.h> |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 15 | #include <dm/device_compat.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 17 | #include <dm/device-internal.h> |
| 18 | #include <dm/uclass-internal.h> |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 19 | #include <dm/lists.h> |
| 20 | #include <dm/util.h> |
| 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Simon Goldschmidt | 12bfb2e | 2018-10-30 21:09:48 +0100 | [diff] [blame] | 24 | #define SPI_DEFAULT_SPEED_HZ 100000 |
| 25 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 26 | static int spi_set_speed_mode(struct udevice *bus, int speed, int mode) |
| 27 | { |
| 28 | struct dm_spi_ops *ops; |
| 29 | int ret; |
| 30 | |
| 31 | ops = spi_get_ops(bus); |
| 32 | if (ops->set_speed) |
| 33 | ret = ops->set_speed(bus, speed); |
| 34 | else |
| 35 | ret = -EINVAL; |
| 36 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 37 | dev_err(bus, "Cannot set speed (err=%d)\n", ret); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | if (ops->set_mode) |
| 42 | ret = ops->set_mode(bus, mode); |
| 43 | else |
| 44 | ret = -EINVAL; |
| 45 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 46 | dev_err(bus, "Cannot set mode (err=%d)\n", ret); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Peng Fan | 7a3eff4 | 2016-05-03 10:02:22 +0800 | [diff] [blame] | 53 | int dm_spi_claim_bus(struct udevice *dev) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 54 | { |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 55 | struct udevice *bus = dev->parent; |
| 56 | struct dm_spi_ops *ops = spi_get_ops(bus); |
Simon Glass | e564f05 | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 57 | struct dm_spi_bus *spi = dev_get_uclass_priv(bus); |
Peng Fan | 7a3eff4 | 2016-05-03 10:02:22 +0800 | [diff] [blame] | 58 | struct spi_slave *slave = dev_get_parent_priv(dev); |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 59 | uint speed, mode; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 60 | |
| 61 | speed = slave->max_hz; |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 62 | mode = slave->mode; |
| 63 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 64 | if (spi->max_hz) { |
| 65 | if (speed) |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 66 | speed = min(speed, spi->max_hz); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 67 | else |
| 68 | speed = spi->max_hz; |
| 69 | } |
| 70 | if (!speed) |
Simon Goldschmidt | 12bfb2e | 2018-10-30 21:09:48 +0100 | [diff] [blame] | 71 | speed = SPI_DEFAULT_SPEED_HZ; |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 72 | |
| 73 | if (speed != spi->speed || mode != spi->mode) { |
Mario Six | 24fc1ec | 2018-01-15 11:08:41 +0100 | [diff] [blame] | 74 | int ret = spi_set_speed_mode(bus, speed, slave->mode); |
| 75 | |
Simon Glass | 60e2809 | 2015-02-17 15:29:35 -0700 | [diff] [blame] | 76 | if (ret) |
Simon Glass | 5e24a2e | 2018-10-01 12:22:24 -0600 | [diff] [blame] | 77 | return log_ret(ret); |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 78 | |
| 79 | spi->speed = speed; |
| 80 | spi->mode = mode; |
Simon Glass | 60e2809 | 2015-02-17 15:29:35 -0700 | [diff] [blame] | 81 | } |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 82 | |
Simon Glass | 5e24a2e | 2018-10-01 12:22:24 -0600 | [diff] [blame] | 83 | return log_ret(ops->claim_bus ? ops->claim_bus(dev) : 0); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 84 | } |
| 85 | |
Peng Fan | 7a3eff4 | 2016-05-03 10:02:22 +0800 | [diff] [blame] | 86 | void dm_spi_release_bus(struct udevice *dev) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 87 | { |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 88 | struct udevice *bus = dev->parent; |
| 89 | struct dm_spi_ops *ops = spi_get_ops(bus); |
| 90 | |
| 91 | if (ops->release_bus) |
Simon Glass | 9694b72 | 2015-04-19 09:05:40 -0600 | [diff] [blame] | 92 | ops->release_bus(dev); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 93 | } |
| 94 | |
Peng Fan | 7a3eff4 | 2016-05-03 10:02:22 +0800 | [diff] [blame] | 95 | int dm_spi_xfer(struct udevice *dev, unsigned int bitlen, |
| 96 | const void *dout, void *din, unsigned long flags) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 97 | { |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 98 | struct udevice *bus = dev->parent; |
Simon Glass | ccdabd8 | 2019-12-06 21:42:35 -0700 | [diff] [blame] | 99 | struct dm_spi_ops *ops = spi_get_ops(bus); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 100 | |
| 101 | if (bus->uclass->uc_drv->id != UCLASS_SPI) |
| 102 | return -EOPNOTSUPP; |
Simon Glass | ccdabd8 | 2019-12-06 21:42:35 -0700 | [diff] [blame] | 103 | if (!ops->xfer) |
| 104 | return -ENOSYS; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 105 | |
Simon Glass | ccdabd8 | 2019-12-06 21:42:35 -0700 | [diff] [blame] | 106 | return ops->xfer(dev, bitlen, dout, din, flags); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 107 | } |
| 108 | |
Simon Glass | c53b318 | 2019-10-20 21:31:47 -0600 | [diff] [blame] | 109 | int dm_spi_get_mmap(struct udevice *dev, ulong *map_basep, uint *map_sizep, |
| 110 | uint *offsetp) |
| 111 | { |
| 112 | struct udevice *bus = dev->parent; |
| 113 | struct dm_spi_ops *ops = spi_get_ops(bus); |
| 114 | |
| 115 | if (bus->uclass->uc_drv->id != UCLASS_SPI) |
| 116 | return -EOPNOTSUPP; |
| 117 | if (!ops->get_mmap) |
| 118 | return -ENOSYS; |
| 119 | |
| 120 | return ops->get_mmap(dev, map_basep, map_sizep, offsetp); |
| 121 | } |
| 122 | |
Peng Fan | 7a3eff4 | 2016-05-03 10:02:22 +0800 | [diff] [blame] | 123 | int spi_claim_bus(struct spi_slave *slave) |
| 124 | { |
Simon Glass | 5e24a2e | 2018-10-01 12:22:24 -0600 | [diff] [blame] | 125 | return log_ret(dm_spi_claim_bus(slave->dev)); |
Peng Fan | 7a3eff4 | 2016-05-03 10:02:22 +0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void spi_release_bus(struct spi_slave *slave) |
| 129 | { |
| 130 | dm_spi_release_bus(slave->dev); |
| 131 | } |
| 132 | |
Paul Barker | c98f6fe | 2022-10-05 13:18:34 +0100 | [diff] [blame] | 133 | int spi_set_speed(struct spi_slave *slave, uint hz) |
| 134 | { |
| 135 | struct dm_spi_ops *ops; |
| 136 | int ret; |
| 137 | |
| 138 | ops = spi_get_ops(slave->dev->parent); |
| 139 | if (ops->set_speed) |
| 140 | ret = ops->set_speed(slave->dev->parent, hz); |
| 141 | else |
| 142 | ret = -EINVAL; |
| 143 | if (ret) |
| 144 | dev_err(slave->dev, "Cannot set speed (err=%d)\n", ret); |
| 145 | return ret; |
| 146 | } |
| 147 | |
Peng Fan | 7a3eff4 | 2016-05-03 10:02:22 +0800 | [diff] [blame] | 148 | int spi_xfer(struct spi_slave *slave, unsigned int bitlen, |
| 149 | const void *dout, void *din, unsigned long flags) |
| 150 | { |
| 151 | return dm_spi_xfer(slave->dev, bitlen, dout, din, flags); |
| 152 | } |
| 153 | |
Jagan Teki | 8473b32 | 2019-07-22 17:22:56 +0530 | [diff] [blame] | 154 | int spi_write_then_read(struct spi_slave *slave, const u8 *opcode, |
| 155 | size_t n_opcode, const u8 *txbuf, u8 *rxbuf, |
| 156 | size_t n_buf) |
| 157 | { |
| 158 | unsigned long flags = SPI_XFER_BEGIN; |
| 159 | int ret; |
| 160 | |
| 161 | if (n_buf == 0) |
| 162 | flags |= SPI_XFER_END; |
| 163 | |
| 164 | ret = spi_xfer(slave, n_opcode * 8, opcode, NULL, flags); |
| 165 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 166 | dev_dbg(slave->dev, |
| 167 | "spi: failed to send command (%zu bytes): %d\n", |
| 168 | n_opcode, ret); |
Jagan Teki | 8473b32 | 2019-07-22 17:22:56 +0530 | [diff] [blame] | 169 | } else if (n_buf != 0) { |
| 170 | ret = spi_xfer(slave, n_buf * 8, txbuf, rxbuf, SPI_XFER_END); |
| 171 | if (ret) |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 172 | dev_dbg(slave->dev, |
| 173 | "spi: failed to transfer %zu bytes of data: %d\n", |
| 174 | n_buf, ret); |
Jagan Teki | 8473b32 | 2019-07-22 17:22:56 +0530 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | return ret; |
| 178 | } |
| 179 | |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 180 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | 6f849c3 | 2015-06-23 15:39:05 -0600 | [diff] [blame] | 181 | static int spi_child_post_bind(struct udevice *dev) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 182 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 183 | struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 184 | |
Simon Glass | 7d14ee4 | 2020-12-19 10:40:13 -0700 | [diff] [blame] | 185 | if (!dev_has_ofnode(dev)) |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 186 | return 0; |
| 187 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 188 | return spi_slave_of_to_plat(dev, plat); |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 189 | } |
Simon Glass | 71634f2 | 2016-11-13 14:22:01 -0700 | [diff] [blame] | 190 | #endif |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 191 | |
Simon Glass | 6f849c3 | 2015-06-23 15:39:05 -0600 | [diff] [blame] | 192 | static int spi_post_probe(struct udevice *bus) |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 193 | { |
Simon Glass | dcfc42b | 2021-08-07 07:24:06 -0600 | [diff] [blame] | 194 | if (CONFIG_IS_ENABLED(OF_REAL)) { |
| 195 | struct dm_spi_bus *spi = dev_get_uclass_priv(bus); |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 196 | |
Simon Glass | dcfc42b | 2021-08-07 07:24:06 -0600 | [diff] [blame] | 197 | spi->max_hz = dev_read_u32_default(bus, "spi-max-frequency", 0); |
| 198 | } |
Michal Simek | 281f156 | 2015-10-27 13:36:42 +0100 | [diff] [blame] | 199 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
| 200 | struct dm_spi_ops *ops = spi_get_ops(bus); |
Ashok Reddy Soma | 4d9b1af | 2019-09-17 00:11:02 -0600 | [diff] [blame] | 201 | static int reloc_done; |
Michal Simek | 281f156 | 2015-10-27 13:36:42 +0100 | [diff] [blame] | 202 | |
Ashok Reddy Soma | 4d9b1af | 2019-09-17 00:11:02 -0600 | [diff] [blame] | 203 | if (!reloc_done) { |
| 204 | if (ops->claim_bus) |
| 205 | ops->claim_bus += gd->reloc_off; |
| 206 | if (ops->release_bus) |
| 207 | ops->release_bus += gd->reloc_off; |
| 208 | if (ops->set_wordlen) |
| 209 | ops->set_wordlen += gd->reloc_off; |
| 210 | if (ops->xfer) |
| 211 | ops->xfer += gd->reloc_off; |
| 212 | if (ops->set_speed) |
| 213 | ops->set_speed += gd->reloc_off; |
| 214 | if (ops->set_mode) |
| 215 | ops->set_mode += gd->reloc_off; |
| 216 | if (ops->cs_info) |
| 217 | ops->cs_info += gd->reloc_off; |
T Karthik Reddy | 346df7d | 2021-03-17 12:31:30 +0100 | [diff] [blame] | 218 | if (ops->mem_ops) { |
| 219 | struct spi_controller_mem_ops *mem_ops = |
| 220 | (struct spi_controller_mem_ops *)ops->mem_ops; |
| 221 | if (mem_ops->adjust_op_size) |
| 222 | mem_ops->adjust_op_size += gd->reloc_off; |
| 223 | if (mem_ops->supports_op) |
| 224 | mem_ops->supports_op += gd->reloc_off; |
| 225 | if (mem_ops->exec_op) |
| 226 | mem_ops->exec_op += gd->reloc_off; |
| 227 | } |
Ashok Reddy Soma | 4d9b1af | 2019-09-17 00:11:02 -0600 | [diff] [blame] | 228 | reloc_done++; |
| 229 | } |
Michal Simek | 281f156 | 2015-10-27 13:36:42 +0100 | [diff] [blame] | 230 | #endif |
| 231 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
Simon Glass | 6f849c3 | 2015-06-23 15:39:05 -0600 | [diff] [blame] | 235 | static int spi_child_pre_probe(struct udevice *dev) |
Simon Glass | 440714e | 2015-01-25 08:27:11 -0700 | [diff] [blame] | 236 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 237 | struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev); |
Simon Glass | bcbe3d1 | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 238 | struct spi_slave *slave = dev_get_parent_priv(dev); |
Simon Glass | 440714e | 2015-01-25 08:27:11 -0700 | [diff] [blame] | 239 | |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 240 | /* |
| 241 | * This is needed because we pass struct spi_slave around the place |
| 242 | * instead slave->dev (a struct udevice). So we have to have some |
| 243 | * way to access the slave udevice given struct spi_slave. Once we |
| 244 | * change the SPI API to use udevice instead of spi_slave, we can |
| 245 | * drop this. |
| 246 | */ |
Simon Glass | 440714e | 2015-01-25 08:27:11 -0700 | [diff] [blame] | 247 | slave->dev = dev; |
| 248 | |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 249 | slave->max_hz = plat->max_hz; |
| 250 | slave->mode = plat->mode; |
Christophe Ricard | 674f360 | 2016-01-17 11:56:48 +0100 | [diff] [blame] | 251 | slave->wordlen = SPI_DEFAULT_WORDLEN; |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 252 | |
Simon Glass | 440714e | 2015-01-25 08:27:11 -0700 | [diff] [blame] | 253 | return 0; |
| 254 | } |
| 255 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 256 | int spi_chip_select(struct udevice *dev) |
| 257 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 258 | struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 259 | |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 260 | return plat ? plat->cs : -ENOENT; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 261 | } |
| 262 | |
Simon Glass | ff56bba | 2014-11-11 10:46:22 -0700 | [diff] [blame] | 263 | int spi_find_chip_select(struct udevice *bus, int cs, struct udevice **devp) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 264 | { |
Bin Meng | 7bacce5 | 2019-09-09 06:00:02 -0700 | [diff] [blame] | 265 | struct dm_spi_ops *ops; |
| 266 | struct spi_cs_info info; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 267 | struct udevice *dev; |
Bin Meng | 7bacce5 | 2019-09-09 06:00:02 -0700 | [diff] [blame] | 268 | int ret; |
| 269 | |
| 270 | /* |
| 271 | * Ask the driver. For the moment we don't have CS info. |
| 272 | * When we do we could provide the driver with a helper function |
| 273 | * to figure out what chip selects are valid, or just handle the |
| 274 | * request. |
| 275 | */ |
| 276 | ops = spi_get_ops(bus); |
| 277 | if (ops->cs_info) { |
| 278 | ret = ops->cs_info(bus, cs, &info); |
| 279 | } else { |
| 280 | /* |
| 281 | * We could assume there is at least one valid chip select. |
| 282 | * The driver didn't care enough to tell us. |
| 283 | */ |
| 284 | ret = 0; |
| 285 | } |
| 286 | |
| 287 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 288 | dev_err(bus, "Invalid cs %d (err=%d)\n", cs, ret); |
Bin Meng | 7bacce5 | 2019-09-09 06:00:02 -0700 | [diff] [blame] | 289 | return ret; |
| 290 | } |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 291 | |
| 292 | for (device_find_first_child(bus, &dev); dev; |
| 293 | device_find_next_child(&dev)) { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 294 | struct dm_spi_slave_plat *plat; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 295 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 296 | plat = dev_get_parent_plat(dev); |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 297 | dev_dbg(bus, "%s: plat=%p, cs=%d\n", __func__, plat, plat->cs); |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 298 | if (plat->cs == cs) { |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 299 | *devp = dev; |
| 300 | return 0; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | return -ENODEV; |
| 305 | } |
| 306 | |
| 307 | int spi_cs_is_valid(unsigned int busnum, unsigned int cs) |
| 308 | { |
| 309 | struct spi_cs_info info; |
| 310 | struct udevice *bus; |
| 311 | int ret; |
| 312 | |
Simon Glass | 9917591 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 313 | ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, &bus); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 314 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 315 | log_debug("%s: No bus %d\n", __func__, busnum); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 316 | return ret; |
| 317 | } |
| 318 | |
| 319 | return spi_cs_info(bus, cs, &info); |
| 320 | } |
| 321 | |
| 322 | int spi_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info) |
| 323 | { |
| 324 | struct spi_cs_info local_info; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 325 | int ret; |
| 326 | |
| 327 | if (!info) |
| 328 | info = &local_info; |
| 329 | |
| 330 | /* If there is a device attached, return it */ |
| 331 | info->dev = NULL; |
| 332 | ret = spi_find_chip_select(bus, cs, &info->dev); |
Bin Meng | 7bacce5 | 2019-09-09 06:00:02 -0700 | [diff] [blame] | 333 | return ret == -ENODEV ? 0 : ret; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 334 | } |
| 335 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 336 | int spi_find_bus_and_cs(int busnum, int cs, struct udevice **busp, |
| 337 | struct udevice **devp) |
| 338 | { |
| 339 | struct udevice *bus, *dev; |
| 340 | int ret; |
| 341 | |
Simon Glass | 9917591 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 342 | ret = uclass_find_device_by_seq(UCLASS_SPI, busnum, &bus); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 343 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 344 | log_debug("%s: No bus %d\n", __func__, busnum); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 345 | return ret; |
| 346 | } |
| 347 | ret = spi_find_chip_select(bus, cs, &dev); |
| 348 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 349 | dev_dbg(bus, "%s: No cs %d\n", __func__, cs); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 350 | return ret; |
| 351 | } |
| 352 | *busp = bus; |
| 353 | *devp = dev; |
| 354 | |
| 355 | return ret; |
| 356 | } |
| 357 | |
Patrice Chotard | 61708bb | 2022-03-30 09:33:13 +0200 | [diff] [blame] | 358 | int spi_get_bus_and_cs(int busnum, int cs, struct udevice **busp, |
| 359 | struct spi_slave **devp) |
| 360 | { |
| 361 | struct udevice *bus, *dev; |
| 362 | struct dm_spi_bus *bus_data; |
| 363 | struct spi_slave *slave; |
| 364 | int ret; |
| 365 | |
| 366 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
| 367 | ret = uclass_first_device_err(UCLASS_SPI, &bus); |
| 368 | #else |
| 369 | ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus); |
| 370 | #endif |
| 371 | if (ret) { |
| 372 | log_err("Invalid bus %d (err=%d)\n", busnum, ret); |
| 373 | return ret; |
| 374 | } |
| 375 | ret = spi_find_chip_select(bus, cs, &dev); |
| 376 | if (ret) { |
| 377 | dev_err(bus, "Invalid chip select %d:%d (err=%d)\n", busnum, cs, ret); |
| 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | if (!device_active(dev)) { |
| 382 | struct spi_slave *slave; |
| 383 | |
| 384 | ret = device_probe(dev); |
| 385 | if (ret) |
| 386 | goto err; |
| 387 | slave = dev_get_parent_priv(dev); |
| 388 | slave->dev = dev; |
| 389 | } |
| 390 | |
| 391 | slave = dev_get_parent_priv(dev); |
| 392 | bus_data = dev_get_uclass_priv(bus); |
| 393 | |
| 394 | /* |
| 395 | * In case the operation speed is not yet established by |
| 396 | * dm_spi_claim_bus() ensure the bus is configured properly. |
| 397 | */ |
| 398 | if (!bus_data->speed) { |
| 399 | ret = spi_claim_bus(slave); |
| 400 | if (ret) |
| 401 | goto err; |
| 402 | } |
| 403 | *busp = bus; |
| 404 | *devp = slave; |
| 405 | |
| 406 | return 0; |
| 407 | |
| 408 | err: |
| 409 | log_debug("%s: Error path, device '%s'\n", __func__, dev->name); |
| 410 | |
| 411 | return ret; |
| 412 | } |
| 413 | |
| 414 | int _spi_get_bus_and_cs(int busnum, int cs, int speed, int mode, |
| 415 | const char *drv_name, const char *dev_name, |
| 416 | struct udevice **busp, struct spi_slave **devp) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 417 | { |
| 418 | struct udevice *bus, *dev; |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 419 | struct dm_spi_slave_plat *plat; |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 420 | struct dm_spi_bus *bus_data; |
Marcin Wojtas | f7dd537 | 2019-11-21 05:38:47 +0100 | [diff] [blame] | 421 | struct spi_slave *slave; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 422 | bool created = false; |
| 423 | int ret; |
| 424 | |
Thomas Fitzsimmons | 640abba | 2019-09-06 07:51:19 -0400 | [diff] [blame] | 425 | #if CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 71634f2 | 2016-11-13 14:22:01 -0700 | [diff] [blame] | 426 | ret = uclass_first_device_err(UCLASS_SPI, &bus); |
| 427 | #else |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 428 | ret = uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus); |
Simon Glass | 71634f2 | 2016-11-13 14:22:01 -0700 | [diff] [blame] | 429 | #endif |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 430 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 431 | log_err("Invalid bus %d (err=%d)\n", busnum, ret); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 432 | return ret; |
| 433 | } |
| 434 | ret = spi_find_chip_select(bus, cs, &dev); |
| 435 | |
| 436 | /* |
| 437 | * If there is no such device, create one automatically. This means |
| 438 | * that we don't need a device tree node or platform data for the |
| 439 | * SPI flash chip - we will bind to the correct driver. |
| 440 | */ |
| 441 | if (ret == -ENODEV && drv_name) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 442 | dev_dbg(bus, "%s: Binding new device '%s', busnum=%d, cs=%d, driver=%s\n", |
| 443 | __func__, dev_name, busnum, cs, drv_name); |
Simon Glass | 6b18656 | 2014-11-11 10:46:23 -0700 | [diff] [blame] | 444 | ret = device_bind_driver(bus, drv_name, dev_name, &dev); |
Simon Glass | 28f9885 | 2016-11-13 14:22:05 -0700 | [diff] [blame] | 445 | if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 446 | dev_dbg(bus, "%s: Unable to bind driver (ret=%d)\n", |
| 447 | __func__, ret); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 448 | return ret; |
Simon Glass | 28f9885 | 2016-11-13 14:22:05 -0700 | [diff] [blame] | 449 | } |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 450 | plat = dev_get_parent_plat(dev); |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 451 | plat->cs = cs; |
Simon Goldschmidt | 12bfb2e | 2018-10-30 21:09:48 +0100 | [diff] [blame] | 452 | if (speed) { |
| 453 | plat->max_hz = speed; |
| 454 | } else { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 455 | dev_warn(bus, |
| 456 | "Warning: SPI speed fallback to %u kHz\n", |
| 457 | SPI_DEFAULT_SPEED_HZ / 1000); |
Simon Goldschmidt | 12bfb2e | 2018-10-30 21:09:48 +0100 | [diff] [blame] | 458 | plat->max_hz = SPI_DEFAULT_SPEED_HZ; |
| 459 | } |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 460 | plat->mode = mode; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 461 | created = true; |
| 462 | } else if (ret) { |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 463 | dev_err(bus, "Invalid chip select %d:%d (err=%d)\n", busnum, cs, ret); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 464 | return ret; |
Marek Vasut | e2e95e5 | 2021-06-10 14:00:00 +0200 | [diff] [blame] | 465 | } else if (dev) { |
| 466 | plat = dev_get_parent_plat(dev); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | if (!device_active(dev)) { |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 470 | struct spi_slave *slave; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 471 | |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 472 | ret = device_probe(dev); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 473 | if (ret) |
| 474 | goto err; |
Simon Glass | bcbe3d1 | 2015-09-28 23:32:01 -0600 | [diff] [blame] | 475 | slave = dev_get_parent_priv(dev); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 476 | slave->dev = dev; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 477 | } |
| 478 | |
Marcin Wojtas | f7dd537 | 2019-11-21 05:38:47 +0100 | [diff] [blame] | 479 | slave = dev_get_parent_priv(dev); |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 480 | bus_data = dev_get_uclass_priv(bus); |
Patrick Delaunay | b0cc1b8 | 2019-02-27 15:36:44 +0100 | [diff] [blame] | 481 | |
Marcin Wojtas | f7dd537 | 2019-11-21 05:38:47 +0100 | [diff] [blame] | 482 | /* |
| 483 | * In case the operation speed is not yet established by |
| 484 | * dm_spi_claim_bus() ensure the bus is configured properly. |
| 485 | */ |
Ovidiu Panait | 741280e | 2020-12-14 19:06:50 +0200 | [diff] [blame] | 486 | if (!bus_data->speed) { |
Marcin Wojtas | f7dd537 | 2019-11-21 05:38:47 +0100 | [diff] [blame] | 487 | ret = spi_claim_bus(slave); |
| 488 | if (ret) |
| 489 | goto err; |
Vignesh R | 96907c0 | 2016-07-06 10:04:28 +0530 | [diff] [blame] | 490 | } |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 491 | |
Marek Vasut | e2e95e5 | 2021-06-10 14:00:00 +0200 | [diff] [blame] | 492 | /* In case bus frequency or mode changed, update it. */ |
| 493 | if ((speed && bus_data->speed && bus_data->speed != speed) || |
| 494 | (plat && plat->mode != mode)) { |
| 495 | ret = spi_set_speed_mode(bus, speed, mode); |
| 496 | if (ret) |
| 497 | goto err_speed_mode; |
| 498 | } |
| 499 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 500 | *busp = bus; |
Marcin Wojtas | f7dd537 | 2019-11-21 05:38:47 +0100 | [diff] [blame] | 501 | *devp = slave; |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 502 | log_debug("%s: bus=%p, slave=%p\n", __func__, bus, *devp); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 503 | |
| 504 | return 0; |
| 505 | |
Marek Vasut | e2e95e5 | 2021-06-10 14:00:00 +0200 | [diff] [blame] | 506 | err_speed_mode: |
| 507 | spi_release_bus(slave); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 508 | err: |
Patrick Delaunay | 46c5391 | 2020-10-15 17:18:17 +0200 | [diff] [blame] | 509 | log_debug("%s: Error path, created=%d, device '%s'\n", __func__, |
| 510 | created, dev->name); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 511 | if (created) { |
Stefan Roese | 706865a | 2017-03-20 12:51:48 +0100 | [diff] [blame] | 512 | device_remove(dev, DM_REMOVE_NORMAL); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 513 | device_unbind(dev); |
| 514 | } |
| 515 | |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | /* Compatibility function - to be removed */ |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 520 | struct spi_slave *spi_setup_slave(unsigned int busnum, unsigned int cs, |
| 521 | unsigned int speed, unsigned int mode) |
| 522 | { |
| 523 | struct spi_slave *slave; |
| 524 | struct udevice *dev; |
| 525 | int ret; |
| 526 | |
Patrice Chotard | 61708bb | 2022-03-30 09:33:13 +0200 | [diff] [blame] | 527 | ret = _spi_get_bus_and_cs(busnum, cs, speed, mode, NULL, 0, &dev, |
| 528 | &slave); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 529 | if (ret) |
| 530 | return NULL; |
| 531 | |
| 532 | return slave; |
| 533 | } |
| 534 | |
| 535 | void spi_free_slave(struct spi_slave *slave) |
| 536 | { |
Stefan Roese | 706865a | 2017-03-20 12:51:48 +0100 | [diff] [blame] | 537 | device_remove(slave->dev, DM_REMOVE_NORMAL); |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 538 | } |
| 539 | |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 540 | int spi_slave_of_to_plat(struct udevice *dev, struct dm_spi_slave_plat *plat) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 541 | { |
Jagan Teki | 08fe9c2 | 2016-08-08 17:12:12 +0530 | [diff] [blame] | 542 | int mode = 0; |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 543 | int value; |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 544 | |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 545 | plat->cs = dev_read_u32_default(dev, "reg", -1); |
Simon Goldschmidt | 12bfb2e | 2018-10-30 21:09:48 +0100 | [diff] [blame] | 546 | plat->max_hz = dev_read_u32_default(dev, "spi-max-frequency", |
| 547 | SPI_DEFAULT_SPEED_HZ); |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 548 | if (dev_read_bool(dev, "spi-cpol")) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 549 | mode |= SPI_CPOL; |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 550 | if (dev_read_bool(dev, "spi-cpha")) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 551 | mode |= SPI_CPHA; |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 552 | if (dev_read_bool(dev, "spi-cs-high")) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 553 | mode |= SPI_CS_HIGH; |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 554 | if (dev_read_bool(dev, "spi-3wire")) |
Jagan Teki | 379b49d | 2015-12-03 22:19:05 +0530 | [diff] [blame] | 555 | mode |= SPI_3WIRE; |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 556 | if (dev_read_bool(dev, "spi-half-duplex")) |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 557 | mode |= SPI_PREAMBLE; |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 558 | |
| 559 | /* Device DUAL/QUAD mode */ |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 560 | value = dev_read_u32_default(dev, "spi-tx-bus-width", 1); |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 561 | switch (value) { |
| 562 | case 1: |
| 563 | break; |
| 564 | case 2: |
| 565 | mode |= SPI_TX_DUAL; |
| 566 | break; |
| 567 | case 4: |
| 568 | mode |= SPI_TX_QUAD; |
| 569 | break; |
Vignesh Raghavendra | 658df8b | 2019-12-05 15:46:05 +0530 | [diff] [blame] | 570 | case 8: |
| 571 | mode |= SPI_TX_OCTAL; |
| 572 | break; |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 573 | default: |
Simon Glass | 1b7c28f | 2016-11-29 20:00:13 -0700 | [diff] [blame] | 574 | warn_non_spl("spi-tx-bus-width %d not supported\n", value); |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 575 | break; |
| 576 | } |
| 577 | |
Simon Glass | 279e26f | 2017-05-18 20:09:54 -0600 | [diff] [blame] | 578 | value = dev_read_u32_default(dev, "spi-rx-bus-width", 1); |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 579 | switch (value) { |
| 580 | case 1: |
| 581 | break; |
| 582 | case 2: |
Jagan Teki | 08fe9c2 | 2016-08-08 17:12:12 +0530 | [diff] [blame] | 583 | mode |= SPI_RX_DUAL; |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 584 | break; |
| 585 | case 4: |
Jagan Teki | 08fe9c2 | 2016-08-08 17:12:12 +0530 | [diff] [blame] | 586 | mode |= SPI_RX_QUAD; |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 587 | break; |
Vignesh Raghavendra | 658df8b | 2019-12-05 15:46:05 +0530 | [diff] [blame] | 588 | case 8: |
| 589 | mode |= SPI_RX_OCTAL; |
| 590 | break; |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 591 | default: |
Simon Glass | 1b7c28f | 2016-11-29 20:00:13 -0700 | [diff] [blame] | 592 | warn_non_spl("spi-rx-bus-width %d not supported\n", value); |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 593 | break; |
| 594 | } |
| 595 | |
Jagan Teki | 08fe9c2 | 2016-08-08 17:12:12 +0530 | [diff] [blame] | 596 | plat->mode = mode; |
Mugunthan V N | f8e2f92 | 2015-12-23 20:39:37 +0530 | [diff] [blame] | 597 | |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | UCLASS_DRIVER(spi) = { |
| 602 | .id = UCLASS_SPI, |
| 603 | .name = "spi", |
Simon Glass | 9cc36a2 | 2015-01-25 08:27:05 -0700 | [diff] [blame] | 604 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
Simon Glass | 414cc15 | 2021-08-07 07:24:03 -0600 | [diff] [blame] | 605 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | 9119548 | 2016-07-05 17:10:10 -0600 | [diff] [blame] | 606 | .post_bind = dm_scan_fdt_dev, |
Simon Glass | 71634f2 | 2016-11-13 14:22:01 -0700 | [diff] [blame] | 607 | #endif |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 608 | .post_probe = spi_post_probe, |
Simon Glass | 440714e | 2015-01-25 08:27:11 -0700 | [diff] [blame] | 609 | .child_pre_probe = spi_child_pre_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 610 | .per_device_auto = sizeof(struct dm_spi_bus), |
| 611 | .per_child_auto = sizeof(struct spi_slave), |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 612 | .per_child_plat_auto = sizeof(struct dm_spi_slave_plat), |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 613 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | d0cff03 | 2015-01-25 08:27:12 -0700 | [diff] [blame] | 614 | .child_post_bind = spi_child_post_bind, |
Simon Glass | 71634f2 | 2016-11-13 14:22:01 -0700 | [diff] [blame] | 615 | #endif |
Simon Glass | d7af6a4 | 2014-10-13 23:41:52 -0600 | [diff] [blame] | 616 | }; |
| 617 | |
| 618 | UCLASS_DRIVER(spi_generic) = { |
| 619 | .id = UCLASS_SPI_GENERIC, |
| 620 | .name = "spi_generic", |
| 621 | }; |
| 622 | |
| 623 | U_BOOT_DRIVER(spi_generic_drv) = { |
| 624 | .name = "spi_generic_drv", |
| 625 | .id = UCLASS_SPI_GENERIC, |
| 626 | }; |