blob: 7c39aa5f2f5fd99c34101a1f636e7dba95bd9d28 [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>
Simon Glass9bc15642020-02-03 07:36:16 -070010#include <malloc.h>
Simon Glasscceee552016-02-29 15:25:55 -070011#include <dm/device-internal.h>
12#include <dm/lists.h>
Stefan Roeseef58a902017-11-29 16:46:42 +010013#include <dm/uclass-internal.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070014#include <linux/err.h>
Simon Glasscceee552016-02-29 15:25:55 -070015
Simon Glass4131ad52016-05-01 11:36:08 -060016static const char *if_typename_str[IF_TYPE_COUNT] = {
17 [IF_TYPE_IDE] = "ide",
18 [IF_TYPE_SCSI] = "scsi",
19 [IF_TYPE_ATAPI] = "atapi",
20 [IF_TYPE_USB] = "usb",
21 [IF_TYPE_DOC] = "doc",
22 [IF_TYPE_MMC] = "mmc",
23 [IF_TYPE_SD] = "sd",
24 [IF_TYPE_SATA] = "sata",
25 [IF_TYPE_HOST] = "host",
Zhikang Zhang182fccd2017-08-03 02:30:56 -070026 [IF_TYPE_NVME] = "nvme",
Heinrich Schuchardt11206f42018-01-21 19:29:30 +010027 [IF_TYPE_EFI] = "efi",
Tuomas Tynkkynend4580062018-10-15 02:21:10 -070028 [IF_TYPE_VIRTIO] = "virtio",
Simon Glass4131ad52016-05-01 11:36:08 -060029};
30
31static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
Bin Mengb650afa2017-09-10 05:12:51 -070032 [IF_TYPE_IDE] = UCLASS_IDE,
Michal Simekc886f352016-09-08 15:06:45 +020033 [IF_TYPE_SCSI] = UCLASS_SCSI,
Simon Glass4131ad52016-05-01 11:36:08 -060034 [IF_TYPE_ATAPI] = UCLASS_INVALID,
35 [IF_TYPE_USB] = UCLASS_MASS_STORAGE,
36 [IF_TYPE_DOC] = UCLASS_INVALID,
37 [IF_TYPE_MMC] = UCLASS_MMC,
38 [IF_TYPE_SD] = UCLASS_INVALID,
39 [IF_TYPE_SATA] = UCLASS_AHCI,
40 [IF_TYPE_HOST] = UCLASS_ROOT,
Heinrich Schuchardt11206f42018-01-21 19:29:30 +010041 [IF_TYPE_NVME] = UCLASS_NVME,
42 [IF_TYPE_EFI] = UCLASS_EFI,
Tuomas Tynkkynend4580062018-10-15 02:21:10 -070043 [IF_TYPE_VIRTIO] = UCLASS_VIRTIO,
Simon Glass4131ad52016-05-01 11:36:08 -060044};
45
46static enum if_type if_typename_to_iftype(const char *if_typename)
47{
48 int i;
49
50 for (i = 0; i < IF_TYPE_COUNT; i++) {
51 if (if_typename_str[i] &&
52 !strcmp(if_typename, if_typename_str[i]))
53 return i;
54 }
55
56 return IF_TYPE_UNKNOWN;
57}
58
59static enum uclass_id if_type_to_uclass_id(enum if_type if_type)
60{
61 return if_type_uclass_id[if_type];
62}
63
Simon Glass85af5a42017-07-29 11:34:53 -060064const char *blk_get_if_type_name(enum if_type if_type)
65{
66 return if_typename_str[if_type];
67}
68
Simon Glass4131ad52016-05-01 11:36:08 -060069struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum)
70{
71 struct blk_desc *desc;
72 struct udevice *dev;
73 int ret;
74
75 ret = blk_get_device(if_type, devnum, &dev);
76 if (ret)
77 return NULL;
78 desc = dev_get_uclass_platdata(dev);
79
80 return desc;
81}
82
83/*
84 * This function is complicated with driver model. We look up the interface
85 * name in a local table. This gives us an interface type which we can match
86 * against the uclass of the block device's parent.
87 */
88struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
89{
90 enum uclass_id uclass_id;
91 enum if_type if_type;
92 struct udevice *dev;
93 struct uclass *uc;
94 int ret;
95
96 if_type = if_typename_to_iftype(if_typename);
97 if (if_type == IF_TYPE_UNKNOWN) {
98 debug("%s: Unknown interface type '%s'\n", __func__,
99 if_typename);
100 return NULL;
101 }
102 uclass_id = if_type_to_uclass_id(if_type);
103 if (uclass_id == UCLASS_INVALID) {
104 debug("%s: Unknown uclass for interface type'\n",
105 if_typename_str[if_type]);
106 return NULL;
107 }
108
109 ret = uclass_get(UCLASS_BLK, &uc);
110 if (ret)
111 return NULL;
112 uclass_foreach_dev(dev, uc) {
113 struct blk_desc *desc = dev_get_uclass_platdata(dev);
114
115 debug("%s: if_type=%d, devnum=%d: %s, %d, %d\n", __func__,
116 if_type, devnum, dev->name, desc->if_type, desc->devnum);
117 if (desc->devnum != devnum)
118 continue;
119
120 /* Find out the parent device uclass */
121 if (device_get_uclass_id(dev->parent) != uclass_id) {
122 debug("%s: parent uclass %d, this dev %d\n", __func__,
123 device_get_uclass_id(dev->parent), uclass_id);
124 continue;
125 }
126
127 if (device_probe(dev))
128 return NULL;
129
130 debug("%s: Device desc %p\n", __func__, desc);
131 return desc;
132 }
133 debug("%s: No device found\n", __func__);
134
135 return NULL;
136}
137
138/**
Tien Fong Chee10378522018-07-06 16:26:36 +0800139 * blk_get_by_device() - Get the block device descriptor for the given device
140 * @dev: Instance of a storage device
141 *
142 * Return: With block device descriptor on success , NULL if there is no such
143 * block device.
144 */
145struct blk_desc *blk_get_by_device(struct udevice *dev)
146{
Simon Glasscfd72932019-09-25 08:55:56 -0600147 struct udevice *child_dev;
Tien Fong Chee10378522018-07-06 16:26:36 +0800148
Simon Glasscfd72932019-09-25 08:55:56 -0600149 device_foreach_child(child_dev, dev) {
Tien Fong Chee10378522018-07-06 16:26:36 +0800150 if (device_get_uclass_id(child_dev) != UCLASS_BLK)
151 continue;
152
153 return dev_get_uclass_platdata(child_dev);
154 }
155
156 debug("%s: No block device found\n", __func__);
157
158 return NULL;
159}
160
161/**
Simon Glass4131ad52016-05-01 11:36:08 -0600162 * get_desc() - Get the block device descriptor for the given device number
163 *
164 * @if_type: Interface type
165 * @devnum: Device number (0 = first)
166 * @descp: Returns block device descriptor on success
167 * @return 0 on success, -ENODEV if there is no such device and no device
168 * with a higher device number, -ENOENT if there is no such device but there
169 * is one with a higher number, or other -ve on other error.
170 */
171static int get_desc(enum if_type if_type, int devnum, struct blk_desc **descp)
172{
173 bool found_more = false;
174 struct udevice *dev;
175 struct uclass *uc;
176 int ret;
177
178 *descp = NULL;
179 ret = uclass_get(UCLASS_BLK, &uc);
180 if (ret)
181 return ret;
182 uclass_foreach_dev(dev, uc) {
183 struct blk_desc *desc = dev_get_uclass_platdata(dev);
184
185 debug("%s: if_type=%d, devnum=%d: %s, %d, %d\n", __func__,
186 if_type, devnum, dev->name, desc->if_type, desc->devnum);
187 if (desc->if_type == if_type) {
188 if (desc->devnum == devnum) {
189 ret = device_probe(dev);
190 if (ret)
191 return ret;
192
Michal Simekf438b6b2016-11-16 17:37:42 +0100193 *descp = desc;
194 return 0;
Simon Glass4131ad52016-05-01 11:36:08 -0600195 } else if (desc->devnum > devnum) {
196 found_more = true;
197 }
198 }
199 }
200
201 return found_more ? -ENOENT : -ENODEV;
202}
203
Simon Glass13c2c292016-05-01 13:52:30 -0600204int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart)
205{
206 struct udevice *dev;
207 int ret;
208
209 ret = blk_get_device(if_type, devnum, &dev);
210 if (ret)
211 return ret;
212
developerf50d8d12019-08-27 15:32:18 +0800213 return blk_select_hwpart(dev, hwpart);
Simon Glass13c2c292016-05-01 13:52:30 -0600214}
215
Simon Glass4131ad52016-05-01 11:36:08 -0600216int blk_list_part(enum if_type if_type)
217{
218 struct blk_desc *desc;
219 int devnum, ok;
220 int ret;
221
222 for (ok = 0, devnum = 0;; ++devnum) {
223 ret = get_desc(if_type, devnum, &desc);
224 if (ret == -ENODEV)
225 break;
226 else if (ret)
227 continue;
228 if (desc->part_type != PART_TYPE_UNKNOWN) {
229 ++ok;
230 if (devnum)
231 putc('\n');
232 part_print(desc);
233 }
234 }
235 if (!ok)
236 return -ENODEV;
237
238 return 0;
239}
240
241int blk_print_part_devnum(enum if_type if_type, int devnum)
242{
243 struct blk_desc *desc;
244 int ret;
245
246 ret = get_desc(if_type, devnum, &desc);
247 if (ret)
248 return ret;
249 if (desc->type == DEV_TYPE_UNKNOWN)
250 return -ENOENT;
251 part_print(desc);
252
253 return 0;
254}
255
256void blk_list_devices(enum if_type if_type)
257{
258 struct blk_desc *desc;
259 int ret;
260 int i;
261
262 for (i = 0;; ++i) {
263 ret = get_desc(if_type, i, &desc);
264 if (ret == -ENODEV)
265 break;
266 else if (ret)
267 continue;
268 if (desc->type == DEV_TYPE_UNKNOWN)
269 continue; /* list only known devices */
270 printf("Device %d: ", i);
271 dev_print(desc);
272 }
273}
274
275int blk_print_device_num(enum if_type if_type, int devnum)
276{
277 struct blk_desc *desc;
278 int ret;
279
280 ret = get_desc(if_type, devnum, &desc);
281 if (ret)
282 return ret;
283 printf("\nIDE device %d: ", devnum);
284 dev_print(desc);
285
286 return 0;
287}
288
289int blk_show_device(enum if_type if_type, int devnum)
290{
291 struct blk_desc *desc;
292 int ret;
293
294 printf("\nDevice %d: ", devnum);
295 ret = get_desc(if_type, devnum, &desc);
296 if (ret == -ENODEV || ret == -ENOENT) {
297 printf("unknown device\n");
298 return -ENODEV;
299 }
300 if (ret)
301 return ret;
302 dev_print(desc);
303
304 if (desc->type == DEV_TYPE_UNKNOWN)
305 return -ENOENT;
306
307 return 0;
308}
309
310ulong blk_read_devnum(enum if_type if_type, int devnum, lbaint_t start,
311 lbaint_t blkcnt, void *buffer)
312{
313 struct blk_desc *desc;
314 ulong n;
315 int ret;
316
317 ret = get_desc(if_type, devnum, &desc);
318 if (ret)
319 return ret;
320 n = blk_dread(desc, start, blkcnt, buffer);
321 if (IS_ERR_VALUE(n))
322 return n;
323
Simon Glass4131ad52016-05-01 11:36:08 -0600324 return n;
325}
326
327ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
328 lbaint_t blkcnt, const void *buffer)
329{
330 struct blk_desc *desc;
331 int ret;
332
333 ret = get_desc(if_type, devnum, &desc);
334 if (ret)
335 return ret;
336 return blk_dwrite(desc, start, blkcnt, buffer);
337}
338
Simon Glass13c2c292016-05-01 13:52:30 -0600339int blk_select_hwpart(struct udevice *dev, int hwpart)
340{
341 const struct blk_ops *ops = blk_get_ops(dev);
342
343 if (!ops)
344 return -ENOSYS;
345 if (!ops->select_hwpart)
346 return 0;
347
348 return ops->select_hwpart(dev, hwpart);
349}
350
351int blk_dselect_hwpart(struct blk_desc *desc, int hwpart)
352{
developerf50d8d12019-08-27 15:32:18 +0800353 return blk_select_hwpart(desc->bdev, hwpart);
Simon Glass13c2c292016-05-01 13:52:30 -0600354}
355
Simon Glasscceee552016-02-29 15:25:55 -0700356int blk_first_device(int if_type, struct udevice **devp)
357{
358 struct blk_desc *desc;
359 int ret;
360
Stefan Roeseef58a902017-11-29 16:46:42 +0100361 ret = uclass_find_first_device(UCLASS_BLK, devp);
Simon Glasscceee552016-02-29 15:25:55 -0700362 if (ret)
363 return ret;
364 if (!*devp)
365 return -ENODEV;
366 do {
367 desc = dev_get_uclass_platdata(*devp);
368 if (desc->if_type == if_type)
369 return 0;
Stefan Roeseef58a902017-11-29 16:46:42 +0100370 ret = uclass_find_next_device(devp);
Simon Glasscceee552016-02-29 15:25:55 -0700371 if (ret)
372 return ret;
373 } while (*devp);
374
375 return -ENODEV;
376}
377
378int blk_next_device(struct udevice **devp)
379{
380 struct blk_desc *desc;
381 int ret, if_type;
382
383 desc = dev_get_uclass_platdata(*devp);
384 if_type = desc->if_type;
385 do {
Stefan Roeseef58a902017-11-29 16:46:42 +0100386 ret = uclass_find_next_device(devp);
Simon Glasscceee552016-02-29 15:25:55 -0700387 if (ret)
388 return ret;
389 if (!*devp)
390 return -ENODEV;
391 desc = dev_get_uclass_platdata(*devp);
392 if (desc->if_type == if_type)
393 return 0;
394 } while (1);
395}
396
Simon Glassd5d4c102017-04-23 20:02:05 -0600397int blk_find_device(int if_type, int devnum, struct udevice **devp)
Simon Glasscceee552016-02-29 15:25:55 -0700398{
399 struct uclass *uc;
400 struct udevice *dev;
401 int ret;
402
403 ret = uclass_get(UCLASS_BLK, &uc);
404 if (ret)
405 return ret;
406 uclass_foreach_dev(dev, uc) {
407 struct blk_desc *desc = dev_get_uclass_platdata(dev);
408
409 debug("%s: if_type=%d, devnum=%d: %s, %d, %d\n", __func__,
410 if_type, devnum, dev->name, desc->if_type, desc->devnum);
411 if (desc->if_type == if_type && desc->devnum == devnum) {
412 *devp = dev;
Simon Glassd5d4c102017-04-23 20:02:05 -0600413 return 0;
Simon Glasscceee552016-02-29 15:25:55 -0700414 }
415 }
416
417 return -ENODEV;
418}
419
Simon Glassd5d4c102017-04-23 20:02:05 -0600420int blk_get_device(int if_type, int devnum, struct udevice **devp)
421{
422 int ret;
423
424 ret = blk_find_device(if_type, devnum, devp);
425 if (ret)
426 return ret;
427
428 return device_probe(*devp);
429}
430
Simon Glasscceee552016-02-29 15:25:55 -0700431unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
432 lbaint_t blkcnt, void *buffer)
433{
434 struct udevice *dev = block_dev->bdev;
435 const struct blk_ops *ops = blk_get_ops(dev);
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700436 ulong blks_read;
Simon Glasscceee552016-02-29 15:25:55 -0700437
438 if (!ops->read)
439 return -ENOSYS;
440
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700441 if (blkcache_read(block_dev->if_type, block_dev->devnum,
442 start, blkcnt, block_dev->blksz, buffer))
443 return blkcnt;
444 blks_read = ops->read(dev, start, blkcnt, buffer);
445 if (blks_read == blkcnt)
446 blkcache_fill(block_dev->if_type, block_dev->devnum,
447 start, blkcnt, block_dev->blksz, buffer);
448
449 return blks_read;
Simon Glasscceee552016-02-29 15:25:55 -0700450}
451
452unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start,
453 lbaint_t blkcnt, const void *buffer)
454{
455 struct udevice *dev = block_dev->bdev;
456 const struct blk_ops *ops = blk_get_ops(dev);
457
458 if (!ops->write)
459 return -ENOSYS;
460
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700461 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
Simon Glasscceee552016-02-29 15:25:55 -0700462 return ops->write(dev, start, blkcnt, buffer);
463}
464
465unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start,
466 lbaint_t blkcnt)
467{
468 struct udevice *dev = block_dev->bdev;
469 const struct blk_ops *ops = blk_get_ops(dev);
470
471 if (!ops->erase)
472 return -ENOSYS;
473
Eric Nelsonfaf4f052016-03-28 10:05:44 -0700474 blkcache_invalidate(block_dev->if_type, block_dev->devnum);
Simon Glasscceee552016-02-29 15:25:55 -0700475 return ops->erase(dev, start, blkcnt);
476}
477
Simon Glass4f269132017-05-27 11:37:17 -0600478int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
479{
480 struct udevice *dev;
481 enum uclass_id id;
482 int ret;
483
484 device_find_first_child(parent, &dev);
485 if (!dev) {
486 debug("%s: No block device found for parent '%s'\n", __func__,
487 parent->name);
488 return -ENODEV;
489 }
490 id = device_get_uclass_id(dev);
491 if (id != UCLASS_BLK) {
492 debug("%s: Incorrect uclass %s for block device '%s'\n",
493 __func__, uclass_get_name(id), dev->name);
494 return -ENOTBLK;
495 }
496 ret = device_probe(dev);
497 if (ret)
498 return ret;
499 *devp = dev;
500
501 return 0;
502}
503
Simon Glassd089ba32016-05-01 11:36:28 -0600504int blk_find_max_devnum(enum if_type if_type)
505{
506 struct udevice *dev;
507 int max_devnum = -ENODEV;
508 struct uclass *uc;
509 int ret;
510
511 ret = uclass_get(UCLASS_BLK, &uc);
512 if (ret)
513 return ret;
514 uclass_foreach_dev(dev, uc) {
515 struct blk_desc *desc = dev_get_uclass_platdata(dev);
516
517 if (desc->if_type == if_type && desc->devnum > max_devnum)
518 max_devnum = desc->devnum;
519 }
520
521 return max_devnum;
522}
523
Bin Mengfd5eda72018-10-15 02:21:09 -0700524int blk_next_free_devnum(enum if_type if_type)
Simon Glassdbc38612017-04-23 20:02:06 -0600525{
526 int ret;
527
528 ret = blk_find_max_devnum(if_type);
529 if (ret == -ENODEV)
530 return 0;
531 if (ret < 0)
532 return ret;
533
534 return ret + 1;
535}
536
Simon Glasse4fef742017-04-23 20:02:07 -0600537static int blk_claim_devnum(enum if_type if_type, int devnum)
538{
539 struct udevice *dev;
540 struct uclass *uc;
541 int ret;
542
543 ret = uclass_get(UCLASS_BLK, &uc);
544 if (ret)
545 return ret;
546 uclass_foreach_dev(dev, uc) {
547 struct blk_desc *desc = dev_get_uclass_platdata(dev);
548
549 if (desc->if_type == if_type && desc->devnum == devnum) {
550 int next = blk_next_free_devnum(if_type);
551
552 if (next < 0)
553 return next;
554 desc->devnum = next;
555 return 0;
556 }
557 }
558
559 return -ENOENT;
560}
561
Simon Glasscceee552016-02-29 15:25:55 -0700562int blk_create_device(struct udevice *parent, const char *drv_name,
563 const char *name, int if_type, int devnum, int blksz,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200564 lbaint_t lba, struct udevice **devp)
Simon Glasscceee552016-02-29 15:25:55 -0700565{
566 struct blk_desc *desc;
567 struct udevice *dev;
568 int ret;
569
Simon Glassd089ba32016-05-01 11:36:28 -0600570 if (devnum == -1) {
Simon Glasse4fef742017-04-23 20:02:07 -0600571 devnum = blk_next_free_devnum(if_type);
572 } else {
573 ret = blk_claim_devnum(if_type, devnum);
574 if (ret < 0 && ret != -ENOENT)
Simon Glassd089ba32016-05-01 11:36:28 -0600575 return ret;
Simon Glassd089ba32016-05-01 11:36:28 -0600576 }
Simon Glasse4fef742017-04-23 20:02:07 -0600577 if (devnum < 0)
578 return devnum;
Simon Glass77f7fb82016-05-01 13:52:22 -0600579 ret = device_bind_driver(parent, drv_name, name, &dev);
580 if (ret)
581 return ret;
582 desc = dev_get_uclass_platdata(dev);
583 desc->if_type = if_type;
584 desc->blksz = blksz;
Heinrich Schuchardt09ba4ea2019-10-25 12:15:31 +0200585 desc->log2blksz = LOG2(desc->blksz);
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200586 desc->lba = lba;
Simon Glass77f7fb82016-05-01 13:52:22 -0600587 desc->part_type = PART_TYPE_UNKNOWN;
588 desc->bdev = dev;
Simon Glasscceee552016-02-29 15:25:55 -0700589 desc->devnum = devnum;
590 *devp = dev;
591
592 return 0;
593}
594
Simon Glass966b6952016-05-01 11:36:29 -0600595int blk_create_devicef(struct udevice *parent, const char *drv_name,
596 const char *name, int if_type, int devnum, int blksz,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200597 lbaint_t lba, struct udevice **devp)
Simon Glass966b6952016-05-01 11:36:29 -0600598{
599 char dev_name[30], *str;
Simon Glass39e54922016-05-01 13:52:24 -0600600 int ret;
Simon Glass966b6952016-05-01 11:36:29 -0600601
602 snprintf(dev_name, sizeof(dev_name), "%s.%s", parent->name, name);
603 str = strdup(dev_name);
604 if (!str)
605 return -ENOMEM;
606
Simon Glass39e54922016-05-01 13:52:24 -0600607 ret = blk_create_device(parent, drv_name, str, if_type, devnum,
Jean-Jacques Hiblot99b324a2017-06-09 16:45:18 +0200608 blksz, lba, devp);
Simon Glass39e54922016-05-01 13:52:24 -0600609 if (ret) {
610 free(str);
611 return ret;
612 }
613 device_set_name_alloced(*devp);
614
Simon Glass44505972017-07-29 11:34:59 -0600615 return 0;
Simon Glass966b6952016-05-01 11:36:29 -0600616}
617
Simon Glasscceee552016-02-29 15:25:55 -0700618int blk_unbind_all(int if_type)
619{
620 struct uclass *uc;
621 struct udevice *dev, *next;
622 int ret;
623
624 ret = uclass_get(UCLASS_BLK, &uc);
625 if (ret)
626 return ret;
627 uclass_foreach_dev_safe(dev, next, uc) {
628 struct blk_desc *desc = dev_get_uclass_platdata(dev);
629
630 if (desc->if_type == if_type) {
Stefan Roese80b5bc92017-03-20 12:51:48 +0100631 ret = device_remove(dev, DM_REMOVE_NORMAL);
Simon Glasscceee552016-02-29 15:25:55 -0700632 if (ret)
633 return ret;
634 ret = device_unbind(dev);
635 if (ret)
636 return ret;
637 }
638 }
639
640 return 0;
641}
642
Bin Mengcbc3da82018-10-15 02:21:07 -0700643static int blk_post_probe(struct udevice *dev)
644{
Tom Rini1794ae62018-12-05 08:23:38 -0500645#if defined(CONFIG_PARTITIONS) && defined(CONFIG_HAVE_BLOCK_DEVICE)
Bin Mengcbc3da82018-10-15 02:21:07 -0700646 struct blk_desc *desc = dev_get_uclass_platdata(dev);
647
648 part_init(desc);
649#endif
650
651 return 0;
652}
653
Simon Glasscceee552016-02-29 15:25:55 -0700654UCLASS_DRIVER(blk) = {
655 .id = UCLASS_BLK,
656 .name = "blk",
Bin Mengcbc3da82018-10-15 02:21:07 -0700657 .post_probe = blk_post_probe,
Simon Glasscceee552016-02-29 15:25:55 -0700658 .per_device_platdata_auto_alloc_size = sizeof(struct blk_desc),
659};