162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2008-2009 USI Co., Ltd.
562306a36Sopenharmony_ci * All rights reserved.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
862306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
962306a36Sopenharmony_ci * are met:
1062306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1162306a36Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
1262306a36Sopenharmony_ci *    without modification.
1362306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1462306a36Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
1562306a36Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
1662306a36Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
1762306a36Sopenharmony_ci *    binary redistribution.
1862306a36Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
1962306a36Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
2062306a36Sopenharmony_ci *    from this software without specific prior written permission.
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2362306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2462306a36Sopenharmony_ci * Software Foundation.
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * NO WARRANTY
2762306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2862306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2962306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3062306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3162306a36Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3262306a36Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3362306a36Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3462306a36Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3562306a36Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
3662306a36Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3762306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
3862306a36Sopenharmony_ci *
3962306a36Sopenharmony_ci */
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci#ifndef _PM8001_CHIPS_H_
4262306a36Sopenharmony_ci#define _PM8001_CHIPS_H_
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cistatic inline u32 pm8001_read_32(void *virt_addr)
4562306a36Sopenharmony_ci{
4662306a36Sopenharmony_ci	return *((u32 *)virt_addr);
4762306a36Sopenharmony_ci}
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_cistatic inline void pm8001_write_32(void *addr, u32 offset, __le32 val)
5062306a36Sopenharmony_ci{
5162306a36Sopenharmony_ci	*((__le32 *)(addr + offset)) = val;
5262306a36Sopenharmony_ci}
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_cistatic inline u32 pm8001_cr32(struct pm8001_hba_info *pm8001_ha, u32 bar,
5562306a36Sopenharmony_ci		u32 offset)
5662306a36Sopenharmony_ci{
5762306a36Sopenharmony_ci	return readl(pm8001_ha->io_mem[bar].memvirtaddr + offset);
5862306a36Sopenharmony_ci}
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistatic inline void pm8001_cw32(struct pm8001_hba_info *pm8001_ha, u32 bar,
6162306a36Sopenharmony_ci		u32 addr, u32 val)
6262306a36Sopenharmony_ci{
6362306a36Sopenharmony_ci	writel(val, pm8001_ha->io_mem[bar].memvirtaddr + addr);
6462306a36Sopenharmony_ci}
6562306a36Sopenharmony_cistatic inline u32 pm8001_mr32(void __iomem *addr, u32 offset)
6662306a36Sopenharmony_ci{
6762306a36Sopenharmony_ci	return readl(addr + offset);
6862306a36Sopenharmony_ci}
6962306a36Sopenharmony_cistatic inline void pm8001_mw32(void __iomem *addr, u32 offset, u32 val)
7062306a36Sopenharmony_ci{
7162306a36Sopenharmony_ci	writel(val, addr + offset);
7262306a36Sopenharmony_ci}
7362306a36Sopenharmony_cistatic inline u32 get_pci_bar_index(u32 pcibar)
7462306a36Sopenharmony_ci{
7562306a36Sopenharmony_ci		switch (pcibar) {
7662306a36Sopenharmony_ci		case 0x18:
7762306a36Sopenharmony_ci		case 0x1C:
7862306a36Sopenharmony_ci			return 1;
7962306a36Sopenharmony_ci		case 0x20:
8062306a36Sopenharmony_ci			return 2;
8162306a36Sopenharmony_ci		case 0x24:
8262306a36Sopenharmony_ci			return 3;
8362306a36Sopenharmony_ci		default:
8462306a36Sopenharmony_ci			return 0;
8562306a36Sopenharmony_ci	}
8662306a36Sopenharmony_ci}
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#endif  /* _PM8001_CHIPS_H_ */
8962306a36Sopenharmony_ci
90