lubbock_pcic.c revision 1.8
11.8Sthorpej/*      $NetBSD: lubbock_pcic.c,v 1.8 2023/12/20 13:55:18 thorpej Exp $	*/
21.1Sbsh
31.1Sbsh/*-
41.1Sbsh * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Sbsh * All rights reserved.
61.1Sbsh *
71.1Sbsh * This code is derived from software contributed to The NetBSD Foundation
81.1Sbsh * by IWAMOTO Toshihiro.
91.1Sbsh *
101.1Sbsh * Redistribution and use in source and binary forms, with or without
111.1Sbsh * modification, are permitted provided that the following conditions
121.1Sbsh * are met:
131.1Sbsh * 1. Redistributions of source code must retain the above copyright
141.1Sbsh *    notice, this list of conditions and the following disclaimer.
151.1Sbsh * 2. Redistributions in binary form must reproduce the above copyright
161.1Sbsh *    notice, this list of conditions and the following disclaimer in the
171.1Sbsh *    documentation and/or other materials provided with the distribution.
181.1Sbsh *
191.1Sbsh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Sbsh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sbsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sbsh * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Sbsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sbsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sbsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sbsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sbsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sbsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sbsh * POSSIBILITY OF SUCH DAMAGE.
301.1Sbsh */
311.1Sbsh
321.1Sbsh#include <sys/cdefs.h>
331.8Sthorpej__KERNEL_RCSID(0, "$NetBSD: lubbock_pcic.c,v 1.8 2023/12/20 13:55:18 thorpej Exp $");
341.1Sbsh
351.1Sbsh#include <sys/param.h>
361.1Sbsh#include <sys/systm.h>
371.1Sbsh#include <sys/types.h>
381.1Sbsh#include <sys/conf.h>
391.1Sbsh#include <sys/file.h>
401.1Sbsh#include <sys/device.h>
411.1Sbsh#include <sys/kernel.h>
421.1Sbsh#include <sys/kthread.h>
431.1Sbsh
441.7Sdyoung#include <sys/bus.h>
451.1Sbsh
461.1Sbsh#include <dev/pcmcia/pcmciachip.h>
471.1Sbsh#include <dev/pcmcia/pcmciavar.h>
481.1Sbsh#include <arm/sa11x0/sa11x0_reg.h>
491.1Sbsh#include <arm/sa11x0/sa11x0_var.h>
501.1Sbsh#include <arm/sa11x0/sa1111_reg.h>
511.1Sbsh#include <arm/sa11x0/sa1111_var.h>
521.1Sbsh#include <arm/sa11x0/sa11x1_pcicreg.h>
531.1Sbsh#include <arm/sa11x0/sa11xx_pcicvar.h>
541.1Sbsh#include <arm/sa11x0/sa11x1_pcicvar.h>
551.1Sbsh
561.1Sbsh#include <evbarm/lubbock/lubbock_reg.h>
571.1Sbsh#include <evbarm/lubbock/lubbock_var.h>
581.1Sbsh
591.5Srjsstatic	int	sacpcic_match(device_t, cfdata_t, void *);
601.5Srjsstatic	void	sacpcic_attach(device_t, device_t, void *);
611.1Sbshstatic	void	lubbock_set_power(struct sapcic_socket *so, int arg);
621.1Sbshstatic	void	lubbock_socket_setup(struct sapcic_socket *sp);
631.1Sbsh
641.1Sbshstatic struct sapcic_tag lubbock_sacpcic_functions = {
651.1Sbsh	sacpcic_read,
661.1Sbsh	sacpcic_write,
671.1Sbsh	lubbock_set_power,
681.1Sbsh	sacpcic_clear_intr,
691.1Sbsh	sacpcic_intr_establish,
701.1Sbsh	sacpcic_intr_disestablish
711.1Sbsh};
721.1Sbsh
731.5SrjsCFATTACH_DECL_NEW(sacpcic, sizeof(struct sacpcic_softc),
741.1Sbsh    sacpcic_match, sacpcic_attach, NULL, NULL);
751.1Sbsh
761.1Sbshstatic int
771.5Srjssacpcic_match(device_t parent, cfdata_t cf, void *aux)
781.1Sbsh{
791.1Sbsh	return (1);
801.1Sbsh}
811.1Sbsh
821.1Sbshstatic void
831.1Sbshlubbock_socket_setup(struct sapcic_socket *sp)
841.1Sbsh{
851.1Sbsh	sp->power_capability = SAPCIC_POWER_5V | SAPCIC_POWER_3V;
861.1Sbsh	sp->pcictag = &lubbock_sacpcic_functions;
871.1Sbsh}
881.1Sbsh
891.1Sbshstatic void
901.5Srjssacpcic_attach(device_t parent, device_t self, void *aux)
911.1Sbsh{
921.6Sbsh	struct sacpcic_softc *sc = device_private(self);
931.6Sbsh
941.6Sbsh	sc->sc_pc.sc_dev = self;
951.5Srjs	sacpcic_attach_common(device_private(parent),
961.6Sbsh	    sc, aux, lubbock_socket_setup);
971.1Sbsh}
981.1Sbsh
991.1Sbsh
1001.1Sbshstatic void
1011.1Sbshlubbock_set_power(struct sapcic_socket *so, int arg)
1021.1Sbsh{
1031.1Sbsh	struct sacc_softc *sc = so->pcictag_cookie;
1041.5Srjs	struct obio_softc *bsc = device_private(device_parent(sc->sc_dev));
1051.1Sbsh	int s;
1061.1Sbsh	uint16_t tmp;
1071.1Sbsh
1081.1Sbsh	static const uint8_t vval_socket0[] = {
1091.1Sbsh		/* for socket0 (pcmcia) */
1101.1Sbsh		0x00,		/* OFF */
1111.1Sbsh		0x08,		/* 3.3V */
1121.1Sbsh		0x05,		/* 5V */
1131.1Sbsh	};
1141.1Sbsh	static const uint16_t vval_socket1[] = {
1151.1Sbsh		/* for socket1 (CF) */
1161.1Sbsh		0x0000,		/* OFF */
1171.1Sbsh		0x8000,		/* 3.3V */
1181.1Sbsh		0x4000,		/* 5V */
1191.1Sbsh	};
1201.1Sbsh
1211.1Sbsh	if( arg < 0 || SAPCIC_POWER_5V < arg )
1221.1Sbsh		panic("sacpcic_set_power: bogus arg\n");
1231.1Sbsh
1241.1Sbsh	switch( so->socket ){
1251.1Sbsh	case 0:
1261.1Sbsh		bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCGPIOA_DVR,
1271.1Sbsh				  vval_socket0[arg]);
1281.1Sbsh		break;
1291.1Sbsh	case 1:
1301.1Sbsh		s = splhigh();
1311.1Sbsh		tmp = bus_space_read_2(bsc->sc_iot, bsc->sc_obioreg_ioh,
1321.1Sbsh		    LUBBOCK_MISCWR);
1331.1Sbsh		bus_space_write_2(bsc->sc_iot, bsc->sc_obioreg_ioh,
1341.1Sbsh		    LUBBOCK_MISCWR, (tmp & 0x3fff) | vval_socket1[arg] );
1351.1Sbsh		splx(s);
1361.1Sbsh		break;
1371.1Sbsh	default:
1381.5Srjs		aprint_normal("unknown socket number: %d\n", so->socket);
1391.1Sbsh	}
1401.1Sbsh}
141