Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: usb5303: add support for reference clock specified in device tree

USB3503 chip supports 8 values of reference clock. The value is
specified by REF_SEL[1:0] pins and INT_N line. This patch add support
for getting 'refclk' clock, enabling it and setting INT_N line according
to the value of the gathered clock. If no clock has been specified,
driver defaults to the old behaviour (assuming that clock has been
specified by REF_SEL pins from primary reference clock frequencies
table).

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Marek Szyprowski and committed by
Greg Kroah-Hartman
657d898a 6fecd4f2

+65 -2
+8
Documentation/devicetree/bindings/usb/usb3503.txt
··· 15 15 - reset-gpios: Should specify GPIO for reset. 16 16 - initial-mode: Should specify initial mode. 17 17 (1 for HUB mode, 2 for STANDBY mode) 18 + - refclk: Clock used for driving REFCLK signal (optional, if not provided 19 + the driver assumes that clock signal is always available, its 20 + rate is specified by REF_SEL pins and a value from the primary 21 + reference clock frequencies table is used) 22 + - refclk-frequency: Frequency of the REFCLK signal as defined by REF_SEL 23 + pins (optional, if not provided, driver will not set rate of the 24 + REFCLK signal and assume that a value from the primary reference 25 + clock frequencies table is used) 18 26 19 27 Examples: 20 28 usb3503@08 {
+57 -2
drivers/usb/misc/usb3503.c
··· 18 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 21 + #include <linux/clk.h> 21 22 #include <linux/i2c.h> 22 23 #include <linux/gpio.h> 23 24 #include <linux/delay.h> ··· 58 57 enum usb3503_mode mode; 59 58 struct regmap *regmap; 60 59 struct device *dev; 60 + struct clk *clk; 61 61 u8 port_off_mask; 62 62 int gpio_intn; 63 63 int gpio_reset; 64 64 int gpio_connect; 65 + bool secondary_ref_clk; 65 66 }; 66 67 67 68 static int usb3503_reset(struct usb3503 *hub, int state) ··· 187 184 hub->gpio_reset = pdata->gpio_reset; 188 185 hub->mode = pdata->initial_mode; 189 186 } else if (np) { 187 + struct clk *clk; 190 188 hub->port_off_mask = 0; 189 + 190 + clk = devm_clk_get(dev, "refclk"); 191 + if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) { 192 + dev_err(dev, "unable to request refclk (%d)\n", err); 193 + return PTR_ERR(clk); 194 + } 195 + 196 + if (!IS_ERR(clk)) { 197 + u32 rate = 0; 198 + hub->clk = clk; 199 + 200 + if (!of_property_read_u32(np, "refclk-frequency", 201 + &rate)) { 202 + 203 + switch (rate) { 204 + case 38400000: 205 + case 26000000: 206 + case 19200000: 207 + case 12000000: 208 + hub->secondary_ref_clk = 0; 209 + break; 210 + case 24000000: 211 + case 27000000: 212 + case 25000000: 213 + case 50000000: 214 + hub->secondary_ref_clk = 1; 215 + break; 216 + default: 217 + dev_err(dev, 218 + "unsupported reference clock rate (%d)\n", 219 + (int) rate); 220 + return -EINVAL; 221 + } 222 + err = clk_set_rate(hub->clk, rate); 223 + if (err) { 224 + dev_err(dev, 225 + "unable to set reference clock rate to %d\n", 226 + (int) rate); 227 + return err; 228 + } 229 + } 230 + 231 + err = clk_prepare_enable(hub->clk); 232 + if (err) { 233 + dev_err(dev, 234 + "unable to enable reference clock\n"); 235 + return err; 236 + } 237 + } 191 238 192 239 property = of_get_property(np, "disabled-ports", &len); 193 240 if (property && (len / sizeof(u32)) > 0) { ··· 266 213 dev_err(dev, "Ports disabled with no control interface\n"); 267 214 268 215 if (gpio_is_valid(hub->gpio_intn)) { 269 - err = devm_gpio_request_one(dev, hub->gpio_intn, 270 - GPIOF_OUT_INIT_HIGH, "usb3503 intn"); 216 + int val = hub->secondary_ref_clk ? GPIOF_OUT_INIT_LOW : 217 + GPIOF_OUT_INIT_HIGH; 218 + err = devm_gpio_request_one(dev, hub->gpio_intn, val, 219 + "usb3503 intn"); 271 220 if (err) { 272 221 dev_err(dev, 273 222 "unable to request GPIO %d as connect pin (%d)\n",