blob: 77711144919ba8d53e94c88730ffb68f8043b109 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasscceee552016-02-29 15:25:55 -07002/*
3 * Copyright (C) 2016 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glasscceee552016-02-29 15:25:55 -07005 */
6
7#include <common.h>
8#include <blk.h>
9#include <dm.h>
10#include <dm/device-internal.h>
11#include <dm/lists.h>
Stefan Roeseef58a902017-11-29 16:46:42 +010012#include <dm/uclass-internal.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070013#include <linux/err.h>
Simon Glasscceee552016-02-29 15:25:55 -070014
Simon Glass4131ad52016-05-01 11:36:08 -060015static const char *if_typename_str[IF_TYPE_COUNT] = {
16 [IF_TYPE_IDE] = "ide",
17 [IF_TYPE_SCSI] = "scsi",
18 [IF_TYPE_ATAPI] = "atapi",
19 [IF_TYPE_USB] = "usb",
20 [IF_TYPE_DOC] = "doc",
21 [IF_TYPE_MMC] = "mmc",
22 [IF_TYPE_SD] = "sd",
23 [IF_TYPE_SATA] = "sata",
24 [IF_TYPE_HOST] = "host",
Zhikang Zhang182fccd2017-08-03 02:30:56 -070025 [IF_TYPE_NVME] = "nvme",
Heinrich Schuchardt11206f42018-01-21 19:29:30 +010026 [IF_TYPE_EFI] = "efi",
Tuomas Tynkkynend4580062018-10-15 02:21:10 -070027 [IF_TYPE_VIRTIO] = "virtio",
Simon Glass4131ad52016-05-01 11:36:08 -060028};
29
30static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
Bin Mengb650afa2017-09-10 05:12:51 -070031 [IF_TYPE_IDE] = UCLASS_IDE,
Michal Simekc886f352016-09-08 15:06:45 +020032 [IF_TYPE_SCSI] = UCLASS_SCSI,
Simon Glass4131ad52016-05-01 11:36:08 -060033 [IF_TYPE_ATAPI] = UCLASS_INVALID,
34 [IF_TYPE_USB] = UCLASS_MASS_STORAGE,
35 [IF_TYPE_DOC] = UCLASS_INVALID,
36 [IF_TYPE_MMC] = UCLASS_MMC,
37 [IF_TYPE_SD] = UCLASS_INVALID,
38 [IF_TYPE_SATA] = UCLASS_AHCI,
39 [IF_TYPE_HOST] = UCLASS_ROOT,
Heinrich Schuchardt11206f42018-01-21 19:29:30 +010040 [IF_TYPE_NVME] = UCLASS_NVME,
41 [IF_TYPE_EFI] = UCLASS_EFI,
Tuomas Tynkkynend4580062018-10-15 02:21:10 -070042 [IF_TYPE_VIRTIO] = UCLASS_VIRTIO,
Simon Glass4131ad52016-05-01 11:36:08 -060043};
44
45static enum if_type if_typename_to_iftype(const char *if_typename)
46{
47 int i;
48
49 for (i = 0; i < IF_TYPE_COUNT; i++) {
50 if (if_typename_str[i] &&
51 !strcmp(if_typename, if_typename_str[i]))
52 return i;
53 }
54
55 return IF_TYPE_UNKNOWN;
56}
57
58static enum uclass_id if_type_to_uclass_id(enum if_type if_type)
59{
60 return if_type_uclass_id[if_type];
61}
62
Simon Glass85af5a42017-07-29 11:34:53 -060063const char *blk_get_if_type_name(enum if_type if_type)
64{
65 return if_typename_str[if_type];
66}
67
Simon Glass4131ad52016-05-01 11:36:08 -060068struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum)
69{
70 struct blk_desc *desc;
71 struct udevice *dev;
72 int ret;
73
74 ret = blk_get_device(if_type, devnum, &dev);
75 if (ret)
76 return NULL;
77 desc = dev_get_uclass_platdata(dev);
78
79 return desc;
80}
81
82/*
83 * This function is complicated with driver model. We look up the interface
84 * name in a local table. This gives us an interface type which we can match
85 * against the uclass of the block device's parent.
86 */
87struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
88{
89 enum uclass_id uclass_id;
90 enum if_type if_type;
91 struct udevice *dev;
92 struct uclass *uc;
93 int ret;
94
95 if_type = if_typename_to_iftype(if_typename);
96 if (if_type == IF_TYPE_UNKNOWN) {
97 debug("%s: Unknown interface type '%s'\n", __func__,
98 if_typename);
99 return NULL;
100 }
101 uclass_id = if_type_to_uclass_id(if_type);
102 if (uclass_id == UCLASS_INVALID) {
103 debug("%s: Unknown uclass for interface type'\n",
104 if_typename_str[if_type]);
105 return NULL;
106 }
107
108 ret = uclass_get(UCLASS_BLK, &uc);
109 if (ret)
110 return NULL;
111 uclass_foreach_dev(dev, uc) {
112 struct blk_desc *desc = dev_get_uclass_platdata(dev);
113
114 debug("%s: if_type=%d, devnum=%d: %s, %d, %d\n", __func__,
115 if_type, devnum, dev->name, desc->if_type, desc->devnum);
116 if (desc->devnum != devnum)
117 continue;
118
119 /* Find out the parent device uclass */
120 if (device_get_uclass_id(dev->parent) != uclass_id) {
121 debug("%s: parent uclass %d, this dev %d\n", __func__,
122 device_get_uclass_id(dev->parent), uclass_id);
123 continue;
124 }
125
126 if (device_probe(dev))
127 return NULL;
128
129 debug("%s: Device desc %p\n", __func__, desc);
130 return desc;
131 }
132 debug("%s: No device found\n", __func__);
133
134 return NULL;
135}
136
137/**
Tien Fong Chee10378522018-07-06 16:26:36 +0800138 * blk_get_by_device() - Get the block device descriptor for the given device
139 * @dev: Instance of a storage device
140 *
141 * Return: With block device descriptor on success , NULL if there is no such
142 * block device.
143 */
144struct blk_desc *blk_get_by_device(struct udevice *dev)
145{
Simon Glasscfd72932019-09-25 08:55:56 -0600146 struct udevice *child_dev;
Tien Fong Chee10378522018-07-06 16:26:36 +0800147
Simon Glasscfd72932019-09-25 08:55:56 -0600148 device_foreach_child(child_dev, dev) {
Tien Fong Chee10378522018-07-06 16:26:36 +0800149 if (device_get_uclass_id(child_dev) != UCLASS_BLK)
150 continue;
151
152 return dev_get_uclass_platdata(child_dev);
153 }
154
155 debug("%s: No block device found\n", __func__);
156
157 return NULL;
158}
159
160/**
Simon Glass4131ad52016-05-01 11:36:08 -0600161 * get_desc() - Get the block device descriptor for the given device number
162 *
163 * @if_type: Interface type
164 * @devnum: Device number (0 = first)
165 * @descp: Returns block device descriptor on success
166 * @return 0 on success, -ENODEV if there is no such device and no device
167 * with a higher device number, -ENOENT if there is no such device but there
168 * is one with a higher number, or other -ve on other error.
169 */
170static int get_desc(enum if_type if_type, int devnum, struct blk_desc **descp)
171{
172 bool found_more = false;
173 struct udevice *dev;
174 struct uclass *uc;
175 int ret;
176
177 *descp = NULL;
178 ret = uclass_get(UCLASS_BLK, &uc);
179 if (ret)
180 return ret;
181 uclass_foreach_dev(dev, uc) {
182 struct blk_desc *desc = dev_get_uclass_platdata(dev);
183
184 debug("%s: if_type=%d, devnum=%d: %s, %d, %d\n", __func__,
185 if_type, devnum, dev->name, desc->if_type, desc->devnum);
186 if (desc->if_type == if_type) {
187 if (desc->devnum == devnum) {
188 ret = device_probe(dev);
189 if (ret)
190 return ret;
191
Michal Simekf438b6b2016-11-16 17:37:42 +0100192 *descp = desc;
193 return 0;
Simon Glass4131ad52016-05-01 11:36:08 -0600194 } else if (desc->devnum > devnum) {
195 found_more = true;
196 }
197 }
198 }
199
200 return found_more ? -ENOENT : -ENODEV;
201}
202
Simon Glass13c2c292016-05-01 13:52:30 -0600203int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart)
204{
205 struct udevice *dev;
206 int ret;
207
208 ret = blk_get_device(if_type, devnum, &dev);
209 if (ret)
210 return ret;
211
developerf50d8d12019-08-27 15:32:18 +0800212 return blk_select_hwpart(dev, hwpart);
Simon Glass13c2c292016-05-01 13:52:30 -0600213}
214
Simon Glass4131ad52016-05-01 11:36:08 -0600215int blk_list_part(enum if_type if_type)
216{
217 struct blk_desc *desc;
218 int devnum, ok;
219 int ret;
220
221 for (ok = 0, devnum = 0;; ++devnum) {
222 ret = get_desc(if_type, devnum, &desc);
223 if (ret == -ENODEV)
224 break;
225 else if (ret)
226 continue;
227 if (desc->part_type != PART_TYPE_UNKNOWN) {
228 ++ok;
229 if (devnum)
230 putc('\n');
231 part_print(desc);
232 }
233 }
234 if (!ok)
235 return -ENODEV;
236
237 return 0;
238}
239
240int blk_print_part_devnum(enum if_type if_type, int devnum)
241{
242 struct blk_desc *desc;
243 int ret;
244
245 ret = get_desc(if_type, devnum, &desc);
246 if (ret)
247 return ret;
248 if (desc->type == DEV_TYPE_UNKNOWN)
249 return -ENOENT;
250 part_print(desc);
251
252 return 0;
253}
254
255void blk_list_devices(enum if_type if_type)
256{
257 struct blk_desc *desc;
258 int ret;
259 int i;
260
261 for (i = 0;; ++i) {
262 ret = get_desc(if_type, i, &desc);
263 if (ret == -ENODEV)
264 break;
265 else if (ret)
266 continue;
267 if (desc->type == DEV_TYPE_UNKNOWN)
268 continue; /* list only known devices */
269 printf("Device %d: ", i);
270 dev_print(desc);
271 }
272}
273
274int blk_print_device_num(enum if_type if_type, int devnum)
275{
276 struct blk_desc *desc;
277 int ret;
278
279 ret = get_desc(if_type, devnum, &desc);
280 if (ret)
281 return ret;
282 printf("\nIDE device %d: ", devnum);
283 dev_print(desc);
284
285 return 0;
286}
287
288int blk_show_device(enum if_type if_type, int devnum)
289{
290 struct blk_desc *desc;
291 int ret;
292
293 printf("\nDevice %d: ", devnum);
294 ret = get_desc(if_type, devnum, &desc);
295 if (ret == -ENODEV || ret == -ENOENT) {
296 printf("unknown device\n");
297 return -ENODEV;
298 }
299 if (ret)
300 return ret;
301 dev_print(desc);
302
303 if (desc->type == DEV_TYPE_UNKNOWN)
304 return -ENOENT;
305
306 return 0;
307}
308
309ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start,
310 lbaint_t blkcnt, void *buffer)
311{
312 struct blk_desc *desc;
313 ulong n;
314 int ret;
315
316 ret = get_desc(if_type, devnum, &desc);
317 if (ret)
318 return ret;
319 n = blk_dread(desc, start, blkcnt, buffer);
320 if (IS_ERR_VALUE(n))
321 return n;
322
Simon Glass4131ad52016-05-01 11:36:08 -0600323 return n;
324}
325
326ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
327 lbaint_t blkcnt, const void *buffer)
328{
329 struct blk_desc *desc;
330 int ret;
331
332 ret = get_desc(if_type, devnum, &desc);
333 if (ret)
334 return ret;
335 return blk_dwrite(desc, start, blkcnt, buffer);
336}
337
Simon Glass13c2c292016-05-01 13:52:30 -0600338int blk_select_hwpart(struct udevice *dev, int hwpart)
339{
340 const struct blk_ops *ops = blk_get_ops(dev);
341
342 if (!ops)
343 return -ENOSYS;
344 if (!ops->select_hwpart)
345 return 0;
346
347 return ops->select_hwpart(dev, hwpart);
348}
349
350int blk_dselect_hwpart(struct blk_desc *desc, int hwpart)
351{
developerf50d8d12019-08-27 15:32:18 +0800352 return blk_select_hwpart(desc->bdev, hwpart);
Simon Glass13c2c292016-05-01 13:52:30 -0600353}
354
Simon Glasscceee552016-02-29 15:25:55 -0700355int blk_first_device(int if_type, struct udevice **devp)
356{
357 struct blk_desc *desc;
358 int ret;
359
Stefan Roeseef58a902017-11-29 16:46:42 +0100360 ret = uclass_find_first_device(UCLASS_BLK, devp);
Simon Glasscceee552016-02-29 15:25:55 -0700361 if (ret)
362 return ret;
363 if (!*devp)
364 return -ENODEV;
365 do {
366 desc = dev_get_uclass_platdata(*devp);
367 if (desc->if_type == if_type)
368 return 0;
Stefan Roeseef58a902017-11-29 16:46:42 +0100369 ret = uclass_find_next_device(devp);
Simon Glasscceee552016-02-29 15:25:55 -0700370 if (ret)
371 return ret;
372 } while (*devp);
373
374 return -ENODEV;
375}
376
377int blk_next_device(struct udevice **devp)
378{
379 struct blk_desc *desc;
380 int ret, if_type;
381
382 desc = dev_get_uclass_platdata(*devp);
383 if_type = desc->if_type;
384 do {
Stefan Roeseef58a902017-11-29 16:46:42 +0100385 ret = uclass_find_next_device(devp);
Simon Glasscceee552016-02-29 15:25:55 -0700386 if (ret)
387 return ret;
388 if (!*devp)
389 return -ENODEV;
390 desc = dev_get_uclass_platdata(*devp);
391 if (desc->if_type == if_type)
392 return 0;
393 } while (1);
394}
395
Simon Glassd5d4c102017-04-23 20:02:05 -0600396int blk_find_device(int if_type, int devnum, struct udevice **devp)
Simon Glasscceee552016-02-29 15:25:55 -0700397{
398 struct uclass *uc;
399 struct udevice *dev;
400 int ret;
401
402 ret = uclass_get(UCLASS_BLK, &uc);
403 if (ret)
404 return ret;
405 uclass_foreach_dev(dev, uc) {
406 struct blk_desc *desc = dev_get_uclass_platdata(dev);
407
408 debug("%s: if_type=%d, devnum=%d: %s, %d, %d\n", __func__,
409 if_type, devnum, dev->name, desc->if_type, desc->devnum);
410 if (desc->if_type == if_type && desc->devnum == devnum) {
411 *devp = dev;
Simon Glassd5d4c102017-04-23 20:02:05 -0600412 return 0;
Simon Glasscceee552016-02-29 15:25:55 -0700413 }
414 }
415
416 return -ENODEV;
417}
418
Simon Glassd5d4c102017-04-23 20:02:05 -0600419int blk_get_device(int if_type, int devnum, struct udevice **devp)
420{
421 int ret;
422
423 ret = blk_find_device(if_type, devnum, devp);
424 if (ret)
425 return ret;
426
427 return device_probe(*devp);
428}
429
Simon Glasscceee552016-02-29 15:25:55 -0700430unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
431 lbaint_t blkcnt, void *buffer)
432{
433 struct udevice *dev = block_dev->bdev;
434 const struct blk_ops *ops = blk_get_ops(dev);
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700435 ulong blks_read;
Simon Glasscceee552016-02-29 15:25:55 -0700436
437 if (!ops->read)
438 return -ENOSYS;
439
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700440 if (blkcache_read(block_dev->if_type, block_dev->devnum,
441 start, blkcnt, block_dev->blksz, buffer))
442 return blkcnt;
443 blks_read = ops->read(dev, start, blkcnt, buffer);
444 if (blks_read == blkcnt)
445 blkcache_fill(block_dev->if_type, block_dev->devnum,
446 start, blkcnt, block_dev->blksz, buffer);
447
448 return blks_read;
Simon Glasscceee552016-02-29 15:25:55 -0700449}
450
451unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
452 lbaint_t blkcnt, const void *buffer)
453{
454 struct udevice *dev = block_dev->bdev;
455 const struct blk_ops *ops = blk_get_ops(dev);
456
457 if (!ops->write)
458 return -ENOSYS;
459
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700460 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
Simon Glasscceee552016-02-29 15:25:55 -0700461 return ops->write(dev, start, blkcnt, buffer);
462}
463
464unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
465 lbaint_t blkcnt)
466{
467 struct udevice *dev = block_dev->bdev;
468 const struct blk_ops *ops = blk_get_ops(dev);
469
470 if (!ops->erase)
471 return -ENOSYS;
472
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700473 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
Simon Glasscceee552016-02-29 15:25:55 -0700474 return ops->erase(dev, start, blkcnt);
475}
476
Simon Glass4f269132017-05-27 11:37:17 -0600477int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
478{
479 struct udevice *dev;
480 enum uclass_id id;
481 int ret;
482
483 device_find_first_child(parent, &dev);
484 if (!dev) {
485 debug("%s: No block device found for parent '%s'\n", __func__,
486 parent->name);
487 return -ENODEV;
488 }
489 id = device_get_uclass_id(dev);
490 if (id != UCLASS_BLK) {
491 debug("%s: Incorrect uclass %s for block device '%s'\n",
492 __func__, uclass_get_name(id), dev->name);
493 return -ENOTBLK;
494 }
495 ret = device_probe(dev);
496 if (ret)
497 return ret;
498 *devp = dev;
499
500 return 0;
501}
502
Simon Glassd089ba32016-05-01 11:36:28 -0600503int blk_find_max_devnum(enum if_type if_type)
504{
505 struct udevice *dev;
506 int max_devnum = -ENODEV;
507 struct uclass *uc;
508 int ret;
509
510 ret = uclass_get(UCLASS_BLK, &uc);
511 if (ret)
512 return ret;
513 uclass_foreach_dev(dev, uc) {
514 struct blk_desc *desc = dev_get_uclass_platdata(dev);
515
516 if (desc->if_type == if_type && desc->devnum > max_devnum)
517 max_devnum = desc->devnum;
518 }
519
520 return max_devnum;
521}
522
Bin Mengfd5eda72018-10-15 02:21:09 -0700523int blk_next_free_devnum(enum if_type if_type)
Simon Glassdbc38612017-04-23 20:02:06 -0600524{
525 int ret;
526
527 ret = blk_find_max_devnum(if_type);
528 if (ret == -ENODEV)
529 return 0;
530 if (ret < 0)
531 return ret;
532
533 return ret + 1;
534}
535
Simon Glasse4fef742017-04-23 20:02:07 -0600536static int blk_claim_devnum(enum if_type if_type, int devnum)
537{
538 struct udevice *dev;
539 struct uclass *uc;
540 int ret;
541
542 ret = uclass_get(UCLASS_BLK, &uc);
543 if (ret)
544 return ret;
545 uclass_foreach_dev(dev, uc) {
546 struct blk_desc *desc = dev_get_uclass_platdata(dev);
547
548 if (desc->if_type == if_type && desc->devnum == devnum) {
549 int next = blk_next_free_devnum(if_type);
550
551 if (next < 0)
552 return next;
553 desc->devnum = next;
554 return 0;
555 }
556 }
557
558 return -ENOENT;
559}
560
Simon Glasscceee552016-02-29 15:25:55 -0700561int blk_create_device(struct udevice *parent, const char *drv_name,
562 const char *name, int if_type, int devnum, int blksz,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200563 lbaint_t lba, struct udevice **devp)
Simon Glasscceee552016-02-29 15:25:55 -0700564{
565 struct blk_desc *desc;
566 struct udevice *dev;
567 int ret;
568
Simon Glassd089ba32016-05-01 11:36:28 -0600569 if (devnum == -1) {
Simon Glasse4fef742017-04-23 20:02:07 -0600570 devnum = blk_next_free_devnum(if_type);
571 } else {
572 ret = blk_claim_devnum(if_type, devnum);
573 if (ret < 0 && ret != -ENOENT)
Simon Glassd089ba32016-05-01 11:36:28 -0600574 return ret;
Simon Glassd089ba32016-05-01 11:36:28 -0600575 }
Simon Glasse4fef742017-04-23 20:02:07 -0600576 if (devnum < 0)
577 return devnum;
Simon Glass77f7fb82016-05-01 13:52:22 -0600578 ret = device_bind_driver(parent, drv_name, name, &dev);
579 if (ret)
580 return ret;
581 desc = dev_get_uclass_platdata(dev);
582 desc->if_type = if_type;
583 desc->blksz = blksz;
Heinrich Schuchardt09ba4ea2019-10-25 12:15:31 +0200584 desc->log2blksz = LOG2(desc->blksz);
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200585 desc->lba = lba;
Simon Glass77f7fb82016-05-01 13:52:22 -0600586 desc->part_type = PART_TYPE_UNKNOWN;
587 desc->bdev = dev;
Simon Glasscceee552016-02-29 15:25:55 -0700588 desc->devnum = devnum;
589 *devp = dev;
590
591 return 0;
592}
593
Simon Glass966b6952016-05-01 11:36:29 -0600594int blk_create_devicef(struct udevice *parent, const char *drv_name,
595 const char *name, int if_type, int devnum, int blksz,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200596 lbaint_t lba, struct udevice **devp)
Simon Glass966b6952016-05-01 11:36:29 -0600597{
598 char dev_name[30], *str;
Simon Glass39e54922016-05-01 13:52:24 -0600599 int ret;
Simon Glass966b6952016-05-01 11:36:29 -0600600
601 snprintf(dev_name, sizeof(dev_name), "%s.%s", parent->name, name);
602 str = strdup(dev_name);
603 if (!str)
604 return -ENOMEM;
605
Simon Glass39e54922016-05-01 13:52:24 -0600606 ret = blk_create_device(parent, drv_name, str, if_type, devnum,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200607 blksz, lba, devp);
Simon Glass39e54922016-05-01 13:52:24 -0600608 if (ret) {
609 free(str);
610 return ret;
611 }
612 device_set_name_alloced(*devp);
613
Simon Glass44505972017-07-29 11:34:59 -0600614 return 0;
Simon Glass966b6952016-05-01 11:36:29 -0600615}
616
Simon Glasscceee552016-02-29 15:25:55 -0700617int blk_unbind_all(int if_type)
618{
619 struct uclass *uc;
620 struct udevice *dev, *next;
621 int ret;
622
623 ret = uclass_get(UCLASS_BLK, &uc);
624 if (ret)
625 return ret;
626 uclass_foreach_dev_safe(dev, next, uc) {
627 struct blk_desc *desc = dev_get_uclass_platdata(dev);
628
629 if (desc->if_type == if_type) {
Stefan Roese80b5bc92017-03-20 12:51:48 +0100630 ret = device_remove(dev, DM_REMOVE_NORMAL);
Simon Glasscceee552016-02-29 15:25:55 -0700631 if (ret)
632 return ret;
633 ret = device_unbind(dev);
634 if (ret)
635 return ret;
636 }
637 }
638
639 return 0;
640}
641
Bin Mengcbc3da82018-10-15 02:21:07 -0700642static int blk_post_probe(struct udevice *dev)
643{
Tom Rini1794ae62018-12-05 08:23:38 -0500644#if defined(CONFIG_PARTITIONS) && defined(CONFIG_HAVE_BLOCK_DEVICE)
Bin Mengcbc3da82018-10-15 02:21:07 -0700645 struct blk_desc *desc = dev_get_uclass_platdata(dev);
646
647 part_init(desc);
648#endif
649
650 return 0;
651}
652
Simon Glasscceee552016-02-29 15:25:55 -0700653UCLASS_DRIVER(blk) = {
654 .id = UCLASS_BLK,
655 .name = "blk",
Bin Mengcbc3da82018-10-15 02:21:07 -0700656 .post_probe = blk_post_probe,
Simon Glasscceee552016-02-29 15:25:55 -0700657 .per_device_platdata_auto_alloc_size = sizeof(struct blk_desc),
658};