svn commit: r232214 - in projects/armv6/sys: arm/conf arm/ti/am335x
boot/fdt/dts
Damjan Marion
dmarion at FreeBSD.org
Mon Feb 27 15:42:48 UTC 2012
Author: dmarion
Date: Mon Feb 27 15:42:47 2012
New Revision: 232214
URL: http://svn.freebsd.org/changeset/base/232214
Log:
Add support for AM335x power management IC.
So far it only detects power source but later
should be extended to provide some sysctls.
Approved by: cognet (mentor)
Added:
projects/armv6/sys/arm/ti/am335x/am335x_pmic.c
projects/armv6/sys/arm/ti/am335x/files.beaglebone
Modified:
projects/armv6/sys/arm/conf/BEAGLEBONE
projects/armv6/sys/arm/ti/am335x/am335x_scm_padconf.c
projects/armv6/sys/arm/ti/am335x/std.beaglebone
projects/armv6/sys/boot/fdt/dts/beaglebone.dts
Modified: projects/armv6/sys/arm/conf/BEAGLEBONE
==============================================================================
--- projects/armv6/sys/arm/conf/BEAGLEBONE Mon Feb 27 15:14:36 2012 (r232213)
+++ projects/armv6/sys/arm/conf/BEAGLEBONE Mon Feb 27 15:42:47 2012 (r232214)
@@ -79,7 +79,7 @@ device mmcsd # mmc/sd flash cards
device iicbus
device iic
device ti_i2c
-
+device am335x_pmic # AM335x Power Management IC (TPC65217)
device loop
device ether
Added: projects/armv6/sys/arm/ti/am335x/am335x_pmic.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/armv6/sys/arm/ti/am335x/am335x_pmic.c Mon Feb 27 15:42:47 2012 (r232214)
@@ -0,0 +1,162 @@
+/*-
+ * Copyright (c) 2012 Damjan Marion <dmarion at Freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+/*
+* TPS65217 PMIC companion chip for AM335x SoC sitting on I2C bus
+*/
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/clock.h>
+#include <sys/time.h>
+#include <sys/bus.h>
+#include <sys/resource.h>
+#include <sys/rman.h>
+
+#include <dev/iicbus/iicbus.h>
+#include <dev/iicbus/iiconf.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+
+#include "iicbus_if.h"
+
+#define TPS65217A 0x7
+#define TPS65217B 0xF
+
+#define TPS65217_IIC_ADDR 0x24
+
+/* TPS65217 Reisters */
+#define TPS65217_CHIPID_REG 0x00
+#define TPS65217_STATUS_REG 0x0A
+
+struct am335x_pmic_softc {
+ device_t sc_dev;
+ uint32_t sc_addr;
+ struct intr_config_hook enum_hook;
+};
+
+static int
+am335x_pmic_read(device_t dev, uint8_t addr, uint8_t *data, uint8_t size)
+{
+ struct iic_msg msg[] = {
+ { TPS65217_IIC_ADDR, IIC_M_WR, 1, &addr },
+ { TPS65217_IIC_ADDR, IIC_M_RD, size, data },
+ };
+ return (iicbus_transfer(dev, msg, 2));
+}
+
+static void
+am335x_pmic_identify(driver_t *driver, device_t parent)
+{
+ BUS_ADD_CHILD(parent, 0, "am335x_pmic", 0);
+}
+
+static int
+am335x_pmic_probe(device_t dev)
+{
+ struct am335x_pmic_softc *sc;
+ int error;
+ const char *name, *compatible;
+
+ name = ofw_bus_get_name(dev);
+ compatible = ofw_bus_get_compat(dev);
+
+ sc = device_get_softc(dev);
+ sc->sc_dev = dev;
+ sc->sc_addr = iicbus_get_addr(dev);
+
+ device_set_desc(dev, "TI TPS65217 Power Management IC");
+
+ return (BUS_PROBE_NOWILDCARD);
+}
+
+static void
+am335x_pmic_start(void *xdev)
+{
+ struct am335x_pmic_softc *sc;
+ device_t dev = (device_t)xdev;
+ uint8_t reg;
+ char name[16];
+ char pwr[4][11] = {"Unknown", "USB", "AC", "USB and AC"};
+
+ sc = device_get_softc(dev);
+
+ am335x_pmic_read(dev, TPS65217_CHIPID_REG, ®, 1);
+ switch (reg>>4) {
+ case TPS65217A:
+ sprintf(name, "TPS65217A ver 1.%u", reg & 0xF);
+ break;
+ case TPS65217B:
+ sprintf(name, "TPS65217B ver 1.%u", reg & 0xF);
+ break;
+ default:
+ sprintf(name, "Unknown PMIC");
+ }
+
+ am335x_pmic_read(dev, TPS65217_STATUS_REG, ®, 1);
+ device_printf(dev, "%s powered by %s\n", name, pwr[(reg>>2)&0x03]);
+
+ config_intrhook_disestablish(&sc->enum_hook);
+}
+
+static int
+am335x_pmic_attach(device_t dev)
+{
+ struct am335x_pmic_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ sc->enum_hook.ich_func = am335x_pmic_start;
+ sc->enum_hook.ich_arg = dev;
+
+ if (config_intrhook_establish(&sc->enum_hook) != 0)
+ return (ENOMEM);
+
+ return (0);
+}
+
+static device_method_t am335x_pmic_methods[] = {
+ DEVMETHOD(device_identify, am335x_pmic_identify),
+ DEVMETHOD(device_probe, am335x_pmic_probe),
+ DEVMETHOD(device_attach, am335x_pmic_attach),
+ {0, 0},
+};
+
+static driver_t am335x_pmic_driver = {
+ "am335x_pmic",
+ am335x_pmic_methods,
+ sizeof(struct am335x_pmic_softc),
+};
+
+static devclass_t am335x_pmic_devclass;
+
+DRIVER_MODULE(am335x_pmic, iicbus, am335x_pmic_driver, am335x_pmic_devclass, 0, 0);
+MODULE_VERSION(am335x_pmic, 1);
+MODULE_DEPEND(am335x_pmic, iicbus, 1, 1, 1);
Modified: projects/armv6/sys/arm/ti/am335x/am335x_scm_padconf.c
==============================================================================
--- projects/armv6/sys/arm/ti/am335x/am335x_scm_padconf.c Mon Feb 27 15:14:36 2012 (r232213)
+++ projects/armv6/sys/arm/ti/am335x/am335x_scm_padconf.c Mon Feb 27 15:42:47 2012 (r232214)
@@ -62,17 +62,19 @@ __FBSDID("$FreeBSD$");
.muxmodes[7] = m7, \
}
+#define SLEWCTRL (0x01 << 6) /* faster(0) or slower(1) slew rate. */
#define RXACTIVE (0x01 << 5) /* Input enable value for the Pad */
#define PULLTYPESEL (0x01 << 4) /* Pad pullup/pulldown type selection */
#define PULLUDEN (0x01 << 3) /* Pullup/pulldown enabled */
const struct ti_scm_padstate ti_padstate_devmap[] = {
- {"output", 0 },
- {"output_pullup", PULLTYPESEL },
- {"input", RXACTIVE },
- {"input_pulldown", RXACTIVE | PULLUDEN },
- {"input_pullup", RXACTIVE | PULLUDEN | PULLTYPESEL },
- {"input_pullup_inact", RXACTIVE | PULLTYPESEL },
+ {"output", 0 },
+ {"output_pullup", PULLTYPESEL },
+ {"input", RXACTIVE },
+ {"input_pulldown", RXACTIVE | PULLUDEN },
+ {"input_pullup", RXACTIVE | PULLUDEN | PULLTYPESEL },
+ {"input_pullup_inact", RXACTIVE | PULLTYPESEL },
+ {"input_pullup_inact_slow", RXACTIVE | PULLTYPESEL | SLEWCTRL },
{ .state = NULL }
};
@@ -166,8 +168,10 @@ const struct ti_scm_padconf ti_padconf_d
#if 0 /* Incomplete Entries - fill with data from table 2-7 in datasheet */
_PIN(0x950, "spi0_sclk", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
_PIN(0x954, "spi0_d0", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
- _PIN(0x958, "spi0_d1", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
- _PIN(0x95c, "spi0_cs0", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+#endif
+ _PIN(0x958, "spi0_d1", 4, 7, "spi0_d1", "mmc1_sdwp", "I2C1_SDA", "ehrpwm0_tripzone_input", "pr1_uart0_rxd", "pr1_edio_data_in0", "pr1_edio_data_out0", "gpio0_4"),
+ _PIN(0x95c, "spi0_cs0", 5, 7, "spi0_cs0", "mmc2_sdwp", "I2C1_SCL", "ehrpwm0_synci", "pr1_uart0_txd", "pr1_edio_data_in1", "pr1_edio_data_out1", "gpio0_5"),
+#if 0
_PIN(0x960, "spi0_cs1", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
_PIN(0x964, "ecap0_in_pwm0_out",0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
_PIN(0x968, "uart0_ctsn", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
@@ -178,8 +182,10 @@ const struct ti_scm_padconf ti_padconf_d
_PIN(0x97c, "uart1_rtsn", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
_PIN(0x980, "uart1_rxd", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
_PIN(0x984, "uart1_txd", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
- _PIN(0x988, "i2c0_sda", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
- _PIN(0x98c, "i2c0_scl", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
+#endif
+ _PIN(0x988, "I2C0_SDA", 101, 7, "I2C0_SDA", "timer4", "uart2_ctsn", "eCAP2_in_PWM2_out", NULL, NULL, NULL, "gpio3_5"),
+ _PIN(0x98c, "I2C0_SCL", 102, 7, "I2C0_SCL", "timer7", "uart2_rtsn", "eCAP1_in_PWM1_out", NULL, NULL, NULL, "gpio3_6"),
+#if 0
_PIN(0x990, "mcasp0_aclkx", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
_PIN(0x994, "mcasp0_fsx", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
_PIN(0x998, "mcasp0_axr0", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
Added: projects/armv6/sys/arm/ti/am335x/files.beaglebone
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/armv6/sys/arm/ti/am335x/files.beaglebone Mon Feb 27 15:42:47 2012 (r232214)
@@ -0,0 +1,3 @@
+#$FreeBSD$
+
+arm/ti/am335x/am335x_pmic.c optional am335x_pmic
Modified: projects/armv6/sys/arm/ti/am335x/std.beaglebone
==============================================================================
--- projects/armv6/sys/arm/ti/am335x/std.beaglebone Mon Feb 27 15:14:36 2012 (r232213)
+++ projects/armv6/sys/arm/ti/am335x/std.beaglebone Mon Feb 27 15:42:47 2012 (r232214)
@@ -1,3 +1,4 @@
# $FreeBSD$
-include "../ti/am335x/std.am335x"
+files "../ti/am335x/files.beaglebone"
+include "../ti/am335x/std.am335x"
Modified: projects/armv6/sys/boot/fdt/dts/beaglebone.dts
==============================================================================
--- projects/armv6/sys/boot/fdt/dts/beaglebone.dts Mon Feb 27 15:14:36 2012 (r232213)
+++ projects/armv6/sys/boot/fdt/dts/beaglebone.dts Mon Feb 27 15:42:47 2012 (r232214)
@@ -64,6 +64,9 @@
reg = < 0x44e10000 0x2000 >;
/* Set of triplets < padname, muxname, padstate> */
scm-pad-config =
+ /* I2C0 */
+ "I2C0_SDA", "I2C0_SDA","input_pullup_inact_slow",
+ "I2C0_SCL", "I2C0_SCL","input_pullup_inact_slow",
/* Ethernet */
"MII1_RX_ER", "gmii1_rxerr", "input",
"MII1_TX_EN", "gmii1_txen", "output",
@@ -133,27 +136,17 @@
};
i2c0: i2c at 44e0b000 {
+ #address-cells = <1>;
+ #size-cells = <0>;
compatible = "ti,i2c";
reg =< 0x44e0b000 0x1000 >;
interrupts = <70>;
interrupt-parent = <&AINTC>;
i2c-device-id = <0>;
- };
-
- i2c1: i2c at 4802a000 {
- compatible = "ti,i2c";
- reg =< 0x4802a000 0x1000 >;
- interrupts = <71>;
- interrupt-parent = <&AINTC>;
- i2c-device-id = <1>;
- };
-
- i2c2: i2c at 4819c000 {
- compatible = "ti,i2c";
- reg =< 0x4819c000 0x1000 >;
- interrupts = <30>;
- interrupt-parent = <&AINTC>;
- i2c-device-id = <2>;
+ pmic at 24 {
+ compatible = "ti,am335x-pmic";
+ reg = <0x24>;
+ };
};
};
More information about the svn-src-projects
mailing list