<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Oct 9, 2012, at 1:31 PM, Jean-Christophe PLAGNIOL-VILLARD <<a href="mailto:plagnioj@jcrosoft.com">plagnioj@jcrosoft.com</a>> wrote:</div>[cut<span style="font-size: 13px; ">]</span></div><div><span style="font-size: 13px;"><br></span><blockquote type="cite"><blockquote type="cite"><br>+<br>+#include <common.h><br>+#include <errno.h><br>+#include <malloc.h><br>+#include <io.h><br>+#include <gpio.h><br>+#include <init.h><br>+#include <mach/platform.h><br>+<br>+#define GPIOFSEL(x)  (0x00+(x)*4)<br>+#define GPIOSET(x)   (0x1c+(x)*4)<br>+#define GPIOCLR(x)   (0x28+(x)*4)<br>+#define GPIOLEV(x)   (0x34+(x)*4)<br>+#define GPIOEDS(x)   (0x40+(x)*4)<br>+#define GPIOREN(x)   (0x4c+(x)*4)<br>+#define GPIOFEN(x)   (0x58+(x)*4)<br>+#define GPIOHEN(x)   (0x64+(x)*4)<br>+#define GPIOLEN(x)   (0x70+(x)*4)<br>+#define GPIOAREN(x)  (0x7c+(x)*4)<br>+#define GPIOAFEN(x)  (0x88+(x)*4)<br>+#define GPIOUD(x)    (0x94+(x)*4)<br>+#define GPIOUDCLK(x) (0x98+(x)*4)<br></blockquote><br><blockquote type="cite">+<br>+enum {<br>+<span class="Apple-tab-span" style="white-space:pre">       </span>GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,<br>+<span class="Apple-tab-span" style="white-space:pre">       </span>GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,<br>+<span class="Apple-tab-span" style="white-space:pre"> </span>GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,<br>+<span class="Apple-tab-span" style="white-space:pre">  </span>GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,<br>+};<br>+<br>+struct bcm2835_gpio_chip {<br>+<span class="Apple-tab-span" style="white-space:pre">     </span>void __iomem *base;<br>+<span class="Apple-tab-span" style="white-space:pre">      </span>struct gpio_chip chip;<br>+};<br>+<br>+static int bcm2835_set_function(struct gpio_chip *chip, unsigned gpio, int function)<br>+{<br></blockquote>you should add one bank pre gpio_chip <br><blockquote type="cite">+<span class="Apple-tab-span" style="white-space:pre">     </span>struct bcm2835_gpio_chip *bcmgpio = container_of(chip, struct bcm2835_gpio_chip, chip);<br>+<span class="Apple-tab-span" style="white-space:pre">  </span>void __iomem *base = bcmgpio->base;<br>+<span class="Apple-tab-span" style="white-space:pre">   </span>unsigned gpiodir;<br>+<span class="Apple-tab-span" style="white-space:pre">        </span>unsigned gpio_bank = gpio / 10;<br>+<span class="Apple-tab-span" style="white-space:pre">  </span>unsigned gpio_field_offset = (gpio - 10 * gpio_bank) * 3;<br></blockquote>so this will be dropped<br><blockquote type="cite">+<br>+<span class="Apple-tab-span" style="white-space:pre"> </span>gpiodir = readl(base + GPIOFSEL(gpio_bank));<br>+<span class="Apple-tab-span" style="white-space:pre">     </span>gpiodir &= ~(7 << gpio_field_offset);<br>+<span class="Apple-tab-span" style="white-space:pre">  </span>gpiodir |= function << gpio_field_offset;<br>+<span class="Apple-tab-span" style="white-space:pre">  </span>writel(gpiodir, base + GPIOFSEL(gpio_bank));<br>+<span class="Apple-tab-span" style="white-space:pre">     </span>gpiodir = readl(base + GPIOFSEL(gpio_bank));<br>+<br>+<span class="Apple-tab-span" style="white-space:pre">  </span>return 0;<br>+}<br>+<br></blockquote></blockquote></div><br><div>Uhm, this could be not convenient since the two banks in BCM2835 are not really separated, there are not exclusive registers for one bank or for the other. The registers used for GPIOs configuration manage both the two banks (see for example GPFSELx).</div><div>If I add one bank I can avoid calculating the bank offset for GPCLRx and GPSETx but not for GPFSELx and viceversa (in fact in the code I select the bank for GPCLRx and GPSETx with gpio_bank = gpio / 32 whereas for GPIOFSEL with gpio_bank = gpio / 10).  Yay, confusing …</div><div><br></div><div>Best,</div><div><br></div><div>--</div><div>Carlo Caione</div></body></html>