162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2008 Advanced Micro Devices, Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
1262306a36Sopenharmony_ci * all copies or substantial portions of the Software.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * Author: Stanislaw Skowronek
2362306a36Sopenharmony_ci */
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#ifndef ATOM_H
2662306a36Sopenharmony_ci#define ATOM_H
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#include <linux/mutex.h>
2962306a36Sopenharmony_ci#include <linux/types.h>
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define ATOM_BIOS_MAGIC		0xAA55
3262306a36Sopenharmony_ci#define ATOM_ATI_MAGIC_PTR	0x30
3362306a36Sopenharmony_ci#define ATOM_ATI_MAGIC		" 761295520"
3462306a36Sopenharmony_ci#define ATOM_ROM_TABLE_PTR	0x48
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define ATOM_ROM_MAGIC		"ATOM"
3762306a36Sopenharmony_ci#define ATOM_ROM_MAGIC_PTR	4
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define ATOM_ROM_MSG_PTR	0x10
4062306a36Sopenharmony_ci#define ATOM_ROM_CMD_PTR	0x1E
4162306a36Sopenharmony_ci#define ATOM_ROM_DATA_PTR	0x20
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define ATOM_CMD_INIT		0
4462306a36Sopenharmony_ci#define ATOM_CMD_SETSCLK	0x0A
4562306a36Sopenharmony_ci#define ATOM_CMD_SETMCLK	0x0B
4662306a36Sopenharmony_ci#define ATOM_CMD_SETPCLK	0x0C
4762306a36Sopenharmony_ci#define ATOM_CMD_SPDFANCNTL	0x39
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define ATOM_DATA_FWI_PTR	0xC
5062306a36Sopenharmony_ci#define ATOM_DATA_IIO_PTR	0x32
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#define ATOM_FWI_DEFSCLK_PTR	8
5362306a36Sopenharmony_ci#define ATOM_FWI_DEFMCLK_PTR	0xC
5462306a36Sopenharmony_ci#define ATOM_FWI_MAXSCLK_PTR	0x24
5562306a36Sopenharmony_ci#define ATOM_FWI_MAXMCLK_PTR	0x28
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci#define ATOM_CT_SIZE_PTR	0
5862306a36Sopenharmony_ci#define ATOM_CT_WS_PTR		4
5962306a36Sopenharmony_ci#define ATOM_CT_PS_PTR		5
6062306a36Sopenharmony_ci#define ATOM_CT_PS_MASK		0x7F
6162306a36Sopenharmony_ci#define ATOM_CT_CODE_PTR	6
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define ATOM_OP_CNT		123
6462306a36Sopenharmony_ci#define ATOM_OP_EOT		91
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define ATOM_CASE_MAGIC		0x63
6762306a36Sopenharmony_ci#define ATOM_CASE_END		0x5A5A
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define ATOM_ARG_REG		0
7062306a36Sopenharmony_ci#define ATOM_ARG_PS		1
7162306a36Sopenharmony_ci#define ATOM_ARG_WS		2
7262306a36Sopenharmony_ci#define ATOM_ARG_FB		3
7362306a36Sopenharmony_ci#define ATOM_ARG_ID		4
7462306a36Sopenharmony_ci#define ATOM_ARG_IMM		5
7562306a36Sopenharmony_ci#define ATOM_ARG_PLL		6
7662306a36Sopenharmony_ci#define ATOM_ARG_MC		7
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define ATOM_SRC_DWORD		0
7962306a36Sopenharmony_ci#define ATOM_SRC_WORD0		1
8062306a36Sopenharmony_ci#define ATOM_SRC_WORD8		2
8162306a36Sopenharmony_ci#define ATOM_SRC_WORD16		3
8262306a36Sopenharmony_ci#define ATOM_SRC_BYTE0		4
8362306a36Sopenharmony_ci#define ATOM_SRC_BYTE8		5
8462306a36Sopenharmony_ci#define ATOM_SRC_BYTE16		6
8562306a36Sopenharmony_ci#define ATOM_SRC_BYTE24		7
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define ATOM_WS_QUOTIENT	0x40
8862306a36Sopenharmony_ci#define ATOM_WS_REMAINDER	0x41
8962306a36Sopenharmony_ci#define ATOM_WS_DATAPTR		0x42
9062306a36Sopenharmony_ci#define ATOM_WS_SHIFT		0x43
9162306a36Sopenharmony_ci#define ATOM_WS_OR_MASK		0x44
9262306a36Sopenharmony_ci#define ATOM_WS_AND_MASK	0x45
9362306a36Sopenharmony_ci#define ATOM_WS_FB_WINDOW	0x46
9462306a36Sopenharmony_ci#define ATOM_WS_ATTRIBUTES	0x47
9562306a36Sopenharmony_ci#define ATOM_WS_REGPTR  	0x48
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci#define ATOM_IIO_NOP		0
9862306a36Sopenharmony_ci#define ATOM_IIO_START		1
9962306a36Sopenharmony_ci#define ATOM_IIO_READ		2
10062306a36Sopenharmony_ci#define ATOM_IIO_WRITE		3
10162306a36Sopenharmony_ci#define ATOM_IIO_CLEAR		4
10262306a36Sopenharmony_ci#define ATOM_IIO_SET		5
10362306a36Sopenharmony_ci#define ATOM_IIO_MOVE_INDEX	6
10462306a36Sopenharmony_ci#define ATOM_IIO_MOVE_ATTR	7
10562306a36Sopenharmony_ci#define ATOM_IIO_MOVE_DATA	8
10662306a36Sopenharmony_ci#define ATOM_IIO_END		9
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci#define ATOM_IO_MM		0
10962306a36Sopenharmony_ci#define ATOM_IO_PCI		1
11062306a36Sopenharmony_ci#define ATOM_IO_SYSIO		2
11162306a36Sopenharmony_ci#define ATOM_IO_IIO		0x80
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_cistruct card_info {
11462306a36Sopenharmony_ci	struct drm_device *dev;
11562306a36Sopenharmony_ci	void (* reg_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
11662306a36Sopenharmony_ci        uint32_t (* reg_read)(struct card_info *, uint32_t);          /*  filled by driver */
11762306a36Sopenharmony_ci	void (* ioreg_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
11862306a36Sopenharmony_ci        uint32_t (* ioreg_read)(struct card_info *, uint32_t);          /*  filled by driver */
11962306a36Sopenharmony_ci	void (* mc_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
12062306a36Sopenharmony_ci        uint32_t (* mc_read)(struct card_info *, uint32_t);          /*  filled by driver */
12162306a36Sopenharmony_ci	void (* pll_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
12262306a36Sopenharmony_ci        uint32_t (* pll_read)(struct card_info *, uint32_t);          /*  filled by driver */
12362306a36Sopenharmony_ci};
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistruct atom_context {
12662306a36Sopenharmony_ci	struct card_info *card;
12762306a36Sopenharmony_ci	struct mutex mutex;
12862306a36Sopenharmony_ci	struct mutex scratch_mutex;
12962306a36Sopenharmony_ci	void *bios;
13062306a36Sopenharmony_ci	uint32_t cmd_table, data_table;
13162306a36Sopenharmony_ci	uint16_t *iio;
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci	uint16_t data_block;
13462306a36Sopenharmony_ci	uint32_t fb_base;
13562306a36Sopenharmony_ci	uint32_t divmul[2];
13662306a36Sopenharmony_ci	uint16_t io_attr;
13762306a36Sopenharmony_ci	uint16_t reg_block;
13862306a36Sopenharmony_ci	uint8_t shift;
13962306a36Sopenharmony_ci	int cs_equal, cs_above;
14062306a36Sopenharmony_ci	int io_mode;
14162306a36Sopenharmony_ci	uint32_t *scratch;
14262306a36Sopenharmony_ci	int scratch_size_bytes;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciextern int atom_debug;
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_cistruct atom_context *atom_parse(struct card_info *, void *);
14862306a36Sopenharmony_ciint atom_execute_table(struct atom_context *, int, uint32_t *);
14962306a36Sopenharmony_ciint atom_execute_table_scratch_unlocked(struct atom_context *, int, uint32_t *);
15062306a36Sopenharmony_ciint atom_asic_init(struct atom_context *);
15162306a36Sopenharmony_civoid atom_destroy(struct atom_context *);
15262306a36Sopenharmony_cibool atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size,
15362306a36Sopenharmony_ci			    uint8_t *frev, uint8_t *crev, uint16_t *data_start);
15462306a36Sopenharmony_cibool atom_parse_cmd_header(struct atom_context *ctx, int index,
15562306a36Sopenharmony_ci			   uint8_t *frev, uint8_t *crev);
15662306a36Sopenharmony_ciint atom_allocate_fb_scratch(struct atom_context *ctx);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_cistruct i2c_msg;
15962306a36Sopenharmony_cistruct i2c_adapter;
16062306a36Sopenharmony_ciint radeon_atom_hw_i2c_xfer(struct i2c_adapter *i2c_adap,
16162306a36Sopenharmony_ci			    struct i2c_msg *msgs, int num);
16262306a36Sopenharmony_ciu32 radeon_atom_hw_i2c_func(struct i2c_adapter *adap);
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci#include "atom-types.h"
16562306a36Sopenharmony_ci#include "atombios.h"
16662306a36Sopenharmony_ci#include "ObjectID.h"
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci#endif
169