18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2008 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Author: Stanislaw Skowronek
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#ifndef ATOM_H
268c2ecf20Sopenharmony_ci#define ATOM_H
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#include <linux/mutex.h>
298c2ecf20Sopenharmony_ci#include <linux/types.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define ATOM_BIOS_MAGIC		0xAA55
328c2ecf20Sopenharmony_ci#define ATOM_ATI_MAGIC_PTR	0x30
338c2ecf20Sopenharmony_ci#define ATOM_ATI_MAGIC		" 761295520"
348c2ecf20Sopenharmony_ci#define ATOM_ROM_TABLE_PTR	0x48
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define ATOM_ROM_MAGIC		"ATOM"
378c2ecf20Sopenharmony_ci#define ATOM_ROM_MAGIC_PTR	4
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define ATOM_ROM_MSG_PTR	0x10
408c2ecf20Sopenharmony_ci#define ATOM_ROM_CMD_PTR	0x1E
418c2ecf20Sopenharmony_ci#define ATOM_ROM_DATA_PTR	0x20
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define ATOM_CMD_INIT		0
448c2ecf20Sopenharmony_ci#define ATOM_CMD_SETSCLK	0x0A
458c2ecf20Sopenharmony_ci#define ATOM_CMD_SETMCLK	0x0B
468c2ecf20Sopenharmony_ci#define ATOM_CMD_SETPCLK	0x0C
478c2ecf20Sopenharmony_ci#define ATOM_CMD_SPDFANCNTL	0x39
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define ATOM_DATA_FWI_PTR	0xC
508c2ecf20Sopenharmony_ci#define ATOM_DATA_IIO_PTR	0x32
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define ATOM_FWI_DEFSCLK_PTR	8
538c2ecf20Sopenharmony_ci#define ATOM_FWI_DEFMCLK_PTR	0xC
548c2ecf20Sopenharmony_ci#define ATOM_FWI_MAXSCLK_PTR	0x24
558c2ecf20Sopenharmony_ci#define ATOM_FWI_MAXMCLK_PTR	0x28
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define ATOM_CT_SIZE_PTR	0
588c2ecf20Sopenharmony_ci#define ATOM_CT_WS_PTR		4
598c2ecf20Sopenharmony_ci#define ATOM_CT_PS_PTR		5
608c2ecf20Sopenharmony_ci#define ATOM_CT_PS_MASK		0x7F
618c2ecf20Sopenharmony_ci#define ATOM_CT_CODE_PTR	6
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define ATOM_OP_CNT		123
648c2ecf20Sopenharmony_ci#define ATOM_OP_EOT		91
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define ATOM_CASE_MAGIC		0x63
678c2ecf20Sopenharmony_ci#define ATOM_CASE_END		0x5A5A
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define ATOM_ARG_REG		0
708c2ecf20Sopenharmony_ci#define ATOM_ARG_PS		1
718c2ecf20Sopenharmony_ci#define ATOM_ARG_WS		2
728c2ecf20Sopenharmony_ci#define ATOM_ARG_FB		3
738c2ecf20Sopenharmony_ci#define ATOM_ARG_ID		4
748c2ecf20Sopenharmony_ci#define ATOM_ARG_IMM		5
758c2ecf20Sopenharmony_ci#define ATOM_ARG_PLL		6
768c2ecf20Sopenharmony_ci#define ATOM_ARG_MC		7
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define ATOM_SRC_DWORD		0
798c2ecf20Sopenharmony_ci#define ATOM_SRC_WORD0		1
808c2ecf20Sopenharmony_ci#define ATOM_SRC_WORD8		2
818c2ecf20Sopenharmony_ci#define ATOM_SRC_WORD16		3
828c2ecf20Sopenharmony_ci#define ATOM_SRC_BYTE0		4
838c2ecf20Sopenharmony_ci#define ATOM_SRC_BYTE8		5
848c2ecf20Sopenharmony_ci#define ATOM_SRC_BYTE16		6
858c2ecf20Sopenharmony_ci#define ATOM_SRC_BYTE24		7
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define ATOM_WS_QUOTIENT	0x40
888c2ecf20Sopenharmony_ci#define ATOM_WS_REMAINDER	0x41
898c2ecf20Sopenharmony_ci#define ATOM_WS_DATAPTR		0x42
908c2ecf20Sopenharmony_ci#define ATOM_WS_SHIFT		0x43
918c2ecf20Sopenharmony_ci#define ATOM_WS_OR_MASK		0x44
928c2ecf20Sopenharmony_ci#define ATOM_WS_AND_MASK	0x45
938c2ecf20Sopenharmony_ci#define ATOM_WS_FB_WINDOW	0x46
948c2ecf20Sopenharmony_ci#define ATOM_WS_ATTRIBUTES	0x47
958c2ecf20Sopenharmony_ci#define ATOM_WS_REGPTR  	0x48
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define ATOM_IIO_NOP		0
988c2ecf20Sopenharmony_ci#define ATOM_IIO_START		1
998c2ecf20Sopenharmony_ci#define ATOM_IIO_READ		2
1008c2ecf20Sopenharmony_ci#define ATOM_IIO_WRITE		3
1018c2ecf20Sopenharmony_ci#define ATOM_IIO_CLEAR		4
1028c2ecf20Sopenharmony_ci#define ATOM_IIO_SET		5
1038c2ecf20Sopenharmony_ci#define ATOM_IIO_MOVE_INDEX	6
1048c2ecf20Sopenharmony_ci#define ATOM_IIO_MOVE_ATTR	7
1058c2ecf20Sopenharmony_ci#define ATOM_IIO_MOVE_DATA	8
1068c2ecf20Sopenharmony_ci#define ATOM_IIO_END		9
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define ATOM_IO_MM		0
1098c2ecf20Sopenharmony_ci#define ATOM_IO_PCI		1
1108c2ecf20Sopenharmony_ci#define ATOM_IO_SYSIO		2
1118c2ecf20Sopenharmony_ci#define ATOM_IO_IIO		0x80
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistruct card_info {
1148c2ecf20Sopenharmony_ci	struct drm_device *dev;
1158c2ecf20Sopenharmony_ci	void (* reg_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
1168c2ecf20Sopenharmony_ci        uint32_t (* reg_read)(struct card_info *, uint32_t);          /*  filled by driver */
1178c2ecf20Sopenharmony_ci	void (* ioreg_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
1188c2ecf20Sopenharmony_ci        uint32_t (* ioreg_read)(struct card_info *, uint32_t);          /*  filled by driver */
1198c2ecf20Sopenharmony_ci	void (* mc_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
1208c2ecf20Sopenharmony_ci        uint32_t (* mc_read)(struct card_info *, uint32_t);          /*  filled by driver */
1218c2ecf20Sopenharmony_ci	void (* pll_write)(struct card_info *, uint32_t, uint32_t);   /*  filled by driver */
1228c2ecf20Sopenharmony_ci        uint32_t (* pll_read)(struct card_info *, uint32_t);          /*  filled by driver */
1238c2ecf20Sopenharmony_ci};
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistruct atom_context {
1268c2ecf20Sopenharmony_ci	struct card_info *card;
1278c2ecf20Sopenharmony_ci	struct mutex mutex;
1288c2ecf20Sopenharmony_ci	struct mutex scratch_mutex;
1298c2ecf20Sopenharmony_ci	void *bios;
1308c2ecf20Sopenharmony_ci	uint32_t cmd_table, data_table;
1318c2ecf20Sopenharmony_ci	uint16_t *iio;
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci	uint16_t data_block;
1348c2ecf20Sopenharmony_ci	uint32_t fb_base;
1358c2ecf20Sopenharmony_ci	uint32_t divmul[2];
1368c2ecf20Sopenharmony_ci	uint16_t io_attr;
1378c2ecf20Sopenharmony_ci	uint16_t reg_block;
1388c2ecf20Sopenharmony_ci	uint8_t shift;
1398c2ecf20Sopenharmony_ci	int cs_equal, cs_above;
1408c2ecf20Sopenharmony_ci	int io_mode;
1418c2ecf20Sopenharmony_ci	uint32_t *scratch;
1428c2ecf20Sopenharmony_ci	int scratch_size_bytes;
1438c2ecf20Sopenharmony_ci};
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ciextern int atom_debug;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistruct atom_context *atom_parse(struct card_info *, void *);
1488c2ecf20Sopenharmony_ciint atom_execute_table(struct atom_context *, int, uint32_t *);
1498c2ecf20Sopenharmony_ciint atom_execute_table_scratch_unlocked(struct atom_context *, int, uint32_t *);
1508c2ecf20Sopenharmony_ciint atom_asic_init(struct atom_context *);
1518c2ecf20Sopenharmony_civoid atom_destroy(struct atom_context *);
1528c2ecf20Sopenharmony_cibool atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size,
1538c2ecf20Sopenharmony_ci			    uint8_t *frev, uint8_t *crev, uint16_t *data_start);
1548c2ecf20Sopenharmony_cibool atom_parse_cmd_header(struct atom_context *ctx, int index,
1558c2ecf20Sopenharmony_ci			   uint8_t *frev, uint8_t *crev);
1568c2ecf20Sopenharmony_ciint atom_allocate_fb_scratch(struct atom_context *ctx);
1578c2ecf20Sopenharmony_ci#include "atom-types.h"
1588c2ecf20Sopenharmony_ci#include "atombios.h"
1598c2ecf20Sopenharmony_ci#include "ObjectID.h"
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#endif
162