1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *  * Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 *  * Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in
12 *    the documentation and/or other materials provided with the
13 *    distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifndef _ROM_ROM_H_
30#define _ROM_ROM_H_
31
32
33/* public api */
34#define PUBLIC_API_BASE_4430		(0x28400)
35#define PUBLIC_API_BASE_4460		(0x30400)
36
37#define PUBLIC_GET_DRIVER_MEM_OFFSET (0x04)
38#define PUBLIC_GET_DRIVER_PER_OFFSET (0x08)
39#define PUBLIC_GET_DEVICE_MEM_OFFSET (0x80)
40#define PUBLIC_GET_DEVICE_PER_OFFSET (0x84)
41
42#define DEVICE_NULL	0x40
43#define DEVICE_UART1	0x41
44#define DEVICE_UART2	0x42
45#define DEVICE_UART3	0x43
46#define DEVICE_UART4	0x44
47#define DEVICE_USB	0x45
48#define DEVICE_USBEXT	0x46
49
50#define XFER_MODE_CPU 0
51#define XFER_MODE_DMA 1
52
53#define STATUS_OKAY		0
54#define STATUS_FAILED		1
55#define STATUS_TIMEOUT		2
56#define STATUS_BAD_PARAM	3
57#define STATUS_WAITING		4
58#define STATUS_NO_MEMORY	5
59#define STATUS_INVALID_PTR	6
60
61/* Memory ROM interface */
62struct read_desc {
63	u32 sector_start;
64	u32 sector_count;
65	void *destination;
66};
67
68struct mem_device {
69	u32 initialized;
70	u8 device_type;
71	u8 trials_count;
72	u32 xip_device;
73	u16 search_size;
74	u32 base_address;
75	u16 hs_toc_mask;
76	u16 gp_toc_mask;
77	void *device_data;
78	u16 *boot_options;
79};
80
81struct mem_driver {
82	int (*init)(struct mem_device *md);
83	int (*read)(struct mem_device *md, struct read_desc *rd);
84	int (*configure)(struct mem_device *md, void *config);
85};
86
87
88/* Peripheral ROM interface */
89struct per_handle {
90	void *set_to_null;
91	void (*callback)(struct per_handle *rh);
92	void *data;
93	u32 length;
94	u16 *options;
95	u32 xfer_mode;
96	u32 device_type;
97	volatile u32 status;
98	u16 hs_toc_mask;
99	u16 gp_toc_mask;
100	u32 config_timeout;
101};
102
103struct per_driver {
104	int (*init)(struct per_handle *rh);
105	int (*read)(struct per_handle *rh);
106	int (*write)(struct per_handle *rh);
107	int (*close)(struct per_handle *rh);
108	int (*config)(struct per_handle *rh, void *x);
109};
110
111#define USB_SETCONFIGDESC_ATTRIBUTES      (0)
112#define USB_SETCONFIGDESC_MAXPOWER        (1)
113#define USB_SETSUSPEND_CALLBACK           (2)
114struct per_usb_config {
115	u32 configid;
116	u32 value;
117};
118
119#define API(n) ( (void*) (*((u32 *) (n))) )
120/* ROM API End */
121
122struct usb {
123	struct per_handle dread;
124	struct per_handle dwrite;
125	struct per_driver *io;
126};
127
128int usb_open(struct usb *usb);
129void usb_close(struct usb *usb);
130
131void usb_queue_read(struct usb *usb, void *data, unsigned len);
132int usb_wait_read(struct usb *usb);
133
134void usb_queue_write(struct usb *usb, void *data, unsigned len);
135int usb_wait_write(struct usb *usb);
136
137int usb_read(struct usb *usb, void *data, unsigned len);
138int usb_write(struct usb *usb, void *data, unsigned len);
139
140#endif
141