1/*
2 * Broadcom Home Gateway Reference Design
3 * BCM53xx RoboSwitch utility functions
4 *
5 * Copyright 2004, Broadcom Corporation
6 * All Rights Reserved.
7 *
8 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
9 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
10 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
11 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: if_robo.h,v 1.1.1.1 2008/10/15 03:31:34 james26_jang Exp $
13 */
14
15#ifndef _robo_h_
16#define _robo_h_
17
18/* PMII definitions */
19#define PMII_PHYADDR 0x1e
20#define PMII_PAGE_REG     16
21#define PMII_ADDR_REG     17
22#define PMII_ACCESS_STAT  18
23#define PMII_REG_WORD1    24
24#define PMII_REG_WORD2    25
25#define PMII_REG_WORD3    26
26#define PMII_REG_WORD4    27
27#define PMII_MDC_ACCESS_ENB 0x1
28#define PMII_WRITE        0x1
29#define PMII_READ         0x2
30#define PMII_OPCODE_MASK  0x3
31#define PMII_FORMAT_PAGE(page) ((page<<8)  | PMII_MDC_ACCESS_ENB)
32#define PMII_FORMAT_ADDR_WR(addr) ((addr<<8)  | PMII_WRITE)
33#define PMII_FORMAT_ADDR_RD(addr) ((addr<<8)  | PMII_READ)
34
35/* OCP definitions */
36#define BROADCOM_VENDOR_ID      0x14e4
37#define BROADCOM_DEVICE_ID_ROBO BCM47XX_ROBO_ID
38#define REG_BE_8b  0x010000
39#define REG_BE_16b 0x030000
40#define REG_BE_32b 0x0f0000
41#define REG_BE_48b 0x3f0000
42#define REG_BE_64b 0xff0000
43#define REG_CMD_WRITE  0x01000000
44#define REG_CMD_READ   0x02000000
45#define REG_DONE_WRITE 0x40000000
46#define REG_DONE_READ  0x80000000
47#define REG_OFFSET_SW_CTRL      0x00
48#define REG_OFFSET_SW_ADDR      0x04
49#define REG_OFFSET_SW_STATUS    0x0c
50#define REG_OFFSET_SW_LRD       0x10
51#define REG_OFFSET_SW_URD       0x14
52#define REG_OFFSET_SW_LWD       0x18
53#define REG_OFFSET_SW_UWD       0x1c
54
55/* Private state per RoboSwitch */
56typedef struct {
57	void *sbh;			/* SiliconBackplane handle */
58	uint32 coreidx;			/* Current core index */
59	uint32 ssl, clk, mosi, miso;	/* GPIO mapping */
60	int cid, page;			/* Current chip ID and page */
61} robo_info_t;
62
63typedef struct {
64	void *ch;
65	uint16 (*phyrd)(void *ch, uint32 phyaddr, uint32 reg);	          /* read phy register */
66	void (*phywr)(void *ch, uint32 phyaddr, uint32 reg, uint16 val);	/* write phy register */
67} robo_info_pmii_t;
68
69typedef struct {
70	void *ch;
71	uint16 (*phyrd)(void *ch, uint32 phyaddr, uint32 reg);	          /* read phy register */
72	void (*phywr)(void *ch, uint32 phyaddr, uint32 reg, uint16 val);	/* write phy register */
73	void *sbh;			/* SiliconBackplane handle */
74    void *regsva;
75    uint32 *reg_ctrl;
76    uint32 *reg_addr;
77    uint32 *reg_status;
78    uint32 *reg_lrd;
79    uint32 *reg_urd;
80    uint32 *reg_lwd;
81    uint32 *reg_uwd;
82} robo_info_ocp_t;
83
84typedef void (*ROBO_READ)(robo_info_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
85typedef void (*ROBO_WRITE)(robo_info_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
86
87robo_info_t *robosw_attach(void *sbh, uint32 ssl, uint32 clk, uint32 mosi, uint32 miso);
88void robosw_detach(robo_info_t *robo);
89robo_info_pmii_t *robosw_attach_pmii(void);
90void robosw_detach_pmii(robo_info_pmii_t *robo);
91robo_info_ocp_t *robosw_attach_ocp(void);
92void robosw_detach_ocp(robo_info_ocp_t *robo);
93void robosw_rreg(robo_info_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
94void robosw_wreg(robo_info_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
95void robosw_rreg_pmii(robo_info_pmii_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
96void robosw_wreg_pmii(robo_info_pmii_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
97int robosw_pmii_poll(robo_info_pmii_t *robo);
98int robosw_ocp_poll(robo_info_ocp_t *robo, uint32 done_mask);
99void robosw_wreg_ocp(robo_info_ocp_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
100void robosw_rreg_ocp(robo_info_ocp_t *robo, uint8 cid, uint8 page, uint8 addr, uint8 *buf, uint32 len);
101
102typedef struct robo_driver_s {
103  char  *drv_name;
104  ROBO_READ robo_read;
105  ROBO_WRITE robo_write;
106} robo_driver_t;
107
108#define PMII_WREG(robo,reg,val)  (*(robo->phywr))(robo->ch,PMII_PHYADDR,reg,val)
109#define PMII_RREG(robo,reg)  (*(robo->phyrd))(robo->ch,PMII_PHYADDR,reg)
110
111#endif /* _robo_h_ */
112