Deleted Added
full compact
ti_i2c.c (282675) ti_i2c.c (283276)
1/*-
2 * Copyright (c) 2011 Ben Gray <ben.r.gray@gmail.com>.
3 * Copyright (c) 2014 Luiz Otavio O Souza <loos@freebsd.org>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 31 unchanged lines hidden (view full) ---

40 *
41 *
42 * WARNING: This driver uses mtx_sleep and interrupts to perform transactions,
43 * which means you can't do a transaction during startup before the interrupts
44 * have been enabled. Hint - the freebsd function config_intrhook_establish().
45 */
46
47#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2011 Ben Gray <ben.r.gray@gmail.com>.
3 * Copyright (c) 2014 Luiz Otavio O Souza <loos@freebsd.org>.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 31 unchanged lines hidden (view full) ---

40 *
41 *
42 * WARNING: This driver uses mtx_sleep and interrupts to perform transactions,
43 * which means you can't do a transaction during startup before the interrupts
44 * have been enabled. Hint - the freebsd function config_intrhook_establish().
45 */
46
47#include <sys/cdefs.h>
48__FBSDID("$FreeBSD: head/sys/arm/ti/ti_i2c.c 282675 2015-05-09 03:39:18Z loos $");
48__FBSDID("$FreeBSD: head/sys/arm/ti/ti_i2c.c 283276 2015-05-22 03:16:18Z gonzo $");
49
50#include <sys/param.h>
51#include <sys/systm.h>
52#include <sys/bus.h>
53#include <sys/conf.h>
54#include <sys/kernel.h>
55#include <sys/lock.h>
56#include <sys/mbuf.h>

--- 5 unchanged lines hidden (view full) ---

62#include <machine/bus.h>
63
64#include <dev/ofw/openfirm.h>
65#include <dev/ofw/ofw_bus.h>
66#include <dev/ofw/ofw_bus_subr.h>
67
68#include <arm/ti/ti_cpuid.h>
69#include <arm/ti/ti_prcm.h>
49
50#include <sys/param.h>
51#include <sys/systm.h>
52#include <sys/bus.h>
53#include <sys/conf.h>
54#include <sys/kernel.h>
55#include <sys/lock.h>
56#include <sys/mbuf.h>

--- 5 unchanged lines hidden (view full) ---

62#include <machine/bus.h>
63
64#include <dev/ofw/openfirm.h>
65#include <dev/ofw/ofw_bus.h>
66#include <dev/ofw/ofw_bus_subr.h>
67
68#include <arm/ti/ti_cpuid.h>
69#include <arm/ti/ti_prcm.h>
70#include <arm/ti/ti_hwmods.h>
70#include <arm/ti/ti_i2c.h>
71
72#include <dev/iicbus/iiconf.h>
73#include <dev/iicbus/iicbus.h>
74
75#include "iicbus_if.h"
76
77/**
78 * I2C device driver context, a pointer to this is stored in the device
79 * driver structure.
80 */
81struct ti_i2c_softc
82{
83 device_t sc_dev;
71#include <arm/ti/ti_i2c.h>
72
73#include <dev/iicbus/iiconf.h>
74#include <dev/iicbus/iicbus.h>
75
76#include "iicbus_if.h"
77
78/**
79 * I2C device driver context, a pointer to this is stored in the device
80 * driver structure.
81 */
82struct ti_i2c_softc
83{
84 device_t sc_dev;
84 uint32_t device_id;
85 clk_ident_t clk_id;
85 struct resource* sc_irq_res;
86 struct resource* sc_mem_res;
87 device_t sc_iicbus;
88
89 void* sc_irq_h;
90
91 struct mtx sc_mtx;
92

--- 595 unchanged lines hidden (view full) ---

688 return (err);
689
690 return (IIC_ENOADDR);
691}
692
693static int
694ti_i2c_activate(device_t dev)
695{
86 struct resource* sc_irq_res;
87 struct resource* sc_mem_res;
88 device_t sc_iicbus;
89
90 void* sc_irq_h;
91
92 struct mtx sc_mtx;
93

--- 595 unchanged lines hidden (view full) ---

689 return (err);
690
691 return (IIC_ENOADDR);
692}
693
694static int
695ti_i2c_activate(device_t dev)
696{
696 clk_ident_t clk;
697 int err;
698 struct ti_i2c_softc *sc;
699
700 sc = (struct ti_i2c_softc*)device_get_softc(dev);
701
702 /*
703 * 1. Enable the functional and interface clocks (see Section
704 * 23.1.5.1.1.1.1).
705 */
697 int err;
698 struct ti_i2c_softc *sc;
699
700 sc = (struct ti_i2c_softc*)device_get_softc(dev);
701
702 /*
703 * 1. Enable the functional and interface clocks (see Section
704 * 23.1.5.1.1.1.1).
705 */
706 clk = I2C0_CLK + sc->device_id;
707 err = ti_prcm_clk_enable(clk);
706 err = ti_prcm_clk_enable(sc->clk_id);
708 if (err)
709 return (err);
710
711 return (ti_i2c_reset(sc, IIC_UNKNOWN));
712}
713
714/**
715 * ti_i2c_deactivate - deactivates the controller and releases resources

--- 6 unchanged lines hidden (view full) ---

722 *
723 * RETURNS:
724 * nothing
725 */
726static void
727ti_i2c_deactivate(device_t dev)
728{
729 struct ti_i2c_softc *sc = device_get_softc(dev);
707 if (err)
708 return (err);
709
710 return (ti_i2c_reset(sc, IIC_UNKNOWN));
711}
712
713/**
714 * ti_i2c_deactivate - deactivates the controller and releases resources

--- 6 unchanged lines hidden (view full) ---

721 *
722 * RETURNS:
723 * nothing
724 */
725static void
726ti_i2c_deactivate(device_t dev)
727{
728 struct ti_i2c_softc *sc = device_get_softc(dev);
730 clk_ident_t clk;
731
732 /* Disable the controller - cancel all transactions. */
733 ti_i2c_write_2(sc, I2C_REG_IRQENABLE_CLR, 0xffff);
734 ti_i2c_write_2(sc, I2C_REG_STATUS, 0xffff);
735 ti_i2c_write_2(sc, I2C_REG_CON, 0);
736
737 /* Release the interrupt handler. */
738 if (sc->sc_irq_h != NULL) {

--- 11 unchanged lines hidden (view full) ---

750
751 /* Release the IRQ resource. */
752 if (sc->sc_irq_res != NULL) {
753 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
754 sc->sc_irq_res = NULL;
755 }
756
757 /* Finally disable the functional and interface clocks. */
729
730 /* Disable the controller - cancel all transactions. */
731 ti_i2c_write_2(sc, I2C_REG_IRQENABLE_CLR, 0xffff);
732 ti_i2c_write_2(sc, I2C_REG_STATUS, 0xffff);
733 ti_i2c_write_2(sc, I2C_REG_CON, 0);
734
735 /* Release the interrupt handler. */
736 if (sc->sc_irq_h != NULL) {

--- 11 unchanged lines hidden (view full) ---

748
749 /* Release the IRQ resource. */
750 if (sc->sc_irq_res != NULL) {
751 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res);
752 sc->sc_irq_res = NULL;
753 }
754
755 /* Finally disable the functional and interface clocks. */
758 clk = I2C0_CLK + sc->device_id;
759 ti_prcm_clk_disable(clk);
756 ti_prcm_clk_disable(sc->clk_id);
760}
761
762static int
763ti_i2c_sysctl_clk(SYSCTL_HANDLER_ARGS)
764{
765 int clk, psc, sclh, scll;
766 struct ti_i2c_softc *sc;
767

--- 42 unchanged lines hidden (view full) ---

810}
811
812static int
813ti_i2c_probe(device_t dev)
814{
815
816 if (!ofw_bus_status_okay(dev))
817 return (ENXIO);
757}
758
759static int
760ti_i2c_sysctl_clk(SYSCTL_HANDLER_ARGS)
761{
762 int clk, psc, sclh, scll;
763 struct ti_i2c_softc *sc;
764

--- 42 unchanged lines hidden (view full) ---

807}
808
809static int
810ti_i2c_probe(device_t dev)
811{
812
813 if (!ofw_bus_status_okay(dev))
814 return (ENXIO);
818 if (!ofw_bus_is_compatible(dev, "ti,i2c"))
815 if (!ofw_bus_is_compatible(dev, "ti,omap4-i2c"))
819 return (ENXIO);
820 device_set_desc(dev, "TI I2C Controller");
821
822 return (0);
823}
824
825static int
826ti_i2c_attach(device_t dev)

--- 5 unchanged lines hidden (view full) ---

832 struct sysctl_oid_list *tree;
833 uint16_t fifosz;
834
835 sc = device_get_softc(dev);
836 sc->sc_dev = dev;
837
838 /* Get the i2c device id from FDT. */
839 node = ofw_bus_get_node(dev);
816 return (ENXIO);
817 device_set_desc(dev, "TI I2C Controller");
818
819 return (0);
820}
821
822static int
823ti_i2c_attach(device_t dev)

--- 5 unchanged lines hidden (view full) ---

829 struct sysctl_oid_list *tree;
830 uint16_t fifosz;
831
832 sc = device_get_softc(dev);
833 sc->sc_dev = dev;
834
835 /* Get the i2c device id from FDT. */
836 node = ofw_bus_get_node(dev);
840 if ((OF_getencprop(node, "i2c-device-id", &sc->device_id,
841 sizeof(sc->device_id))) <= 0) {
842 device_printf(dev, "missing i2c-device-id attribute in FDT\n");
837 /* i2c ti,hwmods bindings is special: it start with index 1 */
838 sc->clk_id = ti_hwmods_get_clock(dev);
839 if (sc->clk_id == INVALID_CLK_IDENT) {
840 device_printf(dev, "failed to get device id using ti,hwmod\n");
843 return (ENXIO);
844 }
845
846 /* Get the memory resource for the register mapping. */
847 rid = 0;
848 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
849 RF_ACTIVE);
850 if (sc->sc_mem_res == NULL) {

--- 140 unchanged lines hidden ---
841 return (ENXIO);
842 }
843
844 /* Get the memory resource for the register mapping. */
845 rid = 0;
846 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
847 RF_ACTIVE);
848 if (sc->sc_mem_res == NULL) {

--- 140 unchanged lines hidden ---