18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * PMC-Sierra SPC 8001 SAS/SATA based host adapters driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2008-2009 USI Co., Ltd.
58c2ecf20Sopenharmony_ci * All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
98c2ecf20Sopenharmony_ci * are met:
108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
118c2ecf20Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
128c2ecf20Sopenharmony_ci *    without modification.
138c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
148c2ecf20Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
158c2ecf20Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
168c2ecf20Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
178c2ecf20Sopenharmony_ci *    binary redistribution.
188c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
198c2ecf20Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
208c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
238c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
248c2ecf20Sopenharmony_ci * Software Foundation.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci * NO WARRANTY
278c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
288c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
298c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
308c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
318c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
328c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
338c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
348c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
358c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
368c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
378c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#ifndef _PM8001_CHIPS_H_
428c2ecf20Sopenharmony_ci#define _PM8001_CHIPS_H_
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline u32 pm8001_read_32(void *virt_addr)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	return *((u32 *)virt_addr);
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistatic inline void pm8001_write_32(void *addr, u32 offset, __le32 val)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	*((__le32 *)(addr + offset)) = val;
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic inline u32 pm8001_cr32(struct pm8001_hba_info *pm8001_ha, u32 bar,
558c2ecf20Sopenharmony_ci		u32 offset)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	return readl(pm8001_ha->io_mem[bar].memvirtaddr + offset);
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline void pm8001_cw32(struct pm8001_hba_info *pm8001_ha, u32 bar,
618c2ecf20Sopenharmony_ci		u32 addr, u32 val)
628c2ecf20Sopenharmony_ci{
638c2ecf20Sopenharmony_ci	writel(val, pm8001_ha->io_mem[bar].memvirtaddr + addr);
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_cistatic inline u32 pm8001_mr32(void __iomem *addr, u32 offset)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	return readl(addr + offset);
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_cistatic inline void pm8001_mw32(void __iomem *addr, u32 offset, u32 val)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	writel(val, addr + offset);
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_cistatic inline u32 get_pci_bar_index(u32 pcibar)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci		switch (pcibar) {
768c2ecf20Sopenharmony_ci		case 0x18:
778c2ecf20Sopenharmony_ci		case 0x1C:
788c2ecf20Sopenharmony_ci			return 1;
798c2ecf20Sopenharmony_ci		case 0x20:
808c2ecf20Sopenharmony_ci			return 2;
818c2ecf20Sopenharmony_ci		case 0x24:
828c2ecf20Sopenharmony_ci			return 3;
838c2ecf20Sopenharmony_ci		default:
848c2ecf20Sopenharmony_ci			return 0;
858c2ecf20Sopenharmony_ci	}
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#endif  /* _PM8001_CHIPS_H_ */
898c2ecf20Sopenharmony_ci
90