2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
10 #include <platform_def.h>
12 #include <arch_helpers.h>
13 #include <drivers/io/io_block.h>
15 #include <lib/utils_def.h>
19 #define UNIPHIER_LD11_USB_DESC_BASE 0x30010000
20 #define UNIPHIER_LD20_USB_DESC_BASE 0x30014000
21 #define UNIPHIER_PXS3_USB_DESC_BASE 0x30014000
23 #define UNIPHIER_SRB_OCM_CONT 0x61200000
25 struct uniphier_ld11_trans_op
{
29 struct uniphier_ld11_op
{
31 struct uniphier_ld11_trans_op
*trans_op
;
36 struct uniphier_ld20_trans_op
{
40 struct uniphier_ld20_op
{
42 struct uniphier_ld20_trans_op
*trans_op
;
47 struct uniphier_pxs3_op
{
49 struct uniphier_ld20_trans_op
*trans_op
;
54 static int (*__uniphier_usb_read
)(int lba
, uintptr_t buf
, size_t size
);
56 static void uniphier_ld11_usb_init(void)
58 struct uniphier_ld11_op
*op
= (void *)UNIPHIER_LD11_USB_DESC_BASE
;
60 op
->trans_op
= (void *)(op
+ 1);
62 op
->dev_desc
= op
->trans_op
+ 1;
65 static int uniphier_ld11_usb_read(int lba
, uintptr_t buf
, size_t size
)
67 static int (*rom_usb_read
)(uintptr_t desc
, unsigned int lba
,
68 unsigned int size
, uintptr_t buf
);
71 func_addr
= uniphier_get_soc_revision() == 1 ? 0x3880 : 0x3958;
72 rom_usb_read
= (__typeof(rom_usb_read
))func_addr
;
74 return rom_usb_read(UNIPHIER_LD11_USB_DESC_BASE
, lba
, size
, buf
);
77 static void uniphier_ld20_usb_init(void)
79 struct uniphier_ld20_op
*op
= (void *)UNIPHIER_LD20_USB_DESC_BASE
;
81 op
->trans_op
= (void *)(op
+ 1);
83 op
->dev_desc
= op
->trans_op
+ 1;
86 static int uniphier_ld20_usb_read(int lba
, uintptr_t buf
, size_t size
)
88 static int (*rom_usb_read
)(uintptr_t desc
, unsigned int lba
,
89 unsigned int size
, uintptr_t buf
);
92 rom_usb_read
= (__typeof(rom_usb_read
))0x37f0;
94 mmio_write_32(UNIPHIER_SRB_OCM_CONT
, 0x1ff);
96 /* ROM-API - return 1 on success, 0 on error */
97 ret
= rom_usb_read(UNIPHIER_LD20_USB_DESC_BASE
, lba
, size
, buf
);
99 mmio_write_32(UNIPHIER_SRB_OCM_CONT
, 0);
104 static void uniphier_pxs3_usb_init(void)
106 struct uniphier_pxs3_op
*op
= (void *)UNIPHIER_PXS3_USB_DESC_BASE
;
108 op
->trans_op
= (void *)(op
+ 1);
110 op
->dev_desc
= op
->trans_op
+ 1;
113 static int uniphier_pxs3_usb_read(int lba
, uintptr_t buf
, size_t size
)
115 static int (*rom_usb_read
)(uintptr_t desc
, unsigned int lba
,
116 unsigned int size
, uintptr_t buf
);
119 rom_usb_read
= (__typeof(rom_usb_read
))0x39e8;
121 /* ROM-API - return 1 on success, 0 on error */
122 ret
= rom_usb_read(UNIPHIER_PXS3_USB_DESC_BASE
, lba
, size
, buf
);
127 struct uniphier_usb_rom_param
{
129 int (*read
)(int lba
, uintptr_t buf
, size_t size
);
132 static const struct uniphier_usb_rom_param uniphier_usb_rom_params
[] = {
133 [UNIPHIER_SOC_LD11
] = {
134 .init
= uniphier_ld11_usb_init
,
135 .read
= uniphier_ld11_usb_read
,
137 [UNIPHIER_SOC_LD20
] = {
138 .init
= uniphier_ld20_usb_init
,
139 .read
= uniphier_ld20_usb_read
,
141 [UNIPHIER_SOC_PXS3
] = {
142 .init
= uniphier_pxs3_usb_init
,
143 .read
= uniphier_pxs3_usb_read
,
147 static size_t uniphier_usb_read(int lba
, uintptr_t buf
, size_t size
)
151 inv_dcache_range(buf
, size
);
153 ret
= __uniphier_usb_read(lba
, buf
, size
);
155 inv_dcache_range(buf
, size
);
157 return ret
? 0 : size
;
160 static struct io_block_dev_spec uniphier_usb_dev_spec
= {
162 .offset
= UNIPHIER_BLOCK_BUF_BASE
,
163 .length
= UNIPHIER_BLOCK_BUF_SIZE
,
166 .read
= uniphier_usb_read
,
171 int uniphier_usb_init(unsigned int soc
, uintptr_t *block_dev_spec
)
173 const struct uniphier_usb_rom_param
*param
;
175 assert(soc
< ARRAY_SIZE(uniphier_usb_rom_params
));
176 param
= &uniphier_usb_rom_params
[soc
];
181 __uniphier_usb_read
= param
->read
;
183 *block_dev_spec
= (uintptr_t)&uniphier_usb_dev_spec
;