Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2000-2005, DENX Software Engineering |
| 4 | * Wolfgang Denk <wd@denx.de> |
| 5 | * Copyright (C) Procsys. All rights reserved. |
| 6 | * Mushtaq Khan <mushtaq_k@procsys.com> |
| 7 | * <mushtaqk_921@yahoo.co.in> |
| 8 | * Copyright (C) 2008 Freescale Semiconductor, Inc. |
| 9 | * Dave Liu <daveliu@freescale.com> |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 13 | #include <ahci.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 14 | #include <blk.h> |
Simon Glass | 7d741ac | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 15 | #include <dm.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 16 | #include <part.h> |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 17 | #include <sata.h> |
| 18 | |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 19 | #ifndef CONFIG_AHCI |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 20 | struct blk_desc sata_dev_desc[CONFIG_SYS_SATA_MAX_DEVICE]; |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 21 | #endif |
| 22 | |
| 23 | int sata_reset(struct udevice *dev) |
| 24 | { |
| 25 | struct ahci_ops *ops = ahci_get_ops(dev); |
| 26 | |
| 27 | if (!ops->reset) |
| 28 | return -ENOSYS; |
| 29 | |
| 30 | return ops->reset(dev); |
| 31 | } |
| 32 | |
| 33 | int sata_dm_port_status(struct udevice *dev, int port) |
| 34 | { |
| 35 | struct ahci_ops *ops = ahci_get_ops(dev); |
| 36 | |
| 37 | if (!ops->port_status) |
| 38 | return -ENOSYS; |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 39 | |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 40 | return ops->port_status(dev, port); |
| 41 | } |
| 42 | |
| 43 | int sata_scan(struct udevice *dev) |
| 44 | { |
| 45 | struct ahci_ops *ops = ahci_get_ops(dev); |
| 46 | |
| 47 | if (!ops->scan) |
| 48 | return -ENOSYS; |
| 49 | |
| 50 | return ops->scan(dev); |
| 51 | } |
| 52 | |
| 53 | #ifndef CONFIG_AHCI |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 54 | #ifdef CONFIG_PARTITIONS |
| 55 | struct blk_desc *sata_get_dev(int dev) |
| 56 | { |
| 57 | return (dev < CONFIG_SYS_SATA_MAX_DEVICE) ? &sata_dev_desc[dev] : NULL; |
| 58 | } |
| 59 | #endif |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 60 | #endif |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 61 | |
Simon Glass | 7d741ac | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 62 | static unsigned long sata_bread(struct udevice *dev, lbaint_t start, |
| 63 | lbaint_t blkcnt, void *dst) |
| 64 | { |
| 65 | return -ENOSYS; |
| 66 | } |
| 67 | |
| 68 | static unsigned long sata_bwrite(struct udevice *dev, lbaint_t start, |
| 69 | lbaint_t blkcnt, const void *buffer) |
| 70 | { |
| 71 | return -ENOSYS; |
| 72 | } |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 73 | |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 74 | #ifndef CONFIG_AHCI |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 75 | int __sata_initialize(void) |
| 76 | { |
Tang Yuantian | b450f93 | 2016-11-21 10:24:20 +0800 | [diff] [blame] | 77 | int rc, ret = -1; |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 78 | int i; |
| 79 | |
| 80 | for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) { |
| 81 | memset(&sata_dev_desc[i], 0, sizeof(struct blk_desc)); |
Simon Glass | dbfa32c | 2022-08-11 19:34:59 -0600 | [diff] [blame^] | 82 | sata_dev_desc[i].if_type = UCLASS_AHCI; |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 83 | sata_dev_desc[i].devnum = i; |
| 84 | sata_dev_desc[i].part_type = PART_TYPE_UNKNOWN; |
| 85 | sata_dev_desc[i].type = DEV_TYPE_HARDDISK; |
| 86 | sata_dev_desc[i].lba = 0; |
| 87 | sata_dev_desc[i].blksz = 512; |
| 88 | sata_dev_desc[i].log2blksz = LOG2(sata_dev_desc[i].blksz); |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 89 | rc = init_sata(i); |
| 90 | if (!rc) { |
| 91 | rc = scan_sata(i); |
| 92 | if (!rc && sata_dev_desc[i].lba > 0 && |
Tang Yuantian | b450f93 | 2016-11-21 10:24:20 +0800 | [diff] [blame] | 93 | sata_dev_desc[i].blksz > 0) { |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 94 | part_init(&sata_dev_desc[i]); |
Tang Yuantian | b450f93 | 2016-11-21 10:24:20 +0800 | [diff] [blame] | 95 | ret = i; |
| 96 | } |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Tang Yuantian | b450f93 | 2016-11-21 10:24:20 +0800 | [diff] [blame] | 100 | return ret; |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 101 | } |
| 102 | int sata_initialize(void) __attribute__((weak, alias("__sata_initialize"))); |
| 103 | |
| 104 | __weak int __sata_stop(void) |
| 105 | { |
| 106 | int i, err = 0; |
| 107 | |
| 108 | for (i = 0; i < CONFIG_SYS_SATA_MAX_DEVICE; i++) |
| 109 | err |= reset_sata(i); |
| 110 | |
| 111 | if (err) |
| 112 | printf("Could not reset some SATA devices\n"); |
| 113 | |
| 114 | return err; |
| 115 | } |
| 116 | int sata_stop(void) __attribute__((weak, alias("__sata_stop"))); |
Simon Glass | 821bb52 | 2017-07-29 11:35:15 -0600 | [diff] [blame] | 117 | #endif |
Simon Glass | 3665a40 | 2016-05-01 11:36:11 -0600 | [diff] [blame] | 118 | |
Simon Glass | 7d741ac | 2016-05-01 11:36:26 -0600 | [diff] [blame] | 119 | static const struct blk_ops sata_blk_ops = { |
| 120 | .read = sata_bread, |
| 121 | .write = sata_bwrite, |
| 122 | }; |
| 123 | |
| 124 | U_BOOT_DRIVER(sata_blk) = { |
| 125 | .name = "sata_blk", |
| 126 | .id = UCLASS_BLK, |
| 127 | .ops = &sata_blk_ops, |
| 128 | }; |